unit PeakControl; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, MITypes, MCAD_MI1201_Thread_Types, MCAD_MI1201_Form, ExtCtrls; Const Heights :array[boolean]of longint = (143,364); ResourceString cNoiseLevelError = '-1'; type TFormPeakCentering = class(TXForm) Label1: TLabel; FindPeakButton : TButton; CheckBoxShowMore : TCheckBox; ComboBoxMass: TComboBox; GroupBoxPeakParams: TGroupBox; Label2: TLabel; LabelRealMass: TLabel; Label9: TLabel; Label10: TLabel; LabelMaximum: TLabel; LabelRightBound: TLabel; Label13: TLabel; LabelLeftBound: TLabel; PanelAdditionalProperties: TPanel; Label4: TLabel; GroupBoxNoiseSetup: TGroupBox; Label5: TLabel; Label6: TLabel; Label3: TLabel; CheckBoxNoiseInterval: TCheckBox; RecalcNoiseButton: TButton; LeftNoiseRangeEdit: TEdit; RightNoiseRangeEdit: TEdit; NoiseEdit: TEdit; ButtonSetMassCalibration: TButton; ListBoxSavedPeaks: TListBox; GroupBoxTimerSetup: TGroupBox; Label7: TLabel; Label8: TLabel; CheckBoxTimerState: TCheckBox; EditRemeasureInterval: TEdit; ComboBoxRemeasureMass: TComboBox; TimerReMeasurePeak: TTimer; procedure FindPeakButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure ListBoxSavedPeaksDblClick(Sender: TObject); procedure ButtonSetMassCalibrationClick(Sender: TObject); procedure RecalcNoiseButtonClick(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure NotifyHandler(Sender:TObject; Event:tMI1201_Thread_Event); override; procedure CheckBoxShowMoreClick(Sender: TObject); procedure CheckBoxTimerStateClick(Sender: TObject); procedure TimerReMeasurePeakTimer(Sender: TObject); private { Private declarations } Measuring :boolean; // Флаг запущенного измерения RemeasureMass :tMass; // Перемеряемая масса procedure MainChannelCange; procedure FormStateChange; procedure RefreshPeakParams; function AddNumberToStr(Const S:String; Number:double):string; procedure AddNumberToStrs(Const S:TStrings; Number:double); procedure AddToComboBox(Cb:TComboBox; N:tMass); procedure SortToList(S:TStrings;st:openstring); public { Public declarations } end; var FormPeakCentering: TFormPeakCentering; procedure Execute(Sender:tObject); implementation Uses MCAD_MI1201_Thread1, MCAD_MI1201_FormSpectrum, MCAD_MI1201_TChartSeries; {$R *.DFM} Procedure Execute; begin if not Assigned(FormPeakCentering) then try FormPeakCentering := TFormPeakCentering.Create(FormSpectrum); except FormPeakCentering := nil; exit; end; FormPeakCentering.MainChannelCange; FormPeakCentering.Show; end; procedure TFormPeakCentering.MainChannelCange; ResourceString cFormPeakCaption = 'Поиск центра пика - '; begin FormPeakCentering.Caption := cFormPeakCaption + cMSSeriesTitles[FormSpectrum.MassSpectrometer.MainChannel]; RecalcNoiseButtonClick(Self); end; procedure TFormPeakCentering.FormStateChange; begin Height := Heights[CheckBoxShowMore.Checked]; PanelAdditionalProperties.Visible := CheckBoxShowMore.Checked; end; procedure TFormPeakCentering.FormCreate(Sender: TObject); Procedure TimerSetup; begin CheckBoxTimerState.Checked := False; RemeasureMass := 0; // Возможно её нужно будет сохранять и восстанавливать ComboBoxRemeasureMass.Text := ''; ComboBoxRemeasureMass.Items.Clear; EditRemeasureInterval.Text := ''; TimerRemeasurePeak.Enabled := False; Measuring := False; end; Procedure NoiseSetup; begin CheckBoxNoiseInterval.Checked := False; NoiseEdit.Text := ''; LeftNoiseRangeEdit.Text := ''; RightNoiseRangeEdit.Text := ''; end; Procedure FormAndMassSetup; begin MassSpectrometer := FormSpectrum.MassSpectrometer; CheckBoxShowMore.Checked := True; FormStateChange; ComboBoxMass.Text := ''; ComboBoxMass.Items.Clear; LabelRealMass.Caption := ''; LabelMaximum.Caption := ''; LabelLeftBound.Caption := ''; LabelRightBound.Caption := ''; ListBoxSavedPeaks.Items.Clear; end; begin FormAndMassSetup; NoiseSetup; TimerSetup; // Вообще, нужно ли это??? if not Assigned(MassSpectrometer) then Exit; end; procedure TFormPeakCentering.NotifyHandler(Sender:TObject; Event:tMI1201_Thread_Event); begin Case Event.EventID of evMainChannelChanged: Synchronize(MainChannelCange); evDestroy, evTerminate: MassSpectrometerNIL; else end; //Case end; Procedure TFormPeakCentering.SortToList(S:TStrings;st:openstring); Var i:Longint; begin With S do begin Insert(0, St); for i := 1 to Count - 1 do if Strings[0] = Strings[i] then begin Delete(i); break; end; end; //With end; Procedure TFormPeakCentering.RefreshPeakParams; Const cErrorText = 'Ошибка!'; begin with MassSpectrometer do with PeakData, DataSeries[MainChannel] do begin LabelRealMass.Caption := FloatToStr(PeakCenter); LabelMaximum.Caption := FloatToStr(YValues[IndexOfMaximum]); if not LeftLimit then LabelLeftBound.Caption := FloatToStr(XValues[LeftBound]) else LabelLeftBound.Caption := cErrorText; if not RightLimit then LabelRightBound.Caption := FloatToStr(XValues[RightBound]) else LabelRightBound.Caption := cErrorText; end; //with end; procedure TFormPeakCentering.FindPeakButtonClick(Sender: TObject); begin if not Assigned(MassSpectrometer) then Exit; With MassSpectrometer do begin NoiseLevel := StrToFloat_MSG(NoiseEdit.Text); ProcessMessages; try CenterOfPeakMeasure(StrToFloat_MSG(ComboBoxMass.Text)); except exit end; RefreshPeakParams; SortToList(ListBoxSavedPeaks.Items, LabelRealMass.Caption); ListBoxSavedPeaks.ItemIndex := 0; SortToList(ComboBoxMass.Items, ComboBoxMass.Text); ComboBoxMass.ItemIndex := 0; end; //with end; procedure TFormPeakCentering.ListBoxSavedPeaksDblClick(Sender: TObject); begin With ListBoxSavedPeaks do LabelRealMass.Caption := Items[ItemIndex]; end; function TFormPeakCentering.AddNumberToStr(Const S:String; Number:double):string; begin if Length(s) = 0 then Result := s else Result := FloatToStr(StrToFloat_MSG(s) + Number); end; Procedure TFormPeakCentering.AddNumberToStrs(Const S:TStrings; Number:double); Var i:longint; begin For i := 0 to S.Count - 1 do S[i] := AddNumberToStr(S[i], Number); end; Procedure TFormPeakCentering.AddToComboBox(Cb:TComboBox; N:tMass); begin with CB do begin AddNumberToStrS(Items, N); ItemIndex := 0; Text := AddNumberToStr(Text, N); end; //with end; procedure TFormPeakCentering.ButtonSetMassCalibrationClick(Sender: TObject); Const cEOL = #13#10; ResourceString cEnterRealMass = 'Задайте истинную массу для центра пика:'; Var RealMass :tMass; St :String; begin if not Assigned(MassSpectrometer) then Exit; Repeat try St := InputBox('Настройка шкалы масс', cEnterRealMass, ''); if Length(St) = 0 then exit; RealMass := StrToFloat_MSG(St); except RealMass := -1; end; Until RealMass <> - 1; // Предполагаем, что в LabelRealMass корректное число, т.к. он ReadOnly RealMass := RealMass - StrToFloat(LabelRealMass.Caption); AddNumberToStrS(ListBoxSavedPeaks.Items, RealMass); ListBoxSavedPeaks.ItemIndex := 0; AddToComboBox(ComboBoxMass, RealMass); AddToComboBox(ComboBoxRemeasureMass, RealMass); LabelRealMass.Caption := AddNumberToStr(LabelRealMass.Caption, RealMass); if not MassSpectrometer.LimitOfRange then begin LabelLeftBound.Caption := AddNumberToStr(LabelLeftBound.Caption, RealMass); LabelRightBound.Caption := AddNumberToStr(LabelRightBound.Caption, RealMass); end; ProcessMessages; With MassSpectrometer do try RefineMass(Mass + RealMass); except end; end; procedure TFormPeakCentering.RecalcNoiseButtonClick(Sender: TObject); begin if not Assigned(MassSpectrometer) then begin NoiseEdit.Text := cNoiseLevelError; Exit; end; with MassSpectrometer do begin if not CheckBoxNoiseInterval.Checked then begin NoiseEdit.Text := FloatToStr(GetNoiseLevel); exit; end; NoiseEdit.Text := FloatToStr(GetNoiseLevelRange( StrToFloat_MSG(LeftNoiseRangeEdit.Text), StrToFloat_MSG(RightNoiseRangeEdit.Text))); end;//with end; procedure TFormPeakCentering.FormDestroy(Sender: TObject); begin if Self = FormPeakCentering then begin FormPeakCentering := nil; MassSpectrometerNIL; end; end; procedure TFormPeakCentering.CheckBoxShowMoreClick(Sender: TObject); begin FormStateChange; end; procedure TFormPeakCentering.CheckBoxTimerStateClick(Sender: TObject); Const MinToMSec = 60 * 1000; begin With TimerRemeasurePeak do begin Interval := Round(StrToFloat_MSG(EditRemeasureInterval.Text) * MinToMSec); if Interval < MinToMsec then begin CheckBoxTimerState.Checked := False; exit; end; ProcessMessages; RemeasureMass := StrToFloat_MSG(ComboBoxRemeasureMass.Text); SortToList(ComboBoxRemeasureMass.Items, FloatToStr(RemeasureMass)); Enabled := CheckBoxTimerState.Checked; end; //with end; procedure TFormPeakCentering.TimerReMeasurePeakTimer(Sender: TObject); begin // Если идёт измерение, то выходим if Measuring then exit; Measuring := True; // Ставим флаг измерения if not assigned(MassSpectrometer) then begin TimerRemeasurePeak.Enabled := False; CheckBoxTimerState.Checked := False; exit; end; ProcessMessages; RemeasureMass := MassSpectrometer.CenterOfPeakMeasure(RemeasureMass); SortToList(ListBoxSavedPeaks.Items, FloatToStr(RemeasureMass)); ComboBoxRemeasureMass.Text := FloatToStr(RemeasureMass); Measuring := False; // Измерение закончено end; end.