From 31608b25591b282a6668cb622db1e7923815252f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 11 Mar 2009 11:29:00 +0000 Subject: [PATCH] From David Callu, "osgManipulator Object have not META_Object macro call in class definition. > I add META_OSGMANIPULATOR_Object macro which define className, libraryName, > isSameKindAs methods. > Clone method is not appropriate for osgManipulator Object." --- include/osgManipulator/Dragger | 36 ++++++++++--------- include/osgManipulator/RotateCylinderDragger | 4 ++- include/osgManipulator/RotateSphereDragger | 4 ++- include/osgManipulator/Scale1DDragger | 10 +++--- include/osgManipulator/Scale2DDragger | 8 +++-- include/osgManipulator/ScaleAxisDragger | 2 ++ include/osgManipulator/Selection | 13 +++++-- include/osgManipulator/TabBoxDragger | 4 ++- include/osgManipulator/TabPlaneDragger | 4 ++- .../osgManipulator/TabPlaneTrackballDragger | 2 ++ include/osgManipulator/TrackballDragger | 2 ++ include/osgManipulator/Translate1DDragger | 4 ++- include/osgManipulator/Translate2DDragger | 4 ++- include/osgManipulator/TranslateAxisDragger | 2 ++ include/osgManipulator/TranslatePlaneDragger | 4 ++- 15 files changed, 71 insertions(+), 32 deletions(-) diff --git a/include/osgManipulator/Dragger b/include/osgManipulator/Dragger index 13f79751c..d18138945 100644 --- a/include/osgManipulator/Dragger +++ b/include/osgManipulator/Dragger @@ -48,13 +48,13 @@ class OSGMANIPULATOR_EXPORT PointerInfo { _hitList.clear(); _hitIter = _hitList.begin(); - setCamera(0); + setCamera(0); } bool completed() const { return _hitIter==_hitList.end(); } - void next() + void next() { if (!completed()) ++_hitIter; } @@ -66,15 +66,15 @@ class OSGMANIPULATOR_EXPORT PointerInfo osg::Vec3d getLocalIntersectPoint() const { return _hitIter->second; } - + void setNearFarPoints (osg::Vec3d nearPoint, osg::Vec3d farPoint) { _nearPoint = nearPoint; _farPoint=farPoint; _eyeDir = farPoint - nearPoint; } - + const osg::Vec3d& getEyeDir() const {return _eyeDir;} - + void getNearFarPoints( osg::Vec3d& nearPoint, osg::Vec3d& farPoint) const { nearPoint = _nearPoint; farPoint = _farPoint; @@ -84,7 +84,7 @@ class OSGMANIPULATOR_EXPORT PointerInfo void setCamera(osg::Camera* camera) { - + if (camera) { _MVPW = camera->getViewMatrix() * camera->getProjectionMatrix(); @@ -112,7 +112,7 @@ class OSGMANIPULATOR_EXPORT PointerInfo } void setMousePosition(float pixel_x, float pixel_y) - { + { projectWindowXYIntoObject(osg::Vec2d(pixel_x, pixel_y), _nearPoint, _farPoint); } protected: @@ -123,7 +123,7 @@ class OSGMANIPULATOR_EXPORT PointerInfo IntersectionList::const_iterator _hitIter; protected: - + osg::Vec3d _nearPoint,_farPoint; osg::Vec3d _eyeDir; @@ -134,8 +134,8 @@ 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 + * 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 * commands. */ @@ -143,6 +143,8 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection { 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; } @@ -170,24 +172,26 @@ class OSGMANIPULATOR_EXPORT Dragger : public Selection Dragger(); virtual ~Dragger(); - + CommandManager* _commandManager; Dragger* _parentDragger; - + }; /** - * CompositeDragger allows to create complex draggers that are composed of a + * CompositeDragger allows to create complex draggers that are composed of a * hierarchy of Draggers. */ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger { public: + META_OSGMANIPULATOR_Object(osgManipulator,CompositeDragger) + typedef std::vector< osg::ref_ptr > DraggerList; - + virtual const CompositeDragger* getComposite() const { return this; } virtual CompositeDragger* getComposite() { return this; } @@ -210,14 +214,14 @@ class OSGMANIPULATOR_EXPORT CompositeDragger : public Dragger CompositeDragger() {} virtual ~CompositeDragger() {} - + DraggerList _draggerList; }; /** * Culls the drawable all the time. Used by draggers to have invisible geometry * around lines and points so that they can be picked. For example, a dragger - * could have a line with an invisible cylinder around it to enable picking on + * could have a line with an invisible cylinder around it to enable picking on * that line. */ void OSGMANIPULATOR_EXPORT setDrawableToAlwaysCull(osg::Drawable& drawable); diff --git a/include/osgManipulator/RotateCylinderDragger b/include/osgManipulator/RotateCylinderDragger index 73e6f1899..61c49d3ca 100644 --- a/include/osgManipulator/RotateCylinderDragger +++ b/include/osgManipulator/RotateCylinderDragger @@ -29,6 +29,8 @@ class OSGMANIPULATOR_EXPORT RotateCylinderDragger : public Dragger RotateCylinderDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,RotateCylinderDragger) + /** * Handle pick events on dragger and generate TranslateInLine commands. */ @@ -49,7 +51,7 @@ class OSGMANIPULATOR_EXPORT RotateCylinderDragger : public Dragger inline void setPickColor(const osg::Vec4& color) { _pickColor = color; } inline const osg::Vec4 getPickColor() const { return _pickColor; } - + protected: virtual ~RotateCylinderDragger(); diff --git a/include/osgManipulator/RotateSphereDragger b/include/osgManipulator/RotateSphereDragger index 3770317e5..84243a63f 100644 --- a/include/osgManipulator/RotateSphereDragger +++ b/include/osgManipulator/RotateSphereDragger @@ -29,6 +29,8 @@ class OSGMANIPULATOR_EXPORT RotateSphereDragger : public Dragger RotateSphereDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,RotateSphereDragger) + /** * Handle pick events on dragger and generate TranslateInLine commands. */ @@ -42,7 +44,7 @@ class OSGMANIPULATOR_EXPORT RotateSphereDragger : public Dragger inline const osg::Vec4 getColor() const { return _color; } /** - * Set/Get pick color for dragger. Pick color is color of the dragger + * Set/Get pick color for dragger. Pick color is color of the dragger * when picked. It gives a visual feedback to show that the dragger has * been picked. */ diff --git a/include/osgManipulator/Scale1DDragger b/include/osgManipulator/Scale1DDragger index e1d35f93d..e4fac897d 100644 --- a/include/osgManipulator/Scale1DDragger +++ b/include/osgManipulator/Scale1DDragger @@ -32,9 +32,11 @@ class OSGMANIPULATOR_EXPORT Scale1DDragger : public Dragger SCALE_WITH_ORIGIN_AS_PIVOT = 0, SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT }; - + Scale1DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT); + META_OSGMANIPULATOR_Object(osgManipulator,Scale1DDragger) + /** * Handle pick events on dragger and generate TranslateInLine commands. */ @@ -53,8 +55,8 @@ class OSGMANIPULATOR_EXPORT Scale1DDragger : public Dragger /** * Set/Get pick color for dragger. Pick color is color of the dragger - * when picked. It gives a visual feedback to show that the dragger has - * been picked. + * when picked. It gives a visual feedback to show that the dragger has + * been picked. */ inline void setPickColor(const osg::Vec4& color) { _pickColor = color; } inline const osg::Vec4 getPickColor() const { return _pickColor; } @@ -70,7 +72,7 @@ class OSGMANIPULATOR_EXPORT Scale1DDragger : public Dragger inline double getLeftHandlePosition() const { return _projector->getLineStart()[0]; } inline void setRightHandlePosition(double pos) { _projector->getLineEnd() = osg::Vec3d(pos,0.0,0.0); } inline double getRightHandlePosition() { return _projector->getLineEnd()[0]; } - + protected: virtual ~Scale1DDragger(); diff --git a/include/osgManipulator/Scale2DDragger b/include/osgManipulator/Scale2DDragger index 5d726128d..2ebb17c57 100644 --- a/include/osgManipulator/Scale2DDragger +++ b/include/osgManipulator/Scale2DDragger @@ -32,9 +32,11 @@ class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger SCALE_WITH_ORIGIN_AS_PIVOT = 0, SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT }; - + Scale2DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT); + META_OSGMANIPULATOR_Object(osgManipulator,Scale2DDragger) + /** * Handle pick events on dragger and generate TranslateInLine commands. */ @@ -51,7 +53,7 @@ class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); } inline const osg::Vec4 getColor() const { return _color; } - /** + /** * Set/Get pick color for dragger. Pick color is color of the dragger * when picked. It gives a visual feedback to show that the dragger has * been picked. @@ -68,7 +70,7 @@ class OSGMANIPULATOR_EXPORT Scale2DDragger : public Dragger inline osg::Node* getTopRightHandleNode() { return _topRightHandleNode.get(); } inline void setBottomRightHandleNode(osg::Node& node) { _bottomRightHandleNode = &node; } inline osg::Node* getBottomRightHandleNode() { return _bottomRightHandleNode.get(); } - + /** Set/Get the handle nodes postion for dragger. */ inline void setTopLeftHandlePosition(const osg::Vec2d& pos) { _topLeftHandlePosition = pos; } const osg::Vec2d& getTopLeftHandlePosition() { return _topLeftHandlePosition; } diff --git a/include/osgManipulator/ScaleAxisDragger b/include/osgManipulator/ScaleAxisDragger index bf16499ae..0c26a333d 100644 --- a/include/osgManipulator/ScaleAxisDragger +++ b/include/osgManipulator/ScaleAxisDragger @@ -28,6 +28,8 @@ class OSGMANIPULATOR_EXPORT ScaleAxisDragger : public CompositeDragger ScaleAxisDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,ScaleAxisDragger) + /** Setup default geometry for dragger. */ void setupDefaultGeometry(); diff --git a/include/osgManipulator/Selection b/include/osgManipulator/Selection index 75acb1686..d874ed54d 100644 --- a/include/osgManipulator/Selection +++ b/include/osgManipulator/Selection @@ -31,6 +31,13 @@ class Rotate3DCommand; /** Computes the nodepath from the given node all the way upto the root. */ extern OSGMANIPULATOR_EXPORT void computeNodePathToRoot(osg::Node& node, osg::NodePath& np); + + +#define META_OSGMANIPULATOR_Object(library,name) \ +virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast(obj)!=NULL; } \ +virtual const char* libraryName() const { return #library; }\ +virtual const char* className() const { return #name; } + /** * Selection listens to motion commands generated by draggers. */ @@ -39,9 +46,11 @@ class OSGMANIPULATOR_EXPORT Selection : public osg::MatrixTransform public: Selection(); - + + META_OSGMANIPULATOR_Object(osgManipulator,Selection) + /** - * Receive motion commands and set the MatrixTransform accordingly to + * Receive motion commands and set the MatrixTransform accordingly to * transform selections. Returns true on success. */ virtual bool receive(const MotionCommand&); diff --git a/include/osgManipulator/TabBoxDragger b/include/osgManipulator/TabBoxDragger index 98e0e7e5e..486ef6ce1 100644 --- a/include/osgManipulator/TabBoxDragger +++ b/include/osgManipulator/TabBoxDragger @@ -20,7 +20,7 @@ namespace osgManipulator { /** - * TabBoxDragger consists of 6 TabPlaneDraggers to form a box dragger that + * TabBoxDragger consists of 6 TabPlaneDraggers to form a box dragger that * performs translation and scaling. */ class OSGMANIPULATOR_EXPORT TabBoxDragger : public CompositeDragger @@ -29,6 +29,8 @@ class OSGMANIPULATOR_EXPORT TabBoxDragger : public CompositeDragger TabBoxDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,TabBoxDragger) + /** Setup default geometry for dragger. */ void setupDefaultGeometry(); diff --git a/include/osgManipulator/TabPlaneDragger b/include/osgManipulator/TabPlaneDragger index e36e51043..12b82a778 100644 --- a/include/osgManipulator/TabPlaneDragger +++ b/include/osgManipulator/TabPlaneDragger @@ -22,7 +22,7 @@ namespace osgManipulator { /** - * Tab plane dragger consists of a plane with tabs on it's corners and edges + * Tab plane dragger consists of a plane with tabs on it's corners and edges * for scaling. And the plane is used as a 2D translate dragger. */ class OSGMANIPULATOR_EXPORT TabPlaneDragger : public CompositeDragger @@ -31,6 +31,8 @@ class OSGMANIPULATOR_EXPORT TabPlaneDragger : public CompositeDragger TabPlaneDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,TabPlaneDragger) + virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); /** Setup default geometry for dragger. */ diff --git a/include/osgManipulator/TabPlaneTrackballDragger b/include/osgManipulator/TabPlaneTrackballDragger index 6b96d4389..df56d7fd7 100644 --- a/include/osgManipulator/TabPlaneTrackballDragger +++ b/include/osgManipulator/TabPlaneTrackballDragger @@ -29,6 +29,8 @@ class OSGMANIPULATOR_EXPORT TabPlaneTrackballDragger : public CompositeDragger TabPlaneTrackballDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,TabPlaneTrackballDragger) + /** Setup default geometry for dragger. */ void setupDefaultGeometry(); diff --git a/include/osgManipulator/TrackballDragger b/include/osgManipulator/TrackballDragger index 4854da038..f4a531e25 100644 --- a/include/osgManipulator/TrackballDragger +++ b/include/osgManipulator/TrackballDragger @@ -29,6 +29,8 @@ class OSGMANIPULATOR_EXPORT TrackballDragger : public CompositeDragger TrackballDragger(bool useAutoTransform=false); + META_OSGMANIPULATOR_Object(osgManipulator,TrackballDragger) + /** Setup default geometry for dragger. */ void setupDefaultGeometry(); diff --git a/include/osgManipulator/Translate1DDragger b/include/osgManipulator/Translate1DDragger index 127e712fb..dbacd4ab0 100644 --- a/include/osgManipulator/Translate1DDragger +++ b/include/osgManipulator/Translate1DDragger @@ -30,6 +30,8 @@ class OSGMANIPULATOR_EXPORT Translate1DDragger : public Dragger Translate1DDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,Translate1DDragger) + Translate1DDragger(const osg::Vec3d& s, const osg::Vec3d& e); /** Handle pick events on dragger and generate TranslateInLine commands. */ @@ -42,7 +44,7 @@ class OSGMANIPULATOR_EXPORT Translate1DDragger : public Dragger inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); } inline const osg::Vec4 getColor() const { return _color; } - /** Set/Get pick color for dragger. Pick color is color of the dragger when picked. + /** Set/Get pick color for dragger. Pick color is color of the dragger when picked. It gives a visual feedback to show that the dragger has been picked. */ inline void setPickColor(const osg::Vec4& color) { _pickColor = color; } inline const osg::Vec4 getPickColor() const { return _pickColor; } diff --git a/include/osgManipulator/Translate2DDragger b/include/osgManipulator/Translate2DDragger index f20d8e3cd..5a70454ce 100644 --- a/include/osgManipulator/Translate2DDragger +++ b/include/osgManipulator/Translate2DDragger @@ -33,6 +33,8 @@ class OSGMANIPULATOR_EXPORT Translate2DDragger : public Dragger Translate2DDragger(const osg::Plane& plane); + META_OSGMANIPULATOR_Object(osgManipulator,Translate2DDragger) + /** Handle pick events on dragger and generate TranslateInLine commands. */ virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); @@ -43,7 +45,7 @@ class OSGMANIPULATOR_EXPORT Translate2DDragger : public Dragger inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); } inline const osg::Vec4 getColor() const { return _color; } - /** Set/Get pick color for dragger. Pick color is color of the dragger when picked. + /** Set/Get pick color for dragger. Pick color is color of the dragger when picked. It gives a visual feedback to show that the dragger has been picked. */ inline void setPickColor(const osg::Vec4& color) { _pickColor = color; } inline const osg::Vec4 getPickColor() const { return _pickColor; } diff --git a/include/osgManipulator/TranslateAxisDragger b/include/osgManipulator/TranslateAxisDragger index 6c8949865..863c6e855 100644 --- a/include/osgManipulator/TranslateAxisDragger +++ b/include/osgManipulator/TranslateAxisDragger @@ -28,6 +28,8 @@ class OSGMANIPULATOR_EXPORT TranslateAxisDragger : public CompositeDragger TranslateAxisDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,TranslateAxisDragger) + /** Setup default geometry for dragger. */ void setupDefaultGeometry(); diff --git a/include/osgManipulator/TranslatePlaneDragger b/include/osgManipulator/TranslatePlaneDragger index 7b23584e3..25ddb1819 100644 --- a/include/osgManipulator/TranslatePlaneDragger +++ b/include/osgManipulator/TranslatePlaneDragger @@ -21,7 +21,7 @@ namespace osgManipulator { /** - * Tab plane dragger consists of a plane with tabs on it's corners and edges + * Tab plane dragger consists of a plane with tabs on it's corners and edges * for scaling. And the plane is used as a 2D translate dragger. */ class OSGMANIPULATOR_EXPORT TranslatePlaneDragger : public CompositeDragger @@ -30,6 +30,8 @@ class OSGMANIPULATOR_EXPORT TranslatePlaneDragger : public CompositeDragger TranslatePlaneDragger(); + META_OSGMANIPULATOR_Object(osgManipulator,TranslatePlaneDragger) + virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us); /** Setup default geometry for dragger. */