-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitChainEditorMin.pas
3399 lines (3285 loc) · 229 KB
/
UnitChainEditorMin.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 UnitChainEditorMin;
{$IFDEF FPC}
{$MODE Delphi}{$H+}
{$ENDIF}
interface
uses
{$IFnDEF FPC}
Mask, Windows,
{$ELSE}
MaskEdit, LCLIntf, LCLType, //LMessages,
{$ENDIF}
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, ComCtrls, Grids, Buttons, BKStringGrid,
Menus, ExtDlgs;
type
{ T_FormChainEditor }
T_FormChainEditor = class(TForm)
BitBtnDelLastTimeInterval: TButton;
BitBtnNewTimeInterval: TButton;
ButtonExcelExport: TButton;
CopyStateNames: TMenuItem;
EditSumTotalTimeRO: TEdit;
EditSumTotalPowerMultTimeRO: TEdit;
ItemAddStateChilds: TMenuItem;
ItemHidefissionlinks: TMenuItem;
ItemSaveCADimage: TMenuItem;
ItemShowCrossSections: TMenuItem;
ItemShowHalfLifes: TMenuItem;
ItemShowRI: TMenuItem;
ItemUseCumYieldsForState: TMenuItem;
ItemUseIndYieldsForState: TMenuItem;
ItemZoomIn: TMenuItem;
ItemZoomOut: TMenuItem;
Label6: TLabel;
LinkPopupItemUseCumYieldForLink: TMenuItem;
LinkPopupItemUseIndYieldForLink: TMenuItem;
PopupMenuCAD: TPopupMenu;
PopupMenuLink: TPopupMenu;
SaveCadImageDialog: TSavePictureDialog;
SaveDialog: TSaveDialog;
OpenDialog: TOpenDialog;
PageControl: TPageControl;
TabSheetChainEditor: TTabSheet;
TabSheetConditions: TTabSheet;
LabelChainFileName: TLabel;
TabSheetTimes: TTabSheet;
TabSheetCalc: TTabSheet;
TabSheetAnswers: TTabSheet;
LabelTimesFileName: TLabel;
ScrollBoxTimes: TScrollBox;
PanelTimesCommon: TPanel;
BitBtnApplyAllTimes: TBitBtn;
ButtonTimesFileSave: TButton;
ButtonTimesFileOpen: TButton;
PanelCalcRight: TPanel;
MemoCalculatorStdOut: TMemo;
TabSheetSpectra: TTabSheet;
GroupBox1: TGroupBox;
Memo1: TMemo;
PanelChainBottom: TPanel;
StringGridStateLink: TBKStringGrid;
SplitterHorzChainEdit: TSplitter;
PanelChainEditBig: TPanel;
ScrollBoxCAD: TScrollBox;
Image: TImage;
LabelSolverStdOut: TLabel;
SplitterCalcPage: TSplitter;
PanelChainRightBottom: TPanel;
ButtonLookInOOB: TButton;
ButtonToChain: TButton;
SpeedButtonInfo: TSpeedButton;
Panel1: TPanel;
CheckBox1: TCheckBox;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Edit5: TEdit;
ButtonTestChain: TButton;
StringGridAnswers: TStringGrid;
StringGridResults: TStringGrid;
ScrollBoxConditions: TScrollBox;
PanelDepressionSSK: TPanel;
GroupBoxDepression: TGroupBox;
LabelDepressionVolume: TLabel;
LabelDeplessionL: TLabel;
CheckBoxDepression: TCheckBox;
EditDepressionVolume: TEdit;
EditDepressionL: TEdit;
GroupBoxSSKinitial: TGroupBox;
GroupBoxRAs: TGroupBox;
PanelRAs: TPanel;
LabelRA_V: TLabel;
LabelRA_M: TLabel;
LabelNperCM3: TLabel;
EditRA_V: TEdit;
EditRA_M: TEdit;
ButtonLoadResPar: TButton;
ButtonRA_FillDefaults: TButton;
GroupBoxMM: TGroupBox;
LabelMM_V: TLabel;
LabelMM_M: TLabel;
EditMM_V: TEdit;
EditMM_M: TEdit;
ButtonSaveMM: TButton;
ButtonLoadMM: TButton;
StringGridMM: TBKStringGrid;
GroupBoxOM: TGroupBox;
LabelOM_V: TLabel;
LabelOM_M: TLabel;
StringGridOM: TBKStringGrid;
EditOM_V: TEdit;
EditOM_M: TEdit;
ButtonLoadOM: TButton;
ButtonSaveOM: TButton;
PaneRA_Top: TPanel;
PanelBlock: TGroupBox;
LabelVblock: TLabel;
LabelSkin_V: TLabel;
LabelBlock_M: TLabel;
LabelSkin_M: TLabel;
LabelLmean4SSK: TLabel;
LabelTemperature4SSK: TLabel;
LabelUnits_MV: TLabel;
RadioGroupCellType: TRadioGroup;
EditTemperature: TEdit;
EditBlock_V: TEdit;
EditSkin_V: TEdit;
EditBlock_M: TEdit;
EditSkin_M: TEdit;
Editl_mean: TEdit;
CheckBoxSSKconsider: TCheckBox;
ButtonBuildResTable: TButton;
ButtonLoadResTable: TButton;
ButtonSaveResTable: TButton;
GroupBoxInitialValues: TGroupBox;
GroupBoxInitialWhat: TGroupBox;
RadioButtonNuclei: TRadioButton;
RadioButtonMasses: TRadioButton;
StringGridMasses: TStringGrid;
StringGridInitialValues: TBKStringGrid;
CheckBoxPercent: TCheckBox;
ScrollBox1: TScrollBox;
PanelAnswers: TPanel;
RadioGroupAnswers: TRadioGroup;
RadioGroupActivityUnits: TRadioGroup;
CheckBoxAnswersA_Z: TCheckBox;
CheckBoxSaveSlow: TCheckBox;
PanelCalcTop: TScrollBox;
ProgressBarCalc: TProgressBar;
CheckBoxDLL: TCheckBox;
CheckBoxJAC: TCheckBox;
ButtonCalc: TButton;
ButtonAbortCalc: TButton;
RadioGroupSolver: TGroupBox;
RadioButtonVODE: TRadioButton;
RadioButtonLSODA: TRadioButton;
RadioButtonRADAU: TRadioButton;
RadioButtonMEBDF: TRadioButton;
PanelChainRight: TScrollBox;
ButtonRepaint: TButton;
ButtonClearChainEditor: TButton;
ProgressBarLoad: TProgressBar;
GroupBoxStates: TGroupBox;
EditState: TEdit;
CheckBoxBuildLinks: TCheckBox;
ButtonAddState: TButton;
ButtonDeleteState: TButton;
ComboBoxStates: TComboBox;
CheckBoxCapture: TCheckBox;
CheckBoxFission: TCheckBox;
CheckBoxDecay: TCheckBox;
CheckBoxThreshold: TCheckBox;
BitBtnEditAddStatesList: TBitBtn;
GroupBoxLinks: TGroupBox;
LabelStart4Link: TLabel;
LabelEnd4Link: TLabel;
ButtonAddLink: TButton;
ComboBoxLinks: TComboBox;
ButtonDeleteLink: TButton;
EditLinkStart: TComboBox;
EditLinkFinish: TComboBox;
ButtonSaveChain: TButton;
ButtonLoadChain: TButton;
ButtonLoadDB: TButton;
CheckBoxTimesAutoApply: TCheckBox;
ButtonSaveSSKconditions: TButton;
ButtonLoadSSKconditions: TButton;
PanelMassButtons: TPanel;
LabelTotalMass: TLabel;
EditTotalMass: TEdit;
ButtonLoadInitials: TButton;
ButtonSaveInitials: TButton;
StringGridRA_Rs: TStringGrid;
StringGridGroupUpKeV: TStringGrid;
PanelSpectraBottom: TPanel;
ButtonCalcSpectra: TButton;
RadioGroupSpectraWhat: TRadioGroup;
StringGridSpectra: TStringGrid;
CheckBoxSpectraPercent: TCheckBox;
CheckBoxSpectraGasFPonly: TCheckBox;
procedure FormCreate(Sender: TObject);
procedure ButtonRepaintClick(Sender: TObject);
procedure ButtonAddStateClick(Sender: TObject);
procedure ButtonClearChainEditorClick(Sender: TObject);
procedure ButtonLoadDBClick(Sender: TObject);
procedure ImageMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
procedure ButtonAddLinkClick(Sender: TObject);
procedure ComboBoxStatesChange(Sender: TObject);
procedure ButtonDeleteStateClick(Sender: TObject);
procedure ButtonDeleteLinkClick(Sender: TObject);
procedure ComboBoxLinksChange(Sender: TObject);
procedure ButtonLookInOOBClick(Sender: TObject);
procedure ButtonToChainClick(Sender: TObject);
procedure ButtonSaveChainClick(Sender: TObject);
procedure ButtonLoadChainClick(Sender: TObject);
procedure EditStateKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
procedure BitBtnApplyAllTimesClick(Sender: TObject);
procedure TimesChange(Sender: TObject);
procedure BitBtnNewTimeIntervalClick(Sender: TObject);
procedure BitBtnDelLastTimeIntervalClick(Sender: TObject);
procedure ButtonTimesFileSaveClick(Sender: TObject);
procedure ButtonTimesFileOpenClick(Sender: TObject);
procedure TabSheetConditionsShow(Sender: TObject);
procedure RadioButtonMassesNucleiClick(Sender: TObject);
procedure ButtonTestCalcClick(Sender: TObject);
procedure RadioGroupAnswersClick(Sender: TObject);
procedure RadioGroupActivityUnitsClick(Sender: TObject);
procedure TabSheetAnswersShow(Sender: TObject);
procedure ButtonLoadResParClick(Sender: TObject);
procedure TabSheetCalcShow(Sender: TObject);
procedure ButtonSaveMMClick(Sender: TObject);
procedure ButtonSaveOMClick(Sender: TObject);
procedure ButtonLoadMMClick(Sender: TObject);
procedure ButtonLoadOMClick(Sender: TObject);
procedure ButtonRA_FillDefaultsClick(Sender: TObject);
procedure ButtonLoadResTableClick(Sender: TObject);
procedure ButtonSaveResTableClick(Sender: TObject);
procedure StringGridMMKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
procedure ButtonBuildResTableClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
procedure StringGridInitialValuesUserChangedCell(Sender: TObject; ACol, ARow: integer; const Value: string);
procedure ButtonLoadInitialsClick(Sender: TObject);
procedure ButtonSaveInitialsClick(Sender: TObject);
procedure ButtonExcelExportClick(Sender: TObject);
procedure EditLinkStartEndChange(Sender: TObject);
procedure CheckBoxAnswersA_ZClick(Sender: TObject);
procedure StringGridAnswersColumnMoved(Sender: TObject; FromIndex, ToIndex: integer);
procedure EditTotalMassChange(Sender: TObject);
procedure CopyStateNamesClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure StringGridRA_RsDblClick(Sender: TObject);
procedure StringGridRA_RsSelectCell(Sender: TObject; ACol, ARow: integer; var CanSelect: boolean);
procedure RadioGroupSolverClick(Sender: TObject);
procedure ButtonCalcClick(Sender: TObject);
procedure RadioGroupCellTypeClick(Sender: TObject);
procedure StringGridStateLinkUserChangedCell(Sender: TObject; ACol, ARow: integer; const Value: string);
procedure BitBtnEditAddStatesListClick(Sender: TObject);
procedure ItemShowHalfLifesClick(Sender: TObject);
procedure CheckBoxBuildLinksClick(Sender: TObject);
procedure ItemHidefissionlinksClick(Sender: TObject);
procedure ItemUseIndYieldsForStateClick(Sender: TObject);
procedure PopupMenuCADPopup(Sender: TObject);
procedure ItemZoomInClick(Sender: TObject);
procedure ItemZoomOutClick(Sender: TObject);
procedure ItemSaveCADimageClick(Sender: TObject);
procedure ItemShowCrossSectionsClick(Sender: TObject);
procedure ItemShowRIClick(Sender: TObject);
procedure SpeedButtonInfoClick(Sender: TObject);
procedure ItemUseCumYieldsForStateClick(Sender: TObject);
procedure ItemAddStateChildsClick(Sender: TObject);
procedure ButtonAbortCalcClick(Sender: TObject);
procedure StringGridMassesSetEditText(Sender: TObject; ACol, ARow: integer; const Value: string);
procedure StringGridInitialValuesSetEditText(Sender: TObject; ACol, ARow: integer; const Value: string);
procedure CheckBoxConsiderClick(Sender: TObject);
procedure PageControlChange(Sender: TObject);
procedure StringGridRA_RsKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure StringGridRA_RsKeyPress(Sender: TObject; var Key: char);
procedure PanelChainBottomCanResize(Sender: TObject; var NewWidth, NewHeight: integer; var Resize: boolean);
procedure ButtonTestChainClick(Sender: TObject);
procedure PageControlChanging(Sender: TObject; var AllowChange: boolean);
procedure StringGridStateLinkSelectCell(Sender: TObject; ACol, ARow: integer; var CanSelect: boolean);
procedure StringGridStateLinkKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure StringGridInitialValuesKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure StringGridMassesKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure StringGridAnswersKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure PageControlResize(Sender: TObject);
procedure PanelTimesCommonResize(Sender: TObject);
procedure ImageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
procedure ButtonSaveSSKconditionsClick(Sender: TObject);
procedure ButtonLoadSSKconditionsClick(Sender: TObject);
procedure StringGridRA_RsMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure GroupBoxLinksMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: integer);
procedure LinkPopupItemUseIndYieldForLinkClick(Sender: TObject);
procedure LinkPopupItemUseCumYieldForLinkClick(Sender: TObject);
procedure StringGridRA_RsSetEditText(Sender: TObject; ACol, ARow: integer; const Value: string);
procedure FormResize(Sender: TObject);
procedure ButtonCalcSpectraClick(Sender: TObject);
procedure TabSheetSpectraShow(Sender: TObject);
procedure CheckBoxSpectraPercentClick(Sender: TObject);
procedure RadioGroupSpectraWhatClick(Sender: TObject);
procedure CheckBoxSpectraGasFPonlyClick(Sender: TObject);
procedure StringGridAnswersFixedCellClick(Sender: TObject; ACol, ARow: integer);
procedure StringGridAnswersSelectCell(Sender: TObject; ACol, ARow: integer; var CanSelect: boolean);
private
{ Private declarations }
fTimesFileNameWithPath: string;
fMmFileName: string;
fOmFileName: string;
fRtbFileName: string;
fSaveStr: string;
fInitialValuesFileName: string;
fChainCalculated: boolean;
fAnswersCol, fAnswersCol0, fC: array of integer;
fTheDataModule: TObject;
fStringGridRA_RsStateName: string;
fTmpLines: TStringList;
fTmpLines0, fTmpLines1, fTmpLines2, fTmpLines3: TStringList;
fTmpSortedLines: TStringList;
fNeedToBuildSSK_TableList, fNeedNewCalculator, fNeedPrepareConditions: boolean;
fTabSheetAnswersEnabled, fIsReadOnlyDir: boolean;
fAllowPrepareConditions: boolean;
fShiftPressed: boolean;
fDirForCalculator: string;
fApplicationExePath: string;
fSSKCalculating: boolean;
fSSK_CalcAborted: boolean;
fNuclideListLoaded: boolean;
fInAnswerSelection: boolean;
fAnswerColSelection: TGridRect;
procedure RefreshRAdata;
procedure CreateNewCalculator;
function InitCalculator: boolean;
procedure FillRA_RsInfoForm;
procedure LookInOOB_InfoForm;
procedure LoadResTableFromFile(const FileName: string);
procedure RepaintAnswersTable(const AskSlow: boolean; const ItemNo: integer);
procedure DoSolve(const Solver: string);
procedure SetActiveState(aStatePointer: pointer);
procedure SetActiveLink(aLinkPointer: pointer);
procedure LoadInitials(const FileName: string);
function LoadTimes(const FileName: string): boolean;
procedure LoadMM(const FileName: string);
procedure LoadOM(const FileName: string);
procedure PrepareAnswersCols;
function IsGetN0fromMassDolja(const MassDolja: single; const aStateName: string; var N0: single): boolean;
function PrepareConditions: boolean; // prepares grids and Previous values restore
function ApplyConditions: boolean;
function ApplyTimes: boolean;
procedure RepaintCAD;
procedure OnCadChange(Sender: TObject);
function PrepareCalculator: boolean;
// procedure InitDebug;
procedure ChaingAllCumYieldsForDecayChildsWithParentsOnIndYields;
procedure ChaingAllIndYieldsForDecayChildsWithOutParentsOnCumYields;
// procedure InitChainPage;
procedure SetImageSize(const aWidth, aHeight: integer);
procedure AddStatesByNamesStr(const NamesStr: string; Sender: TObject);
procedure StringGridRA_RsMoveTo(const ACol, ARow: integer);
procedure StringGridRA_RsSetCellChecked(const ACol, ARow: integer; const Checked: boolean);
function StringGridRA_RsGetCellChecked(const ACol, ARow: integer): boolean;
procedure RepaintSpectraTable;
function CopyToClipboardFromAnswerStringGrid(StringGrid: TStringGrid): boolean;
procedure ToBuildResTable(Sender: TObject);
public
{ Public declarations }
// IDebug: integer;
// BDebug: LongBool;
procedure FormInit(Sender: TObject);
end;
var
_FormChainEditor: T_FormChainEditor;
implementation
{$IFnDEF FPC}
{$R *.frm}
{$ELSE}
{$R *.frm}
{$ENDIF}
uses
inifiles, Parsing, Clipbrd, ChainClassesMin, CadClassesMin, NuclideClassesMin, UnitDM_OOB, ChainCalculatorMin, EuLibMin,
SelfShieldingCalculatorClassesMin, UnitLookInOOB,
UnitFormMemoOkCancel, UnitSplashSolverMin, mxNativeExcel;
const
// BufferSize = 255;
BegiEndSectionChar: ansichar = #255;
ExcelColLimit = 255;
var
Chain: TChain;
ChainCAD: TChainCAD;
NuclideList: TNuclideList;
ActiveLink: TCadLink;
ActiveState: TCadState;
ChainCalc: TChainCalculator;
AllTimePoint: TList;
SSK_Calc: TSelfShieldingCalculator;
SSK_TableList: TSSK_TableList;
OldCalculators: TList;
GroupUpKeV: TFloatList;
E_gammas, E_betas, E_alphas: array of double;
SpNg_fromT, SpEgNg_fromT, SpNb_fromT, SpEbNb_fromT, SpNa_fromT, SpEaNa_fromT: array of array of double; // Spectra 6 items
EgammasCount, EbetasCount, EalphasCount: integer;
mxNativeExcel: TmxNativeExcel;
function DirExists(Name: string): boolean;
begin
Result := FileExists(Name);
end;
procedure T_FormChainEditor.FormCreate(Sender: TObject);
var
// TODO TempPathPChar, I deleted for linux
// TempPathPChar: array [0 .. BufferSize] of Char;
// I: Integer;
aStr: string;
begin
mxNativeExcel := nil;
fNuclideListLoaded := False;
fApplicationExePath := ExtractFilePath(Application.ExeName);
fDirForCalculator := '';
fIsReadOnlyDir := True;
fAllowPrepareConditions := True;
try
// TODO deleted for linux
(*
I:= GetTempPath(BufferSize, TempPathPChar); // TempDir
if ((I > 0) and (I < BufferSize)) then
begin // OK
aStr:= string(TempPathPChar);
if DirExists(aStr) then
if (IsWritableDir(aStr)) then
begin
fDirForCalculator:= aStr;
fIsReadOnlyDir:= False;
end
end;
*)
if (fDirForCalculator = '') then
begin // CurrentDir
aStr := GetCurrentDir;
if DirExists(aStr) then
if (IsWritableDir(aStr)) then
begin
fDirForCalculator := aStr;
fIsReadOnlyDir := False;
end;
end;
if (fDirForCalculator = '') then
begin // ExeDir
aStr := fApplicationExePath;
fDirForCalculator := aStr; // No Choice
if (IsWritableDir(aStr)) then
begin
fIsReadOnlyDir := False;
end;
end;
except
fDirForCalculator := fApplicationExePath;
fIsReadOnlyDir := not (IsWritableDir(fDirForCalculator));
end;
Image.Visible := False;
fTmpLines := TStringList.Create;
fTmpLines0 := TStringList.Create;
fTmpLines1 := TStringList.Create;
fTmpLines2 := TStringList.Create;
fTmpLines3 := TStringList.Create;
fTmpSortedLines := TStringList.Create;
fTmpSortedLines.Sorted := True;
Chain := TChain.Create;
fTheDataModule := T_DataModuleOOB.Create;
NuclideList := TNuclideList.Create;
OldCalculators := TList.Create;
ChainCAD := TChainCAD.Create(Chain);
ActiveLink := nil;
ActiveState := nil;
AllTimePoint := TList.Create;
AllTimePoint.Add(nil);
ChainCalc := nil;
SSK_Calc := nil;
SSK_TableList := nil;
ChainCAD.OnChange := nil;
ChainCAD.Canvas := nil;
OnKeyUp := nil;
if fIsReadOnlyDir then
begin
CheckBoxDLL.Checked := False;
CheckBoxDLL.Enabled := False;
RadioButtonRADAU.Enabled := False;
RadioButtonMEBDF.Enabled := False;
end;
aStr := fApplicationExePath + 'ChainSolver.hlp';
if not (FileExists(aStr)) then
aStr := 'ChainSolver.hlp';
Application.HelpFile := aStr;
Self.HelpFile := aStr;
fNeedPrepareConditions := True;
GroupUpKeV := TFloatList.Create;
end;
procedure T_FormChainEditor.FormInit(Sender: TObject);
var
I: integer;
begin
SetActiveState(nil);
SetActiveLink(nil);
// PageControl.Pages[PageControl.PageCount - 1].PageControl:= nil;
for I:=0 to PageControl.PageCount-1 do
PageControl.Pages[I].TabVisible:= True;
PageControl.ActivePageIndex := 0;
Application.ProcessMessages;
fTmpLines.Clear;
with StringGridStateLink do
begin
StringGridStateLink.ColWidths[0] := 64;
StringGridStateLink.ColWidths[1] := StringGridStateLink.Width - 65;
fTmpLines.Add(' # ');
fTmpLines.Add('Decay');
fTmpLines.Add('Thermal');
fTmpLines.Add('Resonance');
fTmpLines.Add('Fast');
fTmpLines.Add('g-factor');
Cells[1, 0] := 'str';
for I := 5 to RowCount - 1 do
fTmpLines.Add('Line ' + IntToStr(I + 1));
StringGridStateLink.Cols[0].Assign(fTmpLines);
end;
// Page Spectra
StringGridGroupUpKeV.ColWidths[0] := 32;
fTmpLines.Clear;
fTmpLines.Add(' # ');
for I := 1 to StringGridGroupUpKeV.RowCount - 1 do
fTmpLines.Add(IntToStr(I));
StringGridGroupUpKeV.Cols[0].Assign(fTmpLines);
fTmpLines.Add(' ');
StringGridGroupUpKeV.Cells[1, 0] := ' Eup, keV';
StringGridGroupUpKeV.Cells[1, 1] := ' 1E12';
StringGridGroupUpKeV.Cells[1, 2] := ' 100';
// Page Spectra End
(*
// QQQ
EditState.Text:='Lu-177m,Hf-177g,Hf-177m1,Hf-177m2';
// EditState.Text:='Hf-178...179';
// EditState.Text:='Hf-178m2 Hf-178m1';
// EditState.Text:='Ho-160g Ho-160m1 Ho-160m2';
CheckBoxCapture.Checked:= False;
CheckBoxCapture.Enabled:= False;
CheckBoxThreshold.Checked:= False;
CheckBoxThreshold.Enabled:= False;
CheckBoxFission.Checked:= False;
CheckBoxFission.Enabled:= False;
ButtonLoadDBClick(nil);
ButtonAddState.Enabled:= True;
// EditState.Text:= '';
*)
// QQQ
EditState.Text := '';
StringGridRA_Rs.RowCount := 2;
PrepareConditions;
// Param present
fTmpLines.Clear;
with Self do
begin
fTmpLines.Add('State');
fTmpLines.Add('Consider');
fTmpLines.Add(' N min ');
fTmpLines.Add(' N max ');
fTmpLines.Add(' Points');
StringGridRA_Rs.FixedCols := 0;
StringGridRA_Rs.Rows[0].Assign(fTmpLines);
StringGridRA_Rs.FixedCols := 1;
if ParamCount > 0 then
if ((Pos('.', ParamStr(1)) > 0) and (Pos('\', ParamStr(1)) = 0)) then
begin // The chain
if FileExists(ParamStr(1)) then
begin
Application.ProcessMessages;
ChainCAD.Free;
Chain.LoadFromFile(ParamStr(1)); // '_1.chn');
ChainCAD := TChainCAD.Create(Chain);
ChainCAD.CreateStates;
ChainCAD.CreateLinks;
LabelChainFileName.Caption := 'Chain file:' + ParamStr(1);
OnCadChange(Self);
end;
end
else
begin // all
if FileExists(ParamStr(1) + '.chn') then
begin
Application.ProcessMessages;
ChainCAD.Free;
Chain.LoadFromFile(ParamStr(1) + '.chn');
ChainCAD := TChainCAD.Create(Chain);
ChainCAD.CreateStates;
ChainCAD.CreateLinks;
LabelChainFileName.Caption := 'Chain file:' + ParamStr(1) + '.chn';
OnCadChange(Self);
end;
if FileExists(ParamStr(1) + '.pow') then
begin
LoadTimes(ParamStr(1) + '.pow');
end;
if FileExists(ParamStr(1) + '.mm') then
begin
LoadMM(ParamStr(1) + '.mm');
end;
if FileExists(ParamStr(1) + '.om') then
begin
LoadOM(ParamStr(1) + '.om');
end;
if FileExists(ParamStr(1) + '.ivl') then
begin
if (Chain <> nil) then
if (Chain.States.Count > 0) then
begin
PrepareConditions;
LoadInitials(ParamStr(1) + '.ivl');
end;
end;
if FileExists(ParamStr(1) + '.rtb') then
begin
LoadResTableFromFile(ParamStr(1) + '.rtb');
end;
end;
Application.ProcessMessages;
end;
end;
procedure T_FormChainEditor.FormShow(Sender: TObject);
begin
if not(FileExists(ExtractFilePath(Application.ExeName) + '/!Debug.it+ ')) then
begin // Spectra page - TODO maybe later
// PageControl.Pages[PageControl.PageCount - 1].PageControl := nil; // TabSheetSpectra.Visible:= False;
end;
Application.ProcessMessages;
if _FormSplashSolver.Visible then
_FormSplashSolver.Update;
Application.ProcessMessages;
ChainCAD.Canvas := Image.Canvas;
if _FormSplashSolver.Visible then
_FormSplashSolver.Update;
ChainCAD.OnChange := OnCadChange;
if _FormSplashSolver.Visible then
_FormSplashSolver.Update;
Image.Visible := True;
SetImageSize(ChainCAD.Width, ChainCAD.Height);
RepaintCAD;
Application.ProcessMessages;
if _FormSplashSolver.Visible then
_FormSplashSolver.Hide;
_FormSplashSolver.Close;
if (Pos('Simple', RadioGroupCellType.Items[RadioGroupCellType.ItemIndex]) > 0) then
begin
LabelSkin_V.Visible := False;
EditSkin_V.Visible := False;
// LabelOM_V.Visible:= False;
// EditOM_V.Visible:= False;
end
else
begin
LabelSkin_V.Visible := True;
EditSkin_V.Visible := True;
// LabelOM_V.Visible:= True;
// EditOM_V.Visible:= True;
end;
PageControl.ActivePage := PageControl.Pages[0];
end;
procedure T_FormChainEditor.FormDestroy(Sender: TObject);
var
I: integer;
begin
ChainCalc.Free;
ChainCalc := nil;
for I := OldCalculators.Count - 1 downto 0 do
begin
TChainCalculator(OldCalculators[I]).Free;
OldCalculators[I] := nil;
end;
OldCalculators.Free;
OldCalculators := nil;
fTmpLines.Free;
fTmpLines0.Free;
fTmpLines1.Free;
fTmpLines2.Free;
fTmpLines3.Free;
fTmpSortedLines.Free;
if mxNativeExcel<> nil then
mxNativeExcel.Free;
end;
procedure T_FormChainEditor.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
begin
if (ssShift in Shift) then
fShiftPressed := True
else
fShiftPressed := False;
if (PageControl.ActivePage = TabSheetAnswers) then
begin
// Ctrl+Ins or Ctrl+C
if (not (ssAlt in Shift) and (ssCtrl in Shift) and (Key = VK_INSERT) or (Key = Ord('C'))) then
begin
CopyToClipboardFromAnswerStringGrid(TStringGrid(StringGridAnswers));
end;
end;
end;
procedure T_FormChainEditor.FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
var
I: integer;
begin
try
if (ssShift in Shift) then
fShiftPressed := True
else
fShiftPressed := False;
// TabSheetChainEditor
if TabSheetChainEditor.Visible then
begin
if ((Key in [Ord('I'), Ord('i')]) and (ssCtrl in Shift) and (ssAlt in Shift)) then
begin
if (ChainCAD.States.Count > 0) then
if NuclideList.Count < 1 then
MessageDlg('Nuclides were NOT loaded ! Yields can not be initialized !' + #13 + #10 + 'Use button "LOAD DB"!', mtWarning,
[mbOK], 0)
else
ChaingAllCumYieldsForDecayChildsWithParentsOnIndYields;
end
else if ((Key in [Ord('C'), Ord('c')]) and (ssCtrl in Shift) and (ssAlt in Shift)) then
begin
if NuclideList.Count < 1 then
MessageDlg('Nuclides were NOT loaded ! Yields can not be initialized !' + #13 + #10 + 'Use button "LOAD DB"!', mtWarning,
[mbOK], 0)
else
begin
ChaingAllIndYieldsForDecayChildsWithOutParentsOnCumYields;
end;
Exit;
end
else if ((Key in [Ord('Y'), Ord('y')]) and (ssCtrl in Shift) and (ssAlt in Shift)) then
begin
if NuclideList.Count < 1 then
MessageDlg('Nuclides were NOT loaded ! Yields can not be initialized !' + #13 + #10 + 'Use button "LOAD DB"!', mtWarning,
[mbOK], 0)
else
begin
ChaingAllCumYieldsForDecayChildsWithParentsOnIndYields;
ChaingAllIndYieldsForDecayChildsWithOutParentsOnCumYields;
end;
end;
end;
// Any Tab
if ((Key in [VK_CANCEL, Ord('C'), Ord('c')]) and (ssCtrl in Shift)) then
begin
if (ChainCalc <> nil) then
if ChainCalc.Calculating then
begin
ChainCalc.StopCalculation;
MemoCalculatorStdOut.Lines.Add('ABORTING...');
for I := 0 to ChainCalc.CalculatorStdOut.Count - 1 do
MemoCalculatorStdOut.Lines.Add(ChainCalc.CalculatorStdOut[I]);
if not (TabSheetCalc.Visible) then
TabSheetCalc.Show;
Exit;
end;
if EuLibMin.InLongOperation then
begin
EuLibMin.StopLongOperation := True;
MessageDlg('Ctrl+C or Control+Break pressed.' + #13 + #10 + 'Aborting somewhere !', mtWarning, [mbOK], 0);
Exit;
end;
if fSSKCalculating then
if SSK_Calc <> nil then
begin
SSK_Calc.AbortCalcSSK := True;
fSSK_CalcAborted := True;
Application.ProcessMessages;
end;
end;
except
// Say nothing
end;
end;
procedure T_FormChainEditor.FormResize(Sender: TObject);
begin
StringGridRA_Rs.Height := GroupBoxRAs.Height - StringGridRA_Rs.Top;
end;
procedure T_FormChainEditor.PageControlChanging(Sender: TObject; var AllowChange: boolean);
var
Answer: word;
begin
try
AllowChange := True;
if PageControl.ActivePage = TabSheetChainEditor then
begin
PageControl.SetFocus; // To Enable ButtomToChain if need
if ((ActiveState <> nil) or (ActiveLink <> nil)) then
if (ButtonToChain.Enabled) then
begin
Answer := MessageDlg('Edited data were not saved to chain ! Save ?', mtWarning, [mbYes, mbNo, mbCancel], 0);
if (Answer = mrCancel) then
begin
AllowChange := False;
if (ActiveState <> nil) then
ComboBoxStates.Text := ActiveState.State.Name
else if (ActiveLink <> nil) then
ComboBoxLinks.Text := ActiveLink.Link.Name;
if StringGridStateLink.Visible then
StringGridStateLink.SetFocus;
Exit;
end
else if (Answer = mrYes) then
ButtonToChainClick(Self);
end;
end
else if PageControl.ActivePage = TabSheetTimes then
begin
if CheckBoxTimesAutoApply.Checked then
begin
if not (ApplyTimes) then
begin
AllowChange := False;
end;
end;
end;
except
// Say nothing
end;
end;
// Chain page start
procedure T_FormChainEditor.PanelChainBottomCanResize(Sender: TObject; var NewWidth, NewHeight: integer; var Resize: boolean);
begin
StringGridStateLink.ColWidths[1] := StringGridStateLink.Width - 65;
end;
procedure T_FormChainEditor.ItemZoomInClick(Sender: TObject);
begin
if ChainCAD <> nil then
begin
Image.Visible := False;
with ChainCAD do
begin
if ScrollBoxCAD.Visible then
ScrollBoxCAD.SetFocus;
Image.Canvas.Brush.Color := clWhite;
Image.Canvas.FillRect(Image.Canvas.ClipRect);
ChainCAD.Zoom(2);
SetImageSize(ChainCAD.Width, ChainCAD.Height);
ChainCAD.PaintStates;
ChainCAD.PaintLinks;
if ChainCAD.StateHeight > 8 then
ItemZoomOut.Enabled := True
else
ItemZoomOut.Enabled := False;
if ChainCAD.StateHeight < 80 then
ItemZoomIn.Enabled := True
else
ItemZoomIn.Enabled := False;
end;
Image.Visible := True;
end;
end;
procedure T_FormChainEditor.ItemZoomOutClick(Sender: TObject);
begin
if ChainCAD <> nil then
with ChainCAD do
begin
if ScrollBoxCAD.Visible then
ScrollBoxCAD.SetFocus;
Image.Canvas.Brush.Color := clWhite;
Image.Canvas.FillRect(Image.Canvas.ClipRect);
ChainCAD.Zoom(0.5);
SetImageSize(ChainCAD.Width, ChainCAD.Height);
ChainCAD.PaintStates;
ChainCAD.PaintLinks;
if ChainCAD.StateHeight > 8 then
ItemZoomOut.Enabled := True
else
ItemZoomOut.Enabled := False;
if ChainCAD.StateHeight < 80 then
ItemZoomIn.Enabled := True
else
ItemZoomIn.Enabled := False;
end;
end;
procedure T_FormChainEditor.SetImageSize(const aWidth, aHeight: integer);
procedure AdjustImagePictureGraphicSize(InWidth, InHeight: integer);
const
Divider = 100;
Factor = 99;
begin
if ((InHeight > 0) and (InWidth > 0)) then
try
Image.Picture.Graphic.Height := InHeight;
Image.Picture.Graphic.Width := InWidth;
except
AdjustImagePictureGraphicSize(InWidth * Factor div Divider, InHeight * Factor div Divider);
end;
end;
begin
if ((Image.Picture.Graphic.Height <> aHeight) or (Image.Picture.Graphic.Width <> aWidth)) then
try
Image.Height := aHeight;
Image.Picture.Graphic.Height := aHeight;
Image.Width := aWidth;
Image.Picture.Graphic.Width := aWidth;
except
on EOutOfResources do
begin
MessageDlg('Can not set new image size !' + #10#13 + 'Out of resources: not enough storage is available. Sorry.', mtWarning, [mbOK], 0);
AdjustImagePictureGraphicSize(aWidth, aHeight);
end
else
MessageDlg('Can not set new image height !', mtWarning, [mbOK], 0);
end;
end;
procedure T_FormChainEditor.ItemSaveCADimageClick(Sender: TObject);
var
Bitmap: TBitmap;
Png: TPortableNetworkGraphic;
FileExtenstion: string;
begin
if SaveCadImageDialog.Execute then
begin
Bitmap := TBitmap.Create;
Png := TPortableNetworkGraphic.Create;
if ChainCAD <> nil then
try
FileExtenstion := UpperCase(Trim(ExtractFileExt(SaveCadImageDialog.FileName)));
if (FileExtenstion = '.BMP') then
// Graphic (*.png;*.xpm;*.bmp;*.cur;*.ico;*.icns;*.jpeg;*.jpg;*.jpe;*.jfif;*.tif;*.tiff;*.gif;*.tga;*.pbm;*.pgm;*.ppm;*.gif)|*.png;*.xpm;*.bmp;*.cur;*.ico;*.icns;*.jpeg;*.jpg;*.jpe;*.jfif;*.tif;*.tiff;*.gif;*.tga;*.pbm;*.pgm;*.ppm;*.gif|Portable Network Graphic (*.png)|*.png|Pixmap (*.xpm)|*.xpm|Bitmaps (*.bmp)|*.bmp|Cursor (*.cur)|*.cur|Icon (*.ico)|*.ico|Mac OS X Icon (*.icns)|*.icns|Joint Picture Expert Group (*.jpeg;*.jpg;*.jpe;*.jfif)|*.jpeg;*.jpg;*.jpe;*.jfif|Tagged Image File Format (*.tif;*.tiff)|*.tif;*.tiff|Graphics Interchange Format (*.gif)|*.gif|TARGA (TGA) Image File Format (*.tga)|*.tga|Portable PixMap (*.pbm;*.pgm;*.ppm)|*.pbm;*.pgm;*.ppm|Animated GIF (*.gif)|*.gif|All files (*.*)|*.*|
begin
// BMP
try
Bitmap.LoadFromDevice(Image.Canvas.Handle);
Bitmap.SaveToFile(SaveCadImageDialog.FileName);
except
end;
end
else
if (FileExtenstion = '.PNG') then
// PNG
begin
try
Png.LoadFromDevice(Image.Canvas.Handle);
Png.SaveToFile(SaveCadImageDialog.FileName);
except
end;
end
else
begin
MessageDlg('Unsupported format (' + FileExtenstion + ')' + #10#13 + ' Use BMP *TODO others)!' + #10#13 +
' Will not export', mtWarning, [mbOK], 0);
Exit;
end;
finally
Bitmap.Free;
Png.Free;
end;
end;
end;
procedure T_FormChainEditor.ItemAddStateChildsClick(Sender: TObject);
var
NoInChain, I: integer;
aTransitions: TNuclideTransitions;
ChildList: TLongIntList;
aStr: string;
begin
if NuclideList.Count < 1 then