Moka Ihm Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
gl-multi-window.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 "gl-multi-window.qt.hh"
25 #include "window.qt.hh"
26 #include "HtmlEntities.hh"
27 
28 #ifdef _WINDOWS
29 #include <windows.h>
30 #endif
31 
32 #ifdef __APPLE__
33 #include <GLUT/glut.h>
34 #else
35 #include <GL/glut.h>
36 #endif
37 
38 #include <QtGui/QCloseEvent>
39 #include <QtGui/QMouseEvent>
40 
41 using namespace GMap3d ;
42 
43 
44 //*******************************************************
45 // Constructeur
46 //*******************************************************
47 
48 GLMultiWindow :: GLMultiWindow ( QWorkspace * parent , Window * owner ,
49  GLWindow * share , SelectBar * selection ) :
50  GLWindow ( VIEW_ISO , parent , owner , share , selection ),
51  FCliqued (0),
52  FDoubleCliqued (0)
53 {
54  string str = getViewTypeString();
55  setWindowTitle(*HTML::decode(&str));
56  parent->addWindow(this);
57 }
58 
59 
60 //*******************************************************
61 // Destructeur
62 //*******************************************************
63 
65 
66 
67 //*******************************************************
68 // Accesseurs
69 //*******************************************************
70 
71 TViewId GLMultiWindow::getViewId ( ) const
72 {
73  return FViewIds[0] ;
74 }
75 
77 { return string("Multi-vue"); }
78 
80 {
81  assert (0<=FCliqued && FCliqued<=3 );
82 
83  return FViewIds[FCliqued];
84 }
85 
87 {
88  assert (0<=FDoubleCliqued && FDoubleCliqued<=3 );
89 
90  return FViewIds[FDoubleCliqued];
91 }
92 
93 //*****************************************************
94 // Cadre
95 //*****************************************************
96 
97 int GLMultiWindow :: cadre ( int x , int y )
98 {
99  int w = width ( ) / 2 ;
100  int h = height ( ) / 2 ;
101 
102  if ( x < w )
103  {
104  if ( y >= h )
105  return 0 ;
106  else
107  return 2 ;
108  }
109  if ( y > h )
110  return 1 ;
111  return 3 ;
112 }
113 
114 
115 //************************************************
116 // Methode de fermeture
117 //************************************************
118 
119 void GLMultiWindow :: closeEvent ( QCloseEvent * e )
120 {
121 
122  FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 0 ] ) ;
123  FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 1 ] ) ;
124  FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 2 ] ) ;
125  FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 3 ] ) ;
126  if ( e != NULL )
127  e -> accept ( ) ;
128  else
129  close ( ) ;
130 }
131 
132 
133 
134 //***************************************************
135 // Methode d'affichages OpenGL
136 //***************************************************
137 
139 {
140  // On efface et on active le ciseau
141  glDisable(GL_SCISSOR_TEST);
142  glClearColor(0,0,0, 1);
143  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
144  glEnable(GL_SCISSOR_TEST);
145  glLoadIdentity ( ) ;
146 
147  int x = 0 ; int y = height ( ) / 2 ;
148  int w = width ( ) / 2 ; int h = height ( ) / 2 ;
149 
150  // On dessine les 4 vues bien dans leur cadre
151  for ( unsigned int i = 0 ; i < 4 ; i++ )
152  {
153  if ( i == 1 || i == 3 )
154  x += w ;
155  else if ( i== 2 )
156  {
157  x -= w ;
158  y-= h ;
159  }
160 
161  glViewport ( x+1 , y+1 , w-2 , h-2 );
162  glScissor ( x+1 , y+1 , w-2 , h-2 ) ;
163 
164  FOwner -> getControler ( ) -> viewInit(FViewIds[i]);
165  FOwner -> getControler ( ) -> viewDraw(FViewIds[i]);
166  }
167 
168  // swapBuffers ( ) ;
169 }
170 
171 //***************************************************
172 // Methode d'initialisation OpenGL
173 //***************************************************
174 
176 {
177  glEnable(GL_DEPTH_TEST); // z-buffer
178  glDepthFunc(GL_LEQUAL);
179 
180 // glEnable(GL_NORMALIZE);
181  glDisable(GL_BLEND);
182 
183  glEnable(GL_POLYGON_MODE);
184  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
185 
186  ::glEnable(GL_POLYGON_OFFSET_FILL);
187  ::glPolygonOffset(1.0f,1.0f);
188 
189  // Proprietes des surfaces ----------------------------------------------
190  static const GLfloat Material_Ks[] = {0.5, 0.5, 0.5, 1.0};
191  static const GLfloat Material_Ke[] = {0.0, 0.0, 0.0, 1.0};
192  static const GLfloat Material_Se = 100;
193 
194  glEnable(GL_COLOR_MATERIAL);
195  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR , Material_Ks);
196  glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION , Material_Ke);
197  glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, Material_Se);
198 
199  // Couleur des lumieres ---------------------------------------------------
200  static const GLfloat Light_Ka[] = {0.1, 0.1, 0.1, 1.0};
201  static const GLfloat Light_Kd[] = {1.0, 1.0, 1.0, 1.0};
202  static const GLfloat Light_Ks[] = {0.5, 0.5, 0.5, 1.0};
203 
204  glLightfv(GL_LIGHT0, GL_AMBIENT , Light_Ka);
205  glLightfv(GL_LIGHT0, GL_DIFFUSE , Light_Kd);
206  glLightfv(GL_LIGHT0, GL_SPECULAR, Light_Ks);
207  //*************************************************************************
208 
209  creation ( ) ;
210 }
211 
212 //***************************************************
213 // Initialisation des vues dans le controleur
214 //***************************************************
215 
217 {
218 
219  //initializeGL ( ) ;
220 
221  // if (FShared==NULL)
222  // initializeGL ();
223 
224  if ( FShared==NULL )
225  {
226  GMap3d :: CControlerGMap* controler = FOwner -> getControler ( ) ;
227 
228  FViewIds [ 0 ] = controler->viewCreate(VIEW_XYZ);
229  FViewIds [ 1 ] = controler->viewCreate(VIEW_XY);
230  FViewIds [ 2 ] = controler->viewCreate(VIEW_XZ);
231  FViewIds [ 3 ] = controler->viewCreate(VIEW_YZ);
232 
233  for ( int i = 0 ; i < 4 ; i++ )
234  {
235  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_GRID);
236  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_AXIS);
237  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_AIMED_POINT);
238  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_OBJECT_TRANSFORMATION);
239  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_PREVIEW);
240  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_NORMAL_VECTOR);
241  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_SEW);
242  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_VERTEX);
243 #ifdef MODULE_SPAMOD
244  controler->viewAddPrecompile (FViewIds [ i ], PRECOMPILE_SPAMOD);
245  controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_SPAMOD);
246  controler->getParameterSpamod(FViewIds [ i ])->setViewMode(SPAMOD_NONE);
247 #endif // MODULE_SPAMOD
248  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_DART);
249  controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_FACE);
250 
251  controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_SEW);
252 
253  controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_VERTEX);
254 
255  controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_FACE);
256 
257  controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_NORMAL_VECTOR);
258 
259  controler->loadAllParameters(FViewIds [ i ]);
260  }
261  }
262  else
263  {
264  FViewIds [ 0 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_XYZ, FShared->getViewId() );
265  FViewIds [ 1 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_XY, FShared->getViewId() );
266  FViewIds [ 2 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_XZ, FShared->getViewId() );
267  FViewIds [ 3 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_YZ, FShared->getViewId() );
268  }
269 }
270 
271 
272 //**************************************************
273 // Gestion des evenements souris
274 //**************************************************
275 
276 
277 void GLMultiWindow :: mousePressEvent ( QMouseEvent * eb )
278 {
279  CControlerGMap * controler = FOwner -> getControler ( ) ;
280  int y = this -> height ( ) - eb -> y ( ) ;
281 
282  FCliqued = cadre ( eb -> x() , y );
283 
284  if ( eb -> modifiers () == Qt :: ControlModifier ) // <CONTROL> key is pressed:
285  {
286  switch ( eb -> button ( ) )
287  {
288  case Qt::LeftButton: // bouton gauche de la souris
289 
290  controler ->
291  operationModeIndependentStart(MODE_OPERATION_SCENE_TRANSLATION ,
292  FViewIds [ cadre ( eb -> x() , y ) ],
293  int ( eb -> x ( ) ) ,
294  y ) ;
295  break;
296  case Qt::MidButton : // bouton milieu
297  controler ->
298  operationModeIndependentStart(MODE_OPERATION_SCENE_ROTATION,
299  FViewIds[ cadre ( eb -> x() , y ) ],
300  int(eb->x ( ) ),
301  y );
302 
303  break;
304  case Qt::RightButton : // bouton droit
305  controler ->
306  operationModeIndependentStart(MODE_OPERATION_SCENE_SCALE,
307  FViewIds[ cadre ( eb -> x() , y ) ],
308  int(eb->x ( )),
309  y );
310 
311  break;
312  default : {}
313  }
314  }
315  else
316  {
317  // Clic du bouton gauche de la souris
318  if ( eb -> button ( ) == Qt :: LeftButton )
319  {
320  controler -> setHalfSelectionOrbit
321  ( eb -> modifiers ( ) == Qt :: ShiftModifier ) ;
322  controler -> operationModeStart( FViewIds[ cadre ( eb -> x() , y ) ] ,
323  int(eb->x ( )) ,
324  y ) ;
325 
326  CreationObjet * boite = FOwner -> getCreationActive ( ) ;
327 
328  if ( boite != NULL )
329  boite -> update ( ) ;
330 
331  dialogOperations * op = FOwner -> getOperationActive ( ) ;
332 
333  if ( op != NULL )
334  op -> update ( ) ;
335 
336  FOwner -> repaint( ) ;
337  }
338 
339  //
340  else if ( eb -> button ( ) == Qt::MidButton)
341  {
342  if (controler->isInCreationMode())
343  {
344  CreationObjet * boite = FOwner -> getCreationActive ( ) ;
345 
346  if ( boite != NULL )
347  boite -> create ( ) ;
348  }
349  else
350  {
351  FSelection -> niveauSuivant ( ) ;
352 
353  #ifdef MODULE_ARCHITECTURE
354  FOwner -> getFlapSelection() -> nextLevel();
355  #endif
356  }
357  }
358  else if ( eb -> button ( ) == Qt :: RightButton )
359  {
360  FOwner -> getControler ( ) -> lookAtMouseClick(FViewIds[cadre(eb -> x(),y)],eb -> x(),y);
361  repaint();
362  }
363  }
364 }
365 
366 
367 
368 void GLMultiWindow :: mouseMoveEvent ( QMouseEvent * em )
369 {
370 
371  int y = this -> height ( ) - em -> y ( ) ;
372  FOwner -> getControler ( ) -> operationModeMove ( int ( em -> x ( ) ), y ) ;
373  CreationObjet * boite = FOwner -> getCreationActive ( ) ;
374  if ( boite != NULL )
375  boite -> update ( ) ;
376 
377  dialogOperations * op = FOwner -> getOperationActive ( ) ;
378 
379  if ( op != NULL )
380  op -> update ( ) ;
381 
382  FOwner -> repaint ( ) ;
383  this -> update () ;
384 }
385 
386 
387 
388 
389 void GLMultiWindow :: mouseReleaseEvent ( QMouseEvent * eb )
390 {
391  int y = this -> height ( ) - eb -> y () ;
392  FOwner -> getControler() -> operationModeStop (int(eb->x()),
393  y );
394  CreationObjet * boite = FOwner -> getCreationActive ( ) ;
395  if ( boite != NULL )
396  boite -> update ( ) ;
397 
398  dialogOperations * op = FOwner -> getOperationActive ( ) ;
399  if ( op != NULL )
400  op -> update ( ) ;
401 
402  FOwner -> repaint ( ) ;
403  this -> update () ;
404 
405 }
406 
407 
408 
409 void GLMultiWindow :: mouseDoubleClickEvent ( QMouseEvent * e )
410 {
411  if ( e -> button ( ) == Qt::LeftButton )
412  {
413  int y = this -> height ( ) - e -> y ( ) ;
414  FDoubleCliqued = cadre ( e -> x() , y );
415  FOwner -> setDoubleCliquee ( this ) ;
416  }
417  else
418  {
419  mousePressEvent(e);
420  }
421 
422 }