private void 粗曲线ToolStripMenuItem_Click(object sender, EventArgs e) { if (粗曲线ToolStripMenuItem.Checked) { 粗曲线ToolStripMenuItem.Checked = false; boldLineWidth = 1; for (int i = 0; i < Chart_spec.SeriesCount; i++) { if (i == 1) { continue; } Chart_spec.Series(i).asFastLine.LinePen.Width = boldLineWidth; } } else { 粗曲线ToolStripMenuItem.Checked = true; boldLineWidth = 2; for (int i = 0; i < Chart_spec.SeriesCount; i++) { if (i == 1) { continue; } Chart_spec.Series(i).asFastLine.LinePen.Width = boldLineWidth; } } }
private void toolStripMenuItem2_Click(object sender, EventArgs e) { if (Chart_spec.Series(1).XValues.Count < 1) { return; } double xval = Chart_spec.Tools.Items[2].asTeeCursor.XVal; //uint color = Chart_spec.Series(1).Color; int index = 0; double minvalue = Math.Abs(Chart_spec.Series(1).XValues.Value[0] - xval); for (int i = 0; i < Chart_spec.Series(1).XValues.Count; i++) { if (Math.Abs(Chart_spec.Series(1).XValues.Value[i] - xval) < minvalue) { minvalue = Math.Abs(Chart_spec.Series(1).XValues.Value[i] - xval); index = i; } } if (minvalue < 30) { colorBar1.removeLine(Chart_spec.Series(1).XValues.Value[index]); Chart_spec.Series(1).Delete(index); } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Rows.Count > 0) { int columnIndex = e.ColumnIndex; if (columnIndex == 0) { int rowIndex = e.RowIndex; Boolean value = Boolean.Parse(this.dataGridView1.Rows[rowIndex].Cells[columnIndex].EditedFormattedValue.ToString()); if (value) { if (rowIndex == 0) { Chart_spec.Series(rowIndex).Active = true; } else { Chart_spec.Series(rowIndex + 1).Active = true; } } else { if (rowIndex == 0) { Chart_spec.Series(rowIndex).Active = false; } else { Chart_spec.Series(rowIndex + 1).Active = false; } } } } }
private void toolStripMenuItem1_Click(object sender, EventArgs e) { double Xva = Chart_spec.Series(0).MouseValues.X; double Yva = Chart_spec.MousePosition.Y; if (Chart_spec.Series(0).XValues.Count < 1) { return; } double xval = Chart_spec.Tools.Items[3].asTeeCursor.XVal; uint color = Chart_spec.Series(1).Color; int index = 0; double minvalue = Math.Abs(Chart_spec.Series(0).XValues.Value[0] - xval); for (int i = 0; i < Chart_spec.Series(0).XValues.Count; i++) { if (Math.Abs(Chart_spec.Series(0).XValues.Value[i] - xval) < minvalue) { minvalue = Math.Abs(Chart_spec.Series(0).XValues.Value[i] - xval); index = i; } } double yval = Chart_spec.Series(0).YValues.Value[index]; Chart_spec.Series(1).AddXY(xval, yval, xval.ToString("f3"), color); colorBar1.drawLine(xval); }
private void 清除峰位ToolStripMenuItem_Click(object sender, EventArgs e) { if (Chart_spec.Series(1).Active&& Chart_spec.Series(1).Count > 0) { Chart_spec.Series(1).Clear(); } colorBar1.clearLine(); }
private void Form1_Load(object sender, EventArgs e) { Chart_spec.Series(0).Clear(); Chart_spec.Series(1).Clear(); Chart_spec.Series(1).VerticalAxisCustom = 0; processSpec = new ProcessSpec(); processSpec.OnAddLines += chart_Spectrum_addLine; processSpec.setMinMaxWave += resetChartMinMax; processSpec.addSpecLine += addSpecSeries; fittingControl1.stopGetSpec += StopThread; fittingControl1.selectTablePage2 += selectTablePage; fittingControl1.setRemarks += setRemarks; fittingControl1.addSpecLine += addSpecSeries; fittingControl1.setSignEvent += addSignFittingChart; string str = "select max(ID) from JewDataTable "; string obj = SqliteHelper.ExecuteScalar(str).ToString(); //int id = (int.Parse(obj) + 1); processSpec.JewID = (int.Parse(obj) + 1); addJewDataControl1.processSpec = processSpec; addJewDataControl1.loadCreatorClass(); fittingControl1.processSpec = processSpec; bool connectState = processSpec.connectSpectrometer(); if (connectState) { settoolStripStatusLabel1Text("成功连接光谱仪"); } else { settoolStripStatusLabel1Text("未发现光谱仪"); } int gridindex = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[gridindex].Cells[0].Value = true; this.dataGridView1.Rows[gridindex].Cells[1].Style.BackColor = Color.Red; this.dataGridView1.Rows[gridindex].Cells[2].Value = "当前谱图"; this.dataGridView1.Rows[gridindex].Cells[2].ReadOnly = true; if (processSpec.IsConn) { start = true; getSpectrumThread = new Thread(new ThreadStart(run)); getSpectrumThread.Start(); getSpectrumThread.IsBackground = true; dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black; } Chart_spec.Tools.Items[0].Active = false; }
private void btn_findPeak_Click(object sender, EventArgs e) { if (!processSpec.IsConn) { return; } double[] showY = new double[processSpec.showY.Length]; Array.Copy(processSpec.showY, showY, showY.Length); List <int> peaks1 = new List <int> (), peaks2 = new List <int> (); if (processSpec.findPeakDerection == 0) { double[] backShowY = new double[processSpec.showY.Length]; for (int i = 0; i < processSpec.showY.Length; i++) { backShowY[i] = (-1) * processSpec.showY[i]; } peaks2 = ProcessArray.findPeaks(backShowY, processSpec.findPeakWidth, processSpec.findPeakSmoothWidth, processSpec.findPeakThreshold); } else if (processSpec.findPeakDerection == 1) { peaks1 = ProcessArray.findPeaks(processSpec.showY, processSpec.findPeakWidth, processSpec.findPeakSmoothWidth, processSpec.findPeakThreshold); } else if (processSpec.findPeakDerection == 2) { peaks1 = ProcessArray.findPeaks(processSpec.showY, processSpec.findPeakWidth, processSpec.findPeakSmoothWidth, processSpec.findPeakThreshold); double[] backShowY = new double[processSpec.showY.Length]; for (int i = 0; i < processSpec.showY.Length; i++) { backShowY[i] = (-1) * processSpec.showY[i]; } peaks2 = ProcessArray.findPeaks(backShowY, processSpec.findPeakWidth, processSpec.findPeakSmoothWidth, processSpec.findPeakThreshold); } peaks1.AddRange(peaks2); peaks1.Sort(); double[] peakX = new double[peaks1.Count]; double[] peakY = new double[peaks1.Count]; for (int i = 0; i < peaks1.Count; i++) { peakX[i] = processSpec.wavelengths[peaks1[i]]; peakY[i] = showY[peaks1[i]]; } if (peakX.Length > 0) { Chart_spec.Series(1).AddArray(peakX.Length, peakY, peakX); } else { Chart_spec.Series(1).Clear(); } }
private void chart_Spectrum_addLine(object wave, double[] spec, bool newSeries, string name) { if (newSeries) { ESeriesClass series = new ESeriesClass(); int index = Chart_spec.AddSeries(series); Chart_fitting.Series(index).Title = name; Chart_fitting.Series(index).AddArray(spec.Length, spec, wave); } else { Chart_spec.Series(0).AddArray(spec.Length, spec, wave); } }
private void btn_removeRecord_Click(object sender, EventArgs e) { int selectedRowsCounts = dataGridView1.SelectedCells.Count; foreach (DataGridViewCell dgvRow in dataGridView1.SelectedCells) { int index = dgvRow.RowIndex; if (index > 0) { Chart_spec.RemoveSeries(index + 1); processSpec.removeRecordSpec(index - 1); dataGridView1.Rows.Remove(dgvRow.OwningRow); } } }
private void btn_record_Click(object sender, EventArgs e) { if (processSpec.IsConn) { int index = Chart_spec.AddSeries(ESeriesClass.scFastLine); Color co = colorList.getNextColor(); Chart_spec.Series(index).Color = (uint)ColorTranslator.ToWin32(co); Chart_spec.Series(index).asFastLine.LinePen.Width = boldLineWidth; Chart_spec.Series(index).AddArray(processSpec.pixelNumber, processSpec.showY, processSpec.showX); processSpec.recordSpec(index); int gridindex = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[gridindex].Cells[0].Value = true; this.dataGridView1.Rows[gridindex].Cells[1].Style.BackColor = co; this.dataGridView1.Rows[gridindex].Cells[1].Style.SelectionForeColor = co; this.dataGridView1.Rows[gridindex].Cells[2].Value = "谱图" + index; } }
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex < 0) { return; } if (e.ColumnIndex != 1) { return; } ColorDialog cd = new ColorDialog(); DialogResult dr = cd.ShowDialog(); Color c; if (dr == System.Windows.Forms.DialogResult.OK) { c = cd.Color; dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Style.BackColor = c; Chart_spec.Series(e.RowIndex + 1).Color = (uint)ColorTranslator.ToWin32(c); } }
private void addSpecSeries(double[] bfspectrum, double[] bfwavelength, string showName = "") { if (showName == "") { showName = "谱图" + (Chart_spec.SeriesCount - 1); } processSpec.recordSpec(showName, bfwavelength, bfspectrum); // ESeriesClass series = new ESeriesClass(); int index = Chart_spec.AddSeries(ESeriesClass.scFastLine); Color co = colorList.getNextColor(); Chart_spec.Series(index).Color = (uint)ColorTranslator.ToWin32(co); Chart_spec.Series(index).asFastLine.LinePen.Width = boldLineWidth; Chart_spec.Series(index).AddArray(bfwavelength.Length, bfspectrum, bfwavelength); int gridindex = this.dataGridView1.Rows.Add(); this.dataGridView1.Rows[gridindex].Cells[0].Value = true; this.dataGridView1.Rows[gridindex].Cells[1].Style.BackColor = co; this.dataGridView1.Rows[gridindex].Cells[1].Style.SelectionForeColor = co; this.dataGridView1.Rows[gridindex].Cells[2].Value = showName; }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.CurrentCell.ColumnIndex > 1) { int index = dataGridView1.CurrentCell.RowIndex; if (changeLineEvent != null) { changeLineEvent(index); } if (index >= 1) { index++; } for (int i = 0; i < Chart_spec.SeriesCount; i++) { if (i == 1) { continue; } if (i == index) { Chart_spec.Series(i).asFastLine.LinePen.Width = boldLineWidth + 2; } else { if (Chart_spec.Series(i).asFastLine.LinePen.Width != boldLineWidth) { Chart_spec.Series(i).asFastLine.LinePen.Width = boldLineWidth; } } } } }