| 1 | #include <osgDB/Registry> |
|---|
| 2 | #include <osgDB/Input> |
|---|
| 3 | #include <osgDB/Output> |
|---|
| 4 | #include <osgDB/WriteFile> |
|---|
| 5 | #include <osg/ref_ptr> |
|---|
| 6 | #include <iostream> |
|---|
| 7 | |
|---|
| 8 | #include "TXPNode.h" |
|---|
| 9 | |
|---|
| 10 | using namespace osg; |
|---|
| 11 | |
|---|
| 12 | bool TXPNode_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 13 | bool TXPNode_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 14 | |
|---|
| 15 | osgDB::RegisterDotOsgWrapperProxy TXPNode_Proxy |
|---|
| 16 | ( |
|---|
| 17 | new txp::TXPNode, |
|---|
| 18 | "TXPNode", |
|---|
| 19 | "Object Node TXPNode", |
|---|
| 20 | TXPNode_readLocalData, |
|---|
| 21 | TXPNode_writeLocalData |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | bool TXPNode_readLocalData(osg::Object &obj, osgDB::Input &fr) |
|---|
| 25 | { |
|---|
| 26 | txp::TXPNode &txpNode = static_cast<txp::TXPNode &>(obj); |
|---|
| 27 | bool itrAdvanced = false; |
|---|
| 28 | |
|---|
| 29 | if (fr.matchSequence("databaseOptions %s")) |
|---|
| 30 | { |
|---|
| 31 | txpNode.setOptions(fr[1].getStr()); |
|---|
| 32 | fr += 2; |
|---|
| 33 | itrAdvanced = true; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | if (fr.matchSequence("databaseName %s")) |
|---|
| 37 | { |
|---|
| 38 | txpNode.setArchiveName(fr[1].getStr()); |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | txpNode.loadArchive(NULL); |
|---|
| 44 | |
|---|
| 45 | fr += 2; |
|---|
| 46 | itrAdvanced = true; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | return itrAdvanced; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | class Dump2Osg : public osg::NodeVisitor |
|---|
| 54 | { |
|---|
| 55 | public: |
|---|
| 56 | Dump2Osg( osgDB::Output &fw ) : osg::NodeVisitor( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ), _fw( fw ) |
|---|
| 57 | {} |
|---|
| 58 | |
|---|
| 59 | virtual void apply(osg::Node& node) |
|---|
| 60 | { |
|---|
| 61 | _fw.writeObject(node); |
|---|
| 62 | NodeVisitor::apply(node); |
|---|
| 63 | } |
|---|
| 64 | osgDB::Output &_fw; |
|---|
| 65 | |
|---|
| 66 | protected: |
|---|
| 67 | |
|---|
| 68 | Dump2Osg& operator = (const Dump2Osg&) { return *this; } |
|---|
| 69 | }; |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | bool TXPNode_writeLocalData(const osg::Object &obj, osgDB::Output &fw) |
|---|
| 73 | { |
|---|
| 74 | const txp::TXPNode &txpNode = static_cast<const txp::TXPNode&>(obj); |
|---|
| 75 | |
|---|
| 76 | if ( !txpNode.getOptions().empty() ) |
|---|
| 77 | fw.indent() << "databaseOptions \"" << txpNode.getOptions() << "\"" << std::endl; |
|---|
| 78 | if ( !txpNode.getArchiveName().empty() ) |
|---|
| 79 | fw.indent() << "databaseName \"" << txpNode.getArchiveName() << "\"" << std::endl; |
|---|
| 80 | |
|---|
| 81 | osg::Group* grp = const_cast<osg::Group*>(txpNode.asGroup()); |
|---|
| 82 | |
|---|
| 83 | Dump2Osg wrt(fw); |
|---|
| 84 | grp->accept(wrt); |
|---|
| 85 | |
|---|
| 86 | return true; |
|---|
| 87 | } |
|---|
| 88 | |
|---|