Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
parameter-selection.cc
Go to the documentation of this file.
1 /*
2  * lib-controler-gmap : Le contrôleur de 3-G-cartes, surcouche de lib-controler.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of lib-controler-gmap
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 //******************************************************************************
25 #include "controler-gmap.hh"
26 #include "parameter-selection.hh"
27 #include <cassert>
28 using namespace std;
29 using namespace GMap3d;
30 //******************************************************************************
31 CParameterSelection::CParameterSelection(CControlerGMap* AControlerGMapV,
32  int ANbSelectionLevels, int ANbRef) :
33  CParameter (ANbRef),
34  FControlerGMapV(AControlerGMapV),
35  FNbLevels (ANbSelectionLevels),
36  FCurrentLevel (0),
37  FSelectionOrbit(ORBIT_SELF),
38  FHalfSelection (false),
39  FChanged (false)
40 {
41  assert(AControlerGMapV != NULL);
42  assert(0 < ANbSelectionLevels);
43 
44  FMarks = new int[FNbLevels];
45  FLasts = new CDart* [FNbLevels];
46 
47  for (int i=0; i<FNbLevels; ++i)
48  {
49  FMarks[i] = FControlerGMapV->getMap()->getNewMark();
50  FLasts[i] = NULL;
51  }
52 }
53 //******************************************************************************
55  CParameter (AParam),
56  FControlerGMapV(AParam.FControlerGMapV),
57  FNbLevels (AParam.FNbLevels),
58  FCurrentLevel (AParam.FCurrentLevel),
59  FSelectionOrbit(AParam.FSelectionOrbit),
60  FChanged (false)
61 {
62  FMarks = new int[FNbLevels];
63  FLasts = new CDart* [FNbLevels];
64 
65  for (int i=0; i<FNbLevels; ++i)
66  {
67  FMarks[i] = FControlerGMapV->getMap()->getNewMark();
68  FLasts[i] = NULL;
69  }
70 }
71 //******************************************************************************
73 {
74  for (int i=0; i<FNbLevels; ++i)
75  FControlerGMapV->getMap()->freeMark(FMarks[i]);
76 
77  delete []FMarks;
78  delete []FLasts;
79 }
80 //******************************************************************************
82 { return new CParameterSelection(*this); }
83 //******************************************************************************
84 void CParameterSelection::save(ostream& /*AStream*/)
85 {}
86 //------------------------------------------------------------------------------
87 void CParameterSelection::load(istream& /*AStream*/)
88 {}
89 //------------------------------------------------------------------------------
91 {}
92 //******************************************************************************
94 { return FChanged; }
95 //------------------------------------------------------------------------------
97 {
98  if ( !FChanged )
99  {
100  FChanged = true;
102  }
103 }
104 //------------------------------------------------------------------------------
106 { FChanged = false; }
107 //******************************************************************************
109 { return PARAMETER_SELECTION; }
110 //******************************************************************************
112 { return FNbLevels; }
113 //******************************************************************************
115 { return FCurrentLevel; }
116 //------------------------------------------------------------------------------
118 { return (getSelectionLevel()+AIndex) % getNbSelectionLevels(); }
119 //------------------------------------------------------------------------------
121 {
122  assert( 0<=ALevel && ALevel<FNbLevels );
123  if ( FCurrentLevel!=ALevel )
124  {
125  FCurrentLevel = ALevel;
126  setChanged();
127  }
128 }
129 //******************************************************************************
131 { return FMarks[FCurrentLevel]; }
132 //------------------------------------------------------------------------------
134 {
135  assert( 0<=ALevel && ALevel<FNbLevels );
136  return FMarks[ALevel];
137 }
138 //------------------------------------------------------------------------------
140 { return getSelectionMark(getNextSelectionLevel(AIndex)); }
141 //******************************************************************************
143 { return FSelectionOrbit; }
144 //------------------------------------------------------------------------------
146 {
147  assert(ORBIT_SELF <= AOrbit && AOrbit <= ORBIT_CC);
148  FSelectionOrbit = AOrbit;
149 }
150 //------------------------------------------------------------------------------
152 {
153  FSelectionOrbit = FSelectionOrbit==ORBIT_CC ? ORBIT_SELF : 1 + FSelectionOrbit;
154 }
155 //------------------------------------------------------------------------------
157 { return FHalfSelection; }
158 //------------------------------------------------------------------------------
160 { FHalfSelection = ABool; }
161 //******************************************************************************
163 { return FLasts[FCurrentLevel]; }
164 //------------------------------------------------------------------------------
166 {
167  assert( 0<=ALevel && ALevel<FNbLevels );
168  return FLasts[ALevel];
169 }
170 //------------------------------------------------------------------------------
172 { return getLastSelectedDart(getNextSelectionLevel(AIndex)); }
173 //******************************************************************************
175 {
176  assert( ALastDart!=NULL );
177  if ( FLasts[FCurrentLevel]!=ALastDart )
178  {
179  FLasts[FCurrentLevel] = ALastDart;
180  setChanged();
181  }
182 }
183 //------------------------------------------------------------------------------
184 void CParameterSelection::setLastSelectedDart(int ALevel, CDart* ALastDart)
185 {
186  assert( 0<=ALevel && ALevel<FNbLevels );
187  assert( ALastDart!=NULL );
188  if ( FLasts[ALevel]!=ALastDart )
189  {
190  FLasts[ALevel] = ALastDart;
191  setChanged();
192  }
193 }
194 //******************************************************************************
196 {
197  if ( FLasts[FCurrentLevel]!=NULL )
198  {
199  FLasts[FCurrentLevel] = NULL;
200  setChanged();
201  }
202 }
203 //------------------------------------------------------------------------------
205 {
206  assert( 0<=ALevel && ALevel<FNbLevels );
207 
208  if ( FLasts[ALevel]!=NULL )
209  {
210  FLasts[ALevel] = NULL;
211  setChanged();
212  }
213 }
214 //------------------------------------------------------------------------------
217 //------------------------------------------------------------------------------
219 {
220  for (int i=0; i<getNbSelectionLevels(); ++i)
222 }
223 //******************************************************************************
224 void CParameterSelection::swapLevels(int ALevel1, int ALevel2)
225 {
226  assert( 0<=ALevel1 && ALevel1<FNbLevels );
227  assert( 0<=ALevel2 && ALevel2<FNbLevels );
228 
229  if ( ALevel1==ALevel2 ) return;
230 
231 // int mark = FMarks[ALevel1];
232 // FMarks[ALevel1] = FMarks[ALevel2];
233 // FMarks[ALevel2] = mark;
234 
235  CDart* last = FLasts[ALevel1];
236  FLasts[ALevel1] = FLasts[ALevel2];
237  FLasts[ALevel2] = last;
238 
239  setChanged();
240 }
241 //******************************************************************************
243 { FControlerGMapV->toggleOrbitSelection(ADart, getSelectionLevel()); }
244 //******************************************************************************