diff --git a/BasePlugin/PluginFunctions.cc b/BasePlugin/PluginFunctions.cc index 98adf2bf83d6d35a3e1c2207d04ea97f9de801bc..4a091726dcd26e521e73e45bd5164d7ab9fa179c 100644 --- a/BasePlugin/PluginFunctions.cc +++ b/BasePlugin/PluginFunctions.cc @@ -371,39 +371,28 @@ void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction } -const std::string & pickMode () { +const std::string pickMode () { // No seperate draw modes available all should have the same so take first - return examiner_widgets_[0]->pickMode(); + return viewerProperties().pickMode(); } void pickMode ( std::string _mode) { - for ( uint i = 0 ; i < examiner_widgets_.size() ; ++i ) - examiner_widgets_[i]->pickMode(_mode); + viewerProperties().pickMode(_mode); } -void pickMode ( const unsigned int _examiner, std::string _mode) { - if ( _examiner >= examiner_widgets_.size() ) { - std::cerr << "Wrong examiner id" << std::endl; - return; - } - - examiner_widgets_[_examiner]->pickMode(_mode); +Viewer::ActionMode actionMode() { + return viewerProperties().actionMode(); } void actionMode ( Viewer::ActionMode _mode) { - for ( uint i = 0 ; i < examiner_widgets_.size() ; ++i ) - viewerProperties(i).actionMode(_mode); + viewerProperties().actionMode(_mode); } void getCurrentViewImage(QImage& _image) { examiner_widget_->copyToImage( _image ); } -Viewer::ActionMode actionMode() { - return viewerProperties(activeExaminer_).actionMode(); -} - Viewer::ViewerProperties& viewerProperties(int _id) { if ( _id >= (int)viewerProperties_.size() ) { std::cerr << " Error, requested properties for non-existing Viewer!" << std::endl; diff --git a/BasePlugin/PluginFunctions.hh b/BasePlugin/PluginFunctions.hh index ef55f61a49857abf5811e611354bdc89af1109fa..081d19ed6cf1d7a7949ce7c308521ffc7b685886 100644 --- a/BasePlugin/PluginFunctions.hh +++ b/BasePlugin/PluginFunctions.hh @@ -54,6 +54,7 @@ #include #include + /** The Namespace PluginFunctions contains functions for all plugins. These functions should be used to get the * objects to work on or to set modes in the examiner widget. */ namespace PluginFunctions { @@ -250,16 +251,12 @@ void traverse( const unsigned int _examiner, ACG::SceneGraph::MouseEventAction /// Get the current Picking mode DLLEXPORT -const std::string & pickMode (); +const std::string pickMode (); /// Set the current Picking mode for all examiner widgets DLLEXPORT void pickMode ( std::string _mode); -/// Set pick mode for a specific examiner -DLLEXPORT -void pickMode ( const unsigned int _examiner, std::string _mode); - /// Returns a QImage of the current View DLLEXPORT void getCurrentViewImage(QImage& _image); @@ -309,6 +306,7 @@ QPoint mapToLocal( const QPoint _point ); /** @} */ + //======================================= // Iterators for object Access /** @name Iterators diff --git a/Core/Core.cc b/Core/Core.cc index f5dbbbfc0df59a2529609f5876f47d050c5c05d2..a998cb115f29cb1ca57ac59931e959341d1e9830 100644 --- a/Core/Core.cc +++ b/Core/Core.cc @@ -630,8 +630,7 @@ Core::slotWheelEvent( QWheelEvent * _event, const std::string & _mode) void Core::slotAddPickMode( const std::string _mode ) { if ( OpenFlipper::Options::gui() ) - for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) - coreWidget_->examiner_widgets_[i]->addPickMode(_mode); + coreWidget_->addPickMode(_mode); } @@ -641,8 +640,7 @@ void Core::slotAddHiddenPickMode( const std::string _mode ) { if ( OpenFlipper::Options::gui() ) - for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets(); ++i ) - coreWidget_->examiner_widgets_[i]->addPickMode(_mode,false,1000,false); + coreWidget_->addPickMode(_mode,false,1000,false); } diff --git a/Core/PluginLoader.cc b/Core/PluginLoader.cc index ddd644aeec18d0a4f065026c8a5a83cb5e029a5f..57838ca1693dcd059b035a842244fc554bf08b8b 100644 --- a/Core/PluginLoader.cc +++ b/Core/PluginLoader.cc @@ -727,7 +727,7 @@ void Core::loadPlugin(QString filename, bool silent){ supported = supported + "Picking "; if ( checkSlot( plugin , "slotPickModeChanged(const std::string&)" ) ) - connect(coreWidget_->examiner_widgets_[0],SIGNAL(signalPickModeChanged (const std::string &)), + connect(coreWidget_,SIGNAL(signalPickModeChanged (const std::string &)), plugin,SLOT(slotPickModeChanged( const std::string &))); if ( checkSignal(plugin,"addPickMode(const std::string)") ) @@ -741,13 +741,13 @@ void Core::loadPlugin(QString filename, bool silent){ if ( checkSignal(plugin,"setPickModeCursor(const std::string,QCursor)") ) for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) connect(plugin,SIGNAL(setPickModeCursor( const std::string ,QCursor)), - coreWidget_->examiner_widgets_[i],SLOT(setPickModeCursor( const std::string ,QCursor)),Qt::DirectConnection); + coreWidget_,SLOT(setPickModeCursor( const std::string ,QCursor)),Qt::DirectConnection); if ( checkSignal(plugin,"setPickModeMouseTracking(const std::string,bool)") ) for ( uint i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) connect(plugin,SIGNAL(setPickModeMouseTracking( const std::string ,bool)), - coreWidget_->examiner_widgets_[i],SLOT(setPickModeMouseTracking( const std::string ,bool)),Qt::DirectConnection); + coreWidget_,SLOT(setPickModeMouseTracking( const std::string ,bool)),Qt::DirectConnection); } //Check if the plugin supports INI-Interface diff --git a/common/ViewerProperties.cc b/common/ViewerProperties.cc index bdd0f618665edbd7e972e74e4f8650d95649bb96..93ae8938029544d6b0c46747f03615f520c75f4a 100644 --- a/common/ViewerProperties.cc +++ b/common/ViewerProperties.cc @@ -46,8 +46,6 @@ namespace Viewer { ViewerProperties::ViewerProperties(): - actionMode_(Viewer::PickingMode), - lastActionMode_(Viewer::PickingMode), currentDrawMode_(ACG::SceneGraph::DrawModes::NONE), snapshotName_("snap.png"), snapshotCounter_(0), @@ -73,19 +71,31 @@ namespace Viewer { } - void ViewerProperties::actionMode(Viewer::ActionMode _am) { - if (_am != actionMode_) { - lastActionMode_ = actionMode_; - actionMode_ = _am; - emit actionModeChanged(_am); - } - - } - void ViewerProperties::snapshotBaseFileName(const QString& _fname) { snapshotName_ = _fname; snapshotCounter_ = 0; } + std::string ViewerProperties::pickMode(){ + + std::string mode; + emit getPickMode(mode); + return mode; + } + + void ViewerProperties::pickMode(const std::string _name){ + emit setPickMode(_name); + } + + Viewer::ActionMode ViewerProperties::actionMode(){ + Viewer::ActionMode am; + emit getActionMode(am); + return am; + } + + void ViewerProperties::actionMode(const Viewer::ActionMode _am){ + emit setActionMode(_am); + } + } diff --git a/common/ViewerProperties.hh b/common/ViewerProperties.hh index 4890f6b55817c8f688573161a77be43e4930ab7b..29c8c32e331acf35e8164487d1a66d5fee7e0cb4 100644 --- a/common/ViewerProperties.hh +++ b/common/ViewerProperties.hh @@ -78,37 +78,6 @@ namespace Viewer { public: ViewerProperties(); ~ViewerProperties(); - - //=========================================================================== - /** @name Action Mode States - * @{ */ - //=========================================================================== - - public slots: - - bool examineMode() { return(actionMode_ == Viewer::ExamineMode ); }; - bool pickingMode() { return(actionMode_ == Viewer::PickingMode ); }; - bool lightMode() { return(actionMode_ == Viewer::LightMode ); }; - bool questionMode(){ return(actionMode_ == Viewer::QuestionMode ); }; - - /** Set action mode. - The ActionMode determines the type of reaction on mouse events. - */ - void setExamineMode() { actionMode(Viewer::ExamineMode ); }; - void setPickingMode() { actionMode(Viewer::PickingMode ); }; - void setLightMode() { actionMode(Viewer::LightMode ); }; - void setQuestionMode(){ actionMode(Viewer::QuestionMode ); }; - - public: - void actionMode(Viewer::ActionMode _am); - Viewer::ActionMode actionMode() { return actionMode_; }; - Viewer::ActionMode lastActionMode() { return lastActionMode_; }; - - private : - Viewer::ActionMode actionMode_, lastActionMode_; - - /** @} */ - //=========================================================================== /** @name Draw Mode States @@ -364,8 +333,25 @@ namespace Viewer { */ void updated(); - void actionModeChanged( Viewer::ActionMode ); + void getPickMode(std::string& _mode ); + void setPickMode(const std::string _mode ); + + void getActionMode(Viewer::ActionMode& _am); + void setActionMode(const Viewer::ActionMode _am); + + public: + + /// get active pick mode + std::string pickMode(); + + /// set the pickMode + void pickMode(const std::string _name); + + /// get the action mode + Viewer::ActionMode actionMode(); + /// set active action mode + void actionMode(const Viewer::ActionMode _am); }; diff --git a/widgets/coreWidget/ContextMenu.cc b/widgets/coreWidget/ContextMenu.cc index 0b30e3bb04d52179d979a3e8fc753d50a262c6d6..f05a0d4e4c0d466b21e6a56abe2c42ab21aa285f 100644 --- a/widgets/coreWidget/ContextMenu.cc +++ b/widgets/coreWidget/ContextMenu.cc @@ -284,16 +284,11 @@ void CoreWidget::updatePopupMenuObject(QMenu* _menu , BaseObjectData* _object ) _menu->addSeparator(); // Add picking Menu - if (examiner_widgets_[0]->getPickMenu() != NULL) { - if ( examiner_widgets_[0]->getPickMenu()->actions().size() > 0 ) { - examiner_widgets_[0]->getPickMenu()->setTitle("&Picking"); - contextMenu_->addMenu(examiner_widgets_[0]->getPickMenu() ); - examiner_widgets_[0]->getPickMenu()->setTearOffEnabled(true); - } + if (pickMenu_ != 0 && pickMenu_->actions().size() > 0) { + pickMenu_->setTitle("&Picking"); + contextMenu_->addMenu( pickMenu_ ); + pickMenu_->setTearOffEnabled(true); } - - - } bool CoreWidget::addContextMenus( QMenu* _menu , ContextMenuType _type , int _id ) { diff --git a/widgets/coreWidget/CoreWidget.cc b/widgets/coreWidget/CoreWidget.cc index 3348df9627fcb24bac53b7713116121ddbfec149..357936e72c3b99fb6f96dfb702faf3fd4ebd112a 100644 --- a/widgets/coreWidget/CoreWidget.cc +++ b/widgets/coreWidget/CoreWidget.cc @@ -102,7 +102,12 @@ CoreWidget( QVector& _viewModes, aboutWidget_(0), optionsWidget_(0), plugins_(_plugins), - stereoActive_(false) + stereoActive_(false), + actionMode_(Viewer::PickingMode), + lastActionMode_(Viewer::ExamineMode), + pickMenu_(0), + pick_mode_name_(""), + pick_mode_idx_(-1) { setupStatusBar(); @@ -221,6 +226,16 @@ CoreWidget( QVector& _viewModes, statusBar_); examiner_widgets_.push_back(newWidget); + + connect (&PluginFunctions::viewerProperties(i), SIGNAL( getPickMode(std::string&) ), + this, SLOT( getPickMode(std::string&) ),Qt::DirectConnection ); + connect (&PluginFunctions::viewerProperties(i), SIGNAL( setPickMode(const std::string) ), + this, SLOT( setPickMode(const std::string) ),Qt::DirectConnection ); + connect (&PluginFunctions::viewerProperties(i), SIGNAL( getActionMode(Viewer::ActionMode&) ), + this, SLOT( getActionMode(Viewer::ActionMode&) ),Qt::DirectConnection ); + connect (&PluginFunctions::viewerProperties(i), SIGNAL( setActionMode(const Viewer::ActionMode) ), + this, SLOT( setActionMode(const Viewer::ActionMode)), Qt::DirectConnection ); + } // Initialize all examiners @@ -285,11 +300,11 @@ CoreWidget( QVector& _viewModes, "
  • Rotate using left mouse button.
  • " "
  • Translate using middle mouse button.
  • " "
  • Zoom using left+middle mouse buttons.
" ); - for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) { - connect( moveButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setExamineMode() ) ); - connect( &PluginFunctions::viewerProperties(i) , SIGNAL( actionModeChanged( Viewer::ActionMode ) ), - this , SLOT( slotActionModeChanged(Viewer::ActionMode) ) ); - } + + connect( moveButton_,SIGNAL( clicked() ), this, SLOT( setExamineMode() ) ); + + connect( this, SIGNAL( actionModeChanged( Viewer::ActionMode ) ), + this, SLOT( slotActionModeChanged(Viewer::ActionMode) ) ); viewerToolbar_->addWidget( moveButton_ )->setText("Move"); moveButton_->setDown(true); @@ -303,8 +318,8 @@ CoreWidget( QVector& _viewModes, lightButton_->setWhatsThis( "Switch to light mode.
" "Rotate lights using left mouse button."); - for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) - connect( lightButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setLightMode() ) ); + + connect( lightButton_,SIGNAL( clicked() ), this, SLOT( setLightMode() ) ); viewerToolbar_->addWidget( lightButton_)->setText("Light"); @@ -318,8 +333,7 @@ CoreWidget( QVector& _viewModes, "Use picking functions like flipping edges.
" "To change the mode use the right click
" "context menu in the viewer."); - for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) - connect( pickButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setPickingMode() ) ); + connect( pickButton_,SIGNAL( clicked() ), this, SLOT( setPickingMode() ) ); viewerToolbar_->addWidget( pickButton_)->setText("Pick"); @@ -334,8 +348,7 @@ CoreWidget( QVector& _viewModes, "about objects. Click on an object and see " "the log output for information about the " "object."); - for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) - connect( questionButton_,SIGNAL( clicked() ), &PluginFunctions::viewerProperties(i), SLOT( setQuestionMode() ) ); + connect( questionButton_,SIGNAL( clicked() ), this, SLOT( setQuestionMode() ) ); viewerToolbar_->addWidget( questionButton_)->setText("Question"); viewerToolbar_->addSeparator(); @@ -420,6 +433,7 @@ CoreWidget( QVector& _viewModes, registerCoreKeys(); + setExamineMode(); setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() ); diff --git a/widgets/coreWidget/CoreWidget.hh b/widgets/coreWidget/CoreWidget.hh index 74efd8f69175bec5cd79e3223eb7c6bbe00d313d..eaa66a3f0853f0d8586f4dd22dc3d8d6a1739c57 100644 --- a/widgets/coreWidget/CoreWidget.hh +++ b/widgets/coreWidget/CoreWidget.hh @@ -83,7 +83,7 @@ #include #include - +#include struct ViewMode{ @@ -783,9 +783,6 @@ public: /// Enable or disable Stereo void slotToggleStereoMode(); - /// Change Icons if action mode is changed in an examiner - void slotActionModeChanged( Viewer::ActionMode _mode ); - /// Set Background Color for all viewers at once. void slotSetGlobalBackgroundColor(); @@ -855,6 +852,153 @@ public: bool stereoActive_; /** @} */ + + //=========================================================================== + /** @name Action Mode States + * @{ */ + //=========================================================================== + + public slots: + + bool examineMode() { return(actionMode_ == Viewer::ExamineMode ); }; + bool pickingMode() { return(actionMode_ == Viewer::PickingMode ); }; + bool lightMode() { return(actionMode_ == Viewer::LightMode ); }; + bool questionMode(){ return(actionMode_ == Viewer::QuestionMode ); }; + + /** Set action mode. + The ActionMode determines the type of reaction on mouse events. + */ + void setExamineMode() { setActionMode(Viewer::ExamineMode ); }; + void setPickingMode() { setActionMode(Viewer::PickingMode ); }; + void setLightMode() { setActionMode(Viewer::LightMode ); }; + void setQuestionMode(){ setActionMode(Viewer::QuestionMode ); }; + + void setActionMode(const Viewer::ActionMode _am); + void getActionMode(Viewer::ActionMode& _am); + + public: + Viewer::ActionMode actionMode() { return actionMode_; }; + Viewer::ActionMode lastActionMode() { return lastActionMode_; }; + + private : + Viewer::ActionMode actionMode_, lastActionMode_; + + /** @} */ + + //=========================================================================== + /** @name PickModes + * @{ */ + //=========================================================================== + + public: + + /** \brief add pick mode + * + * @param _name Name of the Pick Mode or "Separator" to insert a separator + * @param _mouse_tracking true: every mouse movement will emit mouse events not only when mousebutton is pressed + * @param _pos position to insert the mode in the popup menu. + */ + void addPickMode(const std::string& _name, + bool _mouse_tracking = false, + int _pos = -1, + bool _visible = true, + QCursor _cursor = Qt::ArrowCursor ); + + /** clear all pick modes + */ + void clearPickModes(); + + /** return the currently active pick mode + */ + const std::string& pickMode() const; + + /** Switch to given picking mode + * @param _id Id of the picking Mode + */ + void pickMode( int _id ); + + public slots: + + /** Switch to given picking mode + * @param _name Name of the picking mode + */ + void setPickMode(const std::string _name); + + + void getPickMode(std::string& _name); + + public slots: + + /** \brief set a new cursor for the pick mode + * + * @param _name Name of the Pick Mode + * @param _cursor the new cursor + */ + void setPickModeCursor(const std::string& _name, QCursor _cursor); + + /** \brief set mouseTracking for the pick mode + * + * @param _name Name of the Pick Mode + * @param _mouseTracking true: every mouse movement will emit mouse events not only when mousebutton is pressed + */ + void setPickModeMouseTracking(const std::string& _name, bool _mouseTracking); + + void actionPickMenu( QAction * _action ); + + signals: + /** This signal is emitted when the pickMode is changed and contains the new PickMode + */ + void signalPickModeChanged(const std::string&); + + private: + + QMenu* pickMenu_; + + /** Struct containing information about pickModes + */ + struct PickMode + { + /// Constructor + PickMode(const std::string& _n, bool _t, bool _v, QCursor _c) : + name(_n), tracking(_t), visible(_v), cursor(_c) {} + + /// Name of the pickMode + std::string name; + + /** MouseTracking enabled for this mode? + */ + bool tracking; + + /** Defines if the Mode will be visible in the popup Menu + */ + bool visible; + + /** Cursor used in this pickMode + */ + QCursor cursor; + }; + + /** Vector of all Picking modes + */ + std::vector pick_modes_; + + /** Name of current pickMode + */ + std::string pick_mode_name_; + + /** Index of current pickMode + */ + int pick_mode_idx_; + + + /// update pick mode menu + void updatePickMenu(); + + private slots: + + void hidePopupMenus(); + /** @} */ + }; diff --git a/widgets/coreWidget/keyHandling.cc b/widgets/coreWidget/keyHandling.cc index 7d377bc83a4dfc55452f00c11e7aabea11ecce54..3823e2df23a1d3d96e949a6e619d323c92f1fa18 100644 --- a/widgets/coreWidget/keyHandling.cc +++ b/widgets/coreWidget/keyHandling.cc @@ -545,8 +545,7 @@ void CoreWidget::coreKeyPressEvent (QKeyEvent* _e){ switch (_e->key()) { case Qt::Key_Escape: - for ( uint i = 0 ; i < examiner_widgets_.size(); ++i) - PluginFunctions::viewerProperties(i).actionMode( PluginFunctions::viewerProperties(i).lastActionMode() ); + setActionMode( lastActionMode() ); break; case Qt::Key_Print: diff --git a/widgets/coreWidget/picking.cc b/widgets/coreWidget/picking.cc new file mode 100644 index 0000000000000000000000000000000000000000..aa3589211a4ad6348a3df8a668bfdefd09acc9d0 --- /dev/null +++ b/widgets/coreWidget/picking.cc @@ -0,0 +1,347 @@ +//============================================================================= +// +// OpenFlipper +// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen +// www.openflipper.org +// +//----------------------------------------------------------------------------- +// +// License +// +// 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. +// +// 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 Lesser General Public License +// along with OpenFlipper. If not, see . +// +//----------------------------------------------------------------------------- +// +// $Revision: 5359 $ +// $Author: wilden $ +// $Date: 2009-03-19 16:43:39 +0100 (Thu, 19 Mar 2009) $ +// +//============================================================================= + + + + +//============================================================================= +// +// CLASS CoreWidget - IMPLEMENTATION +// +//============================================================================= + + +//== INCLUDES ================================================================= + +#include "CoreWidget.hh" + +#include +#include + +//----------------------------------------------------------------------------- + +void CoreWidget::setActionMode(const Viewer::ActionMode _am){ + if (_am != actionMode_) { + lastActionMode_ = actionMode_; + actionMode_ = _am; + + + // update Buttons + + moveButton_->setDown(false); + lightButton_->setDown(false); + pickButton_->setDown(false); + questionButton_->setDown(false); + + switch (_am) + { + case Viewer::ExamineMode: + { + moveButton_->setDown(true); + break; + } + + + case Viewer::LightMode: + { + lightButton_->setDown(true); + break; + } + + + case Viewer::PickingMode: + { + pickButton_->setDown(true); + break; + } + + + case Viewer::QuestionMode: + { + questionButton_->setDown(true); + break; + } + } + + //update Viewers + + for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) { + + examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() ); + + examiner_widgets_[i]->trackMouse(false); + + + switch ( _am ) + { + case Viewer::ExamineMode: + { + examiner_widgets_[i]->setCursor(Qt::PointingHandCursor); + break; + } + + + case Viewer::LightMode: + { + examiner_widgets_[i]->setCursor(Qt::PointingHandCursor); + break; + } + + + case Viewer::PickingMode: + { + examiner_widgets_[i]->setCursor(Qt::ArrowCursor); + if (pick_mode_idx_ != -1) { + examiner_widgets_[i]->trackMouse(pick_modes_[pick_mode_idx_].tracking); + examiner_widgets_[i]->setCursor(pick_modes_[pick_mode_idx_].cursor); + } + + break; + } + + + case Viewer::QuestionMode: + { + examiner_widgets_[i]->setCursor(Qt::WhatsThisCursor); + break; + } + } + } + + //emit pickmodeChanged with either the name of the current pickmode or an empty string + if( pickingMode() ) + emit(signalPickModeChanged(pick_mode_name_)); + else + emit(signalPickModeChanged("")); + + } +} + +//----------------------------------------------------------------------------- + +void CoreWidget::getActionMode(Viewer::ActionMode& _am){ + _am = actionMode_; +} + +//----------------------------------------------------------------------------- + +void CoreWidget::setPickMode(const std::string _mode){ + + for (unsigned int i=0; isetExclusive( true ); + + for (unsigned int i=0; i 0) && (iaddSeparator(); + } + else + { + QAction* ac = new QAction( pick_modes_[i].name.c_str(), ag ); + ac->setData( QVariant( i ) ); + ac->setCheckable( true ); + + if ((int)i == pick_mode_idx_) + ac->setChecked( true ); + + pickMenu_->addAction( ac ); + } + } + + connect( ag, SIGNAL( triggered( QAction * ) ), + this, SLOT( actionPickMenu( QAction * ) )); +} + +//----------------------------------------------------------------------------- + + +void CoreWidget::actionPickMenu( QAction * _action ) +{ + int _id = _action->data().toInt(); + if (_id < (int) pick_modes_.size() ) + { + pickMode( _id ); + } + + setPickingMode(); + + hidePopupMenus(); +} + +//----------------------------------------------------------------------------- + + +void CoreWidget::hidePopupMenus() +{ + + if ( pickMenu_ ) + { + pickMenu_->blockSignals(true); + pickMenu_->hide(); + pickMenu_->blockSignals(false); + } +} + +//----------------------------------------------------------------------------- + + +void CoreWidget::pickMode( int _id ) +{ + if (_id < (int) pick_modes_.size() ) + { + pick_mode_idx_ = _id; + pick_mode_name_ = pick_modes_[pick_mode_idx_].name; + + // adjust mouse tracking + if ( pickingMode() ) + for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) + examiner_widgets_[i]->trackMouse(pick_modes_[pick_mode_idx_].tracking); + + // adjust Cursor + if ( pickingMode() ) + for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) + examiner_widgets_[i]->setCursor( pick_modes_[pick_mode_idx_].cursor); + + + // emit signal + emit(signalPickModeChanged(pick_mode_name_)); + } +} + + +//----------------------------------------------------------------------------- + + +void CoreWidget::addPickMode(const std::string& _name, + bool _tracking, + int _pos, + bool _visible, + QCursor _cursor) +{ + + if ((unsigned int)_pos < pick_modes_.size()) + { + std::vector::iterator it = pick_modes_.begin(); + it += _pos+1; + pick_modes_.insert(it, PickMode(_name, _tracking, _visible, _cursor)); + } + else + pick_modes_.push_back(PickMode(_name, _tracking, _visible, _cursor)); + + updatePickMenu(); +} + +//----------------------------------------------------------------------------- + +void CoreWidget::setPickModeCursor(const std::string& _name, QCursor _cursor) +{ + for (uint i=0; i < pick_modes_.size(); i++) + if ( pick_modes_[i].name == _name ){ + pick_modes_[i].cursor = _cursor; + + //switch cursor if pickMode is active + if (pick_mode_name_ == _name && pickingMode() ) + for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) + examiner_widgets_[i]->setCursor(_cursor); + break; + } +} + +//----------------------------------------------------------------------------- + +void CoreWidget::setPickModeMouseTracking(const std::string& _name, bool _mouseTracking) +{ + for (uint i=0; i < pick_modes_.size(); i++) + if ( pick_modes_[i].name == _name ){ + pick_modes_[i].tracking = _mouseTracking; + + //switch cursor if pickMode is active + if (pick_mode_name_ == _name && pickingMode() ) + for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) + examiner_widgets_[i]->trackMouse(_mouseTracking); + break; + } +} + +//----------------------------------------------------------------------------- + + +void CoreWidget::clearPickModes() +{ + pick_modes_.clear(); + pick_mode_idx_ = -1; + pick_mode_name_ = ""; + updatePickMenu(); +} + + +//----------------------------------------------------------------------------- + + +const std::string& CoreWidget::pickMode() const +{ + return pick_mode_name_; +} + + + diff --git a/widgets/coreWidget/viewerControl.cc b/widgets/coreWidget/viewerControl.cc index 94502b339cb8aac97f18d949b3cea0520c675372..523354e9abd836cfb333aefedb7f41fbb3eb0a03 100644 --- a/widgets/coreWidget/viewerControl.cc +++ b/widgets/coreWidget/viewerControl.cc @@ -68,43 +68,6 @@ void CoreWidget::slotToggleStereoMode() examiner_widgets_[i]->setStereoMode(stereoActive_); } -void CoreWidget::slotActionModeChanged( Viewer::ActionMode _mode ) { - moveButton_->setDown(false); - lightButton_->setDown(false); - pickButton_->setDown(false); - questionButton_->setDown(false); - - switch (_mode) - { - case Viewer::ExamineMode: - { - moveButton_->setDown(true); - break; - } - - - case Viewer::LightMode: - { - lightButton_->setDown(true); - break; - } - - - case Viewer::PickingMode: - { - pickButton_->setDown(true); - break; - } - - - case Viewer::QuestionMode: - { - questionButton_->setDown(true); - break; - } - } -} - void CoreWidget::slotSetGlobalBackgroundColor() { ACG::Vec4f bc = PluginFunctions::viewerProperties().backgroundColor() * 255.0; diff --git a/widgets/glWidget/QtBaseViewer.cc b/widgets/glWidget/QtBaseViewer.cc index 64280e6ed909e93ede0487fad3385be3b6aa10bf..b2611861b8ed9c6ddcf7cdcfac347eadd37d6a91 100644 --- a/widgets/glWidget/QtBaseViewer.cc +++ b/widgets/glWidget/QtBaseViewer.cc @@ -100,6 +100,7 @@ # undef min #endif +#include //== NAMESPACES =============================================================== @@ -126,8 +127,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene, blending_(true), glScene_(_scene), glWidget_(_glWidget), - pick_mode_name_(""), - pick_mode_idx_(-1), properties_(_properties), glstate_(0) { @@ -162,9 +161,6 @@ glViewer::glViewer( QtGLGraphicsScene* _scene, // stereo stereo_ = false; - - pickMenu_ = 0; - // Note: we start locked (initialization of updateLocked_) // will be unlocked in initializeGL() @@ -185,9 +181,7 @@ glViewer::glViewer( QtGLGraphicsScene* _scene, connect( &properties_,SIGNAL(updated()), this, SLOT( slotPropertiesUpdated() ) ); - connect( &properties_,SIGNAL(actionModeChanged(Viewer::ActionMode)), this, SLOT( updateActionMode(Viewer::ActionMode) ) ); - properties_.setExamineMode(); //check for updated properties once slotPropertiesUpdated(); @@ -388,58 +382,6 @@ void glViewer::viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up ) //----------------------------------------------------------------------------- -void glViewer::updateActionMode(Viewer::ActionMode) -{ - - trackMouse(false); - - - switch ( properties_.actionMode() ) - { - case Viewer::ExamineMode: - { - setCursor(Qt::PointingHandCursor); - break; - } - - - case Viewer::LightMode: - { - setCursor(Qt::PointingHandCursor); - break; - } - - - case Viewer::PickingMode: - { - setCursor(Qt::ArrowCursor); - if (pick_mode_idx_ != -1) { - trackMouse(pick_modes_[pick_mode_idx_].tracking); - setCursor(pick_modes_[pick_mode_idx_].cursor); - } - - break; - } - - - case Viewer::QuestionMode: - { - setCursor(Qt::WhatsThisCursor); - break; - } - } - - //emit pickmodeChanged with either the name of the current pickmode or an empty string - if( properties_.pickingMode() ) - emit(signalPickModeChanged(pick_mode_name_)); - else - emit(signalPickModeChanged("")); -} - - -//----------------------------------------------------------------------------- - - void glViewer::normalsMode(NormalsMode _mode) { makeCurrent(); @@ -1162,7 +1104,6 @@ void glViewer::createWidgets(QStatusBar* _sb) { setStatusBar(_sb); - pickMenu_=0; // Construct GL context & widget @@ -1214,21 +1155,6 @@ glViewer::createWidgets(QStatusBar* _sb) //----------------------------------------------------------------------------- -void glViewer::hidePopupMenus() -{ - - if ( pickMenu_ ) - { - pickMenu_->blockSignals(true); - pickMenu_->hide(); - pickMenu_->blockSignals(false); - } -} - - -//----------------------------------------------------------------------------- - - void glViewer::translate(const ACG::Vec3d& _trans) { makeCurrent(); @@ -1349,7 +1275,7 @@ void glViewer::glMousePressEvent(QMouseEvent* _event) // right button pressed => popup menu (ignore here) if (_event->button() != Qt::RightButton ) { - switch (properties_.actionMode()) + switch (PluginFunctions::actionMode()) { case Viewer::ExamineMode: if ((_event->modifiers() & Qt::ControlModifier)) // drag&drop @@ -1359,11 +1285,11 @@ void glViewer::glMousePressEvent(QMouseEvent* _event) break; case Viewer::LightMode: - lightMouseEvent(_event); - break; + lightMouseEvent(_event); + break; case Viewer::PickingMode: // give event to application - emit(signalMouseEvent(_event, pick_mode_name_)); + emit(signalMouseEvent(_event, PluginFunctions::pickMode() )); emit(signalMouseEvent(_event)); break; @@ -1380,7 +1306,7 @@ void glViewer::glMousePressEvent(QMouseEvent* _event) void glViewer::glMouseDoubleClickEvent(QMouseEvent* _event) { - switch (properties_.actionMode()) + switch (PluginFunctions::actionMode()) { case Viewer::ExamineMode: viewMouseEvent(_event); @@ -1391,7 +1317,7 @@ void glViewer::glMouseDoubleClickEvent(QMouseEvent* _event) break; case Viewer::PickingMode: // give event to application - emit(signalMouseEvent(_event, pick_mode_name_)); + emit(signalMouseEvent(_event, PluginFunctions::pickMode() )); emit(signalMouseEvent(_event)); break; @@ -1407,7 +1333,7 @@ void glViewer::glMouseDoubleClickEvent(QMouseEvent* _event) void glViewer::glMouseMoveEvent(QMouseEvent* _event) { - switch ( properties_.actionMode() ) + switch ( PluginFunctions::actionMode() ) { case Viewer::ExamineMode: viewMouseEvent(_event); @@ -1423,7 +1349,7 @@ void glViewer::glMouseMoveEvent(QMouseEvent* _event) if ((_event->buttons() & (Qt::LeftButton | Qt::MidButton | Qt::RightButton)) || trackMouse_) { - emit(signalMouseEvent(_event, pick_mode_name_)); + emit(signalMouseEvent(_event, PluginFunctions::pickMode() )); emit(signalMouseEvent(_event)); } break; @@ -1446,10 +1372,9 @@ void glViewer::glMouseReleaseEvent(QMouseEvent* _event) // if (_event->button() == Qt::RightButton ) // hidePopupMenus(); - if (_event->button() != Qt::RightButton || - properties_.pickingMode() ) + if (_event->button() != Qt::RightButton || (PluginFunctions::actionMode() == Viewer::PickingMode) ) { - switch ( properties_.actionMode() ) + switch ( PluginFunctions::actionMode() ) { case Viewer::ExamineMode: viewMouseEvent(_event); @@ -1460,7 +1385,7 @@ void glViewer::glMouseReleaseEvent(QMouseEvent* _event) break; case Viewer::PickingMode: // give event to application - emit(signalMouseEvent(_event, pick_mode_name_)); + emit(signalMouseEvent(_event, PluginFunctions::pickMode() )); emit(signalMouseEvent(_event)); break; @@ -1482,14 +1407,14 @@ void glViewer::glMouseReleaseEvent(QMouseEvent* _event) void glViewer::glMouseWheelEvent(QWheelEvent* _event) { - switch ( properties_.actionMode() ) + switch ( PluginFunctions::actionMode() ) { case Viewer::ExamineMode: viewWheelEvent(_event); break; case Viewer::PickingMode: // give event to application - emit(signalWheelEvent(_event, pick_mode_name_)); + emit(signalWheelEvent(_event, PluginFunctions::pickMode() )); break; default: // avoid warning @@ -1526,63 +1451,6 @@ void glViewer::dropEvent(QGraphicsSceneDragDropEvent* _e) _e->accept(); } -//----------------------------------------------------------------------------- - -void glViewer::updatePickMenu() -{ - delete pickMenu_; - - pickMenu_ = new QMenu( 0 ); - connect( pickMenu_, SIGNAL( aboutToHide() ), - this, SLOT( hidePopupMenus() ) ); - - QActionGroup * ag = new QActionGroup( pickMenu_ ); - ag->setExclusive( true ); - - for (unsigned int i=0; i 0) && (iaddSeparator(); - } - else - { - QAction * ac = new QAction( pick_modes_[i].name.c_str(), ag ); - ac->setData( QVariant( i ) ); - ac->setCheckable( true ); - - if ((int)i == pick_mode_idx_) - ac->setChecked( true ); - - pickMenu_->addAction( ac ); - } - } - - connect( ag, SIGNAL( triggered( QAction * ) ), - this, SLOT( actionPickMenu( QAction * ) )); -} - - -//----------------------------------------------------------------------------- - - -void glViewer::actionPickMenu( QAction * _action ) -{ - int _id = _action->data().toInt(); - if (_id < (int) pick_modes_.size() ) - { - pickMode( _id ); - } - - properties_.setPickingMode(); - - hidePopupMenus(); -} - - //----------------------------------------------------------------------------- diff --git a/widgets/glWidget/QtBaseViewer.hh b/widgets/glWidget/QtBaseViewer.hh index 44cd7d632a399f3bfd23f91980e0c8fbdcc073e4..cb8c245c7248450d7d069205058f39a7da4b6fda 100644 --- a/widgets/glWidget/QtBaseViewer.hh +++ b/widgets/glWidget/QtBaseViewer.hh @@ -289,10 +289,6 @@ public: /// rotate the scene and update modelview matrix void rotate(const ACG::Vec3d& axis, double angle, const ACG::Vec3d& _center); - /// Get the menu pointers (required to add them to the menubar as a temp workaround for a qt 4.3 bug - QMenu * getPickMenu() { return pickMenu_; }; - - //---------------------------------------------------------------- public slots public slots: @@ -338,8 +334,6 @@ public slots: virtual void setView( const ACG::GLMatrixd& _modelview, const ACG::GLMatrixd& _inverse_modelview ); - void actionPickMenu( QAction * _action ); - void actionPasteView(); void actionCopyView(); @@ -425,9 +419,6 @@ protected: /// updates projection matrix void updateProjectionMatrix(); - /// update pick mode menu - void updatePickMenu(); - //------------------------------------------------------------- protected slots @@ -444,13 +435,6 @@ protected slots: virtual void cleanupEventFilter() { removeEventFilter( sender());} - - -//--------------------------------------------------------------- private slots -private slots: - - void hidePopupMenus(); - //----------------------------------------------------------- private functions private: @@ -517,8 +501,6 @@ private: double frame_time_; - QMenu * pickMenu_; - // scenegraph stuff ACG::SceneGraph::BaseNode* sceneGraphRoot_; @@ -724,57 +706,6 @@ private: bool fast_pick( const QPoint& _mousePos, ACG::Vec3d& _hitPoint ); - /** \brief add pick mode - * - * @param _name Name of the Pick Mode or "Separator" to insert a separator - * @param _mouse_tracking true: every mouse movement will emit mouse events not only when mousebutton is pressed - * @param _pos position to insert the mode in the popup menu. - */ - void addPickMode(const std::string& _name, - bool _mouse_tracking = false, - int _pos = -1, - bool _visible = true, - QCursor _cursor = Qt::ArrowCursor ); - - /** clear all pick modes - */ - void clearPickModes(); - - /** return the currently active pick mode - */ - const std::string& pickMode() const; - - /** Switch to given picking mode - * @param _name Name of the picking mode - */ - void pickMode(const std::string& _name); - - /** Switch to given picking mode - * @param _id Id of the picking Mode - */ - void pickMode( int _id ); - - public slots: - - /** \brief set a new cursor for the pick mode - * - * @param _name Name of the Pick Mode - * @param _cursor the new cursor - */ - void setPickModeCursor(const std::string& _name, QCursor _cursor); - - /** \brief set mouseTracking for the pick mode - * - * @param _name Name of the Pick Mode - * @param _mouseTracking true: every mouse movement will emit mouse events not only when mousebutton is pressed - */ - void setPickModeMouseTracking(const std::string& _name, bool _mouseTracking); - - signals: - /** This signal is emitted when the pickMode is changed and contains the new PickMode - */ - void signalPickModeChanged(const std::string&); - private: /// pick using colors @@ -791,46 +722,6 @@ private: unsigned int& _targetIdx, ACG::Vec3d* _hitPointPtr=0 ); - /** Struct containing information about pickModes - */ - struct PickMode - { - /// Constructor - PickMode(const std::string& _n, bool _t, bool _v, QCursor _c) : - name(_n), tracking(_t), visible(_v), cursor(_c) {} - - /** Name of the pickMode - */ - std::string name; - - /** MouseTracking enabled for this mode? - */ - bool tracking; - - /** Defines if the Mode will be visible in the popup Menu - */ - bool visible; - - /** Cursor used in this pickMode - */ - QCursor cursor; - }; - - /** Vector of all Picking modes - */ - std::vector pick_modes_; - - /** Name of current pickMode - */ - std::string pick_mode_name_; - - /** Index of current pickMode - */ - int pick_mode_idx_; - - - - /** @} */ //=========================================================================== @@ -894,9 +785,6 @@ private: */ void slotPropertiesUpdated(); - /// Called when the actionMode has been updated - void updateActionMode(Viewer::ActionMode _am); - private: /** This will apply all properties without redrawing * You have to set the context yourself! diff --git a/widgets/glWidget/QtBaseViewerPicking.cc b/widgets/glWidget/QtBaseViewerPicking.cc index 21aa6e73ab8dd01a01fbe30fcae691ff84f32fbc..843c07de372b7f9b62a2315f728d6ecf323a0280 100644 --- a/widgets/glWidget/QtBaseViewerPicking.cc +++ b/widgets/glWidget/QtBaseViewerPicking.cc @@ -383,119 +383,6 @@ fast_pick( const QPoint& _mousePos, else return false; } -//----------------------------------------------------------------------------- - - -void glViewer::pickMode( int _id ) -{ - if (_id < (int) pick_modes_.size() ) - { - pick_mode_idx_ = _id; - pick_mode_name_ = pick_modes_[pick_mode_idx_].name; - - // adjust mouse tracking - if ( properties_.pickingMode() ) - trackMouse(pick_modes_[pick_mode_idx_].tracking); - - // adjust Cursor - if ( properties_.pickingMode() ) - setCursor( pick_modes_[pick_mode_idx_].cursor); - - // emit signal - emit(signalPickModeChanged(pick_mode_name_)); - } -} - - -//----------------------------------------------------------------------------- - - -void glViewer::addPickMode(const std::string& _name, - bool _tracking, - int _pos, - bool _visible, - QCursor _cursor) -{ - if ((unsigned int)_pos < pick_modes_.size()) - { - std::vector::iterator it = pick_modes_.begin(); - it += _pos+1; - pick_modes_.insert(it, PickMode(_name, _tracking, _visible, _cursor)); - } - else - pick_modes_.push_back(PickMode(_name, _tracking, _visible, _cursor)); - - updatePickMenu(); -} - -//----------------------------------------------------------------------------- - -void glViewer::setPickModeCursor(const std::string& _name, QCursor _cursor) -{ - for (uint i=0; i < pick_modes_.size(); i++) - if ( pick_modes_[i].name == _name ){ - pick_modes_[i].cursor = _cursor; - - //switch cursor if pickMode is active - if (pick_mode_name_ == _name && properties_.pickingMode() ) - setCursor(_cursor); - break; - } -} - -//----------------------------------------------------------------------------- - -void glViewer::setPickModeMouseTracking(const std::string& _name, bool _mouseTracking) -{ - for (uint i=0; i < pick_modes_.size(); i++) - if ( pick_modes_[i].name == _name ){ - pick_modes_[i].tracking = _mouseTracking; - - //switch cursor if pickMode is active - if (pick_mode_name_ == _name && properties_.pickingMode() ) - trackMouse(_mouseTracking); - break; - } -} - -//----------------------------------------------------------------------------- - - -void glViewer::clearPickModes() -{ - pick_modes_.clear(); - pick_mode_idx_ = -1; - pick_mode_name_ = ""; - updatePickMenu(); -} - - -//----------------------------------------------------------------------------- - - -const std::string& glViewer::pickMode() const -{ - return pick_mode_name_; -} - - -//----------------------------------------------------------------------------- - - -void glViewer::pickMode(const std::string& _name) -{ - for (unsigned int i=0; i