| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | #include <osg/Notify> |
|---|
| 14 | #include <osg/io_utils> |
|---|
| 15 | |
|---|
| 16 | #include <osgDB/ReaderWriter> |
|---|
| 17 | #include <osgDB/FileNameUtils> |
|---|
| 18 | #include <osgDB/FileUtils> |
|---|
| 19 | #include <osgDB/Registry> |
|---|
| 20 | |
|---|
| 21 | #include <osgWidget/PdfReader> |
|---|
| 22 | |
|---|
| 23 | #include "SlideShowConstructor.h" |
|---|
| 24 | |
|---|
| 25 | #include <stdio.h> |
|---|
| 26 | #include <string.h> |
|---|
| 27 | #include <stdlib.h> |
|---|
| 28 | |
|---|
| 29 | #include <osgDB/XmlParser> |
|---|
| 30 | |
|---|
| 31 | #include <sstream> |
|---|
| 32 | #include <iostream> |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | class ReaderWriterP3DXML : public osgDB::ReaderWriter |
|---|
| 39 | { |
|---|
| 40 | public: |
|---|
| 41 | ReaderWriterP3DXML() |
|---|
| 42 | { |
|---|
| 43 | _colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f); |
|---|
| 44 | _colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f); |
|---|
| 45 | _colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f); |
|---|
| 46 | _colorMap["BLUE"] .set(0.0f,0.0f,1.0f,1.0f); |
|---|
| 47 | _colorMap["RED"] .set(1.0f,0.0f,0.0f,1.0f); |
|---|
| 48 | _colorMap["CYAN"] .set(0.0f,1.0f,1.0f,1.0f); |
|---|
| 49 | _colorMap["YELLOW"] .set(1.0f,1.0f,0.0f,1.0f); |
|---|
| 50 | _colorMap["GREEN"] .set(0.0f,1.0f,0.0f,1.0f); |
|---|
| 51 | _colorMap["SKY"] .set(0.2f, 0.2f, 0.4f, 1.0f); |
|---|
| 52 | |
|---|
| 53 | _layoutMap["LEFT_TO_RIGHT"] = osgText::Text::LEFT_TO_RIGHT; |
|---|
| 54 | _layoutMap["RIGHT_TO_LEFT"] = osgText::Text::RIGHT_TO_LEFT; |
|---|
| 55 | _layoutMap["VERTICAL"] = osgText::Text::VERTICAL; |
|---|
| 56 | |
|---|
| 57 | _alignmentMap["LEFT_TOP"] = osgText::Text::LEFT_TOP; |
|---|
| 58 | _alignmentMap["LEFT_CENTER"] = osgText::Text::LEFT_CENTER; |
|---|
| 59 | _alignmentMap["LEFT_BOTTOM"] = osgText::Text::LEFT_BOTTOM; |
|---|
| 60 | |
|---|
| 61 | _alignmentMap["CENTER_TOP"] = osgText::Text::CENTER_TOP; |
|---|
| 62 | _alignmentMap["CENTER_CENTER"] = osgText::Text::CENTER_CENTER; |
|---|
| 63 | _alignmentMap["CENTER_BOTTOM"] = osgText::Text::CENTER_BOTTOM; |
|---|
| 64 | |
|---|
| 65 | _alignmentMap["RIGHT_TOP"] = osgText::Text::RIGHT_TOP; |
|---|
| 66 | _alignmentMap["RIGHT_CENTER"] = osgText::Text::RIGHT_CENTER; |
|---|
| 67 | _alignmentMap["RIGHT_BOTTOM"] = osgText::Text::RIGHT_BOTTOM; |
|---|
| 68 | |
|---|
| 69 | _alignmentMap["LEFT_BASE_LINE"] = osgText::Text::LEFT_BASE_LINE; |
|---|
| 70 | _alignmentMap["CENTER_BASE_LINE"] = osgText::Text::CENTER_BASE_LINE; |
|---|
| 71 | _alignmentMap["RIGHT_BASE_LINE"] = osgText::Text::RIGHT_BASE_LINE; |
|---|
| 72 | _alignmentMap["BASE_LINE"] = osgText::Text::LEFT_BASE_LINE; |
|---|
| 73 | |
|---|
| 74 | _stringKeyMap["Home"]=' '; |
|---|
| 75 | _stringKeyMap["Start"]= osgGA::GUIEventAdapter::KEY_Home; |
|---|
| 76 | _stringKeyMap["Next"]= osgGA::GUIEventAdapter::KEY_Page_Down; |
|---|
| 77 | _stringKeyMap["Previous"]=osgGA::GUIEventAdapter::KEY_Page_Up; |
|---|
| 78 | _stringKeyMap["Up"]=osgGA::GUIEventAdapter::KEY_Up; |
|---|
| 79 | _stringKeyMap["Down"]=osgGA::GUIEventAdapter::KEY_Down; |
|---|
| 80 | _stringKeyMap["End"]=osgGA::GUIEventAdapter::KEY_End; |
|---|
| 81 | _stringKeyMap["Page Down"]=osgGA::GUIEventAdapter::KEY_Page_Down; |
|---|
| 82 | _stringKeyMap["Page Up"]=osgGA::GUIEventAdapter::KEY_Page_Up; |
|---|
| 83 | _stringKeyMap["F1"]=osgGA::GUIEventAdapter::KEY_F1; |
|---|
| 84 | _stringKeyMap["F2"]=osgGA::GUIEventAdapter::KEY_F2; |
|---|
| 85 | _stringKeyMap["F3"]=osgGA::GUIEventAdapter::KEY_F3; |
|---|
| 86 | _stringKeyMap["F4"]=osgGA::GUIEventAdapter::KEY_F4; |
|---|
| 87 | _stringKeyMap["F5"]=osgGA::GUIEventAdapter::KEY_F5; |
|---|
| 88 | _stringKeyMap["F6"]=osgGA::GUIEventAdapter::KEY_F6; |
|---|
| 89 | _stringKeyMap["F7"]=osgGA::GUIEventAdapter::KEY_F7; |
|---|
| 90 | _stringKeyMap["F8"]=osgGA::GUIEventAdapter::KEY_F8; |
|---|
| 91 | _stringKeyMap["F9"]=osgGA::GUIEventAdapter::KEY_F9; |
|---|
| 92 | _stringKeyMap["F10"]=osgGA::GUIEventAdapter::KEY_F10; |
|---|
| 93 | _stringKeyMap["F11"]=osgGA::GUIEventAdapter::KEY_F11; |
|---|
| 94 | _stringKeyMap["F12"]=osgGA::GUIEventAdapter::KEY_F12; |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | _notifyLevel = osg::INFO; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | virtual const char* className() const |
|---|
| 101 | { |
|---|
| 102 | return "present3D XML Reader/Writer"; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | virtual bool acceptsExtension(const std::string& extension) const |
|---|
| 106 | { |
|---|
| 107 | return osgDB::equalCaseInsensitive(extension,"p3d") || |
|---|
| 108 | osgDB::equalCaseInsensitive(extension,"xml") ; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | virtual ReadResult readNode(const std::string& fileName, |
|---|
| 112 | const osgDB::ReaderWriter::Options* options) const; |
|---|
| 113 | |
|---|
| 114 | virtual ReadResult readNode(std::istream& fin, const Options* options) const; |
|---|
| 115 | |
|---|
| 116 | ReadResult readNode(osgDB::XmlNode::Input& input, const osgDB::ReaderWriter::Options* options) const; |
|---|
| 117 | |
|---|
| 118 | void parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; |
|---|
| 119 | |
|---|
| 120 | void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; |
|---|
| 121 | |
|---|
| 122 | void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; |
|---|
| 123 | |
|---|
| 124 | void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; |
|---|
| 125 | |
|---|
| 126 | void parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; |
|---|
| 127 | void parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const; |
|---|
| 128 | |
|---|
| 129 | void parsePage (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; |
|---|
| 130 | |
|---|
| 131 | void parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool parseTitles=true, bool parseLayers=true) const; |
|---|
| 132 | |
|---|
| 133 | void parsePdfDocument (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; |
|---|
| 134 | |
|---|
| 135 | osg::Vec4 mapStringToColor(const std::string& str) const |
|---|
| 136 | { |
|---|
| 137 | ColorMap::const_iterator itr=_colorMap.find(str); |
|---|
| 138 | if (itr!=_colorMap.end()) return itr->second; |
|---|
| 139 | osg::Vec4 color; |
|---|
| 140 | if (read(str,color)) return color; |
|---|
| 141 | else return osg::Vec4(0.0f,0.0f,0.0f,1.0f); |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | inline osg::Vec4 accumulateRotation(const osg::Vec4& lhs, const osg::Vec4& rhs) const |
|---|
| 145 | { |
|---|
| 146 | osg::Quat qlhs,qrhs; |
|---|
| 147 | qlhs.makeRotate(osg::DegreesToRadians(lhs[0]),lhs[1],lhs[2],lhs[3]); |
|---|
| 148 | qrhs.makeRotate(osg::DegreesToRadians(rhs[0]),rhs[1],rhs[2],rhs[3]); |
|---|
| 149 | osg::Quat quat = qlhs*qrhs; |
|---|
| 150 | osg::Vec4d result; |
|---|
| 151 | quat.getRotate ( result[0], result[1], result[2], result[3]); |
|---|
| 152 | result[0] = osg::RadiansToDegrees(result[0]); |
|---|
| 153 | return result; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | inline bool read(const char* str, int& value) const; |
|---|
| 157 | inline bool read(const char* str, float& value) const; |
|---|
| 158 | inline bool read(const char* str, double& value) const; |
|---|
| 159 | inline bool read(const char* str, osg::Vec2& value) const; |
|---|
| 160 | inline bool read(const char* str, osg::Vec3& value) const; |
|---|
| 161 | inline bool read(const char* str, osg::Vec4& value) const; |
|---|
| 162 | |
|---|
| 163 | inline bool read(const std::string& str, int& value) const; |
|---|
| 164 | inline bool read(const std::string& str, float& value) const; |
|---|
| 165 | inline bool read(const std::string& str, double& value) const; |
|---|
| 166 | inline bool read(const std::string& str, osg::Vec2& value) const; |
|---|
| 167 | inline bool read(const std::string& str, osg::Vec3& value) const; |
|---|
| 168 | inline bool read(const std::string& str, osg::Vec4& value) const; |
|---|
| 169 | |
|---|
| 170 | bool getProperty(osgDB::XmlNode*cur, const char* token) const; |
|---|
| 171 | bool getProperty(osgDB::XmlNode*cur, const char* token, int& value) const; |
|---|
| 172 | bool getProperty(osgDB::XmlNode*cur, const char* token, float& value) const; |
|---|
| 173 | bool getProperty(osgDB::XmlNode*cur, const char* token, double& value) const; |
|---|
| 174 | bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const; |
|---|
| 175 | bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const; |
|---|
| 176 | bool getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const; |
|---|
| 177 | bool getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const; |
|---|
| 178 | bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const; |
|---|
| 179 | bool getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const; |
|---|
| 180 | |
|---|
| 181 | bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const; |
|---|
| 182 | bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const; |
|---|
| 183 | bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const; |
|---|
| 184 | bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const; |
|---|
| 185 | bool getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const; |
|---|
| 186 | |
|---|
| 187 | bool getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; |
|---|
| 188 | bool getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const; |
|---|
| 189 | |
|---|
| 190 | typedef std::map<std::string,osg::Vec4> ColorMap; |
|---|
| 191 | typedef std::map<std::string,osgText::Text::Layout> LayoutMap; |
|---|
| 192 | typedef std::map<std::string,osgText::Text::AlignmentType> AlignmentMap; |
|---|
| 193 | typedef std::map<std::string, unsigned int> StringKeyMap; |
|---|
| 194 | |
|---|
| 195 | std::string expandEnvVarsInFileName(const std::string& filename) const; |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | ColorMap _colorMap; |
|---|
| 199 | LayoutMap _layoutMap; |
|---|
| 200 | AlignmentMap _alignmentMap; |
|---|
| 201 | StringKeyMap _stringKeyMap; |
|---|
| 202 | |
|---|
| 203 | typedef std::map<std::string, osg::ref_ptr<osgDB::XmlNode> > TemplateMap; |
|---|
| 204 | mutable TemplateMap _templateMap; |
|---|
| 205 | |
|---|
| 206 | osg::NotifySeverity _notifyLevel; |
|---|
| 207 | |
|---|
| 208 | }; |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | osgDB::RegisterReaderWriterProxy<ReaderWriterP3DXML> g_readerWriter_P3DXML_Proxy; |
|---|
| 212 | |
|---|
| 213 | std::string ReaderWriterP3DXML::expandEnvVarsInFileName(const std::string& filename) const |
|---|
| 214 | { |
|---|
| 215 | std::string argument(filename); |
|---|
| 216 | std::string::size_type start_pos = argument.find("${"); |
|---|
| 217 | |
|---|
| 218 | while (start_pos != std::string::npos) |
|---|
| 219 | { |
|---|
| 220 | std::string::size_type end_pos = argument.find("}",start_pos); |
|---|
| 221 | if (start_pos != std::string::npos) |
|---|
| 222 | { |
|---|
| 223 | std::string var = argument.substr(start_pos+2, end_pos-start_pos-2); |
|---|
| 224 | const char* str = getenv(var.c_str()); |
|---|
| 225 | if (str) |
|---|
| 226 | { |
|---|
| 227 | argument.erase(start_pos, end_pos-start_pos+1); |
|---|
| 228 | argument.insert(start_pos, str); |
|---|
| 229 | } |
|---|
| 230 | start_pos = argument.find("${",end_pos); |
|---|
| 231 | } |
|---|
| 232 | else |
|---|
| 233 | { |
|---|
| 234 | start_pos = std::string::npos; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | } |
|---|
| 238 | |
|---|
| 239 | return argument; |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | bool ReaderWriterP3DXML::read(const char* str, int& value) const |
|---|
| 243 | { |
|---|
| 244 | if (!str) return false; |
|---|
| 245 | std::istringstream iss((const char*)str); |
|---|
| 246 | iss >> value; |
|---|
| 247 | return !iss.fail(); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | bool ReaderWriterP3DXML::read(const char* str, float& value) const |
|---|
| 251 | { |
|---|
| 252 | if (!str) return false; |
|---|
| 253 | std::istringstream iss((const char*)str); |
|---|
| 254 | iss >> value; |
|---|
| 255 | return !iss.fail(); |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | bool ReaderWriterP3DXML::read(const char* str, double& value) const |
|---|
| 259 | { |
|---|
| 260 | if (!str) return false; |
|---|
| 261 | std::istringstream iss((const char*)str); |
|---|
| 262 | iss >> value; |
|---|
| 263 | return !iss.fail(); |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | bool ReaderWriterP3DXML::read(const char* str, osg::Vec2& value) const |
|---|
| 267 | { |
|---|
| 268 | if (!str) return false; |
|---|
| 269 | std::istringstream iss((const char*)str); |
|---|
| 270 | iss >> value.x() >> value.y(); |
|---|
| 271 | return !iss.fail(); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | bool ReaderWriterP3DXML::read(const char* str, osg::Vec3& value) const |
|---|
| 275 | { |
|---|
| 276 | if (!str) return false; |
|---|
| 277 | std::istringstream iss((const char*)str); |
|---|
| 278 | iss >> value.x() >> value.y() >> value.z(); |
|---|
| 279 | return !iss.fail(); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | bool ReaderWriterP3DXML::read(const char* str, osg::Vec4& value) const |
|---|
| 283 | { |
|---|
| 284 | if (!str) return false; |
|---|
| 285 | std::istringstream iss((const char*)str); |
|---|
| 286 | iss >> value.x() >> value.y() >> value.z() >> value.w(); |
|---|
| 287 | return !iss.fail(); |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | bool ReaderWriterP3DXML::read(const std::string& str, int& value) const |
|---|
| 291 | { |
|---|
| 292 | std::istringstream iss(str); |
|---|
| 293 | iss >> value; |
|---|
| 294 | return !iss.fail(); |
|---|
| 295 | } |
|---|
| 296 | |
|---|
| 297 | bool ReaderWriterP3DXML::read(const std::string& str, float& value) const |
|---|
| 298 | { |
|---|
| 299 | std::istringstream iss(str); |
|---|
| 300 | iss >> value; |
|---|
| 301 | return !iss.fail(); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | bool ReaderWriterP3DXML::read(const std::string& str, double& value) const |
|---|
| 305 | { |
|---|
| 306 | std::istringstream iss(str); |
|---|
| 307 | iss >> value; |
|---|
| 308 | return !iss.fail(); |
|---|
| 309 | } |
|---|
| 310 | |
|---|
| 311 | bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec2& value) const |
|---|
| 312 | { |
|---|
| 313 | std::istringstream iss(str); |
|---|
| 314 | iss >> value.x() >> value.y(); |
|---|
| 315 | return !iss.fail(); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec3& value) const |
|---|
| 319 | { |
|---|
| 320 | std::istringstream iss(str); |
|---|
| 321 | iss >> value.x() >> value.y() >> value.z(); |
|---|
| 322 | return !iss.fail(); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | bool ReaderWriterP3DXML::read(const std::string& str, osg::Vec4& value) const |
|---|
| 326 | { |
|---|
| 327 | std::istringstream iss(str); |
|---|
| 328 | iss >> value.x() >> value.y() >> value.z() >> value.w(); |
|---|
| 329 | return !iss.fail(); |
|---|
| 330 | } |
|---|
| 331 | |
|---|
| 332 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode* cur, const char* token) const |
|---|
| 333 | { |
|---|
| 334 | return cur->properties.count(token)!=0; |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, int& value) const |
|---|
| 338 | { |
|---|
| 339 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 340 | if (itr==cur->properties.end()) return false; |
|---|
| 341 | return read(itr->second,value); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, float& value) const |
|---|
| 345 | { |
|---|
| 346 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 347 | if (itr==cur->properties.end()) return false; |
|---|
| 348 | return read(itr->second,value); |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, double& value) const |
|---|
| 352 | { |
|---|
| 353 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 354 | if (itr==cur->properties.end()) return false; |
|---|
| 355 | return read(itr->second,value); |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec2& value) const |
|---|
| 359 | { |
|---|
| 360 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 361 | if (itr==cur->properties.end()) return false; |
|---|
| 362 | return read(itr->second,value); |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec3& value) const |
|---|
| 366 | { |
|---|
| 367 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 368 | if (itr==cur->properties.end()) return false; |
|---|
| 369 | return read(itr->second,value); |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osg::Vec4& value) const |
|---|
| 373 | { |
|---|
| 374 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 375 | if (itr==cur->properties.end()) return false; |
|---|
| 376 | return read(itr->second,value); |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, std::string& value) const |
|---|
| 380 | { |
|---|
| 381 | osgDB::XmlNode::Properties::iterator itr = cur->properties.find(token); |
|---|
| 382 | if (itr==cur->properties.end()) return false; |
|---|
| 383 | value = itr->second; |
|---|
| 384 | return true; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::Layout& value) const |
|---|
| 388 | { |
|---|
| 389 | osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token); |
|---|
| 390 | if (pitr==cur->properties.end()) return false; |
|---|
| 391 | |
|---|
| 392 | const std::string& str = pitr->second; |
|---|
| 393 | LayoutMap::const_iterator itr = _layoutMap.find(str); |
|---|
| 394 | if (itr!=_layoutMap.end()) |
|---|
| 395 | { |
|---|
| 396 | value = itr->second; |
|---|
| 397 | } |
|---|
| 398 | return true; |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | bool ReaderWriterP3DXML::getProperty(osgDB::XmlNode*cur, const char* token, osgText::Text::AlignmentType& value) const |
|---|
| 402 | { |
|---|
| 403 | osgDB::XmlNode::Properties::iterator pitr = cur->properties.find(token); |
|---|
| 404 | if (pitr==cur->properties.end()) return false; |
|---|
| 405 | |
|---|
| 406 | const std::string& str = pitr->second; |
|---|
| 407 | AlignmentMap::const_iterator itr = _alignmentMap.find(str); |
|---|
| 408 | if (itr!=_alignmentMap.end()) |
|---|
| 409 | { |
|---|
| 410 | value = itr->second; |
|---|
| 411 | } |
|---|
| 412 | return true; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::PositionData& value) const |
|---|
| 416 | { |
|---|
| 417 | bool propertiesRead=false; |
|---|
| 418 | |
|---|
| 419 | osg::Vec3 position(0.0f,1.0f,0.0f); |
|---|
| 420 | osg::Vec4 rotate(0.0f,0.0f,0.0f,1.0f); |
|---|
| 421 | float scale = 1.0f; |
|---|
| 422 | |
|---|
| 423 | osg::Vec4 rotation(0.0f,0.0f,0.0f,1.0f); |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | std::string str; |
|---|
| 427 | |
|---|
| 428 | if (getProperty(cur, "coordinate_frame", str)) |
|---|
| 429 | { |
|---|
| 430 | propertiesRead = true; |
|---|
| 431 | |
|---|
| 432 | if (str=="model") value.frame = osgPresentation::SlideShowConstructor::MODEL; |
|---|
| 433 | else if (str=="slide") value.frame = osgPresentation::SlideShowConstructor::SLIDE; |
|---|
| 434 | else osg::notify(_notifyLevel)<<"Parser error - coordinate_frame=\""<<str<<"\" unrecongonized value"<<std::endl; |
|---|
| 435 | |
|---|
| 436 | osg::notify(_notifyLevel)<<"read coordinate_frame "<< ((value.frame==osgPresentation::SlideShowConstructor::MODEL) ? "osgPresentation::SlideShowConstructor::MODEL" : "osgPresentation::SlideShowConstructor::SLIDE")<<std::endl; |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | if (value.frame==osgPresentation::SlideShowConstructor::SLIDE) |
|---|
| 440 | { |
|---|
| 441 | |
|---|
| 442 | if (getProperty(cur, "position", str)) |
|---|
| 443 | { |
|---|
| 444 | value.position.set(0.5,0.5,0.0); |
|---|
| 445 | |
|---|
| 446 | propertiesRead = true; |
|---|
| 447 | |
|---|
| 448 | osg::Vec2 vec2; |
|---|
| 449 | osg::Vec3 vec3; |
|---|
| 450 | |
|---|
| 451 | bool fail = false; |
|---|
| 452 | if (str=="center") value.position.set(0.5f,.5f,0.0f); |
|---|
| 453 | else if (str=="eye") value.position.set(0.0f,0.0f,1.0f); |
|---|
| 454 | else if (read(str,vec3)) value.position = vec3; |
|---|
| 455 | else if (read(str,vec2)) value.position.set(vec3.x(),vec3.y(),0.0f); |
|---|
| 456 | else fail = true; |
|---|
| 457 | |
|---|
| 458 | if (fail) osg::notify(_notifyLevel)<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl; |
|---|
| 459 | else osg::notify(_notifyLevel)<<"Read position="<<value.position<<std::endl; |
|---|
| 460 | } |
|---|
| 461 | } |
|---|
| 462 | else |
|---|
| 463 | { |
|---|
| 464 | |
|---|
| 465 | if (getProperty(cur, "position", str)) |
|---|
| 466 | { |
|---|
| 467 | value.position.set(0.0,0.0,0.0); |
|---|
| 468 | |
|---|
| 469 | propertiesRead = true; |
|---|
| 470 | |
|---|
| 471 | bool fail = false; |
|---|
| 472 | if (str=="center") value.position.set(0.0f,1.0f,0.0f); |
|---|
| 473 | else if (str=="eye") value.position.set(0.0f,0.0f,0.0f); |
|---|
| 474 | else if (!read(str,value.position)) fail = true; |
|---|
| 475 | |
|---|
| 476 | if (fail) osg::notify(_notifyLevel)<<"Parser error - position=\""<<str<<"\" unrecongonized value"<<std::endl; |
|---|
| 477 | else osg::notify(_notifyLevel)<<"Read position="<<value.position<<std::endl; |
|---|
| 478 | } |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | if (getProperty(cur, "scale", scale)) |
|---|
| 483 | { |
|---|
| 484 | value.scale.set(scale,scale,scale); |
|---|
| 485 | propertiesRead = true; |
|---|
| 486 | osg::notify(_notifyLevel)<<"scale read "<<scale<<std::endl; |
|---|
| 487 | } |
|---|
| 488 | |
|---|
| 489 | if (getProperty(cur, "scale_x", scale) || getProperty(cur, "width", scale)) |
|---|
| 490 | { |
|---|
| 491 | value.scale.x() = scale; |
|---|
| 492 | propertiesRead = true; |
|---|
| 493 | osg::notify(_notifyLevel)<<"scale read_x "<<scale<<std::endl; |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | if (getProperty(cur, "scale_y", scale) || getProperty(cur, "height", scale)) |
|---|
| 497 | { |
|---|
| 498 | value.scale.y() = scale; |
|---|
| 499 | propertiesRead = true; |
|---|
| 500 | osg::notify(_notifyLevel)<<"scale read_y "<<scale<<std::endl; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | if (getProperty(cur, "scale_z", scale)) |
|---|
| 504 | { |
|---|
| 505 | value.scale.z() = scale; |
|---|
| 506 | propertiesRead = true; |
|---|
| 507 | osg::notify(_notifyLevel)<<"scale read_z "<<scale<<std::endl; |
|---|
| 508 | } |
|---|
| 509 | |
|---|
| 510 | if (getProperty(cur, "rotate", rotate)) |
|---|
| 511 | { |
|---|
| 512 | value.rotate = rotate; |
|---|
| 513 | propertiesRead = true; |
|---|
| 514 | osg::notify(_notifyLevel)<<"rotate read "<<rotate<<std::endl; |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | if (getProperty(cur, "rotate1", rotate)) |
|---|
| 518 | { |
|---|
| 519 | |
|---|
| 520 | value.rotate = accumulateRotation(rotate,value.rotate); |
|---|
| 521 | propertiesRead = true; |
|---|
| 522 | osg::notify(_notifyLevel)<<"rotate1 read "<<rotate<<std::endl; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | if (getProperty(cur, "rotate2", rotate)) |
|---|
| 526 | { |
|---|
| 527 | |
|---|
| 528 | value.rotate = accumulateRotation(rotate,value.rotate); |
|---|
| 529 | propertiesRead = true; |
|---|
| 530 | osg::notify(_notifyLevel)<<"rotate1 read "<<rotate<<std::endl; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | if (getProperty(cur, "rotate3", rotate)) |
|---|
| 534 | { |
|---|
| 535 | |
|---|
| 536 | value.rotate = accumulateRotation(rotate,value.rotate); |
|---|
| 537 | propertiesRead = true; |
|---|
| 538 | osg::notify(_notifyLevel)<<"rotate1 read "<<rotate<<std::endl; |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | if (getProperty(cur, "rotation", rotation)) |
|---|
| 542 | { |
|---|
| 543 | value.rotation = rotation; |
|---|
| 544 | osg::notify(_notifyLevel)<<"rotation read "<<rotation<<std::endl; |
|---|
| 545 | propertiesRead = true; |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | if (getProperty(cur, "rotation1", rotation)) |
|---|
| 549 | { |
|---|
| 550 | value.rotation = accumulateRotation(rotation,value.rotation); |
|---|
| 551 | osg::notify(_notifyLevel)<<"rotation1 read "<<rotation<<std::endl; |
|---|
| 552 | propertiesRead = true; |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | if (getProperty(cur, "rotation2", rotation)) |
|---|
| 556 | { |
|---|
| 557 | value.rotation = accumulateRotation(rotation,value.rotation); |
|---|
| 558 | osg::notify(_notifyLevel)<<"rotation2 read "<<rotation<<std::endl; |
|---|
| 559 | propertiesRead = true; |
|---|
| 560 | } |
|---|
| 561 | |
|---|
| 562 | if (getProperty(cur, "rotation3", rotation)) |
|---|
| 563 | { |
|---|
| 564 | value.rotation = accumulateRotation(rotation,value.rotation); |
|---|
| 565 | osg::notify(_notifyLevel)<<"rotation3 read "<<rotation<<std::endl; |
|---|
| 566 | propertiesRead = true; |
|---|
| 567 | } |
|---|
| 568 | |
|---|
| 569 | if (getProperty(cur, "path", str)) |
|---|
| 570 | { |
|---|
| 571 | |
|---|
| 572 | value.absolute_path = false; |
|---|
| 573 | value.inverse_path = false; |
|---|
| 574 | value.path = expandEnvVarsInFileName(str); |
|---|
| 575 | |
|---|
| 576 | osg::notify(_notifyLevel)<<"path read "<<str<<std::endl; |
|---|
| 577 | propertiesRead = true; |
|---|
| 578 | } |
|---|
| 579 | |
|---|
| 580 | if (getProperty(cur, "camera_path", str)) |
|---|
| 581 | { |
|---|
| 582 | value.absolute_path = true; |
|---|
| 583 | value.inverse_path = true; |
|---|
| 584 | value.path = expandEnvVarsInFileName(str); |
|---|
| 585 | |
|---|
| 586 | osg::notify(_notifyLevel)<<"camera path read "<<str<<std::endl; |
|---|
| 587 | propertiesRead = true; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | if (getProperty(cur, "path_time_offset", value.path_time_offset)) |
|---|
| 591 | { |
|---|
| 592 | osg::notify(_notifyLevel)<<"read path_time_offset"<<value.path_time_offset<<std::endl; |
|---|
| 593 | propertiesRead = true; |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | if (getProperty(cur, "path_time_multiplier", value.path_time_multiplier)) |
|---|
| 597 | { |
|---|
| 598 | osg::notify(_notifyLevel)<<"read path_time_multiplier"<<value.path_time_multiplier<<std::endl; |
|---|
| 599 | propertiesRead = true; |
|---|
| 600 | } |
|---|
| 601 | |
|---|
| 602 | if (getProperty(cur, "animation_material_time_offset", value.animation_material_time_offset)) |
|---|
| 603 | { |
|---|
| 604 | osg::notify(_notifyLevel)<<"read animation_material_time_offset"<<value.animation_material_time_offset<<std::endl; |
|---|
| 605 | propertiesRead = true; |
|---|
| 606 | } |
|---|
| 607 | |
|---|
| 608 | if (getProperty(cur, "animation_material_time_multiplier", value.animation_material_time_multiplier)) |
|---|
| 609 | { |
|---|
| 610 | osg::notify(_notifyLevel)<<"read animation_material_time_multiplier"<<value.animation_material_time_multiplier<<std::endl; |
|---|
| 611 | propertiesRead = true; |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | if (getProperty(cur, "animation_material", str)) |
|---|
| 615 | { |
|---|
| 616 | value.animation_material_filename = str; |
|---|
| 617 | |
|---|
| 618 | osg::notify(_notifyLevel)<<"animation_material read "<<str<<std::endl; |
|---|
| 619 | propertiesRead = true; |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | if (getProperty(cur, "animation_name", str)) |
|---|
| 623 | { |
|---|
| 624 | value.animation_name = str; |
|---|
| 625 | |
|---|
| 626 | osg::notify(_notifyLevel)<<"animation_name "<<str<<std::endl; |
|---|
| 627 | propertiesRead = true; |
|---|
| 628 | } |
|---|
| 629 | |
|---|
| 630 | if (getProperty(cur, "fade", value.fade)) |
|---|
| 631 | { |
|---|
| 632 | osg::notify(_notifyLevel)<<"fade "<<value.fade<<std::endl; |
|---|
| 633 | propertiesRead = true; |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | if (getProperty(cur, "path_loop_mode", str)) |
|---|
| 637 | { |
|---|
| 638 | osg::notify(_notifyLevel)<<"path_loop_mode "<<str<<std::endl; |
|---|
| 639 | if (str=="LOOP") value.path_loop_mode=osg::AnimationPath::LOOP; |
|---|
| 640 | else if (str=="SWING") value.path_loop_mode=osg::AnimationPath::SWING; |
|---|
| 641 | else if (str=="NO_LOOPING") value.path_loop_mode=osg::AnimationPath::NO_LOOPING; |
|---|
| 642 | propertiesRead = true; |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | if (getProperty(cur, "animation_material_loop_mode", str)) |
|---|
| 646 | { |
|---|
| 647 | osg::notify(_notifyLevel)<<"animation_material_loop_mode "<<str<<std::endl; |
|---|
| 648 | if (str=="LOOP") value.animation_material_loop_mode=ss3d::AnimationMaterial::LOOP; |
|---|
| 649 | else if (str=="SWING") value.animation_material_loop_mode=ss3d::AnimationMaterial::SWING; |
|---|
| 650 | else if (str=="NO_LOOPING") value.animation_material_loop_mode=ss3d::AnimationMaterial::NO_LOOPING; |
|---|
| 651 | propertiesRead = true; |
|---|
| 652 | } |
|---|
| 653 | |
|---|
| 654 | return propertiesRead; |
|---|
| 655 | } |
|---|
| 656 | |
|---|
| 657 | bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const |
|---|
| 658 | { |
|---|
| 659 | bool propertiesRead=false; |
|---|
| 660 | |
|---|
| 661 | osg::notify(_notifyLevel)<<"in getProperties(FontData)"<<std::endl; |
|---|
| 662 | |
|---|
| 663 | if (getProperty(cur, "font", value.font)) |
|---|
| 664 | { |
|---|
| 665 | propertiesRead = true; |
|---|
| 666 | osg::notify(_notifyLevel)<<"read font \""<<value.font<<"\""<<std::endl; |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | if (getProperty(cur, "character_size", value.characterSize)) |
|---|
| 670 | { |
|---|
| 671 | propertiesRead = true; |
|---|
| 672 | osg::notify(_notifyLevel)<<"read height \""<<value.characterSize<<"\""<<std::endl; |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | if (getProperty(cur, "layout", value.layout)) |
|---|
| 676 | { |
|---|
| 677 | propertiesRead = true; |
|---|
| 678 | |
|---|
| 679 | osg::notify(_notifyLevel)<<"read layout \""<<value.layout<<"\""<<std::endl; |
|---|
| 680 | } |
|---|
| 681 | |
|---|
| 682 | if (getProperty(cur, "alignment", value.alignment)) |
|---|
| 683 | { |
|---|
| 684 | propertiesRead = true; |
|---|
| 685 | |
|---|
| 686 | osg::notify(_notifyLevel)<<"read alignment \""<<value.alignment<<"\""<<std::endl; |
|---|
| 687 | } |
|---|
| 688 | |
|---|
| 689 | return propertiesRead; |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const |
|---|
| 693 | { |
|---|
| 694 | bool propertiesRead=false; |
|---|
| 695 | |
|---|
| 696 | osg::notify(_notifyLevel)<<"in getProperties(ModelData)"<<std::endl; |
|---|
| 697 | |
|---|
| 698 | if (getProperty(cur, "effect", value.effect)) |
|---|
| 699 | { |
|---|
| 700 | propertiesRead = true; |
|---|
| 701 | osg::notify(_notifyLevel)<<"read effect \""<<value.effect<<"\""<<std::endl; |
|---|
| 702 | } |
|---|
| 703 | |
|---|
| 704 | return propertiesRead; |
|---|
| 705 | } |
|---|
| 706 | |
|---|
| 707 | bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const |
|---|
| 708 | { |
|---|
| 709 | bool propertiesRead=false; |
|---|
| 710 | |
|---|
| 711 | osg::notify(_notifyLevel)<<"in getProperties(ImageData)"<<std::endl; |
|---|
| 712 | |
|---|
| 713 | if (getProperty(cur, "page", value.page)) |
|---|
| 714 | { |
|---|
| 715 | propertiesRead = true; |
|---|
| 716 | osg::notify(_notifyLevel)<<"read page \""<<value.page<<"\""<<std::endl; |
|---|
| 717 | } |
|---|
| 718 | |
|---|
| 719 | osg::Vec4 bgColour; |
|---|
| 720 | if (getProperty(cur, "background", value.backgroundColor)) |
|---|
| 721 | { |
|---|
| 722 | propertiesRead = true; |
|---|
| 723 | osg::notify(_notifyLevel)<<"read background colour \""<<value.backgroundColor<<"\""<<std::endl; |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | if (getProperty(cur, "width", value.width)) |
|---|
| 727 | { |
|---|
| 728 | propertiesRead = true; |
|---|
| 729 | osg::notify(_notifyLevel)<<"read width \""<<value.width<<"\""<<std::endl; |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | if (getProperty(cur, "height", value.height)) |
|---|
| 733 | { |
|---|
| 734 | propertiesRead = true; |
|---|
| 735 | osg::notify(_notifyLevel)<<"read height \""<<value.height<<"\""<<std::endl; |
|---|
| 736 | } |
|---|
| 737 | |
|---|
| 738 | if (getProperty(cur, "region", value.region)) |
|---|
| 739 | { |
|---|
| 740 | propertiesRead = true; |
|---|
| 741 | value.region_in_pixel_coords = false; |
|---|
| 742 | osg::notify(_notifyLevel)<<"read region \""<<value.region<<"\""<<std::endl; |
|---|
| 743 | } |
|---|
| 744 | |
|---|
| 745 | if (getProperty(cur, "pixel_region", value.region)) |
|---|
| 746 | { |
|---|
| 747 | propertiesRead = true; |
|---|
| 748 | value.region_in_pixel_coords = true; |
|---|
| 749 | osg::notify(_notifyLevel)<<"read pixel_region \""<<value.region<<"\""<<std::endl; |
|---|
| 750 | } |
|---|
| 751 | |
|---|
| 752 | std::string str; |
|---|
| 753 | if (getProperty(cur, "looping", str)) |
|---|
| 754 | { |
|---|
| 755 | propertiesRead = true; |
|---|
| 756 | if (str=="ON") value.loopingMode = osg::ImageStream::LOOPING; |
|---|
| 757 | else value.loopingMode = osg::ImageStream::NO_LOOPING; |
|---|
| 758 | osg::notify(_notifyLevel)<<"looping \""<<str<<"\""<<std::endl; |
|---|
| 759 | } |
|---|
| 760 | |
|---|
| 761 | |
|---|
| 762 | |
|---|
| 763 | |
|---|
| 764 | |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | |
|---|
| 772 | |
|---|
| 773 | |
|---|
| 774 | |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | |
|---|
| 780 | return propertiesRead; |
|---|
| 781 | } |
|---|
| 782 | |
|---|
| 783 | bool ReaderWriterP3DXML::getJumpProperties(osgDB::XmlNode*cur, bool& relativeJump, int& slideNum, int& layerNum) const |
|---|
| 784 | { |
|---|
| 785 | bool propertyRead = false; |
|---|
| 786 | |
|---|
| 787 | if (getProperty(cur, "slide", slideNum)) |
|---|
| 788 | { |
|---|
| 789 | osg::notify(osg::NOTICE)<<"slide "<<slideNum<<std::endl; |
|---|
| 790 | propertyRead = true; |
|---|
| 791 | } |
|---|
| 792 | |
|---|
| 793 | if (getProperty(cur, "layer", layerNum)) |
|---|
| 794 | { |
|---|
| 795 | osg::notify(osg::NOTICE)<<"layer "<<layerNum<<std::endl; |
|---|
| 796 | propertyRead = true; |
|---|
| 797 | } |
|---|
| 798 | |
|---|
| 799 | std::string jumpType; |
|---|
| 800 | if (getProperty(cur, "jump", jumpType)) |
|---|
| 801 | { |
|---|
| 802 | osg::notify(osg::NOTICE)<<"jump "<<jumpType<<std::endl; |
|---|
| 803 | propertyRead = true; |
|---|
| 804 | relativeJump = (jumpType=="relative") || (jumpType=="Relative") || (jumpType=="RELATIVE") ; |
|---|
| 805 | } |
|---|
| 806 | |
|---|
| 807 | return propertyRead; |
|---|
| 808 | } |
|---|
| 809 | |
|---|
| 810 | void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const |
|---|
| 811 | { |
|---|
| 812 | |
|---|
| 813 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData(); |
|---|
| 814 | bool positionRead = getProperties(cur,positionData); |
|---|
| 815 | |
|---|
| 816 | osgPresentation::SlideShowConstructor::ModelData modelData; |
|---|
| 817 | getProperties(cur,modelData); |
|---|
| 818 | |
|---|
| 819 | std::string filename = cur->contents; |
|---|
| 820 | |
|---|
| 821 | if (!filename.empty()) |
|---|
| 822 | { |
|---|
| 823 | constructor.addModel(filename, |
|---|
| 824 | positionRead ? positionData : constructor.getModelPositionData(), |
|---|
| 825 | modelData); |
|---|
| 826 | } |
|---|
| 827 | } |
|---|
| 828 | |
|---|
| 829 | void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const |
|---|
| 830 | { |
|---|
| 831 | |
|---|
| 832 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData(); |
|---|
| 833 | bool positionRead = getProperties(cur,positionData); |
|---|
| 834 | |
|---|
| 835 | std::string filename = cur->contents; |
|---|
| 836 | |
|---|
| 837 | if (!filename.empty()) |
|---|
| 838 | { |
|---|
| 839 | constructor.addVolume(filename, |
|---|
| 840 | positionRead ? positionData : constructor.getModelPositionData()); |
|---|
| 841 | } |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const |
|---|
| 845 | { |
|---|
| 846 | std::string filenameLeft; |
|---|
| 847 | std::string filenameRight; |
|---|
| 848 | |
|---|
| 849 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); |
|---|
| 850 | bool positionRead = getProperties(cur,positionData); |
|---|
| 851 | |
|---|
| 852 | osgPresentation::SlideShowConstructor::ImageData imageDataLeft; |
|---|
| 853 | osgPresentation::SlideShowConstructor::ImageData imageDataRight; |
|---|
| 854 | |
|---|
| 855 | for(osgDB::XmlNode::Children::iterator itr = cur->children.begin(); |
|---|
| 856 | itr != cur->children.end(); |
|---|
| 857 | ++itr) |
|---|
| 858 | { |
|---|
| 859 | osgDB::XmlNode* child = itr->get(); |
|---|
| 860 | |
|---|
| 861 | if (child->name == "image_left") |
|---|
| 862 | { |
|---|
| 863 | getProperties(child,imageDataLeft); |
|---|
| 864 | filenameLeft = child->name; |
|---|
| 865 | } |
|---|
| 866 | if (cur->name == "image_right") |
|---|
| 867 | { |
|---|
| 868 | getProperties(child,imageDataRight); |
|---|
| 869 | filenameRight = child->name; |
|---|
| 870 | getProperties(cur,imageDataRight); |
|---|
| 871 | } |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | if (!filenameLeft.empty() && !filenameRight.empty()) |
|---|
| 875 | constructor.addStereoImagePair(filenameLeft,imageDataLeft, |
|---|
| 876 | filenameRight, imageDataRight, |
|---|
| 877 | positionRead ? positionData : constructor.getImagePositionData()); |
|---|
| 878 | |
|---|
| 879 | } |
|---|
| 880 | |
|---|
| 881 | bool ReaderWriterP3DXML::getKeyPosition(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const |
|---|
| 882 | { |
|---|
| 883 | if (cur->name == "key") |
|---|
| 884 | { |
|---|
| 885 | return getKeyPositionInner(cur, keyPosition); |
|---|
| 886 | } |
|---|
| 887 | if (cur->name == "escape" || |
|---|
| 888 | cur->name == "esc" || |
|---|
| 889 | cur->name == "exit") |
|---|
| 890 | { |
|---|
| 891 | keyPosition.set(osgGA::GUIEventAdapter::KEY_Escape, 0.0f, 0.0f); |
|---|
| 892 | return true; |
|---|
| 893 | } |
|---|
| 894 | return false; |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation::KeyPosition& keyPosition) const |
|---|
| 898 | { |
|---|
| 899 | |
|---|
| 900 | float x = FLT_MAX; |
|---|
| 901 | getProperty(cur, "x", x); |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | float y = FLT_MAX; |
|---|
| 905 | getProperty(cur, "y", y); |
|---|
| 906 | |
|---|
| 907 | float h = FLT_MAX; |
|---|
| 908 | if (getProperty(cur, "h", h)) |
|---|
| 909 | { |
|---|
| 910 | |
|---|
| 911 | x = h*2.0f-1.0f; |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | float v = FLT_MAX; |
|---|
| 915 | if (getProperty(cur, "v", v)) |
|---|
| 916 | { |
|---|
| 917 | |
|---|
| 918 | y = v*2.0f-1.0f; |
|---|
| 919 | } |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | std::string key = cur->contents; |
|---|
| 923 | unsigned int keyValue = 0; |
|---|
| 924 | |
|---|
| 925 | StringKeyMap::const_iterator itr=_stringKeyMap.find(key); |
|---|
| 926 | if (itr != _stringKeyMap.end()) |
|---|
| 927 | { |
|---|
| 928 | keyValue = itr->second; |
|---|
| 929 | } |
|---|
| 930 | else if (key.length()==1) |
|---|
| 931 | { |
|---|
| 932 | keyValue = key[0]; |
|---|
| 933 | } |
|---|
| 934 | else |
|---|
| 935 | { |
|---|
| 936 | osg::notify(osg::NOTICE)<<"Warning: unreconginized key sequence '"<<key<<"'"<<std::endl; |
|---|
| 937 | } |
|---|
| 938 | |
|---|
| 939 | keyPosition.set(keyValue,x,y); |
|---|
| 940 | return true; |
|---|
| 941 | } |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | |
|---|
| 945 | |
|---|
| 946 | void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const |
|---|
| 947 | { |
|---|
| 948 | |
|---|
| 949 | osgPresentation::KeyPosition keyPosition; |
|---|
| 950 | |
|---|
| 951 | osg::notify(osg::INFO)<<std::endl<<"parseLayer"<<std::endl; |
|---|
| 952 | |
|---|
| 953 | float totalIndent = 0.0f; |
|---|
| 954 | |
|---|
| 955 | for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); |
|---|
| 956 | itr != root->children.end(); |
|---|
| 957 | ++itr) |
|---|
| 958 | { |
|---|
| 959 | osgDB::XmlNode* cur = itr->get(); |
|---|
| 960 | if (cur->name == "run") |
|---|
| 961 | { |
|---|
| 962 | osg::notify(osg::INFO)<<"run ["<<cur->contents<<"]"<<std::endl; |
|---|
| 963 | constructor.addLayerRunString(cur->contents); |
|---|
| 964 | } |
|---|
| 965 | else if (cur->name == "jump") |
|---|
| 966 | { |
|---|
| 967 | osg::notify(osg::NOTICE)<<"Parsed Jump "<<std::endl; |
|---|
| 968 | |
|---|
| 969 | bool relativeJump = true; |
|---|
| 970 | int slideNum = 0; |
|---|
| 971 | int layerNum = 0; |
|---|
| 972 | if (getJumpProperties(cur, relativeJump, slideNum, layerNum)) |
|---|
| 973 | { |
|---|
| 974 | osg::notify(osg::NOTICE)<<"Layer Jump "<<relativeJump<<","<< slideNum<<", "<<layerNum<<std::endl; |
|---|
| 975 | |
|---|
| 976 | constructor.setLayerJump(relativeJump, slideNum, layerNum); |
|---|
| 977 | } |
|---|
| 978 | } |
|---|
| 979 | else if (cur->name == "click_to_run") |
|---|
| 980 | { |
|---|
| 981 | bool relativeJump = true; |
|---|
| 982 | int slideNum = 0; |
|---|
| 983 | int layerNum = 0; |
|---|
| 984 | getJumpProperties(cur, relativeJump, slideNum, layerNum); |
|---|
| 985 | |
|---|
| 986 | osg::notify(osg::INFO)<<"click_to_run ["<<cur->contents<<"]"<<std::endl; |
|---|
| 987 | constructor.layerClickToDoOperation(cur->contents,osgPresentation::RUN, relativeJump, slideNum, layerNum); |
|---|
| 988 | } |
|---|
| 989 | else if (cur->name == "click_to_load") |
|---|
| 990 | { |
|---|
| 991 | bool relativeJump = true; |
|---|
| 992 | int slideNum = 0; |
|---|
| 993 | int layerNum = 0; |
|---|
| 994 | getJumpProperties(cur, relativeJump, slideNum, layerNum); |
|---|
| 995 | |
|---|
| 996 | osg::notify(osg::INFO)<<"click_to_load ["<<cur->contents<<"]"<<std::endl; |
|---|
| 997 | constructor.layerClickToDoOperation(cur->contents,osgPresentation::LOAD, relativeJump, slideNum, layerNum); |
|---|
| 998 | } |
|---|
| 999 | |
|---|
| 1000 | else if (cur->name == "click_to_event") |
|---|
| 1001 | { |
|---|
| 1002 | bool relativeJump = true; |
|---|
| 1003 | int slideNum = 0; |
|---|
| 1004 | int layerNum = 0; |
|---|
| 1005 | getJumpProperties(cur, relativeJump, slideNum, layerNum); |
|---|
| 1006 | |
|---|
| 1007 | if (getKeyPositionInner( cur, keyPosition)) |
|---|
| 1008 | { |
|---|
| 1009 | osg::notify(osg::INFO)<<"click_to_event ["<<keyPosition._key<<"]"<<std::endl; |
|---|
| 1010 | constructor.layerClickEventOperation(keyPosition, relativeJump, slideNum, layerNum); |
|---|
| 1011 | } |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | else if (cur->name == "click_to_jump") |
|---|
| 1015 | { |
|---|
| 1016 | bool relativeJump = true; |
|---|
| 1017 | int slideNum = 0; |
|---|
| 1018 | int layerNum = 0; |
|---|
| 1019 | getJumpProperties(cur, relativeJump, slideNum, layerNum); |
|---|
| 1020 | |
|---|
| 1021 | constructor.layerClickEventOperation(osgPresentation::JUMP, relativeJump, slideNum, layerNum); |
|---|
| 1022 | } |
|---|
| 1023 | |
|---|
| 1024 | else if (cur->name == "newline") |
|---|
| 1025 | { |
|---|
| 1026 | constructor.translateTextCursor(osg::Vec3(0.0f,-0.05f,0.0f)); |
|---|
| 1027 | } |
|---|
| 1028 | else if (cur->name == "indent") |
|---|
| 1029 | { |
|---|
| 1030 | float localIndent = 0.05f; |
|---|
| 1031 | constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); |
|---|
| 1032 | totalIndent += localIndent; |
|---|
| 1033 | } |
|---|
| 1034 | else if (cur->name == "unindent") |
|---|
| 1035 | { |
|---|
| 1036 | float localIndent = -0.05f; |
|---|
| 1037 | constructor.translateTextCursor(osg::Vec3(localIndent,0.0f,0.0f)); |
|---|
| 1038 | totalIndent += localIndent; |
|---|
| 1039 | } |
|---|
| 1040 | else if (cur->name == "bullet") |
|---|
| 1041 | { |
|---|
| 1042 | osg::notify(osg::INFO)<<"bullet ["<<cur->contents<<"]"<<std::endl; |
|---|
| 1043 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); |
|---|
| 1044 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1045 | |
|---|
| 1046 | osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); |
|---|
| 1047 | bool fontRead = getProperties(cur,fontData); |
|---|
| 1048 | |
|---|
| 1049 | constructor.addBullet(cur->contents, |
|---|
| 1050 | positionRead ? positionData : constructor.getTextPositionData(), |
|---|
| 1051 | fontRead ? fontData : constructor.getTextFontData()); |
|---|
| 1052 | } |
|---|
| 1053 | else if (cur->name == "paragraph") |
|---|
| 1054 | { |
|---|
| 1055 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); |
|---|
| 1056 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1057 | |
|---|
| 1058 | osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); |
|---|
| 1059 | bool fontRead = getProperties(cur,fontData); |
|---|
| 1060 | |
|---|
| 1061 | constructor.addParagraph(cur->contents, |
|---|
| 1062 | positionRead ? positionData : constructor.getTextPositionData(), |
|---|
| 1063 | fontRead ? fontData : constructor.getTextFontData()); |
|---|
| 1064 | } |
|---|
| 1065 | else if (cur->name == "image") |
|---|
| 1066 | { |
|---|
| 1067 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); |
|---|
| 1068 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1069 | |
|---|
| 1070 | osgPresentation::SlideShowConstructor::ImageData imageData; |
|---|
| 1071 | getProperties(cur,imageData); |
|---|
| 1072 | |
|---|
| 1073 | constructor.addImage(cur->contents, |
|---|
| 1074 | positionRead ? positionData : constructor.getImagePositionData(), |
|---|
| 1075 | imageData); |
|---|
| 1076 | } |
|---|
| 1077 | else if (cur->name == "vnc") |
|---|
| 1078 | { |
|---|
| 1079 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); |
|---|
| 1080 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1081 | |
|---|
| 1082 | osgPresentation::SlideShowConstructor::ImageData imageData; |
|---|
| 1083 | getProperties(cur,imageData); |
|---|
| 1084 | |
|---|
| 1085 | constructor.addVNC(cur->contents, |
|---|
| 1086 | positionRead ? positionData : constructor.getImagePositionData(), |
|---|
| 1087 | imageData); |
|---|
| 1088 | } |
|---|
| 1089 | else if (cur->name == "browser") |
|---|
| 1090 | { |
|---|
| 1091 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); |
|---|
| 1092 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1093 | |
|---|
| 1094 | osgPresentation::SlideShowConstructor::ImageData imageData; |
|---|
| 1095 | getProperties(cur,imageData); |
|---|
| 1096 | |
|---|
| 1097 | constructor.addBrowser(cur->contents, |
|---|
| 1098 | positionRead ? positionData : constructor.getImagePositionData(), |
|---|
| 1099 | imageData); |
|---|
| 1100 | } |
|---|
| 1101 | else if (cur->name == "pdf") |
|---|
| 1102 | { |
|---|
| 1103 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); |
|---|
| 1104 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1105 | |
|---|
| 1106 | osgPresentation::SlideShowConstructor::ImageData imageData; |
|---|
| 1107 | getProperties(cur,imageData); |
|---|
| 1108 | |
|---|
| 1109 | constructor.addPDF(cur->contents, |
|---|
| 1110 | positionRead ? positionData : constructor.getImagePositionData(), |
|---|
| 1111 | imageData); |
|---|
| 1112 | } |
|---|
| 1113 | else if (cur->name == "stereo_pair") |
|---|
| 1114 | { |
|---|
| 1115 | parseStereoPair(constructor, cur); |
|---|
| 1116 | } |
|---|
| 1117 | else if (cur->name == "model") |
|---|
| 1118 | { |
|---|
| 1119 | parseModel(constructor, cur); |
|---|
| 1120 | } |
|---|
| 1121 | else if (cur->name == "volume") |
|---|
| 1122 | { |
|---|
| 1123 | parseVolume(constructor, cur); |
|---|
| 1124 | } |
|---|
| 1125 | else if (cur->name == "duration") |
|---|
| 1126 | { |
|---|
| 1127 | constructor.setLayerDuration(atof(cur->contents.c_str())); |
|---|
| 1128 | } |
|---|
| 1129 | else if (getKeyPosition(cur, keyPosition)) |
|---|
| 1130 | { |
|---|
| 1131 | constructor.addLayerKey(keyPosition); |
|---|
| 1132 | } |
|---|
| 1133 | } |
|---|
| 1134 | |
|---|
| 1135 | if (totalIndent != 0.0f) |
|---|
| 1136 | { |
|---|
| 1137 | constructor.translateTextCursor(osg::Vec3(-totalIndent,0.0f,0.0f)); |
|---|
| 1138 | } |
|---|
| 1139 | |
|---|
| 1140 | } |
|---|
| 1141 | |
|---|
| 1142 | void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const |
|---|
| 1143 | { |
|---|
| 1144 | constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); |
|---|
| 1145 | |
|---|
| 1146 | osg::notify(osg::INFO)<<"bullets ["<<cur->contents<<"]"<<std::endl; |
|---|
| 1147 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); |
|---|
| 1148 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1149 | |
|---|
| 1150 | osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); |
|---|
| 1151 | bool fontRead = getProperties(cur,fontData); |
|---|
| 1152 | |
|---|
| 1153 | constructor.addBullet(cur->contents, |
|---|
| 1154 | positionRead ? positionData : constructor.getTextPositionData(), |
|---|
| 1155 | fontRead ? fontData : constructor.getTextFontData()); |
|---|
| 1156 | } |
|---|
| 1157 | |
|---|
| 1158 | |
|---|
| 1159 | void ReaderWriterP3DXML::parseText(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur, bool inheritPreviousLayers, bool defineAsBaseLayer) const |
|---|
| 1160 | { |
|---|
| 1161 | constructor.addLayer(inheritPreviousLayers, defineAsBaseLayer); |
|---|
| 1162 | |
|---|
| 1163 | osg::notify(osg::INFO)<<"text ["<<cur->contents<<"]"<<std::endl; |
|---|
| 1164 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); |
|---|
| 1165 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1166 | |
|---|
| 1167 | osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); |
|---|
| 1168 | bool fontRead = getProperties(cur,fontData); |
|---|
| 1169 | |
|---|
| 1170 | constructor.addParagraph(cur->contents, |
|---|
| 1171 | positionRead ? positionData : constructor.getTextPositionData(), |
|---|
| 1172 | fontRead ? fontData : constructor.getTextFontData()); |
|---|
| 1173 | } |
|---|
| 1174 | |
|---|
| 1175 | void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const |
|---|
| 1176 | { |
|---|
| 1177 | constructor.addSlide(); |
|---|
| 1178 | |
|---|
| 1179 | std::string title; |
|---|
| 1180 | getProperty(cur, "title", title); |
|---|
| 1181 | |
|---|
| 1182 | std::string inherit; |
|---|
| 1183 | getProperty(cur, "inherit", inherit); |
|---|
| 1184 | |
|---|
| 1185 | if (!inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1186 | { |
|---|
| 1187 | parseSlide(constructor, _templateMap[inherit].get(), true, false); |
|---|
| 1188 | } |
|---|
| 1189 | |
|---|
| 1190 | if (!title.empty()) |
|---|
| 1191 | { |
|---|
| 1192 | constructor.setSlideTitle(title, |
|---|
| 1193 | constructor.getTitlePositionData(), |
|---|
| 1194 | constructor.getTitleFontData()); |
|---|
| 1195 | } |
|---|
| 1196 | |
|---|
| 1197 | if (!inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1198 | { |
|---|
| 1199 | parseSlide(constructor, _templateMap[inherit].get(), false, true); |
|---|
| 1200 | } |
|---|
| 1201 | |
|---|
| 1202 | constructor.addLayer(true,false); |
|---|
| 1203 | |
|---|
| 1204 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTextPositionData(); |
|---|
| 1205 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1206 | |
|---|
| 1207 | osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData(); |
|---|
| 1208 | bool fontRead = getProperties(cur,fontData); |
|---|
| 1209 | |
|---|
| 1210 | constructor.addParagraph(cur->contents, |
|---|
| 1211 | positionRead ? positionData : constructor.getTextPositionData(), |
|---|
| 1212 | fontRead ? fontData : constructor.getTextFontData()); |
|---|
| 1213 | } |
|---|
| 1214 | |
|---|
| 1215 | void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const |
|---|
| 1216 | { |
|---|
| 1217 | std::string title; |
|---|
| 1218 | getProperty(cur, "title", title); |
|---|
| 1219 | |
|---|
| 1220 | std::string inherit; |
|---|
| 1221 | getProperty(cur, "inherit", inherit); |
|---|
| 1222 | |
|---|
| 1223 | constructor.addSlide(); |
|---|
| 1224 | |
|---|
| 1225 | if (!inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1226 | { |
|---|
| 1227 | parseSlide(constructor, _templateMap[inherit].get(), true, false); |
|---|
| 1228 | } |
|---|
| 1229 | |
|---|
| 1230 | if (!title.empty()) |
|---|
| 1231 | { |
|---|
| 1232 | constructor.setSlideTitle(title, |
|---|
| 1233 | constructor.getTitlePositionData(), |
|---|
| 1234 | constructor.getTitleFontData()); |
|---|
| 1235 | } |
|---|
| 1236 | |
|---|
| 1237 | if (!inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1238 | { |
|---|
| 1239 | parseSlide(constructor, _templateMap[inherit].get(), false, true); |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | constructor.addLayer(true,false); |
|---|
| 1243 | |
|---|
| 1244 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getImagePositionData(); |
|---|
| 1245 | getProperties(cur,positionData); |
|---|
| 1246 | |
|---|
| 1247 | osgPresentation::SlideShowConstructor::ImageData imageData; |
|---|
| 1248 | imageData.page = 0; |
|---|
| 1249 | getProperties(cur,imageData); |
|---|
| 1250 | |
|---|
| 1251 | osg::Image* image = constructor.addInteractiveImage(cur->contents, positionData, imageData); |
|---|
| 1252 | osgWidget::PdfImage* pdfImage = dynamic_cast<osgWidget::PdfImage*>(image); |
|---|
| 1253 | if (pdfImage) |
|---|
| 1254 | { |
|---|
| 1255 | int numPages = pdfImage->getNumOfPages(); |
|---|
| 1256 | osg::notify(osg::NOTICE)<<"NumOfPages = "<<numPages<<std::endl; |
|---|
| 1257 | |
|---|
| 1258 | if (numPages>1) |
|---|
| 1259 | { |
|---|
| 1260 | for(int pageNum=1; pageNum<numPages; ++pageNum) |
|---|
| 1261 | { |
|---|
| 1262 | imageData.page = pageNum; |
|---|
| 1263 | |
|---|
| 1264 | constructor.addSlide(); |
|---|
| 1265 | |
|---|
| 1266 | if (!inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1267 | { |
|---|
| 1268 | parseSlide(constructor, _templateMap[inherit].get(), true, false); |
|---|
| 1269 | } |
|---|
| 1270 | |
|---|
| 1271 | if (!title.empty()) |
|---|
| 1272 | { |
|---|
| 1273 | constructor.setSlideTitle(title, |
|---|
| 1274 | constructor.getTitlePositionData(), |
|---|
| 1275 | constructor.getTitleFontData()); |
|---|
| 1276 | } |
|---|
| 1277 | |
|---|
| 1278 | if (!inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1279 | { |
|---|
| 1280 | parseSlide(constructor, _templateMap[inherit].get(), false, true); |
|---|
| 1281 | } |
|---|
| 1282 | |
|---|
| 1283 | constructor.addLayer(true,false); |
|---|
| 1284 | |
|---|
| 1285 | constructor.addPDF(cur->contents, positionData, imageData); |
|---|
| 1286 | |
|---|
| 1287 | } |
|---|
| 1288 | } |
|---|
| 1289 | } |
|---|
| 1290 | } |
|---|
| 1291 | |
|---|
| 1292 | void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root, bool parseTitles, bool parseLayers) const |
|---|
| 1293 | { |
|---|
| 1294 | |
|---|
| 1295 | osg::Vec4 previous_bgcolor = constructor.getBackgroundColor(); |
|---|
| 1296 | osg::Vec4 previous_textcolor = constructor.getTextColor(); |
|---|
| 1297 | |
|---|
| 1298 | |
|---|
| 1299 | osgPresentation::KeyPosition keyPosition; |
|---|
| 1300 | |
|---|
| 1301 | for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); |
|---|
| 1302 | itr != root->children.end(); |
|---|
| 1303 | ++itr) |
|---|
| 1304 | { |
|---|
| 1305 | osgDB::XmlNode* cur = itr->get(); |
|---|
| 1306 | |
|---|
| 1307 | if (parseTitles) |
|---|
| 1308 | { |
|---|
| 1309 | if (cur->name == "title") |
|---|
| 1310 | { |
|---|
| 1311 | osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getTitlePositionData(); |
|---|
| 1312 | bool positionRead = getProperties(cur,positionData); |
|---|
| 1313 | |
|---|
| 1314 | osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTitleFontData(); |
|---|
| 1315 | bool fontRead = getProperties(cur,fontData); |
|---|
| 1316 | |
|---|
| 1317 | constructor.setSlideTitle(cur->contents, |
|---|
| 1318 | positionRead ? positionData : constructor.getTitlePositionData(), |
|---|
| 1319 | fontRead ? fontData : constructor.getTitleFontData()); |
|---|
| 1320 | } |
|---|
| 1321 | else if (cur->name == "background") |
|---|
| 1322 | { |
|---|
| 1323 | constructor.setSlideBackground(cur->contents); |
|---|
| 1324 | } |
|---|
| 1325 | else if (cur->name == "bgcolor") |
|---|
| 1326 | { |
|---|
| 1327 | constructor.setBackgroundColor(mapStringToColor(cur->contents),true); |
|---|
| 1328 | } |
|---|
| 1329 | else if (cur->name == "textcolor") |
|---|
| 1330 | { |
|---|
| 1331 | constructor.setTextColor(mapStringToColor(cur->contents)); |
|---|
| 1332 | } |
|---|
| 1333 | } |
|---|
| 1334 | if (parseLayers) |
|---|
| 1335 | { |
|---|
| 1336 | if (cur->name == "base") |
|---|
| 1337 | { |
|---|
| 1338 | constructor.addLayer(true, true); |
|---|
| 1339 | parseLayer (constructor, cur); |
|---|
| 1340 | } |
|---|
| 1341 | else if (cur->name == "layer") |
|---|
| 1342 | { |
|---|
| 1343 | constructor.addLayer(true, false); |
|---|
| 1344 | parseLayer (constructor, cur); |
|---|
| 1345 | } |
|---|
| 1346 | else if (cur->name == "clean_layer") |
|---|
| 1347 | { |
|---|
| 1348 | constructor.addLayer(false, false); |
|---|
| 1349 | parseLayer (constructor, cur); |
|---|
| 1350 | } |
|---|
| 1351 | else if (cur->name == "modify_layer") |
|---|
| 1352 | { |
|---|
| 1353 | int layerNum; |
|---|
| 1354 | if (getProperty(cur, "layer", layerNum)) |
|---|
| 1355 | { |
|---|
| 1356 | constructor.selectLayer(layerNum); |
|---|
| 1357 | } |
|---|
| 1358 | else |
|---|
| 1359 | { |
|---|
| 1360 | constructor.addLayer(true, false); |
|---|
| 1361 | } |
|---|
| 1362 | |
|---|
| 1363 | parseLayer (constructor, cur); |
|---|
| 1364 | } |
|---|
| 1365 | else if (cur->name == "bullets") |
|---|
| 1366 | { |
|---|
| 1367 | parseBullets (constructor, cur,true, false); |
|---|
| 1368 | } |
|---|
| 1369 | else if (cur->name == "duration") |
|---|
| 1370 | { |
|---|
| 1371 | constructor.setSlideDuration(atof(cur->contents.c_str())); |
|---|
| 1372 | } |
|---|
| 1373 | else if (getKeyPosition(cur, keyPosition)) |
|---|
| 1374 | { |
|---|
| 1375 | constructor.addSlideKey(keyPosition); |
|---|
| 1376 | } |
|---|
| 1377 | } |
|---|
| 1378 | } |
|---|
| 1379 | |
|---|
| 1380 | constructor.setBackgroundColor(previous_bgcolor,false); |
|---|
| 1381 | constructor.setTextColor(previous_textcolor); |
|---|
| 1382 | |
|---|
| 1383 | return; |
|---|
| 1384 | } |
|---|
| 1385 | |
|---|
| 1386 | #include <iostream> |
|---|
| 1387 | |
|---|
| 1388 | osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(const std::string& file, |
|---|
| 1389 | const osgDB::ReaderWriter::Options* options) const |
|---|
| 1390 | { |
|---|
| 1391 | std::string ext = osgDB::getLowerCaseFileExtension(file); |
|---|
| 1392 | if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; |
|---|
| 1393 | |
|---|
| 1394 | std::string fileName = osgDB::findDataFile( file ); |
|---|
| 1395 | if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; |
|---|
| 1396 | |
|---|
| 1397 | osgDB::XmlNode::Input input; |
|---|
| 1398 | input.open(fileName); |
|---|
| 1399 | input.readAllDataIntoBuffer(); |
|---|
| 1400 | |
|---|
| 1401 | return readNode(input, options); |
|---|
| 1402 | } |
|---|
| 1403 | |
|---|
| 1404 | osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(std::istream& fin, const Options* options) const |
|---|
| 1405 | { |
|---|
| 1406 | osgDB::XmlNode::Input input; |
|---|
| 1407 | input.attach(fin); |
|---|
| 1408 | input.readAllDataIntoBuffer(); |
|---|
| 1409 | |
|---|
| 1410 | return readNode(input, options); |
|---|
| 1411 | } |
|---|
| 1412 | |
|---|
| 1413 | osgDB::ReaderWriter::ReadResult ReaderWriterP3DXML::readNode(osgDB::XmlNode::Input& input, const osgDB::ReaderWriter::Options* options) const |
|---|
| 1414 | { |
|---|
| 1415 | bool readOnlyHoldingPage = options ? options->getOptionString()=="holding_slide" : false; |
|---|
| 1416 | |
|---|
| 1417 | |
|---|
| 1418 | osgPresentation::KeyPosition keyPosition; |
|---|
| 1419 | |
|---|
| 1420 | osg::ref_ptr<osgDB::XmlNode> doc = new osgDB::XmlNode; |
|---|
| 1421 | osgDB::XmlNode* root = 0; |
|---|
| 1422 | |
|---|
| 1423 | |
|---|
| 1424 | doc->read(input); |
|---|
| 1425 | |
|---|
| 1426 | |
|---|
| 1427 | |
|---|
| 1428 | if (doc == NULL ) |
|---|
| 1429 | { |
|---|
| 1430 | fprintf(stderr,"Document not parsed successfully. \n"); |
|---|
| 1431 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 1432 | } |
|---|
| 1433 | |
|---|
| 1434 | for(osgDB::XmlNode::Children::iterator itr = doc->children.begin(); |
|---|
| 1435 | itr != doc->children.end() && !root; |
|---|
| 1436 | ++itr) |
|---|
| 1437 | { |
|---|
| 1438 | if ((*itr)->name=="presentation") root = itr->get(); |
|---|
| 1439 | } |
|---|
| 1440 | |
|---|
| 1441 | if (root == NULL) |
|---|
| 1442 | { |
|---|
| 1443 | fprintf(stderr,"empty document\n"); |
|---|
| 1444 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 1445 | } |
|---|
| 1446 | |
|---|
| 1447 | if (root->name!="presentation") |
|---|
| 1448 | { |
|---|
| 1449 | fprintf(stderr,"document of the wrong type, root node != presentation"); |
|---|
| 1450 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 1451 | } |
|---|
| 1452 | |
|---|
| 1453 | osgPresentation::SlideShowConstructor constructor; |
|---|
| 1454 | |
|---|
| 1455 | osgDB::FilePathList previousPaths = osgDB::getDataFilePathList(); |
|---|
| 1456 | |
|---|
| 1457 | bool readSlide = false; |
|---|
| 1458 | |
|---|
| 1459 | for(osgDB::XmlNode::Children::iterator itr = root->children.begin(); |
|---|
| 1460 | itr != root->children.end(); |
|---|
| 1461 | ++itr) |
|---|
| 1462 | { |
|---|
| 1463 | osgDB::XmlNode* cur = itr->get(); |
|---|
| 1464 | |
|---|
| 1465 | if (cur->name == "name") |
|---|
| 1466 | { |
|---|
| 1467 | constructor.setPresentationName(cur->contents); |
|---|
| 1468 | } |
|---|
| 1469 | else if (cur->name == "loop") |
|---|
| 1470 | { |
|---|
| 1471 | constructor.setLoopPresentation(true); |
|---|
| 1472 | } |
|---|
| 1473 | else if (cur->name == "auto") |
|---|
| 1474 | { |
|---|
| 1475 | constructor.setAutoSteppingActive(true); |
|---|
| 1476 | } |
|---|
| 1477 | else if (cur->name == "title-settings") |
|---|
| 1478 | { |
|---|
| 1479 | bool fontRead = getProperties(cur,constructor.getTitleFontDataDefault()); |
|---|
| 1480 | if (fontRead) |
|---|
| 1481 | { |
|---|
| 1482 | osg::notify(osg::INFO)<<"Title font details read"<<std::endl; |
|---|
| 1483 | } |
|---|
| 1484 | } |
|---|
| 1485 | else if (cur->name == "text-settings") |
|---|
| 1486 | { |
|---|
| 1487 | bool fontRead = getProperties(cur,constructor.getTextFontDataDefault()); |
|---|
| 1488 | if (fontRead) |
|---|
| 1489 | { |
|---|
| 1490 | osg::notify(osg::INFO)<<"Text font details read"<<std::endl; |
|---|
| 1491 | } |
|---|
| 1492 | } |
|---|
| 1493 | |
|---|
| 1494 | |
|---|
| 1495 | |
|---|
| 1496 | |
|---|
| 1497 | |
|---|
| 1498 | |
|---|
| 1499 | else if (cur->name == "path") |
|---|
| 1500 | { |
|---|
| 1501 | osg::notify(osg::INFO)<<"Appending search path "<<cur->contents<<std::endl; |
|---|
| 1502 | osgDB::getDataFilePathList().push_front(expandEnvVarsInFileName(cur->contents)); |
|---|
| 1503 | } |
|---|
| 1504 | else if (cur->name == "bgcolor") |
|---|
| 1505 | { |
|---|
| 1506 | constructor.setBackgroundColor(mapStringToColor(cur->contents),false); |
|---|
| 1507 | } |
|---|
| 1508 | else if (cur->name == "textcolor") |
|---|
| 1509 | { |
|---|
| 1510 | constructor.setTextColor(mapStringToColor(cur->contents)); |
|---|
| 1511 | } |
|---|
| 1512 | else if (cur->name == "duration") |
|---|
| 1513 | { |
|---|
| 1514 | constructor.setPresentationDuration(atof(cur->contents.c_str())); |
|---|
| 1515 | } |
|---|
| 1516 | else if (getKeyPosition(cur, keyPosition)) |
|---|
| 1517 | { |
|---|
| 1518 | constructor.addPresentationKey(keyPosition); |
|---|
| 1519 | } |
|---|
| 1520 | else if (readOnlyHoldingPage && cur->name == "holding_slide") |
|---|
| 1521 | { |
|---|
| 1522 | readSlide = true; |
|---|
| 1523 | constructor.addSlide(); |
|---|
| 1524 | parseSlide (constructor, cur); |
|---|
| 1525 | } |
|---|
| 1526 | else if (!readOnlyHoldingPage && cur->name == "slide") |
|---|
| 1527 | { |
|---|
| 1528 | readSlide = true; |
|---|
| 1529 | constructor.addSlide(); |
|---|
| 1530 | |
|---|
| 1531 | std::string inherit; |
|---|
| 1532 | if (getProperty(cur, "inherit", inherit) && !inherit.empty() && _templateMap.count(inherit)!=0) |
|---|
| 1533 | { |
|---|
| 1534 | parseSlide(constructor, _templateMap[inherit].get(), true, false); |
|---|
| 1535 | parseSlide (constructor, cur, true, false); |
|---|
| 1536 | parseSlide(constructor, _templateMap[inherit].get(), false, true); |
|---|
| 1537 | parseSlide (constructor, cur, false, true); |
|---|
| 1538 | } |
|---|
| 1539 | else |
|---|
| 1540 | { |
|---|
| 1541 | parseSlide (constructor, cur); |
|---|
| 1542 | } |
|---|
| 1543 | } |
|---|
| 1544 | else if (!readOnlyHoldingPage && cur->name == "modify_slide") |
|---|
| 1545 | { |
|---|
| 1546 | readSlide = true; |
|---|
| 1547 | int slideNum; |
|---|
| 1548 | if (getProperty(cur, "slide", slideNum)) |
|---|
| 1549 | { |
|---|
| 1550 | constructor.selectSlide(slideNum); |
|---|
| 1551 | parseSlide (constructor, cur); |
|---|
| 1552 | } |
|---|
| 1553 | else |
|---|
| 1554 | { |
|---|
| 1555 | constructor.addSlide(); |
|---|
| 1556 | } |
|---|
| 1557 | } |
|---|
| 1558 | else if (!readOnlyHoldingPage && cur->name == "page") |
|---|
| 1559 | { |
|---|
| 1560 | readSlide = true; |
|---|
| 1561 | parsePage (constructor, cur); |
|---|
| 1562 | } |
|---|
| 1563 | else if (!readOnlyHoldingPage && cur->name == "pdf_document") |
|---|
| 1564 | { |
|---|
| 1565 | readSlide = true; |
|---|
| 1566 | parsePdfDocument(constructor, cur); |
|---|
| 1567 | } |
|---|
| 1568 | else if (!readOnlyHoldingPage && cur->name == "template_slide") |
|---|
| 1569 | { |
|---|
| 1570 | readSlide = true; |
|---|
| 1571 | std::string name; |
|---|
| 1572 | if (getProperty(cur, "name", name)) |
|---|
| 1573 | { |
|---|
| 1574 | _templateMap[name] = cur; |
|---|
| 1575 | std::cout<<"Defining template slide "<<name<<std::endl; |
|---|
| 1576 | } |
|---|
| 1577 | } |
|---|
| 1578 | } |
|---|
| 1579 | |
|---|
| 1580 | |
|---|
| 1581 | osgDB::getDataFilePathList() = previousPaths; |
|---|
| 1582 | |
|---|
| 1583 | return constructor.takePresentation(); |
|---|
| 1584 | |
|---|
| 1585 | |
|---|
| 1586 | |
|---|
| 1587 | |
|---|
| 1588 | } |
|---|