Hello,

This patch for the OpenFlight reader implements reading of ancillary
IndexedStrings for switch sets.

In the OpenFlight file format, the switch sets for switches can have names
associated with them. We needed that in our software, so that the user can
define names e.g. in Performer's UI, and our visualizer presents options in
its UI with the names that come from the FLT file.

The changes are:

- New ancillary record added to the OpenFlight reader
- New interface for setting MultiSwitch names added to Record.h
- New SwitchSetNameList (a std::vector<std::string>) added to MultiSwitch,
with getters and setters.

Comments are appreciated.

Thank you for the great job that is OSG!

Eduardo
From 69086457990874fbaf8409e2d503149f52665796 Mon Sep 17 00:00:00 2001
From: Eduardo Poyart <[email protected]>
Date: Mon, 22 Nov 2010 18:10:14 -0800
Subject: [PATCH] OSG patch: made it read ancillary IndexedStrings into MultiSwitch

---
 .../include/osgSim/MultiSwitch                     |   16 +++++++---
 .../src/osgPlugins/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/nrts/3rdparty/OpenSceneGraph-2.9.9/include/osgSim/MultiSwitch b/nrts/3rdparty/OpenSceneGraph-2.9.9/include/osgSim/MultiSwitch
index d400279..7501e5d 100644
--- a/nrts/3rdparty/OpenSceneGraph-2.9.9/include/osgSim/MultiSwitch
+++ b/nrts/3rdparty/OpenSceneGraph-2.9.9/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<bool>       ValueList;
-        typedef std::vector<ValueList>  SwitchSetList;
+        typedef std::vector<bool>        ValueList;
+        typedef std::vector<ValueList>   SwitchSetList;
+        typedef std::vector<std::string> 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/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/AncillaryRecords.cpp b/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/AncillaryRecords.cpp
index a5e7ffd..fce52d9 100644
--- a/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/AncillaryRecords.cpp
+++ b/nrts/3rdparty/OpenSceneGraph-2.9.9/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/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/PrimaryRecords.cpp b/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/PrimaryRecords.cpp
index ca56f72..8f97b5c 100644
--- a/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/PrimaryRecords.cpp
+++ b/nrts/3rdparty/OpenSceneGraph-2.9.9/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/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/Record.h b/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/Record.h
index 52cea77..64a8357 100644
--- a/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgPlugins/OpenFlight/Record.h
+++ b/nrts/3rdparty/OpenSceneGraph-2.9.9/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/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgSim/MultiSwitch.cpp b/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgSim/MultiSwitch.cpp
index 6a74644..3fc8ddd 100644
--- a/nrts/3rdparty/OpenSceneGraph-2.9.9/src/osgSim/MultiSwitch.cpp
+++ b/nrts/3rdparty/OpenSceneGraph-2.9.9/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;
+}
-- 
1.7.3.2

_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to