CommandManager 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. //osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
  14. #ifndef OSGMANIPULATOR_COMMANDMANAGER
  15. #define OSGMANIPULATOR_COMMANDMANAGER 1
  16. #include <osgManipulator/Dragger>
  17. #include <osgManipulator/Selection>
  18. #include <osgManipulator/Constraint>
  19. namespace osgManipulator {
  20. /**
  21. * Deprecated.
  22. * CommandManager class is now no longer required as Dragger now matains all references to Constraints and Selections (now just generic MatrixTransforms).
  23. * To replace CommandManager usage simple replace cmdMgr->connect(*dragger, *selection) with dragger->addTransformUpdating(selection) and
  24. * cmdMgr->connect(*dragger, *selection) with dragger->addConstaint(constraint).
  25. */
  26. class CommandManager : public osg::Referenced
  27. {
  28. public:
  29. CommandManager() {}
  30. bool connect(Dragger& dragger, Selection& selection)
  31. {
  32. dragger.addTransformUpdating(&selection);
  33. return true;
  34. }
  35. bool connect(Dragger& dragger, Constraint& constraint)
  36. {
  37. dragger.addConstraint(&constraint);
  38. return true;
  39. }
  40. bool disconnect(Dragger& dragger)
  41. {
  42. dragger.getConstraints().clear();
  43. dragger.getDraggerCallbacks().clear();
  44. return true;
  45. }
  46. typedef std::list< osg::ref_ptr<Selection> > Selections;
  47. Selections getConnectedSelections(Dragger& dragger)
  48. {
  49. Selections selections;
  50. for(Dragger::DraggerCallbacks::iterator itr = dragger.getDraggerCallbacks().begin();
  51. itr != dragger.getDraggerCallbacks().end();
  52. ++itr)
  53. {
  54. DraggerCallback* dc = itr->get();
  55. DraggerTransformCallback* dtc = dynamic_cast<DraggerTransformCallback*>(dc);
  56. if (dtc && dtc->getTransform()) selections.push_back(dtc->getTransform());
  57. }
  58. return selections;
  59. }
  60. protected:
  61. virtual ~CommandManager() {}
  62. };
  63. }
  64. #endif