-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEditor.pas
More file actions
1523 lines (1269 loc) · 49.7 KB
/
Editor.pas
File metadata and controls
1523 lines (1269 loc) · 49.7 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 Editor;
{$MODE Delphi}
interface
uses
Windows, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SynEdit, SynEditHighlighter, SynHighlighterPas, StdCtrls, SynMemo,
ExtCtrls, ComCtrls, SynEditTypes, Menus, math,
uPSComponent, uPSUtils, uPSRuntime, SynCompletion, uPSComponent_Default,
uPSComponent_StdCtrls, uPSComponent_Controls, uPSComponent_Forms, ProjConfig,
SynEditMiscClasses, PrintersDlgs, uPSCompiler, Clipbrd, lNetComponents,
IniPropStorage, Rlan, SynEditMarks, process, LCLIntf, Types, LCLType, lnet,
GLGraphics;
type
{ TFEditor }
TFEditor = class(TForm)
IniPropStorage: TIniPropStorage;
MenuIncreaseFont: TMenuItem;
MenuDecreaseFont: TMenuItem;
MenuResetFont: TMenuItem;
MenuItem2: TMenuItem;
SynPasSyn: TSynPasSyn;
PageControl: TPageControl;
TabProject: TTabSheet;
TabControl: TTabSheet;
Splitter: TSplitter;
SynEditST: TSynEdit;
PageControlBottom: TPageControl;
TabOutput: TTabSheet;
TabErrors: TTabSheet;
LBErrors: TListBox;
TabPascal: TTabSheet;
SynEditPascal: TSynEdit;
SynMemoHeader: TSynMemo;
StatusBar: TStatusBar;
MainMenu: TMainMenu;
MenuFile: TMenuItem;
MenuNew: TMenuItem;
MenuOpen: TMenuItem;
N2: TMenuItem;
MenuSave: TMenuItem;
MenuSaveAs: TMenuItem;
N3: TMenuItem;
MenuPrintSource: TMenuItem;
N1: TMenuItem;
MenuExit: TMenuItem;
MenuEdit: TMenuItem;
MenuUndo: TMenuItem;
MenuRedo: TMenuItem;
N4: TMenuItem;
MenuFind: TMenuItem;
MenuReplace: TMenuItem;
MenuPascal: TMenuItem;
MenuProgram: TMenuItem;
MenuCompile: TMenuItem;
MenuRun: TMenuItem;
MenuStop: TMenuItem;
MenuWindow: TMenuItem;
MenuChart: TMenuItem;
MenuControl: TMenuItem;
MenuLog: TMenuItem;
MenuCalculator: TMenuItem;
MenuHelp: TMenuItem;
MenuAbout: TMenuItem;
MenuLocalHelp: TMenuItem;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
FindDialog: TFindDialog;
ReplaceDialog: TReplaceDialog;
PrintDialog: TPrintDialog;
PSScript: TPSScriptDebugger;
MenuTest: TMenuItem;
TabVariables: TTabSheet;
LBVariables: TListBox;
MenuSetResetInspector: TMenuItem;
N5: TMenuItem;
MenuShowLocalVariables: TMenuItem;
MenuShowGlobalVariables: TMenuItem;
SynCompletionProposal: TSynCompletion;
PSImport_Classes: TPSImport_Classes;
PSImport_Forms: TPSImport_Forms;
PSImport_Controls: TPSImport_Controls;
PSImport_StdCtrls: TPSImport_StdCtrls;
CBSaveOnRun: TCheckBox;
PopupMenuOutput: TPopupMenu;
PopUpClearAll: TMenuItem;
Label3: TLabel;
MemoDescription: TMemo;
LBResult: TListBox;
MenuCopy: TMenuItem;
MenuCut: TMenuItem;
N6: TMenuItem;
MenuPaste: TMenuItem;
procedure FindDialogFind(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure MenuCopyClick(Sender: TObject);
procedure MenuCutClick(Sender: TObject);
procedure MenuDecreaseFontClick(Sender: TObject);
procedure MenuIncreaseFontClick(Sender: TObject);
procedure MenuPasteClick(Sender: TObject);
procedure MenuResetFontClick(Sender: TObject);
procedure MenuShowGlobalVariablesClick(Sender: TObject);
procedure MenuShowLocalVariablesClick(Sender: TObject);
procedure PopUpClearAllClick(Sender: TObject);
procedure PSScriptBreakpoint(Sender: TObject; const FileName: tbtstring;
Position, Row, Col: Cardinal);
function PSScriptNeedFile(Sender: TObject; const OrginFileName: tbtstring;
var FileName, Output: tbtstring): Boolean;
procedure ReplaceDialogFind(Sender: TObject);
procedure ReplaceDialogReplace(Sender: TObject);
procedure SynCompletionProposalCodeCompletion(var Value: string;
SourceValue: string; var SourceStart, SourceEnd: TPoint;
KeyChar: TUTF8Char; Shift: TShiftState);
procedure SynCompletionProposalSearchPosition(var APosition: integer);
procedure SynEditSTGutterClick(Sender: TObject; X, Y, Line: integer;
mark: TSynEditMark);
procedure SynEditSTMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SynEditSTSpecialLineColors(Sender: TObject; Line: integer;
var Special: boolean; var FG, BG: TColor);
procedure SynEditSTStatusChange(Sender: TObject;
Changes: TSynStatusChanges);
procedure LBErrorsDblClick(Sender: TObject);
procedure MenuExitClick(Sender: TObject);
procedure MenuCompileClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MenuSaveAsClick(Sender: TObject);
procedure MenuUndoClick(Sender: TObject);
procedure MenuRedoClick(Sender: TObject);
procedure MenuAboutClick(Sender: TObject);
procedure MenuFindClick(Sender: TObject);
procedure MenuReplaceClick(Sender: TObject);
procedure MenuCalculatorClick(Sender: TObject);
procedure MenuSaveClick(Sender: TObject);
procedure MenuNewClick(Sender: TObject);
procedure MenuOpenClick(Sender: TObject);
procedure MenuRunClick(Sender: TObject);
procedure MenuStopClick(Sender: TObject);
procedure MenuLocalHelpClick(Sender: TObject);
procedure PSScript_Compile(Sender: TPSScript);
procedure PSScript_Execute(Sender: TPSScript);
procedure MenuTestClick(Sender: TObject);
procedure MenuSetResetInspectorClick(Sender: TObject);
private
FuncList, InsertList: TStringList;
TypeList: TStringList;
procedure BuildRegFuncList(Sender: TPSScript);
function ReadUDPData: string;
procedure WriteUDPData(ToIP: string; ToPort: integer; s: string);
procedure ProjectSave(FileName: string);
function ProjectOpen(FileName: string): boolean;
procedure BuildRegTypeList(Sender: TPSScript);
procedure BuildRegTypeListEx(Sender: TPSPascalCompiler);
function ReadUDPPacket: string;
function GetUDPPacketCount: integer;
public
ProgCyclesCount: integer;
ProgTime: double;
//ScriptState : TScriptState; //ProgRunning: boolean;
ScriptStartTime, ScriptLastTime, ScriptTotalRunTime: LongWord;
ProgramStartTime, ScriptCyclesCount: LongWord;
SimLevel: Dword;
// IOControl: TIOControl;
compiled, LocalInspector: boolean;
LocalInspectorLine: integer;
SimTwoCloseRequested: boolean;
procedure RunOnce;
function Compile: boolean;
procedure UpdateStatusLine;
function ReadComPort: string;
procedure WriteComPort(s: string);
procedure writeLn(S: string);
end;
type
TProjectConfig = record
FileName : string;
//Modified: boolean; // Always compile
//Author: string;
//Comments: string;
end;
var
FEditor: TFEditor;
Project: TProjectConfig;
implementation
//uses Viewer, ProjManage, Params, FastChart, uPSDebugger;
uses uPSDebugger, Sheets, Viewer, Utils, Params, uPSI_ODERobotsPublished, uPSI_PathFinder, uPSI_dynmatrix,
uPSI_user_charts, cameras;
{$R *.lfm}
procedure TFEditor.SynEditSTMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var ScreenCoord: TPoint;
BufCoord: TPoint;
//varname, varvalue: string;
len: integer;
begin
//ScreenCoord:=SynEditST.PixelsToRowColumn(point(X,Y));
//BufCoord:= SynEditST.DisplayToBufferPos(ScreenCoord);
//if (BufCoord.Line >= 1) and (BufCoord.Line <= SynEditST.Lines.Count) then begin
// Len := Length(SynEditST.Lines[BufCoord.Line - 1]);
// if BufCoord.Char <= Len then begin
{ varname:=SynEditST.GetWordAtRowCol(BufCoord);
varvalue:= GetStringValueFromAnyVarName(varname);
if varvalue<>'' then
StatusBar.Panels[4].text:=varname+': '+varvalue;}
// end;
//end else begin
// StatusBar.Panels[4].text:='';
// end;
end;
procedure TFEditor.SynEditSTStatusChange(Sender: TObject;
Changes: TSynStatusChanges);
begin
if (scCaretX in Changes) or (scCaretY in Changes) then
StatusBar.Panels[0].Text := format('%6d: %3d',[SynEditST.CaretY, SynEditST.CaretX]);
if scInsertMode in Changes then begin
if SynEditST.InsertMode then begin
StatusBar.Panels[2].Text := 'Insert';
end else begin
StatusBar.Panels[2].Text := 'Overwrite';
end;
end;
if scModified in Changes then begin
if SynEditST.Modified then begin
StatusBar.Panels[1].Text := 'Modified';
end else begin
StatusBar.Panels[1].Text := '';
end;
end;
StatusBar.Invalidate;
end;
function FixLineColInErrorLine(const txt : string; var LC: TPoint; offset: integer): string;
var p1, p2, p3 : integer;
s: string;
begin
LC.x:=-1;
LC.y:=-1;
p1:= pos('(',txt);
p2:= pos(':',txt);
p3:= pos(')',txt);
if (p1>0) and (p2>0) and (p3>0) then begin
s:=copy(txt, p1+1, p2-(p1+1));
LC.y:=strToIntdef(s,-1);
s:=copy(txt,p2+1,p3-(p2+1));
LC.x:=strToIntdef(s,-1);
//result:=copy(txt,1,p1+6)+IntToStr(LC.y+offset)+', column: '+IntToStr(LC.x)+copy(txt,p3,length(txt));
result:=copy(txt,p3+1,maxint);
end;
end;
procedure TFEditor.LBErrorsDblClick(Sender: TObject);
var txt: string;
LinCol: TPoint;
i: integer;
begin
i:= LBErrors.ItemIndex;
if i<0 then exit;
txt:=LBErrors.Items[i];
FixLineColInErrorLine(txt, LinCol, 0);
if (LinCol.x<>-1) and (LinCol.y<>-1) then begin
SynEditST.caretX:=LinCol.x;
SynEditST.caretY:=LinCol.y - SynMemoHeader.Lines.Count;
//TODO SynEditST.UpdateCaret;
SynEditST.setfocus;
end;
end;
procedure TFEditor.writeLn(S: string);
begin
LBResult.Items.BeginUpdate;
while LBResult.Items.Count > 100 do begin
LBResult.Items.Delete(0);
end;
LBResult.Items.Add(S);
LBResult.ItemIndex := LBResult.Items.Count-1;
LBResult.Items.EndUpdate;
end;
procedure TFEditor.RunOnce;
var i64_start, i64_end, i64_freq: int64;
//Saved8087CW: Word;
i: integer;
var_name, txt: string;
tp: TPSVariantIFC;
FPUExceptionMask: TFPUExceptionMask;
begin
if PSScript.Exec.Status <> isLoaded then exit;
ScriptCyclesCount:=0;
queryperformancecounter(i64_start);
ClearExceptions(false);
//Saved8087CW := Get8087CW;
//Set8087CW(Default8087CW);
FPUExceptionMask := GetExceptionMask;
SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
ProgTime := ProgCyclesCount * WorldODE.Ode_dt;
LocalInspector := false;
try
if ProgCyclesCount = 0 then
PSScript.ExecuteFunction([],'Initialize');
except
on E: Exception do begin //ErrorDialog(E.Message, E.HelpContext);
ClearExceptions(false);
SetExceptionMask(FPUExceptionMask);
FParams.RGControlBlock.itemindex := 0;
LBErrors.Items.Add('Error while executing script: ' + E.Message);
//Set8087CW(Saved8087CW);
exit;
end;
end;
try
if PSScript.Execute then begin
if MenuShowGlobalVariables.Checked then begin
LBVariables.Items.BeginUpdate;
if (not MenuShowLocalVariables.Checked) or (not LocalInspector) then LBVariables.Clear;
for i := 0 to PSScript.Exec.GlobalVarNames.Count -1 do begin
tp := NewTPSVariantIFC(PSScript.Exec.GetGlobalVar(i), false);
var_name := PSScript.Exec.GlobalVarNames[i];
txt := format('%s: %s',[ var_name , PSVariantToString(tp,'')]);
LBVariables.Items.Add(txt);
end;
LBVariables.Items.EndUpdate;
end;
//EditDebug.Text := txt;
end else begin
FParams.RGControlBlock.itemindex := 0;
// LBErrors.Items.clear;
LBErrors.Items.Add('Error while executing script: ' + PSScript.ExecErrorToString);
//PSScript.Exec.Clear;
end;
except
on E: Exception do begin //ShowMessage(E.Message);
ClearExceptions(false);
SetExceptionMask(FPUExceptionMask);
FParams.RGControlBlock.itemindex := 0;
LBErrors.Items.Add('Exception while executing script: ' + E.Message);
//Set8087CW(Saved8087CW);
exit;
end;
end;
ClearExceptions(false);
SetExceptionMask(FPUExceptionMask);
//Set8087CW(Saved8087CW);
PSScript.Exec.RaiseCurrentException;
//StatusBar.Panels[4].Text := inttostr(PSScript.Exec.ExceptionPos);
queryperformancecounter(i64_end);
inc(ProgCyclesCount);
QueryPerformanceFrequency(i64_freq);
StatusBar.Panels[3].Text := format('%f',[1000*(i64_end-i64_start)/i64_freq]);
end;
function TFEditor.Compile: boolean;
var i: integer;
i64_start, i64_end, i64_freq: int64;
begin
SynEditPascal.Text := SynMemoHeader.Text + crlf + SynEditST.text + crlf + crlf + 'begin Control; end.';
queryperformancecounter(i64_start);
PSScript.Comp.Clear;
PSScript.Script.Text := SynEditPascal.Text;
Compiled := PSScript.Compile;
LBErrors.Items.clear;
LBErrors.Items.Add('Compile Messages:'+inttostr(PSScript.CompilerMessageCount));
for i := 0 to PSScript.CompilerMessageCount -1 do begin
LBErrors.Items.Add(PSScript.CompilerMessages[i].MessageToString);
end;
if not Compiled then begin
PageControlBottom.ActivePageIndex:=1; // Select Errors Tab
result := false;
end else begin
queryperformancecounter(i64_end);
QueryPerformanceFrequency(i64_freq);
//EditDebug.Text:=format('%f',[1000*(i64_end-i64_start)/i64_freq]);
LBErrors.Items.clear;
LBErrors.Items.Append(format('Compile OK in %f ms',[1000*(i64_end-i64_start)/i64_freq]));
result := true;
end;
end;
procedure TFEditor.MenuExitClick(Sender: TObject);
begin
if SynEditST.Modified then begin
if MessageDlg('Program was changed.'+crlf+
'Exit anyway?',
mtConfirmation , [mbOk,mbCancel], 0)
= mrCancel then exit;
end;
FViewer.close;
end;
procedure TFEditor.MenuCompileClick(Sender: TObject);
begin
FParams.RGControlBlock.ItemIndex := 0; // none
if not compile then exit;
SynEditST.Refresh;
end;
procedure TFEditor.FormCreate(Sender: TObject);
var Plugin, PathPlugin, MatrixPlugin, ChartPlugin: TPSPlugin;
begin
IniPropStorage.IniFileName := GetIniFineName(copy(name, 2, MaxInt));
//TabPascal.TabVisible:=false;
FuncList := TStringList.Create;
InsertList := TStringList.Create;
TypeList := TStringList.Create;
LocalInspectorLine := -1;
MatrixPlugin := TPSImport_dynmatrix.Create(Self);
TPSPluginItem(PSScript.Plugins.add).Plugin := MatrixPlugin;
Plugin := TPSImport_ODERobotsPublished.Create(Self);
TPSPluginItem(PSScript.Plugins.add).Plugin := Plugin;
PathPlugin := TPSImport_PathFinder.Create(Self);
TPSPluginItem(PSScript.Plugins.add).Plugin := PathPlugin;
ChartPlugin := TPSImport_user_charts.Create(Self);
TPSPluginItem(PSScript.Plugins.add).Plugin := ChartPlugin;
try
with PrintDialog do begin
Collate := True;
Copies := 1;
Options := [poPageNums];
end;
except on E: Exception do begin
showmessage(E.Message);
end;
end;
end;
procedure TFEditor.UpdateStatusLine;
begin
SynEditSTStatusChange(FEditor,[scCaretX, scCaretY,scInsertMode,scModified]);
StatusBar.Invalidate;
end;
procedure TFEditor.ProjectSave(FileName: string);
begin
Project.FileName := ExtractFileName(FileName);
SynEditST.Lines.SaveToFile(FileName);
IniPropStorage.WriteString('LastProjectName', Project.FileName);
MemoDescription.Lines.SaveToFile('info.txt');
SynEditST.Modified:=False;
caption := FormEditorCaption + Project.FileName;
UpdateStatusLine;
end;
procedure TFEditor.MenuSaveAsClick(Sender: TObject);
var CurDir: string;
begin
if SaveDialog.initialDir ='' then SaveDialog.initialDir := GetCurrentDir;
SaveDialog.FileName := Project.FileName;
CurDir := GetCurrentDir;
if not SaveDialog.Execute then exit;
SetCurrentDir(CurDir);
ProjectSave(SaveDialog.FileName);
end;
procedure TFEditor.MenuUndoClick(Sender: TObject);
begin
SynEditST.Undo;
end;
procedure TFEditor.MenuRedoClick(Sender: TObject);
begin
SynEditST.Redo;
end;
procedure TFEditor.MenuAboutClick(Sender: TObject);
begin
ShowMessage(SimTwoVersion + crlf + crlf+
'Copyright (C) 2008-2009 Paulo Costa' + crlf + crlf+
'Special thanks to:' + crlf+
'José Luís Lima, José Alexandre Gonçalves,' + crlf+
'Paulo Malheiros, Paulo Marques,' + crlf+
'Armando Sousa, António Paulo Moreira and the' + crlf+
'ODE, GLScene, SynEdit and PascalScript Teams,' + crlf+
crlf+
'Compiled: ' + DateToStr(FileDateToDateTime(FileAge(Application.ExeName))));
end;
procedure TFEditor.MenuFindClick(Sender: TObject);
begin
FindDialog.Execute;
end;
procedure TFEditor.MenuReplaceClick(Sender: TObject);
begin
ReplaceDialog.Execute;
end;
procedure TFEditor.MenuCalculatorClick(Sender: TObject);
//begin
// OpenDocument('Calc.exe'); { *Converted from ShellExecute* }
//end;
var
Process: TProcess;
i: Integer;
begin
Process := TProcess.Create(nil);
try
Process.InheritHandles := False;
Process.Options := [];
Process.ShowWindow := swoShow;
// Copy default environment variables including DISPLAY variable for GUI application to work
for i := 1 to GetEnvironmentVariableCount do
Process.Environment.Add(GetEnvironmentString(I));
Process.Executable := 'Calc.exe';
Process.Execute;
finally
Process.Free;
end;
end;
procedure TFEditor.MenuSaveClick(Sender: TObject);
var CurDir: string;
begin
//FileName:= Project.FileName;
if Project.FileName = 'Untitled' then begin
if SaveDialog.initialDir ='' then SaveDialog.initialDir := GetCurrentDir;
SaveDialog.FileName := Project.FileName;
CurDir := GetCurrentDir;
if not SaveDialog.Execute then exit;
SetCurrentDir(CurDir);
Project.FileName := ExtractFileName(SaveDialog.FileName);
end;
ProjectSave(Project.FileName);
end;
{
procedure TFEditor.FormSave(ProjMemIni : TMemIniFile);
begin
SaveStringsToMemIni(ProjMemIni, 'Main','STText',SynEditST.lines);
ProjMemIni.WriteInteger('Main','ActiveTab',PageControl.ActivePageIndex);
ProjMemIni.WriteInteger('Main','MessagesHeight',max(PageControlBottom.Height,Splitter1.MinSize)); // corrige bug splitter nulo
ProjMemIni.WriteString('Main','ProjectAuthor',Project.Author);
ProjMemIni.WriteString('Main','ProjectComments',Project.Comments);
ProjMemIni.WriteBool('Main','SaveOnRun', CBSaveOnRun.Checked);
SaveFormGeometryToMemIni(ProjMemIni,FEditor);
end;
procedure TFEditor.FormLoad(ProjMemIni : TMemIniFile);
begin
LoadStringsFromMemIni(ProjMemIni, 'Main','STText',SynEditST.lines);
PageControl.ActivePageIndex := ProjMemIni.ReadInteger('Main','ActiveTab',PageControl.ActivePageIndex);
PageControlBottom.Height := ProjMemIni.ReadInteger('Main','MessagesHeight',PageControlBottom.Height);
Project.Author:= ProjMemIni.ReadString('Main','ProjectAuthor',Project.Author);
Project.Comments := ProjMemIni.ReadString('Main','ProjectComments',Project.Comments);
CBSaveOnRun.Checked := ProjMemIni.ReadBool('Main','SaveOnRun', CBSaveOnRun.Checked);
LoadFormGeometryFromMemIni(ProjMemIni,FEditor);
end;
}
procedure TFEditor.MenuNewClick(Sender: TObject);
begin
if SynEditST.Modified then begin
if MessageDlg('Old project was changed.'+crlf+
'Start a new project ?',
mtConfirmation , [mbOk,mbCancel], 0)
= mrCancel then exit;
end;
// ProjectNew;
with Project do begin
FileName:='Untitled';
end;
// EditAuthors.text:='';
// EditDescription.Text:='';
MemoDescription.Text:='';
SynEditST.Modified:=False;
UpdateStatusLine;
caption := FormEditorCaption + Project.FileName;
end;
function TFEditor.ProjectOpen(FileName: string): boolean;
begin
result := false;
if not fileexists(FileName) then exit;
SynEditST.Lines.LoadFromFile(FileName);
Project.FileName := ExtractFileName(FileName);
SynEditST.ReadOnly := false;
SynEditST.Modified := false;
// SynEditST.Modified := (GetCurrentDir + '\' + Project.FileName) <> OpenDialog.FileName;
if FileExists('info.txt') then
MemoDescription.Lines.LoadFromFile('info.txt');
UpdateStatusLine;
Caption := FormEditorCaption + ExtractFileName(Project.FileName);
result := true;
end;
procedure TFEditor.MenuOpenClick(Sender: TObject);
var curdir: string;
begin
if SynEditST.Modified then
if MessageDlg('Project Modified.'+crlf+
'Loading will lose changes since last save.'+crlf+
'Open Project ?',
mtConfirmation , [mbOk,mbCancel], 0)
= mrCancel then exit;
curdir := GetCurrentDir;
if OpenDialog.initialDir ='' then OpenDialog.initialDir := GetCurrentDir;
if not OpenDialog.Execute then exit;
SetCurrentDir(curdir);
{ if not fileexists(OpenDialog.FileName) then exit; // TODO: queixar ao utilizador
SynEditST.Lines.LoadFromFile(OpenDialog.FileName);
SynEditST.ReadOnly:=False;
sname := ExtractFileName(OpenDialog.FileName);
txt := GetCurrentDir + '\' + sname;
SynEditST.Modified := txt <> OpenDialog.FileName;
// SynEditST.Modified := GetCurrentDir + '\' + sname <> OpenDialog.FileName;
with Project do begin
fileName:= sname;
//EditAuthors.text:=Author;
//EditComments.Text:=Comments;
end;
UpdateStatusLine;
Caption := FormEditorCaption+ExtractFileName(Project.FileName);}
if not ProjectOpen(OpenDialog.FileName) then begin
ShowMessage('Could not open File: ' + OpenDialog.FileName);
end;
//if not ProjectOpen(OpenDialog.FileName) then ProjectNew;
end;
procedure TFEditor.MenuRunClick(Sender: TObject);
begin
if not compile then exit;
if CBSaveOnRun.Checked then begin
ProjectSave(Project.FileName);
end;
FParams.RGControlBlock.ItemIndex := 1; // script
ProgCyclesCount := 0;
SynEditST.Refresh;
end;
procedure TFEditor.MenuStopClick(Sender: TObject);
begin
FParams.RGControlBlock.ItemIndex := 0; // none
SynEditST.Refresh;
end;
procedure TFEditor.MenuLocalHelpClick(Sender: TObject);
begin
OpenDocument('funclist.txt'); { *Converted from ShellExecute* }
end;
procedure TFEditor.BuildRegFuncList(Sender: TPSScript);
var i, j, typ: integer;
SaveFunclist: TStringList;
S: string;
begin
FuncList.Clear;
InsertList.Clear;
for i := 0 to Sender.Comp.GetRegProcCount-1 do begin
//procedure Getdecl(decl : TPSParametersDecl; var T,v :string);
s:= Sender.Comp.GetRegProc(i).OrgName;
if (s <> '') and (s[1] <> '_') and (UpperCase(s) <> s) then begin
if Sender.Comp.GetRegProc(i).Decl.Result <> nil then begin
//s := 'function ' + s;
typ := 0;
end else begin
//s := 'procedure ' + s;
typ := 1;
end;
Insertlist.Add(s);
s := s + '(';
for j := 0 to Sender.Comp.GetRegProc(i).Decl.ParamCount - 1 do begin
if j <> 0 then s := s + ' ';
s := s + Sender.Comp.GetRegProc(i).Decl.Params[j].OrgName;
if Sender.Comp.GetRegProc(i).Decl.Params[j].aType <> nil then begin
s := s + ': ' + Sender.Comp.GetRegProc(i).Decl.Params[j].aType.OriginalName;
if j <> Sender.Comp.GetRegProc(i).Decl.ParamCount - 1 then s := s + ';';
end;
end;
if Sender.Comp.GetRegProc(i).Decl.Result <> nil then begin
s := s + '): ' + Sender.Comp.GetRegProc(i).Decl.Result.OriginalName + ';';
end else begin
s := s + ');';
end;
Funclist.AddObject(S, TObject(typ));
end;
end;
//Insertlist.Sort;
//Funclist.Sort;
for i := 0 to Funclist.Count -1 do begin
if PtrUInt(Funclist.Objects[i]) = 1 then begin
Funclist.Strings[i] := ' procedure ' + Funclist.Strings[i];
end else begin
Funclist.Strings[i] := ' function ' + Funclist.Strings[i];
end;
end;
SaveFunclist := TStringList.Create;
try
SaveFunclist.AddStrings(Funclist);
SaveFunclist.SaveToFile('funclist.txt');
finally
SaveFunclist.Free;
end;
end;
procedure TFEditor.BuildRegTypeList(Sender: TPSScript);
var i, j: integer;
SaveList: TStringList;
S: string;
begin
for i := 0 to Sender.Comp.GetTypeCount - 1 do begin
s := Sender.Comp.GetType(i).OriginalName;
if (s <> '') {and (s[1] <> '_') and (UpperCase(s) <> s)} then begin
for j := 0 to Sender.Comp.GetType(i).Attributes.Count - 1 do begin
if j <> 0 then s := s + ' ';
//s := s + Sender.Comp.GetType(i).Attributes.Items[j].AType.OrgName;
if Sender.Comp.GetType(i).Attributes.Items[j].aType <> nil then begin
s := s + ': ' + Sender.Comp.GetType(i).Attributes.Items[j].aType.OrgName;
//if j <> Sender.Comp.GetRegProc(i).Decl.ParamCount - 1 then s := s + ';';
end;
end;
TypeList.Add(s);
end;
end;
TypeList.Sort;
SaveList := TStringList.Create;
try
SaveList.AddStrings(TypeList);
SaveList.SaveToFile('TypeList.txt');
finally
SaveList.Free;
end;
end;
procedure TFEditor.BuildRegTypeListEx(Sender: TPSPascalCompiler);
var i, j: integer;
SaveList: TStringList;
S: string;
begin
//showmessage(inttostr(Sender.FindClass('TTIMER').Items[0].));
//exit;
for i := 0 to Sender.GetTypeCount - 1 do begin
//procedure Getdecl(decl : TPSParametersDecl; var T,v :string);
s := Sender.GetType(i).OriginalName;
if (s <> '') {and (s[1] <> '_') and (UpperCase(s) <> s)} then begin
{if Sender.Comp.GetType(i). Decl.Result <> nil then begin
//s := 'function ' + s;
typ := 0;
end else begin
//s := 'procedure ' + s;
typ := 1;
end;}
//TypeList.Add(s); TPSCompileTimeClass
//Sender.Comp.GetType(i).Attributes.Items[j].
s := s + '(' + inttostr(Sender.GetType(i).Attributes.Count);
for j := 0 to Sender.GetType(i).Attributes.Count - 1 do begin
if j <> 0 then s := s + ' ';
//s := s + Sender.Comp.GetType(i).Attributes.Items[j].AType.OrgName;
if Sender.GetType(i).Attributes.Items[j].aType <> nil then begin
s := s + ': ' + Sender.GetType(i).Attributes.Items[j].aType.OrgName;
//if j <> Sender.Comp.GetRegProc(i).Decl.ParamCount - 1 then s := s + ';';
end;
end;
{if Sender.Comp.GetRegProc(i).Decl.Result <> nil then begin
s := s + '): ' + Sender.Comp.GetRegProc(i).Decl.Result.OriginalName + ';';
end else begin
s := s + ');';
end;
Funclist.AddObject(S, TObject(typ));}
TypeList.Add(s);
end;
end;
TypeList.Sort;
{ for i := 0 to Funclist.Count -1 do begin
if ptruint(Funclist.Objects[i]) = 1 then begin
Funclist.Strings[i] := ' procedure ' + Funclist.Strings[i];
end else begin
Funclist.Strings[i] := ' function ' + Funclist.Strings[i];
end;
end;}
SaveList := TStringList.Create;
try
SaveList.AddStrings(TypeList);
SaveList.SaveToFile('TypeList.txt');
finally
SaveList.Free;
end;
end;
function FillTypes(Sender: TPSPascalCompiler): Boolean;
begin
FEditor.BuildRegTypeListEx(Sender);
result := true;
end;
function random01: double;
begin
result := random;
end;
procedure CloseSimTwo;
begin
FEditor.SimTwoCloseRequested := true;
end;
function ScriptPeriod: double;
begin
result := WorldODE.DecPeriod;
end;
function SqrD(X: double): double;
begin
result := Sqr(X);
end;
function ExpD(X: double): double;
begin
result := exp(X);
end;
function LnD(X: double): double;
begin
result := ln(X);
end;
function FloatAsInteger(X: single): integer;
begin
result := PInteger(@X)^;
end;
function IntegerAsFloat(X: integer): single;
begin
result := PSingle(@X)^;
end;
procedure TFEditor.PSScript_Compile(Sender: TPSScript);
var i: integer;
s: string;
begin
Sender.AddFunction(@arcsin, 'function arcsin(x: Extended): Extended');
Sender.AddFunction(@arccos, 'function arccos(x: Extended): Extended');
Sender.AddFunction(@tan, 'function tan(x: Extended): Extended');
Sender.AddFunction(@ATan2, 'function ATan2(y,x: double): double');
Sender.AddFunction(@ACos2, 'function ACos2(y,x: double): double');
Sender.AddFunction(@ASin2, 'function ASin2(y,x: double): double');
Sender.AddFunction(@Power, 'function Power(const Base, Exponent: Extended): Extended');
Sender.AddFunction(@Log10, 'function Log10(const X: Extended): Extended');
Sender.AddFunction(@LogN, 'function LogN(const Base, X: Extended): Extended');
Sender.AddFunction(@SqrD, 'function Sqr(X: double): double');
Sender.AddFunction(@ExpD, 'function Exp(X: double): double');
Sender.AddFunction(@LnD, 'function Ln(X: double): double');
Sender.AddFunction(@FloatAsInteger, 'function FloatAsInteger(X: single): integer');
Sender.AddFunction(@IntegerAsFloat, 'function IntegerAsFloat(X: integer): single');
Sender.AddFunction(@DiffAngle, 'function DiffAngle(a1,a2: double): double;');
Sender.AddFunction(@Dist, 'function Dist(x,y: double): double');
Sender.AddFunction(@Sign, 'function Sign(a: double): double');
Sender.AddFunction(@Sat, 'function Sat(a,limit: double): double');
Sender.AddFunction(@NormalizeAngle, 'function NormalizeAngle(ang: double): double');
Sender.AddFunction(@TranslateAndRotate, 'function TranslateAndRotate(var rx,ry: double; px,py,tx,ty,teta: double): double');
Sender.AddFunction(@RotateAndTranslate, 'function RotateAndTranslate(var rx,ry: double; px,py,tx,ty,teta: double): double');
Sender.AddFunction(@RotateAroundPoint, 'function RotateAroundPoint(var rx,ry: double; px,py,cx,cy,teta: double): double');
Sender.AddFunction(@RandG, 'function RandG(Mean, StdDev: Extended): Extended;');
Sender.AddFunction(@random01, 'function random01: double;');
Sender.AddFunction(@Randomize, 'procedure Randomize;');
Sender.AddFunction(@BiLinInterp, 'function BiLinInterp(Surf: matrix; xmin, xmax, ymin, ymax, x,y: double): double;');
//Sender.AddFunction(@IntToHex, 'function IntToHex(Value: Int64; Digits: Integer): string;');
Sender.AddFunction(@IntToHex, 'function IntToHex(Value: integer; Digits: Integer): string;');
Sender.AddMethod(Self, @TFEditor.Writeln, 'procedure WriteLn(S: string)');
// Sender.AddMethod(Self, @TFEditor.myformat, 'function Format(const sFormat: string; const Args: array of const): string;');
Sender.AddFunction(@format, 'function Format(const sFormat: string; const Args: array of const): string;');
Sender.AddMethod(Self, @TFEditor.ReadComPort, 'function ReadComPort: string;');
Sender.AddMethod(Self, @TFEditor.WriteComPort, 'procedure WriteComPort(s: string);');
Sender.AddMethod(Self, @TFEditor.ReadUDPData, 'function ReadUDPData: string;');
Sender.AddMethod(Self, @TFEditor.WriteUDPData, 'procedure WriteUDPData(ToIP: string; ToPort: integer; s: string);');
Sender.AddMethod(Self, @TFEditor.ReadUDPPacket, 'function ReadUDPPacket: string;');
Sender.AddMethod(Self, @TFEditor.GetUDPPacketCount, 'function GetUDPPacketCount: integer;');
Sender.AddFunction(@SetRCValue, 'procedure SetRCValue(r, c: integer; s: string);');
Sender.AddFunction(@GetRCValue, 'function GetRCValue(r, c: integer): double;');
Sender.AddFunction(@GetRCText, 'function GetRCText(r, c: integer): string;');
Sender.AddFunction(@RCButtonPressed, 'function RCButtonPressed(r, c: integer): boolean;');
Sender.AddFunction(@RangeToMatrix, 'function RangeToMatrix(r, c, rows, cols: integer): Matrix;');
Sender.AddFunction(@MatrixToRange, 'procedure MatrixToRange(r, c: integer; const M: Matrix);');
Sender.AddFunction(@MatrixToRangeF, 'procedure MatrixToRangeF(r, c: integer; const M: Matrix; FormatString: string);');
Sender.AddFunction(@ClearButtons, 'procedure ClearButtons;');
Sender.AddFunction(@RefreshSheets, 'procedure RefreshSheets;');