00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include "CoreWidget.hh"
00055
00056 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00057 #include <OpenFlipper/common/GlobalOptions.hh>
00058 #include <OpenFlipper/widgets/snapshotDialog/SnapshotDialog.hh>
00059
00060
00061
00062
00063
00064
00065 void CoreWidget::slotToggleStereoMode()
00066 {
00067 stereoActive_ = !stereoActive_;
00068
00069 if ( stereoActive_ ) {
00070 statusBar_->showMessage(tr("Stereo enabled"));
00071 stereoButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"stereo.png") );
00072 } else {
00073 statusBar_->showMessage(tr("Stereo disabled"));
00074 stereoButton_->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"mono.png") );
00075 }
00076
00077 cursorPainter_->setEnabled (stereoActive_);
00078
00079 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00080 examiner_widgets_[i]->setStereoMode(stereoActive_);
00081 }
00082
00083 void CoreWidget::slotSetGlobalBackgroundColor() {
00084 ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0;
00085
00086 QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]);
00087 QColor c = QColorDialog::getColor(backCol,this);
00088
00089 if (c != backCol && c.isValid())
00090 for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i )
00091 PluginFunctions::viewerProperties(i).backgroundColor(ACG::Vec4f(((double) c.redF()) ,
00092 ((double) c.greenF()) ,
00093 ((double) c.blueF()) ,
00094 1.0));
00095
00096 OpenFlipperSettings().setValue("Core/Gui/glViewer/defaultBackgroundColor",c);
00097
00098 }
00099
00100 void CoreWidget::slotSetContextBackgroundColor() {
00101 ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0;
00102
00103 QColor backCol((int)bc[0], (int)bc[1], (int)bc[2], (int)bc[3]);
00104 QColor c = QColorDialog::getColor(backCol,this);
00105
00106 if (c != backCol && c.isValid())
00107 PluginFunctions::viewerProperties().backgroundColor(ACG::Vec4f(((double) c.redF()) ,
00108 ((double) c.greenF()) ,
00109 ((double) c.blueF()) ,
00110 1.0));
00111 }
00112
00113
00115 void CoreWidget::slotContextHomeView() {
00116 examiner_widgets_[PluginFunctions::activeExaminer()]->home();
00117 }
00118
00120 void CoreWidget::slotSwitchWheels(bool _state) {
00121 std::vector< glViewer* >::iterator it = examiner_widgets_.begin();
00122
00123 for(; it != examiner_widgets_.end(); it++)
00124 _state ? (*it)->slotShowWheels() : (*it)->slotHideWheels();
00125 }
00126
00128 void CoreWidget::slotSwitchNavigation(bool _egomode) {
00129 std::vector< glViewer* >::iterator it = examiner_widgets_.begin();
00130
00131 for(; it != examiner_widgets_.end(); it++) {
00132 _egomode ? (*it)->navigationMode(glViewer::FIRSTPERSON_NAVIGATION) :
00133 (*it)->navigationMode(glViewer::NORMAL_NAVIGATION);
00134 }
00135 }
00136
00138 void CoreWidget::slotGlobalHomeView() {
00139 for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
00140 examiner_widgets_[i]->home();
00141 }
00142
00144 void CoreWidget::slotContextSetHomeView() {
00145 examiner_widgets_[PluginFunctions::activeExaminer()]->setHome();
00146 }
00147
00148
00150 void CoreWidget::slotGlobalSetHomeView() {
00151 for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
00152 examiner_widgets_[i]->setHome();
00153 }
00154
00156 void CoreWidget::slotContextViewAll() {
00157 examiner_widgets_[PluginFunctions::activeExaminer()]->viewAll();
00158 }
00159
00160
00162 void CoreWidget::slotGlobalViewAll() {
00163 for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
00164 examiner_widgets_[i]->viewAll();
00165 }
00166
00168 void CoreWidget::slotContextSwitchProjection() {
00169 examiner_widgets_[PluginFunctions::activeExaminer()]->toggleProjectionMode();
00170 }
00171
00173 void CoreWidget::slotGlobalPerspectiveProjection() {
00174 for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
00175 examiner_widgets_[i]->perspectiveProjection();
00176 }
00177
00179 void CoreWidget::slotGlobalOrthographicProjection() {
00180 for ( int i = 0 ; i < PluginFunctions::viewers() ; ++i )
00181 examiner_widgets_[i]->orthographicProjection();
00182 }
00183
00185 void CoreWidget::slotGlobalChangeAnimation(bool _animation){
00186 for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00187 PluginFunctions::viewerProperties(i).animation(_animation);
00188 }
00189
00191 void CoreWidget::slotLocalChangeAnimation(bool _animation){
00192 PluginFunctions::viewerProperties().animation(_animation);
00193 }
00194
00196 void CoreWidget::slotGlobalChangeBackFaceCulling(bool _backFaceCulling){
00197 for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00198 PluginFunctions::viewerProperties(i).backFaceCulling(_backFaceCulling);
00199
00200 }
00201
00203 void CoreWidget::slotLocalChangeBackFaceCulling(bool _backFaceCulling){
00204 PluginFunctions::viewerProperties().backFaceCulling(_backFaceCulling);
00205 }
00206
00207
00209 void CoreWidget::slotGlobalChangeTwoSidedLighting(bool _lighting) {
00210 for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00211 PluginFunctions::viewerProperties(i).twoSidedLighting(_lighting);
00212 }
00213
00215 void CoreWidget::slotLocalChangeTwoSidedLighting(bool _lighting) {
00216 PluginFunctions::viewerProperties().twoSidedLighting(_lighting);
00217 }
00218
00220 void CoreWidget::slotGlobalChangeMultisampling(bool _multisampling) {
00221 for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00222 PluginFunctions::viewerProperties(i).multisampling( _multisampling );
00223 }
00224
00226 void CoreWidget::slotLocalChangeMultisampling(bool _multisampling) {
00227 PluginFunctions::viewerProperties().multisampling( _multisampling );
00228 }
00229
00231 void CoreWidget::slotSnapshot() {
00232
00233 QFileInfo fi(PluginFunctions::viewerProperties().snapshotName());
00234 int counter = PluginFunctions::viewerProperties().snapshotCounter();
00235
00236
00237 QString number = QString::number(counter);
00238 while ( number.size() < 7 )
00239 number = "0" + number;
00240
00241 QString suggest = fi.baseName() + "." + number + ".";
00242
00243 QString format="png";
00244
00245 if (fi.completeSuffix() == "ppm")
00246 format="ppmraw";
00247
00248 if (fi.completeSuffix() == "jpg")
00249 format="jpg";
00250
00251 suggest += format;
00252
00253 QFileDialog dialog(this);
00254 dialog.setFileMode(QFileDialog::AnyFile);
00255 dialog.setDefaultSuffix("png");
00256 dialog.setNameFilter(tr("Images (*.png *.ppm *.jpg)"));
00257 dialog.setFileMode(QFileDialog::AnyFile);
00258 dialog.setConfirmOverwrite(true);
00259 dialog.setDirectory( fi.path() );
00260 dialog.selectFile( suggest );
00261 dialog.setAcceptMode(QFileDialog::AcceptSave);
00262 dialog.setWindowTitle(tr("Save Snapshot"));
00263
00264 if (dialog.exec()){
00265 QString newName = dialog.selectedFiles()[0];
00266
00267 if (newName != fi.path() + OpenFlipper::Options::dirSeparator() + suggest)
00268 PluginFunctions::viewerProperties().snapshotBaseFileName(newName);
00269
00270 QImage image;
00271 examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(image);
00272
00273 image.save(newName);
00274 }
00275 }
00276
00278 void CoreWidget::applicationSnapshotDialog() {
00279
00280 QFileInfo fi(snapshotName_);
00281
00282 if (snapshotName_ == "")
00283 fi.setFile( OpenFlipperSettings().value("Core/CurrentDir").toString() + QDir::separator() + "snap.png" );
00284
00285
00286 QString number = QString::number(snapshotCounter_);
00287 while ( number.size() < 7 )
00288 number = "0" + number;
00289
00290 QString suggest = fi.path() + QDir::separator() + fi.baseName() + "." + number + ".";
00291
00292 QString format="png";
00293
00294 if (fi.completeSuffix() == "ppm")
00295 format="ppmraw";
00296
00297 if (fi.completeSuffix() == "jpg")
00298 format="jpg";
00299
00300 suggest += format;
00301
00302
00303 SnapshotDialog dialog(suggest, false, 0);
00304
00305 int w = width();
00306 int h = height();
00307
00308 dialog.snapWidth->setValue(w);
00309 dialog.snapHeight->setValue(h);
00310
00311 connect(&dialog, SIGNAL(resizeApplication(int,int)), this, SIGNAL(resizeApplication(int,int)) );
00312
00313 bool ok = dialog.exec();
00314
00315 if ( ok ){
00316 QString newName = dialog.filename->text();
00317
00318 if (newName != suggest){
00319
00320 OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
00321
00322 snapshotName_ = newName;
00323 snapshotCounter_ = 1;
00324 }else
00325 snapshotCounter_++;
00326
00327 QApplication::processEvents();
00328
00329 QPixmap pic = QPixmap::grabWindow( winId() );
00330
00331 pic.save(newName);
00332 }
00333
00334 emit resizeApplication(w,h);
00335 }
00336
00338 void CoreWidget::applicationSnapshot() {
00339
00340 QFileInfo fi(snapshotName_);
00341
00342
00343 QString number = QString::number(snapshotCounter_++);
00344 while ( number.size() < 7 )
00345 number = "0" + number;
00346
00347 QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + number + ".";
00348
00349 QString format="png";
00350
00351 if (fi.completeSuffix() == "ppm")
00352 format="ppmraw";
00353
00354 if (fi.completeSuffix() == "jpg")
00355 format="jpg";
00356
00357 suggest += format;
00358
00359 QApplication::processEvents();
00360
00361 QPixmap pic = QPixmap::grabWindow( winId() );
00362
00363 pic.save(suggest);
00364 }
00365
00366
00368 void CoreWidget::viewerSnapshotDialog() {
00369
00370 QFileInfo fi(snapshotName_);
00371
00372 if (snapshotName_ == "")
00373 fi.setFile( OpenFlipperSettings().value("Core/CurrentDir").toString() + QDir::separator() + "snap.png" );
00374
00375
00376 QString number = QString::number(snapshotCounter_);
00377 while ( number.size() < 7 )
00378 number = "0" + number;
00379
00380 QString suggest = fi.path() + QDir::separator() + fi.baseName() + "." + number + ".";
00381
00382 QString format="png";
00383
00384 if (fi.completeSuffix() == "ppm")
00385 format="ppmraw";
00386
00387 if (fi.completeSuffix() == "jpg")
00388 format="jpg";
00389
00390 suggest += format;
00391
00392 SnapshotDialog dialog(suggest, true, 0);
00393
00394 int w = glView_->width();
00395 int h = glView_->height();
00396
00397 dialog.snapWidth->setValue(w);
00398 dialog.snapHeight->setValue(h);
00399
00400 connect(&dialog, SIGNAL(resizeViewers(int,int)), this, SIGNAL(resizeViewers(int,int)) );
00401
00402 bool ok = dialog.exec();
00403
00404 if (ok){
00405 QString newName = dialog.filename->text();
00406
00407 if (newName != suggest){
00408
00409 OpenFlipperSettings().setValue("Core/CurrentDir", QFileInfo(newName).absolutePath() );
00410
00411 snapshotName_ = newName;
00412 snapshotCounter_ = 1;
00413
00414 }else
00415 snapshotCounter_++;
00416
00417
00418 switch ( baseLayout_->mode() ){
00419
00420 case QtMultiViewLayout::SingleView:
00421 {
00422 QImage finalImage;
00423
00424 examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage);
00425
00426 finalImage.save(newName);
00427
00428 break;
00429 }
00430 case QtMultiViewLayout::Grid:
00431 {
00432 QImage img0,img1,img2,img3;
00433
00434 examiner_widgets_[0]->snapshot(img0);
00435 examiner_widgets_[1]->snapshot(img1);
00436 examiner_widgets_[2]->snapshot(img2);
00437 examiner_widgets_[3]->snapshot(img3);
00438
00439 QImage finalImage(img0.width() + img1.width()+2, img0.height() + img2.height()+2, QImage::Format_ARGB32_Premultiplied);
00440
00441 QPainter painter(&finalImage);
00442
00443 painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));
00444
00445 painter.drawImage(QRectF( 0, 0, img0.width(), img0.height()),img0,
00446 QRectF( 0, 0, img0.width(), img0.height()) );
00447 painter.drawImage(QRectF(img0.width()+2, 0, img1.width(), img1.height()),img1,
00448 QRectF( 0, 0, img1.width(), img1.height()) );
00449 painter.drawImage(QRectF( 0,img0.height()+2, img2.width(), img2.height()),img2,
00450 QRectF( 0, 0, img2.width(), img2.height()) );
00451 painter.drawImage(QRectF(img0.width()+2, img0.height()+2, img3.width(), img3.height()),img3,
00452 QRectF( 0, 0, img3.width(), img3.height()) );
00453
00454 finalImage.save(newName);
00455
00456 break;
00457 }
00458 case QtMultiViewLayout::HSplit:
00459 {
00460 QImage img0,img1,img2,img3;
00461
00462 examiner_widgets_[0]->snapshot(img0);
00463 examiner_widgets_[1]->snapshot(img1);
00464 examiner_widgets_[2]->snapshot(img2);
00465 examiner_widgets_[3]->snapshot(img3);
00466
00467 QImage finalImage(img0.width() + img1.width() +2, img0.height(), QImage::Format_ARGB32_Premultiplied);
00468
00469 QPainter painter(&finalImage);
00470
00471 painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));
00472
00473 painter.drawImage(QRectF( 0, 0, img0.width(), img0.height()),img0,
00474 QRectF( 0, 0, img0.width(), img0.height()) );
00475 painter.drawImage(QRectF(img0.width()+2, 0, img1.width(), img1.height()),img1,
00476 QRectF( 0, 0, img1.width(), img1.height()) );
00477 painter.drawImage(QRectF(img0.width()+2, img1.height()+2, img2.width(), img2.height()),img2,
00478 QRectF( 0, 0, img2.width(), img2.height()) );
00479 painter.drawImage(QRectF(img0.width()+2, img1.height()+img2.height()+4, img3.width(),img3.height()),img3,
00480 QRectF( 0, 0, img3.width(), img3.height()) );
00481
00482 finalImage.save(newName);
00483
00484 break;
00485 }
00486 default: break;
00487
00488 }
00489 }
00490 glView_->resize(w, h);
00491 }
00492
00494 void CoreWidget::viewerSnapshot() {
00495
00496 QFileInfo fi(snapshotName_);
00497
00498
00499 QString number = QString::number(snapshotCounter_++);
00500 while ( number.size() < 7 )
00501 number = "0" + number;
00502
00503 QString suggest = fi.path() + QDir::separator() +fi.baseName() + "." + number + ".";
00504
00505 QString format="png";
00506
00507 if (fi.completeSuffix() == "ppm")
00508 format="ppmraw";
00509
00510 if (fi.completeSuffix() == "jpg")
00511 format="jpg";
00512
00513 suggest += format;
00514
00515
00516 switch ( baseLayout_->mode() ){
00517
00518 case QtMultiViewLayout::SingleView:
00519 {
00520 QImage finalImage;
00521
00522 examiner_widgets_[PluginFunctions::activeExaminer()]->snapshot(finalImage);
00523
00524 finalImage.save(suggest);
00525
00526 break;
00527 }
00528 case QtMultiViewLayout::Grid:
00529 {
00530 QImage img0,img1,img2,img3;
00531
00532 examiner_widgets_[0]->snapshot(img0);
00533 examiner_widgets_[1]->snapshot(img1);
00534 examiner_widgets_[2]->snapshot(img2);
00535 examiner_widgets_[3]->snapshot(img3);
00536
00537 QImage finalImage(img0.width() + img1.width() + 2, img0.height() + img2.height() + 2, QImage::Format_ARGB32_Premultiplied);
00538
00539 QPainter painter(&finalImage);
00540
00541 painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));
00542
00543 painter.drawImage(QRectF( 0, 0, img0.width(), img0.height()),img0,
00544 QRectF( 0, 0, img0.width(), img0.height()) );
00545 painter.drawImage(QRectF(img0.width()+2, 0, img1.width(), img1.height()),img1,
00546 QRectF( 0, 0, img1.width(), img1.height()) );
00547 painter.drawImage(QRectF( 0, img0.height()+2, img2.width(), img2.height()),img2,
00548 QRectF( 0, 0, img2.width(), img2.height()) );
00549 painter.drawImage(QRectF(img0.width()+2, img0.height()+2, img3.width(), img3.height()),img3,
00550 QRectF( 0, 0, img3.width(), img3.height()) );
00551
00552 finalImage.save(suggest);
00553
00554 break;
00555 }
00556 case QtMultiViewLayout::HSplit:
00557 {
00558 QImage img0,img1,img2,img3;
00559
00560 examiner_widgets_[0]->snapshot(img0);
00561 examiner_widgets_[1]->snapshot(img1);
00562 examiner_widgets_[2]->snapshot(img2);
00563 examiner_widgets_[3]->snapshot(img3);
00564
00565 QImage finalImage(img0.width() + img1.width() + 2, img0.height(), QImage::Format_ARGB32_Premultiplied);
00566
00567 QPainter painter(&finalImage);
00568
00569 painter.fillRect(0,0,finalImage.width(), finalImage.height(), QBrush(Qt::gray));
00570
00571 painter.drawImage(QRectF( 0, 0, img0.width(), img0.height()),img0,
00572 QRectF( 0, 0, img0.width(), img0.height()) );
00573 painter.drawImage(QRectF(img0.width()+2, 0, img1.width(), img1.height()),img1,
00574 QRectF( 0, 0, img1.width(), img1.height()) );
00575 painter.drawImage(QRectF(img0.width()+2, img1.height()+2, img2.width(), img2.height()),img2,
00576 QRectF( 0, 0, img2.width(), img2.height()) );
00577 painter.drawImage(QRectF(img0.width()+2, img1.height()+img2.height()+4, img3.width(),img3.height()),img3,
00578 QRectF( 0, 0, img3.width(), img3.height()) );
00579
00580 finalImage.save(suggest);
00581
00582 break;
00583 }
00584 default: break;
00585
00586 }
00587 }
00588
00589 void CoreWidget::applicationSnapshotName(QString _name) {
00590
00591 snapshotName_ = _name;
00592 snapshotCounter_ = 0;
00593 }
00594
00595
00596 void CoreWidget::slotPasteView( ) {
00597 examiner_widgets_[PluginFunctions::activeExaminer()]->actionPasteView();
00598 }
00599
00600 void CoreWidget::slotCopyView( ) {
00601 examiner_widgets_[PluginFunctions::activeExaminer()]->actionCopyView();
00602 }
00603
00604 void CoreWidget::slotCoordSysVisibility(bool _visible){
00605
00606 ACG::SceneGraph::BaseNode* root = PluginFunctions::getSceneGraphRootNode();
00607 ACG::SceneGraph::BaseNode* coordSys = root->find("Core Coordsys Node");
00608
00609 if (coordSys == 0){
00610 emit log( LOGERR, tr("CoordSys Node not found"));
00611 return;
00612 }
00613
00614 if (_visible)
00615 coordSys->show();
00616 else
00617 coordSys->hide();
00618
00619 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
00620 examiner_widgets_[i]->updateGL();
00621
00622 }
00623
00624 void CoreWidget::slotSetViewingDirection(QAction* _action) {
00625
00626 PluginFunctions::setFixedView( _action->data().toInt() );
00627 }
00628
00629 void CoreWidget::moveBack() {
00630 examiner_widgets_[PluginFunctions::activeExaminer()]->moveBack();
00631 }
00632
00633 void CoreWidget::moveForward() {
00634 examiner_widgets_[PluginFunctions::activeExaminer()]->moveForward();
00635 }
00636
00637 void CoreWidget::strafeLeft() {
00638 examiner_widgets_[PluginFunctions::activeExaminer()]->strafeLeft();
00639 }
00640
00641 void CoreWidget::strafeRight() {
00642 examiner_widgets_[PluginFunctions::activeExaminer()]->strafeRight();
00643 }
00644
00645