Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operations-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 "g-map-vertex.hh"
26 #include "controler-gmap.hh"
27 #include <cassert>
28 #include <sstream>
29 
30 using namespace GMap3d;
31 //******************************************************************************
32 void CControlerGMap::setSelectionLevel(int ALevel)
33 {
34  assert(0 <= ALevel && ALevel < getNbSelectionLevels());
35 
36  if (ALevel != getSelectionLevel() &&
39  {
40  FParameterSelection->setSelectionLevel(ALevel);
41 
42  std::stringstream s;
43  s<<"Selection level number: "<<ALevel + 1;
45  setMessage(s.str());
46  }
47 }
48 //******************************************************************************
50 {
52 }
53 //******************************************************************************
55 {
58  {
59  FMap->unmarkAll(getSelectionMark());
62  setMessage("Darts unmarked");
63  return true;
64  }
65 
66  return false;
67 }
68 //******************************************************************************
70 {
73  {
74  int mark = getSelectionMark();
75 
76  FMap->negateMaskMark(mark);
77 
78  CDart* last = getLastSelectedDart();
79  if (last != NULL)
81 
83  setMessage("Marked darts negated");
84  return true;
85  }
86 
87  return false;
88 }
89 //******************************************************************************
90 bool CControlerGMap::swapSelectionLevels(int ALevel1, int ALevel2)
91 {
94  {
95  // TEMPORAIRE POUR NE PAS AVOIR A SAUVER LES NUMEROS DES MARQUES
96  // CE QU'IL FAUDRAIT FAIRE ENSUITE POUR LE UNDO
97  int mark1 = getSelectionMark(ALevel1);
98  int mark2 = getSelectionMark(ALevel2);
99  CDynamicCoverageAll it(FMap);
100  while (it.cont())
101  {
102  bool t = FMap->isMarked(*it, mark1);
103  FMap->setMarkTo(*it, mark1, FMap->isMarked(*it, mark2));
104  FMap->setMarkTo(*it, mark2, t);
105  ++it;
106  }
107 
108  // FIN TEMPO
109  FParameterSelection->swapLevels(ALevel1, ALevel2);
111 
112  std::stringstream s;
113  s<<"Swap selection levels "<<ALevel1<<" and "<<ALevel2;
114  setMessage(s.str());
115  return true;
116  }
117 
118  return false;
119 }
120 //******************************************************************************
122 {
124 }
125 //******************************************************************************
127 {
130  {
131  FMap->markIncidentCells(getSelectionOrbit(), getSelectionMark());
132  setMessage("Incident cells marked");
134  return true;
135  }
136 
137  return false;
138 }
139 //******************************************************************************
140 bool CControlerGMap::selectBorders(int ADimension)
141 {
142  assert(0 <= ADimension && ADimension <= 3);
143 
145  SUB_OPERATION_BORDERS, ADimension)))
146  {
147  if (FMap->markBorders(getSelectionMark(), ADimension))
148  {
150  setMessage(ADimension,
151  "-borders incident to selected darts marked");
152  return true;
153  }
154  else
155  {
156  setMessage("No border marked");
157  return false;
158  }
159  }
160 
161  return false;
162 }
163 //******************************************************************************
165 {
167  SUB_OPERATION_BORDERS, -1)))
168  {
169  if (FMap->markBorders(getSelectionMark()))
170  {
172  setMessage("Borders incident to selected darts marked");
173  return true;
174  }
175  else
176  {
177  setMessage("No border marked");
178  return false;
179  }
180  }
181 
182  return false;
183 }
184 //******************************************************************************
186 {
189  -1)))
190  {
191  if (FMap->markNonPlanarPolylines(getSelectionMark()))
192  {
193  setMessage("Non-planar faces marked");
195  return true;
196  }
197  else
198  {
199  setMessage("There is no non-planar face");
200  return false;
201  }
202  }
203 
204  return false;
205 }
206 //******************************************************************************
207 bool CControlerGMap::markInterior(int ADimension)
208 {
211  ADimension)))
212  {
213  if (getLastSelectedDart() == NULL)
214  {
215  setMessage("A 'last' dart must be selected");
216  return false;
217  }
218 
219  FMap->markInterior(getLastSelectedDart(),
220  ADimension, getSelectionMark());
221 
223  setMessage("Interior marked");
224  return true;
225  }
226 
227  return false;
228 }
229 //******************************************************************************
230 bool CControlerGMap::markIntersection(int AInitialDim, int AFinalDim)
231 {
234  {
235  if (!((1 <= AInitialDim && AInitialDim <= 3) &&
236  (0 <= AFinalDim && AFinalDim <= 2) &&
237  (AInitialDim != AFinalDim)))
238  {
239  setMessage("Selection of the intersection not possible");
240  return false;
241  }
242 
243  int mark1 = getSelectionMark();
244  int mark2 = getNextSelectionMark(1);
245  int markR = FMap->getNewMark();
246 
247  TOrbit orbit1 = ORBIT_CELL[AInitialDim];
248  TOrbit orbit2 = ORBIT_CELL[AFinalDim ];
249 
250  undoRedoPreSave();
251  FMap->markIntersection(mark1, mark2, orbit1, orbit2, markR, true);
252  FMap->markCopy(markR, mark1);
254 
256  setMessage("Intersection selected");
257  return true;
258  }
259 
260  return false;
261 }
262 //******************************************************************************
263 bool CControlerGMap::findMotifOff(const char* AFilename)
264 {
266  {
267  CGMapVertex motif;
268  if (!motif.importOff(AFilename))
269  {
270  setMessage("Error to import the Off file");
271  return false;
272  }
273  undoRedoPreSave();
274  int index = motif.findMotif(FMap);
276 
277  if (index == -1)
278  setMessage("Motif not founded in the current map");
279  else
280  {
281  setMessage("Motif founded");
282  for (CDynamicCoverageAll it(&motif); it.cont(); ++it)
283  {
284  assert(motif.getDirectInfo(*it, index) != NULL);
285  FMap->setMark(motif.getDirectInfoAsDart(*it, index),
286  getSelectionMark());
287  }
288  motif.freeDirectInfo(index);
290  }
291  return true;
292  }
293  return false;
294 }
295 //******************************************************************************
296 bool CControlerGMap::findMotifMoka(const char* AFilename)
297 {
299  {
300  CGMapVertex motif;
301  TSaveFormat format = CGMapVertex::getFileFormat(AFilename);
302  if (motif.load(AFilename, format)==NULL)
303  {
304  setMessage("Error to load the file");
305  return false;
306  }
307  undoRedoPreSave();
308  int index = motif.findMotif(FMap);
310 
311  if (index == -1)
312  setMessage("Motif not founded in the current map");
313  else
314  {
315  setMessage("Motif founded");
316  for (CDynamicCoverageAll it(&motif); it.cont(); ++it)
317  {
318  assert(motif.getDirectInfo(*it, index) != NULL);
319  FMap->setMark(motif.getDirectInfoAsDart(*it, index),
320  getSelectionMark());
321  }
322  motif.freeDirectInfo(index);
324  }
325  return true;
326  }
327  return false;
328 }
329 //******************************************************************************
330 bool CControlerGMap::countNumberOfMotifsMoka(const char* AFilename)
331 {
333  {
334  CGMapVertex motif;
335  TSaveFormat format = CGMapVertex::getFileFormat(AFilename);
336  if (motif.load(AFilename, format)==NULL)
337  {
338  setMessage("Error to load the file");
339  return false;
340  }
341  undoRedoPreSave();
342  unsigned int res = motif.countNumberOfMotifs(FMap);
344 
345  if (res == 0)
346  setMessage("Motif not founded in the current map");
347  else
348  {
349  setMessage("Motif founded ", res, (res>1?"times":"time"));
350  }
351  return true;
352  }
353  return false;
354 }
355 //******************************************************************************
356 bool CControlerGMap::countNumberOfMotifsOff(const char* AFilename)
357 {
359  {
360  CGMapVertex motif;
361  if (!motif.importOff(AFilename))
362  {
363  setMessage("Error to import the Off file");
364  return false;
365  }
366  undoRedoPreSave();
367  unsigned int res = motif.countNumberOfMotifs(FMap);
369 
370  if (res == 0)
371  setMessage("Motif not founded in the current map");
372  else
373  {
374  setMessage("Motif founded ", res, (res>1?"times":"time"));
375  }
376  return true;
377  }
378  return false;
379 }
380 //******************************************************************************