Added support for naming slides and layers with slide_name and layer_name properties respectively.

Added support for creating events based on key presses using a <key_to_run> and <key_to_jump> tags.
This commit is contained in:
Robert Osfield 2012-11-09 21:32:54 +00:00
parent fd4126dc59
commit ff476e9c15
8 changed files with 424 additions and 183 deletions

View File

@ -27,9 +27,9 @@ class OSGPRESENTATION_EXPORT PickEventHandler : public osgGA::GUIEventHandler
{ {
public: public:
PickEventHandler(osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); PickEventHandler(osgPresentation::Operation operation, const JumpData& jumpData=JumpData());
PickEventHandler(const std::string& str, osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); PickEventHandler(const std::string& str, osgPresentation::Operation operation, const JumpData& jumpData=JumpData());
PickEventHandler(const osgPresentation::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); PickEventHandler(const osgPresentation::KeyPosition& keyPos, const JumpData& jumpData=JumpData());
void setOperation(osgPresentation::Operation operation) { _operation = operation; } void setOperation(osgPresentation::Operation operation) { _operation = operation; }
osgPresentation::Operation getOperation() const { return _operation; } osgPresentation::Operation getOperation() const { return _operation; }
@ -40,15 +40,9 @@ class OSGPRESENTATION_EXPORT PickEventHandler : public osgGA::GUIEventHandler
void setKeyPosition(const osgPresentation::KeyPosition& keyPos) { _keyPos = keyPos; } void setKeyPosition(const osgPresentation::KeyPosition& keyPos) { _keyPos = keyPos; }
const osgPresentation::KeyPosition& getKeyPosition() const { return _keyPos; } const osgPresentation::KeyPosition& getKeyPosition() const { return _keyPos; }
void setRelativeJump(int slideDelta, int layerDelta); void setJumpData(const JumpData& jumpData) { _jumpData = jumpData; }
void setAbsoluteJump(int slideNum, int layerNum); const JumpData& getJumpData() const { return _jumpData; }
bool getRelativeJump() const { return _relativeJump; }
int getSlideNum() const { return _slideNum; }
int getLayerNum() const { return _layerNum; }
bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; }
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object* object, osg::NodeVisitor* nv);
virtual void accept(osgGA::GUIEventHandlerVisitor& v); virtual void accept(osgGA::GUIEventHandlerVisitor& v);
@ -61,9 +55,7 @@ class OSGPRESENTATION_EXPORT PickEventHandler : public osgGA::GUIEventHandler
osgPresentation::KeyPosition _keyPos; osgPresentation::KeyPosition _keyPos;
osgPresentation::Operation _operation; osgPresentation::Operation _operation;
bool _relativeJump; JumpData _jumpData;
int _slideNum;
int _layerNum;
}; };
} }

View File

@ -26,6 +26,9 @@
namespace osgPresentation namespace osgPresentation
{ {
// forward declare
class SlideEventHandler;
/// Operations related to click to run/load/key events. /// Operations related to click to run/load/key events.
enum Operation enum Operation
{ {
@ -35,6 +38,60 @@ enum Operation
JUMP JUMP
}; };
struct JumpData
{
JumpData():
relativeJump(false),
slideNum(0),
layerNum(0) {}
JumpData(bool in_relativeJump, int in_slideNum, int in_layerNum):
relativeJump(in_relativeJump),
slideNum(in_slideNum),
layerNum(in_layerNum) {}
JumpData(const std::string& in_slideName, const std::string& in_layerName):
relativeJump(false),
slideNum(-1),
layerNum(-1),
slideName(in_slideName),
layerName(in_layerName) {}
JumpData(const JumpData& rhs):
relativeJump(rhs.relativeJump),
slideNum(rhs.slideNum),
layerNum(rhs.layerNum),
slideName(rhs.slideName),
layerName(rhs.layerName) {}
JumpData& operator = (const JumpData& rhs)
{
if (&rhs==this) return *this;
relativeJump = rhs.relativeJump;
slideNum = rhs.slideNum;
layerNum = rhs.layerNum;
slideName = rhs.slideName;
layerName = rhs.layerName;
return *this;
}
bool requiresJump() const
{
if (!slideName.empty() || !layerName.empty()) return true;
return relativeJump ? (slideNum!=0 || layerNum!=0) : true;
}
bool jump(SlideEventHandler* seh) const;
bool relativeJump;
int slideNum;
int layerNum;
std::string slideName;
std::string layerName;
};
struct HomePosition : public virtual osg::Referenced struct HomePosition : public virtual osg::Referenced
{ {
HomePosition() {} HomePosition() {}
@ -76,8 +133,8 @@ struct LayerCallback : public virtual osg::Referenced
struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced
{ {
LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {} LayerAttributes():_duration(0) {}
LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {} LayerAttributes(double in_duration):_duration(in_duration) {}
void setDuration(double duration) { _duration = duration; } void setDuration(double duration) { _duration = duration; }
double getDuration() const { return _duration; } double getDuration() const { return _duration; }
@ -95,26 +152,13 @@ struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced
void addRunString(const std::string& runString) { _runStrings.push_back(runString); } void addRunString(const std::string& runString) { _runStrings.push_back(runString); }
void setJump(bool relativeJump, int slideNum, int layerNum) void setJump(const JumpData& jumpData) { _jumpData = jumpData; }
{ const JumpData& getJumpData() const { return _jumpData; }
_relativeJump = relativeJump;
_slideNum = slideNum;
_layerNum = layerNum;
}
bool getRelativeJump() const { return _relativeJump; } double _duration;
int getSlideNum() const { return _slideNum; } Keys _keys;
int getLayerNum() const { return _layerNum; } RunStrings _runStrings;
JumpData _jumpData;
bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; }
double _duration;
Keys _keys;
RunStrings _runStrings;
bool _relativeJump;
int _slideNum;
int _layerNum;
void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); } void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); }
void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); } void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); }
@ -144,9 +188,6 @@ struct dereference_less
} }
}; };
// forward declare
class SlideEventHandler;
struct ObjectOperator : public osg::Referenced struct ObjectOperator : public osg::Referenced
{ {
inline bool operator < (const ObjectOperator& rhs) const { return ptr() < rhs.ptr(); } inline bool operator < (const ObjectOperator& rhs) const { return ptr() < rhs.ptr(); }
@ -282,6 +323,8 @@ public:
osgViewer::Viewer* getViewer() { return _viewer.get(); } osgViewer::Viewer* getViewer() { return _viewer.get(); }
osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); }
enum WhichPosition enum WhichPosition
{ {
FIRST_POSITION = 0, FIRST_POSITION = 0,
@ -296,6 +339,9 @@ public:
int getActiveSlide() const { return _activeSlide; } int getActiveSlide() const { return _activeSlide; }
int getActiveLayer() const { return _activeLayer; } int getActiveLayer() const { return _activeLayer; }
osg::Switch* getSlide(int slideNum);
osg::Node* getLayer(int slideNum, int layerNum);
bool selectSlide(int slideNum,int layerNum=FIRST_POSITION); bool selectSlide(int slideNum,int layerNum=FIRST_POSITION);
bool selectLayer(int layerNum); bool selectLayer(int layerNum);

View File

@ -79,6 +79,7 @@ public:
enum CoordinateFrame { SLIDE, MODEL }; enum CoordinateFrame { SLIDE, MODEL };
LayerAttributes* getOrCreateLayerAttributes(osg::Node* node); LayerAttributes* getOrCreateLayerAttributes(osg::Node* node);
void setDuration(osg::Node* node,double duration) void setDuration(osg::Node* node,double duration)
@ -96,9 +97,9 @@ public:
getOrCreateLayerAttributes(node)->addRunString(runString); getOrCreateLayerAttributes(node)->addRunString(runString);
} }
void setJump(osg::Node* node, bool relativeJump, int slideNum, int layerNum) void setJump(osg::Node* node, const JumpData& jumpData)
{ {
getOrCreateLayerAttributes(node)->setJump(relativeJump, slideNum, layerNum); getOrCreateLayerAttributes(node)->setJump(jumpData);
} }
void addPresentationKey(const KeyPosition& kp) void addPresentationKey(const KeyPosition& kp)
@ -125,10 +126,10 @@ public:
if (_slide.valid()) addRunString(_slide.get(),runString); if (_slide.valid()) addRunString(_slide.get(),runString);
} }
void setSlideJump(bool relativeJump, int switchNum, int layerNum) void setSlideJump(const JumpData& jumpData)
{ {
if (!_slide) addSlide(); if (!_slide) addSlide();
if (_slide.valid()) setJump(_slide.get(),relativeJump, switchNum, layerNum); if (_slide.valid()) setJump(_slide.get(),jumpData);
} }
void addLayerKey(const KeyPosition& kp) void addLayerKey(const KeyPosition& kp)
@ -144,10 +145,10 @@ public:
} }
void setLayerJump(bool relativeJump, int switchNum, int layerNum) void setLayerJump(const JumpData& jumpData)
{ {
if (!_currentLayer) addLayer(); if (!_currentLayer) addLayer();
if (_currentLayer.valid()) setJump(_currentLayer.get(),relativeJump, switchNum, layerNum); if (_currentLayer.valid()) setJump(_currentLayer.get(),jumpData);
} }
@ -334,7 +335,6 @@ public:
osg::Vec4 color; osg::Vec4 color;
}; };
SlideShowConstructor(osgDB::Options* options); SlideShowConstructor(osgDB::Options* options);
void createPresentation(); void createPresentation();
@ -404,9 +404,21 @@ public:
PositionData& getModelPositionDataDefault() { return _modelPositionDataDefault; } PositionData& getModelPositionDataDefault() { return _modelPositionDataDefault; }
void layerClickToDoOperation(Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); enum PresentationContext {
void layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); CURRENT_PRESENTATION,
void layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); CURRENT_SLIDE,
CURRENT_LAYER
};
void addEventHandler(PresentationContext presentationContext, osg::ref_ptr<osgGA::GUIEventHandler> handler);
void keyToDoOperation(PresentationContext presentationContext, int key, Operation operation, const JumpData& jumpData=JumpData());
void keyToDoOperation(PresentationContext presentationContext, int key, const std::string& command, Operation operation, const JumpData& jumpData=JumpData());
void keyEventOperation(PresentationContext presentationContext, int key, const KeyPosition& keyPos, const JumpData& jumpData=JumpData());
void layerClickToDoOperation(Operation operation, const JumpData& jumpData=JumpData());
void layerClickToDoOperation(const std::string& command, Operation operation, const JumpData& jumpData=JumpData());
void layerClickEventOperation(const KeyPosition& keyPos, const JumpData& jumpData=JumpData());
void addToCurrentLayer(osg::Node* subgraph); void addToCurrentLayer(osg::Node* subgraph);
@ -540,7 +552,9 @@ protected:
osg::ref_ptr<FilePathData> _filePathData; osg::ref_ptr<FilePathData> _filePathData;
osg::ref_ptr<osg::Group> _layerToApplyEventCallbackTo; osg::ref_ptr<osg::Group> _layerToApplyEventCallbackTo;
osg::ref_ptr<osgGA::GUIEventHandler> _currentEventCallbackToApply;
typedef std::list< osg::ref_ptr<osgGA::GUIEventHandler> > EventHandlerList;
EventHandlerList _currentEventCallbacksToApply;
std::string findFileAndRecordPath(const std::string& filename); std::string findFileAndRecordPath(const std::string& filename);

View File

@ -178,6 +178,7 @@ public:
inline bool read(const std::string& str, osg::Vec4& value) const; inline bool read(const std::string& str, osg::Vec4& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token) const; bool getProperty(osgDB::XmlNode*cur, const char* token) const;
bool getKeyProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const; bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const; bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const;
bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const; bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const;
@ -195,7 +196,7 @@ public:
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const; bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const; bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const; bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const;
bool getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const; bool getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const;
bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const;
@ -380,6 +381,40 @@ bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int&
return read(itr->second,value); return read(itr->second,value);
} }
bool ReaderWriterP3DXML::getKeyProperty(osgDB::XmlNode*cur, const char* token, int& value) const
{
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
if (itr==cur->properties.end()) return false;
OSG_NOTICE<<"getKeyProperty()="<<itr->second<<std::endl;
if (itr->second.empty())
{
OSG_NOTICE<<" empty()"<<std::endl;
return false;
}
if (itr->second.find("0x",0,2)!=std::string::npos)
{
std::istringstream iss(itr->second);
iss>>std::hex>>value;
return true;
}
else if (itr->second.size()>1 && (itr->second[0]>='0' && itr->second[0]<='9'))
{
std::istringstream iss(itr->second);
iss>>value;
OSG_NOTICE<<" numeric result = "<<value<<std::endl;
return true;
}
else
{
value = itr->second[0];
OSG_NOTICE<<" alphanumeric result = "<<value<<std::endl;
return true;
}
}
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const
{ {
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
@ -922,19 +957,31 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
return propertiesRead; return propertiesRead;
} }
bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const
{ {
bool propertyRead = false; bool propertyRead = false;
if (getProperty(cur, "slide", slideNum)) if (getProperty(cur, "slide_name", jumpData.slideName))
{ {
OSG_INFO<<"slide "<<slideNum<<std::endl; OSG_INFO<<"slide_name "<<jumpData.slideName<<std::endl;
propertyRead = true; propertyRead = true;
} }
if (getProperty(cur, "layer", layerNum)) if (getProperty(cur, "slide", jumpData.slideNum))
{ {
OSG_INFO<<"layer "<<layerNum<<std::endl; OSG_INFO<<"slide "<<jumpData.slideNum<<std::endl;
propertyRead = true;
}
if (getProperty(cur, "layer", jumpData.layerNum))
{
OSG_INFO<<"layer "<<jumpData.layerNum<<std::endl;
propertyRead = true;
}
if (getProperty(cur, "layer_name", jumpData.layerName))
{
OSG_INFO<<"layer_name "<<jumpData.layerName<<std::endl;
propertyRead = true; propertyRead = true;
} }
@ -943,7 +990,7 @@ bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJum
{ {
OSG_INFO<<"jump "<<jumpType<<std::endl; OSG_INFO<<"jump "<<jumpType<<std::endl;
propertyRead = true; propertyRead = true;
relativeJump = (jumpType=="relative") || (jumpType=="Relative") || (jumpType=="RELATIVE") ; jumpData.relativeJump = (jumpType=="relative") || (jumpType=="Relative") || (jumpType=="RELATIVE") ;
} }
return propertyRead; return propertyRead;
@ -1245,59 +1292,104 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
{ {
OSG_INFO<<"Parsed Jump "<<std::endl; OSG_INFO<<"Parsed Jump "<<std::endl;
bool relativeJump = true; osgPresentation::JumpData jumpData;
int slideNum = 0; if (getJumpProperties(cur, jumpData))
int layerNum = 0;
if (getJumpProperties(cur, relativeJump, slideNum, layerNum))
{ {
OSG_INFO<<"Layer Jump "<<relativeJump<<","<< slideNum<<", "<<layerNum<<std::endl; OSG_INFO<<"Layer Jump "<<jumpData.relativeJump<<","<< jumpData.slideNum<<", "<<jumpData.layerNum<<std::endl;
constructor.setLayerJump(relativeJump, slideNum, layerNum); constructor.setLayerJump(jumpData);
} }
} }
else if (cur->name == "click_to_run") else if (cur->name == "click_to_run")
{ {
bool relativeJump = true; osgPresentation::JumpData jumpData;
int slideNum = 0; getJumpProperties(cur, jumpData);
int layerNum = 0;
getJumpProperties(cur, relativeJump, slideNum, layerNum);
OSG_INFO<<"click_to_run ["<<cur->contents<<"]"<<std::endl; OSG_INFO<<"click_to_run ["<<cur->contents<<"]"<<std::endl;
constructor.layerClickToDoOperation(cur->contents,osgPresentation::RUN, relativeJump, slideNum, layerNum); constructor.layerClickToDoOperation(cur->contents,osgPresentation::RUN, jumpData);
} }
else if (cur->name == "click_to_load") else if (cur->name == "click_to_load")
{ {
bool relativeJump = true; osgPresentation::JumpData jumpData;
int slideNum = 0; getJumpProperties(cur, jumpData);
int layerNum = 0;
getJumpProperties(cur, relativeJump, slideNum, layerNum);
OSG_INFO<<"click_to_load ["<<cur->contents<<"]"<<std::endl; OSG_INFO<<"click_to_load ["<<cur->contents<<"]"<<std::endl;
constructor.layerClickToDoOperation(cur->contents,osgPresentation::LOAD, relativeJump, slideNum, layerNum); constructor.layerClickToDoOperation(cur->contents,osgPresentation::LOAD, jumpData);
} }
else if (cur->name == "click_to_event") else if (cur->name == "click_to_event")
{ {
bool relativeJump = true; osgPresentation::JumpData jumpData;
int slideNum = 0; getJumpProperties(cur, jumpData);
int layerNum = 0;
getJumpProperties(cur, relativeJump, slideNum, layerNum);
if (getKeyPositionInner( cur, keyPosition)) if (getKeyPositionInner( cur, keyPosition))
{ {
OSG_INFO<<"click_to_event ["<<keyPosition._key<<"]"<<std::endl; OSG_INFO<<"click_to_event ["<<keyPosition._key<<"]"<<std::endl;
constructor.layerClickEventOperation(keyPosition, relativeJump, slideNum, layerNum); constructor.layerClickEventOperation(keyPosition, jumpData);
} }
} }
else if (cur->name == "click_to_jump") else if (cur->name == "click_to_jump")
{ {
bool relativeJump = true; osgPresentation::JumpData jumpData;
int slideNum = 0; getJumpProperties(cur, jumpData);
int layerNum = 0;
getJumpProperties(cur, relativeJump, slideNum, layerNum);
constructor.layerClickEventOperation(osgPresentation::JUMP, relativeJump, slideNum, layerNum); constructor.layerClickEventOperation(osgPresentation::JUMP, jumpData);
}
else if (cur->name == "key_to_run")
{
int key;
if (getKeyProperty(cur, "key", key))
{
osgPresentation::JumpData jumpData;
getJumpProperties(cur, jumpData);
OSG_NOTICE<<"key_to_run ["<<cur->contents<<"], key="<<key<<std::endl;
constructor.keyToDoOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, cur->contents,osgPresentation::RUN, jumpData);
}
}
else if (cur->name == "key_to_load")
{
int key;
if (getKeyProperty(cur, "key", key))
{
osgPresentation::JumpData jumpData;
getJumpProperties(cur, jumpData);
OSG_NOTICE<<"key_to_load ["<<cur->contents<<"]"<<std::endl;
constructor.keyToDoOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, cur->contents,osgPresentation::LOAD, jumpData);
}
}
else if (cur->name == "key_to_event")
{
int key;
if (getKeyProperty(cur, "key", key))
{
osgPresentation::JumpData jumpData;
getJumpProperties(cur, jumpData);
if (getKeyPositionInner( cur, keyPosition))
{
OSG_NOTICE<<"key_to_event ["<<keyPosition._key<<"]"<<std::endl;
constructor.keyEventOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, keyPosition, jumpData);
}
}
}
else if (cur->name == "key_to_jump")
{
int key;
if (getKeyProperty(cur, "key", key))
{
osgPresentation::JumpData jumpData;
getJumpProperties(cur, jumpData);
OSG_NOTICE<<"key_to_jump"<<std::endl;
constructor.keyEventOperation(osgPresentation::SlideShowConstructor::CURRENT_LAYER, key, osgPresentation::JUMP, jumpData);
}
} }
else if (cur->name == "newline") else if (cur->name == "newline")
@ -1449,6 +1541,19 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
constructor.translateTextCursor(osg::Vec3(-totalIndent,0.0f,0.0f)); constructor.translateTextCursor(osg::Vec3(-totalIndent,0.0f,0.0f));
} }
std::string name;
if (getProperty(root, "layer_name", name))
{
if (constructor.getCurrentLayer())
{
constructor.getCurrentLayer()->setUserValue("name",name);
OSG_NOTICE<<"Setting current layers name "<<name<<std::endl;
}
else
{
OSG_NOTICE<<"getCurrentSlide() returns NULL, unable to set name "<<std::endl;
}
}
} }
void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const
@ -1657,6 +1762,7 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
{ {
constructor.addLayer(true, true); constructor.addLayer(true, true);
parseLayer (constructor, cur); parseLayer (constructor, cur);
} }
else if (cur->name == "layer") else if (cur->name == "layer")
{ {
@ -1697,6 +1803,20 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
} }
} }
std::string name;
if (getProperty(root, "slide_name", name))
{
if (constructor.getCurrentSlide())
{
constructor.getCurrentSlide()->setUserValue("name",name);
OSG_NOTICE<<"Setting current slide name "<<name<<std::endl;
}
else
{
OSG_NOTICE<<"getCurrentSlide() returns NULL, unable to set name "<<std::endl;
}
}
constructor.setBackgroundColor(previous_bgcolor,false); constructor.setBackgroundColor(previous_bgcolor,false);
constructor.setTextColor(previous_textcolor); constructor.setTextColor(previous_textcolor);

View File

@ -12,6 +12,7 @@ SET(TARGET_H
${HEADER_PATH}/AnimationMaterial ${HEADER_PATH}/AnimationMaterial
${HEADER_PATH}/CompileSlideCallback ${HEADER_PATH}/CompileSlideCallback
${HEADER_PATH}/PickEventHandler ${HEADER_PATH}/PickEventHandler
${HEADER_PATH}/KeyEventHandler
${HEADER_PATH}/SlideEventHandler ${HEADER_PATH}/SlideEventHandler
${HEADER_PATH}/SlideShowConstructor ${HEADER_PATH}/SlideShowConstructor
) )
@ -21,6 +22,7 @@ SET(TARGET_SRC
AnimationMaterial.cpp AnimationMaterial.cpp
CompileSlideCallback.cpp CompileSlideCallback.cpp
PickEventHandler.cpp PickEventHandler.cpp
KeyEventHandler.cpp
SlideEventHandler.cpp SlideEventHandler.cpp
SlideShowConstructor.cpp SlideShowConstructor.cpp
${OPENSCENEGRAPH_VERSIONINFO_RC} ${OPENSCENEGRAPH_VERSIONINFO_RC}

View File

@ -21,29 +21,23 @@
using namespace osgPresentation; using namespace osgPresentation;
PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): PickEventHandler::PickEventHandler(osgPresentation::Operation operation, const JumpData& jumpData):
_operation(operation), _operation(operation),
_relativeJump(relativeJump), _jumpData(jumpData)
_slideNum(slideNum),
_layerNum(layerNum)
{ {
} }
PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum): PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation, const JumpData& jumpData):
_command(str), _command(str),
_operation(operation), _operation(operation),
_relativeJump(relativeJump), _jumpData(jumpData)
_slideNum(slideNum),
_layerNum(layerNum)
{ {
} }
PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos, const JumpData& jumpData):
_keyPos(keyPos), _keyPos(keyPos),
_operation(osgPresentation::EVENT), _operation(osgPresentation::EVENT),
_relativeJump(relativeJump), _jumpData(jumpData)
_slideNum(slideNum),
_layerNum(layerNum)
{ {
} }
@ -101,21 +95,6 @@ void PickEventHandler::getUsage(osg::ApplicationUsage& /*usage*/) const
{ {
} }
void PickEventHandler::setRelativeJump(int slideNum, int layerNum)
{
_relativeJump = true;
_slideNum = slideNum;
_layerNum = layerNum;
}
void PickEventHandler::setAbsoluteJump(int slideNum, int layerNum)
{
_relativeJump = false;
_slideNum = slideNum;
_layerNum = layerNum;
}
void PickEventHandler::doOperation() void PickEventHandler::doOperation()
{ {
switch(_operation) switch(_operation)
@ -198,29 +177,9 @@ void PickEventHandler::doOperation()
} }
} }
if (requiresJump()) if (_jumpData.requiresJump())
{ {
OSG_NOTICE<<"Requires jump "<<_relativeJump<<", "<<_slideNum<<", "<<_layerNum<<std::endl; _jumpData.jump(SlideEventHandler::instance());
if (_relativeJump)
{
int previousSlide = SlideEventHandler::instance()->getActiveSlide();
int previousLayer = SlideEventHandler::instance()->getActiveLayer();
int newSlide = previousSlide + _slideNum;
int newLayer = previousLayer + _layerNum;
if (newLayer<0)
{
newLayer = 0;
}
OSG_NOTICE<<" jump to "<<newSlide<<", "<<newLayer<<std::endl;
SlideEventHandler::instance()->selectSlide(newSlide, newLayer);
}
else
{
SlideEventHandler::instance()->selectSlide(_slideNum,_layerNum);
}
} }
else else
{ {

View File

@ -23,6 +23,8 @@
#include <osgUtil/TransformCallback> #include <osgUtil/TransformCallback>
#include <osgUtil/GLObjectsVisitor> #include <osgUtil/GLObjectsVisitor>
#include <osgDB/WriteFile>
#include <osgGA/AnimationPathManipulator> #include <osgGA/AnimationPathManipulator>
#include <osgPresentation/AnimationMaterial> #include <osgPresentation/AnimationMaterial>
@ -35,6 +37,75 @@ static osg::observer_ptr<SlideEventHandler> s_seh;
SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); } SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); }
bool JumpData::jump(SlideEventHandler* seh) const
{
OSG_INFO<<"Requires jump "<<relativeJump<<", "<<slideNum<<", "<<layerNum<<", "<<slideName<<", "<<layerName<<std::endl;
int slideNumToUse = slideNum;
int layerNumToUse = layerNum;
if (!slideName.empty())
{
osg::Switch* presentation = seh->getPresentationSwitch();
for(unsigned int i=0; i<presentation->getNumChildren(); ++i)
{
osg::Node* node = seh->getSlide(i);
std::string name;
if (node->getUserValue("name",name) && slideName==name)
{
slideNumToUse = i;
break;
}
}
}
else if (relativeJump)
{
slideNumToUse = seh->getActiveSlide() + slideNum;
}
if (!layerName.empty())
{
osg::Switch* slide = seh->getSlide(slideNumToUse);
if (slide)
{
unsigned int i;
for(i=0; i<slide->getNumChildren(); ++i)
{
osg::Node* node = slide->getChild(i);
std::string name;
if (node->getUserValue("name",name))
{
if (layerName==name)
{
layerNumToUse = i;
break;
}
}
}
if (i==slide->getNumChildren())
{
OSG_INFO<<"Could not find layer with "<<layerName<<std::endl;
}
}
else
{
OSG_INFO<<"No appropriate Slide found."<<std::endl;
}
}
else if (relativeJump)
{
layerNumToUse = seh->getActiveLayer() + layerNum;
}
if (slideNumToUse<0) slideNumToUse = 0;
if (layerNumToUse<0) layerNumToUse = 0;
OSG_INFO<<" jump to "<<slideNumToUse<<", "<<layerNumToUse<<std::endl;
return seh->selectSlide(slideNumToUse,layerNumToUse);
}
void LayerAttributes::callEnterCallbacks(osg::Node* node) void LayerAttributes::callEnterCallbacks(osg::Node* node)
{ {
OSG_INFO<<"LayerAttributes::callEnterCallbacks("<<node<<")"<<std::endl; OSG_INFO<<"LayerAttributes::callEnterCallbacks("<<node<<")"<<std::endl;
@ -441,7 +512,15 @@ void ActiveOperators::collect(osg::Node* incommingNode, osg::NodeVisitor::Traver
_current.clear(); _current.clear();
FindOperatorsVisitor fov(_current, tm); FindOperatorsVisitor fov(_current, tm);
incommingNode->accept(fov);
if (incommingNode)
{
incommingNode->accept(fov);
}
else
{
OSG_NOTICE<<"ActiveOperators::collect() incommingNode="<<incommingNode<<std::endl;
}
OSG_INFO<<"ActiveOperators::collect("<<incommingNode<<")"<<std::endl; OSG_INFO<<"ActiveOperators::collect("<<incommingNode<<")"<<std::endl;
OSG_INFO<<" _previous.size()="<<_previous.size()<<std::endl; OSG_INFO<<" _previous.size()="<<_previous.size()<<std::endl;
@ -1098,6 +1177,21 @@ unsigned int SlideEventHandler::getNumSlides()
else return 0; else return 0;
} }
osg::Switch* SlideEventHandler::getSlide(int slideNum)
{
if (slideNum<0 || slideNum>static_cast<int>(_presentationSwitch->getNumChildren())) return 0;
FindNamedSwitchVisitor findSlide("Slide");
_presentationSwitch->getChild(slideNum)->accept(findSlide);
return findSlide._switch;
}
osg::Node* SlideEventHandler::getLayer(int slideNum, int layerNum)
{
osg::Switch* slide = getSlide(slideNum);
return (slide && (layerNum>=0 && layerNum<static_cast<int>(slide->getNumChildren()))) ? slide->getChild(layerNum) : 0;
}
bool SlideEventHandler::selectSlide(int slideNum,int layerNum) bool SlideEventHandler::selectSlide(int slideNum,int layerNum)
{ {
@ -1245,25 +1339,9 @@ bool SlideEventHandler::nextSlide()
{ {
OSG_INFO<<"nextSlide()"<<std::endl; OSG_INFO<<"nextSlide()"<<std::endl;
LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast<LayerAttributes*>(_slideSwitch->getUserData()) : 0; LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast<LayerAttributes*>(_slideSwitch->getUserData()) : 0;
if (la && la->requiresJump()) if (la && la->getJumpData().requiresJump())
{ {
if (la->getRelativeJump()) return la->getJumpData().jump(this);
{
int previousSlide = getActiveSlide();
int previousLayer = getActiveLayer();
int newSlide = previousSlide + la->getSlideNum();
int newLayer = previousLayer + la->getLayerNum();
if (newLayer<0)
{
newLayer = 0;
}
return selectSlide(newSlide, newLayer);
}
else
{
return selectSlide(la->getSlideNum(),la->getLayerNum());
}
} }
if (selectSlide(_activeSlide+1)) return true; if (selectSlide(_activeSlide+1)) return true;
@ -1294,25 +1372,9 @@ bool SlideEventHandler::nextLayer()
{ {
la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer)); la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer));
if (la->requiresJump()) if (la->getJumpData().requiresJump())
{ {
if (la->getRelativeJump()) return la->getJumpData().jump(this);
{
int previousSlide = getActiveSlide();
int previousLayer = getActiveLayer();
int newSlide = previousSlide + la->getSlideNum();
int newLayer = previousLayer + la->getLayerNum();
if (newLayer<0)
{
newLayer = 0;
}
return selectSlide(newSlide, newLayer);
}
else
{
return selectSlide(la->getSlideNum(),la->getLayerNum());
}
} }
} }

View File

@ -51,6 +51,7 @@
#include <osgPresentation/AnimationMaterial> #include <osgPresentation/AnimationMaterial>
#include <osgPresentation/PickEventHandler> #include <osgPresentation/PickEventHandler>
#include <osgPresentation/KeyEventHandler>
#include <osgManipulator/TabBoxDragger> #include <osgManipulator/TabBoxDragger>
#include <osgManipulator/TabBoxTrackballDragger> #include <osgManipulator/TabBoxTrackballDragger>
@ -199,7 +200,7 @@ SlideShowConstructor::SlideShowConstructor(osgDB::Options* options):
_slideBackgroundAsHUD = false; _slideBackgroundAsHUD = false;
_layerToApplyEventCallbackTo = 0; _layerToApplyEventCallbackTo = 0;
_currentEventCallbackToApply = 0; _currentEventCallbacksToApply.clear();
} }
void SlideShowConstructor::setPresentationAspectRatio(float aspectRatio) void SlideShowConstructor::setPresentationAspectRatio(float aspectRatio)
@ -393,6 +394,7 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
if (!_slide) addSlide(); if (!_slide) addSlide();
_currentLayer = new osg::Group; _currentLayer = new osg::Group;
_currentLayer->setName("Layer");
// OSG_NOTICE<<"addLayer"<<std::endl; // OSG_NOTICE<<"addLayer"<<std::endl;
@ -542,14 +544,22 @@ void SlideShowConstructor::addToCurrentLayer(osg::Node* subgraph)
if (!_currentLayer) addLayer(); if (!_currentLayer) addLayer();
if (_currentEventCallbackToApply.valid()) OSG_NOTICE<<"_currentEventCallbacksToApply.size()="<<_currentEventCallbacksToApply.size()<<std::endl;
if (!_currentEventCallbacksToApply.empty())
{ {
OSG_NOTICE<<" subgraph->getEventCallback()=="<<subgraph->getEventCallback()<<std::endl;
if (subgraph->getEventCallback()==0) if (subgraph->getEventCallback()==0)
{ {
if (_layerToApplyEventCallbackTo==0 || _currentLayer==_layerToApplyEventCallbackTo) if (_layerToApplyEventCallbackTo==0 || _currentLayer==_layerToApplyEventCallbackTo)
{ {
OSG_INFO<<"Assigning event callback."<<std::endl; OSG_NOTICE<<"Assigning event callbacks."<<std::endl;
subgraph->setEventCallback(_currentEventCallbackToApply.get());
for(EventHandlerList::iterator itr = _currentEventCallbacksToApply.begin();
itr != _currentEventCallbacksToApply.end();
++itr)
{
subgraph->addEventCallback(itr->get());
}
} }
else else
{ {
@ -560,29 +570,65 @@ void SlideShowConstructor::addToCurrentLayer(osg::Node* subgraph)
{ {
OSG_NOTICE<<"Warning: subgraph already has event callback assigned, cannot add second event callback."<<std::endl; OSG_NOTICE<<"Warning: subgraph already has event callback assigned, cannot add second event callback."<<std::endl;
} }
_currentEventCallbackToApply = 0; _currentEventCallbacksToApply.clear();
} }
_currentLayer->addChild(subgraph); _currentLayer->addChild(subgraph);
} }
void SlideShowConstructor::layerClickToDoOperation(Operation operation, bool relativeJump, int slideNum, int layerNum) void SlideShowConstructor::addEventHandler(PresentationContext presentationContext, osg::ref_ptr<osgGA::GUIEventHandler> handler)
{ {
_layerToApplyEventCallbackTo = _currentLayer; switch(presentationContext)
_currentEventCallbackToApply = new PickEventHandler(operation, relativeJump, slideNum, layerNum); {
case(CURRENT_PRESENTATION):
OSG_NOTICE<<"Need to add event handler to presentation."<<std::endl;
break;
case(CURRENT_SLIDE):
OSG_NOTICE<<"Need to add event handler to slide."<<std::endl;
break;
case(CURRENT_LAYER):
OSG_INFO<<"Add event handler to layer."<<std::endl;
_layerToApplyEventCallbackTo = _currentLayer;
_currentEventCallbacksToApply.push_back(handler);
break;
}
}
void SlideShowConstructor::keyToDoOperation(PresentationContext presentationContext, int key, Operation operation, const JumpData& jumpData)
{
OSG_INFO<<"keyToDoOperation(key="<<key<<", operation="<<operation<<")"<<std::endl;
addEventHandler(presentationContext, new KeyEventHandler(key, operation, jumpData));
} }
void SlideShowConstructor::layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump, int slideNum, int layerNum) void SlideShowConstructor::keyToDoOperation(PresentationContext presentationContext, int key, const std::string& command, Operation operation, const JumpData& jumpData)
{ {
_layerToApplyEventCallbackTo = _currentLayer; OSG_INFO<<"keyToDoOperation(key="<<key<<",command="<<command<<")"<<std::endl;
_currentEventCallbackToApply = new PickEventHandler(command, operation, relativeJump, slideNum, layerNum); addEventHandler(presentationContext, new KeyEventHandler(key, command, operation, jumpData));
} }
void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum) void SlideShowConstructor::keyEventOperation(PresentationContext presentationContext, int key, const KeyPosition& keyPos, const JumpData& jumpData)
{ {
_layerToApplyEventCallbackTo = _currentLayer; OSG_INFO<<"keyEventOperation(key="<<key<<")"<<std::endl;
_currentEventCallbackToApply = new PickEventHandler(keyPos, relativeJump, slideNum, layerNum); addEventHandler(presentationContext, new KeyEventHandler(key, keyPos, jumpData));
}
void SlideShowConstructor::layerClickToDoOperation(Operation operation, const JumpData& jumpData)
{
addEventHandler(CURRENT_LAYER, new PickEventHandler(operation, jumpData));
}
void SlideShowConstructor::layerClickToDoOperation(const std::string& command, Operation operation, const JumpData& jumpData)
{
addEventHandler(CURRENT_LAYER, new PickEventHandler(command, operation, jumpData));
}
void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, const JumpData& jumpData)
{
addEventHandler(CURRENT_LAYER, new PickEventHandler(keyPos, jumpData));
} }