Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ContextMenu.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openflipper.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenFlipper. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41 
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 //=============================================================================
53 //
54 // CLASS CoreWidget - IMPLEMENTATION
55 //
56 //=============================================================================
57 
58 
59 //== INCLUDES =================================================================
60 
61 // -------------------- mview
62 #include "CoreWidget.hh"
63 
64 //== IMPLEMENTATION ==========================================================
65 
66 void CoreWidget::slotCustomContextMenu( const QPoint& _point ) {
67 
68  QPoint popupPosition;
69  QPoint scenePos;
70 
71  // Calculate popup position. Use the position from the viewer which was clicked on.
72  popupPosition = examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point);
73  QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y()));
74  scenePos = QPoint (f.x(), f.y());
75 
76  // Call function to adapt the menu to the currently used contex.
77  updatePopupMenu(scenePos);
78 
79  // If the menu is not correctly initialized, dont try to show it.
80  if ( !contextMenu_->isEmpty () )
81  contextMenu_->popup( popupPosition );
82 
83 }
84 
86  contextMenu_->hide();
87 }
88 
98 
99  QString nodeName = QString(_node->name().c_str());
100  QAction* typeEntry = new QAction( nodeName ,_menu );
101  _menu->addAction( typeEntry );
102 
103  _menu->addSeparator();
104 
105  emit updateContextMenuNode(_node->id());
106 
107  addContextMenus( _menu , CONTEXTNODEMENU, _node->id() ) ;
108 }
109 
119 void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu , const int /*_part*/) {
120 
121  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
122 
123  QAction* typeEntry = new QAction(tr("Viewer Settings"),_menu);
124  _menu->addAction( typeEntry );
125  typeEntry->setDisabled(true);
126  _menu->addSeparator();
127 
128  QAction* orthogonalCoordsys = 0;
130  orthogonalCoordsys = new QAction( tr("Switch to Orthogonal coordinate system"), _menu );
131  orthogonalCoordsys->setIcon( QIcon(iconPath+"orthogonal.png") );
132  } else {
133  orthogonalCoordsys = new QAction( tr("Switch to Perspective coordinate system"), _menu );
134  orthogonalCoordsys->setIcon( QIcon(iconPath+"perspective.png") );
135  }
136  connect( orthogonalCoordsys,SIGNAL( triggered() ), this, SLOT( slotContextSwitchCoordsysProjection() ) );
137  _menu->addAction(orthogonalCoordsys);
138 
139  //====================================================================================================
140  // DrawModes
141  //====================================================================================================
143  if (! viewerDrawMenu_->isEmpty())
144  _menu->addMenu( viewerDrawMenu_ );
145 
146  //====================================================================================================
147  // RenderingOptions
148  //====================================================================================================
149 
150  QMenu* renderingOptionsMenu = new QMenu(tr("Rendering Options"),_menu);
151  renderingOptionsMenu->setIcon( QIcon(iconPath+"core_renderingOptions.png") );
152  _menu->addMenu(renderingOptionsMenu);
153 
154  QAction* projectionAction = 0;
156  projectionAction = new QAction( tr("Switch to Orthogonal Projection"), renderingOptionsMenu );
157  projectionAction->setIcon( QIcon(iconPath+"orthogonal.png") );
158  projectionAction->setToolTip( tr("Switch to perspective orthogonal mode."));
159  } else {
160  projectionAction = new QAction( tr("Switch to Perspective Projection"), renderingOptionsMenu );
161  projectionAction->setIcon( QIcon(iconPath+"perspective.png") );
162  projectionAction->setToolTip( tr("Switch to perspective projection mode."));
163  }
164 
165  projectionAction->setCheckable( false );
166  projectionAction->setToolTip( tr("Switch between <b>perspective</b> and "
167  "<b>parrallel</b> projection mode."));
168  projectionAction->setWhatsThis( tr("Switch projection modes<br><br>"
169  "Switch between <b>perspective</b> and "
170  "<b>parrallel</b> projection mode."));
171  connect( projectionAction,SIGNAL( triggered() ), this, SLOT( slotContextSwitchProjection() ) );
172  renderingOptionsMenu->addAction( projectionAction );
173 
174 
175  QAction* animation = renderingOptionsMenu->addAction(tr("Animation"));
176 
177  animation->setToolTip(tr("Animate rotation of objects"));
178  animation->setCheckable( true );
179  animation->setIcon( QIcon(iconPath+"animation.png") );
180  animation->setChecked( PluginFunctions::viewerProperties(PluginFunctions::activeExaminer()).animation() );
181  connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeAnimation(bool) ) );
182 
183 
184  //====================================================================================================
185 
186  QAction* backfaceCulling = renderingOptionsMenu->addAction(tr("Backface Culling"));
187  backfaceCulling->setToolTip(tr("Enable backface culling"));
188  backfaceCulling->setCheckable( true );
189  backfaceCulling->setIcon( QIcon(iconPath+"backFaceCulling.png") );
190  backfaceCulling->setChecked( PluginFunctions::viewerProperties().backFaceCulling() );
191  connect(backfaceCulling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeBackFaceCulling(bool) ) );
192 
193  //====================================================================================================
194 
195  QAction* twoSidedLighting = renderingOptionsMenu->addAction(tr("Two-sided Lighting"));
196  twoSidedLighting->setToolTip(tr("Enable two-sided lighting"));
197  twoSidedLighting->setCheckable( true );
198  twoSidedLighting->setIcon( QIcon(iconPath+"twosidedLighting.png") );
199  twoSidedLighting->setChecked( PluginFunctions::viewerProperties().twoSidedLighting() );
200  connect(twoSidedLighting, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeTwoSidedLighting(bool) ) );
201 
202  //====================================================================================================
203 
204  QAction* multisampling = renderingOptionsMenu->addAction(tr("Multisampling"));
205  multisampling->setToolTip(tr("Enable Multisampling"));
206  multisampling->setCheckable( true );
207  multisampling->setIcon( QIcon(iconPath+"multiSampling.png") );
208  multisampling->setChecked( PluginFunctions::viewerProperties().multisampling() );
209  connect(multisampling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeMultisampling(bool) ) );
210 
211  //====================================================================================================
212 
213  QAction* mipmapping = renderingOptionsMenu->addAction(tr("Mipmapping"));
214  mipmapping->setToolTip(tr("Enable Mipmapping"));
215  mipmapping->setCheckable( true );
216  mipmapping->setIcon( QIcon(iconPath+"mipmapping.png") );
217  mipmapping->setChecked( PluginFunctions::viewerProperties().mipmapping() );
218  connect(mipmapping, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeMipmapping(bool) ) );
219 
220  //============================================================================================================
221  // Renderer Menu
222  //============================================================================================================
223 
224  if ( renderManager().available() > 1 ) {
225  QMenu* rendererMenu = new QMenu(tr("Renderers"),_menu);
226  rendererMenu->setIcon(QIcon(iconPath+"renderers.png"));
227 
228  _menu->addMenu(rendererMenu);
229 
230  // Recreate actionGroup
231  QActionGroup* groupRenderer = new QActionGroup( this );
232  groupRenderer->setExclusive( true );
233 
234 
235  // Get the options action for the currently active renderer
236  if( renderManager()[ renderManager().activeId(PluginFunctions::activeExaminer() )]->optionsAction != 0 ) {
237  rendererMenu->addAction(renderManager()[ renderManager().activeId(PluginFunctions::activeExaminer() ) ]->optionsAction );
238 
239  }
240 
241  QAction* showRendererDialog = new QAction(tr("Show renderer manager"),this);
242  connect(showRendererDialog,SIGNAL(triggered()),this,SLOT(slotShowRenderManager()));
243  rendererMenu->addAction(showRendererDialog);
244 
245  QAction* showRendererObjectWidget = new QAction(tr("Show render objects"),this);
246  connect(showRendererObjectWidget,SIGNAL(triggered()),this,SLOT(slotShowRenderObjectWidget()));
247  rendererMenu->addAction(showRendererObjectWidget);
248 
249  rendererMenu->addSeparator();
250 
251  for ( unsigned int i = 0 ; i < renderManager().available() ; ++i) {
252 
253  // Add a new Action with the renderer name
254  QAction * action = new QAction( renderManager()[i]->name, groupRenderer );
255  action->setCheckable( true );
256 
257  // Check if this processor is currently active
258  if ( renderManager().activeId(PluginFunctions::activeExaminer() ) == i )
259  action->setChecked(true);
260 
261  // Remember the id for the processor
262  action->setData(QVariant(i));
263  }
264 
265  // Add all new actions from the group to the menu
266  rendererMenu->addActions( groupRenderer->actions() );
267 
268  // Connect signal of group to our managing slot
269  connect( groupRenderer , SIGNAL( triggered( QAction * ) ),
270  this , SLOT( slotRenderMenu( QAction * ) ) );
271 
272  }
273 
274  //============================================================================================================
275  // Viewing Direction Menu
276  //============================================================================================================
277 
278  QMenu* viewingDirectionMenu = new QMenu( tr("Viewing Direction"), _menu);
279  viewingDirectionMenu->setIcon(QIcon(iconPath+"core_viewingDirection.png"));
280  _menu->addMenu(viewingDirectionMenu);
281 
282  QActionGroup* dirGroup = new QActionGroup(this);
283 
284  QAction* viewAction;
285  // freeView
286  viewAction = new QAction( tr("Free View"), viewingDirectionMenu );
287  viewAction->setIcon( QIcon(iconPath+"orthogonal.png") );
288  viewAction->setCheckable( true );
289  viewAction->setData( PluginFunctions::VIEW_FREE );
290  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_FREE );
291  viewingDirectionMenu->addAction( viewAction );
292  dirGroup->addAction(viewAction);
293  viewingDirectionMenu->addSeparator();
294  // TOP
295  viewAction = new QAction( tr("Top View"), viewingDirectionMenu );
296  viewAction->setIcon( QIcon(iconPath+"viewcontrol_top.png") );
297  viewAction->setCheckable( true );
298  viewAction->setData( PluginFunctions::VIEW_TOP );
299  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_TOP );
300  viewingDirectionMenu->addAction( viewAction );
301  dirGroup->addAction(viewAction);
302  // BOTTOM
303  viewAction = new QAction( tr("Bottom View"), viewingDirectionMenu );
304  viewAction->setIcon( QIcon(iconPath+"viewcontrol_bottom.png") );
305  viewAction->setCheckable( true );
306  viewAction->setData( PluginFunctions::VIEW_BOTTOM );
307  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BOTTOM );
308  viewingDirectionMenu->addAction( viewAction );
309  dirGroup->addAction(viewAction);
310  // LEFT
311  viewAction = new QAction( tr("Left View"), viewingDirectionMenu );
312  viewAction->setIcon( QIcon(iconPath+"viewcontrol_left.png") );
313  viewAction->setCheckable( true );
314  viewAction->setData( PluginFunctions::VIEW_LEFT );
315  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_LEFT );
316  viewingDirectionMenu->addAction( viewAction );
317  dirGroup->addAction(viewAction);
318  // RIGHT
319  viewAction = new QAction( tr("Right View"), viewingDirectionMenu );
320  viewAction->setIcon( QIcon(iconPath+"viewcontrol_right.png") );
321  viewAction->setCheckable( true );
322  viewAction->setData( PluginFunctions::VIEW_RIGHT );
323  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_RIGHT );
324  viewingDirectionMenu->addAction( viewAction );
325  dirGroup->addAction(viewAction);
326  // FRONT
327  viewAction = new QAction( tr("Front View"), viewingDirectionMenu );
328  viewAction->setIcon( QIcon(iconPath+"viewcontrol_front.png") );
329  viewAction->setCheckable( true );
330  viewAction->setData( PluginFunctions::VIEW_FRONT );
331  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_FRONT );
332  viewingDirectionMenu->addAction( viewAction );
333  dirGroup->addAction(viewAction);
334  // BACK
335  viewAction = new QAction( tr("Back View"), viewingDirectionMenu );
336  viewAction->setIcon( QIcon(iconPath+"viewcontrol_back.png") );
337  viewAction->setCheckable( true );
338  viewAction->setData( PluginFunctions::VIEW_BACK );
339  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BACK );
340  viewingDirectionMenu->addAction( viewAction );
341  dirGroup->addAction(viewAction);
342 
343  viewingDirectionMenu->addSeparator();
344 
345  connect( dirGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSetViewingDirection(QAction*) ) );
346 
347  //===========================================================================
348  // Check box to determine whether rotation should be locked or not
349 
350  QAction* lockAction = viewingDirectionMenu->addAction("Lock rotation");
351  lockAction->setCheckable( true );
352  lockAction->setIcon( QIcon(iconPath+"lock_rotation.png") );
353  lockAction->setToolTip(tr("Lock rotation in current examiner"));
354  lockAction->setChecked( PluginFunctions::viewerProperties().rotationLocked() );
355  viewingDirectionMenu->addAction( lockAction );
356 
357  connect( lockAction, SIGNAL(triggered(bool)), this, SLOT(slotLockRotation(bool) ) );
358 
359  //====================================================================================================
360  // Other Toplevel Action
361  //====================================================================================================
362 
363  _menu->addSeparator();
364 
365  //====================================================================================================
366 
367  //============================================================================================================
368  // Post processor Manager
369  //============================================================================================================
370 
371  QAction* showPostProcessorDialog = new QAction(tr("Show post processor manager"),this);
372  showPostProcessorDialog->setIcon(QIcon(iconPath+"postprocessors.png"));
373  connect(showPostProcessorDialog,SIGNAL(triggered()),this,SLOT(slotShowPostProcessorManager()));
374  _menu->addAction(showPostProcessorDialog);
375 
376  _menu->addSeparator();
377 
378  //====================================================================================================
379 
380  QAction* homeAction = new QAction(tr("Restore home view"),_menu);
381  homeAction->setIcon( QIcon(iconPath+"go-home.png") );
382  homeAction->setCheckable( false );
383  homeAction->setToolTip(tr("Restore <b>home</b> view."));
384  homeAction->setWhatsThis( tr("Restore home view<br><br>"
385  "Resets the view to the home view"));
386  _menu->addAction( homeAction );
387  connect( homeAction,SIGNAL( triggered() ), this, SLOT( slotContextHomeView() ) );
388 
389  QAction* setHomeAction = new QAction( tr("Set Home View") , _menu );
390  setHomeAction->setIcon( QIcon(iconPath+"set-home.png") );
391  setHomeAction->setCheckable( false );
392  setHomeAction->setToolTip(tr("Set <b>home</b> view"));
393  setHomeAction->setWhatsThis( tr("Store home view<br><br>"
394  "Stores the current view as the home view"));
395  _menu->addAction( setHomeAction);
396  connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotContextSetHomeView() ) );
397 
398  QAction* viewAllAction = new QAction( tr("View all"), _menu );
399  viewAllAction->setIcon( QIcon(iconPath+"viewall.png") );
400  viewAllAction->setCheckable( false );
401  viewAllAction->setToolTip(tr("View all."));
402  viewAllAction->setWhatsThis( tr("View all<br><br>"
403  "Move the objects in the scene so that"
404  " the whole scene is visible."));
405  connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotContextViewAll() ) );
406  _menu->addAction( viewAllAction);
407 
408 
409  _menu->addSeparator();
410 
411  //====================================================================================================
412 
413  QAction* copyView = _menu->addAction(tr("Copy View"));
414  copyView->setToolTip(tr("Copy current view, window size and toolbar size to clipboard. Hold Ctrl to generate C/C++/JavaScipt-Style string."));
415  copyView->setIcon( QIcon(iconPath+"edit-copy.png") );
416  connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );
417 
418  //====================================================================================================
419 
420  QAction* pasteView = _menu->addAction(tr("Paste View"));
421  pasteView->setToolTip(tr("Paste current view from clipboard"));
422  pasteView->setIcon( QIcon(iconPath+"edit-paste.png") );
423  connect(pasteView, SIGNAL(triggered()), this , SLOT( slotPasteView( ) ) );
424 
425  //====================================================================================================
426 
427  QAction* pasteViewAndWindow = _menu->addAction(tr("Paste View and Window Size"));
428  pasteViewAndWindow->setToolTip(tr("Paste current view, window size and the toolbox size from clipboard"));
429  pasteViewAndWindow->setIcon( QIcon(iconPath+"edit-paste.png") );
430  connect(pasteViewAndWindow, SIGNAL(triggered()), this , SLOT( slotPasteViewAndWindow( ) ) );
431 
432  //====================================================================================================
433 
434  QAction* snapshot_examiner = _menu->addAction(tr("Examiner Snapshot"));
435  snapshot_examiner->setToolTip(tr("Take a snapshot of the current examiner"));
436  snapshot_examiner->setIcon( QIcon(iconPath+"snapshot.png") );
437  connect(snapshot_examiner, SIGNAL(triggered()), this, SLOT( slotExaminerSnapshot() ) );
438 
439  //====================================================================================================
440 
441  QAction* snapshot_viewer = _menu->addAction(tr("Viewer Snapshot"));
442  snapshot_viewer->setToolTip(tr("Take a snapshot of the whole viewer"));
443  snapshot_viewer->setIcon( QIcon(iconPath+"snapshot.png") );
444  connect(snapshot_viewer, SIGNAL(triggered()), this, SLOT( viewerSnapshotDialog() ) );
445 
446 }
447 
457 void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& /*_point*/) {
458 
459  //====================================================================================================
460  // DrawModes
461  //====================================================================================================
463  _menu->addMenu( viewerDrawMenu_ );
464 
465  _menu->addSeparator();
466 
467  QAction* action = _menu->addAction(tr("Set Background Color"));
468  action->setToolTip(tr("Set the background color for the current viewer"));
469  action->setStatusTip(tr("Set the background color for the current viewer"));
470  action->setWhatsThis(tr("Set the background color for the current viewer"));
471  action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
472  connect(action, SIGNAL(triggered()), this, SLOT(slotSetContextBackgroundColor()) );
473 
474  /*
475  * Show coordsys context menu of coordsys if
476  * invisible...
477  */
478 
480  ACG::SceneGraph::BaseNode* coordSys = root->find("Core Coordsys Node");
481 
482  if(!coordSys->visible()) {
483 
484  if(!coordSysMenu_) {
485  coordSysMenu_ = new QMenu(tr("Viewer Settings"), _menu);
487  }
488  _menu->addSeparator();
489  _menu->addMenu(coordSysMenu_);
490  }
491 
492  // Tell Plugins to update their context Menu
494 
496 
497 }
498 
507 void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) {
508 
509  QAction* typeEntry = new QAction( typeName(_object->dataType())+QString(": ")+_object->name() ,_menu);
510  typeEntry->setIcon(typeIcon(_object->dataType()));
511  _menu->addAction( typeEntry );
512 
513  _menu->addSeparator( );
514 
515  // Tell Plugins to update their context Menu
516  emit updateContextMenu(_object->id() );
517 
518  if ( addContextMenus( _menu , CONTEXTOBJECTMENU , _object->id() ) )
519  _menu->addSeparator();
520 
521  // Add picking Menu
522  if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) {
523  pickMenu_->setTitle(tr("&Picking"));
524  contextMenu_->addMenu( pickMenu_ );
525  pickMenu_->setTearOffEnabled(true);
526  }
527 }
528 
529 bool CoreWidget::addContextMenus( QMenu* _menu , ContextMenuType _type , int _id ) {
530 
531  bool added = false;
532 
533  QMap< QString , QAction* > menuMap; //QMap sorts by key
534  QMap< QString , QAction* > actionMap;
535 
536  // Add context menus from plugins
537  for ( uint i = 0 ; i < contextMenus_.size(); ++i ) {
538 
539  if ( contextMenus_[i].type != _type )
540  continue;
541 
542  switch (contextMenus_[i].type) {
544  break;
545  case CONTEXTOBJECTMENU:
546  BaseObjectData* object;
547  if ( !PluginFunctions::getObject(_id, object) ) {
548  emit log(LOGERR,tr("Cant get object for objectContextMenu"));
549  continue;
550  }
551 
552  // Datatype does not match
553  if ( ! object->dataType( contextMenus_[i].contextType ) )
554  continue;
555 
556  break;
557  case CONTEXTNODEMENU:
558  break;
559 
560  }
561 
562  QMenu* menu = contextMenus_[i].action->menu();
563 
564  if (menu == 0) //is it a menu
565  actionMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
566  else
567  menuMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
568 
569  added = true;
570 
571  // Get all Actions in the menu and its submenus.
572  // Set their data to the picked Object id
573 
574 
575  QList< QAction *> allActions;
576  if ( menu == 0) {
577  allActions.push_back(contextMenus_[i].action);
578  } else {
579  allActions = menu->actions();
580  }
581 
582  while ( !allActions.empty() ) {
583  QList< QAction *> tmpList;
584 
585  // Set userdata of all actions to the picked Object Id
586  for ( int j = 0 ; j < allActions.size(); ++j ) {
587  allActions[j]->setData( QVariant( _id ) );
588  if ( allActions[j]->menu() != 0 )
589  tmpList << allActions[j]->menu()->actions();
590  }
591 
592  allActions = tmpList;
593  }
594 
595  }
596 
597  //find the currently selected view mode
598  int id = -1;
599  for (int i=0; i<viewModes_.size(); i++) {
600  if (viewModes_[i]->name == OpenFlipper::Options::currentViewMode()) {
601  id = i;
602  break;
603  }
604  }
605 
606  // Default to mode all (0) if not found
607  if ( id == -1 ) {
608  emit log(LOGERR, tr("Unable to find view mode %1.").arg(OpenFlipper::Options::currentViewMode()) );
609  id = 0;
610  }
611 
613 
614  //first add all menus
615  QMapIterator<QString, QAction*> it(menuMap);
616 
617  QStringList visible = viewModes_[id]->visibleContextMenus;
618  if (visible.contains("ALL_THAT_EXIST")) {
619  //this plugin adds all context menus, no special configuration so far.
620  visible = viewModes_[0]->visibleContextMenus;
621  }
622 
623  // Remove Plugin Name from string
624  visible.replaceInStrings(QRegExp(".*>"), "");
625 
626  // Remove accelerator specifications
627  visible.replaceInStrings("&", "");
628 
629  while (it.hasNext()) {
630  it.next();
631 
632  for ( int i = 0 ; i < visible.size(); ++i ) {
633  if ( it.key().contains(visible[i]) ) {
634  _menu->addAction( it.value() );
635  }
636  }
637  }
638 
639  _menu->addSeparator();
640 
641  //then all actions
642  QMapIterator<QString, QAction*> it2(actionMap);
643 
644  while (it2.hasNext()) {
645  it2.next();
646 
647  for ( int i = 0 ; i < visible.size(); ++i ) {
648  if ( it2.key().contains(visible[i]) ) {
649  _menu->addAction( it2.value() );
650  }
651  }
652  }
653 
654  return added;
655 }
656 
657 
658 
665 void CoreWidget::updatePopupMenu(const QPoint& _point) {
666 
667  // Clear the complete context menu.
668  contextMenu_->clear();
669 
670  // Clear the selection context menu part.
671  contextSelectionMenu_->clear();
672 
673  // =============================================================================
674  // First do a picking on the current position to check which context we are in.
675  // =============================================================================
676 
677  enum CONTEXTTYPE {
678  COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT, NODECONTEXT
679  } context = BACKGROUNDCONTEXT;
680 
681  // Do picking in the gl area to find an object
682  unsigned int node_idx, target_idx;
683  ACG::Vec3d hit_point;
684  BaseObjectData* object = 0;
685  ACG::SceneGraph::BaseNode* node = 0;
686 
687  if (examiner_widgets_[PluginFunctions::activeExaminer()]->pick( ACG::SceneGraph::PICK_ANYTHING,_point,node_idx, target_idx, &hit_point ) ) {
688 
689  if ( PluginFunctions::getPickedObject(node_idx, object) ) {
690  context = OBJECTCONTEXT;
691  } else {
693  if ( node != 0 && ( node->name() == "Core Coordsys Node") )
694  context = COORDSYSCONTEXT;
695  else
696  context = NODECONTEXT;
697  }
698  }
699 
700  // =============================================================================
701  // Depending on the context create the basic context menu.
702  // =============================================================================
703 
704  QIcon icon;
705 
706  switch (context) {
707  case BACKGROUNDCONTEXT:
709  return;
710  break;
711  case OBJECTCONTEXT:
713  return;
714  break;
715  case COORDSYSCONTEXT:
717  return;
718  break;
719  case NODECONTEXT:
721  return;
722  break;
723  }
724 
725 }
726 
727 
729  std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
730 
732 
733  fname.replace('%', '$');
734  fname = QFileDialog::getSaveFileName ( 0,
735  tr("Save snapshot name"),
736  OpenFlipperSettings().value("Core/CurrentDir").toString());
737 
738  if (!fname.isEmpty())
739  {
740  fname.replace('$', '%');
741 
742 
743  // Get the chosen directory and remember it.
744  QFileInfo fileInfo(fname);
745  OpenFlipperSettings().setValue("Core/CurrentDir", fileInfo.absolutePath() );
746 
748  QString msg=tr("next snapshot: ");
749  statusBar()->showMessage(msg);
750  }
751 
752 }
753 
754 void CoreWidget::slotAddContextItem(QAction* _entry, ContextMenuType _type) {
755  MenuInfo info;
756  info.action = _entry;
757  info.type = _type;
758 
759  contextMenus_.push_back(info);
761 }
762 
763 void CoreWidget::slotAddContextItem( QAction* _entry , DataType _dataType ,ContextMenuType _type ) {
764  MenuInfo info;
765  info.action = _entry;
766  info.contextType = _dataType;
767  info.type = _type;
768 
769  contextMenus_.push_back(info);
771 }
772 
774  int id = -1;
775  // Find the plugin which added this Context Menu
776  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
777  if ( plugins_[i].plugin == sender() ) {
778  id = i;
779  break;
780  }
781  }
782 
783  // Find the scripting plugin because we assign this context menu to it as we did not find the original sender
784  if ( id == -1 ) {
785  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
786  if ( plugins_[i].name == "Scripting" ) {
787  id = i;
788  break;
789  }
790  }
791 
792 
793  if ( id == -1 ) {
794  std::cerr << "Unknown sender plugin when adding Context Menu!" << std::endl;
795  return;
796  }
797  }
798 
799  plugins_[id].contextMenus.push_back( std::pair< QString,QAction* >( plugins_[id].name + "->" + _entry->text(), _entry) );
800 
801  // add widget name to viewMode 'all'
802  if ( !viewModes_[0]->visibleContextMenus.contains(plugins_[id].name + "->" + _entry->text()) ){
803  viewModes_[0]->visibleContextMenus << plugins_[id].name + "->" + _entry->text();
804  viewModes_[0]->visibleContextMenus.sort();
805  }
806 
807  setViewMode( OpenFlipper::Options::currentViewMode() );
808 }
809 
811  if ( drawGroupViewer_ ) {
812 
813  disconnect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
814  this , SLOT( slotViewerDrawMenu( QAction * ) ) );
815  delete( drawGroupViewer_ );
816  drawGroupViewer_ = 0;
817 
818  }
819 
820  // Recreate drawGroup
821  drawGroupViewer_ = new QActionGroup( this );
822  drawGroupViewer_->setExclusive( false );
823 
824  connect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
825  this , SLOT( slotViewerDrawMenu( QAction * ) ) );
826 
827  if ( !viewerDrawMenu_ ) {
828 
829  QIcon icon;
830  icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
831  viewerDrawMenu_ = new QMenu(tr("Set Draw Mode"));
832  viewerDrawMenu_->setTearOffEnabled(true);
833  viewerDrawMenu_->setIcon(icon);
834 
835  connect(viewerDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
836  }
837 
838  if (viewerDrawMenuWidget_) {
839  delete viewerDrawMenuWidget_;
840  }
841  viewerDrawMenuWidget_ = new QWidget(viewerDrawMenu_);
842 
843  // Collect available draw modes
844  // Single pass action, draw modes independent from multipass rendering
847  availableGlobalDrawModes_ = actionAvailable.drawModes();
848 
849  // Get currently active drawModes (first viewer only )
850  // TODO: create combination from all viewers!
852 
853  // Convert to ids
854  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
855  availDrawModeIds = availableGlobalDrawModes_.getAtomicDrawModes() ;
856 
857  viewerDrawMenu_->clear();
858 
859  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
860  {
861  ACG::SceneGraph::DrawModes::DrawMode id = availDrawModeIds[i];
862  std::string descr = id.description();
863 
864  QCheckBox *checkBox = new QCheckBox(QString(descr.c_str()), viewerDrawMenuWidget_);
865  checkBox->setChecked(activeDrawModes.containsAtomicDrawMode(id));
866  QWidgetAction *checkableAction = new QWidgetAction(drawGroupViewer_);
867  checkableAction->setText(descr.c_str());
868  checkableAction->setDefaultWidget(checkBox);
869  connect(checkBox, SIGNAL(toggled(bool) ), checkableAction, SLOT(trigger() ) );
870  }
871 
872  viewerDrawMenu_->addActions( drawGroupViewer_->actions() );
873 
874 }
875 
876 void CoreWidget::slotViewerDrawMenu(QAction * _action) {
877 
878  //======================================================================================
879  // Get the mode toggled
880  //======================================================================================
882  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
883  availDrawModeIds = availableGlobalDrawModes_.getAtomicDrawModes();
884  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
885  {
886  QString descr = QString( availDrawModeIds[i].description().c_str() );
887 
888  if ( descr == _action->text() ) {
889  mode = availDrawModeIds[i];
890  break;
891  }
892  }
893 
894  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
896  else
897  {
898  contextMenu_->hide();
900  }
901 
902 }
903 
904 void CoreWidget::slotPostProcessorMenu( QAction * _action) {
905  unsigned int mode = _action->data().toUInt();
906  postProcessorManager().setActive(mode,PluginFunctions::activeExaminer());
907 }
908 
909 void CoreWidget::slotRenderMenu( QAction * _action) {
910  unsigned int mode = _action->data().toUInt();
911  renderManager().setActive(mode,PluginFunctions::activeExaminer());
912 
913  QString defaultRendererKey = "Viewer" + QString::number(PluginFunctions::activeExaminer())+"/DefaultRenderer";
914  QString defaultRendererName = renderManager()[mode]->name;
915  OpenFlipperSettings().setValue(defaultRendererKey,defaultRendererName);
916 }
917 
918 //=============================================================================
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void updatePopupMenuObject(QMenu *_menu, BaseObjectData *_object)
Update popup Menu when an object has been clicked on.
Definition: ContextMenu.cc:507
DLLEXPORT QIcon & typeIcon(DataType _id)
Get an QIcon associated with the given DataType.
Definition: Types.cc:223
ACG::SceneGraph::DrawModes::DrawMode drawMode(int _viewer)
Get the current draw Mode of a Viewer.
void slotContextSetHomeView()
Set the active viewers home position.
void updateContextMenuBackground()
tells the plugins to update their context menu when the background is picked
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
void slotSetContextBackgroundColor()
Set Background Color for one viewer.
void slotLocalChangeBackFaceCulling(bool _backFaceCulling)
Set backface culling for active viewer.
unsigned int id() const
Definition: BaseNode.hh:399
void slotLocalChangeMultisampling(bool _multisampling)
Set multisampling for active viewer.
QMenu * coordSysMenu_
Definition: CoreWidget.hh:999
bool visible()
Is node visible (status == Active)?
Definition: BaseNode.hh:385
void viewerSnapshotDialog()
Create a snapshot of the whole app with fileDialog.
DrawModes::DrawMode drawModes() const
Get the collected draw modes.
Definition: SceneGraph.hh:588
void setActive(unsigned int _active, int _viewerId)
set the active post processor for viewer
QActionGroup * drawGroupViewer_
DrawGroup for per Viewer Draw Modes.
Definition: CoreWidget.hh:989
bool containsAtomicDrawMode(DrawMode _atomicDrawMode) const
Check whether an Atomic DrawMode is active in this draw Mode.
void slotPostProcessorMenu(QAction *_action)
Called when a different post processor has been chosen.
Definition: ContextMenu.cc:904
QString name() const
return the name of the object. The name defaults to NONAME if unset.
Definition: BaseObject.cc:741
void slotShowRenderObjectWidget()
Shows the widget containing the current render objects.
pick any of the prior targets (should be implemented for all nodes)
Definition: BaseNode.hh:110
void updateContextMenuNode(int)
tells the plugins to update their context menu when a node is picked
std::vector< DrawMode > getAtomicDrawModes() const
Separates this drawMode into a list of all separate atomic draw modes.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void slotShowRenderManager()
shows the widget for the rendermanager
void slotCustomContextMenu(const QPoint &_point)
This slot is called by the examiner widgets gl area when a context menu is requested.
Definition: ContextMenu.cc:66
void slotUpdateViewerDrawMenu()
Creates a draw Menu for the currently active Viewer.
Definition: ContextMenu.cc:810
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
void slotUpdateGlobalDrawMenu()
Setup and update the global draw menu.
Definition: MenuBar.cc:829
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node
void snapshotBaseFileName(const QString &_fname)
DLLEXPORT QString typeName(DataType _id)
Get the name of a type with given id.
Definition: Types.cc:165
bool dataType(DataType _type) const
Definition: BaseObject.cc:232
unsigned int available()
number of available renderers
void slotSetViewingDirection(QAction *_action)
Change the viewing direction from context-menu.
void slotExaminerSnapshot()
Create a snapshot of the last active examiner.
void updatePopupMenuNode(QMenu *_menu, ACG::SceneGraph::BaseNode *_node)
Update context Menu when an arbitrary node has been clicked on.
Definition: ContextMenu.cc:97
The Menu will be shown when the background was picked.
void slotContextViewAll()
Change view on active viewer to view complete scene.
void updatePopupMenuCoordsysNode(QMenu *_menu, const int _part)
Update context Menu when Coordsys node has been clicked on.
Definition: ContextMenu.cc:119
ACG::SceneGraph::CoordsysNode::ProjectionMode getCoordsysProjection()
Toggle coordsys projection mode of the active viewer.
void setViewMode(QString _mode, bool _expandAll=false)
Set the view Mode to the given Mode.
Definition: viewMode.cc:316
std::string name() const
Returns: name of node (needs not be unique)
Definition: BaseNode.hh:391
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
QMenu * pickMenu_
Definition: CoreWidget.hh:1550
ContextMenuType type
Type of the context Menu ( Context for what type .. Background,Object,Node)
Definition: CoreWidget.hh:176
void slotLockRotation(bool _lock)
Lock rotation in current examiner widget.
ACG::SceneGraph::DrawModes::DrawMode availableGlobalDrawModes_
This variable holds the global draw menu.
Definition: CoreWidget.hh:889
void updatePopupMenuBackground(QMenu *_menu, const QPoint &_point)
Update context Menu when background has been clicked on.
Definition: ContextMenu.cc:457
QAction * action
The context item.
Definition: CoreWidget.hh:170
QMenu * contextMenu_
context Menu for the gl area
Definition: CoreWidget.hh:980
void slotLocalChangeTwoSidedLighting(bool _lighting)
Set two-sided lighting for active viewer.
void slotAddContextItem(QAction *_entry, ContextMenuType _type)
called by plugins to add a new context menu item
Definition: ContextMenu.cc:754
QWidget * viewerDrawMenuWidget_
owns all the checkboxes of viewerDrawMenu_
Definition: CoreWidget.hh:995
The Menu will be shown when an object was picked.
void updateContextMenu(int)
tells the plugins to update their context menu when an object is picked
BaseNode * find_node(BaseNode *_root, unsigned int _node_idx)
Find a node in the scene graph.
Definition: SceneGraph.cc:83
void setActive(unsigned int _active, int _id)
set the active renderer
The Menu will be shown when a node was picked.
void slotAddContextItemToViewMode(QAction *_entry)
called by slotAddContextItem to add the item to the view mode
Definition: ContextMenu.cc:773
DataType contextType
Type of objects for which the context Menu should be visible.
Definition: CoreWidget.hh:173
void slotContextSwitchProjection()
Toggle projection mode of the active viewer.
void slotPasteView()
Paste the view to the last active examiner.
void slotContextSwitchCoordsysProjection()
Toggle coordsys projection mode of the active viewer.
QMenu * contextSelectionMenu_
Context Menu containing all selection elements.
Definition: CoreWidget.hh:983
QVector< ViewMode * > & viewModes_
List of currently available viewModes.
Definition: CoreWidget.hh:577
std::vector< MenuInfo > contextMenus_
All real context menu entries.
Definition: CoreWidget.hh:986
Predefined datatypes.
Definition: DataTypes.hh:96
void setValue(const QString &key, const QVariant &value)
Wrapper function which makes it possible to enable Debugging output with -DOPENFLIPPER_SETTINGS_DEBUG...
void slotPasteViewAndWindow()
Paste the view, the window and toolbox size to the last active examiner.
void slotViewerDrawMenu(QAction *_action)
Called when a coordsys drawMode has been changed.
Definition: ContextMenu.cc:876
unsigned int activeExaminer()
Get the id of the examiner which got the last mouse events.
void traverse(BaseNode *_node, Action &_action)
Definition: SceneGraph.hh:143
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
void slotContextHomeView()
Set the active viewer to home position.
void slotHideContextMenu()
Hide the context menu.
Definition: ContextMenu.cc:85
void slotLocalChangeAnimation(bool _animation)
Set the animation mode for active viewer.
bool addContextMenus(QMenu *_menu, ContextMenuType _type, int _id=-1)
Definition: ContextMenu.cc:529
void slotSnapshotName()
Set the snapShot name for all examiners.
Definition: ContextMenu.cc:728
void slotRenderMenu(QAction *_action)
Called when a different renderer has been chosen.
Definition: ContextMenu.cc:909
int id() const
Definition: BaseObject.cc:201
ChildIter find(BaseNode *_node)
Definition: BaseNode.hh:322
QMenu * viewerDrawMenu_
Draw Menu for per Viewer Draw Modes.
Definition: CoreWidget.hh:992
void updatePopupMenu(const QPoint &_point)
check current context and initialize context menu according to this context.
Definition: ContextMenu.cc:665
void slotLocalChangeMipmapping(bool _mipmapping)
Set mipmapping for active viewer.
std::vector< glViewer * > examiner_widgets_
Examiner Widget.
Definition: CoreWidget.hh:669
void slotCopyView()
Copy view from the last active examiner.