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_Thread01, MCAD_MI1201_Thread2, MCAD_MI1201_Thread, ComCtrls, Grids; resourcestring rsncCoeff='Коэфф. K'; rsncCounterShift='Сдвиг сч. dC'; rsncCounterM1='Счетчик M1'; rsncCounterM2='Счетчик M2'; type tsgNewCalibrationRow=( sgncr_K, sgncr_dC, sgncr_C1, sgncr_C2 ); 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; bCalculate: TButton; bSetUp: TButton; ActionListMassCalibration: TActionList; ActionMassCalibrationCalculate: TAction; ActionMassCalibrationRefineMasses: TAction; ActionMassCalibrationSetNew: TAction; cbUseExistingData: TCheckBox; ActionMassCalibrationDoNotRemeasure: TAction; pDisbalance: TPanel; eDisb: TEdit; bbM1Refine: TBitBtn; bbM2Refine: TBitBtn; ActionPeakCenter1: TAction; ActionPeakCenter2: TAction; cbStayOnTop: TCheckBox; pStatusBar: TStatusBar; bStop: TButton; ActionCalibrationStop: TAction; sgNewCalibration: TStringGrid; 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); procedure ActionCalibrationStopExecute(Sender: TObject); procedure sgNewCalibrationGetEditText(Sender: TObject; ACol, ARow: Integer; var Value: String); procedure sgNewCalibrationSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); private prOldsgNewCalibration:string; { 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 ProcessCalibrationCommandPending; procedure ProcessCalibrationCommandEnd; 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 sgNewCalibration.RowCount:=Succ(ord(High(tsgNewCalibrationRow))); sgNewCalibration.Cells[0,Ord(sgncr_K)]:=rsncCoeff; sgNewCalibration.Cells[0,Ord(sgncr_dC)]:=rsncCounterShift; sgNewCalibration.Cells[0,Ord(sgncr_C1)]:=rsncCounterM1; sgNewCalibration.Cells[0,Ord(sgncr_C2)]:=rsncCounterM2; 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 evCalibrationCommandPending: begin Synchronize(ProcessCalibrationCommandPending); end; evCalibrationCommandEnd: begin Synchronize(ProcessCalibrationCommandEnd); end; evCalibrationMassRefined: begin Synchronize(ProcessCalibrationMassRefined); end; evCalibrationNewCalculated: begin Synchronize(ProcessCalibrationNew); end; evCalibrationError: begin Synchronize(ProcessCalibrationError); end; evCalibrationParametersChanged: begin Synchronize(ProcessParameters); end; evCalibrationPeakProcessing: begin Synchronize(ProcessPeakProcessing); end; evCalibrationPeakProcessing_Disbalance: begin Synchronize(ProcessPeakProcessingDisbalance); end; evCalibrationPeakProcessing_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 sgNewCalibration.Cells[1,Ord(sgncr_K)]:=FloatToStr(MassSpectrometer.CalibrationNew_K); sgNewCalibration.Cells[1,Ord(sgncr_dC)]:=FloatToStr(MassSpectrometer.CalibrationNew_dC); sgNewCalibration.Cells[1,Ord(sgncr_C1)]:=IntToStr(MassSpectrometer.CalibrationNew_C[0]); sgNewCalibration.Cells[1,Ord(sgncr_C2)]:=IntToStr(MassSpectrometer.CalibrationNew_C[1]); except end; end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationMassRefined; begin if not Assigned(MassSpectrometer) then Exit; try if (0 in MassSpectrometer.CalibrationCur_M_Refined) then M1.Text:=FloatToStr(MassSpectrometer.CalibrationCur_M[0]); if (1 in MassSpectrometer.CalibrationCur_M_Refined) then M2.Text:=FloatToStr(MassSpectrometer.CalibrationCur_M[1]); if (MassSpectrometer.CalibrationDisbalanceValid) then eDisb.Text:=IntToStr(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.Panels[2].Text:=MassSpectrometer.CalibrationErrorMsg; pStatusBar.Hint:=pStatusBar.Panels[2].Text; if MassSpectrometer.CalibrationError<>nceOK then pStatusBar.Font.Style:=pStatusBar.Font.Style+[fsBold] else pStatusBar.Font.Style:=pStatusBar.Font.Style-[fsBold]; if (MassSpectrometer.CalibrationError<>nceOK) then ProcessCalibrationCommandEnd; 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 pStatusBar.Panels[1].Text:=MassSpectrometer.MainChannelName; end else begin pStatusBar.Panels[1].Text:='?'; 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+[fCalibrationDoNotRemeasureOnMassRefine]; end else begin MassSpectrometer.CalibrationFlags:=MassSpectrometer.CalibrationFlags-[fCalibrationDoNotRemeasureOnMassRefine]; end; end; procedure TFormMassScaleSimpleCalibration.ProcessParameters; begin if not Assigned(MassSpectrometer) then Exit; ActionMassCalibrationDoNotRemeasure.Checked:=(fCalibrationDoNotRemeasureOnMassRefine 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.CalibrationPeakInProcessing else i:=0; if i>0 then Msg('Поиск центра пика '+IntToStr(i)+'...') else Msg(''); end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationCommandPending; begin ActionCalibrationStop.Enabled:=TRUE; bPeakCentersFind.Enabled:=FALSE; bCalculate.Enabled:=FALSE; bSetUp.Enabled:=FALSE; bbM1Refine.Enabled:=FALSE; bbM2Refine.Enabled:=FALSE; end; procedure TFormMassScaleSimpleCalibration.ProcessCalibrationCommandEnd; begin ActionCalibrationStop.Enabled:=FALSE; bPeakCentersFind.Enabled:=TRUE; bCalculate.Enabled:=TRUE; bSetUp.Enabled:=TRUE; bbM1Refine.Enabled:=TRUE; bbM2Refine.Enabled:=TRUE; end; procedure TFormMassScaleSimpleCalibration.ProcessPeakProcessingEnd; begin if Assigned(MassSpectrometer) then begin if MassSpectrometer.CalibrationError=nceOK then begin Msg('Поиск центров пиков завершен.'); end else begin Msg('Поиск центров пиков завершен c ОШИБКОЙ: '+MassSpectrometer.CalibrationErrorMsg); end; end else begin Msg('Поиск центров пиков завершен.'); end; // ProcessCalibrationCommandEnd; end; procedure TFormMassScaleSimpleCalibration.Msg(msg:string); begin pStatusBar.Font.Style:=pStatusBar.Font.Style-[fsBold]; pStatusBar.Panels[2].Text:=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.Panels[2].Text:='Можно указать массу, щелкнув правой кнопкой мыши на оси М'; end; nrDetach: begin Result:=naOK; prMassFromBottomAxiesRightClickTarget:=NIL; pStatusBar.Panels[2].Text:=''; 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 ne:=MassFromBottomAxiesRightClick; if (@tFormSpectrum(Owner).MassFromBottomAxiesRightClickNotificator=@ne) then tFormSpectrum(Owner).MassFromBottomAxiesRightClickNotificator:=NIL; except end; prMassFromBottomAxiesRightClickTarget:=NIL; end; end; procedure TFormMassScaleSimpleCalibration.ActionCalibrationStopExecute( Sender: TObject); begin if Assigned(MassSpectrometer) then begin if MassSpectrometer.CalibrationTerminated=TRUE then begin ProcessCalibrationCommandEnd; end; MassSpectrometer.CalibrationTerminated:=TRUE; end; end; procedure TFormMassScaleSimpleCalibration.sgNewCalibrationGetEditText( Sender: TObject; ACol, ARow: Integer; var Value: String); begin prOldsgNewCalibration:=Value; end; procedure TFormMassScaleSimpleCalibration.sgNewCalibrationSetEditText( Sender: TObject; ACol, ARow: Integer; const Value: String); begin if Value<>prOldsgNewCalibration then begin sgNewCalibration.Cells[ACol, ARow]:=prOldsgNewCalibration; end; end; end.