示例#1
0
/** Gets the first extension that the algorithm passed algorithm has in it's
 *  FileProperty (the FileProperty must have the name "Filename"
 *  @param algName :: name of the Mantid save algorithm
 *  @return the first extension, if the algorithm's Filename property has an
 * extension list or ""
 */
QString SaveWorkspaces::getSaveAlgExt(const QString &algName) {
  IAlgorithm_sptr alg =
      AlgorithmManager::Instance().create(algName.toStdString());
  Property *prop = alg->getProperty("Filename");
  FileProperty *fProp = dynamic_cast<FileProperty *>(prop);
  if (fProp) {
    return QString::fromStdString(fProp->getDefaultExt());
  } else { // the algorithm doesn't have a "Filename" file property which may
           // indicate an error later on or maybe OK
    return "";
  }
}
示例#2
0
/**
* Create a list of file extensions from the given algorithm
* @param algName :: The name of the algorithm
* @param propName :: The name of the property
* @returns A list of file extensions
*/
QStringList
MWRunFiles::getFileExtensionsFromAlgorithm(const QString &algName,
                                           const QString &propName) {
  Mantid::API::IAlgorithm_sptr algorithm =
      Mantid::API::AlgorithmManager::Instance().createUnmanaged(
          algName.toStdString());
  QStringList fileExts;
  if (!algorithm)
    return fileExts;
  algorithm->initialize();
  Property *prop = algorithm->getProperty(propName.toStdString());
  FileProperty *fileProp = dynamic_cast<FileProperty *>(prop);
  MultipleFileProperty *multiFileProp =
      dynamic_cast<MultipleFileProperty *>(prop);

  std::vector<std::string> allowed;
  QString preferredExt;

  if (fileProp) {
    allowed = fileProp->allowedValues();
    preferredExt = QString::fromStdString(fileProp->getDefaultExt());
  } else if (multiFileProp) {
    allowed = multiFileProp->allowedValues();
    preferredExt = QString::fromStdString(multiFileProp->getDefaultExt());
  } else {
    return fileExts;
  }

  std::vector<std::string>::const_iterator iend = allowed.end();
  int index(0);
  for (std::vector<std::string>::const_iterator it = allowed.begin();
       it != iend; ++it) {
    if (!it->empty()) {
      QString ext = QString::fromStdString(*it);
      fileExts.append(ext);
      if (ext == preferredExt) {
        fileExts.move(index, 0);
      }
      ++index;
    }
  }

  return fileExts;
}