Added PresentationInterface class to make it more convinient to access the current presentation from scripting languages
This commit is contained in:
parent
ee266255eb
commit
8f30a262f4
62
include/osgPresentation/PresentationInterface
Normal file
62
include/osgPresentation/PresentationInterface
Normal file
@ -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 <osgViewer/ViewerBase>
|
||||
#include <osgPresentation/deprecated/SlideEventHandler>
|
||||
|
||||
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
|
@ -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
|
||||
|
57
src/osgPresentation/PresentationInterface.cpp
Normal file
57
src/osgPresentation/PresentationInterface.cpp
Normal file
@ -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 <osgPresentation/PresentationInterface>
|
||||
|
||||
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);
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
#include <osgPresentation/PresentationInterface>
|
||||
#include <osgGA/Event>
|
||||
#include <osgDB/ObjectWrapper>
|
||||
#include <osgDB/InputStream>
|
||||
#include <osgDB/OutputStream>
|
||||
|
||||
struct PresentationInterfaceGetSlideEventHandler : public osgDB::MethodObject
|
||||
{
|
||||
virtual bool run(void* objectPtr, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
|
||||
{
|
||||
osgPresentation::PresentationInterface* pi = reinterpret_cast<osgPresentation::PresentationInterface*>(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<osgPresentation::PresentationInterface*>(objectPtr);
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
for(osg::Parameters::iterator itr = inputParameters.begin();
|
||||
itr != inputParameters.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::Event* event = dynamic_cast<osgGA::Event*>(itr->get());
|
||||
osgPresentation::KeyPosition* kp = dynamic_cast<osgPresentation::KeyPosition*>(itr->get());
|
||||
OSG_NOTICE<<"Dispatch event "<<pi<<", "<<kp<<", "<<event<<std::endl;
|
||||
if (kp) pi->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<osgPresentation::PresentationInterface*>(objectPtr);
|
||||
if (inputParameters.empty()) return false;
|
||||
|
||||
for(osg::Parameters::iterator itr = inputParameters.begin();
|
||||
itr != inputParameters.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::Event* event = dynamic_cast<osgGA::Event*>(itr->get());
|
||||
OSG_NOTICE<<"forward event "<<pi<<", "<<event<<std::endl;
|
||||
if (event) pi->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 );
|
||||
}
|
Loading…
Reference in New Issue
Block a user