Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
operations-creation.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 using namespace std;
31 //******************************************************************************
33 {
34  switch (getMode())
35  {
36  case MODE_CREATION_POLYLINE: return createPolyline (); break;
37  case MODE_CREATION_POLYGON : return createPolygon (); break;
38  case MODE_CREATION_MESH : return createMesh (); break;
39  case MODE_CREATION_SPHERE : return createSphere (); break;
40  case MODE_CREATION_CYLINDER: return createCylinder (); break;
41  case MODE_CREATION_PYRAMID : return createPyramid (); break;
42  case MODE_CREATION_TORUS : return createTorus (); break;
43  }
44  return false;
45 }
46 //******************************************************************************
48 {
51  FParameterPolylinePosition->getNbVertices()==0 )
52  return false;
53 
55  FMap->createPolyline(FParameterPolylinePosition->getVertices());
57 
59  setMessage("Polyline created");
60  return true;
61 }
62 //******************************************************************************
64 {
67  return false;
68 
69  CTransformationMatrix matrix =
70  FParameterObjectPosition[OBJECT_POLYGON]->getTransformationMatrix();
71 
73 
75  FMap->applyMatrix(matrix, FMap->createRegularPolygon(n), ORBIT_CC);
77 
79  setMessage("Polygone created");
80  return true;
81 }
82 //******************************************************************************
84 {
87  return false;
88 
89  CTransformationMatrix matrix =
90  FParameterObjectPosition[OBJECT_MESH]->getTransformationMatrix();
91 
95 
97 
98  CDart * handle1, * handle2;
99 
100  undoRedoPreSave();
101 
102  switch (getParameterCreation()->getMeshDimension())
103  {
104  case 1:
105  handle1 = FMap->createMesh1(SD==0 ? 1 : SX);
106  FMap->applyMatrix(matrix, handle1, ORBIT_CC);
107 
108  switch (SD)
109  {
110  case 0: setMessage("Edge created"); break;
111  case 1: setMessage("Edge meshed created"); break;
112  default: return false;
113  }
114 
115  break;
116 
117  case 2:
118  handle1 = FMap->createSquareIMeshed(SX, SY, SD);
119  FMap->applyMatrix(matrix, handle1, ORBIT_CC);
120 
121  switch (SD)
122  {
123  case 0: setMessage("Square created"); break;
124  case 1: setMessage("Square 1-meshed created"); break;
125  case 2: setMessage("Square 2-meshed created"); break;
126  default: return false;
127  }
128 
129  break;
130 
131  case 3:
132  if (SD==3)
133  {
134  handle1 = FMap->createMesh3(SX, SY, SZ);
135  handle2 = NULL;
136  setMessage("Cube 3-meshed created");
137  }
138  else
139  {
140  unsigned char F = getParameterCreation()->getMeshCreatedFaces();
141 
142  bool created[3][2] =
143  {
144  { F & CUBE_X1, F & CUBE_X2 },
145  { F & CUBE_Y1, F & CUBE_Y2 },
146  { F & CUBE_Z1, F & CUBE_Z2 }
147  };
148 
149  FMap->createCubeIMeshed(SX,SY,SZ, SD, created, & handle1, & handle2);
150 
151  switch (SD)
152  {
153  case 0: setMessage("Cube created"); break;
154  case 1: setMessage("Cube 1-meshed created"); break;
155  case 2: setMessage("Cube 2-meshed created"); break;
156  default: return false;
157  }
158  }
159 
160  FMap->applyMatrix(matrix, handle1, ORBIT_CC);
161 
162  if (handle2 != NULL)
163  FMap->applyMatrix(matrix, handle2, ORBIT_CC);
164 
165  break;
166 
167  default: return false;
168  }
169 
171  setModelChanged();
172  return true;
173 }
174 //******************************************************************************
176 {
179  return false;
180 
181  CTransformationMatrix matrix =
182  FParameterObjectPosition[OBJECT_CYLINDER]->getTransformationMatrix();
183 
188 
189  undoRedoPreSave();
190  FMap->applyMatrix(matrix, FMap->createCylinder(M, P, C1, C2), ORBIT_CC);
192 
193  setModelChanged();
194  setMessage("Cylindre created");
195  return true;
196 }
197 //******************************************************************************
199 {
202  return false;
203 
204  CTransformationMatrix matrix =
205  FParameterObjectPosition[OBJECT_PYRAMID]->getTransformationMatrix();
206 
210 
211  undoRedoPreSave();
212  FMap->applyMatrix(matrix, FMap->createPyramid(M, P, C), ORBIT_CC);
214 
215  setModelChanged();
216  setMessage("Pyramide created");
217  return true;
218 }
219 //******************************************************************************
221 {
224  return false;
225 
226  CTransformationMatrix matrix =
227  FParameterObjectPosition[OBJECT_SPHERE]->getTransformationMatrix();
228 
231 
232  undoRedoPreSave();
233  FMap->applyMatrix(matrix, FMap->createSphere(M, P), ORBIT_CC);
235 
236  setModelChanged();
237  setMessage("Sphere created");
238  return true;
239 }
240 //******************************************************************************
242 {
245  return false;
246 
247  CTransformationMatrix matrix =
248  FParameterObjectPosition[OBJECT_TORUS]->getTransformationMatrix();
249 
253 
254  undoRedoPreSave();
255  FMap->applyMatrix(matrix, FMap->createTorus(M, P, R), ORBIT_CC);
257 
258  setModelChanged();
259  setMessage("Torus created");
260  return true;
261 }
262 //******************************************************************************
264 {
265  return FParameterObjectPosition[OBJECT_POLYGON]->getScale()
266  *dSin(180.0/FParameterCreation->getPolygonNbEdges());
267 }
268 //------------------------------------------------------------------------------
270 {
271  // getEdgesNumber()>3 => dSin != 0
272  CParameterObjectPosition* param = FParameterObjectPosition[OBJECT_POLYGON];
273 
274  TCoordinate s = AValue/dSin(180.0/FParameterCreation->getPolygonNbEdges());
275  param->setScale(s);
276  param->setDimensions(2*s*param->getProportions());
277 }
278 //------------------------------------------------------------------------------
280 {
281  FParameterCreation->setPolygonNbEdges(AValue);
282  setPolygonEdgesLength(FParameterObjectPosition[OBJECT_POLYGON]->getScale()*
283  dSin(180.0/AValue));
284 }
285 //******************************************************************************
287 {
288  FMap->randomizeDarts();
289  setMessage("Order of darts was randomized");
290  return true;
291 }
292 //******************************************************************************