Added PresentationInterface class to make it more convinient to access the current presentation from scripting languages
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
Reference in New Issue
Block a user