ContextMenu.cc 28.3 KB
Newer Older
1
2
3
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
/*===========================================================================*\
 *                                                                           *
 *                              OpenFlipper                                  *
 *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
 *                           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/>.                                      *
 *                                                                           *
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
34

35
36
37
38
39
40
41
/*===========================================================================*\
 *                                                                           *
 *   $Revision$                                                         *
 *   $Author$                                                      *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
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"
Jan Möbius's avatar
 
Jan Möbius committed
60

Jan Möbius's avatar
Jan Möbius committed
61
//== IMPLEMENTATION ==========================================================
Jan Möbius's avatar
 
Jan Möbius committed
62
63

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

Jan Möbius's avatar
Jan Möbius committed
65
  QPoint   popupPosition;
Jan Möbius's avatar
Jan Möbius committed
66
  QPoint   scenePos;
Jan Möbius's avatar
Jan Möbius committed
67

Jan Möbius's avatar
Jan Möbius committed
68
69
70
71
  // 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());
72

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

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

Jan Möbius's avatar
 
Jan Möbius committed
80
81
}

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/** \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());

100
  addContextMenus( _menu , CONTEXTNODEMENU, _node->id() ) ;
101
102
}

Jan Möbius's avatar
Jan Möbius committed
103
/** \brief Update context Menu when Coordsys node has been clicked on.
104
 *
Jan Möbius's avatar
Jan Möbius committed
105
106
107
 * 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...
108
 *
Jan Möbius's avatar
Jan Möbius committed
109
110
111
 * @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
112
void CoreWidget::updatePopupMenuCoordsysNode(QMenu* _menu  , const int /*_part*/) {
Jan Möbius's avatar
Jan Möbius committed
113
//   std::cerr << "Coordsys part was : " << _part << std::endl;
114
  QAction* typeEntry = new QAction(tr("Viewer Settings"),_menu);
Jan Möbius's avatar
Jan Möbius committed
115
  _menu->addAction( typeEntry );
116
  _menu->addSeparator();
117

Jan Möbius's avatar
Jan Möbius committed
118
  //====================================================================================================
119
120
121
122
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
  _menu->addMenu( viewerDrawMenu_ );
123

124
125
126
  //====================================================================================================
  // RenderingOptions
  //====================================================================================================
127

128
  QMenu* renderingOptionsMenu = new QMenu(tr("Rendering Options"),_menu);
Jan Möbius's avatar
Jan Möbius committed
129
  renderingOptionsMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"core_renderingOptions.png") );
130
  _menu->addMenu(renderingOptionsMenu);
131

132
133
  QAction* projectionAction = 0;
  if ( examiner_widgets_[PluginFunctions::activeExaminer() ]->projectionMode() == glViewer::PERSPECTIVE_PROJECTION ) {
134
    projectionAction = new QAction( tr("Switch to Orthogonal Projection"), renderingOptionsMenu );
135
    projectionAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
136
    projectionAction->setToolTip(   tr("Switch to perspective orthogonal mode."));
137
  } else {
138
    projectionAction = new QAction( tr("Switch to Perspective Projection"), renderingOptionsMenu );
139
    projectionAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"perspective.png") );
140
    projectionAction->setToolTip(   tr("Switch to perspective projection mode."));
141
  }
142

143
  projectionAction->setCheckable( false );
144
145
146
  projectionAction->setToolTip(   tr("Switch between <b>perspective</b> and "
      "<b>parrallel</b> projection mode."));
  projectionAction->setWhatsThis( tr("Switch projection modes<br><br>"
147
      "Switch between <b>perspective</b> and "
148
      "<b>parrallel</b> projection mode."));
149
150
  connect( projectionAction,SIGNAL( triggered() ), this, SLOT( slotContextSwitchProjection() ) );
  renderingOptionsMenu->addAction( projectionAction );
151
152


153
  QAction* animation = renderingOptionsMenu->addAction(tr("Animation"));
154

155
  animation->setToolTip(tr("Animate rotation of objects"));
156
157
158
159
  animation->setCheckable( true );
  animation->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"animation.png") );
  animation->setChecked( PluginFunctions::viewerProperties(PluginFunctions::activeExaminer()).animation() );
  connect(animation, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeAnimation(bool) ) );
160
161


162
163
  //====================================================================================================

164
165
  QAction* backfaceCulling = renderingOptionsMenu->addAction(tr("Backface Culling"));
  backfaceCulling->setToolTip(tr("Enable backface culling"));
166
167
168
169
170
171
172
  backfaceCulling->setCheckable( true );
  backfaceCulling->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"backFaceCulling.png") );
  backfaceCulling->setChecked( PluginFunctions::viewerProperties().backFaceCulling() );
  connect(backfaceCulling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeBackFaceCulling(bool) ) );

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

173
174
  QAction* twoSidedLighting = renderingOptionsMenu->addAction(tr("Two-sided Lighting"));
  twoSidedLighting->setToolTip(tr("Enable two-sided lighting"));
175
176
177
178
  twoSidedLighting->setCheckable( true );
  twoSidedLighting->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"twosidedLighting.png") );
  twoSidedLighting->setChecked( PluginFunctions::viewerProperties().twoSidedLighting() );
  connect(twoSidedLighting, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeTwoSidedLighting(bool) ) );
179
180
181
  
  //====================================================================================================

182
183
  QAction* multisampling = renderingOptionsMenu->addAction(tr("Multisampling"));
  multisampling->setToolTip(tr("Enable Multisampling"));
184
  multisampling->setCheckable( true );
Dirk Wilden's avatar
Dirk Wilden committed
185
  multisampling->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"multiSampling.png") );
186
187
  multisampling->setChecked( PluginFunctions::viewerProperties().multisampling() );
  connect(multisampling, SIGNAL(triggered(bool)), this , SLOT( slotLocalChangeMultisampling(bool) ) );   
188

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
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
251
252
253
254
255
256
257
258
259
260

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

  QMenu* viewingDirectionMenu = new QMenu( tr("Viewing Direction"), _menu);
//   viewingDirectionMenu->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"renderingOptions.png"));
  _menu->addMenu(viewingDirectionMenu);

  QActionGroup* dirGroup = new QActionGroup(this);

  QAction* viewAction;
  // freeView
  viewAction = new QAction( tr("Free View"), viewingDirectionMenu );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  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 );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  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 );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  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 );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  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 );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  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 );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  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 );
//   viewAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"orthogonal.png") );
  viewAction->setCheckable( true );
  viewAction->setData( PluginFunctions::VIEW_BACK );
  viewAction->setChecked( PluginFunctions::viewerProperties().currentViewingDirection() == PluginFunctions::VIEW_BACK );
  viewingDirectionMenu->addAction( viewAction );
  dirGroup->addAction(viewAction);

  connect( dirGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotSetViewingDirection(QAction*) ) );

261
262
263
  //====================================================================================================
  // Other Toplevel Action
  //====================================================================================================
264

265
  _menu->addSeparator();
266

267
  //====================================================================================================
268

269
  QAction* homeAction = new QAction(tr("Restore home view"),_menu);
270
271
  homeAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"go-home.png") );
  homeAction->setCheckable( false );
272
273
274
  homeAction->setToolTip(tr("Restore <b>home</b> view."));
  homeAction->setWhatsThis( tr("Restore home view<br><br>"
                            "Resets the view to the home view"));
275
276
  _menu->addAction( homeAction );
  connect( homeAction,SIGNAL( triggered() ), this, SLOT( slotContextHomeView() ) );
277

278
  QAction* setHomeAction = new QAction( tr("Set Home View") , _menu );
279
280
  setHomeAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"set-home.png") );
  setHomeAction->setCheckable( false );
281
282
283
  setHomeAction->setToolTip(tr("Set <b>home</b> view"));
  setHomeAction->setWhatsThis( tr("Store home view<br><br>"
                               "Stores the current view as the home view"));
284
  _menu->addAction( setHomeAction);
285
286
  connect( setHomeAction,SIGNAL( triggered() ), this, SLOT( slotContextSetHomeView() ) );

287
  QAction* viewAllAction = new QAction( tr("View all"), _menu );
288
289
  viewAllAction->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"viewall.png") );
  viewAllAction->setCheckable( false );
290
291
292
293
  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."));
294
295
  connect( viewAllAction,SIGNAL( triggered() ), this, SLOT( slotContextViewAll() ) );
  _menu->addAction( viewAllAction);
296
297


298
  _menu->addSeparator();
299

300
  //====================================================================================================
301

302
303
  QAction* copyView = _menu->addAction(tr("Copy View"));
  copyView->setToolTip(tr("Copy current view to clipboard"));
Dirk Wilden's avatar
Dirk Wilden committed
304
  copyView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-copy.png") );
305
306
307
308
  connect(copyView, SIGNAL(triggered()), this, SLOT(slotCopyView()) );

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

309
310
  QAction* pasteView = _menu->addAction(tr("Paste View"));
  pasteView->setToolTip(tr("Paste current view from clipboard"));
Dirk Wilden's avatar
Dirk Wilden committed
311
  pasteView->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"edit-paste.png") );
312
  connect(pasteView, SIGNAL(triggered()), this , SLOT( slotPasteView( ) ) );
313

314
  //====================================================================================================
315

316
317
  QAction* snapshot = _menu->addAction(tr("Snapshot"));
  snapshot->setToolTip(tr("Make a snapshot"));
318
319
  snapshot->setIcon( QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"snapshot.png") );
  connect(snapshot, SIGNAL(triggered()), this, SLOT( slotSnapshot() ) );
320

321
322
}

Jan Möbius's avatar
Jan Möbius committed
323
/** \brief Update context Menu when background has been clicked on.
324
 *
Jan Möbius's avatar
Jan Möbius committed
325
 * This function is called when the background in a viewer has been clicked on.
326
 * This context menu will show functions which are related to the background of the
Jan Möbius's avatar
Jan Möbius committed
327
 * viewer.
328
 *
Jan Möbius's avatar
Jan Möbius committed
329
330
331
 * @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
332
void CoreWidget::updatePopupMenuBackground(QMenu* _menu , const QPoint& /*_point*/) {
333

334
335
336
337
338
339
340
341
  //====================================================================================================
  // DrawModes
  //====================================================================================================
  slotUpdateViewerDrawMenu();
  _menu->addMenu( viewerDrawMenu_ );

  _menu->addSeparator();

342
343
  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
344
  action->setStatusTip(tr("Set the background color for the current viewer"));
345
  action->setWhatsThis(tr("Set the background color for the current viewer"));
346
  action->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"BackgroundColor.png") );
347
  connect(action, SIGNAL(triggered()), this, SLOT(slotSetContextBackgroundColor()) );
348

349
  /*
Mike Kremer's avatar
Mike Kremer committed
350
   * Show coordsys context menu of coordsys if
351
352
353
354
355
356
357
   * invisible...
   */

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

  if(!coordSys->visible()) {
358
359

	  if(!coordSysMenu_) {
360
		  coordSysMenu_ = new QMenu(tr("Viewer Settings"), _menu);
361
362
		  updatePopupMenuCoordsysNode(coordSysMenu_, 0);
	  }
363
	  _menu->addSeparator();
364
	  _menu->addMenu(coordSysMenu_);
365
366
  }

367
368
369
370
371
  // Tell Plugins to update their context Menu
  emit updateContextMenuBackground();

  addContextMenus( _menu , CONTEXTBACKGROUNDMENU ) ;

Jan Möbius's avatar
Jan Möbius committed
372
}
Jan Möbius's avatar
Jan Möbius committed
373

Jan Möbius's avatar
Jan Möbius committed
374
/** \brief Update context Menu an object has been clicked on.
375
 *
Jan Möbius's avatar
Jan Möbius committed
376
377
 * This function is called when an object has been clicked on.
 * This context menu will show all properties for the given object.
378
 *
Jan Möbius's avatar
Jan Möbius committed
379
380
381
 * @param _menu Pointer to the context Menu
 * @param _objectId Id of the object that has been clicked on.
 */
382
383
384
void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) {

  QAction* typeEntry = new QAction( typeName(_object->dataType()) ,_menu);
385
  typeEntry->setIcon(typeIcon(_object->dataType()));
386
387
388
389
390
391
392
393
394
395
396
  _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
397
  if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) {
398
    pickMenu_->setTitle(tr("&Picking"));
399
400
    contextMenu_->addMenu( pickMenu_ );
    pickMenu_->setTearOffEnabled(true);
401
402
403
404
405
406
407
  }
}

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

  bool added = false;

408
409
410
  QMap< QString , QAction* > menuMap; //QMap sorts by key
  QMap< QString , QAction* > actionMap;

411
412
413
414
415
416
417
418
419
420
421
422
  // 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) ) {
423
          emit log(LOGERR,tr("Cant get object for objectContextMenu"));
424
425
426
427
428
429
430
431
432
433
434
435
436
          continue;
        }

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

        break;
      case CONTEXTNODEMENU:
        break;

    }

437
438
439
440
441
442
    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;
443
444
445
446
447

    added = true;

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

Jan Möbius's avatar
 
Jan Möbius committed
449
450
451
452
453
454
455
456

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

457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
    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;
    }

  }

472
473
474
475
476
477
478
479
480
481
482
483
  //first add all menus
  QMapIterator<QString, QAction*> it(menuMap);

  while (it.hasNext()) {
     it.next();
    _menu->addAction( it.value() );
  }

  _menu->addSeparator();

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

485
486
487
488
489
490
  while (it2.hasNext()) {
     it2.next();
    _menu->addAction( it2.value() );
  }

  return added;
Jan Möbius's avatar
Jan Möbius committed
491
}
Jan Möbius's avatar
Jan Möbius committed
492
493
494



495
496
497
/** \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
498
499
500
501
 * 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
502

Jan Möbius's avatar
Jan Möbius committed
503
504
  // Clear the complete context menu.
  contextMenu_->clear();
505

Jan Möbius's avatar
Jan Möbius committed
506
507
  // Clear the selection context menu part.
  contextSelectionMenu_->clear();
Jan Möbius's avatar
Jan Möbius committed
508

Jan Möbius's avatar
Jan Möbius committed
509
510
511
  // =============================================================================
  // First do a picking on the current position to check which context we are in.
  // =============================================================================
Jan Möbius's avatar
 
Jan Möbius committed
512
  int objectId = -1;
513

Jan Möbius's avatar
Jan Möbius committed
514
  enum CONTEXTTYPE {
515
    COORDSYSCONTEXT ,BACKGROUNDCONTEXT ,OBJECTCONTEXT, NODECONTEXT
Jan Möbius's avatar
Jan Möbius committed
516
  } context = BACKGROUNDCONTEXT;
Jan Möbius's avatar
Jan Möbius committed
517

Jan Möbius's avatar
 
Jan Möbius committed
518
  // Do picking in the gl area to find an object
519
520
521
522
523
  unsigned int               node_idx, target_idx;
  ACG::Vec3d                 hit_point;
  BaseObjectData*            object;
  ACG::SceneGraph::BaseNode* node = 0;

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

Jan Möbius's avatar
Jan Möbius committed
526
    if ( PluginFunctions::getPickedObject(node_idx, object) ) {
Jan Möbius's avatar
 
Jan Möbius committed
527
      objectId = object->id();
Jan Möbius's avatar
Jan Möbius committed
528
529
      context  = OBJECTCONTEXT;
    } else {
530
531
      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
532
        context = COORDSYSCONTEXT;
533
534
      else
        context = NODECONTEXT;
535
    }
536
537
  }

Jan Möbius's avatar
Jan Möbius committed
538
539
540
  // =============================================================================
  // Depending on the context create the basic context menu.
  // =============================================================================
541

Jan Möbius's avatar
Jan Möbius committed
542
  QIcon icon;
543

Jan Möbius's avatar
Jan Möbius committed
544
545
546
  switch (context) {
    case BACKGROUNDCONTEXT:
      updatePopupMenuBackground(contextMenu_,_point);
547
      return;
Jan Möbius's avatar
Jan Möbius committed
548
549
      break;
    case OBJECTCONTEXT:
550
      updatePopupMenuObject(contextMenu_ , object );
551
      return;
Jan Möbius's avatar
Jan Möbius committed
552
553
554
      break;
    case COORDSYSCONTEXT:
      updatePopupMenuCoordsysNode(contextMenu_,target_idx);
555
      return;
Jan Möbius's avatar
Jan Möbius committed
556
      break;
557
558
559
560
    case NODECONTEXT:
      updatePopupMenuNode(contextMenu_,node);
      return;
      break;
Jan Möbius's avatar
 
Jan Möbius committed
561
  }
Jan Möbius's avatar
Jan Möbius committed
562

Jan Möbius's avatar
 
Jan Möbius committed
563
564
}

565

566
567
void CoreWidget::slotSnapshotName() {
  std::cerr << "Todo : slotSnapShotName only sets name for current viewer" << std::endl;
568
569
570
571

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

  fname.replace('%', '$');
572
  fname = QFileDialog::getSaveFileName ( 0, tr("Save snapshot name") );
573
574
575
576
577
  if (!fname.isEmpty())
  {
    fname.replace('$', '%');

    PluginFunctions::viewerProperties().snapshotBaseFileName(fname);
578
    QString msg=tr("next snapshot: ");
579
580
581
    statusBar()->showMessage(msg);
  }

582
583
}

Jan Möbius's avatar
 
Jan Möbius committed
584
void CoreWidget::slotAddContextItem(QAction* _entry, ContextMenuType _type) {
Jan Möbius's avatar
 
Jan Möbius committed
585
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
586
587
  info.action = _entry;
  info.type   = _type;
Jan Möbius's avatar
Jan Möbius committed
588

589
  contextMenus_.push_back(info);
Jan Möbius's avatar
 
Jan Möbius committed
590
591
}

Jan Möbius's avatar
 
Jan Möbius committed
592
void CoreWidget::slotAddContextItem( QAction* _entry , DataType _dataType ,ContextMenuType _type ) {
Jan Möbius's avatar
 
Jan Möbius committed
593
  MenuInfo info;
Jan Möbius's avatar
 
Jan Möbius committed
594
  info.action      = _entry;
Jan Möbius's avatar
 
Jan Möbius committed
595
  info.contextType = _dataType;
Jan Möbius's avatar
 
Jan Möbius committed
596
  info.type        = _type;
Jan Möbius's avatar
Jan Möbius committed
597

Jan Möbius's avatar
 
Jan Möbius committed
598
599
600
  contextMenus_.push_back(info);
}

601
602
void CoreWidget::slotUpdateViewerDrawMenu() {
  if ( drawGroupViewer_ ) {
603

604
605
606
607
    disconnect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
                this             , SLOT( slotViewerDrawMenu( QAction * ) ) );
    delete( drawGroupViewer_ );
    drawGroupViewer_ = 0;
608

609
  }
610

611
612
613
  // Recreate drawGroup
  drawGroupViewer_ = new QActionGroup( this );
  drawGroupViewer_->setExclusive( false );
614

615
  connect( drawGroupViewer_ , SIGNAL( triggered( QAction * ) ),
616
617
           this       , SLOT( slotViewerDrawMenu( QAction * ) ) );

618
  if ( !viewerDrawMenu_ ) {
619

620
621
    QIcon icon;
    icon.addFile(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"drawModes.png");
622
    viewerDrawMenu_  = new QMenu(tr("Set Draw Mode"));
623
624
    viewerDrawMenu_->setTearOffEnabled(true);
    viewerDrawMenu_->setIcon(icon);
625

626
627
    connect(viewerDrawMenu_,SIGNAL(aboutToShow () ) , this, SLOT(slotUpdateGlobalDrawMenu() ) );
  }
628

629
630
  // Collect available draw modes
  // Single pass action, draw modes independent from multipass rendering
631
632
633
  ACG::SceneGraph::CollectDrawModesAction actionAvailable;
  ACG::SceneGraph::traverse( PluginFunctions::getRootNode() , actionAvailable);
  availableGlobalDrawModes_ = actionAvailable.drawModes();
634

635
636
637
  // Get currently active drawModes (first viewer only )
  // TODO: create combination from all viewers!
  int activeDrawModes = PluginFunctions::drawMode();
638

639
640
641
  // Convert to ids
  std::vector< unsigned int > availDrawModeIds;
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
642

643
  viewerDrawMenu_->clear();
644

645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
  {
    unsigned int id    = availDrawModeIds[i];
    std::string  descr = ACG::SceneGraph::DrawModes::description( id );

    QAction * action = new QAction( descr.c_str(), drawGroupViewer_ );
    action->setCheckable( true );
    action->setChecked( ACG::SceneGraph::DrawModes::containsId( activeDrawModes, id ) );
  }

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

}

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

661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
  //======================================================================================
  // Get the mode toggled
  //======================================================================================
  unsigned int mode = 0;
  std::vector< unsigned int > availDrawModeIds;
  availDrawModeIds = ACG::SceneGraph::DrawModes::getDrawModeIDs( availableGlobalDrawModes_ );
  for ( unsigned int i = 0; i < availDrawModeIds.size(); ++i )
  {
    QString descr = QString( ACG::SceneGraph::DrawModes::description( availDrawModeIds[i] ).c_str() );

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

677
678
679
680
  if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
    PluginFunctions::viewerProperties().drawMode(  PluginFunctions::viewerProperties().drawMode() ^ mode );
  else
    PluginFunctions::viewerProperties().drawMode(mode );
681

682
683
}

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