From 9d8fd69fa9ec533bd0b44fcd03a8a70e6d150647 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 Nov 2005 11:00:36 +0000 Subject: [PATCH] Change the KeySwitchMatrixManipulator so that it two sets of getMatrixManipulator methods, two that takes an index,two that takes a key value. Updated the ViewEventHandler so the it now uses the getMatrixManipulatorWithIndex() method to avoid previous ambiguity. --- include/osgGA/KeySwitchMatrixManipulator | 10 ++++-- src/osgGA/KeySwitchMatrixManipulator.cpp | 32 ++++++++++++++++--- src/osgProducer/ViewerEventHandler.cpp | 5 +-- .../osgGA/KeySwitchMatrixManipulator.cpp | 7 ++-- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/include/osgGA/KeySwitchMatrixManipulator b/include/osgGA/KeySwitchMatrixManipulator index 94b796d53..062b8519e 100644 --- a/include/osgGA/KeySwitchMatrixManipulator +++ b/include/osgGA/KeySwitchMatrixManipulator @@ -68,11 +68,17 @@ public: const MatrixManipulator* getCurrentMatrixManipulator() const { return _current.get(); } + /** Get manipulator assigned to a specified index.*/ + MatrixManipulator* getMatrixManipulatorWithIndex(unsigned int key); + + /** Get const manipulator assigned to a specified index.*/ + const MatrixManipulator* getMatrixManipulatorWithIndex(unsigned int key) const; + /** Get manipulator assigned to a specified key.*/ - MatrixManipulator* getMatrixManipulator(unsigned int key); + MatrixManipulator* getMatrixManipulatorWithKey(unsigned int key); /** Get const manipulator assigned to a specified key.*/ - const MatrixManipulator* getMatrixManipulator(unsigned int key) const; + const MatrixManipulator* getMatrixManipulatorWithKey(unsigned int key) const; // Overrides from MatrixManipulator... diff --git a/src/osgGA/KeySwitchMatrixManipulator.cpp b/src/osgGA/KeySwitchMatrixManipulator.cpp index cb103a9bb..ed2934b04 100644 --- a/src/osgGA/KeySwitchMatrixManipulator.cpp +++ b/src/osgGA/KeySwitchMatrixManipulator.cpp @@ -118,16 +118,40 @@ void KeySwitchMatrixManipulator::setCoordinateFrameCallback(CoordinateFrameCallb } } -MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulator(unsigned int num) +MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithIndex(unsigned int index) { - KeyManipMap::iterator itr = _manips.find(num); + unsigned i=0; + for(KeyManipMap::iterator itr = _manips.begin(); + itr != _manips.end(); + ++itr, ++i) + { + if (i==index) return itr->second.second.get(); + } + return 0; +} + +const MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithIndex(unsigned int index) const +{ + unsigned i=0; + for(KeyManipMap::const_iterator itr = _manips.begin(); + itr != _manips.end(); + ++itr, ++i) + { + if (i==index) return itr->second.second.get(); + } + return 0; +} + +MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithKey(unsigned int key) +{ + KeyManipMap::iterator itr = _manips.find(key); if (itr!=_manips.end()) return itr->second.second.get(); else return 0; } -const MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulator(unsigned int num) const +const MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulatorWithKey(unsigned int key) const { - KeyManipMap::const_iterator itr = _manips.find(num); + KeyManipMap::const_iterator itr = _manips.find(key); if (itr!=_manips.end()) return itr->second.second.get(); else return 0; } diff --git a/src/osgProducer/ViewerEventHandler.cpp b/src/osgProducer/ViewerEventHandler.cpp index b2e854c25..c4f870625 100644 --- a/src/osgProducer/ViewerEventHandler.cpp +++ b/src/osgProducer/ViewerEventHandler.cpp @@ -1080,9 +1080,10 @@ bool ViewerEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActio osgGA::KeySwitchMatrixManipulator* kscm = viewer->getKeySwitchMatrixManipulator(); if (kscm) { - for(apmNo=0;apmNogetNumMatrixManipulators() && apm==0;++apmNo) + for(apmNo=0;apmNogetNumMatrixManipulators();++apmNo) { - apm = dynamic_cast(kscm->getMatrixManipulator(apmNo)); + apm = dynamic_cast(kscm->getMatrixManipulatorWithIndex(apmNo)); + if (apm) break; } } diff --git a/src/osgWrappers/osgGA/KeySwitchMatrixManipulator.cpp b/src/osgWrappers/osgGA/KeySwitchMatrixManipulator.cpp index 73130fb3e..1b04caae6 100644 --- a/src/osgWrappers/osgGA/KeySwitchMatrixManipulator.cpp +++ b/src/osgWrappers/osgGA/KeySwitchMatrixManipulator.cpp @@ -43,8 +43,10 @@ BEGIN_OBJECT_REFLECTOR(osgGA::KeySwitchMatrixManipulator) I_Method0(const osgGA::KeySwitchMatrixManipulator::KeyManipMap &, getKeyManipMap); I_Method0(osgGA::MatrixManipulator *, getCurrentMatrixManipulator); I_Method0(const osgGA::MatrixManipulator *, getCurrentMatrixManipulator); - I_Method1(osgGA::MatrixManipulator *, getMatrixManipulator, IN, unsigned int, key); - I_Method1(const osgGA::MatrixManipulator *, getMatrixManipulator, IN, unsigned int, key); + I_Method1(osgGA::MatrixManipulator *, getMatrixManipulatorWithIndex, IN, unsigned int, key); + I_Method1(const osgGA::MatrixManipulator *, getMatrixManipulatorWithIndex, IN, unsigned int, key); + I_Method1(osgGA::MatrixManipulator *, getMatrixManipulatorWithKey, IN, unsigned int, key); + I_Method1(const osgGA::MatrixManipulator *, getMatrixManipulatorWithKey, IN, unsigned int, key); I_Method1(void, setMinimumDistance, IN, float, minimumDistance); I_Method1(void, setCoordinateFrameCallback, IN, osgGA::MatrixManipulator::CoordinateFrameCallback *, cb); I_Method1(void, setByMatrix, IN, const osg::Matrixd &, matrix); @@ -73,7 +75,6 @@ BEGIN_OBJECT_REFLECTOR(osgGA::KeySwitchMatrixManipulator) I_ReadOnlyProperty(osg::Matrixd, InverseMatrix); I_ReadOnlyProperty(osgGA::KeySwitchMatrixManipulator::KeyManipMap &, KeyManipMap); I_ReadOnlyProperty(osg::Matrixd, Matrix); - I_ArrayProperty_G(osgGA::MatrixManipulator *, MatrixManipulator, MatrixManipulators, unsigned int, void); I_WriteOnlyProperty(float, MinimumDistance); I_Property(osg::Node *, Node); END_REFLECTOR