From Eduardo Poyart, OSG patch: made it read ancillary IndexedStrings into MultiSwitch

This commit is contained in:
Robert Osfield 2010-11-26 17:35:06 +00:00
parent 3f6c837a5a
commit b9ae28d344
5 changed files with 57 additions and 6 deletions

View File

@ -71,6 +71,7 @@ class OSGSIM_EXPORT MultiSwitch : public osg::Group
typedef std::vector<bool> ValueList; typedef std::vector<bool> ValueList;
typedef std::vector<ValueList> SwitchSetList; typedef std::vector<ValueList> SwitchSetList;
typedef std::vector<std::string> SwitchSetNameList;
/** Set the compile set of different values.*/ /** Set the compile set of different values.*/
void setSwitchSetList(const SwitchSetList& switchSetList); 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.*/ /** Get the a single set of different values for a particular switch set.*/
const ValueList& getValueList(unsigned int switchSet) const { return _values[switchSet]; } 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 : protected :
virtual ~MultiSwitch() {} virtual ~MultiSwitch() {}
@ -94,6 +99,7 @@ class OSGSIM_EXPORT MultiSwitch : public osg::Group
bool _newChildDefaultValue; bool _newChildDefaultValue;
unsigned int _activeSwitchSet; unsigned int _activeSwitchSet;
SwitchSetList _values; SwitchSetList _values;
SwitchSetNameList _valueNames;
}; };
} }

View File

@ -316,6 +316,35 @@ class Replicate : public Record
REGISTER_FLTRECORD(Replicate, REPLICATE_OP) 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: // Prevent "unknown record" message for the following ancillary records:
REGISTER_FLTRECORD(DummyRecord, OLD_TRANSLATE2_OP) REGISTER_FLTRECORD(DummyRecord, OLD_TRANSLATE2_OP)
REGISTER_FLTRECORD(DummyRecord, OLD_ROTATE_ABOUT_POINT_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_ROTATE_SCALE_TO_POINT_OP)
REGISTER_FLTRECORD(DummyRecord, OLD_PUT_TRANSFORM_OP) REGISTER_FLTRECORD(DummyRecord, OLD_PUT_TRANSFORM_OP)
REGISTER_FLTRECORD(DummyRecord, OLD_BOUNDING_BOX_OP) REGISTER_FLTRECORD(DummyRecord, OLD_BOUNDING_BOX_OP)
REGISTER_FLTRECORD(DummyRecord, INDEXED_STRING_OP)
REGISTER_FLTRECORD(DummyRecord, ROAD_ZONE_OP) REGISTER_FLTRECORD(DummyRecord, ROAD_ZONE_OP)
REGISTER_FLTRECORD(DummyRecord, ROTATE_ABOUT_EDGE_OP) REGISTER_FLTRECORD(DummyRecord, ROTATE_ABOUT_EDGE_OP)
REGISTER_FLTRECORD(DummyRecord, TRANSLATE_OP) REGISTER_FLTRECORD(DummyRecord, TRANSLATE_OP)

View File

@ -615,6 +615,14 @@ public:
} }
} }
virtual void setMultiSwitchValueName(unsigned int switchSet, const std::string& name)
{
if (_multiSwitch.valid())
{
_multiSwitch->setValueName(switchSet, name);
}
}
protected: protected:
virtual ~Switch() {} virtual ~Switch() {}

View File

@ -86,6 +86,7 @@ public:
virtual void addVertex(Vertex& /*vertex*/) {} virtual void addVertex(Vertex& /*vertex*/) {}
virtual void addVertexUV(int /*layer*/,const osg::Vec2& /*uv*/) {} virtual void addVertexUV(int /*layer*/,const osg::Vec2& /*uv*/) {}
virtual void addMorphVertex(Vertex& /*vertex0*/, Vertex& /*vertex100*/) {} virtual void addMorphVertex(Vertex& /*vertex0*/, Vertex& /*vertex100*/) {}
virtual void setMultiSwitchValueName(unsigned int /*switchSet*/, const std::string& /*name*/) {}
void setNumberOfReplications(int num) { _numberOfReplications = num; } void setNumberOfReplications(int num) { _numberOfReplications = num; }
void setMatrix(const osg::Matrix& matrix) { _matrix = new osg::RefMatrix(matrix); } void setMatrix(const osg::Matrix& matrix) { _matrix = new osg::RefMatrix(matrix); }

View File

@ -163,6 +163,7 @@ void MultiSwitch::expandToEncompassSwitchSet(unsigned int switchSet)
// need to expand arrays. // need to expand arrays.
unsigned int originalSize = _values.size(); unsigned int originalSize = _values.size();
_values.resize(switchSet+1); _values.resize(switchSet+1);
_valueNames.resize(switchSet+1);
for(unsigned int i=originalSize;i<=switchSet;++i) for(unsigned int i=originalSize;i<=switchSet;++i)
{ {
ValueList& values = _values[i]; ValueList& values = _values[i];
@ -232,3 +233,10 @@ void MultiSwitch::setValueList(unsigned int switchSet, const ValueList& values)
_values[switchSet] = values; _values[switchSet] = values;
} }
void MultiSwitch::setValueName(unsigned int switchSet, const std::string& name)
{
expandToEncompassSwitchSet(switchSet);
_valueNames[switchSet] = name;
}