Developer Documentation
picking.cc
1/*===========================================================================*\
2* *
3* OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39* *
40\*===========================================================================*/
41
42
43
44
45
46
47//=============================================================================
48//
49// CLASS CoreWidget - IMPLEMENTATION
50//
51//=============================================================================
52
53
54//== INCLUDES =================================================================
55
56#include "CoreWidget.hh"
57
59
60//-----------------------------------------------------------------------------
61
63
64 // update Buttons
65 moveButton_->setChecked(false);
66 pickButton_->setChecked(false);
67 questionButton_->setChecked(false);
68
69 switch (_am)
70 {
71 case Viewer::ExamineMode:
72 moveButton_->setChecked(true);
73 break;
74 case Viewer::LightMode:
75 break;
76 case Viewer::PickingMode:
77 pickButton_->setChecked(true);
78 break;
79 case Viewer::QuestionMode:
80 questionButton_->setChecked(true);
81 break;
82 }
83
84 if (_am != actionMode_) {
86 actionMode_ = _am;
87
88 // update cursor
89 switch ( _am )
90 {
91 case Viewer::ExamineMode:
92 cursorPainter_->setCursor(QCursor( QPixmap( OpenFlipper::Options::iconDirStr() + QDir::separator() + "cursor_move.png" ) ,0,0 ));
93 break;
94 case Viewer::LightMode:
95 cursorPainter_->setCursor(QCursor( QPixmap( OpenFlipper::Options::iconDirStr() + QDir::separator() + "cursor_light.png" ) ,0,0 ));
96 break;
97 case Viewer::PickingMode:
98 cursorPainter_->setCursor(QCursor( QPixmap( OpenFlipper::Options::iconDirStr() + QDir::separator() + "cursor_arrow.png" ) ,0,0 ));
99 if (pick_mode_idx_ != -1) {
101 }
102 break;
103 case Viewer::QuestionMode:
104 cursorPainter_->setCursor(QCursor( QPixmap( OpenFlipper::Options::iconDirStr() + QDir::separator() + "cursor_whatsthis.png" ) ,0,0 ));
105 break;
106 }
107
108 // Update pickmode toolbar
109 switch ( _am ) {
110 case Viewer::PickingMode:
111 // Show the pickMode Toolbar for this picking mode if it is set
112 if (pick_mode_idx_ != -1) {
113 if (pick_modes_[pick_mode_idx_].toolbar() )
115 else
117 }
118 break;
119
120 default:
122 break;
123 }
124
125 unsigned int maxPases = 1;
126 ACG::Vec3d bbmin,bbmax;
128
129 //update Viewers
130 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
131
132 examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
133 examiner_widgets_[i]->trackMouse(false);
134
135 if(_am == Viewer::PickingMode) {
136 if (pick_mode_idx_ != -1) {
137 examiner_widgets_[i]->trackMouse(pick_modes_[pick_mode_idx_].tracking() );
138 }
139 }
140 }
141
142 //emit pickmodeChanged with either the name of the current pickmode or an empty string
143 if( pickingMode() )
145 else
146 emit(signalPickModeChanged(""));
147 }
148}
149
150//-----------------------------------------------------------------------------
151
153 _am = actionMode_;
154}
155
156//-----------------------------------------------------------------------------
157
158void CoreWidget::setPickMode(const std::string& _mode){
159
160 for (unsigned int i=0; i<pick_modes_.size(); ++i)
161 {
162 if (pick_modes_[i].name() == _mode)
163 {
164 pickMode( i );
166 return;
167 }
168 }
169}
170
171//-----------------------------------------------------------------------------
172
173void CoreWidget::getPickMode(std::string& _mode){
174 _mode = pick_mode_name_;
175}
176
177//-----------------------------------------------------------------------------
178
179void CoreWidget::setActivePickToolBar(QToolBar* _tool) {
180
181 if(_tool != 0) {
182
183 // Hide all picking toolbars
185
186 bool showInScene = OpenFlipperSettings().value("Core/Gui/ToolBars/PickToolbarInScene", true).toBool();
187
188#ifdef WIN32 //workaround for coreprofile since qt 5.9 is simply too buggy on windows
189 //remove this entire ifdef, as soon as qt can render on windows
190 //(qpainter does not work on coreprofiles)
191 if(OpenFlipper::Options::coreProfile())
192 showInScene = false;
193#endif
194
195 if ( showInScene ) {
196
197 // Try to find toolbar in local map ( if it is in the gl scene
198 PickToolBarMap::iterator ret = curPickingToolbarItems_.find(_tool);
199 if(ret == curPickingToolbarItems_.end()) {
200
201 // Set horizontal orientation
202 _tool->setOrientation(Qt::Horizontal);
203
204 // Update size as the orientation changed
205 _tool->adjustSize();
206
207 // Add widget to the gl scene
208 QGraphicsProxyWidget* item = glScene_->addWidget(_tool);
209
210
211 // Put it into center of the screen
212 int midP = (glScene_->width() / 2) - (int)(_tool->width() / 2);
213 item->setPos(midP, 3);
214
215 item->show();
216
217 // Remember it as being part of the scene
218 curPickingToolbarItems_.insert(std::pair<QToolBar*,QGraphicsProxyWidget*>(_tool,item));
219 } else {
220 // Widget has already been added once, so just show it
221 ret->second->show();
222 }
223 } else {
224
225 // Try to find toolbar in local map
226 // If its in there, we need to remove it from the graphics scene before adding it
227 // to the side toolbar.
228 PickToolBarMap::iterator ret = curPickingToolbarItems_.find(_tool);
229 if(ret != curPickingToolbarItems_.end()) {
230
231 glScene_->removeItem(ret->second);
232 ret->first->setParent(0);
233
234 // remove from list of widgets in glScene
235 curPickingToolbarItems_.erase(ret);
236 }
237
238 pickToolBarExternal_ = _tool;
239
240 // Check whether this toolbar has been displayed before
241 if(registeredToolbars_.count(_tool) == 0) {
242
243 /*
244 * This code makes sure that the orientation and size
245 * of a toolbar is only set once (the first time it is added).
246 * In some cases, the user wants to move the toolbar somewhere
247 * else and thus this check makes sure that it does not
248 * loose its position and orientation after a pickmode change.
249 */
250
251 // Adjust its size and orientation
252 pickToolBarExternal_->setOrientation(Qt::Vertical);
253 pickToolBarExternal_->adjustSize();
254
255 addToolBar(Qt::LeftToolBarArea,_tool);
256
257 // Add to registered toolbars
258 registeredToolbars_.insert(_tool);
259 }
260
261 _tool->show();
262 }
263 } else {
265 }
266}
267
268//-----------------------------------------------------------------------------
269
271
272 // Hide all picking toolbars
273 for(PickToolBarMap::iterator it = curPickingToolbarItems_.begin();
274 it != curPickingToolbarItems_.end(); ++it) {
275 it->second->hide();
276 }
277
278 // if a toolbar is in the global scene, we remove it here.
279 if ( pickToolBarExternal_ != 0 ) {
280 pickToolBarExternal_->hide();
282 }
283
284
285
286
287}
288
289//-----------------------------------------------------------------------------
290
292{
293 if (pickMenu_ != 0) {
294 pickMenu_->clear();
295 } else {
296 pickMenu_ = new QMenu( 0 );
297 connect( pickMenu_, SIGNAL( aboutToHide() ),
298 this, SLOT( hidePopupMenus() ) );
299 }
300
301 QActionGroup * ag = new QActionGroup( pickMenu_ );
302 ag->setExclusive( true );
303
304 for (unsigned int i=0; i<pick_modes_.size(); ++i) {
305 if ( !pick_modes_[i].visible() )
306 continue;
307
308 if (pick_modes_[i].name() == "Separator")
309 {
310 if ((i > 0) && (i<pick_modes_.size()-1)) // not first, not last
311 pickMenu_->addSeparator();
312 }
313 else
314 {
315 QAction* ac = new QAction( pick_modes_[i].name().c_str(), ag );
316 ac->setData( QVariant( i ) );
317 ac->setCheckable( true );
318
319 if ((int)i == pick_mode_idx_)
320 ac->setChecked( true );
321
322 pickMenu_->addAction( ac );
323 }
324 }
325
326 connect( ag, SIGNAL( triggered( QAction * ) ),
327 this, SLOT( actionPickMenu( QAction * ) ));
328}
329
330//-----------------------------------------------------------------------------
331
332
333void CoreWidget::actionPickMenu( QAction * _action )
334{
335 int _id = _action->data().toInt();
336 if (_id < (int) pick_modes_.size() )
337 {
338 pickMode( _id );
339 }
340
342
344}
345
346//-----------------------------------------------------------------------------
347
348
350{
351
352 if ( pickMenu_ )
353 {
354 pickMenu_->blockSignals(true);
355 pickMenu_->hide();
356 pickMenu_->blockSignals(false);
357 }
358}
359
360//-----------------------------------------------------------------------------
361
362
363void CoreWidget::pickMode( int _id )
364{
365 if (_id < (int) pick_modes_.size() )
366 {
367 pick_mode_idx_ = _id;
369
370 if (pick_modes_[pick_mode_idx_].toolbar() )
372 else
374
375 // adjust mouse tracking
376 if ( pickingMode() )
377 for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i )
378 examiner_widgets_[i]->trackMouse(pick_modes_[pick_mode_idx_].tracking() );
379
380 // adjust Cursor
381 if ( pickingMode() )
383
384 // emit signal
386 }
387}
388
389
390//-----------------------------------------------------------------------------
391
392
393void CoreWidget::addPickMode(const std::string& _name,
394 bool _tracking,
395 int _pos,
396 bool _visible,
397 QCursor _cursor)
398{
399
400 if ((unsigned int)_pos < pick_modes_.size())
401 {
402 std::vector<PickMode>::iterator it = pick_modes_.begin();
403 it += _pos+1;
404 pick_modes_.insert(it, PickMode(_name, _tracking, _visible, _cursor));
405 }
406 else
407 pick_modes_.push_back(PickMode(_name, _tracking, _visible, _cursor));
408
410}
411
412//-----------------------------------------------------------------------------
413
414void CoreWidget::setPickModeCursor(const std::string& _name, QCursor _cursor)
415{
416 for (uint i=0; i < pick_modes_.size(); i++)
417 if ( pick_modes_[i].name() == _name ){
418 pick_modes_[i].cursor( _cursor );
419
420 //switch cursor if pickMode is active
421 if (pick_mode_name_ == _name && pickingMode() )
422 cursorPainter_->setCursor(_cursor);
423 break;
424 }
425}
426
427//-----------------------------------------------------------------------------
428
429void CoreWidget::setPickModeMouseTracking(const std::string& _name, bool _mouseTracking)
430{
431 for (uint i=0; i < pick_modes_.size(); i++)
432 if ( pick_modes_[i].name() == _name ){
433
434 pick_modes_[i].tracking(_mouseTracking );
435
436 //switch cursor if pickMode is active
437 if (pick_mode_name_ == _name && pickingMode() )
438 for ( unsigned int j = 0 ; j < OpenFlipper::Options::examinerWidgets() ; ++j )
439 examiner_widgets_[j]->trackMouse(_mouseTracking);
440 break;
441 }
442}
443
444//-----------------------------------------------------------------------------
445
446void CoreWidget::setPickModeToolbar( const std::string& _mode , QToolBar * _toolbar )
447{
448
449 // Get the pickmode that belongs to the given name
450 for (uint i=0; i < pick_modes_.size(); i++)
451 if ( pick_modes_[i].name() == _mode ){
452
453 // Set the new toolbar for that mode
454 pick_modes_[i].toolbar( _toolbar );
455
456 // Activate the toolbar if this mode is currently active
457 if (pick_mode_name_ == _mode && pickingMode() )
458 setActivePickToolBar(_toolbar);
459
460 break;
461 }
462}
463
464//-----------------------------------------------------------------------------
465
466void CoreWidget::removePickModeToolbar( const std::string& _mode )
467{
468 for (uint i=0; i < pick_modes_.size(); i++)
469 if ( pick_modes_[i].name() == _mode ){
470
471 pick_modes_[i].toolbar(0);
472
473 if (pick_mode_name_ == _mode && pickingMode() )
475 break;
476 }
477}
478
479//-----------------------------------------------------------------------------
480
482{
483 pick_modes_.clear();
484 pick_mode_idx_ = -1;
485 pick_mode_name_ = "";
487}
488
489
490//-----------------------------------------------------------------------------
491
492void CoreWidget::expandToolBoxWidget(QWidget *widget, bool expand) {
493 toolBox_->expand(widget, expand);
494}
495
496
497const std::string& CoreWidget::pickMode() const
498{
499 return pick_mode_name_;
500}
501
502
503
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
ActionMode
Enum listing action modes of the viewers.
void setActionMode(const Viewer::ActionMode _am)
Definition: picking.cc:62
std::vector< PickMode > pick_modes_
Definition: CoreWidget.hh:1583
void removePickModeToolbar(const std::string &_mode)
Removes the additional toolbar of the given PickMode.
Definition: picking.cc:466
QMenu * pickMenu_
Definition: CoreWidget.hh:1579
void setPickModeToolbar(const std::string &_mode, QToolBar *_toolbar)
Set the additional toolbar of the given PickMode.
Definition: picking.cc:446
std::vector< glViewer * > examiner_widgets_
Examiner Widget.
Definition: CoreWidget.hh:684
void expandToolBoxWidget(QWidget *widget, bool expand)
Definition: picking.cc:492
void setPickingMode()
Definition: CoreWidget.hh:1470
Viewer::ActionMode lastActionMode_
Definition: CoreWidget.hh:1481
QtGLGraphicsScene * glScene_
graphics scene used to paint gl context and widgets
Definition: CoreWidget.hh:717
void clearPickModes()
Definition: picking.cc:481
QToolButton * moveButton_
Called by Plugins to add a Toolbar.
Definition: CoreWidget.hh:833
SideArea * toolBox_
Toolbox.
Definition: CoreWidget.hh:741
CursorPainter * cursorPainter_
Cursor handling.
Definition: CoreWidget.hh:757
void getPickMode(std::string &_name)
Definition: picking.cc:173
void addPickMode(const std::string &_name, bool _mouse_tracking=false, int _pos=-1, bool _visible=true, QCursor _cursor=Qt::ArrowCursor)
add pick mode
Definition: picking.cc:393
QToolButton * pickButton_
Called by Plugins to add a Toolbar.
Definition: CoreWidget.hh:834
void setPickModeCursor(const std::string &_name, QCursor _cursor)
set a new cursor for the pick mode
Definition: picking.cc:414
void signalPickModeChanged(const std::string &)
void setActivePickToolBar(QToolBar *_tool)
Set toolbar to be active pick toolbar.
Definition: picking.cc:179
std::string pick_mode_name_
Definition: CoreWidget.hh:1587
void setPickModeMouseTracking(const std::string &_name, bool _mouseTracking)
set mouseTracking for the pick mode
Definition: picking.cc:429
void actionPickMenu(QAction *_action)
Definition: picking.cc:333
Viewer::ActionMode actionMode_
Definition: CoreWidget.hh:1481
void getActionMode(Viewer::ActionMode &_am)
Definition: picking.cc:152
QToolButton * questionButton_
Called by Plugins to add a Toolbar.
Definition: CoreWidget.hh:835
bool pickingMode()
Definition: CoreWidget.hh:1462
void updatePickMenu()
update pick mode menu
Definition: picking.cc:291
QToolBar * pickToolBarExternal_
Extra toolbar not in scene for picking.
Definition: CoreWidget.hh:751
void setPickMode(const std::string &_name)
Definition: picking.cc:158
std::set< QToolBar * > registeredToolbars_
Store all toolbars that once have been registered.
Definition: CoreWidget.hh:754
const std::string & pickMode() const
Definition: picking.cc:497
void hidePickToolBar()
Hide picking toolbar.
Definition: picking.cc:270
void hidePopupMenus()
Definition: picking.cc:349
int pick_mode_idx_
Definition: CoreWidget.hh:1591
PickToolBarMap curPickingToolbarItems_
Handle to picking toolbar.
Definition: CoreWidget.hh:748
void setCursor(const QCursor &_cursor)
Sets the current used cursor.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Struct containing information about pickModes.
Definition: CoreWidget.hh:184
void analyzeSceneGraph(ACG::SceneGraph::BaseNode *_root, unsigned int &_maxPasses, ACG::Vec3d &_bbmin, ACG::Vec3d &_bbmax)
Analyze the SceneGraph <ACG/Scenegraph/SceneGraphAnalysis.hh>
ACG::SceneGraph::BaseNode * getSceneGraphRootNode()
get scenegraph root node