-
Notifications
You must be signed in to change notification settings - Fork 0
/
duplicateremovalui.pas
413 lines (371 loc) · 15.9 KB
/
duplicateremovalui.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
UNIT duplicateRemovalUi;
{$mode objfpc}{$H+}
INTERFACE
USES
Classes, sysutils, Forms, Controls, Graphics, Dialogs, Grids, ExtCtrls,
StdCtrls, compoundGates, challenges, workspaces,visualGates,sprites,myGenerics;
TYPE
{ TDuplicateRemovalDialog }
TDuplicateRemovalDialog = class(TForm)
CaptionLabelA: TLabel;
CaptionLabelB: TLabel;
deleteBLabel: TLabel;
deleteBShape: TShape;
DetailsMemoA: TMemo;
DetailsMemoB: TMemo;
generateTestCasesLabel: TLabel;
generateTestCasesLabel1: TLabel;
deleteALabel: TLabel;
generateTestCasesShape: TShape;
generateTestCasesShape1: TShape;
CompareCaptionLabel: TLabel;
deleteAShape: TShape;
Label6: TLabel;
Label7: TLabel;
StepCountEdit: TEdit;
CandidatesPanel: TPanel;
ComparisonPanel: TPanel;
ElementAPanel: TPanel;
ElementBPanel: TPanel;
CandidateStringGrid: TStringGrid;
TestCasesStringGrid: TStringGrid;
TestCaseCountEdit: TEdit;
Timer1: TTimer;
PROCEDURE CandidateStringGridSelection(Sender: TObject; aCol, aRow: integer);
PROCEDURE deleteAShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE deleteBShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE FormResize(Sender: TObject);
PROCEDURE FormShow(Sender: TObject);
PROCEDURE generateTestCasesShape1MouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE generateTestCasesShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
PROCEDURE StepCountEditEditingDone(Sender: TObject);
PROCEDURE TestCaseCountEditEditingDone(Sender: TObject);
PROCEDURE TestCasesStringGridHeaderClick(Sender: TObject; IsColumn: boolean; index: integer);
PROCEDURE TestCasesStringGridValidateEntry(Sender: TObject; aCol, aRow: integer; CONST oldValue: string; VAR newValue: string);
PROCEDURE Timer1Timer(Sender: TObject);
private
indexA ,indexB :longint;
testerA,testerB :P_testCreator;
//TODO: visualA,visualB :P_visualGate; (Create visual representations, scale them [!!!] to fit into the boxes and paint them...)
candidateIndexes:T_arrayOfLongint;
lastUpdatedA,lastUpdatedB:longint;
PROCEDURE fillTable;
public
PROCEDURE showFor(CONST paletteEntryIndex:longint);
end;
FUNCTION DuplicateRemovalDialog: TDuplicateRemovalDialog;
IMPLEMENTATION
USES paletteHandling, logicalGates,visuals;
VAR myDuplicateRemovalDialog: TDuplicateRemovalDialog=nil;
FUNCTION DuplicateRemovalDialog: TDuplicateRemovalDialog;
begin
if myDuplicateRemovalDialog=nil then myDuplicateRemovalDialog:=TDuplicateRemovalDialog.create(nil);
result:=myDuplicateRemovalDialog;
end;
{$R *.lfm}
{ TDuplicateRemovalDialog }
PROCEDURE TDuplicateRemovalDialog.TestCaseCountEditEditingDone(Sender: TObject);
VAR newCount: longint;
begin
newCount:=strToIntDef(TestCaseCountEdit.text,-1);
if (newCount<=0) or (newCount=length(testerA^.tests)) then begin
TestCaseCountEdit.text:=intToStr(length(testerA^.tests));
exit;
end;
testerA^.setNumberOfTestCases(newCount);
if testerB<>nil then testerB^.copyTestInputs(testerA);
lastUpdatedA:=-1;
lastUpdatedB:=-1;
end;
PROCEDURE TDuplicateRemovalDialog.TestCasesStringGridValidateEntry(Sender: TObject; aCol, aRow: integer; CONST oldValue: string; VAR newValue: string);
VAR
newStepCount: longint;
wireValue: T_wireValue;
i:longint;
begin
//Editing output...
if aCol>length(testerA^.Interfaces.inputs) then begin
newValue:=oldValue;
exit;
end;
//Editing number of steps...
if aCol=length(testerA^.Interfaces.inputs) then begin
newStepCount:=strToIntDef(newValue,-1);
if (newStepCount<1) then begin
newValue:=oldValue;
end else begin
testerA^.tests[aRow-1].maxTotalSteps:=newStepCount;
lastUpdatedA:=-1;
lastUpdatedB:=-1;
testerA^.updateTestCaseResults;
if testerB<>nil then testerB^.copyTestInputs(testerA);
end;
exit;
end;
//Editing input...
wireValue:=parseWire(newValue,testerA^.Interfaces.inputs[aCol].wireWidth,testerA^.Interfaces.inputs[aCol].representation);
for i:=0 to wireValue.width-1 do if wireValue.bit[i]=tsv_undetermined then begin
newValue:=oldValue;
exit;
end;
newValue:=getWireString(wireValue,testerA^.Interfaces.inputs[aCol].representation);
testerA^.tests[aRow-1].inputs[aCol]:=wireValue;
lastUpdatedA:=-1;
lastUpdatedB:=-1;
testerA^.updateTestCaseResults;
if testerB<>nil then testerB^.copyTestInputs(testerA);
end;
PROCEDURE TDuplicateRemovalDialog.Timer1Timer(Sender: TObject);
VAR
ka, kb: longint;
begin
if Assigned(TestCasesStringGrid.editor) and TestCasesStringGrid.editor.showing then exit;
ka:=testerA^.lastTestCasePrepared;
if testerB<>nil
then kb:=testerB^.lastTestCasePrepared
else kb:=maxLongint;
if (ka<>lastUpdatedA) or (kb<>lastUpdatedB) then begin
fillTable;
lastUpdatedA:=ka;
lastUpdatedB:=kb;
end;
end;
PROCEDURE TDuplicateRemovalDialog.StepCountEditEditingDone(Sender: TObject);
VAR newCount: int64;
i:longint;
begin
newCount:=StrToInt64Def(StepCountEdit.text,-1);
if newCount>maxLongint
then begin
newCount:=maxLongint;
StepCountEdit.text:=intToStr(maxLongint);
end else if (newCount<=0) then begin
StepCountEdit.text:='';
exit;
end;
for i:=0 to length(testerA^.tests)-1 do testerA^.tests[i].maxTotalSteps:=newCount;
testerA^.updateTestCaseResults;
if testerB<>nil then testerB^.copyTestInputs(testerA);
lastUpdatedA:=-1;
lastUpdatedB:=-1;
end;
PROCEDURE TDuplicateRemovalDialog.CandidateStringGridSelection(Sender: TObject; aCol, aRow: integer);
begin
dec(aRow);
if (aRow>=0) and (aRow<length(candidateIndexes)) then begin
indexB:=candidateIndexes[aRow];
DetailsMemoB.text:=workspace.getWorkspacePalette^.describeEntry(indexB);
if testerB<>nil then dispose(testerB,destroy);
new(testerB,createForAnalysis(workspace.getWorkspacePalette^.paletteEntries[indexB].prototype));
testerB^.copyTestInputs(testerA);
lastUpdatedB:=-1;
end;
end;
PROCEDURE TDuplicateRemovalDialog.deleteAShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
Timer1.enabled:=false;
addBackup(@workspace,wht_beforeDuplicateRemoval);
workspace.clearPreviousStates;
workspace.getWorkspacePalette^.removeEntryReplacing(indexB,indexA);
ModalResult:=mrOk;
end;
PROCEDURE TDuplicateRemovalDialog.deleteBShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
Timer1.enabled:=false;
addBackup(@workspace,wht_beforeDuplicateRemoval);
workspace.clearPreviousStates;
workspace.getWorkspacePalette^.removeEntryReplacing(indexA,indexB);
ModalResult:=mrOk;
end;
PROCEDURE TDuplicateRemovalDialog.FormResize(Sender: TObject);
CONST totalSpacing=15;
VAR k:longint;
begin
k:=(width-totalSpacing) shr 1;
ElementBPanel.width:=k;
ElementAPanel.width:=k;
end;
PROCEDURE TDuplicateRemovalDialog.FormShow(Sender: TObject);
begin
applyColorScheme(self);
ElementBPanel.color:=colorScheme.tableAlternativeColor;
DetailsMemoB .color:=colorScheme.tableAlternativeColor;
end;
PROCEDURE TDuplicateRemovalDialog.generateTestCasesShape1MouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
testerA^.generateTestCases(true,false);
if testerB<>nil then testerB^.copyTestInputs(testerA);
lastUpdatedA:=-1;
lastUpdatedB:=-1;
end;
PROCEDURE TDuplicateRemovalDialog.generateTestCasesShapeMouseDown(Sender: TObject; button: TMouseButton; Shift: TShiftState; X, Y: integer);
begin
testerA^.generateTestCases;
if testerB<>nil then testerB^.copyTestInputs(testerA);
lastUpdatedA:=-1;
lastUpdatedB:=-1;
end;
PROCEDURE TDuplicateRemovalDialog.TestCasesStringGridHeaderClick(Sender: TObject; IsColumn: boolean; index: integer);
CONST nextMode:array[T_multibitWireRepresentation] of T_multibitWireRepresentation=(wr_decimal,wr_2complement,wr_binary);
begin
if not(IsColumn) then exit;
if index<length(testerA^.Interfaces.inputs) then begin
testerA^.Interfaces.inputs[index].representation:=nextMode[testerA^.Interfaces.inputs[index].representation];
fillTable;
exit;
end;
dec(index,1+length(testerA^.Interfaces.inputs));
if index<0 then exit;
if index>length(testerA^.Interfaces.outputs) then dec(index,length(testerA^.Interfaces.outputs)+1);
if index<0 then exit;
testerA^.Interfaces.outputs[index].representation:=nextMode[testerA^.Interfaces.outputs[index].representation];
fillTable;
end;
PROCEDURE TDuplicateRemovalDialog.fillTable;
VAR i,j,k:longint;
gateInterface: T_gateInterface;
FUNCTION bothEqualAt(CONST j:longint):string;
VAR k:longint;
begin
if (testerB=nil) or (j<0) or (j>=length(testerA^.tests)) or (j>length(testerB^.tests)) then exit('');
for k:=0 to length(testerA^.tests[j].outputs)-1 do
if testerA^.tests[j].outputs[k]<>testerB^.tests[j].outputs[k]
then exit(' ');
result:='x';
end;
begin
TestCasesStringGrid.rowCount:=1+length(testerA^.tests);
k:=length(testerA^.Interfaces.inputs)+length(testerA^.Interfaces.outputs)*2+4;
while TestCasesStringGrid.Columns.count>k do TestCasesStringGrid.Columns.delete(TestCasesStringGrid.Columns.count-1);
while TestCasesStringGrid.Columns.count<k do TestCasesStringGrid.Columns.add;
if Assigned(TestCasesStringGrid.editor) then begin
TestCasesStringGrid.editor.Font.color:=colorScheme.ENABLED_TEXT_COLOR;
TestCasesStringGrid.editor.color :=colorScheme.editorBackgroundColor;
end;
//Header
i:=0;
for gateInterface in testerA^.Interfaces.inputs do begin
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableColor;
if gateInterface.wireWidth<=1
then TestCasesStringGrid.Columns[i].title.caption:=gateInterface.name
else TestCasesStringGrid.Columns[i].title.caption:=gateInterface.name+' ('+ C_multibitWireRepresentationName[gateInterface.representation]+')';
inc(i);
end;
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableAlternativeColor;
TestCasesStringGrid.Columns[i].title.caption:='Schritte';
inc(i);
TestCasesStringGrid.Columns[i].color:=colorScheme.tableAlternativeColor;
TestCasesStringGrid.Columns[i].title.caption:='=';
TestCasesStringGrid.Columns[i].readonly:=true;
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsCheckboxColumn;
TestCasesStringGrid.Columns[i].ValueChecked:='x';
TestCasesStringGrid.Columns[i].ValueUnchecked:=' ';
inc(i);
for gateInterface in testerA^.Interfaces.outputs do begin
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableColor;
if gateInterface.wireWidth<=1
then TestCasesStringGrid.Columns[i].title.caption:=gateInterface.name
else TestCasesStringGrid.Columns[i].title.caption:=gateInterface.name+' ('+ C_multibitWireRepresentationName[gateInterface.representation]+')';
TestCasesStringGrid.Columns[i].readonly:=true;
inc(i);
end;
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableColor;
TestCasesStringGrid.Columns[i].title.caption:='aktiv für';
TestCasesStringGrid.Columns[i].readonly:=true;
inc(i);
if testerB=nil then for gateInterface in testerA^.Interfaces.outputs do begin
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableAlternativeColor;
TestCasesStringGrid.Columns[i].title.caption:='';
TestCasesStringGrid.Columns[i].readonly:=true;
inc(i);
end else for gateInterface in testerB^.Interfaces.outputs do begin
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableAlternativeColor;
if gateInterface.wireWidth<=1
then TestCasesStringGrid.Columns[i].title.caption:=gateInterface.name
else TestCasesStringGrid.Columns[i].title.caption:=gateInterface.name+' ('+ C_multibitWireRepresentationName[gateInterface.representation]+')';
TestCasesStringGrid.Columns[i].readonly:=true;
inc(i);
end;
TestCasesStringGrid.Columns[i].ButtonStyle:=cbsAuto;
TestCasesStringGrid.Columns[i].color:=colorScheme.tableAlternativeColor;
TestCasesStringGrid.Columns[i].title.caption:='aktiv für';
TestCasesStringGrid.Columns[i].readonly:=true;
inc(i);
//Body
for j:=0 to length(testerA^.tests)-1 do begin
i:=0;
for gateInterface in testerA^.Interfaces.inputs do begin
TestCasesStringGrid.Cells[i,j+1]:=getWireString(testerA^.tests[j].inputs[i],gateInterface.representation);
inc(i);
end;
TestCasesStringGrid.Cells[i,j+1]:=intToStr(testerA^.tests[j].maxTotalSteps);
inc(i);
TestCasesStringGrid.Cells[i,j+1]:=bothEqualAt(j);
inc(i);
k:=0;
for gateInterface in testerA^.Interfaces.outputs do begin
if k<length(testerA^.tests[j].outputs)
then TestCasesStringGrid.Cells[i,j+1]:=getWireString(testerA^.tests[j].outputs[k],gateInterface.representation)
else TestCasesStringGrid.Cells[i,j+1]:='?';
inc(i); inc(k);
end;
TestCasesStringGrid.Cells[i,j+1]:=intToStr(testerA^.tests[j].actuallyActive);
inc(i);
k:=0;
if testerB=nil then for gateInterface in testerA^.Interfaces.outputs do begin
TestCasesStringGrid.Cells[i,j+1]:='';
inc(i);
end else for gateInterface in testerA^.Interfaces.outputs do begin
if k<length(testerB^.tests[j].outputs)
then TestCasesStringGrid.Cells[i,j+1]:=getWireString(testerB^.tests[j].outputs[k],gateInterface.representation)
else TestCasesStringGrid.Cells[i,j+1]:='?';
inc(i); inc(k);
end;
if testerB=nil
then TestCasesStringGrid.Cells[i,j+1]:=''
else TestCasesStringGrid.Cells[i,j+1]:=intToStr(testerB^.tests[j].actuallyActive);
inc(i);
end;
TestCasesStringGrid.AutoSizeColumns;
end;
PROCEDURE TDuplicateRemovalDialog.showFor(CONST paletteEntryIndex: longint);
VAR prototypeA: P_visualBoard;
i,row:longint;
begin
if workspace.getWorkspacePalette^.paletteEntries[paletteEntryIndex].prototype=nil
then exit
else prototypeA:=workspace.getWorkspacePalette^.paletteEntries[paletteEntryIndex].prototype;
indexA:=paletteEntryIndex;
indexB:=-1;
new(testerA,createForAnalysis(prototypeA));
testerB:=nil;
candidateIndexes:=workspace.getWorkspacePalette^.findEntriesWithSameInterfaceAs(indexA);
CandidateStringGrid.rowCount:=length(candidateIndexes)+1;
row:=1;
for i in candidateIndexes do begin
CandidateStringGrid.Cells[0,row]:=
StringReplace(titleOf(workspace.getWorkspacePalette^.paletteEntries[i]),LineEnding,'\n',[rfReplaceAll]);
inc(row);
end;
DetailsMemoA.text:=workspace.getWorkspacePalette^.describeEntry(indexA);
lastUpdatedA:=maxLongint;
lastUpdatedB:=maxLongint;
Timer1.enabled:=true;
ShowModal;
Timer1.enabled:=false;
dispose(testerA,destroy);
testerA:=nil;
if testerB<>nil then begin
dispose(testerB,destroy);
testerB:=nil;
end;
end;
FINALIZATION
if myDuplicateRemovalDialog<>nil then FreeAndNil(myDuplicateRemovalDialog);
end.