From b9ae28d344a8965579979eb389fb051989407cd8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 26 Nov 2010 17:35:06 +0000 Subject: [PATCH] From Eduardo Poyart, OSG patch: made it read ancillary IndexedStrings into MultiSwitch --- include/osgSim/MultiSwitch | 16 ++++++---- .../OpenFlight/AncillaryRecords.cpp | 30 ++++++++++++++++++- src/osgPlugins/OpenFlight/PrimaryRecords.cpp | 8 +++++ src/osgPlugins/OpenFlight/Record.h | 1 + src/osgSim/MultiSwitch.cpp | 8 +++++ 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/include/osgSim/MultiSwitch b/include/osgSim/MultiSwitch index d400279b6..7501e5d75 100644 --- a/include/osgSim/MultiSwitch +++ b/include/osgSim/MultiSwitch @@ -69,8 +69,9 @@ class OSGSIM_EXPORT MultiSwitch : public osg::Group /** Get which of the available switch set lists to use.*/ unsigned int getActiveSwitchSet() const { return _activeSwitchSet; } - typedef std::vector ValueList; - typedef std::vector SwitchSetList; + typedef std::vector ValueList; + typedef std::vector SwitchSetList; + typedef std::vector SwitchSetNameList; /** Set the compile set of different values.*/ void setSwitchSetList(const SwitchSetList& switchSetList); @@ -84,6 +85,10 @@ class OSGSIM_EXPORT MultiSwitch : public osg::Group /** Get the a single set of different values for a particular switch set.*/ const ValueList& getValueList(unsigned int switchSet) const { return _values[switchSet]; } + void setValueName(unsigned int switchSet, const std::string& name); + + const std::string& getValueName(unsigned int switchSet) const { return _valueNames[switchSet]; } + protected : virtual ~MultiSwitch() {} @@ -91,9 +96,10 @@ class OSGSIM_EXPORT MultiSwitch : public osg::Group void expandToEncompassSwitchSet(unsigned int switchSet); // this is effectively a list of bit mask. - bool _newChildDefaultValue; - unsigned int _activeSwitchSet; - SwitchSetList _values; + bool _newChildDefaultValue; + unsigned int _activeSwitchSet; + SwitchSetList _values; + SwitchSetNameList _valueNames; }; } diff --git a/src/osgPlugins/OpenFlight/AncillaryRecords.cpp b/src/osgPlugins/OpenFlight/AncillaryRecords.cpp index a5e7ffdef..fce52d9c6 100644 --- a/src/osgPlugins/OpenFlight/AncillaryRecords.cpp +++ b/src/osgPlugins/OpenFlight/AncillaryRecords.cpp @@ -316,6 +316,35 @@ class Replicate : public Record REGISTER_FLTRECORD(Replicate, REPLICATE_OP) + +/** IndexedString - + */ +class IndexedString : public Record +{ + public: + + IndexedString() {} + + META_Record(IndexedString) + + protected: + + virtual ~IndexedString() {} + + virtual void readRecord(RecordInputStream& in, Document& /*document*/) + { + std::streamsize size = in.getRecordSize(); + uint32 index = in.readUInt32(); + std::string name = in.readString(size-8); + + if (_parent.valid()) + _parent->setMultiSwitchValueName(index, name); + } +}; + +REGISTER_FLTRECORD(IndexedString, INDEXED_STRING_OP) + + // Prevent "unknown record" message for the following ancillary records: REGISTER_FLTRECORD(DummyRecord, OLD_TRANSLATE2_OP) REGISTER_FLTRECORD(DummyRecord, OLD_ROTATE_ABOUT_POINT_OP) @@ -327,7 +356,6 @@ REGISTER_FLTRECORD(DummyRecord, OLD_ROTATE_ABOUT_POINT2_OP) REGISTER_FLTRECORD(DummyRecord, OLD_ROTATE_SCALE_TO_POINT_OP) REGISTER_FLTRECORD(DummyRecord, OLD_PUT_TRANSFORM_OP) REGISTER_FLTRECORD(DummyRecord, OLD_BOUNDING_BOX_OP) -REGISTER_FLTRECORD(DummyRecord, INDEXED_STRING_OP) REGISTER_FLTRECORD(DummyRecord, ROAD_ZONE_OP) REGISTER_FLTRECORD(DummyRecord, ROTATE_ABOUT_EDGE_OP) REGISTER_FLTRECORD(DummyRecord, TRANSLATE_OP) diff --git a/src/osgPlugins/OpenFlight/PrimaryRecords.cpp b/src/osgPlugins/OpenFlight/PrimaryRecords.cpp index ca56f722f..8f97b5c80 100644 --- a/src/osgPlugins/OpenFlight/PrimaryRecords.cpp +++ b/src/osgPlugins/OpenFlight/PrimaryRecords.cpp @@ -615,6 +615,14 @@ public: } } + virtual void setMultiSwitchValueName(unsigned int switchSet, const std::string& name) + { + if (_multiSwitch.valid()) + { + _multiSwitch->setValueName(switchSet, name); + } + } + protected: virtual ~Switch() {} diff --git a/src/osgPlugins/OpenFlight/Record.h b/src/osgPlugins/OpenFlight/Record.h index 52cea77ac..64a835724 100644 --- a/src/osgPlugins/OpenFlight/Record.h +++ b/src/osgPlugins/OpenFlight/Record.h @@ -86,6 +86,7 @@ public: virtual void addVertex(Vertex& /*vertex*/) {} virtual void addVertexUV(int /*layer*/,const osg::Vec2& /*uv*/) {} virtual void addMorphVertex(Vertex& /*vertex0*/, Vertex& /*vertex100*/) {} + virtual void setMultiSwitchValueName(unsigned int /*switchSet*/, const std::string& /*name*/) {} void setNumberOfReplications(int num) { _numberOfReplications = num; } void setMatrix(const osg::Matrix& matrix) { _matrix = new osg::RefMatrix(matrix); } diff --git a/src/osgSim/MultiSwitch.cpp b/src/osgSim/MultiSwitch.cpp index 6a74644e6..3fc8ddd62 100644 --- a/src/osgSim/MultiSwitch.cpp +++ b/src/osgSim/MultiSwitch.cpp @@ -163,6 +163,7 @@ void MultiSwitch::expandToEncompassSwitchSet(unsigned int switchSet) // need to expand arrays. unsigned int originalSize = _values.size(); _values.resize(switchSet+1); + _valueNames.resize(switchSet+1); for(unsigned int i=originalSize;i<=switchSet;++i) { ValueList& values = _values[i]; @@ -232,3 +233,10 @@ void MultiSwitch::setValueList(unsigned int switchSet, const ValueList& values) _values[switchSet] = values; } + +void MultiSwitch::setValueName(unsigned int switchSet, const std::string& name) +{ + expandToEncompassSwitchSet(switchSet); + + _valueNames[switchSet] = name; +}