From 2ba5f002d29fcb739b62964f77aa1cbd4e7f6cf7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 19 Jun 2008 14:57:36 +0000 Subject: [PATCH] from Andrew Bettison, LineStipple support for .ive --- src/osgPlugins/ive/LineStipple.cpp | 56 ++++++++++++++++++++++++++++++ src/osgPlugins/ive/LineStipple.h | 15 ++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/osgPlugins/ive/LineStipple.cpp create mode 100644 src/osgPlugins/ive/LineStipple.h diff --git a/src/osgPlugins/ive/LineStipple.cpp b/src/osgPlugins/ive/LineStipple.cpp new file mode 100644 index 000000000..29b300cca --- /dev/null +++ b/src/osgPlugins/ive/LineStipple.cpp @@ -0,0 +1,56 @@ +/********************************************************************** + * + * FILE: LineStipple.cpp + * + * DESCRIPTION: Read/Write osg::LineStipple in binary format to disk. + * + * CREATED BY: Copied from LineWidth + * and modified by Andrew Bettison + * + * HISTORY: Created 12.6.2008 + * + * Copyright 2008 VR-C + **********************************************************************/ + +#include "Exception.h" +#include "LineStipple.h" +#include "Object.h" + +using namespace ive; + +void LineStipple::write(DataOutputStream* out){ + // Write CullFace's identification. + out->writeInt(IVELINESTIPPLE); + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* obj = dynamic_cast(this); + if (obj) { + ((ive::Object*)(obj))->write(out); + } + else + throw Exception("LineStipple::write(): Could not cast this osg::LineStipple to an osg::Object."); + // Write LineStipple's properties. + out->writeUShort(getPattern()); + out->writeInt(getFactor()); +} + +void LineStipple::read(DataInputStream* in){ + // Peek on LineStipple's identification. + int id = in->peekInt(); + if (id == IVELINESTIPPLE) { + // Read LineStipple's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* obj = dynamic_cast(this); + if (obj) { + ((ive::Object*)(obj))->read(in); + } + else + throw Exception("LineStipple::read(): Could not cast this osg::LineStipple to an osg::Object."); + // Read LineStipple's properties + setPattern(in->readUShort()); + setFactor(in->readInt()); + } + else{ + throw Exception("LineStipple::read(): Expected LineStipple identification."); + } +} diff --git a/src/osgPlugins/ive/LineStipple.h b/src/osgPlugins/ive/LineStipple.h new file mode 100644 index 000000000..78f2e39e6 --- /dev/null +++ b/src/osgPlugins/ive/LineStipple.h @@ -0,0 +1,15 @@ +#ifndef IVE_LINESTIPPLE +#define IVE_LINESTIPPLE 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class LineStipple : public osg::LineStipple, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif