]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_EnsightMeshDriver.hxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / MEDMEM / MEDMEM_EnsightMeshDriver.hxx
1 // Copyright (C) 2007-2012  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
23 #ifndef ENSIGHT_MESH_DRIVER_HXX
24 #define ENSIGHT_MESH_DRIVER_HXX
25
26 #include "MEDMEM_define.hxx"
27 #include "MEDMEM_Exception.hxx"
28 #include "MEDMEM_EnsightUtils.hxx"
29
30 #include <fstream>
31
32 namespace MEDMEM {
33
34   class GMESH;
35   class SUPPORT;
36
37 // ==============================================================================
38 /*!
39   Driver Ensight for MESH ( writing and reading ).
40
41   Generic part : implement open and close methods.
42 */
43 // ==============================================================================
44
45 class MEDMEM_EXPORT ENSIGHT_MESH_DRIVER : public MEDMEM_ENSIGHT::_CaseFileDriver_User
46 {
47 protected:
48
49   GMESH *      _ptrMesh;
50   std::string  _meshName;
51
52   virtual void openConst(bool checkDataFile=false) const;
53
54 public :
55   ENSIGHT_MESH_DRIVER() ;
56   ENSIGHT_MESH_DRIVER(const std::string & fileName,  GMESH * ptrMesh) ;
57   ENSIGHT_MESH_DRIVER(const std::string & fileName,  GMESH * ptrMesh,
58                       MED_EN::med_mode_acces accessMode);
59   ENSIGHT_MESH_DRIVER(const ENSIGHT_MESH_DRIVER & driver) ;
60   virtual ~ENSIGHT_MESH_DRIVER() ;
61
62   void open();
63   void close();
64
65   virtual void        setMeshName(const string & meshName);
66   virtual std::string getMeshName() const;
67
68   GMESH* getMesh() { return _ptrMesh; }
69 };
70
71 // ==============================================================================
72 /*!
73  * \brief Reading EnSight driver.
74  */
75 // ==============================================================================
76   
77 class MEDMEM_EXPORT ENSIGHT_MESH_RDONLY_DRIVER : public virtual ENSIGHT_MESH_DRIVER
78 {
79 public :
80   //!< to read mesh of index-th time step
81   ENSIGHT_MESH_RDONLY_DRIVER(const std::string & fileName, MESH * ptrMesh, int index=1);
82
83   ENSIGHT_MESH_RDONLY_DRIVER();
84   ENSIGHT_MESH_RDONLY_DRIVER(const ENSIGHT_MESH_RDONLY_DRIVER & driver);
85   virtual ~ENSIGHT_MESH_RDONLY_DRIVER();
86   virtual GENDRIVER * copy ( void ) const;
87   virtual void merge ( const GENDRIVER& driver );
88   virtual void write       ( void ) const throw (MEDEXCEPTION) ;
89   virtual void read        ( void ) throw (MEDEXCEPTION);
90
91   //!< count number of parts in EnSight geometry file 
92   static int countParts(const std::string& geomFileName,
93                         const bool         isSingleFileMode);
94
95   static GROUP* makeGroup( MEDMEM::_groupe &           interGroup,
96                            MEDMEM_ENSIGHT::_InterMed & imed);
97                         
98 private:
99
100   void readGoldASCII (MEDMEM_ENSIGHT::_InterMed & imed);
101   void readGoldBinary(MEDMEM_ENSIGHT::_InterMed & imed);
102   void read6ASCII    (MEDMEM_ENSIGHT::_InterMed & imed);
103   void read6Binary   (MEDMEM_ENSIGHT::_InterMed & imed);
104
105   static int countPartsBinary(MEDMEM_ENSIGHT::_BinaryFileReader& fileReader,
106                               const bool                         isSingleFileMode);
107
108   bool _isMadeByMed;
109   int  _indexInCaseFile;
110 };
111
112 // ==============================================================================
113 /*!
114  * \brief Writing EnSight mesh driver.
115  *     To set writing format use
116  *       setEnSightFormatForWriting(EnSightFormat) and
117  *       setEnSightBinaryFormatForWriting(bool)
118  */
119 // ==============================================================================
120
121 class MEDMEM_EXPORT ENSIGHT_MESH_WRONLY_DRIVER : public virtual ENSIGHT_MESH_DRIVER
122 {
123 public :
124   //!< write a mesh;
125   // to be appended, a mesh mush have same nb of groups and dimension as already present ones
126   ENSIGHT_MESH_WRONLY_DRIVER(const std::string & fileName,
127                              const GMESH * ptrMesh,
128                              bool append=false);
129
130   ENSIGHT_MESH_WRONLY_DRIVER();
131   ENSIGHT_MESH_WRONLY_DRIVER(const ENSIGHT_MESH_WRONLY_DRIVER & driver);
132   virtual ~ENSIGHT_MESH_WRONLY_DRIVER();
133   GENDRIVER * copy ( void ) const;
134   void write       ( void ) const throw (MEDEXCEPTION) ;
135   void read        ( void ) throw (MEDEXCEPTION) ;
136
137   int nbPartsToWrite() const;
138
139 private:
140
141   void writePart6Binary   (MEDMEM_ENSIGHT::_BinaryFileWriter& file, const SUPPORT* support) const;
142   void writePartGoldBinary(MEDMEM_ENSIGHT::_BinaryFileWriter& file, const SUPPORT* support) const;
143   void writePart6ASCII    (std::ofstream&               fileStream, const SUPPORT* support) const;
144   void writePartGoldASCII (std::ofstream&               fileStream, const SUPPORT* support) const;
145
146   bool _append;
147 };
148
149 }
150
151 #endif /* ENSIGHT_MESH_DRIVER_HXX */
152