ContextMenu.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8549 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:38 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 //=============================================================================
00046 //
00047 //  CLASS CoreWidget - IMPLEMENTATION
00048 //
00049 //=============================================================================
00050 
00051 
00052 //== INCLUDES =================================================================
00053 
00054 // -------------------- mview
00055 #include "CoreWidget.hh"
00056 
00057 #include <OpenFlipper/BasePlugin/PluginFunctions.hh>
00058 #include <OpenFlipper/common/GlobalOptions.hh>
00059 #include "../../common/GlobalOptions.hh"
00060 
00061 //== IMPLEMENTATION ==========================================================
00062 
00063 void CoreWidget::slotCustomContextMenu( const QPoint& _point ) {
00064 
00065   QPoint   popupPosition;
00066   QPoint   scenePos;
00067 
00068   // Calculate popup position. Use the position from the viewer which was clicked on.
00069   popupPosition =  examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point);
00070   QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y()));
00071   scenePos = QPoint (f.x(), f.y());
00072 
00073   // Call function to adapt the menu to the currently used contex.
00074   updatePopupMenu(scenePos);
00075 
00076   // If the menu is not correctly initialized, dont try to show it.
00077   if ( !contextMenu_->isEmpty () )
00078     contextMenu_->popup( popupPosition );
00079 
00080 }
00081 
00090 void CoreWidget::updatePopupMenuNode(QMenu* _menu , ACG::SceneGraph::BaseNode* _node) {
00091 
00092   QString nodeName = QString(_node->name().c_str());
00093   QAction* typeEntry = new QAction( nodeName ,_menu );
00094   _menu->addAction( typeEntry );
00095 
00096   _menu->addSeparator();
00097 
00098   emit updateContextMenuNode(_node->id());
00099 
00100   addContextMenus( _menu , CONTEXTNODEMENU, _node->id() ) ;
00101 }
00102 
00112 void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu  , const int /*_part*/) {
00113 //   std::cerr << "Coordsys part was : " << _part << std::endl;
00114   QAction* typeEntry = new QAction(tr("Viewer Settings"),_menu);
00115   _menu->addAction( typeEntry );
00116   _menu->addSeparator();
00117 
00118   //====================================================================================================
00119   // DrawModes
00120   //====================================================================================================
00121   slotUpdateViewerDrawMenu();
00122   _menu->addMenu( viewerDrawMenu_ );
00123 
00124   //====================================================================================================
00125   // RenderingOptions
00126   //====================================================================================================
00127 
00128   QMenu* renderingOptionsMenu = new QMenu(tr("Rendering Options"),_menu);
00129   renderingOptionsMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"core_renderingOptions.png") );
00130   _menu->addMenu(renderingOptionsMenu);
00131 
00132   QAction* projectionAction = 0;
00133   if ( examiner_widgets_[PluginFunctions::activeExaminer() ]->projectionMode() == glViewer::PERSPECTIVE_PROJECTION ) {
00134     projectionAction = new QAction( tr("Switch to Orthogonal Projection"), renderingOptionsMenu );
00135     projectionAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00136     projectionAction->setToolTip(   tr("Switch to perspective orthogonal mode."));
00137   } else {
00138     projectionAction = new QAction( tr("Switch to Perspective Projection"), renderingOptionsMenu );
00139     projectionAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"perspective.png") );
00140     projectionAction->setToolTip(   tr("Switch to perspective projection mode."));
00141   }
00142 
00143   projectionAction->setCheckable( false );
00144   projectionAction->setToolTip(   tr("Switch between <b>perspective</b> and "
00145       "<b>parrallel</b> projection mode."));
00146   projectionAction->setWhatsThis( tr("Switch projection modes<br><br>"
00147       "Switch between <b>perspective</b> and "
00148       "<b>parrallel</b> projection mode."));
00149   connect( projectionAction,SIGNAL( triggered() ), this, SLOT( slotContextSwitchProjection() ) );
00150   renderingOptionsMenu->addAction( projectionAction );
00151 
00152 
00153   QAction* animation = renderingOptionsMenu->addAction(tr("Animation"));
00154 
00155   animation->setToolTip(tr("Animate rotation of objects"));
00156   animation->setCheckable( true );
00157   animation->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"animation.png") );
00158   animation->setChecked( PluginFunctions::viewerProperties(PluginFunctions::activeExaminer()).animation() );
00159   connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeAnimation(bool) ) );
00160 
00161 
00162   //====================================================================================================
00163 
00164   QAction* backfaceCulling = renderingOptionsMenu->addAction(tr("Backface Culling"));
00165   backfaceCulling->setToolTip(tr("Enable backface culling"));
00166   backfaceCulling->setCheckable( true );
00167   backfaceCulling->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"backFaceCulling.png") );
00168   backfaceCulling->setChecked( PluginFunctions::viewerProperties().backFaceCulling() );
00169   connect(backfaceCulling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeBackFaceCulling(bool) ) );
00170 
00171   //====================================================================================================
00172 
00173   QAction* twoSidedLighting = renderingOptionsMenu->addAction(tr("Two-sided Lighting"));
00174   twoSidedLighting->setToolTip(tr("Enable two-sided lighting"));
00175   twoSidedLighting->setCheckable( true );
00176   twoSidedLighting->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"twosidedLighting.png") );
00177   twoSidedLighting->setChecked( PluginFunctions::viewerProperties().twoSidedLighting() );
00178   connect(twoSidedLighting, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeTwoSidedLighting(bool) ) );
00179   
00180   //====================================================================================================
00181 
00182   QAction* multisampling = renderingOptionsMenu->addAction(tr("Multisampling"));
00183   multisampling->setToolTip(tr("Enable Multisampling"));
00184   multisampling->setCheckable( true );
00185   multisampling->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiSampling.png") );
00186   multisampling->setChecked( PluginFunctions::viewerProperties().multisampling() );
00187   connect(multisampling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeMultisampling(bool) ) );   
00188 
00189 
00190   //============================================================================================================
00191   // Viewing Direction Menu
00192   //============================================================================================================
00193 
00194   QMenu* viewingDirectionMenu = new QMenu( tr("Viewing Direction"), _menu);
00195 //   viewingDirectionMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"renderingOptions.png"));
00196   _menu->addMenu(viewingDirectionMenu);
00197 
00198   QActionGroup* dirGroup = new QActionGroup(this);
00199 
00200   QAction* viewAction;
00201   // freeView
00202   viewAction = new QAction( tr("Free View"), viewingDirectionMenu );
00203 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00204   viewAction->setCheckable( true );
00205   viewAction->setData( PluginFunctions::VIEW_FREE );
00206   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_FREE );
00207   viewingDirectionMenu->addAction( viewAction );
00208   dirGroup->addAction(viewAction);
00209   viewingDirectionMenu->addSeparator();
00210   // TOP
00211   viewAction = new QAction( tr("Top View"), viewingDirectionMenu );
00212 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00213   viewAction->setCheckable( true );
00214   viewAction->setData( PluginFunctions::VIEW_TOP );
00215   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_TOP );
00216   viewingDirectionMenu->addAction( viewAction );
00217   dirGroup->addAction(viewAction);
00218   // BOTTOM
00219   viewAction = new QAction( tr("Bottom View"), viewingDirectionMenu );
00220 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00221   viewAction->setCheckable( true );
00222   viewAction->setData( PluginFunctions::VIEW_BOTTOM );
00223   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BOTTOM );
00224   viewingDirectionMenu->addAction( viewAction );
00225   dirGroup->addAction(viewAction);
00226   // LEFT
00227   viewAction = new QAction( tr("Left View"), viewingDirectionMenu );
00228 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00229   viewAction->setCheckable( true );
00230   viewAction->setData( PluginFunctions::VIEW_LEFT );
00231   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_LEFT );
00232   viewingDirectionMenu->addAction( viewAction );
00233   dirGroup->addAction(viewAction);
00234   // RIGHT
00235   viewAction = new QAction( tr("Right View"), viewingDirectionMenu );
00236 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00237   viewAction->setCheckable( true );
00238   viewAction->setData( PluginFunctions::VIEW_RIGHT );
00239   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_RIGHT );
00240   viewingDirectionMenu->addAction( viewAction );
00241   dirGroup->addAction(viewAction);
00242   // FRONT
00243   viewAction = new QAction( tr("Front View"), viewingDirectionMenu );
00244 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00245   viewAction->setCheckable( true );
00246   viewAction->setData( PluginFunctions::VIEW_FRONT );
00247   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_FRONT );
00248   viewingDirectionMenu->addAction( viewAction );
00249   dirGroup->addAction(viewAction);
00250   // BACK
00251   viewAction = new QAction( tr("Back View"), viewingDirectionMenu );
00252 //   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
00253   viewAction->setCheckable( true );
00254   viewAction->setData( PluginFunctions::VIEW_BACK );
00255   viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BACK );
00256   viewingDirectionMenu->addAction( viewAction );
00257   dirGroup->addAction(viewAction);
00258 
00259   connect( dirGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSetViewingDirection(QAction*) ) );
00260 
00261   //====================================================================================================
00262   // Other Toplevel Action
00263   //====================================================================================================
00264 
00265   _menu->addSeparator();
00266 
00267   //====================================================================================================
00268 
00269   QAction* homeAction = new QAction(tr("Restore home view"),_menu);
00270   homeAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"go-home.png") );
00271   homeAction->setCheckable( false );
00272   homeAction->setToolTip(tr("Restore <b>home</b> view."));
00273   homeAction->setWhatsThis( tr("Restore home view<br><br>"
00274                             "Resets the view to the home view"));
00275   _menu->addAction( homeAction );
00276   connect( homeAction,SIGNAL( triggered() ), this, SLOT( slotContextHomeView() ) );
00277 
00278   QAction* setHomeAction = new QAction( tr("Set Home View") , _menu );
00279   setHomeAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"set-home.png") );
00280   setHomeAction->setCheckable( false );
00281   setHomeAction->setToolTip(tr("Set <b>home</b> view"));
00282   setHomeAction->setWhatsThis( tr("Store home view<br><br>"
00283                                "Stores the current view as the home view"));
00284   _menu->addAction( setHomeAction);
00285   connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotContextSetHomeView() ) );
00286 
00287   QAction* viewAllAction = new QAction( tr("View all"), _menu );
00288   viewAllAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"viewall.png") );
00289   viewAllAction->setCheckable( false );
00290   viewAllAction->setToolTip(tr("View all."));
00291   viewAllAction->setWhatsThis( tr("View all<br><br>"
00292                                   "Move the objects in the scene so that"
00293                                   " the whole scene is visible."));
00294   connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotContextViewAll() ) );
00295   _menu->addAction( viewAllAction);
00296 
00297 
00298   _menu->addSeparator();
00299 
00300   //====================================================================================================
00301 
00302   QAction* copyView = _menu->addAction(tr("Copy View"));
00303   copyView->setToolTip(tr("Copy current view to clipboard"));
00304   copyView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png") );
00305   connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );
00306 
00307   //====================================================================================================
00308 
00309   QAction* pasteView = _menu->addAction(tr("Paste View"));
00310   pasteView->setToolTip(tr("Paste current view from clipboard"));
00311   pasteView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-paste.png") );
00312   connect(pasteView, SIGNAL(triggered()), this , SLOT( slotPasteView( ) ) );
00313 
00314   //====================================================================================================
00315 
00316   QAction* snapshot = _menu->addAction(tr("Snapshot"));
00317   snapshot->setToolTip(tr("Make a snapshot"));
00318   snapshot->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
00319   connect(snapshot, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) );
00320 
00321 }
00322 
00332 void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& /*_point*/) {
00333 
00334   //====================================================================================================
00335   // DrawModes
00336   //====================================================================================================
00337   slotUpdateViewerDrawMenu();
00338   _menu->addMenu( viewerDrawMenu_ );
00339 
00340   _menu->addSeparator();
00341 
00342   QAction* action = _menu->addAction(tr("Set Background Color"));
00343   action->setToolTip(tr("Set the background color for the current viewer"));
00344   action->setStatusTip(tr("Set the background color for the current viewer"));
00345   action->setWhatsThis(tr("Set the background color for the current viewer"));
00346   action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
00347   connect(action, SIGNAL(triggered()), this, SLOT(slotSetContextBackgroundColor()) );
00348 
00349   /*
00350    * Show coordsys context menu of coordsys if
00351    * invisible...
00352    */
00353 
00354   ACG::SceneGraph::BaseNode* root = PluginFunctions::getSceneGraphRootNode();
00355   ACG::SceneGraph::BaseNode* coordSys = root->find("Core Coordsys Node");
00356 
00357   if(!coordSys->visible()) {
00358 
00359           if(!coordSysMenu_) {
00360                   coordSysMenu_ = new QMenu(tr("Viewer Settings"), _menu);
00361                   updatePopupMenuCoordsysNode(coordSysMenu_, 0);
00362           }
00363           _menu->addSeparator();
00364           _menu->addMenu(coordSysMenu_);
00365   }
00366 
00367   // Tell Plugins to update their context Menu
00368   emit updateContextMenuBackground();
00369 
00370   addContextMenus( _menu , CONTEXTBACKGROUNDMENU ) ;
00371 
00372 }
00373 
00382 void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) {
00383 
00384   QAction* typeEntry = new QAction( typeName(_object->dataType()) ,_menu);
00385   typeEntry->setIcon(typeIcon(_object->dataType()));
00386   _menu->addAction( typeEntry );
00387 
00388   _menu->addSeparator( );
00389 
00390   // Tell Plugins to update their context Menu
00391   emit updateContextMenu(_object->id() );
00392 
00393   if ( addContextMenus( _menu , CONTEXTOBJECTMENU , _object->id() ) )
00394     _menu->addSeparator();
00395 
00396   // Add picking Menu
00397   if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) {
00398     pickMenu_->setTitle(tr("&Picking"));
00399     contextMenu_->addMenu( pickMenu_ );
00400     pickMenu_->setTearOffEnabled(true);
00401   }
00402 }
00403 
00404 bool CoreWidget::addContextMenus( QMenu* _menu , ContextMenuType _type , int _id ) {
00405 
00406   bool added = false;
00407 
00408   QMap< QString , QAction* > menuMap; //QMap sorts by key
00409   QMap< QString , QAction* > actionMap;
00410 
00411   // Add context menus from plugins
00412   for ( uint i = 0 ; i < contextMenus_.size(); ++i ) {
00413 
00414     if ( contextMenus_[i].type != _type )
00415       continue;
00416 
00417     switch (contextMenus_[i].type) {
00418       case CONTEXTBACKGROUNDMENU:
00419         break;
00420       case CONTEXTOBJECTMENU:
00421         BaseObjectData* object;
00422         if ( !PluginFunctions::getObject(_id, object) ) {
00423           emit log(LOGERR,tr("Cant get object for objectContextMenu"));
00424           continue;
00425         }
00426 
00427         // Datatype does not match
00428         if ( ! object->dataType(  contextMenus_[i].contextType ) )
00429           continue;
00430 
00431         break;
00432       case CONTEXTNODEMENU:
00433         break;
00434 
00435     }
00436 
00437     QMenu* menu = contextMenus_[i].action->menu();
00438 
00439     if (menu == 0) //is it a menu
00440       actionMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
00441     else
00442       menuMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
00443 
00444     added = true;
00445 
00446     // Get all Actions in the menu and its submenus.
00447     // Set their data to the picked Object id
00448 
00449 
00450     QList< QAction *> allActions;
00451     if ( menu == 0) {
00452       allActions.push_back(contextMenus_[i].action);
00453     } else {
00454       allActions = menu->actions();
00455     }
00456 
00457     while ( !allActions.empty() ) {
00458       QList< QAction *> tmpList;
00459 
00460       // Set userdata of all actions to the picked Object Id
00461       for ( int j = 0 ; j < allActions.size(); ++j ) {
00462         allActions[j]->setData( QVariant( _id ) );
00463         if ( allActions[j]->menu() != 0 )
00464           tmpList << allActions[j]->menu()->actions();
00465       }
00466 
00467       allActions = tmpList;
00468     }
00469 
00470   }
00471 
00472   //first add all menus
00473   QMapIterator<QString, QAction*> it(menuMap);
00474 
00475   while (it.hasNext()) {
00476      it.next();
00477     _menu->addAction( it.value() );
00478   }
00479 
00480   _menu->addSeparator();
00481 
00482   //then all actions
00483   QMapIterator<QString, QAction*> it2(actionMap);
00484 
00485   while (it2.hasNext()) {
00486      it2.next();
00487     _menu->addAction( it2.value() );
00488   }
00489 
00490   return added;
00491 }
00492 
00493 
00494 
00501 void CoreWidget::updatePopupMenu(const QPoint& _point) {
00502 
00503   // Clear the complete context menu.
00504   contextMenu_->clear();
00505 
00506   // Clear the selection context menu part.
00507   contextSelectionMenu_->clear();
00508 
00509   // =============================================================================
00510   // First do a picking on the current position to check which context we are in.
00511   // =============================================================================
00512   int objectId = -1;
00513 
00514   enum CONTEXTTYPE {
00515     COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT, NODECONTEXT
00516   } context = BACKGROUNDCONTEXT;
00517 
00518   // Do picking in the gl area to find an object
00519   unsigned int               node_idx, target_idx;
00520   ACG::Vec3d                 hit_point;
00521   BaseObjectData*            object;
00522   ACG::SceneGraph::BaseNode* node = 0;
00523 
00524   if (examiner_widgets_[PluginFunctions::activeExaminer()]->pick( ACG::SceneGraph::PICK_ANYTHING,_point,node_idx, target_idx, &hit_point ) ) {
00525 
00526     if ( PluginFunctions::getPickedObject(node_idx, object) ) {
00527       objectId = object->id();
00528       context  = OBJECTCONTEXT;
00529     } else {
00530       node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode() , node_idx );
00531       if ( node != 0 && ( node->name() == "Core Coordsys Node") )
00532         context = COORDSYSCONTEXT;
00533       else
00534         context = NODECONTEXT;
00535     }
00536   }
00537 
00538   // =============================================================================
00539   // Depending on the context create the basic context menu.
00540   // =============================================================================
00541 
00542   QIcon icon;
00543 
00544   switch (context) {
00545     case BACKGROUNDCONTEXT:
00546       updatePopupMenuBackground(contextMenu_,_point);
00547       return;
00548       break;
00549     case OBJECTCONTEXT:
00550       updatePopupMenuObject(contextMenu_ , object );
00551       return;
00552       break;
00553     case COORDSYSCONTEXT:
00554       updatePopupMenuCoordsysNode(contextMenu_,target_idx);
00555       return;
00556       break;
00557     case NODECONTEXT:
00558       updatePopupMenuNode(contextMenu_,node);
00559       return;
00560       break;
00561   }
00562 
00563 }
00564 
00565 
00566 void CoreWidget::slotSnapshotName() {
00567   std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
00568 
00569   QString fname = PluginFunctions::viewerProperties().snapshotName();
00570 
00571   fname.replace('%', '$');
00572   fname = QFileDialog::getSaveFileName ( 0, tr("Save snapshot name") );
00573   if (!fname.isEmpty())
00574   {
00575     fname.replace('$', '%');
00576 
00577     PluginFunctions::viewerProperties().snapshotBaseFileName(fname);
00578     QString msg=tr("next snapshot: ");
00579     statusBar()->showMessage(msg);
00580   }
00581 
00582 }
00583 
00584 void CoreWidget::slotAddContextItem(QAction* _entry, ContextMenuType _type) {
00585   MenuInfo info;
00586   info.action = _entry;
00587   info.type   = _type;
00588 
00589   contextMenus_.push_back(info);
00590 }
00591 
00592 void CoreWidget::slotAddContextItem( QAction* _entry , DataType _dataType ,ContextMenuType _type ) {
00593   MenuInfo info;
00594   info.action      = _entry;
00595   info.contextType = _dataType;
00596   info.type        = _type;
00597 
00598   contextMenus_.push_back(info);
00599 }
00600 
00601 void CoreWidget::slotUpdateViewerDrawMenu() {
00602   if ( drawGroupViewer_ ) {
00603 
00604     disconnect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
00605                 this             , SLOT( slotViewerDrawMenu( QAction * ) ) );
00606     delete( drawGroupViewer_ );
00607     drawGroupViewer_ = 0;
00608 
00609   }
00610 
00611   // Recreate drawGroup
00612   drawGroupViewer_ = new QActionGroup( this );
00613   drawGroupViewer_->setExclusive( false );
00614 
00615   connect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
00616            this       , SLOT( slotViewerDrawMenu( QAction * ) ) );
00617 
00618   if ( !viewerDrawMenu_ ) {
00619 
00620     QIcon icon;
00621     icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
00622     viewerDrawMenu_  = new QMenu(tr("Set Draw Mode"));
00623     viewerDrawMenu_->setTearOffEnabled(true);
00624     viewerDrawMenu_->setIcon(icon);
00625 
00626     connect(viewerDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
00627   }
00628 
00629   // Collect available draw modes
00630   // Single pass action, draw modes independent from multipass rendering
00631   ACG::SceneGraph::CollectDrawModesAction actionAvailable;
00632   ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
00633   availableGlobalDrawModes_ = actionAvailable.drawModes();
00634 
00635   // Get currently active drawModes (first viewer only )
00636   // TODO: create combination from all viewers!
00637   ACG::SceneGraph::DrawModes::DrawMode activeDrawModes = PluginFunctions::drawMode();
00638 
00639   // Convert to ids
00640   std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
00641   availDrawModeIds = availableGlobalDrawModes_.getAtomicDrawModes() ;
00642 
00643   viewerDrawMenu_->clear();
00644 
00645   for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
00646   {
00647     ACG::SceneGraph::DrawModes::DrawMode id    = availDrawModeIds[i];
00648     std::string  descr =  id.description();
00649 
00650     QAction * action = new QAction( descr.c_str(), drawGroupViewer_ );
00651     action->setCheckable( true );
00652     action->setChecked(  activeDrawModes.containsAtomicDrawMode(id) );
00653   }
00654 
00655   viewerDrawMenu_->addActions( drawGroupViewer_->actions() );
00656 
00657 }
00658 
00659 void CoreWidget::slotViewerDrawMenu(QAction * _action) {
00660 
00661   //======================================================================================
00662   // Get the mode toggled
00663   //======================================================================================
00664   ACG::SceneGraph::DrawModes::DrawMode mode = 0;
00665   std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
00666   availDrawModeIds = availableGlobalDrawModes_.getAtomicDrawModes();
00667   for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
00668   {
00669     QString descr = QString(  availDrawModeIds[i].description().c_str() );
00670 
00671     if ( descr == _action->text() ) {
00672       mode = availDrawModeIds[i];
00673       break;
00674     }
00675   }
00676 
00677   if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
00678     PluginFunctions::viewerProperties().drawMode(  PluginFunctions::viewerProperties().drawMode() ^ mode );
00679   else
00680     PluginFunctions::viewerProperties().drawMode(mode );
00681 
00682 }
00683 
00684 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .