-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.pas
More file actions
2481 lines (2226 loc) · 74.6 KB
/
main.pas
File metadata and controls
2481 lines (2226 loc) · 74.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 Main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, usimplegraph,
ExtCtrls, StdCtrls, Buttons, Menus, LadderGraphUnit, LadderSymbol,
Types, LCLType, ActnList, Grids,projectunit,
unitnewprojectform, xmlunit,lad2Pas,fgl,VariableUnit,LazFileUtils,
Generics.Collections,simulatorUnit,character,unitAboutForm;
type
{ TLadderGraphList }
TLadderGraphList = class(specialize TFPGObjectList<TLadderGraph>)
constructor Create(aFreeObjects: Boolean);
end;
{ TIOList }
TIOList = class(specialize TFPGObjectList<TIOPlc>)
constructor Create(aFreeObjects: Boolean);
end;
{ TVarList }
TVarList = class(specialize TFPGObjectList<TVariable>)
constructor Create(aFreeObjects: Boolean);
end;
{ TSystemList }
TSystemList = specialize TDictionary<string,string>;
{ TTimerList }
TTimerList = class(specialize TFPGObjectList<TTimerVar>)
constructor Create(aFreeObjects: Boolean);
end;
type
{ TForm1 }
TForm1 = class(TForm)
addButton: TSpeedButton;
coilFrontPbutton: TSpeedButton;
coilFrontNbutton: TSpeedButton;
divButton: TSpeedButton;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
itemFindRef: TMenuItem;
LabelMult1: TLabel;
LabelMult2: TLabel;
LabelMult3: TLabel;
aboutItem: TMenuItem;
MenuItemSymbolToDataWatch: TMenuItem;
MenuItemSetValue: TMenuItem;
MenuItemRemoveVar: TMenuItem;
MenuItemStartSim: TMenuItem;
MenuItemStopSim: TMenuItem;
MenuItemRemove: TMenuItem;
MenuItemMoveUp: TMenuItem;
MenuItemMoveDown: TMenuItem;
MenuItemSetOn: TMenuItem;
MenuItemPulseOff: TMenuItem;
MenuItemPulseOn: TMenuItem;
MenuItemSetOff: TMenuItem;
MenuItemAddToDataWatch: TMenuItem;
MenuItemStart: TMenuItem;
MenuItemStop: TMenuItem;
multButton: TSpeedButton;
LabelDiv: TLabel;
LabelMult: TLabel;
PopupMenuDataWatchBit: TPopupMenu;
PopupMenuCrossRef: TPopupMenu;
dataWatchGrid: TStringGrid;
compileIndicator: TShape;
TimerGrid: TStringGrid;
TabSheetTimer: TTabSheet;
FlashButton: TSpeedButton;
TimerOnButton: TSpeedButton;
simulatorRunIndicator: TShape;
subButton: TSpeedButton;
itemCopySymbol: TMenuItem;
itemPasteSymbol: TMenuItem;
itemPaste: TMenuItem;
itemCopy: TMenuItem;
itemSimulate: TMenuItem;
LabelAdd: TLabel;
LabelSub: TLabel;
retractVarButton: TShape;
expandVarButton: TShape;
crossRefGrid: TStringGrid;
TabSheetTime: TTabSheet;
TabSheetDataWatch: TTabSheet;
TabSheetMath: TTabSheet;
TabSheetCrossRef: TTabSheet;
TimerOffButton: TSpeedButton;
TimerPulse: TTimer;
TimerSimulator: TTimer;
TimerIOplcGrid: TTimer;
TimerVarGrid: TTimer;
// Variables
VariablesPageControl: TPageControl;
titreVariables: TShape;
LabelTitreVariables: TLabel;
tabSheetSystem: TTabSheet;
SystemGrid: TStringGrid;
TabSheetVar: TTabSheet;
VARGrid: TStringGrid;
TabSheetIO: TTabSheet;
IOplcGrid: TStringGrid;
// main menu
MainMenu: TMainMenu;
ItelmProject: TMenuItem;
itemNew: TMenuItem;
itemOpen: TMenuItem;
itemSave: TMenuItem;
itemSaveAs: TMenuItem;
itemExit: TMenuItem;
itemPLC: TMenuItem;
itemCompile: TMenuItem;
// popup menu
PopupMenuGraphe: TPopupMenu;
itemAddCommentOnGraph: TMenuItem;
PopupLadderTabSheet: TPopupMenu;
itemLadderClose: TMenuItem;
PopupTitreBlock: TPopupMenu;
itemAddBlock: TMenuItem;
PopupBlock: TPopupMenu;
itemOpenBlock: TMenuItem;
itemRenameBlock: TMenuItem;
PopupMenuSymbole: TPopupMenu;
itemDeleteSymbol: TMenuItem;
// Symbols
contactTools: TPageControl;
// Basic
tabsheetBasic: TTabSheet;
powerRail: TSpeedButton;
contactNObutton: TSpeedButton;
contactNCbutton: TSpeedButton;
coilNObutton: TSpeedButton;
coilSETbutton: TSpeedButton;
coilRESETbutton: TSpeedButton;
CommentButton: TButton;
CommentLabel: TLabel;
// Compare
TabSheetCompare: TTabSheet;
equalsButton: TSpeedButton;
LabelEquals: TLabel;
notEqualsButton: TSpeedButton;
LabelnotEquals: TLabel;
greaterButton: TSpeedButton;
greaterLabel: TLabel;
greaterEqualsButton: TSpeedButton;
greaterEqualsLabel: TLabel;
lesserButton: TSpeedButton;
lesserLabel: TLabel;
lesserEqualsButton: TSpeedButton;
lesserEqualsLabel: TLabel;
// Store
TabSheetStore: TTabSheet;
storeButton: TSpeedButton;
storeLabel: TLabel;
// Graphe
ladderSurface: TPageControl;
titreProjectTree: TShape;
LabelTitreProjectTree: TLabel;
projectTree: TTreeView;
// trait de separation projet/ladder
traitProjectTree: TShape;
traitHorizontalHaut: TShape;
// Graphe events
procedure addButtonClick(Sender: TObject);
procedure coilFrontNbuttonClick(Sender: TObject);
procedure coilFrontPbuttonClick(Sender: TObject);
procedure crossRefGridDblClick(Sender: TObject);
procedure dataWatchGridContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure dataWatchGridPrepareCanvas(Sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
procedure divButtonClick(Sender: TObject);
procedure FlashButtonClick(Sender: TObject);
procedure IOplcGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure aboutItemClick(Sender: TObject);
procedure MenuItemMoveDownClick(Sender: TObject);
procedure MenuItemMoveUpClick(Sender: TObject);
procedure MenuItemPulseOnClick(Sender: TObject);
procedure MenuItemRemoveClick(Sender: TObject);
procedure MenuItemRemoveVarClick(Sender: TObject);
procedure MenuItemSetOffClick(Sender: TObject);
procedure MenuItemSetOnClick(Sender: TObject);
procedure MenuItemSetValueClick(Sender: TObject);
procedure MenuItemStartSimClick(Sender: TObject);
procedure MenuItemStopSimClick(Sender: TObject);
procedure MenuItemSymbolToDataWatchClick(Sender: TObject);
// Vartabsheet buttons
procedure reDimVarTabSheetLarge;
procedure reDimVarTabSheetSmall;
procedure expandVarButtonClick(Sender: TObject);
procedure retractVarButtonClick(Sender: TObject);
procedure CommentButtonClick(Sender: TObject);
procedure equalsButtonClick(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure greaterButtonClick(Sender: TObject);
procedure greaterEqualsButtonClick(Sender: TObject);
procedure IOplcGridContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure IOplcGridDblClick(Sender: TObject);
procedure IOplcGridEditingDone(Sender: TObject);
procedure IOplcGridHeaderClick(Sender: TObject; IsColumn: Boolean;
Index: Integer);
procedure itemCompileClick(Sender: TObject);
procedure itemCopySymbolClick(Sender: TObject);
procedure itemDeleteSymbolClick(Sender: TObject);
procedure itemExitClick(Sender: TObject);
procedure itemFindRefClick(Sender: TObject);
procedure itemLadderCloseClick(Sender: TObject);
procedure itemNewClick(Sender: TObject);
procedure itemOpenClick(Sender: TObject);
procedure itemPasteSymbolClick(Sender: TObject);
procedure itemSaveAsClick(Sender: TObject);
procedure itemSaveClick(Sender: TObject);
procedure itemSimulateClick(Sender: TObject);
procedure ladderSurfaceChange(Sender: TObject);
procedure ladderSurfaceCloseTabClicked(Sender: TObject);
procedure ladderSurfaceContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure lesserButtonClick(Sender: TObject);
procedure lesserEqualsButtonClick(Sender: TObject);
procedure itemAddCommentOnGraphClick(Sender: TObject);
procedure MenuItemAddToDataWatchClick(Sender: TObject);
procedure MenuItemStartClick(Sender: TObject);
procedure MenuItemStopClick(Sender: TObject);
procedure multButtonClick(Sender: TObject);
procedure notEqualsButtonClick(Sender: TObject);
// ProjectTree events
function getStringFromLevel(treePath:string;level:integer):string;
function getLevelFromString(treePath:string;levelString:string):integer;
procedure projectTreeContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure itemAddBlockClick(Sender: TObject);
procedure itemOpenBlockClick(Sender: TObject);
procedure itemRenameBlockClick(Sender: TObject);
procedure projectTreeEditingEnd(Sender: TObject; Node: TTreeNode;
Cancel: Boolean);
procedure coilNObuttonClick(Sender: TObject);
procedure coilRESETbuttonClick(Sender: TObject);
procedure coilSETbuttonClick(Sender: TObject);
procedure contactNCbuttonClick(Sender: TObject);
procedure contactNObuttonClick(Sender: TObject);
procedure powerRailClick(Sender: TObject);
procedure storeButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure saveClick(Sender: TObject);
procedure subButtonClick(Sender: TObject);
procedure SystemGridContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure SystemGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure SystemGridHeaderClick(Sender: TObject; IsColumn: Boolean;
Index: Integer);
procedure TimerIOplcGridTimer(Sender: TObject);
procedure TimerOffButtonClick(Sender: TObject);
procedure TimerOnButtonClick(Sender: TObject);
procedure TimerPulseTimer(Sender: TObject);
procedure TimerSimulatorTimer(Sender: TObject);
procedure TimerVarGridTimer(Sender: TObject);
procedure traitProjectTreeMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure traitProjectTreeMouseEnter(Sender: TObject);
procedure traitProjectTreeMouseLeave(Sender: TObject);
procedure traitProjectTreeMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure traitProjectTreeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure error(message:string);
procedure addNewBloc( blocName : string );
procedure openBlock(blocName:string);
procedure traitVariablesMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure traitVariablesMouseEnter(Sender: TObject);
procedure traitVariablesMouseLeave(Sender: TObject);
procedure traitVariablesMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure traitVariablesMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure VARGridContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure VARGridDblClick(Sender: TObject);
procedure VARGridDrawCell(Sender: TObject; aCol, aRow: Integer;
aRect: TRect; aState: TGridDrawState);
procedure VARGridEditingDone(Sender: TObject);
procedure VARGridHeaderClick(Sender: TObject; IsColumn: Boolean;
Index: Integer);
procedure VariablesPageControlChange(Sender: TObject);
{ UTILITY }
procedure lockMenu;
procedure unLockMenu;
private
public
traitProjectTreeSelected : boolean;
traitProjectTreeMouseSelected : boolean;
traitVariablesSelected : boolean;
traitVariablesMouseselected : boolean;
columnGPIO : TGridColumn;
columnTypeGPIO : TGridColumn;
projectName : string;
projectPath : string;
projectPLC : string;
selectedTreeStr : string;
VarCol,VarRow : integer;
IOPlcCol,IOPlcRow : integer;
// form project new
askForNew : boolean;
projectCurrent : TProject;
// project functions
procedure newProject;
end;
const
widthTabVar=122;
var
Form1 : TForm1;
ladderGraphList : TLadderGraphList;
ioPlcList : TIOList;
varList : TVarList;
systemVarList : TSystemList;
timerList : TTimerList;
crossRefList : TSymbolList;
blocCrossRefList : TStringList;
classCrossRefList: TStringList;
copiedSymbolList : TSymbolList;
grapheCurrent : TLadderGraph;
OldNodeName : string;
copieGraphe : TLadderGraph;
ladToPass : TladToPas;
popUpOrigin : TTreeNode;
oldBlocName : string;
currentEditedCol : integer=-1;
currentEditedRow : integer=-1;
columnVar : TGridColumn;
offsetIOGrid : Integer;
FirstScanIOGrid : boolean;
clipboardFull : boolean;
// simulator
simulator : TSimulator;
dataWatchVarSelected : string;
dataWatchInstruction : string='';
graphError : boolean;
implementation
{$R *.lfm}
{ TLadderGraphList }
constructor TLadderGraphList.Create(aFreeObjects: Boolean);
begin
inherited Create(aFreeObjects);
end;
{ TIOPlc }
constructor TIOList.Create(aFreeObjects: Boolean);
begin
inherited Create(aFreeObjects);
end;
{ TVariable }
constructor TVarList.Create(aFreeObjects: Boolean);
begin
inherited Create(aFreeObjects);
end;
{ TTimerVar }
constructor TTimerList.Create(aFreeObjects: Boolean);
begin
inherited Create(aFreeObjects);
end;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
inherited;
ladderGraphList:=TladderGraphList.Create(false);
{ IO PLC List and Combobox }
ioPlcList:=TIOList.Create(false);
columnTypeGPIO:=IOplcGrid.Columns[2];
columnTypeGPIO.ButtonStyle:=cbsPickList;
columnTypeGPIO.PickList.Clear;
columnTypeGPIO.PickList.Add('INPUT');
columnTypeGPIO.PickList.Add('OUTPUT');
columnTypeGPIO.PickList.Add('ANALOG');
{ Var List and Combobox }
varList:=TVarList.Create(false);
varList.clear;
columnVar:=VARGrid.Columns[1];
columnVar.ButtonStyle:=cbsPickList;
columnVar.PickList.Clear;
columnVar.PickList.Add('BIT');
columnVar.PickList.Add('PULSE');
columnVar.PickList.Add('INT');
columnVar.PickList.Add('DINT');
columnVar.PickList.Add('WORD');
columnVar.PickList.Add('DWORD');
{ system Var List }
systemVarList:=TSystemList.create;
{ timer list }
timerList:=TTimerList.create(false);
{ cross ref List }
crossRefList:=TSymbolList.Create(false);
blocCrossRefList:=TStringList.Create;
classCrossRefList:=TStringList.Create;
//offsetIOGrid:=80;
FirstScanIOGrid:=true;
// defaut grid selected
VariablesPageControl.ActivePage:=VariablesPageControl.Pages[0];
VariablesPageControl.Tag:=0;
retractVarButton.Tag:=1;
reDimVarTabSheetSmall;
IOplcGrid.Options:=[goFixedHorzLine,goFixedVertLine,goHorzLine,goVertLine];
VARGrid.Options:=[goFixedHorzLine,goFixedVertLine,goHorzLine,goVertLine];
compileIndicator.Brush.Color:=clRed;
form1.simulatorRunIndicator.Brush.Color:=clRed;
end;
procedure TForm1.saveClick(Sender: TObject);
begin
projectCurrent.saveProject;
end;
{ move manager PROJECTTREE}
procedure TForm1.traitProjectTreeMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
traitProjectTreeMouseselected:=true;
end;
procedure TForm1.traitProjectTreeMouseEnter(Sender: TObject);
begin
traitProjectTree.Cursor:=crSizeWE;
traitProjectTreeSelected:=true;
end;
procedure TForm1.traitProjectTreeMouseLeave(Sender: TObject);
begin
traitProjectTree.Cursor:=crDefault;
traitProjectTreeSelected:=false;
end;
procedure TForm1.traitProjectTreeMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if traitProjectTreeSelected and traitProjectTreeMouseSelected then
begin
projectTree.Width:=mouse.CursorPos.x;
if grapheCurrent<>nil then
begin
ladderSurface.Width:=form1.width-projectTree.Width-VariablesPageControl.Width ;
grapheCurrent.expandGraphOnPanel;
end;
Application.ProcessMessages;
end;
end;
procedure TForm1.traitProjectTreeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
traitProjectTreeMouseSelected:=false;
end;
{ move manager VARIABLES}
procedure TForm1.traitVariablesMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//traitVariablesMouseselected:=true;
end;
procedure TForm1.traitVariablesMouseEnter(Sender: TObject);
begin
//traitVariables.Cursor:=crSizeWE;
//traitVariablesselected:=true;
end;
procedure TForm1.traitVariablesMouseLeave(Sender: TObject);
begin
//traitVariables.Cursor:=crDefault;
//traitVariablesselected:=false;
end;
procedure TForm1.traitVariablesMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
GridWidth : integer;
begin
{
if TabSheetIO.Focused then
GridWidth:= IOplcGrid.ColWidths[0]+
IOplcGrid.ColWidths[1]+
IOplcGrid.ColWidths[2]+
IOplcGrid.ColWidths[3];
if TabSheetVar.Focused then
GridWidth:= VARGrid.ColWidths[0]+
VARGrid.ColWidths[1]+
VARGrid.ColWidths[2];
if tabSheetSystem.Focused then
GridWidth:= SystemGrid.ColWidths[0]+
SystemGrid.ColWidths[1]+
SystemGrid.ColWidths[2];
if TabSheetCrossRef.Focused then
GridWidth:= crossRefGrid.ColWidths[0]+
crossRefGrid.ColWidths[1]+
crossRefGrid.ColWidths[2];
if TabSheetCrossRef.showing then
begin
GridWidth:= crossRefGrid.ColWidths[0]+
crossRefGrid.ColWidths[1];
end;
if traitVariablesSelected and traitVariablesMouseselected then
if (VariablesPageControl.width<=GridWidth) or
(form1.width-mouse.CursorPos.x<GridWidth) then
if mouse.CursorPos.x<form1.Width-18 then
begin
traitVariables.Left:=mouse.CursorPos.x;
ladderSurface.Width:=mouse.CursorPos.x-projectTree.width ;
if grapheCurrent<>nil then
grapheCurrent.expandGraphOnPanel;
// state of expand and retract Buttons
expandVarButton.Tag:=0;
retractVarButton.Tag:=0;
Application.ProcessMessages;
end;
}
end;
procedure TForm1.traitVariablesMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
//traitVariablesMouseselected:=false;
end;
procedure TForm1.reDimVarTabSheetLarge;
var
GridWidth : integer;
begin
if VariablesPageControl.ActivePage.Caption='IO PLC' then
begin
GridWidth:= IOplcGrid.ColWidths[0]+
IOplcGrid.ColWidths[1]+
IOplcGrid.ColWidths[2]+
IOplcGrid.ColWidths[3];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='Variable' then
begin
GridWidth:= VARGrid.ColWidths[0]+
VARGrid.ColWidths[1]+
VARGrid.ColWidths[2];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='System' then
begin
GridWidth:= SystemGrid.ColWidths[0]+
SystemGrid.ColWidths[1]+
SystemGrid.ColWidths[2];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='TMR/CNT' then
begin
GridWidth:= TimerGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='CrossRef' then
begin
GridWidth:= crossRefGrid.ColWidths[0]+
crossRefGrid.ColWidths[1]+
crossRefGrid.ColWidths[2];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='Data Watch' then
begin
GridWidth:= dataWatchGrid.ColWidths[0]+
dataWatchGrid.ColWidths[1];
GridWidth:=GridWidth+widthTabVar;
end;
VariablesPageControl.Width:=GridWidth;
//traitVariables.left:=form1.Width-GridWidth;
if grapheCurrent<>nil then
grapheCurrent.expandGraphOnPanel;
end;
procedure TForm1.reDimVarTabSheetSmall;
var
GridWidth : integer;
begin
if VariablesPageControl.ActivePage.Caption='IO PLC' then
begin
GridWidth:= IOplcGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='Variable' then
begin
GridWidth:= VARGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='System' then
begin
GridWidth:= SystemGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='TMR/CNT' then
begin
GridWidth:= TimerGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='CrossRef' then
begin
GridWidth:= crossRefGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
if VariablesPageControl.ActivePage.Caption='Data Watch' then
begin
GridWidth:= dataWatchGrid.ColWidths[0];
GridWidth:=GridWidth+widthTabVar;
end;
VariablesPageControl.Width:=GridWidth;
//traitVariables.left:=form1.Width-GridWidth;
if grapheCurrent<>nil then
grapheCurrent.expandGraphOnPanel;
end;
procedure TForm1.expandVarButtonClick(Sender: TObject);
begin
reDimVarTabSheetLarge;
Application.ProcessMessages;
// store last action on button
expandVarButton.Tag:=1;
retractVarButton.Tag:=0;
end;
procedure TForm1.retractVarButtonClick(Sender: TObject);
begin
reDimVarTabSheetSmall;
Application.ProcessMessages;
// store last action on button
expandVarButton.Tag:=0;
retractVarButton.Tag:=1;
grapheCurrent.expandGraphOnPanel;
end;
{ SYMBOL EVENT }
procedure TForm1.contactNObuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TBit.create(grapheCurrent,'contactNO','????????');
end;
end;
procedure TForm1.contactNCbuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TBit.create(grapheCurrent,'contactNC','');
end;
end;
procedure TForm1.coilNObuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCoil.create(grapheCurrent,'coilNO','');
end;
end;
procedure TForm1.coilSETbuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCoil.create(grapheCurrent,'coilSET','');
end;
end;
procedure TForm1.coilRESETbuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCoil.create(grapheCurrent,'coilRESET','');
end;
end;
procedure TForm1.CommentButtonClick(Sender: TObject);
begin
itemAddCommentOnGraphClick(self);
end;
procedure TForm1.coilFrontPbuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TFrontCoil.create(grapheCurrent,'BobineP','');
end;
end;
procedure TForm1.coilFrontNbuttonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TFrontCoil.create(grapheCurrent,'BobineN','');
end;
end;
procedure TForm1.powerRailClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TpowerRail.create(grapheCurrent,'powerRail','');
end;
end;
procedure TForm1.equalsButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCompare.create(grapheCurrent,'equals','?????','?????');
end;
end;
procedure TForm1.notEqualsButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCompare.create(grapheCurrent,'notequals','?????','?????');
end;
end;
procedure TForm1.greaterButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCompare.create(grapheCurrent,'greater','?????','?????');
end;
end;
procedure TForm1.greaterEqualsButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCompare.create(grapheCurrent,'greaterOrEquals','?????','?????');
end;
end;
procedure TForm1.lesserButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCompare.create(grapheCurrent,'less','?????','?????');
end;
end;
procedure TForm1.lesserEqualsButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TCompare.create(grapheCurrent,'lessOrEquals','?????','?????');
end;
end;
procedure TForm1.storeButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TStore.create(grapheCurrent,'store','?????','?????');
end;
end;
{ MATH SYMBOL }
procedure TForm1.addButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TMath.create(grapheCurrent,'add','?????','?????','?????');
end;
end;
procedure TForm1.subButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TMath.create(grapheCurrent,'sub','?????','?????','?????');
end;
end;
procedure TForm1.divButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TMath.create(grapheCurrent,'div','?????','?????','?????');
end;
end;
procedure TForm1.multButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TMath.create(grapheCurrent,'mult','?????','?????','?????');
end;
end;
{ /MATH SYMBOL }
{ TIMER SYMBOL }
procedure TForm1.TimerOnButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TTOn.create(grapheCurrent,'Ton','?????',100);
end;
end;
procedure TForm1.TimerOffButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TToff.create(grapheCurrent,'Toff','?????',100);
end;
end;
procedure TForm1.FlashButtonClick(Sender: TObject);
begin
if ladderGraphList.Count>0 then
begin
grapheCurrent:=TLadderGraph(ladderGraphList[ladderSurface.ActivePage.TabIndex]);
TFlash.create(grapheCurrent,'TFlash','?????',30,30);
end;
end;
{ /TIMER SYMBOL }
// Project Tree Events
function TForm1.getStringFromLevel(treePath:string;level:integer):string;
var
i : integer;
pathElement : string;
begin
i:=0;
repeat
pathElement:=copy(treePath,0,pos('/',treePath)-1);
if i=level then
begin
result:=pathElement;
exit;
end;
treePath:=copy(treePath,pos('/',treePath)+1,length(treePath));
i:=i+1;
until pos('/',treePath)=0;
if i=level then result:=treePath
else result:='';
end;
function TForm1.getLevelFromString(treePath:string;levelString:string):integer;
var
i : integer;
pathElement : string;
begin
i:=0;
repeat
pathElement:=copy(treePath,0,pos('/',treePath)-1);
if pathElement=levelString then
begin
result:=i;
exit;
end;
treePath:=copy(treePath,pos('/',treePath)+1,length(treePath));
i:=i+1;
until pos('/',treePath)=0;
if treePath=levelString then result:=i
else result:=-1;
end;
procedure TForm1.projectTreeContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var
textPath : string;
begin
if projectCurrent<>nil then
begin
popUpOrigin:=projectTree.GetNodeAt(MousePos.X,MousePos.y);
if popUpOrigin.Selected then
begin
textPath:=popUpOrigin.GetTextPath;
if getStringFromLevel(textPath,1)='Block' then
begin
if popUpOrigin.text='Block' then
begin
projectTree.PopupMenu:=PopupTitreBlock;
exit;
end
else
begin
selectedTreeStr:=popUpOrigin.text;
projectTree.PopupMenu:=PopUpBlock;;
exit;
end;
end;
if getStringFromLevel(textPath,1)<>'Block' then
begin
Handled:=true;
exit;
end