-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopfunit.pas
1726 lines (1548 loc) · 44.1 KB
/
opfunit.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 opfunit;
{modification history
completed 4/2/2000
24/2/2000 altered field size on output
patient diameter print only on opposing field 24/2/2000
swapped FSX and FSY fields in output factor ST
increase max SSD to 230 cm
increase max diameter to 50 cm
altered beam file to align fields needed by programs compiled under
Delphi 5
30/5/2001 altered format of output slightly
fixed save bug
fixed variable SSD bug
11/6/2002 added definable expiry date
added reference dose
Automatic date entry added
27/6/2003 add multiple machines
fixed save on close bug
8/8/2003 altered skin dose depth from 0.03 to 0.1
19/8/2003 fixed variable SSD print
fixed update fields before exit
included compensator option
9/2/2004 added initialise with dmax for dose to maximum
10/3/2004 disable TDepth for Single field dose to maximum
8/6/2005 ported to linux using Lazarus and Free Pascal Compiler
Use CRC for integrity verification instead of checksum
Fix exit bug
Help disabled for the moment
21/4/2008 convert to TMR tables
20/6/2008 reduce depth range to 25 to conform with diam of 50
1/2/2011 fixed date format error, fixed various error checks
2/7/2012 added on line help and web help server
10/1/2013 fixed TMR bug on smallest field
16/10/2014 altered output to pdf
17/10/2014 disable compensators
20/10/2014 added status bar and error reporting
added DR no
22/10/2014 set save default to My Documents/Patients
18/11/2014 fixed inconsistent save action and directories
12/7/2016 fixed defines for windows 64 bit
24/4/2019 fixed beam empty cell and data errors
10/7/2019 fix spelling Normalisation
added standard about unit
5/2/2020 remove expiry check
7//2/2020 fix save as file name error
update statusbar messaging system and refactor
implemented login module
17/3/2020 add refresh linac list on beam module exit
24/3/2020 look in program data config dir first for beam file
16/4/2020 fix various mem leaks
3/8/2020 correct title of login module
18/11/2022 fix double free causing exception on new patient
fix special characters in filenames
23/11/2022 convert resunit to form2pdf
24/11/2022 use form2pdf to print
29/11/2022 use Form2PDF to print beamform
27/1/2023 fix overprint of filename in results
30/4/2024 add form location property storage
remove web server
2/5/2024 update about form with version info
11/7/2024 delete webserver variables and hanging unit}
{$mode DELPHI}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Menus,
ExtCtrls, Buttons, StdCtrls, LazHelpHTML, ComCtrls, XMLPropStorage,
FileUtil;
const NE = 5; {maximum number of energies}
SCD = 100; {source calibration distance}
FaintRed: TColor = $7979ff;
FaintYellow: TColor = $cffcff;
FaintGreen: TColor = $e4ffd3;
type
TPrescription = (Tumour, Max); {Tumour dose or Maximum dose}
TPresentation = (AP,Lat); {Anterior/Posterior, Lateral}
TField = (Opposing, Single);
TTech = (FixedSSD,Isocentric, VarSSD); {Fixed SSD 100cm, Isocentric, Variable SSD}
String10 = string[10];
String255 = string[255];
TPatRec = record
Fname :string255; {file name}
PDate :string10; {date of plan}
Pname :string255; {patient name}
DRno :string255; {unique identification number}
Bdate :string10; {patient's birth date}
Diagnosis, {diagnosis of patient}
Comment :string255; {comment about patient}
Prescript: TPrescription; {prescription, tumour or maximum dose}
TDose, {total prescribed dose}
Frac :double; {number of fractions}
Fields :TField; {opposing or single field}
Treatment:TTech; {treatment technique, SSD, isocentric}
Present :TPresentation; {type of presentation, AP or Lat}
Energy :integer; {index of selected energy}
EName :string10; {name of selected energy}
Machine :integer; {index of selected machine}
MName :string10; {name of selected machine}
Comp :boolean; {true for compensator}
CDepth, {compensator depth}
FSX, {X field size}
FSY, {Y field size}
Depth, {treatment depth}
Diam, {patient diameter}
SSD, {source surface distance}
TrayFac, {tray factor}
TableFac, {table factor}
CFac :double; {compensator factor}
Changed :boolean; {true if patient data has changed}
end;
TPatient = class
PatRec :TPatRec; {Patient information}
public
constructor Create; {create and initialise TPatient}
procedure Clear; {clear field of TPatient}
procedure Save; {save patient data}
procedure Open; {load patient data}
end; {of TPatient}
TDmax = array[1..NE] of double; {array for Dmax}
TTable = array[1..NE] of double; {array for factors}
TTray = array[1..NE,1..5] of double; {array for factors}
TTmrArray = array of array of double; {array for TMR values}
Ttmr = array[1..NE] of TTmrArray; {array for TMR parameter}
TOutfac = array[1..NE,1..7] of double; {array for output factors}
String10Arr = array[1..NE] of String10;
TLinacRec = record
CheckSum :dword; {verify integrity of data file}
Title :string255; {name of installation}
Name :string10; {accelerator name}
NoE :integer; {number of photon energies available}
Energy :String10Arr; {photon energies available}
Table :TTable; {table factors for each energy}
Tray :TTray; {Tray factors for each energy}
DM :TDmax; {dmax of each energy}
S :TOutfac; {regression coefficients for output factors}
EDate :TDateTime; {program expiry date}
end;
TLinac = class
LinacRec :TLinacRec; {Linac data}
public
constructor Create; {create and initialise Linac}
end; {of Tlinac}
{ TOPFForm }
TOPFForm = class(TForm)
cbTTech: TComboBox;
cbType: TComboBox;
cbFields: TComboBox;
cbTTechcbMachine: TComboBox;
cbMachine: TComboBox;
cbEnergy: TComboBox;
cbPresentation: TComboBox;
cbTrayFac: TComboBox;
cbTableFac: TComboBox;
ebPName: TEdit;
ebDiag: TEdit;
ebComment: TEdit;
ebDate: TEdit;
ebBdate: TEdit;
ebTDose: TEdit;
ebNFrac: TEdit;
ebFSY: TEdit;
ebFSX: TEdit;
ebDiam: TEdit;
ebTDepth: TEdit;
ebSSD: TEdit;
ebWedge: TEdit;
ebDRNo: TEdit;
gbParticulars: TGroupBox;
gbPrescription: TGroupBox;
gbParameters: TGroupBox;
HTMLBrowserHelpViewer: THTMLBrowserHelpViewer;
HTMLHelpDatabase: THTMLHelpDatabase;
ImageList: TImageList;
Label1: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label2: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
Label28: TLabel;
Label29: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
MenuItem2: TMenuItem;
miManage: TMenuItem;
miResetP: TMenuItem;
miAddUser: TMenuItem;
miSettings: TMenuItem;
MainMenu1: TMainMenu;
MenuItem1: TMenuItem;
ExitMenu: TMenuItem;
miAbout: TMenuItem;
miTut: TMenuItem;
miContents: TMenuItem;
miHelp: TMenuItem;
NewMenu: TMenuItem;
MenuItem3: TMenuItem;
OpenDialog: TOpenDialog;
OpenMenu: TMenuItem;
CalcMenu: TMenuItem;
SaveDialog: TSaveDialog;
SaveMenu: TMenuItem;
SaveAsMenu: TMenuItem;
MenuItem9: TMenuItem;
StatusBar: TStatusBar;
StatusMessages: TStringList;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ToolButton9: TToolButton;
XMLPropStorage: TXMLPropStorage;
procedure miAddUserClick(Sender: TObject);
procedure miManageClick(Sender: TObject);
procedure miResetPClick(Sender: TObject);
procedure StatusBarDrawPanel(SBar: TStatusBar;Panel: TStatusPanel; const Rect: TRect);
procedure OPFError(sError:string);
procedure OPFWarning(sWarn:string);
procedure OPFMessage(sMess:string);
procedure ClearStatus;
procedure CalcMenuClick(Sender: TObject);
procedure EnableFields;
procedure DisableFields;
procedure ExitMenuClick(Sender: TObject);
procedure miAboutClick(Sender: TObject);
procedure miContentsClick(Sender: TObject);
procedure miTutClick(Sender: TObject);
procedure NewMenuClick(Sender: TObject);
procedure OPFFormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure OPFFormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure OpenMenuClick(Sender: TObject);
procedure ReadLinac(FileName:string);
procedure ListLinacs;
procedure OPFFormCreate(Sender: TObject);
procedure PutData(var PatRec:TPatRec);
function GetData(var PatRec:TPatRec):boolean;
function SaveAsMenuClick(Sender: TObject):boolean;
procedure SaveMenuClick(Sender: TObject);
procedure cbEnergyChange(Sender: TObject);
procedure cbFieldsExit(Sender: TObject);
procedure cbMachineChange(Sender: TObject);
procedure cbPresentationExit(Sender: TObject);
procedure cbTTechChange(Sender: TObject);
procedure cbTableFacExit(Sender: TObject);
procedure cbTrayFacExit(Sender: TObject);
procedure cbTypeExit(Sender: TObject);
procedure ebDiamExit(Sender: TObject);
procedure ebFSXExit(Sender: TObject);
procedure ebFSYExit(Sender: TObject);
procedure ebNFracExit(Sender: TObject);
procedure ebPNameChange(Sender: TObject);
procedure ebSSDExit(Sender: TObject);
procedure ebTDepthExit(Sender: TObject);
procedure ebTDoseExit(Sender: TObject);
procedure ebWedgeExit(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
function ToAlphaNum(TheString:string):string;
var
OPFForm :TOPFForm;
Pat :TPatient;
Linac :TLinac;
TMR :TTmr;
Fault :boolean;
implementation
uses beamunit, loginunit, CRC32,resunit2, helpintfs, aboutunit, LazFileUtils;
function ToAlphaNum(TheString:string):string;
{Eliminates everthing except alphanumeric characters from a string}
var Character: char;
begin
Result := '';
for Character in TheString do
if Character in ['0'..'9','A'..'Z','a'..'z'] then
Result := Result + Character;
end;
{TPatient}
constructor TPatient.Create;
{Create and initialise TPatient}
begin
inherited Create;
Clear;
end;
procedure TPatient.Clear;
{Clear the fields of TPatient}
begin
with PatRec do
begin
Fname := '';
PDate := DateToStr(Now);
Pname := '';
DRNo := '';
Bdate := '';
Diagnosis := '';
Comment := '';
Prescript := Tumour;
TDose := 0;
Frac := 0;
Fields := Opposing;
Treatment := Isocentric;
Present := AP;
Energy := 1;
EName := '';
Machine := 1;
MName := '';
Comp := false;
CDepth := 0;
FSX := 0;
FSY := 0;
Depth := 0;
Diam := 0;
SSD := 100;
TrayFac := 1;
TableFac := 1;
CFac := 1;
Changed := False;
end;
end;
procedure TPatient.Save;
{This procedure saves the patient data.}
var Outfile :file of TPatRec;
begin
if Pat <> nil then
begin
AssignFile(Outfile,Pat.PatRec.Fname);
Rewrite(Outfile);
Write(Outfile,Pat.PatRec);
CloseFile(Outfile);
end;
end;
procedure TPatient.Open;
{This procedure loads the patient data.}
var Infile :file of TPatRec;
begin
Assignfile(Infile,Pat.PatRec.Fname);
Reset(Infile);
Read(Infile,Pat.PatRec);
CloseFile(Infile);
end;
{TLinac}
constructor TLinac.Create;
{Create and initialise TLinac}
var I,J :integer;
begin
inherited Create;
with LinacRec do
begin
Title := '';
Name := '';
NoE := 0;
EDate := 0;
for I:=1 to NE do
begin
Energy[I] := '';
DM[I] := 0;
Table[I] := 0;
for J:=1 to 5 do Tray[I,J] := 0;
for J:=1 to 7 do S[I,J] := 0;
Setlength(TMR[I],0);
end;
end;
end;
{ TOPFForm }
procedure TOpfForm.StatusBarDrawPanel(SBar: TStatusBar;Panel: TStatusPanel;
const Rect: TRect);
{Workaround for consistent colour panel on windows and linux}
begin
with SBar.Canvas do
begin
Brush.Color := StatusBar.Color;
FillRect(Rect);
TextRect(Rect,2 + Rect.Left, 1 + Rect.Top,Panel.Text) ;
end;
end;
procedure TOPFForm.miManageClick(Sender: TObject);
var BeamForm :TBeamForm;
Current :string;
begin
ClearStatus;
Current := cbMachine.Text;
try
BeamForm := TBeamForm.Create(self);
BeamForm.ShowModal;
finally
BeamForm.Free;
end;
ListLinacs;
cbMachine.ItemIndex := cbMachine.Items.IndexOf(Current);
if cbMachine.ItemIndex < 0 then
begin
OPFError('Could not find previous machine.');
cbMachine.ItemIndex := 0;
end;
ReadLinac(cbMachine.Items[cbMachine.ItemIndex]);
end;
procedure TOPFForm.miResetPClick(Sender: TObject);
var LoginForm :TLoginForm;
begin
try
LoginForm := TLoginForm.Create(self);
LoginForm.bbEnter.Caption := 'Reset' + LineEnding + 'Password';
LoginForm.bbEnter.OnClick := LoginForm.ResetPass;
LoginForm.ShowModal;
finally
LoginForm.Free;
end;
end;
procedure TOPFForm.miAddUserClick(Sender: TObject);
var LoginForm :TLoginForm;
begin
try
LoginForm := TLoginForm.Create(self);
LoginForm.bbEnter.Caption := 'Add User';
LoginForm.bbEnter.OnClick := LoginForm.AddUser;
LoginForm.ShowModal;
finally
LoginForm.Free;
end;
end;
procedure TOpfForm.OPFError(sError:string);
begin
StatusBar.Panels[0].Text := sError;
StatusBar.Color := FaintRed;
StatusMessages.Add(StatusBar.Panels[0].Text);
StatusBar.Hint := StatusMessages.Text;
end;
procedure TOpfForm.OPFWarning(sWarn:string);
begin
StatusBar.Panels[0].Text := sWarn;
StatusBar.Color := FaintYellow;
StatusMessages.Add(StatusBar.Panels[0].Text);
StatusBar.Hint := StatusMessages.Text;
end;
procedure TOpfForm.OPFMessage(sMess:string);
begin
StatusBar.Panels[0].Text := sMess;
StatusBar.Color := FaintGreen;
StatusMessages.Add(StatusBar.Panels[0].Text);
StatusBar.Hint := StatusMessages.Text;
end;
procedure TOpfForm.ClearStatus;
begin
StatusBar.Panels[0].Text := '';
StatusBar.Color := clDefault;
end;
procedure TOpfForm.ReadLinac(FileName:string);
var I,J,K,
Size,
TMRL,
TMRW :integer;
CRCValue :dword;
sExePath,
sDataPath :string;
Infile :TextFile;
begin
{Set directory path to program files}
{$ifdef WINDOWS}
sDataPath := GetAppConfigDir(true);
{$else}
sDataPath := GetAppConfigDir(false);
{$endif}
sDataPath := AppendPathDelim(sDataPath) + FileName + '.bdf';
sExePath := ExtractFilePath(Application.ExeName);
sExePath := AppendPathDelim(sExePath) + FileName + '.bdf';
{create and read linac data}
Fault := false;
if Linac <> nil then
begin
Linac.Free;
Linac := nil;
end;
Linac := TLinac.Create;
with Linac.LinacRec do
begin
{read data from disk}
try
if FileExists(sDataPath) then
AssignFile(Infile,sDataPath)
else
AssignFile(Infile,sExePath);
Reset(Infile);
Readln(Infile,Checksum);
Readln(Infile,Title);
Readln(Infile,Name);
Readln(Infile,NoE);
Readln(Infile,EDate);
for I:=1 to NoE do
begin
Readln(Infile,Energy[I]);
Readln(Infile,DM[I]);
Readln(Infile,Table[I]);
for J:=1 to 5 do Read(Infile,Tray[I,J]);
for J:=1 to 7 do Read(Infile,S[I,J]);
Readln(Infile,TMRL);
Readln(Infile,TMRW);
SetLength(TMR[I],TMRL);
for J:=0 to TMRL - 1 do
begin
SetLength(TMR[I,J],TMRW);
for K:=0 to TMRW - 1 do
Read(Infile,TMR[I,J,K]);
end;
Readln(Infile);
end;
CloseFile(Infile);
except
Fault := true;
OPFError('File error, could not read data file');
DisableFields;
end;
end;
if FileName <> Linac.LinacRec.Name then
begin
Fault := true;
OPFError('Integrity of the beam data file has been'
+ ' compromised. Please select another accelerator.');
DisableFields;
end;
{Check if use limit of beam data has expired}
{if Now > Linac.LinacRec.EDate then
begin
Fault := true;
StatusBar.SimpleText := 'The use limit of this data has expired. '
+ 'Please contact the authors to obtain an updated copy.';
StatusBar.Color := clRed;
StatusMessages.Add(StatusBar.SimpleText);
StatusBar.Hint := StatusMessages.Text;
DisableFields;
end; }
with Linac.LinacRec do
begin
{check integrity}
{create CRC value}
CRCValue := $FFFFFFFF;
Size := SizeOf(Title);
CalcCRC32(@Title,Size,CRCValue);
Size := SizeOf(Name);
CalcCRC32(@Name,Size,CRCValue);
Size := SizeOf(NoE);
CalcCRC32(@NoE,Size,CRCValue);
Size := SizeOf(Energy);
CalcCRC32(@Energy,Size,CRCValue);
Size := SizeOf(Table);
CalcCRC32(@Table,Size,CRCValue);
Size := SizeOf(Tray);
CalcCRC32(@Tray,Size,CRCValue);
Size := SizeOf(DM);
CalcCRC32(@DM,Size,CRCValue);
Size := SizeOf(S);
CalcCRC32(@S,Size,CRCValue);
Size := SizeOf(EDate);
CalcCRC32(@EDate,Size,CRCValue);
for I:=1 to NoE do
for J:=0 to Length(TMR[I]) - 1 do
begin
Size := Length(TMR[I,J])*SizeOf(double);
CalcCRC32(@TMR[I,J,0],Size,CRCValue);
end;
if CRCValue <> Linac.LinacRec.CheckSum then
begin
Fault := true;
OPFError('Integrity of the beam data file has been'
+ ' compromised. Please select another accelerator.');
DisableFields;
end;
{transfer data to OpfForm}
if not Fault then
begin
OpfForm.Caption := Title;
CBEnergy.Items.Clear;
for I:=1 to NoE do CBEnergy.Items.Add(Energy[I]);
CBEnergy.ItemIndex := 0;
CBTableFac.Items.Clear;
CBTableFac.Items.Add('1');
CBTableFac.Items.Add(FloatToStr(Table[1]));
CBTableFac.ItemIndex := 0;
CBTrayFac.Items.Clear;
I := 1;
while (Tray[1,I] <> 0) and (I <= 5) do
begin
CBTrayFac.Items.Add(FloatToStr(Tray[1,I]));
Inc(I);
end;
CBTrayFac.ItemIndex := 0;
if (CBType.ItemIndex = 1) and (CBFields.ItemIndex = 1) then
ebTDepth.Text := FloatToStr(DM[CBEnergy.ItemIndex + 1]);
ClearStatus;
EnableFields;
end;
end;
end;
procedure TOPFForm.ListLinacs;
var SearchRec :TSearchRec;
sExePath,
sDataPath,
FileName :string;
begin
CBMachine.Items.Clear;
{first look in data dir where config files should be stored}
{$ifdef WINDOWS}
sDataPath := GetAppConfigDir(true);
{$else}
sDataPath := GetAppConfigDir(false);
{$endif}
sDataPath := AppendPathDelim(sDataPath) + '*.bdf';
if FindFirst(sDataPath,0,SearchRec) = 0 then
repeat
FileName := ExtractFileName(SearchRec.Name);
FileName := Copy(FileName,1,length(FileName) - 4);
CBMachine.Items.Add(FileName);
until FindNext(SearchRec)<>0
else
begin {else look in exe dir where beam files were stored}
sExePath := ExtractFilePath(Application.ExeName);
sExePath := AppendPathDelim(sExePath) + '*.bdf';
if FindFirst('*.bdf',0,SearchRec) = 0 then
repeat
FileName := ExtractFileName(SearchRec.Name);
FileName := Copy(FileName,1,length(FileName) - 4);
CBMachine.Items.Add(FileName);
until FindNext(SearchRec) <> 0;
end;
FindClose(SearchRec);
end;
procedure TOPFForm.OPFFormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
if Pat <> nil then Pat.Free;
OpenDialog.Destroy;
StatusMessages.Free;
Linac.Free;
end;
procedure TOpfForm.EnableFields;
begin
ebPName.Enabled := True;
ebPName.Color := clWindow;
ebDate.Enabled := True;
ebDate.Color := clWindow;
ebDate.Text := FormatDateTime('d mmmm yyyy', Now);
ebDRNo.Enabled := true;
ebDRNo.Color := clWindow;
ebDiag.Enabled := True;
ebDiag.Color := clWindow;
ebComment.Enabled := True;
ebComment.Color := clWindow;
ebBDate.Enabled := True;
ebBDate.Color := clWindow;
CBType.Enabled := True;
CBType.Color := clWindow;
ebTDose.Enabled := True;
ebTDose.Color := clWindow;
ebNFrac.Enabled := True;
ebNFrac.Color := clWindow;
CBFields.Enabled := True;
CBFields.Color := clWindow;
CBTTech.Enabled := True;
CBTTech.Color := clWindow;
CBPresentation.Enabled := True;
CBPresentation.Color := clWindow;
CBEnergy.Enabled := True;
CBEnergy.Color := clWindow;
CBMachine.Enabled := True;
CBMachine.Color := clWindow;
ebFSX.Enabled := True;
ebFSX.Color := clWindow;
ebFSY.Enabled := True;
ebFSY.Color := clWindow;
ebTDepth.Enabled := True;
ebTDepth.Color := clWindow;
ebDiam.Enabled := True;
ebDiam.Color := clWindow;
ebSSD.Enabled := True;
ebSSD.Color := clWindow;
CBTrayFac.Enabled := True;
CBTrayFac.Color := clWindow;
CBTableFac.Enabled := True;
CBTableFac.Color := clWindow;
ebWedge.Enabled := True;
ebWedge.Color := clWindow;
cbFieldsExit(Self);
cbPresentationExit(Self);
cbTTechChange(Self);
end;
procedure TOpfForm.DisableFields;
begin
ebPName.Enabled := false;
ebPName.Color := clWindow;
ebDate.Enabled := false;
ebDate.Color := clWindow;
ebDRNo.Enabled := false;
ebDRNo.Color := clWindow;
ebDiag.Enabled := false;
ebDiag.Color := clWindow;
ebComment.Enabled := false;
ebComment.Color := clWindow;
ebBDate.Enabled := false;
ebBDate.Color := clWindow;
CBType.Enabled := false;
CBType.Color := clWindow;
ebTDose.Enabled := false;
ebTDose.Color := clWindow;
ebNFrac.Enabled := false;
ebNFrac.Color := clWindow;
CBFields.Enabled := false;
CBFields.Color := clWindow;
CBTTech.Enabled := false;
CBTTech.Color := clWindow;
CBPresentation.Enabled := false;
CBPresentation.Color := clWindow;
CBEnergy.Enabled := false;
CBEnergy.Color := clWindow;
CBMachine.Enabled := True;
CBMachine.Color := clWindow;
ebFSX.Enabled := false;
ebFSX.Color := clWindow;
ebFSY.Enabled := false;
ebFSY.Color := clWindow;
ebTDepth.Enabled := false;
ebTDepth.Color := clWindow;
ebDiam.Enabled := false;
ebDiam.Color := clWindow;
ebSSD.Enabled := false;
ebSSD.Color := clWindow;
CBTrayFac.Enabled := false;
CBTrayFac.Color := clWindow;
CBTableFac.Enabled := false;
CBTableFac.Color := clWindow;
ebWedge.Enabled := false;
ebWedge.Color := clWindow;
end;
procedure TOPFForm.CalcMenuClick(Sender: TObject);
var ResForm :TResForm2;
sDataDir,
sTemp :string;
begin
if (Pat <> nil) and GetData(Pat.PatRec) then
begin
try
sDataDir := GetUserDir;
{$ifdef WINDOWS}
sDataDir := AppendPathdelim(sDataDir) + 'My Documents';
{$else}
sDataDir := AppendPathdelim(sDataDir) + 'Documents';
{$endif}
sDataDir := AppendPathdelim(sDataDir) + 'Patients';
if not DirectoryExists(sDataDir) then CreateDir(sDataDir);
sDataDir := AppendPathdelim(sDataDir) + 'temp';
if not DirectoryExists(sDataDir) then CreateDir(sDataDir);
sTemp := Pat.PatRec.FName;
Pat.PatRec.FName := AppendPathDelim(sDataDir) + FormatDateTime('yyyymmddHHMMss',Now) +
ToAlphaNum(Pat.PatRec.Pname) + ToAlphaNum(Pat.PatRec.DRNo) + '.pnt';
Pat.Save;
Pat.PatRec.FName := sTemp;
except
OPFError('Could not write temp file!');
end;
ResForm := TResForm2.Create(Self);
ResForm.ShowModal;
ResForm.Free;
end;
end;
procedure TOPFForm.ExitMenuClick(Sender: TObject);
begin
close;
end;
procedure TOPFForm.miAboutClick(Sender: TObject);
var AboutFrm :TAboutForm;
begin
AboutFrm := TAboutForm.Create(self);
AboutFrm.ShowModal;
AboutFrm.Free;
end;
procedure TOPFForm.miContentsClick(Sender: TObject);
begin
ShowHelpOrErrorForKeyword('','HTML/OPFHelp.html');
end;
procedure TOPFForm.miTutClick(Sender: TObject);
begin
ShowHelpOrErrorForKeyword('','HTML/OPFHelp7.html');
end;
procedure TOPFForm.NewMenuClick(Sender: TObject);
var Action :boolean;
begin
Action := true;
if Pat <> nil then
if Pat.PatRec.Changed then
case MessageDlg('Save patient?',mtConfirmation,[mbYes,mbNo,mbCancel],0) of
mrYes:begin
Action := SaveAsMenuClick(Sender);
end;
mrNo :;
mrCancel :Action := False;
end;
if Action then
begin
Pat.Free;
Pat := TPatient.Create;
EnableFields;
PutData(Pat.PatRec);
Pat.PatRec.Changed := False;
ebPName.SetFocus;
Application.ProcessMessages
end;
end;
procedure TOPFForm.OPFFormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
CanClose := False;
if Pat <> nil then
begin
if Pat.PatRec.Changed then
case MessageDlg('Save patient?',mtConfirmation,[mbYes,mbNo,mbCancel],0) of
mrYes: begin
if SaveAsMenuClick(Sender) then CanClose := true;
end;
mrNo: CanClose := True;
end
else
CanClose := True;
end
else
CanClose := True;
end;
procedure TOPFForm.OpenMenuClick(Sender: TObject);
var Action :boolean;
sDataDir :string;
begin
Action := true;
if Pat <> nil then
if Pat.PatRec.Changed then
case MessageDlg('Save patient?',mtConfirmation,[mbYes,mbNo,mbCancel],0) of
mrYes:begin
Action := SaveAsMenuClick(Sender);
end;
mrNo:;
mrCancel:Action := False;
end;
if Action then
begin
try
sDataDir := GetUserDir;
{$ifdef WINDOWS}
sDataDir := AppendPathdelim(sDataDir) + 'My Documents';
{$else}
sDataDir := AppendPathdelim(sDataDir) + 'Documents';
{$endif}
sDataDir := AppendPathdelim(sDataDir) + 'Patients';
if not DirectoryExists(sDataDir) then CreateDir(sDataDir);
sDataDir := AppendPathdelim(sDataDir) + FormatDateTime('yyyy',Date);
if not DirectoryExists(sDataDir) then CreateDir(sDataDir);
sDataDir := AppendPathdelim(sDataDir) + FormatDateTime('mmMMMM',Date);
if not DirectoryExists(sDataDir) then CreateDir(sDataDir);
OpenDialog.InitialDir := sDataDir;
except
OPFError('Could not create patient directory');
end;
if OpenDialog.Execute then
begin
try
Pat.Free;
Pat := TPatient.Create;
Pat.PatRec.Fname := OpenDialog.FileName;
Pat.Open;
EnableFields;
ebPName.SetFocus;
Application.ProcessMessages;
PutData(Pat.PatRec);
Pat.PatRec.Changed := False;
except
OPFError('Could not open patient!');
end;
end;