00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "gl-multi-window.qt.hh"
00025 #include "window.qt.hh"
00026 #include "HtmlEntities.hh"
00027
00028 #ifdef __APPLE__
00029 #include <GLUT/glut.h>
00030 #else
00031 #include <GL/glut.h>
00032 #endif
00033
00034 #include <QtGui/QCloseEvent>
00035 #include <QtGui/QMouseEvent>
00036
00037 using namespace GMap3d ;
00038
00039
00040
00041
00042
00043
00044 GLMultiWindow :: GLMultiWindow ( QWorkspace * parent , Window * owner ,
00045 GLWindow * share , SelectBar * selection ) :
00046 GLWindow ( VIEW_ISO , parent , owner , share , selection ),
00047 FCliqued (0),
00048 FDoubleCliqued (0)
00049 {
00050 string str = getViewTypeString();
00051 setWindowTitle(*HTML::decode(&str));
00052 parent->addWindow(this);
00053 }
00054
00055
00056
00057
00058
00059
00060 GLMultiWindow :: ~GLMultiWindow ( ) { }
00061
00062
00063
00064
00065
00066
00067 TViewId GLMultiWindow::getViewId ( ) const
00068 {
00069 return FViewIds[0] ;
00070 }
00071
00072 string GLMultiWindow::getViewTypeString() const
00073 { return string("Multi-vue"); }
00074
00075 TViewId GLMultiWindow :: getCliquedViewId ( ) const
00076 {
00077 assert (0<=FCliqued && FCliqued<=3 );
00078
00079 return FViewIds[FCliqued];
00080 }
00081
00082 TViewId GLMultiWindow :: getDoubleCliquedViewId ( ) const
00083 {
00084 assert (0<=FDoubleCliqued && FDoubleCliqued<=3 );
00085
00086 return FViewIds[FDoubleCliqued];
00087 }
00088
00089
00090
00091
00092
00093 int GLMultiWindow :: cadre ( int x , int y )
00094 {
00095 int w = width ( ) / 2 ;
00096 int h = height ( ) / 2 ;
00097
00098 if ( x < w )
00099 {
00100 if ( y >= h )
00101 return 0 ;
00102 else
00103 return 2 ;
00104 }
00105 if ( y > h )
00106 return 1 ;
00107 return 3 ;
00108 }
00109
00110
00111
00112
00113
00114
00115 void GLMultiWindow :: closeEvent ( QCloseEvent * e )
00116 {
00117
00118 FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 0 ] ) ;
00119 FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 1 ] ) ;
00120 FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 2 ] ) ;
00121 FOwner -> getControler ( ) -> viewDestroy ( FViewIds [ 3 ] ) ;
00122 if ( e != NULL )
00123 e -> accept ( ) ;
00124 else
00125 close ( ) ;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134 void GLMultiWindow :: paintGL ( )
00135 {
00136
00137 glDisable(GL_SCISSOR_TEST);
00138 glClearColor(0,0,0, 1);
00139 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00140 glEnable(GL_SCISSOR_TEST);
00141 glLoadIdentity ( ) ;
00142
00143 int x = 0 ; int y = height ( ) / 2 ;
00144 int w = width ( ) / 2 ; int h = height ( ) / 2 ;
00145
00146
00147 for ( unsigned int i = 0 ; i < 4 ; i++ )
00148 {
00149 if ( i == 1 || i == 3 )
00150 x += w ;
00151 else if ( i== 2 )
00152 {
00153 x -= w ;
00154 y-= h ;
00155 }
00156
00157 glViewport ( x+1 , y+1 , w-2 , h-2 );
00158 glScissor ( x+1 , y+1 , w-2 , h-2 ) ;
00159
00160 FOwner -> getControler ( ) -> viewInit(FViewIds[i]);
00161 FOwner -> getControler ( ) -> viewDraw(FViewIds[i]);
00162 }
00163
00164 swapBuffers ( ) ;
00165 }
00166
00167
00168
00169
00170
00171 void GLMultiWindow :: initializeGL ( )
00172 {
00173
00174 glEnable(GL_DEPTH_TEST);
00175 glDepthFunc(GL_LEQUAL);
00176
00177 glEnable(GL_NORMALIZE);
00178
00179 glDisable(GL_BLEND);
00180
00181 glEnable(GL_POLYGON_MODE);
00182 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00183
00184
00185 static const GLfloat Material_Ks[] = {0.5, 0.5, 0.5, 1.0};
00186 static const GLfloat Material_Ke[] = {0.0, 0.0, 0.0, 1.0};
00187 static const GLfloat Material_Se = 100;
00188
00189 glEnable(GL_COLOR_MATERIAL);
00190 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR , Material_Ks);
00191 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION , Material_Ke);
00192 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, Material_Se);
00193
00194
00195 static const GLfloat Light_Ka[] = {0.1, 0.1, 0.1, 1.0};
00196 static const GLfloat Light_Kd[] = {1.0, 1.0, 1.0, 1.0};
00197 static const GLfloat Light_Ks[] = {0.5, 0.5, 0.5, 1.0};
00198
00199 glLightfv(GL_LIGHT0, GL_AMBIENT , Light_Ka);
00200 glLightfv(GL_LIGHT0, GL_DIFFUSE , Light_Kd);
00201 glLightfv(GL_LIGHT0, GL_SPECULAR, Light_Ks);
00202
00203
00204 creation ( ) ;
00205 }
00206
00207
00208
00209
00210
00211 void GLMultiWindow :: creation ( )
00212 {
00213
00214
00215
00216
00217
00218
00219 if ( FShared==NULL )
00220 {
00221 GMap3d :: CControlerGMap* controler = FOwner -> getControler ( ) ;
00222
00223 FViewIds [ 0 ] = controler->viewCreate(VIEW_XYZ);
00224 FViewIds [ 1 ] = controler->viewCreate(VIEW_XY);
00225 FViewIds [ 2 ] = controler->viewCreate(VIEW_XZ);
00226 FViewIds [ 3 ] = controler->viewCreate(VIEW_YZ);
00227
00228 for ( int i = 0 ; i < 4 ; i++ )
00229 {
00230 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_GRID);
00231 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_AXIS);
00232 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_AIMED_POINT);
00233 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_FACE);
00234 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_OBJECT_TRANSFORMATION);
00235 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_PREVIEW);
00236 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_NORMAL_VECTOR);
00237 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_SEW);
00238 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_VERTEX);
00239 #ifdef MODULE_SPAMOD
00240 controler->viewAddPrecompile (FViewIds [ i ], PRECOMPILE_SPAMOD);
00241 controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_SPAMOD);
00242 controler->getParameterSpamod(FViewIds [ i ])->setViewMode(SPAMOD_NONE);
00243 #endif // MODULE_SPAMOD
00244 controler->viewAddPrecompile(FViewIds [ i ], PRECOMPILE_DART);
00245
00246 controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_SEW);
00247
00248 controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_VERTEX);
00249
00250 controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_FACE);
00251
00252 controler->viewDisablePrecompile(FViewIds [ i ], PRECOMPILE_NORMAL_VECTOR);
00253
00254 controler->loadAllParameters(FViewIds [ i ]);
00255 }
00256 }
00257 else
00258 {
00259 FViewIds [ 0 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_XYZ, FShared->getViewId() );
00260 FViewIds [ 1 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_XY, FShared->getViewId() );
00261 FViewIds [ 2 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_XZ, FShared->getViewId() );
00262 FViewIds [ 3 ] = FOwner -> getControler ( )->viewCreateShare(VIEW_YZ, FShared->getViewId() );
00263 }
00264 }
00265
00266
00267
00268
00269
00270
00271
00272 void GLMultiWindow :: mousePressEvent ( QMouseEvent * eb )
00273 {
00274 CControlerGMap * controler = FOwner -> getControler ( ) ;
00275 int y = this -> height ( ) - eb -> y ( ) ;
00276
00277 FCliqued = cadre ( eb -> x() , y );
00278
00279 if ( eb -> modifiers () == Qt :: ControlModifier )
00280 {
00281 switch ( eb -> button ( ) )
00282 {
00283 case Qt::LeftButton:
00284
00285 controler ->
00286 operationModeIndependentStart(MODE_OPERATION_SCENE_TRANSLATION ,
00287 FViewIds [ cadre ( eb -> x() , y ) ],
00288 int ( eb -> x ( ) ) ,
00289 y ) ;
00290 break;
00291 case Qt::MidButton :
00292 controler ->
00293 operationModeIndependentStart(MODE_OPERATION_SCENE_ROTATION,
00294 FViewIds[ cadre ( eb -> x() , y ) ],
00295 int(eb->x ( ) ),
00296 y );
00297
00298 break;
00299 case Qt::RightButton :
00300 controler ->
00301 operationModeIndependentStart(MODE_OPERATION_SCENE_SCALE,
00302 FViewIds[ cadre ( eb -> x() , y ) ],
00303 int(eb->x ( )),
00304 y );
00305
00306 break;
00307 default : {}
00308 }
00309 }
00310 else
00311 {
00312
00313 if ( eb -> button ( ) == Qt :: LeftButton )
00314 {
00315 controler -> setHalfSelectionOrbit
00316 ( eb -> modifiers ( ) == Qt :: ShiftModifier ) ;
00317 controler -> operationModeStart( FViewIds[ cadre ( eb -> x() , y ) ] ,
00318 int(eb->x ( )) ,
00319 y ) ;
00320
00321 CreationObjet * boite = FOwner -> getCreationActive ( ) ;
00322
00323 if ( boite != NULL )
00324 boite -> update ( ) ;
00325
00326 dialogOperations * op = FOwner -> getOperationActive ( ) ;
00327
00328 if ( op != NULL )
00329 op -> update ( ) ;
00330
00331 FOwner -> repaint( ) ;
00332 }
00333
00334
00335 else if ( eb -> button ( ) == Qt::MidButton)
00336 {
00337 if (controler->isInCreationMode())
00338 {
00339 CreationObjet * boite = FOwner -> getCreationActive ( ) ;
00340
00341 if ( boite != NULL )
00342 boite -> create ( ) ;
00343 }
00344 else
00345 {
00346 FSelection -> niveauSuivant ( ) ;
00347
00348 #ifdef MODULE_ARCHITECTURE
00349 FOwner -> getFlapSelection() -> nextLevel();
00350 #endif
00351 }
00352 }
00353 else if ( eb -> button ( ) == Qt :: RightButton )
00354 {
00355 FOwner -> getControler ( ) -> lookAtMouseClick(FViewIds[cadre(eb -> x(),y)],eb -> x(),y);
00356 repaint();
00357 }
00358 }
00359 }
00360
00361
00362
00363 void GLMultiWindow :: mouseMoveEvent ( QMouseEvent * em )
00364 {
00365
00366 int y = this -> height ( ) - em -> y ( ) ;
00367 FOwner -> getControler ( ) -> operationModeMove ( int ( em -> x ( ) ), y ) ;
00368 CreationObjet * boite = FOwner -> getCreationActive ( ) ;
00369 if ( boite != NULL )
00370 boite -> update ( ) ;
00371
00372 dialogOperations * op = FOwner -> getOperationActive ( ) ;
00373
00374 if ( op != NULL )
00375 op -> update ( ) ;
00376
00377 FOwner -> repaint ( ) ;
00378 this -> update () ;
00379 }
00380
00381
00382
00383
00384 void GLMultiWindow :: mouseReleaseEvent ( QMouseEvent * eb )
00385 {
00386 int y = this -> height ( ) - eb -> y () ;
00387 FOwner -> getControler() -> operationModeStop (int(eb->x()),
00388 y );
00389 CreationObjet * boite = FOwner -> getCreationActive ( ) ;
00390 if ( boite != NULL )
00391 boite -> update ( ) ;
00392
00393 dialogOperations * op = FOwner -> getOperationActive ( ) ;
00394 if ( op != NULL )
00395 op -> update ( ) ;
00396
00397 FOwner -> repaint ( ) ;
00398 this -> update () ;
00399
00400 }
00401
00402
00403
00404 void GLMultiWindow :: mouseDoubleClickEvent ( QMouseEvent * e )
00405 {
00406 if ( e -> button ( ) == Qt::LeftButton )
00407 {
00408 int y = this -> height ( ) - e -> y ( ) ;
00409 FDoubleCliqued = cadre ( e -> x() , y );
00410 FOwner -> setDoubleCliquee ( this ) ;
00411 }
00412 else
00413 {
00414 mousePressEvent(e);
00415 }
00416
00417 }