From 1fcadcf514d93cf9181bd181416e916c610f6178 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 17 Jan 2013 09:51:15 +0000 Subject: [PATCH] Added support for to Timeout support. --- include/osgPresentation/SlideShowConstructor | 2 +- include/osgPresentation/Timeout | 8 +- src/osgPlugins/p3d/ReaderWriterP3D.cpp | 394 +++++++++++-------- src/osgPresentation/SlideShowConstructor.cpp | 3 +- src/osgPresentation/Timeout.cpp | 6 + 5 files changed, 240 insertions(+), 173 deletions(-) diff --git a/include/osgPresentation/SlideShowConstructor b/include/osgPresentation/SlideShowConstructor index 1d2b03424..5c4a39398 100644 --- a/include/osgPresentation/SlideShowConstructor +++ b/include/osgPresentation/SlideShowConstructor @@ -381,7 +381,7 @@ public: void setSlideDuration(double duration); - void addTimeout(); + Timeout* addTimeout(); void addLayer(bool inheritPreviousLayers=true, bool defineAsBaseLayer=false); diff --git a/include/osgPresentation/Timeout b/include/osgPresentation/Timeout index eaeeacfaf..2c80ac03f 100644 --- a/include/osgPresentation/Timeout +++ b/include/osgPresentation/Timeout @@ -15,7 +15,8 @@ #define OSGPRESENTATION_TIMOUTOUT 1 #include -#include + +#include namespace osgPresentation { @@ -55,6 +56,9 @@ class OSGPRESENTATION_EXPORT Timeout : public osg::Transform void setIdleDurationBeforeTimeoutAction(double t) { _idleDurationBeforeTimeoutAction = t; } double getIdleDurationBeforeTimeoutAction() const { return _idleDurationBeforeTimeoutAction; } + void setJumpData(const JumpData& jumpData) { _jumpData = jumpData; } + const JumpData& getJumpData() const { return _jumpData; } + virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const; virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor*) const; @@ -71,6 +75,8 @@ class OSGPRESENTATION_EXPORT Timeout : public osg::Transform double _timeOfLastEvent; double _idleDurationBeforeTimeoutDisplay; double _idleDurationBeforeTimeoutAction; + + JumpData _jumpData; }; } diff --git a/src/osgPlugins/p3d/ReaderWriterP3D.cpp b/src/osgPlugins/p3d/ReaderWriterP3D.cpp index 17dde7065..39916415b 100644 --- a/src/osgPlugins/p3d/ReaderWriterP3D.cpp +++ b/src/osgPlugins/p3d/ReaderWriterP3D.cpp @@ -134,6 +134,8 @@ public: void parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; + bool parseLayerChild(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur, float& totalIndent) const; + void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; @@ -1443,24 +1445,225 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation } -void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const +void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const { // to allow the timeout to be nested with a Layer but still behave like a Layer itself we push the timeout as a Layer, saving the original Layer constructor.pushCurrentLayer(); - constructor.addTimeout(); + osg::ref_ptr timeout = constructor.addTimeout(); - parseLayer(constructor, cur); + OSG_NOTICE<<"parseTimeout"<children.begin(); + itr != root->children.end(); + ++itr) + { + osgDB::XmlNode* cur = itr->get(); + if (parseLayerChild(constructor, cur, totalIndent)) + { + // no need to do anything + } + else if (cur->name == "timeout_jump") + { + OSG_NOTICE<<"Parsed Jump "<setJumpData(jumpData); + } + } + } constructor.popCurrentLayer(); // return the } +bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur, float& totalIndent) const +{ + if (cur->name == "newline") + { + constructor.translateTextCursor(osg::Vec3(0.0f,-0.05f,0.0f)); + return true; + } + else if (cur->name == "indent") + { + float localIndent = 0.05f; + constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); + totalIndent += localIndent; + return true; + } + else if (cur->name == "unindent") + { + float localIndent = -0.05f; + constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); + totalIndent += localIndent; + return true; + } + else if (cur->name == "bullet") + { + OSG_INFO<<"bullet ["<contents<<"]"<contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); + return true; + } + else if (cur->name == "paragraph") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); + bool fontRead = getProperties(cur,fontData); + + constructor.addParagraph(cur->contents, + positionRead ? positionData : constructor.getTextPositionData(), + fontRead ? fontData : constructor.getTextFontData()); + return true; + } + else if (cur->name == "image") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); + + constructor.addImage(cur->getTrimmedContents(), + positionRead ? positionData : constructor.getImagePositionData(), + imageData); + return true; + } + else if (cur->name == "imagesequence") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + imageData.imageSequence = true; + getProperties(cur,imageData); + + constructor.addImage(cur->getTrimmedContents(), + positionRead ? positionData : constructor.getImagePositionData(), + imageData); + return true; + } + else if (cur->name == "graph") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); + + std::string options; + getProperty(cur, "options", options); + + constructor.addGraph(cur->getTrimmedContents(), + positionRead ? positionData : constructor.getImagePositionData(), + imageData); + return true; + } + else if (cur->name == "vnc") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); + + std::string password; + getProperty(cur, "password", password); + + constructor.addVNC(cur->getTrimmedContents(), + positionRead ? positionData : constructor.getImagePositionData(), + imageData, + password + ); + return true; + } + else if (cur->name == "browser") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); + + constructor.addBrowser(cur->getTrimmedContents(), + positionRead ? positionData : constructor.getImagePositionData(), + imageData); + return true; + } + else if (cur->name == "pdf") + { + osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); + bool positionRead = getProperties(cur,positionData); + + osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); + getProperties(cur,imageData); + + constructor.addPDF(cur->getTrimmedContents(), + positionRead ? positionData : constructor.getImagePositionData(), + imageData); + return true; + } + else if (cur->name == "stereo_pair") + { + parseStereoPair(constructor, cur); + return true; + } + else if (cur->name == "model") + { + parseModel(constructor, cur); + return true; + } + else if (cur->name == "volume") + { + parseVolume(constructor, cur); + return true; + } + else if (cur->name == "duration") + { + constructor.setLayerDuration(osg::asciiToDouble(cur->contents.c_str())); + return true; + } + else if (cur->name == "property_animation") + { + osg::ref_ptr pa = new osgPresentation::PropertyAnimation; + if (parsePropertyAnimation(cur,*pa)) + { + constructor.addPropertyAnimation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, pa.get()); + } + return true; + } + else if (cur->name == "properties") + { + if (!constructor.getCurrentLayer()) constructor.addLayer(); + if (constructor.getCurrentLayer()) + { + osg::ref_ptr udc = constructor.getCurrentLayer()->getOrCreateUserDataContainer(); + if (parseProperties(cur, *udc)) + { + OSG_NOTICE<<"Assigned properties to Layer"<get(); - if (cur->name == "run") + if (parseLayerChild(constructor, cur, totalIndent)) + { + // no need to do anything + } + else if (cur->name == "timeout") + { + parseTimeout(constructor, cur); + } + else if (cur->name == "run") { OSG_INFO<<"run ["<contents<<"]"<contents); @@ -1516,6 +1727,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const osgPresentation::JumpData jumpData; getJumpProperties(cur, jumpData); + osgPresentation::KeyPosition keyPosition; if (getKeyPositionInner( cur, keyPosition)) { OSG_INFO<<"click_to_event ["<name == "newline") + else { - constructor.translateTextCursor(osg::Vec3(0.0f,-0.05f,0.0f)); - } - else if (cur->name == "indent") - { - float localIndent = 0.05f; - constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); - totalIndent += localIndent; - } - else if (cur->name == "unindent") - { - float localIndent = -0.05f; - constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); - totalIndent += localIndent; - } - else if (cur->name == "bullet") - { - OSG_INFO<<"bullet ["<contents<<"]"<contents, - positionRead ? positionData : constructor.getTextPositionData(), - fontRead ? fontData : constructor.getTextFontData()); - } - else if (cur->name == "paragraph") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); - bool fontRead = getProperties(cur,fontData); - - constructor.addParagraph(cur->contents, - positionRead ? positionData : constructor.getTextPositionData(), - fontRead ? fontData : constructor.getTextFontData()); - } - else if (cur->name == "image") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); - - constructor.addImage(cur->getTrimmedContents(), - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } - else if (cur->name == "imagesequence") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - imageData.imageSequence = true; - getProperties(cur,imageData); - - constructor.addImage(cur->getTrimmedContents(), - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } - else if (cur->name == "graph") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); - - std::string options; - getProperty(cur, "options", options); - - constructor.addGraph(cur->getTrimmedContents(), - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } - else if (cur->name == "vnc") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); - - std::string password; - getProperty(cur, "password", password); - - constructor.addVNC(cur->getTrimmedContents(), - positionRead ? positionData : constructor.getImagePositionData(), - imageData, - password - ); - } - else if (cur->name == "browser") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); - - constructor.addBrowser(cur->getTrimmedContents(), - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } - else if (cur->name == "pdf") - { - osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); - bool positionRead = getProperties(cur,positionData); - - osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData(); - getProperties(cur,imageData); - - constructor.addPDF(cur->getTrimmedContents(), - positionRead ? positionData : constructor.getImagePositionData(), - imageData); - } - else if (cur->name == "stereo_pair") - { - parseStereoPair(constructor, cur); - } - else if (cur->name == "model") - { - parseModel(constructor, cur); - } - else if (cur->name == "volume") - { - parseVolume(constructor, cur); - } - else if (cur->name == "timeout") - { - parseTimeout(constructor, cur); - } - else if (cur->name == "duration") - { - constructor.setLayerDuration(osg::asciiToDouble(cur->contents.c_str())); - } - else if (cur->name == "property_animation") - { - osg::ref_ptr pa = new osgPresentation::PropertyAnimation; - if (parsePropertyAnimation(cur,*pa)) + osgPresentation::KeyPosition keyPosition; + if (getKeyPosition(cur, keyPosition)) { - constructor.addPropertyAnimation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, pa.get()); + constructor.addLayerKey(keyPosition); } } - else if (cur->name == "properties") - { - if (!constructor.getCurrentLayer()) constructor.addLayer(); - if (constructor.getCurrentLayer()) - { - osg::ref_ptr udc = constructor.getCurrentLayer()->getOrCreateUserDataContainer(); - if (parseProperties(cur, *udc)) - { - OSG_NOTICE<<"Assigned properties to Layer"< timeout = new osgPresentation::Timeout(_hudSettings.get()); if (_currentLayer.valid()) _currentLayer->addChild(timeout.get()); _currentLayer = timeout.get(); + return timeout.release(); } void SlideShowConstructor::pushCurrentLayer() diff --git a/src/osgPresentation/Timeout.cpp b/src/osgPresentation/Timeout.cpp index 57c3007a4..0a13df31b 100644 --- a/src/osgPresentation/Timeout.cpp +++ b/src/osgPresentation/Timeout.cpp @@ -184,6 +184,12 @@ void Timeout::traverse(osg::NodeVisitor& nv) OSG_NOTICE<<"Do action"<getReferenceTime(); + + if (_jumpData.requiresJump()) + { + OSG_NOTICE<<"Doing jump"<