Commit 05439ad5 authored by Jan Möbius's avatar Jan Möbius
Browse files

Made DrawMode an extra class

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@8548 383ad7c9-94d9-4d36-a494-682f7c89f535
parent bc546846
......@@ -1469,7 +1469,7 @@ bool QtBaseViewer::decodeView(const QString& _view)
void QtBaseViewer::actionDrawMenu( QAction * _action )
{
unsigned int mode( _action->data().toUInt() );
SceneGraph::DrawModes::DrawMode mode( _action->data().toUInt() );
// combine draw modes
if (qApp->keyboardModifiers() & Qt::ShiftModifier)
......@@ -1491,7 +1491,7 @@ void QtBaseViewer::actionDrawMenu( QAction * _action )
aIter != aEnd;
++aIter )
{
if( (*aIter)->data().toUInt() != mode )
if( SceneGraph::DrawModes::DrawMode((*aIter)->data().toUInt()) != mode )
(*aIter)->setChecked( false );
}
......@@ -1941,19 +1941,19 @@ void QtBaseViewer::updatePopupMenu()
drawMenuActions_.clear();
std::vector< unsigned int > draw_mode_id;
std::vector< SceneGraph::DrawModes::DrawMode > draw_mode_id;
draw_mode_id = SceneGraph::DrawModes::getDrawModeIDs( availDrawModes_ );
draw_mode_id = availDrawModes_.getAtomicDrawModes();
for ( unsigned int i = 0; i < draw_mode_id.size(); ++i )
{
unsigned int id = draw_mode_id[i];
std::string descr = SceneGraph::DrawModes::description( id );
SceneGraph::DrawModes::DrawMode id = draw_mode_id[i];
std::string descr = id.description();
QAction * action = new QAction( descr.c_str(), drawGroup );
action->setData( QVariant( id ) );
action->setData( QVariant( id.getIndex() ) );
action->setCheckable( true );
action->setChecked( SceneGraph::DrawModes::containsId( curDrawMode_, id ) );
action->setChecked( curDrawMode_.containsAtomicDrawMode(id) );
drawMenuActions_.push_back( action );
}
......
......@@ -56,6 +56,7 @@
#include "../GL/GLState.hh"
#include "../Scenegraph/SceneGraph.hh"
#include "../Scenegraph/DrawModes.hh"
#include <QtOpenGL/QGLFormat>
#include <QBoxLayout>
......@@ -442,14 +443,14 @@ public:
/// set draw mode (No test if this mode is available!)
void drawMode(unsigned int _mode)
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
{
curDrawMode_=_mode;
updatePopupMenu();
}
/// get current draw mode
unsigned int drawMode() { return curDrawMode_; }
ACG::SceneGraph::DrawModes::DrawMode drawMode() { return curDrawMode_; }
/// convert current view to text representation
void encodeView(QString& _view);
......@@ -820,8 +821,8 @@ private:
// scenegraph stuff
SceneGraph::BaseNode* sceneGraphRoot_;
unsigned int curDrawMode_,
availDrawModes_;
ACG::SceneGraph::DrawModes::DrawMode curDrawMode_,
availDrawModes_;
bool updateLocked_;
bool projectionUpdateLocked_;
......
......@@ -92,16 +92,6 @@ namespace QtWidgets {
//== IMPLEMENTATION ==========================================================
enum PopupMenuItems
{
M_Options = SceneGraph::DrawModes::UNUSED+1
};
//-----------------------------------------------------------------------------
QtSceneGraphWidget::
QtSceneGraphWidget( QWidget * _parent,
SceneGraph::BaseNode * _rootNode ) :
......@@ -289,25 +279,23 @@ slotItemPressed( QTreeWidgetItem * _item,
connect( modeGroup, SIGNAL( triggered( QAction * ) ),
this, SLOT( slotModeMenu( QAction * ) ) );
unsigned int availDrawModes( node->availableDrawModes() );
ACG::SceneGraph::DrawModes::DrawMode availDrawModes( node->availableDrawModes() );
availDrawModes |= SceneGraph::DrawModes::DEFAULT;
unsigned int currentDrawMode( node->drawMode() );
ACG::SceneGraph::DrawModes::DrawMode currentDrawMode( node->drawMode() );
std::vector< unsigned int > available_modes
( SceneGraph::DrawModes::getDrawModeIDs( availDrawModes ) );
std::vector< ACG::SceneGraph::DrawModes::DrawMode > available_modes( availDrawModes.getAtomicDrawModes() );
for ( unsigned int i = 0; i < available_modes.size(); ++i )
{
unsigned int id = available_modes[i];
std::string descr = SceneGraph::DrawModes::description( id );
ACG::SceneGraph::DrawModes::DrawMode id = available_modes[i];
std::string descr = id.description();
QAction * action = new QAction( descr.c_str(), modeGroup );
action->setCheckable( true );
action->setChecked
( SceneGraph::DrawModes::containsId( currentDrawMode, id ) );
action->setData( QVariant( id ) );
action->setChecked ( currentDrawMode.containsAtomicDrawMode(id ) ) ;
action->setData( QVariant( id.getIndex() ) );
}
modeMenu_->addActions( modeGroup->actions() );
......@@ -446,14 +434,8 @@ void QtSceneGraphWidget::slotEditCoordinateFrame()
void QtSceneGraphWidget::slotModeMenu( QAction * _action )
{
unsigned int id = _action->data().toUInt();
SceneGraph::DrawModes::DrawMode new_drawmode( _action->data().toUInt());
// int old_drawmode = curItem_->node()->drawMode();
int new_drawmode = id;
// if (shiftPressed_)
// new_drawmode ^= (old_drawmode & 0xFFFE);
curItem_->node()->drawMode( new_drawmode );
curItem_->update();
emit signalNodeChanged( curItem_->node() );
......@@ -552,7 +534,7 @@ QtSceneGraphWidget::Item::update()
case BaseNode::HideSubtree: setText( 2, "HideSubtree"); break;
}
setText( 3, SceneGraph::DrawModes::description(node_->drawMode()).c_str());
setText( 3, node_->drawMode().description().c_str());
}
......
......@@ -74,12 +74,12 @@ QtShaderDialog::QtShaderDialog( QWidget * _parent,
{
ui_.setupUi( this );
unsigned int drawmode = ACG::SceneGraph::DrawModes::DEFAULT;
ACG::SceneGraph::DrawModes::DrawMode drawmode = ACG::SceneGraph::DrawModes::DEFAULT;
while ( drawmode != ACG::SceneGraph::DrawModes::UNUSED )
{
ui_.drawModeBox->addItem( QString(ACG::SceneGraph::DrawModes::description(drawmode).c_str() ));
drawmode *= 2 ;
ui_.drawModeBox->addItem( QString( drawmode.description().c_str() ) );
++drawmode ;
}
ui_.shaderDir->setText( QString(_node->shaderDir().c_str()) );
......
......@@ -173,7 +173,7 @@ BaseNode::delete_subtree()
//----------------------------------------------------------------------------
void
BaseNode::enterPick(GLState& _state, PickTarget /*_target*/, unsigned int _drawMode)
BaseNode::enterPick(GLState& _state, PickTarget /*_target*/, DrawModes::DrawMode _drawMode)
{
enter (_state, _drawMode);
}
......@@ -181,7 +181,7 @@ BaseNode::enterPick(GLState& _state, PickTarget /*_target*/, unsigned int _drawM
//----------------------------------------------------------------------------
void
BaseNode::leavePick(GLState& _state, PickTarget /*_target*/, unsigned int _drawMode)
BaseNode::leavePick(GLState& _state, PickTarget /*_target*/, DrawModes::DrawMode _drawMode)
{
leave (_state, _drawMode);
}
......
......@@ -69,6 +69,7 @@
#include <string>
#include <algorithm>
#include <iostream>
#include <ACG/Scenegraph/DrawModes.hh>
//== NAMESPACES ===============================================================
......@@ -147,7 +148,7 @@ public:
/** Return a list of available draw modes for this node: should be OR'ed
from the items of the enum DrawModeIDs. */
virtual unsigned int availableDrawModes() const { return 0; }
virtual DrawModes::DrawMode availableDrawModes() const { return DrawModes::NONE; }
/** Compute the bounding box of this node and update the values
_bbMin and _bbMax accordingly. Do not initialize _bbMin and
......@@ -162,15 +163,15 @@ public:
function.
\see MaterialNode
*/
virtual void enter(GLState& /*_state */, unsigned int /*_drawMode*/ ) {}
virtual void enter(GLState& /*_state */, DrawModes::DrawMode /*_drawMode*/ ) {}
/** Draw this node using the draw modes _drawMode */
virtual void draw(GLState& /* _state */, unsigned int /* _drawMode */) {}
virtual void draw(GLState& /* _state */, DrawModes::DrawMode /* _drawMode */) {}
/** The leave function is used to restore GL states the have been changed.
This function must restore the status before enter() !
*/
virtual void leave(GLState& /* _state */, unsigned int /* _drawMode */) {}
virtual void leave(GLState& /* _state */, DrawModes::DrawMode /* _drawMode */) {}
/** This function is called when traversing the scene graph during picking
and arriving at this node. It can be used to store GL states that
......@@ -178,7 +179,7 @@ public:
function. Its default implementation will call the enter() function.
*/
virtual void enterPick(GLState& _state , PickTarget _target,
unsigned int _drawMode );
DrawModes::DrawMode _drawMode );
/** Draw the node using the GL picking name stack. The node's ID
will already be on the name stack, so only names identifing e.g. faces
......@@ -191,7 +192,7 @@ public:
Its default implementation will call the leave() function.
*/
virtual void leavePick(GLState& _state, PickTarget _target,
unsigned int _drawMode );
DrawModes::DrawMode _drawMode );
/** Enable or Disable picking for this node
* ( default: enabled )
......@@ -365,10 +366,10 @@ public:
//--- draw mode ---
/// Return the own draw modes of this node
unsigned int drawMode() const { return drawMode_; }
DrawModes::DrawMode drawMode() const { return drawMode_; }
/** Set this node's own draw mode. It will be used for drawing instead of
the the global draw mode. */
void drawMode(unsigned int _drawMode) { drawMode_ = _drawMode; }
void drawMode(DrawModes::DrawMode _drawMode) { drawMode_ = _drawMode; }
//--- traverse type ---
......@@ -550,7 +551,7 @@ private:
unsigned int id_;
/// private draw mode
unsigned int drawMode_;
DrawModes::DrawMode drawMode_;
/// depth func
GLenum depth_func_;
......
......@@ -63,7 +63,7 @@ namespace SceneGraph {
//== IMPLEMENTATION ==========================================================
unsigned int
DrawModes::DrawMode
BoundingBoxNode::
availableDrawModes() const
{
......@@ -79,7 +79,7 @@ BoundingBoxNode::~BoundingBoxNode() {
void
BoundingBoxNode::
draw(GLState& /* _state */ , unsigned int _drawMode)
draw(GLState& /* _state */ , DrawModes::DrawMode _drawMode)
{
ACG::SceneGraph::BoundingBoxAction act;
......
......@@ -96,10 +96,10 @@ public:
ACG_CLASSNAME(BoundingBoxNode);
/// return available draw modes
unsigned int availableDrawModes() const;
DrawModes::DrawMode availableDrawModes() const;
/// draw lines and normals
void draw(GLState& _state, unsigned int _drawMode);
void draw(GLState& _state, DrawModes::DrawMode _drawMode);
};
......
......@@ -67,7 +67,7 @@ CartesianClippingNode::CartesianClippingNode( BaseNode* _parent,
void
CartesianClippingNode::enter( GLState & _state, unsigned int /* _drawmode */ )
CartesianClippingNode::enter( GLState & _state, DrawModes::DrawMode /* _drawmode */ )
{
Vec3d eye = _state.eye();
......@@ -146,7 +146,7 @@ CartesianClippingNode::enter( GLState & _state, unsigned int /* _drawmode */ )
void
CartesianClippingNode::leave( GLState & /* _state */ , unsigned int /* _drawmode */ )
CartesianClippingNode::leave( GLState & /* _state */ , DrawModes::DrawMode /* _drawmode */ )
{
glDisable( GL_CLIP_PLANE0 );
glDisable( GL_CLIP_PLANE1 );
......
......@@ -87,10 +87,10 @@ public:
ACG_CLASSNAME(CartesianClippingNode);
/// begin clipping
void enter( GLState & _state, unsigned int _drawmode );
void enter( GLState & _state, DrawModes::DrawMode _drawmode );
/// stop clipping
void leave( GLState & _state, unsigned int _drawmode );
void leave( GLState & _state, DrawModes::DrawMode _drawmode );
/// set position
void set_cursor( const Vec3f & _pos );
......
......@@ -133,7 +133,7 @@ ClippingNode::set_offset(float _offset)
//----------------------------------------------------------------------------
void ClippingNode::enter(GLState& /* _state */ , unsigned int /* _drawmode */ )
void ClippingNode::enter(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode */ )
{
// one clipping plane
if (slice_width_ == 0.0)
......@@ -157,7 +157,7 @@ void ClippingNode::enter(GLState& /* _state */ , unsigned int /* _drawmode */ )
//----------------------------------------------------------------------------
void ClippingNode::leave(GLState& /* _state */ , unsigned int /* _drawmode */ )
void ClippingNode::leave(GLState& /* _state */ , DrawModes::DrawMode /* _drawmode */ )
{
glDisable(GL_CLIP_PLANE0);
if (slice_width_ > 0.0)
......
......@@ -96,10 +96,10 @@ public:
ACG_CLASSNAME(ClippingNode);
/// set texture
void enter(GLState& _state, unsigned int _drawmode);
void enter(GLState& _state, DrawModes::DrawMode _drawmode);
/// restores original texture (or no-texture)
void leave(GLState& _state, unsigned int _drawmode);
void leave(GLState& _state, DrawModes::DrawMode _drawmode);
/// set position and normal of plane
void set_plane(const Vec3f& _position, const Vec3f& _normal, float _eps=0.0);
......
......@@ -82,7 +82,7 @@ CoordFrameNode(BaseNode* _parent, const std::string& _name)
//-----------------------------------------------------------------------------
unsigned int
DrawModes::DrawMode
CoordFrameNode::availableDrawModes() const
{
return ( DrawModes::WIREFRAME |
......@@ -105,7 +105,7 @@ CoordFrameNode::boundingBox(Vec3d& _bbMin, Vec3d& _bbMax)
void
CoordFrameNode::draw(GLState& /* _state */ , unsigned int /* _drawMode */ )
CoordFrameNode::draw(GLState& /* _state */ , DrawModes::DrawMode /* _drawMode */ )
{
// draw bounding box
......
......@@ -93,11 +93,11 @@ public:
/// implement className()
ACG_CLASSNAME(CoordFrameNode);
/// return available draw modes
unsigned int availableDrawModes() const;
DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// drawing the primitive
void draw(GLState& _state, unsigned int _drawMode);
void draw(GLState& _state, DrawModes::DrawMode _drawMode);
/// update bounding box (compute in from BB of children)
......
......@@ -77,7 +77,7 @@ boundingBox(Vec3d& /*_bbMin*/, Vec3d& /*_bbMax*/)
//----------------------------------------------------------------------------
unsigned int
DrawModes::DrawMode
CoordsysNode::
availableDrawModes() const
{
......@@ -208,7 +208,7 @@ CoordsysNode::drawCoordsysPick( GLState& _state) {
void
CoordsysNode::
draw(GLState& _state , unsigned int /*_drawMode*/)
draw(GLState& _state , DrawModes::DrawMode /*_drawMode*/)
{
GLboolean colorMask[4];
glGetBooleanv (GL_COLOR_WRITEMASK, colorMask);
......
......@@ -104,13 +104,13 @@ public:
ACG_CLASSNAME(CoordsysNode);
/// return available draw modes
unsigned int availableDrawModes() const;
ACG::SceneGraph::DrawModes::DrawMode availableDrawModes() const;
/// update bounding box
void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
/// draw Coordsys
void draw(GLState& _state, unsigned int _drawMode);
void draw(GLState& _state, DrawModes::DrawMode _drawMode);
/// draw Coordsys for object picking
void pick(GLState& _state, PickTarget _target);
......
......@@ -69,100 +69,189 @@ namespace DrawModes {
/** Definition of a draw mode */
class DrawMode {
public:
class DrawModeInternal {
public:
/** Default constructor. */
DrawMode() {}
DrawModeInternal() {}
/** Initializing constructor. */
DrawMode( const std::string & _name, const int & _id )
: name_( _name ), id_( _id ) {}
DrawModeInternal( const std::string & _name, const DrawMode & _id )
: name_( _name ), id_( _id ) {}
std::string name_;
unsigned int id_;
DrawMode id_;
};
typedef std::vector< DrawMode > VecDrawModes;
typedef std::vector< DrawModeInternal > VecDrawModes;
/** Vector of all currently defined DrawModes.
*/
static VecDrawModes currentDrawModes_;
/** First free DrawMode ID for custom modes. */
static unsigned int firstFreeID_;
static DrawMode firstFreeID_;
DrawMode::DrawMode(unsigned int _index) {
modeFlags_.reset();
if ( _index >= modeFlags_.size() ) {
std::cerr << "Illegal drawMode specification from unsigned int. This should not be a bitset!!!" << std::endl;
} else {
modeFlags_.set(_index);
}
}
//----------------------------------------------------------------------------
DrawMode::DrawMode() {
}
DrawMode::DrawMode( ModeFlagSet _flags ) {
modeFlags_ = _flags;
}
DrawMode::operator bool() {
return( modeFlags_ != NONE.modeFlags_ );
}
std::string description(unsigned int _drawMode)
{
/* HACK TODO!! Required when using plugins under windows. ACG as static lib
links a static drawmodes for each plugins->only one initialized.
Solution : Build ACG as dll under windows */
// if ( currentDrawModes_.empty() )
//initializeDefaultDrawModes();
bool DrawMode::operator==(const DrawMode& _mode) const {
// If we are asked for Point, also return the Modes for Points shaded and colors
// if ( (_mode.modeFlags_ & POINTS.modeFlags_).any() )
// return ( (modeFlags_ & ( POINTS_COLORED | POINTS_SHADED ).modeFlags_).any() );
///\todo Implement more combined returns for faces and Shading
return ((modeFlags_ & _mode.modeFlags_).any());
}
bool DrawMode::operator!=( const DrawMode& _mode2 ) const {
return (modeFlags_ != _mode2.modeFlags_);
}
DrawMode& DrawMode::operator++() {
if ( modeFlags_.count() != 1 ) {
std::cerr << "Operator ++ for drawMode which is not atomic!!" << std::endl;
}
modeFlags_ << 1;
return (*this);
}
DrawMode DrawMode::operator&(const DrawMode& _mode) {
// If we are asked for Point, also return the Modes for Points shaded and colors
// if ( (_mode.modeFlags_ & POINTS.modeFlags_).any() )
// return ( modeFlags_ & ( POINTS_COLORED | POINTS_SHADED ).modeFlags_ );
///\todo Implement more combined returns for faces and Shading
return (modeFlags_ & _mode.modeFlags_);
}
DrawMode& DrawMode::operator|=( const DrawMode& _mode2 ) {
modeFlags_ |= _mode2.modeFlags_;
return (*this);
}
DrawMode& DrawMode::operator&=( const DrawMode& _mode2 ) {
modeFlags_ &= _mode2.modeFlags_;
return (*this);
}
DrawMode DrawMode::operator|( const DrawMode& _mode2 ) const {
return( modeFlags_ | _mode2.modeFlags_ );
}
DrawMode DrawMode::operator^( const DrawMode& _mode2 ) const {
return( modeFlags_ ^ _mode2.modeFlags_ );
}
DrawMode DrawMode::operator~( ) const {
return( ~modeFlags_ );
}
unsigned int DrawMode::getIndex() {
if ( modeFlags_.count() == 1 ) {
for ( size_t i = 0 ; i < modeFlags_.size() ; ++i )
if ( modeFlags_[i] )
return i;
}
return 0;
}
std::string DrawMode::description()
{
std::string text("");
VecDrawModes::iterator modeIter, modeEnd( currentDrawModes_.end() );
for( modeIter = currentDrawModes_.begin();
modeIter != modeEnd;
++modeIter )
for( modeIter = currentDrawModes_.begin(); modeIter != modeEnd; ++modeIter )
{
if( _drawMode & modeIter->id_ )
if( (*this) & modeIter->id_ )
{
if (!text.empty()) text += "+";
text += modeIter->name_;
}
}
return text;
}
//----------------------------------------------------------------------------
std::vector< unsigned int >
getDrawModeIDs( unsigned int _drawModes )
std::vector< DrawMode >
DrawMode::getAtomicDrawModes( )
{
/* HACK TODO!! Required when using plugins under windows. ACG as static lib
links a static drawmodes for each plugins->only one initialized.
Solution : Build ACG as dll under windows */
// if ( currentDrawModes_.empty() )
// initializeDefaultDrawModes();
std::vector< unsigned int > draw_mode_ids;
<