Salome HOME
Update copyrights 2014.
[modules/smesh.git] / src / MEDWrapper / Base / MED_TStructures.hxx
1 // Copyright (C) 2007-2014  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 #ifndef MED_TStructures_HeaderFile
23 #define MED_TStructures_HeaderFile
24
25 #include "MED_Structures.hxx"
26
27 #ifdef WIN32
28 #pragma warning(disable:4250)
29 #endif
30
31 namespace MED
32 {
33   //---------------------------------------------------------------
34   //! To provide a common way to handle values of MEDWrapper types as native MED types
35   template<class TValue, class TRepresentation>
36   struct TValueHolder
37   {
38     TValue& myValue;
39     TRepresentation myRepresentation;
40
41     TValueHolder(TValue& theValue):
42       myValue(theValue),
43       myRepresentation(TRepresentation(theValue))
44     {}
45
46     ~TValueHolder()
47     {
48       myValue = TValue(myRepresentation);
49     }
50
51     TRepresentation*
52     operator& ()
53     {
54       return &myRepresentation;
55     }
56
57     operator TRepresentation () const
58     {
59       return myRepresentation;
60     }  
61
62     const TValue&
63     operator() () const
64     {
65       return myValue;
66     }  
67   };
68   
69   //! To customize TValueHolder common template definition for TVector
70   template<class TVal, class TRepresentation>
71   struct TValueHolder<TVector<TVal>, TRepresentation>
72   {
73     typedef TVector<TVal> TValue;
74     TValue& myValue;
75     TRepresentation* myRepresentation;
76
77     TValueHolder(TValue& theValue):
78       myValue(theValue)
79     {
80       if(theValue.empty())
81         myRepresentation = (TRepresentation*)NULL;
82       else
83         myRepresentation = (TRepresentation*)&theValue[0];
84     }
85
86     TRepresentation*
87     operator& ()
88     {
89       return myRepresentation;
90     }
91   };
92   
93   //---------------------------------------------------------------
94   template<EVersion eVersion>
95   struct TTNameInfo: virtual TNameInfo
96   {
97     TTNameInfo(const std::string& theValue)
98     {
99       myName.resize(GetNOMLength<eVersion>()+1);
100       SetName(theValue);
101     }
102
103     virtual
104     std::string
105     GetName() const 
106     { 
107       return GetString(0, GetNOMLength<eVersion>(), myName);
108     }
109
110     virtual
111     void
112     SetName(const std::string& theValue)
113     {
114       SetString(0, GetNOMLength<eVersion>(), myName, theValue);
115     }
116
117     virtual
118     void
119     SetName(const TString& theValue)
120     {
121       SetString(0, GetNOMLength<eVersion>(), myName, theValue);
122     }
123   };
124
125
126   //---------------------------------------------------------------
127   template<EVersion eVersion>
128   struct TTMeshInfo: 
129     virtual TMeshInfo, 
130     virtual TTNameInfo<eVersion>
131   {
132     typedef TTNameInfo<eVersion> TNameInfoBase;
133
134     TTMeshInfo(const PMeshInfo& theInfo):
135       TNameInfoBase(theInfo->GetName())
136     {
137       myDim = theInfo->GetDim();
138       mySpaceDim = theInfo->GetSpaceDim();
139       myType = theInfo->GetType();
140       
141       myDesc.resize(GetDESCLength<eVersion>()+1);
142       SetDesc(theInfo->GetDesc());
143     }
144
145     TTMeshInfo(TInt theDim, TInt theSpaceDim,
146                const std::string& theValue,
147                EMaillage theType,
148                const std::string& theDesc):
149       TNameInfoBase(theValue)
150     {
151       myDim = theDim;
152       mySpaceDim = theSpaceDim;
153       myType = theType;
154       
155       myDesc.resize(GetDESCLength<eVersion>()+1);
156       SetDesc(theDesc);
157     }
158
159     virtual 
160     std::string
161     GetDesc() const 
162     { 
163       return GetString(0, GetDESCLength<eVersion>(), myDesc);
164     }
165
166     virtual
167     void
168     SetDesc(const std::string& theValue)
169     {
170       SetString(0, GetDESCLength<eVersion>(), myDesc, theValue);
171     }
172   };
173
174
175   //---------------------------------------------------------------
176   template<EVersion eVersion>
177   struct TTFamilyInfo: 
178     virtual TFamilyInfo, 
179     virtual TTNameInfo<eVersion>
180   {
181     typedef TTNameInfo<eVersion> TNameInfoBase;
182
183     TTFamilyInfo(const PMeshInfo& theMeshInfo, const PFamilyInfo& theInfo):
184       TNameInfoBase(theInfo->GetName())
185     {
186       myMeshInfo = theMeshInfo;
187
188       myId = theInfo->GetId();
189
190       myNbGroup = theInfo->GetNbGroup();
191       myGroupNames.resize(myNbGroup*GetLNOMLength<eVersion>()+1);
192       if(myNbGroup){
193         for(TInt anId = 0; anId < myNbGroup; anId++){
194           SetGroupName(anId,theInfo->GetGroupName(anId));
195         }
196       }
197
198       myNbAttr = theInfo->GetNbAttr();
199       myAttrId.resize(myNbAttr);
200       myAttrVal.resize(myNbAttr);
201       myAttrDesc.resize(myNbAttr*GetDESCLength<eVersion>()+1);
202       if(myNbAttr){
203         for(TInt anId = 0; anId < myNbAttr; anId++){
204           SetAttrDesc(anId,theInfo->GetAttrDesc(anId));
205           myAttrVal[anId] = theInfo->GetAttrVal(anId);
206           myAttrId[anId] = theInfo->GetAttrId(anId);
207         }
208       }
209     }
210
211     TTFamilyInfo(const PMeshInfo& theMeshInfo,
212                  TInt theNbGroup, 
213                  TInt theNbAttr,
214                  TInt theId,
215                  const std::string& theValue):
216       TNameInfoBase(theValue)
217     {
218       myMeshInfo = theMeshInfo;
219
220       myId = theId;
221
222       myNbGroup = theNbGroup;
223       myGroupNames.resize(theNbGroup*GetLNOMLength<eVersion>()+1);
224
225       myNbAttr = theNbAttr;
226       myAttrId.resize(theNbAttr);
227       myAttrVal.resize(theNbAttr);
228       myAttrDesc.resize(theNbAttr*GetDESCLength<eVersion>()+1);
229     }
230
231     TTFamilyInfo(const PMeshInfo& theMeshInfo,
232                  const std::string& theValue,
233                  TInt theId,
234                  const TStringSet& theGroupNames, 
235                  const TStringVector& theAttrDescs, 
236                  const TIntVector& theAttrIds, 
237                  const TIntVector& theAttrVals):
238       TNameInfoBase(theValue)
239     {
240       myMeshInfo = theMeshInfo;
241
242       myId = theId;
243
244       myNbGroup = (TInt)theGroupNames.size();
245       myGroupNames.resize(myNbGroup*GetLNOMLength<eVersion>()+1);
246       if(myNbGroup){
247         TStringSet::const_iterator anIter = theGroupNames.begin();
248         for(TInt anId = 0; anIter != theGroupNames.end(); anIter++, anId++){
249           const std::string& aVal = *anIter;
250           SetGroupName(anId,aVal);
251         }
252       }
253
254       myNbAttr = (TInt)theAttrDescs.size();
255       myAttrId.resize(myNbAttr);
256       myAttrVal.resize(myNbAttr);
257       myAttrDesc.resize(myNbAttr*GetDESCLength<eVersion>()+1);
258       if(myNbAttr){
259         for(TInt anId = 0, anEnd = (TInt)theAttrDescs.size(); anId < anEnd; anId++){
260           SetAttrDesc(anId,theAttrDescs[anId]);
261           myAttrVal[anId] = theAttrVals[anId];
262           myAttrId[anId] = theAttrIds[anId];
263         }
264       }
265     }
266
267     virtual
268     std::string
269     GetGroupName(TInt theId) const 
270     { 
271       return GetString(theId, GetLNOMLength<eVersion>(), myGroupNames);
272     }
273
274     virtual
275     void
276     SetGroupName(TInt theId, const std::string& theValue)
277     {
278       SetString(theId, GetLNOMLength<eVersion>(), myGroupNames, theValue);
279     }
280
281     virtual
282     std::string
283     GetAttrDesc(TInt theId) const 
284     { 
285       return GetString(theId, GetDESCLength<eVersion>(), myAttrDesc);
286     }
287
288     virtual
289     void
290     SetAttrDesc(TInt theId, const std::string& theValue)
291     {
292       SetString(theId, GetDESCLength<eVersion>(), myAttrDesc, theValue);
293     }
294   };
295
296
297   //---------------------------------------------------------------
298   template<EVersion eVersion>
299   struct TTElemInfo: virtual TElemInfo
300   {
301     TTElemInfo(const PMeshInfo& theMeshInfo, const PElemInfo& theInfo)
302     {
303       myMeshInfo = theMeshInfo;
304       
305       myNbElem = theInfo->GetNbElem();
306       myFamNum.reset(new TElemNum(myNbElem));
307       myIsFamNum = eFAUX; // is set to eVRAI in SetFamNum()
308
309       myIsElemNum = theInfo->IsElemNum();
310       if(theInfo->IsElemNum())
311         myElemNum.reset(new TElemNum(myNbElem));
312       else
313         myElemNum.reset(new TElemNum());
314
315       myIsElemNames = theInfo->IsElemNames();
316       if(theInfo->IsElemNames())
317         myElemNames.reset(new TString(myNbElem*GetPNOMLength<eVersion>() + 1));
318       else
319         myElemNames.reset(new TString());
320
321       if(theInfo->GetNbElem()){
322         for(TInt anId = 0; anId < myNbElem; anId++){
323           SetFamNum(anId, theInfo->GetFamNum(anId));
324         }
325         if(theInfo->IsElemNum() == eVRAI){
326           for(TInt anId = 0; anId < myNbElem; anId++){
327             SetElemNum(anId, theInfo->GetElemNum(anId));
328           }
329         }
330         if(theInfo->IsElemNames() == eVRAI){
331           for(TInt anId = 0; anId < myNbElem; anId++){
332             SetElemName(anId,theInfo->GetElemName(anId));
333           }
334         }
335       }
336     }
337
338     TTElemInfo(const PMeshInfo& theMeshInfo, 
339                TInt theNbElem,
340                EBooleen theIsElemNum,
341                EBooleen theIsElemNames)
342     {
343       myMeshInfo = theMeshInfo;
344
345       myNbElem = theNbElem;
346       myFamNum.reset(new TElemNum(theNbElem));
347       myIsFamNum = eFAUX; // is set to eVRAI in SetFamNum()
348
349       myIsElemNum = theIsElemNum;
350       if(theIsElemNum)
351         myElemNum.reset(new TElemNum(theNbElem));
352       else
353         myElemNum.reset(new TElemNum());
354
355       myIsElemNames = theIsElemNames;
356       if(theIsElemNames)
357         myElemNames.reset(new TString(theNbElem*GetPNOMLength<eVersion>() + 1));
358       else
359         myElemNames.reset(new TString());
360    }
361     
362     TTElemInfo(const PMeshInfo& theMeshInfo, 
363                TInt theNbElem,
364                const TIntVector& theFamilyNums,
365                const TIntVector& theElemNums,
366                const TStringVector& theElemNames)
367     {
368       myMeshInfo = theMeshInfo;
369       
370       myNbElem = theNbElem;
371       myFamNum.reset(new TElemNum(theNbElem));
372       myIsFamNum = eFAUX; // is set to eVRAI in SetFamNum()
373       
374       myIsElemNum = theElemNums.size()? eVRAI: eFAUX;
375       if(myIsElemNum)
376         myElemNum.reset(new TElemNum(theNbElem));
377       else
378         myElemNum.reset(new TElemNum());
379       
380       myIsElemNames = theElemNames.size()? eVRAI: eFAUX;
381       if(myIsElemNames)
382         myElemNames.reset(new TString(theNbElem*GetPNOMLength<eVersion>() + 1));
383       else
384         myElemNames.reset(new TString());
385      
386       if(theNbElem){
387
388         if(theFamilyNums.size())
389           *myFamNum = theFamilyNums;
390
391         if(myIsElemNum)
392           *myElemNum = theElemNums;
393
394         if(myIsElemNames){
395           for(TInt anId = 0; anId < theNbElem; anId++){
396             const std::string& aVal = theElemNames[anId];
397             SetElemName(anId,aVal);
398           }
399         }
400       }
401     }
402
403     virtual
404     std::string
405     GetElemName(TInt theId) const 
406     { 
407       return GetString(theId,GetPNOMLength<eVersion>(), *myElemNames);
408     }
409
410     virtual
411     void
412     SetElemName(TInt theId, const std::string& theValue)
413     {
414       SetString(theId,GetPNOMLength<eVersion>(), *myElemNames, theValue);
415     }
416   };
417
418
419   //---------------------------------------------------------------
420   template<EVersion eVersion>
421   struct TTNodeInfo: 
422     virtual TNodeInfo, 
423     virtual TTElemInfo<eVersion>
424   {
425     typedef TTElemInfo<eVersion> TElemInfoBase;
426
427     TTNodeInfo(const PMeshInfo& theMeshInfo, const PNodeInfo& theInfo):
428       TNodeInfo(theInfo),
429       TElemInfoBase(theMeshInfo, theInfo)
430     {
431       myModeSwitch = theInfo->GetModeSwitch();
432       
433       mySystem = theInfo->GetSystem();
434       
435       myCoord.reset(new TNodeCoord(*theInfo->myCoord));
436       
437       TInt aSpaceDim = theMeshInfo->GetSpaceDim();
438
439       myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
440       for(TInt anId = 0; anId < aSpaceDim; anId++)
441         SetCoordName(anId,theInfo->GetCoordName(anId));
442       
443       myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
444       for(TInt anId = 0; anId < aSpaceDim; anId++)
445         SetCoordUnit(anId,theInfo->GetCoordUnit(anId));
446     }
447
448     TTNodeInfo(const PMeshInfo& theMeshInfo, 
449                TInt theNbElem,
450                EModeSwitch theMode,
451                ERepere theSystem, 
452                EBooleen theIsElemNum,
453                EBooleen theIsElemNames):
454       TModeSwitchInfo(theMode),
455       TElemInfoBase(theMeshInfo,
456                     theNbElem,
457                     theIsElemNum,
458                     theIsElemNames)
459     {
460       mySystem = theSystem;
461
462       myCoord.reset(new TNodeCoord(theNbElem * theMeshInfo->mySpaceDim));
463
464       myCoordUnits.resize(theMeshInfo->mySpaceDim*GetPNOMLength<eVersion>()+1);
465
466       myCoordNames.resize(theMeshInfo->mySpaceDim*GetPNOMLength<eVersion>()+1);
467     }
468
469     
470     TTNodeInfo(const PMeshInfo& theMeshInfo, 
471                const TFloatVector& theNodeCoords,
472                EModeSwitch theMode,
473                ERepere theSystem, 
474                const TStringVector& theCoordNames,
475                const TStringVector& theCoordUnits,
476                const TIntVector& theFamilyNums,
477                const TIntVector& theElemNums,
478                const TStringVector& theElemNames):
479       TModeSwitchInfo(theMode),
480       TElemInfoBase(theMeshInfo,
481                     (TInt)theNodeCoords.size()/theMeshInfo->GetDim(),
482                     theFamilyNums,
483                     theElemNums,
484                     theElemNames)
485     {
486       mySystem = theSystem;
487
488       myCoord.reset(new TNodeCoord(theNodeCoords));
489       
490       TInt aSpaceDim = theMeshInfo->GetSpaceDim();
491
492       myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
493       if(!theCoordNames.empty())
494         for(TInt anId = 0; anId < aSpaceDim; anId++)
495           SetCoordName(anId,theCoordNames[anId]);
496       
497       myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>() + 1);
498       if(!theCoordUnits.empty())
499         for(TInt anId = 0; anId < aSpaceDim; anId++)
500           SetCoordUnit(anId, theCoordUnits[anId]);
501     }
502
503     virtual
504     std::string
505     GetCoordName(TInt theId) const 
506     { 
507       return GetString(theId,GetPNOMLength<eVersion>(),myCoordNames);
508     }
509
510     virtual
511     void
512     SetCoordName(TInt theId, const std::string& theValue)
513     {
514       SetString(theId,GetPNOMLength<eVersion>(),myCoordNames,theValue);
515     }
516
517     virtual
518     std::string 
519     GetCoordUnit(TInt theId) const 
520     { 
521       return GetString(theId,GetPNOMLength<eVersion>(),myCoordUnits);
522     }
523
524     virtual
525     void
526     SetCoordUnit(TInt theId, const std::string& theValue)
527     {
528       SetString(theId,GetPNOMLength<eVersion>(),myCoordUnits,theValue);
529     }
530   };
531
532   //---------------------------------------------------------------
533   template<EVersion eVersion>
534   struct TTPolygoneInfo: 
535     virtual TPolygoneInfo, 
536     virtual TTElemInfo<eVersion>
537   {
538     typedef TTElemInfo<eVersion> TElemInfoBase;
539
540     TTPolygoneInfo(const PMeshInfo& theMeshInfo, const PPolygoneInfo& theInfo):
541       TElemInfoBase(theMeshInfo,theInfo)
542     {
543       myEntity = theInfo->GetEntity();
544       myGeom = theInfo->GetGeom();
545
546       myIndex.reset(new TElemNum(*theInfo->myIndex));
547       myConn.reset(new TElemNum(*theInfo->myConn));
548
549       myConnMode = theInfo->GetConnMode();
550     }
551
552     TTPolygoneInfo(const PMeshInfo& theMeshInfo, 
553                    EEntiteMaillage theEntity, 
554                    EGeometrieElement theGeom,
555                    TInt theNbElem,
556                    TInt theConnSize,
557                    EConnectivite theConnMode,
558                    EBooleen theIsElemNum,
559                    EBooleen theIsElemNames):
560       TElemInfoBase(theMeshInfo,
561                     theNbElem,
562                     theIsElemNum,
563                     theIsElemNames)
564     {
565       myEntity = theEntity;
566       myGeom = theGeom;
567
568       myIndex.reset(new TElemNum(theNbElem + 1));
569       myConn.reset(new TElemNum(theConnSize));
570
571       myConnMode = theConnMode;
572     }
573     
574     TTPolygoneInfo(const PMeshInfo& theMeshInfo, 
575                    EEntiteMaillage theEntity, 
576                    EGeometrieElement theGeom,
577                    const TIntVector& theIndexes,
578                    const TIntVector& theConnectivities,
579                    EConnectivite theConnMode,
580                    const TIntVector& theFamilyNums,
581                    const TIntVector& theElemNums,
582                    const TStringVector& theElemNames):
583       TElemInfoBase(theMeshInfo,
584                     (TInt)theIndexes.size() - 1,
585                     theFamilyNums,
586                     theElemNums,
587                     theElemNames)
588     {
589       myEntity = theEntity;
590       myGeom = theGeom;
591
592       myIndex.reset(new TElemNum(theIndexes));
593       myConn.reset(new TElemNum(theConnectivities));
594
595       myConnMode = theConnMode;
596     }
597   };
598   
599   //---------------------------------------------------------------
600   template<EVersion eVersion>
601   struct TTPolyedreInfo: 
602     virtual TPolyedreInfo, 
603     virtual TTElemInfo<eVersion>
604   {
605     typedef TTElemInfo<eVersion> TElemInfoBase;
606
607     TTPolyedreInfo(const PMeshInfo& theMeshInfo, const PPolyedreInfo& theInfo):
608       TElemInfoBase(theMeshInfo,theInfo)
609     {
610       myEntity = theInfo->GetEntity();
611       myGeom = theInfo->GetGeom();
612
613       myIndex.reset(new TElemNum(*theInfo->myIndex));
614       myFaces.reset(new TElemNum(*theInfo->myFaces));
615       myConn.reset(new TElemNum(*theInfo->myConn));
616
617       myConnMode = theInfo->GetConnMode();
618     }
619
620     TTPolyedreInfo(const PMeshInfo& theMeshInfo, 
621                    EEntiteMaillage theEntity, 
622                    EGeometrieElement theGeom,
623                    TInt theNbElem,
624                    TInt theNbFaces,
625                    TInt theConnSize,
626                    EConnectivite theConnMode,
627                    EBooleen theIsElemNum,
628                    EBooleen theIsElemNames):
629       TElemInfoBase(theMeshInfo,
630                     theNbElem,
631                     theIsElemNum,
632                     theIsElemNames)
633     {
634       myEntity = theEntity;
635       myGeom = theGeom;
636
637       myIndex.reset(new TElemNum(theNbElem + 1));
638       myFaces.reset(new TElemNum(theNbFaces));
639       myConn.reset(new TElemNum(theConnSize));
640
641       myConnMode = theConnMode;
642     }
643     
644     TTPolyedreInfo(const PMeshInfo& theMeshInfo, 
645                    EEntiteMaillage theEntity, 
646                    EGeometrieElement theGeom,
647                    const TIntVector& theIndexes,
648                    const TIntVector& theFaces,
649                    const TIntVector& theConnectivities,
650                    EConnectivite theConnMode,
651                    const TIntVector& theFamilyNums,
652                    const TIntVector& theElemNums,
653                    const TStringVector& theElemNames):
654       TElemInfoBase(theMeshInfo,
655                     (TInt)theIndexes.size()-1,
656                     theFamilyNums,
657                     theElemNums,
658                     theElemNames)
659     {
660       myEntity = theEntity;
661       myGeom = theGeom;
662
663       myIndex.reset(new TElemNum(theIndexes));
664       myFaces.reset(new TElemNum(theFaces));
665       myConn.reset(new TElemNum(theConnectivities));
666
667       myConnMode = theConnMode;
668     }
669   };
670
671   //---------------------------------------------------------------
672   template<EVersion eVersion>
673   struct TTCellInfo: 
674     virtual TCellInfo, 
675     virtual TTElemInfo<eVersion>
676   {
677     typedef TTElemInfo<eVersion> TElemInfoBase;
678
679     TTCellInfo(const PMeshInfo& theMeshInfo, const PCellInfo& theInfo):
680       TElemInfoBase(theMeshInfo,theInfo)
681     {
682       myEntity = theInfo->GetEntity();
683       myGeom = theInfo->GetGeom();
684       myConnMode  = theInfo->GetConnMode();
685       
686       TInt aConnDim = GetNbNodes(myGeom);
687       TInt aNbConn = GetNbConn<eVersion>(myGeom, myEntity, myMeshInfo->myDim);
688       myConn.reset(new TElemNum(myNbElem * aNbConn));
689       for(TInt anElemId = 0; anElemId < myNbElem; anElemId++){
690         TConnSlice aConnSlice = GetConnSlice(anElemId);
691         TCConnSlice aConnSlice2 = theInfo->GetConnSlice(anElemId);
692         for(TInt anConnId = 0; anConnId < aConnDim; anConnId++){
693           aConnSlice[anConnId] = aConnSlice2[anConnId];
694         }
695       }
696     }
697
698     TTCellInfo(const PMeshInfo& theMeshInfo, 
699                EEntiteMaillage theEntity, 
700                EGeometrieElement theGeom,
701                TInt theNbElem,
702                EConnectivite theConnMode,
703                EBooleen theIsElemNum,
704                EBooleen theIsElemNames,
705                EModeSwitch theMode):
706       TModeSwitchInfo(theMode),
707       TElemInfoBase(theMeshInfo,
708                     theNbElem,
709                     theIsElemNum,
710                     theIsElemNames)
711     {
712       myEntity = theEntity;
713       myGeom = theGeom;
714
715       myConnMode = theConnMode;
716       TInt aNbConn = GetNbConn<eVersion>(theGeom, myEntity, theMeshInfo->myDim);
717       myConn.reset(new TElemNum(theNbElem * aNbConn));
718     }
719     
720     TTCellInfo(const PMeshInfo& theMeshInfo, 
721                EEntiteMaillage theEntity, 
722                EGeometrieElement theGeom,
723                const TIntVector& theConnectivities,
724                EConnectivite theConnMode,
725                const TIntVector& theFamilyNums,
726                const TIntVector& theElemNums,
727                const TStringVector& theElemNames,
728                EModeSwitch theMode):
729       TModeSwitchInfo(theMode),
730       TElemInfoBase(theMeshInfo,
731                     (TInt)theConnectivities.size() / GetNbNodes(theGeom),
732                     theFamilyNums,
733                     theElemNums,
734                     theElemNames)
735     {
736       myEntity = theEntity;
737       myGeom = theGeom;
738
739       myConnMode = theConnMode;
740       TInt aConnDim = GetNbNodes(myGeom);
741       TInt aNbConn = GetNbConn<eVersion>(myGeom, myEntity, myMeshInfo->myDim);
742       myConn.reset(new TElemNum(myNbElem * aNbConn));
743       for(TInt anElemId = 0; anElemId < myNbElem; anElemId++){
744         TConnSlice aConnSlice = GetConnSlice(anElemId);
745         for(TInt anConnId = 0; anConnId < aConnDim; anConnId++){
746           aConnSlice[anConnId] = theConnectivities[anElemId*aConnDim + anConnId];
747         }
748       }
749     }
750
751     virtual 
752     TInt
753     GetConnDim() const 
754     { 
755       return GetNbConn<eVersion>(myGeom, myEntity, myMeshInfo->myDim);
756     }
757
758   };
759
760   //---------------------------------------------------------------
761   template<EVersion eVersion>
762   struct TTBallInfo: 
763     virtual TBallInfo,
764     virtual TTCellInfo<eVersion>
765   {
766     typedef TTCellInfo<eVersion> TCellInfoBase;
767
768     TTBallInfo(const PMeshInfo& theMeshInfo, const PBallInfo& theInfo):
769       TCellInfoBase::TElemInfoBase(theMeshInfo, theInfo),
770       TCellInfoBase(theMeshInfo,theInfo)
771     {
772       myDiameters = theInfo->myDiameters;
773     }
774
775     TTBallInfo(const PMeshInfo& theMeshInfo,
776                TInt             theNbElem,
777                EBooleen         theIsElemNum ):
778       TCellInfoBase::TElemInfoBase(theMeshInfo,
779                                    theNbElem,
780                                    theIsElemNum,
781                                    /*theIsElemNames=*/eFAUX),
782       TCellInfoBase(theMeshInfo,
783                     eSTRUCT_ELEMENT,
784                     eBALL,
785                     theNbElem,
786                     /*EConnectivite=*/eNOD,
787                     theIsElemNum,
788                     /*theIsElemNames=*/eFAUX,
789                     eFULL_INTERLACE)
790     {
791       myDiameters.resize( theNbElem );
792     }
793
794     TTBallInfo(const PMeshInfo&  theMeshInfo, 
795                const TIntVector& theNodes,
796                TFloatVector&     theDiameters,
797                const TIntVector& theFamilyNums,
798                const TIntVector& theElemNums):
799       TCellInfoBase::TElemInfoBase(theMeshInfo,
800                                    (TInt)std::max(theNodes.size(),theDiameters.size() ),
801                                    theFamilyNums,
802                                    theElemNums,
803                                    TStringVector()),
804       TCellInfoBase(theMeshInfo,
805                     eSTRUCT_ELEMENT,
806                     eBALL,
807                     theNodes,
808                     /*EConnectivite=*/eNOD,
809                     theFamilyNums,
810                     theElemNums,
811                     TStringVector(),
812                     eFULL_INTERLACE)
813     {
814       myDiameters.swap( theDiameters );
815     }
816   };
817
818   //---------------------------------------------------------------
819   template<EVersion eVersion>
820   struct TTFieldInfo: 
821     virtual TFieldInfo, 
822     virtual TTNameInfo<eVersion>
823   {
824     typedef TTNameInfo<eVersion> TNameInfoBase;
825
826     TTFieldInfo(const PMeshInfo& theMeshInfo, const PFieldInfo& theInfo):
827       TNameInfoBase(theInfo->GetName())
828     {
829       myMeshInfo = theMeshInfo;
830
831       myNbComp = theInfo->GetNbComp();
832       myCompNames.resize(myNbComp*GetPNOMLength<eVersion>()+1);
833       for(TInt anId = 0; anId < myNbComp; anId++){
834         SetCompName(anId,theInfo->GetCompName(anId));
835       }
836
837       myUnitNames.resize(myNbComp*GetPNOMLength<eVersion>()+1);
838       for(TInt anId = 0; anId < myNbComp; anId++){
839         SetUnitName(anId,theInfo->GetUnitName(anId));
840       }
841
842       myType = theInfo->GetType();
843
844       myIsLocal = theInfo->GetIsLocal();
845       myNbRef = theInfo->GetNbRef();
846     }
847
848     TTFieldInfo(const PMeshInfo& theMeshInfo, 
849                 TInt theNbComp,
850                 ETypeChamp theType,
851                 const std::string& theValue,
852                 EBooleen theIsLocal,
853                 TInt theNbRef):
854       TNameInfoBase(theValue)
855     {
856       myMeshInfo = theMeshInfo;
857
858       myNbComp = theNbComp;
859       myCompNames.resize(theNbComp*GetPNOMLength<eVersion>()+1);
860       myUnitNames.resize(theNbComp*GetPNOMLength<eVersion>()+1);
861
862       myType = theType;
863
864       myIsLocal = theIsLocal;
865       myNbRef = theNbRef;
866     }
867     
868     virtual 
869     std::string
870     GetCompName(TInt theId) const 
871     { 
872       return GetString(theId,GetPNOMLength<eVersion>(),myCompNames);
873     }
874
875     virtual
876     void
877     SetCompName(TInt theId, const std::string& theValue)
878     {
879       SetString(theId,GetPNOMLength<eVersion>(),myCompNames,theValue);
880     }
881
882     virtual
883     std::string 
884     GetUnitName(TInt theId) const 
885     { 
886       return GetString(theId,GetPNOMLength<eVersion>(),myUnitNames);
887     }
888
889     virtual
890     void
891     SetUnitName(TInt theId, const std::string& theValue)
892     {
893       SetString(theId,GetPNOMLength<eVersion>(),myUnitNames,theValue);
894     }
895   };
896
897
898   //---------------------------------------------------------------
899   template<EVersion eVersion>
900   struct TTGaussInfo: 
901     virtual TGaussInfo,
902     virtual TTNameInfo<eVersion>
903   {
904     typedef TTNameInfo<eVersion> TNameInfoBase;
905
906     TTGaussInfo(const TGaussInfo::TInfo& theInfo,
907                 EModeSwitch theMode):
908       TModeSwitchInfo(theMode),
909       TNameInfoBase(boost::get<1>(boost::get<0>(theInfo)))
910     {
911       const TGaussInfo::TKey& aKey = boost::get<0>(theInfo);
912
913       myGeom = boost::get<0>(aKey);
914       myRefCoord.resize(GetNbRef()*GetDim());
915
916       TInt aNbGauss = boost::get<1>(theInfo);
917       myGaussCoord.resize(aNbGauss*GetDim());
918       myWeight.resize(aNbGauss);
919     }
920   };
921
922
923   //---------------------------------------------------------------
924   template<EVersion eVersion>
925   struct TTTimeStampInfo: virtual TTimeStampInfo
926   {
927     TTTimeStampInfo(const PFieldInfo& theFieldInfo, const PTimeStampInfo& theInfo)
928     {
929       myFieldInfo = theFieldInfo;
930
931       myEntity = theInfo->GetEntity();
932       myGeom2Size = theInfo->GetGeom2Size();
933
934       myNumDt = theInfo->GetNumDt();
935       myNumOrd = theInfo->GetNumOrd();
936       myDt = theInfo->GetDt();
937
938       myUnitDt.resize(GetPNOMLength<eVersion>()+1);
939       SetUnitDt(theInfo->GetUnitDt());
940
941       myGeom2NbGauss = theInfo->myGeom2NbGauss;
942       myGeom2Gauss = theInfo->GetGeom2Gauss();
943     }
944
945     TTTimeStampInfo(const PFieldInfo& theFieldInfo, 
946                     EEntiteMaillage theEntity,
947                     const TGeom2Size& theGeom2Size,
948                     const TGeom2NbGauss& theGeom2NbGauss,
949                     TInt theNumDt,
950                     TInt theNumOrd,
951                     TFloat theDt,
952                     const std::string& theUnitDt,
953                     const TGeom2Gauss& theGeom2Gauss)
954     {
955       myFieldInfo = theFieldInfo;
956
957       myEntity = theEntity;
958       myGeom2Size = theGeom2Size;
959
960       myNumDt = theNumDt;
961       myNumOrd = theNumDt;
962       myDt = theDt;
963
964       myUnitDt.resize(GetPNOMLength<eVersion>()+1);
965       SetUnitDt(theUnitDt);
966
967       myGeom2NbGauss = theGeom2NbGauss;
968       myGeom2Gauss = theGeom2Gauss;
969     }
970
971     virtual 
972     std::string
973     GetUnitDt() const
974     { 
975       return GetString(0,GetPNOMLength<eVersion>(),myUnitDt);
976     }
977
978     virtual
979     void
980     SetUnitDt(const std::string& theValue)
981     {
982       SetString(0,GetPNOMLength<eVersion>(),myUnitDt,theValue);
983     }
984   };
985
986
987   //---------------------------------------------------------------
988   template<EVersion eVersion>
989   struct TTProfileInfo: 
990     virtual TProfileInfo,
991     virtual TTNameInfo<eVersion>
992   {
993     typedef TTNameInfo<eVersion> TNameInfoBase;
994
995     TTProfileInfo(const TProfileInfo::TInfo& theInfo,
996                   EModeProfil theMode):
997       TNameInfoBase(boost::get<0>(theInfo))
998     {
999       TInt aSize = boost::get<1>(theInfo);
1000       myElemNum.reset(new TElemNum(aSize));
1001       myMode = aSize > 0? theMode: eNO_PFLMOD;
1002     }
1003   };
1004
1005
1006   //---------------------------------------------------------------
1007   template<EVersion eVersion, class TMeshValueType>
1008   struct TTTimeStampValue: virtual TTimeStampValue<TMeshValueType>
1009   {
1010     TTTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
1011                      const PTimeStampValueBase& theInfo,
1012                      ETypeChamp theTypeChamp)
1013     {
1014       typedef TTimeStampValue<TMeshValueType> TCompatible;
1015       if(TCompatible* aCompatible = dynamic_cast<TCompatible*>(theInfo.get())){
1016         this->myTimeStampInfo = theTimeStampInfo;
1017         this->myTypeChamp = theTypeChamp;
1018         this->myGeom2Profile = aCompatible->GetGeom2Profile();
1019         this->myGeom2Value = aCompatible->myGeom2Value;
1020         this->myGeomSet = aCompatible->GetGeomSet();
1021       }else
1022         EXCEPTION(std::runtime_error,"TTTimeStampValue::TTTimeStampValue - use incompatible arguments!");
1023     }
1024
1025     TTTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
1026                      ETypeChamp theTypeChamp,
1027                      const TGeom2Profile& theGeom2Profile,
1028                      EModeSwitch theMode):
1029       TModeSwitchInfo(theMode)
1030     {
1031       this->myTimeStampInfo = theTimeStampInfo;
1032
1033       this->myTypeChamp = theTypeChamp;
1034
1035       this->myGeom2Profile = theGeom2Profile;
1036
1037       TInt aNbComp = theTimeStampInfo->myFieldInfo->myNbComp;
1038
1039       const TGeom2Size& aGeom2Size = theTimeStampInfo->GetGeom2Size();
1040       TGeom2Size::const_iterator anIter = aGeom2Size.begin();
1041       for(; anIter != aGeom2Size.end(); anIter++){
1042         const EGeometrieElement& aGeom = anIter->first;
1043         TInt aNbElem = anIter->second;
1044
1045         MED::PProfileInfo aProfileInfo;
1046         MED::TGeom2Profile::const_iterator anIter = theGeom2Profile.find(aGeom);
1047         if(anIter != theGeom2Profile.end())
1048           aProfileInfo = anIter->second;
1049
1050         if(aProfileInfo && aProfileInfo->IsPresent())
1051           aNbElem = aProfileInfo->GetSize();
1052
1053         TInt aNbGauss = theTimeStampInfo->GetNbGauss(aGeom);
1054         
1055         this->GetMeshValue(aGeom).Allocate(aNbElem,aNbGauss,aNbComp);
1056       }
1057     }
1058
1059     virtual 
1060     size_t
1061     GetValueSize(EGeometrieElement theGeom) const
1062     {
1063       return this->GetMeshValue(theGeom).GetSize();
1064     }
1065
1066     virtual 
1067     size_t
1068     GetNbVal(EGeometrieElement theGeom) const
1069     {
1070       return this->GetMeshValue(theGeom).GetNbVal();
1071     }
1072
1073     virtual 
1074     size_t
1075     GetNbGauss(EGeometrieElement theGeom) const
1076     {
1077       return this->GetMeshValue(theGeom).GetNbGauss();
1078     }
1079
1080     virtual 
1081     void
1082     AllocateValue(EGeometrieElement theGeom,
1083                   TInt theNbElem,
1084                   TInt theNbGauss,
1085                   TInt theNbComp,
1086                   EModeSwitch theMode = eFULL_INTERLACE)
1087     {
1088       this->GetMeshValue(theGeom).Allocate(theNbElem,theNbGauss,theNbComp,theMode);
1089     }
1090     
1091     virtual 
1092     unsigned char*
1093     GetValuePtr(EGeometrieElement theGeom)
1094     {
1095       return this->GetMeshValue(theGeom).GetValuePtr();
1096     }
1097   };
1098
1099   //---------------------------------------------------------------
1100   template<EVersion eVersion>
1101   struct TTGrilleInfo:
1102     virtual TGrilleInfo
1103   {
1104     TTGrilleInfo(const PMeshInfo& theMeshInfo,
1105                  const PGrilleInfo& theInfo)
1106     {
1107       myMeshInfo        = theMeshInfo;
1108
1109       myCoord           = theInfo->GetNodeCoord();
1110       
1111       myGrilleType      = theInfo->GetGrilleType();
1112
1113       myCoordNames      = theInfo->myCoordNames;
1114
1115       myCoordUnits      = theInfo->myCoordUnits;
1116
1117       myIndixes         = theInfo->GetMapOfIndexes();
1118
1119       myGrilleStructure = theInfo->GetGrilleStructure();
1120
1121       myGrilleType      = theInfo->GetGrilleType();
1122
1123       myFamNumNode.resize(theInfo->GetNbNodes());
1124       myFamNumNode      = theInfo->myFamNumNode;
1125
1126       myFamNum      = theInfo->myFamNum;
1127     }
1128
1129     TTGrilleInfo(const PMeshInfo& theMeshInfo,
1130                  const EGrilleType& type,
1131                  const TInt nnoeuds)
1132     {
1133       myMeshInfo        = theMeshInfo;
1134       TInt aSpaceDim = theMeshInfo->GetSpaceDim();
1135       if(type == eGRILLE_STANDARD){
1136         myCoord.resize(aSpaceDim*nnoeuds);
1137         myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
1138         myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
1139       } else { //if(type == eGRILLE_CARTESIENNE){
1140         myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+aSpaceDim);
1141         myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+aSpaceDim);
1142       }
1143       myGrilleStructure.resize(aSpaceDim);
1144       myFamNumNode.resize(nnoeuds);
1145     }
1146
1147     TTGrilleInfo(const PMeshInfo& theMeshInfo,
1148                  const EGrilleType& type)
1149     {
1150       myMeshInfo        = theMeshInfo;
1151       TInt aSpaceDim = theMeshInfo->GetSpaceDim();
1152       if(type == eGRILLE_STANDARD){
1153         myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
1154         myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
1155       } else {// if(type == eGRILLE_CARTESIENNE){
1156         myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+aSpaceDim);
1157         myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+aSpaceDim);
1158       }
1159       myGrilleStructure.resize(aSpaceDim);
1160     }
1161
1162     TTGrilleInfo(const PMeshInfo& theMeshInfo,
1163                  const EGrilleType& type,
1164                  const MED::TIntVector& nbNodeVec)
1165     {
1166       myMeshInfo        = theMeshInfo;
1167
1168       TInt aSpaceDim = theMeshInfo->GetSpaceDim();
1169       if(type == eGRILLE_STANDARD){
1170         myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
1171         myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+1);
1172       } else {// if(type == eGRILLE_CARTESIENNE){
1173         myCoordNames.resize(aSpaceDim*GetPNOMLength<eVersion>()+aSpaceDim);
1174         myCoordUnits.resize(aSpaceDim*GetPNOMLength<eVersion>()+aSpaceDim);
1175       }
1176
1177       if(type != eGRILLE_STANDARD)
1178         for(unsigned int aAxe=0;aAxe<nbNodeVec.size();aAxe++){
1179           myIndixes[aAxe].resize(nbNodeVec[aAxe]);
1180         }
1181       myGrilleStructure.resize(aSpaceDim);
1182     }
1183
1184     virtual
1185     std::string
1186     GetCoordName(TInt theId) const 
1187     { 
1188       return GetString(theId,GetPNOMLength<eVersion>(),myCoordNames);
1189     }
1190
1191     virtual
1192     void
1193     SetCoordName(TInt theId, const std::string& theValue)
1194     {
1195       SetString(theId,GetPNOMLength<eVersion>(),myCoordNames,theValue);
1196     }
1197
1198     virtual
1199     std::string 
1200     GetCoordUnit(TInt theId) const 
1201     { 
1202       return GetString(theId,GetPNOMLength<eVersion>(),myCoordUnits);
1203     }
1204
1205     virtual
1206     void
1207     SetCoordUnit(TInt theId, const std::string& theValue)
1208     {
1209       SetString(theId,GetPNOMLength<eVersion>(),myCoordUnits,theValue);
1210     }
1211
1212   };
1213 }
1214
1215 #endif