Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operations-sew-unsew.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 
29 using namespace GMap3d;
30 //******************************************************************************
32 {
35  {
36  CDart * dart1, * dart2;
37 
38  if (getDartsForSew(& dart1, & dart2))
39  {
40  int dim = FMap->getSewDimension(dart1, dart2);
41  if (dim!=4)
42  {
44  FMap->sew(dart1, dart2, dim);
47 
49  setMessage("Intuitive sew done");
50  return true;
51  }
52  }
53  }
54 
55  return false;
56 }
57 //******************************************************************************
58 bool CControlerGMap::topoSew(int ADimension)
59 {
60  assert(0 <= ADimension && ADimension <= 3);
61 
63  ADimension)))
64  {
65  CDart * dart1, * dart2;
66 
67  if (getDartsForSew(& dart1, & dart2))
68  {
69  if (FMap->canSew(dart1, dart2, ADimension))
70  {
72  FMap->sew(dart1, dart2, ADimension);
75 
77  setMessage("Sew done");
78  return true;
79  }
80  }
81  }
82 
83  return false;
84 }
85 //******************************************************************************
87 {
90  {
91  CDart * dart1, * dart2;
92 
93  if (getDartsForSew(& dart1, & dart2))
94  {
95  int dim = FMap->getSewDimension(dart1, dart2);
96  if (dim!=4)
97  {
99  FMap->geoSew(dart1, dart2, dim,
100  getParameterOperations()->getRotateCells(),
101  getParameterOperations()->getScaleCells(),
102  getParameterOperations()->getTranslateCells());
105 
106  setModelChanged();
107  setMessage("Intuitive sew with plating done");
108  return true;
109  }
110  }
111  }
112 
113  return false;
114 }
115 //******************************************************************************
116 bool CControlerGMap::geoSew(int ADimension)
117 {
118  assert(0 < ADimension && ADimension <= 3); // ADimension != 0
119 
121  ADimension)))
122  {
123  CDart * dart1, * dart2;
124 
125  if (getDartsForSew(& dart1, & dart2))
126  {
127  if (FMap->canSew(dart1, dart2, ADimension))
128  {
129  undoRedoPreSave();
130  FMap->geoSew(dart1, dart2, ADimension,
131  getParameterOperations()->getRotateCells(),
132  getParameterOperations()->getScaleCells(),
133  getParameterOperations()->getTranslateCells());
136 
137  setModelChanged();
138  setMessage("Sew with plating done");
139  return true;
140  }
141  }
142  }
143 
144  return false;
145 }
146 //******************************************************************************
148 {
149  bool res = false;
150 
153  {
154  undoRedoPreSave();
155 
156  int nb = FMap->intuitiveUnsewMarkedCells(getSelectionMark());
157 
158  if (nb==0)
159  {
160  setMessage("No unsew done");
162  }
163  else
164  {
166 
167  setModelChanged();
168  res = true;
169  setMessage(nb, (nb==1 ? " intuitive unsew done" :
170  " intuitive unsews done"));
171  }
172  }
173 
174  return res;
175 }
176 //******************************************************************************
177 bool CControlerGMap::unsew(int ADimension)
178 {
179  assert(ADimension>=0 && ADimension<=3);
180 
181  bool res = false;
182 
184  ADimension)))
185  {
186  undoRedoPreSave();
187 
188  int nb = FMap->unsewMarkedCells(getSelectionMark(), ADimension);
189 
190  if (nb==0)
191  {
192  setMessage("No unsew done");
194  }
195  else
196  {
198 
199  setModelChanged();
200  res = true;
201  setMessage(nb, (nb==1 ? " unsew done" :
202  " unsews done"));
203  }
204  }
205 
206  return res;
207 }
208 //******************************************************************************
210  // Invertion de la dernière opération lorsque cela est possible. Par exemple
211  // si on vient de 2-coudre(d1,d2), alors découd et 2-coud(d1,alpha0(d2))
212 {
214  return false;
215 
218  {
219  setMessage("Last operation not reversible");
220  return false;
221  }
222 
223  COperation toReevaluate(FLastOperation);
224  basicUndo();
225  CDart *d1, *d2;
226 
227  if (FMap->getMarkedCells(ORBIT_SELF, getSelectionMark(),
228  getLastSelectedDart(), &d2,&d1) != 2)
229  {
230  setMessage("Selection not correct [???]");
231  basicRedo();
232  return false;
233  }
234 
235  deselectDart(d2);
236  selectDart(FMap->alpha0(d2));
237 
238  if (!applyOperation(toReevaluate))
239  {
240  setMessage("Not possible to revert the last operation");
241  return false;
242  }
243 
244  setMessage("Last operation reversed");
245  return true;
246 }
247 //******************************************************************************
249  // Ici on inverse la géométrie, c'est à dire l'ordre des paramètre.
250 {
252  return false;
253 
256  {
257  setMessage("Last operation not reversible");
258  return false;
259  }
260 
261  COperation toReevaluate(FLastOperation);
262  basicUndo();
263  CDart *d1, *d2;
264 
265  if (FMap->getMarkedCells(ORBIT_SELF, getSelectionMark(),
266  getLastSelectedDart(), &d2,&d1) != 2)
267  {
268  setMessage("Selection not correct [???]");
269  basicRedo();
270  return false;
271  }
272 
273  selectDart(d1);
274 
275  if (!applyOperation(toReevaluate))
276  {
277  setMessage("Not possible to revert the last operation");
278  return false;
279  }
280 
281  setMessage("Last operation reversed");
282  return true;
283 }
284 //******************************************************************************
285 bool CControlerGMap::topoSewBorders(int ADimension)
286 {
287  assert( ADimension==1 || ADimension==2 );
288 
290  ADimension)))
291  {
292  CDart *d1, *d2;
293 
294  if (FMap->getMarkedCells(ORBIT_SELF, getSelectionMark(),
295  getLastSelectedDart(), &d2,&d1) != 2)
296  {
297  setMessage("Selection not correct: you need two darts");
298  return false;
299  }
300 
301  if (FMap->getBorderDimension(d1)!=ADimension ||
302  !FMap->canSewBorders(d1,d2, ADimension))
303  {
304  setMessage("Borders not possible to sew");
305  return false;
306  }
307 
308  undoRedoPreSave();
309  FMap->intuitiveBorderSew(d1,d2);
312 
313  setModelChanged();
314  setMessage("Borders sewn");
315  return true;
316  }
317 
318  return false;
319 }
320 //******************************************************************************
321 bool CControlerGMap::geoSewBorders(int ADimension)
322 {
323  assert( ADimension==1 || ADimension==2 );
324 
326  ADimension)))
327  {
328  CDart *d1, *d2;
329 
330  if (FMap->getMarkedCells(ORBIT_SELF, getSelectionMark(),
331  getLastSelectedDart(), &d2,&d1) != 2)
332  {
333  setMessage("Selection not correct");
334  return false;
335  }
336 
337  if (FMap->getBorderDimension(d1)!=ADimension ||
338  !FMap->canSewBorders(d1,d2, ADimension))
339  {
340  setMessage("Borders impossible to sew");
341  return false;
342  }
343 
344  undoRedoPreSave();
345  FMap->intuitiveGeoBorderSew(d1,d2,
346  getParameterOperations()->getRotateCells(),
347  getParameterOperations()->getScaleCells(),
348  getParameterOperations()->getTranslateCells());
351 
352  setModelChanged();
353  setMessage("Borders sewn");
354  return true;
355  }
356 
357  return false;
358 }
359 //******************************************************************************