| 1 | #include <osgSim/ShapeAttribute> |
|---|
| 2 | |
|---|
| 3 | #include <iostream> |
|---|
| 4 | #include <string> |
|---|
| 5 | |
|---|
| 6 | #include <osgDB/Registry> |
|---|
| 7 | #include <osgDB/Input> |
|---|
| 8 | #include <osgDB/Output> |
|---|
| 9 | #include <osgDB/ParameterOutput> |
|---|
| 10 | |
|---|
| 11 | using namespace osgSim; |
|---|
| 12 | |
|---|
| 13 | bool ShapeAttributeList_readLocalData(osg::Object &obj, osgDB::Input &fr); |
|---|
| 14 | bool ShapeAttributeList_writeLocalData(const osg::Object &obj, osgDB::Output &fw); |
|---|
| 15 | |
|---|
| 16 | REGISTER_DOTOSGWRAPPER(ShapeAttributeList_Proxy) |
|---|
| 17 | ( |
|---|
| 18 | new ShapeAttributeList, |
|---|
| 19 | "ShapeAttributeList", |
|---|
| 20 | "Object ShapeAttributeList", |
|---|
| 21 | &ShapeAttributeList_readLocalData, |
|---|
| 22 | &ShapeAttributeList_writeLocalData, |
|---|
| 23 | osgDB::DotOsgWrapper::READ_AND_WRITE |
|---|
| 24 | ); |
|---|
| 25 | |
|---|
| 26 | bool ShapeAttributeList_readLocalData(osg::Object &obj, osgDB::Input &fr) |
|---|
| 27 | { |
|---|
| 28 | bool iteratorAdvanced = false; |
|---|
| 29 | ShapeAttributeList &sal = static_cast<ShapeAttributeList &>(obj); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 33 | |
|---|
| 34 | while (!fr.eof() && fr[0].getNoNestedBrackets()>=entry) |
|---|
| 35 | { |
|---|
| 36 | if (fr.matchSequence("string %s %s")) |
|---|
| 37 | { |
|---|
| 38 | sal.push_back(osgSim::ShapeAttribute(fr[1].getStr(), fr[2].getStr())); |
|---|
| 39 | fr += 3; |
|---|
| 40 | iteratorAdvanced = true; |
|---|
| 41 | } |
|---|
| 42 | else if (fr.matchSequence("double %s %f")) |
|---|
| 43 | { |
|---|
| 44 | double value; |
|---|
| 45 | fr[2].getFloat(value); |
|---|
| 46 | sal.push_back(osgSim::ShapeAttribute(fr[1].getStr(), value)); |
|---|
| 47 | fr += 3; |
|---|
| 48 | iteratorAdvanced = true; |
|---|
| 49 | } |
|---|
| 50 | else if (fr.matchSequence("int %s %i")) |
|---|
| 51 | { |
|---|
| 52 | int value; |
|---|
| 53 | fr[2].getInt(value); |
|---|
| 54 | sal.push_back(osgSim::ShapeAttribute(fr[1].getStr(), value)); |
|---|
| 55 | fr += 3; |
|---|
| 56 | iteratorAdvanced = true; |
|---|
| 57 | } |
|---|
| 58 | else ++fr; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | return iteratorAdvanced; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | bool ShapeAttributeList_writeLocalData(const osg::Object &obj, osgDB::Output &fw) |
|---|
| 66 | { |
|---|
| 67 | const ShapeAttributeList &sal = static_cast<const ShapeAttributeList &>(obj); |
|---|
| 68 | |
|---|
| 69 | for (ShapeAttributeList::const_iterator it = sal.begin(); it != sal.end(); ++it) |
|---|
| 70 | { |
|---|
| 71 | switch (it->getType()) |
|---|
| 72 | { |
|---|
| 73 | case osgSim::ShapeAttribute::STRING: |
|---|
| 74 | { |
|---|
| 75 | fw.indent()<<"string "<< fw.wrapString(it->getName())<<" "<<fw.wrapString(it->getString()) << std::endl; |
|---|
| 76 | break; |
|---|
| 77 | } |
|---|
| 78 | case osgSim::ShapeAttribute::INTEGER: |
|---|
| 79 | { |
|---|
| 80 | fw.indent()<<"int "<< fw.wrapString(it->getName())<<" "<<it->getInt() << std::endl; |
|---|
| 81 | break; |
|---|
| 82 | } |
|---|
| 83 | case osgSim::ShapeAttribute::DOUBLE: |
|---|
| 84 | { |
|---|
| 85 | fw.indent()<<"double "<< fw.wrapString(it->getName())<<" "<<it->getDouble() << std::endl; |
|---|
| 86 | break; |
|---|
| 87 | } |
|---|
| 88 | case osgSim::ShapeAttribute::UNKNOWN: |
|---|
| 89 | default: break; |
|---|
| 90 | } |
|---|
| 91 | } |
|---|
| 92 | return true; |
|---|
| 93 | } |
|---|