Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operations-extrusion.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 {
33  bool res = false;
35  {
37 
38  float coef = getParameterOperations()->getExtrusionCoef();
39 
40  int nb = FMap->thickenMarkedDarts(getSelectionMark(), coef);
41 
42  if (nb==0)
43  {
44  setMessage("No object to thicken");
46  }
47  else
48  {
51  setMessage(nb, nb==1 ? " dart thicken" : " darts thicken");
52  res = true;
53  }
54  }
55 
56  return res;
57 }
58 //******************************************************************************
60 {
61  bool res = false;
64  {
66 
67  float coef = getParameterOperations()->getExtrusionCoef();
68 
69  int nb =
70  FMap->extrudeByNormalMarkedCells(getSelectionMark(), ADim,
72  ->getExtrusionAdjacentSews(),
73  coef);
74 
75  if (nb==0)
76  {
77  setMessage("No extrusion possible");
79  }
80  else
81  {
83 
84  switch (ADim)
85  {
86  case 0:
87  setMessage(nb, nb==1? " vertex extruded": " vertices extruded");
88  break;
89  case 1:
90  setMessage(nb, nb==1? " edge extruded" : " edges extruded");
91  break;
92  case 2:
93  setMessage(nb, nb==1? " face extruded" : " faces extruded" );
94  break;
95  }
96 
98  res = true;
99  }
100  }
101 
102  return res;
103 }
104 //******************************************************************************
106 {
107  bool res = false;
110  {
111  undoRedoPreSave();
112 
113  float coef = getParameterOperations()->getExtrusionCoef();
114 
115  int nb =
116  FMap->intuitiveExtrudeByNormalMarkedCells(getSelectionMark(),
118  ->getExtrusionAdjacentSews(),
119  coef);
120 
121  if (nb==0)
122  {
123  setMessage("No extrusion possible");
125  }
126  else
127  {
129 
130  setModelChanged();
131  setMessage(nb, nb==1 ? " cell extruded" : " cells extruded" );
132  res = true;
133  }
134  }
135 
136  return res;
137 }
138 //******************************************************************************
140 {
141  bool res = false;
142 
145  {
146  CDart * pathStart = getNextLastSelectedDart(1);
147  CDart * pathPonderation = NULL;
148 
149  bool ok = true;
150 
151  if (getParameterOperations()->getExtrusionPonderateSection())
152  {
153  CDart * last2 = getNextLastSelectedDart(2);
154 
155  int n = FMap->getMarkedCells(ORBIT_SELF, getNextSelectionMark(2),
156  last2, &pathPonderation);
157 
158  if (last2==NULL && n>1)
159  {
160  ok = false;
161  setMessage("Extrusion impossible: "
162  "ambiguity on the ponderation path");
163  }
164 
165  if (ok && pathPonderation!=NULL &&
166  FMap->isClosedPolyline(pathPonderation))
167  {
168  ok = false;
169  setMessage("Extrusion impossible: "
170  "the ponderation path is closed");
171  }
172  }
173 
174  if (ok)
175  {
176  if (pathStart==NULL &&
177  FMap->getMarkedCells(ORBIT_SELF, getNextSelectionMark(1),
178  NULL, &pathStart) != 1)
179  setMessage("Extrusion impossible: no path selected");
180  else
181  {
182  undoRedoPreSave();
183 
184  int nb =
185  FMap->extrudeByPathMarkedCells(getSelectionMark(), ADim, pathStart,
187  getExtrusionAdjacentSews(),
189  getExtrusionInitialPositionMode(),
191  getExtrusionInitialDirectionMode(),
193  getExtrusionDirection(),
195  getExtrusionScale(),
196  pathPonderation);
197 
198  if (nb==0)
199  {
200  setMessage("No extrusion done");
202  }
203  else
204  {
206 
207  switch (ADim)
208  {
209  case 1:
210  setMessage(nb, nb==1 ? " edge extruded" :
211  " edges extruded");
212  break;
213  case 2:
214  setMessage(nb, nb==1 ? " face extruded" :
215  " faces extruded" );
216  break;
217  }
218 
219  setModelChanged();
220  res = true;
221  }
222  }
223  }
224  }
225 
226  return res;
227 }
228 //******************************************************************************
230 {
231  bool res = false;
234  {
235  bool ok = true;
236 
237  CDart * d1, * d2; // axe
238  CDart * pathPonderation = NULL;
239 
240  int found = FMap->getMarkedCells(ORBIT_VERTEX, getNextSelectionMark(1),
241  getNextLastSelectedDart(1), &d2,&d1);
242 
243  if (found!=2 && (found!=1 || FMap->isFree0(d2)))
244  {
245  setMessage("Selection of the axis not correct: we need two darts");
246  ok = false;
247  }
248 
249  if (ok && d1==NULL)
250  {
251  assert(d2!=NULL);
252  assert(!FMap->isFree0(d2));
253  d1 = FMap->alpha0(d2);
254  }
255 
256  CVertex axeVertex, axeDirection;
257 
258  if (ok)
259  {
260  axeVertex = * FMap->findVertex(d1);
261  axeDirection = * FMap->findVertex(d2) - axeVertex;
262 
263  if (axeDirection.isNull())
264  {
265  setMessage("Extrusion impossible: axis of length zero");
266  ok = false;
267  }
268  }
269 
270  if (ok && getParameterOperations()->getExtrusionPonderateSection())
271  {
272  CDart * last2 = getNextLastSelectedDart(2);
273 
274  int n = FMap->getMarkedCells(ORBIT_SELF, getNextSelectionMark(2),
275  last2, &pathPonderation);
276 
277  if (last2==NULL && n>1)
278  {
279  ok = false;
280  setMessage("Extrusion impossible: "
281  "ambiguity on the ponderation path");
282  }
283 
284  if (ok && pathPonderation!=NULL &&
285  FMap->isClosedPolyline(pathPonderation))
286  {
287  ok = false;
288  setMessage("Extrusion impossible: "
289  "the ponderation path is closed");
290  }
291  }
292 
293  if (ok)
294  {
295  undoRedoPreSave();
296 
297  float angle =
299 
300  int nb =
301  FMap->extrudeByRevolutionMarkedCells(getSelectionMark(),
302  ADim, axeVertex, axeDirection,
303  angle,
305  getExtrusionRevolutionNbEdges(),
307  getExtrusionAdjacentSews(),
309  getExtrusionInitialPositionMode(),
311  getExtrusionInitialDirectionMode(),
313  getExtrusionDirection(),
315  getExtrusionScale(),
316  pathPonderation);
317 
318  if (nb==0)
319  {
320  setMessage("No extrusion done");
322  }
323  else
324  {
326 
327  switch (ADim)
328  {
329  case 1:
330  setMessage(nb, nb==1
331  ? " edge extruded" : " edges extruded");
332  break;
333  case 2:
334  setMessage(nb, nb==1
335  ? " face extruded" : " faces extruded" );
336  break;
337  }
338 
339  setModelChanged();
340  res = true;
341  }
342  }
343  }
344 
345  return res;
346 }
347 //******************************************************************************