unit MCAD_MI1201_MassScaleSimpleCalibration; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, ActnList, MCAD_MI1201_XForm, MCAD_MI1201_Thread_Types, MCAD_MI1201_Thread2, MCAD_MI1201_Thread; type TFormMassScaleSimpleCalibration = class(TXForm) pM: TPanel; lPosition: TLabel; gbM: TGroupBox; pM1: TPanel; pM2: TPanel; bPeakCentersFind: TButton; gbM0: TGroupBox; pM01: TPanel; pM02: TPanel; pClb: TPanel; M1: TComboBox; M2: TComboBox; M01: TComboBox; M02: TComboBox; lNewCalibration: TLabel; pK: TPanel; bCalculate: TButton; eK: TEdit; bSetUp: TButton; pC: TPanel; eC1: TEdit; pdC: TPanel; edC: TEdit; eC2: TEdit; ActionListMassCalibration: TActionList; ActionMassCalibrationCalculate: TAction; ActionMassCalibrationRefineMasses: TAction; pChannel: TPanel; lChannel: TLabel; ActionMassCalibrationSetNew: TAction; cbUseExistingData: TCheckBox; ActionMassCalibrationDoNotRemeasure: TAction; pDisbalance: TPanel; eDisb: TEdit; pStatusBar: TPanel; bbM1Refine: TBitBtn; bbM2Refine: TBitBtn; ActionPeakCenter1: TAction; ActionPeakCenter2: TAction; cbStayOnTop: TCheckBox; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ActionMassCalibrationCalculateExecute(Sender: TObject); procedure MKeyPress(Sender: TObject; var Key: Char); procedure ActionMassCalibrationRefineMassesExecute(Sender: TObject); procedure cbStayOnTopClick(Sender: TObject); procedure ActionMassCalibrationSetNewExecute(Sender: TObject); procedure ActionMassCalibrationDoNotRemeasureExecute(Sender: TObject); procedure cbUseExistingDataClick(Sender: TObject); procedure ActionPeakCenter1Execute(Sender: TObject); procedure ActionPeakCenter2Execute(Sender: TObject); procedure M1Enter(Sender: TObject); procedure M1Exit(Sender: TObject); private { Private declarations } prMassFromBottomAxiesRightClickTarget:tWinControl; procedure NotifyHandler(Sender:TObject; Event:tMI1201_Thread_Event); override; procedure MassSpectrometerSet(const MassSpectr:tMsThread); override; procedure ProcessMassSpDestroyFast; procedure ProcessCalibrationNew; procedure ProcessCalibrationMassRefined; procedure ProcessCalibrationMass; procedure ProcessCalibrationError; procedure ProcessMainChannel; procedure ProcessParameters; procedure ProcessPeakProcessing; procedure ProcessPeakProcessingEnd; procedure ProcessPeakProcessingDisbalance; procedure ProcessAll; procedure ProcessComboBox(Sender:tComboBox); procedure Msg(msg:string); function MassFromBottomAxiesRightClick(Sender:TObject; Reason:tMassNotifyReason; Mass:double):tMassNotifyAnsver; public { Public declarations } constructor Create(AOwner:TComponent); override; end; var FormMassScaleSimpleCalibration: TFormMassScaleSimpleCalibration; implementation USES MCAD_MI1201_FormSpectrum; {$R *.DFM} constructor TFormMassScaleSimpleCalibration.Create; begin Inherited Create(AOwner); prNotifyData.NotifyMask:=[evDestroy, evCalibration, evDestroy,evTerminate, evMainChannelChanged ]; end; procedure TFormMassScaleSimpleCalibration.ProcessAll; begin ProcessCalibrationNew; ProcessCalibrationMassRefined; ProcessCalibrationMass; ProcessCalibrationError; ProcessMainChannel; ProcessParameters; end; procedure TFormMassScaleSimpleCalibration.FormCreate(Sender: TObject); begin RegistryReadForm; if RegistryOpenForRead then begin RegistryReadComboBox0(M1); RegistryReadComboBox0(M2); RegistryReadComboBox0(M01); RegistryReadComboBox0(M02); try cbStayOnTop.Checked:=prRegistry.ReadBool(cbStayOnTop.Name); cbStayOnTopClick(Self); except end; prRegistry.CloseKey; end; ProcessAll; end; procedure TFormMassScaleSimpleCalibration.FormDestroy(Sender: TObject); begin if Self=FormMassScaleSimpleCalibration then begin FormMassScaleSimpleCalibration:=NIL; end; MassSpectrometerNIL; RegistryWriteForm; if RegistryOpenForWrite then begin RegistryWriteComboBox(M1); RegistryWriteComboBox(M2); RegistryWriteComboBox(M01); RegistryWriteComboBox(M02); try prRegistry.WriteBool(cbStayOnTop.Name,cbStayOnTop.Checked); except end; prRegistry.CloseKey; end; end; procedure TFormMassScaleSimpleCalibration.MassSpectrometerSet(const MassSpectr:tMsThread); begin Inherited; ProcessAll; end; procedure TFormMassScaleSimpleCalibration.NotifyHandler(Sender:TObject; Event:tMI1201_Thread_Event); begin if not Assigned(MassSpectrometer) or (Sender<>MassSpectrometer) then Exit; try case Event.EventID of evDestroy,evTerminate: begin prMsSpDestroyed:=TRUE; ProcessMassSpDestroyFast; end; evCalibration: begin case tNCEvent(Event.ParameterB) of evMassRefined: begin Synchronize(ProcessCalibrationMassRefined); end; evNewCalculated: begin Synchronize(ProcessCalibrationNew); end; evError: begin Synchronize(ProcessCalibrationError); end; evParametersChanged: begin Synchronize(ProcessParameters); end; evPeakProcessing: begin Synchronize(ProcessPeakProcessing); end; evPeakProcessing_Disbalance: begin Synchronize(ProcessPeakProcessingDisbalance); end; evPeakProcessing_End: begin Synchronize(ProcessPeakProcessingEnd); end; end; end; evMainChannelChanged: begin Synchronize(ProcessMainChannel); end; end; except end; end; procedure TFormMassScaleSimpleCalibration.ProcessMassSpDestroyFast; begin MassSpectrometerNIL; end; procedure TFormMassScaleSimpleCalibration.ActionMassCalibrationCalculateExecute( Sender: TObject); begin ProcessComboBox(M01); ProcessComboBox(M02); if not Assigned(MassSpectrometer) then Exit; try MassSpectrometer.CalibrationCur_M[0]:=StrToFloat_MSG(M1.Text); MassSpectrometer.CalibrationCur_M[1]:=StrToFloat_MSG(M2.Text); MassSpectrometer.CalibrationExact_M[0]:=StrToFloat_MSG(M01.Text); MassSpectrometer.CalibrationExact_M[1]:=StrToFloat_MSG(M02.Text); MassSpectrometer.CalibrationCalculateNewX; except end; end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationNew; begin if not Assigned(MassSpectrometer) then Exit; try eC1.Text:=IntToStr(MassSpectrometer.CalibrationNew_C[0]); eC2.Text:=IntToStr(MassSpectrometer.CalibrationNew_C[1]); edC.Text:=FloatToStr(MassSpectrometer.CalibrationNew_dC); eK.Text:=FloatToStr(MassSpectrometer.CalibrationNew_K); except end; end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationMassRefined; begin if not Assigned(MassSpectrometer) then Exit; try M1.Text:=FloatToStr(MassSpectrometer.CalibrationCur_M[0]); M2.Text:=FloatToStr(MassSpectrometer.CalibrationCur_M[1]); eDisb.Text:=FloatToStr(MassSpectrometer.CalibrationDisbalance); except end; end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationMass; begin if not Assigned(MassSpectrometer) then Exit; try M01.Text:=FloatToStr(MassSpectrometer.CalibrationExact_M[0]); M02.Text:=FloatToStr(MassSpectrometer.CalibrationExact_M[1]); except end; end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationError; begin if not Assigned(MassSpectrometer) then Exit; pStatusBar.Caption:=MassSpectrometer.CalibrationErrorMsg; pStatusBar.Hint:=pStatusBar.Caption; pStatusBar.Font.Style:=pStatusBar.Font.Style+[fsBold]; end; procedure TFormMassScaleSimpleCalibration.ProcessComboBox(Sender:tComboBox); begin AddTextToStringsListIfNotExist0(Sender); end; procedure TFormMassScaleSimpleCalibration.MKeyPress(Sender: TObject; var Key: Char); begin if not Sender.InheritsFrom(tComboBox) then Exit; case Key of #13: begin ProcessComboBox(Sender as tComboBox); end; end; end; procedure TFormMassScaleSimpleCalibration.ActionMassCalibrationRefineMassesExecute( Sender: TObject); begin if not MsOK_WithMsg then Exit; try MassSpectrometer.CalibrationCur_M[0]:=StrToFloat_MSG(M1.Text); MassSpectrometer.CalibrationCur_M[1]:=StrToFloat_MSG(M2.Text); ProcessComboBox(M01); ProcessComboBox(M02); MassSpectrometer.CalibrationRefineInitialMassesX; except end; end; procedure TFormMassScaleSimpleCalibration.cbStayOnTopClick( Sender: TObject); begin if cbStayOnTop.Checked then FormStyle:=fsStayOnTop else FormStyle:=fsNormal; end; procedure TFormMassScaleSimpleCalibration.ProcessMainChannel; begin if Assigned(MassSpectrometer) then begin lChannel.Caption:=MassSpectrometer.MainChannelName; end else begin lChannel.Caption:='?'; end; end; procedure TFormMassScaleSimpleCalibration.ActionMassCalibrationSetNewExecute( Sender: TObject); begin if Assigned(MassSpectrometer) then begin MassSpectrometer.CalibrationSetNewX; end; end; procedure TFormMassScaleSimpleCalibration.ActionMassCalibrationDoNotRemeasureExecute( Sender: TObject); begin if Sender.InheritsFrom(tCheckBox) then ActionMassCalibrationDoNotRemeasure.Checked:=(Sender as tCheckBox).Checked else ActionMassCalibrationDoNotRemeasure.Checked:=not ActionMassCalibrationDoNotRemeasure.Checked; if not Assigned(MassSpectrometer) then Exit; if ActionMassCalibrationDoNotRemeasure.Checked then begin MassSpectrometer.CalibrationFlags:=MassSpectrometer.CalibrationFlags+[fDoNotRemeasureOnMassRefine]; end else begin MassSpectrometer.CalibrationFlags:=MassSpectrometer.CalibrationFlags-[fDoNotRemeasureOnMassRefine]; end; end; procedure TFormMassScaleSimpleCalibration.ProcessParameters; begin if not Assigned(MassSpectrometer) then Exit; ActionMassCalibrationDoNotRemeasure.Checked:=(fDoNotRemeasureOnMassRefine in MassSpectrometer.CalibrationFlags); end; procedure TFormMassScaleSimpleCalibration.cbUseExistingDataClick( Sender: TObject); begin ActionMassCalibrationDoNotRemeasure.Checked:=cbUseExistingData.Checked; ActionMassCalibrationDoNotRemeasure.Execute; end; procedure TFormMassScaleSimpleCalibration.ProcessPeakProcessing; var i:integer; begin if Assigned(MassSpectrometer) then i:=MassSpectrometer.PeakInProcessing else i:=0; if i>0 then Msg('Поиск центра пика '+IntToStr(i)+'...') else Msg(''); end; procedure TFormMassScaleSimpleCalibration.ProcessPeakProcessingEnd; begin Msg('Поиск центров пиков завершен.'); end; procedure TFormMassScaleSimpleCalibration.Msg(msg:string); begin pStatusBar.Font.Style:=pStatusBar.Font.Style-[fsBold]; pStatusBar.Caption:=msg; end; procedure TFormMassScaleSimpleCalibration.ProcessPeakProcessingDisbalance; begin Msg('Определение дисбаланса...'); end; procedure TFormMassScaleSimpleCalibration.ActionPeakCenter1Execute(Sender: TObject); begin if Assigned(MassSpectrometer) then begin MassSpectrometer.CalibrationCur_M[0]:=StrToFloat_MSG(M1.Text); ProcessComboBox(M01); MassSpectrometer.CalibrationRefineMassIX(0); end; end; procedure TFormMassScaleSimpleCalibration.ActionPeakCenter2Execute( Sender: TObject); begin if Assigned(MassSpectrometer) then begin try MassSpectrometer.CalibrationCur_M[1]:=StrToFloat_MSG(M2.Text); ProcessComboBox(M02); MassSpectrometer.CalibrationRefineMassIX(1); except end; end; end; function TFormMassScaleSimpleCalibration.MassFromBottomAxiesRightClick(Sender:TObject; Reason:tMassNotifyReason; Mass:double):tMassNotifyAnsver; begin if not Assigned(prMassFromBottomAxiesRightClickTarget) then begin Result:=naCancel; end else begin case Reason of nrMass: begin Result:=naOK; if prMassFromBottomAxiesRightClickTarget.InheritsFrom(tCustomComboBox) then begin tComboBox(prMassFromBottomAxiesRightClickTarget).Text:=FloatToStr(Mass); Activate; prMassFromBottomAxiesRightClickTarget.SetFocus; end else begin Result:=naCancel; prMassFromBottomAxiesRightClickTarget:=NIL; end; end; nrAttach: begin Result:=naOK; pStatusBar.Caption:='Можно указать массу, щелкнув правой кнопкой мыши на оси М'; end; nrDetach: begin Result:=naOK; prMassFromBottomAxiesRightClickTarget:=NIL; pStatusBar.Caption:=''; end; else begin Result:=naCancel; prMassFromBottomAxiesRightClickTarget:=NIL; end; end; end; end; procedure TFormMassScaleSimpleCalibration.M1Enter(Sender: TObject); begin if Owner.InheritsFrom(tFormSpectrum) then begin try prMassFromBottomAxiesRightClickTarget:=Sender as tComboBox; tFormSpectrum(Owner).MassFromBottomAxiesRightClickNotificator:=MassFromBottomAxiesRightClick; pStatusBar.Font.Style:=pStatusBar.Font.Style-[fsBold]; except M1Exit(Sender); end; end; end; procedure TFormMassScaleSimpleCalibration.M1Exit(Sender: TObject); var ne:tMassNotifyEvent; begin if Owner.InheritsFrom(tFormSpectrum) then begin try prMassFromBottomAxiesRightClickTarget:=NIL; ne:=MassFromBottomAxiesRightClick; if (@tFormSpectrum(Owner).MassFromBottomAxiesRightClickNotificator=@ne) then tFormSpectrum(Owner).MassFromBottomAxiesRightClickNotificator:=NIL; except end; end; end; end.