OTB  9.0.0
Orfeo Toolbox
otbWrapperListViewParameter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbWrapperListViewParameter_h
22 #define otbWrapperListViewParameter_h
23 
25 #include <string>
26 
27 namespace otb
28 {
29 namespace Wrapper
30 {
31 
41 class OTBApplicationEngine_EXPORT ListViewParameter : public Parameter
42 {
43 public:
47  typedef itk::SmartPointer<Self> Pointer;
48  typedef itk::SmartPointer<const Self> ConstPointer;
49 
51  itkNewMacro(Self);
52 
54  itkTypeMacro(ListViewParameter, Parameter);
55 
56  itkSetMacro(SingleSelection, bool);
57  itkGetMacro(SingleSelection, bool);
58  itkBooleanMacro(SingleSelection);
59 
61  void AddChoice(std::string choicekey, std::string choiceName);
62 
64  std::string GetChoiceKey(int i) const;
65 
67  std::vector<std::string> GetChoiceKeys();
68 
70  std::string GetChoiceName(int i);
71 
73  std::vector<std::string> GetChoiceNames();
74 
76  unsigned int GetNbChoices(void);
77 
79  virtual void SetValue(unsigned int v);
80 
82  virtual void SetValue(std::string choiceKey);
83 
85  virtual unsigned int GetValue() const;
86 
87  bool HasValue() const override
88  {
89  // a choice parameter always has a value
90  return true;
91  }
92 
93  void ClearValue() override
94  {
95  // nothing to do : a choice parameter always has a value
96  }
97 
98  void ClearChoices();
99 
100  std::vector<int> GetSelectedItems()
101  {
102  return m_SelectedItems;
103  }
104 
105  void SetSelectedNames(std::vector<std::string> selectedNames);
106 
107  std::vector<std::string> GetSelectedNames() const
108  {
109  return m_SelectedNames;
110  }
111 
112 
113  void SetSelectedKeys(std::vector<std::string> selectedKeys);
114 
115  std::vector<std::string> GetSelectedKeys()
116  {
117  return m_SelectedKeys;
118  }
119 
123  {
124  }
125 
129  {
130  }
131 
132  void SetSelectedItems(std::vector<std::string> selectedItems)
133  {
134  std::vector<int> items;
135  for (unsigned int i = 0; i < selectedItems.size(); i++)
136  {
137  items.push_back(atoi(selectedItems[i].c_str()));
138  }
139  this->SetSelectedItems(items);
140  }
141 
142  void SetSelectedItems(std::vector<int> selectedItems)
143  {
144  m_SelectedItems = selectedItems;
145  m_SelectedNames.clear();
146  m_SelectedKeys.clear();
147  // update selected names and keys
148  std::vector<std::string> names = this->GetChoiceNames();
149  std::vector<std::string> keys = this->GetChoiceKeys();
150  for (unsigned int i = 0; i < m_SelectedItems.size(); i++)
151  {
152  m_SelectedNames.push_back(names[m_SelectedItems[i]]);
153  m_SelectedKeys.push_back(keys[m_SelectedItems[i]]);
154  }
155  }
156 
157  ParameterType GetType() const override
158  {
159  return ParameterType_ListView;
160  }
161 
162  std::string ToString() const override
163  {
164  std::string choiceKey = GetChoiceKey(GetValue());
165  size_t lastPointPos = choiceKey.find_last_of('.');
166 
167  if (lastPointPos != std::string::npos)
168  {
169  return choiceKey.substr(lastPointPos);
170  }
171  return choiceKey;
172  }
173 
174  void FromString(const std::string& value) override
175  {
176  SetSelectedNames({value});
177  }
178 
179  std::vector<std::string> ToStringList() const override
180  {
181  return GetSelectedNames();
182  }
183 
184  void FromStringList(const std::vector<std::string>& values) override
185  {
186  SetSelectedNames(values);
187  }
188 
189 protected:
192 
194  ~ListViewParameter() override;
195 
197  {
199  {
200  }
201 
202  std::string m_Key;
203  std::string m_Name;
204  };
205 
206  typedef std::vector<ListViewChoice> ChoiceList;
208  unsigned int m_CurrentChoice;
209  std::vector<int> m_SelectedItems;
210  std::vector<std::string> m_SelectedKeys;
211  std::vector<std::string> m_SelectedNames;
213 
214 private:
215  ListViewParameter(const ListViewParameter&) = delete;
216  void operator=(const ListViewParameter&) = delete;
217 
218 }; // End class Parameter
219 
220 } // End namespace Wrapper
221 } // End namespace otb
222 
223 #endif
otb::Wrapper::ListViewParameter::Superclass
Parameter Superclass
Definition: otbWrapperListViewParameter.h:46
otb::Wrapper::Parameter
This class represent a parameter for the wrapper framework This class is a high level class represent...
Definition: otbWrapperParameter.h:49
otb::Wrapper::ListViewParameter::m_SingleSelection
bool m_SingleSelection
Definition: otbWrapperListViewParameter.h:212
otb::Wrapper::ListViewParameter::ClearValue
void ClearValue() override
Definition: otbWrapperListViewParameter.h:93
otb::Wrapper::ListViewParameter::ListViewChoice::m_Name
std::string m_Name
Definition: otbWrapperListViewParameter.h:203
otb::Wrapper::ListViewParameter::Self
ListViewParameter Self
Definition: otbWrapperListViewParameter.h:45
otb::Wrapper::ListViewParameter::m_SelectedNames
std::vector< std::string > m_SelectedNames
Definition: otbWrapperListViewParameter.h:211
otb::Wrapper::ListViewParameter::m_ChoiceList
ChoiceList m_ChoiceList
Definition: otbWrapperListViewParameter.h:207
otb::Wrapper::ListViewParameter
This class represent a ListWidget parameter for the wrapper framework.
Definition: otbWrapperListViewParameter.h:41
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Wrapper::ListViewParameter::SetSelectedItems
void SetSelectedItems(std::vector< std::string > selectedItems)
Definition: otbWrapperListViewParameter.h:132
otb::Wrapper::ListViewParameter::FromString
void FromString(const std::string &value) override
Definition: otbWrapperListViewParameter.h:174
otb::Wrapper::ListViewParameter::ListViewChoice::m_Key
std::string m_Key
Definition: otbWrapperListViewParameter.h:202
otb::Wrapper::ListViewParameter::m_CurrentChoice
unsigned int m_CurrentChoice
Definition: otbWrapperListViewParameter.h:208
otb::Wrapper::ListViewParameter::SetSelectedItemsByKeys
void SetSelectedItemsByKeys()
Definition: otbWrapperListViewParameter.h:122
otb::Wrapper::ListViewParameter::ListViewChoice::ListViewChoice
ListViewChoice()
Definition: otbWrapperListViewParameter.h:198
otb::Wrapper::ListViewParameter::SetSelectedItemsByNames
void SetSelectedItemsByNames()
Definition: otbWrapperListViewParameter.h:128
otb::Wrapper::ListViewParameter::ChoiceList
std::vector< ListViewChoice > ChoiceList
Definition: otbWrapperListViewParameter.h:206
otb::Wrapper::ListViewParameter::ToString
std::string ToString() const override
Definition: otbWrapperListViewParameter.h:162
otb::Wrapper::ListViewParameter::m_SelectedItems
std::vector< int > m_SelectedItems
Definition: otbWrapperListViewParameter.h:209
otb::Wrapper::ListViewParameter::GetSelectedKeys
std::vector< std::string > GetSelectedKeys()
Definition: otbWrapperListViewParameter.h:115
otb::Wrapper::ListViewParameter::ToStringList
std::vector< std::string > ToStringList() const override
Definition: otbWrapperListViewParameter.h:179
otb::Wrapper::ListViewParameter::m_SelectedKeys
std::vector< std::string > m_SelectedKeys
Definition: otbWrapperListViewParameter.h:210
otb::Wrapper::ListViewParameter::GetType
ParameterType GetType() const override
Definition: otbWrapperListViewParameter.h:157
otb::Wrapper::ListViewParameter::SetSelectedItems
void SetSelectedItems(std::vector< int > selectedItems)
Definition: otbWrapperListViewParameter.h:142
otb::Wrapper::ListViewParameter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbWrapperListViewParameter.h:48
otb::Wrapper::ListViewParameter::GetSelectedNames
std::vector< std::string > GetSelectedNames() const
Definition: otbWrapperListViewParameter.h:107
otb::Wrapper::ListViewParameter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbWrapperListViewParameter.h:47
otb::Wrapper::ListViewParameter::HasValue
bool HasValue() const override
Definition: otbWrapperListViewParameter.h:87
otb::Wrapper::ListViewParameter::GetSelectedItems
std::vector< int > GetSelectedItems()
Definition: otbWrapperListViewParameter.h:100
otbWrapperParameterGroup.h
otb::Wrapper::ParameterType_ListView
@ ParameterType_ListView
Definition: otbWrapperTypes.h:56
otb::Wrapper::ListViewParameter::ListViewChoice
Definition: otbWrapperListViewParameter.h:196
otb::Wrapper::ParameterType
ParameterType
Definition: otbWrapperTypes.h:37
otb::Wrapper::ListViewParameter::FromStringList
void FromStringList(const std::vector< std::string > &values) override
Definition: otbWrapperListViewParameter.h:184