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

@ -38,6 +38,8 @@
#include <iostream>
// #define USE_COMMAND_MANAGER
osgManipulator::Dragger* createDragger(const std::string& name)
{
osgManipulator::Dragger* dragger = 0;
@ -90,43 +92,6 @@ osgManipulator::Dragger* createDragger(const std::string& name)
}
osg::Node* createHUD()
{
osg::Geode* geode = new osg::Geode();
std::string timesFont("fonts/arial.ttf");
osg::StateSet* stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
osgText::Text* text = new osgText::Text;
geode->addDrawable( text );
osg::Vec3 position(50.0f,50.0f,0.0f);
text->setPosition(position);
text->setText("Use the Tab key to switch between the trackball and pick modes.");
text->setFont(timesFont);
osg::Camera* camera = new osg::Camera;
// set the projection matrix
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
// set the view matrix
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
// only clear the depth buffer
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
// draw subgraph after main camera view.
camera->setRenderOrder(osg::Camera::POST_RENDER);
camera->addChild(geode);
return camera;
}
osg::Node* addDraggerToScene(osg::Node* scene, osgManipulator::CommandManager* cmdMgr, const std::string& name)
{
scene->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
@ -141,13 +106,16 @@ osg::Node* addDraggerToScene(osg::Node* scene, osgManipulator::CommandManager* c
osg::Group* root = new osg::Group;
root->addChild(dragger);
root->addChild(selection);
root->addChild(createHUD());
float scale = scene->getBound().radius() * 1.6;
dragger->setMatrix(osg::Matrix::scale(scale, scale, scale) *
osg::Matrix::translate(scene->getBound().center()));
cmdMgr->connect(*dragger, *selection);
#ifdef USE_COMMAND_MANAGER
cmdMgr->connect(*dragger, *selection);
#else
dragger->addSelection(selection);
#endif
return root;
}
@ -247,104 +215,7 @@ osg::Node* createDemoScene(osgManipulator::CommandManager* cmdMgr) {
return root;
}
class PickModeHandler : public osgGA::GUIEventHandler
{
public:
enum Modes
{
VIEW = 0,
PICK
};
PickModeHandler():
_mode(VIEW),
_activeDragger(0)
{
}
bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa,
osg::Object*, osg::NodeVisitor*)
{
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_Tab &&
ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN &&
_activeDragger == 0)
{
_mode = ! _mode;
}
if (VIEW == _mode) return false;
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::PUSH:
{
osgUtil::LineSegmentIntersector::Intersections intersections;
_pointer.reset();
if (view->computeIntersections(ea.getX(),ea.getY(),intersections))
{
_pointer.setCamera(view->getCamera());
_pointer.setMousePosition(ea.getX(), ea.getY());
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
_pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
}
for (osg::NodePath::iterator itr = _pointer._hitList.front().first.begin();
itr != _pointer._hitList.front().first.end();
++itr)
{
osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
if (dragger)
{
dragger->handle(_pointer, ea, aa);
_activeDragger = dragger;
break;
}
}
}
}
case osgGA::GUIEventAdapter::DRAG:
case osgGA::GUIEventAdapter::RELEASE:
{
if (_activeDragger)
{
_pointer._hitIter = _pointer._hitList.begin();
_pointer.setCamera(view->getCamera());
_pointer.setMousePosition(ea.getX(), ea.getY());
_activeDragger->handle(_pointer, ea, aa);
}
break;
}
default:
break;
}
if (ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
{
_activeDragger = 0;
_pointer.reset();
}
return true;
}
private:
unsigned int _mode;
osgManipulator::Dragger* _activeDragger;
osgManipulator::PointerInfo _pointer;
};
//
int main( int argc, char **argv )
{
@ -397,7 +268,12 @@ int main( int argc, char **argv )
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
// create a command manager
osg::ref_ptr<osgManipulator::CommandManager> cmdMgr = new osgManipulator::CommandManager;
osg::ref_ptr<osgManipulator::CommandManager> cmdMgr;
#ifdef USE_COMMAND_MANAGER
cmdMgr = new osgManipulator::CommandManager;
#endif
// if no model has been successfully loaded report failure.
bool tragger2Scene(true);
@ -434,7 +310,7 @@ int main( int argc, char **argv )
} else {
viewer.setSceneData(loadedModel.get());
}
// viewer.addEventHandler(new PickModeHandler());
return viewer.run();
}

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.
*/

View File

@ -27,54 +27,23 @@ CommandManager::~CommandManager()
bool CommandManager::connect(Dragger& dragger, Selection& selection)
{
dragger.setCommandManager(this);
// Check to see if the selection is already associated with the dragger.
if (_draggerSelectionMap.count(&dragger) > 0)
{
std::pair<DraggerSelectionMap::iterator,DraggerSelectionMap::iterator> s;
s = _draggerSelectionMap.equal_range(&dragger);
for (DraggerSelectionMap::iterator iter = s.first; iter != s.second; ++iter)
{
if (iter->second == &selection)
return false;
}
}
// Associate selection with dragger
_draggerSelectionMap.insert(DraggerSelectionMap::value_type(&dragger,&selection));
dragger.addSelection(&selection);
return true;
}
bool CommandManager::connect(Dragger& dragger, Constraint& constraint)
{
dragger.setCommandManager(this);
// Check to see if the selection is already associated with the dragger.
if (_draggerConstraintMap.count(&dragger) > 0)
{
std::pair<DraggerConstraintMap::iterator,DraggerConstraintMap::iterator> s;
s = _draggerConstraintMap.equal_range(&dragger);
for (DraggerConstraintMap::iterator iter = s.first; iter != s.second; ++iter)
{
if (iter->second == &constraint)
return false;
}
}
// Associate selection with dragger
_draggerConstraintMap.insert(DraggerConstraintMap::value_type(&dragger,&constraint));
dragger.addConstraint(&constraint);
return true;
}
bool CommandManager::disconnect(Dragger& dragger)
{
_draggerSelectionMap.erase(&dragger);
_draggerConstraintMap.erase(&dragger);
dragger.getConstraints().clear();
dragger.getSelections().clear();
return true;
}
@ -85,41 +54,21 @@ void CommandManager::dispatch(MotionCommand& command)
void CommandManager::addSelectionsToCommand(MotionCommand& command, Dragger& dragger)
{
// Apply constraints to the command.
if (_draggerConstraintMap.count(&dragger) > 0)
for(Dragger::Constraints::iterator itr = dragger.getConstraints().begin();
itr != dragger.getConstraints().end();
++itr)
{
// Get all the selections assoicated with this dragger.
std::pair<DraggerConstraintMap::iterator,DraggerConstraintMap::iterator> s;
s = _draggerConstraintMap.equal_range(&dragger);
for (DraggerConstraintMap::iterator iter = s.first; iter != s.second; ++iter)
{
// Add the selection to the command.
if (iter->second.valid())
{
command.applyConstraint(iter->second.get());
}
}
command.applyConstraint(itr->get());
}
// Add the dragger to the selection list first.
command.addSelection(&dragger);
// Add the remaining selections.
if (_draggerSelectionMap.count(&dragger) > 0)
for(Dragger::Selections::iterator itr = dragger.getSelections().begin();
itr != dragger.getSelections().end();
++itr)
{
// Get all the selections assoicated with this dragger.
std::pair<DraggerSelectionMap::iterator,DraggerSelectionMap::iterator> s;
s = _draggerSelectionMap.equal_range(&dragger);
for (DraggerSelectionMap::iterator iter = s.first; iter != s.second; ++iter)
{
// Add the selection to the command.
if (iter->second.valid())
{
command.addSelection(iter->second.get());
}
}
command.addSelection(*itr);
}
}
@ -128,18 +77,12 @@ CommandManager::Selections CommandManager::getConnectedSelections(Dragger& dragg
{
Selections selections;
//Test if the dragger is in the list
if (_draggerSelectionMap.count(&dragger) > 0)
for(Dragger::Selections::iterator itr = dragger.getSelections().begin();
itr != dragger.getSelections().end();
++itr)
{
//Get the iterator range on key 'dragger'
std::pair<DraggerSelectionMap::iterator,DraggerSelectionMap::iterator> draggerRange = _draggerSelectionMap.equal_range(&dragger);
for (DraggerSelectionMap::iterator selectionsIterator = draggerRange.first;
selectionsIterator != draggerRange.second;
++selectionsIterator)
{
//Push in the list all selections connected with the dragger
selections.push_back((*selectionsIterator).second);
}
selections.push_back(*itr);
}
return selections;
}

View File

@ -41,6 +41,12 @@ osg::Vec3d snap_point_to_grid(const osg::Vec3d& point, const osg::Vec3d& origin,
void Constraint::computeLocalToWorldAndWorldToLocal() const
{
if (!_refNode)
{
osg::notify(osg::INFO)<<"osgManipulator::Constraint::computeLocalToWorldAndWorldToLocal() error, _refNode is null"<<std::endl;
return;
}
osg::NodePath pathToRoot;
computeNodePathToRoot(const_cast<osg::Node&>(getReferenceNode()),pathToRoot);
_localToWorld = osg::computeLocalToWorld(pathToRoot);

View File

@ -13,12 +13,17 @@
//osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
#include <osgManipulator/Dragger>
#include <osgManipulator/Command>
#include <osg/Material>
#include <osgGA/EventVisitor>
#include <osgViewer/View>
using namespace osgManipulator;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// PointerInfo
//
PointerInfo::PointerInfo():
_nearPoint(osg::Vec3d()),
_farPoint(osg::Vec3d()),
@ -41,10 +46,14 @@ bool PointerInfo::projectWindowXYIntoObject(const osg::Vec2d& windowCoord, osg::
return true;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Dragger
//
Dragger::Dragger() :
_handleEvents(false),
_draggerActive(false),
_commandManager(0)
_draggerActive(false)
{
_parentDragger = this;
getOrCreateStateSet()->setDataVariance(osg::Object::DYNAMIC);
@ -65,6 +74,69 @@ void Dragger::setHandleEvents(bool flag)
else if (getNumChildrenRequiringEventTraversal()>=1) setNumChildrenRequiringEventTraversal(getNumChildrenRequiringEventTraversal()-1);
}
void Dragger::addConstraint(Constraint* constraint)
{
// check to make sure constaint hasn't already been attached.
for(Constraints::iterator itr = _constraints.begin();
itr != _constraints.end();
++itr)
{
if (*itr = constraint) return;
}
_constraints.push_back(constraint);
}
void Dragger::removeConstraint(Constraint* constraint)
{
for(Constraints::iterator itr = _constraints.begin();
itr != _constraints.end();
++itr)
{
if (*itr = constraint)
{
_constraints.erase(itr);
return;
}
}
}
void Dragger::objectDeleted(void* object)
{
removeSelection(reinterpret_cast<Selection*>(object));
}
void Dragger::addSelection(Selection* selection)
{
// check to make sure constaint hasn't already been attached.
for(Selections::iterator itr = _selections.begin();
itr != _selections.end();
++itr)
{
if (*itr == selection) return;
}
selection->addObserver(this);
_selections.push_back(selection);
}
void Dragger::removeSelection(Selection* selection)
{
for(Selections::iterator itr = _selections.begin();
itr != _selections.end();
++itr)
{
if (*itr == selection)
{
selection->removeObserver(this);
_selections.erase(itr);
return;
}
}
}
void Dragger::traverse(osg::NodeVisitor& nv)
{
if (_handleEvents && nv.getVisitorType()==osg::NodeVisitor::EVENT_VISITOR)
@ -159,6 +231,34 @@ bool Dragger::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&
return handled;
}
void Dragger::dispatch(MotionCommand& command)
{
// apply any constraints
for(Constraints::iterator itr = _constraints.begin();
itr != _constraints.end();
++itr)
{
command.applyConstraint(itr->get());
}
// move self
getParentDragger()->receive(command);
// then run through any selections
for(Selections::iterator itr = getParentDragger()->getSelections().begin();
itr != getParentDragger()->getSelections().end();
++itr)
{
(*itr)->receive(command);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// CompositeDragger
//
bool CompositeDragger::handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
// Check if the dragger node is in the nodepath.
@ -172,7 +272,6 @@ bool CompositeDragger::handle(const PointerInfo& pi, const osgGA::GUIEventAdapte
}
return false;
}
bool CompositeDragger::containsDragger( const Dragger* dragger ) const
{
for (DraggerList::const_iterator itr = _draggerList.begin(); itr != _draggerList.end(); ++itr)
@ -213,14 +312,6 @@ bool CompositeDragger::removeDragger(Dragger *dragger)
else return false;
}
void CompositeDragger::setCommandManager(CommandManager* cm)
{
for (DraggerList::iterator itr = _draggerList.begin(); itr != _draggerList.end(); ++itr)
{
(*itr)->setCommandManager(cm);
}
Dragger::setCommandManager(cm);
}
void CompositeDragger::setParentDragger(Dragger* dragger)
{

View File

@ -14,7 +14,6 @@
#include <osgManipulator/RotateCylinderDragger>
#include <osgManipulator/Command>
#include <osgManipulator/CommandManager>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
@ -67,11 +66,7 @@ bool RotateCylinderDragger::handle(const PointerInfo& pointer, const osgGA::GUIE
cmd->setLocalToWorldAndWorldToLocal(_startLocalToWorld,_startWorldToLocal);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Set color to pick color.
setMaterialColor(_pickColor,*this);
@ -107,11 +102,7 @@ bool RotateCylinderDragger::handle(const PointerInfo& pointer, const osgGA::GUIE
cmd->setRotation(rotation);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
_prevWorldProjPt = projectedPoint * _projector->getLocalToWorld();
_prevRotation = rotation;
@ -130,11 +121,7 @@ bool RotateCylinderDragger::handle(const PointerInfo& pointer, const osgGA::GUIE
cmd->setLocalToWorldAndWorldToLocal(_startLocalToWorld,_startWorldToLocal);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Reset color.
setMaterialColor(_color,*this);

View File

@ -14,7 +14,6 @@
#include <osgManipulator/RotateSphereDragger>
#include <osgManipulator/Command>
#include <osgManipulator/CommandManager>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
@ -68,11 +67,7 @@ bool RotateSphereDragger::handle(const PointerInfo& pointer, const osgGA::GUIEve
cmd->setLocalToWorldAndWorldToLocal(_startLocalToWorld,_startWorldToLocal);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Set color to pick color.
setMaterialColor(_pickColor,*this);
@ -109,11 +104,7 @@ bool RotateSphereDragger::handle(const PointerInfo& pointer, const osgGA::GUIEve
cmd->setRotation(rotation);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
_prevWorldProjPt = projectedPoint * _projector->getLocalToWorld();
_prevRotation = rotation;
@ -132,11 +123,7 @@ bool RotateSphereDragger::handle(const PointerInfo& pointer, const osgGA::GUIEve
cmd->setLocalToWorldAndWorldToLocal(_startLocalToWorld,_startWorldToLocal);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Reset color.
setMaterialColor(_color,*this);

View File

@ -14,7 +14,6 @@
#include <osgManipulator/Scale1DDragger>
#include <osgManipulator/Command>
#include <osgManipulator/CommandManager>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
@ -80,11 +79,7 @@ bool Scale1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAda
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Set color to pick color.
setMaterialColor(_pickColor,*this);
@ -123,11 +118,7 @@ bool Scale1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAda
cmd->setMinScale(getMinScale());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
aa.requestRedraw();
}
@ -143,11 +134,7 @@ bool Scale1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAda
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Reset color.
setMaterialColor(_color,*this);

View File

@ -14,7 +14,6 @@
#include <osgManipulator/Scale2DDragger>
#include <osgManipulator/Command>
#include <osgManipulator/CommandManager>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
@ -109,11 +108,7 @@ bool Scale2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAda
cmd->setReferencePoint(_referencePoint);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Set color to pick color.
setMaterialColor(_pickColor,*this);
@ -145,11 +140,7 @@ bool Scale2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAda
cmd->setMinScale(getMinScale());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
aa.requestRedraw();
}
@ -166,11 +157,7 @@ bool Scale2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEventAda
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Reset color.
setMaterialColor(_color,*this);

View File

@ -14,7 +14,6 @@
#include <osgManipulator/Translate1DDragger>
#include <osgManipulator/Command>
#include <osgManipulator/CommandManager>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
@ -69,11 +68,7 @@ bool Translate1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEven
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Set color to pick color.
setMaterialColor(_pickColor,*this);
@ -97,11 +92,7 @@ bool Translate1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEven
cmd->setTranslation(projectedPoint - _startProjectedPoint);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
aa.requestRedraw();
}
@ -121,11 +112,7 @@ bool Translate1DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEven
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Reset color.
setMaterialColor(_color,*this);

View File

@ -14,7 +14,6 @@
#include <osgManipulator/Translate2DDragger>
#include <osgManipulator/Command>
#include <osgManipulator/CommandManager>
#include <osg/ShapeDrawable>
#include <osg/Geometry>
@ -69,11 +68,7 @@ bool Translate2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEven
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Set color to pick color.
setMaterialColor(_pickColor,*this);
@ -99,11 +94,7 @@ bool Translate2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEven
cmd->setReferencePoint(_startProjectedPoint);
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
aa.requestRedraw();
}
@ -120,11 +111,7 @@ bool Translate2DDragger::handle(const PointerInfo& pointer, const osgGA::GUIEven
cmd->setLocalToWorldAndWorldToLocal(_projector->getLocalToWorld(),_projector->getWorldToLocal());
// Dispatch command.
if (_commandManager)
{
_commandManager->addSelectionsToCommand(*cmd, *getParentDragger());
_commandManager->dispatch(*cmd);
}
dispatch(*cmd);
// Reset color.
setMaterialColor(_color,*this);

View File

@ -17,8 +17,9 @@
#include <osg/Vec3d>
#include <osgGA/GUIActionAdapter>
#include <osgGA/GUIEventAdapter>
#include <osgManipulator/CommandManager>
#include <osgManipulator/Constraint>
#include <osgManipulator/Dragger>
#include <osgManipulator/Selection>
// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
@ -58,11 +59,6 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::CompositeDragger)
__CompositeDragger_P1__getComposite,
"Returns 0 if this Dragger is not a CompositeDragger. ",
"");
I_Method1(void, setCommandManager, IN, osgManipulator::CommandManager *, cm,
Properties::VIRTUAL,
__void__setCommandManager__CommandManager_P1,
"Set/Get the CommandManager. ",
"Draggers use CommandManager to dispatch commands. ");
I_Method1(void, setParentDragger, IN, osgManipulator::Dragger *, parent,
Properties::VIRTUAL,
__void__setParentDragger__Dragger_P1,
@ -111,9 +107,6 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::CompositeDragger)
I_ProtectedConstructor0(____CompositeDragger,
"",
"");
I_SimpleProperty(osgManipulator::CommandManager *, CommandManager,
0,
__void__setCommandManager__CommandManager_P1);
I_SimpleProperty(osgManipulator::CompositeDragger *, Composite,
__CompositeDragger_P1__getComposite,
0);
@ -129,9 +122,14 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::CompositeDragger)
__void__setParentDragger__Dragger_P1);
END_REFLECTOR
TYPE_NAME_ALIAS(std::vector< osg::ref_ptr< osgManipulator::Constraint > >, osgManipulator::Dragger::Constraints)
TYPE_NAME_ALIAS(std::vector< osgManipulator::Selection * >, osgManipulator::Dragger::Selections)
BEGIN_OBJECT_REFLECTOR(osgManipulator::Dragger)
I_DeclaringFile("osgManipulator/Dragger");
I_BaseType(osgManipulator::Selection);
I_BaseType(osg::Observer);
I_Method1(bool, isSameKindAs, IN, const osg::Object *, obj,
Properties::VIRTUAL,
__bool__isSameKindAs__C5_osg_Object_P1,
@ -147,21 +145,6 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Dragger)
__C5_char_P1__className,
"return the name of the node's class type. ",
"");
I_Method1(void, setCommandManager, IN, osgManipulator::CommandManager *, cm,
Properties::VIRTUAL,
__void__setCommandManager__CommandManager_P1,
"Set/Get the CommandManager. ",
"Draggers use CommandManager to dispatch commands. ");
I_Method0(osgManipulator::CommandManager *, getCommandManager,
Properties::NON_VIRTUAL,
__CommandManager_P1__getCommandManager,
"",
"");
I_Method0(const osgManipulator::CommandManager *, getCommandManager,
Properties::NON_VIRTUAL,
__C5_CommandManager_P1__getCommandManager,
"",
"");
I_Method1(void, setParentDragger, IN, osgManipulator::Dragger *, parent,
Properties::VIRTUAL,
__void__setParentDragger__Dragger_P1,
@ -222,15 +205,67 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Dragger)
__bool__handle__C5_PointerInfo_R1__C5_osgGA_GUIEventAdapter_R1__osgGA_GUIActionAdapter_R1,
"",
"");
I_Method1(void, addConstraint, IN, osgManipulator::Constraint *, constraint,
Properties::NON_VIRTUAL,
__void__addConstraint__Constraint_P1,
"",
"");
I_Method1(void, removeConstraint, IN, osgManipulator::Constraint *, constraint,
Properties::NON_VIRTUAL,
__void__removeConstraint__Constraint_P1,
"",
"");
I_Method0(osgManipulator::Dragger::Constraints &, getConstraints,
Properties::NON_VIRTUAL,
__Constraints_R1__getConstraints,
"",
"");
I_Method0(const osgManipulator::Dragger::Constraints &, getConstraints,
Properties::NON_VIRTUAL,
__C5_Constraints_R1__getConstraints,
"",
"");
I_Method1(void, addSelection, IN, osgManipulator::Selection *, selection,
Properties::NON_VIRTUAL,
__void__addSelection__Selection_P1,
"",
"");
I_Method1(void, removeSelection, IN, osgManipulator::Selection *, selection,
Properties::NON_VIRTUAL,
__void__removeSelection__Selection_P1,
"",
"");
I_Method0(osgManipulator::Dragger::Selections &, getSelections,
Properties::NON_VIRTUAL,
__Selections_R1__getSelections,
"",
"");
I_Method0(const osgManipulator::Dragger::Selections &, getSelections,
Properties::NON_VIRTUAL,
__C5_Selections_R1__getSelections,
"",
"");
I_ProtectedConstructor0(____Dragger,
"",
"");
I_SimpleProperty(osgManipulator::CommandManager *, CommandManager,
__CommandManager_P1__getCommandManager,
__void__setCommandManager__CommandManager_P1);
I_ProtectedMethod1(void, dispatch, IN, osgManipulator::MotionCommand &, command,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
__void__dispatch__MotionCommand_R1,
"",
"");
I_ProtectedMethod1(void, objectDeleted, IN, void *, object,
Properties::VIRTUAL,
Properties::NON_CONST,
__void__objectDeleted__void_P1,
"",
"");
I_SimpleProperty(osgManipulator::CompositeDragger *, Composite,
__CompositeDragger_P1__getComposite,
0);
I_SimpleProperty(osgManipulator::Dragger::Constraints &, Constraints,
__Constraints_R1__getConstraints,
0);
I_SimpleProperty(bool, DraggerActive,
__bool__getDraggerActive,
__void__setDraggerActive__bool);
@ -240,6 +275,9 @@ BEGIN_OBJECT_REFLECTOR(osgManipulator::Dragger)
I_SimpleProperty(osgManipulator::Dragger *, ParentDragger,
__Dragger_P1__getParentDragger,
__void__setParentDragger__Dragger_P1);
I_SimpleProperty(osgManipulator::Dragger::Selections &, Selections,
__Selections_R1__getSelections,
0);
END_REFLECTOR
TYPE_NAME_ALIAS(std::pair< osg::NodePath COMMA osg::Vec3d >, osgManipulator::PointerInfo::NodePathIntersectionPair)
@ -329,6 +367,46 @@ BEGIN_VALUE_REFLECTOR(osgManipulator::PointerInfo)
I_PublicMemberProperty(osgManipulator::PointerInfo::IntersectionList, _hitList);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgManipulator::Constraint >)
I_DeclaringFile("osg/ref_ptr");
I_Constructor0(____ref_ptr,
"",
"");
I_Constructor1(IN, osgManipulator::Constraint *, ptr,
Properties::NON_EXPLICIT,
____ref_ptr__T_P1,
"",
"");
I_Constructor1(IN, const osg::ref_ptr< osgManipulator::Constraint > &, rp,
Properties::NON_EXPLICIT,
____ref_ptr__C5_ref_ptr_R1,
"",
"");
I_Method0(osgManipulator::Constraint *, get,
Properties::NON_VIRTUAL,
__T_P1__get,
"",
"");
I_Method0(bool, valid,
Properties::NON_VIRTUAL,
__bool__valid,
"",
"");
I_Method0(osgManipulator::Constraint *, release,
Properties::NON_VIRTUAL,
__T_P1__release,
"",
"");
I_Method1(void, swap, IN, osg::ref_ptr< osgManipulator::Constraint > &, rp,
Properties::NON_VIRTUAL,
__void__swap__ref_ptr_R1,
"",
"");
I_SimpleProperty(osgManipulator::Constraint *, ,
__T_P1__get,
0);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgManipulator::Dragger >)
I_DeclaringFile("osg/ref_ptr");
I_Constructor0(____ref_ptr,
@ -373,5 +451,9 @@ STD_LIST_REFLECTOR(std::list< osgManipulator::PointerInfo::NodePathIntersectionP
STD_PAIR_REFLECTOR(std::pair< osg::NodePath COMMA osg::Vec3d >)
STD_VECTOR_REFLECTOR(std::vector< osg::ref_ptr< osgManipulator::Constraint > >)
STD_VECTOR_REFLECTOR(std::vector< osg::ref_ptr< osgManipulator::Dragger > >)
STD_VECTOR_REFLECTOR(std::vector< osgManipulator::Selection * >)

View File

@ -22,6 +22,48 @@
#undef OUT
#endif
BEGIN_ABSTRACT_OBJECT_REFLECTOR(osgManipulator::CommandProcessor)
I_DeclaringFile("osgManipulator/Selection");
I_Constructor0(____CommandProcessor,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::MotionCommand &, x,
Properties::PURE_VIRTUAL,
__bool__receive__C5_MotionCommand_R1,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::TranslateInLineCommand &, command,
Properties::PURE_VIRTUAL,
__bool__receive__C5_TranslateInLineCommand_R1,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::TranslateInPlaneCommand &, command,
Properties::PURE_VIRTUAL,
__bool__receive__C5_TranslateInPlaneCommand_R1,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::Scale1DCommand &, command,
Properties::PURE_VIRTUAL,
__bool__receive__C5_Scale1DCommand_R1,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::Scale2DCommand &, command,
Properties::PURE_VIRTUAL,
__bool__receive__C5_Scale2DCommand_R1,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::ScaleUniformCommand &, command,
Properties::PURE_VIRTUAL,
__bool__receive__C5_ScaleUniformCommand_R1,
"",
"");
I_Method1(bool, receive, IN, const osgManipulator::Rotate3DCommand &, command,
Properties::PURE_VIRTUAL,
__bool__receive__C5_Rotate3DCommand_R1,
"",
"");
END_REFLECTOR
BEGIN_OBJECT_REFLECTOR(osgManipulator::Selection)
I_DeclaringFile("osgManipulator/Selection");
I_BaseType(osg::MatrixTransform);