From 115f3f284cd9260fc957e750e8a17735dd9f7c76 Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Sun, 12 Jun 2011 12:14:58 +0200 Subject: [PATCH] ENH: add GetParametersKeys --- Code/Core/otbWrapperApplication.cxx | 7 +++++ Code/Core/otbWrapperApplication.h | 9 +++--- Code/Core/otbWrapperChoiceParameter.cxx | 33 ++++++++++++++++---- Code/Core/otbWrapperChoiceParameter.h | 5 ++-- Code/Core/otbWrapperParameterGroup.cxx | 40 +++++++++++++++++++++++++ Code/Core/otbWrapperParameterGroup.h | 2 ++ 6 files changed, 83 insertions(+), 13 deletions(-) diff --git a/Code/Core/otbWrapperApplication.cxx b/Code/Core/otbWrapperApplication.cxx index 26b7b1c392..bdd9348ff1 100644 --- a/Code/Core/otbWrapperApplication.cxx +++ b/Code/Core/otbWrapperApplication.cxx @@ -48,6 +48,13 @@ Application::~Application() { } + +std::list<std::string> +Application::GetParametersKeys() +{ + return GetParameterList()->GetParametersKeys(); +} + ParameterGroup* Application::GetParameterList() { if (!m_ParameterList) diff --git a/Code/Core/otbWrapperApplication.h b/Code/Core/otbWrapperApplication.h index 6917323991..6e469079df 100644 --- a/Code/Core/otbWrapperApplication.h +++ b/Code/Core/otbWrapperApplication.h @@ -225,13 +225,14 @@ public: /* GetParameterInt * * Can be called for types : - * \li ParameterType_Int - * \li ParameterType_Float - * \li ParameterType_Radius - * \li ParameterType_Choice + * \li ParameterType_InputVectorData */ VectorDataType* GetParameterVectorData(std::string parameter); + /* Get the list of all parameters + */ + std::list<std::string> GetParametersKeys(); + protected: /** Constructor */ Application(); diff --git a/Code/Core/otbWrapperChoiceParameter.cxx b/Code/Core/otbWrapperChoiceParameter.cxx index ad9c269ede..46b66977b1 100644 --- a/Code/Core/otbWrapperChoiceParameter.cxx +++ b/Code/Core/otbWrapperChoiceParameter.cxx @@ -42,12 +42,6 @@ ChoiceParameter::AddChoice( std::string choicekey, std::string choiceName ) m_ChoiceList.push_back(choice); } -void -ChoiceParameter::AddParameterToChoice( std::string choicekey, std::string choiceName, Parameter* param ) -{ - -} - std::string ChoiceParameter::GetChoiceKey( int i ) { @@ -149,6 +143,33 @@ ChoiceParameter::GetAnyValue() } +/** Return any value */ +std::list<std::string> +ChoiceParameter::GetParametersKeys() +{ + std::cout << "ChoiceParameter::GetParametersKeys()" << std::endl; + std::list<std::string> parameters; + + ChoiceList::iterator cit = m_ChoiceList.begin(); + + for (cit = m_ChoiceList.begin(); cit != m_ChoiceList.end(); ++cit) + { + std::cout << "Choice " << cit->m_Key << std::endl; + if (cit->m_AssociatedParameter) + { + std::list<std::string> subparams = cit->m_AssociatedParameter->GetParametersKeys(); + for (std::list<std::string>::const_iterator it = subparams.begin(); + it != subparams.end(); ++it) + { + std::cout << "ParameterGroup push_back " << cit->m_Key + "." + *it << std::endl; + + parameters.push_back( cit->m_Key + "." + *it ); + } + } + } + return parameters; +} + } } diff --git a/Code/Core/otbWrapperChoiceParameter.h b/Code/Core/otbWrapperChoiceParameter.h index 09daa29910..53e3b69b7f 100644 --- a/Code/Core/otbWrapperChoiceParameter.h +++ b/Code/Core/otbWrapperChoiceParameter.h @@ -51,9 +51,6 @@ public: /** Add a value to the choice */ void AddChoice( std::string choicekey, std::string choiceName ); - /** Add parameter to choice */ - void AddParameterToChoice( std::string choicekey, std::string choiceName , Parameter* param ); - /** Get the key of a specific choice value */ std::string GetChoiceKey( int i ); @@ -66,6 +63,8 @@ public: /** Get the ParameterGroup associated to a choice value */ ParameterGroup::Pointer GetChoiceParameterGroupByKey( std::string choiceKey ); + std::list<std::string> GetParametersKeys(); + /** Get the number of available choice */ unsigned int GetNbChoices( void ); diff --git a/Code/Core/otbWrapperParameterGroup.cxx b/Code/Core/otbWrapperParameterGroup.cxx index 856cb3fb59..fc92a5e327 100644 --- a/Code/Core/otbWrapperParameterGroup.cxx +++ b/Code/Core/otbWrapperParameterGroup.cxx @@ -43,6 +43,46 @@ ParameterGroup::~ParameterGroup() { } +std::list<std::string> +ParameterGroup::GetParametersKeys() +{ + std::list<std::string> parameters; + + ParameterListType::iterator pit; + for (pit = m_ParameterList.begin(); pit != m_ParameterList.end(); ++pit) + { + Parameter* param = *pit; + if (dynamic_cast<ParameterGroup*>(param)) + { + ParameterGroup* paramAsGroup = dynamic_cast<ParameterGroup*>(param); + std::list<std::string> subparams = paramAsGroup->GetParametersKeys(); + for (std::list<std::string>::const_iterator it = subparams.begin(); + it != subparams.end(); ++it) + { + parameters.push_back( std::string(paramAsGroup->GetKey()) + "." + *it ); + } + } + else if (dynamic_cast<ChoiceParameter*>(param)) + { + ChoiceParameter* paramAsChoice = dynamic_cast<ChoiceParameter*>(param); + parameters.push_back( param->GetKey() ); + + std::list<std::string> subparams = paramAsChoice->GetParametersKeys(); + for (std::list<std::string>::const_iterator it = subparams.begin(); + it != subparams.end(); ++it) + { + parameters.push_back( std::string(paramAsChoice->GetKey()) + "." + *it ); + } + } + else + { + parameters.push_back( param->GetKey() ); + } + } + return parameters; +} + + /** Add a new choice value to the parameter group */ void ParameterGroup::AddChoice(std::string paramKey, std::string paramName) diff --git a/Code/Core/otbWrapperParameterGroup.h b/Code/Core/otbWrapperParameterGroup.h index 73dbd976ac..9a58ac149b 100644 --- a/Code/Core/otbWrapperParameterGroup.h +++ b/Code/Core/otbWrapperParameterGroup.h @@ -59,6 +59,8 @@ public: unsigned int GetNumberOfParameters(); + std::list<std::string> GetParametersKeys(); + protected: ParameterGroup(); virtual ~ParameterGroup(); -- GitLab