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