diff --git a/include/osgManipulator/Command b/include/osgManipulator/Command index ea7d28cc5..143b76ccf 100644 --- a/include/osgManipulator/Command +++ b/include/osgManipulator/Command @@ -51,23 +51,8 @@ class OSGMANIPULATOR_EXPORT MotionCommand : public osg::Referenced MotionCommand(); - /** Execute the command. */ - virtual bool execute() = 0; - - /** Undo the command. The inverse of this command is executed. */ - virtual bool unexecute() = 0; - - /** Apply a constraint to the command. */ - virtual void applyConstraint(const Constraint*) = 0; - - /** - * Add Selection (receiver) to the command. The command will be - * executed on all the selections. - */ - void addSelection(Selection*); - - /** Remove Selection (receiver) from the command. */ - void removeSelection(Selection*); + /** create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. */ + virtual MotionCommand* createCommandInverse() = 0; /** * Gets the matrix for transforming the Selection. This matrix is in the @@ -103,18 +88,12 @@ class OSGMANIPULATOR_EXPORT MotionCommand : public osg::Referenced protected: virtual ~MotionCommand(); - typedef std::vector< osg::ref_ptr > SelectionList; - - SelectionList& getSelectionList() { return _selectionList; } - const SelectionList& getSelectionList() const { return _selectionList; } private: osg::Matrix _localToWorld; osg::Matrix _worldToLocal; Stage _stage; - - SelectionList _selectionList; }; @@ -129,9 +108,7 @@ class OSGMANIPULATOR_EXPORT TranslateInLineCommand : public MotionCommand TranslateInLineCommand(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e); - virtual bool execute(); - virtual bool unexecute(); - virtual void applyConstraint(const Constraint*); + virtual MotionCommand* createCommandInverse(); inline void setLine(const osg::LineSegment::vec_type& s, const osg::LineSegment::vec_type& e) { _line->start() = s; _line->end() = e; } inline const osg::LineSegment::vec_type& getLineStart() const { return _line->start(); } @@ -165,9 +142,7 @@ class OSGMANIPULATOR_EXPORT TranslateInPlaneCommand : public MotionCommand TranslateInPlaneCommand(const osg::Plane& plane); - virtual bool execute(); - virtual bool unexecute(); - virtual void applyConstraint(const Constraint*); + virtual MotionCommand* createCommandInverse(); inline void setPlane(const osg::Plane& plane) { _plane = plane; } inline const osg::Plane& getPlane() const { return _plane; } @@ -203,9 +178,7 @@ class OSGMANIPULATOR_EXPORT Scale1DCommand : public MotionCommand Scale1DCommand(); - virtual bool execute(); - virtual bool unexecute(); - virtual void applyConstraint(const Constraint*); + virtual MotionCommand* createCommandInverse(); inline void setScale(double s) { _scale = s; } inline double getScale() const { return _scale; } @@ -247,9 +220,7 @@ class OSGMANIPULATOR_EXPORT Scale2DCommand : public MotionCommand Scale2DCommand(); - virtual bool execute(); - virtual bool unexecute(); - virtual void applyConstraint(const Constraint*); + virtual MotionCommand* createCommandInverse(); inline void setScale(const osg::Vec2d& s) { _scale = s; } inline const osg::Vec2d& getScale() const { return _scale; } @@ -291,9 +262,7 @@ class OSGMANIPULATOR_EXPORT ScaleUniformCommand : public MotionCommand ScaleUniformCommand(); - virtual bool execute(); - virtual bool unexecute(); - virtual void applyConstraint(const Constraint*); + virtual MotionCommand* createCommandInverse(); inline void setScale(double s) { _scale = s; } inline double getScale() const { return _scale; } @@ -326,9 +295,7 @@ class OSGMANIPULATOR_EXPORT Rotate3DCommand : public MotionCommand Rotate3DCommand(); - virtual bool execute(); - virtual bool unexecute(); - virtual void applyConstraint(const Constraint*); + virtual MotionCommand* createCommandInverse(); inline void setRotation(const osg::Quat& rotation) { _rotation = rotation; } inline const osg::Quat& getRotation() const { return _rotation; } diff --git a/include/osgManipulator/CommandManager b/include/osgManipulator/CommandManager index 4fcd4359d..e194c1357 100644 --- a/include/osgManipulator/CommandManager +++ b/include/osgManipulator/CommandManager @@ -22,7 +22,7 @@ namespace osgManipulator { /** - * Command manager receives commands from draggers and dispatches them to selections. + * Deprecated. CommandManager class is now no longer required as Dragger now matains all references to Constraints and Selections. */ class OSGMANIPULATOR_EXPORT CommandManager : public osg::Referenced { @@ -41,12 +41,6 @@ class OSGMANIPULATOR_EXPORT CommandManager : public osg::Referenced /** Disconnect the selections from a dragger. */ virtual bool disconnect(Dragger& dragger); - /** Dispatches a command. Usually called from a dragger. */ - virtual void dispatch(MotionCommand& command); - - /** Add all selections connected to the dragger to the command. */ - void addSelectionsToCommand(MotionCommand& command, Dragger& dragger); - typedef std::list< osg::ref_ptr > Selections; /** Returns the selections connected to the dragger */ diff --git a/src/osgManipulator/Command.cpp b/src/osgManipulator/Command.cpp index 9daff1083..92bce4cfd 100644 --- a/src/osgManipulator/Command.cpp +++ b/src/osgManipulator/Command.cpp @@ -33,17 +33,6 @@ MotionCommand::~MotionCommand() { } -void MotionCommand::addSelection(Selection* selection) -{ - _selectionList.push_back(selection); -} - -void MotionCommand::removeSelection(Selection* selection) -{ - _selectionList.erase(std::remove(_selectionList.begin(), _selectionList.end(), selection), - _selectionList.end()); -} - /////////////////////////////////////////////////////////////////////////////// // @@ -64,35 +53,12 @@ TranslateInLineCommand::~TranslateInLineCommand() { } -bool TranslateInLineCommand::execute() -{ - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*this); - } - return true; -} - -bool TranslateInLineCommand::unexecute() +MotionCommand* TranslateInLineCommand::createCommandInverse() { osg::ref_ptr inverse = new TranslateInLineCommand(); *inverse = *this; inverse->setTranslation(-_translation); - - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*inverse); - } - return true; -} - -void TranslateInLineCommand::applyConstraint(const Constraint* constraint) -{ - if (constraint) constraint->constrain(*this); + return inverse.release(); } /////////////////////////////////////////////////////////////////////////////// @@ -111,36 +77,12 @@ TranslateInPlaneCommand::TranslateInPlaneCommand(const osg::Plane& plane) : _pla TranslateInPlaneCommand::~TranslateInPlaneCommand() { } - -bool TranslateInPlaneCommand::execute() -{ - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*this); - } - return true; -} - -bool TranslateInPlaneCommand::unexecute() +MotionCommand* TranslateInPlaneCommand::createCommandInverse() { osg::ref_ptr inverse = new TranslateInPlaneCommand(); *inverse = *this; inverse->setTranslation(-_translation); - - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*inverse); - } - return true; -} - -void TranslateInPlaneCommand::applyConstraint(const Constraint* constraint) -{ - if (constraint) constraint->constrain(*this); + return inverse.release(); } /////////////////////////////////////////////////////////////////////////////// @@ -156,35 +98,12 @@ Scale1DCommand::~Scale1DCommand() { } -bool Scale1DCommand::execute() -{ - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*this); - } - return true; -} - -bool Scale1DCommand::unexecute() +MotionCommand* Scale1DCommand::createCommandInverse() { osg::ref_ptr inverse = new Scale1DCommand(); *inverse = *this; if (_scale) inverse->setScale(1.0/_scale); - - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*inverse); - } - return true; -} - -void Scale1DCommand::applyConstraint(const Constraint* constraint) -{ - if (constraint) constraint->constrain(*this); + return inverse.release(); } /////////////////////////////////////////////////////////////////////////////// @@ -200,36 +119,13 @@ Scale2DCommand::~Scale2DCommand() { } -bool Scale2DCommand::execute() -{ - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*this); - } - return true; -} - -bool Scale2DCommand::unexecute() +MotionCommand* Scale2DCommand::createCommandInverse() { osg::ref_ptr inverse = new Scale2DCommand(); *inverse = *this; if (_scale[0] && _scale[1]) inverse->setScale(osg::Vec2(1.0/_scale[0],1.0/_scale[1])); - - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*inverse); - } - return true; -} - -void Scale2DCommand::applyConstraint(const Constraint* constraint) -{ - if (constraint) constraint->constrain(*this); + return inverse.release(); } /////////////////////////////////////////////////////////////////////////////// @@ -245,35 +141,13 @@ ScaleUniformCommand::~ScaleUniformCommand() { } -bool ScaleUniformCommand::execute() -{ - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*this); - } - return true; -} - -bool ScaleUniformCommand::unexecute() +MotionCommand* ScaleUniformCommand::createCommandInverse() { osg::ref_ptr inverse = new ScaleUniformCommand(); *inverse = *this; if (_scale) inverse->setScale(1.0/_scale); - - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*inverse); - } - return true; -} -void ScaleUniformCommand::applyConstraint(const Constraint* constraint) -{ - if (constraint) constraint->constrain(*this); + return inverse.release(); } /////////////////////////////////////////////////////////////////////////////// @@ -289,33 +163,10 @@ Rotate3DCommand::~Rotate3DCommand() { } -bool Rotate3DCommand::execute() -{ - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*this); - } - return true; -} - -bool Rotate3DCommand::unexecute() +MotionCommand* Rotate3DCommand::createCommandInverse() { osg::ref_ptr inverse = new Rotate3DCommand(); *inverse = *this; inverse->setRotation(_rotation.inverse()); - - for (SelectionList::iterator iter = getSelectionList().begin(); - iter != getSelectionList().end(); - ++iter) - { - (*iter)->receive(*inverse); - } - return true; -} - -void Rotate3DCommand::applyConstraint(const Constraint* constraint) -{ - if (constraint) constraint->constrain(*this); + return inverse.release(); } diff --git a/src/osgManipulator/CommandManager.cpp b/src/osgManipulator/CommandManager.cpp index 69833557c..a4a419104 100644 --- a/src/osgManipulator/CommandManager.cpp +++ b/src/osgManipulator/CommandManager.cpp @@ -47,32 +47,6 @@ bool CommandManager::disconnect(Dragger& dragger) return true; } -void CommandManager::dispatch(MotionCommand& command) -{ - command.execute(); -} - -void CommandManager::addSelectionsToCommand(MotionCommand& command, Dragger& dragger) -{ - for(Dragger::Constraints::iterator itr = dragger.getConstraints().begin(); - itr != dragger.getConstraints().end(); - ++itr) - { - command.applyConstraint(itr->get()); - } - - // Add the dragger to the selection list first. - command.addSelection(&dragger); - - for(Dragger::Selections::iterator itr = dragger.getSelections().begin(); - itr != dragger.getSelections().end(); - ++itr) - { - command.addSelection(*itr); - } -} - - CommandManager::Selections CommandManager::getConnectedSelections(Dragger& dragger) { Selections selections; diff --git a/src/osgManipulator/Dragger.cpp b/src/osgManipulator/Dragger.cpp index cf758874c..71c66ecf9 100644 --- a/src/osgManipulator/Dragger.cpp +++ b/src/osgManipulator/Dragger.cpp @@ -238,7 +238,7 @@ void Dragger::dispatch(MotionCommand& command) itr != _constraints.end(); ++itr) { - command.applyConstraint(itr->get()); + (*itr)->constrain(command); } // move self diff --git a/src/osgWrappers/osgManipulator/Command.cpp b/src/osgWrappers/osgManipulator/Command.cpp index 8cc336c89..c6569a39d 100644 --- a/src/osgWrappers/osgManipulator/Command.cpp +++ b/src/osgWrappers/osgManipulator/Command.cpp @@ -18,8 +18,6 @@ #include #include #include -#include -#include // Must undefine IN and OUT macros defined in Windows headers #ifdef IN @@ -43,30 +41,10 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgManipulator::MotionCommand) I_Constructor0(____MotionCommand, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::PURE_VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::PURE_VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::PURE_VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", - ""); - I_Method1(void, addSelection, IN, osgManipulator::Selection *, x, - Properties::NON_VIRTUAL, - __void__addSelection__Selection_P1, - "Add Selection (receiver) to the command. ", - "The command will be executed on all the selections. "); - I_Method1(void, removeSelection, IN, osgManipulator::Selection *, x, - Properties::NON_VIRTUAL, - __void__removeSelection__Selection_P1, - "Remove Selection (receiver) from the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method0(osg::Matrix, getMotionMatrix, Properties::PURE_VIRTUAL, @@ -98,8 +76,6 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgManipulator::MotionCommand) __Stage__getStage, "", ""); - - I_SimpleProperty(const osg::Matrix &, LocalToWorld, __C5_osg_Matrix_R1__getLocalToWorld, 0); @@ -120,20 +96,10 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Rotate3DCommand) I_Constructor0(____Rotate3DCommand, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method1(void, setRotation, IN, const osg::Quat &, rotation, Properties::NON_VIRTUAL, @@ -164,20 +130,10 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Scale1DCommand) I_Constructor0(____Scale1DCommand, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method1(void, setScale, IN, double, s, Properties::NON_VIRTUAL, @@ -247,20 +203,10 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Scale2DCommand) I_Constructor0(____Scale2DCommand, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method1(void, setScale, IN, const osg::Vec2d &, s, Properties::NON_VIRTUAL, @@ -330,20 +276,10 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::ScaleUniformCommand) I_Constructor0(____ScaleUniformCommand, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method1(void, setScale, IN, double, s, Properties::NON_VIRTUAL, @@ -391,20 +327,10 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::TranslateInLineCommand) ____TranslateInLineCommand__C5_osg_LineSegment_vec_type_R1__C5_osg_LineSegment_vec_type_R1, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method2(void, setLine, IN, const osg::LineSegment::vec_type &, s, IN, const osg::LineSegment::vec_type &, e, Properties::NON_VIRTUAL, @@ -461,20 +387,10 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::TranslateInPlaneCommand) ____TranslateInPlaneCommand__C5_osg_Plane_R1, "", ""); - I_Method0(bool, execute, + I_Method0(osgManipulator::MotionCommand *, createCommandInverse, Properties::VIRTUAL, - __bool__execute, - "Execute the command. ", - ""); - I_Method0(bool, unexecute, - Properties::VIRTUAL, - __bool__unexecute, - "Undo the command. ", - "The inverse of this command is executed. "); - I_Method1(void, applyConstraint, IN, const osgManipulator::Constraint *, x, - Properties::VIRTUAL, - __void__applyConstraint__C5_Constraint_P1, - "Apply a constraint to the command. ", + __MotionCommand_P1__createCommandInverse, + "create a MotionCommand that is the inverse of this command, and if applied will undo this commands changes. ", ""); I_Method1(void, setPlane, IN, const osg::Plane &, plane, Properties::NON_VIRTUAL, diff --git a/src/osgWrappers/osgManipulator/CommandManager.cpp b/src/osgWrappers/osgManipulator/CommandManager.cpp index ae811c9af..e0788a9e5 100644 --- a/src/osgWrappers/osgManipulator/CommandManager.cpp +++ b/src/osgWrappers/osgManipulator/CommandManager.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include #include @@ -47,16 +46,6 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::CommandManager) __bool__disconnect__Dragger_R1, "Disconnect the selections from a dragger. ", ""); - I_Method1(void, dispatch, IN, osgManipulator::MotionCommand &, command, - Properties::VIRTUAL, - __void__dispatch__MotionCommand_R1, - "Dispatches a command. ", - "Usually called from a dragger. "); - I_Method2(void, addSelectionsToCommand, IN, osgManipulator::MotionCommand &, command, IN, osgManipulator::Dragger &, dragger, - Properties::NON_VIRTUAL, - __void__addSelectionsToCommand__MotionCommand_R1__Dragger_R1, - "Add all selections connected to the dragger to the command. ", - ""); I_Method1(osgManipulator::CommandManager::Selections, getConnectedSelections, IN, osgManipulator::Dragger &, dragger, Properties::NON_VIRTUAL, __Selections__getConnectedSelections__Dragger_R1,