OTB  6.7.0
Orfeo Toolbox
otbWrapperListViewParameter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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
42  : public Parameter
43 {
44 public:
50 
52  itkNewMacro(Self);
53 
55  itkTypeMacro(ListViewParameter, Parameter);
56 
57  itkSetMacro(SingleSelection,bool);
58  itkGetMacro(SingleSelection,bool);
59  itkBooleanMacro(SingleSelection);
60 
62  void AddChoice( std::string choicekey, std::string choiceName );
63 
65  std::string GetChoiceKey(int i) const;
66 
68  std::vector<std::string> GetChoiceKeys();
69 
71  std::string GetChoiceName( int i );
72 
74  std::vector<std::string> GetChoiceNames();
75 
77  unsigned int GetNbChoices( void );
78 
80  virtual void SetValue(unsigned int v);
81 
83  virtual void SetValue(std::string choiceKey);
84 
86  virtual unsigned int GetValue() const;
87 
88  bool HasValue() const override
89  {
90  // a choice parameter always has a value
91  return true;
92  }
93 
94  void ClearValue() override
95  {
96  // nothing to do : a choice parameter always has a value
97  }
98 
99  void ClearChoices();
100 
101  std::vector<int> GetSelectedItems()
102  {
103  return m_SelectedItems;
104  }
105 
106  void SetSelectedNames(std::vector<std::string> selectedNames);
107 
108  std::vector<std::string> GetSelectedNames() const
109  {
110  return m_SelectedNames;
111  }
112 
113 
114  void SetSelectedKeys(std::vector<std::string> selectedKeys);
115 
116  std::vector<std::string> GetSelectedKeys()
117  {
118  return m_SelectedKeys;
119  }
120 
124 
128 
129  void SetSelectedItems(std::vector<std::string> selectedItems)
130  {
131  std::vector<int> items;
132  for( unsigned int i=0; i<selectedItems.size(); i++ )
133  {
134  items.push_back( atoi( selectedItems[i].c_str() ) );
135  }
136  this->SetSelectedItems(items);
137  }
138 
139  void SetSelectedItems(std::vector<int> selectedItems)
140  {
141  m_SelectedItems = selectedItems;
142  m_SelectedNames.clear();
143  m_SelectedKeys.clear();
144  // update selected names and keys
145  std::vector<std::string> names = this->GetChoiceNames();
146  std::vector<std::string> keys = this->GetChoiceKeys();
147  for (unsigned int i=0 ; i<m_SelectedItems.size() ; i++)
148  {
149  m_SelectedNames.push_back(names[m_SelectedItems[i]]);
150  m_SelectedKeys.push_back(keys[m_SelectedItems[i]]);
151  }
152  }
153 
154  ParameterType GetType() const override
155  {
156  return ParameterType_ListView;
157  }
158 
159  std::string ToString() const override
160  {
161  std::string choiceKey = GetChoiceKey(GetValue());
162  size_t lastPointPos = choiceKey.find_last_of('.');
163 
164  if (lastPointPos != std::string::npos)
165  {
166  return choiceKey.substr(lastPointPos);
167  }
168  return choiceKey;
169  }
170 
171  void FromString(const std::string& value) override
172  {
173  SetValue(value);
174  }
175 
176  std::vector<std::string> ToStringList() const override
177  {
178  return GetSelectedNames();
179  }
180 
181  void FromStringList(const std::vector<std::string>& values) override
182  {
183  SetSelectedNames(values);
184  }
185 
186 protected:
189 
191  ~ListViewParameter() override;
192 
194  {
196 
197  std::string m_Key;
198  std::string m_Name;
199  };
200 
201  typedef std::vector<ListViewChoice> ChoiceList;
203  unsigned int m_CurrentChoice;
204  std::vector<int> m_SelectedItems;
205  std::vector<std::string> m_SelectedKeys;
206  std::vector<std::string> m_SelectedNames;
208 
209 private:
210  ListViewParameter(const ListViewParameter &) = delete;
211  void operator =(const ListViewParameter&) = delete;
212 
213 }; // End class Parameter
214 
215 } // End namespace Wrapper
216 } // End namespace otb
217 
218 #endif
std::vector< ListViewChoice > ChoiceList
void SetSelectedItems(std::vector< std::string > selectedItems)
void FromString(const std::string &value) override
This class represent a parameter for the wrapper framework This class is a high level class represent...
void FromStringList(const std::vector< std::string > &values) override
std::vector< std::string > m_SelectedNames
std::vector< std::string > GetSelectedKeys()
This class represent a ListWidget parameter for the wrapper framework.
void SetSelectedItems(std::vector< int > selectedItems)
std::vector< std::string > GetSelectedNames() const
itk::SmartPointer< const Self > ConstPointer
ParameterType GetType() const override
std::vector< std::string > ToStringList() const override