1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

39
src/VrmlData/FILES Executable file
View File

@@ -0,0 +1,39 @@
VrmlData_Appearance.hxx
VrmlData_ArrayVec3d.hxx
VrmlData_Box.hxx
VrmlData_Color.hxx
VrmlData_Cone.hxx
VrmlData_Coordinate.hxx
VrmlData_Cylinder.hxx
VrmlData_ErrorStatus.hxx
VrmlData_Faceted.hxx
VrmlData_Geometry.cxx
VrmlData_Geometry.hxx
VrmlData_Group.cxx
VrmlData_Group.hxx
VrmlData_ImageTexture.hxx
VrmlData_InBuffer.hxx
VrmlData_IndexedFaceSet.cxx
VrmlData_IndexedFaceSet.hxx
VrmlData_ListOfNode.hxx
VrmlData_MapOfNode.hxx
VrmlData_WorldInfo.hxx
VrmlData_WorldInfo.cxx
VrmlData_IndexedLineSet.hxx
VrmlData_IndexedLineSet.cxx
VrmlData_Material.hxx
VrmlData_Material.cxx
VrmlData_Node.cxx
VrmlData_Node.hxx
VrmlData_Normal.hxx
VrmlData_Scene.cxx
VrmlData_Scene.hxx
VrmlData_ShapeNode.hxx
VrmlData_Sphere.hxx
VrmlData_Texture.hxx
VrmlData_TextureCoordinate.hxx
VrmlData_TextureTransform.hxx
VrmlData_UnknownNode.hxx
VrmlData_ShapeConvert.hxx
VrmlData_ShapeConvert.cxx
VrmlData_DataMapOfShapeAppearance.hxx

View File

@@ -0,0 +1,116 @@
// File: VrmlData_Appearance.hxx
// Created: 25.05.06 15:30:58
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Appearance_HeaderFile
#define VrmlData_Appearance_HeaderFile
#include <VrmlData_Material.hxx>
#include <VrmlData_Texture.hxx>
#include <VrmlData_TextureTransform.hxx>
/**
* Implementation of the Appearance node type
*/
class VrmlData_Appearance : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Appearance () {}
/**
* Constructor
*/
inline VrmlData_Appearance (const VrmlData_Scene& theScene,
const char * theName)
: VrmlData_Node (theScene, theName) {}
/**
* Query the Material
*/
inline const Handle(VrmlData_Material)&
Material () const { return myMaterial; }
/**
* Query the Texture
*/
inline const Handle(VrmlData_Texture)&
Texture () const { return myTexture; }
/**
* Query the TextureTransform
*/
inline const Handle(VrmlData_TextureTransform)&
TextureTransform () const { return myTTransform; }
/**
* Set the Material
*/
inline void SetMaterial (const Handle(VrmlData_Material)& theMat)
{ myMaterial = theMat; }
/**
* Set the Texture
*/
inline void SetTexture (const Handle(VrmlData_Texture)& theTexture)
{ myTexture = theTexture; }
/**
* Set the Texture Transform
*/
inline void SetTextureTransform
(const Handle(VrmlData_TextureTransform)& theTT)
{ myTTransform = theTT; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.<p>
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)&)const;
/**
* Read the node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Returns True if the node is default, so that it should not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
Handle(VrmlData_Material) myMaterial;
Handle(VrmlData_Texture) myTexture;
Handle(VrmlData_TextureTransform) myTTransform;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Appearance)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Appearance, VrmlData_Node)
#endif

View File

@@ -0,0 +1,121 @@
// File: VrmlData_ArrayVec3d.hxx
// Created: 26.05.06 18:12:55
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_ArrayVec3d_HeaderFile
#define VrmlData_ArrayVec3d_HeaderFile
#include <VrmlData_Node.hxx>
class gp_XYZ;
/**
* Implementatioon of basic node for Coordinate, Normal and Color
* (array of triplets).
*/
class VrmlData_ArrayVec3d : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_ArrayVec3d ()
: myArray (0L), myLength (0)
{}
/**
* Constructor
*/
inline VrmlData_ArrayVec3d (const VrmlData_Scene& theScene,
const char * theName,
const size_t nVec,
const gp_XYZ * arrVec)
: VrmlData_Node (theScene, theName),
myArray (arrVec),
myLength (nVec)
{}
/**
* Query the number of vectors
*/
inline size_t Length () const { return myLength; }
/**
* Query the array
*/
inline const gp_XYZ * Values () const { return myArray; }
/**
* Create a data array and assign the field myArray.
* @return
* True if allocation was successful.
*/
Standard_EXPORT Standard_Boolean
AllocateValues (const Standard_Size theLength);
/**
* Set the array data
*/
inline void SetValues (const size_t nValues,
const gp_XYZ * arrValues)
{ myLength = nValues; myArray = arrValues; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
// Standard_EXPORT virtual Handle(VrmlData_Node)
// Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT VrmlData_ErrorStatus
ReadArray (VrmlData_InBuffer& theBuffer,
const char * theName,
const Standard_Boolean isScale);
/**
* Write the Node to the output stream currently opened in Scene.
*/
Standard_EXPORT VrmlData_ErrorStatus
WriteArray(const char * theName,
const Standard_Boolean isScale) const;
/**
* Returns True if the node is default, so that it should not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
protected:
// ---------- PROTECTED METHODS ----------
/**
* Query one vector
* @param i
* index in the array of vectors [0 .. N-1]
* @return
* the vector for the index. If index irrelevant, returns (0., 0., 0.)
*/
Standard_EXPORT const gp_XYZ& Value (const Standard_Integer i) const;
protected:
// ---------- PROTECTED FIELDS ----------
const gp_XYZ * myArray;
Standard_Size myLength;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_ArrayVec3d)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_ArrayVec3d, VrmlData_Node)
#endif

94
src/VrmlData/VrmlData_Box.hxx Executable file
View File

@@ -0,0 +1,94 @@
// File: VrmlData_Box.hxx
// Created: 25.05.06 16:57:19
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Box_HeaderFile
#define VrmlData_Box_HeaderFile
#include <VrmlData_Geometry.hxx>
#include <gp_XYZ.hxx>
/**
* Inplementation of the Box node.
* This node is defined by Size vector, assumong that the box center is located
* in (0., 0., 0.) and that each corner is 0.5*|Size| distance from the center.
*/
class VrmlData_Box : public VrmlData_Geometry
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Box ()
: mySize (2., 2., 2.)
{}
/**
* Constructor
*/
inline VrmlData_Box (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Real sizeX = 2.,
const Standard_Real sizeY = 2.,
const Standard_Real sizeZ = 2.)
: VrmlData_Geometry (theScene, theName),
mySize (sizeX, sizeY, sizeZ)
{}
/**
* Query the Box size
*/
inline const gp_XYZ& Size () const { return mySize; }
/**
* Set the Box Size
*/
inline void SetSize (const gp_XYZ& theSize)
{ mySize = theSize; SetModified(); }
/**
* Query the primitive topology. This method returns a Null shape if there
* is an internal error during the primitive creation (zero radius, etc.)
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)&
TShape ();
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Fill the Node internal data from the given input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
private:
// ---------- PRIVATE FIELDS ----------
gp_XYZ mySize;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Box)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Box, VrmlData_Geometry)
#endif

90
src/VrmlData/VrmlData_Color.hxx Executable file
View File

@@ -0,0 +1,90 @@
// File: VrmlData_Color.hxx
// Created: 28.05.06 23:55:45
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Color_HeaderFile
#define VrmlData_Color_HeaderFile
#include <VrmlData_ArrayVec3d.hxx>
#include <Quantity_Color.hxx>
#include <gp_XYZ.hxx>
/**
* Implementation of the node Color
*/
class VrmlData_Color : public VrmlData_ArrayVec3d
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor.
*/
inline VrmlData_Color () {}
/**
* Constructor.
*/
inline VrmlData_Color (const VrmlData_Scene& theScene,
const char * theName,
const size_t nColors =0,
const gp_XYZ * arrColors=0L)
: VrmlData_ArrayVec3d (theScene, theName, nColors, arrColors)
{}
/**
* Query one color
* @param i
* index in the array of colors [0 .. N-1]
* @return
* the color value for the index. If index irrelevant, returns (0., 0., 0.)
*/
inline const Quantity_Color Color (const Standard_Integer i) const
{ return Quantity_Color (Value(i).X(), Value(i).Y(), Value(i).Z(),
Quantity_TOC_RGB); }
/**
* Set the array data
*/
inline void SetColors (const size_t nColors,
const gp_XYZ * arrColors)
{ myLength = nColors; myArray = arrColors; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.<p>
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to the Scene output.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
private:
// ---------- PRIVATE FIELDS ----------
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Color)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Color, VrmlData_ArrayVec3d)
#endif

135
src/VrmlData/VrmlData_Cone.hxx Executable file
View File

@@ -0,0 +1,135 @@
// File: VrmlData_Cone.hxx
// Created: 25.05.06 17:29:32
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Cone_HeaderFile
#define VrmlData_Cone_HeaderFile
#include <VrmlData_Geometry.hxx>
/**
* Implementation of the Cone node.
* The cone is located with its middle of the height segment in (0., 0., 0.)
* The height is oriented along OY.
*/
class VrmlData_Cone : public VrmlData_Geometry
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Cone ()
: myBottomRadius (1.),
myHeight (2.),
myHasSide (Standard_True),
myHasBottom (Standard_True)
{}
/**
* Constructor
*/
inline VrmlData_Cone (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Real theBottomRadius = 1.,
const Standard_Real theHeight = 2.)
: VrmlData_Geometry (theScene, theName),
myBottomRadius (theBottomRadius),
myHeight (theHeight),
myHasSide (Standard_True),
myHasBottom (Standard_True)
{}
/**
* Query the Bottom Radius
*/
inline Standard_Real BottomRadius () const { return myBottomRadius; }
/**
* Query the Height
*/
inline Standard_Real Height () const { return myHeight; }
/**
* Query if the bottom circle is included
*/
inline Standard_Boolean HasBottom () const { return myHasBottom; }
/**
* Query if the side surface is included
*/
inline Standard_Boolean HasSide () const { return myHasSide; }
/**
* Set the Bottom Radius
*/
inline void SetBottomRadius (const Standard_Real theRadius)
{ myBottomRadius = theRadius; SetModified(); }
/**
* Set the Height
*/
inline void SetHeight (const Standard_Real theHeight)
{ myHeight = theHeight; SetModified(); }
/**
* Set which faces are included
*/
inline void SetFaces (const Standard_Boolean hasBottom,
const Standard_Boolean hasSide)
{ myHasBottom = hasBottom; myHasSide = hasSide; SetModified(); }
/**
* Query the primitive topology. This method returns a Null shape if there
* is an internal error during the primitive creation (zero radius, etc.)
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape ();
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther) const;
/**
* Fill the Node internal data from the given input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
Standard_Real myBottomRadius;
Standard_Real myHeight;
Standard_Boolean myHasSide : 1;
Standard_Boolean myHasBottom : 1;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Cone)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Cone, VrmlData_Geometry)
#endif

View File

@@ -0,0 +1,77 @@
// File: VrmlData_Coordinate.hxx
// Created: 26.05.06 18:22:03
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Coordinate_HeaderFile
#define VrmlData_Coordinate_HeaderFile
#include <VrmlData_ArrayVec3d.hxx>
/**
* Implementation of the node Coordinate
*/
class VrmlData_Coordinate : public VrmlData_ArrayVec3d
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty Constructor
*/
inline VrmlData_Coordinate () {}
/**
* Constructor
*/
inline VrmlData_Coordinate (const VrmlData_Scene& theScene,
const char * theName,
const size_t nPoints = 0,
const gp_XYZ * arrPoints = 0L)
: VrmlData_ArrayVec3d (theScene, theName, nPoints, arrPoints)
{}
/**
* Query one point
* @param i
* index in the array of points [0 .. N-1]
* @return
* the coordinate for the index. If index irrelevant, returns (0., 0., 0.)
*/
inline const gp_XYZ& Coordinate (const Standard_Integer i) const
{ return Value(i); }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to the Scene output.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
private:
// ---------- PRIVATE FIELDS ----------
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Coordinate)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Coordinate, VrmlData_ArrayVec3d)
#endif

View File

@@ -0,0 +1,139 @@
// File: VrmlData_Cylinder.hxx
// Created: 25.05.06 22:30:33
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Cylinder_HeaderFile
#define VrmlData_Cylinder_HeaderFile
#include <VrmlData_Geometry.hxx>
/**
* Implementation of the Cylinder node
*/
class VrmlData_Cylinder : public VrmlData_Geometry
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Cylinder ()
: myRadius (1.),
myHeight (2.),
myHasBottom (Standard_True),
myHasSide (Standard_True),
myHasTop (Standard_True)
{}
/**
* Constructor
*/
inline VrmlData_Cylinder (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Real theRadius = 1.,
const Standard_Real theHeight = 2.)
: VrmlData_Geometry (theScene, theName),
myRadius (theRadius),
myHeight (theHeight),
myHasBottom (Standard_True),
myHasSide (Standard_True),
myHasTop (Standard_True)
{}
/**
* Query the Radius
*/
inline Standard_Real Radius () const { return myRadius; }
/**
* Query the Height
*/
inline Standard_Real Height () const { return myHeight; }
/**
* Query if the bottom circle is included
*/
inline Standard_Boolean HasBottom () const { return myHasBottom; }
/**
* Query if the side surface is included
*/
inline Standard_Boolean HasSide () const { return myHasSide; }
/**
* Query if the top surface is included
*/
inline Standard_Boolean HasTop () const { return myHasTop; }
/**
* Set the Radius
*/
inline void SetRadius (const Standard_Real theRadius)
{ myRadius = theRadius; SetModified(); }
/**
* Set the Height
*/
inline void SetHeight (const Standard_Real theHeight)
{ myHeight = theHeight; SetModified(); }
/**
* Set which faces are included
*/
inline void SetFaces (const Standard_Boolean hasBottom,
const Standard_Boolean hasSide,
const Standard_Boolean hasTop)
{ myHasBottom = hasBottom; myHasSide = hasSide;
myHasTop = hasTop; SetModified(); }
/**
* Query the primitive topology. This method returns a Null shape if there
* is an internal error during the primitive creation (zero radius, etc.)
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape ();
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Fill the Node internal data from the given input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
Standard_Real myRadius;
Standard_Real myHeight;
Standard_Boolean myHasBottom : 1;
Standard_Boolean myHasSide : 1;
Standard_Boolean myHasTop : 1;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Cylinder)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Cylinder, VrmlData_Geometry)
#endif

View File

@@ -0,0 +1,55 @@
// File: VrmlData_DataMapOfShapeAppearance.hxx
// Created: 03.06.08 10:16
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2008
#ifndef VrmlData_DataMapOfShapeAppearance_HeaderFile
#define VrmlData_DataMapOfShapeAppearance_HeaderFile
#include <NCollection_DataMap.hxx>
#include <Handle_TopoDS_TShape.hxx>
#include <VrmlData_Appearance.hxx>
#include <TopoDS_TShape.hxx>
/**
* Data Map that provides the link between each Shape obtained in VRML import
* and the corresponding Appearance.
*/
class VrmlData_DataMapOfShapeAppearance
: public NCollection_DataMap<Handle_TopoDS_TShape, Handle_VrmlData_Appearance>
{
public:
//! Constructor
inline VrmlData_DataMapOfShapeAppearance
(const Standard_Integer NbBuckets=1,
const Handle(NCollection_BaseAllocator)& theAllocator = 0L)
: NCollection_DataMap<Handle_TopoDS_TShape,
Handle_VrmlData_Appearance> (NbBuckets, theAllocator)
{}
//! Copy constructor
inline VrmlData_DataMapOfShapeAppearance
(const VrmlData_DataMapOfShapeAppearance& theOther)
: NCollection_DataMap<Handle_TopoDS_TShape,
Handle_VrmlData_Appearance> (theOther)
{}
friend Standard_Boolean IsEqual (const Handle_TopoDS_TShape& one,
const Handle_TopoDS_TShape& two);
};
//=======================================================================
//function : IsEqual
//purpose : for NCollection_DataMap interface
//=======================================================================
inline Standard_Boolean IsEqual (const Handle_TopoDS_TShape& one,
const Handle_TopoDS_TShape& two)
{
return one == two;
}
#endif

View File

@@ -0,0 +1,34 @@
// File: VrmlData_ErrorStatus.hxx
// Created: 28.10.06 12:34
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_ErrorStatus_HeaderFile
#define VrmlData_ErrorStatus_HeaderFile
/**
* Status of read/write or other operation.
*/
enum VrmlData_ErrorStatus {
VrmlData_StatusOK = 0,
VrmlData_EmptyData,
VrmlData_UnrecoverableError,
VrmlData_GeneralError,
VrmlData_EndOfFile,
VrmlData_NotVrmlFile,
VrmlData_CannotOpenFile,
VrmlData_VrmlFormatError,
VrmlData_NumericInputError,
VrmlData_IrrelevantNumber,
VrmlData_BooleanInputError,
VrmlData_StringInputError,
VrmlData_NodeNameUnknown,
VrmlData_NonPositiveSize,
VrmlData_ReadUnknownNode,
VrmlData_NonSupportedFeature,
VrmlData_OutputStreamUndefined,
VrmlData_NotImplemented
};
#endif

113
src/VrmlData/VrmlData_Faceted.hxx Executable file
View File

@@ -0,0 +1,113 @@
// File: VrmlData_Faceted.hxx
// Created: 26.05.06 08:59:15
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Faceted_HeaderFile
#define VrmlData_Faceted_HeaderFile
#include <VrmlData_Geometry.hxx>
/**
* Common API of faceted Geometry nodes: IndexedFaceSet, ElevationGrid,
* Extrusion.
*/
class VrmlData_Faceted : public VrmlData_Geometry
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Faceted ()
: myCreaseAngle (0.),
myIsCCW (Standard_True),
myIsSolid (Standard_True),
myIsConvex (Standard_True)
{}
/**
* Empty constructor
*/
inline VrmlData_Faceted (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Boolean isCCW,
const Standard_Boolean isSolid,
const Standard_Boolean isConvex,
const Standard_Real theCreaseAngle)
: VrmlData_Geometry (theScene, theName),
myCreaseAngle (theCreaseAngle),
myIsCCW (isCCW),
myIsSolid (isSolid),
myIsConvex (isConvex)
{}
/**
* Query "Is Counter-Clockwise" attribute
*/
inline Standard_Boolean IsCCW () const { return myIsCCW; }
/**
* Query "Is Solid" attribute
*/
inline Standard_Boolean IsSolid () const { return myIsSolid; }
/**
* Query "Is Convex" attribute
*/
inline Standard_Boolean IsConvex () const { return myIsConvex; }
/**
* Query the Crease Angle
*/
inline Standard_Real CreaseAngle () const { return myCreaseAngle; }
/**
* Set "Is Counter-Clockwise" attribute
*/
inline void SetCCW (const Standard_Boolean theValue)
{ myIsCCW = theValue; }
/**
* Set "Is Solid" attribute
*/
inline void SetSolid (const Standard_Boolean theValue)
{ myIsSolid = theValue; }
/**
* Set "Is Convex" attribute
*/
inline void SetConvex (const Standard_Boolean theValue)
{ myIsConvex = theValue; }
/**
* Set "Is Convex" attribute
*/
inline void SetCreaseAngle (const Standard_Real theValue)
{ myCreaseAngle = theValue; }
// ---------- PROTECTED METHODS ----------
protected:
Standard_EXPORT VrmlData_ErrorStatus
readData (VrmlData_InBuffer& theBuffer);
private:
// ---------- PRIVATE FIELDS ----------
Standard_Real myCreaseAngle;
Standard_Boolean myIsCCW : 1;
Standard_Boolean myIsSolid : 1;
Standard_Boolean myIsConvex : 1;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Faceted)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Faceted, VrmlData_Geometry)
#endif

View File

@@ -0,0 +1,870 @@
// File: VrmlData_Geometry.cxx
// Created: 25.05.06 17:07:37
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#include <VrmlData_Scene.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_Color.hxx>
#include <VrmlData_Normal.hxx>
#include <VrmlData_TextureCoordinate.hxx>
#include <VrmlData_InBuffer.hxx>
#include <VrmlData_Box.hxx>
#include <VrmlData_Cone.hxx>
#include <VrmlData_Cylinder.hxx>
#include <VrmlData_Sphere.hxx>
#include <VrmlData_UnknownNode.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrim_Cone.hxx>
#include <BRepPrim_Cylinder.hxx>
#include <BRepPrim_Sphere.hxx>
#include <BRepPrim_Builder.hxx>
#include <NCollection_Vector.hxx>
#include <Standard_ErrorHandler.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_Geometry, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Geometry, VrmlData_Node)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Box, VrmlData_Geometry)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Box, VrmlData_Geometry)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Cone, VrmlData_Geometry)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Cone, VrmlData_Geometry)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Cylinder, VrmlData_Geometry)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Cylinder, VrmlData_Geometry)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Sphere, VrmlData_Geometry)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Sphere, VrmlData_Geometry)
IMPLEMENT_STANDARD_HANDLE (VrmlData_ArrayVec3d, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_ArrayVec3d, VrmlData_Node)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Color, VrmlData_ArrayVec3d)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Color, VrmlData_ArrayVec3d)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Coordinate, VrmlData_ArrayVec3d)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Coordinate, VrmlData_ArrayVec3d)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Normal, VrmlData_ArrayVec3d)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Normal, VrmlData_ArrayVec3d)
IMPLEMENT_STANDARD_HANDLE (VrmlData_TextureCoordinate, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_TextureCoordinate, VrmlData_Node)
//=======================================================================
//function : Value
//purpose :
//=======================================================================
const gp_XYZ& VrmlData_ArrayVec3d::Value (const Standard_Integer i) const
{
size_t anIndex = (size_t)i;
if (anIndex < 0 || anIndex >= myLength) {
static gp_XYZ anOrigin (0., 0., 0.);
return anOrigin;
}
return myArray[i];
}
//=======================================================================
//function : AllocateValues
//purpose :
//=======================================================================
Standard_Boolean VrmlData_ArrayVec3d::AllocateValues
(const Standard_Size theLength)
{
myArray = reinterpret_cast <const gp_XYZ *>
(Scene().Allocator()->Allocate (theLength*sizeof(gp_XYZ)));
myLength = theLength;
return (myArray != 0L);
}
//=======================================================================
//function : VrmlData_Box::TShape
//purpose :
//=======================================================================
const Handle(TopoDS_TShape)& VrmlData_Box::TShape ()
{
if (myIsModified) {
try {
const TopoDS_Shell aShell =
BRepPrimAPI_MakeBox (gp_Pnt (-0.5 * mySize),
mySize.X(), mySize.Y(), mySize.Z());
SetTShape (aShell.TShape());
myIsModified = Standard_False;
} catch (Standard_Failure) {
myTShape.Nullify();
}
}
return myTShape;
}
//=======================================================================
//function : VrmlData_Box::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Box::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Box) aResult =
Handle(VrmlData_Box)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Box (theOther.IsNull() ? Scene() : theOther->Scene(),
Name());
aResult->SetSize(mySize);
return aResult;
}
//=======================================================================
//function : VrmlData_Box::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Box::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "size"))
aStatus = Scene().ReadXYZ (theBuffer, mySize,
Standard_True, Standard_True);
if (OK(aStatus))
aStatus = readBrace (theBuffer);
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Box::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Box::Write (const char * thePrefix) const
{
static char header[] = "Box {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
char buf[128];
sprintf (buf, "size %.12g %.12g %.12g", mySize.X(), mySize.Y(), mySize.Z());
Scene().WriteLine (buf);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Cone::TShape
//purpose :
//=======================================================================
const Handle(TopoDS_TShape)& VrmlData_Cone::TShape ()
{
if (myIsModified && (myHasBottom || myHasSide)) {
try {
gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
gp_Dir (0., 1., 0.));
BRepPrim_Cone aBuilder (aLocalAxis, myBottomRadius, 0., myHeight);
if (!myHasBottom)
myTShape = aBuilder.LateralFace().TShape();
else if (!myHasSide)
myTShape = aBuilder.BottomFace().TShape();
else
myTShape = aBuilder.Shell().TShape();
myIsModified = Standard_False;
} catch (Standard_Failure) {
myTShape.Nullify();
}
}
return myTShape;
}
//=======================================================================
//function : VrmlData_Cone::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Cone::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Cone) aResult =
Handle(VrmlData_Cone)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Cone (theOther.IsNull() ? Scene(): theOther->Scene(),
Name());
aResult->SetBottomRadius (myBottomRadius);
aResult->SetHeight (myHeight);
aResult->SetFaces (myHasBottom, myHasSide);
return aResult;
}
//=======================================================================
//function : VrmlData_Cone::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Cone::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
{
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottomRadius"))
aStatus = Scene().ReadReal (theBuffer, myBottomRadius,
Standard_True, Standard_True);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
aStatus = Scene().ReadReal (theBuffer, myHeight,
Standard_True, Standard_True);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
myHasSide = hasSide;
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
myHasBottom = hasBottom;
} else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
return aStatus;
}
//=======================================================================
//function : VrmlData_Cone::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Cone::Write (const char * thePrefix) const
{
static char header[] = "Cone {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
char buf[128];
if ((myBottomRadius - 1.)*(myBottomRadius - 1.) > Precision::Confusion()) {
sprintf (buf, "bottomRadius %.12g", myBottomRadius);
aStatus = Scene().WriteLine (buf);
}
if (OK(aStatus) &&
(myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
sprintf (buf, "height %.12g", myHeight);
aStatus = Scene().WriteLine (buf);
}
if (OK(aStatus) && myHasBottom == Standard_False)
aStatus = Scene().WriteLine ("bottom FALSE");
if (OK(aStatus) && myHasSide == Standard_False)
aStatus = Scene().WriteLine ("side FALSE");
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Cone::IsDefault
//purpose :
//=======================================================================
// Standard_Boolean VrmlData_Cone::IsDefault () const
// {
// return
// (myHasBottom && myHasSide &&
// ((myBottomRadius - 1.)*(myBottomRadius-1.) < Precision::Confusion()) &&
// ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
// }
//=======================================================================
//function : VrmlData_Cylinder::TShape
//purpose :
//=======================================================================
const Handle(TopoDS_TShape)& VrmlData_Cylinder::TShape ()
{
if (myIsModified && (myHasBottom || myHasSide || myHasTop)) {
try {
gp_Ax2 aLocalAxis (gp_Pnt (0., -0.5 * myHeight, 0.),
gp_Dir (0., 1., 0.));
BRepPrim_Cylinder aBuilder (aLocalAxis, myRadius, myHeight);
BRepPrim_Builder aShapeBuilder;
TopoDS_Shell aShell;
aShapeBuilder.MakeShell(aShell);
if (myHasSide)
aShapeBuilder.AddShellFace (aShell, aBuilder.LateralFace());
if (myHasTop)
aShapeBuilder.AddShellFace (aShell, aBuilder.TopFace());
if (myHasBottom)
aShapeBuilder.AddShellFace (aShell, aBuilder.BottomFace());
myTShape = aShell.TShape();
myIsModified = Standard_False;
} catch (Standard_Failure) {
myTShape.Nullify();
}
}
return myTShape;
}
//=======================================================================
//function : VrmlData_Cylinder::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Cylinder::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Cylinder) aResult =
Handle(VrmlData_Cylinder)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Cylinder(theOther.IsNull()?Scene():theOther->Scene(),
Name());
aResult->SetRadius (myRadius);
aResult->SetHeight (myHeight);
aResult->SetFaces (myHasBottom, myHasSide, myHasTop);
return aResult;
}
//=======================================================================
//function : VrmlData_Cylinder::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Cylinder::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
Standard_Boolean hasSide(Standard_True), hasBottom(Standard_True);
Standard_Boolean hasTop (Standard_True);
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
{
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
aStatus = Scene().ReadReal (theBuffer, myRadius,
Standard_True, Standard_True);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "height"))
aStatus = Scene().ReadReal (theBuffer, myHeight,
Standard_True, Standard_True);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "top")) {
if (OK(aStatus, ReadBoolean (theBuffer, hasTop)))
myHasTop = hasTop;
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "side")) {
if (OK(aStatus, ReadBoolean (theBuffer, hasSide)))
myHasSide = hasSide;
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bottom")) {
if (OK(aStatus, ReadBoolean (theBuffer, hasBottom)))
myHasBottom = hasBottom;
} else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
return aStatus;
}
//=======================================================================
//function : VrmlData_Cylinder::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Cylinder::Write (const char * thePrefix) const
{
static char header[] = "Cylinder {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
char buf[128];
if ((myRadius - 1.)*(myRadius - 1.) > Precision::Confusion()) {
sprintf (buf, "radius %.12g", myRadius);
aStatus = Scene().WriteLine (buf);
}
if (OK(aStatus) &&
(myHeight - 2.)*(myHeight - 2.) > Precision::Confusion()) {
sprintf (buf, "height %.12g", myHeight);
aStatus = Scene().WriteLine (buf);
}
if (OK(aStatus) && myHasBottom == Standard_False)
aStatus = Scene().WriteLine ("bottom FALSE");
if (OK(aStatus) && myHasSide == Standard_False)
aStatus = Scene().WriteLine ("side FALSE");
if (OK(aStatus) && myHasTop == Standard_False)
aStatus = Scene().WriteLine ("top FALSE");
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Cylinder::IsDefault
//purpose :
//=======================================================================
// Standard_Boolean VrmlData_Cylinder::IsDefault () const
// {
// return
// (myHasBottom && myHasSide && myHasTop &&
// ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion()) &&
// ((myHeight - 2.)*(myHeight - 2.) < Precision::Confusion()));
// }
//=======================================================================
//function : VrmlData_Sphere::TShape
//purpose :
//=======================================================================
const Handle(TopoDS_TShape)& VrmlData_Sphere::TShape ()
{
if (myIsModified) {
try {
myTShape = BRepPrim_Sphere(myRadius).Shell().TShape();
myIsModified = Standard_False;
} catch (Standard_Failure) {
myTShape.Nullify();
}
}
return myTShape;
}
//=======================================================================
//function : VrmlData_Sphere::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Sphere::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Sphere) aResult =
Handle(VrmlData_Sphere)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Sphere(theOther.IsNull()? Scene() :theOther->Scene(),
Name());
aResult->SetRadius (myRadius);
return aResult;
}
//=======================================================================
//function : VrmlData_Sphere::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Sphere::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "radius"))
aStatus = Scene().ReadReal (theBuffer, myRadius,
Standard_True, Standard_True);
else
break;
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
return aStatus;
}
//=======================================================================
//function : VrmlData_Sphere::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Sphere::Write (const char * thePrefix) const
{
static char header[] = "Sphere {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
char buf[128];
sprintf (buf, "radius %.12g", myRadius);
Scene().WriteLine (buf);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Sphere::IsDefault
//purpose :
//=======================================================================
// Standard_Boolean VrmlData_Sphere::IsDefault () const
// {
// return ((myRadius - 1.)*(myRadius - 1.) < Precision::Confusion())
// }
//=======================================================================
//function : VrmlData_TextureCoordinate::AllocateValues
//purpose :
//=======================================================================
Standard_Boolean VrmlData_TextureCoordinate::AllocateValues
(const Standard_Size theLength)
{
myPoints = reinterpret_cast <const gp_XY *>
(Scene().Allocator()->Allocate (theLength*sizeof(gp_XY)));
myLength = theLength;
return (myPoints != 0L);
}
//=======================================================================
//function : VrmlData_TextureCoordinate::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_TextureCoordinate::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_TextureCoordinate) aResult =
Handle(VrmlData_TextureCoordinate)::DownCast
(VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_TextureCoordinate
(theOther.IsNull() ? Scene() : theOther->Scene(), Name());
if (&aResult->Scene() == &Scene())
aResult->SetPoints (myLength, myPoints);
else {
aResult->AllocateValues (myLength);
for (Standard_Size i = 0; i < myLength; i++)
const_cast <gp_XY&> (aResult->myPoints[i]) = myPoints[i];
}
return aResult;
}
//=======================================================================
//function : VrmlData_TextureCoordinate::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_TextureCoordinate::Read
(VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
NCollection_Vector<gp_XY> vecValues;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
// Match the name with the current word in the stream
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "point"))
// Read the body of the data node (comma-separated list of duplets)
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
if (theBuffer.LinePtr[0] != '[') // opening bracket
aStatus = VrmlData_VrmlFormatError;
else {
theBuffer.LinePtr++;
while (~0) {
gp_XY anXY;
if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
// closing bracket, in case that it follows a comma
if (theBuffer.LinePtr[0] == ']') {
theBuffer.LinePtr++;
break;
}
if (!OK(aStatus, Scene().ReadXY(theBuffer, anXY,
Standard_False, Standard_False)))
break;
vecValues.Append(anXY);
if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
if (theBuffer.LinePtr[0] == ',') {
theBuffer.LinePtr++;
continue;
} else if (theBuffer.LinePtr[0] == ']') // closing bracket
theBuffer.LinePtr++;
else
aStatus = VrmlData_VrmlFormatError;
break;
}
}
if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
myLength = vecValues.Length();
if (myLength > 0) {
gp_XY * aPoints = reinterpret_cast <gp_XY *>
(Scene().Allocator()->Allocate (myLength * sizeof(gp_XY)));
myPoints = aPoints;
for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
aPoints[i] = vecValues(i);
}
}
}
return aStatus;
}
//=======================================================================
//function : VrmlData_ArrayVec3d::Clone
//purpose :
//=======================================================================
// Handle(VrmlData_Node) VrmlData_ArrayVec3d::Clone
// (const Handle(VrmlData_Node)& theOther) const
// {
// VrmlData_Node::Clone (theOther);
// const Handle(VrmlData_ArrayVec3d) anArrayNode =
// Handle(VrmlData_ArrayVec3d)::DownCast (theOther);
// if (anArrayNode.IsNull() == Standard_False)
// anArrayNode->SetValues (myLength, myArray);
// return theOther;
// }
//=======================================================================
//function : VrmlData_ArrayVec3d::ReadArray
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_ArrayVec3d::ReadArray
(VrmlData_InBuffer& theBuffer,
const char * theName,
const Standard_Boolean isScale)
{
VrmlData_ErrorStatus aStatus;
NCollection_Vector<gp_XYZ> vecValues;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
// Match the name with the current word in the stream
if (theName) {
const Standard_Integer aNameLen = strlen(theName);
if (strncmp (theBuffer.LinePtr, theName, aNameLen))
aStatus = VrmlData_VrmlFormatError;
else
theBuffer.LinePtr += aNameLen;
} else {
// Skip the word in the input
while (theBuffer.LinePtr[0] != ' ' &&
theBuffer.LinePtr[0] != ',' &&
theBuffer.LinePtr[0] != '\t' &&
theBuffer.LinePtr[0] != '\n' &&
theBuffer.LinePtr[0] != '\r' &&
theBuffer.LinePtr[0] != '\0')
theBuffer.LinePtr++;
}
// Read the body of the data node (list of triplets)
if (OK(aStatus) && OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
if (theBuffer.LinePtr[0] != '[') // opening bracket
aStatus = VrmlData_VrmlFormatError;
else {
theBuffer.LinePtr++;
while (~0) {
gp_XYZ anXYZ;
if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
// closing bracket, in case that it follows a comma
if (theBuffer.LinePtr[0] == ']') {
theBuffer.LinePtr++;
break;
}
// Read three numbers (XYZ value)
if (!OK(aStatus, Scene().ReadXYZ(theBuffer, anXYZ,
isScale, Standard_False)))
break;
vecValues.Append(anXYZ);
if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
if (theBuffer.LinePtr[0] == ']') {// closing bracket
theBuffer.LinePtr++;
break;
}
}
}
if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
myLength = vecValues.Length();
if (myLength > 0) {
gp_XYZ * anArray = reinterpret_cast <gp_XYZ *>
(Scene().Allocator()->Allocate (myLength * sizeof(gp_XYZ)));
myArray = anArray;
for (Standard_Integer i = 0; i < Standard_Integer(myLength); i++)
anArray[i] = vecValues(i);
}
}
}
return aStatus;
}
//=======================================================================
//function : VrmlData_ArrayVec3d::WriteArray
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_ArrayVec3d::WriteArray
(const char * theName,
const Standard_Boolean isScale) const
{
VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
if (myLength > 0) {
aStatus = Scene().WriteLine (theName, "[", 2*GlobalIndent());
if (OK(aStatus)) {
for (Standard_Size i = 0; i < myLength-1; i++)
if (!OK (aStatus, Scene().WriteXYZ (myArray[i], isScale, ",")))
break;
if (OK(aStatus))
aStatus = Scene().WriteXYZ (myArray[myLength-1], isScale);
}
if (aStatus == VrmlData_StatusOK)
aStatus = Scene().WriteLine ("]", 0L, -2*GlobalIndent());
}
return aStatus;
}
//=======================================================================
//function : VrmlData_ArrayVec3d::IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_ArrayVec3d::IsDefault () const
{
return myLength == 0;
}
//=======================================================================
//function : VrmlData_Coodinate::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Coordinate::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Coordinate) aResult =
Handle(VrmlData_Coordinate)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Coordinate
(theOther.IsNull() ? Scene() : theOther->Scene(), Name());
if (&aResult->Scene() == &Scene())
aResult->SetValues (Length(), Values());
else {
aResult->AllocateValues (Length());
for (Standard_Size i = 0; i < Length(); i++)
const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
}
return aResult;
}
//=======================================================================
//function : VrmlData_Coordinate::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Coordinate::Read (VrmlData_InBuffer& theBuffer)
{
return VrmlData_ArrayVec3d::ReadArray (theBuffer, "point", Standard_True);
}
//=======================================================================
//function : VrmlData_Coordinate::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Coordinate::Write (const char * thePrefix) const
{
static char header[] = "Coordinate {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
WriteArray ("point", Standard_True);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Color::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Color::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Color) aResult =
Handle(VrmlData_Color)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Color(theOther.IsNull()? Scene() : theOther->Scene(),
Name());
if (&aResult->Scene() == &Scene())
aResult->SetValues (Length(), Values());
else {
aResult->AllocateValues (Length());
for (Standard_Size i = 0; i < Length(); i++)
const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
}
return aResult;
}
//=======================================================================
//function : VrmlData_Color::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Color::Read (VrmlData_InBuffer& theBuffer)
{
return ReadArray (theBuffer, "color", Standard_False);
}
//=======================================================================
//function : VrmlData_Color::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Color::Write (const char * thePrefix) const
{
static char header[] = "Color {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
WriteArray ("color", Standard_False);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Normal::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Normal::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Normal) aResult =
Handle(VrmlData_Normal)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult= new VrmlData_Normal(theOther.IsNull()? Scene() : theOther->Scene(),
Name());
if (&aResult->Scene() == &Scene())
aResult->SetValues (Length(), Values());
else {
aResult->AllocateValues (Length());
for (Standard_Size i = 0; i < Length(); i++)
const_cast <gp_XYZ&> (aResult->Values()[i]) = Values()[i];
}
return aResult;
}
//=======================================================================
//function : VrmlData_Normal::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Normal::Read (VrmlData_InBuffer& theBuffer)
{
return VrmlData_ArrayVec3d::ReadArray (theBuffer, "vector", Standard_False);
}
//=======================================================================
//function : VrmlData_Normal::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Normal::Write (const char * thePrefix) const
{
static char header[] = "Normal {";
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, Scene().WriteLine (thePrefix, header, GlobalIndent())))
{
WriteArray ("vector", Standard_False);
aStatus = WriteClosing();
}
return aStatus;
}

View File

@@ -0,0 +1,75 @@
// File: VrmlData_Geometry.hxx
// Created: 25.05.06 16:42:51
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Geometry_HeaderFile
#define VrmlData_Geometry_HeaderFile
#include <VrmlData_Node.hxx>
#include <Handle_TopoDS_TShape.hxx>
/**
* Implementation of the Geometry node.
* Contains the topological representation (TopoDS_Shell) of the VRML geometry
*/
class VrmlData_Geometry : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Geometry ()
: myIsModified (Standard_True)
{}
/**
* Constructor
*/
inline VrmlData_Geometry (const VrmlData_Scene& theScene,
const char * theName)
: VrmlData_Node (theScene, theName),
myIsModified (Standard_True)
{}
/**
* Query the shape. This method checks the flag myIsModified; if True it
* should rebuild the shape presentation.
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape () = 0;
protected:
// ---------- PROTECTED METHODS ----------
/**
* Set the TShape.
*/
inline void SetTShape (const Handle(TopoDS_TShape)& theTShape)
{ myTShape = theTShape; }
/**
* Mark modification
*/
inline void SetModified () { myIsModified= Standard_True; }
protected:
// ---------- PROTECTED FIELDS ----------
Handle(TopoDS_TShape) myTShape;
Standard_Boolean myIsModified;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Geometry)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Geometry, VrmlData_Node)
#endif

475
src/VrmlData/VrmlData_Group.cxx Executable file
View File

@@ -0,0 +1,475 @@
// File: VrmlData_Group.cxx
// Created: 06.11.06 08:01
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#include <VrmlData_Group.hxx>
#include <VrmlData_Geometry.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_WorldInfo.hxx>
#include <VrmlData_InBuffer.hxx>
#include <VrmlData_ListOfNode.hxx>
#include <VrmlData_UnknownNode.hxx>
#include <Precision.hxx>
#include <gp_Ax1.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_Group, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Group, VrmlData_Node)
//=======================================================================
//function : VrmlData_Group
//purpose : Constructor
//=======================================================================
VrmlData_Group::VrmlData_Group (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Boolean isTransform)
: VrmlData_Node (theScene, theName),
myIsTransform (isTransform),
myNodes (theScene.Allocator())
{}
//=======================================================================
//function : RemoveNode
//purpose :
//=======================================================================
Standard_Boolean VrmlData_Group::RemoveNode
(const Handle(VrmlData_Node)& theNode)
{
Standard_Boolean aResult (Standard_False);
for (Iterator anIter = NodeIterator(); anIter.More(); anIter.Next())
if (anIter.Value() == theNode) {
aResult = Standard_True;
myNodes.Remove (anIter);
break;
}
return aResult;
}
//=======================================================================
//function : SetTransform
//purpose :
//=======================================================================
Standard_Boolean VrmlData_Group::SetTransform (const gp_Trsf& theTrsf)
{
Standard_Boolean aResult (Standard_False);
if (myIsTransform) {
myTrsf = theTrsf;
aResult = Standard_True;
}
return aResult;
}
//=======================================================================
//function : VrmlData_Group::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Group::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Group) aResult =
Handle(VrmlData_Group)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult =
new VrmlData_Group (theOther.IsNull() ? Scene() : theOther->Scene(),
Name(), myIsTransform);
aResult->myIsTransform = myIsTransform;
if (&aResult->Scene() == &Scene())
aResult->myNodes = myNodes;
else {
// Create a dummy node to pass the different Scene instance to methods Clone
const Handle(VrmlData_UnknownNode) aDummyNode =
new VrmlData_UnknownNode (aResult->Scene());
Iterator anIter (myNodes);
for (; anIter.More(); anIter.Next()) {
const Handle(VrmlData_Node)& aNode = anIter.Value();
if (aNode.IsNull() == Standard_False)
aResult->myNodes.Append(aNode->Clone (aDummyNode));
}
}
if (myIsTransform)
aResult->SetTransform (myTrsf);
aResult->SetBox (myBox);
return aResult;
}
//=======================================================================
//function : FindNode
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Group::FindNode
(const char * theName,
gp_Trsf& theLocation) const
{
Handle(VrmlData_Node) aResult;
Iterator anIter (myNodes);
for (; anIter.More(); anIter.Next()) {
const Handle(VrmlData_Node)& aNode = anIter.Value();
if (aNode.IsNull() == Standard_False) {
if (strcmp(aNode->Name(), theName) == 0)
{
aResult = aNode;
theLocation = myTrsf;
break;
}
// Try a Group type of node
if (aNode->IsKind(STANDARD_TYPE(VrmlData_Group)))
{
const Handle(VrmlData_Group) aGroup =
Handle(VrmlData_Group)::DownCast (aNode);
if (aGroup.IsNull() == Standard_False) {
aResult = aGroup->FindNode(theName, theLocation);
if (aResult.IsNull() == Standard_False) {
//theLocation *= myTrsf;
theLocation.PreMultiply(myTrsf);
break;
}
}
}
}
}
return aResult;
}
//=======================================================================
//function : VrmlData_Group::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Group::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
gp_XYZ aBoxCenter(0., 0., 0.), aBoxSize(-1., -1., -1.);
gp_XYZ aCenter (0., 0., 0.), aScale (1., 1., 1.), aTrans (0., 0., 0.);
gp_XYZ aRotAxis (0., 0., 1.), aScaleAxis (0., 0., 1.);
Standard_Real aRotAngle (0.), aScaleAngle(0.);
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
{
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bboxCenter"))
aStatus = Scene().ReadXYZ (theBuffer, aBoxCenter,
Standard_True, Standard_False);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "bboxSize"))
aStatus = Scene().ReadXYZ (theBuffer, aBoxSize,
Standard_True, Standard_False);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "children")) {
Standard_Boolean isBracketed (Standard_False);
// Read the opening bracket for the list of children
if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
if (theBuffer.LinePtr[0] == '[') {
theBuffer.LinePtr++;
if (!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
isBracketed = Standard_True;
}
// Read the child nodes
Handle(VrmlData_Node) aChildNode;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
// read the end-of-list bracket
if (isBracketed && theBuffer.LinePtr[0] == ']') {
theBuffer.LinePtr++;
break;
}
// otherwise read a node
if (!OK(aStatus, ReadNode (theBuffer, aChildNode)))
break;
AddNode (aChildNode);
if (isBracketed == Standard_False)
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "center"))
if (myIsTransform)
aStatus = Scene().ReadXYZ (theBuffer, aCenter,
Standard_True, Standard_False);
else {
aStatus = VrmlData_VrmlFormatError;
break;
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "rotation"))
if (myIsTransform) {
if (OK(aStatus, Scene().ReadXYZ (theBuffer, aRotAxis,
Standard_False, Standard_False)))
{
if (aRotAxis.SquareModulus() < Precision::Confusion())
aRotAxis.SetZ (1.0);
aStatus = Scene().ReadReal (theBuffer, aRotAngle,
Standard_False, Standard_False);
}
} else {
aStatus = VrmlData_VrmlFormatError;
break;
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "scale")) {
if (myIsTransform)
aStatus = Scene().ReadXYZ (theBuffer, aScale,
Standard_False, Standard_True);
else {
aStatus = VrmlData_VrmlFormatError;
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "scaleOrientation"))
if (myIsTransform) {
if (OK(aStatus, Scene().ReadXYZ (theBuffer, aScaleAxis,
Standard_False, Standard_False)))
aStatus = Scene().ReadReal (theBuffer, aScaleAngle,
Standard_False, Standard_False);
} else {
aStatus = VrmlData_VrmlFormatError;
break;
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "translation"))
if (myIsTransform)
aStatus = Scene().ReadXYZ (theBuffer, aTrans,
Standard_True, Standard_False);
else {
aStatus = VrmlData_VrmlFormatError;
break;
}
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "url")) {
NCollection_List<TCollection_AsciiString> lstURL;
if (OK(aStatus, ReadMultiString (theBuffer, lstURL))) {
NCollection_List<TCollection_AsciiString>::Iterator anIter (lstURL);
for (; anIter.More(); anIter.Next()) {
ifstream aStream;
const TCollection_AsciiString& aFileName = anIter.Value();
if (!OK(aStatus, openFile (aStream, aFileName)))
break;
VrmlData_Scene aScene (Scene().Allocator());
aScene.myLinearScale = Scene().myLinearScale;
aScene.myVrmlDir = Scene().myVrmlDir;
aScene << aStream;
if (!OK(aStatus, aScene.Status()))
break;
VrmlData_Scene::Iterator anIterN = aScene.GetIterator();
for (; anIterN.More(); anIterN.Next())
if (!anIterN.Value()->IsKind(STANDARD_TYPE(VrmlData_WorldInfo)))
AddNode (anIterN.Value());
VrmlData_Scene::Iterator anAllIter(aScene.myAllNodes);
for (; anAllIter.More(); anAllIter.Next()) {
const Handle(VrmlData_Node)& aNode = anAllIter.Value();
if (aNode->IsKind(STANDARD_TYPE(VrmlData_WorldInfo)))
continue;
const_cast <VrmlData_Scene&> (Scene()).myAllNodes.Append (aNode);
aNode->myScene = &Scene();
// The name of the imported node should be prefixed by the URL
// because each name must remain unique in the global scene.
if (aNode->Name())
if (* aNode->Name() != '\0') {
char buf[1024];
strncpy (buf, aFileName.ToCString(), sizeof(buf));
char * ptr = strchr (buf, '.');
if (!ptr)
ptr = strchr (buf,'\0');
* ptr = '_';
strncpy (ptr+1, aNode->Name(), (&buf[sizeof(buf)]-ptr)-2);
const size_t len = strlen(buf) + 1;
char * aNewName =
static_cast<char *> (Scene().Allocator()->Allocate (len));
if (aNewName) {
aNode->myName = aNewName;
memcpy (aNewName, buf, len);
}
}
}
}
}
} else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
if (OK(aStatus)) {
// Check if the Bounding Box has been imported
if (aBoxSize.X() > -Precision::Confusion() &&
aBoxSize.Y() > -Precision::Confusion() &&
aBoxSize.Z() > -Precision::Confusion())
{
myBox.SetCenter (aBoxCenter);
myBox.SetHSize (aBoxSize*0.5);
}
if (myIsTransform) {
// Create the corresponding transformation.
gp_Trsf tRot, tCentInv;
myTrsf.SetTranslation(aTrans+aCenter);
gp_Ax1 aRotation (gp::Origin(), aRotAxis);
tRot.SetRotation(gp_Ax1 (gp::Origin(), aRotAxis), aRotAngle);
myTrsf.Multiply (tRot);
// Check that the scale is uniform (the same value in all 3 directions.
// Only in this case the scaling is applied.
const Standard_Real aScaleDiff[2] = {
aScale.X()-aScale.Y(),
aScale.X()-aScale.Z()
};
if (aScaleDiff[0]*aScaleDiff[0] + aScaleDiff[1]*aScaleDiff[1]
< Precision::Confusion())
{
gp_Trsf tScale;
tScale.SetScale (gp::Origin(), (aScale.X()+aScale.Y()+aScale.Z())/3.);
myTrsf.Multiply (tScale);
}
tCentInv.SetTranslation (aCenter.Reversed());
myTrsf.Multiply (tCentInv);
}
}
return aStatus;
}
//=======================================================================
//function : Shape
//purpose :
//=======================================================================
void VrmlData_Group::Shape (TopoDS_Shape& theShape,
VrmlData_DataMapOfShapeAppearance * pMapApp)
{
VrmlData_Scene::createShape (theShape, myNodes, pMapApp);
theShape.Location(myTrsf);
}
//=======================================================================
//function : openFile
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Group::openFile
(Standard_IStream& theStream,
const TCollection_AsciiString& theFilename)
{
ifstream& aStream = static_cast<ifstream&> (theStream);
VrmlData_ErrorStatus aStatus (VrmlData_EmptyData);
NCollection_List<TCollection_ExtendedString>::Iterator aDirIter =
Scene().VrmlDirIterator();
for (; aDirIter.More(); aDirIter.Next()) {
if (!aDirIter.Value().IsAscii())
continue;
const TCollection_AsciiString aFullName =
TCollection_AsciiString (aDirIter.Value()) + theFilename;
aStream.open (aFullName.ToCString(), ios::in);
if (aStream.fail())
aStream.clear();
else {
aStatus = VrmlData_StatusOK;
break;
}
}
if (aStatus == VrmlData_EmptyData) {
aStream.open (theFilename.ToCString(), ios::in);
if (!aStream.fail())
aStatus = VrmlData_StatusOK;
}
if (aStatus == VrmlData_EmptyData)
aStatus = VrmlData_CannotOpenFile;
return aStatus;
}
//=======================================================================
//function : Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Group::Write (const char * thePrefix) const
{
VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
if (myNodes.IsEmpty() == Standard_False) {
const VrmlData_Scene& aScene = Scene();
Standard_Boolean isTransform = myIsTransform;
if (isTransform && myTrsf.Form() == gp_Identity)
isTransform = Standard_False;
static const char * header[2] = { "Group {" , "Transform {" };
if (OK (aStatus, aScene.WriteLine (thePrefix, header[isTransform ? 1 : 0],
GlobalIndent())))
{
char buf[240];
if (OK(aStatus) && aScene.IsDummyWrite() == Standard_False)
{
const gp_XYZ aBoxCorner[2] = {
myBox.CornerMin(),
myBox.CornerMax()
};
// Check that the box is not void
if (aBoxCorner[0].X() < aBoxCorner[1].X() + Precision::Confusion()) {
sprintf (buf, "bboxCenter %.9g %.9g %.9g",
0.5 * (aBoxCorner[0].X() + aBoxCorner[1].X()),
0.5 * (aBoxCorner[0].Y() + aBoxCorner[1].Y()),
0.5 * (aBoxCorner[0].Z() + aBoxCorner[1].Z()));
aStatus = aScene.WriteLine (buf);
if (OK(aStatus)) {
sprintf (buf, "bboxSize %.9g %.9g %.9g",
aBoxCorner[1].X() - aBoxCorner[0].X(),
aBoxCorner[1].Y() - aBoxCorner[0].Y(),
aBoxCorner[1].Z() - aBoxCorner[0].Z());
aStatus = aScene.WriteLine (buf);
}
}
}
if (OK(aStatus) && isTransform && aScene.IsDummyWrite() == Standard_False)
{
// Output the Scale
const Standard_Real aScaleFactor = myTrsf.ScaleFactor();
if ((aScaleFactor - 1.)*(aScaleFactor - 1.) >
0.0001*Precision::Confusion())
{
sprintf (buf, "scale %.12g %.12g %.12g",
aScaleFactor, aScaleFactor, aScaleFactor);
aStatus = aScene.WriteLine (buf);
}
// Output the Translation
const gp_XYZ& aTrans = myTrsf.TranslationPart();
if (aTrans.SquareModulus() > 0.0001*Precision::Confusion()) {
sprintf (buf, "translation %.12g %.12g %.12g",
aTrans.X(), aTrans.Y(), aTrans.Z());
aStatus = aScene.WriteLine (buf);
}
// Output the Rotation
gp_XYZ anAxis;
Standard_Real anAngle;
if (myTrsf.GetRotation (anAxis, anAngle)) {
// output the Rotation
sprintf (buf, "rotation %.12g %.12g %.12g %.9g",
anAxis.X(), anAxis.Y(), anAxis.Z(), anAngle);
aStatus = aScene.WriteLine (buf);
}
}
if (OK(aStatus)) {
aStatus = aScene.WriteLine ("children [", 0L, GlobalIndent());
VrmlData_ListOfNode::Iterator anIterChild (myNodes);
for (; anIterChild.More() && OK(aStatus); anIterChild.Next()) {
const Handle(VrmlData_Node)& aNode = anIterChild.Value();
aScene.WriteNode (0L, aNode);
}
if (OK(aStatus)) {
aStatus = aScene.WriteLine ("]", 0L, -GlobalIndent());
}
}
aStatus = WriteClosing();
}
}
return aStatus;
}

171
src/VrmlData/VrmlData_Group.hxx Executable file
View File

@@ -0,0 +1,171 @@
// File: VrmlData_Group.hxx
// Created: 29.05.06 08:56:28
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Group_HeaderFile
#define VrmlData_Group_HeaderFile
#include <VrmlData_ListOfNode.hxx>
#include <Bnd_B3f.hxx>
#include <gp_Trsf.hxx>
class TopoDS_Shape;
class VrmlData_DataMapOfShapeAppearance;
/**
* Implementation of node "Group"
*/
class VrmlData_Group : public VrmlData_Node
{
public:
typedef VrmlData_ListOfNode::Iterator Iterator;
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor.
* @param isTransform
* True if the group of type Transform is defined
* @param theAlloc
* Allocator used for the list of children
*/
VrmlData_Group (const Standard_Boolean isTransform = Standard_False)
: myIsTransform (isTransform)
{}
/**
* Constructor.
* @param theName
* Name of the Group node
* @param isTransform
* True if the group of type Transform is defined
* @param theAlloc
* Allocator used for the list of children
*/
Standard_EXPORT VrmlData_Group
(const VrmlData_Scene& theScene,
const char * theName,
const Standard_Boolean isTransform = Standard_False);
/**
* Add one node to the Group.
*/
inline Handle(VrmlData_Node)&
AddNode (const Handle(VrmlData_Node)& theNode)
{ return myNodes.Append(theNode); }
/**
* Remove one node from the Group.
* @return
* True if the node was located and removed, False if none removed.
*/
Standard_EXPORT Standard_Boolean
RemoveNode (const Handle(VrmlData_Node)& theNode);
/**
* Create iterator on nodes belonging to the Group.
*/
inline Iterator
NodeIterator () const { return Iterator (myNodes); }
/**
* Query the bounding box.
*/
inline const Bnd_B3f&
Box () const { return myBox; }
/**
* Set the bounding box.
*/
inline void SetBox (const Bnd_B3f& theBox) { myBox = theBox; }
/**
* Set the transformation. Returns True if the group is Transform type,
* otherwise do nothing and return False.
*/
Standard_EXPORT Standard_Boolean
SetTransform (const gp_Trsf& theTrsf);
/**
* Query the transform value.
* For group without transformation this always returns Identity
*/
inline const gp_Trsf&
GetTransform () const { return myTrsf; }
/**
* Query if the node is Transform type.
*/
inline Standard_Boolean
IsTransform () const { return myIsTransform; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther) const;
/**
* Fill the Node internal data from the given input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Find a node by its name, inside this Group
* @param theName
* Name of the node to search for.
* @param theLocation
* Location of the found node with respect to this Group.
*/
Standard_EXPORT Handle(VrmlData_Node)
FindNode (const char * theName,
gp_Trsf& theLocation) const;
/**
* Get the shape representing the group geometry.
*/
Standard_EXPORT void
Shape (TopoDS_Shape& theShape,
VrmlData_DataMapOfShapeAppearance * pMapApp);
protected:
// ---------- PROTECTED METHODS ----------
/**
* Try to open a file by the given filename, using the search directories
* list myVrmlDir of the Scene.
*/
Standard_EXPORT VrmlData_ErrorStatus
openFile (Standard_IStream& theStream,
const TCollection_AsciiString& theFilename);
private:
// ---------- PRIVATE FIELDS ----------
Standard_Boolean myIsTransform;
VrmlData_ListOfNode myNodes;
Bnd_B3f myBox;
gp_Trsf myTrsf;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Group)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Group, VrmlData_Node)
#endif

View File

@@ -0,0 +1,76 @@
// File: VrmlData_ImageTexture.hxx
// Created: 25.05.06 16:08:10
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_ImageTexture_HeaderFile
#define VrmlData_ImageTexture_HeaderFile
#include <VrmlData_Texture.hxx>
/**
* Implementation of the ImageTexture node
*/
class VrmlData_ImageTexture : public VrmlData_Texture
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_ImageTexture ()
{}
/**
* Constructor
*/
Standard_EXPORT VrmlData_ImageTexture
(const VrmlData_Scene& theScene,
const char * theName,
const char * theURL = 0L,
const Standard_Boolean theRepS = Standard_False,
const Standard_Boolean theRepT = Standard_False);
/**
* Query the associated URL.
*/
inline const NCollection_List<TCollection_AsciiString>&
URL () const
{ return myURL; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
NCollection_List<TCollection_AsciiString> myURL;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_ImageTexture)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_ImageTexture, VrmlData_Texture)
#endif

View File

@@ -0,0 +1,29 @@
// File: VrmlData_InBuffer.hxx
// Created: 08.10.06 23:19
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_InBuffer_HeaderFile
#define VrmlData_InBuffer_HeaderFile
#include <Standard_IStream.hxx>
#include <Standard_Boolean.hxx>
/**
* Structure passed to the methods dealing with input stream.
*/
struct VrmlData_InBuffer {
Standard_IStream& Input;
char Line[8096];
char * LinePtr;
Standard_Boolean IsProcessed;
Standard_Integer LineCount;
VrmlData_InBuffer (Standard_IStream& theStream)
: Input (theStream),
LinePtr (&Line[0]),
IsProcessed (Standard_False),
LineCount (0) {}
};
#endif

View File

@@ -0,0 +1,404 @@
// File: VrmlData_IndexedFaceSet.cxx
// Created: 04.11.06 21:28
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#include <VrmlData_IndexedFaceSet.hxx>
#include <VrmlData_InBuffer.hxx>
#include <VrmlData_UnknownNode.hxx>
#include <Poly_Triangulation.hxx>
#include <BRep_TFace.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_Color.hxx>
#include <VrmlData_Normal.hxx>
#include <VrmlData_TextureCoordinate.hxx>
#include <VrmlData_Scene.hxx>
#include <Precision.hxx>
#include <NCollection_Vector.hxx>
#include <NCollection_DataMap.hxx>
#include <Poly.hxx>
#include <TShort_HArray1OfShortReal.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_Faceted, VrmlData_Geometry)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Faceted, VrmlData_Geometry)
IMPLEMENT_STANDARD_HANDLE (VrmlData_IndexedFaceSet, VrmlData_Faceted)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_IndexedFaceSet, VrmlData_Faceted)
//=======================================================================
//function : readData
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Faceted::readData (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus (VrmlData_EmptyData);
Standard_Boolean aBool;
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "ccw")) {
if (OK(aStatus, ReadBoolean (theBuffer, aBool)))
myIsCCW = aBool;
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "convex")) {
if (OK(aStatus, ReadBoolean (theBuffer, aBool)))
myIsConvex = aBool;
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "solid")) {
if (OK(aStatus, ReadBoolean (theBuffer, aBool)))
myIsSolid = aBool;
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "creaseAngle")) {
Standard_Real anAngle;
if (OK(aStatus, Scene().ReadReal (theBuffer, anAngle,
Standard_False, Standard_False)))
if (anAngle < -Precision::Confusion()*0.001)
aStatus = VrmlData_IrrelevantNumber;
else
myCreaseAngle = anAngle;
}
return aStatus;
}
//=======================================================================
//function : VrmlData_IndexedFaceSet::TShape
//purpose :
//=======================================================================
const Handle(TopoDS_TShape)& VrmlData_IndexedFaceSet::TShape ()
{
if (myNbPolygons == 0)
myTShape.Nullify();
else if (myIsModified) {
// Create an empty topological Face
const gp_XYZ * arrNodes = myCoords->Values();
Standard_Integer i, nTri(0);
NCollection_DataMap <int, int> mapNodeId;
// Count non-degenerated triangles
for (i = 0; i < (int)myNbPolygons; i++) {
const Standard_Integer * arrIndice;
if (Polygon(i, arrIndice) == 3) {
if (arrIndice[0] < 0)
continue;
const gp_XYZ aVec[2] = {
arrNodes[arrIndice[1]] - arrNodes[arrIndice[0]],
arrNodes[arrIndice[2]] - arrNodes[arrIndice[0]]
};
if ((aVec[0] ^ aVec[1]).SquareModulus() >
Precision::Confusion()*Precision::Confusion())
++nTri;
else {
const_cast<Standard_Integer&> (arrIndice[0]) = -1;
continue;
}
}
if (mapNodeId.IsBound (arrIndice[0]) == Standard_False)
mapNodeId.Bind (arrIndice[0], 0);
if (mapNodeId.IsBound (arrIndice[1]) == Standard_False)
mapNodeId.Bind (arrIndice[1], 0);
if (mapNodeId.IsBound (arrIndice[2]) == Standard_False)
mapNodeId.Bind (arrIndice[2], 0);
}
const Standard_Integer nbNodes (mapNodeId.Extent());
const Standard_Integer nNodesTri
(myNormalPerVertex && myArrNormalInd==0L ? nbNodes : nTri * 3);
// Create the CasCade triangulation
//Handle(BRep_Triangulation) aTriangulation =
//new BRep_Triangulation (nbNodes, nTri,
//myNormalPerVertex && myArrNormalInd==0L);
Handle(Poly_Triangulation) aTriangulation =
new Poly_Triangulation (nNodesTri, nTri, Standard_False);
Handle(BRep_TFace) aFace = new BRep_TFace();
aFace->Triangulation (aTriangulation);
myTShape = aFace;
TColgp_Array1OfPnt& aNodes = aTriangulation->ChangeNodes();
Poly_Array1OfTriangle& aTriangles = aTriangulation->ChangeTriangles();
const Handle(TShort_HArray1OfShortReal) aNormals =
new TShort_HArray1OfShortReal(1, 3*nNodesTri);
aTriangulation->SetNormals(aNormals);
nTri = 0;
// Copy the triangulation vertices
// This is only the case when normals are defined by node so each
// node can be shared by several triangles
if (nNodesTri == nbNodes)
{
NCollection_DataMap <int, int>::Iterator anIterN(mapNodeId);
for (i = 1; anIterN.More(); anIterN.Next()) {
const int aKey = anIterN.Key();
const gp_XYZ& aNodePnt = arrNodes[aKey];
aNodes(i) = gp_Pnt (aNodePnt);
anIterN.ChangeValue() = i++;
}
// Fill the array of triangles
for (i = 0; i < (int)myNbPolygons; i++) {
const Standard_Integer * arrIndice;
if (Polygon(i, arrIndice) == 3)
if (arrIndice[0] >= 0) // check to avoid previously skipped faces
aTriangles(++nTri).Set (mapNodeId(arrIndice[0]),
mapNodeId(arrIndice[1]),
mapNodeId(arrIndice[2]));
}
// Normals should be defined; if they are not, compute them
if (myNormals.IsNull()) {
//aTriangulation->ComputeNormals();
Poly::ComputeNormals(aTriangulation);
} else {
// Copy the normals-per-vertex.
NCollection_DataMap <int, int>::Iterator anIterNN (mapNodeId);
for (; anIterNN.More(); anIterNN.Next()) {
const Standard_Integer ind = (anIterNN.Value() - 1) * 3 + 1;
const gp_XYZ& aNormal = myNormals->Normal(anIterNN.Key());
aNormals->SetValue(ind + 0, Standard_ShortReal(aNormal.X()));
aNormals->SetValue(ind + 1, Standard_ShortReal(aNormal.Y()));
aNormals->SetValue(ind + 2, Standard_ShortReal(aNormal.Z()));
}
}
}
else {
// Copy the triangles. Only the triangle-type polygons are supported.
// In this loop we also get rid of any possible degenerated triangles.
for (i = 0; i < (int)myNbPolygons; i++) {
const Standard_Integer * arrIndice;
if (Polygon(i, arrIndice) == 3)
if (arrIndice[0] >= 0) { // check to avoid previously skipped faces
// normals by triangle - each node belongs to a perticular triangle
nTri++;
aTriangles(nTri).Set (nTri*3 - 2, nTri*3 - 1, nTri*3);
aNodes(nTri*3 - 2) = arrNodes[arrIndice[0]];
aNodes(nTri*3 - 1) = arrNodes[arrIndice[1]];
aNodes(nTri*3 - 0) = arrNodes[arrIndice[2]];
if (IndiceNormals(i, arrIndice) == 3) {
for (Standard_Integer j = 0; j < 3; j++) {
const Standard_Integer ind = ((nTri-1)*3 + j) * 3;
const gp_XYZ& aNormal = myNormals->Normal(arrIndice[j]);
aNormals->SetValue(ind + 1, Standard_ShortReal(aNormal.X()));
aNormals->SetValue(ind + 2, Standard_ShortReal(aNormal.Y()));
aNormals->SetValue(ind + 3, Standard_ShortReal(aNormal.Z()));
}
}
}
}
}
}
return myTShape;
}
//=======================================================================
//function : VrmlData_IndexedFaceSet::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_IndexedFaceSet::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_IndexedFaceSet) aResult =
Handle(VrmlData_IndexedFaceSet)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult =
new VrmlData_IndexedFaceSet(theOther.IsNull()? Scene(): theOther->Scene(),
Name());
if (&aResult->Scene() == &Scene()) {
aResult->SetCoordinates (myCoords);
aResult->SetNormals (myNormals);
aResult->SetColors (myColors);
aResult->SetPolygons (myNbPolygons, myArrPolygons);
aResult->SetNormalInd (myNbNormals, myArrNormalInd);
aResult->SetColorInd (myNbColors, myArrColorInd);
aResult->SetTextureCoordInd (myNbTextures, myArrTextureInd);
} else {
// Create a dummy node to pass the different Scene instance to methods Clone
const Handle(VrmlData_UnknownNode) aDummyNode =
new VrmlData_UnknownNode (aResult->Scene());
if (myCoords.IsNull() == Standard_False)
aResult->SetCoordinates (Handle(VrmlData_Coordinate)::DownCast
(myCoords->Clone (aDummyNode)));
if (myNormals.IsNull() == Standard_False)
aResult->SetNormals (Handle(VrmlData_Normal)::DownCast
(myNormals->Clone (aDummyNode)));
if (myColors.IsNull() == Standard_False)
aResult->SetColors (Handle(VrmlData_Color)::DownCast
(myColors->Clone (aDummyNode)));
//TODO: Replace the following lines with the relevant copying
aResult->SetPolygons (myNbPolygons, myArrPolygons);
aResult->SetNormalInd (myNbNormals, myArrNormalInd);
aResult->SetColorInd (myNbColors, myArrColorInd);
aResult->SetTextureCoordInd (myNbTextures, myArrTextureInd);
}
aResult->SetNormalPerVertex (myNormalPerVertex);
aResult->SetColorPerVertex (myColorPerVertex);
return aResult;
}
//=======================================================================
//function : VrmlData_IndexedFaceSet::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_IndexedFaceSet::Read(VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
const VrmlData_Scene& aScene = Scene();
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
{
if (OK(aStatus, VrmlData_Faceted::readData (theBuffer)))
continue;
if (aStatus != VrmlData_EmptyData)
break;
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "colorPerVertex"))
aStatus = ReadBoolean (theBuffer, myColorPerVertex);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "normalPerVertex"))
aStatus = ReadBoolean (theBuffer, myNormalPerVertex);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coordIndex"))
aStatus = aScene.ReadArrIndex (theBuffer, myArrPolygons, myNbPolygons);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "colorIndex"))
aStatus = aScene.ReadArrIndex (theBuffer, myArrColorInd, myNbColors);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "normalIndex"))
aStatus = aScene.ReadArrIndex (theBuffer, myArrNormalInd, myNbNormals);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texCoordIndex"))
aStatus = aScene.ReadArrIndex (theBuffer, myArrTextureInd, myNbTextures);
// These four checks should be the last one to avoid their interference
// with the other tokens (e.g., coordIndex)
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texCoord"))
aStatus = ReadNode (theBuffer, myTxCoords,
STANDARD_TYPE(VrmlData_TextureCoordinate));
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color"))
aStatus = ReadNode (theBuffer, myColors,
STANDARD_TYPE(VrmlData_Color));
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord"))
aStatus = ReadNode (theBuffer, myCoords,
STANDARD_TYPE(VrmlData_Coordinate));
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "normal"))
aStatus = ReadNode (theBuffer, myNormals,
STANDARD_TYPE(VrmlData_Normal));
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus) || aStatus == VrmlData_EmptyData)
if (OK(aStatus, readBrace (theBuffer))) {
// Post-processing
;
}
return aStatus;
}
// //=======================================================================
// //function : dummyReadBrackets
// //purpose : static (local) function
// //=======================================================================
// VrmlData_ErrorStatus dummyReadBrackets (VrmlData_InBuffer& theBuffer)
// {
// VrmlData_ErrorStatus aStatus;
// Standard_Integer aLevelCounter (0);
// // This loop searches for any opening bracket.
// // Such bracket increments the level counter. A closing bracket decrements
// // the counter. The loop terminates when the counter becomes zero.
// while ((aStatus = VrmlData_Scene::ReadLine(theBuffer)) == VrmlData_StatusOK)
// {
// int aChar;
// while ((aChar = theBuffer.LinePtr[0]) != '\0') {
// theBuffer.LinePtr++;
// if (aChar == '[') {
// aLevelCounter++;
// break;
// } else if (aChar == ']') {
// aLevelCounter--;
// break;
// }
// }
// if (aLevelCounter <= 0)
// break;
// }
// return aStatus;
// }
//=======================================================================
//function : IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_IndexedFaceSet::IsDefault () const
{
Standard_Boolean aResult (Standard_True);
if (myNbPolygons)
aResult = Standard_False;
else if (myCoords.IsNull() == Standard_False)
aResult = myCoords->IsDefault();
return aResult;
}
//=======================================================================
//function : Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_IndexedFaceSet::Write
(const char * thePrefix) const
{
static char header[] = "IndexedFaceSet {";
const VrmlData_Scene& aScene = Scene();
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent()))) {
// Write the attributes of interface "VrmlData_Faceted"
if (IsCCW() == Standard_False)
aStatus = aScene.WriteLine ("ccw FALSE");
if (OK(aStatus) && IsSolid() == Standard_False)
aStatus = aScene.WriteLine ("solid FALSE");
if (OK(aStatus) && IsConvex() == Standard_False)
aStatus = aScene.WriteLine ("convex FALSE");
if (OK(aStatus) && CreaseAngle() > Precision::Confusion()) {
char buf[64];
sprintf (buf, "%.9g", CreaseAngle());
aStatus = aScene.WriteLine ("creaseAngle", buf);
}
if (OK(aStatus) && myCoords.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("coord", myCoords);
if (OK(aStatus))
aStatus = aScene.WriteArrIndex ("coordIndex", myArrPolygons,myNbPolygons);
if (OK(aStatus) && myNormalPerVertex == Standard_False)
aStatus = aScene.WriteLine ("normalPerVertex FALSE");
if (OK(aStatus) && myNormals.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("normal", myNormals);
if (OK(aStatus))
aStatus = aScene.WriteArrIndex ("normalIndex",myArrNormalInd,myNbNormals);
if (OK(aStatus) && myColorPerVertex == Standard_False)
aStatus = aScene.WriteLine ("colorPerVertex FALSE");
if (OK(aStatus) && myColors.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("color", myColors);
if (OK(aStatus))
aStatus = aScene.WriteArrIndex ("colorIndex", myArrColorInd, myNbColors);
if (OK(aStatus) && myTxCoords.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("texCoord", myTxCoords);
if (OK(aStatus))
aStatus = aScene.WriteArrIndex ("texCoordIndex", myArrTextureInd,
myNbTextures);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : GetColor
//purpose :
//=======================================================================
Quantity_Color VrmlData_IndexedFaceSet::GetColor
(const Standard_Integer /*iFace*/,
const Standard_Integer /*iVertex*/)
{
//TODO
return Quantity_NOC_BLACK;
}

View File

@@ -0,0 +1,334 @@
// File: VrmlData_IndexedFaceSet.hxx
// Created: 26.05.06 08:48:31
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_IndexedFaceSet_HeaderFile
#define VrmlData_IndexedFaceSet_HeaderFile
#include <VrmlData_Faceted.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_Normal.hxx>
#include <VrmlData_Color.hxx>
#include <VrmlData_TextureCoordinate.hxx>
#include <gp_XYZ.hxx>
#include <Quantity_Color.hxx>
/**
* Implementation of IndexedFaceSet node
*/
class VrmlData_IndexedFaceSet : public VrmlData_Faceted
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_IndexedFaceSet ()
: myArrPolygons (0L),
myArrNormalInd (0L),
myArrColorInd (0L),
myArrTextureInd (0L),
myNbPolygons (0),
myNbNormals (0),
myNbColors (0),
myNbTextures (0),
myNormalPerVertex (Standard_True),
myColorPerVertex (Standard_True)
{}
/**
* Constructor
*/
inline VrmlData_IndexedFaceSet (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Boolean isCCW =Standard_True,
const Standard_Boolean isSolid =Standard_True,
const Standard_Boolean isConvex=Standard_True,
const Standard_Real theCreaseAngle = 0.)
: VrmlData_Faceted (theScene, theName, isCCW, isSolid, isConvex,
theCreaseAngle),
myArrPolygons (0L),
myArrNormalInd (0L),
myArrColorInd (0L),
myArrTextureInd (0L),
myNbPolygons (0),
myNbNormals (0),
myNbColors (0),
myNbTextures (0),
myNormalPerVertex (Standard_True),
myColorPerVertex (Standard_True)
{}
/**
* Query the Normals.
*/
inline const Handle(VrmlData_Normal)&
Normals () const { return myNormals; }
/**
* Query the Colors.
*/
inline const Handle(VrmlData_Color)&
Colors () const { return myColors; }
/**
* Query the Texture Coordinates.
*/
inline const Handle(VrmlData_TextureCoordinate)&
TextureCoords () const { return myTxCoords; }
// ========================================================================
// =========================== TRIANGULATION GRID =========================
/**
* Query the Coordinates.
*/
inline const Handle(VrmlData_Coordinate)&
Coordinates () const { return myCoords; }
/**
* Query the array of polygons
*/
inline size_t Polygons (const Standard_Integer**& arrPolygons) const
{ arrPolygons = myArrPolygons; return myNbPolygons; }
/**
* Query one polygon.
* @param iFace
* rank of the polygon [0 .. N-1]
* @param outIndice
* <tt>[out]</tt> array of vertex indice
* @return
* number of vertice in the polygon - the dimension of outIndice array
*/
inline Standard_Integer
Polygon (const Standard_Integer iFace,
const Standard_Integer *& outIndice)
{ return * (outIndice = myArrPolygons[iFace])++; }
/**
* Set the nodes
*/
inline void SetCoordinates (const Handle(VrmlData_Coordinate)& theCoord)
{ myCoords = theCoord; }
/**
* Set the polygons
*/
inline void SetPolygons (const Standard_Integer nPolygons,
const Standard_Integer ** thePolygons)
{ myNbPolygons = nPolygons; myArrPolygons = thePolygons; }
// ========================================================================
// ================================ NORMALS ===============================
/**
* Query the array of normal indice
* @param arrNormalInd
* <tt>[out]</tt> array of normalIndex as it is described in VRML2.0 spec
* @return
* Number of integers in the array arrNormalInd.
*/
inline size_t ArrayNormalInd (const Standard_Integer**& arrNormalInd) const
{ arrNormalInd = myArrNormalInd; return myNbNormals; }
/**
* Query normals indice for one face. This method should be called after
* checking myArrNormalInd != NULL, otherwise exception will be thrown.
* @param iFace
* rank of the face [0 .. N-1]
* @param outIndice
* <tt>[out]</tt> array of normals indice
* @return
* number of indice in the array - the dimension of outIndice array
*/
inline Standard_Integer
IndiceNormals (const Standard_Integer iFace,
const Standard_Integer *& outIndice)
{ return * (outIndice = myArrNormalInd[iFace])++; }
/**
* Query a normal for one node in the given element. The normal is
* interpreted according to fields myNormals, myArrNormalInd,
* myNormalPerVertex, as defined in VRML 2.0.
* @param iFace
* rank of the polygon [0 .. N-1]
* @param iVertex
* rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
* if (myNormalPerVertex == False)
* @return
* Normal vector; if the normal is indefinite then returns (0., 0., 0.)
*/
Standard_EXPORT gp_XYZ
GetNormal (const Standard_Integer iFace,
const Standard_Integer iVertex);
/**
* Set the normals array of indice
*/
inline void SetNormalInd (const Standard_Integer nIndice,
const Standard_Integer ** theIndice)
{ myNbNormals = nIndice; myArrNormalInd = theIndice; }
/**
* Set the normals node
*/
inline void SetNormals (const Handle(VrmlData_Normal)& theNormals)
{ myNormals = theNormals; }
/**
* Set the boolean value "normalPerVertex"
*/
inline void SetNormalPerVertex (const Standard_Boolean isNormalPerVertex)
{ myNormalPerVertex = isNormalPerVertex; }
// ========================================================================
// ================================ COLORS ================================
/**
* Query the array of color indice
* @param arrColorInd
* <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
* @return
* Number of integers in the array arrColorInd.
*/
inline size_t ArrayColorInd (const Standard_Integer**& arrColorInd) const
{ arrColorInd = myArrColorInd; return myNbColors; }
/**
* Query a color for one node in the given element. The color is
* interpreted according to fields myColors, myArrColorInd,
* myColorPerVertex, as defined in VRML 2.0.
* @param iFace
* rank of the polygon [0 .. N-1]
* @param iVertex
* rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
* if (myColorPerVertex == False)
* @return
* Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
*/
Standard_EXPORT Quantity_Color
GetColor (const Standard_Integer iFace,
const Standard_Integer iVertex);
/**
* Set the colors array of indice
*/
inline void SetColorInd (const Standard_Integer nIndice,
const Standard_Integer ** theIndice)
{ myNbColors = nIndice; myArrColorInd = theIndice; }
/**
* Set the Color node
*/
inline void SetColors (const Handle(VrmlData_Color)& theColors)
{ myColors = theColors; }
/**
* Set the boolean value "colorPerVertex"
*/
inline void SetColorPerVertex (const Standard_Boolean isColorPerVertex)
{ myColorPerVertex = isColorPerVertex; }
// ========================================================================
// ========================== TEXTURE COIRDINATES =========================
/**
* Query the array of texture coordinate indice
* @param arrTextureCoordInd
* <tt>[out]</tt> array of texCoordIndex as it is described in VRML2.0 spec
* @return
* Number of integers in the array texCoordIndex.
*/
inline size_t ArrayTextureCoordInd
(const Standard_Integer**& arrTextureCoordInd) const
{ arrTextureCoordInd = myArrTextureInd; return myNbTextures; }
/**
* Set the TexCoordiante array of indice
*/
inline void SetTextureCoordInd (const Standard_Integer nIndice,
const Standard_Integer ** theIndice)
{ myNbTextures = nIndice; myArrTextureInd = theIndice; }
/**
* Set the Texture Coordinate node
*/
inline void SetTextureCoords(const Handle(VrmlData_TextureCoordinate)& tc)
{ myTxCoords = tc; }
/**
* Query the shape. This method checks the flag myIsModified; if True it
* should rebuild the shape presentation.
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape ();
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Returns True if the node is default, so that it should not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
protected:
// ---------- PROTECTED METHODS ----------
// /**
// * If the normals are not defined, here we compute them from the polygons.
// * @param theArray
// * Array of float values having length:<ul>
// * <li>if myNormalPerVertex==TRUE : 3 * myCoords->Length()</li>
// * <li>if myNormalPerVertex==FALSE: 9 * number_of_triangles </li>
// * </ul>
// */
// Standard_EXPORT void
// computeNormals (Standard_ShortReal * theArray);
private:
// ---------- PRIVATE FIELDS ----------
Handle(VrmlData_Coordinate) myCoords;
Handle(VrmlData_Normal) myNormals;
Handle(VrmlData_Color) myColors;
Handle(VrmlData_TextureCoordinate) myTxCoords;
const Standard_Integer ** myArrPolygons;
const Standard_Integer ** myArrNormalInd;
const Standard_Integer ** myArrColorInd;
const Standard_Integer ** myArrTextureInd;
Standard_Size myNbPolygons;
Standard_Size myNbNormals;
Standard_Size myNbColors;
Standard_Size myNbTextures;
Standard_Boolean myNormalPerVertex;
Standard_Boolean myColorPerVertex;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_IndexedFaceSet)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_IndexedFaceSet, VrmlData_Faceted)
#endif

View File

@@ -0,0 +1,200 @@
// File: VrmlData_IndexedLineSet.cxx
// Created: 01.08.07 09:20
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#include <VrmlData_IndexedLineSet.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_InBuffer.hxx>
#include <VrmlData_UnknownNode.hxx>
#include <BRep_Builder.hxx>
#include <Poly_Polygon3D.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_IndexedLineSet, VrmlData_Geometry)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_IndexedLineSet, VrmlData_Geometry)
//=======================================================================
//function : GetColor
//purpose :
//=======================================================================
Quantity_Color VrmlData_IndexedLineSet::GetColor
(const Standard_Integer /*iFace*/,
const Standard_Integer /*iVertex*/)
{
//TODO
return Quantity_NOC_BLACK;
}
//=======================================================================
//function : TShape
//purpose : Query the shape. This method checks the flag myIsModified;
// if True it should rebuild the shape presentation.
//=======================================================================
const Handle(TopoDS_TShape)& VrmlData_IndexedLineSet::TShape ()
{
if (myNbPolygons == 0)
myTShape.Nullify();
else if (myIsModified) {
Standard_Integer i;
BRep_Builder aBuilder;
const gp_XYZ * arrNodes = myCoords->Values();
// Create the Wire
TopoDS_Wire aWire;
aBuilder.MakeWire(aWire);
for (i = 0; i < (int)myNbPolygons; i++) {
const Standard_Integer * arrIndice;
const Standard_Integer nNodes = Polygon(i, arrIndice);
TColgp_Array1OfPnt arrPoint (1, nNodes);
TColStd_Array1OfReal arrParam (1, nNodes);
for (Standard_Integer j = 0; j < nNodes; j++) {
arrPoint(j+1).SetXYZ (arrNodes[arrIndice[j]]);
arrParam(j+1) = j;
}
const Handle(Poly_Polygon3D) aPolyPolygon =
new Poly_Polygon3D (arrPoint, arrParam);
TopoDS_Edge anEdge;
aBuilder.MakeEdge (anEdge, aPolyPolygon);
aBuilder.Add (aWire, anEdge);
}
myTShape = aWire.TShape();
}
return myTShape;
}
//=======================================================================
//function : Clone
//purpose : Create a copy of this node
//=======================================================================
Handle(VrmlData_Node) VrmlData_IndexedLineSet::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_IndexedLineSet) aResult =
Handle(VrmlData_IndexedLineSet)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult =
new VrmlData_IndexedLineSet(theOther.IsNull()? Scene(): theOther->Scene(),
Name());
if (&aResult->Scene() == &Scene()) {
aResult->SetCoordinates (myCoords);
aResult->SetColors (myColors);
aResult->SetPolygons (myNbPolygons, myArrPolygons);
aResult->SetColorInd (myNbColors, myArrColorInd);
} else {
// Create a dummy node to pass the different Scene instance to methods Clone
const Handle(VrmlData_UnknownNode) aDummyNode =
new VrmlData_UnknownNode (aResult->Scene());
if (myCoords.IsNull() == Standard_False)
aResult->SetCoordinates (Handle(VrmlData_Coordinate)::DownCast
(myCoords->Clone (aDummyNode)));
if (myColors.IsNull() == Standard_False)
aResult->SetColors (Handle(VrmlData_Color)::DownCast
(myColors->Clone (aDummyNode)));
//TODO: Replace the following lines with the relevant copying
aResult->SetPolygons (myNbPolygons, myArrPolygons);
aResult->SetColorInd (myNbColors, myArrColorInd);
}
aResult->SetColorPerVertex (myColorPerVertex);
return aResult;
}
//=======================================================================
//function : Read
//purpose : Read the Node from input stream.
//=======================================================================
VrmlData_ErrorStatus VrmlData_IndexedLineSet::Read
(VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
const VrmlData_Scene& aScene = Scene();
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
{
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "colorPerVertex"))
aStatus = ReadBoolean (theBuffer, myColorPerVertex);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coordIndex"))
aStatus = aScene.ReadArrIndex (theBuffer, myArrPolygons, myNbPolygons);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "colorIndex"))
aStatus = aScene.ReadArrIndex (theBuffer, myArrColorInd, myNbColors);
// These two checks should be the last one to avoid their interference
// with the other tokens (e.g., coordIndex)
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "color"))
aStatus = ReadNode (theBuffer, myColors,
STANDARD_TYPE(VrmlData_Color));
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "coord"))
aStatus = ReadNode (theBuffer, myCoords,
STANDARD_TYPE(VrmlData_Coordinate));
else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus) || aStatus == VrmlData_EmptyData)
if (OK(aStatus, readBrace (theBuffer))) {
// Post-processing
;
}
return aStatus;
}
//=======================================================================
//function : Write
//purpose : Write the Node to output stream
//=======================================================================
VrmlData_ErrorStatus VrmlData_IndexedLineSet::Write
(const char * thePrefix) const
{
static char header[] = "IndexedLineSet {";
const VrmlData_Scene& aScene = Scene();
VrmlData_ErrorStatus aStatus;
if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent()))) {
if (OK(aStatus) && myCoords.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("coord", myCoords);
if (OK(aStatus))
aStatus = aScene.WriteArrIndex ("coordIndex", myArrPolygons,myNbPolygons);
if (OK(aStatus) && myColorPerVertex == Standard_False)
aStatus = aScene.WriteLine ("colorPerVertex FALSE");
if (OK(aStatus) && myColors.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("color", myColors);
if (OK(aStatus))
aStatus = aScene.WriteArrIndex ("colorIndex", myArrColorInd, myNbColors);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : IsDefault
//purpose : Returns True if the node is default,
// so that it should not be written.
//=======================================================================
Standard_Boolean VrmlData_IndexedLineSet::IsDefault () const
{
Standard_Boolean aResult (Standard_True);
if (myNbPolygons)
aResult = Standard_False;
else if (myCoords.IsNull() == Standard_False)
aResult = myCoords->IsDefault();
return aResult;
}

View File

@@ -0,0 +1,198 @@
// File: VrmlData_IndexedLineSet.hxx
// Created: 01.08.07 09:06
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#ifndef VrmlData_IndexedLineSet_HeaderFile
#define VrmlData_IndexedLineSet_HeaderFile
#include <VrmlData_Geometry.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_Color.hxx>
//#include <Quantity_Color.hxx>
/**
* Data type to store a set of polygons.
*/
class VrmlData_IndexedLineSet : public VrmlData_Geometry
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor.
*/
inline VrmlData_IndexedLineSet ()
: myArrPolygons (0L),
myArrColorInd (0L),
myNbPolygons (0),
myNbColors (0),
myColorPerVertex (Standard_True)
{}
/**
* Constructor.
*/
inline VrmlData_IndexedLineSet (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Boolean isColorPerVertex
= Standard_True)
: VrmlData_Geometry (theScene, theName),
myArrPolygons (0L),
myArrColorInd (0L),
myNbPolygons (0),
myNbColors (0),
myColorPerVertex (isColorPerVertex)
{}
/**
* Query the Coordinates.
*/
inline const Handle(VrmlData_Coordinate)&
Coordinates () const { return myCoords; }
/**
* Set the nodes
*/
inline void SetCoordinates (const Handle(VrmlData_Coordinate)& theCoord)
{ myCoords = theCoord; }
/**
* Query the Colors.
*/
inline const Handle(VrmlData_Color)&
Colors () const { return myColors; }
/**
* Set the Color node
*/
inline void SetColors (const Handle(VrmlData_Color)& theColors)
{ myColors = theColors; }
// ========================================================================
// =========================== POLYLINES =================================
/**
* Query the array of polygons
*/
inline size_t Polygons (const Standard_Integer**& arrPolygons) const
{ arrPolygons = myArrPolygons; return myNbPolygons; }
/**
* Query one polygon.
* @param iPolygon
* rank of the polygon [0 .. N-1]
* @param outIndice
* <tt>[out]</tt> array of vertex indice
* @return
* number of vertice in the polygon - the dimension of outIndice array
*/
inline Standard_Integer
Polygon (const Standard_Integer iPolygon,
const Standard_Integer *& outIndice)
{ return * (outIndice = myArrPolygons[iPolygon])++; }
/**
* Set the polygons
*/
inline void SetPolygons (const Standard_Integer nPolygons,
const Standard_Integer ** thePolygons)
{ myNbPolygons = nPolygons; myArrPolygons = thePolygons; }
// ========================================================================
// ================================ COLORS ================================
/**
* Query the array of color indice
* @param arrColorInd
* <tt>[out]</tt> array of colorIndex as it is described in VRML2.0 spec
* @return
* Number of integers in the array arrColorInd.
*/
inline size_t ArrayColorInd (const Standard_Integer**& arrColorInd) const
{ arrColorInd = myArrColorInd; return myNbColors; }
/**
* Query a color for one node in the given element. The color is
* interpreted according to fields myColors, myArrColorInd,
* myColorPerVertex, as defined in VRML 2.0.
* @param iFace
* rank of the polygon [0 .. N-1]
* @param iVertex
* rank of the vertex in the polygon [0 .. M-1]. This parameter is ignored
* if (myColorPerVertex == False)
* @return
* Color value (RGB); if the color is indefinite then returns (0., 0., 0.)
*/
Standard_EXPORT Quantity_Color
GetColor (const Standard_Integer iFace,
const Standard_Integer iVertex);
/**
* Set the colors array of indice
*/
inline void SetColorInd (const Standard_Integer nIndice,
const Standard_Integer ** theIndice)
{ myNbColors = nIndice; myArrColorInd = theIndice; }
/**
* Set the boolean value "colorPerVertex"
*/
inline void SetColorPerVertex (const Standard_Boolean isColorPerVertex)
{ myColorPerVertex = isColorPerVertex; }
/**
* Query the shape. This method checks the flag myIsModified; if True it
* should rebuild the shape presentation.
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)&
TShape ();
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Returns True if the node is default, so that it should not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
private:
// ---------- PRIVATE FIELDS ----------
Handle(VrmlData_Coordinate) myCoords;
Handle(VrmlData_Color) myColors;
const Standard_Integer ** myArrPolygons;
const Standard_Integer ** myArrColorInd;
Standard_Size myNbPolygons;
Standard_Size myNbColors;
Standard_Boolean myColorPerVertex;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_IndexedLineSet)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_IndexedLineSet, VrmlData_Geometry)
#endif

View File

@@ -0,0 +1,19 @@
// File: VrmlData_ListOfNode.hxx
// Created: 06.11.06 11:39
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#ifndef VrmlData_ListOfNode_HeaderFile
#define VrmlData_ListOfNode_HeaderFile
#include <NCollection_List.hxx>
#include <VrmlData_Node.hxx>
/**
* Container of List type, holding handles to VrmlData_Node objects
*/
typedef NCollection_List<Handle_VrmlData_Node> VrmlData_ListOfNode;
#endif

View File

@@ -0,0 +1,19 @@
// File: VrmlData_MapOfNode.hxx
// Created: 22.07.07 09:12
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#ifndef VrmlData_MapOfNode_HeaderFile
#define VrmlData_MapOfNode_HeaderFile
#include <NCollection_Map.hxx>
#include <VrmlData_Node.hxx>
/**
* Container of Map type, holding handles to VrmlData_Node objects
*/
typedef NCollection_Map<Handle_VrmlData_Node> VrmlData_MapOfNode;
#endif

View File

@@ -0,0 +1,262 @@
// File: VrmlData_Material.cxx
// Created: 17.07.07 12:10:32
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#include <VrmlData_Material.hxx>
#include <Precision.hxx>
#include <VrmlData_InBuffer.hxx>
#include <VrmlData_Scene.hxx>
#include <gp_XYZ.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_Material, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Material, VrmlData_Node)
//=======================================================================
//function : VrmlData_Material()
//purpose : Empty Constructor
//=======================================================================
VrmlData_Material::VrmlData_Material ()
: myAmbientIntensity (0.2),
myShininess (0.2),
myTransparency (0.),
myDiffuseColor (0.8, 0.8, 0.8, Quantity_TOC_RGB),
myEmissiveColor (0., 0., 0., Quantity_TOC_RGB),
mySpecularColor (0., 0., 0., Quantity_TOC_RGB)
{}
//=======================================================================
//function : VrmlData_Material
//purpose : Constructor
//=======================================================================
VrmlData_Material::VrmlData_Material (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Real theAmbientIntens,
const Standard_Real theShininess,
const Standard_Real theTransparency)
: VrmlData_Node (theScene, theName),
myAmbientIntensity (theAmbientIntens < 0. ? 0.2 : theAmbientIntens),
myShininess (theShininess < 0. ? 0.2 : theShininess),
myTransparency (theTransparency < 0 ? 0. : theTransparency),
myDiffuseColor (0.8, 0.8, 0.8, Quantity_TOC_RGB),
myEmissiveColor (0., 0., 0., Quantity_TOC_RGB),
mySpecularColor (0., 0., 0., Quantity_TOC_RGB)
{}
//=======================================================================
//function : VrmlData_Material::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Material::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Material) aResult =
Handle(VrmlData_Material)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult =
new VrmlData_Material (theOther.IsNull() ? Scene() : theOther->Scene(),
Name());
aResult->SetAmbientIntensity (myAmbientIntensity);
aResult->SetShininess (myShininess);
aResult->SetTransparency (myTransparency);
aResult->SetDiffuseColor (myDiffuseColor);
aResult->SetEmissiveColor (myEmissiveColor);
aResult->SetSpecularColor (mySpecularColor);
return aResult;
}
//=======================================================================
//function : VrmlData_Material::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Material::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
const Standard_Real aConf = 0.001 * Precision::Confusion();
Standard_Real anIntensity[3] = { 0.2, 0.2, 0. };
gp_XYZ aColor[3] = {
gp_XYZ (0.8, 0.8, 0.8),
gp_XYZ (0.0, 0.0, 0.0),
gp_XYZ (0.0, 0.0, 0.0)
};
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "ambientIntensity")) {
if (OK(aStatus, Scene().ReadReal (theBuffer, anIntensity[0],
Standard_False, Standard_False)))
if (anIntensity[0] < -aConf || anIntensity[0] > 1.+aConf) {
aStatus = VrmlData_IrrelevantNumber;
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "shininess")) {
if (OK(aStatus, Scene().ReadReal (theBuffer, anIntensity[1],
Standard_False, Standard_False)))
if (anIntensity[1] < -aConf || anIntensity[1] > 1.+aConf) {
aStatus = VrmlData_IrrelevantNumber;
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "transparency")) {
if (OK(aStatus, Scene().ReadReal (theBuffer, anIntensity[2],
Standard_False, Standard_False)))
if (anIntensity[2] < -aConf || anIntensity[2] > 1.+aConf) {
aStatus = VrmlData_IrrelevantNumber;
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "diffuseColor")) {
if (OK(aStatus, Scene().ReadXYZ (theBuffer, aColor[0],
Standard_False, Standard_False)))
if (aColor[0].X() < -aConf || aColor[0].X() > 1.+aConf ||
aColor[0].Y() < -aConf || aColor[0].Y() > 1.+aConf ||
aColor[0].Z() < -aConf || aColor[0].Z() > 1.+aConf)
{
aStatus = VrmlData_IrrelevantNumber;
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "emissiveColor")) {
if (OK(aStatus, Scene().ReadXYZ (theBuffer, aColor[1],
Standard_False, Standard_False)))
if (aColor[1].X() < -aConf || aColor[1].X() > 1.+aConf ||
aColor[1].Y() < -aConf || aColor[1].Y() > 1.+aConf ||
aColor[1].Z() < -aConf || aColor[1].Z() > 1.+aConf)
{
aStatus = VrmlData_IrrelevantNumber;
break;
}
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "specularColor")) {
if (OK(aStatus, Scene().ReadXYZ (theBuffer, aColor[2],
Standard_False, Standard_False)))
if (aColor[2].X() < -aConf || aColor[2].X() > 1.+aConf ||
aColor[2].Y() < -aConf || aColor[2].Y() > 1.+aConf ||
aColor[2].Z() < -aConf || aColor[2].Z() > 1.+aConf)
{
aStatus = VrmlData_IrrelevantNumber;
break;
}
} else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
// Store the values in the Material node instance
if (OK(aStatus)) {
myAmbientIntensity = anIntensity[0];
myShininess = anIntensity[1];
myTransparency = anIntensity[2];
myDiffuseColor.SetValues (aColor[0].X(), aColor[0].Y(), aColor[0].Z(),
Quantity_TOC_RGB);
myEmissiveColor.SetValues (aColor[1].X(), aColor[1].Y(), aColor[1].Z(),
Quantity_TOC_RGB);
mySpecularColor.SetValues (aColor[2].X(), aColor[2].Y(), aColor[2].Z(),
Quantity_TOC_RGB);
}
return aStatus;
}
//=======================================================================
//function : VrmlData_Material::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Material::Write (const char * thePrefix) const
{
VrmlData_ErrorStatus aStatus;
const VrmlData_Scene& aScene = Scene();
static char header[] = "Material {";
if (aScene.IsDummyWrite() == Standard_False &&
OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
{
char buf[128];
Standard_Real val[3];
Quantity_TypeOfColor bidType (Quantity_TOC_RGB);
const Standard_Real aConf (0.001 * Precision::Confusion());
if (OK(aStatus) && fabs(myAmbientIntensity - 0.2) > aConf) {
sprintf (buf, "%.6g", myAmbientIntensity);
aStatus = aScene.WriteLine ("ambientIntensity ", buf);
}
if (OK(aStatus)) {
myDiffuseColor.Values (val[0], val[1], val[2], bidType);
if ((val[0] - 0.8) * (val[0] - 0.8) +
(val[1] - 0.8) * (val[1] - 0.8) +
(val[2] - 0.8) * (val[2] - 0.8) > 1e-7)
{
sprintf (buf, "%.6g %.6g %.6g", val[0], val[1], val[2]);
aStatus = aScene.WriteLine ("diffuseColor ", buf);
}
}
if (OK(aStatus)) {
myEmissiveColor.Values (val[0], val[1], val[2], bidType);
if (val[0] * val[0] + val[1] * val[1] + val[2] * val[2] > 1e-7) {
sprintf (buf, "%.6g %.6g %.6g", val[0], val[1], val[2]);
aStatus = aScene.WriteLine ("emissiveColor ", buf);
}
}
if (OK(aStatus) && fabs(myShininess - 0.2) > aConf) {
sprintf (buf, "%.6g", myShininess);
aStatus = aScene.WriteLine ("shininess ", buf);
}
if (OK(aStatus)) {
mySpecularColor.Values (val[0], val[1], val[2], bidType);
if (val[0] * val[0] + val[1] * val[1] + val[2] * val[2] > 1e-7) {
sprintf (buf, "%.6g %.6g %.6g", val[0], val[1], val[2]);
aStatus = aScene.WriteLine ("specularColor ", buf);
}
}
if (OK(aStatus) && myTransparency > aConf) {
sprintf (buf, "%.6g", myTransparency);
aStatus = aScene.WriteLine ("transparency ", buf);
}
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_Material::IsDefault () const
{
const Standard_Real aConf (0.001 * Precision::Confusion());
Standard_Boolean aResult (Standard_False);
if (fabs(myAmbientIntensity - 0.2) < aConf &&
fabs(myShininess - 0.2) < aConf &&
myTransparency < aConf)
{
Standard_Real val[3][3];
Quantity_TypeOfColor bidType (Quantity_TOC_RGB);
myDiffuseColor.Values (val[0][0], val[0][1], val[0][2], bidType);
myEmissiveColor.Values (val[1][0], val[1][1], val[1][2], bidType);
mySpecularColor.Values (val[2][0], val[2][1], val[2][2], bidType);
aResult = (((val[0][0] - 0.8)*(val[0][0] - 0.8) +
(val[0][1] - 0.8)*(val[0][1] - 0.8) +
(val[0][2] - 0.8)*(val[0][2] - 0.8) < 1e-7) &&
(val[1][0] * val[1][0] +
val[1][1] * val[1][0] +
val[1][2] * val[1][0] < 1e-7) &&
(val[2][0] * val[2][0] +
val[2][1] * val[2][0] +
val[2][2] * val[2][0] < 1e-7));
}
return aResult;
}

View File

@@ -0,0 +1,157 @@
// File: VrmlData_Material.hxx
// Created: 25.05.06 15:39:22
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Material_HeaderFile
#define VrmlData_Material_HeaderFile
#include <VrmlData_Node.hxx>
#include <Quantity_Color.hxx>
/**
* Implementation of the Material node
*/
class VrmlData_Material : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
Standard_EXPORT VrmlData_Material ();
/**
* Constructor
*/
Standard_EXPORT VrmlData_Material
(const VrmlData_Scene& theScene,
const char * theName,
const Standard_Real theAmbientIntensity = -1.,
const Standard_Real theShininess = -1.,
const Standard_Real theTransparency = -1.);
/**
* Query the Ambient Intensity value
*/
inline Standard_Real
AmbientIntensity() const { return myAmbientIntensity; }
/**
* Query the Shininess value
*/
inline Standard_Real
Shininess () const { return myShininess; }
/**
* Query the Transparency value
*/
inline Standard_Real
Transparency () const { return myTransparency; }
/**
* Query the Diffuse color
*/
inline const Quantity_Color&
DiffuseColor () const { return myDiffuseColor; }
/**
* Query the Emissive color
*/
inline const Quantity_Color&
EmissiveColor () const { return myEmissiveColor; }
/**
* Query the Specular color
*/
inline const Quantity_Color&
SpecularColor () const { return mySpecularColor; }
/**
* Set the Ambient Intensity value
*/
inline void SetAmbientIntensity
(const Standard_Real theAmbientIntensity)
{ myAmbientIntensity = theAmbientIntensity; }
/**
* Set the Shininess value
*/
inline void SetShininess (const Standard_Real theShininess)
{ myShininess = theShininess; }
/**
* Set the Transparency value
*/
inline void SetTransparency (const Standard_Real theTransparency)
{ myTransparency = theTransparency; }
/**
* Query the Diffuse color
*/
inline void SetDiffuseColor (const Quantity_Color& theColor)
{ myDiffuseColor = theColor; }
/**
* Query the Emissive color
*/
inline void SetEmissiveColor (const Quantity_Color& theColor)
{ myEmissiveColor = theColor; }
/**
* Query the Specular color
*/
inline void SetSpecularColor (const Quantity_Color& theColor)
{ mySpecularColor = theColor; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to the Scene output.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Returns True if the node is default, so that it should not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
Standard_Real myAmbientIntensity;
Standard_Real myShininess;
Standard_Real myTransparency;
Quantity_Color myDiffuseColor;
Quantity_Color myEmissiveColor;
Quantity_Color mySpecularColor;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Material)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Material, VrmlData_Node)
#endif

638
src/VrmlData/VrmlData_Node.cxx Executable file
View File

@@ -0,0 +1,638 @@
// File: VrmlData_Node.cxx
// Created: 25.05.06 16:33:25
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#include <Precision.hxx>
#include <VrmlData_Appearance.hxx>
#include <VrmlData_ImageTexture.hxx>
#include <VrmlData_Material.hxx>
#include <VrmlData_ShapeNode.hxx>
#include <VrmlData_UnknownNode.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_InBuffer.hxx>
#include <gp_XY.hxx>
#include <gp_XYZ.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_Node, Standard_Transient)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Node, Standard_Transient)
IMPLEMENT_STANDARD_HANDLE (VrmlData_ShapeNode, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_ShapeNode, VrmlData_Node)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Texture, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Texture, VrmlData_Node)
IMPLEMENT_STANDARD_HANDLE (VrmlData_TextureTransform, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_TextureTransform, VrmlData_Node)
IMPLEMENT_STANDARD_HANDLE (VrmlData_ImageTexture, VrmlData_Texture)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_ImageTexture, VrmlData_Texture)
IMPLEMENT_STANDARD_HANDLE (VrmlData_Appearance, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_Appearance, VrmlData_Node)
IMPLEMENT_STANDARD_HANDLE (VrmlData_UnknownNode, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_UnknownNode, VrmlData_Node)
static VrmlData_Scene MyDefaultScene;
//=======================================================================
//function : IsEqual
//purpose : Global method
//=======================================================================
Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne,
const Handle(VrmlData_Node)& theTwo)
{
Standard_Boolean aResult (Standard_False);
if (theOne->Name() != 0L && theTwo->Name() != 0L)
aResult = (strcmp (theOne->Name(), theTwo->Name()) == 0);
return aResult;
}
//=======================================================================
//function : HashCode
//purpose : Global method
//=======================================================================
Standard_Integer HashCode(const Handle(VrmlData_Node)& theNode,
const Standard_Integer theUpper)
{
return (theNode->Name() == 0L ? 0
: HashCode((Standard_CString)theNode->Name(), theUpper));
}
//=======================================================================
//function : VrmlData_Node
//purpose :
//=======================================================================
VrmlData_Node::VrmlData_Node ()
: myScene (&MyDefaultScene),
myName (0L) {}
//=======================================================================
//function : VrmlData_Node
//purpose : Constructor
//=======================================================================
VrmlData_Node::VrmlData_Node (const VrmlData_Scene& theScene,
const char * theName)
: myScene (&theScene)
{
if (theName == 0L)
theName = "";
setName (theName);
}
//=======================================================================
//function : Clone
//purpose : Create a copy of this node.
//=======================================================================
Handle(VrmlData_Node) VrmlData_Node::Clone
(const Handle(VrmlData_Node)& theOther) const
{
if (theOther.IsNull() == Standard_False) {
if (theOther->IsKind (DynamicType()) == Standard_False)
return NULL;
if (&theOther->Scene() == myScene)
theOther->myName = myName;
else
theOther->setName (myName);
}
return theOther;
}
//=======================================================================
//function : setName
//purpose :
//=======================================================================
void VrmlData_Node::setName (const char * theName, const char * theSuffix)
{
size_t len[2] = {
strlen(theName) + 1,
0
};
if (theSuffix)
len[1] = strlen (theSuffix);
char * aName = (char *)Scene().Allocator()->Allocate(len[0]+len[1]);
myName = aName;
memcpy (aName, theName, len[0]);
if (len[1])
memcpy (&aName[len[0] - 1], theSuffix, len[1]+1);
}
//=======================================================================
//function : IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_Node::IsDefault () const
{
return Standard_False;
}
//=======================================================================
//function : Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::Write (const char *) const
{
return VrmlData_NotImplemented;
}
//=======================================================================
//function : WriteClosing
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::WriteClosing () const
{
VrmlData_ErrorStatus aResult = Scene().Status();
if (aResult == VrmlData_StatusOK || aResult == VrmlData_NotImplemented)
aResult = Scene().WriteLine ("}", 0L, -GlobalIndent());
return aResult;
}
//=======================================================================
//function : readBrace
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::readBrace (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
if (theBuffer.LinePtr[0] == '}')
theBuffer.LinePtr++;
else
aStatus = VrmlData_VrmlFormatError;
return aStatus;
}
//=======================================================================
//function : ReadBoolean
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::ReadBoolean (VrmlData_InBuffer& theBuffer,
Standard_Boolean& theResult)
{
VrmlData_ErrorStatus aStatus;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "TRUE"))
theResult = Standard_True;
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "FALSE"))
theResult = Standard_False;
else
aStatus = VrmlData_BooleanInputError;
}
return aStatus;
}
//=======================================================================
//function : ReadInteger
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::ReadInteger (VrmlData_InBuffer& theBuffer,
long& theResult)
{
VrmlData_ErrorStatus aStatus;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
char * endptr;
long aResult;
aResult = strtol (theBuffer.LinePtr, &endptr, 10);
if (endptr == theBuffer.LinePtr)
aStatus = VrmlData_NumericInputError;
else {
theResult = aResult;
theBuffer.LinePtr = endptr;
}
}
return aStatus;
}
//=======================================================================
//function : ReadString
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::ReadString
(VrmlData_InBuffer& theBuffer,
TCollection_AsciiString& theResult)
{
VrmlData_ErrorStatus aStatus;
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (theBuffer.LinePtr[0] != '\"')
aStatus = VrmlData_StringInputError;
else {
char * ptr = &theBuffer.LinePtr[1];
while (*ptr != '\0' && *ptr != '\"')
ptr++;
if (*ptr == '\0')
aStatus = VrmlData_StringInputError;
else {
*ptr = '\0';
theResult = (Standard_CString) &theBuffer.LinePtr[1];
theBuffer.LinePtr = ptr+1;
}
}
}
return aStatus;
}
//=======================================================================
//function : ReadMultiString
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::ReadMultiString
(VrmlData_InBuffer& theBuffer,
NCollection_List<TCollection_AsciiString>& theResult)
{
VrmlData_ErrorStatus aStatus;
Standard_Boolean isBracketed (Standard_False);
// Read the list of URL
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (theBuffer.LinePtr[0] == '[') {
theBuffer.LinePtr++;
isBracketed = Standard_True;
}
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (isBracketed && theBuffer.LinePtr[0] == ']') { // closing bracket
theBuffer.LinePtr++;
break;
}
TCollection_AsciiString aString;
if (!OK(aStatus, ReadString(theBuffer, aString)))
break;
theResult.Append(aString);
if (isBracketed == Standard_False ||
!OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
break;
if (theBuffer.LinePtr[0] == ',') {
theBuffer.LinePtr++;
continue;
} else if (theBuffer.LinePtr[0] == ']') // closing bracket
theBuffer.LinePtr++;
else
aStatus = VrmlData_VrmlFormatError;
break;
}
}
return aStatus;
}
//=======================================================================
//function : ReadNode
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Node::ReadNode
(VrmlData_InBuffer& theBuffer,
Handle(VrmlData_Node)& theNode,
const Handle(Standard_Type)& theType)
{
Handle(VrmlData_Node) aNode;
VrmlData_ErrorStatus aStatus;
// First line of a new node should identify this node type
if (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE(theBuffer.LinePtr, "USE")) {
TCollection_AsciiString aName;
aStatus = VrmlData_Scene::ReadWord (theBuffer, aName);
if (aStatus == VrmlData_StatusOK) {
aNode = myScene->FindNode (aName.ToCString(), theType);
if (aNode.IsNull())
aStatus = VrmlData_NodeNameUnknown;
// else
// aNode = aNode->Clone(0L);
}
}
// We create a relevant node using the line with the type ID
else if (OK(aStatus,
const_cast<VrmlData_Scene *>(myScene)->createNode (theBuffer,
aNode,
theType)))
if (aNode.IsNull() == Standard_False)
// The node data are read here, including the final closing brace
aStatus = aNode->Read(theBuffer);
if (aStatus == VrmlData_StatusOK)
theNode = aNode;
}
return aStatus;
}
//=======================================================================
//function : VrmlData_ShapeNode::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_ShapeNode::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_ShapeNode) aResult =
Handle(VrmlData_ShapeNode)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult= new VrmlData_ShapeNode(theOther.IsNull()?Scene():theOther->Scene(),
Name());
if (&aResult->Scene() == &Scene()) {
aResult->SetAppearance (myAppearance);
aResult->SetGeometry (myGeometry);
} else {
// Create a dummy node to pass the different Scene instance to methods Clone
const Handle(VrmlData_UnknownNode) aDummyNode =
new VrmlData_UnknownNode (aResult->Scene());
if (myAppearance.IsNull() == Standard_False)
aResult->SetAppearance(Handle(VrmlData_Appearance)::DownCast
(myAppearance->Clone (aDummyNode)));
if (myGeometry.IsNull() == Standard_False)
aResult->SetGeometry (Handle(VrmlData_Geometry)::DownCast
(myGeometry->Clone (aDummyNode)));
}
return aResult;
}
//=======================================================================
//function : VrmlData_ShapeNode::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_ShapeNode::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "appearance"))
aStatus = ReadNode (theBuffer, myAppearance,
STANDARD_TYPE(VrmlData_Appearance));
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "geometry"))
aStatus = ReadNode (theBuffer, myGeometry);
// here we do not check for the Geometry type because unknown node types can
// occur (IndexedLineSet, etc.)
// STANDARD_TYPE(VrmlData_Geometry));
else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
return aStatus;
}
//=======================================================================
//function : VrmlData_ShapeNode::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_ShapeNode::Write (const char * thePrefix) const
{
VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
const VrmlData_Scene& aScene = Scene();
static char header[] = "Shape {";
if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
{
if (myAppearance.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("appearance", myAppearance);
if (myGeometry.IsNull() == Standard_False && OK(aStatus))
aStatus = aScene.WriteNode ("geometry", myGeometry);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : VrmlData_ShapeNode::IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_ShapeNode::IsDefault () const
{
Standard_Boolean aResult (Standard_True);
if (myGeometry.IsNull() == Standard_False)
aResult = myGeometry->IsDefault();
return aResult;
}
//=======================================================================
//function : VrmlData_UnknownNode::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_UnknownNode::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
Standard_Integer aLevelCounter (0);
// This loop searches for any opening brace.
// Such brace increments the level counter. A closing brace decrements
// the counter. The loop terminates when the counter becomes negative.
while (aLevelCounter >= 0 &&
OK(aStatus, VrmlData_Scene::ReadLine(theBuffer)))
{
int aChar;
while ((aChar = theBuffer.LinePtr[0]) != '\0') {
theBuffer.LinePtr++;
if (aChar == '{') {
aLevelCounter++;
break;
} else if (aChar == '}') {
aLevelCounter--;
break;
}
}
}
return aStatus;
}
//=======================================================================
//function : VrmlData_UnknownNode::IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_UnknownNode::IsDefault () const
{
return Standard_True;
}
//=======================================================================
//function : VrmlData_Appearance::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_Appearance::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_Appearance) aResult =
Handle(VrmlData_Appearance)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult = new VrmlData_Appearance
(theOther.IsNull() ? Scene() : theOther->Scene(), Name());
if (&aResult->Scene() == &Scene()) {
aResult->SetMaterial (myMaterial);
aResult->SetTexture (myTexture);
aResult->SetTextureTransform (myTTransform);
} else {
// Create a dummy node to pass the different Scene instance to methods Clone
const Handle(VrmlData_UnknownNode) aDummyNode =
new VrmlData_UnknownNode (aResult->Scene());
if (myMaterial.IsNull() == Standard_False)
aResult->SetMaterial (Handle(VrmlData_Material)::DownCast
(myMaterial->Clone (aDummyNode)));
if (myTexture.IsNull() == Standard_False)
aResult->SetTexture(Handle(VrmlData_Texture)::DownCast
(myTexture->Clone (aDummyNode)));
if (myTTransform.IsNull() == Standard_False)
aResult->SetTextureTransform(Handle(VrmlData_TextureTransform)::DownCast
(myTTransform->Clone (aDummyNode)));
}
return aResult;
}
//=======================================================================
//function : VrmlData_Appearance::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Appearance::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "material"))
aStatus = ReadNode (theBuffer, myMaterial,
STANDARD_TYPE(VrmlData_Material));
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "textureTransform"))
aStatus = ReadNode (theBuffer, myTTransform
/*,STANDARD_TYPE(VrmlData_TextureTransform)*/);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "texture"))
aStatus = ReadNode (theBuffer, myTexture,
STANDARD_TYPE(VrmlData_Texture));
else
break;
if (!OK(aStatus))
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
return aStatus;
}
//=======================================================================
//function : VrmlData_Appearance::Write
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_Appearance::Write (const char * thePrefix) const
{
static char header[] = "Appearance {";
VrmlData_ErrorStatus aStatus;
const VrmlData_Scene& aScene = Scene();
if (OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
{
if (myMaterial.IsNull() == Standard_False)
aStatus = aScene.WriteNode ("material", myMaterial);
if (myTexture.IsNull() == Standard_False && OK(aStatus))
aStatus = aScene.WriteNode ("texture", myTexture);
if (myTTransform.IsNull() == Standard_False && OK(aStatus))
aStatus = aScene.WriteNode ("textureTransform", myTTransform);
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_Appearance::IsDefault () const
{
Standard_Boolean aResult (Standard_True);
if (myMaterial.IsNull() == Standard_False)
aResult = myMaterial->IsDefault();
if (aResult == Standard_False)
if (myTexture.IsNull() == Standard_False)
aResult = myTexture->IsDefault();
if (aResult == Standard_False)
if (myTTransform.IsNull() == Standard_False)
aResult = myTTransform->IsDefault();
return aResult;
}
//=======================================================================
//function : VrmlData_ImageTexture
//purpose : Constructor
//=======================================================================
VrmlData_ImageTexture::VrmlData_ImageTexture (const VrmlData_Scene& theScene,
const char * theName,
const char * theURL,
const Standard_Boolean theRepS,
const Standard_Boolean theRepT)
: VrmlData_Texture (theScene, theName, theRepS, theRepT),
myURL (theScene.Allocator())
{
myURL.Append (theURL ? (Standard_CString)theURL : "");
}
//=======================================================================
//function : VrmlData_ImageTexture::Clone
//purpose :
//=======================================================================
Handle(VrmlData_Node) VrmlData_ImageTexture::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_ImageTexture) aResult =
Handle(VrmlData_ImageTexture)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult =
new VrmlData_ImageTexture(theOther.IsNull() ? Scene() : theOther->Scene(),
Name());
aResult->myURL = myURL;
return aResult;
}
//=======================================================================
//function : VrmlData_ImageTexture::Read
//purpose :
//=======================================================================
VrmlData_ErrorStatus VrmlData_ImageTexture::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
Standard_Boolean aRepeatS (Standard_True), aRepeatT (Standard_True);
myURL.Clear();
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "url"))
aStatus = ReadMultiString (theBuffer, myURL);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "repeatS"))
aStatus = ReadBoolean (theBuffer, aRepeatS);
else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "repeatT"))
aStatus = ReadBoolean (theBuffer, aRepeatT);
else
break;
if (!OK(aStatus))
break;
}
if (OK(aStatus) && OK(aStatus, readBrace (theBuffer))) {
SetRepeatS (aRepeatS);
SetRepeatT (aRepeatT);
}
return aStatus;
}

201
src/VrmlData/VrmlData_Node.hxx Executable file
View File

@@ -0,0 +1,201 @@
// File: VrmlData_Node.hxx
// Created: 25.05.06 14:58:45
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Node_HeaderFile
#define VrmlData_Node_HeaderFile
#include <Handle_Standard_Type.hxx>
#include <NCollection_List.hxx>
#include <Standard_DefineHandle.hxx>
#include <Standard_TypeDef.hxx>
#include <TCollection_AsciiString.hxx>
#include <VrmlData_ErrorStatus.hxx>
#define VRMLDATA_LCOMPARE(aa, bb) \
((strncmp (aa, bb, sizeof(bb)-1)) ? 0L : (aa += sizeof(bb)-1))
struct VrmlData_InBuffer;
class VrmlData_Scene;
class gp_XY;
class gp_XYZ;
class Handle_VrmlData_Node;
class TCollection_AsciiString;
/**
* Abstract VRML Node
*/
class VrmlData_Node : public Standard_Transient
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
Standard_EXPORT VrmlData_Node ();
/**
* Destructor
*/
virtual ~VrmlData_Node () {}
/**
* Query the Scene that contains this Node
*/
inline const VrmlData_Scene& Scene () const
{ return * myScene; }
/**
* Query the name
*/
inline const char * Name () const { return myName; }
/**
* Read a complete node definition from VRML stream
* @param theBuffer
* Buffer receiving the input data.
* @param theNode
* <tt>[out]</tt> Node restored from the buffer data
* @param Type
* Node type to be checked. If it is NULL(default) no type checking is done.
* Otherwise the created node is matched and an error is returned if
* no match detected.
*/
Standard_EXPORT VrmlData_ErrorStatus
ReadNode (VrmlData_InBuffer& theBuffer,
Handle(VrmlData_Node)&theNode,
const Handle(Standard_Type)& Type
= NULL);
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer) = 0;
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Returns True if the node is default, then it would not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
/**
* Write the closing brace in the end of a node output.
*/
Standard_EXPORT VrmlData_ErrorStatus
WriteClosing () const;
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.<p>
* This method nullifies the argument node if its member myScene differs
* from that one of the current instance.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)&)const;
/**
* Read one boolean value (TRUE or FALSE).
*/
Standard_EXPORT static VrmlData_ErrorStatus
ReadBoolean (VrmlData_InBuffer& theBuffer,
Standard_Boolean& theResult);
/**
* Read one quoted string, the quotes are removed.
*/
Standard_EXPORT static VrmlData_ErrorStatus
ReadString (VrmlData_InBuffer& theBuffer,
TCollection_AsciiString& theRes);
/**
* Read one quoted string, the quotes are removed.
*/
Standard_EXPORT static VrmlData_ErrorStatus
ReadMultiString
(VrmlData_InBuffer& theBuffer,
NCollection_List<TCollection_AsciiString>& theRes);
/**
* Read one integer value.
*/
Standard_EXPORT static VrmlData_ErrorStatus
ReadInteger (VrmlData_InBuffer& theBuffer,
long& theResult);
static inline Standard_Boolean OK (const VrmlData_ErrorStatus theStat)
{ return theStat == VrmlData_StatusOK; }
static inline Standard_Boolean OK (VrmlData_ErrorStatus& outStat,
const VrmlData_ErrorStatus theStat)
{ return (outStat = theStat) == VrmlData_StatusOK; }
/**
* Define the common Indent in spaces, for writing all nodes.
*/
static inline Standard_Integer GlobalIndent ()
{ return 2; }
protected:
// ---------- PROTECTED METHODS ----------
/**
* Constructor
*/
Standard_EXPORT VrmlData_Node (const VrmlData_Scene& theScene,
const char * theName);
/**
* Read the closing brace. If successful, theBufrfer is incremented.
* If no brace is found, theBuffer stays in untouched and the method returns
* VrmlFormatError.
*/
Standard_EXPORT static VrmlData_ErrorStatus
readBrace (VrmlData_InBuffer& theBuffer);
private:
// ---------- PRIVATE METHODS ----------
/**
* Method called from VrmlData_Scene when a name should be assigned
* automatically.
*/
Standard_EXPORT void setName (const char * theName,
const char * theSuffix = 0L);
private:
// ---------- PRIVATE FIELDS ----------
const VrmlData_Scene * myScene;
const char * myName; ///< name of the node
#ifdef _DEBUG
Standard_Integer myLineCount;
#endif
friend class VrmlData_Group;
friend class VrmlData_Scene;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Node)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Node, Standard_Transient)
Standard_EXPORT Standard_Integer HashCode(const Handle_VrmlData_Node& theNode,
const Standard_Integer theUpper);
Standard_EXPORT Standard_Boolean IsEqual (const Handle(VrmlData_Node)& theOne,
const Handle(VrmlData_Node)& theTwo);
#endif

View File

@@ -0,0 +1,79 @@
// File: VrmlData_Normal.hxx
// Created: 26.05.06 18:34:13
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Normal_HeaderFile
#define VrmlData_Normal_HeaderFile
#include <VrmlData_ArrayVec3d.hxx>
/**
* Implementation of the node Normal
*/
class VrmlData_Normal : public VrmlData_ArrayVec3d
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Normal () {}
/**
* Constructor
*/
inline VrmlData_Normal (const VrmlData_Scene& theScene,
const char * theName,
const size_t nVec = 0,
const gp_XYZ * arrVec = 0L)
: VrmlData_ArrayVec3d (theScene, theName, nVec, arrVec)
{}
/**
* Query one normal
* @param i
* index in the array of normals [0 .. N-1]
* @return
* the normal value for the index. If index irrelevant, returns (0., 0., 0.)
*/
inline const gp_XYZ& Normal (const Standard_Integer i) const
{ return Value(i); }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to the Scene output.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
private:
// ---------- PRIVATE FIELDS ----------
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Normal)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Normal, VrmlData_ArrayVec3d)
#endif

1157
src/VrmlData/VrmlData_Scene.cxx Executable file

File diff suppressed because it is too large Load Diff

395
src/VrmlData/VrmlData_Scene.hxx Executable file
View File

@@ -0,0 +1,395 @@
// File: VrmlData_Scene.hxx
// Created: 08.10.06 18:35:39
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Scene_HeaderFile
#define VrmlData_Scene_HeaderFile
#include <VrmlData_ListOfNode.hxx>
#include <VrmlData_MapOfNode.hxx>
#include <VrmlData_ErrorStatus.hxx>
#include <VrmlData_Geometry.hxx>
#include <VrmlData_WorldInfo.hxx>
#include <TopoDS_Shape.hxx>
#include <Standard_OStream.hxx>
#include <Standard_IStream.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Standard_Mutex.hxx>
struct VrmlData_InBuffer;
class Handle_VrmlData_WorldInfo;
class VrmlData_DataMapOfShapeAppearance;
/**
* Block of comments describing class VrmlData_Scene
*/
class VrmlData_Scene
{
public:
/**
* Iterator type to get all contained Nodes one-by-one.
*/
typedef VrmlData_ListOfNode::Iterator Iterator;
// ---------- PUBLIC METHODS ----------
/**
* Constructor.
*/
Standard_EXPORT VrmlData_Scene (const Handle(NCollection_IncAllocator)& = 0L);
/**
* Query the status of the previous operation.
* Normally it should be equal to VrmlData_StatusOK (no error).
*/
inline VrmlData_ErrorStatus Status () const
{ return myStatus; }
/**
* Add the given directory path to the list of VRML file search directories.
* This method forms the list of directories ordered according to the
* sequence of this method calls. When an Inline node is found, the URLs
* in that node are matched with these directories.
* The last (implicit) search directory is the current process directory
* ("."). It takes effect if the list is empty or if there is no match with
* exisiting directories.
*/
Standard_EXPORT void SetVrmlDir (const TCollection_ExtendedString&);
/**
* Set the scale factor that would be further used in methods
* ReadReal, ReadXYZ and ReadXY. All coordinates, distances and sized are
* multiplied by this factor during reading the data.
*/
inline void SetLinearScale (const Standard_Real theScale)
{ myLinearScale = theScale; }
/**
* Returns the directory iterator, to check the presence of requested VRML
* file in each iterated directory.
*/
inline NCollection_List<TCollection_ExtendedString>::Iterator
VrmlDirIterator () const
{ return NCollection_List<TCollection_ExtendedString>::Iterator(myVrmlDir); }
/**
* Iterator of Nodes
*/
inline Iterator GetIterator () const
{ return Iterator (myLstNodes); }
/**
* Get the iterator of named nodes.
*/
inline VrmlData_MapOfNode::Iterator
NamedNodesIterator() const
{ return myNamedNodes; }
/**
* Allocator used by all nodes contained in the Scene.
*/
inline const Handle(NCollection_IncAllocator)&
Allocator () const
{ return myAllocator; }
/**
* Add a Node. If theN belongs to another Scene, it is cloned.
* <p>VrmlData_WorldInfo cannot be added, in this case the method
* returns a NULL handle.
*/
Standard_EXPORT const Handle(VrmlData_Node)&
AddNode (const Handle(VrmlData_Node)& theN,
const Standard_Boolean isTopLevel
= Standard_True);
/**
* Find a node by its name.
* @param theName
* Name of the node to find.
* @param theType
* Type to match. If this value is NULL, the first found node with the
* given name is returned. If theType is given, only the node that has
* that type is returned.
*/
Standard_EXPORT Handle(VrmlData_Node)
FindNode (const char * theName,
const Handle(Standard_Type)&
theType = 0L) const;
/**
* Find a node by its name.
* @param theName
* Name of the node to search for.
* @param theLocation
* Location of the found node with respect to the whole VRML shape.
*/
Standard_EXPORT Handle(VrmlData_Node)
FindNode(const char * theName,
gp_Trsf& theLocation) const;
/**
* Export to text stream (file or else).
* This method is protected by Mutex, it is not allowed to read/write
* two VRML streams concurrently.
* The stream should give as the first line the VRML header:
* <code>
* #VRML V2.0 <encoding type> [optional comment] <line terminator>
* </code>
*
*/
friend Standard_EXPORT Standard_OStream&
operator << (Standard_OStream& theOutput,
const VrmlData_Scene& theScene);
/**
* Import from text stream (file or else).
* This method is protected by Mutex, it is not allowed to read/write
* two VRML streams concurrently.
*/
Standard_EXPORT VrmlData_Scene& operator<<(Standard_IStream& theInput);
/**
* Convert the scene to a Shape.
*/
Standard_EXPORT operator TopoDS_Shape () const;
/**
* Convert the scene to a Shape, with the information on materials defined
* for each sub-shape. This method should be used instead of TopoDS_Shape
* explicit conversion operator when you need to retrieve the material
* aspect for each face or edge in the returned topological object.
* @param M
* Data Map that binds an Appearance instance to each created TFace or
* TEdge if the Appearance node is defined in VRML scene for that geometry.
* @return
* TopoDS_Shape (Compound) holding all the scene, similar to the result of
* explicit TopoDS_Shape conversion operator.
*/
Standard_EXPORT TopoDS_Shape GetShape (VrmlData_DataMapOfShapeAppearance& M);
/**
* Query the WorldInfo member.
*/
Standard_EXPORT const Handle_VrmlData_WorldInfo&
WorldInfo() const;
/**
* Read a VRML line. Empty lines and comments are skipped.
* The processing starts here from theBuffer.LinePtr; if there is at least
* one non-empty character (neither space nor comment), this line is used
* without reading the next one.
* @param theLine
* Buffer receiving the input line
* @param theInput
* Input stream
* @param theLen
* Length of the input buffer (maximal line length)
*/
Standard_EXPORT static VrmlData_ErrorStatus
ReadLine (VrmlData_InBuffer& theBuffer);
/**
* Read a singel word from the input stream, delimited by whitespace.
*/
Standard_EXPORT static VrmlData_ErrorStatus
ReadWord (VrmlData_InBuffer& theBuffer,
TCollection_AsciiString& theStr);
/**
* Diagnostic dump of the contents
*/
Standard_EXPORT void Dump (Standard_OStream& theStream) const;
/**
* Read one real value.
*/
Standard_EXPORT VrmlData_ErrorStatus
ReadReal (VrmlData_InBuffer& theBuffer,
Standard_Real& theResult,
Standard_Boolean isApplyScale,
Standard_Boolean isOnlyPositive)
const;
/**
* Read one triplet of real values.
*/
Standard_EXPORT VrmlData_ErrorStatus
ReadXYZ (VrmlData_InBuffer& theBuffer,
gp_XYZ& theXYZ,
Standard_Boolean isApplyScale,
Standard_Boolean isOnlyPositive)
const;
/**
* Read one doublet of real values.
*/
Standard_EXPORT VrmlData_ErrorStatus
ReadXY (VrmlData_InBuffer& theBuffer,
gp_XY& theXYZ,
Standard_Boolean isApplyScale,
Standard_Boolean isOnlyPositive)
const;
/**
* Read an array of integer indices, for IndexedfaceSet and IndexedLineSet.
*/
Standard_EXPORT VrmlData_ErrorStatus
ReadArrIndex(VrmlData_InBuffer& theBuffer,
const Standard_Integer **& theArr,
Standard_Size& theNBl)
const;
/**
* Query the line where the error occurred (if the status is not OK)
*/
inline Standard_Integer GetLineError() const { return myLineError; }
/**
* Store the indentation for VRML output.
* @param nSpc
* number of spaces to insert at every indentation level
*/
inline void SetIndent (const Standard_Integer nSpc)
{ myIndent = nSpc; }
/**
* Write a triplet of real values on a separate line.
* @param theXYZ
* The value to be output.
* @param isScale
* If True, then each component is divided by myLinearScale.
* @param thePostfix
* Optional string that is added before the end of the line.
*/
Standard_EXPORT VrmlData_ErrorStatus
WriteXYZ (const gp_XYZ& theXYZ,
const Standard_Boolean isScale,
const char * thePostfix
= 0L) const;
/**
* Write an array of integer indices, for IndexedFaceSet and IndexedLineSet.
*/
Standard_EXPORT VrmlData_ErrorStatus
WriteArrIndex(const char * thePrefix,
const Standard_Integer ** theArr,
const Standard_Size theNbBl)
const;
/**
* Write a string to the output stream respecting the indentation. The string
* can be defined as two substrings that will be separated by a space.
* Each of the substrings can be NULL, then it is ignored. If both
* are NULL, then a single newline is output (without indent).
* @param theLine0
* The first part of string to output
* @param theLine1
* The second part of string to output
* @param theIndent
* - 0 value ignored.
* - negative decreases the current indent and then outputs.
* - positive outputs and then increases the current indent.
* @return
* Error status of the stream, or a special error if myOutput == NULL.
*/
Standard_EXPORT VrmlData_ErrorStatus
WriteLine (const char * theLine0,
const char * theLine1=0L,
const Standard_Integer theIndent
= 0) const;
/**
* Write the given node to output stream 'myOutput'.
*/
Standard_EXPORT VrmlData_ErrorStatus
WriteNode (const char * thePrefix,
const Handle_VrmlData_Node&) const;
/**
* Query if the current write operation is dummy, i.e., for the purpose of
* collecting information before the real write is commenced.
*/
inline Standard_Boolean IsDummyWrite() const
{ return myOutput == 0L; }
private:
// ---------- PRIVATE METHODS (PROHIBITED) ----------
VrmlData_Scene (const VrmlData_Scene&);
VrmlData_Scene& operator = (const VrmlData_Scene&);
protected:
/**
* Read whatever line from the input checking the istream flags.
*/
Standard_EXPORT static VrmlData_ErrorStatus
readLine (VrmlData_InBuffer& theBuffer);
/**
* Read and verify the VRML header (the 1st line of the file)
*/
Standard_EXPORT static VrmlData_ErrorStatus
readHeader (VrmlData_InBuffer& theBuffer);
/**
* Create the node.
* @param theBuffer
* Input buffer from where the node is created
* @param theNode
* Output parameter, contains the created node on exit
* @param Type
* Node type to be checked. If it is NULL no type checking is done.
* Otherwise the created node is matched and an error is returned if
* no match detected.
*/
Standard_EXPORT VrmlData_ErrorStatus
createNode (VrmlData_InBuffer& theBuffer,
Handle(VrmlData_Node)& theNode,
const Handle(Standard_Type)& Type);
/**
* Create a single Shape object from all geometric nodes in the list.
*/
Standard_EXPORT static void createShape (TopoDS_Shape& outShape,
const VrmlData_ListOfNode&,
VrmlData_DataMapOfShapeAppearance*);
private:
// ---------- PRIVATE FIELDS ----------
Standard_Real myLinearScale;
VrmlData_ListOfNode myLstNodes; ///! top-level nodes
VrmlData_ListOfNode myAllNodes; ///! all nodes
VrmlData_ErrorStatus myStatus;
Handle_NCollection_IncAllocator myAllocator;
Handle_VrmlData_WorldInfo myWorldInfo;
VrmlData_MapOfNode myNamedNodes;
// read from stream
NCollection_List<TCollection_ExtendedString> myVrmlDir;
Standard_Mutex myMutex;
Standard_Integer myLineError;///! #0 if error
// write to stream
Standard_OStream * myOutput;
Standard_Integer myIndent;
Standard_Integer myCurrentIndent;
/**
* This map is used to avoid multiple storage of the same named node: each
* named node is added here when it is written the first time.
*/
VrmlData_MapOfNode myNamedNodesOut;
/**
* This map allows to resolve multiple reference to any unnamed node. It
* is used during the dummy write (myOutput == 0L). When a node is processed
* the first time it is added to this map, the second time it is automatically
* assigned a name.
*/
NCollection_Map<Standard_Address> myUnnamedNodesOut;
Standard_Integer myAutoNameCounter;
friend class VrmlData_Group;
friend class VrmlData_Node;
};
#endif

View File

@@ -0,0 +1,568 @@
// File: VrmlData_ShapeConvert.cxx
// Created: 04.08.07 10:09
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#include <VrmlData_ShapeConvert.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_Group.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_IndexedFaceSet.hxx>
#include <VrmlData_IndexedLineSet.hxx>
#include <VrmlData_ShapeNode.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRep_Builder.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Surface.hxx>
#include <NCollection_DataMap.hxx>
#include <Poly_Triangulation.hxx>
#include <Poly_Connect.hxx>
#include <Poly_PolygonOnTriangulation.hxx>
#include <Poly_Polygon3D.hxx>
#include <Precision.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TShort_Array1OfShortReal.hxx>
#include <GeomLib.hxx>
#include <TShort_HArray1OfShortReal.hxx>
//=======================================================================
//function : IsEqual
//purpose : for NCollection_DataMap interface
//=======================================================================
inline Standard_Boolean IsEqual (const TopoDS_Shape& one,
const TopoDS_Shape& two)
{
return one == two;
}
//=======================================================================
//function : AddShape
//purpose :
//=======================================================================
void VrmlData_ShapeConvert::AddShape (const TopoDS_Shape& theShape,
const char * theName)
{
ShapeData aData;/* = { - compilation problem on SUN
TCollection_AsciiString(),
theShape,
NULL
};*/
aData.Shape = theShape;
aData.Node = NULL;
if (theName) {
char buf[2048], * optr = &buf[0];
char * eptr = &buf[sizeof(buf)-1];
for (const char * ptr = theName;; ptr++) {
int sym = *ptr;
if (sym == '\0' || sym == '\n' || sym == '\r') {
* optr = '\0';
break;
}
if (sym == '\"' || sym == '\\')
* optr = '/';
else if (sym == '.')
* optr = '_';
else
* optr = sym;
if (++optr >= eptr) {
*optr = '\0';
break;
}
}
aData.Name = buf;
}
myShapes.Append (aData);
}
//=======================================================================
//function : Convert
//purpose :
//=======================================================================
void VrmlData_ShapeConvert::Convert (const Standard_Boolean theExtractFaces,
const Standard_Boolean theExtractEdges,
const Standard_Real theDeflection,
const Standard_Real theDeflAngle)
{
const Standard_Real aDeflection =
theDeflection < 0.0001 ? 0.0001 : theDeflection;
Standard_Boolean Extract[2] = {theExtractFaces, theExtractEdges};
TopAbs_ShapeEnum ShapeType[2] = {TopAbs_FACE, TopAbs_EDGE};
Standard_Integer i;
const Handle(NCollection_IncAllocator) anAlloc = new NCollection_IncAllocator;
// Relocation map for converted shapes. We should distinguish both TShape
// and Orientation in this map.
NCollection_DataMap <TopoDS_Shape,Handle(VrmlData_Geometry)>
aRelMap (100, anAlloc);
NCollection_List<ShapeData>::Iterator anIter (myShapes);
for (; anIter.More(); anIter.Next()) {
ShapeData& aData = anIter.ChangeValue();
Handle(VrmlData_Group) aGroup =
new VrmlData_Group (myScene, aData.Name.ToCString());
myScene.AddNode (aGroup);
for(i = 0; i < 2; ++i) {
if(!Extract[i]) continue;
TopExp_Explorer anExp (aData.Shape, ShapeType[i]);
for (; anExp.More(); anExp.Next()) {
const TopoDS_Shape& aShape = anExp.Current();
TopLoc_Location aLoc;
Handle(VrmlData_Geometry) aTShapeNode;
const Standard_Boolean isReverse=(aShape.Orientation()==TopAbs_REVERSED);
TopoDS_Shape aTestedShape;
aTestedShape.TShape (aShape.TShape());
aTestedShape.Orientation (isReverse ? TopAbs_REVERSED : TopAbs_FORWARD);
Standard_Boolean isTessellate (Standard_False);
switch (ShapeType[i]) {
case TopAbs_FACE:
{
const TopoDS_Face& aFace = TopoDS::Face (aShape);
if (aFace.IsNull() == Standard_False) {
Handle(Poly_Triangulation) aTri =
BRep_Tool::Triangulation (aFace, aLoc);
if (aRelMap.IsBound (aTestedShape)) {
aTShapeNode = aRelMap(aTestedShape);
break;
}
if (aTri.IsNull())
isTessellate = Standard_True;
// Check the existing deflection
else if (aTri->Deflection() > aDeflection+ Precision::Confusion())
isTessellate = Standard_True;
if (isTessellate) {
// Triangulate the face by the standard OCC mesher
BRepMesh_IncrementalMesh IM (aFace, aDeflection, Standard_False, theDeflAngle);
aTri = BRep_Tool::Triangulation (aFace, aLoc);
}
if (aTri.IsNull() == Standard_False) {
TopoDS_Shape aTestedShapeRev = aTestedShape;
aTestedShapeRev.Orientation (isReverse ?
TopAbs_FORWARD : TopAbs_REVERSED);
Handle(VrmlData_IndexedFaceSet) aFaceSetToReuse;
if (aRelMap.IsBound (aTestedShapeRev))
aFaceSetToReuse = Handle(VrmlData_IndexedFaceSet)::DownCast
(aRelMap(aTestedShapeRev));
Handle(VrmlData_Coordinate) aCoordToReuse;
if (aFaceSetToReuse.IsNull() == Standard_False)
aCoordToReuse = aFaceSetToReuse->Coordinates();
aTShapeNode = triToIndexedFaceSet (aTri, aFace, aCoordToReuse);
myScene.AddNode (aTShapeNode, Standard_False);
// Bind the converted face
aRelMap.Bind (aTestedShape, aTShapeNode);
}
}
}
break;
case TopAbs_WIRE:
{
const TopoDS_Wire& aWire = TopoDS::Wire (aShape);
if (aWire.IsNull() == Standard_False) {
}
}
break;
case TopAbs_EDGE:
{
const TopoDS_Edge& aEdge = TopoDS::Edge (aShape);
if (aEdge.IsNull() == Standard_False) {
Handle(Poly_Polygon3D) aPol = BRep_Tool::Polygon3D (aEdge, aLoc);
if (aRelMap.IsBound (aTestedShape)) {
aTShapeNode = aRelMap(aTestedShape);
break;
}
// Check the presence of reversly oriented Edge. It can also be used
// because we do not distinguish the orientation for edges.
aTestedShape.Orientation (isReverse ?
TopAbs_FORWARD : TopAbs_REVERSED);
if (aRelMap.IsBound (aTestedShape)) {
aTShapeNode = aRelMap(aTestedShape);
break;
}
if (aPol.IsNull())
isTessellate = Standard_True;
// Check the existing deflection
else if (aPol->Deflection() > aDeflection+ Precision::Confusion()
&& BRep_Tool::IsGeometric(aEdge))
isTessellate = Standard_True;
if (isTessellate && BRep_Tool::IsGeometric(aEdge)) {
//try to find PolygonOnTriangulation
Handle(Poly_PolygonOnTriangulation) aPT;
Handle(Poly_Triangulation) aT;
TopLoc_Location aL;
Standard_Boolean found = Standard_False;
for(i = 1; Standard_True; i++) {
BRep_Tool::PolygonOnTriangulation(aEdge, aPT, aT, aL, i);
if(aPT.IsNull() || aT.IsNull()) break;
if(aPT->Deflection() <= aDeflection + Precision::Confusion() &&
aPT->HasParameters()) {
found = Standard_True;
break;
}
}
if(found) {
BRepAdaptor_Curve aCurve(aEdge);
Handle(TColStd_HArray1OfReal) aPrs = aPT->Parameters();
Standard_Integer nbNodes = aPT->NbNodes();
TColgp_Array1OfPnt arrNodes(1, nbNodes);
TColStd_Array1OfReal arrUVNodes(1, nbNodes);
for(i = 1; i <= nbNodes; i++) {
arrUVNodes(i) = aPrs->Value(aPrs->Lower() + i - 1);
arrNodes(i) = aCurve.Value(arrUVNodes(i));
}
aPol = new Poly_Polygon3D(arrNodes, arrUVNodes);
aPol->Deflection (aPT->Deflection());
}
else{
BRepAdaptor_Curve aCurve(aEdge);
const Standard_Real aFirst = aCurve.FirstParameter();
const Standard_Real aLast = aCurve.LastParameter();
GCPnts_TangentialDeflection TD (aCurve, aFirst, aLast,
theDeflAngle, aDeflection, 2);
const Standard_Integer nbNodes = TD.NbPoints();
TColgp_Array1OfPnt arrNodes(1, nbNodes);
TColStd_Array1OfReal arrUVNodes(1, nbNodes);
for (i = 1; i <= nbNodes; i++) {
arrNodes(i) = TD.Value(i);
arrUVNodes(i) = TD.Parameter(i);
}
aPol = new Poly_Polygon3D(arrNodes, arrUVNodes);
aPol->Deflection (aDeflection);
}
BRep_Builder aBld;
aBld.UpdateEdge (aEdge, aPol);
}
aTShapeNode = polToIndexedLineSet (aPol);
myScene.AddNode (aTShapeNode, Standard_False);
// Bind the converted face
aRelMap.Bind (aTestedShape, aTShapeNode);
}
}
break;
}
if (aTShapeNode.IsNull() == Standard_False) {
const Handle(VrmlData_ShapeNode) aShapeNode =
new VrmlData_ShapeNode (myScene, 0L);
aShapeNode->SetAppearance (ShapeType[i] == TopAbs_FACE ?
defaultMaterialFace():defaultMaterialEdge());
myScene.AddNode (aShapeNode, Standard_False);
aShapeNode->SetGeometry (aTShapeNode);
if (aLoc.IsIdentity())
// Store the shape node directly into the main Group.
aGroup->AddNode (aShapeNode);
else {
// Create a Transform grouping node
Handle(VrmlData_Group) aTrans = new VrmlData_Group (myScene, 0L,
Standard_True);
gp_Trsf aTrsf (aLoc);
if (fabs(myScale - 1.) > Precision::Confusion()) {
const gp_XYZ aTransl = aTrsf.TranslationPart() * myScale;
aTrsf.SetTranslationPart (aTransl);
}
aTrans->SetTransform (aTrsf);
myScene.AddNode (aTrans, Standard_False);
aGroup->AddNode (aTrans);
// Store the shape node under the transform.
aTrans->AddNode (aShapeNode);
}
}
}
}
}
myShapes.Clear();
}
//=======================================================================
//function : triToIndexedFaceSet
//purpose :
//=======================================================================
Handle_VrmlData_Geometry VrmlData_ShapeConvert::triToIndexedFaceSet
(const Handle_Poly_Triangulation& theTri,
const TopoDS_Face& theFace,
const Handle_VrmlData_Coordinate& theCoord)
{
Standard_Integer i;
const Standard_Integer nNodes (theTri->NbNodes());
const Standard_Integer nTriangles (theTri->NbTriangles());
const TColgp_Array1OfPnt& arrPolyNodes = theTri->Nodes();
const Poly_Array1OfTriangle& arrTriangles = theTri->Triangles();
const Handle(VrmlData_IndexedFaceSet) aFaceSet =
new VrmlData_IndexedFaceSet (myScene,
0L, // no name
Standard_True, // IsCCW
Standard_False, // IsSolid
Standard_False); // IsConvex
const Handle(NCollection_IncAllocator)& anAlloc = myScene.Allocator();
const Standard_Boolean isReverse = (theFace.Orientation() == TopAbs_REVERSED);
// Create the array of triangles
const Standard_Integer ** arrPolygons = static_cast<const Standard_Integer **>
(anAlloc->Allocate (nTriangles * sizeof(const Standard_Integer *)));
aFaceSet->SetPolygons (nTriangles, arrPolygons);
// Store the triangles
for (i = 0; i < nTriangles; i++) {
Standard_Integer * aPolygon = static_cast<Standard_Integer *>
(anAlloc->Allocate (4*sizeof(Standard_Integer)));
aPolygon[0] = 3;
arrTriangles(i+1).Get (aPolygon[1],aPolygon[2],aPolygon[3]);
aPolygon[1]--;
if (isReverse) {
const Standard_Integer aTmp = aPolygon[2]-1;
aPolygon[2] = aPolygon[3]-1;
aPolygon[3] = aTmp;
} else {
aPolygon[2]--;
aPolygon[3]--;
}
arrPolygons[i] = aPolygon;
}
// Create the Coordinates node
if (theCoord.IsNull() == Standard_False)
aFaceSet->SetCoordinates (theCoord);
else {
gp_XYZ * arrNodes = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
for (i = 0; i < nNodes; i++)
arrNodes[i] = arrPolyNodes(i+1).XYZ() * myScale;
const Handle(VrmlData_Coordinate) aCoordNode =
new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes);
myScene.AddNode (aCoordNode, Standard_False);
aFaceSet->SetCoordinates (aCoordNode);
}
// Create the Normals node if theTri has normals
if(theTri->HasNormals()) {
gp_XYZ * arrVec = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
const TShort_Array1OfShortReal& Norm = theTri->Normals();
Standard_Integer j;
for (i = 0, j = 1; i < nNodes; i++, j += 3) {
gp_XYZ aNormal(Norm(j), Norm(j+1), Norm(j+2));
arrVec[i] = aNormal;
}
const Handle(VrmlData_Normal) aNormalNode =
new VrmlData_Normal (myScene, 0L, nNodes, arrVec);
myScene.AddNode (aNormalNode, Standard_False);
aFaceSet->SetNormals (aNormalNode);
return aFaceSet;
}
Poly_Connect PC(theTri);
// Create the Normals node (if UV- values are available)
TopLoc_Location aLoc;
const Standard_Real aConf2 = Precision::Confusion()*Precision::Confusion();
const Handle(Geom_Surface) aSurface = BRep_Tool::Surface (theFace, aLoc);
if (theTri->HasUVNodes() && aSurface.IsNull() == Standard_False) {
if (aSurface->IsCNu(1) && aSurface->IsCNv(1))
{
Standard_Integer nbNormVal = nNodes * 3;
Handle(TShort_HArray1OfShortReal) Normals =
new TShort_HArray1OfShortReal(1, nbNormVal);
const TColgp_Array1OfPnt2d& arrUV = theTri->UVNodes();
gp_XYZ * arrVec = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
// Compute the normal vectors
Standard_Real Tol = Sqrt(aConf2);
for (i = 0; i < nNodes; i++) {
const gp_Pnt2d& aUV = arrUV(i+1);
gp_Dir aNormal;
if (GeomLib::NormEstim(aSurface, aUV, Tol, aNormal) > 1) {
//Try to estimate as middle normal of adjacent triangles
Standard_Integer n[3];
gp_XYZ eqPlan(0., 0., 0.);
for (PC.Initialize(i+1); PC.More(); PC.Next()) {
arrTriangles(PC.Value()).Get(n[0], n[1], n[2]);
gp_XYZ v1(arrPolyNodes(n[1]).Coord()-arrPolyNodes(n[0]).Coord());
gp_XYZ v2(arrPolyNodes(n[2]).Coord()-arrPolyNodes(n[1]).Coord());
gp_XYZ vv = v1^v2;
Standard_Real mod = vv.Modulus();
if (mod < Tol)
continue;
eqPlan += vv/mod;
}
if (eqPlan.SquareModulus() > gp::Resolution())
aNormal = gp_Dir(eqPlan);
}
if (isReverse)
aNormal.Reverse();
if (aNormal.X()*aNormal.X() < aConf2)
aNormal.SetX(0.);
if (aNormal.Y()*aNormal.Y() < aConf2)
aNormal.SetY(0.);
if (aNormal.Z()*aNormal.Z() < aConf2)
aNormal.SetZ(0.);
arrVec[i] = aNormal.XYZ();
Standard_Integer j = i * 3;
Normals->SetValue(j + 1, aNormal.X());
Normals->SetValue(j + 2, aNormal.Y());
Normals->SetValue(j + 3, aNormal.Z());
}
theTri->SetNormals(Normals);
const Handle(VrmlData_Normal) aNormalNode =
new VrmlData_Normal (myScene, 0L, nNodes, arrVec);
myScene.AddNode (aNormalNode, Standard_False);
aFaceSet->SetNormals (aNormalNode);
}
}
return aFaceSet;
}
//=======================================================================
//function : polToIndexedLineSet
//purpose : single polygon3D => IndexedLineSet
//=======================================================================
Handle_VrmlData_Geometry VrmlData_ShapeConvert::polToIndexedLineSet
(const Handle_Poly_Polygon3D& thePol)
{
Standard_Integer i;
const Standard_Integer nNodes (thePol->NbNodes());
const TColgp_Array1OfPnt& arrPolyNodes = thePol->Nodes();
const Handle(NCollection_IncAllocator)& anAlloc = myScene.Allocator();
const Handle(VrmlData_IndexedLineSet) aLineSet =
new VrmlData_IndexedLineSet (myScene, 0L);
// Create the array of polygons (1 member)
const Standard_Integer ** arrPolygons = static_cast<const Standard_Integer **>
(anAlloc->Allocate (sizeof(const Standard_Integer *)));
aLineSet->SetPolygons (1, arrPolygons);
// Store the polygon
Standard_Integer * aPolygon = static_cast<Standard_Integer *>
(anAlloc->Allocate ((nNodes+1)*sizeof(Standard_Integer)));
aPolygon[0] = nNodes;
for (i = 1; i <= nNodes; i++)
aPolygon[i] = i-1;
arrPolygons[0] = aPolygon;
// Create the Coordinates node
gp_XYZ * arrNodes = static_cast <gp_XYZ *>
(anAlloc->Allocate (nNodes * sizeof(gp_XYZ)));
for (i = 0; i < nNodes; i++)
arrNodes[i] = arrPolyNodes(i+1).XYZ() * myScale;
const Handle(VrmlData_Coordinate) aCoordNode =
new VrmlData_Coordinate (myScene, 0L, nNodes, arrNodes);
myScene.AddNode (aCoordNode, Standard_False);
aLineSet->SetCoordinates (aCoordNode);
return aLineSet;
}
//=======================================================================
//function : defaultMaterialFace
//purpose :
//=======================================================================
Handle(VrmlData_Appearance) VrmlData_ShapeConvert::defaultMaterialFace () const
{
static char aNodeName[] = "__defaultMaterialFace";
Handle(VrmlData_Appearance) anAppearance =
Handle(VrmlData_Appearance)::DownCast(myScene.FindNode(aNodeName));
if (anAppearance.IsNull()) {
const Handle(VrmlData_Material) aMaterial =
new VrmlData_Material (myScene, 0L, 1.0, 0.022, 0.);
aMaterial->SetDiffuseColor (Quantity_Color(0.780392, 0.568627, 0.113725,
Quantity_TOC_RGB));
aMaterial->SetEmissiveColor(Quantity_Color(0.329412, 0.223529, 0.027451,
Quantity_TOC_RGB));
aMaterial->SetSpecularColor(Quantity_Color(0.992157, 0.941176, 0.807843,
Quantity_TOC_RGB));
myScene.AddNode (aMaterial, Standard_False);
anAppearance = new VrmlData_Appearance (myScene, aNodeName);
anAppearance->SetMaterial (aMaterial);
myScene.AddNode (anAppearance, Standard_False);
}
return anAppearance;
}
//=======================================================================
//function : defaultMaterialEdge
//purpose :
//=======================================================================
Handle(VrmlData_Appearance) VrmlData_ShapeConvert::defaultMaterialEdge () const
{
static char aNodeName[] = "__defaultMaterialEdge";
Handle(VrmlData_Appearance) anAppearance =
Handle(VrmlData_Appearance)::DownCast(myScene.FindNode(aNodeName));
if (anAppearance.IsNull()) {
const Handle(VrmlData_Material) aMaterial =
new VrmlData_Material (myScene, 0L, 0.2, 0.2, 0.2);
aMaterial->SetDiffuseColor (Quantity_Color(0.2, 0.7, 0.2,
Quantity_TOC_RGB));
aMaterial->SetEmissiveColor(Quantity_Color(0.2, 0.7, 0.2,
Quantity_TOC_RGB));
aMaterial->SetSpecularColor(Quantity_Color(0.2, 0.7, 0.2,
Quantity_TOC_RGB));
myScene.AddNode (aMaterial, Standard_False);
anAppearance = new VrmlData_Appearance (myScene, aNodeName);
anAppearance->SetMaterial (aMaterial);
myScene.AddNode (anAppearance, Standard_False);
}
return anAppearance;
}

View File

@@ -0,0 +1,102 @@
// File: VrmlData_ShapeConvert.hxx
// Created: 04.08.07 09:48
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#ifndef VrmlData_ShapeConvert_HeaderFile
#define VrmlData_ShapeConvert_HeaderFile
#include <VrmlData_Geometry.hxx>
#include <VrmlData_Appearance.hxx>
#include <NCollection_List.hxx>
#include <TopoDS_Shape.hxx>
class VrmlData_Scene;
class TopoDS_Face;
class Handle_Poly_Triangulation;
class Handle_Poly_Polygon3D;
class Handle_VrmlData_Coordinate;
/**
* Algorithm converting one shape or a set of shapes to VrmlData_Scene.
*/
class VrmlData_ShapeConvert
{
public:
typedef struct {
TCollection_AsciiString Name;
TopoDS_Shape Shape;
Handle(VrmlData_Node) Node;
} ShapeData;
// ---------- PUBLIC METHODS ----------
/**
* Constructor.
* @param theScene
* Scene receiving all Vrml data.
* @param theScale
* Scale factor, considering that VRML standard specifies coordinates in
* meters. So if your data are in mm, you should provide theScale=0.001
*/
inline VrmlData_ShapeConvert (VrmlData_Scene& theScene,
const Standard_Real theScale = 1.)
: myScene (theScene),
myScale (theScale)
{}
/**
* Add one shape to the internal list, may be called several times with
* different shapes.
*/
Standard_EXPORT void AddShape (const TopoDS_Shape& theShape,
const char * theName = 0L);
/**
* Convert all accumulated shapes and store them in myScene.
* The internal data structures are cleared in the end of convertion.
* @param theExtractFaces
* If True, converter extracst faces from the shapes.
* @param theExtractEdges
* If True, converter extracts edges from the shapes.
* @param theDeflection
* Deflection for tessellation of geometrical lines/surfaces. Existing mesh
* is used if its deflection is smaller than the one given by this
* parameter.
* @param theDeflAngle
* Angular deflection for tessellation of geometrical lines.
*/
Standard_EXPORT void Convert (const Standard_Boolean theExtractFaces,
const Standard_Boolean theExtractEdges,
const Standard_Real theDeflection = 0.01,
const Standard_Real theDeflAngle = 20.*PI/180.);
//this value of theDeflAngle is used by default
//for tesselation while shading (Drawer->HLRAngle())
protected:
// ---------- PROTECTED METHODS ----------
Handle_VrmlData_Geometry triToIndexedFaceSet
(const Handle_Poly_Triangulation&,
const TopoDS_Face&,
const Handle_VrmlData_Coordinate&);
Handle_VrmlData_Geometry polToIndexedLineSet
(const Handle_Poly_Polygon3D&);
Handle_VrmlData_Appearance defaultMaterialFace () const;
Handle_VrmlData_Appearance defaultMaterialEdge () const;
private:
// ---------- PRIVATE FIELDS ----------
VrmlData_Scene& myScene;
Standard_Real myScale;
NCollection_List <ShapeData> myShapes;
};
#endif

View File

@@ -0,0 +1,103 @@
// File: VrmlData_ShapeNode.hxx
// Created: 25.05.06 15:12:12
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_ShapeNode_HeaderFile
#define VrmlData_ShapeNode_HeaderFile
#include <VrmlData_Appearance.hxx>
#include <VrmlData_Geometry.hxx>
/**
* Implementation of the Shape node type
*/
class VrmlData_ShapeNode : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_ShapeNode () {}
/**
* Constructor
*/
inline VrmlData_ShapeNode (const VrmlData_Scene& theScene,
const char * theName)
: VrmlData_Node (theScene, theName) {}
/**
* Query the Appearance.
*/
inline const Handle(VrmlData_Appearance)&
Appearance () const { return myAppearance; }
/**
* Query the Geometry.
*/
inline const Handle(VrmlData_Geometry)&
Geometry () const { return myGeometry; }
/**
* Set the Appearance
*/
inline void SetAppearance (const Handle(VrmlData_Appearance)& theAppear)
{ myAppearance = theAppear; }
/**
* Set the Geometry
*/
inline void SetGeometry (const Handle(VrmlData_Geometry)& theGeometry)
{ myGeometry = theGeometry; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Fill the Node internal data from the given input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Check if the Shape Node is writeable.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
Handle(VrmlData_Appearance) myAppearance;
Handle(VrmlData_Geometry) myGeometry;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_ShapeNode)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_ShapeNode, VrmlData_Node)
#endif

View File

@@ -0,0 +1,88 @@
// File: VrmlData_Sphere.hxx
// Created: 26.05.06 22:05:53
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Sphere_HeaderFile
#define VrmlData_Sphere_HeaderFile
#include <VrmlData_Geometry.hxx>
/**
* Implementation of the Sphere node.
*/
class VrmlData_Sphere : public VrmlData_Geometry
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Sphere ()
: myRadius (1.)
{}
/**
* Constructor
*/
inline VrmlData_Sphere (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Real theRadius = 1.)
: VrmlData_Geometry (theScene, theName),
myRadius (theRadius)
{}
/**
* Query the sphere radius
*/
inline Standard_Real Radius () const { return myRadius; }
/**
* Set the spere radius
*/
inline void SetRadius (const Standard_Real theRadius)
{ myRadius = theRadius; SetModified(); }
/**
* Query the primitive topology. This method returns a Null shape if there
* is an internal error during the primitive creation (zero radius, etc.)
*/
Standard_EXPORT virtual const Handle(TopoDS_TShape)& TShape ();
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Fill the Node internal data from the given input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to output stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
private:
// ---------- PRIVATE FIELDS ----------
Standard_Real myRadius;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Sphere)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Sphere, VrmlData_Geometry)
#endif

View File

@@ -0,0 +1,84 @@
// File: VrmlData_Texture.hxx
// Created: 25.05.06 15:59:43
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_Texture_HeaderFile
#define VrmlData_Texture_HeaderFile
#include <VrmlData_Node.hxx>
/**
* Implementation of the Texture node
*/
class VrmlData_Texture : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_Texture ()
: myRepeatS (Standard_False),
myRepeatT (Standard_False)
{}
/**
* Constructor
*/
inline VrmlData_Texture (const VrmlData_Scene& theScene,
const char * theName,
const Standard_Boolean theRepeatS = Standard_False,
const Standard_Boolean theRepeatT = Standard_False)
: VrmlData_Node (theScene, theName),
myRepeatS (theRepeatS),
myRepeatT (theRepeatT)
{}
/**
* Query the RepeatS value
*/
inline Standard_Boolean
RepeatS () const { return myRepeatS; }
/**
* Query the RepeatT value
*/
inline Standard_Boolean
RepeatT () const { return myRepeatT; }
/**
* Set the RepeatS flag
*/
inline void SetRepeatS (const Standard_Boolean theFlag)
{ myRepeatS = theFlag; }
/**
* Set the RepeatT flag
*/
inline void SetRepeatT (const Standard_Boolean theFlag)
{ myRepeatT = theFlag; }
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
Standard_Boolean myRepeatS;
Standard_Boolean myRepeatT;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_Texture)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_Texture, VrmlData_Node)
#endif

View File

@@ -0,0 +1,93 @@
// File: VrmlData_TextureCoordinate.hxx
// Created: 26.05.06 18:44:47
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_TextureCoordinate_HeaderFile
#define VrmlData_TextureCoordinate_HeaderFile
#include <VrmlData_Node.hxx>
class gp_XY;
/**
* Implementation of the node TextureCoordinate
*/
class VrmlData_TextureCoordinate : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_TextureCoordinate ()
: myPoints (0L), myLength (0) {}
/**
* Constructor
*/
inline VrmlData_TextureCoordinate (const VrmlData_Scene& theScene,
const char * theName,
const size_t nPoints = 0,
const gp_XY * arrPoints = 0L)
: VrmlData_Node (theScene, theName),
myPoints (arrPoints),
myLength (nPoints)
{}
/**
* Create a data array and assign the field myArray.
* @return
* True if allocation was successful.
*/
Standard_EXPORT Standard_Boolean
AllocateValues (const Standard_Size theLength);
/**
* Query the number of points
*/
inline size_t Length () { return myLength; }
/**
* Query the points
*/
inline const gp_XY * Points () { return myPoints; }
/**
* Set the points array
*/
inline void SetPoints (const size_t nPoints,
const gp_XY * arrPoints)
{ myPoints = arrPoints; myLength = nPoints; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther)const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
private:
// ---------- PRIVATE FIELDS ----------
const gp_XY * myPoints;
size_t myLength;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_TextureCoordinate)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_TextureCoordinate, VrmlData_Node)
#endif

View File

@@ -0,0 +1,97 @@
// File: VrmlData_TextureTransform.hxx
// Created: 25.05.06 16:25:17
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_TextureTransform_HeaderFile
#define VrmlData_TextureTransform_HeaderFile
#include <VrmlData_Node.hxx>
#include <gp_XY.hxx>
/// Implementation of the TextureTransform node
//
class VrmlData_TextureTransform : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty constructor
*/
inline VrmlData_TextureTransform () {}
/**
* Constructor
*/
inline VrmlData_TextureTransform (const VrmlData_Scene& theScene,
const char * theName)
: VrmlData_Node (theScene, theName)
{}
/**
* Query the Center
*/
inline const gp_XY& Center () const { return myCenter; }
/**
* Query the Rotation
*/
inline Standard_Real Rotation () const { return myRotation; }
/**
* Query the Scale
*/
inline const gp_XY& Scale () const { return myScale; }
/**
* Query the Translation
*/
inline const gp_XY& Translation () const { return myTranslation; }
/**
* Set the Center
*/
inline void SetCenter (const gp_XY& V) { myCenter = V; }
/**
* Set the Rotation
*/
inline void SetRotation (const Standard_Real V)
{ myRotation = V; }
/**
* Set the Scale
*/
inline void SetScale (const gp_XY& V) { myScale = V; }
/**
* Set the Translation
*/
inline void SetTranslation (const gp_XY& V) { myTranslation = V; }
protected:
// ---------- PROTECTED METHODS ----------
private:
// ---------- PRIVATE FIELDS ----------
gp_XY myCenter;
Standard_Real myRotation;
gp_XY myScale;
gp_XY myTranslation;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_TextureTransform)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_TextureTransform, VrmlData_Node)
#endif

View File

@@ -0,0 +1,70 @@
// File: VrmlData_UnknownNode.hxx
// Created: 08.10.06 20:23:25
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2006
#ifndef VrmlData_UnknownNode_HeaderFile
#define VrmlData_UnknownNode_HeaderFile
#include <VrmlData_Node.hxx>
#include <TCollection_AsciiString.hxx>
/**
* Definition of UnknownNode -- placeholder for node types that
* are not processed now.
*/
class VrmlData_UnknownNode : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty Constructor.
*/
inline VrmlData_UnknownNode () {}
/**
* Constructor.
*/
inline VrmlData_UnknownNode (const VrmlData_Scene& theScene,
const char * theName = 0L,
const char * theTitle= 0L)
: VrmlData_Node (theScene, theName)
{ if (theTitle) myTitle = (Standard_CString)theTitle; }
/**
* Read the unknown node, till the last closing brace of it.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Query the title of the unknown node.
*/
inline const TCollection_AsciiString&
GetTitle () const
{ return myTitle; }
/**
* Check if the Node is non-writeable -- always returns true.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault () const;
private:
// ---------- PRIVATE FIELDS ----------
TCollection_AsciiString myTitle;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_UnknownNode)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_UnknownNode, VrmlData_Node)
#endif

View File

@@ -0,0 +1,175 @@
// File: VrmlData_WorldInfo.cxx
// Created: 01.08.07 08:21
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#include <VrmlData_WorldInfo.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_InBuffer.hxx>
#ifdef WNT
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable:4996)
#endif
IMPLEMENT_STANDARD_HANDLE (VrmlData_WorldInfo, VrmlData_Node)
IMPLEMENT_STANDARD_RTTIEXT (VrmlData_WorldInfo, VrmlData_Node)
//=======================================================================
//function : VrmlData_WorldInfo::VrmlData_WorldInfo
//purpose : Constructor
//=======================================================================
VrmlData_WorldInfo::VrmlData_WorldInfo (const VrmlData_Scene& theScene,
const char * theName,
const char * theTitle)
: VrmlData_Node (theScene, theName),
myInfo (theScene.Allocator())
{
SetTitle (theTitle);
}
//=======================================================================
//function : SetTitle
//purpose : Set or modify the title.
//=======================================================================
void VrmlData_WorldInfo::SetTitle (const char * theString)
{
if (theString == 0L)
myTitle = 0L;
else {
const size_t len = strlen (theString) + 1;
if (len == 1)
myTitle = 0L;
else {
myTitle = static_cast <const char *>(Scene().Allocator()->Allocate(len));
memcpy (const_cast<char *> (myTitle), theString, len);
}
}
}
//=======================================================================
//function : AddInfo
//purpose : Add a string to the list of info strings.
//=======================================================================
void VrmlData_WorldInfo::AddInfo (const char * theString)
{
if (theString != 0L)
if (* theString != '\0') {
const size_t len = strlen (theString) + 1;
char * aStr = static_cast <char *>(Scene().Allocator()->Allocate(len));
memcpy (aStr, theString, len);
myInfo.Append (aStr);
}
}
//=======================================================================
//function : Clone
//purpose : Create a copy of this node
//=======================================================================
Handle(VrmlData_Node) VrmlData_WorldInfo::Clone
(const Handle(VrmlData_Node)& theOther) const
{
Handle(VrmlData_WorldInfo) aResult =
Handle(VrmlData_WorldInfo)::DownCast (VrmlData_Node::Clone(theOther));
if (aResult.IsNull())
aResult =
new VrmlData_WorldInfo (theOther.IsNull() ? Scene() : theOther->Scene(),
Name());
if (&aResult->Scene() == &Scene()) {
aResult->myTitle = myTitle;
aResult->myInfo = myInfo;
} else {
aResult->SetTitle (myTitle);
NCollection_List <const char *>::Iterator anIter (myInfo);
for (; anIter.More(); anIter.Next())
aResult->AddInfo (anIter.Value());
}
return aResult;
}
//=======================================================================
//function : Read
//purpose : Read the Node from input stream.
//=======================================================================
VrmlData_ErrorStatus VrmlData_WorldInfo::Read (VrmlData_InBuffer& theBuffer)
{
VrmlData_ErrorStatus aStatus;
while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "title")) {
TCollection_AsciiString aTitleString;
if (OK (aStatus, ReadString (theBuffer, aTitleString)))
SetTitle (aTitleString.ToCString());
} else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "info")) {
NCollection_List<TCollection_AsciiString> lstInfo;
if (OK (aStatus, ReadMultiString (theBuffer, lstInfo))) {
NCollection_List<TCollection_AsciiString>::Iterator anIter (lstInfo);
for (; anIter.More(); anIter.Next())
AddInfo (anIter.Value().ToCString());
}
} else
break;
}
// Read the terminating (closing) brace
if (OK(aStatus))
aStatus = readBrace (theBuffer);
return aStatus;
}
//=======================================================================
//function : Write
//purpose : Write the Node to the Scene output.
//=======================================================================
VrmlData_ErrorStatus VrmlData_WorldInfo::Write (const char * thePrefix) const
{
VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
const VrmlData_Scene& aScene = Scene();
static char header[] = "WorldInfo {";
if (aScene.IsDummyWrite() == Standard_False &&
OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
{
char buf[4096];
if (myTitle) {
sprintf (buf, "title \"%s\"", myTitle);
aStatus = aScene.WriteLine (buf);
}
if (myInfo.IsEmpty() == Standard_False && OK(aStatus)) {
if (OK (aStatus, aScene.WriteLine ("info [", 0L, GlobalIndent()))) {
NCollection_List<const char *>::Iterator anIter (myInfo);
while (anIter.More()) {
sprintf (buf, "\"%s\"", anIter.Value());
anIter.Next();
if (anIter.More())
aStatus = aScene.WriteLine (buf, ",");
else
aStatus = aScene.WriteLine (buf);
}
}
aStatus = aScene.WriteLine ("]", 0L, -GlobalIndent());
}
aStatus = WriteClosing();
}
return aStatus;
}
//=======================================================================
//function : IsDefault
//purpose :
//=======================================================================
Standard_Boolean VrmlData_WorldInfo::IsDefault() const
{
return (myTitle == 0L && myInfo.IsEmpty());
}

View File

@@ -0,0 +1,97 @@
// File: VrmlData_WorldInfo.hxx
// Created: 01.08.07 07:24
// Author: Alexander GRIGORIEV
// Copyright: Open Cascade 2007
#ifndef VrmlData_WorldInfo_HeaderFile
#define VrmlData_WorldInfo_HeaderFile
#include <VrmlData_Node.hxx>
/**
* Data type for WorldInfo node
*/
class VrmlData_WorldInfo : public VrmlData_Node
{
public:
// ---------- PUBLIC METHODS ----------
/**
* Empty Constructor.
*/
inline VrmlData_WorldInfo () : myTitle (0L) {}
/**
* Constructor.
*/
Standard_EXPORT VrmlData_WorldInfo (const VrmlData_Scene& theScene,
const char * theName = 0L,
const char * theTitle = 0L);
/**
* Set or modify the title.
*/
Standard_EXPORT void SetTitle (const char * theString);
/**
* Add a string to the list of info strings.
*/
Standard_EXPORT void AddInfo (const char * theString);
/**
* Query the title string.
*/
inline const char * Title () const
{ return myTitle; }
/**
* Return the iterator of Info strings.
*/
inline NCollection_List <const char *>::Iterator
InfoIterator () const
{ return myInfo; }
/**
* Create a copy of this node.
* If the parameter is null, a new copied node is created. Otherwise new node
* is not created, but rather the given one is modified.
*/
Standard_EXPORT virtual Handle(VrmlData_Node)
Clone (const Handle(VrmlData_Node)& theOther) const;
/**
* Read the Node from input stream.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Read (VrmlData_InBuffer& theBuffer);
/**
* Write the Node to the Scene output.
*/
Standard_EXPORT virtual VrmlData_ErrorStatus
Write (const char * thePrefix) const;
/**
* Returns True if the node is default, then it would not be written.
*/
Standard_EXPORT virtual Standard_Boolean
IsDefault() const;
private:
// ---------- PRIVATE FIELDS ----------
const char * myTitle;
NCollection_List <const char *> myInfo;
public:
// Declaration of CASCADE RTTI
DEFINE_STANDARD_RTTI (VrmlData_WorldInfo)
};
// Definition of HANDLE object using Standard_DefineHandle.hxx
DEFINE_STANDARD_HANDLE (VrmlData_WorldInfo, VrmlData_Node)
#endif