From 7059a5d97cefeb6a836d8cf476074e86e5599085 Mon Sep 17 00:00:00 2001 From: Amber Date: Sat, 21 Jan 2023 23:53:03 +0300 Subject: [PATCH] Mutifile Calibration --- BecquerelMonitor/BecquerelMonitor.csproj | 4 +- .../DCEnergyCalibrationView.Designer.cs | 15 +++- BecquerelMonitor/DCEnergyCalibrationView.cs | 80 ++++++++++++++----- BecquerelMonitor/DCEnergyCalibrationView.resx | 32 +++++++- .../DCEnergyCalibrationView.ru.resx | 6 ++ BecquerelMonitor/MainForm.cs | 9 +++ BecquerelMonitor/Properties/AssemblyInfo.cs | 4 +- BecquerelMonitor/ResultData.cs | 15 ++++ BecquerelMonitor/Utils/CalibrationSolver.cs | 5 +- 9 files changed, 142 insertions(+), 28 deletions(-) diff --git a/BecquerelMonitor/BecquerelMonitor.csproj b/BecquerelMonitor/BecquerelMonitor.csproj index 5688fcd..b6a513a 100644 --- a/BecquerelMonitor/BecquerelMonitor.csproj +++ b/BecquerelMonitor/BecquerelMonitor.csproj @@ -35,8 +35,8 @@ 2022.07.08.7 true index.html - 2 - 2023.01.21.2 + 4 + 2023.01.21.4 true true true diff --git a/BecquerelMonitor/DCEnergyCalibrationView.Designer.cs b/BecquerelMonitor/DCEnergyCalibrationView.Designer.cs index 9853435..9810392 100644 --- a/BecquerelMonitor/DCEnergyCalibrationView.Designer.cs +++ b/BecquerelMonitor/DCEnergyCalibrationView.Designer.cs @@ -52,7 +52,8 @@ void InitializeComponent() this.toolTip1 = new global::System.Windows.Forms.ToolTip(this.components); this.button7 = new global::System.Windows.Forms.Button(); this.button11 = new global::System.Windows.Forms.Button(); - this.label36 = new global::System.Windows.Forms.Label(); + this.button14 = new global::System.Windows.Forms.Button(); + this.label36 = new global::System.Windows.Forms.Label(); this.panel1 = new global::System.Windows.Forms.Panel(); this.button9 = new global::System.Windows.Forms.Button(); this.button8 = new global::System.Windows.Forms.Button(); @@ -197,6 +198,7 @@ void InitializeComponent() this.panel1.Controls.Add(this.numericUpDown6); this.panel1.Controls.Add(this.label37); this.panel1.Controls.Add(this.checkBox2); + this.panel1.Controls.Add(this.button14); this.panel1.Name = "panel1"; componentResourceManager.ApplyResources(this.checkBox2, "checkBox2"); this.checkBox2.Name = "checkBox2"; @@ -204,6 +206,11 @@ void InitializeComponent() this.checkBox2.UseVisualStyleBackColor = true; this.checkBox2.Checked = false; this.checkBox2.Click += new global::System.EventHandler(this.checkBox2_Click); + componentResourceManager.ApplyResources(this.button14, "button14"); + this.button14.Name = "button14"; + this.toolTip1.SetToolTip(this.button14, componentResourceManager.GetString("button14.ToolTip")); + this.button14.UseVisualStyleBackColor = true; + this.button14.Click += new global::System.EventHandler(this.button14_Click); componentResourceManager.ApplyResources(this.numericUpDown6, "numericUpDown6"); this.numericUpDown6.Name = "numericUpDown6"; this.numericUpDown6.Increment = 1; @@ -367,8 +374,10 @@ void InitializeComponent() // Token: 0x04000433 RID: 1075 global::System.Windows.Forms.Button button11; - // Token: 0x04000434 RID: 1076 - global::System.Windows.Forms.Label label36; + global::System.Windows.Forms.Button button14; + + // Token: 0x04000434 RID: 1076 + global::System.Windows.Forms.Label label36; global::System.Windows.Forms.Label label6; diff --git a/BecquerelMonitor/DCEnergyCalibrationView.cs b/BecquerelMonitor/DCEnergyCalibrationView.cs index cbbff11..bcf2c7f 100644 --- a/BecquerelMonitor/DCEnergyCalibrationView.cs +++ b/BecquerelMonitor/DCEnergyCalibrationView.cs @@ -27,6 +27,20 @@ public DCEnergyCalibrationView(MainForm mainForm) void DCEnergyCalibrationView_Load(object sender, EventArgs e) { this.HideMultipointForm(); + this.LoadCalibrationPoints(); + } + + public void LoadCalibrationPoints() + { + if (this.mainForm.ActiveDocument != null && + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0) + { + List points = this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints; + foreach (CalibrationPoint point in points) + { + AddCalibration(point.Channel, point.Energy, point.Count); + } + } } // Token: 0x06000815 RID: 2069 RVA: 0x0002DD18 File Offset: 0x0002BF18 @@ -65,7 +79,7 @@ public void SetEnergyCalibration(EnergyCalibration energyCalibration, EnergyCali this.numericUpDown4.Text = this.energyCalibration.Coefficients[4].ToString(); } this.formLoading = false; - this.calibrationPoints.Clear(); + //this.calibrationPoints.Clear(); this.ShowCalibrationPoints(); this.UpdateMultipointButtonState(); } @@ -374,9 +388,16 @@ void button8_Click(object sender, EventArgs e) // Token: 0x06000829 RID: 2089 RVA: 0x0002E478 File Offset: 0x0002C678 void UpdateMultipointButtonState() { - this.button7.Enabled = (this.calibrationPoints.Count > 0 && !this.channelPickupProcessing && this.multipointModified); + if (this.mainForm.ActiveDocument != null) + { + this.button7.Enabled = (this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0 && !this.channelPickupProcessing && this.multipointModified); + this.button9.Enabled = (this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0 && !this.channelPickupProcessing); + } else + { + this.button7.Enabled = false; + this.button9.Enabled = false; + } this.button8.Enabled = (!this.channelPickupProcessing); - this.button9.Enabled = (this.calibrationPoints.Count > 0 && !this.channelPickupProcessing); this.button11.Enabled = this.channelPickupProcessing; if (this.calibrationDone) { @@ -400,7 +421,7 @@ void energySpectrumView_ChannelPickuped(object sender, ChannelPickupedEventArgs } decimal energy = Math.Round((decimal)this.energyCalibration.ChannelToEnergy((double)e.Channel), 2); CalibrationPoint item = new CalibrationPoint(e.Channel, energy, e.Count); - this.calibrationPoints.Add(item); + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Add(item); this.multipointModified = true; this.calibrationDone = false; this.ShowCalibrationPoints(); @@ -410,7 +431,7 @@ void energySpectrumView_ChannelPickuped(object sender, ChannelPickupedEventArgs public void AddCalibration(int channel, decimal energy, int count) { CalibrationPoint item = new CalibrationPoint(channel, energy, count); - this.calibrationPoints.Add(item); + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Add(item); this.multipointModified = true; this.calibrationDone = false; this.ShowCalibrationPoints(); @@ -447,13 +468,13 @@ void button9_Click(object sender, EventArgs e) { num = 0; } - if (num < 0 && num >= this.calibrationPoints.Count) + if (num < 0 && num >= this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count) { return; } try { - this.calibrationPoints.RemoveAt(num); + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.RemoveAt(num); } catch { @@ -471,8 +492,8 @@ void ShowCalibrationPoints() int num = 1; this.table1.SuspendLayout(); this.tableModel1.Rows.Clear(); - this.calibrationPoints.Sort(); - foreach (CalibrationPoint calibrationPoint in this.calibrationPoints) + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Sort(); + foreach (CalibrationPoint calibrationPoint in this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints) { Row row = new Row(); row.Cells.Add(new Cell(num.ToString())); @@ -508,10 +529,10 @@ void table1_EditingStopped(object sender, CellEditEventArgs e) if (e.Column == 1) { string text = ((NumberCellEditor)e.Editor).TextBox.Text; - this.calibrationPoints[row.Index].Channel = (int)decimal.Parse(text); - if (this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum.Length > this.calibrationPoints[row.Index].Channel) + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Channel = (int)decimal.Parse(text); + if (this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum.Length > this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Channel) { - this.calibrationPoints[row.Index].Count = this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum[this.calibrationPoints[row.Index].Channel]; + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Count = this.mainForm.ActiveDocument.ActiveResultData.EnergySpectrum.Spectrum[this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Channel]; } else { @@ -525,7 +546,7 @@ void table1_EditingStopped(object sender, CellEditEventArgs e) else if (e.Column == 2) { string text2 = ((NumberCellEditor)e.Editor).TextBox.Text; - this.calibrationPoints[row.Index].Energy = decimal.Parse(text2); + this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints[row.Index].Energy = decimal.Parse(text2); this.multipointModified = true; this.calibrationDone = false; this.UpdateMultipointButtonState(); @@ -538,9 +559,35 @@ void table1_EditingStopped(object sender, CellEditEventArgs e) } } + void button14_Click(object sender, EventArgs e) + { + List points = new List(); + + if (this.mainForm.DocumentList != null) + { + foreach (DocEnergySpectrum doc in this.mainForm.DocumentList) + { + foreach(ResultData data in doc.ResultDataFile.ResultDataList) + { + if (data.CalibrationPoints.Count > 0) + { + points.AddRange(data.CalibrationPoints); + } + } + } + foreach (CalibrationPoint point in points) + { + AddCalibration(point.Channel, point.Energy, point.Count); + } + } + } + void checkBox2_Click(object sender, EventArgs e) { - this.button7.Enabled = true; + if (this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints.Count > 0) + { + this.button7.Enabled = true; + } } // Token: 0x06000831 RID: 2097 RVA: 0x0002E8C0 File Offset: 0x0002CAC0 @@ -553,7 +600,7 @@ void button7_Click(object sender, EventArgs e) int PolynomOrder = (int)this.numericUpDown6.Value; double[] matrix; - List points = this.calibrationPoints; + List points = this.mainForm.ActiveDocument.ActiveResultData.CalibrationPoints; if (points.Count == 1) { CalibrationPoint zero = new CalibrationPoint(0, 0, 0); @@ -674,8 +721,5 @@ void DCEnergyCalibrationView_SizeChanged(object sender, EventArgs e) // Token: 0x0400041D RID: 1053 bool multipointModified; - - // Token: 0x0400041E RID: 1054 - List calibrationPoints = new List(); } } diff --git a/BecquerelMonitor/DCEnergyCalibrationView.resx b/BecquerelMonitor/DCEnergyCalibrationView.resx index 199e9b7..5d0c430 100644 --- a/BecquerelMonitor/DCEnergyCalibrationView.resx +++ b/BecquerelMonitor/DCEnergyCalibrationView.resx @@ -460,7 +460,7 @@ $this - 159, 5 + 115, 5 groupBox1 @@ -1131,4 +1131,34 @@ Top, Right + + 0 + + + 9 + + + 185, 5 + + + button14 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + NoControl + + + Get all points + + + Get all calibration points from all documents in this table + + + 66, 23 + + + panel1 + \ No newline at end of file diff --git a/BecquerelMonitor/DCEnergyCalibrationView.ru.resx b/BecquerelMonitor/DCEnergyCalibrationView.ru.resx index c98bb6b..7d9100f 100644 --- a/BecquerelMonitor/DCEnergyCalibrationView.ru.resx +++ b/BecquerelMonitor/DCEnergyCalibrationView.ru.resx @@ -687,4 +687,10 @@ Использовать точки калибровки с весами, которые рассчитываются исходя из числа импульсов на этом канале. + + Собрать всё + + + Собрать все точки калибровки по всем открытым документам в этой таблице + \ No newline at end of file diff --git a/BecquerelMonitor/MainForm.cs b/BecquerelMonitor/MainForm.cs index 0f03bd9..d3bdd8d 100644 --- a/BecquerelMonitor/MainForm.cs +++ b/BecquerelMonitor/MainForm.cs @@ -2033,6 +2033,7 @@ public void RefreshAllView() if (this.dcEnergyCalibrationView != null) { this.dcEnergyCalibrationView.UpdateEnergyCalibrationConfig(); + this.dcEnergyCalibrationView.LoadCalibrationPoints(); } foreach (DocEnergySpectrum docEnergySpectrum in this.documentManager.DocumentList) { @@ -2431,6 +2432,14 @@ void CloseAllDocuments() } } + public List DocumentList + { + get + { + return this.documentManager.DocumentList; + } + } + // Token: 0x040005C7 RID: 1479 LayoutMode layoutMode; diff --git a/BecquerelMonitor/Properties/AssemblyInfo.cs b/BecquerelMonitor/Properties/AssemblyInfo.cs index fb77994..399e9bb 100644 --- a/BecquerelMonitor/Properties/AssemblyInfo.cs +++ b/BecquerelMonitor/Properties/AssemblyInfo.cs @@ -4,13 +4,13 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -[assembly: AssemblyVersion("2023.01.21.2")] +[assembly: AssemblyVersion("2023.01.21.4")] [assembly: AssemblyProduct("BecquerelMonitor")] [assembly: AssemblyCopyright("free")] [assembly: AssemblyTrademark("none")] [assembly: AssemblyConfiguration("")] [assembly: Guid("40110b38-4882-47c1-ad94-a71e58dcb5f8")] -[assembly: AssemblyFileVersion("2023.01.21.2")] +[assembly: AssemblyFileVersion("2023.01.21.4")] [assembly: AssemblyDescription("")] [assembly: AssemblyCompany("free")] [assembly: CompilationRelaxations(8)] diff --git a/BecquerelMonitor/ResultData.cs b/BecquerelMonitor/ResultData.cs index c7cfe72..3beb844 100644 --- a/BecquerelMonitor/ResultData.cs +++ b/BecquerelMonitor/ResultData.cs @@ -336,6 +336,19 @@ public PeakDetectionMethodConfig PeakDetectionMethodConfig } } + [XmlIgnore] + public List CalibrationPoints + { + get + { + return this.calibrationPoints; + } + set + { + this.calibrationPoints = value; + } + } + // Token: 0x170001F9 RID: 505 // (get) Token: 0x0600069B RID: 1691 RVA: 0x00027B38 File Offset: 0x00025D38 // (set) Token: 0x0600069C RID: 1692 RVA: 0x00027B40 File Offset: 0x00025D40 @@ -468,5 +481,7 @@ public ResultData(ResultData_097b old) // Token: 0x04000376 RID: 886 List calibrationPeaks = new List(); + + List calibrationPoints = new List(); } } diff --git a/BecquerelMonitor/Utils/CalibrationSolver.cs b/BecquerelMonitor/Utils/CalibrationSolver.cs index 1a1b324..823b8ab 100644 --- a/BecquerelMonitor/Utils/CalibrationSolver.cs +++ b/BecquerelMonitor/Utils/CalibrationSolver.cs @@ -61,6 +61,7 @@ public static double[] SolveWeighted (List points, int Polynom double[,] dense_weight = new double[points.Count, points.Count]; double max_count = 1.0; + double max_count_sqrt = 1.0; for (int i = 0; i < points.Count; i++) { if (points[i].Count > max_count) @@ -68,7 +69,7 @@ public static double[] SolveWeighted (List points, int Polynom max_count = points[i].Count; } } - max_count = Math.Sqrt(max_count); + max_count_sqrt = Math.Sqrt(max_count); for (int i = 0; i < points.Count; i++) { @@ -76,7 +77,7 @@ public static double[] SolveWeighted (List points, int Polynom { if (i == j) { - dense_weight[i, j] = Math.Sqrt((double)points[i].Count) / (double)max_count; + dense_weight[i, j] = Math.Sqrt((double)points[i].Count) / max_count_sqrt; } else {