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

Revision 13041, 3.0 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:            ShapeDrawable.cpp
4 *
5 *    DESCRIPTION:    Read/Write osg::ShapeDrawable in binary format to disk.
6 *
7 *    CREATED BY:        Auto generated by iveGenerator
8 *                    and later modified by Rune Schmidt Jensen.
9 *
10 *    HISTORY:        Created 27.3.2003
11 *
12 *    Copyright 2003 VR-C
13 **********************************************************************/
14
15#include "Drawable.h"
16#include "Exception.h"
17#include "ShapeDrawable.h"
18#include "Object.h"
19
20using namespace ive;
21
22void ShapeDrawable::write(DataOutputStream* out)
23{
24    // Write CullFace's identification.
25    out->writeInt(IVESHAPEDRAWABLE);
26
27    if ( out->getVersion() >= VERSION_0004 )
28    {
29        // If the osg class is inherited by any other class we should also write this to file.
30        osg::Drawable*  drawable = dynamic_cast<osg::Drawable*>(this);
31        if(drawable){
32            ((ive::Drawable*)(drawable))->write(out);
33        }
34        else
35            out_THROW_EXCEPTION("ShapeDrawable::write(): Could not cast this osg::ShapeDrawable to an osg::Object.");
36
37    }
38    else
39    {
40        osg::Object* obj = dynamic_cast<osg::Object*>(this);
41        if(obj){
42            ((ive::Object*)(obj))->write(out);
43        }
44        else
45            out_THROW_EXCEPTION("ShapeDrawable::write(): Could not cast this osg::ShapeDrawable to an osg::Object.");
46    }
47
48    // Write ShapeDrawable's properties.
49    out->writeVec4(getColor());
50
51    if (getShape())
52    {
53        out->writeBool(true);
54        out->writeShape(getShape());
55    }
56    else
57    {
58        out->writeBool(false);
59    }
60}
61
62void ShapeDrawable::read(DataInputStream* in)
63{
64    // Peek on ShapeDrawable's identification.
65    int id = in->peekInt();
66    if(id == IVESHAPEDRAWABLE)
67    {
68        // Read ShapeDrawable's identification.
69        id = in->readInt();
70
71        if ( in->getVersion() >= VERSION_0004 )
72        {
73            // If the osg class is inherited by any other class we should also read this from file.
74            osg::Drawable*  drawable = dynamic_cast<osg::Drawable*>(this);
75            if(drawable){
76                ((ive::Drawable*)(drawable))->read(in);
77            }
78            else
79                in_THROW_EXCEPTION("ShapeDrawable::read(): Could not cast this osg::ShapeDrawable to an osg::Object.");
80        }
81        else
82        {
83            // If the osg class is inherited by any other class we should also read this from file.
84            osg::Object*  obj = dynamic_cast<osg::Object*>(this);
85            if(obj){
86                ((ive::Object*)(obj))->read(in);
87            }
88            else
89                in_THROW_EXCEPTION("ShapeDrawable::read(): Could not cast this osg::ShapeDrawable to an osg::Object.");
90        }
91
92        // Read ShapeDrawable's properties
93        setColor(in->readVec4());
94
95        if (in->readBool())
96        {
97            setShape(in->readShape());
98        }
99
100    }
101    else
102    {
103        in_THROW_EXCEPTION("ShapeDrawable::read(): Expected ShapeDrawable identification.");
104    }
105}
Note: See TracBrowser for help on using the browser.