Moka Ihm Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
creation-maillage.qt.cc
Go to the documentation of this file.
1 /*
2  * Moka : Un modeleur de 3-G-cartes.
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 Moka
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU 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 General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "creation-maillage.qt.hh"
25 #include "window.qt.hh"
26 #include "HtmlEntities.hh"
27 #include "SpaceWidget.qt.hh"
28 
29 #include <QtGui/QLabel>
30 #include <QtGui/QHBoxLayout>
31 #include <QtGui/QVBoxLayout>
32 
33 
34 /*******************************************************************/
35 /* CLASSE creationMaillage */
36 /*******************************************************************/
37 
38 // Constructeur
39 //-------------
40 
42  GMap3d :: CControlerGMap * controler) :
43  CreationObjet(parent , HTML::decode("Create Mesh") ,
44  controler),
45  FModifie(true)
46 {
47 
48  //--------- Partie haute -------------
49  QWidget * haut = new QWidget ;
50  QHBoxLayout * bb = new QHBoxLayout(haut);
51  bb -> setSpacing(0);
52  bb -> setContentsMargins(0, 0, 0, 0);
53 
54  FAffCel =
55  new QLabel(*HTML::decode
56  (" Dimension of the cell to create: ")) ;
57 
58  FDimCell = new QComboBox ;
59  FDimCell -> addItem(*HTML::decode("1 (edge/polyline)")) ;
60  FDimCell -> addItem("2 (face/grid)") ;
61  FDimCell -> addItem("3 (mesh/3D volume)") ;
62 
63  FAffMai = new QLabel("Mesh dimension: ") ;
64 
65  FDimMail = new QComboBox ;
66  FDimMail -> addItem("0 (no mesh)") ;
67  FDimMail -> addItem(*HTML::decode("1 (edge mesh)")) ;
68  FDimMail -> addItem("2 (face mesh)") ;
69  FDimMail -> addItem("3 (volume mesh)") ;
70 
71  QObject :: connect(FDimCell , SIGNAL(activated(int)) , this ,
72  SLOT(callbackDimCell())) ;
73  QObject :: connect(FDimMail , SIGNAL(activated(int)) , this ,
74  SLOT(callbackDimMesh())) ;
75 
76  // Subdivisions
77  FAffSub = new QLabel("Subdivisions : ") ;
78 
79  FAffX = new QLabel(" X : ") ;
80  FSaisieX = new QSpinBox ;
81  FSaisieX -> setMinimum(1);
82  FSaisieX -> setMaximum(1000);
83  FSaisieX -> setValue(1) ;
84  FSaisieX -> setAccelerated(true);
85 
86  FAffY = new QLabel(" Y : ") ;
87  FSaisieY = new QSpinBox ;
88  FSaisieY -> setMinimum(1);
89  FSaisieY -> setMaximum(1000);
90  FSaisieY -> setValue(1) ;
91  FSaisieY -> setAccelerated(true);
92 
93  FAffZ = new QLabel(" Z : ") ;
94  FSaisieZ = new QSpinBox ;
95  FSaisieZ -> setMinimum(1);
96  FSaisieZ -> setMaximum(1000);
97  FSaisieZ -> setValue(1) ;
98  FSaisieZ -> setAccelerated(true);
99 
100  QObject :: connect(FSaisieX , SIGNAL(valueChanged(int)) , this ,
101  SLOT(callbackSubdivisions())) ;
102  QObject :: connect(FSaisieY , SIGNAL(valueChanged(int)) , this ,
103  SLOT(callbackSubdivisions())) ;
104  QObject :: connect(FSaisieZ , SIGNAL(valueChanged(int)) , this ,
105  SLOT(callbackSubdivisions())) ;
106 
107  bb -> addWidget(FAffCel) ;
108  bb -> addWidget(FDimCell) ;
109  bb -> addSpacing(SPACE_PIX_SIZE);
110  bb -> addWidget(FAffMai) ;
111  bb -> addWidget(FDimMail) ;
112  bb -> addSpacing(SPACE_PIX_SIZE);
113  bb -> addWidget(FAffSub) ;
114  bb -> addWidget(FAffX) ;
115  bb -> addWidget(FSaisieX) ;
116  bb -> addWidget(FAffY) ;
117  bb -> addWidget(FSaisieY) ;
118  bb -> addWidget(FAffZ) ;
119  bb -> addWidget(FSaisieZ) ;
120 
121  //----------- Partie basse ----------------
122 
123  // Faces creees
124  QWidget * bas = new QWidget ;
125  QHBoxLayout * bh = new QHBoxLayout(bas);
126  bh -> setSpacing(0);
127  bh -> setContentsMargins(0, 0, 0, 0);
128 
129  FAffFac = new QLabel(*HTML::decode(" Faces created: ")) ;
130  FGauche = new QCheckBox("Left ") ;
131  FDroite = new QCheckBox("Right ") ;
132  FDevant = new QCheckBox("Front ") ;
133  FDerriere = new QCheckBox(*HTML::decode("Back ")) ;
134  FBas = new QCheckBox("Down ") ;
135  FHaut = new QCheckBox("Up ") ;
136 
137  // Ajout au layout bas
138  bh -> addWidget(FAffFac) ;
139  bh -> addWidget(FGauche) ;
140  bh -> addWidget(FDroite) ;
141  bh -> addWidget(FDevant) ;
142  bh -> addWidget(FDerriere) ;
143  bh -> addWidget(FBas) ;
144  bh -> addWidget(FHaut) ;
145 
146  FChoix = new BoutonsCreation(this , bh) ;
147 
148  //--------- Layout principal ---------
149  QWidget * centre = new QWidget ;
150  QVBoxLayout * bl = new QVBoxLayout(centre);
151  bl -> setSpacing(5);
152  bl -> setContentsMargins(0, 0, 0, 0);
153  bl -> addWidget(haut) ;
154  bl -> addWidget(bas) ;
155 
156  addWidget(centre);
157 
158  FPosit = new BoitePositionnement(this , parent , OBJECT_MESH) ;
159 
160  update() ;
161  repaint() ;
162 
163  QObject :: connect(FGauche , SIGNAL(clicked()) , this ,
164  SLOT(callbackToggleButton())) ;
165  QObject :: connect(FDroite , SIGNAL(clicked()) , this ,
166  SLOT(callbackToggleButton())) ;
167  QObject :: connect(FDevant , SIGNAL(clicked()) , this ,
168  SLOT(callbackToggleButton())) ;
169  QObject :: connect(FDerriere , SIGNAL(clicked()) , this ,
170  SLOT(callbackToggleButton())) ;
171  QObject :: connect(FBas , SIGNAL(clicked()) , this ,
172  SLOT(callbackToggleButton())) ;
173  QObject :: connect(FHaut , SIGNAL(clicked()) , this ,
174  SLOT(callbackToggleButton())) ;
175 }
176 
177 // Destructeur
178 //------------
180 
182 {
183 
184  FModifie = false ;
186 
187  FSaisieX->setValue(FControler->getParameterCreation()
188  ->getMeshNbSubdivisionsX());
189  FSaisieY->setValue(FControler->getParameterCreation()
190  ->getMeshNbSubdivisionsY());
191  FSaisieZ->setValue(FControler->getParameterCreation()
192  ->getMeshNbSubdivisionsZ());
193 
194  unsigned char toCreate =
195  FControler -> getParameterCreation()->getMeshCreatedFaces();
196 
197  FGauche -> setChecked((toCreate & (1 << 0)) != 0) ;
198  FDroite -> setChecked((toCreate & (1 << 1)) != 0) ;
199  FDevant -> setChecked((toCreate & (1 << 2)) != 0) ;
200  FDerriere -> setChecked((toCreate & (1 << 3)) != 0) ;
201  FBas -> setChecked((toCreate & (1 << 4)) != 0) ;
202  FHaut -> setChecked((toCreate & (1 << 5)) != 0) ;
203 
204  int dCell = FControler->getParameterCreation()->getMeshDimension();
205  int dMail = FControler->getParameterCreation()->getMeshSubdivisionDimension();
206 
207  FDimCell -> setCurrentIndex(dCell - 1) ;
208  FDimMail -> setCurrentIndex(dMail) ;
209 
210  bool b = dCell == 3 && dMail != 3 ;
211 
212  FGauche -> setEnabled(b) ;
213  FDroite -> setEnabled(b) ;
214  FDevant -> setEnabled(b) ;
215  FDerriere -> setEnabled(b) ;
216  FBas -> setEnabled(b) ;
217  FHaut -> setEnabled(b) ;
218 
219  FSaisieX->setEnabled(dMail != 0 && dCell > 0);
220  FSaisieY->setEnabled(dMail != 0 && dCell > 1);
221  FSaisieZ->setEnabled(dMail != 0 && dCell > 2);
222 
223  FModifie = true ;
224 }
225 
226 // Dialogbox callbacks ---------------------------------------------------------
227 void CreationMaillage::callbackSubdivisions()
228 {
229  if (FModifie)
231  getSubdivisions(1),
232  getSubdivisions(2));
233 }
234 
235 void CreationMaillage::callbackToggleButton()
236 {
237  if (FModifie)
239 }
240 
241 void CreationMaillage::callbackDimCell()
242 {
243  if (FModifie)
244  setCellDimension(1 + FDimCell -> currentIndex()) ;
245 }
246 
247 void CreationMaillage::callbackDimMesh()
248 {
249  if (FModifie)
250  setMeshDimension(FDimMail -> currentIndex()) ;
251 }
252 
253 // Accesseurs
254 //-----------
256 {
257  switch (i)
258  {
259  case 0 :
260  return FSaisieX -> value() ;
261  break ;
262  case 1:
263  return FSaisieY -> value() ;
264  break ;
265  case 2 :
266  return FSaisieZ -> value() ;
267  break ;
268  }
269  return -1 ;
270 }
271 
273 {
274  uchar result = 0;
275 
276  if (FGauche -> isChecked())
277  result |= (1 << 0) ;
278  if (FDroite -> isChecked())
279  result |= (1 << 1) ;
280  if (FDevant -> isChecked())
281  result |= (1 << 2) ;
282  if (FDerriere -> isChecked())
283  result |= (1 << 3) ;
284  if (FBas -> isChecked())
285  result |= (1 << 4) ;
286  if (FHaut -> isChecked())
287  result |= (1 << 5) ;
288 
289  return result;
290 }
291 
292 void CreationMaillage :: setSubdivisions(int x , int y , int z)
293 {
294  FControler ->getParameterCreation()->setMeshNbSubdivisionsX(x);
295  FControler ->getParameterCreation()->setMeshNbSubdivisionsY(y);
296  FControler ->getParameterCreation()->setMeshNbSubdivisionsZ(z);
297 
298  update() ;
299  repaint() ;
300 }
301 
303 {
304  FControler -> getParameterCreation()->setMeshCreatedFaces(c);
305  update() ;
306  repaint() ;
307 }
308 
310 {
311  FControler -> getParameterCreation()->setMeshDimension(dim);
312  update();
313  repaint() ;
314 }
315 
317 {
318  FControler->getParameterCreation()->setMeshSubdivisionDimension(dim);
319  update() ;
320  repaint() ;
321 }