Refactored osgManipulator so that CommandManager is no longer required, instead Dragger directly manages Constaints and associate Selections.

This commit is contained in:
Robert Osfield
2009-06-30 11:39:39 +00:00
parent a73a403301
commit a2ae370c8e
16 changed files with 368 additions and 380 deletions

View File

@@ -56,11 +56,6 @@ class OSGMANIPULATOR_EXPORT CommandManager : public osg::Referenced
virtual ~CommandManager();
typedef std::multimap< osg::ref_ptr<Dragger>, osg::ref_ptr<Selection> > DraggerSelectionMap;
DraggerSelectionMap _draggerSelectionMap;
typedef std::multimap< osg::ref_ptr<Dragger>, osg::ref_ptr<Constraint> > DraggerConstraintMap;
DraggerConstraintMap _draggerConstraintMap;
};
}

View File

@@ -17,6 +17,7 @@
#include <osgManipulator/Export>
#include <osg/observer_ptr>
#include <osg/Node>
#include <osg/Matrix>
@@ -55,7 +56,7 @@ class OSGMANIPULATOR_EXPORT Constraint : public osg::Referenced
private:
osg::ref_ptr<osg::Node> _refNode;
osg::observer_ptr<osg::Node> _refNode;
mutable osg::Matrix _localToWorld;
mutable osg::Matrix _worldToLocal;
};

View File

@@ -16,6 +16,8 @@
#define OSGMANIPULATOR_DRAGGER 1
#include <osgManipulator/Selection>
#include <osgManipulator/Constraint>
#include <osgManipulator/Command>
#include <osg/BoundingSphere>
#include <osgUtil/SceneView>
@@ -26,7 +28,6 @@
namespace osgManipulator
{
class CommandManager;
class CompositeDragger;
class OSGMANIPULATOR_EXPORT PointerInfo
@@ -115,6 +116,7 @@ class OSGMANIPULATOR_EXPORT PointerInfo
{
projectWindowXYIntoObject(osg::Vec2d(pixel_x, pixel_y), _nearPoint, _farPoint);
}
protected:
bool projectWindowXYIntoObject(const osg::Vec2d& windowCoord, osg::Vec3d& nearPoint, osg::Vec3d& farPoint) const;
@@ -135,21 +137,15 @@ class OSGMANIPULATOR_EXPORT PointerInfo
/**
* Base class for draggers. Concrete draggers implement the pick event handler
* and generate motion commands (translate, rotate, ...) and sends these
* command to the CommandManager. The CommandManager dispatches the commands
* to all the Selections that are connected to the Dragger that generates the
* command to all the Selections that are connected to the Dragger that generates the
* commands.
*/
class OSGMANIPULATOR_EXPORT Dragger : public Selection
class OSGMANIPULATOR_EXPORT Dragger : public Selection, public osg::Observer
{
public:
META_OSGMANIPULATOR_Object(osgManipulator,Dragger)
/** Set/Get the CommandManager. Draggers use CommandManager to dispatch commands. */
virtual void setCommandManager(CommandManager* cm) { _commandManager = cm; }
CommandManager* getCommandManager() { return _commandManager; }
const CommandManager* getCommandManager() const { return _commandManager; }
/**
* Set/Get parent dragger. For simple draggers parent points to itself.
* For composite draggers parent points to the parent dragger that uses
@@ -178,19 +174,40 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection
virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);
virtual bool handle(const PointerInfo&, const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) { return false; }
typedef std::vector< osg::ref_ptr<Constraint> > Constraints;
void addConstraint(Constraint* constraint);
void removeConstraint(Constraint* constraint);
Constraints& getConstraints() { return _constraints; }
const Constraints& getConstraints() const { return _constraints; }
typedef std::vector< Selection* > Selections;
void addSelection(Selection* selection);
void removeSelection(Selection* selection);
Selections& getSelections() { return _selections; }
const Selections& getSelections() const { return _selections; }
protected:
Dragger();
virtual ~Dragger();
void dispatch(MotionCommand& command);
virtual void objectDeleted(void* object);
bool _handleEvents;
bool _draggerActive;
osgManipulator::PointerInfo _pointer;
CommandManager* _commandManager;
Dragger* _parentDragger;
Constraints _constraints;
Selections _selections;
};
@@ -209,8 +226,6 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger
virtual const CompositeDragger* getComposite() const { return this; }
virtual CompositeDragger* getComposite() { return this; }
virtual void setCommandManager(CommandManager* cm);
virtual void setParentDragger(Dragger* parent);
virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa);

View File

@@ -38,6 +38,21 @@ virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<co
virtual const char* libraryName() const { return #library; }\
virtual const char* className() const { return #name; }
class CommandProcessor
{
public:
virtual bool receive(const MotionCommand&) = 0;
virtual bool receive(const TranslateInLineCommand& command) = 0;
virtual bool receive(const TranslateInPlaneCommand& command) = 0;
virtual bool receive(const Scale1DCommand& command) = 0;
virtual bool receive(const Scale2DCommand& command) = 0;
virtual bool receive(const ScaleUniformCommand& command) = 0;
virtual bool receive(const Rotate3DCommand& command) = 0;
};
/**
* Selection listens to motion commands generated by draggers.
*/