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

Revision 13041, 2.7 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/**********************************************************************
2 *
3 *    FILE:            Geode.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::Geode in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerated
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 18.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Exception.h"
16#include "Node.h"
17#include "Geode.h"
18#include "Geometry.h"
19
20#include <osg/Node>
21#include <osg/Geometry>
22
23using namespace ive;
24
25void Geode::write(DataOutputStream* out){
26    // Write Geode's identification.
27    out->writeInt(IVEGEODE);
28    // If the osg class is inherited by any other class we should also write this to file.
29    osg::Node*  node = dynamic_cast<osg::Node*>(this);
30    if(node){
31        ((ive::Node*)(node))->write(out);
32    }
33    else
34        out_THROW_EXCEPTION("Geode::write(): Could not cast this osg::Geode to an osg::Node.");
35
36
37    // Write Geode's properties.
38
39    // Write number of drawables.
40    out->writeInt(getNumDrawables());
41    // Write out every drawable.
42        for(unsigned int i=0;i<getNumDrawables();i++){
43        osg::Drawable* drawable = getDrawable(i);
44#if 0
45        if(dynamic_cast<osg::Geometry*>(drawable))
46            ((ive::Geometry*)(drawable))->write(out);
47        else{
48            in_THROW_EXCEPTION("Unknown drawable in Geode::write()");
49        }
50#else
51        out->writeDrawable(drawable);
52#endif
53    }
54}
55
56void Geode::read(DataInputStream* in){
57    // Read Geode's identification.
58    int id = in->peekInt();
59    if(id == IVEGEODE){
60        // Code to read Geode's properties.
61        id = in->readInt();
62        // If the osg class is inherited by any other class we should also read this from file.
63        osg::Node*  node = dynamic_cast<osg::Node*>(this);
64        if(node){
65            ((ive::Node*)(node))->read(in);
66        }
67        else
68            in_THROW_EXCEPTION("Geode::read(): Could not cast this osg::Geode to an osg::Node.");
69
70
71        // Read number of drawables.
72        int size = in->readInt();
73        // Read the drawables.
74        for(int i = 0; i<size; i++){
75#if 0
76            int id = in->peekInt();
77            osg::Drawable* drawable;
78            if(id == IVEGEOMETRY){
79                drawable = new osg::Geometry();
80                ((Geometry*)(drawable))->read(in);
81                addDrawable(drawable);
82            }
83            else
84                in_THROW_EXCEPTION("Unknown drawable identification in Geode::read()");
85#else
86            addDrawable(in->readDrawable());
87#endif
88        }
89    }
90    else{
91        in_THROW_EXCEPTION("Geode::read(): Expected Geode identification.");
92    }
93}
Note: See TracBrowser for help on using the browser.