Re: [osg-users] osgSim::MultiSwitch Serialization

2018-07-29 Thread David Stephan
Attached is a little test.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74419#74419



/* OpenSceneGraph example, osgmultiswitchtest.
*
*  Permission is hereby granted, free of charge, to any person obtaining a copy
*  of this software and associated documentation files (the "Software"), to deal
*  in the Software without restriction, including without limitation the rights
*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the Software is
*  furnished to do so, subject to the following conditions:
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*  THE SOFTWARE.
*/

#include 
#include 
#include 

#include 

void assert2(bool success) {
if (!success) throw std::runtime_error("");
}

void testSerializer(const osgSim::MultiSwitch::SwitchSetList ,
const osgSim::MultiSwitch::SwitchSetNameList ) {

osg::ref_ptr ms(new osgSim::MultiSwitch);
if (values.size() > 0) {
int nchildren = values[0].size();
for (int i = 0; i < nchildren; i++) {
ms->addChild(new osg::Node);
}
}

ms->setSwitchSetList(values);
for (int i = 0; i < names.size(); i++) {
ms->setValueName(i, names[i]);
}

osgDB::ReaderWriter *rw = 
osgDB::Registry::instance()->getReaderWriterForExtension("osgb");
osg::ref_ptr options = new osgDB::Options;
std::stringstream ss;

// write
auto wresult = rw->writeNode(*ms, ss, options);

// read
auto rresult = rw->readNode(ss, options);
osg::ref_ptr node = rresult.takeNode();

osg::ref_ptr 
ms2(dynamic_cast(node.get()));
assert2(ms2 != nullptr);

assert2(ms2->getSwitchSetList() == values);
for (int i = 0; i < values.size(); i++) {
assert2(ms2->getValueName(i) == names[i]);
}
assert2(ms->getNumChildren() == ms2->getNumChildren());
}

int main( int argc, char **argv )
{
testSerializer(
{
{false, false},
{true, true}
},
{ "offs", "ons" }
);

testSerializer({}, {});

testSerializer(
{
{ true, true, false, true, false, true }
},
{"stuff"}
);

return 0;
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] osgSim::MultiSwitch Serialization

2018-07-26 Thread Robert Osfield
HI David,

I'm don't have time to look at the code right now so will just provide
some general hints.  The serailizers have SO version built into them
so you can add or remove components of the serializer based on the SO
version of the OSG.  There are number of places in the OSG serailizers
that you can look at for inspiration, for instance
src/osgWrappers/serializers/Node.cpp has:

ADD_USER_SERIALIZER( Descriptions );  // _descriptions, deprecated
{
UPDATE_TO_VERSION_SCOPED( 77 )
REMOVE_SERIALIZER( Descriptions );
}

Have a search through the serializers to see the
UPDATE_TO_VERSION_SCOPED used in various ways.

Robert.


On Thu, 26 Jul 2018 at 13:57, David Stephan  wrote:
>
> osgSim::MultiSwitch and flt files support named switches, but the names 
> aren't saved. It seems like an easy fix, though I'm not sure how to mess with 
> the serializer in a backwards compatible way.
>
> relevant files:
> src/osgSim/MultiSwitch.cpp
> src/osgWrappers/serializers/osgSim/MultiSwitch.cpp
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=74385#74385
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] osgSim::MultiSwitch Serialization

2018-07-26 Thread David Stephan
osgSim::MultiSwitch and flt files support named switches, but the names aren't 
saved. It seems like an easy fix, though I'm not sure how to mess with the 
serializer in a backwards compatible way.

relevant files:
src/osgSim/MultiSwitch.cpp
src/osgWrappers/serializers/osgSim/MultiSwitch.cpp

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=74385#74385





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org