Created a simple XmlNode parser class for reading of basic xml files, such as used by present3D.

Converted Present3D across from using libxml2 to using the new osgDB::XmlNode/XmlNode::Input classes from Xml Parsing.
This changes removes the dependency on libxml2, and allows the present3D application and p3d to work on all platforms.
This commit is contained in:
Robert Osfield 2009-04-29 20:30:21 +00:00
parent b42706f034
commit 590ac02859
19 changed files with 1895 additions and 1455 deletions

View File

@ -325,7 +325,6 @@ FIND_PACKAGE(OurDCMTK)
FIND_PACKAGE(OpenAL) FIND_PACKAGE(OpenAL)
FIND_PACKAGE(XUL) FIND_PACKAGE(XUL)
FIND_PACKAGE(FFmpeg) FIND_PACKAGE(FFmpeg)
FIND_PACKAGE(LibXml2)
#use pkg-config to find various modues #use pkg-config to find various modues
INCLUDE(FindPkgConfig OPTIONAL) INCLUDE(FindPkgConfig OPTIONAL)

View File

@ -32,9 +32,7 @@ IF(DYNAMIC_OPENSCENEGRAPH)
ADD_SUBDIRECTORY(osgconv) ADD_SUBDIRECTORY(osgconv)
ADD_SUBDIRECTORY(osgfilecache) ADD_SUBDIRECTORY(osgfilecache)
ADD_SUBDIRECTORY(osgversion) ADD_SUBDIRECTORY(osgversion)
IF(LIBXML2_FOUND) ADD_SUBDIRECTORY(present3D)
ADD_SUBDIRECTORY(present3D)
ENDIF()
ELSE() ELSE()
# need to define this on win32 or linker cries about _declspecs # need to define this on win32 or linker cries about _declspecs
ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC) ADD_DEFINITIONS(-DOSG_LIBRARY_STATIC)

View File

@ -2,6 +2,21 @@ INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR} )
SET(TARGET_EXTERNAL_LIBRARIES ${LIBXML2_LIBRARIES}) SET(TARGET_EXTERNAL_LIBRARIES ${LIBXML2_LIBRARIES})
SET(TARGET_SRC SET(TARGET_SRC
AnimationMaterial.cpp
Cluster.cpp
CompileSlideCallback.cpp
ExportHTML.cpp
PickEventHandler.cpp
PointsEventHandler.cpp
present3D.cpp
ReaderWriterP3D.cpp
ReadShowFile.cpp
ShowEventHandler.cpp
SlideEventHandler.cpp
SlideShowConstructor.cpp
)
SET(TARGET_H
AnimationMaterial.h AnimationMaterial.h
Cluster.h Cluster.h
CompileSlideCallback.h CompileSlideCallback.h
@ -14,21 +29,6 @@ SET(TARGET_SRC
SlideShowConstructor.h SlideShowConstructor.h
) )
SET(TARGET_H
AnimationMaterial.cpp
Cluster.cpp
CompileSlideCallback.cpp
ExportHTML.cpp
PickEventHandler.cpp
PointsEventHandler.cpp
present3D.cpp
ReaderWriterXML.cpp
ReadShowFile.cpp
ShowEventHandler.cpp
SlideEventHandler.cpp
SlideShowConstructor.cpp
)
IF (SDL_FOUND) IF (SDL_FOUND)
OPTION(BUILD_WITH_SDL "Set to ON to build with SDL for joystick support." OFF) OPTION(BUILD_WITH_SDL "Set to ON to build with SDL for joystick support." OFF)
@ -56,4 +56,4 @@ ENDIF(SDL_FOUND)
SET(TARGET_ADDED_LIBRARIES osgVolume osgFX) SET(TARGET_ADDED_LIBRARIES osgVolume osgFX)
SETUP_APPLICATION(present3D) SETUP_APPLICATION(present3D-osg)

View File

@ -24,8 +24,7 @@
#include <osgVolume/VolumeTile> #include <osgVolume/VolumeTile>
#include <libxml/xmlmemory.h> #include <osgDB/XmlParser>
#include <libxml/parser.h>
#include <string.h> #include <string.h>
@ -107,10 +106,14 @@ bool p3d::readEnvVars(const std::string& fileName)
!osgDB::equalCaseInsensitive(ext,"p3d")) return false; !osgDB::equalCaseInsensitive(ext,"p3d")) return false;
xmlDocPtr doc; osg::ref_ptr<osgDB::XmlNode> doc = new osgDB::XmlNode;
xmlNodePtr cur; osgDB::XmlNode* root = 0;
doc = xmlParseFile(fileName.c_str()); osgDB::XmlNode::Input input;
input.open(fileName);
input.readAllDataIntoBuffer();
doc->read(input);
if (doc == NULL ) if (doc == NULL )
{ {
@ -118,50 +121,43 @@ bool p3d::readEnvVars(const std::string& fileName)
return false; return false;
} }
cur = xmlDocGetRootElement(doc); for(osgDB::XmlNode::Children::iterator itr = doc->children.begin();
itr != doc->children.end() && !root;
if (cur == NULL) ++itr)
{ {
fprintf(stderr,"empty document\n"); if ((*itr)->name=="presentation") root = itr->get();
xmlFreeDoc(doc);
return false;
} }
if (xmlStrcmp(cur->name, (const xmlChar *) "presentation")) if (root == NULL)
{ {
fprintf(stderr,"document of the wrong type, root node != presentation"); fprintf(stderr,"empty document\n");
xmlFreeDoc(doc); return false;
return false;
} }
if (root->name!="presentation")
{
fprintf(stderr,"document of the wrong type, root node != presentation");
return false;
}
bool readVars = false; bool readVars = false;
xmlChar *key; for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
cur = cur->xmlChildrenNode; itr != root->children.end();
while (cur != NULL) { ++itr)
{
osgDB::XmlNode* cur = itr->get();
if ((!xmlStrcmp(cur->name, (const xmlChar *)"env"))) if (cur->name=="env")
{ {
key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); char* str = strdup(cur->contents.c_str());
if (key) osg::notify(osg::INFO)<<"putenv("<<str<<")"<<std::endl;
{ putenv(str);
char* str = strdup((char*)key); readVars = true;
osg::notify(osg::INFO)<<"putenv("<<str<<")"<<std::endl;
putenv(str);
readVars = true;
}
xmlFree(key);
} }
cur = cur->next;
} }
#ifndef __APPLE__ return readVars;
xmlFreeDoc(doc);
#endif
return readVars;
} }
osg::Node* p3d::readHoldingSlide(const std::string& filename) osg::Node* p3d::readHoldingSlide(const std::string& filename)

135
include/osgDB/XmlParser Normal file
View File

@ -0,0 +1,135 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 OSGDB_XML_PARSER
#define OSGDB_XML_PARSER 1
#include <osgDB/Registry>
namespace osgDB {
// forward declare
class XmlNode;
/** read an Xml file, find the file in ReaderWriter::Options DataFilePathList.*/
extern OSGDB_EXPORT XmlNode* readXmlFile(const std::string& filename,const ReaderWriter::Options* options);
/** read an Xml file, find the file in osgDB::Registry's eaderWriter::Options DataFilePathList.*/
inline XmlNode* readXmlFile(const std::string& filename)
{
return readXmlFile(filename, osgDB::Registry::instance()->getOptions());
}
/** read an Xml from from an istream.*/
extern OSGDB_EXPORT XmlNode* readXmlStream(std::istream& fin);
/** XmlNode class for very basic reading and writing of xml files.*/
class XmlNode : public osg::Referenced
{
public:
XmlNode();
enum NodeType
{
UNASSIGNED,
ATOM,
NODE,
GROUP,
ROOT,
COMMENT,
INFORMATION
};
typedef std::map< std::string, std::string > Properties;
typedef std::vector< osg::ref_ptr<XmlNode> > Children;
NodeType type;
std::string name;
std::string contents;
Properties properties;
Children children;
public:
class Input
{
public:
Input();
Input(const Input&);
~Input();
typedef std::string::size_type size_type;
void open(const std::string& filename);
void attach(std::istream& istream);
void readAllDataIntoBuffer();
operator bool () const { return _currentPos<_buffer.size(); }
int get() { if (_currentPos<_buffer.size()) return _buffer[_currentPos++]; else return -1; }
int operator [] (size_type i) const { if ((_currentPos+i)<_buffer.size()) return _buffer[_currentPos+i]; else return -1; }
void operator ++ () { if (_currentPos<_buffer.size()) ++_currentPos; }
void operator += (size_type n) { if ((_currentPos+n)<_buffer.size()) _currentPos+=n; else _currentPos = _buffer.size(); }
void skipWhiteSpace();
std::string substr(size_type pos, size_type n=std::string::npos) { return (_currentPos<_buffer.size()) ? _buffer.substr(_currentPos+pos,n) : std::string(); }
size_type find(const std::string& str)
{
if (_currentPos<_buffer.size())
{
size_type pos = _buffer.find(str, _currentPos);
if (pos==std::string::npos) return std::string::npos;
else return pos-_currentPos;
} else return std::string::npos;
}
bool match(const std::string& str) { return (_currentPos<_buffer.size()) ? _buffer.compare(_currentPos, str.size(), str)==0 : false; }
typedef std::map< std::string, int > ControlToCharacterMap;
typedef std::map< int, std::string> CharacterToControlMap;
void addControlToCharacter(const std::string& control, int c);
ControlToCharacterMap _controlToCharacterMap;
CharacterToControlMap _characterToControlMap;
private:
void setUpControlMappings();
size_type _currentPos;
std::ifstream _fin;
std::string _buffer;
};
bool read(Input& input);
bool write(std::ostream& fout) const;
bool writeString(std::ostream& fout, const std::string& str) const;
};
}
#endif

View File

@ -46,6 +46,7 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/SharedStateManager ${HEADER_PATH}/SharedStateManager
${HEADER_PATH}/Version ${HEADER_PATH}/Version
${HEADER_PATH}/WriteFile ${HEADER_PATH}/WriteFile
${HEADER_PATH}/XmlParser
) )
# FIXME: For OS X, need flag for Framework or dylib # FIXME: For OS X, need flag for Framework or dylib
@ -77,6 +78,7 @@ ADD_LIBRARY(${LIB_NAME}
SharedStateManager.cpp SharedStateManager.cpp
Version.cpp Version.cpp
WriteFile.cpp WriteFile.cpp
XmlParser.cpp
${OPENSCENEGRAPH_VERSIONINFO_RC} ${OPENSCENEGRAPH_VERSIONINFO_RC}
) )

View File

@ -139,7 +139,7 @@ DynamicLibrary::PROC_ADDRESS DynamicLibrary::getProcAddress(const std::string& p
if (_handle==NULL) return NULL; if (_handle==NULL) return NULL;
#if defined(WIN32) && !defined(__CYGWIN__) #if defined(WIN32) && !defined(__CYGWIN__)
return (DynamicLibrary::PROC_ADDRESS)GetProcAddress( (HMODULE)_handle, return (DynamicLibrary::PROC_ADDRESS)GetProcAddress( (HMODULE)_handle,
procName.c_str() ); procName.c_str() ); /* FIX WARNING */
#elif defined(__APPLE__) && defined(APPLE_PRE_10_3) #elif defined(__APPLE__) && defined(APPLE_PRE_10_3)
std::string temp("_"); std::string temp("_");
NSSymbol symbol; NSSymbol symbol;

415
src/osgDB/XmlParser.cpp Normal file
View File

@ -0,0 +1,415 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2009 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 <osgDB/XmlParser>
#include <osgDB/FileUtils>
#include <osg/Notify>
using namespace osgDB;
XmlNode* osgDB::readXmlFile(const std::string& filename,const ReaderWriter::Options* options)
{
std::string foundFile = osgDB::findDataFile(filename, options);
if (!foundFile.empty())
{
XmlNode::Input input;
input.open(foundFile);
if (!input)
{
osg::notify(osg::NOTICE)<<"Could not open XML file: "<<filename<<std::endl;
return 0;
}
input.readAllDataIntoBuffer();
osg::ref_ptr<XmlNode> root = new XmlNode;
root->read(input);
return root.release();
}
else
{
osg::notify(osg::NOTICE)<<"Could not find XML file: "<<filename<<std::endl;
return 0;
}
}
XmlNode* osgDB::readXmlStream(std::istream& fin)
{
XmlNode::Input input;
input.attach(fin);
if (!input)
{
osg::notify(osg::NOTICE)<<"Could not attach to XML stream."<<std::endl;
return 0;
}
input.readAllDataIntoBuffer();
osg::ref_ptr<XmlNode> root = new XmlNode;
root->read(input);
return root.release();
}
XmlNode::Input::Input():
_currentPos(0)
{
setUpControlMappings();
}
XmlNode::Input::Input(const Input&):
_currentPos(0)
{
setUpControlMappings();
}
XmlNode::Input::~Input()
{
}
void XmlNode::Input::setUpControlMappings()
{
addControlToCharacter("&amp;",'&');
addControlToCharacter("&lt;",'<');
addControlToCharacter("&gt;",'>');
addControlToCharacter("&quot;",'"');
addControlToCharacter("&apos;",'\'');
}
void XmlNode::Input::addControlToCharacter(const std::string& control, int c)
{
_controlToCharacterMap[control] = c;
_characterToControlMap[c] = control;
}
void XmlNode::Input::open(const std::string& filename)
{
_fin.open(filename.c_str());
}
void XmlNode::Input::attach(std::istream& fin)
{
std::ios &fios = _fin;
fios.rdbuf(fin.rdbuf());
}
void XmlNode::Input::readAllDataIntoBuffer()
{
while(_fin)
{
int c = _fin.get();
if (c>=0 && c<=255)
{
_buffer.push_back(c);
}
}
}
void XmlNode::Input::skipWhiteSpace()
{
while(_currentPos<_buffer.size() && _buffer[_currentPos]==' ') ++_currentPos;
}
XmlNode::XmlNode()
{
type = UNASSIGNED;
}
bool XmlNode::read(Input& input)
{
if (type == UNASSIGNED) type = ROOT;
while(input)
{
//input.skipWhiteSpace();
if (input.match("<!--"))
{
XmlNode* commentNode = new XmlNode;
commentNode->type = XmlNode::COMMENT;
children.push_back(commentNode);
input += 4;
XmlNode::Input::size_type end = input.find("-->");
commentNode->contents = input.substr(0, end);
if (end!=std::string::npos)
{
osg::notify(osg::INFO)<<"Valid Comment record ["<<commentNode->contents<<"]"<<std::endl;
input += (end+3);
}
else
{
osg::notify(osg::NOTICE)<<"Error: Unclosed Comment record ["<<commentNode->contents<<"]"<<std::endl;
input += end;
}
}
else if (input.match("</"))
{
input += 2;
XmlNode::Input::size_type end = input.find(">");
std::string comment = input.substr(0, end);
if (end!=std::string::npos)
{
osg::notify(osg::INFO)<<"Valid end tag ["<<comment<<"]"<<std::endl;
input += (end+1);
}
else
{
osg::notify(osg::NOTICE)<<"Error: Unclosed end tag ["<<comment<<"]"<<std::endl;
input += end;
}
if (comment==name) osg::notify(osg::INFO)<<"end tag is matched correctly"<<std::endl;
else osg::notify(osg::NOTICE)<<"Error: end tag is not matched correctly"<<std::endl;
return true;
}
else if (input.match("<?"))
{
XmlNode* commentNode = new XmlNode;
commentNode->type = XmlNode::INFORMATION;
children.push_back(commentNode);
input += 2;
XmlNode::Input::size_type end = input.find("?>");
commentNode->contents = input.substr(0, end);
if (end!=std::string::npos)
{
osg::notify(osg::INFO)<<"Valid infomation record ["<<commentNode->contents<<"]"<<std::endl;
input += (end+2);
}
else
{
osg::notify(osg::NOTICE)<<"Error: Unclosed infomation record ["<<commentNode->contents<<"]"<<std::endl;
input += end;
}
}
else if (input.match("<"))
{
XmlNode* childNode = new XmlNode;
childNode->type = XmlNode::NODE;
children.push_back(childNode);
input += 1;
input.skipWhiteSpace();
int c = 0;
while ((c=input[0])>=0 && c!=' ' && c!='>' )
{
childNode->name.push_back(c);
++input;
}
while ((c=input[0])>=0 && c!='>')
{
input.skipWhiteSpace();
std::string option;
std::string value;
while((c=input[0])>=0 && c!='>' && c!='"' && c!='\'' && c!='=')
{
option.push_back(c);
++input;
}
input.skipWhiteSpace();
if (input[0]=='=')
{
++input;
if (input[0]=='"')
{
++input;
while((c=input[0])>=0 && c!='"')
{
value.push_back(c);
++input;
}
++input;
}
else if (input[0]=='\'')
{
++input;
while((c=input[0])>=0 && c!='\'')
{
value.push_back(c);
++input;
}
++input;
}
else
{
++input;
while((c=input[0])>=0 && c!=' ' && c!='"' && c!='\'' && c!='>')
{
value.push_back(c);
++input;
}
}
}
if (!option.empty())
{
osg::notify(osg::INFO)<<"Assigning option "<<option<<" with value "<<value<<std::endl;
childNode->properties[option] = value;
}
}
if ((c=input[0])>=0 && c=='>' )
{
++input;
osg::notify(osg::INFO)<<"Valid tag ["<<childNode->name<<"]"<<std::endl;
bool result = childNode->read(input);
if (!result) return false;
if (type==NODE && !children.empty()) type = GROUP;
}
else
{
osg::notify(osg::NOTICE)<<"Unclosed tag ["<<childNode->name<<"]"<<std::endl;
return false;
}
}
else
{
int c = input[0];
if (c=='&')
{
std::string value;
while(input && (c=input.get())!=';') { value.push_back(c); }
value.push_back(c);
if (input._controlToCharacterMap.count(value)!=0)
{
c = input._controlToCharacterMap[value];
osg::notify(osg::INFO)<<"Read control character "<<value<<" converted to "<<char(c)<<std::endl;
contents.push_back(c);
}
else
{
osg::notify(osg::NOTICE)<<"Warning: read control character "<<value<<", but have no mapping to convert it to."<<std::endl;
}
}
else
{
contents.push_back( c );
++input;
}
}
}
if (type==NODE && !children.empty()) type = GROUP;
return false;
}
bool XmlNode::write(std::ostream& fout) const
{
switch(type)
{
case(UNASSIGNED):
return false;
case(ATOM):
{
fout<<"<"<<name;
for(Properties::const_iterator oitr = properties.begin();
oitr != properties.end();
++oitr)
{
fout<<oitr->first<<"\"";
writeString(fout,oitr->second);
fout<<"\""<<std::endl;
}
return true;
}
case(ROOT):
{
for(Children::const_iterator citr = children.begin();
citr != children.end();
++citr)
{
(*citr)->write(fout);
}
return true;
}
case(NODE):
{
fout<<"<"<<name;
for(Properties::const_iterator oitr = properties.begin();
oitr != properties.end();
++oitr)
{
fout<<" "<<oitr->first<<"=\"";
writeString(fout,oitr->second);
fout<<"\"";
}
fout<<">";
for(Children::const_iterator citr = children.begin();
citr != children.end();
++citr)
{
(*citr)->write(fout);
}
if (!contents.empty()) writeString(fout,contents);
fout<<"</"<<name<<">"<<std::endl;
return true;
}
case(GROUP):
{
fout<<"<"<<name;
for(Properties::const_iterator oitr = properties.begin();
oitr != properties.end();
++oitr)
{
fout<<" "<<oitr->first<<"=\"";
writeString(fout,oitr->second);
fout<<"\"";
}
fout<<">"<<std::endl;
for(Children::const_iterator citr = children.begin();
citr != children.end();
++citr)
{
(*citr)->write(fout);
}
fout<<"</"<<name<<">"<<std::endl;
return true;
}
case(COMMENT):
{
fout<<"<!--"<<contents<<"-->"<<std::endl;
return true;
}
case(INFORMATION):
{
fout<<"<?"<<contents<<"?>"<<std::endl;
return true;
}
}
return false;
}
bool XmlNode::writeString(std::ostream& fout, const std::string& str) const
{
fout<<str;
return true;
}

View File

@ -134,9 +134,7 @@ ENDIF()
ADD_SUBDIRECTORY(3dc) ADD_SUBDIRECTORY(3dc)
IF(LIBXML2_FOUND) ADD_SUBDIRECTORY(p3d)
ADD_SUBDIRECTORY(p3d)
ENDIF()
IF(CURL_FOUND) IF(CURL_FOUND)
ADD_SUBDIRECTORY(curl) ADD_SUBDIRECTORY(curl)

View File

@ -1,6 +1,3 @@
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR} )
SET(TARGET_EXTERNAL_LIBRARIES ${LIBXML2_LIBRARIES})
SET(TARGET_SRC SET(TARGET_SRC
SlideShowConstructor.cpp SlideShowConstructor.cpp
ReaderWriterP3D.cpp ReaderWriterP3D.cpp

View File

@ -17,7 +17,9 @@
#include <osg/Notify> #include <osg/Notify>
#include <osgDB/FileUtils> #include <osgDB/FileUtils>
PickEventHandler::PickEventHandler(SlideShowConstructor::Operation operation,bool relativeJump, int slideNum, int layerNum): using namespace osgPresentation;
PickEventHandler::PickEventHandler(osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum):
_operation(operation), _operation(operation),
_relativeJump(relativeJump), _relativeJump(relativeJump),
_slideNum(slideNum), _slideNum(slideNum),
@ -25,7 +27,7 @@ PickEventHandler::PickEventHandler(SlideShowConstructor::Operation operation,boo
{ {
} }
PickEventHandler::PickEventHandler(const std::string& str, SlideShowConstructor::Operation operation,bool relativeJump, int slideNum, int layerNum): PickEventHandler::PickEventHandler(const std::string& str, osgPresentation::Operation operation,bool relativeJump, int slideNum, int layerNum):
_command(str), _command(str),
_operation(operation), _operation(operation),
_relativeJump(relativeJump), _relativeJump(relativeJump),
@ -34,9 +36,9 @@ PickEventHandler::PickEventHandler(const std::string& str, SlideShowConstructor:
{ {
} }
PickEventHandler::PickEventHandler(const SlideShowConstructor::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum): PickEventHandler::PickEventHandler(const osgPresentation::KeyPosition& keyPos,bool relativeJump, int slideNum, int layerNum):
_keyPos(keyPos), _keyPos(keyPos),
_operation(SlideShowConstructor::EVENT), _operation(osgPresentation::EVENT),
_relativeJump(relativeJump), _relativeJump(relativeJump),
_slideNum(slideNum), _slideNum(slideNum),
_layerNum(layerNum) _layerNum(layerNum)
@ -114,13 +116,12 @@ void PickEventHandler::doOperation()
{ {
switch(_operation) switch(_operation)
{ {
case(SlideShowConstructor::RUN): case(osgPresentation::RUN):
{ {
osg::notify(osg::NOTICE)<<"Run "<<_command<<std::endl; osg::notify(osg::NOTICE)<<"Run "<<_command<<std::endl;
#if 0
osgDB::FilePathList& paths = osgDB::getDataFilePathList(); osgDB::FilePathList& paths = osgDB::getDataFilePathList();
#if 0
if (!paths.empty()) if (!paths.empty())
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -164,17 +165,22 @@ void PickEventHandler::doOperation()
break; break;
} }
case(SlideShowConstructor::LOAD): case(osgPresentation::LOAD):
{ {
osg::notify(osg::NOTICE)<<"Load "<<_command<<std::endl; osg::notify(osg::NOTICE)<<"Load "<<_command<<std::endl;
break; break;
} }
case(SlideShowConstructor::EVENT): case(osgPresentation::EVENT):
{ {
osg::notify(osg::INFO)<<"Event "<<_keyPos._key<<" "<<_keyPos._x<<" "<<_keyPos._y<<std::endl; osg::notify(osg::INFO)<<"Event "<<_keyPos._key<<" "<<_keyPos._x<<" "<<_keyPos._y<<std::endl;
if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_keyPos); if (SlideEventHandler::instance()) SlideEventHandler::instance()->dispatchEvent(_keyPos);
break; break;
} }
case(osgPresentation::JUMP):
{
osg::notify(osg::NOTICE)<<"Requires jump "<<std::endl;
break;
}
} }
if (requiresJump()) if (requiresJump())

View File

@ -18,24 +18,27 @@
#include <osgGA/GUIEventHandler> #include <osgGA/GUIEventHandler>
#include "SlideShowConstructor.h" #include "SlideEventHandler.h"
namespace osgPresentation
{
class PickEventHandler : public osgGA::GUIEventHandler class PickEventHandler : public osgGA::GUIEventHandler
{ {
public: public:
PickEventHandler(SlideShowConstructor::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); PickEventHandler(osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0);
PickEventHandler(const std::string& str, SlideShowConstructor::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); PickEventHandler(const std::string& str, osgPresentation::Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0);
PickEventHandler(const SlideShowConstructor::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); PickEventHandler(const osgPresentation::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0);
void setOperation(SlideShowConstructor::Operation operation) { _operation = operation; } void setOperation(osgPresentation::Operation operation) { _operation = operation; }
SlideShowConstructor::Operation getOperation() const { return _operation; } osgPresentation::Operation getOperation() const { return _operation; }
void setCommand(const std::string& str) { _command = str; } void setCommand(const std::string& str) { _command = str; }
const std::string& getCommand() const { return _command; } const std::string& getCommand() const { return _command; }
void setKeyPosition(const SlideShowConstructor::KeyPosition& keyPos) { _keyPos = keyPos; } void setKeyPosition(const osgPresentation::KeyPosition& keyPos) { _keyPos = keyPos; }
const SlideShowConstructor::KeyPosition& getKeyPosition() const { return _keyPos; } const osgPresentation::KeyPosition& getKeyPosition() const { return _keyPos; }
void setRelativeJump(int slideDelta, int layerDelta); void setRelativeJump(int slideDelta, int layerDelta);
void setAbsoluteJump(int slideNum, int layerNum); void setAbsoluteJump(int slideNum, int layerNum);
@ -55,12 +58,14 @@ class PickEventHandler : public osgGA::GUIEventHandler
void doOperation(); void doOperation();
std::string _command; std::string _command;
SlideShowConstructor::KeyPosition _keyPos; osgPresentation::KeyPosition _keyPos;
SlideShowConstructor::Operation _operation; osgPresentation::Operation _operation;
bool _relativeJump; bool _relativeJump;
int _slideNum; int _slideNum;
int _layerNum; int _layerNum;
}; };
}
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -29,11 +29,35 @@
#include <iostream> #include <iostream>
using namespace osgPresentation;
static osg::observer_ptr<SlideEventHandler> s_seh; static osg::observer_ptr<SlideEventHandler> s_seh;
SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); } SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); }
void LayerAttributes::callEnterCallbacks(osg::Node* node)
{
osg::notify(osg::INFO)<<"LayerAttributes::callEnterCallbacks("<<node<<")"<<std::endl;
for(LayerCallbacks::iterator itr = _enterLayerCallbacks.begin();
itr != _enterLayerCallbacks.end();
++itr)
{
(*(*itr))(node);
}
}
void LayerAttributes::callLeaveCallbacks(osg::Node* node)
{
osg::notify(osg::INFO)<<"LayerAttributes::callLeaveCallbacks("<<node<<")"<<std::endl;
for(LayerCallbacks::iterator itr = _leaveLayerCallbacks.begin();
itr != _leaveLayerCallbacks.end();
++itr)
{
(*(*itr))(node);
}
}
struct ImageStreamOperator : public ObjectOperator struct ImageStreamOperator : public ObjectOperator
{ {
ImageStreamOperator(osg::ImageStream* imageStream): ImageStreamOperator(osg::ImageStream* imageStream):
@ -159,7 +183,7 @@ struct CallbackOperator : public ObjectOperator
struct LayerAttributesOperator : public ObjectOperator struct LayerAttributesOperator : public ObjectOperator
{ {
LayerAttributesOperator(osg::Node* node, SlideShowConstructor::LayerAttributes* la): LayerAttributesOperator(osg::Node* node, LayerAttributes* la):
_node(node), _node(node),
_layerAttribute(la) _layerAttribute(la)
{ {
@ -175,7 +199,7 @@ struct LayerAttributesOperator : public ObjectOperator
{ {
osg::notify(osg::INFO)<<"applyKeys {"<<std::endl; osg::notify(osg::INFO)<<"applyKeys {"<<std::endl;
for(SlideShowConstructor::LayerAttributes::Keys::iterator itr = _layerAttribute->_keys.begin(); for(LayerAttributes::Keys::iterator itr = _layerAttribute->_keys.begin();
itr != _layerAttribute->_keys.end(); itr != _layerAttribute->_keys.end();
++itr) ++itr)
{ {
@ -186,7 +210,7 @@ struct LayerAttributesOperator : public ObjectOperator
} }
if (!_layerAttribute->_runStrings.empty()) if (!_layerAttribute->_runStrings.empty())
{ {
for(SlideShowConstructor::LayerAttributes::RunStrings::iterator itr = _layerAttribute->_runStrings.begin(); for(LayerAttributes::RunStrings::iterator itr = _layerAttribute->_runStrings.begin();
itr != _layerAttribute->_runStrings.end(); itr != _layerAttribute->_runStrings.end();
++itr) ++itr)
{ {
@ -232,7 +256,7 @@ struct LayerAttributesOperator : public ObjectOperator
osg::ref_ptr<osg::Node> _node; osg::ref_ptr<osg::Node> _node;
osg::ref_ptr<SlideShowConstructor::LayerAttributes> _layerAttribute; osg::ref_ptr<LayerAttributes> _layerAttribute;
}; };
@ -252,7 +276,7 @@ public:
_operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback())); _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback()));
} }
SlideShowConstructor::LayerAttributes* la = dynamic_cast<SlideShowConstructor::LayerAttributes*>(node.getUserData()); LayerAttributes* la = dynamic_cast<LayerAttributes*>(node.getUserData());
if (la) if (la)
{ {
_operatorList.insert(new LayerAttributesOperator(&node, la)); _operatorList.insert(new LayerAttributesOperator(&node, la));
@ -409,7 +433,7 @@ public:
void apply(osg::Node& node) void apply(osg::Node& node)
{ {
SlideShowConstructor::HomePosition* homePosition = dynamic_cast<SlideShowConstructor::HomePosition*>(node.getUserData()); HomePosition* homePosition = dynamic_cast<HomePosition*>(node.getUserData());
if (homePosition) if (homePosition)
{ {
_homePosition = homePosition; _homePosition = homePosition;
@ -418,7 +442,7 @@ public:
traverse(node); traverse(node);
} }
osg::ref_ptr<SlideShowConstructor::HomePosition> _homePosition; osg::ref_ptr<HomePosition> _homePosition;
}; };
@ -457,7 +481,7 @@ public:
void apply(osg::Node& node) void apply(osg::Node& node)
{ {
SlideShowConstructor::FilePathData* fdd = dynamic_cast<SlideShowConstructor::FilePathData*>(node.getUserData()); FilePathData* fdd = dynamic_cast<FilePathData*>(node.getUserData());
if (fdd) if (fdd)
{ {
osg::notify(osg::INFO)<<"Recorded FilePathData"<<std::endl; osg::notify(osg::INFO)<<"Recorded FilePathData"<<std::endl;
@ -632,7 +656,7 @@ SlideEventHandler::SlideEventHandler(osgViewer::Viewer* viewer):
_updateOpacityActive(false), _updateOpacityActive(false),
_previousX(0), _previousY(0), _previousX(0), _previousY(0),
_cursorOn(true), _cursorOn(true),
_releaseAndCompileOnEachNewSlide(false), _releaseAndCompileOnEachNewSlide(true),
_firstSlideOrLayerChange(true), _firstSlideOrLayerChange(true),
_tickAtFirstSlideOrLayerChange(0), _tickAtFirstSlideOrLayerChange(0),
_tickAtLastSlideOrLayerChange(0), _tickAtLastSlideOrLayerChange(0),
@ -645,7 +669,7 @@ SlideEventHandler::SlideEventHandler(osgViewer::Viewer* viewer):
double SlideEventHandler::getDuration(const osg::Node* node) const double SlideEventHandler::getDuration(const osg::Node* node) const
{ {
const SlideShowConstructor::LayerAttributes* la = dynamic_cast<const SlideShowConstructor::LayerAttributes*>(node->getUserData()); const LayerAttributes* la = dynamic_cast<const LayerAttributes*>(node->getUserData());
return la ? la->_duration : -1.0; return la ? la->_duration : -1.0;
} }
@ -677,7 +701,7 @@ void SlideEventHandler::set(osg::Node* model)
_timePerSlide = duration; _timePerSlide = duration;
} }
//selectSlide(0); selectSlide(0);
} }
else else
{ {
@ -694,7 +718,7 @@ void SlideEventHandler::set(osg::Node* model)
osg::notify(osg::INFO)<<"Found presentation slide"<<findSlide._switch->getName()<<std::endl; osg::notify(osg::INFO)<<"Found presentation slide"<<findSlide._switch->getName()<<std::endl;
_slideSwitch = findSlide._switch; _slideSwitch = findSlide._switch;
//selectLayer(0); selectLayer(0);
} }
else else
{ {
@ -729,38 +753,8 @@ double SlideEventHandler::getCurrentTimeDelayBetweenSlides() const
} }
void SlideEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev)
{
if (node->getNumChildrenRequiringEventTraversal()>0) traverse(node,nv);
if (ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handleWithCheckAgainstIgnoreHandledEventsMask(*(*itr), *(ev->getActionAdapter()), node, nv);
}
}
}
}
bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{ {
if (!_viewer)
{
_viewer = dynamic_cast<osgViewer::Viewer*>(&aa);
selectSlide(0);
home();
osg::notify(osg::NOTICE)<<"Assigned viewer. to SlideEventHandler"<<std::endl;
}
// else osg::notify(osg::NOTICE)<<"SlideEventHandler::handle()"<<std::endl;
if (ea.getHandled()) return false; if (ea.getHandled()) return false;
switch(ea.getEventType()) switch(ea.getEventType())
@ -1121,7 +1115,7 @@ bool SlideEventHandler::previousLayerOrSlide()
bool SlideEventHandler::nextSlide() bool SlideEventHandler::nextSlide()
{ {
SlideShowConstructor::LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast<SlideShowConstructor::LayerAttributes*>(_slideSwitch->getUserData()) : 0; LayerAttributes* la = _slideSwitch.valid() ? dynamic_cast<LayerAttributes*>(_slideSwitch->getUserData()) : 0;
if (la && la->requiresJump()) if (la && la->requiresJump())
{ {
if (la->getRelativeJump()) if (la->getRelativeJump())
@ -1165,7 +1159,7 @@ bool SlideEventHandler::previousSlide()
bool SlideEventHandler::nextLayer() bool SlideEventHandler::nextLayer()
{ {
SlideShowConstructor::LayerAttributes* la = (_slideSwitch.valid() && _activeLayer>=0) ? dynamic_cast<SlideShowConstructor::LayerAttributes*>(_slideSwitch->getChild(_activeLayer)->getUserData()) : 0; LayerAttributes* la = (_slideSwitch.valid() && _activeLayer>=0) ? dynamic_cast<LayerAttributes*>(_slideSwitch->getChild(_activeLayer)->getUserData()) : 0;
if (la) if (la)
{ {
la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer)); la->callLeaveCallbacks(_slideSwitch->getChild(_activeLayer));
@ -1207,11 +1201,8 @@ void SlideEventHandler::updateOperators()
_activeOperators.collect(_slideSwitch.get()); _activeOperators.collect(_slideSwitch.get());
_activeOperators.process(); _activeOperators.process();
if (_viewer.valid()) UpdateLightVisitor uav(_viewer->getCamera()->getViewMatrix(),0.0f,0.0f);
{ _viewer->getSceneData()->accept(uav);
UpdateLightVisitor uav(_viewer->getCamera()->getViewMatrix(),0.0f,0.0f);
_viewer->getSceneData()->accept(uav);
}
} }
bool SlideEventHandler::home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) bool SlideEventHandler::home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
@ -1298,7 +1289,7 @@ void SlideEventHandler::releaseSlide(unsigned int slideNum)
_presentationSwitch->getChild(slideNum)->accept(globjVisitor); _presentationSwitch->getChild(slideNum)->accept(globjVisitor);
} }
void SlideEventHandler::dispatchEvent(const SlideShowConstructor::KeyPosition& keyPosition) void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition)
{ {
osg::notify(osg::INFO)<<" keyPosition._key "<<keyPosition._key<<" "<<keyPosition._x<<" "<<keyPosition._y<<std::endl; osg::notify(osg::INFO)<<" keyPosition._key "<<keyPosition._key<<" "<<keyPosition._x<<" "<<keyPosition._y<<std::endl;

View File

@ -20,7 +20,117 @@
#include <osgViewer/Viewer> #include <osgViewer/Viewer>
#include "CompileSlideCallback.h" #include "CompileSlideCallback.h"
#include "SlideShowConstructor.h"
namespace osgPresentation
{
/// Operations related to click to run/load/key events.
enum Operation
{
RUN,
LOAD,
EVENT,
JUMP
};
struct HomePosition : public virtual osg::Referenced
{
HomePosition() {}
HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up):
eye(in_eye),
center(in_center),
up(in_up) {}
osg::Vec3 eye;
osg::Vec3 center;
osg::Vec3 up;
};
struct KeyPosition
{
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX):
_key((osgGA::GUIEventAdapter::KeySymbol)key),
_x(x),
_y(y) {}
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX)
{
_key = (osgGA::GUIEventAdapter::KeySymbol)key;
_x = x;
_y = y;
}
osgGA::GUIEventAdapter::KeySymbol _key;
float _x;
float _y;
};
struct LayerCallback : public virtual osg::Referenced
{
virtual void operator() (osg::Node* node) const = 0;
};
struct LayerAttributes : public virtual osg::Referenced
{
LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {}
LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {}
void setDuration(double duration) { _duration = duration; }
double getDuration() const { return _duration; }
typedef std::vector<KeyPosition> Keys;
typedef std::vector<std::string> RunStrings;
void setKeys(const Keys& keys) { _keys = keys; }
const Keys& getKeys() const { return _keys; }
void addKey(const KeyPosition& kp) { _keys.push_back(kp); }
void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; }
const RunStrings& getRunStrings() const { return _runStrings; }
void addRunString(const std::string& runString) { _runStrings.push_back(runString); }
void setJump(bool relativeJump, int slideNum, int layerNum)
{
_relativeJump = relativeJump;
_slideNum = slideNum;
_layerNum = layerNum;
}
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; }
double _duration;
Keys _keys;
RunStrings _runStrings;
bool _relativeJump;
int _slideNum;
int _layerNum;
void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); }
void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); }
void callEnterCallbacks(osg::Node* node);
void callLeaveCallbacks(osg::Node* node);
typedef std::list< osg::ref_ptr<LayerCallback> > LayerCallbacks;
LayerCallbacks _enterLayerCallbacks;
LayerCallbacks _leaveLayerCallbacks;
};
struct FilePathData : public virtual osg::Referenced
{
FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {}
osgDB::FilePathList filePathList;
};
struct dereference_less struct dereference_less
@ -95,9 +205,6 @@ public:
virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); } virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); }
/** Event traversal node callback method.*/
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
virtual void getUsage(osg::ApplicationUsage& usage) const; virtual void getUsage(osg::ApplicationUsage& usage) const;
@ -151,7 +258,7 @@ public:
void setLoopPresentation(bool loop) { _loopPresentation = loop; } void setLoopPresentation(bool loop) { _loopPresentation = loop; }
bool getLoopPresentation() const { return _loopPresentation; } bool getLoopPresentation() const { return _loopPresentation; }
void dispatchEvent(const SlideShowConstructor::KeyPosition& keyPosition); void dispatchEvent(const KeyPosition& keyPosition);
enum ObjectMask enum ObjectMask
{ {
@ -173,13 +280,13 @@ protected:
osg::observer_ptr<osgViewer::Viewer> _viewer; osg::observer_ptr<osgViewer::Viewer> _viewer;
osg::observer_ptr<osg::Switch> _showSwitch; osg::ref_ptr<osg::Switch> _showSwitch;
unsigned int _activePresentation; unsigned int _activePresentation;
osg::observer_ptr<osg::Switch> _presentationSwitch; osg::ref_ptr<osg::Switch> _presentationSwitch;
unsigned int _activeSlide; unsigned int _activeSlide;
osg::observer_ptr<osg::Switch> _slideSwitch; osg::ref_ptr<osg::Switch> _slideSwitch;
unsigned int _activeLayer; unsigned int _activeLayer;
bool _firstTraversal; bool _firstTraversal;
@ -215,4 +322,6 @@ protected:
}; };
}
#endif #endif

View File

@ -50,6 +50,8 @@
#include "AnimationMaterial.h" #include "AnimationMaterial.h"
#include "PickEventHandler.h" #include "PickEventHandler.h"
using namespace osgPresentation;
class SetToTransparentBin : public osg::NodeVisitor class SetToTransparentBin : public osg::NodeVisitor
{ {
public: public:
@ -84,28 +86,6 @@ public:
} }
}; };
void SlideShowConstructor::LayerAttributes::callEnterCallbacks(osg::Node* node)
{
osg::notify(osg::INFO)<<"SlideShowConstructor::LayerAttributes::callEnterCallbacks("<<node<<")"<<std::endl;
for(LayerCallbacks::iterator itr = _enterLayerCallbacks.begin();
itr != _enterLayerCallbacks.end();
++itr)
{
(*(*itr))(node);
}
}
void SlideShowConstructor::LayerAttributes::callLeaveCallbacks(osg::Node* node)
{
osg::notify(osg::INFO)<<"SlideShowConstructor::LayerAttributes::callLeaveCallbacks("<<node<<")"<<std::endl;
for(LayerCallbacks::iterator itr = _leaveLayerCallbacks.begin();
itr != _leaveLayerCallbacks.end();
++itr)
{
(*(*itr))(node);
}
}
SlideShowConstructor::SlideShowConstructor() SlideShowConstructor::SlideShowConstructor()
{ {
_slideDistance = osg::DisplaySettings::instance()->getScreenDistance(); _slideDistance = osg::DisplaySettings::instance()->getScreenDistance();
@ -208,7 +188,7 @@ void SlideShowConstructor::createPresentation()
if (_autoSteppingActive) _root->addDescription("auto"); if (_autoSteppingActive) _root->addDescription("auto");
} }
SlideShowConstructor::LayerAttributes* SlideShowConstructor::getOrCreateLayerAttributes(osg::Node* node) LayerAttributes* SlideShowConstructor::getOrCreateLayerAttributes(osg::Node* node)
{ {
LayerAttributes* la = dynamic_cast<LayerAttributes*>(node->getUserData()); LayerAttributes* la = dynamic_cast<LayerAttributes*>(node->getUserData());
if (!la) if (!la)
@ -294,7 +274,7 @@ void SlideShowConstructor::selectSlide(int slideNum)
{ {
addSlide(); addSlide();
} }
else if (slideNum>=_presentationSwitch->getNumChildren()) else if (slideNum>=static_cast<int>(_presentationSwitch->getNumChildren()))
{ {
addSlide(); addSlide();
} }
@ -329,6 +309,8 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
if (!_slide) addSlide(); if (!_slide) addSlide();
_currentLayer = new osg::Group; _currentLayer = new osg::Group;
// osg::notify(osg::NOTICE)<<"addLayer"<<std::endl;
if (!_previousLayer || !inheritPreviousLayers) if (!_previousLayer || !inheritPreviousLayers)
{ {
@ -336,26 +318,47 @@ void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBas
_imagePositionData = _imagePositionDataDefault; _imagePositionData = _imagePositionDataDefault;
_modelPositionData = _modelPositionDataDefault; _modelPositionData = _modelPositionDataDefault;
// create the background and title.. // osg::notify(osg::NOTICE)<<" new layer background = "<<_slideBackgroundImageFileName<<std::endl;
if (!_slideBackgroundImageFileName.empty())
{
osg::Geometry* backgroundQuad = osg::createTexturedQuadGeometry(_slideOrigin,
osg::Vec3(_slideWidth,0.0f,0.0f),
osg::Vec3(0.0f,0.0f,_slideHeight));
osg::ref_ptr<osg::Image> image = !_slideBackgroundImageFileName.empty() ?
osgDB::readImageFile(_slideBackgroundImageFileName) :
0;
// create the background and title..
if (image.valid())
{
osg::Geode* background = new osg::Geode; osg::Geode* background = new osg::Geode;
osg::StateSet* backgroundStateSet = background->getOrCreateStateSet(); osg::StateSet* backgroundStateSet = background->getOrCreateStateSet();
backgroundStateSet->setAttributeAndModes( backgroundStateSet->setAttributeAndModes(
new osg::PolygonOffset(1.0f,2.0f), new osg::PolygonOffset(1.0f,2.0f),
osg::StateAttribute::ON); osg::StateAttribute::ON);
osg::Texture2D* texture = new osg::Texture2D(osgDB::readImageFile(_slideBackgroundImageFileName));
texture->setResizeNonPowerOfTwoHint(false);
backgroundStateSet->setTextureAttributeAndModes(0,
texture, bool useTextureRectangle = true;
osg::StateAttribute::ON); float s = useTextureRectangle ? image->s() : 1.0;
float t = useTextureRectangle ? image->t() : 1.0;
osg::Geometry* backgroundQuad = osg::createTexturedQuadGeometry(_slideOrigin,
osg::Vec3(_slideWidth,0.0f,0.0f),
osg::Vec3(0.0f,0.0f,_slideHeight),
s, t);
// osg::notify(osg::NOTICE)<<"Image loaded "<<image.get()<<" "<<_slideBackgroundImageFileName<<std::endl;
if (useTextureRectangle)
{
osg::TextureRectangle* texture = new osg::TextureRectangle(image.get());
backgroundStateSet->setTextureAttributeAndModes(0,
texture,
osg::StateAttribute::ON);
}
else
{
osg::Texture2D* texture = new osg::Texture2D(image.get());
texture->setResizeNonPowerOfTwoHint(false);
backgroundStateSet->setTextureAttributeAndModes(0,
texture,
osg::StateAttribute::ON);
}
background->addDrawable(backgroundQuad); background->addDrawable(backgroundQuad);
@ -412,7 +415,7 @@ void SlideShowConstructor::selectLayer(int layerNum)
addSlide(); addSlide();
addLayer(); addLayer();
} }
else if (layerNum>=0 && layerNum<_slide->getNumChildren() && _slide->getChild(layerNum)->asGroup()) else if (layerNum>=0 && layerNum<static_cast<int>(_slide->getNumChildren()) && _slide->getChild(layerNum)->asGroup())
{ {
_currentLayer = _slide->getChild(layerNum)->asGroup(); _currentLayer = _slide->getChild(layerNum)->asGroup();
_previousLayer = _currentLayer; _previousLayer = _currentLayer;
@ -493,7 +496,7 @@ void SlideShowConstructor::layerClickToDoOperation(const std::string& command, O
} }
void SlideShowConstructor::layerClickEventOperation(const SlideShowConstructor::KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum) void SlideShowConstructor::layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump, int slideNum, int layerNum)
{ {
if (!_currentLayer) addLayer(); if (!_currentLayer) addLayer();
@ -1052,7 +1055,7 @@ void SlideShowConstructor::addPDF(const std::string& filename, const PositionDat
addInteractiveImage(filename, positionData, imageData); addInteractiveImage(filename, positionData, imageData);
} }
class SetPageCallback: public SlideShowConstructor::LayerCallback class SetPageCallback: public LayerCallback
{ {
public: public:
SetPageCallback(osgWidget::PdfImage* pdfImage, int pageNum): SetPageCallback(osgWidget::PdfImage* pdfImage, int pageNum):
@ -1421,7 +1424,7 @@ void SlideShowConstructor::addModel(osg::Node* subgraph, const PositionData& pos
void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& positionData) void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& positionData)
{ {
osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC // osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC
std::string foundFile = filename; std::string foundFile = filename;

View File

@ -26,6 +26,10 @@
#include <osgDB/FileUtils> #include <osgDB/FileUtils>
#include "AnimationMaterial.h" #include "AnimationMaterial.h"
#include "SlideEventHandler.h"
namespace osgPresentation
{
class SlideShowConstructor class SlideShowConstructor
{ {
@ -34,98 +38,6 @@ public:
enum CoordinateFrame { SLIDE, MODEL }; enum CoordinateFrame { SLIDE, MODEL };
struct HomePosition : public virtual osg::Referenced
{
HomePosition() {}
HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up):
eye(in_eye),
center(in_center),
up(in_up) {}
osg::Vec3 eye;
osg::Vec3 center;
osg::Vec3 up;
};
struct KeyPosition
{
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX):
_key((osgGA::GUIEventAdapter::KeySymbol)key),
_x(x),
_y(y) {}
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX)
{
_key = (osgGA::GUIEventAdapter::KeySymbol)key;
_x = x;
_y = y;
}
osgGA::GUIEventAdapter::KeySymbol _key;
float _x;
float _y;
};
struct LayerCallback : public virtual osg::Referenced
{
virtual void operator() (osg::Node* node) const = 0;
};
struct LayerAttributes : public virtual osg::Referenced
{
LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {}
LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {}
void setDuration(double duration) { _duration = duration; }
double getDuration() const { return _duration; }
typedef std::vector<KeyPosition> Keys;
typedef std::vector<std::string> RunStrings;
void setKeys(const Keys& keys) { _keys = keys; }
const Keys& getKeys() const { return _keys; }
void addKey(const KeyPosition& kp) { _keys.push_back(kp); }
void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; }
const RunStrings& getRunStrings() const { return _runStrings; }
void addRunString(const std::string& runString) { _runStrings.push_back(runString); }
void setJump(bool relativeJump, int slideNum, int layerNum)
{
_relativeJump = relativeJump;
_slideNum = slideNum;
_layerNum = layerNum;
}
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; }
double _duration;
Keys _keys;
RunStrings _runStrings;
bool _relativeJump;
int _slideNum;
int _layerNum;
void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); }
void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); }
void callEnterCallbacks(osg::Node* node);
void callLeaveCallbacks(osg::Node* node);
typedef std::list< osg::ref_ptr<LayerCallback> > LayerCallbacks;
LayerCallbacks _enterLayerCallbacks;
LayerCallbacks _leaveLayerCallbacks;
};
LayerAttributes* getOrCreateLayerAttributes(osg::Node* node); LayerAttributes* getOrCreateLayerAttributes(osg::Node* node);
@ -198,12 +110,6 @@ public:
if (_currentLayer.valid()) setJump(_currentLayer.get(),relativeJump, switchNum, layerNum); if (_currentLayer.valid()) setJump(_currentLayer.get(),relativeJump, switchNum, layerNum);
} }
struct FilePathData : public virtual osg::Referenced
{
FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {}
osgDB::FilePathList filePathList;
};
struct PositionData struct PositionData
@ -320,14 +226,6 @@ public:
osg::Vec4 color; osg::Vec4 color;
}; };
/// Operations related to click to run/load/key events.
enum Operation
{
RUN,
LOAD,
EVENT,
JUMP
};
SlideShowConstructor(); SlideShowConstructor();
@ -399,7 +297,7 @@ public:
void layerClickToDoOperation(Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); void layerClickToDoOperation(Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0);
void layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0); void layerClickToDoOperation(const std::string& command, Operation operation, bool relativeJump=true, int slideNum=0, int layerNum=0);
void layerClickEventOperation(const SlideShowConstructor::KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0); void layerClickEventOperation(const KeyPosition& keyPos, bool relativeJump=true, int slideNum=0, int layerNum=0);
void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData); void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData);
@ -515,4 +413,6 @@ protected:
}; };
}
#endif #endif

View File

@ -0,0 +1,179 @@
// ***************************************************************************
//
// Generated automatically by genwrapper.
// Please DO NOT EDIT this file!
//
// ***************************************************************************
#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>
#include <osgDB/XmlParser>
// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif
BEGIN_ENUM_REFLECTOR(osgDB::XmlNode::NodeType)
I_DeclaringFile("osgDB/XmlParser");
I_EnumLabel(osgDB::XmlNode::UNASSIGNED);
I_EnumLabel(osgDB::XmlNode::ATOM);
I_EnumLabel(osgDB::XmlNode::NODE);
I_EnumLabel(osgDB::XmlNode::GROUP);
I_EnumLabel(osgDB::XmlNode::ROOT);
I_EnumLabel(osgDB::XmlNode::COMMENT);
I_EnumLabel(osgDB::XmlNode::INFORMATION);
END_REFLECTOR
TYPE_NAME_ALIAS(std::map< std::string COMMA std::string >, osgDB::XmlNode::Properties)
TYPE_NAME_ALIAS(std::vector< osg::ref_ptr< osgDB::XmlNode > >, osgDB::XmlNode::Children)
BEGIN_OBJECT_REFLECTOR(osgDB::XmlNode)
I_DeclaringFile("osgDB/XmlParser");
I_BaseType(osg::Referenced);
I_Constructor0(____XmlNode,
"",
"");
I_Method1(bool, read, IN, osgDB::XmlNode::Input &, input,
Properties::NON_VIRTUAL,
__bool__read__Input_R1,
"",
"");
I_Method1(bool, write, IN, std::ostream &, fout,
Properties::NON_VIRTUAL,
__bool__write__std_ostream_R1,
"",
"");
I_Method2(bool, writeString, IN, std::ostream &, fout, IN, const std::string &, str,
Properties::NON_VIRTUAL,
__bool__writeString__std_ostream_R1__C5_std_string_R1,
"",
"");
I_PublicMemberProperty(osgDB::XmlNode::NodeType, type);
I_PublicMemberProperty(std::string, name);
I_PublicMemberProperty(std::string, contents);
I_PublicMemberProperty(osgDB::XmlNode::Properties, properties);
I_PublicMemberProperty(osgDB::XmlNode::Children, children);
END_REFLECTOR
TYPE_NAME_ALIAS(std::string::size_type, osgDB::XmlNode::Input::size_type)
TYPE_NAME_ALIAS(std::map< std::string COMMA int >, osgDB::XmlNode::Input::ControlToCharacterMap)
TYPE_NAME_ALIAS(std::map< int COMMA std::string >, osgDB::XmlNode::Input::CharacterToControlMap)
BEGIN_VALUE_REFLECTOR(osgDB::XmlNode::Input)
I_DeclaringFile("osgDB/XmlParser");
I_Constructor0(____Input,
"",
"");
I_Constructor1(IN, const osgDB::XmlNode::Input &, x,
Properties::NON_EXPLICIT,
____Input__C5_Input_R1,
"",
"");
I_Method1(void, open, IN, const std::string &, filename,
Properties::NON_VIRTUAL,
__void__open__C5_std_string_R1,
"",
"");
I_Method1(void, attach, IN, std::istream &, istream,
Properties::NON_VIRTUAL,
__void__attach__std_istream_R1,
"",
"");
I_Method0(void, readAllDataIntoBuffer,
Properties::NON_VIRTUAL,
__void__readAllDataIntoBuffer,
"",
"");
I_Method0(int, get,
Properties::NON_VIRTUAL,
__int__get,
"",
"");
I_Method0(void, skipWhiteSpace,
Properties::NON_VIRTUAL,
__void__skipWhiteSpace,
"",
"");
I_MethodWithDefaults2(std::string, substr, IN, osgDB::XmlNode::Input::size_type, pos, , IN, osgDB::XmlNode::Input::size_type, n, std::string::npos,
Properties::NON_VIRTUAL,
__std_string__substr__size_type__size_type,
"",
"");
I_Method1(osgDB::XmlNode::Input::size_type, find, IN, const std::string &, str,
Properties::NON_VIRTUAL,
__size_type__find__C5_std_string_R1,
"",
"");
I_Method1(bool, match, IN, const std::string &, str,
Properties::NON_VIRTUAL,
__bool__match__C5_std_string_R1,
"",
"");
I_Method2(void, addControlToCharacter, IN, const std::string &, control, IN, int, c,
Properties::NON_VIRTUAL,
__void__addControlToCharacter__C5_std_string_R1__int,
"",
"");
I_SimpleProperty(int, ,
__int__get,
0);
I_PublicMemberProperty(osgDB::XmlNode::Input::ControlToCharacterMap, _controlToCharacterMap);
I_PublicMemberProperty(osgDB::XmlNode::Input::CharacterToControlMap, _characterToControlMap);
END_REFLECTOR
BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgDB::XmlNode >)
I_DeclaringFile("osg/ref_ptr");
I_Constructor0(____ref_ptr,
"",
"");
I_Constructor1(IN, osgDB::XmlNode *, ptr,
Properties::NON_EXPLICIT,
____ref_ptr__T_P1,
"",
"");
I_Constructor1(IN, const osg::ref_ptr< osgDB::XmlNode > &, rp,
Properties::NON_EXPLICIT,
____ref_ptr__C5_ref_ptr_R1,
"",
"");
I_Method0(osgDB::XmlNode *, get,
Properties::NON_VIRTUAL,
__T_P1__get,
"",
"");
I_Method0(bool, valid,
Properties::NON_VIRTUAL,
__bool__valid,
"",
"");
I_Method0(osgDB::XmlNode *, release,
Properties::NON_VIRTUAL,
__T_P1__release,
"",
"");
I_Method1(void, swap, IN, osg::ref_ptr< osgDB::XmlNode > &, rp,
Properties::NON_VIRTUAL,
__void__swap__ref_ptr_R1,
"",
"");
I_SimpleProperty(osgDB::XmlNode *, ,
__T_P1__get,
0);
END_REFLECTOR
STD_MAP_REFLECTOR(std::map< int COMMA std::string >)
STD_MAP_REFLECTOR(std::map< std::string COMMA int >)
STD_VECTOR_REFLECTOR(std::vector< osg::ref_ptr< osgDB::XmlNode > >)