ContextMenu.cc 35.5 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
34

35
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58



//=============================================================================
//
//  CLASS CoreWidget - IMPLEMENTATION
//
//=============================================================================


//== INCLUDES =================================================================

// -------------------- mview
#include "CoreWidget.hh"

#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
59
#include "../../common/GlobalOptions.hh"
60
#include <OpenFlipper/Core/RendererInfo.hh>
Jan Möbius's avatar
 
Jan Möbius committed
61

Jan Möbius's avatar
Jan Möbius committed
62
//== IMPLEMENTATION ==========================================================
63
#include <ACG/Scenegraph/CoordsysNode.hh>
Jan Möbius's avatar
 
Jan Möbius committed
64
65

void CoreWidget::slotCustomContextMenu( const QPoint& _point ) {
Jan Möbius's avatar
Jan Möbius committed
66

Jan Möbius's avatar
Jan Möbius committed
67
  QPoint   popupPosition;
Jan Möbius's avatar
Jan Möbius committed
68
  QPoint   scenePos;
Jan Möbius's avatar
Jan Möbius committed
69

Jan Möbius's avatar
Jan Möbius committed
70
71
72
73
  // Calculate popup position. Use the position from the viewer which was clicked on.
  popupPosition =  examiner_widgets_[PluginFunctions::activeExaminer()]->glMapToGlobal(_point);
  QPointF f = examiner_widgets_[PluginFunctions::activeExaminer()]->mapToScene(QPointF(_point.x(), _point.y()));
  scenePos = QPoint (f.x(), f.y());
74

Jan Möbius's avatar
Jan Möbius committed
75
  // Call function to adapt the menu to the currently used contex.
76
  updatePopupMenu(scenePos);
Jan Möbius's avatar
Jan Möbius committed
77

Jan Möbius's avatar
Jan Möbius committed
78
  // If the menu is not correctly initialized, dont try to show it.
Jan Möbius's avatar
 
Jan Möbius committed
79
  if ( !contextMenu_->isEmpty () )
Jan Möbius's avatar
Jan Möbius committed
80
    contextMenu_->popup( popupPosition );
Jan Möbius's avatar
Jan Möbius committed
81

Jan Möbius's avatar
 
Jan Möbius committed
82
83
}

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/** \brief Update context Menu when an arbitrary node has been clicked on.
 *
 * This function is called when a node has been clicked on not belonging to an object.
 * This context menu will show all function relevant for the Node.
 *
 * @param _menu Pointer to the context Menu
 * @param _node node which has been clicked on.
 */
void CoreWidget::updatePopupMenuNode(QMenu* _menu , ACG::SceneGraph::BaseNode* _node) {

  QString nodeName = QString(_node->name().c_str());
  QAction* typeEntry = new QAction( nodeName ,_menu );
  _menu->addAction( typeEntry );

  _menu->addSeparator();

  emit updateContextMenuNode(_node->id());

102
  addContextMenus( _menu , CONTEXTNODEMENU, _node->id() ) ;
103
104
}

Jan Möbius's avatar
Jan Möbius committed
105
/** \brief Update context Menu when Coordsys node has been clicked on.
106
 *
Jan Möbius's avatar
Jan Möbius committed
107
108
109
 * This function is called when the coordinate system in a viewer has been clicked on.
 * This context menu will show all function relevant for the current view like the
 * projection/viewing direction...
110
 *
Jan Möbius's avatar
Jan Möbius committed
111
112
113
 * @param _menu Pointer to the context Menu
 * @param _part id of the coordsys part which has been clicked on.
 */
Jan Möbius's avatar
Jan Möbius committed
114
void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu  , const int /*_part*/) {
115
116
117
    
  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
  
118
  QAction* typeEntry = new QAction(tr("Viewer Settings"),_menu);
Jan Möbius's avatar
Jan Möbius committed
119
  _menu->addAction( typeEntry );
120
  typeEntry->setDisabled(true);
121
  _menu->addSeparator();
122
123
124
125
126
127
128
129
130
131
132
  
  QAction* orthogonalCoordsys = 0;
  if ( getCoordsysProjection() == ACG::SceneGraph::CoordsysNode::PERSPECTIVE_PROJECTION ) {
    orthogonalCoordsys = new QAction( tr("Switch to Orthogonal coordinate system"), _menu );
    orthogonalCoordsys->setIcon( QIcon(iconPath+"orthogonal.png") );
  } else {
    orthogonalCoordsys = new QAction( tr("Switch to Perspective coordinate system"), _menu );
    orthogonalCoordsys->setIcon( QIcon(iconPath+"perspective.png") );
  }
  connect( orthogonalCoordsys,SIGNAL( triggered() ), this, SLOT( slotContextSwitchCoordsysProjection() ) );
  _menu->addAction(orthogonalCoordsys);
133

Jan Möbius's avatar
Jan Möbius committed
134
  //====================================================================================================
135
136
137
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
138
139
  if (! viewerDrawMenu_->isEmpty())
    _menu->addMenu( viewerDrawMenu_ );
140

141
142
143
  //====================================================================================================
  // RenderingOptions
  //====================================================================================================
144
  
145
  QMenu* renderingOptionsMenu = new QMenu(tr("Rendering Options"),_menu);
146
  renderingOptionsMenu->setIcon( QIcon(iconPath+"core_renderingOptions.png") );
147
  _menu->addMenu(renderingOptionsMenu);
148

149
150
  QAction* projectionAction = 0;
  if ( examiner_widgets_[PluginFunctions::activeExaminer() ]->projectionMode() == glViewer::PERSPECTIVE_PROJECTION ) {
151
    projectionAction = new QAction( tr("Switch to Orthogonal Projection"), renderingOptionsMenu );
152
    projectionAction->setIcon( QIcon(iconPath+"orthogonal.png") );
153
    projectionAction->setToolTip(   tr("Switch to perspective orthogonal mode."));
154
  } else {
155
    projectionAction = new QAction( tr("Switch to Perspective Projection"), renderingOptionsMenu );
156
    projectionAction->setIcon( QIcon(iconPath+"perspective.png") );
157
    projectionAction->setToolTip(   tr("Switch to perspective projection mode."));
158
  }
159

160
  projectionAction->setCheckable( false );
161
162
163
  projectionAction->setToolTip(   tr("Switch between <b>perspective</b> and "
      "<b>parrallel</b> projection mode."));
  projectionAction->setWhatsThis( tr("Switch projection modes<br><br>"
164
      "Switch between <b>perspective</b> and "
165
      "<b>parrallel</b> projection mode."));
166
167
  connect( projectionAction,SIGNAL( triggered() ), this, SLOT( slotContextSwitchProjection() ) );
  renderingOptionsMenu->addAction( projectionAction );
168
169


170
  QAction* animation = renderingOptionsMenu->addAction(tr("Animation"));
171

172
  animation->setToolTip(tr("Animate rotation of objects"));
173
  animation->setCheckable( true );
174
  animation->setIcon( QIcon(iconPath+"animation.png") );
175
176
  animation->setChecked( PluginFunctions::viewerProperties(PluginFunctions::activeExaminer()).animation() );
  connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeAnimation(bool) ) );
177
178


179
180
  //====================================================================================================

181
182
  QAction* backfaceCulling = renderingOptionsMenu->addAction(tr("Backface Culling"));
  backfaceCulling->setToolTip(tr("Enable backface culling"));
183
  backfaceCulling->setCheckable( true );
184
  backfaceCulling->setIcon( QIcon(iconPath+"backFaceCulling.png") );
185
186
187
188
189
  backfaceCulling->setChecked( PluginFunctions::viewerProperties().backFaceCulling() );
  connect(backfaceCulling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeBackFaceCulling(bool) ) );

  //====================================================================================================

190
191
  QAction* twoSidedLighting = renderingOptionsMenu->addAction(tr("Two-sided Lighting"));
  twoSidedLighting->setToolTip(tr("Enable two-sided lighting"));
192
  twoSidedLighting->setCheckable( true );
193
  twoSidedLighting->setIcon( QIcon(iconPath+"twosidedLighting.png") );
194
195
  twoSidedLighting->setChecked( PluginFunctions::viewerProperties().twoSidedLighting() );
  connect(twoSidedLighting, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeTwoSidedLighting(bool) ) );
196
197
198
  
  //====================================================================================================

199
200
  QAction* multisampling = renderingOptionsMenu->addAction(tr("Multisampling"));
  multisampling->setToolTip(tr("Enable Multisampling"));
201
  multisampling->setCheckable( true );
202
  multisampling->setIcon( QIcon(iconPath+"multiSampling.png") );
203
  multisampling->setChecked( PluginFunctions::viewerProperties().multisampling() );
Mike Kremer's avatar
Mike Kremer committed
204
205
206
207
208
209
210
  connect(multisampling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeMultisampling(bool) ) );
  
  //====================================================================================================

  QAction* mipmapping = renderingOptionsMenu->addAction(tr("Mipmapping"));
  mipmapping->setToolTip(tr("Enable Mipmapping"));
  mipmapping->setCheckable( true );
211
  mipmapping->setIcon( QIcon(iconPath+"mipmapping.png") );
Mike Kremer's avatar
Mike Kremer committed
212
213
  mipmapping->setChecked( PluginFunctions::viewerProperties().mipmapping() );
  connect(mipmapping, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeMipmapping(bool) ) );
214

Jan Möbius's avatar
Jan Möbius committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  //============================================================================================================
  // Renderer Menu
  //============================================================================================================

  if ( renderManager().available() > 1 ) {
    QMenu* rendererMenu = new QMenu(tr("Renderers"),_menu);

    _menu->addMenu(rendererMenu);

    // Recreate actionGroup
    QActionGroup* groupRenderer = new QActionGroup( this );
    groupRenderer->setExclusive( true );

    for ( unsigned int i = 0 ; i < renderManager().available() ; ++i) {

      // Add a new Action with the renderer name
      QAction * action = new QAction( renderManager()[i]->name, groupRenderer );
      action->setCheckable( true );

      // Check if this processor is currently active
      if ( renderManager().activeId(PluginFunctions::activeExaminer() ) == i )
        action->setChecked(true);

      // Remember the id for the processor
      action->setData(QVariant(i));
    }

    // Add all new actions from the group to the menu
    rendererMenu->addActions( groupRenderer->actions() );

    // Connect signal of group to our managing slot
    connect( groupRenderer , SIGNAL( triggered( QAction * ) ),
        this               , SLOT( slotRenderMenu( QAction * ) ) );

  }

251
252
253
254
  //============================================================================================================
  // Post processor Menu
  //============================================================================================================

255
  if ( postProcessorManager().available() > 1 ) {
256
257
258
259
260
261
262
263
    QMenu* postProcessorMenu = new QMenu(tr("Post processors"),_menu);

    _menu->addMenu(postProcessorMenu);

    // Recreate actionGroup
    QActionGroup* groupPostProcessor = new QActionGroup( this );
    groupPostProcessor->setExclusive( true );

264
265
266
267
268
269
270
271
272
273
274
275
    // Get the options action for the currently active
    for ( unsigned int i = 0 ; i < postProcessorManager().available() ; ++i) {

      if ( postProcessorManager().activeId(PluginFunctions::activeExaminer() ) == i )
        if( postProcessorManager()[i]->optionsAction != 0 ) {
          postProcessorMenu->addAction(postProcessorManager()[i]->optionsAction);
          postProcessorMenu->addSeparator();
        }

    }

    // Now add the processor chooser
276
277
278
279
280
281
282
    for ( unsigned int i = 0 ; i < postProcessorManager().available() ; ++i) {

      // Add a new Action with the postprocessors name
      QAction * action = new QAction( postProcessorManager()[i]->name, groupPostProcessor );
      action->setCheckable( true );

      // Check if this processor is currently active
Jan Möbius's avatar
Jan Möbius committed
283
      if ( postProcessorManager().activeId(PluginFunctions::activeExaminer() ) == i )
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
        action->setChecked(true);

      // Remember the id for the processor
      action->setData(QVariant(i));
    }

    // Add all new actions from the group to the menu
    postProcessorMenu->addActions( groupPostProcessor->actions() );

    // Connect signal of group to our managing slot
    connect( groupPostProcessor , SIGNAL( triggered( QAction * ) ),
             this               , SLOT( slotPostProcessorMenu( QAction * ) ) );

  }

299
300
301
302
303
304

  //============================================================================================================
  // Viewing Direction Menu
  //============================================================================================================

  QMenu* viewingDirectionMenu = new QMenu( tr("Viewing Direction"), _menu);
305
  viewingDirectionMenu->setIcon(QIcon(iconPath+"core_viewingDirection.png"));
306
307
308
309
310
311
312
  _menu->addMenu(viewingDirectionMenu);

  QActionGroup* dirGroup = new QActionGroup(this);

  QAction* viewAction;
  // freeView
  viewAction = new QAction( tr("Free View"), viewingDirectionMenu );
313
  viewAction->setIcon( QIcon(iconPath+"orthogonal.png") );
314
315
316
317
318
319
320
321
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_FREE );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_FREE );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
  viewingDirectionMenu->addSeparator();
  // TOP
  viewAction = new QAction( tr("Top View"), viewingDirectionMenu );
322
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_top.png") );
323
324
325
326
327
328
329
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_TOP );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_TOP );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
  // BOTTOM
  viewAction = new QAction( tr("Bottom View"), viewingDirectionMenu );
330
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_bottom.png") );
331
332
333
334
335
336
337
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_BOTTOM );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BOTTOM );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
  // LEFT
  viewAction = new QAction( tr("Left View"), viewingDirectionMenu );
338
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_left.png") );
339
340
341
342
343
344
345
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_LEFT );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_LEFT );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
  // RIGHT
  viewAction = new QAction( tr("Right View"), viewingDirectionMenu );
346
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_right.png") );
347
348
349
350
351
352
353
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_RIGHT );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_RIGHT );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
  // FRONT
  viewAction = new QAction( tr("Front View"), viewingDirectionMenu );
354
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_front.png") );
355
356
357
358
359
360
361
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_FRONT );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_FRONT );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
  // BACK
  viewAction = new QAction( tr("Back View"), viewingDirectionMenu );
362
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_back.png") );
363
364
365
366
367
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_BACK );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BACK );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
368
369
  
  viewingDirectionMenu->addSeparator();
370
371

  connect( dirGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSetViewingDirection(QAction*) ) );
372
373
374
375
376
377
  
  //===========================================================================
  // Check box to determine whether rotation should be locked or not
  
  QAction* lockAction = viewingDirectionMenu->addAction("Lock rotation");
  lockAction->setCheckable( true );
378
  lockAction->setIcon( QIcon(iconPath+"lock_rotation.png") );
379
380
381
382
383
384
  lockAction->setToolTip(tr("Lock rotation in current examiner"));
  lockAction->setChecked( PluginFunctions::viewerProperties().rotationLocked() );
  viewingDirectionMenu->addAction( lockAction );
  
  connect( lockAction, SIGNAL(triggered(bool)), this, SLOT(slotLockRotation(bool) ) );
  
385
386
387
  //====================================================================================================
  // Other Toplevel Action
  //====================================================================================================
388

389
  _menu->addSeparator();
390

391
  //====================================================================================================
392

393
  QAction* homeAction = new QAction(tr("Restore home view"),_menu);
394
  homeAction->setIcon( QIcon(iconPath+"go-home.png") );
395
  homeAction->setCheckable( false );
396
397
398
  homeAction->setToolTip(tr("Restore <b>home</b> view."));
  homeAction->setWhatsThis( tr("Restore home view<br><br>"
                            "Resets the view to the home view"));
399
400
  _menu->addAction( homeAction );
  connect( homeAction,SIGNAL( triggered() ), this, SLOT( slotContextHomeView() ) );
401

402
  QAction* setHomeAction = new QAction( tr("Set Home View") , _menu );
403
  setHomeAction->setIcon( QIcon(iconPath+"set-home.png") );
404
  setHomeAction->setCheckable( false );
405
406
407
  setHomeAction->setToolTip(tr("Set <b>home</b> view"));
  setHomeAction->setWhatsThis( tr("Store home view<br><br>"
                               "Stores the current view as the home view"));
408
  _menu->addAction( setHomeAction);
409
410
  connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotContextSetHomeView() ) );

411
  QAction* viewAllAction = new QAction( tr("View all"), _menu );
412
  viewAllAction->setIcon( QIcon(iconPath+"viewall.png") );
413
  viewAllAction->setCheckable( false );
414
415
416
417
  viewAllAction->setToolTip(tr("View all."));
  viewAllAction->setWhatsThis( tr("View all<br><br>"
                                  "Move the objects in the scene so that"
                                  " the whole scene is visible."));
418
419
  connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotContextViewAll() ) );
  _menu->addAction( viewAllAction);
420
421


422
  _menu->addSeparator();
423

424
  //====================================================================================================
425

426
427
  QAction* copyView = _menu->addAction(tr("Copy View"));
  copyView->setToolTip(tr("Copy current view to clipboard"));
428
  copyView->setIcon( QIcon(iconPath+"edit-copy.png") );
429
430
431
432
  connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );

  //====================================================================================================

433
434
  QAction* pasteView = _menu->addAction(tr("Paste View"));
  pasteView->setToolTip(tr("Paste current view from clipboard"));
435
  pasteView->setIcon( QIcon(iconPath+"edit-paste.png") );
436
  connect(pasteView, SIGNAL(triggered()), this , SLOT( slotPasteView( ) ) );
437

438
  //====================================================================================================
439

440
441
  QAction* snapshot_examiner = _menu->addAction(tr("Examiner Snapshot"));
  snapshot_examiner->setToolTip(tr("Take a snapshot of the current examiner"));
442
  snapshot_examiner->setIcon( QIcon(iconPath+"snapshot.png") );
443
444
445
446
447
448
  connect(snapshot_examiner, SIGNAL(triggered()), this, SLOT( slotExaminerSnapshot() ) );
  
  //====================================================================================================
  
  QAction* snapshot_viewer = _menu->addAction(tr("Viewer Snapshot"));
  snapshot_viewer->setToolTip(tr("Take a snapshot of the whole viewer"));
449
  snapshot_viewer->setIcon( QIcon(iconPath+"snapshot.png") );
450
  connect(snapshot_viewer, SIGNAL(triggered()), this, SLOT( viewerSnapshotDialog() ) );
451

452
453
}

Jan Möbius's avatar
Jan Möbius committed
454
/** \brief Update context Menu when background has been clicked on.
455
 *
Jan Möbius's avatar
Jan Möbius committed
456
 * This function is called when the background in a viewer has been clicked on.
457
 * This context menu will show functions which are related to the background of the
Jan Möbius's avatar
Jan Möbius committed
458
 * viewer.
459
 *
Jan Möbius's avatar
Jan Möbius committed
460
461
462
 * @param _menu Pointer to the context Menu
 * @param _point position in the viewer where the user clicked.
 */
Jan Möbius's avatar
Jan Möbius committed
463
void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& /*_point*/) {
464

465
466
467
468
469
470
471
  //====================================================================================================
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
  _menu->addMenu( viewerDrawMenu_ );

  _menu->addSeparator();
472
  
473
474
  QAction* action = _menu->addAction(tr("Set Background Color"));
  action->setToolTip(tr("Set the background color for the current viewer"));
Jan Möbius's avatar
Jan Möbius committed
475
  action->setStatusTip(tr("Set the background color for the current viewer"));
476
  action->setWhatsThis(tr("Set the background color for the current viewer"));
477
  action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
478
  connect(action, SIGNAL(triggered()), this, SLOT(slotSetContextBackgroundColor()) );
479

480
  /*
Mike Kremer's avatar
Mike Kremer committed
481
   * Show coordsys context menu of coordsys if
482
483
484
485
486
487
488
   * invisible...
   */

  ACG::SceneGraph::BaseNode* root = PluginFunctions::getSceneGraphRootNode();
  ACG::SceneGraph::BaseNode* coordSys = root->find("Core Coordsys Node");

  if(!coordSys->visible()) {
489
490

	  if(!coordSysMenu_) {
491
		  coordSysMenu_ = new QMenu(tr("Viewer Settings"), _menu);
492
493
		  updatePopupMenuCoordsysNode(coordSysMenu_, 0);
	  }
494
	  _menu->addSeparator();
495
	  _menu->addMenu(coordSysMenu_);
496
497
  }

498
499
500
501
502
  // Tell Plugins to update their context Menu
  emit updateContextMenuBackground();

  addContextMenus( _menu , CONTEXTBACKGROUNDMENU ) ;

Jan Möbius's avatar
Jan Möbius committed
503
}
Jan Möbius's avatar
Jan Möbius committed
504

Jan Möbius's avatar
Jan Möbius committed
505
/** \brief Update context Menu an object has been clicked on.
506
 *
Jan Möbius's avatar
Jan Möbius committed
507
508
 * This function is called when an object has been clicked on.
 * This context menu will show all properties for the given object.
509
 *
Jan Möbius's avatar
Jan Möbius committed
510
511
512
 * @param _menu Pointer to the context Menu
 * @param _objectId Id of the object that has been clicked on.
 */
513
514
515
void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) {

  QAction* typeEntry = new QAction( typeName(_object->dataType()) ,_menu);
516
  typeEntry->setIcon(typeIcon(_object->dataType()));
517
518
519
520
521
522
523
524
525
526
527
  _menu->addAction( typeEntry );

  _menu->addSeparator( );

  // Tell Plugins to update their context Menu
  emit updateContextMenu(_object->id() );

  if ( addContextMenus( _menu , CONTEXTOBJECTMENU , _object->id() ) )
    _menu->addSeparator();

  // Add picking Menu
528
  if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) {
529
    pickMenu_->setTitle(tr("&Picking"));
530
531
    contextMenu_->addMenu( pickMenu_ );
    pickMenu_->setTearOffEnabled(true);
532
533
534
535
536
537
538
  }
}

bool CoreWidget::addContextMenus( QMenu* _menu , ContextMenuType _type , int _id ) {

  bool added = false;

539
540
541
  QMap< QString , QAction* > menuMap; //QMap sorts by key
  QMap< QString , QAction* > actionMap;

542
543
544
545
546
547
548
549
550
551
552
553
  // Add context menus from plugins
  for ( uint i = 0 ; i < contextMenus_.size(); ++i ) {

    if ( contextMenus_[i].type != _type )
      continue;

    switch (contextMenus_[i].type) {
      case CONTEXTBACKGROUNDMENU:
        break;
      case CONTEXTOBJECTMENU:
        BaseObjectData* object;
        if ( !PluginFunctions::getObject(_id, object) ) {
554
          emit log(LOGERR,tr("Cant get object for objectContextMenu"));
555
556
557
558
559
560
561
562
563
564
565
566
567
          continue;
        }

        // Datatype does not match
        if ( ! object->dataType(  contextMenus_[i].contextType ) )
          continue;

        break;
      case CONTEXTNODEMENU:
        break;

    }

568
569
570
571
572
573
    QMenu* menu = contextMenus_[i].action->menu();

    if (menu == 0) //is it a menu
      actionMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
    else
      menuMap[ contextMenus_[i].action->text() ] = contextMenus_[i].action;
574
575
576
577
578

    added = true;

    // Get all Actions in the menu and its submenus.
    // Set their data to the picked Object id
579

Jan Möbius's avatar
 
Jan Möbius committed
580
581
582
583
584
585
586
587

    QList< QAction *> allActions;
    if ( menu == 0) {
      allActions.push_back(contextMenus_[i].action);
    } else {
      allActions = menu->actions();
    }

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
    while ( !allActions.empty() ) {
      QList< QAction *> tmpList;

      // Set userdata of all actions to the picked Object Id
      for ( int j = 0 ; j < allActions.size(); ++j ) {
        allActions[j]->setData( QVariant( _id ) );
        if ( allActions[j]->menu() != 0 )
          tmpList << allActions[j]->menu()->actions();
      }

      allActions = tmpList;
    }

  }

Jan Möbius's avatar
Marlin:  
Jan Möbius committed
603
604
605
606
607
608
609
610
  //find the currently selected view mode
  int id = -1;
  for (int i=0; i<viewModes_.size(); i++) {
    if (viewModes_[i]->name == OpenFlipper::Options::currentViewMode()) {
      id = i;
      break;
    }
  }
611
612
613
614
615
616

  // Default to mode all (0) if not found
  if ( id == -1 ) {
    emit log(LOGERR, tr("Unable to find view mode %1.").arg(OpenFlipper::Options::currentViewMode()) );
    id = 0;
  }
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
617
618
  
  /// \todo Sort the menu entries by the order given in visibleContextMenus
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
619
  
620
621
  //first add all menus
  QMapIterator<QString, QAction*> it(menuMap);
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
622
623
  
  QStringList visible = viewModes_[id]->visibleContextMenus;
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
624
625
626
627
  if (visible.contains("ALL_THAT_EXIST")) {
    //this plugin adds all context menus, no special configuration so far.
    visible = viewModes_[0]->visibleContextMenus;
  }
628
629

  // Remove Plugin Name from string
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
630
  visible.replaceInStrings(QRegExp(".*>"), "");
631

632
633
634
  // Remove accelerator specifications
  visible.replaceInStrings("&", "");

635
  while (it.hasNext()) {
636
637
638
639
640
641
642
    it.next();

	for ( int i = 0 ; i < visible.size(); ++i ) {
	  if ( it.key().contains(visible[i]) ) {
	    _menu->addAction( it.value() );
	  }
    }
643
644
645
646
647
648
  }

  _menu->addSeparator();

  //then all actions
  QMapIterator<QString, QAction*> it2(actionMap);
649

650
651
  while (it2.hasNext()) {
     it2.next();
652
653
654
655
656
657

	 for ( int i = 0 ; i < visible.size(); ++i ) {
		 if ( it2.key().contains(visible[i]) ) {
	       _menu->addAction( it2.value() );
		 }
	 }
658
659
660
  }

  return added;
Jan Möbius's avatar
Jan Möbius committed
661
}
Jan Möbius's avatar
Jan Möbius committed
662
663


664
 
665
666
667
/** \brief check current context and initialize context menu according to this context.
 *
 * This function is called whenever a context menu for the corewidget is requested.
Jan Möbius's avatar
Jan Möbius committed
668
669
670
671
 * It will decide about the current context, collect all menus for plugins and
 * construct the final context menu.
 */
void CoreWidget::updatePopupMenu(const QPoint& _point) {
Jan Möbius's avatar
Jan Möbius committed
672

Jan Möbius's avatar
Jan Möbius committed
673
674
  // Clear the complete context menu.
  contextMenu_->clear();
675

Jan Möbius's avatar
Jan Möbius committed
676
677
  // Clear the selection context menu part.
  contextSelectionMenu_->clear();
Jan Möbius's avatar
Jan Möbius committed
678

Jan Möbius's avatar
Jan Möbius committed
679
680
681
  // =============================================================================
  // First do a picking on the current position to check which context we are in.
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
682
  int objectId = -1;
683

Jan Möbius's avatar
Jan Möbius committed
684
  enum CONTEXTTYPE {
685
    COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT, NODECONTEXT
Jan Möbius's avatar
Jan Möbius committed
686
  } context = BACKGROUNDCONTEXT;
Jan Möbius's avatar
Jan Möbius committed
687

Jan Möbius's avatar
 
Jan Möbius committed
688
  // Do picking in the gl area to find an object
689
690
691
692
693
  unsigned int               node_idx, target_idx;
  ACG::Vec3d                 hit_point;
  BaseObjectData*            object;
  ACG::SceneGraph::BaseNode* node = 0;

694
  if (examiner_widgets_[PluginFunctions::activeExaminer()]->pick( ACG::SceneGraph::PICK_ANYTHING,_point,node_idx, target_idx, &hit_point ) ) {
695

Jan Möbius's avatar
Jan Möbius committed
696
    if ( PluginFunctions::getPickedObject(node_idx, object) ) {
Jan Möbius's avatar
 
Jan Möbius committed
697
      objectId = object->id();
Jan Möbius's avatar
Jan Möbius committed
698
699
      context  = OBJECTCONTEXT;
    } else {
700
701
      node = ACG::SceneGraph::find_node( PluginFunctions::getSceneGraphRootNode() , node_idx );
      if ( node != 0 && ( node->name() == "Core Coordsys Node") )
Jan Möbius's avatar
Jan Möbius committed
702
        context = COORDSYSCONTEXT;
703
704
      else
        context = NODECONTEXT;
705
    }
706
707
  }

Jan Möbius's avatar
Jan Möbius committed
708
709
710
  // =============================================================================
  // Depending on the context create the basic context menu.
  // =============================================================================
711

Jan Möbius's avatar
Jan Möbius committed
712
  QIcon icon;
713

Jan Möbius's avatar
Jan Möbius committed
714
715
716
  switch (context) {
    case BACKGROUNDCONTEXT:
      updatePopupMenuBackground(contextMenu_,_point);
717
      return;
Jan Möbius's avatar
Jan Möbius committed
718
719
      break;
    case OBJECTCONTEXT:
720
      updatePopupMenuObject(contextMenu_ , object );
721
      return;
Jan Möbius's avatar
Jan Möbius committed
722
723
724
      break;
    case COORDSYSCONTEXT:
      updatePopupMenuCoordsysNode(contextMenu_,target_idx);
725
      return;
Jan Möbius's avatar
Jan Möbius committed
726
      break;
727
728
729
730
    case NODECONTEXT:
      updatePopupMenuNode(contextMenu_,node);
      return;
      break;
Jan Möbius's avatar
 
Jan Möbius committed
731
  }
Jan Möbius's avatar
Jan Möbius committed
732

Jan Möbius's avatar
 
Jan Möbius committed
733
734
}

735

736
737
void CoreWidget::slotSnapshotName() {
  std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
738
739
740
741

  QString fname = PluginFunctions::viewerProperties().snapshotName();

  fname.replace('%', '$');
Jan Möbius's avatar
Jan Möbius committed
742
743
744
745
  fname = QFileDialog::getSaveFileName ( 0,
                                         tr("Save snapshot name"),
                                         OpenFlipperSettings().value("Core/CurrentDir").toString());

746
747
748
749
  if (!fname.isEmpty())
  {
    fname.replace('$', '%');

Jan Möbius's avatar
Jan Möbius committed
750
751
752
753
754

    // Get the chosen directory and remember it.
    QFileInfo fileInfo(fname);
    OpenFlipperSettings().setValue("Core/CurrentDir", fileInfo.absolutePath() );

755
    PluginFunctions::viewerProperties().snapshotBaseFileName(fname);
756
    QString msg=tr("next snapshot: ");
757
758
759
    statusBar()->showMessage(msg);
  }

760
761
}

Jan Möbius's avatar
 
Jan Möbius committed
762
void CoreWidget::slotAddContextItem(QAction* _entry, ContextMenuType _type) {
Jan Möbius's avatar
 
Jan Möbius committed
763
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
764
765
  info.action = _entry;
  info.type   = _type;
Jan Möbius's avatar
Jan Möbius committed
766

Jan Möbius's avatar
Marlin:  
Jan Möbius committed
767
768
  contextMenus_.push_back(info); 
  slotAddContextItemToViewMode(_entry);
Jan Möbius's avatar
 
Jan Möbius committed
769
770
}

Jan Möbius's avatar
 
Jan Möbius committed
771
void CoreWidget::slotAddContextItem( QAction* _entry , DataType _dataType ,ContextMenuType _type ) {
Jan Möbius's avatar
 
Jan Möbius committed
772
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
773
  info.action      = _entry;
Jan Möbius's avatar
 
Jan Möbius committed
774
  info.contextType = _dataType;
Jan Möbius's avatar
 
Jan Möbius committed
775
  info.type        = _type;
Jan Möbius's avatar
Jan Möbius committed
776

Jan Möbius's avatar
 
Jan Möbius committed
777
  contextMenus_.push_back(info);
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
  slotAddContextItemToViewMode(_entry);
}

void CoreWidget::slotAddContextItemToViewMode( QAction* _entry ) {
  int id = -1;
  // Find the plugin which added this Context Menu
  for ( uint i = 0 ; i < plugins_.size(); ++i ) {
    if ( plugins_[i].plugin == sender() ) {
      id = i;
      break;
    }
  }

  // Find the scripting plugin because we assign this context menu to it as we did not find the original sender
  if ( id == -1 ) {
    for ( uint i = 0 ; i < plugins_.size(); ++i ) {
      if ( plugins_[i].name == "Scripting" ) {
        id = i;
        break;
      }
    }


    if ( id == -1 ) {
      std::cerr << "Unknown sender plugin when adding Context Menu!" << std::endl;
      return;
    }
  }

  plugins_[id].contextMenus.push_back( std::pair< QString,QAction* >( plugins_[id].name + "->" + _entry->text(), _entry) );

  // add widget name to viewMode 'all'
  if ( !viewModes_[0]->visibleContextMenus.contains(plugins_[id].name + "->" + _entry->text()) ){
    viewModes_[0]->visibleContextMenus << plugins_[id].name + "->" + _entry->text();
    viewModes_[0]->visibleContextMenus.sort();
  }

  setViewMode( OpenFlipper::Options::currentViewMode() );
Jan Möbius's avatar
 
Jan Möbius committed
816
817
}

818
819
void CoreWidget::slotUpdateViewerDrawMenu() {
  if ( drawGroupViewer_ ) {
820

821
822
823
824
    disconnect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
                this             , SLOT( slotViewerDrawMenu( QAction * ) ) );
    delete( drawGroupViewer_ );
    drawGroupViewer_ = 0;
825

826
  }
827

828
829
830
  // Recreate drawGroup
  drawGroupViewer_ = new QActionGroup( this );
  drawGroupViewer_->setExclusive( false );
831

832
  connect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
833
834
           this       , SLOT( slotViewerDrawMenu( QAction * ) ) );

835
  if ( !viewerDrawMenu_ ) {
836

837
838
    QIcon icon;
    icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
839
    viewerDrawMenu_  = new QMenu(tr("Set Draw Mode"));
840
841
    viewerDrawMenu_->setTearOffEnabled(true);
    viewerDrawMenu_->setIcon(icon);
842

843
844
    connect(viewerDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
  }
845

846
847
  // Collect available draw modes
  // Single pass action, draw modes independent from multipass rendering
848
849
850
  ACG::SceneGraph::CollectDrawModesAction actionAvailable;
  ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
  availableGlobalDrawModes_ = actionAvailable.drawModes();
851

852
853
  // Get currently active drawModes (first viewer only )
  // TODO: create combination from all viewers!
Jan Möbius's avatar
Jan Möbius committed
854
  ACG::SceneGraph::DrawModes::DrawMode activeDrawModes = PluginFunctions::drawMode();
855

856
  // Convert to ids
Jan Möbius's avatar
Jan Möbius committed
857
858
  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
  availDrawModeIds = availableGlobalDrawModes_.getAtomicDrawModes() ;
859

860
  viewerDrawMenu_->clear();
861

862
863
  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
  {
Jan Möbius's avatar
Jan Möbius committed
864
865
    ACG::SceneGraph::DrawModes::DrawMode id    = availDrawModeIds[i];
    std::string  descr =  id.description();
866
867
868

    QAction * action = new QAction( descr.c_str(), drawGroupViewer_ );
    action->setCheckable( true );
Jan Möbius's avatar
Jan Möbius committed
869
    action->setChecked(  activeDrawModes.containsAtomicDrawMode(id) );
870
871
872
873
874
875
876
  }

  viewerDrawMenu_->addActions( drawGroupViewer_->actions() );

}

void CoreWidget::slotViewerDrawMenu(QAction * _action) {
877

878
879
880
  //======================================================================================
  // Get the mode toggled
  //======================================================================================
Jan Möbius's avatar
Jan Möbius committed
881
882
883
  ACG::SceneGraph::DrawModes::DrawMode mode = 0;
  std::vector< ACG::SceneGraph::DrawModes::DrawMode > availDrawModeIds;
  availDrawModeIds = availableGlobalDrawModes_.getAtomicDrawModes();
884
885
  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
  {
Jan Möbius's avatar
Jan Möbius committed
886
    QString descr = QString(  availDrawModeIds[i].description().c_str() );
887
888
889
890
891
892

    if ( descr == _action->text() ) {
      mode = availDrawModeIds[i];
      break;
    }
  }
893

894
895
896
897
  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
    PluginFunctions::viewerProperties().drawMode(  PluginFunctions::viewerProperties().drawMode() ^ mode );
  else
    PluginFunctions::viewerProperties().drawMode(mode );
898

899
900
}

901
902
void CoreWidget::slotPostProcessorMenu( QAction * _action)  {
  unsigned int mode = _action->data().toUInt();
Jan Möbius's avatar
Jan Möbius committed
903
  postProcessorManager().setActive(mode,PluginFunctions::activeExaminer());
904
905
}

Jan Möbius's avatar
Jan Möbius committed
906
907
908
909
910
void CoreWidget::slotRenderMenu( QAction * _action)  {
  unsigned int mode = _action->data().toUInt();
  renderManager().setActive(mode,PluginFunctions::activeExaminer());
}

Jan Möbius's avatar
 
Jan Möbius committed
911
//=============================================================================