Moka controlers
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
controler-gmap-protected-methods.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 "precompile.hh"
27 #include "view-precompile.hh"
28 #include "g-map-vertex.hh"
29 #include "parameter-selection.hh"
30 #include "math-extension.hh"
31 
32 #include "precompile-dart.hh"
33 #include "precompile-face.hh"
34 #include "precompile-preview.hh"
37 #include "precompile-sew.hh"
38 #include "precompile-vertex.hh"
39 #ifdef MODULE_SPAMOD
40 #include "precompile-spamod.hh"
41 #endif // MODULE_SPAMOD
42 
43 #include <cassert>
44 #include <string>
45 using namespace std;
46 using namespace GMap3d;
47 //******************************************************************************
49 {
50  if ( !FMap->checkTopology() )
51  return false;
52 
53  if ( !FMap->checkEmbeddings(ORBIT_VERTEX, ATTRIBUTE_VERTEX, true) )
54  return false;
55 
56  return true;
57 }
58 //******************************************************************************
60 {
61  assert( getParameterGMapVertex()!=NULL );
63 }
64 //------------------------------------------------------------------------------
66 {
67  assert( getParameterGMapVertex()!=NULL );
70 }
71 //------------------------------------------------------------------------------
73 {
74  assert( getParameterGMapVertex()!=NULL );
77 }
78 //******************************************************************************
80 {
81  assert( getParameterGMapVertex()!=NULL );
83 }
84 //------------------------------------------------------------------------------
86 {
87  assert( getParameterGMapVertex()!=NULL );
89 }
90 //------------------------------------------------------------------------------
92 {
93  assert( getParameterGMapVertex()!=NULL );
95 }
96 //******************************************************************************
98 {
99  // Recalculer les coordonnées éclatées ssi la carte à changé
100  // et si on n'est pas bloqué.
101  if ( isModelBlocked() ) return;
102 
104 
105  if ( isModelChanged() )
106  {
107  FMap->updateAllBurstDarts();
108  if ( FParameterGMapVertex->getMapEmbedding()!=NULL )
109  FParameterGMapVertex->getMapEmbedding()->updateAllBurstDarts();
110 
112  }
113  else if ( isPartialModelChanged() )
114  {
115  if ( getParameterGMapVertex()->getMarkPartialChanged()!=-1 )
116  FMap->updateMarkedBurstDarts(getParameterGMapVertex()->
117  getMarkPartialChanged(),
118  false);
119  else
120  FMap->updateAllBurstDarts();
121 
123  }
124 }
125 //******************************************************************************
127 {
128  assert( getParameterSelection()!=NULL );
129  return getParameterSelection()->getChanged();
130 }
131 //------------------------------------------------------------------------------
133 {
134  assert( getParameterSelection()!=NULL );
136 }
137 //------------------------------------------------------------------------------
139 {
140  assert( getParameterSelection()!=NULL );
142 }
143 //******************************************************************************
145 {
146  /* Recalculer si besoin est les caractéristiques de la carte : nb de brins,
147  * de sommets, de brins sélectionnés.
148  */
149  if ( isSelectionChanged() )
150  {
151  int nbLevels = getNbSelectionLevels();
152  bool* validLast=new bool[nbLevels];
153  // bool validLast[nbLevels]; marche pas sous VC++ !!!
154 
155  for (int i=0; i<nbLevels; ++i)
156  validLast[i] = false;
157 
158  FNbDarts = 0;
159  FNbSelectedDarts = 0;
160  FNbVertices = 0;
161 
162  for (CDynamicCoverageAll it(FMap); it.cont(); ++it)
163  {
164  ++FNbDarts;
165 
166  if (isDartSelected(*it)) ++FNbSelectedDarts;
167 
168  if (FMap->getVertex(*it)!=NULL) ++FNbVertices;
169 
170  for (int j=0; j<nbLevels; ++j)
171  if (*it == getLastSelectedDart(j))
172  validLast[j] = true;
173  }
174 
175  for (int k=0; k<nbLevels; ++k)
176  if (!validLast[k])
178 
180 
181  delete []validLast;
182  }
183 }
184 //******************************************************************************
186  TPrecompile APrecompileType)
187 {
188  CPrecompile* precompile = NULL;
189  int n;
190 
191  switch (APrecompileType)
192  {
193  case PRECOMPILE_DART:
194  n = FParameterSelection->getNbSelectionLevels();
195  precompile =
196  new CPrecompileDart(FParameterGMapVertex, new CParameterDart(n),
197  FParameterSelection);
198  break;
199  case PRECOMPILE_FACE:
200  precompile = new CPrecompileFace(FParameterGMapVertex,
201  new CParameterFace);
202  break;
204  precompile = new CPrecompileNormalVector(FParameterGMapVertex,
206  FParameterSelection);
207  break;
209  precompile =
211  FParameterTranslation,
212  FParameterRotation,
213  FParameterScale,
214  FParameterPonderation);
215  break;
216  case PRECOMPILE_PREVIEW:
217  precompile = new CPrecompilePreview(new CParameterPreview,
218  FParameterObjectPosition[0],
219  FParameterCreation,
220  FParameterPolylinePosition);
221  break;
222  case PRECOMPILE_SEW:
223  precompile = new CPrecompileSew(FParameterGMapVertex,
224  new CParameterSew);
225  break;
226 #ifdef MODULE_SPAMOD
227  case PRECOMPILE_SPAMOD:
228  precompile = new CPrecompileSpamod(FParameterGMapVertex,
229  new CParameterSpamod);
230  break;
231 #endif // MODULE_SPAMOD
232  case PRECOMPILE_VERTEX:
233  precompile = new CPrecompileVertex(FParameterGMapVertex,
234  new CParameterVertex);
235  break;
236  default:
237  precompile = CControler::newPrecompile(AViewId, APrecompileType);
238  break;
239  }
240 
241  return precompile;
242 }
243 //******************************************************************************
244 bool CControlerGMap::getDartsForSew(CDart** ADart1, CDart** ADart2)
245 {
246  assert(ADart1 != NULL);
247  assert(ADart2 != NULL);
248 
249  CDart* last = getLastSelectedDart();
250  int mark = getSelectionMark();
251 
252  if (last == NULL ||
253  FMap->getMarkedCells(ORBIT_SELF, mark, last, ADart2, ADart1) != 2)
254  {
255  setMessage("No correct selection: you need two darts");
256  return false;
257  }
258 
259  return true;
260 }
261 //******************************************************************************