Added support for trimming the contents of parsed Xml graph
This commit is contained in:
@@ -33,6 +33,8 @@ inline XmlNode* readXmlFile(const std::string& filename)
|
||||
/** read an Xml from from an istream.*/
|
||||
extern OSGDB_EXPORT XmlNode* readXmlStream(std::istream& fin);
|
||||
|
||||
extern OSGDB_EXPORT std::string trimEnclosingSpaces(const std::string& str);
|
||||
|
||||
/** XmlNode class for very basic reading and writing of xml files.*/
|
||||
class OSGDB_EXPORT XmlNode : public osg::Referenced
|
||||
{
|
||||
@@ -60,6 +62,8 @@ class OSGDB_EXPORT XmlNode : public osg::Referenced
|
||||
Properties properties;
|
||||
Children children;
|
||||
|
||||
std::string getTrimmedContents() const { return trimEnclosingSpaces(contents); }
|
||||
|
||||
public:
|
||||
|
||||
class OSGDB_EXPORT Input
|
||||
|
||||
@@ -45,6 +45,20 @@ XmlNode* osgDB::readXmlFile(const std::string& filename,const Options* options)
|
||||
}
|
||||
}
|
||||
|
||||
std::string osgDB::trimEnclosingSpaces(const std::string& str)
|
||||
{
|
||||
if (str.empty()) return str;
|
||||
|
||||
std::string::size_type start = str.find_first_not_of(' ');
|
||||
if (start==std::string::npos) return std::string();
|
||||
|
||||
std::string::size_type end = str.find_last_not_of(' ');
|
||||
if (end==std::string::npos) return std::string();
|
||||
|
||||
return std::string(str, start, (end-start)+1);
|
||||
}
|
||||
|
||||
|
||||
XmlNode* osgDB::readXmlStream(std::istream& fin)
|
||||
{
|
||||
XmlNode::Input input;
|
||||
@@ -120,7 +134,7 @@ void XmlNode::Input::readAllDataIntoBuffer()
|
||||
|
||||
void XmlNode::Input::skipWhiteSpace()
|
||||
{
|
||||
while(_currentPos<_buffer.size() && _buffer[_currentPos]==' ' || _buffer[_currentPos]=='\t' )
|
||||
while(_currentPos<_buffer.size() && (_buffer[_currentPos]==' ' || _buffer[_currentPos]=='\t'))
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"_currentPos="<<_currentPos<<"_buffer.size()="<<_buffer.size()<<" v="<<_buffer[_currentPos]<<std::endl;
|
||||
++_currentPos;
|
||||
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
result[0] = osg::RadiansToDegrees(result[0]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline bool read(const char* str, int& value) const;
|
||||
inline bool read(const char* str, float& value) const;
|
||||
inline bool read(const char* str, double& value) const;
|
||||
@@ -179,6 +179,7 @@ public:
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const;
|
||||
bool getTrimmedProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const;
|
||||
bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const;
|
||||
|
||||
@@ -215,7 +216,6 @@ public:
|
||||
// reader/writer.
|
||||
REGISTER_OSGPLUGIN(p3d, ReaderWriterP3DXML)
|
||||
|
||||
|
||||
std::string ReaderWriterP3DXML::expandEnvVarsInFileName(const std::string& filename) const
|
||||
{
|
||||
std::string argument(filename);
|
||||
@@ -239,9 +239,8 @@ std::string ReaderWriterP3DXML::expandEnvVarsInFileName(const std::string& filen
|
||||
{
|
||||
start_pos = std::string::npos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return argument;
|
||||
}
|
||||
|
||||
@@ -390,6 +389,14 @@ bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, std:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getTrimmedProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const
|
||||
{
|
||||
osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token);
|
||||
if (itr==cur->properties.end()) return false;
|
||||
value = osgDB::trimEnclosingSpaces(itr->second);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const
|
||||
{
|
||||
osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token);
|
||||
@@ -572,7 +579,7 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
|
||||
propertiesRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "path", str))
|
||||
if (getTrimmedProperty(cur, "path", str))
|
||||
{
|
||||
|
||||
value.absolute_path = false;
|
||||
@@ -583,7 +590,7 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
|
||||
propertiesRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "camera_path", str))
|
||||
if (getTrimmedProperty(cur, "camera_path", str))
|
||||
{
|
||||
value.absolute_path = true;
|
||||
value.inverse_path = true;
|
||||
@@ -617,7 +624,7 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
|
||||
propertiesRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "animation_material", str))
|
||||
if (getTrimmedProperty(cur, "animation_material", str))
|
||||
{
|
||||
value.animation_material_filename = str;
|
||||
|
||||
@@ -625,7 +632,7 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
|
||||
propertiesRead = true;
|
||||
}
|
||||
|
||||
if (getProperty(cur, "animation_name", str))
|
||||
if (getTrimmedProperty(cur, "animation_name", str))
|
||||
{
|
||||
value.animation_name = str;
|
||||
|
||||
@@ -822,7 +829,7 @@ void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& const
|
||||
osgPresentation::SlideShowConstructor::ModelData modelData;// = constructor.getModelData();
|
||||
getProperties(cur,modelData);
|
||||
|
||||
std::string filename = cur->contents;
|
||||
std::string filename = cur->getTrimmedContents();
|
||||
|
||||
if (!filename.empty())
|
||||
{
|
||||
@@ -891,7 +898,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
|
||||
|
||||
// check for any transfer function required
|
||||
std::string transferFunctionFile;
|
||||
if (getProperty(cur, "tf", transferFunctionFile))
|
||||
if (getTrimmedProperty(cur, "tf", transferFunctionFile))
|
||||
{
|
||||
volumeData.transferFunction = readTransferFunctionFile(transferFunctionFile);
|
||||
}
|
||||
@@ -917,7 +924,7 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
|
||||
}
|
||||
}
|
||||
|
||||
std::string filename = cur->contents;
|
||||
std::string filename = cur->getTrimmedContents();
|
||||
if (!filename.empty())
|
||||
{
|
||||
constructor.addVolume(filename,
|
||||
@@ -950,12 +957,12 @@ void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor&
|
||||
if (child->name == "image_left")
|
||||
{
|
||||
getProperties(child,imageDataLeft);
|
||||
filenameLeft = child->contents;
|
||||
filenameLeft = child->getTrimmedContents();
|
||||
}
|
||||
if (child->name == "image_right")
|
||||
{
|
||||
getProperties(child,imageDataRight);
|
||||
filenameRight = child->contents;
|
||||
filenameRight = child->getTrimmedContents();
|
||||
getProperties(cur,imageDataRight);
|
||||
}
|
||||
}
|
||||
@@ -1012,7 +1019,7 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
|
||||
}
|
||||
|
||||
|
||||
std::string key = cur->contents;
|
||||
std::string key = cur->getTrimmedContents();
|
||||
unsigned int keyValue = 0;
|
||||
|
||||
StringKeyMap::const_iterator itr=_stringKeyMap.find(key);
|
||||
@@ -1163,7 +1170,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
|
||||
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
|
||||
getProperties(cur,imageData);
|
||||
|
||||
constructor.addImage(cur->contents,
|
||||
constructor.addImage(cur->getTrimmedContents(),
|
||||
positionRead ? positionData : constructor.getImagePositionData(),
|
||||
imageData);
|
||||
}
|
||||
@@ -1175,7 +1182,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
|
||||
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
|
||||
getProperties(cur,imageData);
|
||||
|
||||
constructor.addVNC(cur->contents,
|
||||
constructor.addVNC(cur->getTrimmedContents(),
|
||||
positionRead ? positionData : constructor.getImagePositionData(),
|
||||
imageData);
|
||||
}
|
||||
@@ -1187,7 +1194,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
|
||||
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
|
||||
getProperties(cur,imageData);
|
||||
|
||||
constructor.addBrowser(cur->contents,
|
||||
constructor.addBrowser(cur->getTrimmedContents(),
|
||||
positionRead ? positionData : constructor.getImagePositionData(),
|
||||
imageData);
|
||||
}
|
||||
@@ -1199,7 +1206,7 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
|
||||
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
|
||||
getProperties(cur,imageData);
|
||||
|
||||
constructor.addPDF(cur->contents,
|
||||
constructor.addPDF(cur->getTrimmedContents(),
|
||||
positionRead ? positionData : constructor.getImagePositionData(),
|
||||
imageData);
|
||||
}
|
||||
@@ -1375,7 +1382,7 @@ void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor&
|
||||
|
||||
constructor.addLayer(true,false);
|
||||
|
||||
constructor.addPDF(cur->contents, positionData, imageData);
|
||||
constructor.addPDF(cur->getTrimmedContents(), positionData, imageData);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1857,7 +1864,10 @@ osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Inp
|
||||
|
||||
osg::notify(osg::INFO)<<"P3D xml file read, now building presentation scene graph."<<std::endl;
|
||||
|
||||
// doc->write(std::cout);
|
||||
#if 0
|
||||
std::ofstream fout("output.p3d");
|
||||
doc->write(fout);
|
||||
#endif
|
||||
|
||||
if (doc == NULL )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user