Commit 93b239e2 authored by Jan Möbius's avatar Jan Möbius

More PluginFunctions for viewer Controls

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4965 383ad7c9-94d9-4d36-a494-682f7c89f535
parent adf91a47
......@@ -82,8 +82,8 @@ void setDataRoot( BaseObject* _root ) {
objectRoot_ = _root;
}
void setViewers( std::vector< glViewer* > _examiner_widgets ) {
PluginFunctions::examiner_widgets_ = _examiner_widgets;
void setViewers( std::vector< glViewer* > _viewerWidgets ) {
PluginFunctions::examiner_widgets_ = _viewerWidgets;
PluginFunctions::examiner_widget_ = examiner_widgets_[0];
}
......@@ -95,6 +95,15 @@ void setActiveExaminer( const unsigned int _id ) {
activeExaminer_ = _id;
}
glViewer* viewer(int _viewerId ) {
if ( _viewerId < 0 || _viewerId >= (int)examiner_widgets_.size() ) {
std::cerr << "Requested unknown viewer with id : " << _viewerId << std::endl;
return examiner_widgets_[activeExaminer()];
}
return( examiner_widgets_[_viewerId] );
}
unsigned int activeExaminer( ) {
return activeExaminer_;
}
......@@ -273,14 +282,23 @@ QPoint mapToLocal( const QPoint _point ) {
return examiner_widgets_[activeExaminer_]->glMapFromGlobal(_point);
}
/** Set the draw Mode of the examiner widget.\n
*
* The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
* They can be combined.
*/
void setDrawMode( const unsigned int _mode ) {
examiner_widgets_[activeExaminer_]->drawMode(_mode);
examiner_widgets_[activeExaminer_]->updateGL();
void setDrawMode( const unsigned int _mode , int _viewer) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->drawMode(_mode);
examiner_widgets_[activeExaminer_]->updateGL();
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i ) {
examiner_widgets_[i]->drawMode(_mode);
examiner_widgets_[i]->updateGL();
}
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() ) {
examiner_widgets_[_viewer]->drawMode(_mode);
examiner_widgets_[_viewer]->updateGL();
}
else
std::cerr << "Requested illegal viewer for setting DrawMode!!" << std::endl;
}
/** Get the current draw Mode of the examiner widget.\n
......@@ -288,16 +306,17 @@ void setDrawMode( const unsigned int _mode ) {
* The DrawModes are defined at ACG/Scenegraph/DrawModes.hh \n
* They can be combined.
*/
unsigned int drawMode( ) {
return examiner_widgets_[activeExaminer_]->drawMode();
}
void setGlobalDrawMode( const unsigned int _mode ) {
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i ) {
examiner_widgets_[i]->drawMode(_mode);
examiner_widgets_[i]->updateGL();
}
unsigned int drawMode( int _viewer ) {
if ( _viewer == ACTIVE_VIEWER ) {
return examiner_widgets_[activeExaminer_]->drawMode();
} else if ( _viewer == ALL_VIEWERS )
std::cerr << "Please select viewer to get viewing direction!" << std::endl;
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
return examiner_widgets_[_viewer]->drawMode();
else
std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
return examiner_widgets_[activeExaminer_]->drawMode();
}
bool scenegraphPick( ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0 ) {
......@@ -358,10 +377,6 @@ void actionMode ( Viewer::ActionMode _mode) {
viewerProperties(i).actionMode(_mode);
}
ACG::GLState& glState() {
return viewerProperties().glState();
}
void getCurrentViewImage(QImage& _image) {
examiner_widget_->copyToImage( _image );
}
......@@ -399,17 +414,42 @@ void setMainGLContext() {
examiner_widget_->makeCurrent();
}
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up) {
examiner_widgets_[activeExaminer_]->viewingDirection(_dir,_up);
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up , int _viewer ) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->viewingDirection(_dir,_up);
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->viewingDirection(_dir,_up);
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->viewingDirection(_dir,_up);
else
std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
}
void setScenePos(const ACG::Vec3d& _center,const double _radius) {
examiner_widgets_[activeExaminer_]->setScenePos( _center, _radius );
}
void setScenePos(const ACG::Vec3d& _center) {
examiner_widgets_[activeExaminer_]->setScenePos( _center, examiner_widgets_[activeExaminer_]->scene_radius() );
void setScenePos(const ACG::Vec3d& _center,const double _radius, int _viewer ) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->setScenePos( _center, _radius );
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->setScenePos( _center, _radius );
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->setScenePos( _center, _radius );
else
std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
examiner_widgets_[activeExaminer_];
}
void setScenePos(const ACG::Vec3d& _center, int _viewer ) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->setScenePos( _center, examiner_widgets_[activeExaminer_]->scene_radius() );
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->setScenePos( _center, examiner_widgets_[i]->scene_radius() );
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->setScenePos( _center, examiner_widgets_[_viewer]->scene_radius() );
else
std::cerr << "Requested illegal viewer for setScenePos!!" << std::endl;
}
const ACG::Vec3d& sceneCenter() {
......@@ -420,34 +460,94 @@ double sceneRadius() {
return examiner_widgets_[activeExaminer_]->scene_radius();
}
void translate( const ACG::Vec3d &_vector ) {
examiner_widgets_[activeExaminer_]->translate(_vector);
void translate( const ACG::Vec3d &_vector , int _viewer ) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->translate(_vector);
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->translate(_vector);
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->translate(_vector);
else
std::cerr << "Requested illegal viewer for translate!!" << std::endl;
}
void rotate(const ACG::Vec3d& _axis,
const double _angle,
const ACG::Vec3d& _center)
const ACG::Vec3d& _center,
int _viewer )
{
examiner_widgets_[activeExaminer_]->rotate(_axis,_angle,_center);
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->rotate(_axis,_angle,_center);
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->rotate(_axis,_angle,_center);
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->rotate(_axis,_angle,_center);
else
std::cerr << "Requested illegal viewer for rotate!!" << std::endl;
}
void viewHome() {
examiner_widgets_[activeExaminer_]->home();
void viewHome(int _viewer) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->home();
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->home();
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->home();
else
std::cerr << "Requested illegal viewer for viewHome!!" << std::endl;
}
void viewAll() {
examiner_widgets_[activeExaminer_]->viewAll();
void viewAll(int _viewer) {
if ( _viewer == ACTIVE_VIEWER ) {
examiner_widgets_[activeExaminer_]->viewAll();
} else if ( _viewer == ALL_VIEWERS )
for ( uint i = 0 ; i < examiner_widgets_.size(); ++i )
examiner_widgets_[i]->viewAll();
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
examiner_widgets_[_viewer]->viewAll();
else
std::cerr << "Requested illegal viewer for viewAll!!" << std::endl;
}
ACG::Vec3d viewingDirection() {
ACG::Vec3d viewingDirection(int _viewer) {
if ( _viewer == ACTIVE_VIEWER ) {
return viewerProperties(activeExaminer_).glState().viewing_direction();
} else if ( _viewer == ALL_VIEWERS )
std::cerr << "Please select viewer to get viewing direction!" << std::endl;
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
return viewerProperties(_viewer).glState().viewing_direction();
else
std::cerr << "Requested illegal viewer for viewingDirection!!" << std::endl;
return viewerProperties().glState().viewing_direction();
}
ACG::Vec3d eyePos() {
ACG::Vec3d eyePos(int _viewer) {
if ( _viewer == ACTIVE_VIEWER ) {
return viewerProperties(activeExaminer_).glState().eye();
} else if ( _viewer == ALL_VIEWERS )
std::cerr << "Please select viewer to get eyePos!" << std::endl;
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
return viewerProperties(_viewer).glState().eye();
else
std::cerr << "Requested illegal viewer for eyePos!!" << std::endl;
return viewerProperties().glState().eye();
}
ACG::Vec3d upVector() {
ACG::Vec3d upVector(int _viewer) {
if ( _viewer == ACTIVE_VIEWER ) {
return viewerProperties(activeExaminer_).glState().up();
} else if ( _viewer == ALL_VIEWERS )
std::cerr << "Please select viewer to get up vector!" << std::endl;
else if ( ( _viewer >= 0 ) && _viewer < (int)examiner_widgets_.size() )
return viewerProperties(_viewer).glState().up();
else
std::cerr << "Requested illegal viewer for up vector!!" << std::endl;
return viewerProperties().glState().up();
}
......
......@@ -50,9 +50,7 @@
#include <OpenFlipper/common/Types.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
// #include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <ACG/GL/GLState.hh>
#include <OpenFlipper/common/ViewerProperties.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. */
......@@ -236,10 +234,6 @@ void pickMode ( std::string _mode);
DLLEXPORT
void pickMode ( const unsigned int _examiner, std::string _mode);
/// Get the current gl state from examiner
DLLEXPORT
ACG::GLState& glState();
/// Returns a QImage of the current View
DLLEXPORT
void getCurrentViewImage(QImage& _image);
......@@ -268,15 +262,6 @@ void actionMode ( Viewer::ActionMode _mode);
DLLEXPORT
Viewer::ActionMode actionMode();
/** Get the viewer properties
* -1 will get the properties of the active Viewer which is the default
*/
DLLEXPORT
Viewer::ViewerProperties& viewerProperties(int _id = -1);
/** Lock scene rotation via mouse
*
* @param _mode allow or disallow rotation
......@@ -284,140 +269,6 @@ Viewer::ViewerProperties& viewerProperties(int _id = -1);
DLLEXPORT
void allowRotation(bool _mode);
/** @} */
//=======================================
// View settings
/** @name View settings
* @{ */
//=======================================
/** \brief Set current GL Context to main context
*/
DLLEXPORT
void setMainGLContext();
/** \brief Set the viewing direction
* @param _dir direction
* @param _up up vector
*/
DLLEXPORT
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up);
/** \brief Set the Scene position
* @param _center Center of the current scene
* @param _radius Radius of the scene ( Use scene_radius to get the current radius )
*/
DLLEXPORT
void setScenePos(const ACG::Vec3d& _center, const double _radius);
/** \brief Set the scene position (Same as setScenePos(const ACG::Vec3d& _center, double _radius) )
*
*/
DLLEXPORT
void setScenePos(const ACG::Vec3d& _center);
/** \brief Get the current scene center
*
*/
DLLEXPORT
const ACG::Vec3d& sceneCenter();
/** \brief Returns the current scene radius from the examiner widget
*
* Returns the Radius of the scene
*/
DLLEXPORT
double sceneRadius();
/** \brief Translate viewer pos by given vector
*
* Translates the scene by a given vector. ( This is only a view transformation and does not
* effect the scene center. To really translate the scene, use setScenePos );
* @param _vector translation
*/
DLLEXPORT
void translate( const ACG::Vec3d &_vector );
/** \brief Rotate Scene around axis
*
* Rotates the current scene.
* @param _axis Rotation axis
* @param _angle Rotation Angle
* @param _center Rotation Center
*/
DLLEXPORT
void rotate(const ACG::Vec3d& _axis,
const double _angle,
const ACG::Vec3d& _center);
/** \brief Go to home position
*/
DLLEXPORT
void viewHome();
/** \brief View the whole scene
*/
DLLEXPORT
void viewAll();
/** \brief Get the current viewing Direction
*/
DLLEXPORT
ACG::Vec3d viewingDirection();
/** \brief Get the current viewer position
*/
DLLEXPORT
ACG::Vec3d eyePos();
/** \brief Get the current up vector
*/
DLLEXPORT
ACG::Vec3d upVector();
/** \brief Switch to orthographic Projection
*
*/
DLLEXPORT
void orthographicProjection();
/** \brief Switch to perspective Projection
*
*/
DLLEXPORT
void perspectiveProjection();
/** \brief Switch active examiner to a different draw mode
*
*/
DLLEXPORT
void setDrawMode( const unsigned int _mode );
/** \brief Get the current draw Mode of the active Examiner
*
*/
DLLEXPORT
unsigned int drawMode( );
/** \brief Switch all examiners to a different draw mode
*
*/
DLLEXPORT
void setGlobalDrawMode( const unsigned int _mode );
/** \brief Set the background color of the examiner widget.
*
*/
DLLEXPORT
void setBackColor( OpenMesh::Vec4f _color);
/** \brief Map coordinates of GL Widget to global coordinates
*
*/
......@@ -432,24 +283,6 @@ QPoint mapToLocal( const QPoint _point );
/** @} */
//=======================================
// Do animations in examiner viewer
/** @name Animations
* @{ */
//=======================================
/** Fly to point and set new viewing direction (animated).
* @param _position New viewer position ( the new eye point of the viewer )
* @param _center The new scene center ( the point we are looking at )
* @param _time Animation time in ms
*/
DLLEXPORT
void flyTo (const ACG::Vec3d &_position, const ACG::Vec3d &_center, double _time=1000.0);
/** @} */
//=======================================
// Iterators for object Access
/** @name Iterators
......
......@@ -60,9 +60,13 @@ namespace PluginFunctions {
/** @name Setup Functions
* @{ */
//=======================================
/// Set the internal examiner pointer ( DO NOT USE!! )
/// Set the internal Viewer pointer ( DO NOT USE!! )
DLLEXPORT
void setViewers( std::vector< glViewer* > _examiner_widgets );
void setViewers( std::vector< glViewer* > _viewerWidgets );
/// Get a Viewer
DLLEXPORT
glViewer* viewer(int _viewerId );
/// Set the internal viewerProperties pointer ( DO NOT USE!! )
DLLEXPORT
......
//=============================================================================
//
// 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: 4796 $
// $Author: moebius $
// $Date: 2009-02-12 10:09:43 +0100 (Do, 12. Feb 2009) $
//
//=============================================================================
//=============================================================================
//
// Standard Functions
//
//=============================================================================
/**
* \file PluginFunctions.hh
* This file contains functions which can be used by plugins to access data in the framework.
*/
//
#ifndef PLUGINFUNCTIONS_VIEWCONTROL_HH
#define PLUGINFUNCTIONS_VIEWCONTROL_HH
#include <OpenFlipper/common/Types.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
#include <ACG/GL/GLState.hh>
#include <OpenFlipper/common/ViewerProperties.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 {
const int ALL_VIEWERS = -2;
const int ACTIVE_VIEWER = -1;
//=======================================
// Get/set status of viewers
/** @name Viewer Status and properties
* @{ */
//=======================================
/** Get the viewer properties
* -1 will get the properties of the active Viewer which is the default
*/
DLLEXPORT
Viewer::ViewerProperties& viewerProperties(int _id = -1);
/** @} */
//=======================================
// View settings
/** @name View settings
* @{ */
//=======================================
/** Lock scene rotation via mouse
*
* @param _mode allow or disallow rotation
*/
DLLEXPORT
void allowRotation(bool _mode);
/** \brief Set current GL Context to main context
*/
DLLEXPORT
void setMainGLContext();
/** \brief Set the viewing direction
* @param _dir direction
* @param _up up vector
* @param _viewer Id of the viewer to use.
* ALL_VIEWERS will set all viewers (Default)
* ACTIVE_VIEWER active viewer
* 0..3 Choose viewer explicitly
*/
DLLEXPORT
void viewingDirection(const ACG::Vec3d &_dir, const ACG::Vec3d &_up , int _viewer = ALL_VIEWERS);
/** \brief Set the Scene position
* @param _center Center of the current scene
* @param _radius Radius of the scene ( Use scene_radius to get the current radius )
* @param _viewer Id of the viewer to use.
* ALL_VIEWERS will set all viewers (Default)
* ACTIVE_VIEWER active viewer
* 0..3 Choose viewer explicitly
*/
DLLEXPORT
void setScenePos(const ACG::Vec3d& _center, const double _radius , int _viewer = ALL_VIEWERS);
/** \brief Set the scene position
*
* Same as setScenePos(const ACG::Vec3d& _center, double _radius) but reuses the current radius
*
* @param _viewer Id of the viewer to use.
* ALL_VIEWERS will set all viewers (Default)
* ACTIVE_VIEWER active viewer
* 0..3 Choose viewer explicitly
*/
DLLEXPORT
void setScenePos(const ACG::Vec3d& _center , int _viewer = ALL_VIEWERS);
/** \brief Get the current scene center
*
*/
DLLEXPORT
const ACG::Vec3d& sceneCenter();
/** \brief Returns the current scene radius from the examiner widget
*
* Returns the Radius of the scene
*/
DLLEXPORT
double sceneRadius();
/** \brief Translate viewer pos by given vector
*
* Translates the scene by a given vector. ( This is only a view transformation and does not
* effect the scene center. To really translate the scene, use setScenePos );
* @param _vector translation
* @param _viewer Id of the viewer to use.
* ALL_VIEWERS will set all viewers (Default)
* ACTIVE_VIEWER active viewer
* 0..3 Choose viewer explicitly
*/
DLLEXPORT
void translate( const ACG::Vec3d &_vector , int _viewer = ALL_VIEWERS);
/** \brief Rotate Scene around axis
*
* Rotates the current scene.
* @param _axis Rotation axis
* @param _angle Rotation Angle
* @param _center Rotation Center
* @param _viewer Id of the viewer to use.
* ALL_VIEWERS will set all viewers (Default)
* ACTIVE_VIEWER active viewer
* 0..3 Choose viewer explicitly