summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2016-01-28 15:40:31 +0100
committerErich Eckner <git@eckner.net>2016-01-28 15:40:31 +0100
commit8e406ec976debaf8f0af6ae167d91f537f5fca20 (patch)
tree78ef6f74aab368bf31ade2fe848c15ae3e509f46
parent042b7edeabf0cc5e0168bbfdbf18363ccb9391e5 (diff)
downloadFilterBruteForce-8e406ec976debaf8f0af6ae167d91f537f5fca20.tar.xz
Editieren der ausgewählten Lösung nun möglich
-rw-r--r--filterBruteForce.lpi9
-rw-r--r--filterBruteForce.lpr3
-rw-r--r--unit1.lfm17
-rw-r--r--unit1.pas13
-rw-r--r--unit2.pas250
-rw-r--r--unit4.lfm52
-rw-r--r--unit4.pas101
7 files changed, 388 insertions, 57 deletions
diff --git a/filterBruteForce.lpi b/filterBruteForce.lpi
index d88b0cb..ff44625 100644
--- a/filterBruteForce.lpi
+++ b/filterBruteForce.lpi
@@ -33,7 +33,7 @@
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
- <Units Count="4">
+ <Units Count="5">
<Unit0>
<Filename Value="filterBruteForce.lpr"/>
<IsPartOfProject Value="True"/>
@@ -58,6 +58,13 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit3"/>
</Unit3>
+ <Unit4>
+ <Filename Value="unit4.pas"/>
+ <IsPartOfProject Value="True"/>
+ <ComponentName Value="Form3"/>
+ <ResourceBaseClass Value="Form"/>
+ <UnitName Value="Unit4"/>
+ </Unit4>
</Units>
</ProjectOptions>
<CompilerOptions>
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.Itemindex<length(loesungen.inhalt)) then begin
+ form3.loesung.free;
+ form3.loesung:=tLoesung.create(loesungen.inhalt[listBox1.itemIndex]);
+ form3.showModal;
+ end;
+end;
+
procedure TForm1.loesungsCallBack(Sender: TObject);
begin
inc(c2);
diff --git a/unit2.pas b/unit2.pas
index e75d847..edd6b70 100644
--- a/unit2.pas
+++ b/unit2.pas
@@ -24,6 +24,7 @@ type
function count: longint;
procedure add(x: extended; cnt: longint); overload;
procedure add(x: string; cnt: longint); overload;
+ function toStr(llNum: longint): string;
procedure dump(sl: tStrings);
property inhalt[i: longint]: extended
read rInhalt; default;
@@ -59,10 +60,14 @@ type
write wFrequenz;
function ordnungNichtDirektEinstellen: boolean; inline;
procedure anzeigen(sl: tStrings);
+ procedure uebersicht(sl: tStrings);
+ procedure sortenreinAnzeigen(rsl,csl: tStrings);
function dump: string;
function weite: longint;
function cWaehlen(idx: longint; var nutzen: extended): boolean; // Erfolg?
- function rsWaehlen(idx: longint): boolean; dynamic; abstract; // Erfolg?
+ function rsWaehlen(idx: longint): boolean; dynamic; abstract; // Erfolg?
+ procedure allesZurueckLegen;
+ function findeRsZuAnderenCs(_cs,_rs: tStrings): boolean; // Erfolg?
end;
tHochpass = class(tFilter)
function rsWaehlen(idx: longint): boolean; override;
@@ -86,6 +91,7 @@ type
function ordnungsSchritt: boolean;
function auswahlSchritt(minNutzen: extended; callBack: tNotifyEvent): boolean;
procedure anzeigen(sl: tStrings);
+ procedure filterUebersicht(sl: tStrings);
function dump: string;
function dumpWeite: string;
end;
@@ -101,6 +107,8 @@ type
function minNutzen(cnt: longint): extended;
end;
+function strToScientific(s: string): extended; inline;
+function scientificToStr(x: extended): string; inline;
function liesExtendedArray(sl: tStrings): tMyExtendedArray; overload;
function liesExtendedArray(sl: tStrings; suf: string): tMyExtendedArray; overload;
procedure liesExtendedArray(sl: tStrings; suf: string; var arr: tMyExtendedArray); overload;
@@ -201,25 +209,17 @@ begin
end;
procedure tMyExtendedArray.add(x: string; cnt: longint);
-const
- edg: array[0..13] of string = ('k','M','G','T','P','E','m','µ','n','p','f','a','y','z');
- fak: array[0..13] of extended = (1e3,1e6,1e9,1e12,1e15,1e18,1e-3,1e-6,1e-9,1e-12,1e-15,1e-18,1e-21,1e-24);
-var
- i: longint;
- c: char;
begin
- if decimalseparator='.' then
- c:=','
- else
- c:='.';
- while pos(c,x)>0 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<length(ars.zahlen)) then
- s:=s+floattostr(ars.zahlen[Rs[i].i])
- else
- s:=s+'nan('+inttostr(Rs[i].i)+')';
- s:=s+' Ω, C'+inttostr(i+1)+' = ';
- if (Cs[i]>=0) and
- (Cs[i]<length(acs.zahlen)) then
- s:=s+floattostr(acs.zahlen[Cs[i]])
- else
- s:=s+'nan('+inttostr(Cs[i])+')';
- s:=s+' F';
- sl.add(s);
+ sl.add(s+' '+inttostr(ordnung)+'. Ordnung ('+scientificToStr(frequenz)+'Hz)');
+end;
+
+procedure tFilter.sortenreinAnzeigen(rsl,csl: tStrings);
+var
+ i: longint;
+begin
+ if assigned(rsl) then begin
+ rsl.clear;
+ for i:=0 to ordnung-1 do
+ rsl.add(scientificToStr(Rs[i].x)+'Ω');
+ end;
+ if assigned(csl) then begin
+ csl.clear;
+ for i:=0 to ordnung-1 do
+ csl.add(acs.toStr(Cs[i])+'F');
end;
end;
@@ -462,6 +464,101 @@ begin
result:=true;
end;
+procedure tFilter.allesZurueckLegen;
+var
+ i: longint;
+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;
+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)<ordnung then begin
+ _rs.add('zu wenige Kondensatoren!');
+ result:=false;
+ end;
+
+ for i:=0 to length(tmpVals)-1 do
+ cs[i]:=acs.findeWenigstens(tmpVals[i]);
+
+ for i:=0 to (ordnung div 2) -1 do
+ if not rsWaehlen(i) then begin
+ _rs.add('Widerstandspaar ('+inttostr(2*i+1)+';'+inttostr(2*i+2)+') nicht wählbar!');
+ result:=false;
+ break;
+ end;
+
+ if result then begin
+ self.sortenreinAnzeigen(_rs,nil);
+ _rs.add('alles ok ('+inttostr(random(1000))+')!');
+ end;
+
+ ars.free;
+ acs.free;
+
+ ars:=tmpArs; // kleinen Hack rückgängig machen
+ acs:=tmpAcs;
+ setlength(Rs,length(tmpRs));
+ setlength(Rs,length(tmpRs));
+ for i:=0 to length(Rs)-1 do
+ Rs[i]:=tmpRs[i];
+ setlength(Cs,length(tmpCs));
+ for i:=0 to length(Cs)-1 do
+ Cs[i]:=tmpCs[i];
+end;
+
// tHochpass *******************************************************************
function tHochpass.rsWaehlen(idx: longint): boolean;
@@ -705,6 +802,15 @@ begin
filter[i].anzeigen(sl);
end;
+procedure tLoesung.filterUebersicht(sl: tStrings);
+var
+ i: longint;
+begin
+ sl.clear;
+ for i:=0 to length(filter)-1 do
+ filter[i].uebersicht(sl);
+end;
+
function tLoesung.dump: string;
var
i: longint;
@@ -806,6 +912,58 @@ end;
// allgemeine Funktionen *******************************************************
+const
+ edg: array[0..13] of string = ('k','M','G','T','P','E','m','µ','n','p','f','a','y','z');
+ fak: array[0..13] of extended = (1e3,1e6,1e9,1e12,1e15,1e18,1e-3,1e-6,1e-9,1e-12,1e-15,1e-18,1e-21,1e-24);
+
+function strToScientific(s: string): extended;
+var
+ i: longint;
+ c: char;
+begin
+ if decimalseparator='.' then
+ c:=','
+ else
+ c:='.';
+ while pos(c,s)>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<length(loesung.filter)) then begin
+ loesung.filter[listBox1.itemIndex].sortenreinAnzeigen(listBox3.items,listBox2.items);
+ if tmpInhalt[listBox1.itemIndex]=nil then begin
+ tmpInhalt[listBox1.itemIndex]:=tStringList.create;
+ tmpInhalt[listBox1.itemIndex].text:=listBox2.items.text;
+ end;
+ memo1.lines.text:=tmpInhalt[listBox1.itemIndex].text;
+ end;
+end;
+
+procedure TForm3.Memo1Change(Sender: TObject);
+begin
+ tmpInhalt[listBox1.itemIndex].text:=memo1.lines.text;
+ loesung.filter[listBox1.itemIndex].findeRsZuAnderenCs(memo1.lines,listBox3.items);
+end;
+
+end.
+