Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-01 08:59:55

0001 // Created on: 2004-05-11
0002 // Created by: Sergey ZARITCHNY <szy@opencascade.com>
0003 // Copyright (c) 2004-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _BinTools_ShapeSet_HeaderFile
0017 #define _BinTools_ShapeSet_HeaderFile
0018 
0019 #include <BinTools_ShapeSetBase.hxx>
0020 
0021 #include <TopTools_ShapeMapHasher.hxx>
0022 #include <NCollection_IndexedMap.hxx>
0023 #include <BinTools_LocationSet.hxx>
0024 #include <BRep_Builder.hxx>
0025 #include <BinTools_SurfaceSet.hxx>
0026 #include <BinTools_CurveSet.hxx>
0027 #include <BinTools_Curve2dSet.hxx>
0028 #include <Standard_Transient.hxx>
0029 #include <Standard_OStream.hxx>
0030 #include <Standard_IStream.hxx>
0031 
0032 //! Writes topology in OStream in binary format
0033 class BinTools_ShapeSet : public BinTools_ShapeSetBase
0034 {
0035 public:
0036   DEFINE_STANDARD_ALLOC
0037 
0038   //! Builds an empty ShapeSet.
0039   //! @param[in] theWithTriangles  flag to write triangulation data
0040   Standard_EXPORT BinTools_ShapeSet();
0041 
0042   Standard_EXPORT ~BinTools_ShapeSet() override;
0043 
0044   //! Clears the content of the set.
0045   Standard_EXPORT void Clear() override;
0046 
0047   //! Stores <S> and its sub-shape. Returns the index of <S>.
0048   //! The method AddGeometry is called on each sub-shape.
0049   Standard_EXPORT int Add(const TopoDS_Shape& S);
0050 
0051   //! Returns the sub-shape of index <I>.
0052   Standard_EXPORT const TopoDS_Shape& Shape(const int I);
0053 
0054   //! Returns the index of <S>.
0055   Standard_EXPORT int Index(const TopoDS_Shape& S) const;
0056 
0057   Standard_EXPORT const BinTools_LocationSet& Locations() const;
0058 
0059   Standard_EXPORT BinTools_LocationSet& ChangeLocations();
0060 
0061   //! Returns number of shapes read from file.
0062   Standard_EXPORT int NbShapes() const;
0063 
0064   //! Writes the content of me on the stream <OS> in binary
0065   //! format that can be read back by Read.
0066   //!
0067   //! Writes the locations.
0068   //!
0069   //! Writes the geometry calling WriteGeometry.
0070   //!
0071   //! Dumps the shapes from last to first.
0072   //! For each shape:
0073   //! Write the type.
0074   //! calls WriteGeometry(S).
0075   //! Write the flags, the subshapes.
0076   Standard_EXPORT void Write(
0077     Standard_OStream&            OS,
0078     const Message_ProgressRange& theRange = Message_ProgressRange()) override;
0079 
0080   //! Reads the content of me from the binary stream <IS>. me
0081   //! is first cleared.
0082   //!
0083   //! Reads the locations.
0084   //!
0085   //! Reads the geometry calling ReadGeometry.
0086   //!
0087   //! Reads the shapes.
0088   //! For each shape
0089   //! Reads the type.
0090   //! calls ReadGeometry(T,S).
0091   //! Reads the flag, the subshapes.
0092   Standard_EXPORT void Read(
0093     Standard_IStream&            IS,
0094     const Message_ProgressRange& theRange = Message_ProgressRange()) override;
0095 
0096   //! Writes on <OS> the shape <S>. Writes the
0097   //! orientation, the index of the TShape and the index
0098   //! of the Location.
0099   Standard_EXPORT void Write(const TopoDS_Shape& S, Standard_OStream& OS) override;
0100 
0101   //! Writes the geometry of me on the stream <OS> in a
0102   //! binary format that can be read back by Read.
0103   Standard_EXPORT virtual void WriteGeometry(
0104     Standard_OStream&            OS,
0105     const Message_ProgressRange& theRange = Message_ProgressRange()) const;
0106 
0107   //! Reads the geometry of me from the stream <IS>.
0108   Standard_EXPORT virtual void ReadGeometry(
0109     Standard_IStream&            IS,
0110     const Message_ProgressRange& theRange = Message_ProgressRange());
0111 
0112   //! Reads from <IS> a shape flags and sub-shapes and modifies S.
0113   Standard_EXPORT virtual void ReadFlagsAndSubs(TopoDS_Shape&          S,
0114                                                 const TopAbs_ShapeEnum T,
0115                                                 Standard_IStream&      IS,
0116                                                 const int              NbShapes);
0117 
0118   //! Reads from <IS> a shape and returns it in S.
0119   //! <NbShapes> is the number of tshapes in the set.
0120   Standard_EXPORT virtual void ReadSubs(TopoDS_Shape& S, Standard_IStream& IS, const int NbShapes);
0121 
0122   //! An empty virtual method for redefinition in shape-reader.
0123   Standard_EXPORT void Read(Standard_IStream& /*theStream*/, TopoDS_Shape& /*theShape*/) override {
0124   };
0125 
0126   //! Writes the shape <S> on the stream <OS> in a
0127   //! binary format that can be read back by Read.
0128   Standard_EXPORT virtual void WriteShape(const TopoDS_Shape& S, Standard_OStream& OS) const;
0129 
0130   //! Reads a shape of type <T> from the stream <IS> and returns it in <S>.
0131   Standard_EXPORT virtual void ReadShape(const TopAbs_ShapeEnum T,
0132                                          Standard_IStream&      IS,
0133                                          TopoDS_Shape&          S);
0134 
0135   //! Stores the shape <S>.
0136   Standard_EXPORT virtual void AddShape(const TopoDS_Shape& S);
0137 
0138   //! Inserts the shape <S2> in the shape <S1>.
0139   Standard_EXPORT virtual void AddShapes(TopoDS_Shape& S1, const TopoDS_Shape& S2);
0140 
0141   //! Reads the 3d polygons of me
0142   //! from the stream <IS>.
0143   Standard_EXPORT void ReadPolygon3D(
0144     Standard_IStream&            IS,
0145     const Message_ProgressRange& theRange = Message_ProgressRange());
0146 
0147   //! Writes the 3d polygons
0148   //! on the stream <OS> in a format that can
0149   //! be read back by Read.
0150   Standard_EXPORT void WritePolygon3D(
0151     Standard_OStream&            OS,
0152     const Message_ProgressRange& theRange = Message_ProgressRange()) const;
0153 
0154   //! Reads the triangulation of me
0155   //! from the stream <IS>.
0156   Standard_EXPORT void ReadTriangulation(
0157     Standard_IStream&            IS,
0158     const Message_ProgressRange& theRange = Message_ProgressRange());
0159 
0160   //! Writes the triangulation
0161   //! on the stream <OS> in a format that can
0162   //! be read back by Read.
0163   Standard_EXPORT void WriteTriangulation(
0164     Standard_OStream&            OS,
0165     const Message_ProgressRange& theRange = Message_ProgressRange()) const;
0166 
0167   //! Reads the polygons on triangulation of me
0168   //! from the stream <IS>.
0169   Standard_EXPORT void ReadPolygonOnTriangulation(
0170     Standard_IStream&            IS,
0171     const Message_ProgressRange& theRange = Message_ProgressRange());
0172 
0173   //! Writes the polygons on triangulation
0174   //! on the stream <OS> in a format that can
0175   //! be read back by Read.
0176   Standard_EXPORT void WritePolygonOnTriangulation(
0177     Standard_OStream&            OS,
0178     const Message_ProgressRange& theRange = Message_ProgressRange()) const;
0179 
0180 private:
0181   NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher>
0182                        myShapes; ///< index and its shape (started from 1)
0183   BinTools_LocationSet myLocations;
0184   BRep_Builder         myBuilder;
0185   BinTools_SurfaceSet  mySurfaces;
0186   BinTools_CurveSet    myCurves;
0187   BinTools_Curve2dSet  myCurves2d;
0188   NCollection_IndexedMap<occ::handle<Poly_Polygon2D>> myPolygons2D;
0189   NCollection_IndexedMap<occ::handle<Poly_Polygon3D>> myPolygons3D;
0190   NCollection_IndexedDataMap<occ::handle<Poly_Triangulation>,
0191                              // clang-format off
0192                              bool> myTriangulations; //!< Contains a boolean flag with information
0193                                                                  //!  to save normals for triangulation
0194   // clang-format on
0195   NCollection_IndexedMap<occ::handle<Poly_PolygonOnTriangulation>> myNodes;
0196 };
0197 
0198 #endif // _BinTools_ShapeSet_HeaderFile