| 1 | // Created on: 2004-05-11 |
| 2 | // Created by: Sergey ZARITCHNY <szy@opencascade.com> |
| 3 | // Copyright (c) 2004-2014 OPEN CASCADE SAS |
| 4 | // |
| 5 | // This file is part of Open CASCADE Technology software library. |
| 6 | // |
| 7 | // This library is free software; you can redistribute it and/or modify it under |
| 8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 9 | // by the Free Software Foundation, with special exception defined in the file |
| 10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 11 | // distribution for complete text of the license and disclaimer of any warranty. |
| 12 | // |
| 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 14 | // commercial license or contractual agreement. |
| 15 | |
| 16 | #ifndef _BinTools_ShapeSet_HeaderFile |
| 17 | #define _BinTools_ShapeSet_HeaderFile |
| 18 | |
| 19 | #include <Standard.hxx> |
| 20 | #include <Standard_DefineAlloc.hxx> |
| 21 | #include <Standard_Handle.hxx> |
| 22 | |
| 23 | #include <TopTools_IndexedMapOfShape.hxx> |
| 24 | #include <BinTools_LocationSet.hxx> |
| 25 | #include <Standard_Integer.hxx> |
| 26 | #include <BRep_Builder.hxx> |
| 27 | #include <BinTools_SurfaceSet.hxx> |
| 28 | #include <BinTools_CurveSet.hxx> |
| 29 | #include <BinTools_Curve2dSet.hxx> |
| 30 | #include <TColStd_IndexedMapOfTransient.hxx> |
| 31 | #include <Standard_Boolean.hxx> |
| 32 | #include <Standard_OStream.hxx> |
| 33 | #include <Standard_IStream.hxx> |
| 34 | #include <TopAbs_ShapeEnum.hxx> |
| 35 | class TopoDS_Shape; |
| 36 | class BinTools_LocationSet; |
| 37 | |
| 38 | |
| 39 | //! Writes topology in OStream in binary format |
| 40 | class BinTools_ShapeSet |
| 41 | { |
| 42 | public: |
| 43 | |
| 44 | DEFINE_STANDARD_ALLOC |
| 45 | |
| 46 | |
| 47 | //! Builds an empty ShapeSet. |
| 48 | //! Parameter <isWithTriangles> is added for XML Persistence |
| 49 | Standard_EXPORT BinTools_ShapeSet(const Standard_Boolean isWithTriangles = Standard_False); |
| 50 | |
| 51 | Standard_EXPORT virtual ~BinTools_ShapeSet(); |
| 52 | |
| 53 | //! Return true if shape should be stored with triangles. |
| 54 | Standard_Boolean IsWithTriangles() const { return myWithTriangles; } |
| 55 | |
| 56 | //! Define if shape will be stored with triangles. |
| 57 | //! Ignored (always written) if face defines only triangulation (no surface). |
| 58 | void SetWithTriangles (const Standard_Boolean isWithTriangles) { myWithTriangles = isWithTriangles; } |
| 59 | |
| 60 | Standard_EXPORT void SetFormatNb (const Standard_Integer theFormatNb); |
| 61 | |
| 62 | //! two formats available for the moment: |
| 63 | //! First: does not write CurveOnSurface UV Points into the file |
| 64 | //! on reading calls Check() method. |
| 65 | //! Second: stores CurveOnSurface UV Points. |
| 66 | //! On reading format is recognized from Version string. |
| 67 | Standard_EXPORT Standard_Integer FormatNb() const; |
| 68 | |
| 69 | //! Clears the content of the set. |
| 70 | Standard_EXPORT virtual void Clear(); |
| 71 | |
| 72 | //! Stores <S> and its sub-shape. Returns the index of <S>. |
| 73 | //! The method AddGeometry is called on each sub-shape. |
| 74 | Standard_EXPORT Standard_Integer Add (const TopoDS_Shape& S); |
| 75 | |
| 76 | //! Returns the sub-shape of index <I>. |
| 77 | Standard_EXPORT const TopoDS_Shape& Shape (const Standard_Integer I) const; |
| 78 | |
| 79 | //! Returns the index of <S>. |
| 80 | Standard_EXPORT Standard_Integer Index (const TopoDS_Shape& S) const; |
| 81 | |
| 82 | Standard_EXPORT const BinTools_LocationSet& Locations() const; |
| 83 | |
| 84 | Standard_EXPORT BinTools_LocationSet& ChangeLocations(); |
| 85 | |
| 86 | //! Returns number of shapes read from file. |
| 87 | Standard_EXPORT Standard_Integer NbShapes() const; |
| 88 | |
| 89 | //! Writes the content of me on the stream <OS> in binary |
| 90 | //! format that can be read back by Read. |
| 91 | //! |
| 92 | //! Writes the locations. |
| 93 | //! |
| 94 | //! Writes the geometry calling WriteGeometry. |
| 95 | //! |
| 96 | //! Dumps the shapes from last to first. |
| 97 | //! For each shape : |
| 98 | //! Write the type. |
| 99 | //! calls WriteGeometry(S). |
| 100 | //! Write the flags, the subshapes. |
| 101 | Standard_EXPORT virtual void Write (Standard_OStream& OS) const; |
| 102 | |
| 103 | //! Reads the content of me from the binary stream <IS>. me |
| 104 | //! is first cleared. |
| 105 | //! |
| 106 | //! Reads the locations. |
| 107 | //! |
| 108 | //! Reads the geometry calling ReadGeometry. |
| 109 | //! |
| 110 | //! Reads the shapes. |
| 111 | //! For each shape |
| 112 | //! Reads the type. |
| 113 | //! calls ReadGeometry(T,S). |
| 114 | //! Reads the flag, the subshapes. |
| 115 | Standard_EXPORT virtual void Read (Standard_IStream& IS); |
| 116 | |
| 117 | //! Writes on <OS> the shape <S>. Writes the |
| 118 | //! orientation, the index of the TShape and the index |
| 119 | //! of the Location. |
| 120 | Standard_EXPORT virtual void Write (const TopoDS_Shape& S, Standard_OStream& OS) const; |
| 121 | |
| 122 | //! Writes the geometry of me on the stream <OS> in a |
| 123 | //! binary format that can be read back by Read. |
| 124 | Standard_EXPORT virtual void WriteGeometry (Standard_OStream& OS) const; |
| 125 | |
| 126 | //! Reads the geometry of me from the stream <IS>. |
| 127 | Standard_EXPORT virtual void ReadGeometry (Standard_IStream& IS); |
| 128 | |
| 129 | //! Reads from <IS> a shape and returns it in S. |
| 130 | //! <NbShapes> is the number of tshapes in the set. |
| 131 | Standard_EXPORT virtual void Read (TopoDS_Shape& S, Standard_IStream& IS, const Standard_Integer NbShapes) const; |
| 132 | |
| 133 | //! Writes the geometry of <S> on the stream <OS> in a |
| 134 | //! binary format that can be read back by Read. |
| 135 | Standard_EXPORT virtual void WriteGeometry (const TopoDS_Shape& S, Standard_OStream& OS) const; |
| 136 | |
| 137 | //! Reads the geometry of a shape of type <T> from the |
| 138 | //! stream <IS> and returns it in <S>. |
| 139 | Standard_EXPORT virtual void ReadGeometry (const TopAbs_ShapeEnum T, Standard_IStream& IS, TopoDS_Shape& S); |
| 140 | |
| 141 | //! Stores the goemetry of <S>. |
| 142 | Standard_EXPORT virtual void AddGeometry (const TopoDS_Shape& S); |
| 143 | |
| 144 | //! Inserts the shape <S2> in the shape <S1>. |
| 145 | Standard_EXPORT virtual void AddShapes (TopoDS_Shape& S1, const TopoDS_Shape& S2); |
| 146 | |
| 147 | //! Reads the 3d polygons of me |
| 148 | //! from the stream <IS>. |
| 149 | Standard_EXPORT void ReadPolygon3D (Standard_IStream& IS); |
| 150 | |
| 151 | //! Writes the 3d polygons |
| 152 | //! on the stream <OS> in a format that can |
| 153 | //! be read back by Read. |
| 154 | Standard_EXPORT void WritePolygon3D (Standard_OStream& OS) const; |
| 155 | |
| 156 | //! Reads the triangulation of me |
| 157 | //! from the stream <IS>. |
| 158 | Standard_EXPORT void ReadTriangulation (Standard_IStream& IS); |
| 159 | |
| 160 | //! Writes the triangulation |
| 161 | //! on the stream <OS> in a format that can |
| 162 | //! be read back by Read. |
| 163 | Standard_EXPORT void WriteTriangulation (Standard_OStream& OS) const; |
| 164 | |
| 165 | //! Reads the polygons on triangulation of me |
| 166 | //! from the stream <IS>. |
| 167 | Standard_EXPORT void ReadPolygonOnTriangulation (Standard_IStream& IS); |
| 168 | |
| 169 | //! Writes the polygons on triangulation |
| 170 | //! on the stream <OS> in a format that can |
| 171 | //! be read back by Read. |
| 172 | Standard_EXPORT void WritePolygonOnTriangulation (Standard_OStream& OS) const; |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | protected: |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | private: |
| 184 | |
| 185 | |
| 186 | |
| 187 | TopTools_IndexedMapOfShape myShapes; |
| 188 | BinTools_LocationSet myLocations; |
| 189 | Standard_Integer myFormatNb; |
| 190 | BRep_Builder myBuilder; |
| 191 | BinTools_SurfaceSet mySurfaces; |
| 192 | BinTools_CurveSet myCurves; |
| 193 | BinTools_Curve2dSet myCurves2d; |
| 194 | TColStd_IndexedMapOfTransient myPolygons2D; |
| 195 | TColStd_IndexedMapOfTransient myPolygons3D; |
| 196 | TColStd_IndexedMapOfTransient myTriangulations; |
| 197 | TColStd_IndexedMapOfTransient myNodes; |
| 198 | Standard_Boolean myWithTriangles; |
| 199 | |
| 200 | |
| 201 | }; |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | #endif // _BinTools_ShapeSet_HeaderFile |