Exemplo n.º 1
0
/** For each save format tick box take the user setting from the
 * main form
 * @param defSavs the formats to save into
 */
void SaveWorkspaces::setupFormatTicks(
    const QHash<const QCheckBox *const, QString> &defSavs) {
  for (SavFormatsConstIt i = m_savFormats.begin(); i != m_savFormats.end();
       ++i) {
    // find the setting that has been passed for this save format
    QHash<const QCheckBox *const, QString>::const_iterator j = defSavs.begin();
    for (; j != defSavs.end(); ++j) {
      // the values are the algorithm names
      if (j.value() ==
          i.value()) { // copy over the checked status of the check box
        i.key()->setChecked(j.key()->isChecked());
      }
    }
  }
}
Exemplo n.º 2
0
/**
 * Checks if the save option selection is compatible with the dimensionality
 * selection
 * @return true if the save option selection is compatible with the
 * dimensionality selection else false
 */
bool SaveWorkspaces::isValid() {
  // Get the dimensionality of the workspaces
  auto is2D = false;
  auto workspacesList = m_workspaces->selectedItems();
  for (auto it = workspacesList.begin(); it != workspacesList.end(); ++it) {
    auto wsName = (*it)->text();
    auto workspace =
        AnalysisDataService::Instance()
            .retrieveWS<Mantid::API::MatrixWorkspace>(wsName.toStdString());
    if (workspace->getNumberHistograms() != 1) {
      is2D = true;
    }
  }

  // Check if CanSAS was selected
  auto isCanSAS = false;
  for (SavFormatsConstIt i = m_savFormats.begin(); i != m_savFormats.end();
       ++i) { // the key to a pointer to the check box that the user may have
              // clicked
    if (i.key()->isChecked()) { // we need to save in this format
      if (i.value() == "SaveCanSAS1D") {
        isCanSAS = true;
      }
    }
  }

  // Check for errors
  QString message;
  auto isValidOption = true;

  if (is2D && isCanSAS) {
    isValidOption = false;
    message += "Save option issue: Cannot save in CanSAS format for 2D data.\n";
  }

  // Print the error message if there are any
  if (!message.isEmpty()) {
    QString warning = "Please correct these save settings before proceeding:\n";
    warning += message;
    QMessageBox::warning(this, "Inconsistent input", warning);
  }

  return isValidOption;
}
Exemplo n.º 3
0
/** Excutes the selected save algorithms on the workspaces that
 *  have been selected to be saved
 */
void SaveWorkspaces::saveSel() {
  // Check if the save selection is valid
  if (!isValid()) {
    return;
  }

  // For each selected workspace, provide an zero-error free clone
  QHash<QString, QString> workspaceMap =
      provideZeroFreeWorkspaces(m_workspaces);

  QString saveCommands;
  for (SavFormatsConstIt i = m_savFormats.begin(); i != m_savFormats.end();
       ++i) { // the key to a pointer to the check box that the user may have
              // clicked
    if (i.key()->isChecked()) { // we need to save in this format

      bool toAppend = m_append->isChecked();

      try {
        saveCommands += saveList(m_workspaces->selectedItems(), i.value(),
                                 m_fNameEdit->text(), toAppend, workspaceMap);
      } catch (std::logic_error &) {
        QMessageBox::information(
            this, "No workspace to save",
            "You must select at least one workspace to save");
        return;
      }
    } // end if save in this format
  }   // end loop over formats

  saveCommands += "print('success')";
  QString status(runPythonCode(saveCommands).trimmed());

  if (m_saveAsZeroErrorFree) {
    removeZeroFreeWorkspaces(workspaceMap);
  }

  if (status != "success") {
    QMessageBox::critical(this, "Error saving workspace",
                          "One of the workspaces could not be saved in one of "
                          "the selected formats");
  }
}