diff --git a/LFPSO/unit_LFPSO_Base.pas b/LFPSO/unit_LFPSO_Base.pas index 6bf0abe..2e949c4 100644 --- a/LFPSO/unit_LFPSO_Base.pas +++ b/LFPSO/unit_LFPSO_Base.pas @@ -1,4 +1,4 @@ -(* ***************************************************************************** + (* ***************************************************************************** * * X-Ray Calc 3 * diff --git a/components/editor_Layer.dfm b/components/editor_Layer.dfm index a0ffd56..a1afe60 100644 --- a/components/editor_Layer.dfm +++ b/components/editor_Layer.dfm @@ -130,6 +130,7 @@ object edtrLayer: TedtrLayer ParentColor = True TabOrder = 2 TabStop = False + OnClick = btnOKClick Kind = bkOK end object btnCancel: TRzBitBtn @@ -151,6 +152,7 @@ object edtrLayer: TedtrLayer ParentColor = True TabOrder = 0 TabStop = False + OnClick = btnPrevClick end object btnNext: TRzBitBtn Tag = 1 @@ -161,6 +163,7 @@ object edtrLayer: TedtrLayer ParentColor = True TabOrder = 1 TabStop = False + OnClick = btnNextClick end end end diff --git a/components/editor_Layer.pas b/components/editor_Layer.pas index d5d50d2..8c70e02 100644 --- a/components/editor_Layer.pas +++ b/components/editor_Layer.pas @@ -33,12 +33,19 @@ TedtrLayer = class(TForm) btnPrev: TRzBitBtn; btnNext: TRzBitBtn; procedure edMaterialButtonClick(Sender: TObject); + procedure btnNextClick(Sender: TObject); + procedure btnOKClick(Sender: TObject); + procedure btnPrevClick(Sender: TObject); private { Private declarations } + FData: TLayerData; + FSeq: boolean; public { Public declarations } - function ShowEditor(const IsSubstrate: Boolean; var Data: TLayerData): boolean; + procedure SetData(const IsSubstrate: Boolean; Data: TLayerData); + function GetData: TLayerData; + property Seq: boolean read FSeq; end; var @@ -46,34 +53,27 @@ TedtrLayer = class(TForm) implementation +uses + unit_SMessages; + //uses frm_MList; {$R *.dfm} -function TedtrLayer.ShowEditor(const IsSubstrate: Boolean; var Data: TLayerData): boolean; +procedure TedtrLayer.btnNextClick(Sender: TObject); begin - Result := False; - edMaterial.Text := Data.Material; - edH.Value := Data.P[1].V; - edSigma.Value := Data.P[2].V; - edRo.Value := Data.P[3].V; - - edH.Visible := not IsSubstrate; - Label2.Visible := not IsSubstrate; - - - ActiveControl := edMaterial; + LayerEditNext(FData.StackID, FData.LayerID); +end; - if ShowModal = mrOk then - begin - Data.Material := edMaterial.Text; - Data.P[1].V := edH.Value; - Data.P[2].V := edSigma.Value; - Data.P[3].V := edRo.Value; - Result := True; - end; +procedure TedtrLayer.btnOKClick(Sender: TObject); +begin + FSeq := False; +end; +procedure TedtrLayer.btnPrevClick(Sender: TObject); +begin + LayerEditPrev(FData.StackID, FData.LayerID); end; procedure TedtrLayer.edMaterialButtonClick(Sender: TObject); @@ -84,4 +84,35 @@ procedure TedtrLayer.edMaterialButtonClick(Sender: TObject); edMaterial.Text := S; end; +function TedtrLayer.GetData: TLayerData; +begin + Result := FData; + + Result.Material := edMaterial.Text; + Result.P[1].V := edH.Value; + Result.P[2].V := edSigma.Value; + Result.P[3].V := edRo.Value; + +end; + +procedure TedtrLayer.SetData(const IsSubstrate: Boolean; Data: TLayerData); +begin + FSeq := Self.Showing; + + FData := Data; + + edMaterial.Text := Data.Material; + edH.Value := Data.P[1].V; + edSigma.Value := Data.P[2].V; + edRo.Value := Data.P[3].V; + + edH.Visible := not IsSubstrate; + Label2.Visible := not IsSubstrate; + + btnPrev.Visible := not IsSubstrate; + btnNext.Visible := not IsSubstrate; + + ActiveControl := edMaterial; +end; + end. diff --git a/components/unit_SMessages.pas b/components/unit_SMessages.pas index d900445..4d5e27c 100644 --- a/components/unit_SMessages.pas +++ b/components/unit_SMessages.pas @@ -24,6 +24,9 @@ interface WM_RECALC = WM_STR_BASE + 2; WM_STR_LAYER_CLICK = WM_STR_BASE + 3; WM_STR_LINKED_CLICK = WM_STR_BASE + 4; + WM_STR_EDIT_NEXT = WM_STR_BASE + 5; + WM_STR_EDIT_PREV = WM_STR_BASE + 6; + WM_STR_LAYER_DOUBLECLICK = WM_STR_BASE + 7; WM_STR_LAYER_UP = WM_STR_BASE + 20; WM_STR_LAYER_DOWN = WM_STR_BASE + 21; @@ -35,9 +38,11 @@ interface procedure StackDoubleClick(const ID: integer); procedure SendRecalcMessage; procedure LayerClick(const StackID, ID: integer); + procedure LayerDoubleClick(const StackID, ID: integer); procedure LinkedClick(const StackID, ID: integer); procedure ArrangeLayer(const Msg: Cardinal; const StackID, ID: integer); - + procedure LayerEditNext(const StackID, ID: integer); + procedure LayerEditPrev(const StackID, ID: integer); implementation @@ -68,7 +73,39 @@ procedure LayerClick(const StackID, ID: integer); begin PostMessage( Application.MainFormHandle, - WM_STR_LAYER_CLICK , + WM_STR_LAYER_CLICK, + StackID, + ID + ); +end; + +procedure LayerDoubleClick(const StackID, ID: integer); +begin + PostMessage( + Application.MainFormHandle, + WM_STR_LAYER_DOUBLECLICK, + StackID, + ID + ); +end; + +procedure LayerEditNext(const StackID, ID: integer); +begin + PostMessage( + Application.MainFormHandle, + WM_STR_EDIT_NEXT, + StackID, + ID + ); +end; + + + +procedure LayerEditPrev(const StackID, ID: integer); +begin + PostMessage( + Application.MainFormHandle, + WM_STR_EDIT_PREV, StackID, ID ); diff --git a/components/unit_XRCLayerControl.pas b/components/unit_XRCLayerControl.pas index 3ba5695..ebc1f4d 100644 --- a/components/unit_XRCLayerControl.pas +++ b/components/unit_XRCLayerControl.pas @@ -255,10 +255,17 @@ destructor TXRCLayerControl.Destroy; procedure TXRCLayerControl.Edit; begin - if edtrLayer.ShowEditor(FSubstrate, FData) then + edtrLayer.SetData(FSubstrate, FData); + + + if edtrLayer.ShowModal = mrOk then begin - Name.Caption := Data.Material; - SetLayerData(FData); + if not edtrLayer.Seq then + begin + FData := edtrLayer.GetData; + Name.Caption := FData.Material; + SetLayerData(FData); + end; end; SetSlected(False); @@ -331,7 +338,7 @@ procedure TXRCLayerControl.InternalOnClick(Sender: TObject); procedure TXRCLayerControl.InternalOnDblClick(Sender: TObject); begin - Edit; + LayerDoubleClick(FData.StackID, FData.LayerID); end; procedure TXRCLayerControl.LinkedOnClick(Sender: TObject); diff --git a/components/unit_XRCStackControl.pas b/components/unit_XRCStackControl.pas index 4c703ad..e22b583 100644 --- a/components/unit_XRCStackControl.pas +++ b/components/unit_XRCStackControl.pas @@ -132,6 +132,9 @@ procedure TXRCStack.AddSubstrate(const Material: string; s, rho: single); Data: TLayerData; begin SetLength(FLayers, 1); + Data.StackID := 65535; + Data.LayerID := 65535; + Data.Material := Material; Data.P[1].V := 1E8; Data.P[2].V := s; diff --git a/components/unit_XRCStructure.pas b/components/unit_XRCStructure.pas index ba6cd5a..4b0615e 100644 --- a/components/unit_XRCStructure.pas +++ b/components/unit_XRCStructure.pas @@ -54,6 +54,10 @@ TXRCStructure = class (TRzPanel) function FindStrValue(const Value: string): string; function GetSelectedLayer: Integer; procedure SetPeriodicMode(const Value: boolean); + function GetCurrentLayerData: TLayerData; + procedure SetCurrentLayerData(const Value: TLayerData); + function GetSubstrateData: TLayerData; + procedure SetSubstrateData(const Value: TLayerData); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -72,6 +76,8 @@ TXRCStructure = class (TRzPanel) procedure Select(const ID: Integer); procedure ClearSelection(const Reset:boolean = False); inline; procedure SelectLayer(const StackID, LayerID: Integer); + procedure EditNextLayer(const StackID, LayerID: Integer; Frwrd: boolean); + procedure LinkLayer(const StackID, LayerID: Integer); procedure MoveLayer(const StackID, LayerID, Direction: Integer); procedure EditStack(const ID: Integer); @@ -102,6 +108,8 @@ TXRCStructure = class (TRzPanel) // procedure EnablePairing; function IfValidLayerSelected: Boolean; inline; property RealHeight: Integer read FRealHeight; + property LayerData: TLayerData read GetCurrentLayerData write SetCurrentLayerData; + property SubstrateData: TLayerData read GetSubstrateData write SetSubstrateData; published property Increment: single read FIncrement write SetIncrement; end; @@ -112,7 +120,7 @@ TXRCStructure = class (TRzPanel) implementation uses - unit_consts; + unit_consts, editor_Layer; { TXRCStructure } @@ -340,6 +348,35 @@ destructor TXRCStructure.Destroy; inherited Destroy; end; +procedure TXRCStructure.EditNextLayer(const StackID, LayerID: Integer; + Frwrd: boolean); +begin + Stacks[StackID].UpdateLayer(LayerID, edtrLayer.GetData); + + if Frwrd then + begin + if LayerID < High(Stacks[StackID].Layers) then + begin + edtrLayer.SetData(False, Stacks[StackID].Layers[LayerID + 1].Data); + end + else if StackID < High(Stacks) then + begin + edtrLayer.SetData(False, Stacks[StackID + 1].Layers[0].Data); + end; + end + else begin + if LayerID > 0 then + begin + edtrLayer.SetData(False, Stacks[StackID].Layers[LayerID - 1].Data); + end + else if StackID > 0 then + begin + edtrLayer.SetData(False, Stacks[StackID - 1].Layers[High(Stacks[StackID - 1].Layers)].Data); + end; + end; + +end; + procedure TXRCStructure.EditStack; begin FStacks[ID].Edit; @@ -493,6 +530,11 @@ procedure TXRCStructure.SelectLayer(const StackID, LayerID: Integer); end; end; +procedure TXRCStructure.SetCurrentLayerData(const Value: TLayerData); +begin + Stacks[Value.StackID].UpdateLayer(Value.LayerID, Value); +end; + procedure TXRCStructure.SetIncrement(const Value: single); var i: Integer; @@ -510,6 +552,11 @@ procedure TXRCStructure.SetPeriodicMode(const Value: boolean); Stack.EnablePairing(not Value); end; +procedure TXRCStructure.SetSubstrateData(const Value: TLayerData); +begin + Substrate.UpdateLayer(0, Value); +end; + procedure TXRCStructure.UpdateInterfaceNP(const Inp: TFitStructure); var i, j: integer; @@ -784,6 +831,11 @@ procedure TXRCStructure.FromString(const S: string); Visible := True; end; +function TXRCStructure.GetCurrentLayerData: TLayerData; +begin + +end; + procedure TXRCStructure.GetLayersList(const ID: integer; List: TStrings); var j: Integer; @@ -833,4 +885,9 @@ procedure TXRCStructure.GetStacksList(PeriodicOnly: Boolean; List: TStrings; var end; end; +function TXRCStructure.GetSubstrateData: TLayerData; +begin + Result := Substrate.Layers[0].Data; +end; + end. diff --git a/forms/frm_Benchmark.dfm b/forms/frm_Benchmark.dfm index c2065f9..6561d80 100644 --- a/forms/frm_Benchmark.dfm +++ b/forms/frm_Benchmark.dfm @@ -25,28 +25,30 @@ object frmBenchmark: TfrmBenchmark BorderWidth = 2 Color = 15987699 TabOrder = 0 - object BitBtn1: TBitBtn - Left = 896 - Top = 363 + ExplicitWidth = 969 + ExplicitHeight = 379 + object btnCancel: TBitBtn + Left = 895 + Top = 354 Width = 75 Height = 25 - Caption = 'Close' + Caption = 'Cancel' TabOrder = 0 - OnClick = BitBtn1Click + OnClick = btnCancelClick end object Grid: TXRCGrid AlignWithMargins = True Left = 7 Top = 7 - Width = 971 - Height = 342 + Width = 963 + Height = 330 Margins.Bottom = 50 Align = alClient TabOrder = 1 AutoFit = False Text = #9#9#9#9 - ExplicitWidth = 963 - ExplicitHeight = 330 + ExplicitWidth = 955 + ExplicitHeight = 318 end end end diff --git a/forms/frm_Benchmark.pas b/forms/frm_Benchmark.pas index d0b0c6f..bf838d3 100644 --- a/forms/frm_Benchmark.pas +++ b/forms/frm_Benchmark.pas @@ -16,16 +16,25 @@ interface Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Grids, Vcl.StdCtrls, Vcl.Buttons, RzPanel, RzGrids, unit_XRCGrid; +const + WM_STR_BASE = WM_APP + $0900; + + WM_BENCH_CANCEL = WM_STR_BASE + 0; + + type TfrmBenchmark = class(TForm) RzPanel1: TRzPanel; - BitBtn1: TBitBtn; + btnCancel: TBitBtn; Grid: TXRCGrid; - procedure BitBtn1Click(Sender: TObject); + procedure btnCancelClick(Sender: TObject); private FLine: Integer; FFileName: string; + FOnProgress: Boolean; { Private declarations } + + procedure SendCancelMessage; public { Public declarations } procedure Clear(const N: integer); @@ -34,7 +43,6 @@ TfrmBenchmark = class(TForm) procedure CalcStats(const Full: Boolean); procedure Init(const OutputDir: string); - end; var @@ -58,15 +66,25 @@ procedure TfrmBenchmark.AddValue(const n: integer; Val: string); Grid.Cells[n, FLine] := Val; end; -procedure TfrmBenchmark.BitBtn1Click(Sender: TObject); +procedure TfrmBenchmark.btnCancelClick(Sender: TObject); begin + if FOnProgress then SendCancelMessage; Close; end; procedure TfrmBenchmark.CalcStats; begin - if Full then Grid.CalcStat; + if Full then + begin + Grid.CalcStat; + btnCancel.Caption := 'Close'; + end + else + btnCancel.Caption := 'Abort'; + Grid.SaveToFile(FFileName); + FOnProgress := not Full; + end; procedure TfrmBenchmark.Clear; @@ -94,6 +112,19 @@ procedure TfrmBenchmark.Init; FileName := Format('%s-%s.dat',['benchmark', Date]); FFileName := OutputDir + FileName; + + FOnProgress := True; + btnCancel.Caption := 'Cancel'; +end; + +procedure TfrmBenchmark.SendCancelMessage; +begin + PostMessage( + Application.MainFormHandle, + WM_BENCH_CANCEL, + 0, + 0 + ); end; end. diff --git a/forms/frm_Main.dfm b/forms/frm_Main.dfm index a10fefb..7282287 100644 --- a/forms/frm_Main.dfm +++ b/forms/frm_Main.dfm @@ -1878,15 +1878,15 @@ object frmMain: TfrmMain ImageIndex = 1 object Add1: TMenuItem Action = PeriodAdd - Caption = 'Add Period' + Caption = 'Add Stack' end object Insert1: TMenuItem Action = PeriodInsert - Caption = 'Insert Period' + Caption = 'Insert Stack' end object Delete1: TMenuItem Action = PeriodDelete - Caption = 'Delete Period' + Caption = 'Delete Stack' end object N3: TMenuItem Caption = '-' diff --git a/forms/frm_Main.pas b/forms/frm_Main.pas index 468bbdf..4b664e8 100644 --- a/forms/frm_Main.pas +++ b/forms/frm_Main.pas @@ -15,7 +15,7 @@ interface unit_SMessages, unit_calc, unit_XRCProjectTree, RzRadGrp, Vcl.RibbonLunaStyleActnCtrls, unit_materials, VCLTee.TeeFunci, unit_LFPSO_Base, unit_LFPSO_Periodic, Vcl.Buttons, - unit_LFPSO_Irregular, Vcl.Imaging.pngimage; + unit_LFPSO_Irregular, Vcl.Imaging.pngimage, frm_Benchmark; type TSeriesList = array of TLineSeries; @@ -486,6 +486,9 @@ TfrmMain = class(TForm) { Public declarations } procedure WMStackClick(var Msg: TMessage); message WM_STR_STACK_CLICK; procedure WMLayerClick(var Msg: TMessage); message WM_STR_LAYER_CLICK; + procedure WMLayerDoubleClick(var Msg: TMessage); message WM_STR_LAYER_DOUBLECLICK; + procedure WMLayerEditNext(var Msg: TMessage); message WM_STR_EDIT_NEXT; + procedure WMLayerEditPrev(var Msg: TMessage); message WM_STR_EDIT_PREV; procedure WMLinkedClick(var Msg: TMessage); message WM_STR_Linked_CLICK; //procedure WMStackDblClick(var Msg: TMessage); message WM_STR_STACKDBLCLICK; procedure OnMyMessage(var Msg: TMessage); message WM_RECALC; @@ -494,6 +497,7 @@ TfrmMain = class(TForm) procedure OnLayerDownMsg(var Msg: TMessage); message WM_STR_LAYER_DOWN; procedure OnLayerDeleteMsg(var Msg: TMessage); message WM_STR_LAYER_DELETE; procedure OnLayerInsertMsg(var Msg: TMessage); message WM_STR_LAYER_INSERT; + procedure OnCancelBenchmarkMsg(var Msg: TMessage); message WM_BENCH_CANCEL; end; var @@ -524,12 +528,13 @@ implementation editor_JSON, unit_LFPSO_Poly, unit_SavitzkyGolay, - frm_Benchmark, unit_files_list, unit_config, frm_settings, unit_XRCStackControl, - editor_ProfileTable, unit_sys_helpers, frm_FitSettings; + editor_ProfileTable, + unit_sys_helpers, + frm_FitSettings; {$R *.dfm} @@ -589,6 +594,11 @@ procedure TfrmMain.actItemProperitesExecute(Sender: TObject); EditProjectItem; end; +procedure TfrmMain.OnCancelBenchmarkMsg(var Msg: TMessage); +begin + CalcStopExecute(nil); +end; + procedure TfrmMain.OnFitUpdateMsg(var Msg: TMessage); var msg_prm: PUpdateFitProgressMsg; @@ -600,11 +610,12 @@ procedure TfrmMain.OnFitUpdateMsg(var Msg: TMessage); // chFittingProgress.LeftAxis.Maximum := 1.1 * msg_prm.BestChi; - spChiSqr.Caption := FloatToStrF(msg_prm.BestChi, ffFixed, 8, 4); + spChiSqr.Caption := FloatToStrF(msg_prm.LastChi, ffFixed, 8, 4); spChiBest.Caption := FloatToStrF(msg_prm.BestChi, ffFixed, 8, 4); + FLastChiSquare := msg_prm.BestChi; if (Length(msg_prm.Curve) > 1) then begin - PlotResults(msg_prm.Curve); + PlotResults(msg_prm.Curve); end; Dispose(msg_prm); DecodeTime(Now - FitStartTime, Hour, Min, Sec, MSec); @@ -1853,7 +1864,6 @@ procedure TfrmMain.CalcRunExecute(Sender: TObject); FCalc.Run; if (Project.LinkedData <> nil) and FSeriesList[Project.ActiveModel.CurveID].Visible then begin - FLastChiSquare := FCalc.ChiSQR; FCalc.CalcChiSquare(cbTWChi.ItemIndex); spChiSqr.Caption := FloatToStrF(FCalc.ChiSQR, ffFixed, 8, 4); end @@ -2046,20 +2056,21 @@ procedure TfrmMain.ProcessBenchFile(Sender: TObject; const F: TSearchRec); frmBenchmark.AddFile(ChangeFileExt(F.Name, '')); for i := 1 to FBenchmarkRuns do begin + if FTerminated then Break; actProjectReopenExecute(nil); actAutoFittingExecute(nil); - frmBenchmark.AddValue(i, spChiSqr.Caption); - frmBenchmark.CalcStats(False); Application.ProcessMessages; - if FTerminated then Break; + frmBenchmark.AddValue(i, FloatToStrF(FLastChiSquare, ffFixed, 8, 4)); + frmBenchmark.CalcStats(False); end; - frmBenchmark.CalcStats(True); + if not FTerminated then frmBenchmark.CalcStats(True); end; procedure TfrmMain.actCalcBenchmarkExecute(Sender: TObject); var Files: TFilesList; begin + FLastChiSquare := 0; FBenchmarkRuns := TConfig.Section.BenchmarkRuns; try @@ -2279,8 +2290,9 @@ procedure TfrmMain.LayerAddExecute(Sender: TObject); Data.P[2].New(3); Data.P[3].New(0); - if edtrLayer.ShowEditor(False, Data) then - Structure.AddLayer(Structure.SelectedStack, Data); + edtrLayer.SetData(False, Data); + if edtrLayer.ShowModal = mrOk then + Structure.AddLayer(Structure.SelectedStack, edtrLayer.GetData); MatchToStructure; end; @@ -2319,8 +2331,9 @@ procedure TfrmMain.LayerInsertExecute(Sender: TObject); Data.P[2].New(3); Data.P[3].New(0); - if edtrLayer.ShowEditor(False, Data) then - Structure.InsertLayer(Data); + edtrLayer.SetData(False, Data); + if edtrLayer.ShowModal = mrOk then + Structure.InsertLayer(edtrLayer.GetData); MatchToStructure; end; @@ -2825,6 +2838,47 @@ procedure TfrmMain.WMLayerClick(var Msg: TMessage); Structure.SelectLayer(LayerID, ID); end; +procedure TfrmMain.WMLayerDoubleClick(var Msg: TMessage); +var + StackID, LayerID: Integer; + ifSubstrate : boolean; + +begin + LayerID := Msg.LParam; + StackID := Msg.WParam; + ifSubstrate := (LayerID = 65535) and (StackID = 65535); + if IfSubstrate then + edtrLayer.SetData(True, Structure.SubstrateData) + else + edtrLayer.SetData(False, Structure.Stacks[StackID].Layers[LayerID].Data); + + if edtrLayer.ShowModal = mrOk then + begin + if IfSubstrate then + Structure.SubstrateData := edtrLayer.GetData + else + Structure.LayerData := edtrLayer.GetData; + end; +end; + +procedure TfrmMain.WMLayerEditNext(var Msg: TMessage); +var + ID, LayerID: Integer; +begin + LayerID := Msg.WParam; + ID := Msg.LParam; + Structure.EditNextLayer(LayerID, ID, True); +end; + +procedure TfrmMain.WMLayerEditPrev(var Msg: TMessage); +var + ID, LayerID: Integer; +begin + LayerID := Msg.WParam; + ID := Msg.LParam; + Structure.EditNextLayer(LayerID, ID, False); +end; + procedure TfrmMain.WMLinkedClick(var Msg: TMessage); var ID, LayerID: Integer;