1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #ifndef GIBI_MESH_DRIVER_HXX
24 #define GIBI_MESH_DRIVER_HXX
34 #include "MEDMEM_define.hxx"
35 #include "MEDMEM_GenDriver.hxx"
37 #include "MEDMEM_STRING.hxx"
38 #include "MEDMEM_Exception.hxx"
39 #include "MEDMEM_Utilities.hxx"
41 #include "MEDMEM_FieldForward.hxx"
57 Generic part : implement the readopen and close methods.
69 struct _intermediateMED;
71 // IMP 0020434: mapping GIBI names to MED names
72 struct nameGIBItoMED {
74 int gibi_pile; // PILE_SOUS_MAILLAGE or PILE_FIELD/PILE_NODES_FIELD, or PILE_STRINGS(for components)
76 string gibi_name; // used only for components
78 // med_pile = 27; // PILE_STRINGS
79 int med_id; // used only on reading
80 string med_name; // used only on writing
83 class MEDMEM_EXPORT GIBI_MESH_DRIVER : public GENDRIVER
88 std::string _meshName;
90 // This enumeration is used to substitude static const
91 // memers data causing link errors on VC7 compiler.
94 nb_geometrie_gibi = 47
96 // tableau de correspondance des types géométriques de CASTEM -> MED
97 //static const size_t nb_geometrie_gibi=47;
98 static const MED_EN::medGeometryElement geomGIBItoMED[nb_geometrie_gibi];
110 GIBI_MESH_DRIVER(const string & fileName,
112 MED_EN::med_mode_acces accessMode) ;
116 GIBI_MESH_DRIVER(const GIBI_MESH_DRIVER & driver) ;
121 virtual ~GIBI_MESH_DRIVER() ;
123 virtual void write( void ) const = 0 ;
124 virtual void read ( void ) = 0 ;
127 Set the name of the MESH asked in file.
129 It could be different than the name of the MESH object.
131 void setMeshName(const string & meshName) ;
133 Get the name of the MESH asked in file.
135 string getMeshName() const ;
137 static MED_EN::medGeometryElement gibi2medGeom( size_t gibiTypeNb );
138 static int med2gibiGeom( MED_EN::medGeometryElement medGeomType );
141 virtual GENDRIVER * copy ( void ) const = 0 ;
146 class MEDMEM_EXPORT GIBI_MESH_RDONLY_DRIVER : public virtual GIBI_MESH_DRIVER
153 GIBI_MESH_RDONLY_DRIVER() ;
157 GIBI_MESH_RDONLY_DRIVER(const string & fileName, MESH * ptrMesh) ;
161 GIBI_MESH_RDONLY_DRIVER(const GIBI_MESH_RDONLY_DRIVER & driver) ;
166 virtual ~GIBI_MESH_RDONLY_DRIVER() ;
169 Return a MEDEXCEPTION : it is the read-only driver.
171 void write( void ) const throw (MEDEXCEPTION);
173 Read MESH in the specified file.
175 void read ( void ) throw (MEDEXCEPTION);
182 bool readFile(_intermediateMED* medi, bool readFields );
184 void fillMesh(_intermediateMED* medi);
186 void updateSupports();
190 GENDRIVER * copy ( void ) const ;
192 // fields and methods for file reading
194 bool getLine(char* & line);
195 bool getNextLine (char* & line, bool raiseIfNot = true ) throw (MEDEXCEPTION)
197 if ( getLine( line )) return true;
198 if ( raiseIfNot ) throw MEDEXCEPTION(LOCALIZED(STRING("Unexpected EOF on ln ")<<_lineNb));
201 void initNameReading(int nbValues, int width = 8); // FORMAT(8(1X,A8))
202 void initIntReading(int nbValues); // FORMAT(10I8)
203 void initDoubleReading(int nbValues); // FORMAT(1P,3E22.14)
204 void init( int nbToRead, int nbPosInLine, int width, int shift = 0 );
207 char* str() const { return _curPos; }
208 int index() const { return _iRead; }
210 float getFloat() const;
211 double getDouble() const;
212 string getName() const;
222 int _iPos, _nbPosInLine, _width, _shift;
223 int _iRead, _nbToRead;
247 Driver Med for MESH : Write only.
249 Implement write method.
253 class MEDMEM_EXPORT GIBI_MESH_WRONLY_DRIVER : public virtual GIBI_MESH_DRIVER {
260 GIBI_MESH_WRONLY_DRIVER() ;
264 GIBI_MESH_WRONLY_DRIVER(const string & fileName, GMESH * ptrMesh) ;
268 GIBI_MESH_WRONLY_DRIVER(const GIBI_MESH_WRONLY_DRIVER & driver) ;
273 virtual ~GIBI_MESH_WRONLY_DRIVER() ;
276 Write MESH in the specified file.
278 void write( void ) const throw (MEDEXCEPTION);
280 Return a MEDEXCEPTION : it is the write-only driver.
282 void read ( void ) throw (MEDEXCEPTION);
292 Add a support to write. Return true if a support will be written
294 bool addSupport( const SUPPORT * support );
296 return submesh id and size for a support. Call it after writeSupportsAndMesh()
298 int getSubMeshIdAndSize(const SUPPORT * support,
299 std::list<std::pair<int,int> > & idsAndSizes ) const;
301 Write MESH and _supports.
303 void writeSupportsAndMesh(list<nameGIBItoMED>& listGIBItoMED_mail);
305 * Store MED names of supports and fields.
306 * All MED names are written in STRINGS PILE, and the correspondence
307 * between GIBI and MED names is written as TABLE "noms_med"
309 void writeMEDNames(const std::list<nameGIBItoMED>& listGIBItoMED_mail,
310 const std::list<nameGIBItoMED>& listGIBItoMED_cham,
311 const std::list<nameGIBItoMED>& listGIBItoMED_comp);
313 Write the record closing file
315 void writeLastRecord();
317 //static void addName( map<string,int>& nameMap, string& name, int index, string prefix );
318 static void addName( std::map<std::string,int>& nameMap,
319 std::map<std::string,int>& namePrefixesMap,
320 const std::string& name,
323 void writeNames( std::map<std::string,int>& nameMap );
330 const int * _ptrElemIDs; // elem ids or
331 int _elemID1; // first elem id if isOnAllElements()
332 typeData( int nbElems=0, const int * ptrElemIDs=NULL, int elemID1=0 )
333 : _nbElems(nbElems), _ptrElemIDs(ptrElemIDs), _elemID1(elemID1) {}
337 typedef map< MED_EN::medGeometryElement, list< typeData > >::iterator typeIterator;
340 map< MED_EN::medGeometryElement, list< typeData > > _types;
341 supportData(): _id(0) {}
342 int getNumberOfTypes() const { return _types.size(); }
343 int getNumberObjects() const
344 { return _types.size() < 2 ? _types.size() : _types.size() + !_cleanName.empty(); }
345 void addTypeData(MED_EN::medGeometryElement type, int nbElems,
346 const int * ptrElemIDs, int elemID1 )
347 { _types[type].push_back( typeData( nbElems, ptrElemIDs, elemID1 )); }
350 void writeElements (MED_EN::medGeometryElement geomType,
351 list< typeData >& typeDataList,
352 const int * nodalConnect,
353 const int * nodalConnectIndex);
355 map<const SUPPORT*, supportData> _supports;
357 GENDRIVER * copy ( void ) const ;
363 Driver GIBI for MESH : Read write.
364 - Use read method from GIBI_MESH_RDONLY_DRIVER
365 - Use write method from GIBI_MESH_WRONLY_DRIVER
369 class MEDMEM_EXPORT GIBI_MESH_RDWR_DRIVER : public GIBI_MESH_RDONLY_DRIVER, public GIBI_MESH_WRONLY_DRIVER {
376 GIBI_MESH_RDWR_DRIVER() ;
380 GIBI_MESH_RDWR_DRIVER(const std::string & fileName, MESH * ptrMesh) ;
384 GIBI_MESH_RDWR_DRIVER(const GIBI_MESH_RDWR_DRIVER & driver) ;
389 ~GIBI_MESH_RDWR_DRIVER() ;
392 Write MESH in the specified file.
394 void write(void) const throw (MEDEXCEPTION);
396 Read MESH in the specified file.
398 void read (void) throw (MEDEXCEPTION);
404 GENDRIVER * copy(void) const ;
408 class MEDMEM_EXPORT GIBI_MED_RDONLY_DRIVER : public GIBI_MESH_RDONLY_DRIVER {
410 std::vector<FIELD_*> * _fields;
417 GIBI_MED_RDONLY_DRIVER() ;
421 GIBI_MED_RDONLY_DRIVER(const std::string & fileName, std::vector<FIELD_*>& ptrFields) ;
425 GIBI_MED_RDONLY_DRIVER(const GIBI_MED_RDONLY_DRIVER & driver) ;
430 virtual ~GIBI_MED_RDONLY_DRIVER() ;
433 Read MESH and FIELDs in the specified file.
435 void read ( void ) throw (MEDEXCEPTION);
437 MESH* getMesh() const;
441 GENDRIVER * copy ( void ) const ;
447 Driver Med for MESH : Write only.
449 Implement write method.
453 class MEDMEM_EXPORT GIBI_MED_WRONLY_DRIVER : public GIBI_MESH_WRONLY_DRIVER {
455 std::vector<const FIELD_*> _fields;
462 GIBI_MED_WRONLY_DRIVER() ;
464 Constructor. To write a mesh and all fields on it
466 GIBI_MED_WRONLY_DRIVER(const std::string & fileName,
467 const std::vector<const FIELD_*>& fields,
472 GIBI_MED_WRONLY_DRIVER(const GIBI_MED_WRONLY_DRIVER & driver) ;
477 virtual ~GIBI_MED_WRONLY_DRIVER() ;
480 Write MESH in the specified file.
482 void write( void ) const throw (MEDEXCEPTION);
484 //int getSupports(const FIELD_* field, list<const SUPPORT*>& supList) const;
488 GENDRIVER * copy ( void ) const ;
494 #endif /* GIBI_MESH_DRIVER_HXX */