Salome HOME
Copyrights update
[modules/med.git] / src / MEDMEM / MEDMEM_Med.hxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 # ifndef MED_HXX
21 # define MED_HXX
22
23 // STL
24 # include <string>
25 # include <map>
26 # include <vector>
27 # include <deque>
28
29 // LOCAL
30 # include "MEDMEM_define.hxx"
31 # include "MEDMEM_Exception.hxx"
32 # include "MEDMEM_GenDriver.hxx"
33
34
35 namespace MEDMEM {
36 class MESH;
37 class FIELD_;
38 class SUPPORT ;
39
40 typedef string MESH_NAME_;
41 typedef string FIELD_NAME_;
42 typedef struct { int dt; int it; } DT_IT_;
43 struct LT_DT_IT_
44 {
45   bool operator() (const DT_IT_ &p1, const DT_IT_ &p2) const
46   {
47     if ( p1.dt == p2.dt)
48       return p1.it < p2.it ;
49     else
50       return  p1.dt < p2.dt ;
51   }
52 };
53 typedef map<DT_IT_, FIELD_*, LT_DT_IT_ > MAP_DT_IT_;
54
55 // - IN THE FIRST CASE THE USER WANTS TO DISCOVER MESHES & FIELD_S
56 //   CONTAINNED WITHIN A FILE <fileName> OF TYPE GIVEN BY THE  <driverType> PARAMETER
57 // - IN THE SECOND CASE THE USER BEGINS HIS WORK WITH A MESH OR A FIELD,
58 //   ?? GET A MED POINTER THEN CAN ADD MESHes OR FIELDs ??
59 //
60
61 /*!
62
63   This class is use to group together some MESH, SUPPORT and FIELD
64   objects.
65
66 */
67
68 class MED
69 {
70   // Add your personnal driver line (step 2)
71   friend class MED_MED_RDONLY_DRIVER21;
72   friend class MED_MED_WRONLY_DRIVER21;
73   friend class MED_MED_RDWR_DRIVER21;
74   friend class MED_MED_RDONLY_DRIVER22;
75   friend class MED_MED_WRONLY_DRIVER22;
76   friend class MED_MED_RDWR_DRIVER22;
77
78 private:
79
80   map<MESH_NAME_,MESH*>        _meshes;     // We can't have two MESHes with the same meshName.
81                                             // The string key is a meshName.
82
83   map<FIELD_NAME_,MAP_DT_IT_>  _fields;     // We can't have two FIELD_s with the same fieldName.
84
85   map<FIELD_ *, MESH_NAME_>    _meshName;   // Get the meshName associated with a FIELD_ *
86                                             // in order to get the MESH* from _meshes
87
88   // POURQUOI MED_FR::med_entite_maillage ? devrait être MED_EN !
89   map < MESH_NAME_, map < MED_EN::medEntityMesh, SUPPORT * > > _support ;
90   // For each MESH, we list support for each entity on all elements.
91
92   vector<GENDRIVER *>  _drivers;          // Storage of the MED_MED drivers currently in use
93
94 public:
95
96   MED();
97   MED (driverTypes driverType, const string & fileName); // Analyse the file <fileName> by calling readFileStruct
98   ~MED();
99
100   // INUTILE : void addMesh  (const string & meshName  ); // Read the mesh <meshName> found in the file <_fileName>. <_fileName> must be set.
101   // INUTILE : void addField (const string & fieldName ); // Pensez au cas ou on ajoute un Field/Mesh avec un driver déjà existant.
102
103   void addField ( FIELD_  * const ptrField  ) throw (MED_EXCEPTION) ;
104   void addMesh  ( MESH    * const ptrMesh   ) throw (MED_EXCEPTION) ;
105   int  addDriver     (driverTypes driverType,
106                       const string & fileName,
107                       MED_EN::med_mode_acces access=MED_EN::MED_REMP);
108   int  addDriver     (GENDRIVER & driver);
109   void rmDriver      (int index=0) throw (MEDEXCEPTION) ;
110
111   void readFileStruct(int index=0) throw (MEDEXCEPTION) ;
112   void read          (int index=0) throw (MEDEXCEPTION) ;
113   void writeFrom     (int index=0) throw (MEDEXCEPTION) ;
114   void write         (int index=0) throw (MEDEXCEPTION) ;
115
116   // ------ End Of Drivers Management Part
117
118   int        getNumberOfMeshes ( void ) const;
119   int        getNumberOfFields ( void ) const;
120   void       getMeshNames      ( string * meshNames ) const throw (MEDEXCEPTION) ;
121   deque<string> getMeshNames   () const;
122   MESH     * getMesh           ( const string & meshName ) const throw (MEDEXCEPTION) ;
123   MESH     * getMesh           ( const  FIELD_ * const field ) const throw (MEDEXCEPTION) ;
124   void       getFieldNames     ( string * fieldNames        ) const throw (MEDEXCEPTION) ;
125   deque<string> getFieldNames  () const;
126   // A FAIRE DES ROUTINES QUI DONNENT LES PDT ET ITE
127   deque<DT_IT_> getFieldIteration (const string & fieldName) const throw (MEDEXCEPTION) ;
128   FIELD_   * getField          ( const string & fieldName,
129                                  const int dt,  const int it) const throw (MEDEXCEPTION) ;
130   FIELD_   * getField2          ( const string & fieldName,
131                                  double time, int it=0) const throw (MEDEXCEPTION) ;
132
133   const map<MED_EN::medEntityMesh,SUPPORT *> & getSupports(const string & meshName) const throw (MEDEXCEPTION) ;
134
135   SUPPORT *  getSupport (const string & meshName,MED_EN::medEntityMesh entity) const throw (MEDEXCEPTION) ;
136
137   void       updateSupport () ;
138
139   // GERER LE CAS DE L'APPARITION DES MEMES NOMS DS DES FICHIERS <> !!!!!
140
141   //friend ostream & operator<<(ostream &os,const MED & med);
142
143 };
144 };
145
146 #endif
147
148 //REM : AJOUTER DS LES DRIVERS des attributes INTERLACE, NO INTERLACE .........
149 //      AJOUTER L'OPERATEUR DE RECOPIE