Salome HOME
Version ok de MED avec MEDGUI.
[modules/med.git] / src / MEDMEM / MEDMEM_Med.hxx
1 # ifndef MED_HXX
2 # define MED_HXX
3
4 // STL
5 # include <string>
6 # include <map>
7 # include <vector>
8 # include <deque>
9
10 // LOCAL
11 # include "MEDMEM_define.hxx"
12 # include "MEDMEM_MedMedDriver.hxx"
13 # include "MEDMEM_Exception.hxx"
14 //using namespace MED_EN;
15
16
17 class MESH;
18 class FIELD_;
19 class SUPPORT ;
20
21 typedef string MESH_NAME_;
22 typedef string FIELD_NAME_;
23 typedef struct { int dt; int it; } DT_IT_;
24 struct LT_DT_IT_
25 {
26   bool operator() (const DT_IT_ &p1, const DT_IT_ &p2) const
27   {
28     if ( bool test = p1.dt == p2.dt)
29       return p1.it < p2.it ;
30     else
31       return  p1.dt < p2.dt ;
32   }
33 };
34 typedef map<DT_IT_, FIELD_*, LT_DT_IT_ > MAP_DT_IT_; 
35
36 // - IN THE FIRST CASE THE USER WANTS TO DISCOVER MESHES & FIELD_S 
37 //   CONTAINNED WITHIN A FILE <fileName> OF TYPE GIVEN BY THE  <driverType> PARAMETER
38 // - IN THE SECOND CASE THE USER BEGINS HIS WORK WITH A MESH OR A FIELD, 
39 //   ?? GET A MED POINTER THEN CAN ADD MESHes OR FIELDs ??
40
41 class MED
42 {
43   friend class MED_MED_DRIVER;
44   friend class MED_MED_RDONLY_DRIVER;
45
46 private:
47
48   map<MESH_NAME_,MESH*>        _meshes;     // We can't have two MESHes with the same meshName.  
49                                            // The string key is a meshName.
50
51   map<FIELD_NAME_,MAP_DT_IT_>  _fields;     // We can't have two FIELDs with the same fieldName. 
52  
53   map<FIELD_ *, MESH_NAME_>    _meshName;   // Get the meshName associated with a FIELD * 
54                                            // in order to get the MESH* from _meshes 
55
56   map < MESH_NAME_, map <MED_FR::med_entite_maillage,SUPPORT * > > _support ;
57   // For each MESH, we list support for each entity on all elements.
58
59   vector<GENDRIVER *>  _drivers;          // Storage of the MED_MED drivers currently in use
60
61 public:
62
63   MED();
64   MED (driverTypes driverType, const string & fileName); // Analyse the file <fileName> by calling readFileStruct
65   ~MED();
66   
67   // INUTILE : void addMesh  (const string & meshName  ); // Read the mesh <meshName> found in the file <_fileName>. <_fileName> must be set.
68   // INUTILE : void addField (const string & fieldName ); // Pensez au cas ou on ajoute un Field/Mesh avec un driver déjà existant.
69   
70   void addField (const FIELD_  * const ptrField  ) throw (MEDEXCEPTION) ; // Add an existing FIELD object to the FIELD list, the meshName is given by the FIELD object.
71   void addMesh  (const MESH   * ptrMesh   ) throw (MEDEXCEPTION) ; // Add an existing MESH object to the MESH list, the meshName is given by the MESH object.
72  
73   // ------  Drivers Management Part
74 protected:
75
76   class INSTANCE {
77   public:
78     virtual GENDRIVER * run(const string & fileName, MED * const ptrMed) const = 0 ;
79   } ;
80   
81   template <class T> class INSTANCE_DE : public INSTANCE {
82   public :
83     GENDRIVER * run(const string & fileName,  MED * const ptrMed) const { return new T(fileName,ptrMed) ; }
84   } ;
85   
86   static INSTANCE_DE<MED_MED_DRIVER> inst_med ;
87   //static INSTANCE_DE<VTK_DRIVER>   inst_vtk   ;
88   static const INSTANCE * const instances[] ;
89
90 public:
91
92   int  addDriver     (driverTypes driverType, const string & fileName);
93   void rmDriver      (int index=0);
94   void readFileStruct(int index=0);
95   // void read          (int index=0);
96   void writeFrom     (int index=0); 
97   void write         (int index=0); 
98   
99   // ------ End Of Drivers Management Part
100
101   int        getNumberOfMeshes ( void ) const;       
102   int        getNumberOfFields ( void ) const;       
103   void       getMeshNames      ( string * meshNames         ) const;
104   deque<string>       getMeshNames      () const;
105   MESH     * getMesh           ( const string & meshName    ) const;
106   MESH     * getMesh           ( const  FIELD_ *  field     ) const;
107   void       getFieldNames     ( string * fieldNames        ) const;
108   deque<string>       getFieldNames     () const;
109   // A FAIRE DES ROUTINES QUI DONNENT LES PDT ET ITE
110   deque<DT_IT_>       getFieldIteration (const string & fieldName) const ;
111   FIELD_   * getField          ( const string & fieldName,
112                                  const int dt,  const int it) const;
113
114   const map<MED_FR::med_entite_maillage,SUPPORT *> & getSupports(const string & meshName) const;
115   SUPPORT *  getSupport (const string & meshName,MED_FR::med_entite_maillage entity) const ;
116
117   void       updateSupport () ;
118
119   // GERER LE CAS DE L'APPARITION DES MEMES NOMS DS DES FICHIERS <> !!!!!
120  
121   //friend ostream & operator<<(ostream &os,const MED & med);
122
123 };
124
125 #endif
126
127 //REM : AJOUTER DS LES DRIVERS des attributes INTERLACE, NO INTERLACE .........
128 //      AJOUTER L'OPERATEUR DE RECOPIE