]> SALOME platform Git repositories - modules/med.git/blob - src/MEDMEM/MEDMEM_Med.hxx
Salome HOME
sources v1.2
[modules/med.git] / src / MEDMEM / MEDMEM_Med.hxx
1 //  MED MEDMEM : MED files in memory
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : MEDMEM_Med.hxx
25 //  Module : MED
26
27 # ifndef MED_HXX
28 # define MED_HXX
29
30 // STL
31 # include <string>
32 # include <map>
33 # include <vector>
34 # include <deque>
35
36 // LOCAL
37 # include "MEDMEM_define.hxx"
38
39 // Add your own driver header (step 2)
40 # include "MEDMEM_MedMedDriver.hxx"
41 # include "MEDMEM_VtkMedDriver.hxx"
42
43 # include "MEDMEM_Exception.hxx"
44 //using namespace MED_EN;
45
46
47 class MESH;
48 class FIELD_;
49 class SUPPORT ;
50
51 typedef string MESH_NAME_;
52 typedef string FIELD_NAME_;
53 typedef struct { int dt; int it; } DT_IT_;
54 struct LT_DT_IT_
55 {
56   bool operator() (const DT_IT_ &p1, const DT_IT_ &p2) const
57   {
58     if ( bool test = p1.dt == p2.dt)
59       return p1.it < p2.it ;
60     else
61       return  p1.dt < p2.dt ;
62   }
63 };
64 typedef map<DT_IT_, FIELD_*, LT_DT_IT_ > MAP_DT_IT_; 
65
66 // - IN THE FIRST CASE THE USER WANTS TO DISCOVER MESHES & FIELD_S 
67 //   CONTAINNED WITHIN A FILE <fileName> OF TYPE GIVEN BY THE  <driverType> PARAMETER
68 // - IN THE SECOND CASE THE USER BEGINS HIS WORK WITH A MESH OR A FIELD, 
69 //   ?? GET A MED POINTER THEN CAN ADD MESHes OR FIELDs ??
70 //
71
72 /*!
73
74   This class is use to group together some MESH, SUPPORT and FIELD
75   objects.
76
77 */
78
79 class MED
80 {
81   // Add your personnal driver line (step 2)
82   friend class MED_MED_RDONLY_DRIVER;
83   friend class MED_MED_WRONLY_DRIVER;
84   friend class MED_MED_RDWR_DRIVER;
85
86 private:
87
88   map<MESH_NAME_,MESH*>        _meshes;     // We can't have two MESHes with the same meshName.  
89                                             // The string key is a meshName.
90
91   map<FIELD_NAME_,MAP_DT_IT_>  _fields;     // We can't have two FIELD_s with the same fieldName. 
92  
93   map<FIELD_ *, MESH_NAME_>    _meshName;   // Get the meshName associated with a FIELD_ * 
94                                             // in order to get the MESH* from _meshes 
95
96   // POURQUOI MED_FR::med_entite_maillage ? devrait être MED_EN !
97   map < MESH_NAME_, map <MED_FR::med_entite_maillage,SUPPORT * > > _support ;
98   // For each MESH, we list support for each entity on all elements.
99
100   vector<GENDRIVER *>  _drivers;          // Storage of the MED_MED drivers currently in use
101
102 public:
103
104   MED();
105   MED (driverTypes driverType, const string & fileName); // Analyse the file <fileName> by calling readFileStruct
106   ~MED();
107   
108   // INUTILE : void addMesh  (const string & meshName  ); // Read the mesh <meshName> found in the file <_fileName>. <_fileName> must be set.
109   // INUTILE : void addField (const string & fieldName ); // Pensez au cas ou on ajoute un Field/Mesh avec un driver déjà existant.
110   
111   void addField ( FIELD_  * const ptrField  ) throw (MED_EXCEPTION) ;
112   void addMesh  ( MESH    * const ptrMesh   ) throw (MED_EXCEPTION) ;
113
114   // ------  Drivers Management Part
115 protected:
116
117   class INSTANCE {
118   public:
119     virtual GENDRIVER * run(const string & fileName, MED * const ptrMed) const = 0 ;
120   } ;
121   
122   template <class T> class INSTANCE_DE : public INSTANCE {
123   public :
124     GENDRIVER * run(const string & fileName,  MED * const ptrMed) const 
125     { 
126       MESSAGE("GENDRIVER * run") ;
127       return new T(fileName,ptrMed) ; 
128     }
129   } ;
130   
131   // Add your new driver instance here (step 3)
132   static INSTANCE_DE<MED_MED_RDWR_DRIVER> inst_med ;
133   static INSTANCE_DE<VTK_MED_DRIVER> inst_vtk ;
134   static const INSTANCE * const instances[] ;
135
136 public:
137
138   int  addDriver     (driverTypes driverType, const string & fileName);
139   int  addDriver     (GENDRIVER & driver);
140   void rmDriver      (int index=0) throw (MEDEXCEPTION) ;
141
142   void readFileStruct(int index=0) throw (MEDEXCEPTION) ;
143   void read          (int index=0) throw (MEDEXCEPTION) ;
144   void writeFrom     (int index=0) throw (MEDEXCEPTION) ; 
145   void write         (int index=0) throw (MEDEXCEPTION) ; 
146   
147   // ------ End Of Drivers Management Part
148
149   int        getNumberOfMeshes ( void ) const;       
150   int        getNumberOfFields ( void ) const;       
151   void       getMeshNames      ( string * meshNames ) const throw (MEDEXCEPTION) ;
152   deque<string> getMeshNames   () const;
153   MESH     * getMesh           ( const string & meshName ) const throw (MEDEXCEPTION) ;
154   MESH     * getMesh           ( const  FIELD_ * const field ) const throw (MEDEXCEPTION) ;
155   void       getFieldNames     ( string * fieldNames        ) const throw (MEDEXCEPTION) ;
156   deque<string> getFieldNames  () const;
157   // A FAIRE DES ROUTINES QUI DONNENT LES PDT ET ITE
158   deque<DT_IT_> getFieldIteration (const string & fieldName) const throw (MEDEXCEPTION) ;
159   FIELD_   * getField          ( const string & fieldName,
160                                  const int dt,  const int it) const throw (MEDEXCEPTION) ;
161
162   const map<MED_FR::med_entite_maillage,SUPPORT *> & getSupports(const string & meshName) const throw (MEDEXCEPTION) ;
163
164   SUPPORT *  getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const throw (MEDEXCEPTION) ;
165
166   void       updateSupport () ;
167
168   // GERER LE CAS DE L'APPARITION DES MEMES NOMS DS DES FICHIERS <> !!!!!
169  
170   //friend ostream & operator<<(ostream &os,const MED & med);
171
172 };
173
174 #endif
175
176 //REM : AJOUTER DS LES DRIVERS des attributes INTERLACE, NO INTERLACE .........
177 //      AJOUTER L'OPERATEUR DE RECOPIE