本文整理汇总了C++中mantid::kernel::Property::allowedValues方法的典型用法代码示例。如果您正苦于以下问题:C++ Property::allowedValues方法的具体用法?C++ Property::allowedValues怎么用?C++ Property::allowedValues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mantid::kernel::Property
的用法示例。
在下文中一共展示了Property::allowedValues方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fillAndSetComboBox
/**
* Takes a combobox and adds the allowed values of the given property to its
* list.
* It also sets the displayed value to the correct one based on either the
* history
* or a script input value
* @param propName :: The name of the property
* @param optionsBox :: A pointer to a QComoboBox object
* @returns A newed QComboBox
*/
void AlgorithmDialog::fillAndSetComboBox(const QString &propName,
QComboBox *optionsBox) const {
if (!optionsBox)
return;
Mantid::Kernel::Property *property = getAlgorithmProperty(propName);
if (!property)
return;
std::vector<std::string> items = property->allowedValues();
std::vector<std::string>::const_iterator vend = items.end();
for (std::vector<std::string>::const_iterator vitr = items.begin();
vitr != vend; ++vitr) {
optionsBox->addItem(QString::fromStdString(*vitr));
}
// Display the appropriate value
QString displayed("");
if (!isForScript()) {
displayed =
AlgorithmInputHistory::Instance().previousInput(m_algName, propName);
}
if (displayed.isEmpty()) {
displayed = QString::fromStdString(property->value());
}
int index = optionsBox->findText(displayed);
if (index >= 0) {
optionsBox->setCurrentIndex(index);
}
}
示例2: createAlgorithmDocs
std::string FrameworkManagerProxy::createAlgorithmDocs(const std::string& algName, const int version)
{
const std::string EOL="\n";
API::IAlgorithm_sptr algm = API::AlgorithmManager::Instance().createUnmanaged(algName, version);
algm->initialize();
// Put in the quick overview message
std::stringstream buffer;
std::string temp = algm->getOptionalMessage();
if (temp.size() > 0)
buffer << temp << EOL << EOL;
// get a sorted copy of the properties
PropertyVector properties(algm->getProperties());
std::sort(properties.begin(), properties.end(), PropertyOrdering());
// generate the sanitized names
StringVector names(properties.size());
size_t numProps = properties.size();
for ( size_t i = 0; i < numProps; ++i)
{
names[i] = removeCharacters(properties[i]->name(), "");
}
buffer << "Property descriptions: " << EOL << EOL;
// write the actual property descriptions
Mantid::Kernel::Property *prop;
for ( size_t i = 0; i < numProps; ++i)
{
prop = properties[i];
buffer << names[i] << "("
<< Mantid::Kernel::Direction::asText(prop->direction());
if (!prop->isValid().empty())
buffer << ":req";
buffer << ") *" << prop->type() << "* ";
std::set<std::string> allowed = prop->allowedValues();
if (!prop->documentation().empty() || !allowed.empty())
{
buffer << " " << prop->documentation();
if (!allowed.empty())
{
buffer << " [" << Kernel::Strings::join(allowed.begin(), allowed.end(), ", ");
buffer << "]";
}
buffer << EOL;
if( i < numProps - 1 ) buffer << EOL;
}
}
return buffer.str();
}
示例3: CreateSimpleAPIHelper
/**
* A helper function to create the simple API
* @param algName :: A string giving the name of the algorithm
* @param path :: The path to the .m file that we should create
*/
void CreateSimpleAPIHelper(const std::string &algName,
const std::string &path) {
IAlgorithm *alg;
try {
alg = FrameworkManager::Instance().createAlgorithm(algName);
} catch (std::exception &) {
std::string err = "An error occurred while writing the ";
err += algName + " function definition.\n";
mexErrMsgTxt(err.c_str());
return;
}
std::string fullpath(path + algName + ".m");
std::ofstream mfile(fullpath.c_str());
typedef std::vector<Mantid::Kernel::Property *> PropertyVector;
// parameter list
mfile << "function res = " << algName << "(varargin)\n";
// help string
PropertyVector orderedProperties(alg->getProperties());
std::sort(orderedProperties.begin(), orderedProperties.end(),
PropertyOrdering());
PropertyVector::const_iterator pIter = orderedProperties.begin();
PropertyVector::const_iterator pEnd = orderedProperties.end();
mfile << "%\t" << algName << "(";
for (; pIter != pEnd;) {
mfile << (*pIter)->name();
if (++pIter != pEnd)
mfile << ", ";
}
mfile << ")\n";
mfile << "%\t\tArgument description:\n";
pIter = orderedProperties.begin();
unsigned int iOpt(0);
for (; pIter != pEnd; ++pIter) {
Mantid::Kernel::Property *prop = *pIter;
mfile << "%\t\tName: " << prop->name() << ", Optional: ";
if (prop->isValid() == "") {
++iOpt;
mfile << "Yes, Default value: " << santizePropertyValue(prop->value());
} else
mfile << "No";
mfile << ", Direction: "
<< Mantid::Kernel::Direction::asText(prop->direction()); // << ", ";
auto allowed = prop->allowedValues();
if (!allowed.empty()) {
mfile << ", Allowed values: ";
auto sIter = allowed.begin();
auto sEnd = allowed.end();
for (; sIter != sEnd;) {
mfile << (*sIter);
if (++sIter != sEnd)
mfile << ", ";
}
}
mfile << "\n";
}
mfile << "%\n%\tNote: All string arguments must be wrapped in single quotes "
"''.\n";
// The function definition
mfile << "if nargin < " << (orderedProperties.size() - iOpt) << "\n"
<< "\tfprintf('All mandatory arguments have not been supplied, type "
"\"help " << algName << "\" for more information\\n');\n"
<< "\treturn\n"
<< "end\n";
mfile << "alg = MantidAlgorithm('" << algName << "');\n"
<< "argstring = '';\n";
// Build arguments list
mfile << "for i = 1:nargin\n"
<< "\targstring = strcat(argstring,varargin{i});\n"
<< "\tif i < nargin\n"
<< "\t\targstring = strcat(argstring, ';');\n"
<< "\tend\n"
<< "end\n";
// Run the algorithm
mfile << "res = run(alg, argstring);\n";
mfile.close();
}
示例4: initLayout
/**
* Reimplemented virtual function to set up the dialog
*/
void LoadRawDialog::initLayout() {
QVBoxLayout *main_layout = new QVBoxLayout(this);
// Add the helpful summary message
if (isMessageAvailable())
this->addOptionalMessage(main_layout);
//------------- Filename property ---------------------
QHBoxLayout *prop_line = new QHBoxLayout;
prop_line->addWidget(new QLabel("Select a file to load:"));
m_pathBox = new QLineEdit;
m_pathBox->setMinimumWidth(m_pathBox->fontMetrics().maxWidth() * 13);
prop_line->addWidget(m_pathBox);
tie(m_pathBox, "Filename", prop_line);
QPushButton *browseBtn = new QPushButton("Browse");
connect(browseBtn, SIGNAL(clicked()), this, SLOT(browseClicked()));
browseBtn->setEnabled(isWidgetEnabled("Filename"));
prop_line->addWidget(browseBtn);
main_layout->addLayout(prop_line);
//------------- OutputWorkspace property ---------------------
m_wsBox = new QLineEdit;
prop_line = new QHBoxLayout;
prop_line->addWidget(new QLabel("Enter name for workspace:"));
prop_line->addWidget(m_wsBox);
tie(m_wsBox, "OutputWorkspace", prop_line);
prop_line->addStretch();
main_layout->addLayout(prop_line);
//------------- Spectra properties ---------------------
QGroupBox *groupbox = new QGroupBox("Spectra Options");
prop_line = new QHBoxLayout;
QLineEdit *text_field = new QLineEdit;
text_field->setMaximumWidth(m_wsBox->fontMetrics().width("888888"));
prop_line->addWidget(new QLabel("Start:"));
prop_line->addWidget(text_field);
tie(text_field, "SpectrumMin", prop_line);
text_field = new QLineEdit;
text_field->setMaximumWidth(m_wsBox->fontMetrics().width("888888"));
prop_line->addWidget(new QLabel("End:"));
prop_line->addWidget(text_field);
tie(text_field, "SpectrumMax", prop_line);
text_field = new QLineEdit;
prop_line->addWidget(new QLabel("List:"));
prop_line->addWidget(text_field);
tie(text_field, "SpectrumList", prop_line);
prop_line->addStretch();
groupbox->setLayout(prop_line);
main_layout->addWidget(groupbox);
//------------- Period properties ---------------------
prop_line = new QHBoxLayout;
text_field = new QLineEdit;
prop_line->addWidget(new QLabel("Periods:"));
prop_line->addWidget(text_field);
prop_line->addStretch();
tie(text_field, "PeriodList", prop_line);
main_layout->addLayout(prop_line);
//------------- Cache option , log files options and Monitors Options
//---------------------
Mantid::Kernel::Property *cacheProp = getAlgorithmProperty("Cache");
if (cacheProp) {
QComboBox *cacheBox = new QComboBox;
std::vector<std::string> items = cacheProp->allowedValues();
std::vector<std::string>::const_iterator vend = items.end();
for (std::vector<std::string>::const_iterator vitr = items.begin();
vitr != vend; ++vitr) {
cacheBox->addItem(QString::fromStdString(*vitr));
}
prop_line = new QHBoxLayout;
prop_line->addWidget(new QLabel("Cache file locally:"), 0, Qt::AlignRight);
prop_line->addWidget(cacheBox, 0, Qt::AlignLeft);
tie(cacheBox, "Cache", prop_line);
}
prop_line->addStretch();
// If the algorithm version supports the LoadLog property add a check box for
// it
Mantid::Kernel::Property *loadlogs = getAlgorithmProperty("LoadLogFiles");
if (loadlogs) {
QCheckBox *checkbox = new QCheckBox("Load Log Files", this);
prop_line->addWidget(checkbox);
tie(checkbox, "LoadLogFiles", prop_line);
}
prop_line->addStretch();
//------------- If the algorithm version supports the LoadMonitors property
//.........这里部分代码省略.........