private void Control_PUnitsChanged(object source, MainForm.PUnitsChangedEventArgs args) { // не меняем реальное давление при смене едениц bool controllerIsOnOld = controllerIsOn; controllerIsOn = false; double vmin = (double)nudMinP.Value; double vmax = (double)nudMaxP.Value; nudMaxP.DecimalPlaces = MainForm.progState.RoundToDigits; nudMaxP.Maximum = (decimal)PUnitConverter.ConvertP((double)nudMaxP.Maximum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMaxP.Minimum = (decimal)PUnitConverter.ConvertP((double)nudMaxP.Minimum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMaxP.Value = (decimal)PUnitConverter.ConvertP(vmax, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMaxP.Increment = Math.Round((nudMaxP.Maximum - nudMaxP.Minimum) / 1000, 1); if (nudMaxP.Increment < 0.1M) { nudMaxP.Increment = 0.1M; } nudMinP.DecimalPlaces = MainForm.progState.RoundToDigits; nudMinP.Maximum = (decimal)PUnitConverter.ConvertP((double)nudMinP.Maximum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMinP.Minimum = (decimal)PUnitConverter.ConvertP((double)nudMinP.Minimum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMinP.Value = (decimal)PUnitConverter.ConvertP(vmin, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMinP.Increment = nudMaxP.Increment; controllerIsOn = controllerIsOnOld; UpdatePtLabels(); }
private void SettingsForm_Load(object sender, EventArgs e) { nudSetpointPrecision.Value = (decimal)MainForm.progState.CurrentSetptPrecision * 100; nudBarometricP.Value = (decimal)PUnitConverter.ConvertP(MainForm.progState.CurrentBarometricP, MainForm.progState.CurrentPUnits, PressureUnits.KGS); nudMeasurementInterval.Value = MainForm.progState.ReadPInterval; nudTimeToSetpoint.Value = MainForm.progState.SetptDelay; nudGraphTScale.Value = MainForm.progState.TimeLength; }
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 Control_PUnitsChanged(object source, MainForm.PUnitsChangedEventArgs args) { double v = (double)nudSetpoint.Value; nudSetpoint.DecimalPlaces = MainForm.progState.RoundToDigits; nudSetpoint.Maximum = (decimal)PUnitConverter.ConvertP((double)nudSetpoint.Maximum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudSetpoint.Minimum = (decimal)PUnitConverter.ConvertP((double)nudSetpoint.Minimum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudSetpoint.Value = (decimal)PUnitConverter.ConvertP(v, args.OldPUnits, MainForm.progState.CurrentPUnits); nudSetpoint.Increment = Math.Round((nudSetpoint.Maximum - nudSetpoint.Minimum) / 1000, 1); if (nudSetpoint.Increment < 0.1M) { nudSetpoint.Increment = 0.1M; } }
private void Control_NewControllerSelected(object source) { // пределы nudMaxP.DecimalPlaces = MainForm.progState.RoundToDigits; nudMaxP.Maximum = (decimal)MainForm.CurrentDPI.MaximalPressure; nudMaxP.Minimum = (decimal)MainForm.CurrentDPI.MinimalPressure; nudMaxP.Increment = Math.Round((nudMaxP.Maximum - nudMaxP.Minimum) / 1000, 1); if (nudMaxP.Increment < 0.1M) { nudMaxP.Increment = 0.1M; } nudMaxP.Value = (decimal)PUnitConverter.ConvertP((double)nudMaxP.Value, PressureUnits.KGS, MainForm.progState.CurrentPUnits); nudMinP.DecimalPlaces = MainForm.progState.RoundToDigits; nudMinP.Maximum = (decimal)MainForm.CurrentDPI.MaximalPressure; nudMinP.Minimum = (decimal)MainForm.CurrentDPI.MinimalPressure; nudMinP.Increment = nudMaxP.Increment; nudMinP.Value = (decimal)PUnitConverter.ConvertP((double)nudMinP.Value, PressureUnits.KGS, MainForm.progState.CurrentPUnits); // заполняем точки pPoints = new double[(int)nudPointCount.Value]; for (int i = 0; i < pPoints.Length; i++) { pPoints[i] = (double)(nudMinP.Value + (nudMaxP.Value - nudMinP.Value) / (pPoints.Length - 1) * i); } // обновляем интерфейсные таблички currentPtIndex = 0; Control_PTypeChanged(null); try { MainForm.CurrentDPI.SetMeasureMode(); controllerIsOn = false; mainFormRef.UpdateStatusLabel(Color.Black, ""); } catch (Exception exp) { mainFormRef.UpdateStatusLabel(Color.DarkRed, "ОШИБКА! " + exp.Message); } }
private void Control_PUnitsChanged(object source, MainForm.PUnitsChangedEventArgs args) { if (dgvSetpoints.Rows.Count != 0) { // не меняем реальное давление при смене единиц bool controllerIsOnOld = controllerIsOn; controllerIsOn = false; for (int i = 0; i < nudPointsCount.Value; i++) { pPoints[i] = PUnitConverter.ConvertP(pPoints[i], args.OldPUnits, MainForm.progState.CurrentPUnits); } for (int j = 0; j < nudPointsCount.Value; j++) { dgvSetpoints.Rows[j].Cells[0].Value = pPoints[j]; } controllerIsOn = controllerIsOnOld; UpdatePtLabels(); } }
private void Control_PUnitsChanged(object source, MainForm.PUnitsChangedEventArgs args) { // не меняем реальное давление при смене едениц bool isSetPressureOld = isSetPressure; isSetPressure = false; double v = (double)nudSetpoint.Value; nudSetpoint.DecimalPlaces = MainForm.progState.RoundToDigits; nudSetpoint.Maximum = (decimal)PUnitConverter.ConvertP((double)nudSetpoint.Maximum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudSetpoint.Minimum = (decimal)PUnitConverter.ConvertP((double)nudSetpoint.Minimum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudSetpoint.Value = (decimal)PUnitConverter.ConvertP(v, args.OldPUnits, MainForm.progState.CurrentPUnits); nudSetpoint.Increment = Math.Round((nudSetpoint.Maximum - nudSetpoint.Minimum) / 1000, 1); if (nudSetpoint.Increment < 0.1M) { nudSetpoint.Increment = 0.1M; } isSetPressure = isSetPressureOld; }
private void Control_NewControllerSelected(object source) { double v = (double)nudSetpoint.Value; nudSetpoint.DecimalPlaces = MainForm.progState.RoundToDigits; nudSetpoint.Maximum = (decimal)MainForm.CurrentDPI.MaximalPressure; nudSetpoint.Minimum = (decimal)MainForm.CurrentDPI.MinimalPressure; nudSetpoint.Value = (decimal)PUnitConverter.ConvertP(v, PressureUnits.KGS, MainForm.progState.CurrentPUnits); if (MainForm.progState.PIsAbsolute) { nudSetpoint.Maximum += (decimal)MainForm.progState.CurrentBarometricP; nudSetpoint.Minimum += (decimal)MainForm.progState.CurrentBarometricP; //nudSetpoint.Value = (decimal)(v + MainForm.progState.CurrentBarometricP); } else { nudSetpoint.Maximum -= (decimal)MainForm.progState.CurrentBarometricP; nudSetpoint.Minimum -= (decimal)MainForm.progState.CurrentBarometricP; nudSetpoint.Value = (decimal)(v - MainForm.progState.CurrentBarometricP); } }
private void Control_PUnitsChanged(object source, MainForm.PUnitsChangedEventArgs args) { double vmin = (double)nudMinP.Value; double vmax = (double)nudMaxP.Value; nudMaxP.DecimalPlaces = MainForm.progState.RoundToDigits; nudMaxP.Maximum = (decimal)PUnitConverter.ConvertP((double)nudMaxP.Maximum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMaxP.Minimum = (decimal)PUnitConverter.ConvertP((double)nudMaxP.Minimum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMaxP.Value = (decimal)PUnitConverter.ConvertP(vmax, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMaxP.Increment = Math.Round((nudMaxP.Maximum - nudMaxP.Minimum) / 1000, 1); if (nudMaxP.Increment < 0.1M) { nudMaxP.Increment = 0.1M; } nudMinP.DecimalPlaces = MainForm.progState.RoundToDigits; nudMinP.Maximum = (decimal)PUnitConverter.ConvertP((double)nudMinP.Maximum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMinP.Minimum = (decimal)PUnitConverter.ConvertP((double)nudMinP.Minimum, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMinP.Value = (decimal)PUnitConverter.ConvertP(vmin, args.OldPUnits, MainForm.progState.CurrentPUnits); nudMinP.Increment = nudMaxP.Increment; UpdatePtLabels(); }
private void nudBarometricP_ValueChanged(object sender, EventArgs e) { MainForm.progState.CurrentBarometricP = PUnitConverter.ConvertP((double)nudBarometricP.Value, PressureUnits.KGS, MainForm.progState.CurrentPUnits); }