Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-22 09:32:47

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_HeaderFile
0017 #define _BinTools_HeaderFile
0018 
0019 #include <BinTools_FormatVersion.hxx>
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Real.hxx>
0025 #include <Message_ProgressRange.hxx>
0026 
0027 class TopoDS_Shape;
0028 
0029 //! Tool to keep shapes in binary format
0030 class BinTools
0031 {
0032 public:
0033   DEFINE_STANDARD_ALLOC
0034 
0035   Standard_EXPORT static Standard_OStream& PutReal(Standard_OStream& OS, const double& theValue);
0036 
0037   Standard_EXPORT static Standard_OStream& PutShortReal(Standard_OStream& OS,
0038                                                         const float&      theValue);
0039 
0040   Standard_EXPORT static Standard_OStream& PutInteger(Standard_OStream& OS, const int theValue);
0041 
0042   Standard_EXPORT static Standard_OStream& PutBool(Standard_OStream& OS, const bool theValue);
0043 
0044   Standard_EXPORT static Standard_OStream& PutExtChar(Standard_OStream& OS,
0045                                                       const char16_t    theValue);
0046 
0047   Standard_EXPORT static Standard_IStream& GetReal(Standard_IStream& IS, double& theValue);
0048 
0049   Standard_EXPORT static Standard_IStream& GetShortReal(Standard_IStream& IS, float& theValue);
0050 
0051   Standard_EXPORT static Standard_IStream& GetInteger(Standard_IStream& IS, int& theValue);
0052 
0053   Standard_EXPORT static Standard_IStream& GetBool(Standard_IStream& IS, bool& theValue);
0054 
0055   Standard_EXPORT static Standard_IStream& GetExtChar(Standard_IStream& IS, char16_t& theValue);
0056 
0057   //! Writes the shape to the stream in binary format BinTools_FormatVersion_CURRENT.
0058   //! This alias writes shape with triangulation data.
0059   //! @param[in] theShape        the shape to write
0060   //! @param[in][out] theStream  the stream to output shape into
0061   //! @param theRange            the range of progress indicator to fill in
0062   static void Write(const TopoDS_Shape&          theShape,
0063                     Standard_OStream&            theStream,
0064                     const Message_ProgressRange& theRange = Message_ProgressRange())
0065   {
0066     Write(theShape, theStream, true, false, BinTools_FormatVersion_CURRENT, theRange);
0067   }
0068 
0069   //! Writes the shape to the stream in binary format of specified version.
0070   //! @param[in] theShape          the shape to write
0071   //! @param[in][out] theStream    the stream to output shape into
0072   //! @param[in] theWithTriangles  flag which specifies whether to save shape with (TRUE) or without
0073   //! (FALSE) triangles;
0074   //!                              has no effect on triangulation-only geometry
0075   //! @param[in] theWithNormals    flag which specifies whether to save triangulation with (TRUE) or
0076   //! without (FALSE) normals;
0077   //!                              has no effect on triangulation-only geometry
0078   //! @param[in] theVersion        the BinTools format version
0079   //! @param theRange              the range of progress indicator to fill in
0080   Standard_EXPORT static void Write(
0081     const TopoDS_Shape&          theShape,
0082     Standard_OStream&            theStream,
0083     const bool                   theWithTriangles,
0084     const bool                   theWithNormals,
0085     const BinTools_FormatVersion theVersion,
0086     const Message_ProgressRange& theRange = Message_ProgressRange());
0087 
0088   //! Reads a shape from <theStream> and returns it in <theShape>.
0089   Standard_EXPORT static void Read(TopoDS_Shape&                theShape,
0090                                    Standard_IStream&            theStream,
0091                                    const Message_ProgressRange& theRange = Message_ProgressRange());
0092 
0093   //! Writes the shape to the file in binary format BinTools_FormatVersion_CURRENT.
0094   //! @param[in] theShape  the shape to write
0095   //! @param[in] theFile   the path to file to output shape into
0096   //! @param theRange      the range of progress indicator to fill in
0097   static bool Write(const TopoDS_Shape&          theShape,
0098                     const char* const            theFile,
0099                     const Message_ProgressRange& theRange = Message_ProgressRange())
0100   {
0101     return Write(theShape, theFile, true, false, BinTools_FormatVersion_CURRENT, theRange);
0102   }
0103 
0104   //! Writes the shape to the file in binary format of specified version.
0105   //! @param[in] theShape          the shape to write
0106   //! @param[in] theFile           the path to file to output shape into
0107   //! @param[in] theWithTriangles  flag which specifies whether to save shape with (TRUE) or without
0108   //! (FALSE) triangles;
0109   //!                              has no effect on triangulation-only geometry
0110   //! @param[in] theWithNormals    flag which specifies whether to save triangulation with (TRUE) or
0111   //! without (FALSE) normals;
0112   //!                              has no effect on triangulation-only geometry
0113   //! @param[in] theVersion        the BinTools format version
0114   //! @param theRange              the range of progress indicator to fill in
0115   Standard_EXPORT static bool Write(
0116     const TopoDS_Shape&          theShape,
0117     const char* const            theFile,
0118     const bool                   theWithTriangles,
0119     const bool                   theWithNormals,
0120     const BinTools_FormatVersion theVersion,
0121     const Message_ProgressRange& theRange = Message_ProgressRange());
0122 
0123   //! Reads a shape from <theFile> and returns it in <theShape>.
0124   Standard_EXPORT static bool Read(TopoDS_Shape&                theShape,
0125                                    const char* const            theFile,
0126                                    const Message_ProgressRange& theRange = Message_ProgressRange());
0127 };
0128 
0129 #endif // _BinTools_HeaderFile