From 8e406ec976debaf8f0af6ae167d91f537f5fca20 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 28 Jan 2016 15:40:31 +0100 Subject: Editieren der ausgewählten Lösung nun möglich MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filterBruteForce.lpi | 9 +- filterBruteForce.lpr | 3 +- unit1.lfm | 17 ++-- unit1.pas | 13 ++- unit2.pas | 250 +++++++++++++++++++++++++++++++++++++++++---------- unit4.lfm | 52 +++++++++++ unit4.pas | 101 +++++++++++++++++++++ 7 files changed, 388 insertions(+), 57 deletions(-) create mode 100644 unit4.lfm create mode 100644 unit4.pas diff --git a/filterBruteForce.lpi b/filterBruteForce.lpi index d88b0cb..ff44625 100644 --- a/filterBruteForce.lpi +++ b/filterBruteForce.lpi @@ -33,7 +33,7 @@ - + @@ -58,6 +58,13 @@ + + + + + + + diff --git a/filterBruteForce.lpr b/filterBruteForce.lpr index 96157be..6e5fcda 100644 --- a/filterBruteForce.lpr +++ b/filterBruteForce.lpr @@ -7,7 +7,7 @@ uses cthreads, {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset - Forms, Unit1, Unit2, Unit3 + Forms, Unit1, Unit2, Unit3,Unit4 { you can add units after this }; {$R *.res} @@ -17,6 +17,7 @@ begin Application.Initialize; Application.CreateForm(TForm1, Form1); Application.CreateForm(TForm2, Form2); + Application.CreateForm(TForm3,Form3); Application.Run; end. diff --git a/unit1.lfm b/unit1.lfm index 7ef51fa..2e52412 100644 --- a/unit1.lfm +++ b/unit1.lfm @@ -31,9 +31,9 @@ object Form1: TForm1 end object Label1: TLabel Left = 0 - Height = 13 + Height = 20 Top = 0 - Width = 98 + Width = 101 Caption = 'Kondensatoren:' ParentColor = False end @@ -54,9 +54,9 @@ object Form1: TForm1 end object Label2: TLabel Left = 152 - Height = 13 + Height = 20 Top = 0 - Width = 98 + Width = 96 Caption = 'Potentiometer:' ParentColor = False end @@ -73,9 +73,9 @@ object Form1: TForm1 end object Label3: TLabel Left = 303 - Height = 13 + Height = 20 Top = 0 - Width = 77 + Width = 80 Caption = 'Frequenzen:' ParentColor = False end @@ -95,7 +95,8 @@ object Form1: TForm1 Width = 76 ItemHeight = 0 OnClick = ListBox1Click - ScrollWidth = 72 + OnDblClick = ListBox1DblClick + ScrollWidth = 74 TabOrder = 4 TopIndex = -1 end @@ -105,7 +106,7 @@ object Form1: TForm1 Top = 0 Width = 484 ItemHeight = 0 - ScrollWidth = 480 + ScrollWidth = 482 TabOrder = 5 TopIndex = -1 end diff --git a/unit1.pas b/unit1.pas index 716c1ef..da318a7 100644 --- a/unit1.pas +++ b/unit1.pas @@ -29,6 +29,7 @@ type procedure FormResize(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure iterationsCallBack(Sender: TObject); + procedure ListBox1DblClick(Sender: TObject); procedure loesungsCallBack(Sender: TObject); private { private declarations } @@ -45,7 +46,7 @@ implementation {$R *.lfm} -uses unit3; +uses unit3, unit4; { TForm1 } @@ -106,6 +107,16 @@ begin end; end; +procedure TForm1.ListBox1DblClick(Sender: TObject); +begin + if (Listbox1.Itemindex>=0) and + (Listbox1.Itemindex0 do - x[pos(c,x)]:=decimalseparator; - for i:=0 to length(edg)-1 do - if pos(edg[i],x)>0 then begin - add(strtofloat(trim(leftStr(x,pos(edg[i],x)-1)))*fak[i],cnt); - exit; - end; - add(strtofloat(trim(x)),cnt); + add(strToScientific(x),cnt); +end; + +function tMyExtendedArray.toStr(llNum: longint): string; +begin + if (llNum<0) or (llNum>=length(zahlen)) then begin + result:='nan ('+inttostr(llNum)+') '; + exit; + end; + result:=scientificToStr(zahlen[llNum]) end; procedure tMyExtendedArray.dump(sl: tStrings); @@ -335,16 +335,7 @@ var i: longint; begin if _ordnung<>o then begin - for i:=0 to length(Rs)-1 do - if Rs[i].i>=0 then begin - inc(ars.anzahlen[Rs[i].i]); - Rs[i].i:=-1; - end; - for i:=0 to length(Cs)-1 do - if Cs[i]>=0 then begin - inc(acs.anzahlen[Cs[i]]); - Cs[i]:=-1; - end; + allesZurueckLegen; _ordnung:=o; if assigned(gegenstueck) then @@ -375,28 +366,39 @@ end; procedure tFilter.anzeigen(sl: tStrings); var - s: string; i: longint; +begin + uebersicht(sl); + for i:=0 to ordnung-1 do + sl.add( + ' R'+inttostr(i+1)+' = '+scientificToStr(Rs[i].x)+'Ω von '+ars.toStr(Rs[i].i)+'Ω,'+ + ' C'+inttostr(i+1)+' = '+acs.toStr(Cs[i])+'F' + ); +end; + +procedure tFilter.uebersicht(sl: tStrings); +var + s: string; begin if self is tHochpass then s:='Hochpass' else s:='Tiefpass'; if assigned(gegenstueck) then s:=s+''''; - sl.add(s+' '+inttostr(ordnung)+'. Ordnung ('+floattostr(frequenz)+' Hz)'); - for i:=0 to ordnung-1 do begin - s:=' R'+inttostr(i+1)+' = '+floattostr(Rs[i].x)+' Ω von '; - if (Rs[i].i>=0) and - (Rs[i].i=0 then begin + inc(ars.anzahlen[Rs[i].i]); + Rs[i].i:=-1; + end; + for i:=0 to length(Cs)-1 do + if Cs[i]>=0 then begin + inc(acs.anzahlen[Cs[i]]); + Cs[i]:=-1; + end; +end; + +function tFilter.findeRsZuAnderenCs(_cs,_rs: tStrings): boolean; +var + tmpArs,tmpAcs: tMyExtendedArray; + tmpRs: tExtendedLongintArray; + tmpCs: tLongintArray; + tmpVals: array of extended; + i: longint; +begin + result:=true; + + tmpArs:=ars; // kleiner Hack + tmpAcs:=acs; + + setlength(tmpRs,length(Rs)); + for i:=0 to length(tmpRs)-1 do + tmpRs[i]:=Rs[i]; + setlength(tmpCs,length(Cs)); + for i:=0 to length(tmpCs)-1 do + tmpCs[i]:=Cs[i]; + + ars:=tMyExtendedArray.create; + for i:=0 to length(Rs)-1 do // Widerstände nach Soll generieren + if Rs[i].i>=0 then begin + ars.add(tmpArs.zahlen[Rs[i].i],1); + Rs[i].i:=-1; + end; + + if ars.count<>ordnung then begin + _rs.add('Ich habe '+inttostr(ars.count)+' Widerstände zur Verfügung statt erwarteter '+inttostr(ordnung)+'.'); + result:=false; + end; + + setlength(tmpVals,0); + acs:=tMyExtendedArray.create; + for i:=0 to _cs.count-1 do // Kondensatoren aus Tabelle auslesen + if rightStr(trim(_cs[i]),1)='F' then begin + if length(tmpVals)>=ordnung then begin + _rs.add('zu viele Kondensatoren!'); + result:=false; + break; + end; + setlength(tmpVals,length(tmpVals)+1); + tmpVals[length(tmpVals)-1]:=strToScientific(leftStr(_cs[i],length(_cs[i])-1)); + acs.add(tmpVals[length(tmpVals)-1],1); + end; + if length(tmpVals)0 do + s[pos(c,s)]:=decimalseparator; + for i:=0 to length(edg)-1 do + if pos(edg[i],s)>0 then begin + result:=strtofloat(trim(leftStr(s,pos(edg[i],s)-1)))*fak[i]; + exit; + end; + result:=strtofloat(trim(s)); +end; + +function scientificToStr(x: extended): string; +var + f: extended; + i: longint; +begin + f:=1; + while abs(x)>=0.99e3 do begin + x:=x*1e-3; + f:=f*1e3; + end; + if x<>0 then + while abs(x)<0.99 do begin + x:=x*1e3; + f:=f*1e-3; + end; + for i:=0 to length(fak)-1 do + if abs(f/fak[i]-1)<0.1 then begin + result:=floattostr(x); + if length(result)-pos(decimalSeparator,result+decimalSeparator)>3 then + delete(result,pos(decimalSeparator,result+decimalSeparator)+4,length(result)); + result:=result+' '+edg[i]; + exit; + end; + result:=floattostr(x*f); + if length(result)-pos(decimalSeparator,result+decimalSeparator)>3 then + delete(result,pos(decimalSeparator,result+decimalSeparator)+4,length(result)); + result:=result+' '; +end; + function liesExtendedArray(sl: tStrings): tMyExtendedArray; begin result:=liesExtendedArray(sl,''); diff --git a/unit4.lfm b/unit4.lfm new file mode 100644 index 0000000..add640b --- /dev/null +++ b/unit4.lfm @@ -0,0 +1,52 @@ +object Form3: TForm3 + Left = 514 + Height = 543 + Top = 239 + Width = 761 + Caption = 'Form3' + ClientHeight = 543 + ClientWidth = 761 + OnDestroy = FormDestroy + OnResize = FormResize + OnShow = FormShow + LCLVersion = '1.4.4.0' + object ListBox1: TListBox + Left = 0 + Height = 200 + Top = 0 + Width = 272 + ItemHeight = 0 + OnClick = ListBox1Click + ScrollWidth = 270 + TabOrder = 0 + TopIndex = -1 + end + object Memo1: TMemo + Left = 384 + Height = 200 + Top = 0 + Width = 113 + OnChange = Memo1Change + TabOrder = 1 + end + object ListBox2: TListBox + Left = 504 + Height = 200 + Top = 0 + Width = 248 + ItemHeight = 0 + ScrollWidth = 246 + TabOrder = 2 + TopIndex = -1 + end + object ListBox3: TListBox + Left = 280 + Height = 200 + Top = 0 + Width = 96 + ItemHeight = 0 + ScrollWidth = 94 + TabOrder = 3 + TopIndex = -1 + end +end diff --git a/unit4.pas b/unit4.pas new file mode 100644 index 0000000..8d11c99 --- /dev/null +++ b/unit4.pas @@ -0,0 +1,101 @@ +unit Unit4; + +{$mode objfpc}{$H+} + +interface + +uses + Classes,SysUtils,FileUtil,Forms,Controls,Graphics,Dialogs,StdCtrls,unit2; + +type + + { TForm3 } + + TForm3 = class(TForm) + ListBox1: TListBox; + ListBox2: TListBox; + ListBox3: TListBox; + Memo1: TMemo; + procedure FormDestroy(Sender: TObject); + procedure FormResize(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure ListBox1Click(Sender: TObject); + procedure Memo1Change(Sender: TObject); + private + { private declarations } + public + { public declarations } + loesung: tLoesung; + tmpInhalt: array of tStringList; + end; + +var + Form3: TForm3; + +implementation + +{$R *.lfm} + +{ TForm3 } + +procedure TForm3.FormResize(Sender: TObject); +begin + listBox1.height:=form3.clientHeight-listBox1.top; + listBox1.width:=(form3.clientWidth-listBox1.left-12) div 4; + listBox2.height:=form3.clientHeight-listBox2.top; + listBox2.left:=listBox1.left+listBox1.width+4; + listBox2.width:=(form3.clientWidth-listBox2.left-8) div 3; + memo1.height:=form3.clientHeight-memo1.top; + memo1.left:=listBox2.left+listBox2.width+4; + memo1.width:=(form3.clientWidth-memo1.left-4) div 2; + listBox3.height:=form3.clientHeight-listBox3.top; + listBox3.left:=memo1.left+memo1.width+4; + listBox3.width:=form3.clientWidth-listBox3.left; +end; + +procedure TForm3.FormDestroy(Sender: TObject); +var + i: longint; +begin + loesung.free; + for i:=0 to length(tmpInhalt)-1 do + tmpInhalt[i].free; + setlength(tmpInhalt,0); +end; + +procedure TForm3.FormShow(Sender: TObject); +var + i: longint; +begin + loesung.filterUebersicht(listBox1.items); + for i:=0 to length(tmpInhalt)-1 do + tmpInhalt[i].free; + setlength(tmpInhalt,listBox1.items.count); + for i:=0 to length(tmpInhalt)-1 do + tmpInhalt[i]:=nil; + listBox2.items.clear; + listBox3.items.clear; + memo1.lines.clear; +end; + +procedure TForm3.ListBox1Click(Sender: TObject); +begin + if (listBox1.itemIndex>=0) and + (listBox1.itemIndex