]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_EnsightMeshDriver.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM / MEDMEM_EnsightMeshDriver.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef ENSIGHT_MESH_DRIVER_HXX
23 #define ENSIGHT_MESH_DRIVER_HXX
24
25 #include "MEDMEM_define.hxx"
26 #include "MEDMEM_Exception.hxx"
27 #include "MEDMEM_EnsightUtils.hxx"
28
29 #include <fstream>
30
31 namespace MEDMEM {
32
33   class MESH;
34   class SUPPORT;
35
36 // ==============================================================================
37 /*!
38   Driver Ensight for MESH ( writing and reading ).
39
40   Generic part : implement open and close methods.
41 */
42 // ==============================================================================
43
44 class MEDMEM_EXPORT ENSIGHT_MESH_DRIVER : public MEDMEM_ENSIGHT::_CaseFileDriver_User
45 {
46 protected:
47
48   MESH *       _ptrMesh;
49   std::string  _meshName;
50
51   virtual void openConst(bool checkDataFile=false) const;
52
53 public :
54   ENSIGHT_MESH_DRIVER() ;
55   ENSIGHT_MESH_DRIVER(const std::string & fileName,  MESH * ptrMesh) ;
56   ENSIGHT_MESH_DRIVER(const std::string & fileName,  MESH * ptrMesh,
57                       MED_EN::med_mode_acces accessMode);
58   ENSIGHT_MESH_DRIVER(const ENSIGHT_MESH_DRIVER & driver) ;
59   virtual ~ENSIGHT_MESH_DRIVER() ;
60
61   void open();
62   void close();
63
64   virtual void        setMeshName(const string & meshName);
65   virtual std::string getMeshName() const;
66
67   MESH* getMesh() { return _ptrMesh; }
68 };
69
70 // ==============================================================================
71 /*!
72  * \brief Reading EnSight driver.
73  */
74 // ==============================================================================
75   
76 class MEDMEM_EXPORT ENSIGHT_MESH_RDONLY_DRIVER : public virtual ENSIGHT_MESH_DRIVER
77 {
78 public :
79   //!< to read mesh of index-th time step
80   ENSIGHT_MESH_RDONLY_DRIVER(const std::string & fileName, MESH * ptrMesh, int index=1);
81
82   ENSIGHT_MESH_RDONLY_DRIVER();
83   ENSIGHT_MESH_RDONLY_DRIVER(const ENSIGHT_MESH_RDONLY_DRIVER & driver);
84   virtual ~ENSIGHT_MESH_RDONLY_DRIVER();
85   virtual GENDRIVER * copy ( void ) const;
86   virtual void merge ( const GENDRIVER& driver );
87   virtual void write       ( void ) const throw (MEDEXCEPTION) ;
88   virtual void read        ( void ) throw (MEDEXCEPTION);
89
90   //!< count number of parts in EnSight geometry file 
91   static int countParts(const std::string& geomFileName,
92                         const bool         isSingleFileMode);
93
94   static GROUP* makeGroup( MEDMEM::_groupe &           interGroup,
95                            MEDMEM_ENSIGHT::_InterMed & imed);
96                         
97 private:
98
99   void readGoldASCII (MEDMEM_ENSIGHT::_InterMed & imed);
100   void readGoldBinary(MEDMEM_ENSIGHT::_InterMed & imed);
101   void read6ASCII    (MEDMEM_ENSIGHT::_InterMed & imed);
102   void read6Binary   (MEDMEM_ENSIGHT::_InterMed & imed);
103
104   static int countPartsBinary(MEDMEM_ENSIGHT::_BinaryFileReader& fileReader,
105                               const bool                         isSingleFileMode);
106
107   bool _isMadeByMed;
108   int  _indexInCaseFile;
109 };
110
111 // ==============================================================================
112 /*!
113  * \brief Writing EnSight mesh driver.
114  *     To set writing format use
115  *       setEnSightFormatForWriting(EnSightFormat) and
116  *       setEnSightBinaryFormatForWriting(bool)
117  */
118 // ==============================================================================
119
120 class MEDMEM_EXPORT ENSIGHT_MESH_WRONLY_DRIVER : public virtual ENSIGHT_MESH_DRIVER
121 {
122 public :
123   //!< write a mesh;
124   // to be appended, a mesh mush have same nb of groups and dimension as already present ones
125   ENSIGHT_MESH_WRONLY_DRIVER(const std::string & fileName,  MESH * ptrMesh, bool append=false);
126
127   ENSIGHT_MESH_WRONLY_DRIVER();
128   ENSIGHT_MESH_WRONLY_DRIVER(const ENSIGHT_MESH_WRONLY_DRIVER & driver);
129   virtual ~ENSIGHT_MESH_WRONLY_DRIVER();
130   GENDRIVER * copy ( void ) const;
131   void write       ( void ) const throw (MEDEXCEPTION) ;
132   void read        ( void ) throw (MEDEXCEPTION) ;
133
134   int nbPartsToWrite() const;
135
136 private:
137
138   void writePart6Binary   (MEDMEM_ENSIGHT::_BinaryFileWriter& file, const SUPPORT* support) const;
139   void writePartGoldBinary(MEDMEM_ENSIGHT::_BinaryFileWriter& file, const SUPPORT* support) const;
140   void writePart6ASCII    (std::ofstream&               fileStream, const SUPPORT* support) const;
141   void writePartGoldASCII (std::ofstream&               fileStream, const SUPPORT* support) const;
142
143   bool _append;
144 };
145
146 }
147
148 #endif /* ENSIGHT_MESH_DRIVER_HXX */
149