Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
controler-gmap-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 "g-map-vertex.hh"
27 #include "parameter-selection.hh"
28 #include "view-precompile.hh"
29 using namespace std;
30 using namespace GMap3d;
31 //******************************************************************************
32 static string textOrbit[16] =
33 {
34  "Dart", "0", "1", "01",
35  "2", "02", "12", "Volume",
36  "3", "03", "13", "Face",
37  "23", "Edge", "Vertex", "Connected component"
38 };
39 //******************************************************************************
41 { return FParameterSelection->getNbSelectionLevels(); }
42 //******************************************************************************
44 { return FParameterSelection->getSelectionLevel(); }
45 //------------------------------------------------------------------------------
47 { return FParameterSelection->getNextSelectionLevel(AIndex); }
48 //******************************************************************************
50 { return FParameterSelection->getSelectionOrbit(); }
51 //------------------------------------------------------------------------------
53 {
54  FParameterSelection->setSelectionOrbit(AOrbit);
55 
56  string message("Selected orbit: orbit ");
57  setMessage(message + textOrbit[getSelectionOrbit()]);
58 }
59 //------------------------------------------------------------------------------
61 {
62  FParameterSelection->setNextSelectionOrbit();
63 
64  string message("Selected orbit: orbit ");
65  setMessage(message + textOrbit[getSelectionOrbit()]);
66 }
67 //------------------------------------------------------------------------------
69 { return FParameterSelection->getHalfSelection(); }
70 //------------------------------------------------------------------------------
72 { FParameterSelection->setHalfSelection(ABool); }
73 //******************************************************************************
75 { return FParameterSelection->getSelectionMark(); }
76 //------------------------------------------------------------------------------
77 int CControlerGMap::getSelectionMark(int ALevel) const
78 { return FParameterSelection->getSelectionMark(ALevel); }
79 //------------------------------------------------------------------------------
81 { return FParameterSelection->getNextSelectionMark(AIndex); }
82 //******************************************************************************
84 { return FParameterSelection->getLastSelectedDart(); }
85 //------------------------------------------------------------------------------
86 CDart* CControlerGMap::getLastSelectedDart(int ALevel) const
87 { return FParameterSelection->getLastSelectedDart(ALevel); }
88 //------------------------------------------------------------------------------
90 { return FParameterSelection->getNextLastSelectedDart(AIndex); }
91 //******************************************************************************
93 { FParameterSelection->unsetLastSelectedDart(); }
94 //------------------------------------------------------------------------------
96 { FParameterSelection->unsetLastSelectedDart(ALevel); }
97 //------------------------------------------------------------------------------
99 { FParameterSelection->unsetNextLastSelectedDart(AIndex); }
100 //------------------------------------------------------------------------------
102 { FParameterSelection->unsetAllLastSelectedDarts(); }
103 //******************************************************************************
104 bool CControlerGMap::isDartSelected(CDart* ADart) const
105 { return FMap->isMarked(ADart, getSelectionMark()); }
106 //------------------------------------------------------------------------------
107 bool CControlerGMap::isDartSelected(CDart* ADart, int ALevel) const
108 { return FMap->isMarked(ADart, getSelectionMark(ALevel)); }
109 //------------------------------------------------------------------------------
110 bool CControlerGMap::isDartNextSelected(CDart* ADart, int AIndex) const
111 { return FMap->isMarked(ADart, getNextSelectionMark(AIndex)); }
112 //******************************************************************************
113 void CControlerGMap::selectDart(CDart* ADart)
114 { selectDart(ADart, getSelectionLevel()); }
115 //------------------------------------------------------------------------------
116 void CControlerGMap::selectDart(CDart* ADart, int ALevel)
117 {
118  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
119  assert(ADart != NULL);
120 
121  if (!isDartSelected(ADart, ALevel))
122  {
123  FMap->setMark(ADart, getSelectionMark(ALevel));
125  }
126 
127  FParameterSelection->setLastSelectedDart(ALevel, ADart);
128 }
129 //------------------------------------------------------------------------------
130 void CControlerGMap::selectNextDart(CDart* ADart, int AIndex)
131 { selectDart(ADart, getNextSelectionLevel(AIndex)); }
132 //******************************************************************************
134 { deselectDart(ADart, getSelectionLevel()); }
135 //------------------------------------------------------------------------------
136 void CControlerGMap::deselectDart(CDart* ADart, int ALevel)
137 {
138  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
139  assert(ADart != NULL);
140 
141  if (isDartSelected(ADart, ALevel))
142  {
143  FMap->unsetMark(ADart, getSelectionMark(ALevel));
145 
146  if (ADart == getLastSelectedDart(ALevel))
147  FParameterSelection->unsetLastSelectedDart(ALevel);
148  }
149 }
150 //------------------------------------------------------------------------------
151 void CControlerGMap::deselectNextDart(CDart* ADart, int AIndex)
152 { deselectDart(ADart, getNextSelectionLevel(AIndex)); }
153 //******************************************************************************
156 //------------------------------------------------------------------------------
157 void CControlerGMap::toggleDartSelection(CDart* ADart, int ALevel)
158 {
159  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
160  assert(ADart != NULL);
161 
162  if (isDartSelected(ADart, ALevel)) deselectDart(ADart, ALevel);
163  else selectDart(ADart, ALevel);
164 }
165 //------------------------------------------------------------------------------
166 void CControlerGMap::toggleDartNextSelection(CDart* ADart, int AIndex)
167 { toggleDartSelection(ADart, getNextSelectionLevel(AIndex)); }
168 //******************************************************************************
169 void CControlerGMap::selectOrbit(CDart* ADart)
170 { selectOrbit(ADart, getSelectionLevel()); }
171 //------------------------------------------------------------------------------
172 void CControlerGMap::selectOrbit(CDart* ADart, int ALevel)
173 {
174  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
175  assert(ADart != NULL);
176 
177  if (FParameterSelection->getHalfSelection() &&
178  FMap->isOrientable(ADart, getSelectionOrbit()))
179  FMap->halfMarkOrbit(ADart,getSelectionOrbit(),getSelectionMark(ALevel));
180  else
181  FMap->markOrbit(ADart, getSelectionOrbit(), getSelectionMark(ALevel));
182 
183  FParameterSelection->setLastSelectedDart(ALevel, ADart);
185 }
186 //------------------------------------------------------------------------------
187 void CControlerGMap::selectNextOrbit(CDart* ADart, int AIndex)
188 { selectOrbit(ADart, getNextSelectionLevel(AIndex)); }
189 //******************************************************************************
191 { deselectOrbit(ADart, getSelectionLevel()); }
192 //------------------------------------------------------------------------------
193 void CControlerGMap::deselectOrbit(CDart* ADart, int ALevel)
194 {
195  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
196  assert(ADart != NULL);
197 
198  if (FParameterSelection->getHalfSelection() &&
199  FMap->isOrientable(ADart, getSelectionOrbit()))
200  FMap->halfUnmarkOrbit(ADart, getSelectionOrbit(),
201  getSelectionMark(ALevel));
202  else
203  FMap->unmarkOrbit(ADart, getSelectionOrbit(), getSelectionMark(ALevel));
204 
205  if (getLastSelectedDart(ALevel) != NULL &&
206  !isDartSelected(getLastSelectedDart(ALevel), ALevel))
207  FParameterSelection->unsetLastSelectedDart(ALevel);
208 
210 }
211 //------------------------------------------------------------------------------
212 void CControlerGMap::deselectNextOrbit(CDart* ADart, int AIndex)
213 { deselectOrbit(ADart, getNextSelectionLevel(AIndex)); }
214 //******************************************************************************
217 //------------------------------------------------------------------------------
218 void CControlerGMap::toggleOrbitSelection(CDart* ADart, int ALevel)
219 {
220  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
221  assert(ADart != NULL);
222 
223  if (isDartSelected(ADart, ALevel)) deselectOrbit(ADart, ALevel);
224  else selectOrbit(ADart, ALevel);
225 }
226 //------------------------------------------------------------------------------
227 void CControlerGMap::toggleOrbitNextSelection(CDart* ADart, int AIndex)
228 { toggleOrbitSelection(ADart, getNextSelectionLevel(AIndex)); }
229 //******************************************************************************
230 bool CControlerGMap::takeCenter(CVertex & AResult)
231 {
232  int sel = getNextSelectionMark(1);
233  CDart* last = getNextLastSelectedDart(1);
234 
235  if (last == NULL)
236  if (FMap->getMarkedCells(ORBIT_VERTEX, sel, NULL, &last) != 1)
237  return false;
238 
239  AResult = * FMap->findVertex(last);
240  return true;
241 }
242 //------------------------------------------------------------------------------
243 bool CControlerGMap::takeVector(CVertex & AResult)
244 {
245  int sel = getNextSelectionMark(1);
246  CDart* last = getNextLastSelectedDart(1);
247 
248  if (last == NULL)
249  return false;
250 
251  CDart* d1;
252  CDart* d2;
253 
254  int nb = FMap->getMarkedCells(ORBIT_VERTEX, sel, last, &d1, &d2);
255 
256  if (nb != 1 && nb != 2)
257  return false;
258 
259  if (nb == 1)
260  {
261  if (FMap->isFree1(last))
262  return false;
263 
264  d2 = FMap->alpha0(d1);
265  }
266 
267  // Axe definition
268  AResult = * FMap->findVertex(d1) - * FMap->findVertex(d2);
269  return true;
270 }
271 //******************************************************************************
273 { FDeselectMode = true; }
274 //------------------------------------------------------------------------------
276 { return FDeselectMode; }
277 //******************************************************************************
279 {
281 
282  if (view != NULL && FFirstX != FLastX && FFirstY != FLastY)
283  {
284  CDart * dart;
285  float screen1[3], screen2[3];
286  int xmin, ymin, xmax, ymax;
287  CVertex v1, v2;
288 
289  if (FFirstX < FLastX){ xmin = FFirstX; xmax = FLastX; }
290  else { xmin = FLastX; xmax = FFirstX; }
291  if (FFirstY < FLastY){ ymin = FFirstY; ymax = FLastY; }
292  else { ymin = FLastY; ymax = FFirstY; }
293 
294  // Pointeur vers fonction membre pour éviter de faire le
295  // meme test plein de fois dans la boucle.
296  void (CControlerGMap::*f)(CDart*);
298  else f = &CControlerGMap::selectDart;
299 
300  // Parcours des brins
301  for (CDynamicCoverageAll coverage(FMap); coverage.cont(); ++coverage)
302  {
303  dart = *coverage;
304 
305  v1 = FMap -> getBurstVertex(dart);
306  view -> project(v1.getX(), v1.getY(), v1.getZ(), screen1);
307 
308  if (screen1[0] >= xmin && screen1[1] >= ymin &&
309  screen1[0] <= xmax && screen1[1] <= ymax)
310  (this->*f)(dart);
311  else
312  {
313  v2 = FMap -> computeBurstExtremity(dart);
314  view -> project(v2.getX(), v2.getY(), v2.getZ(), screen2);
315 
316  if (screen2[0] >= xmin && screen2[1] >= ymin &&
317  screen2[0] <= xmax && screen2[1] <= ymax)
318  (this->*f)(dart);
319  }
320  }
321  }
322  FDeselectMode = false;
323 }
324 //******************************************************************************