diff --git a/Code/Core/otbWrapperApplication.cxx b/Code/Core/otbWrapperApplication.cxx index a7f683dde64338465e295baca8247c34d7dc3a95..96f45e1201acc3f08d7892fe870a6a76655977b7 100644 --- a/Code/Core/otbWrapperApplication.cxx +++ b/Code/Core/otbWrapperApplication.cxx @@ -233,6 +233,28 @@ ParameterType Application::GetParameterType(std::string paramKey) const return type; } +std::vector<std::string> Application::GetChoiceKeys(std::string name) +{ + Parameter* param = GetParameterByKey(name); + if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + return paramChoice->GetChoiceKeys(); + } + itkExceptionMacro(<< name << " is not a choice parameter"); +} + +std::vector<std::string> Application::GetChoiceNames(std::string name) +{ + Parameter* param = GetParameterByKey(name); + if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramChoice = dynamic_cast<ChoiceParameter*>(param); + return paramChoice->GetChoiceNames(); + } + itkExceptionMacro(<< name << " is not a choice parameter"); +} + void Application::SetParameterInt(std::string parameter, int value) { Parameter* param = GetParameterByKey(parameter); diff --git a/Code/Core/otbWrapperApplication.h b/Code/Core/otbWrapperApplication.h index 1ccc04bd84e92d195a538270d2d913e9ad7dcc7e..68bfa7210f98b9a221beb6c609e633052cde7032 100644 --- a/Code/Core/otbWrapperApplication.h +++ b/Code/Core/otbWrapperApplication.h @@ -137,6 +137,13 @@ public: /* Get the parameter type from its name */ ParameterType GetParameterType(std::string paramKey) const; + /* Returns the description of a parameter */ + std::vector<std::string> GetChoiceKeys(std::string paramKey); + + /* Returns the description of a parameter */ + std::vector<std::string> GetChoiceNames(std::string paramKey); + + /* Set an integer value * * Can be called for types : diff --git a/Code/Core/otbWrapperChoiceParameter.cxx b/Code/Core/otbWrapperChoiceParameter.cxx index 2f0245cc0e20381d6df15bc76d85bf0d81dc941c..fd883db885389982ad6ca733848b6496c66f01c2 100644 --- a/Code/Core/otbWrapperChoiceParameter.cxx +++ b/Code/Core/otbWrapperChoiceParameter.cxx @@ -48,12 +48,44 @@ ChoiceParameter::GetChoiceKey( int i ) return m_ChoiceList[i].m_Key; } + +std::vector<std::string> +ChoiceParameter::GetChoiceKeys( ) +{ + std::vector<std::string> ret; + ChoiceList::iterator it = m_ChoiceList.begin(); + + for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it) + { + ret.push_back(it->m_Key); + } + + return ret; +} + + std::string ChoiceParameter::GetChoiceName( int i ) { return m_ChoiceList[i].m_Name; } + +std::vector<std::string> +ChoiceParameter::GetChoiceNames( ) +{ + std::vector<std::string> ret; + ChoiceList::iterator it = m_ChoiceList.begin(); + + for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it) + { + ret.push_back(it->m_Name); + } + return ret; +} + + + ParameterGroup::Pointer ChoiceParameter::GetChoiceParameterGroupByIndex( int i ) { diff --git a/Code/Core/otbWrapperChoiceParameter.h b/Code/Core/otbWrapperChoiceParameter.h index b35af25587b0550bd19715097bb9e3ab8c46a007..1df1c302f193bce3f357f4fd5dd94c9a0fb30c91 100644 --- a/Code/Core/otbWrapperChoiceParameter.h +++ b/Code/Core/otbWrapperChoiceParameter.h @@ -54,17 +54,25 @@ public: /** Get the key of a specific choice value */ std::string GetChoiceKey( int i ); + /** Get the list of the different choice keys */ + std::vector<std::string> GetChoiceKeys(); + /** Get the long name of a specific choice value */ std::string GetChoiceName( int i ); + /** Get the list of the different choice keys */ + std::vector<std::string> GetChoiceNames(); + /** Get the ParameterGroup associated to a choice value */ ParameterGroup::Pointer GetChoiceParameterGroupByIndex( int i ); /** Get the ParameterGroup associated to a choice value */ ParameterGroup::Pointer GetChoiceParameterGroupByKey( std::string choiceKey ); + /** Get all parameters that are child of this choice parameter */ std::vector<std::string> GetParametersKeys(); + /** Get the number of available choice */ unsigned int GetNbChoices( void ); diff --git a/Code/Wrappers/PyQt/otbapp/widgets.py b/Code/Wrappers/PyQt/otbapp/widgets.py index be70170f8aeb40cfe644058c00d62feec8aef029..2d58ceac708385952506e4542719d7b36039b71b 100644 --- a/Code/Wrappers/PyQt/otbapp/widgets.py +++ b/Code/Wrappers/PyQt/otbapp/widgets.py @@ -103,24 +103,43 @@ class QParameterChoice(QParameterBase): stack = QtGui.QStackedWidget() - allparams = app.GetParametersKeys() - subgroups = set() + allparams = app.GetParametersKeys(True) + print str(allparams) + + subgroups = [] + choicelist = [] for paramKey in allparams: + print 'paramKey ' + paramKey if paramKey.startswith(self._paramKey): + choicelist.append(paramKey) choiceSubParam = paramKey.partition(self._paramKey + '.')[2].partition('.')[0] if choiceSubParam: - subgroups.add(choiceSubParam.partition('.')[0]) - + print "choiceSubParam "+ choiceSubParam + subgroups.append(choiceSubParam.partition('.')[0]) + else: + print "choiceSubParam None" + subgroups.append(None) + + print 'choicelist ' + str(choicelist) + for choice in zip(app.GetChoiceKeys(self._paramKey), app.GetChoiceNames(self._paramKey)): + combo.addItem(choice[1], choice[0]) + for subgroup in subgroups: - combo.addItem(subgroup, subgroup) + if not subgroup: + continue widget = QParameterGroup(self.GetModel(), self._paramKey + '.' + subgroup) if widget: widget.CreateWidget() stack.addWidget(widget) - + else: + stack.addWidget(QtGui.QWidget()) + + self.connect(combo, QtCore.SIGNAL("currentIndexChanged(int)"), self.SetValue) + self.connect(combo, QtCore.SIGNAL("currentIndexChanged(int)"), stack.setCurrentIndex) layout.addWidget(combo) layout.addWidget(stack) + layout.addStretch() self.setLayout(layout) def SetValue(self, val): diff --git a/Code/Wrappers/SWIG/otbApplication.i b/Code/Wrappers/SWIG/otbApplication.i index f6e39db73a82c7e5eaf23d8e4d042e357562ecb2..fb20a947ef8b2385e2d1181e7e34b17f362d17b5 100644 --- a/Code/Wrappers/SWIG/otbApplication.i +++ b/Code/Wrappers/SWIG/otbApplication.i @@ -106,6 +106,9 @@ public: int GetParameterInt(std::string parameter); float GetParameterFloat(std::string parameter); std::string GetParameterString(std::string parameter); + + std::vector<std::string> GetChoiceKeys(std::string choiceKey); + std::vector<std::string> GetChoiceNames(std::string choiceKey); protected: Application(); diff --git a/Example/otbTestApplication.cxx b/Example/otbTestApplication.cxx index c27ddcf51ca6b5c5daeb96e0f1d5a833c2196727..3427ac8a4058fa30ed7b324342bfdc109f6ca507 100644 --- a/Example/otbTestApplication.cxx +++ b/Example/otbTestApplication.cxx @@ -68,6 +68,13 @@ private: AddChoice("choice.choice1", "Choice 1"); AddChoice("choice.choice2", "Choice 2"); AddChoice("choice.choice3", "Choice 3"); + AddParameter(ParameterType_Float, "choice.choice1.floatchoice1", "Float of choice1"); + SetParameterFloat("choice.choice1.floatchoice1", 0.125); +// AddParameter(ParameterType_Float, "choice.choice2.floatchoice2", "Float of choice2"); +// SetParameterFloat("choice.choice2.floatchoice2", 1.0); + AddParameter(ParameterType_Float, "choice.choice3.floatchoice3", "Float of choice3"); + SetParameterFloat("choice.choice3.floatchoice3", 5.0); + //AddParameter(ParameterType_Group, "group", "Group"); }