From 8f30a262f4d22d40e114b74575e492301824f86e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Mar 2014 10:52:10 +0000 Subject: [PATCH] Added PresentationInterface class to make it more convinient to access the current presentation from scripting languages --- include/osgPresentation/PresentationInterface | 62 +++++++++++++++++ src/osgPresentation/CMakeLists.txt | 4 ++ src/osgPresentation/PresentationInterface.cpp | 57 ++++++++++++++++ .../osgPresentation/PresentationInterface.cpp | 67 +++++++++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 include/osgPresentation/PresentationInterface create mode 100644 src/osgPresentation/PresentationInterface.cpp create mode 100644 src/osgWrappers/serializers/osgPresentation/PresentationInterface.cpp diff --git a/include/osgPresentation/PresentationInterface b/include/osgPresentation/PresentationInterface new file mode 100644 index 000000000..a87713fd0 --- /dev/null +++ b/include/osgPresentation/PresentationInterface @@ -0,0 +1,62 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef OSGPRESENTATION_PRESENTATIONINTERFACE +#define OSGPRESENTATION_PRESENTATIONINTERFACE 1 + +#include +#include + +namespace osgPresentation { + +/** PresentationInterface is a helper class for scripting languages to use to access the key services of the presentation.*/ +class OSGPRESENTATION_EXPORT PresentationInterface : public osg::Object +{ + public : + + PresentationInterface() {} + + /** Copy constructor using CopyOp to manage deep vs shallow copy. */ + PresentationInterface(const PresentationInterface& pi,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Object(pi,copyop) {} + + META_Object(osgPresentation, PresentationInterface); + + /** get the viewer associated with the current active presentation.*/ + osgViewer::ViewerBase* getViewer(); + + /** get current active root presentation Node.*/ + osg::Node* getPresentation(); + + /** get SlideEventHandler that is managing the current active presentation.*/ + osgPresentation::SlideEventHandler* getSlideEventHandler(); + + /** pass on a jump command to the presentation to change layer/slide.*/ + void jump(const osgPresentation::JumpData* jumpdata); + + /** send KeyPosition event to viewer so that that it can be handled by the viewer and associated event handlers. */ + void sendEventToViewer(const osgPresentation::KeyPosition* kp); + + /** send event to viewer so that that it can be handled by the viewer and associated event handlers. */ + void sendEventToViewer(osgGA::Event* event); + + /** send event to devices attached to the viewer. */ + void sendEventToDevices(osgGA::Event* event); + +protected : + + virtual ~PresentationInterface() {} +}; + +} + +#endif diff --git a/src/osgPresentation/CMakeLists.txt b/src/osgPresentation/CMakeLists.txt index ec4aa0a1c..31c638802 100644 --- a/src/osgPresentation/CMakeLists.txt +++ b/src/osgPresentation/CMakeLists.txt @@ -27,6 +27,8 @@ SET(TARGET_H ${HEADER_PATH}/Text ${HEADER_PATH}/Volume + ${HEADER_PATH}/PresentationInterface + ${HEADER_PATH}/deprecated/AnimationMaterial ${HEADER_PATH}/deprecated/CompileSlideCallback ${HEADER_PATH}/deprecated/PickEventHandler @@ -57,6 +59,8 @@ SET(TARGET_SRC Text.cpp Volume.cpp + PresentationInterface.cpp + deprecated/AnimationMaterial.cpp deprecated/CompileSlideCallback.cpp deprecated/PickEventHandler.cpp diff --git a/src/osgPresentation/PresentationInterface.cpp b/src/osgPresentation/PresentationInterface.cpp new file mode 100644 index 000000000..71a52ad28 --- /dev/null +++ b/src/osgPresentation/PresentationInterface.cpp @@ -0,0 +1,57 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2013 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include + +using namespace osgPresentation; + +osgViewer::ViewerBase* PresentationInterface::getViewer() +{ + SlideEventHandler* seh = SlideEventHandler::instance(); + return (seh!=0) ? seh->getViewer() : 0; +} + +osg::Node* PresentationInterface::getPresentation() +{ + SlideEventHandler* seh = SlideEventHandler::instance(); + return (seh!=0) ? seh->getPresentationSwitch() : 0; +} + +osgPresentation::SlideEventHandler* PresentationInterface::getSlideEventHandler() +{ + return SlideEventHandler::instance(); +} + +void PresentationInterface::jump(const osgPresentation::JumpData* jumpdata) +{ + SlideEventHandler* seh = SlideEventHandler::instance(); + if ((seh!=0) && (jumpdata!=0)) jumpdata->jump(seh); +} + +void PresentationInterface::sendEventToViewer(osgGA::Event* event) +{ + SlideEventHandler* seh = SlideEventHandler::instance(); + if ((seh!=0) && (event!=0)) seh->dispatchEvent(event); +} + +void PresentationInterface::sendEventToViewer(const osgPresentation::KeyPosition* kp) +{ + SlideEventHandler* seh = SlideEventHandler::instance(); + if ((seh!=0) && (kp!=0)) seh->dispatchEvent(*kp); +} + +void PresentationInterface::sendEventToDevices(osgGA::Event* event) +{ + SlideEventHandler* seh = SlideEventHandler::instance(); + if ((seh!=0) && (event!=0)) seh->forwardEventToDevices(event); +} diff --git a/src/osgWrappers/serializers/osgPresentation/PresentationInterface.cpp b/src/osgWrappers/serializers/osgPresentation/PresentationInterface.cpp new file mode 100644 index 000000000..788e774a5 --- /dev/null +++ b/src/osgWrappers/serializers/osgPresentation/PresentationInterface.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include + +struct PresentationInterfaceGetSlideEventHandler : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + { + osgPresentation::PresentationInterface* pi = reinterpret_cast(objectPtr); + outputParameters.push_back(pi->getSlideEventHandler()); + return true; + } +}; + +struct PresentationInterfaceSendEventToViewer : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + { + osgPresentation::PresentationInterface* pi = reinterpret_cast(objectPtr); + if (inputParameters.empty()) return false; + + for(osg::Parameters::iterator itr = inputParameters.begin(); + itr != inputParameters.end(); + ++itr) + { + osgGA::Event* event = dynamic_cast(itr->get()); + osgPresentation::KeyPosition* kp = dynamic_cast(itr->get()); + OSG_NOTICE<<"Dispatch event "<sendEventToViewer(kp); + else if (event) pi->sendEventToViewer(event); + } + + return true; + } +}; + +struct PresentationInterfaceSendEventToDevices : public osgDB::MethodObject +{ + virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const + { + osgPresentation::PresentationInterface* pi = reinterpret_cast(objectPtr); + if (inputParameters.empty()) return false; + + for(osg::Parameters::iterator itr = inputParameters.begin(); + itr != inputParameters.end(); + ++itr) + { + osgGA::Event* event = dynamic_cast(itr->get()); + OSG_NOTICE<<"forward event "<sendEventToDevices(event); + } + + return true; + } +}; + +REGISTER_OBJECT_WRAPPER( osgPresentation_PresentationInterface, + new osgPresentation::PresentationInterface, + osgPresentation::PresentationInterface, + "osg::Object osgPresentation::PresentationInterface" ) +{ + ADD_METHOD_OBJECT( "getSlideEventHandler", PresentationInterfaceGetSlideEventHandler ); + ADD_METHOD_OBJECT( "sendEventToViewer", PresentationInterfaceSendEventToViewer ); + ADD_METHOD_OBJECT( "sendEventToDevices", PresentationInterfaceSendEventToDevices ); +}