Salome HOME
564d24dd16ed7f78f9c9442f1d8e46b508675f08
[modules/smesh.git] / src / MEDWrapper / MED_Structures.hxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 MED_Structures_HeaderFile
24 #define MED_Structures_HeaderFile
25
26 #include "MED_WrapperDef.hxx"
27 #include "MED_Common.hxx"
28 #include "MED_Utilities.hxx"
29
30 #ifdef WIN32
31 #pragma warning(disable:4251)
32 #endif
33
34 namespace MED
35 {
36   //---------------------------------------------------------------
37   //! Defines a type for managing sequence of strings
38   typedef TVector<char> TString; 
39   typedef SharedPtr<TString> PString;
40
41   //! Extract a substring from the sequence of the strings
42   MEDWRAPPER_EXPORT
43   std::string 
44   GetString(TInt theId, TInt theStep, 
45             const TString& theString);
46   
47   //! Set a substring in the sequence of the strings
48   MEDWRAPPER_EXPORT 
49   void
50   SetString(TInt theId, TInt theStep, 
51                  TString& theString, 
52                  const std::string& theValue);
53
54   //! Set a substring in the sequence of the strings
55   MEDWRAPPER_EXPORT
56   void
57   SetString(TInt theId, TInt theStep, 
58                  TString& theString, 
59                  const TString& theValue);
60
61   //---------------------------------------------------------------
62   //! Define a parent class for all MEDWrapper classes
63   struct MEDWRAPPER_EXPORT TBase
64   {
65     virtual ~TBase() {} 
66   };
67
68   //---------------------------------------------------------------
69   //! Define a parent class for all named MED entities
70   struct MEDWRAPPER_EXPORT TNameInfo: virtual TBase
71   {
72     TString myName; //!< Keeps its name
73     virtual std::string GetName() const = 0; //!< Gets its name
74     virtual void SetName(const std::string& theValue) = 0; //!< Set a new name
75     virtual void SetName(const TString& theValue) = 0; //!< Set a new name
76   };
77
78   //---------------------------------------------------------------
79   //! Define a parent class for all MED entities that contains a sequence of numbers
80   /*!
81     It defines through corresponding enumeration (EModeSwitch) how the sequence 
82     should be interpreted in C or Fortran mode (eFULL_INTERLACE or eNON_INTERLACE).
83   */
84   struct MEDWRAPPER_EXPORT TModeSwitchInfo: virtual TBase
85   {
86     //! To construct instance of the class by default
87     TModeSwitchInfo():
88       myModeSwitch(eFULL_INTERLACE)
89     {}
90
91     //! To construct instance of the class
92     TModeSwitchInfo(EModeSwitch theModeSwitch):
93       myModeSwitch(theModeSwitch)
94     {}
95
96     EModeSwitch myModeSwitch; //!< Keeps the 
97     EModeSwitch GetModeSwitch() const { return myModeSwitch;}
98   };
99
100   //---------------------------------------------------------------
101   //! Define a base class which represents MED Mesh entity
102   struct MEDWRAPPER_EXPORT TMeshInfo: virtual TNameInfo
103   {
104     TInt myDim; //!< Dimension of the mesh (0, 1, 2 or 3)
105     TInt GetDim() const { return myDim;} //!< Gets dimension of the mesh
106
107     TInt mySpaceDim;
108     TInt GetSpaceDim() const { return mySpaceDim; }
109
110     EMaillage myType; //!< Type of the mesh
111     EMaillage GetType() const { return myType;} //!< Gets type of the mesh
112
113     TString myDesc; //!< Description of the mesh
114     virtual std::string GetDesc() const = 0; //!< Get description for the mesh
115     virtual void SetDesc(const std::string& theValue) = 0; //!< Sets description for the mesh
116   };
117
118   //---------------------------------------------------------------
119   typedef TVector<TInt> TIntVector;
120   typedef TSlice<TInt> TIntVecSlice;
121   typedef TCSlice<TInt> TCIntVecSlice;
122
123   typedef TIntVector TFamAttr;
124
125   //! Define a base class which represents MED Family entity
126   struct MEDWRAPPER_EXPORT TFamilyInfo: virtual TNameInfo
127   {
128     PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh
129     //! Get a reference to corresponding MED Mesh
130     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;} 
131
132     TInt myId; //!< An unique index of the MED FAMILY
133     TInt GetId() const { return myId;} //!< Gets number of the MED FAMILY
134     void SetId(TInt theId) { myId = theId;} //! Define number of the MED FAMILY
135
136     TInt myNbGroup; //!< Defines number MED Groups connected to
137     //! Gets number of MED GROUPS the MED FAMILY is bound to
138     TInt GetNbGroup() const { return myNbGroup;} 
139
140     //! Contains sequence of the names for the MED Groups connected to
141     TString myGroupNames; 
142     //! Gets name of a bound MED GROUP by its number
143     virtual std::string GetGroupName(TInt theId) const = 0;
144     //! Sets name of the defined MED GROUP by its number
145     virtual void SetGroupName(TInt theId, const std::string& theValue) = 0;
146
147     TInt myNbAttr; //!< Defines number of the MED Family attributes 
148     //! Gets number of attached attributes for the MED FAMILY
149     TInt GetNbAttr() const { return myNbAttr;} 
150
151     //! Defines sequence of the indexes of the MED Family attributes
152     TFamAttr myAttrId; 
153     //! Get MED FAMILY attribute by its number
154     TInt GetAttrId(TInt theId) const;
155     //! Set MED FAMILY attribute by its number
156     void SetAttrId(TInt theId, TInt theVal);
157
158     //! Defines sequence of the values of the MED Family attributes
159     TFamAttr myAttrVal;
160     //! Get MED FAMILY attribute by its number
161     TInt GetAttrVal(TInt theId) const;
162     //! Set MED FAMILY attribute by its number
163     void SetAttrVal(TInt theId, TInt theVal);
164
165     //! Defines sequence of the names of the MED Family attributes
166     TString myAttrDesc;
167     //! Get value of the MED FAMILY attribute by its number
168     virtual std::string GetAttrDesc(TInt theId) const = 0;
169     //! Set value of the MED FAMILY attribute by its number
170     virtual void SetAttrDesc(TInt theId, const std::string& theValue) = 0;
171   };
172
173   //---------------------------------------------------------------
174   typedef TIntVector TElemNum;
175   typedef SharedPtr<TElemNum> PElemNum;
176   
177   //! Define a parent class for all MED entities that describes mesh entites such as nodes and cells.
178   struct MEDWRAPPER_EXPORT TElemInfo: virtual TBase
179   {
180     PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh
181     //! Get a reference to corresponding MED Mesh
182     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;}
183
184     TInt myNbElem; //<! Number of corresponding mesh entities
185     TInt GetNbElem() const { return myNbElem;} //! Get number of mesh elements
186     
187     //! Defines sequence MED Family indexes for corresponding mesh entites
188     PElemNum myFamNum; 
189     //! Get number of a MED FAMILY by order number of the mesh element
190     TInt GetFamNum(TInt theId) const;
191     //! Set number of a MED FAMILY for the mesh element with the  order number
192     void SetFamNum(TInt theId, TInt theVal);
193
194     //! Defines if the mesh elements are indexed
195     EBooleen myIsElemNum;
196     //! Let know if the mesh elements are indexed
197     EBooleen IsElemNum() const { return myIsElemNum;}
198     
199     //! Defines if the mesh elements family are indexed
200     EBooleen myIsFamNum;
201     //! Let know if the mesh elements family are indexed
202     EBooleen IsFamNum() const { return myIsFamNum;}
203     
204
205     //! Contains sequence of the indexes for the mesh elements
206     PElemNum myElemNum;
207     //! Get a reference number of the mesh element by its order number
208     TInt GetElemNum(TInt theId) const;
209     //! Set a reference number for the mesh element by its order number
210     void SetElemNum(TInt theId, TInt theVal);
211
212     //! Defines if the mesh elements are named
213     EBooleen myIsElemNames;
214     //! Let know if the mesh elements havew names
215     EBooleen IsElemNames() const { return myIsElemNames;}
216
217     //! Contains sequence of the names for the mesh elements
218     PString myElemNames;
219     //! Get name of the mesh element by its order number
220     virtual std::string GetElemName(TInt theId) const = 0;
221     //! Set name of the mesh element by its order number
222     virtual void SetElemName(TInt theId, const std::string& theValue) = 0;
223   };
224
225   //---------------------------------------------------------------
226   typedef TVector<TFloat> TFloatVector;
227   typedef TSlice<TFloat> TFloatVecSlice;
228   typedef TCSlice<TFloat> TCFloatVecSlice;
229
230   typedef TFloatVector TNodeCoord;
231   typedef SharedPtr<TNodeCoord> PNodeCoord;
232
233   typedef TFloatVecSlice TCoordSlice;
234   typedef TCFloatVecSlice TCCoordSlice;
235
236   //! Define a base class which represents MED Nodes entity
237   struct MEDWRAPPER_EXPORT TNodeInfo: 
238     virtual TElemInfo,
239     virtual TModeSwitchInfo 
240   {
241     PNodeCoord myCoord; //!< Contains all nodal coordinates
242
243     //! Gives coordinates for mesh node by its number (const version)
244     TCCoordSlice GetCoordSlice(TInt theId) const;
245     //! Gives coordinates for mesh node by its number
246     TCoordSlice GetCoordSlice(TInt theId);
247
248     ERepere mySystem; //!< Defines, which coordinate system is used
249     //! Get which coordinate system is used for the node describing
250     ERepere GetSystem() const { return mySystem;}
251     //! Set coordinate system to be used for the node describing
252     void SetSystem(ERepere theSystem) { mySystem = theSystem;}
253
254     TString myCoordNames; //!< Contains names for the coordinate dimensions
255     //! Get name of the coordinate dimension by its order number
256     virtual std::string GetCoordName(TInt theId) const = 0;
257     //! Set name of the coordinate dimension by its order number
258     virtual void SetCoordName(TInt theId, const std::string& theValue) = 0;
259
260     TString myCoordUnits; //!< Contains units for the coordinate dimensions
261     //! Get name of unit for the coordinate dimension by its order number
262     virtual std::string GetCoordUnit(TInt theId) const = 0;
263     //! Set name of unit for the coordinate dimension by its order number
264     virtual void SetCoordUnit(TInt theId, const std::string& theValue) = 0;
265   };
266
267   //---------------------------------------------------------------
268   typedef TIntVecSlice TConnSlice;
269   typedef TCIntVecSlice TCConnSlice;
270
271   //! Define a base class which represents MED Cells entity
272   struct MEDWRAPPER_EXPORT TCellInfo: 
273     virtual TElemInfo,
274     virtual TModeSwitchInfo 
275   {
276     EEntiteMaillage myEntity; //!< Defines the MED Entity where the mesh cells belongs to
277     //! Let known what MED ENTITY the cells belong to
278     EEntiteMaillage GetEntity() const { return myEntity;}
279
280     EGeometrieElement myGeom; //!< Defines the MED Geometric type of the instance
281     //! Let known what MED geometrical type the cells belong to
282     EGeometrieElement GetGeom() const { return myGeom;}
283
284     EConnectivite myConnMode; //!< Defines connectivity mode
285     //! Let known in what connectivity the cells are writen
286     EConnectivite GetConnMode() const { return myConnMode;}
287
288     virtual TInt GetConnDim() const = 0; //!< Gives step in the connectivity sequence
289
290     PElemNum myConn; //!< Defines sequence which describe connectivity for each of mesh cell
291
292     //! Gives connectivities for mesh cell by its number (const version)
293     TCConnSlice GetConnSlice(TInt theElemId) const;
294     //! Gives connectivities for mesh cell by its number
295     TConnSlice GetConnSlice(TInt theElemId);
296   };
297
298   //---------------------------------------------------------------
299   //! Define a base class which represents MED Polygon entity
300   struct MEDWRAPPER_EXPORT TPolygoneInfo: 
301     virtual TElemInfo
302   {
303     //! Defines the MED Entity where the polygons belongs to
304     EEntiteMaillage myEntity; // MED_FACE|MED_MAILLE
305     //! Let known what MED ENTITY the MED Polygons belong to
306     EEntiteMaillage GetEntity() const { return myEntity;}
307
308     //! Defines the MED Geometric type of the instance
309     EGeometrieElement myGeom; // ePOLYGONE
310     //! Let known what MED geometrical type the MED Polygons belong to
311     EGeometrieElement GetGeom() const { return ePOLYGONE;}
312
313     //! Defines connectivity mode
314     EConnectivite myConnMode; // eNOD|eDESC(eDESC not used)
315     //! Let known in what connectivity the cells are writen
316     EConnectivite GetConnMode() const { return myConnMode;}
317
318     PElemNum myConn; //!< Table de connectivities
319     PElemNum myIndex; //!< Table de indexes
320
321     //! Gives number of the connectivities for the defined polygon
322     TInt GetNbConn(TInt theElemId) const;
323
324     //! Gives connectivities for polygon by its number (const version)
325     TCConnSlice GetConnSlice(TInt theElemId) const;
326     //! Gives connectivities for polygon by its number
327     TConnSlice GetConnSlice(TInt theElemId);
328   };
329
330   //---------------------------------------------------------------
331   //! Define a class representing MED_BALL structure element.
332   //
333   //  This could be a generic class for any structure element
334   //  holding any number of contant and variable attributes
335   //  but it's too hard to implement
336   //
337   struct MEDWRAPPER_EXPORT TBallInfo: 
338     virtual TCellInfo
339   {
340     TFloatVector myDiameters;
341   };
342
343   //---------------------------------------------------------------
344   typedef TVector<TCConnSlice> TCConnSliceArr;
345   typedef TVector<TConnSlice> TConnSliceArr;
346
347   //! Define a base class which represents MED Polyedre entity
348   struct MEDWRAPPER_EXPORT TPolyedreInfo: 
349     virtual TElemInfo
350   {
351     //! Defines the MED Entity where the polyedres belongs to
352     EEntiteMaillage myEntity; // MED_FACE|MED_MAILLE
353     //! Let known what MED ENTITY the MED Polyedres belong to
354     EEntiteMaillage GetEntity() const { return myEntity;}
355
356     //! Defines the MED Geometric type of the instance
357     EGeometrieElement myGeom; // ePOLYEDRE
358     //! Let known what MED geometrical type the MED Polyedres belong to
359     EGeometrieElement GetGeom() const { return ePOLYEDRE;}
360
361     //! Defines connectivity mode
362     EConnectivite myConnMode; // eNOD|eDESC(eDESC not used)
363     //! Let known in what connectivity the cells are writen
364     EConnectivite GetConnMode() const { return myConnMode;}
365
366     PElemNum myConn; //!< Table de connectivities
367     PElemNum myFaces; //!< Table de faces indexes
368     PElemNum myIndex; //!< Table de indexes
369
370     //! Gives number of the faces for the defined polyedre (const version)
371     TInt GetNbFaces(TInt theElemId) const;
372     //! Gives number of the nodes for the defined polyedre
373     TInt GetNbNodes(TInt theElemId) const;
374
375     //! Gives sequence of the face connectivities for polyedre by its number (const version)
376     TCConnSliceArr GetConnSliceArr(TInt theElemId) const;
377     //! Gives sequence of the face connectivities for polyedre by its number
378     TConnSliceArr GetConnSliceArr(TInt theElemId);
379   };
380
381   //---------------------------------------------------------------
382   //! Define a base class which represents MED Field entity
383   struct MEDWRAPPER_EXPORT TFieldInfo: 
384     virtual TNameInfo
385   {
386     PMeshInfo myMeshInfo; //!< A reference to correspondig MED Mesh
387     //! Get a reference to corresponding MED Mesh
388     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;}
389
390     ETypeChamp myType; //!< Defines type of the MED Field
391     //! Let known what type of the MED FIELD is used
392     ETypeChamp GetType() const { return myType;}
393
394     TInt myNbComp; //!< Defines number of components stored in the field
395     //! Get number of components for the MED FIELD
396     TInt GetNbComp() const { return myNbComp;}
397
398     EBooleen myIsLocal; //!< Defines if the MED Field is local
399     //! Let known is the MED FIELD is local or not
400     EBooleen GetIsLocal() const { return myIsLocal;}
401
402     TInt myNbRef; //!< Defines number of refereces of the field
403     //! Let known number of references for the MED FIELD
404     TInt GetNbRef() const { return myNbRef;}
405
406     TString myCompNames; //!< Contains names for each of MED Field components
407     //! Get name of the component by its order number
408     virtual std::string GetCompName(TInt theId) const = 0;
409     //! Set name for the component by its order number
410     virtual void SetCompName(TInt theId, const std::string& theValue) = 0;
411
412     TString myUnitNames; //!< Contains units for each of MED Field components
413     //! Get unit of the component by its order number
414     virtual std::string GetUnitName(TInt theId) const = 0;
415     //! Set unit for the component by its order number
416     virtual void SetUnitName(TInt theId, const std::string& theValue) = 0;
417   };
418
419   //---------------------------------------------------------------
420   //! Get dimension of the Gauss coordinates for the defined type of mesh cell
421   MEDWRAPPER_EXPORT
422   TInt
423   GetDimGaussCoord(EGeometrieElement theGeom);
424
425   //! Get number of referenced nodes for the defined type of mesh cell
426   MEDWRAPPER_EXPORT
427   TInt
428   GetNbRefCoord(EGeometrieElement theGeom);
429
430   typedef TFloatVector TWeight;
431
432   //! The class represents MED Gauss entity
433   struct MEDWRAPPER_EXPORT TGaussInfo: 
434     virtual TNameInfo,
435     virtual TModeSwitchInfo 
436   {
437     typedef boost::tuple<EGeometrieElement,std::string> TKey;
438     typedef boost::tuple<TKey,TInt> TInfo;
439     struct MEDWRAPPER_EXPORT TLess
440     {
441       bool
442       operator()(const TKey& theLeft, const TKey& theRight) const;
443
444       bool
445       operator()(const TGaussInfo& theLeft, const TGaussInfo& theRight) const;
446     };
447
448     //! Defines, which geometrical type the MED Gauss entity belongs to
449     EGeometrieElement myGeom; 
450     //! Let known what MED geometrical type the MED GAUSS entity belong to
451     EGeometrieElement GetGeom() const { return myGeom;}
452
453     //! Contains coordinates for the refereced nodes
454     TNodeCoord myRefCoord; 
455
456     //! Gives coordinates for the referenced node by its number
457     TCCoordSlice GetRefCoordSlice(TInt theId) const;
458     //! Gives coordinates for the referenced node by its number
459     TCoordSlice GetRefCoordSlice(TInt theId);
460
461     //! Contains coordinates for the Gauss points
462     TNodeCoord myGaussCoord;
463
464     //! Gives coordinates for the Gauss points by its number
465     TCCoordSlice GetGaussCoordSlice(TInt theId) const;
466     //! Gives coordinates for the Gauss points by its number
467     TCoordSlice GetGaussCoordSlice(TInt theId);
468
469     //! Contains wheights for the Gauss points
470     TWeight myWeight;
471
472     //! Gives number of the referenced nodes
473     TInt GetNbRef() const { return GetNbRefCoord(GetGeom());}
474
475     //! Gives dimension of the referenced nodes
476     TInt GetDim() const { return GetDimGaussCoord(GetGeom());}
477
478     //! Gives number of the Gauss Points
479     TInt GetNbGauss() const { return (TInt)(myGaussCoord.size()/GetDim());}
480   };
481
482   //---------------------------------------------------------------
483   typedef std::map<EGeometrieElement,PGaussInfo> TGeom2Gauss;
484   typedef std::map<EGeometrieElement,TInt> TGeom2NbGauss;
485
486   //! Define a base class which represents MED TimeStamp
487   struct MEDWRAPPER_EXPORT TTimeStampInfo: 
488     virtual TBase
489   {
490     PFieldInfo myFieldInfo; //!< A reference to correspondig MED Field
491     //! Get a reference to corresponding MED Field
492     const PFieldInfo& GetFieldInfo() const { return myFieldInfo;}
493
494     //! Defines the MED Entity where the MED TimeStamp belongs to
495     EEntiteMaillage myEntity;
496     //! Let known to what MED Entity the MED TimeStamp belong to
497     EEntiteMaillage GetEntity() const { return myEntity;}
498
499     //! Keeps map of number of cells per geometric type where the MED TimeStamp belongs to
500     TGeom2Size myGeom2Size;
501     //! Get map of number of cells per geometric type where the MED TimeStamp belongs to
502     const TGeom2Size& GetGeom2Size() const { return myGeom2Size;}
503
504     TGeom2NbGauss myGeom2NbGauss; //!< Keeps number of the Gauss Points for the MED TimeStamp
505     TInt GetNbGauss(EGeometrieElement theGeom) const; //!< Gives number of the Gauss Points for the MED TimeStamp
506
507     TInt myNumDt; //!< Keeps number in time for the MED TimeStamp
508     TInt GetNumDt() const { return myNumDt;} //!< Defines number in time for the MED TimeStamp
509
510     TInt myNumOrd; //!< Keeps number for the MED TimeStamp
511     TInt GetNumOrd() const { return myNumOrd;} //!< Defines number for the MED TimeStamp
512
513     TFloat myDt; //!< Keeps time for the MED TimeStamp
514     TFloat GetDt() const { return myDt;} //!< Defines time for the MED TimeStamp
515
516     //! Keeps map of MED Gauss entityes per geometric type
517     TGeom2Gauss myGeom2Gauss;
518     //! Gets a map of MED Gauss entityes per geometric type
519     const TGeom2Gauss& GetGeom2Gauss() const { return myGeom2Gauss;}
520
521     TString myUnitDt; //!< Defines unit for the time for the MED TimeStamp
522     //! Get unit of time for the MED TimeStamp
523     virtual std::string GetUnitDt() const = 0;
524     //! Set unit of time for the MED TimeStamp
525     virtual void SetUnitDt(const std::string& theValue) = 0;
526   };
527
528   //---------------------------------------------------------------
529   //! The class represents MED Profile entity
530   struct MEDWRAPPER_EXPORT TProfileInfo: 
531     virtual TNameInfo
532   {
533     typedef std::string TKey;
534     typedef boost::tuple<TKey,TInt> TInfo;
535
536     EModeProfil myMode; //!< Keeps mode for the MED Profile
537     //! Let known what mode of MED Profile is used
538     EModeProfil GetMode() const { return myMode;}
539     //! Set mode for the MED Profile
540     void SetMode(EModeProfil theMode) { myMode = theMode;}
541
542     PElemNum myElemNum; //!< Keeps sequence of cell by its number which belong to the profile
543     //! Get number of mesh elelemts by its order number
544     TInt GetElemNum(TInt theId) const;
545     //! Set number of mesh elelemts by its order number
546     void SetElemNum(TInt theId, TInt theVal);
547
548     //! Let known is the MED Profile defined
549     bool IsPresent() const { return GetName() != "";}
550
551     //! Let known size of the MED Profile
552     TInt GetSize() const { return (TInt)myElemNum->size();}
553   };
554
555   //---------------------------------------------------------------
556   //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp
557   struct MEDWRAPPER_EXPORT TMeshValueBase:
558     virtual TModeSwitchInfo 
559   {
560     TInt myNbElem;
561     TInt myNbComp;
562     TInt myNbGauss;
563     TInt myStep;
564
565     TMeshValueBase();
566
567     //! Initialize the class
568     void
569     Allocate(TInt theNbElem,
570              TInt theNbGauss,
571              TInt theNbComp,
572              EModeSwitch theMode = eFULL_INTERLACE);
573
574     //! Returns size of the value container
575     size_t
576     GetSize() const;
577     
578     //! Returns MED interpetation of the value size
579     size_t
580     GetNbVal() const;
581     
582     //! Returns number of Gauss Points bounded with the value
583     size_t
584     GetNbGauss() const;
585     
586     //! Returns step inside of the data array
587     size_t
588     GetStep() const;
589     
590     //! Returns bare pointer on the internal value representation
591     virtual
592     unsigned char*
593     GetValuePtr() = 0;
594   };
595
596   //---------------------------------------------------------------
597   //! The class is a helper one. It provide safe and flexible way to get access to values for a MED TimeStamp
598   template<class TValueType>
599   struct TTMeshValue:
600     virtual TMeshValueBase 
601   {
602     typedef TValueType TValue;
603     typedef typename TValueType::value_type TElement;
604
605     typedef TSlice<TElement> TValueSlice;
606     typedef TCSlice<TElement> TCValueSlice;
607     
608     typedef TVector<TCValueSlice> TCValueSliceArr;
609     typedef TVector<TValueSlice> TValueSliceArr;
610     
611     TValue myValue;
612
613     //! Initialize the class
614     void
615     Allocate(TInt theNbElem,
616              TInt theNbGauss,
617              TInt theNbComp,
618              EModeSwitch theMode = eFULL_INTERLACE)
619     {
620       TMeshValueBase::Allocate(theNbElem, theNbGauss, theNbComp, theMode);
621       myValue.resize(theNbElem * this->GetStep());
622     }
623
624     //! Returns bare pointer on the internal value representation
625     virtual
626     unsigned char*
627     GetValuePtr()
628     {
629       return (unsigned char*)&myValue[0];
630     }
631
632     //! Returns bare pointer on the internal value representation
633     virtual
634     TElement*
635     GetPointer()
636     {
637       return &myValue[0];
638     }
639
640     //! Returns bare pointer on the internal value representation
641     virtual
642     const TElement*
643     GetPointer() const
644     {
645       return &myValue[0];
646     }
647
648     //! Iteration through Gauss Points by their components
649     TCValueSliceArr
650     GetGaussValueSliceArr(TInt theElemId) const
651     {
652       TCValueSliceArr aValueSliceArr(myNbGauss);
653       if(GetModeSwitch() == eFULL_INTERLACE){
654         TInt anId = theElemId * myStep;
655         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
656           aValueSliceArr[aGaussId] =
657             TCValueSlice(myValue, std::slice(anId, myNbComp, 1));
658           anId += myNbComp;
659         }
660       }
661       else{
662         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
663           aValueSliceArr[aGaussId] =
664             TCValueSlice(myValue, std::slice(theElemId, myNbComp, myStep));
665         }
666       }
667       return aValueSliceArr;
668     }
669
670     //! Iteration through Gauss Points by their components
671     TValueSliceArr 
672     GetGaussValueSliceArr(TInt theElemId)
673     {
674       TValueSliceArr aValueSliceArr(myNbGauss);
675       if(GetModeSwitch() == eFULL_INTERLACE){
676         TInt anId = theElemId*myStep;
677         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
678           aValueSliceArr[aGaussId] =
679             TValueSlice(myValue, std::slice(anId, myNbComp, 1));
680           anId += myNbComp;
681         }
682       }
683       else{
684         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
685           aValueSliceArr[aGaussId] =
686             TValueSlice(myValue, std::slice(theElemId, myNbComp, myStep));
687         }
688       }
689       return aValueSliceArr;
690     }
691
692     //! Iteration through components by corresponding Gauss Points
693     TCValueSliceArr
694     GetCompValueSliceArr(TInt theElemId) const
695     {
696       TCValueSliceArr aValueSliceArr(myNbComp);
697       if(GetModeSwitch() == eFULL_INTERLACE){
698         TInt anId = theElemId*myStep;
699         for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
700           aValueSliceArr[aCompId] =
701             TCValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp));
702           anId += 1;
703         }
704       }
705       else{
706         for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
707           aValueSliceArr[aCompId] =
708             TCValueSlice(myValue, std::slice(theElemId, myNbGauss, myStep));
709         }
710       }
711       return aValueSliceArr;
712     }
713
714     //! Iteration through components by corresponding Gauss Points
715     TValueSliceArr 
716     GetCompValueSliceArr(TInt theElemId)
717     {
718       if(GetModeSwitch() == eFULL_INTERLACE){
719         TValueSliceArr aValueSliceArr(myNbComp);
720         TInt anId = theElemId*myStep;
721         for(TInt aCompId = 0; aCompId < myNbComp; aCompId++){
722           aValueSliceArr[aCompId] =
723             TValueSlice(myValue, std::slice(anId, myNbGauss, myNbComp));
724           anId += 1;
725         }
726         return aValueSliceArr;
727       }
728       else{
729         TValueSliceArr aValueSliceArr(myNbGauss);
730         for(TInt aGaussId = 0; aGaussId < myNbGauss; aGaussId++){
731           aValueSliceArr[aGaussId] =
732             TValueSlice(myValue,std::slice(theElemId, myNbComp, myStep));
733         }
734         return aValueSliceArr;
735       }
736     }
737   };
738
739   typedef TTMeshValue<TFloatVector> TFloatMeshValue;
740   typedef TTMeshValue<TIntVector> TIntMeshValue;
741
742   //---------------------------------------------------------------
743   // Backward compatibility  declarations
744   typedef TFloatVector TValue;
745   typedef TSlice<TFloat> TValueSlice;
746   typedef TCSlice<TFloat> TCValueSlice;
747   
748   typedef TVector<TCValueSlice> TCValueSliceArr;
749   typedef TVector<TValueSlice> TValueSliceArr;
750     
751   typedef TFloatMeshValue TMeshValue;
752   typedef std::map<EGeometrieElement,TMeshValue> TGeom2Value;
753
754   //---------------------------------------------------------------
755   typedef std::map<EGeometrieElement,PProfileInfo> TGeom2Profile;
756   typedef std::set<EGeometrieElement> TGeom;
757
758   //! The class is a base class for MED TimeStamp values holder
759   struct MEDWRAPPER_EXPORT TTimeStampValueBase: 
760     virtual TModeSwitchInfo 
761   {
762     //! A reference to correspondig MED TimeStamp
763     PTimeStampInfo myTimeStampInfo;
764     //!< Get a reference to correspondig MED TimeStamp
765     const PTimeStampInfo& GetTimeStampInfo() const { return myTimeStampInfo;}
766
767     //! Keeps set of MED EGeometrieElement which contains values for the timestamp
768     TGeomSet myGeomSet;
769     const TGeomSet& GetGeomSet() const { return myGeomSet;}
770
771     //! Keeps map of MED Profiles per geometric type
772     TGeom2Profile myGeom2Profile;
773     //! Gets a map of MED Profiles per geometric type
774     const TGeom2Profile& GetGeom2Profile() const { return myGeom2Profile;}
775
776     //! Gets type of the champ
777     virtual 
778     ETypeChamp
779     GetTypeChamp() const = 0;
780
781     //! Allocates values for the given geometry
782     virtual 
783     void
784     AllocateValue(EGeometrieElement theGeom,
785                   TInt theNbElem,
786                   TInt theNbGauss,
787                   TInt theNbComp,
788                   EModeSwitch theMode = eFULL_INTERLACE) = 0;
789     
790     virtual 
791     size_t
792     GetValueSize(EGeometrieElement theGeom) const = 0;
793     
794     virtual 
795     size_t
796     GetNbVal(EGeometrieElement theGeom) const = 0;
797     
798     virtual 
799     size_t
800     GetNbGauss(EGeometrieElement theGeom) const = 0;
801
802     virtual 
803     unsigned char*
804     GetValuePtr(EGeometrieElement theGeom) = 0;
805   };
806
807   //---------------------------------------------------------------
808   //! The class implements a container for MED TimeStamp values
809   template<class TMeshValueType>
810   struct TTimeStampValue: 
811     virtual TTimeStampValueBase 
812   {
813     typedef TMeshValueType TTMeshValue;
814     typedef SharedPtr<TMeshValueType> PTMeshValue;
815     typedef typename TMeshValueType::TElement TElement;
816     typedef std::map<EGeometrieElement, PTMeshValue> TTGeom2Value;
817
818     ETypeChamp myTypeChamp; //<! Keeps type of the champ
819
820     //! Gets type of the champ
821     virtual 
822     ETypeChamp
823     GetTypeChamp() const
824     {
825       return myTypeChamp;
826     }
827
828     //! Keeps map of MED TimeStamp values per geometric type (const version)
829     TTGeom2Value myGeom2Value;
830
831     const TTGeom2Value& 
832     GetGeom2Value() const
833     {
834       return myGeom2Value;
835     }
836
837     //! Gets MED TimeStamp values for the given geometric type (const version)
838     const PTMeshValue& 
839     GetMeshValuePtr(EGeometrieElement theGeom) const
840     {
841       typename TTGeom2Value::const_iterator anIter = myGeom2Value.find(theGeom);
842       if(anIter == myGeom2Value.end())
843         EXCEPTION(std::runtime_error,"TTimeStampValue::GetMeshValuePtr - myGeom2Value.find(theGeom) fails");
844       return anIter->second;
845     }
846
847     //! Gets MED TimeStamp values for the given geometric type
848     PTMeshValue& 
849     GetMeshValuePtr(EGeometrieElement theGeom)
850     {
851       myGeomSet.insert(theGeom);
852       if(myGeom2Value.find(theGeom) == myGeom2Value.end()){
853         myGeom2Value[theGeom] = PTMeshValue(new TTMeshValue());
854         return myGeom2Value[theGeom];
855       }
856       return myGeom2Value[theGeom];
857     }
858
859     //! Gets MED TimeStamp values for the given geometric type (const version)
860     const TTMeshValue& 
861     GetMeshValue(EGeometrieElement theGeom) const
862     {
863       return *(this->GetMeshValuePtr(theGeom));
864     }
865
866     //! Gets MED TimeStamp values for the given geometric type
867     TTMeshValue& 
868     GetMeshValue(EGeometrieElement theGeom)
869     {
870       return *(this->GetMeshValuePtr(theGeom));
871     }
872   };
873
874   //---------------------------------------------------------------
875   typedef TTimeStampValue<TFloatMeshValue> TFloatTimeStampValue;
876   typedef SharedPtr<TFloatTimeStampValue> PFloatTimeStampValue;
877
878   PFloatTimeStampValue MEDWRAPPER_EXPORT
879   CastToFloatTimeStampValue(const PTimeStampValueBase& theTimeStampValue);
880
881   typedef TTimeStampValue<TIntMeshValue> TIntTimeStampValue;
882   typedef SharedPtr<TIntTimeStampValue> PIntTimeStampValue;
883   
884   PIntTimeStampValue MEDWRAPPER_EXPORT
885   CastToIntTimeStampValue(const PTimeStampValueBase& theTimeStampValue);
886
887   //---------------------------------------------------------------
888   template<class TMeshValueTypeFrom, class TMeshValueTypeTo>
889   void
890   CopyTimeStampValue(SharedPtr<TTimeStampValue<TMeshValueTypeFrom> > theTimeStampValueFrom,
891                      SharedPtr<TTimeStampValue<TMeshValueTypeTo> > theTimeStampValueTo)
892   {
893     typedef TTimeStampValue<TMeshValueTypeFrom> TimeStampValueTypeFrom;
894     typedef TTimeStampValue<TMeshValueTypeTo> TimeStampValueTypeTo;
895     typedef typename TMeshValueTypeTo::TElement TElementTo;
896
897     typename TimeStampValueTypeFrom::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value;
898     typename TimeStampValueTypeFrom::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
899     for(; anIter != aGeom2Value.end(); anIter++){
900       const EGeometrieElement& aGeom = anIter->first;
901       const typename TimeStampValueTypeFrom::TTMeshValue& aMeshValue = *anIter->second;
902       typename TimeStampValueTypeTo::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom);
903       aMeshValue2.Allocate(aMeshValue.myNbElem, 
904                            aMeshValue.myNbGauss, 
905                            aMeshValue.myNbComp,
906                            aMeshValue.myModeSwitch);
907       const typename TimeStampValueTypeFrom::TTMeshValue::TValue& aValue = aMeshValue.myValue;
908       typename TimeStampValueTypeTo::TTMeshValue::TValue& aValue2 = aMeshValue2.myValue;
909       TInt aSize = aValue.size();
910       for(TInt anId = 0; anId < aSize; anId++)
911         aValue2[anId] = TElementTo(aValue[anId]);
912     }
913   }
914
915   template<class TMeshValueType>
916   void
917   CopyTimeStampValue(SharedPtr<TTimeStampValue<TMeshValueType> > theTimeStampValueFrom,
918                      SharedPtr<TTimeStampValue<TMeshValueType> > theTimeStampValueTo)
919   {
920     typedef TTimeStampValue<TMeshValueType> TimeStampValueType;
921     typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValueFrom->myGeom2Value;
922     typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
923     for(; anIter != aGeom2Value.end(); anIter++){
924       const EGeometrieElement& aGeom = anIter->first;
925       const typename TimeStampValueType::TTMeshValue& aMeshValue = *anIter->second;
926       typename TimeStampValueType::TTMeshValue& aMeshValue2 = theTimeStampValueTo->GetMeshValue(aGeom);
927       aMeshValue2 = aMeshValue;
928     }
929   }
930
931   //---------------------------------------------------------------
932   inline
933   void
934   CopyTimeStampValueBase(const PTimeStampValueBase& theValueFrom, 
935                          const PTimeStampValueBase& theValueTo)
936   {
937     if(theValueFrom->GetTypeChamp() == theValueTo->GetTypeChamp()){
938       if(theValueFrom->GetTypeChamp() == eFLOAT64)
939         CopyTimeStampValue<TFloatMeshValue>(theValueFrom, theValueTo);
940       else if(theValueFrom->GetTypeChamp() == eINT)
941         CopyTimeStampValue<TIntMeshValue>(theValueFrom, theValueTo);
942     }else{
943       if(theValueFrom->GetTypeChamp() == eFLOAT64 && theValueTo->GetTypeChamp() == eINT)
944         CopyTimeStampValue<TFloatMeshValue, TIntMeshValue>(theValueFrom, theValueTo);
945       else if(theValueFrom->GetTypeChamp() == eINT && theValueTo->GetTypeChamp() == eFLOAT64)
946         CopyTimeStampValue<TIntMeshValue, TFloatMeshValue>(theValueFrom, theValueTo);
947     }
948   }
949
950   //---------------------------------------------------------------
951   // Backward compatibility  declarations
952   typedef TFloatTimeStampValue TTimeStampVal;
953   typedef PFloatTimeStampValue PTimeStampVal;
954
955   //---------------------------------------------------------------
956   typedef std::map<TInt,TFloatVector> TIndexes;
957   typedef std::map<TInt,TString> TNames;
958   
959   //! Define a base class which represents MED Grille (structured mesh)
960   struct MEDWRAPPER_EXPORT TGrilleInfo:
961     virtual TModeSwitchInfo
962   {
963     PMeshInfo myMeshInfo;
964     const PMeshInfo& GetMeshInfo() const { return myMeshInfo;} 
965
966     TNodeCoord myCoord; //!< Contains all nodal coordinates, now used only for eGRILLE_STANDARD
967     //! Gives coordinates for mesh nodes (const version)
968     const TNodeCoord& GetNodeCoord() const;
969     TNodeCoord& GetNodeCoord();
970     //! Gives coordinates for mesh node by its number, array index from 0
971     TNodeCoord GetCoord(TInt theId);
972     //! Gives ids of nodes for mesh cell or sub-cell by its number, array index from 0
973     TIntVector GetConn(TInt theId, const bool isSub=false);
974
975     EGrilleType myGrilleType; //!< Defines grille type (eGRILLE_CARTESIENNE,eGRILLE_POLAIRE,eGRILLE_STANDARD)
976     //!Gets grille type (const version)
977     const EGrilleType& GetGrilleType() const;
978     //!Gets grille type
979     EGrilleType GetGrilleType();
980     //!Sets grille type
981     void SetGrilleType(EGrilleType theGrilleType);
982
983     TString myCoordNames; //!< Contains names for the coordinate dimensions
984     //! Get name of the coordinate dimension by its order number
985     virtual std::string GetCoordName(TInt theId) const = 0 ;
986     //! Set name of the coordinate dimension by its order number
987     virtual void SetCoordName(TInt theId, const std::string& theValue) = 0;
988
989     TString myCoordUnits; //!< Contains units for the coordinate dimensions
990     //! Get name of unit for the coordinate dimension by its order number
991     virtual std::string GetCoordUnit(TInt theId) const = 0;
992     //! Set name of unit for the coordinate dimension by its order number
993     virtual void SetCoordUnit(TInt theId, const std::string& theValue) = 0;
994
995     //! Map of index of axes and Table of indexes for certain axe, now used for eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
996     TIndexes myIndixes;
997     //!Gets a map of Tables (const version)
998     const TIndexes& GetMapOfIndexes() const ;
999     //!Gets a map of Tables
1000     TIndexes& GetMapOfIndexes();
1001     //!Gets a Table of indexes for certain axe(const version)
1002     const TFloatVector& GetIndexes(TInt theAxisNumber) const;
1003     //!Gets a Table of indexes for certain axe
1004     TFloatVector& GetIndexes(TInt theAxisNumber);
1005     //!Gets a number of indices per axe
1006     TInt GetNbIndexes(TInt theAxisNumber);
1007     
1008     TInt GetNbNodes();//! Return count of all points
1009     TInt GetNbCells();//! Return count of all cells
1010     TInt GetNbSubCells();//! Return count of all entities of <mesh dimension-1>
1011     EGeometrieElement GetGeom();//! Return geometry of cells (calculated from mesh dimension)
1012     EGeometrieElement GetSubGeom();//! Return geometry of subcells (calculated from mesh dimension)
1013     EEntiteMaillage GetEntity();//! Return entity (eMAILLE)
1014     EEntiteMaillage GetSubEntity();//! Return sub entity
1015
1016     /*!
1017      *Vector of grille structure (Example: {3,4,5}, 3 nodes in X axe, 4 nodes in Y axe, ...)
1018      */
1019     TIntVector myGrilleStructure;
1020     //!Gets grille structure(const version)
1021     const TIntVector& GetGrilleStructure() const;
1022     //!Gets grille structure
1023     TIntVector GetGrilleStructure();
1024     //!Sets the grille structure of theAxis axe to theNb.
1025     void SetGrilleStructure(TInt theAxis,TInt theNb);
1026     
1027     /*!
1028      *Defines sequence MED Family indexes for corresponding mesh entites
1029      */
1030     TElemNum myFamNum; 
1031     //! Get number of a MED FAMILY by order number of the mesh element
1032     TInt GetFamNum(TInt theId) const;
1033     //! Set number of a MED FAMILY for the mesh element with the  order number
1034     void SetFamNum(TInt theId, TInt theVal);
1035     
1036     /*!
1037      *Defines sequence MED Family indexes for sub entites
1038      */
1039     TElemNum myFamSubNum; 
1040     //! Get number of a MED FAMILY by order number of sub element
1041     TInt GetFamSubNum(TInt theId) const;
1042     //! Set number of a MED FAMILY for theId-th sub element
1043     void SetFamSubNum(TInt theId, TInt theVal);
1044     
1045     /*!
1046      *Defines sequence MED Family indexes for corresponding mesh nodes
1047      */
1048     TElemNum myFamNumNode;
1049     //! Get number of a MED FAMILY by order number of the mesh node
1050     TInt GetFamNumNode(TInt theId) const;
1051     //! Set number of a MED FAMILY for the mesh node with the  order number
1052     void SetFamNumNode(TInt theId, TInt theVal);
1053   };
1054 }
1055
1056 #endif // MED_Structures_HeaderFile