Exemplo n.º 1
0
        public void OkDialog()
        {
            string message;

            if (Source == SpectralLibrarySource.file)
            {
                string path = textFilePath.Text;
                message = ValidateSpectralLibraryPath(path);
                if (message != null)
                {
                    MessageDlg.Show(this, message);
                    textFilePath.Focus();
                    return;
                }
            }
            var librarySpec = Library;

            if (librarySpec == null)
            {
                MessageDlg.Show(this, Resources.ImportIonMobilityFromSpectralLibrary_OkDialog_Please_choose_the_library_you_would_like_to_add_);
                return;
            }

            var table = new ChargeRegressionTable(gridRegression);
            var chargeRegressionLinesList = table.GetTableChargeRegressionLines();

            if (chargeRegressionLinesList == null) // Some error detected in the charged regression lines table
            {
                return;
            }
            ChargeRegressionsLines = chargeRegressionLinesList.ToDictionary(x => x.Charge, x => x.RegressionLine);

            // Have we got everything we need to populate the caller's grid view?
            message = _gridViewDriver.ImportFromSpectralLibrary(librarySpec, ChargeRegressionsLines);
            if (message == null)
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                MessageDlg.Show(this, message);
            }
        }
Exemplo n.º 2
0
        public void OkDialog(bool forceOverwrite = false)
        {
            var helper = new MessageBoxHelper(this);

            var driftTable = new MeasuredDriftTimeTable(gridMeasuredDriftTimes, MeasuredDriftTimeSequence.TargetResolver);

            var table = new ChargeRegressionTable(gridRegression);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            if (_existing.Contains(r => !Equals(_predictor, r) && Equals(name, r.Name)) && !forceOverwrite)
            {
                if (MessageBox.Show(this,
                                    TextUtil.LineSeparate(string.Format(Resources.EditDriftTimePredictorDlg_OkDialog_An_ion_mobility_predictor_with_the_name__0__already_exists_, name),
                                                          Resources.EditDriftTimePredictorDlg_OkDialog_Do_you_want_to_change_it_),
                                    Program.Name, MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }
            }
            if (driftTable.GetTableMeasuredIonMobility(cbOffsetHighEnergySpectra.Checked, Units) == null) // Some error detected in the measured drift times table
            {
                return;
            }
            if (table.GetTableChargeRegressionLines() == null) // Some error detected in the charged regression lines table
            {
                return;
            }
            double resolvingPower = 0;
            double widthAtDt0     = 0;
            double widthAtDtMax   = 0;

            IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType peakWidthType;
            if (cbLinear.Checked)
            {
                if (!helper.ValidateDecimalTextBox(textWidthAtDt0, out widthAtDt0))
                {
                    return;
                }
                if (!helper.ValidateDecimalTextBox(textWidthAtDtMax, out widthAtDtMax))
                {
                    return;
                }
                var errmsg = ValidateWidth(widthAtDt0);
                if (errmsg != null)
                {
                    helper.ShowTextBoxError(textWidthAtDt0, errmsg);
                    return;
                }
                errmsg = ValidateWidth(widthAtDtMax);
                if (errmsg != null)
                {
                    helper.ShowTextBoxError(textWidthAtDtMax, errmsg);
                    return;
                }
                peakWidthType = IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.linear_range;
            }
            else
            {
                if (!helper.ValidateDecimalTextBox(textResolvingPower, out resolvingPower))
                {
                    return;
                }

                var errmsg = ValidateResolvingPower(resolvingPower);
                if (errmsg != null)
                {
                    helper.ShowTextBoxError(textResolvingPower, errmsg);
                    return;
                }
                peakWidthType = IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.resolving_power;
            }

            if ((comboLibrary.SelectedIndex > 0) && (comboLibrary.SelectedItem.ToString().Length == 0))
            {
                MessageBox.Show(this, Resources.EditDriftTimePredictorDlg_OkDialog_Drift_time_prediction_requires_an_ion_mobility_library_,
                                Program.Name);
                comboLibrary.Focus();
                return;
            }
            var ionMobilityLibrary = _driverIonMobilityLibraryListComboDriver.SelectedItem;

            IonMobilityPredictor predictor =
                new IonMobilityPredictor(name, driftTable.GetTableMeasuredIonMobility(cbOffsetHighEnergySpectra.Checked, Units),
                                         ionMobilityLibrary, table.GetTableChargeRegressionLines(), peakWidthType, resolvingPower, widthAtDt0, widthAtDtMax);

            _predictor = predictor;

            DialogResult = DialogResult.OK;
        }
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            var driftTable = new MeasuredDriftTimeTable(gridMeasuredDriftTimes);

            var table = new ChargeRegressionTable(gridRegression);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            if (_existing.Contains(r => !ReferenceEquals(_predictor, r) && Equals(name, r.Name)))
            {
                if (MessageBox.Show(this,
                                    TextUtil.LineSeparate(string.Format(Resources.EditDriftTimePredictorDlg_OkDialog_A_drift_time_predictor_with_the_name__0__already_exists_, name),
                                                          Resources.EditDriftTimePredictorDlg_OkDialog_Do_you_want_to_change_it_),
                                    Program.Name, MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }
            }
            if (driftTable.GetTableMeasuredDriftTimes(cbOffsetHighEnergySpectra.Checked) == null) // Some error detected in the measured drift times table
            {
                return;
            }
            if (table.GetTableChargeRegressionLines() == null) // Some error detected in the charged regression lines table
            {
                return;
            }
            double resolvingPower;

            if (!helper.ValidateDecimalTextBox(textResolvingPower, out resolvingPower))
            {
                return;
            }

            var errmsg = ValidateResolvingPower(resolvingPower);

            if (errmsg != null)
            {
                helper.ShowTextBoxError(textResolvingPower, errmsg);
                return;
            }

            if ((comboLibrary.SelectedIndex > 0) && (comboLibrary.SelectedItem.ToString().Length == 0))
            {
                MessageBox.Show(this, Resources.EditDriftTimePredictorDlg_OkDialog_Drift_time_prediction_requires_an_ion_mobility_library_,
                                Program.Name);
                comboLibrary.Focus();
                return;
            }
            var ionMobilityLibrary = _driverIonMobilityLibraryListComboDriver.SelectedItem;

            DriftTimePredictor predictor =
                new DriftTimePredictor(name, driftTable.GetTableMeasuredDriftTimes(cbOffsetHighEnergySpectra.Checked),
                                       ionMobilityLibrary, table.GetTableChargeRegressionLines(), resolvingPower);

            _predictor = predictor;

            DialogResult = DialogResult.OK;
        }