private void MainForm_Load(object sender, EventArgs e) { // добавляем список единиц tscombUnits.Items.Clear(); int[] enumP = (int[])Enum.GetValues(typeof(PressureUnits)); for (int i = 0; i < enumP.Length; i++) { if ((PressureUnits)enumP[i] == PressureUnits.NA) { continue; } tscombUnits.Items.Add(PUnitConverter.PUnitToString((PressureUnits)enumP[i])); } FindDPIInstruments(); progState.CurrentMode = 0; tsbtnGeneralMode.Checked = true; basicModeControl = new BasicModeControl(this); tblpControl.Controls.Add(basicModeControl); basicModeControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; basicModeControl.Location = new Point(3, 3); // график zgGraph.GraphPane.Title.Text = "P(t)"; zgGraph.GraphPane.XAxis.Title.Text = "t, сек"; zgGraph.GraphPane.YAxis.Title.Text = string.Format("P, {0}", PUnitConverter.PUnitToString(progState.CurrentPUnits)); }
private void tscombUnits_TextChanged(object sender, EventArgs e) { // останавливаем таймер для предотвращения скачков на графике из-за смены едениц давления ticker.Stop(); Cursor.Current = Cursors.WaitCursor; PressureUnits oldUnits = progState.CurrentPUnits; // меняем текущие единицы давления progState.CurrentPUnits = PUnitConverter.StringToPUnit(tscombUnits.Text); // обновляем количество знаков для округления progState.RoundDefine(); // меняем единицы давления на форме CurrentP = PUnitConverter.ConvertP(CurrentP, oldUnits, progState.CurrentPUnits); tbCurrentP.Text = Math.Round(CurrentP, progState.RoundToDigits).ToString(); CurrentSetpt = PUnitConverter.ConvertP(CurrentSetpt, oldUnits, progState.CurrentPUnits); tbSetP.Text = Math.Round(CurrentSetpt, progState.RoundToDigits).ToString(); progState.CurrentBarometricP = PUnitConverter.ConvertP(progState.CurrentBarometricP, oldUnits, progState.CurrentPUnits); try { // меняем единицы задатчика давления if (CurrentDPI != null) { CurrentDPI.SelectUnits(progState.CurrentPUnits); // перечитываем строку параметров tstbControllerParameters.Text = CurrentDPI.GetParameterString(); } // меняем параметры графика zgGraph.GraphPane.YAxis.Title.Text = string.Format("P, {0}", PUnitConverter.PUnitToString(progState.CurrentPUnits)); // преобразуем точки графика к новым единицам давления for (int i = 0; i < GraphPoints.Count; i++) { GraphPoints[i].Y = PUnitConverter.ConvertP(GraphPoints[i].Y, oldUnits, progState.CurrentPUnits); } zgGraph.AxisChange(); zgGraph.Invalidate(); } catch (Exception exp) { MessageBox.Show(exp.Message, "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // вызываем событие для других классов PUnitsChangedEventArgs pArgs = new PUnitsChangedEventArgs(oldUnits); OnPUnitsChanged?.Invoke(this, pArgs); Cursor.Current = Cursors.Default; ticker.Start(); }
private void btnLoadProfile_Click(object sender, EventArgs e) { numericUpDown = true; openFileDialog1.InitialDirectory = "C:\\Users\\user\\Desktop"; openFileDialog1.Filter = "text files(*.txt)|*.txt"; if (openFileDialog1.ShowDialog() == DialogResult.OK) { string patch = openFileDialog1.FileName; StreamReader streamreader = new StreamReader(patch); string str = ""; int count = 0; currentPtIndex = 0; dgvSetpoints.Rows.Clear(); while ((str = streamreader.ReadLine()) != null) { if (count == 0) { switch (str) { case "KGM": MainForm.progState.CurrentPUnits = PressureUnits.KGM; break; case "MPA": MainForm.progState.CurrentPUnits = PressureUnits.MPA; break; case "ATM": MainForm.progState.CurrentPUnits = PressureUnits.ATM; break; case "BAR": MainForm.progState.CurrentPUnits = PressureUnits.BAR; break; case "KGS": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; case "KPA": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; case "MMHG": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; case "HPA": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; case "PSI": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; case "MBAR": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; case "PA": MainForm.progState.CurrentPUnits = PressureUnits.KGS; break; default: break; } } else { if (count == 1) { if (str == "Абс.") { MainForm.progState.PIsAbsolute = true; mainFormRef.tscombAG.SelectedItem = "Абс."; } else { MainForm.progState.PIsAbsolute = false; mainFormRef.tscombAG.SelectedItem = "Изб."; }; } else { dgvSetpoints.Rows.Add(str); pPoints[count - 2] = Convert.ToDouble(str); } } count++; } nudPointsCount.Value = count - 2; streamreader.Close(); UpdatePtLabels(); mainFormRef.tscombUnits.SelectedItem = PUnitConverter.PUnitToString(MainForm.progState.CurrentPUnits); } }