Simplified Command and CommandManager
This commit is contained in:
@@ -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<TranslateInLineCommand> 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<TranslateInPlaneCommand> 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<Scale1DCommand> 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<Scale2DCommand> 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<ScaleUniformCommand> 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<Rotate3DCommand> 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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -238,7 +238,7 @@ void Dragger::dispatch(MotionCommand& command)
|
||||
itr != _constraints.end();
|
||||
++itr)
|
||||
{
|
||||
command.applyConstraint(itr->get());
|
||||
(*itr)->constrain(command);
|
||||
}
|
||||
|
||||
// move self
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
#include <osg/Vec3>
|
||||
#include <osg/Vec3d>
|
||||
#include <osgManipulator/Command>
|
||||
#include <osgManipulator/Constraint>
|
||||
#include <osgManipulator/Selection>
|
||||
|
||||
// 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,
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <osgIntrospection/StaticMethodInfo>
|
||||
#include <osgIntrospection/Attributes>
|
||||
|
||||
#include <osgManipulator/Command>
|
||||
#include <osgManipulator/CommandManager>
|
||||
#include <osgManipulator/Constraint>
|
||||
#include <osgManipulator/Dragger>
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user