ContextMenu.cc 36.7 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2
3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4
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
33
34
35
36
37
38
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
41

42
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
43
44
45
46
47
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
48
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63



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


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

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

Jan Möbius's avatar
Jan Möbius committed
64
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
65
66

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

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

Jan Möbius's avatar
Jan Möbius committed
71
72
73
74
  // 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());
75

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

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

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

Marcel Campen's avatar
Marcel Campen committed
85
86
87
88
void CoreWidget::slotHideContextMenu() {
  contextMenu_->hide();
}

89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/** \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());

107
  addContextMenus( _menu , CONTEXTNODEMENU, _node->id() ) ;
108
109
}

Jan Möbius's avatar
Jan Möbius committed
110
/** \brief Update context Menu when Coordsys node has been clicked on.
111
 *
Jan Möbius's avatar
Jan Möbius committed
112
113
114
 * 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...
115
 *
Jan Möbius's avatar
Jan Möbius committed
116
117
118
 * @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
119
void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu  , const int /*_part*/) {
120
121
122
    
  QString iconPath = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
  
123
  QAction* typeEntry = new QAction(tr("Viewer Settings"),_menu);
Jan Möbius's avatar
Jan Möbius committed
124
  _menu->addAction( typeEntry );
125
  typeEntry->setDisabled(true);
126
  _menu->addSeparator();
127
128
129
130
131
132
133
134
135
136
137
  
  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);
138

Jan Möbius's avatar
Jan Möbius committed
139
  //====================================================================================================
140
141
142
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
143
144
  if (! viewerDrawMenu_->isEmpty())
    _menu->addMenu( viewerDrawMenu_ );
145

146
147
148
  //====================================================================================================
  // RenderingOptions
  //====================================================================================================
149
  
150
  QMenu* renderingOptionsMenu = new QMenu(tr("Rendering Options"),_menu);
151
  renderingOptionsMenu->setIcon( QIcon(iconPath+"core_renderingOptions.png") );
152
  _menu->addMenu(renderingOptionsMenu);
153

154
155
  QAction* projectionAction = 0;
  if ( examiner_widgets_[PluginFunctions::activeExaminer() ]->projectionMode() == glViewer::PERSPECTIVE_PROJECTION ) {
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
167
168
  projectionAction->setToolTip(   tr("Switch between <b>perspective</b> and "
      "<b>parrallel</b> projection mode."));
  projectionAction->setWhatsThis( tr("Switch projection modes<br><br>"
169
      "Switch between <b>perspective</b> and "
170
      "<b>parrallel</b> projection mode."));
171
172
  connect( projectionAction,SIGNAL( triggered() ), this, SLOT( slotContextSwitchProjection() ) );
  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
181
  animation->setChecked( PluginFunctions::viewerProperties(PluginFunctions::activeExaminer()).animation() );
  connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeAnimation(bool) ) );
182
183


184
185
  //====================================================================================================

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

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

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

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

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

Jan Möbius's avatar
Jan Möbius committed
220
221
222
223
224
225
  //============================================================================================================
  // Renderer Menu
  //============================================================================================================

  if ( renderManager().available() > 1 ) {
    QMenu* rendererMenu = new QMenu(tr("Renderers"),_menu);
226
    rendererMenu->setIcon(QIcon(iconPath+"renderers.png"));
Jan Möbius's avatar
Jan Möbius committed
227
228
229
230
231
232
233

    _menu->addMenu(rendererMenu);

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

234
235
236
237

    // Get the options action for the currently active renderer
    if( renderManager()[ renderManager().activeId(PluginFunctions::activeExaminer() )]->optionsAction != 0 ) {
      rendererMenu->addAction(renderManager()[ renderManager().activeId(PluginFunctions::activeExaminer() ) ]->optionsAction );
Jan Möbius's avatar
Jan Möbius committed
238

239
240
    }

Jan Möbius's avatar
Jan Möbius committed
241
242
243
244
    QAction* showRendererDialog = new QAction(tr("Show renderer manager"),this);
    connect(showRendererDialog,SIGNAL(triggered()),this,SLOT(slotShowRenderManager()));
    rendererMenu->addAction(showRendererDialog);

Jan Möbius's avatar
Jan Möbius committed
245
246
247
248
    QAction* showRendererObjectWidget = new QAction(tr("Show render objects"),this);
    connect(showRendererObjectWidget,SIGNAL(triggered()),this,SLOT(slotShowRenderObjectWidget()));
    rendererMenu->addAction(showRendererObjectWidget);

Jan Möbius's avatar
Jan Möbius committed
249
250
    rendererMenu->addSeparator();

Jan Möbius's avatar
Jan Möbius committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
    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 * ) ) );

  }

274
275
276
277
278
  //============================================================================================================
  // Viewing Direction Menu
  //============================================================================================================

  QMenu* viewingDirectionMenu = new QMenu( tr("Viewing Direction"), _menu);
279
  viewingDirectionMenu->setIcon(QIcon(iconPath+"core_viewingDirection.png"));
280
281
282
283
284
285
286
  _menu->addMenu(viewingDirectionMenu);

  QActionGroup* dirGroup = new QActionGroup(this);

  QAction* viewAction;
  // freeView
  viewAction = new QAction( tr("Free View"), viewingDirectionMenu );
287
  viewAction->setIcon( QIcon(iconPath+"orthogonal.png") );
288
289
290
291
292
293
294
295
  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 );
296
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_top.png") );
297
298
299
300
301
302
303
  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 );
304
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_bottom.png") );
305
306
307
308
309
310
311
  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 );
312
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_left.png") );
313
314
315
316
317
318
319
  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 );
320
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_right.png") );
321
322
323
324
325
326
327
  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 );
328
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_front.png") );
329
330
331
332
333
334
335
  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 );
336
  viewAction->setIcon( QIcon(iconPath+"viewcontrol_back.png") );
337
338
339
340
341
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_BACK );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BACK );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);
342
343
  
  viewingDirectionMenu->addSeparator();
344
345

  connect( dirGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSetViewingDirection(QAction*) ) );
346
347
348
349
350
351
  
  //===========================================================================
  // Check box to determine whether rotation should be locked or not
  
  QAction* lockAction = viewingDirectionMenu->addAction("Lock rotation");
  lockAction->setCheckable( true );
352
  lockAction->setIcon( QIcon(iconPath+"lock_rotation.png") );
353
354
355
356
357
358
  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) ) );
  
359
360
361
  //====================================================================================================
  // Other Toplevel Action
  //====================================================================================================
362

363
  _menu->addSeparator();
364

365
  //====================================================================================================
366

367
368
369
370
371
372
373
374
375
376
377
378
379
  //============================================================================================================
  // Post processor Manager
  //============================================================================================================

  QAction* showPostProcessorDialog = new QAction(tr("Show post processor manager"),this);
  showPostProcessorDialog->setIcon(QIcon(iconPath+"postprocessors.png"));
  connect(showPostProcessorDialog,SIGNAL(triggered()),this,SLOT(slotShowPostProcessorManager()));
  _menu->addAction(showPostProcessorDialog);

  _menu->addSeparator();

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

380
  QAction* homeAction = new QAction(tr("Restore home view"),_menu);
381
  homeAction->setIcon( QIcon(iconPath+"go-home.png") );
382
  homeAction->setCheckable( false );
383
384
385
  homeAction->setToolTip(tr("Restore <b>home</b> view."));
  homeAction->setWhatsThis( tr("Restore home view<br><br>"
                            "Resets the view to the home view"));
386
387
  _menu->addAction( homeAction );
  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
393
394
  setHomeAction->setToolTip(tr("Set <b>home</b> view"));
  setHomeAction->setWhatsThis( tr("Store home view<br><br>"
                               "Stores the current view as the home view"));
395
  _menu->addAction( setHomeAction);
396
397
  connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotContextSetHomeView() ) );

398
  QAction* viewAllAction = new QAction( tr("View all"), _menu );
399
  viewAllAction->setIcon( QIcon(iconPath+"viewall.png") );
400
  viewAllAction->setCheckable( false );
401
402
403
404
  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."));
405
406
  connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotContextViewAll() ) );
  _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
417
418
419
  connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );

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

420
421
  QAction* pasteView = _menu->addAction(tr("Paste View"));
  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
428
429
430
431
432
433
  QAction* pasteViewAndWindow = _menu->addAction(tr("Paste View and Window Size"));
  pasteViewAndWindow->setToolTip(tr("Paste current view, window size and the toolbox size from clipboard"));
  pasteViewAndWindow->setIcon( QIcon(iconPath+"edit-paste.png") );
  connect(pasteViewAndWindow, SIGNAL(triggered()), this , SLOT( slotPasteViewAndWindow( ) ) );

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

434
435
  QAction* snapshot_examiner = _menu->addAction(tr("Examiner Snapshot"));
  snapshot_examiner->setToolTip(tr("Take a snapshot of the current examiner"));
436
  snapshot_examiner->setIcon( QIcon(iconPath+"snapshot.png") );
437
438
439
440
441
442
  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"));
443
  snapshot_viewer->setIcon( QIcon(iconPath+"snapshot.png") );
444
  connect(snapshot_viewer, SIGNAL(triggered()), this, SLOT( viewerSnapshotDialog() ) );
445

446
447
}

Jan Möbius's avatar
Jan Möbius committed
448
/** \brief Update context Menu when background has been clicked on.
449
 *
Jan Möbius's avatar
Jan Möbius committed
450
 * This function is called when the background in a viewer has been clicked on.
451
 * This context menu will show functions which are related to the background of the
Jan Möbius's avatar
Jan Möbius committed
452
 * viewer.
453
 *
Jan Möbius's avatar
Jan Möbius committed
454
455
456
 * @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
457
void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& /*_point*/) {
458

459
460
461
462
463
464
465
  //====================================================================================================
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
  _menu->addMenu( viewerDrawMenu_ );

  _menu->addSeparator();
466
  
467
468
  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
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
  /*
Mike Kremer's avatar
Mike Kremer committed
475
   * Show coordsys context menu of coordsys if
476
477
478
479
480
481
482
   * invisible...
   */

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

  if(!coordSys->visible()) {
483
484

	  if(!coordSysMenu_) {
485
		  coordSysMenu_ = new QMenu(tr("Viewer Settings"), _menu);
486
487
		  updatePopupMenuCoordsysNode(coordSysMenu_, 0);
	  }
488
	  _menu->addSeparator();
489
	  _menu->addMenu(coordSysMenu_);
490
491
  }

492
493
494
495
496
  // Tell Plugins to update their context Menu
  emit updateContextMenuBackground();

  addContextMenus( _menu , CONTEXTBACKGROUNDMENU ) ;

Jan Möbius's avatar
Jan Möbius committed
497
}
Jan Möbius's avatar
Jan Möbius committed
498

Jan Möbius's avatar
Jan Möbius committed
499
/** \brief Update popup Menu when an object has been clicked on.
500
 *
Jan Möbius's avatar
Jan Möbius committed
501
502
 * This function is called when an object has been clicked on.
 * This context menu will show all properties for the given object.
503
 *
Jan Möbius's avatar
Jan Möbius committed
504
 * @param _menu Pointer to the context Menu
Jan Möbius's avatar
Jan Möbius committed
505
 * @param _object Object that has been clicked on.
Jan Möbius's avatar
Jan Möbius committed
506
 */
507
508
void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) {

509
  QAction* typeEntry = new QAction( typeName(_object->dataType())+QString(": ")+_object->name() ,_menu);
510
  typeEntry->setIcon(typeIcon(_object->dataType()));
511
512
513
514
515
516
517
518
519
520
521
  _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
522
  if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) {
523
    pickMenu_->setTitle(tr("&Picking"));
524
525
    contextMenu_->addMenu( pickMenu_ );
    pickMenu_->setTearOffEnabled(true);
526
527
528
529
530
531
532
  }
}

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

  bool added = false;

533
534
535
  QMap< QString , QAction* > menuMap; //QMap sorts by key
  QMap< QString , QAction* > actionMap;

536
537
538
539
540
541
542
543
544
545
546
547
  // 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) ) {
548
          emit log(LOGERR,tr("Cant get object for objectContextMenu"));
549
550
551
552
553
554
555
556
557
558
559
560
561
          continue;
        }

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

        break;
      case CONTEXTNODEMENU:
        break;

    }

562
563
564
565
566
567
    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;
568
569
570
571
572

    added = true;

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

Jan Möbius's avatar
 
Jan Möbius committed
574
575
576
577
578
579
580
581

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

582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
    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
597
598
599
600
601
602
603
604
  //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;
    }
  }
605
606
607
608
609
610

  // 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
611
612
  
  /// \todo Sort the menu entries by the order given in visibleContextMenus
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
613
  
614
615
  //first add all menus
  QMapIterator<QString, QAction*> it(menuMap);
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
616
617
  
  QStringList visible = viewModes_[id]->visibleContextMenus;
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
618
619
620
621
  if (visible.contains("ALL_THAT_EXIST")) {
    //this plugin adds all context menus, no special configuration so far.
    visible = viewModes_[0]->visibleContextMenus;
  }
622
623

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

626
627
628
  // Remove accelerator specifications
  visible.replaceInStrings("&", "");

629
  while (it.hasNext()) {
630
631
632
633
634
635
636
    it.next();

	for ( int i = 0 ; i < visible.size(); ++i ) {
	  if ( it.key().contains(visible[i]) ) {
	    _menu->addAction( it.value() );
	  }
    }
637
638
639
640
641
642
  }

  _menu->addSeparator();

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

644
645
  while (it2.hasNext()) {
     it2.next();
646
647
648
649
650
651

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

  return added;
Jan Möbius's avatar
Jan Möbius committed
655
}
Jan Möbius's avatar
Jan Möbius committed
656
657


658
 
659
660
661
/** \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
662
663
664
665
 * 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
666

Jan Möbius's avatar
Jan Möbius committed
667
668
  // Clear the complete context menu.
  contextMenu_->clear();
669

Jan Möbius's avatar
Jan Möbius committed
670
671
  // Clear the selection context menu part.
  contextSelectionMenu_->clear();
Jan Möbius's avatar
Jan Möbius committed
672

Jan Möbius's avatar
Jan Möbius committed
673
674
675
  // =============================================================================
  // First do a picking on the current position to check which context we are in.
  // =============================================================================
676

Jan Möbius's avatar
Jan Möbius committed
677
  enum CONTEXTTYPE {
678
    COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT, NODECONTEXT
Jan Möbius's avatar
Jan Möbius committed
679
  } context = BACKGROUNDCONTEXT;
Jan Möbius's avatar
Jan Möbius committed
680

Jan Möbius's avatar
 
Jan Möbius committed
681
  // Do picking in the gl area to find an object
682
683
  unsigned int               node_idx, target_idx;
  ACG::Vec3d                 hit_point;
Jan Möbius's avatar
Jan Möbius committed
684
685
  BaseObjectData*            object = 0;
  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

Jan Möbius's avatar
Jan Möbius committed
689
690
691
    if ( PluginFunctions::getPickedObject(node_idx, object) ) {
      context  = OBJECTCONTEXT;
    } else {
692
693
      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
694
        context = COORDSYSCONTEXT;
695
696
      else
        context = NODECONTEXT;
697
    }
698
699
  }

Jan Möbius's avatar
Jan Möbius committed
700
701
702
  // =============================================================================
  // Depending on the context create the basic context menu.
  // =============================================================================
703

Jan Möbius's avatar
Jan Möbius committed
704
  QIcon icon;
705

Jan Möbius's avatar
Jan Möbius committed
706
707
708
  switch (context) {
    case BACKGROUNDCONTEXT:
      updatePopupMenuBackground(contextMenu_,_point);
709
      return;
Jan Möbius's avatar
Jan Möbius committed
710
711
      break;
    case OBJECTCONTEXT:
712
      updatePopupMenuObject(contextMenu_ , object );
713
      return;
Jan Möbius's avatar
Jan Möbius committed
714
715
716
      break;
    case COORDSYSCONTEXT:
      updatePopupMenuCoordsysNode(contextMenu_,target_idx);
717
      return;
Jan Möbius's avatar
Jan Möbius committed
718
      break;
719
720
721
722
    case NODECONTEXT:
      updatePopupMenuNode(contextMenu_,node);
      return;
      break;
Jan Möbius's avatar
 
Jan Möbius committed
723
  }
Jan Möbius's avatar
Jan Möbius committed
724

Jan Möbius's avatar
 
Jan Möbius committed
725
726
}

727

728
729
void CoreWidget::slotSnapshotName() {
  std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
730
731
732
733

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

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

738
739
740
741
  if (!fname.isEmpty())
  {
    fname.replace('$', '%');

Jan Möbius's avatar
Jan Möbius committed
742
743
744
745
746

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

747
    PluginFunctions::viewerProperties().snapshotBaseFileName(fname);
748
    QString msg=tr("next snapshot: ");
749
750
751
    statusBar()->showMessage(msg);
  }

752
753
}

Jan Möbius's avatar
 
Jan Möbius committed
754
void CoreWidget::slotAddContextItem(QAction* _entry, ContextMenuType _type) {
Jan Möbius's avatar
 
Jan Möbius committed
755
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
756
757
  info.action = _entry;
  info.type   = _type;
Jan Möbius's avatar
Jan Möbius committed
758

Jan Möbius's avatar
Marlin:  
Jan Möbius committed
759
760
  contextMenus_.push_back(info); 
  slotAddContextItemToViewMode(_entry);
Jan Möbius's avatar
 
Jan Möbius committed
761
762
}

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

Jan Möbius's avatar
 
Jan Möbius committed
769
  contextMenus_.push_back(info);
Jan Möbius's avatar
Marlin:  
Jan Möbius committed
770
771
772
773
774
775
776
777
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
  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
808
809
}

810
811
void CoreWidget::slotUpdateViewerDrawMenu() {
  if ( drawGroupViewer_ ) {
812

813
814
815
816
    disconnect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
                this             , SLOT( slotViewerDrawMenu( QAction * ) ) );
    delete( drawGroupViewer_ );
    drawGroupViewer_ = 0;
817

818
  }
819

820
821
822
  // Recreate drawGroup
  drawGroupViewer_ = new QActionGroup( this );
  drawGroupViewer_->setExclusive( false );
823

824
  connect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
825
826
           this       , SLOT( slotViewerDrawMenu( QAction * ) ) );

827
  if ( !viewerDrawMenu_ ) {
828

829
830
    QIcon icon;
    icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
831
    viewerDrawMenu_  = new QMenu(tr("Set Draw Mode"));
832
833
    viewerDrawMenu_->setTearOffEnabled(true);
    viewerDrawMenu_->setIcon(icon);
834

835
836
    connect(viewerDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
  }
837

Matthias Möller's avatar
Matthias Möller committed
838
839
840
841
842
  if (viewerDrawMenuWidget_) {
    delete viewerDrawMenuWidget_;
  }
  viewerDrawMenuWidget_ = new QWidget(viewerDrawMenu_);

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

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

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

857
  viewerDrawMenu_->clear();
858

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

Matthias Möller's avatar
Matthias Möller committed
864
    QCheckBox *checkBox = new QCheckBox(QString(descr.c_str()), viewerDrawMenuWidget_);
Marcel Campen's avatar
Marcel Campen committed
865
866
867
868
869
    checkBox->setChecked(activeDrawModes.containsAtomicDrawMode(id));
    QWidgetAction *checkableAction = new QWidgetAction(drawGroupViewer_);
    checkableAction->setText(descr.c_str());
    checkableAction->setDefaultWidget(checkBox);
    connect(checkBox, SIGNAL(toggled(bool) ), checkableAction, SLOT(trigger() ) );
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
  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
    PluginFunctions::viewerProperties().drawMode(  PluginFunctions::viewerProperties().drawMode() ^ mode );
  else
Marcel Campen's avatar
Marcel Campen committed
897
898
  {
    contextMenu_->hide();
899
    PluginFunctions::viewerProperties().drawMode(mode );
Marcel Campen's avatar
Marcel Campen committed
900
  }
901

902
903
}

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

Jan Möbius's avatar
Jan Möbius committed
909
910
911
void CoreWidget::slotRenderMenu( QAction * _action)  {
  unsigned int mode = _action->data().toUInt();
  renderManager().setActive(mode,PluginFunctions::activeExaminer());
912
913
914
915

  QString defaultRendererKey  = "Viewer" + QString::number(PluginFunctions::activeExaminer())+"/DefaultRenderer";
  QString defaultRendererName = renderManager()[mode]->name;
  OpenFlipperSettings().setValue(defaultRendererKey,defaultRendererName);
Jan Möbius's avatar
Jan Möbius committed
916
917
}

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