-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathladdersymbol.pas
More file actions
1467 lines (1286 loc) · 37.6 KB
/
laddersymbol.pas
File metadata and controls
1467 lines (1286 loc) · 37.6 KB
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit LadderSymbol;
{$mode ObjFPC}{$H+}{$M+}
interface
uses
Classes, SysUtils,usimplegraph,graphics,forms,
doubleclickbit,doubleclickcompare,doubleclickstore,
doubleclickcomment,doubleclickmath,doubleclicktimer,
doubleclickflash,
stdctrls,
fgl;
type
TSymbol = class;
{ TSymbolList }
TSymbolList = class(specialize TFPGObjectList<TSymbol>)
constructor Create(aFreeObjects: Boolean);
end;
{ TAllias }
type TAllias = class(TEvsRectangularNode)
protected
fowner : TSymbol;
fposx : integer;
fposy : integer;
flastx : longint;
flasty : longint;
public
constructor create(graphe:TEvsSimpleGraph;sender:TSymbol); reintroduce;
procedure updatePosition(newx:longint;newy:longint);
end;
{ TConnexion }
type TConnexion = class(TEvsEllipticNode)
protected
ftype : string; // 'in' ou 'out'
fowner : TSymbol;
private
function GetPreviousLink() : TConnexion;
public
constructor create(graphe:TEvsSimpleGraph; sender:TSymbol; sens:string); reintroduce;
procedure updatePosition(newx:longint;newy:longint);
function isInput: boolean;
published
property previousLink: TConnexion read GetPreviousLink;
property symbolOwner : TSymbol read fowner;
end;
type TSymbol = class(TEvsRectangularNode)
protected
symbol : TEvsRectangularNode;
flastx : longint;
flasty : longint;
fallias : string;
finput : TConnexion;
foutput : TConnexion;
ftextAllias : TAllias;
fequation : string;
ffonction : string;
fcodeBefore : string;
fCodeAfter : string;
fhighlighted: boolean;
fBGcolor : TColor;
fvarList : TStringList;
fSaveBrushColor : longint;
public
constructor create(sender:TEvsSimpleGraph; inputExist, outputExist:boolean; fonctionName:string; symallias:string);
procedure updateAbsolutePosition(newx:longint;newy:longint);
procedure updatePosition(newx:longint;newy:longint);
function codeBefore:string; virtual; Abstract;
function codeAfter:string; virtual; Abstract;
procedure setCodeBefore(code:string);
procedure setCodeAfter(code:string);
procedure writeAllias(name:string);
function isTerminal:boolean; virtual; abstract;
function isVirtual:boolean; virtual; abstract;
function getVarList:TStringList; virtual; abstract;
procedure SetVar(list:TStringList); virtual; Abstract;
procedure SetVar(index:integer;name:string); virtual; Abstract;
procedure doubleClick(objet:TEvsGraphObject); virtual; abstract;
procedure highLight(state:boolean); virtual;
procedure highLightblue; virtual;
procedure unHighlight; virtual;
property allias:string read fallias write fallias;
property symbolInput:TConnexion read finput write finput;
property symbolOutput:TConnexion read foutput write foutput;
property textAllias:TAllias read ftextAllias write ftextAllias;
property fonction : string read ffonction;
property equation : string read fequation write fequation;
property highlighted : boolean read fhighlighted;
end;
type TPowerRail = class(TSymbol)
protected
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;symallias:string);
function codeBefore:string; override;
function codeAfter:string; override;
function isTerminal:boolean; override;
function isVirtual:boolean; override;
function getVarList: TStringList; override;
procedure doubleClick(objet:TEvsGraphObject); override;
end;
type TComment = class(TEvsRectangularNode)
protected
ffonction : string;
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;symallias:string);
procedure updatePosition(newx:longint;newy:longint);
function isTerminal:boolean;
function isVirtual:boolean;
function readText:string;
procedure setText(strtext:string);
procedure doubleClick(objet:TEvsGraphObject);
property allias:string read readText write setText;
end;
type TBit = class(TSymbol)
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;symallias:string);
function codeBefore:string; override;
function codeAfter:string; override;
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure doubleClick(objet:TEvsGraphObject); override;
procedure setEquation(equat:string);
function getVarList: TStringList; override;
procedure SetVar(list:TStringList); override;
procedure SetVar(index:integer;name:string); override;
procedure HighLight(state:boolean); override;
procedure highLightblue; override;
procedure unHighlight; override;
end;
type TCoil = class(TSymbol)
protected
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;symallias:string);
destructor destroy;
function codeBefore:string; override;
function codeAfter:string; override;
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure doubleClick(objet:TEvsGraphObject); override;
function getVarList: TStringList; override;
procedure SetVar(list:TStringList); override;
procedure SetVar(index:integer;name:string); override;
procedure HighLight(state:boolean); override;
procedure highLightblue; override;
procedure unHighLight; override;
end;
type TFrontCoil = class(TCoil)
protected
public
function codeBefore:string; override;
function codeAfter:string; override;
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure doubleClick(objet:TEvsGraphObject); override;
end;
type TStore = class(TSymbol)
protected
protected
fvar1 : string;
fvar2 : string;
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;var1:string;var2:string);
function codeBefore:string; override;
function codeAfter:string; override;
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure doubleClick(objet:TEvsGraphObject); override;
function getVarList: TStringList; override;
procedure SetVar(list:TStringList); override;
procedure SetVar(index:integer;name:string); override;
property var1:string read fvar1 write fvar1;
property var2:string read fvar2 write fvar2;
end;
type TVirtual = class(TSymbol)
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;symallias:string);
function codeBefore:string; override;
function codeAfter:string; override;
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure setEquation(equat:string);
end;
type TCompare = class(TSymbol)
protected
fvar1 : string;
fvar2 : string;
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;var1:string;var2:string);
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure setEquation(equat:string);
function getOperateur:string;
procedure doubleClick(objet:TEvsGraphObject); override;
function getVarList: TStringList; override;
procedure SetVar(list:TStringList); override;
procedure SetVar(index:integer;name:string); override;
property var1:string read fvar1 write fvar1;
property var2:string read fvar2 write fvar2;
end;
type TMath = class(TSymbol)
protected
fvar1 : string;
fvar2 : string;
fvar3 : string;
public
constructor create(sender:TEvsSimpleGraph;fonctionName:string;var1:string;var2:string;var3:string);
function isTerminal:boolean; override;
function isVirtual:boolean; override;
procedure setEquation(equat:string);
function getOperateur:string;
function codeBefore:string; override;
function codeAfter:string; override;
procedure doubleClick(objet:TEvsGraphObject); override;
function getVarList: TStringList; override;
procedure SetVar(list:TStringList); override;
procedure SetVar(index:integer;name:string); override;
property var1:string read fvar1 write fvar1;
property var2:string read fvar2 write fvar2;
property var3:string read fvar3 write fvar3;
end;
type TTimerObject = class(TSymbol)
protected
ftimerEnabled :boolean;
fpresetValue :word;
fcurrentValue :word;
fstate : boolean;
public
property currentValue:word read fcurrentValue;
property preset:word read fpresetValue write fpresetValue;
property state:boolean read fstate;
property timerEnabled:boolean read ftimerEnabled write ftimerEnabled;
constructor Create(sender:TEvsSimpleGraph;fonctionName,alliasValue:string;presetValue:word);
function isTerminal:boolean; override;
function isVirtual:boolean; override;
function codeBefore:string; override;
function codeAfter:string; override;
function getVarList: TStringList; override;
procedure doubleClick(objet:TEvsGraphObject); override;
procedure highLight(etat:boolean); override;
procedure unhighLight; override;
end;
type TTon = class(TTimerObject)
function codeAfter:string; override;
end;
type TToff = class(TTimerObject)
public
function codeAfter:string; override;
end;
type TFlash = class(TTimerObject)
protected
fpresetON : word;
fpresetOff : word;
public
constructor Create(sender:TEvsSimpleGraph;fonctionName,alliasValue:string;presetValueON,presetValueOFF:word);
function codeAfter:string; override;
property presetON:word read fpresetON write fpresetON;
property presetOFF:word read fpresetOFF write fpresetOFF;
procedure doubleClick(objet:TEvsGraphObject); override;
end;
implementation
uses main;
const
onColorR : byte=$AD;
onColorV : byte=$DF;
onColorB : byte=$9F;
offColorR : byte=$E1;
offColorV : byte=$7C;
offColorB : byte=$7C;
{ TSymbolList }
constructor TSymbolList.Create(aFreeObjects: Boolean);
begin
inherited Create(aFreeObjects);
end;
constructor TSymbol.create( sender:TEvsSimpleGraph;
inputExist,outputExist:boolean;
fonctionName:string;
symallias:string);
begin
Inherited create(sender);
sender.BeginUpdate;
with self do
begin
SetBounds(sender.ClientToGraph(0,0).x+17,sender.ClientToGraph(0,0).Y,75,50);
Font.Height:=10;
Margin:=0;
Alignment:=taLeftJustify;
Layout:=tlTop;
Pen.Style:=psClear;
brush.Color:=sender.Brush.Color;
fSaveBrushColor:=brush.color;
fBGcolor:=brush.color;
pen.Color:=sender.Brush.Color;
ffonction:=fonctionName;
if fonctionName<>'powerRail' then
begin
if symallias='' then text:=copy('??????',0,20)
else text:=copy(symallias,0,20);
end;
Options:=[goSelectable];
if fonctionName<>'' then
background.LoadFromFile(ExtractFilePath(paramstr(0))+'/images/'+fonctionName+'.png');
end;
flastx:=sender.ClientToGraph(0,0).x+17;
flasty:=sender.ClientToGraph(0,0).Y;
if inputExist then
SymbolInput:=TConnexion.create(sender,self,'input');
if outputExist then
SymbolOutput:=TConnexion.create(sender,self,'output');
if symallias='' then text:=copy('??????',0,20)
else text:=copy(symallias,0,20);
allias:=text;
textAllias:=TAllias.create(sender,self);
if fonctionName='powerRail' then textAllias.text:='';
//Hint:=textAllias.Text;
Hint:=allias;
fhighlighted:=false;
sender.EndUpdate;
end;
procedure TSymbol.updateAbsolutePosition(newx:longint;newy:longint);
begin
self.SetBounds(newx,newy,75,50);
if symbolInput<>nil then
SymbolInput.updatePosition(newx,newy);
if symbolOutput<>nil then
symbolOutput.updatePosition(newx,newy);
end;
procedure TSymbol.updatePosition(newx:longint;newy:longint);
begin
self.SetBounds(newx,newy,75,50);
if symbolInput<>nil then
SymbolInput.updatePosition(newx-flastx,newy-flasty);
if symbolOutput<>nil then
symbolOutput.updatePosition(newx-flastx,newy-flasty);
textAllias.updatePosition(newx-flastx,newy-flasty);
flastx:=newx;
flasty:=newy;
end;
procedure TSymbol.setCodeBefore(code:string);
begin
fcodeBefore:=code;
end;
procedure TSymbol.setCodeAfter(code:string);
begin
fCodeAfter:=code;
end;
procedure TSymbol.writeAllias(name:string);
begin
textAllias.Text:=name;
fallias:=name;
end;
procedure TSymbol.highLight(state:boolean);
begin
end;
procedure TSymbol.highLightblue;
begin
end;
procedure TSymbol.unHighlight;
begin
end;
function TConnexion.GetPreviousLink(): TConnexion;
begin
if LinkInputCount > 0 then
Result := Linkinputs[0].HookedObjectOf(0) as TConnexion
else
Result := nil;
end;
constructor TConnexion.create( graphe:TEvsSimpleGraph;
sender:TSymbol;
sens:string);
var
offsetx : integer;
offsety : integer;
begin
inherited create(graphe);
offsety:=17;
if sens='input' then
begin
offsetx:=0;
ftype:='in';
end
else
begin
offsetx:=92;
ftype:='out';
end;
with self do
begin
options:=[goLinkable];
SetBounds(graphe.ClientToGraph(0,0).x+offsetx,graphe.ClientToGraph(0,0).Y+offsety,16,16);
end;
fowner:=Tsymbol(sender);
end;
procedure TConnexion.updatePosition(newx: longint; newy: longint);
begin
self.moveby(newx,newy);
end;
function TConnexion.isInput: boolean;
begin
if ftype='in' then isInput:=true
else isInput:=false;
end;
constructor TAllias.create(graphe:TEvsSimpleGraph;sender:TSymbol);
var
offsety : integer;
recLeft : integer;
recTop : integer;
begin
inherited create(graphe);
offsety := 50;
with self do
begin
BeginUpdate;
Font.Height:=12;
Margin:=0;
Alignment:=taLeftJustify;
Pen.Style:=psSolid;
options:=[goShowCaption];
recLeft:=graphe.ClientToGraph(0,0).x-10;
recTop:=graphe.ClientToGraph(0,0).Y+offsety;
SetBounds(recLeft,recTop,140,20);
brush.Color:=graphe.Brush.Color;
pen.Color:=graphe.Brush.Color;
text:=sender.Text;
hint:=sender.text;
Alignment:=taLeftJustify;
Layout:=tlCenter;
fowner:=sender;
EndUpdate;
end;
end;
procedure TAllias.updatePosition(newx:longint;newy:longint);
begin
self.MoveBy(newx,newy);
end;
{ TPOWERRAIL }
constructor TPowerRail.create( sender:TEvsSimpleGraph;
fonctionName:string;
symallias:string);
begin
inherited create(sender,false,true,fonctionName,symallias);
ffonction:=fonctionName;
fallias:='pwr-'+inttostr(self.ID);
end;
function TPowerRail.codeBefore:string;
begin
result:='';
end;
function TPowerRail.codeAfter:string;
begin
result:='';
end;
function TPowerRail.isTerminal:boolean;
begin
result:=false;
end;
function TPowerRail.isVirtual:boolean;
begin
result:=false;
end;
procedure TPowerRail.doubleClick(objet:TEvsGraphObject);
begin
end;
function TPowerRail.getVarList: TStringList;
begin
result:=nil;
end;
{ /TPOWERRAIL }
{ TCOMMENT }
constructor TComment.create(sender:TEvsSimpleGraph;fonctionName:string;symallias:string);
begin
inherited create(sender);
self.Brush.Color:=sender.Brush.Color;
self.Pen.Color:=clBlack;
ffonction:=fonctionName;
with self do
begin
options:=[goSelectable,goShowCaption];
SetBounds(sender.ClientToGraph(0,0).x,sender.ClientToGraph(0,0).Y,100,50);
setText(symallias);
end;
end;
procedure TComment.updatePosition(newx:longint;newy:longint);
begin
self.moveby(newx,newy);
end;
function TComment.isTerminal:boolean;
begin
result:=false;
end;
function TComment.isVirtual:boolean;
begin
result:=false;
end;
function TComment.readText:string;
begin
result:=text;
end;
procedure Tcomment.setText(strtext:string);
begin
text:=strtext;
end;
procedure TComment.doubleClick(objet:TEvsGraphObject);
begin
commentForm.Left:=objet.BoundsRect.Left;
commentForm.Top:=objet.BoundsRect.top;
commentForm.symbole:=self;
commentForm.editComment.Text:=allias;
commentForm.BackgroundColorButton.Brush.Color:=
TEvsRectangularNode(self).Brush.Color;
commentForm.TextcolorButton.Font.Color:=
TEvsRectangularNode(self).Font.Color;
commentForm.show;
end;
{ /TCOMMENT }
{ TBIT }
constructor TBit.create( sender:TEvsSimpleGraph;
fonctionName:string;
symallias:string);
begin
inherited create(sender,true,true,fonctionName,symallias);
if symallias<>'' then allias:=symallias;
ffonction:=fonctionName;
case ffonction of
'contactNO' : begin
self.fCodeBefore:='';
self.fCodeAfter:='.state';
end;
'contactNC' : begin
self.fCodeBefore:='NOT(';
self.fCodeAfter:='.state)';
end;
end;
fequation:=codeBefore+allias+codeAfter;
fvarList:=TStringList.Create();
fvarList.Add(allias);
end;
function TBit.codeBefore:string;
begin
result:=fcodeBefore;
end;
function TBit.codeAfter:string;
begin
result:=fCodeAfter;
end;
function TBit.isTerminal:boolean;
begin
case ffonction of
'contactNO' : result:=false;
'contactNC' : result:=false;
end;
end;
function TBit.isVirtual:boolean;
begin
result:=false;
end;
procedure TBit.doubleClick(objet:TEvsGraphObject);
var
i : integer;
begin
bitForm.Left:=objet.BoundsRect.Left;
bitForm.Top:=objet.BoundsRect.top;
bitform.symbole:=self;
// varList in listBox
bitForm.contactListBox.Clear;
for i:=0 to varList.Count-1 do
if varList.Items[i].typeVar='BIT' then
bitForm.contactListBox.items.Add(varList.Items[i].nameVar);
// IOPLClist in listBox
for i:=0 to ioPlcList.Count-1 do
if (ioPlcList.Items[i].typeVar='INPUT') or
(ioPlcList.Items[i].typeVar='OUTPUT') then
bitForm.contactListBox.items.Add(ioPlcList.Items[i].nameVar);
// timerlist in listBox
for i:=0 to timerList.Count-1 do
bitForm.contactListBox.items.Add(timerList.Items[i].nameVar);
bitForm.contactListBox.Sorted:=true;
bitForm.nameField.text:=self.fallias;
bitForm.nameField.SelectAll;
if bitForm.CheckBoxSystemBit.checked then
for i:=1 to Form1.SystemGrid.RowCount-1 do
if form1.SystemGrid.Cells[0,i]<>'' then
begin
if form1.SystemGrid.Cells[1,i]='BIT' then
begin
bitform.contactListBox.Items.Add(form1.SystemGrid.Cells[0,i]);
end;
end;
bitForm.Caption:='Select Contact';
bitForm.show;
end;
procedure TBit.setEquation(equat:string);
begin
fequation:=equat;
end;
function TBit.getVarList: TStringList;
begin
fvarList.Clear;
fvarList.Add(allias);
result:=fvarList;
end;
procedure TBit.SetVar(list:TStringList);
begin
allias:=list[0];
Text:=list[0];
textAllias.Text:=list[0];
end;
procedure TBit.SetVar(index:integer;name:string);
begin
allias:=name;
Text:=name;
textAllias.Text:=name;
end;
procedure TBit.HighLight(state:boolean);
begin
case ffonction of
'contactNO' : begin
if state then
Brush.Color:=RGBToColor(onColorR,onColorV,onColorB)
else Brush.Color:=RGBToColor(offColorR,offColorV,offColorB);
end;
'contactNC' : begin
if state then
Brush.Color:=RGBToColor(offColorR,offColorV,offColorB)
else Brush.Color:=RGBToColor(onColorR,onColorV,onColorB);
end;
end;
fhighlighted:=true;
end;
procedure TBit.highLightblue;
begin
Brush.Color:=clSkyBlue;
fhighlighted:=true;
end;
procedure TBit.unHighlight;
begin
Brush.Color:=fSaveBrushColor;
end;
{ /TBIT }
{ TCOIL }
constructor Tcoil.create( sender:TEvsSimpleGraph;
fonctionName:string;
symallias:string);
begin
inherited create(sender,true,false,fonctionName,symallias);
if symallias<>'' then allias:=symallias;
ffonction:=fonctionName;
fvarList:=TStringList.Create();
fvarList.Add(allias);
end;
destructor Tcoil.destroy;
begin
inherited;
finput.Delete;
ftextAllias.delete;
end;
function Tcoil.codeBefore:string;
begin
case ffonction of
'coilNO' : result:=fallias+'.state:=(';
'coilSET' : result:='if ';
'coilRESET' : result:='if ';
end;
end;
function Tcoil.codeAfter:string;
begin
case ffonction of
'coilNO' : result:=');';
'coilSET' : result:=' then '+fallias+'.setState;';
'coilRESET' : result:=' then '+fallias+'.resetState;';
end;
end;
function Tcoil.isTerminal:boolean;
begin
case ffonction of
'coilNO' : result:=true;
'coilSET' : result:=true;
'coilRESET' : result:=true;
end;
end;
function Tcoil.isVirtual:boolean;
begin
result:=false;
end;
procedure Tcoil.doubleClick(objet:TEvsGraphObject);
var
i : integer;
begin
bitForm.Left:=objet.BoundsRect.Left;
bitForm.Top:=objet.BoundsRect.top;
bitform.symbole:=self;
// afficher la liste des variables dans la listBox
bitForm.contactListBox.Clear;
for i:=0 to varList.Count-1 do
if varList.Items[i].typeVar='BIT' then
bitForm.contactListBox.items.Add(varList.Items[i].nameVar);
// ajouter la liste des IOPLC dans la listBox
for i:=0 to ioPlcList.Count-1 do
if ioPlcList.Items[i].typeVar='OUTPUT' then
bitForm.contactListBox.items.Add(ioPlcList.Items[i].nameVar);
bitForm.contactListBox.Sorted:=true;
bitForm.nameField.text:=self.fallias;
bitForm.Caption:='Select Coil';
bitForm.show;
end;
function TCoil.getVarList: TStringList;
begin
fvarList.Clear;
fvarList.add(allias);
result:=fvarList;
end;
procedure TCoil.SetVar(list:TStringList);
begin
allias:=list[0];
Text:=list[0];
textAllias.Text:=list[0];
end;
procedure TCoil.SetVar(index:integer;name:string);
begin
allias:=name;
Text:=name;
textAllias.Text:=name;
end;
procedure TCoil.HighLight(state:boolean);
begin
case ffonction of
'coilNO' : begin
if state then
Brush.Color:=RGBToColor(onColorR,onColorV,onColorB)
else Brush.Color:=fSaveBrushColor;
end;
'coilSET' : begin
if state then
Brush.Color:=RGBToColor(onColorR,onColorV,onColorB)
else Brush.Color:=fSaveBrushColor;
end;
'coilRESET' : begin
if state then
Brush.Color:=RGBToColor(onColorR,onColorV,onColorB)
else Brush.Color:=fSaveBrushColor;
end;
end;
fhighlighted:=true;
end;
procedure TCoil.highLightblue;
begin
brush.Color:=clSkyBlue;
fhighlighted:=true;
end;
procedure TCoil.unHighlight;
begin
Brush.Color:=fSaveBrushColor;
end;
{ /TCOIL }
{ TCoilFront }
function TFrontCoil.codeBefore:string;
begin
case ffonction of
'BobineP' : result:='if ';
'BobineN' : result:='if not ';
end;
end;
function TFrontcoil.codeAfter:string;
begin
case ffonction of
'BobineP' : result:=' then begin if not ('+fallias+'.OldState) then begin '+fallias+'.NumScan:=CurrScan+1; end; end '+#10+
'else begin if '+fallias+'.OldState then '+fallias+'.OldState:=false; end;';
'BobineN' : result:=' then begin if not ('+fallias+'.OldState) then begin '+fallias+'.NumScan:=CurrScan+1; end; end '+#10+
'else begin if ('+fallias+'.OldState) then '+fallias+'.OldState:=false; end;';
end;
end;
function TFrontCoil.isTerminal:boolean;
begin
result:=true;
end;
function TFrontCoil.isVirtual:boolean;
begin
result:=false;
end;
procedure TFrontcoil.doubleClick(objet:TEvsGraphObject);
var
i : integer;
begin
bitForm.Left:=objet.BoundsRect.Left;
bitForm.Top:=objet.BoundsRect.top;
bitform.symbole:=self;
// afficher la liste des variables dans la listBox
bitForm.contactListBox.Clear;
for i:=0 to varList.Count-1 do
if (varList.Items[i].typeVar='BIT') or
(varList.Items[i].typeVar='PULSE') then
bitForm.contactListBox.items.Add(varList.Items[i].nameVar);
// ajouter la liste des IOPLC dans la listBox
for i:=0 to ioPlcList.Count-1 do
if ioPlcList.Items[i].typeVar='OUTPUT' then
bitForm.contactListBox.items.Add(ioPlcList.Items[i].nameVar);
bitForm.contactListBox.Sorted:=true;
bitForm.nameField.text:=self.fallias;
bitForm.Caption:='Select Coil';
bitForm.show;
end;
{ TCoilFront }
{ TStore }
constructor TStore.create( sender:TEvsSimpleGraph;
fonctionName:string;
var1:string;
var2:string);
var
alliasValue : string;
begin
alliasValue:=var2+':='+var1;
inherited create(sender,true,false,fonctionName,alliasValue);
ffonction:=fonctionName;
fvar1:=var1;
fvar2:=var2;
fequation:='('+fvar2+':='+fvar1+')';
fvarList:=TStringList.Create();
fvarList.Add(fvar1);
fvarList.Add(fvar2);
end;
function TStore.codeBefore:string;
begin
result:='if ';
end;
function TStore.codeAfter:string;
begin
result:=' then '+fvar2+':='+fvar1+';';
end;
function TStore.isTerminal:boolean;
begin
result:=true;
end;
function TStore.isVirtual:boolean;
begin
result:=false;
end;
procedure TStore.doubleClick(objet:TEvsGraphObject);
var
i : integer;
selectedVar : integer;
begin
storeForm.Left:=objet.BoundsRect.Left;
storeForm.Top:=objet.BoundsRect.top;
storeForm.fsymbole:=self;
// Variable List
storeForm.ComboBoxVar1.Clear;
storeForm.ComboBoxVar2.Clear;
for i:=0 to varList.Count-1 do
if varList.Items[i].typeVar<>'Bit' then
begin
storeForm.ComboBoxVar1.Items.Add(varList.Items[i].nameVar);
storeForm.ComboBoxVar2.Items.Add(varList.Items[i].nameVar);
end;
if storeForm.CheckBoxSystemVar.checked then
begin
for i:=1 to form1.SystemGrid.RowCount-1 do
if (form1.SystemGrid.Cells[1,i]<>'BIT') and
(form1.SystemGrid.Cells[0,i]<>'') then
begin
storeForm.ComboBoxVar1.Items.Add(form1.SystemGrid.Cells[0,i]);
storeForm.ComboBoxVar2.Items.Add(form1.SystemGrid.Cells[0,i]);
end;
end;
storeForm.ComboBoxVar1.Sorted:=true;
storeForm.ComboBoxVar2.Sorted:=true;
// select Var and test if is a variable
selectedVar:=storeForm.ComboBoxVar1.Items.IndexOf(Tstore(objet).Var1);
if (selectedVar=-1) then
begin
if TStore(objet).var1='' then storeForm.ComboBoxVar1.ItemIndex:=0
else storeForm.ComboBoxVar1.Text:=var1;
end
else storeForm.ComboBoxVar1.ItemIndex:=selectedVar;
storeForm.ComboBoxVar2.ItemIndex:=storeForm.ComboBoxVar2.Items.IndexOf(var2);
storeForm.show;
end;
function TStore.getVarList: TStringList;
begin
fvarList.clear;
fvarList.Add(var1);
fvarList.Add(var2);
result:=fvarList;