| 1 | #include "osg/Switch" |
|---|
| 2 | |
|---|
| 3 | #include "osgDB/Registry" |
|---|
| 4 | #include "osgDB/Input" |
|---|
| 5 | #include "osgDB/Output" |
|---|
| 6 | |
|---|
| 7 | using namespace osg; |
|---|
| 8 | using namespace osgDB; |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | bool Switch_readLocalData(Object& obj, Input& fr); |
|---|
| 12 | bool Switch_writeLocalData(const Object& obj, Output& fw); |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | REGISTER_DOTOSGWRAPPER(Switch) |
|---|
| 16 | ( |
|---|
| 17 | new osg::Switch, |
|---|
| 18 | "Switch", |
|---|
| 19 | "Object Node Switch Group", |
|---|
| 20 | &Switch_readLocalData, |
|---|
| 21 | &Switch_writeLocalData |
|---|
| 22 | ); |
|---|
| 23 | |
|---|
| 24 | bool Switch_readLocalData(Object& obj, Input& fr) |
|---|
| 25 | { |
|---|
| 26 | bool iteratorAdvanced = false; |
|---|
| 27 | |
|---|
| 28 | Switch& sw = static_cast<Switch&>(obj); |
|---|
| 29 | |
|---|
| 30 | if (fr.matchSequence("value")) |
|---|
| 31 | { |
|---|
| 32 | if (fr[1].matchWord("ALL_CHILDREN_ON")) |
|---|
| 33 | { |
|---|
| 34 | sw.setAllChildrenOn(); |
|---|
| 35 | iteratorAdvanced = true; |
|---|
| 36 | fr+=2; |
|---|
| 37 | } |
|---|
| 38 | else if (fr[1].matchWord("ALL_CHILDREN_OFF")) |
|---|
| 39 | { |
|---|
| 40 | sw.setAllChildrenOff(); |
|---|
| 41 | iteratorAdvanced = true; |
|---|
| 42 | fr+=2; |
|---|
| 43 | } |
|---|
| 44 | else if (fr[1].isInt()) |
|---|
| 45 | { |
|---|
| 46 | unsigned int value; |
|---|
| 47 | fr[1].getUInt(value); |
|---|
| 48 | sw.setSingleChildOn(value); |
|---|
| 49 | iteratorAdvanced = true; |
|---|
| 50 | fr+=2; |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | if (fr[0].matchWord("NewChildDefaultValue")) |
|---|
| 55 | { |
|---|
| 56 | if (fr[1].matchWord("TRUE")) |
|---|
| 57 | { |
|---|
| 58 | sw.setNewChildDefaultValue(true); |
|---|
| 59 | iteratorAdvanced = true; |
|---|
| 60 | fr += 2; |
|---|
| 61 | } |
|---|
| 62 | else if (fr[1].matchWord("FALSE")) |
|---|
| 63 | { |
|---|
| 64 | sw.setNewChildDefaultValue(false); |
|---|
| 65 | iteratorAdvanced = true; |
|---|
| 66 | fr += 2; |
|---|
| 67 | } |
|---|
| 68 | else if (fr[1].isInt()) |
|---|
| 69 | { |
|---|
| 70 | int value; |
|---|
| 71 | fr[1].getInt(value); |
|---|
| 72 | sw.setNewChildDefaultValue(value!=0); |
|---|
| 73 | iteratorAdvanced = true; |
|---|
| 74 | fr += 2; |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | if (fr.matchSequence("ValueList {")) |
|---|
| 79 | { |
|---|
| 80 | int entry = fr[0].getNoNestedBrackets(); |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | fr += 2; |
|---|
| 84 | |
|---|
| 85 | unsigned int pos=0; |
|---|
| 86 | while (!fr.eof() && fr[0].getNoNestedBrackets()>entry) |
|---|
| 87 | { |
|---|
| 88 | int value; |
|---|
| 89 | if (fr[0].getInt(value)) |
|---|
| 90 | { |
|---|
| 91 | sw.setValue(pos,value!=0); |
|---|
| 92 | ++pos; |
|---|
| 93 | } |
|---|
| 94 | ++fr; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | ++fr; |
|---|
| 98 | |
|---|
| 99 | iteratorAdvanced = true; |
|---|
| 100 | |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | return iteratorAdvanced; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | bool Switch_writeLocalData(const Object& obj, Output& fw) |
|---|
| 108 | { |
|---|
| 109 | const Switch& sw = static_cast<const Switch&>(obj); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | fw.indent()<<"NewChildDefaultValue "<<sw.getNewChildDefaultValue()<<std::endl; |
|---|
| 113 | |
|---|
| 114 | fw.indent()<<"ValueList {"<< std::endl; |
|---|
| 115 | fw.moveIn(); |
|---|
| 116 | const Switch::ValueList& values = sw.getValueList(); |
|---|
| 117 | for(Switch::ValueList::const_iterator itr=values.begin(); |
|---|
| 118 | itr!=values.end(); |
|---|
| 119 | ++itr) |
|---|
| 120 | { |
|---|
| 121 | fw.indent()<<*itr<<std::endl; |
|---|
| 122 | } |
|---|
| 123 | fw.moveOut(); |
|---|
| 124 | fw.indent()<<"}"<< std::endl; |
|---|
| 125 | |
|---|
| 126 | return true; |
|---|
| 127 | } |
|---|