OTB  10.0.0
Orfeo Toolbox
otbWrapperListViewParameter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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:
216  void operator=(const ListViewParameter&) = delete;
217 
218 }; // End class Parameter
219 
220 } // End namespace Wrapper
221 } // End namespace otb
222 
223 #endif
This class represent a ListWidget parameter for the wrapper framework.
std::string GetChoiceKey(int i) const
itk::SmartPointer< const Self > ConstPointer
std::vector< std::string > m_SelectedNames
void FromString(const std::string &value) override
virtual unsigned int GetValue() const
std::vector< std::string > GetSelectedNames() const
ParameterType GetType() const override
std::vector< std::string > ToStringList() const override
void SetSelectedItems(std::vector< int > selectedItems)
std::vector< ListViewChoice > ChoiceList
std::string GetChoiceName(int i)
unsigned int GetNbChoices(void)
std::vector< std::string > GetChoiceNames()
void operator=(const ListViewParameter &)=delete
void SetSelectedItems(std::vector< std::string > selectedItems)
void SetSelectedKeys(std::vector< std::string > selectedKeys)
void SetSelectedNames(std::vector< std::string > selectedNames)
std::vector< std::string > GetSelectedKeys()
void AddChoice(std::string choicekey, std::string choiceName)
ListViewParameter(const ListViewParameter &)=delete
virtual void SetValue(std::string choiceKey)
void FromStringList(const std::vector< std::string > &values) override
virtual void SetValue(unsigned int v)
std::vector< std::string > GetChoiceKeys()
This class represent a parameter for the wrapper framework This class is a high level class represent...
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.