diff --git a/Code/ApplicationEngine/otbWrapperParameterGroup.cxx b/Code/ApplicationEngine/otbWrapperParameterGroup.cxx index 3233dceab1efa2473faecc1a2542cc22c440175c..58014e3d1179af5bb58ff36d90fbb396bfa083b4 100644 --- a/Code/ApplicationEngine/otbWrapperParameterGroup.cxx +++ b/Code/ApplicationEngine/otbWrapperParameterGroup.cxx @@ -17,6 +17,7 @@ =========================================================================*/ #include "otbWrapperParameterGroup.h" #include "otbWrapperChoiceParameter.h" +#include "otbWrapperListViewParameter.h" #include "otbWrapperDirectoryParameter.h" #include "otbWrapperEmptyParameter.h" #include "otbWrapperFilenameParameter.h" @@ -100,12 +101,17 @@ ParameterGroup::AddChoice(std::string paramKey, std::string paramName) std::string parentkey = pKey.GetRoot(); Parameter::Pointer parentParam = GetParameterByKey(parentkey); - // parentParam must be a choice or this is an error - ChoiceParameter* parentAsChoice = dynamic_cast<ChoiceParameter*>(parentParam.GetPointer()); + // parentParam must be a choice, a listBox or this is an error + ChoiceParameter* comboboxParentAsChoice = dynamic_cast<ChoiceParameter*>(parentParam.GetPointer()); + ListViewParameter* listBoxParentAsChoice = dynamic_cast<ListViewParameter*>(parentParam.GetPointer()); - if (parentAsChoice) + if (comboboxParentAsChoice) { - parentAsChoice->AddChoice(lastkey, paramName); + comboboxParentAsChoice->AddChoice(lastkey, paramName); + } + else if (listBoxParentAsChoice) + { + listBoxParentAsChoice->AddChoice(lastkey, paramName); } else { @@ -117,6 +123,77 @@ ParameterGroup::AddChoice(std::string paramKey, std::string paramName) itkExceptionMacro(<<"No choice parameter key given"); } } + +/** Remove the choices made for the ViewList parameter */ +void +ParameterGroup::ClearChoices(std::string paramKey) +{ + ParameterKey pKey( paramKey ); + // Split the parameter name + std::vector<std::string> splittedKey = pKey.Split(); + + std::string parentkey; + Parameter::Pointer parentParam; + + if (splittedKey.size() > 1) + { + parentkey = pKey.GetRoot(); + parentParam = GetParameterByKey(parentkey); + } + else + { + parentParam = GetParameterByKey(splittedKey[0]); + } + + // parentParam must be a choice, a listBox or this is an error + ListViewParameter* listBoxParentAsChoice = dynamic_cast<ListViewParameter*>(parentParam.GetPointer()); + + if (listBoxParentAsChoice) + { + listBoxParentAsChoice->ClearChoices(); + } + else + { + itkExceptionMacro(<<parentkey << " is not a ListView"); + } +} + +/** Get the choices made in the QListWidget */ +std::vector<int> +ParameterGroup::GetSelectedItems(std::string paramKey) +{ + std::vector<int> selectedItems; + ParameterKey pKey( paramKey ); + // Split the parameter name + std::vector<std::string> splittedKey = pKey.Split(); + + std::string parentkey; + Parameter::Pointer parentParam; + + if (splittedKey.size() > 1) + { + parentkey = pKey.GetRoot(); + parentParam = GetParameterByKey(parentkey); + } + else + { + parentParam = GetParameterByKey(splittedKey[0]); + } + + // parentParam must be a choice, a listBox or this is an error + ListViewParameter* listBoxParentAsChoice = dynamic_cast<ListViewParameter*>(parentParam.GetPointer()); + + if (listBoxParentAsChoice) + { + selectedItems = listBoxParentAsChoice->GetSelectedItems(); + } + else + { + itkExceptionMacro(<<parentkey << " is not a ListView"); + } + + return selectedItems; +} /** Add a new parameter to the parameter group */ @@ -229,6 +306,11 @@ ParameterGroup::AddParameter(ParameterType type, std::string paramKey, std::stri newParam = InputImageListParameter::New(); } break; + case ParameterType_ListView: + { + newParam = ListViewParameter::New(); + } + break; } if (newParam.IsNull()) diff --git a/Code/ApplicationEngine/otbWrapperParameterGroup.h b/Code/ApplicationEngine/otbWrapperParameterGroup.h index aa96a2a26f16d557be24fca21b0b1024068078aa..d4a52ec38fe1d6882dabc79c84be7e65850e052d 100644 --- a/Code/ApplicationEngine/otbWrapperParameterGroup.h +++ b/Code/ApplicationEngine/otbWrapperParameterGroup.h @@ -48,6 +48,12 @@ public: /** Add a new choice value to an existing choice parameter */ void AddChoice(std::string paramKey, std::string paramName); + /** Remove choices made in ListViewParamter widget*/ + void ClearChoices(std::string paramKey); + + /** Get the choices made in a ListView Parameter widget*/ + std::vector<int> GetSelectedItems(std::string paramKey); + /** Add a new parameter to the parameter group * the parent key of paramKey can be the path to a parameter group * or the path to a choice value */