Orfeo Toolbox  4.0
otbWrapperChoiceParameter.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 ChoiceParameter::AddChoice( std::string choicekey, std::string choiceName )
37 {
38  Choice choice;
39  choice.m_Key = choicekey;
40  choice.m_Name = choiceName;
42  choice.m_AssociatedParameter->SetName(choiceName);
43  choice.m_AssociatedParameter->SetRoot(this);
44 
45  m_ChoiceList.push_back(choice);
46 
47  // check if the new choice matches the m_CurrentChoice : if so the group should be active.
48  if (m_CurrentChoice == (m_ChoiceList.size() - 1))
49  {
50  m_ChoiceList[m_CurrentChoice].m_AssociatedParameter->SetActive(true);
51  }
52 
53  // Add the associated parameter as a child
54  // in order to not have a gap in the children hierarchy
56 }
57 
58 std::string
60 {
61  return m_ChoiceList[i].m_Key;
62 }
63 
64 
65 std::vector<std::string>
67 {
68  std::vector<std::string> ret;
69  ChoiceList::iterator it = m_ChoiceList.begin();
70 
71  for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
72  {
73  ret.push_back(it->m_Key);
74  }
75 
76  return ret;
77 }
78 
79 
80 std::string
82 {
83  return m_ChoiceList[i].m_Name;
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 
103 {
104  return m_ChoiceList[i].m_AssociatedParameter;
105 }
106 
109 {
110  ChoiceList::iterator it = m_ChoiceList.begin();
111 
112  for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
113  {
114  if ( it->m_Key == choiceKey )
115  {
116  return it->m_AssociatedParameter;
117  }
118  }
119 
120  itkExceptionMacro(<< "Cannot find " << choiceKey);
121 }
122 
123 unsigned int
125 {
126  return m_ChoiceList.size();
127 }
128 
129 void
131 {
132  m_CurrentChoice = v;
133  SetActive(true);
134  // update the active flag in sub parameters
135  for (unsigned int i=0; i< m_ChoiceList.size(); i++)
136  {
137  if (m_ChoiceList[i].m_AssociatedParameter)
138  {
139  if (i==m_CurrentChoice)
140  {
141  if (!m_ChoiceList[i].m_AssociatedParameter->GetActive())
142  {
143  m_ChoiceList[i].m_AssociatedParameter->SetActive(true);
144  }
145  }
146  else
147  {
148  if (m_ChoiceList[i].m_AssociatedParameter->GetActive())
149  {
150  m_ChoiceList[i].m_AssociatedParameter->SetActive(false);
151  }
152  }
153  }
154  }
155 
156  // Call Modified();
157  this->Modified();
158 }
159 
160 void
161 ChoiceParameter::SetValue(std::string choiceKey)
162 {
163  ChoiceList::iterator it = m_ChoiceList.begin();
164 
165  unsigned int i = 0;
166  for (it = m_ChoiceList.begin(); it != m_ChoiceList.end(); ++it)
167  {
168  if ( it->m_Key == choiceKey )
169  {
170  SetValue(i);
171  return;
172  }
173  ++i;
174  }
175 
176  itkExceptionMacro(<< "Cannot find " << choiceKey);
177 }
178 
179 unsigned int
181 {
182  return m_CurrentChoice;
183 }
184 
186 std::vector<std::string>
188 {
189  std::vector<std::string> parameters;
190 
191  ChoiceList::iterator cit = m_ChoiceList.begin();
192 
193  for (cit = m_ChoiceList.begin(); cit != m_ChoiceList.end(); ++cit)
194  {
195  if (cit->m_AssociatedParameter)
196  {
197  std::vector<std::string> subparams = cit->m_AssociatedParameter->GetParametersKeys();
198  for (std::vector<std::string>::const_iterator it = subparams.begin();
199  it != subparams.end(); ++it)
200  {
201  parameters.push_back( cit->m_Key + "." + *it );
202  }
203  }
204  }
205  return parameters;
206 }
207 
208 }
209 }

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