-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunBlock.pas
2298 lines (2004 loc) · 57.2 KB
/
unBlock.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
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 unBlock;
interface
uses
Vcl.ExtCtrls,Vcl.Controls,System.Classes,Winapi.Windows,Winapi.Messages,Vcl.Graphics,Vcl.StdCtrls,
Vcl.ComCtrls;
const WM_REFRESH_MSG = WM_USER + 1;
Type
TPointArray= array of TPoint;
TDspBlock=Class(TCustomControl)
private
loading:boolean;
enblColor:TColor;
cancelMouseDn:boolean;
a: TPointArray;
borderUp:TPointArray;
borderDn:TPointArray;
fLinkTo:TDspBlock;
sameattach:boolean;
FtopNose: boolean;
FBorderColor: TColor;
Fparam1question: String;
FId: integer;
FTotalParams: integer;
Fparam1prompt: string;
FLinkFrom: TDspBlock;
FCommandColor: TColor;
FbotNose: boolean;
Fparam2question: String;
Fparam2prompt: string;
FMyhint: string;
Fprototype: boolean;
FDeviceOnlyCommandID: integer;
FVarParam1: TDspBlock;
FVarParam2: TDspBlock;
FParam1Attaching: Boolean;
FParam2Attaching: Boolean;
FArduCmd:String;
FArduCheck:String;
procedure CalcArea;
function InCircle(p, Cp: Tpoint): boolean;
procedure MakeBorderDn;
procedure MakeBorderUp;
procedure makenose(var a: TPointArray; nx, ny: integer; isUP: boolean=True);
procedure ConnectBorders;
function getFirstBlock: TDspBlock;
procedure SettopNose(const Value: boolean);
procedure SetBorderColor(const Value: TColor);
procedure SetCommandColor(const Value: TColor);
procedure SetId(const Value: integer);
procedure SetLinkFrom(const Value: TDspBlock);
procedure Setparam1prompt(const Value: string);
procedure Setparam1question(const Value: String);
procedure SetbotNose(const Value: boolean);
procedure SetLinkFromName(const Value: String);
procedure SetLinkToName(const Value: String);
function GetLinkFromName: String;
function GetLinkToName: String;
procedure requestParam1;
procedure requestParam2;
procedure Setparam2prompt(const Value: string);
procedure Setparam2question(const Value: String);
procedure SetMyhint(const Value: string);
function getFixedCommandText: String;
function getParentControl: TWincontrol;
function IndexInOwner(VControl: Tcontrol): integer;
procedure SetParamStr(const Value: string);
function getParamStrControl(x, y: integer): integer;
procedure SetDeviceOnlyCommandID(const Value: integer);
function IsParamDev: Boolean;
procedure SetParamD(const Value: String);
procedure SetComboBoxValue;
procedure OnRefreshRequest(var Msg: TMessage); message WM_REFRESH_MSG;
procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
procedure SetPDevice(const Value: Integer);
function getParamDControl(x, y: integer): integer;
procedure ComboChange(Sender: TObject);
function GetVarParam1Name: String;
procedure SetVarParam1(const Value: TDspBlock);
procedure SetVarParam1Name(const Value: String);
procedure SetParam1Attaching(const Value: Boolean);
procedure SubFromRect(Var R:tRect;n: Integer);
function GetVarParam2Name: String;
procedure SetVarParam2(const Value: TDspBlock);
procedure SetVarParam2Name(const Value: String);
procedure SetParam2Attaching(const Value: Boolean);
procedure PaintChildren;
procedure InformClientControls;
function getDeviceParam(pn: integer): Integer;
protected
FCommandText:String;
move:boolean;
P1:TPoint;
lnw:integer; //border line width
nospadUp,nospadDn:Integer;
nosw,nosh:Integer;
fNewlyCreated:boolean;
ActivePointUp:TPoint;
ActivePointDn:TPoint;
CtrltoAttach:TDspBlock;
FCtrlAttachUp:boolean;
FCtrlAttachDn:boolean;
Param1toAttach:TDspBlock;
Param2toAttach:TDspBlock;
ctrl1:TWinControl;
ctrl2:TWinControl;
ctrlS:TWinControl;
ctrlD:TWinControl;
fArduinoCommand:String;
// updn1:tupdown;
// updn2:tupdown;
procedure setfParam1(const Value: Integer);virtual;
procedure setfParam2(const Value: Integer);virtual;
function getParam1Text: String;virtual;
procedure CheckAttach;virtual;
procedure Setprototype(const Value: boolean);Virtual;
procedure SetParent(AParent: TWinControl); override;
procedure CreateCtrl1;virtual;
procedure CreateCtrl2;virtual;
procedure CreateCtrlS;virtual;
procedure CreateCtrlD;virtual;
function getParam1Control(x, y: integer): integer;virtual;
function getParam2Control(x, y: integer): integer;virtual;
procedure edit2Change(Sender: TObject);virtual;
procedure edit1Change(Sender: TObject);virtual;
procedure edit3Change(Sender: TObject);virtual;
procedure setCommandStyle;
procedure SetTotalParams(const Value: integer);virtual;
procedure paintCmd; Virtual;
procedure PaintAttach;Virtual;
procedure paintborderDn;Virtual;
procedure paintborderUp;Virtual;
procedure paintDbg;Virtual;
procedure RecalcWidth;virtual;
procedure checkloopblock;virtual;
function createNewBlock: TDspBlock;virtual;
procedure Paint; override;
procedure Resize; override;
procedure Reattach(Sender: TDspBlock);virtual;
Procedure AttachTo(Blk:TDspBlock;Up:Boolean);
Procedure DettachFrom(Blk:TDspBlock);
procedure AssignTo(Dest:TPersistent);override;
procedure setCommandText(cmdtxt:String);
function getCommandText:String;
procedure setCtrlAttachUp(vl:boolean);
procedure setCtrlAttachDn(vl:boolean);
function getAttachposUp: integer;virtual;
function getAttachposDn: integer;virtual;
procedure setNewlyCreated(v:boolean);virtual;
procedure setLinkTo(const Value: TDspBlock);virtual;
function getLinkTo: TDspBlock;virtual;
function getblocksize: integer;virtual;
function getParam2: Integer;virtual;
function getParam1: Integer;virtual;
procedure loaded;override;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure SetNewWidth(nw: Integer);virtual;
public
fCommndID:Integer; //Command ID
fParam1:integer; //1st Parameter
fParam2:integer; //2nd Parameter
FParamStr: string; //String Parameter
FParamD: String; //Device Name
FPDevice: Integer; //Device Pin formerly in param1 // or Device ID if we keep track on arduino
FLinkToName: String;
FLinkFromName: String;
FVarParam1Name:String;
FVarParam2Name:String;
ctrlcolor1:TColor;
ctrlcolor2:TColor;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
Function IndexInParent(VControl:Tcontrol):integer;
procedure getDspBlockListSize(db: TDspBlock; var res: integer;
recurs: boolean=false);
procedure SetBounds( pLeft , pTop , pWidth , pHeight:integer );Override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure DblClick; override;
function getLastDspBlock(caller:TDspBlock):TDspBlock;virtual;
constructor CreateFloat(AOwner: TComponent);
procedure FillComboBox;
function GetParam1Rect: TRect;virtual;
function GetParam2Rect: TRect;virtual;
function Param1Visible: Boolean;virtual;
function Param2Visible: Boolean;virtual;
function GetArduinoCommand(idnt:integer=1):String;Virtual;
function getDeviceName:string;virtual;
property Height;
Published
property Color;
property Param1Attaching:Boolean read FParam1Attaching write SetParam1Attaching;
property Param2Attaching:Boolean read FParam2Attaching write SetParam2Attaching;
property CtrlAttachUp:boolean read FCtrlAttachUp write setCtrlAttachUp;
property CtrlAttachDn:boolean read FCtrlAttachDn write setCtrlAttachDn;
property CommandText: String read getCommandText write setCommandText;
property NewlyCreated:boolean read fNewlyCreated write setNewlyCreated;
property blocksize:integer read getblocksize;
property firstBlock:TDspBlock read getFirstBlock;
property CommndID:Integer read fCommndID write fCommndID;
property Param1:Integer read getParam1 write setfParam1;
property Param2:Integer read getParam2 write setfParam2;
property ParamStr:string read FParamStr write SetParamStr;
Property ParamD:String read FParamD write SetParamD;
property PDevice:Integer read FPDevice write SetPDevice;
property topNose:boolean read FtopNose write SettopNose;
property botNose:boolean read FbotNose write SetbotNose;
property LinkTo:TDspBlock read getLinkTo write setLinkTo;
property LinkFrom:TDspBlock read FLinkFrom write SetLinkFrom;
property TotalParams:integer read FTotalParams write SetTotalParams;
property param1question:String read Fparam1question write Setparam1question;
property param1prompt:string read Fparam1prompt write Setparam1prompt;
property param2question:String read Fparam2question write Setparam2question;
property param2prompt:string read Fparam2prompt write Setparam2prompt;
property Id:integer read FId write SetId;
property BorderColor:TColor read FBorderColor write SetBorderColor;
property CommandColor:TColor read FCommandColor write SetCommandColor;
property LinkToName:String read GetLinkToName write SetLinkToName;
property LinkFromName:String read GetLinkFromName write SetLinkFromName;
property MyHint:string read FMyhint write SetMyhint;
property prototype:boolean read Fprototype write Setprototype;
property DeviceOnlyCommandID:integer read FDeviceOnlyCommandID write SetDeviceOnlyCommandID;
property VarParam1:TDspBlock read FVarParam1 write SetVarParam1;
Property VarParam1Name:String read GetVarParam1Name write SetVarParam1Name;
property VarParam2:TDspBlock read FVarParam2 write SetVarParam2;
Property VarParam2Name:String read GetVarParam2Name write SetVarParam2Name;
property ArduCmd:String read FArduCmd write FArduCmd;
property ArduCheck:string read fArduCheck write FArduCheck;
End;
tComboHack=Class(TComboBox)
protected
procedure WMPaint(var Msg: TMessage); message WM_Paint;
End;
var debugging:boolean=false;
implementation
uses Vcl.Forms,sysutils,dialogs,types,math,
DspEdit,DspCombo,
DspUtils,unCtrlPlatMain,unDevices,unVariables;
var idcnt:integer=1;
Function GetActiveDevicePins(DevTp:integer=-1):TStrings;
Begin
Result:=frmRoboLang.GetActiveDevicePins(Devtp);
End;
Procedure AddDebug(s:String);
Begin
frmRoboLang.adddebug(s);
End;
Procedure setUniqueComponentName(Comp:TDspBlock;nm:string);
var newname:string;
k:integer;
Begin
if not assigned(comp.owner) then exit;
if Comp.prototype then
nm:='Prot_'+nm;
k:=0;
Repeat
inc(k);
newname:=nm+'_'+inttostr(k);
Until comp.Owner.FindComponent(newname)=nil ;
Comp.Id:=k;
comp.Name:=newname;
End;
Function TDspBlock.IndexInParent(VControl:Tcontrol):integer;
var
ParentControl: TWinControl;
begin
ParentControl:=TForm(VControl.Parent);
if (ParentControl<>nil) then
for Result:=0 to ParentControl.ControlCount-1 do
if (ParentControl.Controls[Result]=VControl) then
Exit;
Result:=-1;
end;
Function TDspBlock.IndexInOwner(VControl:Tcontrol):integer;
var
OwnerControl: TForm;
begin
OwnerControl:=TForm(VControl.Owner);
if (OwnerControl<>nil) then
for Result:=0 to OwnerControl.ComponentCount-1 do
if (OwnerControl.Components[Result]=VControl) then
Exit;
Result:=-1;
end;
constructor TDspBlock.CreateFloat(AOwner: TComponent);
Begin
Create(AOwner);
Prototype:=false;
setUniqueComponentName(Self,'dspBlock_');
End;
constructor TDspBlock.Create(AOwner: TComponent);
begin
inherited;
ControlStyle:=ControlStyle+[ csAcceptsControls, csCaptureMouse, csClickEvents];
Param1Attaching:=false;
Param2Attaching:=false;
// ControlStyle := ControlStyle - [csOpaque];
FDeviceOnlyCommandID:=-1;
ctrlcolor1:=clYellow;//htmltocolor('#FFD900') ;
ctrlcolor2:=clYellow;//htmltocolor('#003300');
Font.Size:=10;
Font.Style:=[fsBold];
enabled:=true;
Prototype:=true;
setUniqueComponentName(Self,'dspBlock_');
cancelMouseDn:=false;
width:=150;
height:=44;
dragMode:=dmManual;
move:=false;
// InterceptMouse:=true;
Doublebuffered:=true;
lnw:=2;
nospadUp:=20;
nospadDn:=20;
nosw:=14;
nosh:=6;
topnose:=true;
botnose:=true;
fNewlyCreated:=true;
Color:=clRed;
enblColor:=-1;
BorderColor:=clRed;
FCommandText:='Command';
CommndID:=-1;
FPDevice:=-1;//default Device none
fParam1:=0;
fParam2:=0;
TotalParams:=0;
// param1question:='Äþóå ôçí ðáñÜìåôñï1';
// param1prompt:='ÐáñÜìåôñïò';
// param2question:='Äþóå ôçí ðáñÜìåôñï2';
// param2prompt:='ÐáñÜìåôñïò';
RecalcWidth;
CalcArea;
createctrl1;
createctrl2;
CreateCtrlS;
CreateCtrlD;
FVarParam1:=nil;
FVarParam1Name:='';
FVarParam2:=nil;
FVarParam2Name:='';
// ID:=IndexInowner(self);
end;
procedure TDspBlock.requestParam1;
Begin
End;
procedure TDspBlock.requestParam2;
Begin
End;
procedure TDspBlock.DblClick;
begin
exit;
cancelMouseDn:=true;
inherited;
if TotalParams>0 then
requestParam1;
if TotalParams>1 then
requestParam2;
end;
destructor TDspBlock.Destroy;
begin
if assigned(flinkto) then
begin
try
Freeandnil(flinkto);
except
Flinkto:=nil;
end;
end;
inherited;
end;
function TDspBlock.getDeviceParam(pn:integer):Integer;
Begin
result:=-1;
if PDevice<>-1 then
Begin
result:=ActDevs[PDevice].ActDevParams[pn];
End;
End;
function TDspBlock.getDeviceName: string;
var dvi:Integer;
begin
result:=Paramd;//%pd has the device id param1
if (result='') and (DeviceOnlyCommandID<>-1) then
Begin
//get 1st device
dvi:=getFirstDeviceOfType(DeviceOnlyCommandID);
result:=ActDevs[dvi].ActDevForm.Caption;
End;
end;
procedure TDspBlock.getDspBlockListSize(db:TDspBlock;var res:integer;recurs:boolean=false);
Begin
if db=nil then
db:=self;
if not recurs then
res:=0;
inc(res,db.blocksize); //get containers total blocks
if Assigned(db.LinkTo) then //linkto skips containers
getDspBlockListSize(db.LinkTo,Res,true);
End;
function TDspBlock.getFirstBlock: TDspBlock;
begin
result:=fLinkto;
end;
procedure TDspBlock.SetBorderColor(const Value: TColor);
begin
FBorderColor := Value;
end;
procedure TDspBlock.SetbotNose(const Value: boolean);
begin
FbotNose := Value;
end;
procedure TDspBlock.SetBounds( pLeft , pTop , pWidth , pHeight:integer );
var
lMoved : BOolean;
ktop,kleft:integer;
begin
if not prototype then
begin
if assigned(parent) and not (parent is TDspBlock) then
Begin
if assigned(parent) and assigned(tscrollbox(parent).VertScrollBar) then
ktop:=tscrollbox(parent).VertScrollBar.ScrollPos;
if assigned(parent) and assigned(tscrollbox(parent).HorzScrollBar) then
kleft:=tscrollbox(parent).HorzScrollBar.ScrollPos;
End;
end
else
Begin
ktop:=0;kleft:=0;
End;
if assigned(parent) and not (parent is TDspBlock) then
Begin
if ktop+ptop<5 then
ptop:=5;
if kleft+pleft<5 then
pLeft:=5;
End;
lMoved := ( pLeft <> Left ) or ( pTop <> Top );
inherited SetBounds( pLeft , pTop , pWidth , pHeight );
if ( lMoved ) then
begin
if (linkfrom=flinkto) and (linkfrom<>nil) then //bug shouldnot happen
Begin
flinkto:=nil;
adddebug('Bug-->>'+inttostr(id)+' is linked up dn to'+inttostr(linkfrom.id));
End;
if fLinkTo<>nil then
Begin
fLinkTo.Reattach(Self);
repaint;
End;
end;
end;
procedure TDspBlock.SetCommandColor(const Value: TColor);
begin
FCommandColor := Value;
font.Color:=Value;
if assigned(ctrld) then
TComboBox(ctrlD).font.Color:=Value;
end;
procedure TDspBlock.setCommandText(cmdtxt: String);
begin
fCommandText:=cmdtxt;
if not (csLoading in componentstate) then
begin
setCommandStyle;
RecalcWidth;
end;
end;
procedure TDspBlock.RecalcWidth;
var w:integer;
begin
if parent=nil then exit;
w:=canvas.TextWidth(getFixedCommandText)+20;
width:=w;
end;
procedure TDspBlock.setCtrlAttachDn(vl: boolean);
begin
fCtrlAttachDn:=vl;
Repaint;
end;
procedure TDspBlock.setCtrlAttachUp(vl: boolean);
begin
fCtrlAttachUp:=vl;
Repaint;
end;
procedure TDspBlock.SetDeviceOnlyCommandID(const Value: integer);
begin
FDeviceOnlyCommandID := Value;
if prototype then enabled:=false;//only at create
end;
procedure TDspBlock.setfParam1(const Value: Integer);
begin
fParam1 := Value;
if not (csLoading in componentstate) then
begin
RecalcWidth;
end;
if assigned(ctrl1) and (ctrl1 is TdspEdit) then
TDspedit(ctrl1).Text:=inttostr(fparam1);
MyHint:=fMyhint;
end;
procedure TDspBlock.setfParam2(const Value: Integer);
begin
fParam2 := Value;
if not (csLoading in componentstate) then
begin
RecalcWidth;
end;
if assigned(ctrl2) and (ctrl2 is TdspEdit) then
Tdspedit(ctrl2).Text:=inttostr(fparam2);
end;
function TDspBlock.getParam1Text:String;
Begin
try
Result:=inttostr(param1);
except
Result:='';
end;
End;
procedure TDspBlock.SetMyhint(const Value: string);
var s,t:string;
begin
if fparamstr<>'' then
s:=#13' ['+fparamstr+']';
hint := Value+s;
fMyhint:=value;
t:=StringReplace(Hint,'%p1',getParam1Text,[]);
hint:=t;
ShowHint:=true;
end;
procedure TDspBlock.SetId(const Value: integer);
begin
FId := Value;
end;
procedure TDspBlock.SetLinkFrom(const Value: TDspBlock);
begin
FLinkFrom := Value;
end;
procedure TDspBlock.SetLinkFromName(const Value: String);
var f:TDspBlock;
begin
FLinkFromName := Value;
if assigned(owner) and not assigned(Linkfrom) then
Begin
f:=TDspBlock(owner.FindComponent(FLinkFromName));
if assigned(f) then
linkfrom:=f;
End;
end;
procedure TDspBlock.setLinkTo(const Value: TDspBlock);
begin
fLinkTo := Value;
end;
procedure TDspBlock.SetLinkToName(const Value: String);
var f:TDspBlock;
begin
FLinkToName := Value;
if assigned(owner) and not assigned(fLinkto) then
Begin
f:=TDspBlock(owner.FindComponent(FLinkToName));
if assigned(f) then
fLinkto:=f;
End;
end;
procedure TDspBlock.setNewlyCreated(v: boolean);
begin
fNewlyCreated:=v;
end;
procedure TDspBlock.Setparam1prompt(const Value: string);
begin
Fparam1prompt := Value;
end;
procedure TDspBlock.Setparam1question(const Value: String);
begin
Fparam1question := Value;
end;
procedure TDspBlock.SetParam2Attaching(const Value: Boolean);
begin
FParam2Attaching := Value;
Repaint;
end;
procedure TDspBlock.Setparam2prompt(const Value: string);
begin
Fparam2prompt := Value;
end;
procedure TDspBlock.Setparam2question(const Value: String);
begin
Fparam2question := Value;
end;
procedure TDspBlock.SetParamD(const Value: String);
begin
FParamD := Value;
if not (csLoading in componentstate) then
begin
RecalcWidth;
if assigned(ctrlS) then
FillComboBox;
end;
end;
procedure TDspBlock.SetParamStr(const Value: string);
begin
FParamStr := Value;
if not (csLoading in componentstate) then
begin
RecalcWidth;
end;
if assigned(ctrlS) then
Tdspedit(ctrlS).Text:=FParamStr;
end;
procedure TDspBlock.SetParent(AParent: TWinControl);
begin
if assigned(parent) and ((Parent is TDspBlock) or (assigned(AParent) and (Aparent is TDspBlock) and TDspBlock(AParent).loading))then //remove from this parent
Begin
Width:=Width+2*lnw;
Height:=Height+2*lnw+8;
Margins.Top:=0;
End;
inherited;
if IsParamDev and (AParent<>nil) then
FillComboBox;
if assigned(Aparent) and (AParent is TDspBlock) then
Begin
//smaller rect
Width:=Width-2*lnw;
Height:=Height-2*lnw-8;
Margins.Top:=2;
End;
InformClientControls;
end;
procedure TDspBlock.InformClientControls;
Var i:integer;
Begin
for i := 0 to Pred(controlcount) do
if controls[i] is TDSpEdit then
TDSpEdit(Controls[i]).ParentSet;
End;
procedure TDspBlock.SetPDevice(const Value: Integer);
begin
FPDevice := Value;
if not (csLoading in componentstate) then
begin
RecalcWidth;
end;
if assigned(ctrlD) then
Begin
SeTComboBoxValue;
End;
end;
procedure TDspBlock.Setprototype(const Value: boolean);
begin
Fprototype := Value;
if value then
setUniqueComponentName(Self,'dspBlock_')
else
Recalcwidth;
end;
procedure TDspBlock.SettopNose(const Value: boolean);
begin
FtopNose := Value;
end;
procedure TDspBlock.SetTotalParams(const Value: integer);
begin
FTotalParams := Value;
end;
procedure TDspBlock.SetVarParam1(const Value: TDspBlock);
begin
if assigned(Value) then //New Var Param
Begin
Value.Parent:=Self;
Value.left:=ctrl1.Left;
value.Top:=ctrl1.Top-lnw*2;
ctrl1.Visible:=false;
if value.CommndID>74 then //fix var from a device
Begin //todo:don't allow this no fix vars on device blocks
if (PDevice<>-1) and (PDevice<>Value.PDevice) then raise Exception.Create('Error device has already a device ID');
FPDevice:=Value.PDevice;
End;
End;
if Assigned(FVarParam1) then //old Var Param Get it Out of us
Begin
FVarParam1.Left:=left+FVarParam1.Left+10;
FVarParam1.Top:=Top+FVarParam1.Top+10;
FVarParam1.Parent:=parent;
// FVarParam1.Height:=FVarParam1.height+2;
if not assigned(value) then //nil
Begin
ctrl1.Visible:=True;
End;
if FVarParam1.CommndID>74 then //fix var from a device remove device id
PDevice:=-1;
End;
FVarParam1 := Value;
end;
procedure TDspBlock.SetVarParam1Name(const Value: String);
var f:TDspBlock;
begin
loading:=(value<>'') and not assigned(FVarParam1);
FVarParam1Name := Value;
if assigned(owner) and not assigned(FVarParam1) then //LinkByName
Begin
f:=TDspBlock(owner.FindComponent(FVarParam1Name));
if assigned(f) then
Begin
VarParam1:=f;
loading:=false;
End;
End;
end;
procedure TDspBlock.SetVarParam2(const Value: TDspBlock);
begin
if assigned(Value) then //New Var Param
Begin
Value.Parent:=Self;
Value.left:=ctrl2.Left;
value.Top:=ctrl2.Top-lnw*2;
ctrl2.Visible:=false;
// if assigned(updn2) then updn2.Visible:=false;
if value.CommndID>74 then //fix var from a device
Begin //todo:don't allow this no fix vars on device blocks
if (PDevice<>-1) and (PDevice<>Value.PDevice) then raise Exception.Create('Error device has already a device ID');
PDevice:=Value.PDevice;
End;
End;
if Assigned(FVarParam2) then //old Var Param Get it Out of us
Begin
FVarParam2.Left:=left+FVarParam2.Left+10;
FVarParam2.Top:=Top+FVarParam2.Top+10;
FVarParam2.Parent:=parent;
if not assigned(value) then //nil
Begin
ctrl2.Visible:=True;
// if assigned(updn2) then updn2.Visible:=True;
if FVarParam2.CommndID>74 then //fix var from a device remove device id
PDevice:=-1;
End;
End;
FVarParam2 := Value;
end;
procedure TDspBlock.SetVarParam2Name(const Value: String);
var f:TDspBlock;
begin
loading:=(value<>'') and not assigned(FVarParam2);
FVarParam2Name := Value;
if assigned(owner) and not assigned(FVarParam2) then //LinkByName
Begin
f:=TDspBlock(owner.FindComponent(FVarParam2Name));
if assigned(f) then
Begin
VarParam2:=f;
loading:=false;
End;
End;
end;
procedure TDspBlock.Resize;
begin
if length(a)>0 then
Begin
calcarea;
SetWindowRgn(Handle, CreatePolygonRgn(a[0],length(a),WINDING), True);
End;
inherited; //the inherited implementation just calls the event
end;
function TDspBlock.createNewBlock:TDspBlock;
Begin
result:=TDspBlock.CreateFloat(Owner);
End;
procedure TDspBlock.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
var newblock: TDspBlock;
begin
inherited;
if (mbLeft = Button) then
if not prototype then
Begin
setfocus;
if not cancelMouseDn then
Begin
move:=true;
bringtofront;
P1.X:=X;
P1.Y:=Y;
End
else
cancelMouseDn:=false;//skipped mouse down after double click
End
else
Begin
newblock:=createNewBlock;
newblock.assign(self);
newblock.Parent:=TWinControl(owner);
newblock.NewlyCreated:=false;
Postmessage(newblock.Handle,WM_LBUTTONDOWN,0,MAKELPARAM(X,Y))
End;
end;
procedure TDspBlock.AssignTo(Dest:TPersistent);
var blck:TDspBlock;
Begin
if Dest is TDspBlock then
Begin
blck:=TDspBlock(Dest);
blck.parent:=TWinControl(blck.Owner);
blck.prototype:=false;
blck.topNose:=topnose;
blck.botNose:=botNose;
blck.nospadUp:=nospadUp;
blck.nospadDn:=nospadDn;
blck.Left:=Left;
blck.Top:=Top;
blck.width:=width;
blck.Height:=Height;
blck.Color:=Color;
blck.BorderColor:=BorderColor;
blck.CommandColor:=CommandColor;
blck.fCommandText:=fCommandText;
blck.CommndID:=CommndID;
blck.Param1:=Param1;
blck.Param2:=Param2;
blck.Paramstr:=Paramstr;
blck.ParamD:=ParamD;
if Paramstr<>'' then
blck.Param2:=Length(blck.Paramstr);
blck.TotalParams:=TotalParams;
blck.param1question:=param1question;
blck.param1prompt:=param1prompt;
blck.param2question:=param2question;
blck.param2prompt:=param2prompt;
blck.MyHint:=myhint;
blck.DeviceOnlyCommandID:=DeviceOnlyCommandID;
blck.enblColor:=enblColor;
blck.ArduCmd:=ArduCmd;
End;
End;
function TDspBlock.InCircle(p:TPoint;Cp:Tpoint):boolean;
const radius=25;
Begin
result:= sqr((p.x - Cp.x)) + sqr((p.y - Cp.y)) < sqr(radius);
End;
procedure TDspBlock.loaded;
begin
inherited;
end;
Const ScrollQuant=100;
Function TDspBlock.Param1Visible:Boolean;
Begin
Result:=Ctrl1.visible and (totalparams>0);
End;
function TDspBlock.Param2Visible: Boolean;
begin
Result:=Ctrl2.visible and (totalparams>1);
end;
Function TDspBlock.GetParam1Rect:TRect;
Begin
if Param1Visible then
Begin
Result:=Ctrl1.BoundsRect;
Result.left:=Result.Left+left;
Result.Right:=Result.Right+left;
Result.Top:=Result.Top+Top;
Result.Bottom:=Result.Bottom+Top;
End
Else Result.Empty;
End;
procedure TDspBlock.CheckAttach;
var tmpctrl:TDspBlock;
otApUp,otApDn,myApUp,myApDn:TPoint;
i:integer;
Begin
if CtrltoAttach<>nil then
Begin
CtrltoAttach.CtrlAttachUp:=false;
CtrltoAttach.CtrlAttachDn:=false;
End;
CtrltoAttach:=nil;
sameattach:=false;
if (parent<>nil) and (parent.Tag=995) then
Begin