root/OpenSceneGraph/trunk/src/osgPlugins/ive/CompositeLayer.cpp @ 13041

Revision 13041, 2.5 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include "Exception.h"
15#include "CompositeLayer.h"
16#include "Layer.h"
17
18using namespace ive;
19
20void CompositeLayer::write(DataOutputStream* out)
21{
22    // Write Layer's identification.
23    out->writeInt(IVECOMPOSITELAYER);
24
25    // If the osg class is inherited by any other class we should also write this to file.
26    osgTerrain::Layer*  layer = dynamic_cast<osgTerrain::Layer*>(this);
27    if  (layer)
28        ((ive::Layer*)(layer))->write(out);
29    else
30        out_THROW_EXCEPTION("CompositeLayer::write(): Could not cast this osgLayer::CompositeLayer to an osgTerrain::Layer.");
31
32    LayerHelper helper;
33
34    out->writeUInt(getNumLayers());
35    for(unsigned int i=0; i<getNumLayers(); ++i)
36    {
37        if(getLayer(i))
38        {
39            out->writeBool(true);
40            helper.writeLayer(out, getLayer(i));
41        }
42        else
43        {
44            out->writeBool(false);
45            out->writeString(getCompoundName(i));
46        }
47    }
48}
49
50void CompositeLayer::read(DataInputStream* in)
51{
52    // Peek on Layer's identification.
53    int id = in->peekInt();
54    if (id != IVECOMPOSITELAYER)
55        in_THROW_EXCEPTION("CompositeLayer::read(): Expected CompositeLayer identification.");
56
57    // Read Layer's identification.
58    id = in->readInt();
59
60    // If the osg class is inherited by any other class we should also read this from file.
61    osgTerrain::Layer*  layer = dynamic_cast<osgTerrain::Layer*>(this);
62    if (layer)
63        ((ive::Layer*)(layer))->read(in);
64    else
65        in_THROW_EXCEPTION("CompositeLayer::read(): Could not cast this osgLayer::Layer to an osg::Group.");
66
67    LayerHelper helper;
68
69    unsigned int numLayers = in->readUInt();
70    for(unsigned int i=0; i<numLayers; ++i)
71    {
72        bool readInlineLayer = in->readBool();
73        if (readInlineLayer)
74        {
75            addLayer(helper.readLayer(in));
76        }
77        else
78        {
79            addLayer(in->readString());
80        }
81    }
82}
Note: See TracBrowser for help on using the browser.