/**
 * Validates the user input in the UI
 * @return if the input was valid
 */
bool ContainerSubtraction::validate() {
  UserInputValidator uiv;
  uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample);
  uiv.checkDataSelectorIsValid("Container", m_uiForm.dsContainer);
  MatrixWorkspace_sptr sampleWs;
  QString sample = m_uiForm.dsSample->getCurrentDataName();
  QString sampleType = sample.right(sample.length() - sample.lastIndexOf("_"));
  QString container = m_uiForm.dsContainer->getCurrentDataName();
  QString containerType =
      container.right(sample.length() - container.lastIndexOf("_"));

  g_log.debug() << "Sample type is: " << sampleType.toStdString() << std::endl;
  g_log.debug() << "Container type is: " << containerType.toStdString()
                << std::endl;

  if (containerType != sampleType)
    uiv.addErrorMessage(
        "Sample and can workspaces must contain the same type of data.");

  // Show errors if there are any
  if (!uiv.isAllInputValid())
    emit showMessageBox(uiv.generateErrorMessage());

  return uiv.isAllInputValid();
}
Exemple #2
0
bool Elwin::validate() {
  UserInputValidator uiv;

  uiv.checkMWRunFilesIsValid("Input", m_uiForm.dsInputFiles);

  auto rangeOne =
      std::make_pair(m_dblManager->value(m_properties["IntegrationStart"]),
                     m_dblManager->value(m_properties["IntegrationEnd"]));
  uiv.checkValidRange("Range One", rangeOne);

  bool useTwoRanges =
      m_blnManager->value(m_properties["BackgroundSubtraction"]);
  if (useTwoRanges) {
    auto rangeTwo =
        std::make_pair(m_dblManager->value(m_properties["BackgroundStart"]),
                       m_dblManager->value(m_properties["BackgroundEnd"]));
    uiv.checkValidRange("Range Two", rangeTwo);
    uiv.checkRangesDontOverlap(rangeOne, rangeTwo);
  }

  QString error = uiv.generateErrorMessage();
  showMessageBox(error);

  return error.isEmpty();
}
Exemple #3
0
  bool ISISDiagnostics::validate()
  {
    UserInputValidator uiv;

    // Check raw input
    uiv.checkMWRunFilesIsValid("Input", m_uiForm.dsInputFiles);
    if(m_uiForm.ckUseCalibration->isChecked())
      uiv.checkMWRunFilesIsValid("Calibration", m_uiForm.dsInputFiles);

    // Check peak range
    auto rangeOne = std::make_pair(m_dblManager->value(m_properties["PeakStart"]), m_dblManager->value(m_properties["PeakEnd"]));
    uiv.checkValidRange("Range One", rangeOne);

    // Check background range
    bool useTwoRanges = m_blnManager->value(m_properties["UseTwoRanges"]);
    if(useTwoRanges)
    {
      auto rangeTwo = std::make_pair(m_dblManager->value(m_properties["BackgroundStart"]), m_dblManager->value(m_properties["BackgroundEnd"]));
      uiv.checkValidRange("Range Two", rangeTwo);

      uiv.checkRangesDontOverlap(rangeOne, rangeTwo);
    }

    // Check spectra range
    auto specRange = std::make_pair(m_dblManager->value(m_properties["SpecMin"]), m_dblManager->value(m_properties["SpecMax"]) + 1);
    uiv.checkValidRange("Spectra Range", specRange);

    QString error = uiv.generateErrorMessage();
    bool isError = error != "";

    if(isError)
      g_log.warning(error.toStdString());

    return !isError;
  }
Exemple #4
0
bool IqtFit::validate() {
  UserInputValidator uiv;

  uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSampleInput);

  auto range = std::make_pair(m_ffRangeManager->value(m_properties["StartX"]),
                              m_ffRangeManager->value(m_properties["EndX"]));
  uiv.checkValidRange("Ranges", range);

  QString error = uiv.generateErrorMessage();
  showMessageBox(error);

  return error.isEmpty();
}
/**
 * Validates the user input in the UI
 * @return if the input was valid
 */
bool ContainerSubtraction::validate() {
    UserInputValidator uiv;

    // Check valid inputs
    const bool samValid = uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample);
    const bool canValid = uiv.checkDataSelectorIsValid("Container", m_uiForm.dsContainer);

    if (samValid && canValid) {
        // Get Workspaces
        MatrixWorkspace_sptr sampleWs =
            AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
                m_uiForm.dsSample->getCurrentDataName().toStdString());
        MatrixWorkspace_sptr containerWs =
            AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
                m_uiForm.dsContainer->getCurrentDataName().toStdString());

        // Check Sample is of same type as container
        QString sample = m_uiForm.dsSample->getCurrentDataName();
        QString sampleType =
            sample.right(sample.length() - sample.lastIndexOf("_"));
        QString container = m_uiForm.dsContainer->getCurrentDataName();
        QString containerType =
            container.right(sample.length() - container.lastIndexOf("_"));

        g_log.debug() << "Sample type is: " << sampleType.toStdString()
                      << std::endl;
        g_log.debug() << "Container type is: " << containerType.toStdString()
                      << std::endl;

        if (containerType != sampleType)
            uiv.addErrorMessage(
                "Sample and can workspaces must contain the same type of data.");

        // Check sample has the same number of Histograms as the contianer
        const size_t sampleHist = sampleWs->getNumberHistograms();
        const size_t containerHist = containerWs->getNumberHistograms();

        if (sampleHist != containerHist) {
            uiv.addErrorMessage(
                " Sample and Container do not have a matching number of Histograms.");
        }
    }

    // Show errors if there are any
    if (!uiv.isAllInputValid())
        emit showMessageBox(uiv.generateErrorMessage());

    return uiv.isAllInputValid();
}
Exemple #6
0
bool IndirectMoments::validate()
{
    UserInputValidator uiv;

    uiv.checkDataSelectorIsValid("Sample input", m_uiForm.dsInput);

    QString msg = uiv.generateErrorMessage();
    if (!msg.isEmpty())
    {
        emit showMessageBox(msg);
        return false;
    }

    return true;
}
bool IndirectFitAnalysisTab::validate() {
  UserInputValidator validator;
  m_dataPresenter->validate(validator);
  m_spectrumPresenter->validate(validator);

  const auto invalidFunction = m_fittingModel->isInvalidFunction();
  if (invalidFunction)
    validator.addErrorMessage(QString::fromStdString(*invalidFunction));
  if (m_fittingModel->numberOfWorkspaces() == 0)
    validator.addErrorMessage(
        QString::fromStdString("No data has been selected for a fit."));

  const auto error = validator.generateErrorMessage();
  emit showMessageBox(error);
  return error.isEmpty();
}
/**
 * Validate user input.
 * Outputs any warnings to the results log at warning level.
 *
 * @param silent If the results should not be logged
 * @return Result of validation
 */
bool SampleTransmission::validate(bool silent) {
  UserInputValidator uiv;

  // Valudate input binning
  int wavelengthBinning = m_uiForm.cbBinningType->currentIndex();
  switch (wavelengthBinning) {
  // Single
  case 0:
    uiv.checkBins(m_uiForm.spSingleLow->value(),
                  m_uiForm.spSingleWidth->value(),
                  m_uiForm.spSingleHigh->value());
    break;

  // Multiple
  case 1:
    uiv.checkFieldIsNotEmpty("Multiple binning", m_uiForm.leMultiple,
                             m_uiForm.valMultiple);
    break;
  }

  // Validate chemical formula
  uiv.checkFieldIsNotEmpty("Chemical Formula", m_uiForm.leChemicalFormula,
                           m_uiForm.valChemicalFormula);

  // Ensure number density is not zero
  uiv.setErrorLabel(
      m_uiForm.valNumberDensity,
      uiv.checkNotEqual("Number Density", m_uiForm.spNumberDensity->value()));

  // Ensure thickness is not zero
  uiv.setErrorLabel(
      m_uiForm.valThickness,
      uiv.checkNotEqual("Thickness", m_uiForm.spThickness->value()));

  // Give error message
  if (!silent && !uiv.isAllInputValid())
    showInformationBox(uiv.generateErrorMessage());

  return uiv.isAllInputValid();
}
Exemple #9
0
bool ApplyPaalmanPings::validate() {
  UserInputValidator uiv;

  uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample);

  MatrixWorkspace_sptr sampleWs;

  bool useCan = m_uiForm.ckUseCan->isChecked();
  bool useCorrections = m_uiForm.ckUseCorrections->isChecked();

  if (!(useCan || useCorrections))
    uiv.addErrorMessage("Must use either container subtraction or corrections");

  if (useCan) {
    uiv.checkDataSelectorIsValid("Container", m_uiForm.dsContainer);

    // Check can and sample workspaces are the same "type" (reduced or S(Q, w))
    QString sample = m_uiForm.dsSample->getCurrentDataName();
    QString sampleType =
        sample.right(sample.length() - sample.lastIndexOf("_"));
    QString container = m_uiForm.dsContainer->getCurrentDataName();
    QString containerType =
        container.right(container.length() - container.lastIndexOf("_"));

    g_log.debug() << "Sample type is: " << sampleType.toStdString() << '\n';
    g_log.debug() << "Can type is: " << containerType.toStdString() << '\n';

    if (containerType != sampleType)
      uiv.addErrorMessage(
          "Sample and can workspaces must contain the same type of data.");
  }

  if (useCorrections) {
    if (m_uiForm.dsCorrections->getCurrentDataName().compare("") == 0) {
      uiv.addErrorMessage(
          "Use Correction must contain a corrections file or workspace.");
    } else {

      QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName();
      WorkspaceGroup_sptr corrections =
          AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(
              correctionsWsName.toStdString());
      for (size_t i = 0; i < corrections->size(); i++) {
        // Check it is a MatrixWorkspace
        MatrixWorkspace_sptr factorWs =
            boost::dynamic_pointer_cast<MatrixWorkspace>(
                corrections->getItem(i));
        if (!factorWs) {
          QString msg = "Correction factor workspace " + QString::number(i) +
                        " is not a MatrixWorkspace";
          uiv.addErrorMessage(msg);
          continue;
        }

        // Check X unit is wavelength
        Mantid::Kernel::Unit_sptr xUnit = factorWs->getAxis(0)->unit();
        if (xUnit->caption() != "Wavelength") {
          QString msg = "Correction factor workspace " +
                        QString::fromStdString(factorWs->name()) +
                        " is not in wavelength";
          uiv.addErrorMessage(msg);
        }
      }
    }
  }

  // Show errors if there are any
  if (!uiv.isAllInputValid())
    emit showMessageBox(uiv.generateErrorMessage());

  return uiv.isAllInputValid();
}
/**
 * Does validation on the user input.
 *
 * @param silent Set to true to avoid creating an error message
 * @return True if all user input is valid
 */
bool CalculatePaalmanPings::doValidation(bool silent) {
  UserInputValidator uiv;

  uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample);
  const auto sampleWsName = m_uiForm.dsSample->getCurrentDataName();
  const auto sampleWsNameStr = sampleWsName.toStdString();
  bool sampleExists =
      AnalysisDataService::Instance().doesExist(sampleWsNameStr);

  if (sampleExists &&
      !AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
          sampleWsNameStr)) {
    uiv.addErrorMessage(
        "Invalid sample workspace. Ensure a MatrixWorkspace is provided.");
  }

  // Validate chemical formula
  if (uiv.checkFieldIsNotEmpty("Sample Chemical Formula",
                               m_uiForm.leSampleChemicalFormula,
                               m_uiForm.valSampleChemicalFormula))
    uiv.checkFieldIsValid("Sample Chemical Formula",
                          m_uiForm.leSampleChemicalFormula,
                          m_uiForm.valSampleChemicalFormula);
  const auto sampleChem =
      m_uiForm.leSampleChemicalFormula->text().toStdString();
  try {
    Mantid::Kernel::Material::parseChemicalFormula(sampleChem);
  } catch (std::runtime_error &ex) {
    UNUSED_ARG(ex);
    uiv.addErrorMessage("Chemical Formula for Sample was not recognised.");
    uiv.setErrorLabel(m_uiForm.valSampleChemicalFormula, false);
  }

  if (m_uiForm.ckUseCan->isChecked()) {
    uiv.checkDataSelectorIsValid("Can", m_uiForm.dsContainer);

    // Validate chemical formula
    if (uiv.checkFieldIsNotEmpty("Can Chemical Formula",
                                 m_uiForm.leCanChemicalFormula,
                                 m_uiForm.valCanChemicalFormula))
      uiv.checkFieldIsValid("Can Chemical Formula",
                            m_uiForm.leCanChemicalFormula,
                            m_uiForm.valCanChemicalFormula);

    const auto containerChem =
        m_uiForm.leCanChemicalFormula->text().toStdString();
    try {
      Mantid::Kernel::Material::parseChemicalFormula(containerChem);
    } catch (std::runtime_error &ex) {
      UNUSED_ARG(ex);
      uiv.addErrorMessage("Chemical Formula for Container was not recognised.");
      uiv.setErrorLabel(m_uiForm.valCanChemicalFormula, false);
    }

    const auto containerWsName = m_uiForm.dsContainer->getCurrentDataName();
    const auto containerWsNameStr = containerWsName.toStdString();
    bool containerExists =
        AnalysisDataService::Instance().doesExist(containerWsNameStr);

    if (containerExists &&
        !AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
            containerWsNameStr)) {
      uiv.addErrorMessage(
          "Invalid container workspace. Ensure a MatrixWorkspace is provided.");
    }

    // Ensure sample and container are the same kind of data
    const auto sampleType = sampleWsName.right(sampleWsName.length() -
                                               sampleWsName.lastIndexOf("_"));
    const auto containerType = containerWsName.right(
        containerWsName.length() - containerWsName.lastIndexOf("_"));

    g_log.debug() << "Sample type is: " << sampleType.toStdString() << '\n';
    g_log.debug() << "Can type is: " << containerType.toStdString() << '\n';

    if (containerType != sampleType)
      uiv.addErrorMessage(
          "Sample and can workspaces must contain the same type of data.");

    // Shape validation

    const auto shape = m_uiForm.cbSampleShape->currentIndex();
    if (shape == 1 && m_uiForm.ckUseCan->isChecked()) {
      auto sampleRadius = m_uiForm.spCylSampleOuterRadius->value();
      auto containerRadius = m_uiForm.spCylCanOuterRadius->value();
      if (containerRadius <= sampleRadius) {
        uiv.addErrorMessage(
            "Container radius must be bigger than sample radius");
      }
    }
    if (shape == 2) {
      auto sampleInnerRadius = m_uiForm.spAnnSampleInnerRadius->value();
      auto sampleOuterRadius = m_uiForm.spAnnSampleOuterRadius->value();
      if (sampleOuterRadius <= sampleInnerRadius) {
        uiv.addErrorMessage(
            "Sample outer radius must be bigger than sample inner radius");
      }
      if (m_uiForm.ckUseCan->isChecked()) {
        auto containerRadius = m_uiForm.spAnnCanOuterRadius->value();
        if (containerRadius <= sampleOuterRadius) {
          uiv.addErrorMessage(
              "Container outer radius must be bigger than sample outer radius");
        }
      }
    }
  }

  // Show error message if needed
  if (!uiv.isAllInputValid() && !silent)
    emit showMessageBox(uiv.generateErrorMessage());

  return uiv.isAllInputValid();
}