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 "dialog-homothetie.qt.hh"
00025 #include "window.qt.hh"
00026 #include "HtmlEntities.hh"
00027 #include "SpaceWidget.qt.hh"
00028
00029 #include <QtGui/QPixmap>
00030 #include <QtGui/QLabel>
00031 #include <QtGui/QBoxLayout>
00032
00033
00034
00035 dialogHomothetie :: dialogHomothetie ( Window * parent ,
00036 GMap3d :: CControlerGMap * controler )
00037 :
00038 dialogOperations ( parent , HTML::decode("Homothétie" ) ,
00039 controler , Qt::BottomToolBarArea )
00040 {
00041
00042
00043 QWidget * gauche = new QWidget ;
00044 QGridLayout * bgauche = new QGridLayout ( gauche ) ;
00045 bgauche -> setSpacing(0);
00046 bgauche -> setContentsMargins(0,0,0,0);
00047
00048 FAffParam = new QLabel ( *HTML::decode(" Homothétie par rapport ")) ;
00049 QLabel* FRapport = new QLabel (*HTML::decode("à : ")) ;
00050 FSaisieParam = new QComboBox ;
00051 FSaisieParam -> addItem ( "Sommet" ) ;
00052 FSaisieParam -> addItem ( "Droite" ) ;
00053 FSaisieParam -> addItem ( "Plan" ) ;
00054
00055 bgauche -> addWidget ( FAffParam, 0, 0, 1, 4 );
00056 bgauche -> addWidget ( FRapport, 1, 0, Qt::AlignRight | Qt::AlignTop);
00057 bgauche -> addWidget ( FSaisieParam, 1, 1, 1, 3,
00058 Qt::AlignLeft | Qt::AlignTop) ;
00059
00060
00061 QWidget * haut = new QWidget ;
00062 QHBoxLayout * bhaut = new QHBoxLayout ( haut ) ;
00063 bhaut -> setSpacing(0);
00064 bhaut -> setContentsMargins(0,0,0,0);
00065
00066 FAffSommet = new QLabel ( " Sommet : " ) ;
00067 FSaisiePonderation = new QCheckBox
00068 ( *HTML::decode("Homothétie pondérée") , haut ) ;
00069
00070 FSaisie = new champsOperations ( this , bhaut ) ;
00071 bhaut -> addSpacing ( SPACE_PIX_SIZE ) ;
00072 bhaut -> addWidget ( FSaisiePonderation ) ;
00073 bhaut -> addStretch ( 1 );
00074
00075
00076
00077 QWidget * bas = new QWidget ;
00078 QHBoxLayout * bbas = new QHBoxLayout ( bas );
00079 bbas -> setSpacing(0);
00080 bbas -> setContentsMargins(0,0,0,0);
00081
00082 FAffVecteur = new QLabel ;
00083 FAffCoef = new QLabel ( "Coefficient : " );
00084
00085 FSaisieCoef = new FloatSpinBox (0.2);
00086 FSaisieCoef -> setWrapping ( true ) ;
00087
00088 FSaisieIso = new QCheckBox ( "iso" ) ;
00089 QIcon p2 ( ":/boutonAnnuler.png" ) ;
00090 FClose = new QPushButton ( p2 , "Fermer" ) ;
00091 FClose -> setShortcut ( Qt :: Key_Space ) ;
00092
00093 bbas -> addWidget ( FAffVecteur ) ;
00094 FSaisieVecteur = new champsOperations ( this , bbas ) ;
00095 bbas -> addSpacing ( SPACE_PIX_SIZE ) ;
00096 bbas -> addWidget ( FSaisieIso ) ;
00097 bbas -> addSpacing ( SPACE_PIX_SIZE ) ;
00098 bbas -> addWidget ( FAffCoef ) ;
00099 bbas -> addWidget ( FSaisieCoef ) ;
00100 bbas -> addSpacing ( SPACE_PIX_SIZE ) ;
00101 bbas -> addWidget ( FClose ) ;
00102 bbas -> addStretch ( 1 );
00103
00104
00105 QWidget * bas2 = new QWidget ;
00106 QHBoxLayout * bbas2 = new QHBoxLayout ( bas2 );
00107 bbas2 -> setSpacing(0);
00108 bbas2 -> setContentsMargins(0,0,0,0);
00109
00110 FAffCoeffs = new QLabel ( "Coefficients : " );
00111
00112 FAffX = new QLabel ( " X : " ) ;
00113 FSaisieX = new FloatSpinBox (0.2) ;
00114 FSaisieX -> setWrapping ( true ) ;
00115
00116 FAffY = new QLabel ( " Y : " ) ;
00117 FSaisieY = new FloatSpinBox (0.2) ;
00118 FSaisieY -> setWrapping ( true ) ;
00119
00120 FAffZ = new QLabel ( " Z : " ) ;
00121 FSaisieZ = new FloatSpinBox (0.2) ;
00122 FSaisieZ -> setWrapping ( true ) ;
00123
00124 bbas2 -> addWidget ( FAffX ) ;
00125 bbas2 -> addWidget ( FSaisieX ) ;
00126 bbas2 -> addWidget ( FAffY ) ;
00127 bbas2 -> addWidget ( FSaisieY ) ;
00128 bbas2 -> addWidget ( FAffZ ) ;
00129 bbas2 -> addWidget ( FSaisieZ ) ;
00130 bbas2 -> addStretch ( 1 );
00131
00132
00133 QWidget * centre = new QWidget ;
00134 QGridLayout * gl = new QGridLayout ( centre );
00135
00136 gl -> setHorizontalSpacing(0);
00137 gl -> setVerticalSpacing(5);
00138 gl -> setContentsMargins(0,0,0,0);
00139 gl -> addWidget(FAffSommet, 0, 0, Qt::AlignRight) ;
00140 gl -> addWidget(FAffVecteur, 1, 0, Qt::AlignRight) ;
00141 gl -> addWidget(FAffCoeffs, 2, 0, Qt::AlignRight) ;
00142 gl -> addWidget(haut, 0, 1) ;
00143 gl -> addWidget(bas, 1, 1) ;
00144 gl -> addWidget(bas2, 2, 1) ;
00145
00146
00147 addWidget(gauche);
00148 addSeparator();
00149 addWidget(centre);
00150
00151 update ( ) ;
00152
00153 connect ( FSaisieParam , SIGNAL ( activated ( int ) ) ,
00154 this , SLOT ( callbackDistance ( ) ) ) ;
00155
00156 connect ( FSaisie -> getSaisieX ( ) , SIGNAL ( valueChanged ( double ) ) ,
00157 this , SLOT ( callbackCx ( ) ) ) ;
00158
00159 connect ( FSaisie -> getSaisieY ( ) , SIGNAL ( valueChanged ( double ) ) ,
00160 this , SLOT ( callbackCy ( ) ) ) ;
00161
00162 connect ( FSaisie -> getSaisieZ ( ) , SIGNAL ( valueChanged ( double ) ) ,
00163 this , SLOT ( callbackCz ( ) ) ) ;
00164
00165 connect ( FSaisie -> getButtonRecuperer ( ) , SIGNAL ( clicked ( ) ) ,
00166 this, SLOT ( callbackTakeCenter ( ) ) ) ;
00167
00168 connect ( FSaisiePonderation , SIGNAL ( clicked ( ) ) ,
00169 this , SLOT ( callbackTogglePonderation ( ) ) ) ;
00170
00171 connect ( FSaisieVecteur -> getSaisieX ( ) ,
00172 SIGNAL ( valueChanged ( double ) ) ,
00173 this , SLOT ( callbackVx ( ) ) ) ;
00174
00175 connect ( FSaisieVecteur -> getSaisieY ( ) ,
00176 SIGNAL ( valueChanged ( double ) ) ,
00177 this , SLOT ( callbackVy ( ) ) ) ;
00178
00179 connect ( FSaisieVecteur -> getSaisieZ ( ) ,
00180 SIGNAL ( valueChanged ( double ) ) ,
00181 this , SLOT ( callbackVz ( ) ) ) ;
00182
00183 connect ( FSaisieVecteur -> getButtonRecuperer ( ) ,
00184 SIGNAL ( clicked ( ) ) ,
00185 this, SLOT ( callbackTakeVector ( ) ) ) ;
00186
00187 connect ( FSaisieCoef , SIGNAL ( valueChanged (double ) ) ,
00188 this , SLOT ( callbackIsoCoef ( ) ) ) ;
00189
00190 connect ( FSaisieX , SIGNAL ( valueChanged ( double ) ) ,
00191 this , SLOT ( callbackKx ( ) ) ) ;
00192
00193 connect ( FSaisieY , SIGNAL ( valueChanged ( double ) ) ,
00194 this , SLOT ( callbackKy ( ) ) ) ;
00195
00196 connect ( FSaisieZ , SIGNAL ( valueChanged ( double ) ) ,
00197 this , SLOT ( callbackKz ( ) ) ) ;
00198
00199 connect ( FSaisieIso , SIGNAL ( clicked ( ) ) ,
00200 this , SLOT ( callbackToggleIsoButton ( ) ) ) ;
00201
00202 connect ( FClose , SIGNAL ( clicked ( ) ) ,
00203 this , SLOT ( callbackClose ( ) ) ) ;
00204 }
00205
00206
00207
00208 dialogHomothetie :: ~dialogHomothetie ( )
00209 {}
00210
00211
00212 void dialogHomothetie :: update ( )
00213 {
00214 FUpdate = true ;
00215 dialogOperations :: update ( ) ;
00216
00217 assert ( FParent != NULL ) ;
00218
00219 FSaisieParam->setCurrentIndex(getControler()->getObjectScaleType());
00220 FSaisiePonderation->setChecked(getControler()->getObjectScalePonderation());
00221
00222 switch ( getControler ( ) -> getObjectScaleType ( ) ) {
00223 case 0 :
00224 FAffVecteur -> setText ( " " ) ;
00225
00226 case 1 :
00227 FAffVecteur -> setText ( " Vecteur directeur : " ) ; break ;
00228 case 2 :
00229 FAffVecteur -> setText ( " Vecteur normal : " ) ; break ;
00230 default : { }
00231 }
00232
00233 bool enabled = (getControler()->getObjectScaleType()!=DistanceToVertex);
00234 FSaisieVecteur -> getLabelX ( ) -> setEnabled ( enabled ) ;
00235 FSaisieVecteur -> getLabelY ( ) -> setEnabled ( enabled ) ;
00236 FSaisieVecteur -> getLabelZ ( ) -> setEnabled ( enabled ) ;
00237 FSaisieVecteur -> getSaisieX ( ) -> setEnabled ( enabled ) ;
00238 FSaisieVecteur -> getSaisieY ( ) -> setEnabled ( enabled ) ;
00239 FSaisieVecteur -> getSaisieZ ( ) -> setEnabled ( enabled ) ;
00240 FSaisieVecteur -> getButtonRecuperer ( ) -> setEnabled ( enabled );
00241
00242
00243 bool not_iso_mode = ! ( getControler()->getObjectScaleIso() ) ;
00244
00245 FSaisieIso ->setChecked ( !not_iso_mode ) ;
00246
00247 FSaisieCoef -> setVisible ( !not_iso_mode ) ;
00248 FAffCoef -> setVisible ( !not_iso_mode ) ;
00249
00250 FAffCoeffs -> setVisible ( not_iso_mode ) ;
00251 FAffX -> setVisible ( not_iso_mode ) ;
00252 FSaisieX -> setVisible ( not_iso_mode ) ;
00253 FAffY -> setVisible ( not_iso_mode ) ;
00254 FSaisieY -> setVisible ( not_iso_mode ) ;
00255 FAffZ -> setVisible ( not_iso_mode ) ;
00256 FSaisieZ -> setVisible ( not_iso_mode ) ;
00257
00258 FSaisie -> setValueX ( getCx ( ) ) ;
00259 FSaisie -> setValueY ( getCy ( ) ) ;
00260 FSaisie -> setValueZ ( getCz ( ) ) ;
00261
00262 FSaisieVecteur -> setValueX ( getVx ( ) ) ;
00263 FSaisieVecteur -> setValueY ( getVy ( ) ) ;
00264 FSaisieVecteur -> setValueZ ( getVz ( ) ) ;
00265
00266 if (!not_iso_mode)
00267 FSaisieCoef->setValuef(getControler() -> getObjectScaleIsoCoef());
00268 else
00269 {
00270 FSaisieX -> setValuef(getKx()) ;
00271 FSaisieY -> setValuef(getKy()) ;
00272 FSaisieZ -> setValuef(getKz()) ;
00273 }
00274
00275 FParent -> repaint ( ) ;
00276 FUpdate = false ;
00277 }
00278
00279
00280
00281 void dialogHomothetie :: setDistanceType ( TScaleType type )
00282 {
00283 assert ( FParent != NULL ) ;
00284 if ( type == getControler ( ) -> getObjectScaleType ( ) )
00285 return;
00286
00287 getControler ( ) -> setObjectScaleType ( type ) ;
00288 update ( ) ;
00289 }
00290
00291 void dialogHomothetie :: setIso ( bool b )
00292 {
00293 assert ( FParent != NULL ) ;
00294 if ( b == getControler ( ) -> getObjectScaleIso ( ) )
00295 return;
00296
00297 getControler ( ) -> setObjectScaleIso ( b ) ;
00298 update ( ) ;
00299 }
00300
00301
00302
00303 void dialogHomothetie :: callbackCx ( )
00304 {
00305 if ( ! FUpdate )
00306 setCx ( FSaisie -> getValueX ( ) ) ;
00307 }
00308
00309 void dialogHomothetie :: callbackCy ( )
00310 {
00311 if ( ! FUpdate )
00312 setCy ( FSaisie -> getValueY ( ) ) ;
00313 }
00314
00315 void dialogHomothetie :: callbackCz ( )
00316 {
00317 if ( ! FUpdate )
00318 setCz ( FSaisie -> getValueZ ( ) ) ;
00319 }
00320
00321 void dialogHomothetie :: callbackVx ( )
00322 {
00323 if ( ! FUpdate )
00324 setVx ( FSaisieVecteur -> getValueX ( ) ) ;
00325 }
00326
00327 void dialogHomothetie :: callbackVy ( )
00328 {
00329 if ( ! FUpdate )
00330 setVy ( FSaisieVecteur -> getValueY ( ) ) ;
00331 }
00332
00333 void dialogHomothetie :: callbackVz ( )
00334 {
00335 if ( ! FUpdate )
00336 setVz ( FSaisieVecteur -> getValueZ ( ) ) ;
00337 }
00338
00339 void dialogHomothetie :: callbackKx ( )
00340 {
00341 if ( ! FUpdate )
00342 setKx ( FSaisieX -> valuef ( ) ) ;
00343 }
00344
00345 void dialogHomothetie :: callbackKy ( )
00346 {
00347 if ( ! FUpdate )
00348 setKy( FSaisieY -> valuef ( ) ) ;
00349 }
00350
00351 void dialogHomothetie :: callbackKz ( )
00352 {
00353 if ( ! FUpdate )
00354 setKz ( FSaisieZ -> valuef ( ) ) ;
00355 }
00356
00357 void dialogHomothetie :: callbackToggleIsoButton ( )
00358 {
00359 if ( ! FUpdate )
00360 setIso ( FSaisieIso -> isChecked ( ) ) ;
00361 }
00362
00363 void dialogHomothetie :: callbackIsoCoef ( )
00364 {
00365 if ( ! FUpdate )
00366 setIsoCoef ( FSaisieCoef -> valuef ( ) ) ;
00367 }
00368
00369 void dialogHomothetie :: callbackDistance( )
00370 {
00371 if ( ! FUpdate )
00372 setDistanceType ( ( TDistanceType ) (FSaisieParam -> currentIndex ( ) ) );
00373 }
00374
00375 void dialogHomothetie :: callbackTakeCenter ( )
00376 {
00377 assert ( FParent != NULL ) ;
00378
00379 CVertex center;
00380 if ( getControler ( ) -> takeCenter ( center ) )
00381 setC ( center ) ;
00382 }
00383
00384 void dialogHomothetie :: callbackTakeVector ( )
00385 {
00386 assert ( FParent != NULL ) ;
00387
00388 CVertex vector;
00389 if ( getControler ( ) -> takeVector ( vector ) )
00390 setV ( vector ) ;
00391 }
00392
00393 void dialogHomothetie :: callbackTogglePonderation ( )
00394 {
00395 if ( ! FUpdate )
00396 {
00397 getControler ( ) -> toggleObjectScalePonderation ( ) ;
00398 FParent -> repaint ( ) ;
00399 }
00400 }
00401
00402
00403
00404 TCoordinate dialogHomothetie :: getCx ( ) const
00405 {
00406 assert ( FParent != NULL ) ;
00407 return getControler ( ) -> getObjectScaleCenter ( ) . getX ( ) ;
00408 }
00409
00410 TCoordinate dialogHomothetie :: getCy ( ) const
00411 {
00412 assert ( FParent != NULL ) ;
00413 return getControler ( ) -> getObjectScaleCenter ( ) . getY ( ) ;
00414 }
00415
00416 TCoordinate dialogHomothetie :: getCz ( ) const
00417 {
00418 assert ( FParent != NULL ) ;
00419 return getControler ( ) -> getObjectScaleCenter ( ) . getZ ( ) ;
00420 }
00421
00422 TCoordinate dialogHomothetie :: getVx ( ) const
00423 {
00424 assert ( FParent != NULL ) ;
00425 return getControler ( ) -> getObjectScaleVector ( ) . getX ( ) ;
00426 }
00427
00428 TCoordinate dialogHomothetie :: getVy ( ) const
00429 {
00430 assert ( FParent != NULL ) ;
00431 return getControler ( ) -> getObjectScaleVector ( ) . getY ( ) ;
00432 }
00433
00434 TCoordinate dialogHomothetie :: getVz ( ) const
00435 {
00436 assert ( FParent != NULL ) ;
00437 return getControler ( ) -> getObjectScaleVector ( ) . getZ ( ) ;
00438 }
00439
00440 TCoordinate dialogHomothetie :: getKx ( ) const
00441 {
00442 assert ( FParent != NULL ) ;
00443 return getControler ( ) -> getObjectScaleCoef ( 0 ) ;
00444 }
00445
00446 TCoordinate dialogHomothetie :: getKy ( ) const
00447 {
00448 assert ( FParent != NULL ) ;
00449 return getControler ( ) -> getObjectScaleCoef ( 1 ) ;
00450 }
00451
00452 TCoordinate dialogHomothetie :: getKz ( ) const
00453 {
00454 assert ( FParent != NULL ) ;
00455 return getControler ( ) -> getObjectScaleCoef ( 2 ) ;
00456 }
00457
00458
00459
00460 void dialogHomothetie :: setCx ( TCoordinate k )
00461 {
00462 setC ( CVertex ( k , getCy ( ) , getCz ( ) ) ) ;
00463 }
00464
00465 void dialogHomothetie :: setCy ( TCoordinate k )
00466 {
00467 setC ( CVertex ( getCx ( ) , k , getCz ( ) ) ) ;
00468 }
00469
00470 void dialogHomothetie :: setCz ( TCoordinate k )
00471 {
00472 setC ( CVertex ( getCx ( ) , getCy ( ) , k ) ) ;
00473 }
00474
00475 void dialogHomothetie :: setVx ( TCoordinate k )
00476 {
00477 setV ( CVertex ( k , getVy ( ) , getVz ( ) ) ) ;
00478 }
00479
00480 void dialogHomothetie :: setVy ( TCoordinate k )
00481 {
00482 setV ( CVertex ( getVx ( ) , k , getVz ( ) ) ) ;
00483 }
00484
00485 void dialogHomothetie :: setVz ( TCoordinate k )
00486 {
00487 setV ( CVertex ( getVx ( ) , getVy ( ) , k ) ) ;
00488 }
00489
00490 void dialogHomothetie :: setKx ( TCoordinate k )
00491 {
00492 setK ( CVertex ( k , getKy ( ) , getKz ( ) ) ) ;
00493 }
00494
00495 void dialogHomothetie :: setKy ( TCoordinate k )
00496 {
00497 setK ( CVertex ( getKx ( ) , k , getKz ( ) ) ) ;
00498 }
00499
00500 void dialogHomothetie :: setKz ( TCoordinate k )
00501 {
00502 setK ( CVertex ( getKx ( ) , getKy ( ) , k ) ) ;
00503 }
00504
00505 void dialogHomothetie :: setC ( const CVertex & C )
00506 {
00507 assert ( FParent != NULL ) ;
00508 if ( C == getControler ( ) -> getObjectScaleCenter ( ) )
00509 return;
00510
00511 getControler ( ) -> setObjectScaleCenter ( C ) ;
00512 update ( ) ;
00513 }
00514
00515 void dialogHomothetie :: setV (const CVertex & V )
00516 {
00517 assert ( FParent != NULL ) ;
00518 if ( V == getControler ( ) -> getObjectScaleVector ( ) )
00519 return;
00520
00521 getControler ( ) -> setObjectScaleVector ( V ) ;
00522 update ( ) ;
00523 }
00524
00525 void dialogHomothetie :: setK ( const CVertex & K )
00526 {
00527 assert ( FParent != NULL ) ;
00528 if ( K == getControler ( ) -> getObjectScaleCoef ( ) )
00529 return;
00530
00531 getControler ( ) -> setObjectScaleCoef ( K ) ;
00532 update ( ) ;
00533 }
00534
00535 void dialogHomothetie :: setIsoCoef ( TCoordinate x )
00536 {
00537 assert ( FParent != NULL ) ;
00538 if ( x == getControler ( ) -> getObjectScaleIsoCoef ( ) )
00539 return;
00540
00541 getControler ( ) -> setObjectScaleIsoCoef ( x ) ;
00542 update ( ) ;
00543 }