50 connect(mCurrentPreset.get(), SIGNAL(changed()),
this, SLOT(currentPresetChangedSlot()));
52 this->currentPresetChangedSlot();
55 void ElastixParameters::addDefaultPresets()
58 this->addDefaultPreset(
"elastix/p_Rigid", defaultExecutable, QStringList() <<
"p_Rigid.txt");
61 void ElastixParameters::addDefaultPreset(QString name, QString executable, QStringList parameterFiles)
67 XmlOptionFile node = mOptions.
descend(
"preset",
"name", name);
68 node.
getElement().setAttribute(
"executable", executable);
69 for (
unsigned i=0; i<parameterFiles.size(); ++i)
71 QString parName = QString(
"parameterFile%1").arg(i);
72 QString parVal = QFileInfo(parameterFiles[i]).fileName();
73 node.getElement().setAttribute(parName, parVal);
77 void ElastixParameters::currentPresetChangedSlot()
79 this->reloadPresets();
81 XmlOptionFile node = mOptions.
descend(
"preset",
"name", mCurrentPreset->getValue());
82 mActiveExecutable = node.getElement().attribute(
"executable");
83 mActiveParameterFile0 = this->getFullParameterFilename(node.getElement().attribute(
"parameterFile0"));
84 mActiveParameterFile1 = this->getFullParameterFilename(node.getElement().attribute(
"parameterFile1"));
88 QString ElastixParameters::getFullParameterFilename(QString filename)
95 QStringList folders =
profile()->getAllRootConfigPaths();
96 for(
int i=0; i<folders.size(); ++i)
97 folders[i] = folders[i] +
"/elastix/parameterFiles";
103 return mCurrentPreset;
110 this->reloadPresets();
111 mCurrentPreset->setValue(
"Select Preset...");
114 void ElastixParameters::reloadPresets()
116 this->addDefaultPresets();
118 presets <<
"Select Preset...";
120 QDomNodeList presetNodeList = mOptions.
getElement().elementsByTagName(
"preset");
121 for (
int i = 0; i < presetNodeList.count(); ++i)
123 presets << presetNodeList.item(i).toElement().attribute(
"name");
125 presets.removeDuplicates();
127 mCurrentPreset->blockSignals(
true);
128 mCurrentPreset->setValueRange(presets);
129 mCurrentPreset->blockSignals(
false);
135 node.
getElement().setAttribute(
"executable", mActiveExecutable);
136 node.
getElement().setAttribute(
"parameterFile0", QFileInfo(mActiveParameterFile0).fileName());
137 node.
getElement().setAttribute(
"parameterFile1", QFileInfo(mActiveParameterFile1).fileName());
138 mCurrentPreset->setValue(name);
143 mActiveParameterFile0 = filename;
149 if (this->validParameterFile(mActiveParameterFile0))
150 return mActiveParameterFile0;
156 mActiveParameterFile1 = filename;
162 if (this->validParameterFile(mActiveParameterFile1))
163 return mActiveParameterFile1;
169 mActiveExecutable = filename;
175 return mActiveExecutable;
178 bool ElastixParameters::validParameterFile(QString file)
const
180 return QFileInfo(file).exists() && QFileInfo(file).isFile();
186 if (this->validParameterFile(mActiveParameterFile0))
187 retval << mActiveParameterFile0;
188 if (this->validParameterFile(mActiveParameterFile1))
189 retval << mActiveParameterFile1;
195 QString retval = QFileInfo(mActiveExecutable).baseName();
197 for (
unsigned i=0; i<parFiles.size(); ++i)
198 retval +=
"/" + QFileInfo(parFiles[i]).baseName();
cxResource_EXPORT ProfilePtr profile()
QString getActiveParameterFile0() const
void saveCurrentPreset(QString newName)
void removeCurrentPreset()
Remove the currently selected preset. Reload.
void setActiveParameterFile1(QString filename)
QDomElement getElement()
return the current element
void elastixParametersChanged()
ElastixParameters(XmlOptionFile options)
void setActiveExecutable(QString filename)
QStringList getParameterFilesDir() const
QStringList getActiveParameterFiles() const
StringPropertyBasePtr getCurrentPreset()
static QString findConfigFilePath(QString fileName, QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
QString getActiveExecutable() const
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
void deleteNode()
Delete the current node.
bool isNull() const
checks if this is null
XmlOptionFile tryDescend(QString element, QString attributeName, QString attributeValue) const
Helper class for xml files used to store ssc/cx data.
QString getActiveParameterFile1() const
void setActiveParameterFile0(QString filename)
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
XmlOptionFile descend(QString element) const
step one level down in the xml tree
QString getPresetNameSuggesion() const
create a name describing the active state, can be used as name for a new preset.