Orfeo Toolbox  4.0
otbWrapperListViewParameter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
19 
20 namespace otb
21 {
22 namespace Wrapper
23 {
24 
26  : m_CurrentChoice(0)
27 {
28 }
29 
31 {
32 }
33 
34 
35 void
36 ListViewParameter::AddChoice( std::string choicekey, std::string choiceName )
37 {
38  ListViewChoice choice;
39  choice.m_Key = choicekey;
40  choice.m_Name = choiceName;
41  m_ChoiceList.push_back(choice);
42 }
43 
44 std::string
46 {
47  if (m_ChoiceList.empty())
48  {
49  return "";
50  }
51  else
52  {
53  return m_ChoiceList[i].m_Key;
54  }
55 }
56 
57 
58 std::vector<std::string>
60 {
61  std::vector<std::string> ret;
62  ChoiceList::iterator it = m_ChoiceList.begin();
63 
64  for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
65  {
66  ret.push_back(it->m_Key);
67  }
68 
69  return ret;
70 }
71 
72 
73 std::string
75 {
76  if (m_ChoiceList.empty())
77  {
78  return "";
79  }
80  else
81  {
82  return m_ChoiceList[i].m_Name;
83  }
84 }
85 
86 
87 std::vector<std::string>
89 {
90  std::vector<std::string> ret;
91  ChoiceList::iterator it = m_ChoiceList.begin();
92 
93  for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
94  {
95  ret.push_back(it->m_Name);
96  }
97  return ret;
98 }
99 
100 unsigned int
102 {
103  return m_ChoiceList.size();
104 }
105 
106 void
108 {
109  m_CurrentChoice = v;
110  SetActive(true);
111  // Call Modified();
112  this->Modified();
113 }
114 
115 void
116 ListViewParameter::SetValue(std::string choiceKey)
117 {
118  ChoiceList::iterator it = m_ChoiceList.begin();
119 
120  unsigned int i = 0;
121  for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
122  {
123  if ( it->m_Key == choiceKey )
124  {
125  SetValue(i);
126  return;
127  }
128  ++i;
129  }
130 
131  itkExceptionMacro(<< "Cannot find " << choiceKey);
132 }
133 
134 unsigned int
136 {
137  return m_CurrentChoice;
138 }
139 
140 
142 void
144 {
145  m_ChoiceList.clear();
146 }
147 
148 void
150 {
151  std::vector<int> selectedItems;
152  std::vector<std::string> names = this->GetChoiceNames();
153  for(unsigned int i=0; i<m_SelectedNames.size(); i++)
154  {
155  const std::string selectedName = m_SelectedNames[i];
156  unsigned int j(0);
157  for(; j<names.size(); j++)
158  {
159  if( names[j] == selectedName )
160  {
161  selectedItems.push_back(j);
162  break;
163  }
164  }
165  // If not found
166  if( j==names.size() )
167  {
168  std::ostringstream oss;
169  for( j=0; j<names.size(); j++)
170  {
171  oss<<names[j];
172  if( j < names.size()-1 )
173  {
174  oss<<", ";
175  }
176  }
177  itkExceptionMacro("Value "<<selectedName<<" not found in the choices possibilities"<<oss.str()<<".");
178  }
179  }
180  this->SetSelectedItems(selectedItems);
181 }
182 
183 
184 void
186 {
187  std::vector<int> selectedItems;
188  std::vector<std::string> keys = this->GetChoiceKeys();
189  for(unsigned int i=0; i<m_SelectedKeys.size(); i++)
190  {
191  const std::string selectedKey = m_SelectedKeys[i];
192  unsigned int j(0);
193  std::ostringstream oss;
194  for(; j<keys.size(); j++)
195  {
196  if( keys[j] == selectedKey )
197  {
198  selectedItems.push_back(j);
199  break;
200  }
201  }
202  // If not found
203  if( j==keys.size() )
204  {
205  for( j=0; j<keys.size(); j++)
206  {
207  oss<<keys[j];
208  if( j < keys.size()-1 )
209  {
210  oss<<", ";
211  }
212  }
213  itkExceptionMacro("Value "<<selectedKey<<" not found in the choices possibilities"<<oss.str()<<".");
214  }
215  }
216  this->SetSelectedItems(selectedItems);
217 }
218 }
219 }

Generated at Sat Mar 8 2014 16:28:49 for Orfeo Toolbox with doxygen 1.8.3.1