Commit 46462207 authored by Dirk Wilden's avatar Dirk Wilden

actionModes/pickModes moved from BaseViewer to CoreWidget

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5381 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 380878ee
......@@ -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;
......
......@@ -54,6 +54,7 @@
#include <ACG/Scenegraph/SceneGraph.hh>
#include <OpenFlipper/BasePlugin/PluginFunctionsViewControls.hh>
/** 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
......
......@@ -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);
}
......
......@@ -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
......
......@@ -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);
}
}
......@@ -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);
};
......
......@@ -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 ) {
......
......@@ -102,7 +102,12 @@ CoreWidget( QVector<ViewMode*>& _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<ViewMode*>& _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<ViewMode*>& _viewModes,
"<ul><li><b>Rotate</b> using <b>left</b> mouse button.</li>"
"<li><b>Translate</b> using <b>middle</b> mouse button.</li>"
"<li><b>Zoom</b> using <b>left+middle</b> mouse buttons.</li></ul>" );
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<ViewMode*>& _viewModes,
lightButton_->setWhatsThis(
"Switch to <b>light</b> mode.<br>"
"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<ViewMode*>& _viewModes,
"Use picking functions like flipping edges.<br>"
"To change the mode use the right click<br>"
"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<ViewMode*>& _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<ViewMode*>& _viewModes,
registerCoreKeys();
setExamineMode();
setWindowIcon( OpenFlipper::Options::OpenFlipperIcon() );
......
......@@ -83,7 +83,7 @@
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
#include <OpenFlipper/INIFile/INIFile.hh>
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
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<PickMode> 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();
/** @} */
};
......
......@@ -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:
......
//=============================================================================
//
// 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 <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 5359 $
// $Author: wilden $
// $Date: 2009-03-19 16:43:39 +0100 (Thu, 19 Mar 2009) $
//
//=============================================================================
//=============================================================================
//
// CLASS CoreWidget - IMPLEMENTATION
//
//=============================================================================
//== INCLUDES =================================================================
#include "CoreWidget.hh"
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
//-----------------------------------------------------------------------------
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: