Salome HOME
Merge branch 'V9_3_BR'
[modules/smesh.git] / src / MEDWrapper / MED_Wrapper.cxx
1 // Copyright (C) 2007-2019  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 #include "MED_Wrapper.hxx"
24 #include "MED_TStructures.hxx"
25 #include "MED_Utilities.hxx"
26
27 #include <med.h>
28 #include <med_err.h>
29 #include <med_proto.h>
30
31 #include <boost/version.hpp>
32
33 #ifdef _DEBUG_
34 static int MYDEBUG = 0;
35 static int MYVALUEDEBUG = 0;
36 #else
37 static int MYDEBUG = 0;
38 static int MYVALUEDEBUG = 0;
39 #endif
40
41 namespace MED
42 {
43   //---------------------------------------------------------------
44   TLockProxy
45   ::TLockProxy(TWrapper* theWrapper):
46     myWrapper(theWrapper)
47   {
48 #if BOOST_VERSION >= 103500
49     myWrapper->myMutex.lock();
50 #else
51     boost::detail::thread::lock_ops<TWrapper::TMutex>::lock(myWrapper->myMutex);
52 #endif
53     INITMSG(MYDEBUG, "TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
54   }
55
56   TLockProxy
57   ::~TLockProxy()
58   {
59     INITMSG(MYDEBUG, "~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
60 #if BOOST_VERSION >= 103500
61     myWrapper->myMutex.unlock();
62 #else
63     boost::detail::thread::lock_ops<TWrapper::TMutex>::unlock(myWrapper->myMutex);
64 #endif
65   }
66
67   TWrapper*
68   TLockProxy
69   ::operator->() const // never throws
70   {
71     return myWrapper;
72   }
73
74   //---------------------------------------------------------------
75   class TFile
76   {
77     TFile();
78     TFile(const TFile&);
79
80   public:
81     TFile(const std::string& theFileName, TInt theMinor=-1):
82       myCount(0),
83       myFid(0),
84       myFileName(theFileName),
85       myMinor(theMinor)
86     {
87       if ((myMinor < 0) || (myMinor > MED_MINOR_NUM)) myMinor = MED_MINOR_NUM;
88     }
89
90     ~TFile()
91     {
92       Close();
93     }
94
95     void
96     Open(EModeAcces theMode,
97          TErr* theErr = NULL)
98     {
99       if (myCount++ == 0) {
100         const char* aFileName = myFileName.c_str();
101         myFid = MEDfileVersionOpen(aFileName,med_access_mode(theMode), MED_MAJOR_NUM, myMinor, MED_RELEASE_NUM);
102       }
103       if (theErr)
104         *theErr = TErr(myFid);
105       else if (myFid < 0)
106         EXCEPTION(std::runtime_error,"TFile - MEDfileVersionOpen('"<<myFileName<<"',"<<theMode<<"',"<< MED_MAJOR_NUM<<"',"<< myMinor<<"',"<< MED_RELEASE_NUM<<")");
107     }
108
109     const TIdt&
110     Id() const
111     {
112       if (myFid < 0)
113         EXCEPTION(std::runtime_error, "TFile - GetFid() < 0");
114       return myFid;
115     }
116
117     void
118     Close()
119     {
120       if (--myCount == 0)
121         MEDfileClose(myFid);
122     }
123
124   protected:
125     TInt myCount;
126     TIdt myFid;
127     std::string myFileName;
128     TInt myMinor;
129   };
130
131   //---------------------------------------------------------------
132   class TFileWrapper
133   {
134     PFile myFile;
135     TInt myMinor;
136
137   public:
138     TFileWrapper(const PFile& theFile,
139                  EModeAcces theMode,
140                  TErr* theErr = NULL,
141                  TInt theMinor=-1):
142       myFile(theFile),
143       myMinor(theMinor)
144     {
145       if (myMinor < 0) myMinor = MED_MINOR_NUM;
146       myFile->Open(theMode, theErr);
147     }
148
149     ~TFileWrapper()
150     {
151       myFile->Close();
152     }
153   };
154
155   //----------------------------------------------------------------------------
156   template<class TimeStampValueType>
157   void
158   Print(SharedPtr<TimeStampValueType> theTimeStampValue)
159   {
160     INITMSG(MYDEBUG,"Print - TimeStampValue\n");
161     typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value;
162     typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
163     for (; anIter != aGeom2Value.end(); anIter++) {
164       const EGeometrieElement& aGeom = anIter->first;
165       const typename TimeStampValueType::TTMeshValue& aMeshValue = anIter->second;
166       TInt aNbElem = aMeshValue.myNbElem;
167       TInt aNbGauss = aMeshValue.myNbGauss;
168       TInt aNbComp = aMeshValue.myNbComp;
169       INITMSG(MYDEBUG, "aGeom = "<<aGeom<<" - "<<aNbElem<<": ");
170       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
171         typename TimeStampValueType::TTMeshValue::TCValueSliceArr aValueSliceArr =
172           aMeshValue.GetGaussValueSliceArr(iElem);
173         ADDMSG(MYVALUEDEBUG, "{");
174         for (TInt iGauss = 0; iGauss < aNbGauss; iGauss++) {
175           const typename TimeStampValueType::TTMeshValue::TCValueSlice& aValueSlice =
176             aValueSliceArr[iGauss];
177           for (TInt iComp = 0; iComp < aNbComp; iComp++) {
178             ADDMSG(MYVALUEDEBUG, aValueSlice[iComp]<<" ");
179           }
180           ADDMSG(MYVALUEDEBUG, "| ");
181         }
182         ADDMSG(MYVALUEDEBUG, "} ");
183       }
184       ADDMSG(MYDEBUG, "\n");
185     }
186   }
187
188   //---------------------------------------------------------------
189   TWrapper
190   ::TWrapper(const std::string& theFileName, bool write, TInt theMinor):
191     myFile(new TFile(theFileName, theMinor)),
192     myMinor(theMinor)
193   {
194     TErr aRet;
195     if ( write ) {
196       myFile->Open(eLECTURE_ECRITURE, &aRet);
197       if (aRet < 0) {
198         myFile->Close();
199         myFile->Open(eCREATION, &aRet);
200       }
201     }
202     else {
203       myFile->Open(eLECTURE, &aRet);
204     }
205   }
206
207   //----------------------------------------------------------------------------
208   TWrapper::
209   ~TWrapper()
210   {
211   }
212
213   //----------------------------------------------------------------------------
214   TInt
215   TWrapper
216   ::GetNbMeshes(TErr* theErr)
217   {
218     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
219
220     if (theErr && *theErr < 0)
221       return -1;
222
223     return MEDnMesh(myFile->Id());
224   }
225
226   //----------------------------------------------------------------------------
227   void
228   TWrapper
229   ::GetMeshInfo(TInt theMeshId,
230                 MED::TMeshInfo& theInfo,
231                 TErr* theErr)
232   {
233     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
234
235     if (theErr && *theErr < 0)
236       return;
237
238     TValueHolder<TString, char> aMeshName(theInfo.myName);
239     TValueHolder<TInt, med_int> aDim(theInfo.myDim);
240     TValueHolder<TInt, med_int> aSpaceDim(theInfo.mySpaceDim);
241     TValueHolder<EMaillage, med_mesh_type> aType(theInfo.myType);
242     char dtunit[MED_SNAME_SIZE+1];
243     med_sorting_type sorttype;
244     med_int nstep;
245     med_axis_type at;
246     int naxis = MEDmeshnAxis(myFile->Id(), theMeshId);
247     char *axisname = new char[naxis*MED_SNAME_SIZE+1];
248     char *axisunit = new char[naxis*MED_SNAME_SIZE+1];
249     TErr aRet = MEDmeshInfo(myFile->Id(),
250                             theMeshId,
251                             &aMeshName,
252                             &aSpaceDim,
253                             &aDim,
254                             &aType,
255                             &theInfo.myDesc[0],
256                             dtunit,
257                             &sorttype,
258                             &nstep,
259                             &at,
260                             axisname,
261                             axisunit);
262     delete [] axisname;
263     delete [] axisunit;
264     if (aRet < 0)
265       EXCEPTION(std::runtime_error, "GetMeshInfo - MEDmeshInfo(...)");
266   }
267
268   //----------------------------------------------------------------------------
269   void
270   TWrapper
271   ::SetMeshInfo(const MED::TMeshInfo& theInfo,
272                 TErr* theErr)
273   {
274     TErr aRet;
275     SetMeshInfo(theInfo, eLECTURE_ECRITURE, &aRet);
276
277     if (aRet < 0)
278       SetMeshInfo(theInfo, eLECTURE_AJOUT, &aRet);
279
280     if (aRet < 0)
281       SetMeshInfo(theInfo, eCREATION, &aRet);
282
283     if (theErr)
284       *theErr = aRet;
285   }
286
287   //----------------------------------------------------------------------------
288   void
289   TWrapper
290   ::SetMeshInfo(const MED::TMeshInfo& theInfo,
291                 EModeAcces theMode,
292                 TErr* theErr)
293   {
294     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
295
296     if (theErr && *theErr < 0)
297       return;
298
299     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
300
301     TValueHolder<TString, char> aMeshName(anInfo.myName);
302     TValueHolder<TInt, med_int> aDim(anInfo.myDim);
303     TValueHolder<TInt, med_int> aSpaceDim(anInfo.mySpaceDim);
304     TValueHolder<EMaillage, med_mesh_type> aType(anInfo.myType);
305     TValueHolder<TString, char> aDesc(anInfo.myDesc);
306
307     char *nam = new char[aSpaceDim*MED_SNAME_SIZE+1];
308     std::fill(nam, nam+aSpaceDim*MED_SNAME_SIZE+1, '\0');
309     char *unit = new char[aSpaceDim*MED_SNAME_SIZE+1];
310     std::fill(unit, unit+aSpaceDim*MED_SNAME_SIZE+1, '\0');
311     TErr aRet = MEDmeshCr(myFile->Id(),
312                           &aMeshName,
313                           aSpaceDim,
314                           aDim,
315                           aType,
316                           &aDesc,
317                           "",
318                           MED_SORT_DTIT,
319                           MED_CARTESIAN,
320                           nam,
321                           unit);
322     delete [] nam;
323     delete [] unit;
324
325     //if (aRet == 0)
326     //  aRet = MEDunvCr(myFile->Id(),&aMeshName);
327
328     INITMSG(MYDEBUG, "TWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
329
330     if (theErr)
331       *theErr = aRet;
332     else if (aRet < 0)
333       EXCEPTION(std::runtime_error, "SetMeshInfo - MEDmeshCr(...)");
334   }
335
336   //----------------------------------------------------------------------------
337   PMeshInfo
338   TWrapper
339   ::CrMeshInfo(TInt theDim,
340                TInt theSpaceDim,
341                const std::string& theValue,
342                EMaillage theType,
343                const std::string& theDesc)
344   {
345     return PMeshInfo(new TTMeshInfo
346                      (theDim,
347                       theSpaceDim,
348                       theValue,
349                       theType,
350                       theDesc));
351   }
352
353   //----------------------------------------------------------------------------
354   PMeshInfo
355   TWrapper
356   ::CrMeshInfo(const PMeshInfo& theInfo)
357   {
358     return PMeshInfo(new TTMeshInfo(theInfo));
359   }
360
361   //----------------------------------------------------------------------------
362   PMeshInfo
363   TWrapper
364   ::GetPMeshInfo(TInt theId,
365                  TErr* theErr)
366   {
367     PMeshInfo anInfo = CrMeshInfo();
368     GetMeshInfo(theId, *anInfo, theErr);
369     return anInfo;
370   }
371
372   //----------------------------------------------------------------------------
373   TInt
374   TWrapper
375   ::GetNbFamilies(const MED::TMeshInfo& theInfo,
376                   TErr* theErr)
377   {
378     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
379
380     if (theErr && *theErr < 0)
381       return -1;
382
383     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
384     TValueHolder<TString, char> aName(anInfo.myName);
385     return MEDnFamily(myFile->Id(), &aName);
386   }
387
388   //----------------------------------------------------------------------------
389   TInt
390   TWrapper
391   ::GetNbFamAttr(TInt theFamId,
392                  const MED::TMeshInfo& theInfo,
393                  TErr* theErr)
394   {
395     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
396
397     if (theErr && *theErr < 0)
398       return -1;
399
400     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
401
402     TValueHolder<TString, char> aName(anInfo.myName);
403
404     return MEDnFamily23Attribute(myFile->Id(), &aName, theFamId);
405   }
406
407   //----------------------------------------------------------------------------
408   TInt
409   TWrapper
410   ::GetNbFamGroup(TInt theFamId,
411                   const MED::TMeshInfo& theInfo,
412                   TErr* theErr)
413   {
414     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
415
416     if (theErr && *theErr < 0)
417       return -1;
418
419     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
420
421     TValueHolder<TString, char> aName(anInfo.myName);
422
423     return MEDnFamilyGroup(myFile->Id(), &aName, theFamId);
424   }
425
426   //----------------------------------------------------------------------------
427   void
428   TWrapper
429   ::GetFamilyInfo(TInt theFamId,
430                   MED::TFamilyInfo& theInfo,
431                   TErr* theErr)
432   {
433     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
434
435     if (theErr && *theErr < 0)
436       return;
437
438     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
439
440     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
441     TValueHolder<TString, char> aFamilyName(theInfo.myName);
442     TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
443     TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
444     TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
445     TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
446     TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
447
448     TErr aRet = MEDfamily23Info(myFile->Id(),
449                                 &aMeshName,
450                                 theFamId,
451                                 &aFamilyName,
452                                 &anAttrId,
453                                 &anAttrVal,
454                                 &anAttrDesc,
455                                 &aFamilyId,
456                                 &aGroupNames);
457
458     if (theErr)
459       *theErr = aRet;
460     else if (aRet < 0)
461       EXCEPTION(std::runtime_error, "GetFamilyInfo - MEDfamily23Info(...) - "<<
462                 " aMeshInfo.myName = '"<<&aMeshName<<
463                 "'; theFamId = "<<theFamId<<
464                 "; theInfo.myNbGroup = "<<theInfo.myNbGroup<<
465                 "; theInfo.myNbAttr = "<<theInfo.myNbAttr);
466   }
467
468   //----------------------------------------------------------------------------
469   void
470   TWrapper
471   ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
472                   TErr* theErr)
473   {
474     TErr aRet;
475     SetFamilyInfo(theInfo, eLECTURE_ECRITURE, &aRet);
476
477     if (aRet < 0)
478       SetFamilyInfo(theInfo, eLECTURE_AJOUT, &aRet);
479
480     if (theErr)
481       *theErr = aRet;
482   }
483
484   //----------------------------------------------------------------------------
485   void
486   TWrapper
487   ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
488                   EModeAcces theMode,
489                   TErr* theErr)
490   {
491     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
492
493     if (theErr && *theErr < 0)
494       return;
495
496     MED::TFamilyInfo& anInfo = const_cast<MED::TFamilyInfo&>(theInfo);
497     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
498
499     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
500     TValueHolder<TString, char> aFamilyName(anInfo.myName);
501     TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
502     TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
503     TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
504     TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
505     TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
506     TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
507     TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
508
509     TErr aRet = MEDfamilyCr(myFile->Id(),
510                             &aMeshName,
511                             &aFamilyName,
512                             aFamilyId,
513                             aNbGroup,
514                             &aGroupNames);
515
516     INITMSG(MYDEBUG, "TWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
517
518     if (theErr)
519       *theErr = aRet;
520     else if (aRet < 0)
521       EXCEPTION(std::runtime_error, "SetFamilyInfo - MEDfamilyCr(...)");
522   }
523
524   //----------------------------------------------------------------------------
525   PFamilyInfo
526   TWrapper
527   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
528                  TInt theNbGroup,
529                  TInt theNbAttr,
530                  TInt theId,
531                  const std::string& theValue)
532   {
533     return PFamilyInfo(new TTFamilyInfo
534                        (theMeshInfo,
535                         theNbGroup,
536                         theNbAttr,
537                         theId,
538                         theValue));
539   }
540
541   //----------------------------------------------------------------------------
542   PFamilyInfo
543   TWrapper
544   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
545                  const std::string& theValue,
546                  TInt theId,
547                  const MED::TStringSet& theGroupNames,
548                  const MED::TStringVector& theAttrDescs,
549                  const MED::TIntVector& theAttrIds,
550                  const MED::TIntVector& theAttrVals)
551   {
552     return PFamilyInfo(new TTFamilyInfo
553                        (theMeshInfo,
554                         theValue,
555                         theId,
556                         theGroupNames,
557                         theAttrDescs,
558                         theAttrIds,
559                         theAttrVals));
560   }
561
562   //----------------------------------------------------------------------------
563   PFamilyInfo
564   TWrapper
565   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
566                  const PFamilyInfo& theInfo)
567   {
568     return PFamilyInfo(new TTFamilyInfo
569                        (theMeshInfo,
570                         theInfo));
571   }
572
573   //----------------------------------------------------------------------------
574   PFamilyInfo
575   TWrapper
576   ::GetPFamilyInfo(const PMeshInfo& theMeshInfo,
577                    TInt theId,
578                    TErr* theErr)
579   {
580     // must be reimplemented in connection with mesh type eSTRUCTURE
581     //     if (theMeshInfo->GetType() != eNON_STRUCTURE)
582     //       return PFamilyInfo();
583
584     TInt aNbAttr = GetNbFamAttr(theId, *theMeshInfo);
585     TInt aNbGroup = GetNbFamGroup(theId, *theMeshInfo);
586     PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo, aNbGroup, aNbAttr);
587     GetFamilyInfo(theId, *anInfo, theErr);
588
589 #ifdef _DEBUG_
590     std::string aName = anInfo->GetName();
591     INITMSG(MYDEBUG, "GetPFamilyInfo - aFamilyName = '"<<aName<<
592             "'; andId = "<<anInfo->GetId()<<
593             "; aNbAttr = "<<aNbAttr<<
594             "; aNbGroup = "<<aNbGroup<<"\n");
595     for (TInt iGroup = 0; iGroup < aNbGroup; iGroup++) {
596       aName = anInfo->GetGroupName(iGroup);
597       INITMSG(MYDEBUG, "aGroupName = '"<<aName<<"'\n");
598     }
599 #endif
600
601     return anInfo;
602   }
603
604   //----------------------------------------------------------------------------
605   void
606   TWrapper
607   ::GetNames(TElemInfo& theInfo,
608              TInt theNb,
609              EEntiteMaillage theEntity,
610              EGeometrieElement theGeom,
611              TErr* theErr)
612   {
613     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
614
615     if (theErr && *theErr < 0)
616       return;
617
618     if (theGeom == eBALL)
619       theGeom = GetBallGeom(theInfo.myMeshInfo);
620
621     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
622
623     TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
624     TValueHolder<TString, char>                        anElemNames(theInfo.myElemNames);
625     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
626     TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
627
628     TErr aRet = MEDmeshEntityNameRd(myFile->Id(),
629                                     &aMeshName,
630                                     MED_NO_DT,
631                                     MED_NO_IT,
632                                     anEntity,
633                                     aGeom,
634                                     &anElemNames);
635
636     theInfo.myIsElemNames = aRet != 0? eFAUX : eVRAI ;
637
638     if (theErr)
639       *theErr = aRet;
640   }
641
642   //----------------------------------------------------------------------------
643   void
644   TWrapper
645   ::SetNames(const TElemInfo& theInfo,
646              EEntiteMaillage theEntity,
647              EGeometrieElement theGeom,
648              TErr* theErr)
649   {
650     SetNames(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
651   }
652
653   //----------------------------------------------------------------------------
654   void
655   TWrapper
656   ::SetNames(const TElemInfo& theInfo,
657              EModeAcces theMode,
658              EEntiteMaillage theEntity,
659              EGeometrieElement theGeom,
660              TErr* theErr)
661   {
662     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
663
664     if (theErr && *theErr < 0)
665       return;
666
667     if (theGeom == eBALL)
668       theGeom = GetBallGeom(theInfo.myMeshInfo);
669
670     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
671     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
672
673     TErr aRet = 0;
674     if (theInfo.myIsElemNames) {
675       TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
676       TValueHolder<TString, char>                        anElemNames(anInfo.myElemNames);
677       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
678       TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
679
680       aRet = MEDmeshEntityNameWr(myFile->Id(),
681                                  &aMeshName,
682                                  MED_NO_DT,
683                                  MED_NO_IT,
684                                  anEntity,
685                                   aGeom,
686                                  (TInt)anInfo.myElemNames->size(),
687                                  &anElemNames);
688       if (theErr)
689         *theErr = aRet;
690       else if (aRet < 0)
691         EXCEPTION(std::runtime_error, "SetNames - MEDmeshEntityNameWr(...)");
692     }
693   }
694
695   //----------------------------------------------------------------------------
696   void
697   TWrapper
698   ::GetNumeration(TElemInfo& theInfo,
699                   TInt theNb,
700                   EEntiteMaillage theEntity,
701                   EGeometrieElement theGeom,
702                   TErr* theErr)
703   {
704     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
705
706     if (theErr && *theErr < 0)
707       return;
708
709     if (theGeom == eBALL)
710       theGeom = GetBallGeom(theInfo.myMeshInfo);
711
712     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
713
714     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
715     TValueHolder<TElemNum, med_int>                    anElemNum(theInfo.myElemNum);
716     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
717     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
718
719     TErr aRet = MEDmeshEntityNumberRd(myFile->Id(),
720                                       &aMeshName,
721                                       MED_NO_DT,
722                                       MED_NO_IT,
723                                       anEntity,
724                                       aGeom,
725                                       &anElemNum);
726
727     theInfo.myIsElemNum = aRet != 0? eFAUX : eVRAI;
728
729     if (theErr)
730       *theErr = aRet;
731   }
732
733   //----------------------------------------------------------------------------
734   void
735   TWrapper
736   ::SetNumeration(const TElemInfo& theInfo,
737                   EEntiteMaillage theEntity,
738                   EGeometrieElement theGeom,
739                   TErr* theErr)
740   {
741     SetNumeration(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
742   }
743
744   //----------------------------------------------------------------------------
745   void
746   TWrapper
747   ::SetNumeration(const TElemInfo& theInfo,
748                   EModeAcces theMode,
749                   EEntiteMaillage theEntity,
750                   EGeometrieElement theGeom,
751                   TErr* theErr)
752   {
753     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
754
755     if (theErr && *theErr < 0)
756       return;
757
758     if (theGeom == eBALL)
759       theGeom = GetBallGeom(theInfo.myMeshInfo);
760
761     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
762     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
763
764     TErr aRet = 0;
765     if (theInfo.myIsElemNum) {
766       TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
767       TValueHolder<TElemNum, med_int>                    anElemNum(anInfo.myElemNum);
768       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
769       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
770
771       aRet = MEDmeshEntityNumberWr(myFile->Id(),
772                                    &aMeshName,
773                                    MED_NO_DT,
774                                    MED_NO_IT,
775                                    anEntity,
776                                    aGeom,
777                                    (TInt)anInfo.myElemNum->size(),
778                                    &anElemNum);
779       if (theErr)
780         *theErr = aRet;
781       else if (aRet < 0)
782         EXCEPTION(std::runtime_error, "SetNumeration - MEDmeshEntityNumberWr(...)");
783     }
784   }
785
786   //----------------------------------------------------------------------------
787   void
788   TWrapper
789   ::GetFamilies(TElemInfo& theInfo,
790                 TInt theNb,
791                 EEntiteMaillage theEntity,
792                 EGeometrieElement theGeom,
793                 TErr* theErr)
794   {
795     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
796
797     if (theErr && *theErr < 0)
798       return;
799
800     if (theGeom == eBALL)
801       theGeom = GetBallGeom(theInfo.myMeshInfo);
802
803     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
804
805     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
806     TValueHolder<TElemNum, med_int>                    aFamNum  (theInfo.myFamNum);
807     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
808     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
809
810     TErr aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
811                                             &aMeshName,
812                                             MED_NO_DT,
813                                             MED_NO_IT,
814                                             anEntity,
815                                             aGeom,
816                                             &aFamNum);
817
818     if (aRet < 0) {
819       //        if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
820       {
821         int aSize = (int)theInfo.myFamNum->size();
822         theInfo.myFamNum->clear();
823         theInfo.myFamNum->resize(aSize,0);
824         aRet = 0;
825       }
826       //        else
827       //          EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...) of CELLS");
828     }
829     if (theErr)
830       *theErr = aRet;
831   }
832
833   //----------------------------------------------------------------------------
834   void
835   TWrapper
836   ::SetFamilies(const TElemInfo& theInfo,
837                 EEntiteMaillage theEntity,
838                 EGeometrieElement theGeom,
839                 TErr* theErr)
840   {
841     SetFamilies(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
842   }
843
844   //----------------------------------------------------------------------------
845   void
846   TWrapper
847   ::SetFamilies(const TElemInfo& theInfo,
848                 EModeAcces theMode,
849                 EEntiteMaillage theEntity,
850                 EGeometrieElement theGeom,
851                 TErr* theErr)
852   {
853     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
854
855     if (theErr && *theErr < 0)
856       return;
857
858     if (theGeom == eBALL)
859       theGeom = GetBallGeom(theInfo.myMeshInfo);
860
861     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
862     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
863
864     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
865     TValueHolder<TElemNum, med_int>                    aFamNum  (anInfo.myFamNum);
866     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
867     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
868
869     TErr aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
870                                             &aMeshName,
871                                             MED_NO_DT,
872                                             MED_NO_IT,
873                                             anEntity,
874                                             aGeom,
875                                             (TInt)anInfo.myFamNum->size(),
876                                             &aFamNum);
877
878     if (theErr)
879       *theErr = aRet;
880     else if (aRet < 0)
881       EXCEPTION(std::runtime_error, "SetFamilies - MEDmeshEntityFamilyNumberWr(...)");
882   }
883
884   //----------------------------------------------------------------------------
885   TInt
886   TWrapper
887   ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
888                TErr* theErr)
889   {
890     return GetNbNodes(theMeshInfo, eCOOR, theErr);
891   }
892
893   //----------------------------------------------------------------------------
894   TInt
895   TWrapper
896   ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
897                ETable theTable,
898                TErr* theErr)
899   {
900     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
901
902     if (theErr && *theErr < 0)
903       return -1;
904
905     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
906
907     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
908     TValueHolder<ETable, med_data_type > aTable(theTable);
909     med_bool chgt,trsf;
910     return MEDmeshnEntity(myFile->Id(),
911                           &aMeshName,
912                           MED_NO_DT,
913                           MED_NO_IT,
914                           MED_NODE,
915                           MED_NO_GEOTYPE,
916                           aTable,
917                           MED_NO_CMODE,
918                           &chgt,
919                           &trsf);
920   }
921
922   //----------------------------------------------------------------------------
923   void
924   TWrapper
925   ::GetNodeInfo(MED::TNodeInfo& theInfo,
926                 TErr* theErr)
927   {
928     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
929
930     if (theErr && *theErr < 0)
931       return;
932
933     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
934
935     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
936     TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
937     TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
938     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
939     TValueHolder<ERepere, med_axis_type> aSystem(theInfo.mySystem);
940     TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
941     TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
942     TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
943     //TValueHolder<EBooleen, med_bool> anIsElemNames(theInfo.myIsElemNames);
944     TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
945     //TValueHolder<EBooleen, med_bool> anIsElemNum(theInfo.myIsElemNum);
946     TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
947     TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
948
949     TErr aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
950                                         &aMeshName,
951                                         MED_NO_DT,
952                                         MED_NO_IT,
953                                         aModeSwitch,
954                                         &aCoord);
955
956     TErr aRet2 =MEDmeshEntityFamilyNumberRd(myFile->Id(),
957                                             &aMeshName,
958                                             MED_NO_DT,
959                                             MED_NO_IT,
960                                             MED_NODE,
961                                             MED_NO_GEOTYPE,
962                                             &aFamNum);
963     if (aRet2 < 0) {
964       //        if (aRet2 == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
965       {
966         int mySize = (int)theInfo.myFamNum->size();
967         theInfo.myFamNum->clear();
968         theInfo.myFamNum->resize(mySize,0);
969       }
970       //        else
971       //          EXCEPTION(std::runtime_error,"GetNodeInfo - MEDmeshEntityFamilyNumberRd(...)");
972     }
973
974     if (MEDmeshEntityNameRd(myFile->Id(),
975                             &aMeshName,
976                             MED_NO_DT,
977                             MED_NO_IT,
978                             MED_NODE,
979                             MED_NO_GEOTYPE,
980                             &anElemNames) < 0) theInfo.myIsElemNames=eFAUX;
981
982     if (MEDmeshEntityNumberRd(myFile->Id(),
983                               &aMeshName,
984                               MED_NO_DT,
985                               MED_NO_IT,
986                               MED_NODE,
987                               MED_NO_GEOTYPE,
988                               &anElemNum) < 0) theInfo.myIsElemNum=eFAUX;
989
990     if (theErr)
991       *theErr = aRet;
992     else if (aRet < 0)
993       EXCEPTION(std::runtime_error, "GetNodeInfo - MEDmeshNodeCoordinateRd(...)");
994   }
995
996   //----------------------------------------------------------------------------
997   void
998   TWrapper
999   ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1000                 TErr* theErr)
1001   {
1002     TErr aRet;
1003     SetNodeInfo(theInfo, eLECTURE_ECRITURE, &aRet);
1004
1005     if (aRet < 0)
1006       SetNodeInfo(theInfo, eLECTURE_AJOUT, &aRet);
1007
1008     if (theErr)
1009       *theErr = aRet;
1010   }
1011
1012   //----------------------------------------------------------------------------
1013   void
1014   TWrapper
1015   ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1016                 EModeAcces theMode,
1017                 TErr* theErr)
1018   {
1019     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1020
1021     if (theErr && *theErr < 0)
1022       return;
1023
1024     MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
1025     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1026
1027     TValueHolder<TString, char>                aMeshName    (aMeshInfo.myName);
1028     TValueHolder<TNodeCoord, med_float>        aCoord       (anInfo.myCoord);
1029     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch  (anInfo.myModeSwitch);
1030     TValueHolder<ERepere, med_axis_type>       aSystem      (anInfo.mySystem);
1031     TValueHolder<TString, char>                aCoordNames  (anInfo.myCoordNames);
1032     TValueHolder<TString, char>                aCoordUnits  (anInfo.myCoordUnits);
1033     TValueHolder<TString, char>                anElemNames  (anInfo.myElemNames);
1034     TValueHolder<EBooleen, med_bool>           anIsElemNames(anInfo.myIsElemNames);
1035     TValueHolder<TElemNum, med_int>            anElemNum    (anInfo.myElemNum);
1036     TValueHolder<EBooleen, med_bool>           anIsElemNum  (anInfo.myIsElemNum);
1037     TValueHolder<TElemNum, med_int>            aFamNum      (anInfo.myFamNum);
1038     TValueHolder<TInt, med_int>                aNbElem      (anInfo.myNbElem);
1039
1040     TErr aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
1041                                         &aMeshName,
1042                                         MED_NO_DT,
1043                                         MED_NO_IT,
1044                                         MED_NO_DT,
1045                                         aModeSwitch,
1046                                         aNbElem,
1047                                         &aCoord);
1048
1049     MEDmeshEntityFamilyNumberWr(myFile->Id(),
1050                                 &aMeshName,
1051                                 MED_NO_DT,
1052                                 MED_NO_IT,
1053                                 MED_NODE,
1054                                 MED_NO_GEOTYPE,
1055                                 aNbElem,
1056                                 &aFamNum);
1057     if (anIsElemNames)
1058       MEDmeshEntityNameWr(myFile->Id(),
1059                           &aMeshName,
1060                           MED_NO_DT,
1061                           MED_NO_IT,
1062                           MED_NODE,
1063                           MED_NO_GEOTYPE,
1064                           aNbElem,
1065                           &anElemNames);
1066     if (anIsElemNum)
1067       MEDmeshEntityNumberWr(myFile->Id(),
1068                             &aMeshName,
1069                             MED_NO_DT,
1070                             MED_NO_IT,
1071                             MED_NODE,
1072                             MED_NO_GEOTYPE,
1073                             aNbElem,
1074                             &anElemNum);
1075     if (theErr)
1076       *theErr = aRet;
1077     else if (aRet < 0)
1078       EXCEPTION(std::runtime_error, "SetNodeInfo - MEDmeshNodeCoordinateWr(...)");
1079   }
1080
1081   //----------------------------------------------------------------------------
1082   PNodeInfo
1083   TWrapper
1084   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1085                TInt theNbElem,
1086                EModeSwitch theMode,
1087                ERepere theSystem,
1088                EBooleen theIsElemNum,
1089                EBooleen theIsElemNames)
1090   {
1091     return PNodeInfo(new TTNodeInfo
1092                      (theMeshInfo,
1093                       theNbElem,
1094                       theMode,
1095                       theSystem,
1096                       theIsElemNum,
1097                       theIsElemNames));
1098   }
1099
1100   //----------------------------------------------------------------------------
1101   PNodeInfo
1102   TWrapper
1103   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1104                const TFloatVector& theNodeCoords,
1105                EModeSwitch theMode,
1106                ERepere theSystem,
1107                const TStringVector& theCoordNames,
1108                const TStringVector& theCoordUnits,
1109                const TIntVector& theFamilyNums,
1110                const TIntVector& theElemNums,
1111                const TStringVector& theElemNames)
1112   {
1113     return PNodeInfo(new TTNodeInfo
1114                      (theMeshInfo,
1115                       theNodeCoords,
1116                       theMode,
1117                       theSystem,
1118                       theCoordNames,
1119                       theCoordUnits,
1120                       theFamilyNums,
1121                       theElemNums,
1122                       theElemNames));
1123   }
1124
1125   //----------------------------------------------------------------------------
1126   PNodeInfo
1127   TWrapper
1128   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1129                const PNodeInfo& theInfo)
1130   {
1131     return PNodeInfo(new TTNodeInfo
1132                      (theMeshInfo,
1133                       theInfo));
1134   }
1135
1136   //----------------------------------------------------------------------------
1137   PNodeInfo
1138   TWrapper
1139   ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
1140                  TErr* theErr)
1141   {
1142     TInt aNbElems = GetNbNodes(*theMeshInfo);
1143     if (aNbElems == 0) {
1144       return PNodeInfo();
1145     }
1146
1147     PNodeInfo anInfo = CrNodeInfo(theMeshInfo, aNbElems);
1148     GetNodeInfo(*anInfo, theErr);
1149
1150 #ifdef _DEBUG_
1151     TInt aDim = theMeshInfo->myDim;
1152     TInt aNbElem = anInfo->GetNbElem();
1153     INITMSG(MYDEBUG, "GetPNodeInfo: ");
1154     {
1155       INITMSG(MYDEBUG, "aCoords: "<<aNbElem<<": ");
1156       TNodeCoord& aCoord = anInfo->myCoord;
1157       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1158         for (TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++) {
1159           ADDMSG(MYVALUEDEBUG, aCoord[anId]<<",");
1160         }
1161         ADDMSG(MYVALUEDEBUG, " ");
1162       }
1163       ADDMSG(MYDEBUG, std::endl);
1164
1165       BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
1166       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1167         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
1168       }
1169       ADDMSG(MYVALUEDEBUG, std::endl);
1170
1171       if (anInfo->IsElemNum()) {
1172         BEGMSG(MYVALUEDEBUG, "GetElemNum: ");
1173         for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1174           ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
1175         }
1176         ADDMSG(MYVALUEDEBUG, std::endl);
1177       }
1178     }
1179     ADDMSG(MYDEBUG, std::endl);
1180 #endif
1181
1182     return anInfo;
1183   }
1184
1185   //----------------------------------------------------------------------------
1186   PElemInfo
1187   TWrapper
1188   ::CrElemInfo(const PMeshInfo& theMeshInfo,
1189                TInt theNbElem,
1190                EBooleen theIsElemNum,
1191                EBooleen theIsElemNames)
1192   {
1193     return PElemInfo(new TTElemInfo
1194                      (theMeshInfo,
1195                       theNbElem,
1196                       theIsElemNum,
1197                       theIsElemNames));
1198   }
1199
1200   //----------------------------------------------------------------------------
1201   PElemInfo
1202   TWrapper
1203   ::CrElemInfo(const PMeshInfo& theMeshInfo,
1204                TInt theNbElem,
1205                const TIntVector& theFamNum,
1206                const TIntVector& aElemNum,
1207                const TStringVector& aElemNames)
1208   {
1209     return PElemInfo(new TTElemInfo
1210                      (theMeshInfo,
1211                       theNbElem,
1212                       theFamNum,
1213                       aElemNum,
1214                       aElemNames));
1215   }
1216
1217   //----------------------------------------------------------------------------
1218   PElemInfo
1219   TWrapper
1220   ::GetPElemInfo(const PMeshInfo& theMeshInfo,
1221                  EEntiteMaillage theEntity,
1222                  EGeometrieElement theGeom,
1223                  EConnectivite theConnMode,
1224                  TErr* theErr)
1225   {
1226     EMaillage aType = theMeshInfo->GetType();
1227     if (aType == eNON_STRUCTURE) {
1228       switch (theGeom) {
1229       case ePOINT1:
1230         if (theEntity == eNOEUD)
1231           return GetPNodeInfo(theMeshInfo, theErr);
1232         return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1233         break;
1234       case ePOLYGONE:
1235         return GetPPolygoneInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1236         break;
1237       case ePOLYEDRE:
1238         return GetPPolyedreInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1239         break;
1240       default:
1241         return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1242       }
1243     }
1244     else {
1245       PGrilleInfo aGrille = GetPGrilleInfo(theMeshInfo);
1246
1247       TInt nbElems;
1248       EBooleen theIsElemNum = eFAUX;
1249       // nodes
1250       switch (theGeom) {
1251       case ePOINT1:
1252         nbElems = aGrille->GetNbNodes();
1253         theIsElemNum = eVRAI;
1254         break;
1255       case eSEG2:
1256       case eQUAD4:
1257       case eHEXA8:
1258         nbElems = aGrille->GetNbCells();
1259         break;
1260       default:
1261         nbElems = 0;
1262       }
1263
1264       TIntVector aFamNum;
1265       TIntVector aElemNum;
1266       TStringVector aElemNames;
1267
1268       PElemInfo aElemInfo;
1269
1270       if (theGeom == ePOINT1) {
1271         aElemInfo = CrElemInfo(theMeshInfo,
1272                                nbElems,
1273                                theIsElemNum);
1274         MED::TElemInfo &aTElemInfo = *aElemInfo;
1275
1276         // must be reimplemente in connection with mesh type eSTRUCTURE
1277         //      GetNumeration(aTElemInfo,
1278         //                    nbElems,
1279         //                    theEntity,
1280         //                    theGeom,
1281         //                    theErr);
1282
1283         GetFamilies(aTElemInfo,
1284                     nbElems,
1285                     theEntity,
1286                     theGeom,
1287                     theErr);
1288
1289         // must be reimplemente in connection with mesh type eSTRUCTURE
1290         //      GetNames(aTElemInfo,
1291         //               nbElems,
1292         //               theEntity,
1293         //               theGeom,
1294         //               theErr);
1295       }
1296       else {
1297         aElemInfo = CrElemInfo(theMeshInfo,
1298                                nbElems,
1299                                aFamNum,
1300                                aElemNum,
1301                                aElemNames);
1302       }
1303
1304       return aElemInfo;
1305     }
1306     return PElemInfo();
1307   }
1308
1309   //----------------------------------------------------------------------------
1310   TInt
1311   TWrapper
1312   ::GetNbPolygones(const MED::TMeshInfo& theMeshInfo,
1313                    EEntiteMaillage theEntity,
1314                    EGeometrieElement theGeom,
1315                    EConnectivite theConnMode,
1316                    TErr* theErr)
1317   {
1318     return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1319   }
1320
1321   //----------------------------------------------------------------------------
1322   TInt
1323   TWrapper
1324   ::GetPolygoneConnSize(const MED::TMeshInfo& theMeshInfo,
1325                         EEntiteMaillage theEntity,
1326                         EGeometrieElement theGeom,
1327                         EConnectivite theConnMode,
1328                         TErr* theErr)
1329   {
1330     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1331
1332     if (theErr && *theErr < 0)
1333       return 0;
1334
1335     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1336
1337     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1338     med_int aTaille = 0;
1339     med_bool chgt,trsf;
1340     aTaille=MEDmeshnEntity(myFile->Id(),
1341                            &aMeshName,
1342                            MED_NO_DT,
1343                            MED_NO_IT,
1344                            med_entity_type(theEntity),
1345                            med_geometry_type(theGeom),
1346                            MED_CONNECTIVITY,
1347                            med_connectivity_mode(theConnMode),
1348                            &chgt,
1349                            &trsf);
1350
1351     if (aTaille < 0)
1352       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1353
1354     return TInt(aTaille);
1355   }
1356
1357   //-----------------------------------------------------------------
1358   void
1359   TWrapper
1360   ::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
1361                     TErr* theErr)
1362   {
1363     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1364
1365     if (theErr && *theErr < 0)
1366       return;
1367
1368     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1369
1370     TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
1371     TValueHolder<TElemNum, med_int                   > anIndex  (theInfo.myIndex);
1372     TValueHolder<TElemNum, med_int                   > aConn    (theInfo.myConn);
1373     TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (theInfo.myEntity);
1374     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theInfo.myGeom);
1375     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1376     TInt aNbElem = (TInt)theInfo.myElemNum->size();
1377
1378     TErr aRet;
1379     aRet = MEDmeshPolygon2Rd(myFile->Id(), &aMeshName,
1380                              MED_NO_DT, MED_NO_IT,
1381                              anEntity, aGeom,
1382                              aConnMode, &anIndex, &aConn);
1383
1384     if (theErr)
1385       *theErr = aRet;
1386     else if (aRet < 0)
1387       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolygonRd(...)");
1388
1389     if (theInfo.myIsElemNames) {
1390       GetNames(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1391       if (theErr)
1392         *theErr = aRet;
1393     }
1394
1395     if (theInfo.myIsElemNum) {
1396       GetNumeration(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1397       if (theErr)
1398         *theErr = aRet;
1399     }
1400
1401     GetFamilies(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1402     if (theErr)
1403       *theErr = aRet;
1404   }
1405
1406   //----------------------------------------------------------------------------
1407   void
1408   TWrapper
1409   ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1410                     TErr* theErr)
1411   {
1412     SetPolygoneInfo(theInfo, eLECTURE_ECRITURE, theErr);
1413   }
1414
1415   //----------------------------------------------------------------------------
1416   void
1417   TWrapper
1418   ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1419                     EModeAcces theMode,
1420                     TErr* theErr)
1421   {
1422     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1423
1424     if (theErr && *theErr < 0)
1425       return;
1426
1427     MED::TPolygoneInfo& anInfo = const_cast<MED::TPolygoneInfo&>(theInfo);
1428     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1429
1430     TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
1431     TValueHolder<TElemNum, med_int                   > anIndex  (anInfo.myIndex);
1432     TValueHolder<TElemNum, med_int                   > aConn    (anInfo.myConn);
1433     TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (anInfo.myEntity);
1434     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (anInfo.myGeom);
1435     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1436
1437     TErr aRet = MEDmeshPolygon2Wr(myFile->Id(), &aMeshName,
1438                                   MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
1439                                   anEntity, aGeom,
1440                                   aConnMode, anInfo.myNbElem + 1,
1441                                   &anIndex, &aConn);
1442     if (theErr)
1443       *theErr = aRet;
1444     else if (aRet < 0)
1445       EXCEPTION(std::runtime_error, "SetPolygoneInfo - MEDmeshPolygonWr(...)");
1446
1447     SetNames(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1448     if (theErr)
1449       *theErr = aRet;
1450
1451     SetNumeration(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1452     if (theErr)
1453       *theErr = aRet;
1454
1455     SetFamilies(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1456     if (theErr)
1457       *theErr = aRet;
1458   }
1459
1460   //----------------------------------------------------------------------------
1461   PPolygoneInfo
1462   TWrapper
1463   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1464                    EEntiteMaillage theEntity,
1465                    EGeometrieElement theGeom,
1466                    TInt theNbElem,
1467                    TInt theConnSize,
1468                    EConnectivite theConnMode,
1469                    EBooleen theIsElemNum,
1470                    EBooleen theIsElemNames)
1471   {
1472     return PPolygoneInfo(new TTPolygoneInfo
1473                          (theMeshInfo,
1474                           theEntity,
1475                           theGeom,
1476                           theNbElem,
1477                           theConnSize,
1478                           theConnMode,
1479                           theIsElemNum,
1480                           theIsElemNames));
1481   }
1482
1483   //----------------------------------------------------------------------------
1484   PPolygoneInfo
1485   TWrapper
1486   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1487                    EEntiteMaillage theEntity,
1488                    EGeometrieElement theGeom,
1489                    const TIntVector& theIndexes,
1490                    const TIntVector& theConnectivities,
1491                    EConnectivite theConnMode,
1492                    const TIntVector& theFamilyNums,
1493                    const TIntVector& theElemNums,
1494                    const TStringVector& theElemNames)
1495   {
1496     return PPolygoneInfo(new TTPolygoneInfo
1497                          (theMeshInfo,
1498                           theEntity,
1499                           theGeom,
1500                           theIndexes,
1501                           theConnectivities,
1502                           theConnMode,
1503                           theFamilyNums,
1504                           theElemNums,
1505                           theElemNames));
1506   }
1507
1508   //----------------------------------------------------------------------------
1509   PPolygoneInfo
1510   TWrapper
1511   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1512                    const PPolygoneInfo& theInfo)
1513   {
1514     return PPolygoneInfo(new TTPolygoneInfo
1515                          (theMeshInfo,
1516                           theInfo));
1517   }
1518
1519   //----------------------------------------------------------------------------
1520   PPolygoneInfo
1521   TWrapper
1522   ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
1523                      EEntiteMaillage theEntity,
1524                      EGeometrieElement theGeom,
1525                      EConnectivite theConnMode)
1526   {
1527     if (theMeshInfo->GetType() != eNON_STRUCTURE)
1528       return PPolygoneInfo();
1529
1530     TInt aNbElem = GetNbPolygones(theMeshInfo, theEntity, theGeom, theConnMode);
1531     TInt aConnSize = GetPolygoneConnSize(theMeshInfo, theEntity, theGeom, theConnMode);
1532     PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo, theEntity, theGeom, aNbElem, aConnSize, theConnMode);
1533     GetPolygoneInfo(anInfo);
1534
1535 #ifdef _DEBUG_
1536     INITMSG(MYDEBUG, "GetPPolygoneInfo"<<
1537             " - theGeom = "<<theGeom<<
1538             "; aNbElem = "<<aNbElem<<": ");
1539     for (TInt iElem = 1; iElem < aNbElem; iElem++) {
1540       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
1541       TInt aConnDim = aConnSlice.size();
1542       for (TInt iConn = 0; iConn < aConnDim; iConn++) {
1543         ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1544       }
1545       ADDMSG(MYDEBUG, " ");
1546     }
1547     ADDMSG(MYDEBUG, std::endl);
1548 #endif
1549
1550     return anInfo;
1551   }
1552
1553   //----------------------------------------------------------------------------
1554   TInt
1555   TWrapper
1556   ::GetNbPolyedres(const MED::TMeshInfo& theMeshInfo,
1557                    EEntiteMaillage theEntity,
1558                    EGeometrieElement theGeom,
1559                    EConnectivite theConnMode,
1560                    TErr* theErr)
1561   {
1562     return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1563   }
1564
1565   //----------------------------------------------------------------------------
1566   void
1567   TWrapper
1568   ::GetPolyedreConnSize(const TMeshInfo& theMeshInfo,
1569                         TInt& theNbFaces,
1570                         TInt& theConnSize,
1571                         EConnectivite theConnMode,
1572                         TErr* theErr)
1573   {
1574     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1575
1576     if (theErr && *theErr < 0)
1577       EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)");
1578
1579     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1580
1581     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1582     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theConnMode);
1583     //TValueHolder<TInt, med_int> aNbFaces(theNbFaces);
1584     //TValueHolder<TInt, med_int> aConnSize(theConnSize);
1585
1586     med_bool chgt, trsf;
1587     theNbFaces = MEDmeshnEntity(myFile->Id(),
1588                                 &aMeshName,
1589                                 MED_NO_DT,
1590                                 MED_NO_IT,
1591                                 MED_CELL,
1592                                 MED_POLYHEDRON,
1593                                 MED_INDEX_NODE,
1594                                 aConnMode,
1595                                 &chgt,
1596                                 &trsf);
1597
1598     theConnSize = MEDmeshnEntity(myFile->Id(),
1599                                  &aMeshName,
1600                                  MED_NO_DT,
1601                                  MED_NO_IT,
1602                                  MED_CELL,
1603                                  MED_POLYHEDRON,
1604                                  MED_CONNECTIVITY,
1605                                  aConnMode,
1606                                  &chgt,
1607                                  &trsf);
1608
1609     if (theNbFaces < 0 || theConnSize<0)
1610       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1611
1612   }
1613
1614   //-----------------------------------------------------------------
1615   void
1616   TWrapper
1617   ::GetPolyedreInfo(TPolyedreInfo& theInfo,
1618                     TErr* theErr)
1619   {
1620     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1621
1622     if (theErr && *theErr < 0)
1623       return;
1624
1625     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1626
1627     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1628     TInt aNbElem = (TInt)theInfo.myElemNum->size();
1629     TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex);
1630     TValueHolder<TElemNum, med_int> aFaces(theInfo.myFaces);
1631     TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
1632     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1633
1634     TErr aRet;
1635     aRet = MEDmeshPolyhedronRd(myFile->Id(),
1636                                &aMeshName,
1637                                MED_NO_DT,
1638                                MED_NO_IT,
1639                                MED_CELL,
1640                                aConnMode,
1641                                &anIndex,
1642                                &aFaces,
1643                                &aConn);
1644
1645     if (theErr)
1646       *theErr = aRet;
1647     else if (aRet < 0)
1648       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolyhedronRd(...)");
1649
1650     if (theInfo.myIsElemNames) {
1651       GetNames(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1652       if (theErr)
1653         *theErr = aRet;
1654     }
1655
1656     if (theInfo.myIsElemNum) {
1657       GetNumeration(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1658       if (theErr)
1659         *theErr = aRet;
1660     }
1661
1662     GetFamilies(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1663     if (theErr)
1664       *theErr = aRet;
1665   }
1666
1667   //----------------------------------------------------------------------------
1668   void
1669   TWrapper
1670   ::SetPolyedreInfo(const TPolyedreInfo& theInfo,
1671                     TErr* theErr)
1672   {
1673     SetPolyedreInfo(theInfo, eLECTURE_ECRITURE, theErr);
1674   }
1675
1676   //----------------------------------------------------------------------------
1677   void
1678   TWrapper
1679   ::SetPolyedreInfo(const MED::TPolyedreInfo& theInfo,
1680                     EModeAcces theMode,
1681                     TErr* theErr)
1682   {
1683     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1684
1685     if (theErr && *theErr < 0)
1686       return;
1687
1688     MED::TPolyedreInfo& anInfo = const_cast<MED::TPolyedreInfo&>(theInfo);
1689     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1690
1691     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1692     TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex);
1693     TValueHolder<TElemNum, med_int> aFaces(anInfo.myFaces);
1694     TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
1695     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1696
1697     TErr aRet;
1698     aRet = MEDmeshPolyhedronWr(myFile->Id(),
1699                                &aMeshName,
1700                                MED_NO_DT,
1701                                MED_NO_IT,
1702                                MED_UNDEF_DT,
1703                                MED_CELL,
1704                                aConnMode,
1705                                anInfo.myNbElem+1,
1706                                &anIndex,
1707                                (TInt)anInfo.myFaces->size(),
1708                                &aFaces,
1709                                &aConn);
1710
1711     if (theErr)
1712       *theErr = aRet;
1713     else if (aRet < 0)
1714       EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshPolyhedronWr(...)");
1715
1716     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(anInfo.myEntity);
1717
1718     if (theInfo.myIsElemNames) {
1719       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
1720       aRet = MEDmeshEntityNameWr(myFile->Id(),
1721                                  &aMeshName,
1722                                  MED_NO_DT,
1723                                  MED_NO_IT,
1724                                  anEntity,
1725                                  MED_POLYHEDRON,
1726                                  (TInt)anInfo.myElemNames->size(),
1727                                  &anElemNames);
1728       if (theErr)
1729         *theErr = aRet;
1730       else if (aRet < 0)
1731         EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNameWr(...)");
1732     }
1733
1734     if (theInfo.myIsElemNum) {
1735       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
1736       aRet = MEDmeshEntityNumberWr(myFile->Id(),
1737                                    &aMeshName,
1738                                    MED_NO_DT,
1739                                    MED_NO_IT,
1740                                    anEntity,
1741                                    MED_POLYHEDRON,
1742                                    (TInt)anInfo.myElemNum->size(),
1743                                    &anElemNum);
1744       if (theErr)
1745         *theErr = aRet;
1746       else if (aRet < 0)
1747         EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNumberWr(...)");
1748     }
1749
1750     TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
1751     aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
1752                                        &aMeshName,
1753                                        MED_NO_DT,
1754                                        MED_NO_IT,
1755                                        anEntity,
1756                                        MED_POLYHEDRON,
1757                                        (TInt)anInfo.myFamNum->size(),
1758                                        &aFamNum);
1759
1760     if (theErr)
1761       *theErr = aRet;
1762     else if (aRet < 0)
1763       EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityFamilyNumberWr(...)");
1764   }
1765
1766   //----------------------------------------------------------------------------
1767   PPolyedreInfo
1768   TWrapper
1769   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1770                    EEntiteMaillage theEntity,
1771                    EGeometrieElement theGeom,
1772                    TInt theNbElem,
1773                    TInt theNbFaces,
1774                    TInt theConnSize,
1775                    EConnectivite theConnMode,
1776                    EBooleen theIsElemNum,
1777                    EBooleen theIsElemNames)
1778   {
1779     return PPolyedreInfo(new TTPolyedreInfo
1780                          (theMeshInfo,
1781                           theEntity,
1782                           theGeom,
1783                           theNbElem,
1784                           theNbFaces,
1785                           theConnSize,
1786                           theConnMode,
1787                           theIsElemNum,
1788                           theIsElemNames));
1789   }
1790
1791   //----------------------------------------------------------------------------
1792   PPolyedreInfo
1793   TWrapper
1794   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1795                    EEntiteMaillage theEntity,
1796                    EGeometrieElement theGeom,
1797                    const TIntVector& theIndexes,
1798                    const TIntVector& theFaces,
1799                    const TIntVector& theConnectivities,
1800                    EConnectivite theConnMode,
1801                    const TIntVector& theFamilyNums,
1802                    const TIntVector& theElemNums,
1803                    const TStringVector& theElemNames)
1804   {
1805     return PPolyedreInfo(new TTPolyedreInfo
1806                          (theMeshInfo,
1807                           theEntity,
1808                           theGeom,
1809                           theIndexes,
1810                           theFaces,
1811                           theConnectivities,
1812                           theConnMode,
1813                           theFamilyNums,
1814                           theElemNums,
1815                           theElemNames));
1816   }
1817
1818   //----------------------------------------------------------------------------
1819   PPolyedreInfo
1820   TWrapper
1821   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1822                    const PPolyedreInfo& theInfo)
1823   {
1824     return PPolyedreInfo(new TTPolyedreInfo
1825                          (theMeshInfo,
1826                           theInfo));
1827   }
1828
1829   //----------------------------------------------------------------------------
1830   PPolyedreInfo
1831   TWrapper
1832   ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
1833                      EEntiteMaillage theEntity,
1834                      EGeometrieElement theGeom,
1835                      EConnectivite theConnMode)
1836   {
1837     if (theMeshInfo->GetType() != eNON_STRUCTURE)
1838       return PPolyedreInfo();
1839     TInt aNbElem = GetNbPolyedres(theMeshInfo, theEntity, theGeom, theConnMode);
1840     TInt aNbFaces, aConnSize;
1841     GetPolyedreConnSize(theMeshInfo, aNbFaces, aConnSize, theConnMode);
1842     PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo, theEntity, theGeom, aNbElem, aNbFaces, aConnSize, theConnMode);
1843     GetPolyedreInfo(anInfo);
1844
1845 #ifdef _DEBUG_
1846     INITMSG(MYDEBUG, "GetPPolyedreInfo"<<
1847             " - theGeom = "<<theGeom<<
1848             "; aNbElem = "<<aNbElem<<": ");
1849     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1850       TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
1851       TInt aNbFaces = aConnSliceArr.size();
1852       ADDMSG(MYDEBUG, "{");
1853       for (TInt iFace = 0; iFace < aNbFaces; iFace++) {
1854         TCConnSlice aConnSlice = aConnSliceArr[iFace];
1855         TInt aNbConn = aConnSlice.size();
1856         ADDMSG(MYDEBUG, "[");
1857         for (TInt iConn = 0; iConn < aNbConn; iConn++) {
1858           ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1859         }
1860         ADDMSG(MYDEBUG, "] ");
1861       }
1862       ADDMSG(MYDEBUG, "} ");
1863     }
1864     ADDMSG(MYDEBUG, std::endl);
1865 #endif
1866
1867     return anInfo;
1868   }
1869
1870   //-----------------------------------------------------------------
1871   TEntityInfo
1872   TWrapper
1873   ::GetEntityInfo(const MED::TMeshInfo& theMeshInfo,
1874                   EConnectivite theConnMode,
1875                   TErr* theErr)
1876   {
1877     TEntityInfo anInfo;
1878
1879     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1880
1881     if (theErr && *theErr < 0)
1882       return anInfo;
1883
1884     if (theMeshInfo.GetType() == eNON_STRUCTURE) {
1885       TInt aNbElem = GetNbNodes(theMeshInfo);
1886       if (aNbElem > 0) {
1887         anInfo[eNOEUD][ePOINT1] = aNbElem;
1888         const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
1889         TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
1890         TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
1891         for (; anIter != anIterEnd; anIter++) {
1892           const EEntiteMaillage& anEntity = anIter->first;
1893           const TGeomSet& aGeomSet = anIter->second;
1894           TGeomSet::const_iterator anIter2 = aGeomSet.begin();
1895           TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
1896           for (; anIter2 != anIterEnd2; anIter2++) {
1897             const EGeometrieElement& aGeom = *anIter2;
1898             aNbElem = GetNbCells(theMeshInfo, anEntity, aGeom, theConnMode, theErr);
1899             if (aNbElem > 0) {
1900               if (anEntity == eSTRUCT_ELEMENT) {
1901                 const TInt nbStructTypes = aNbElem;
1902                 for (TInt structType = 0; structType < nbStructTypes; ++structType) {
1903                   // check type name to keep only "MED_BALL" structured element
1904                   TValueHolder<TString, char> aMeshName((TString&) theMeshInfo.myName);
1905                   char                        geotypename[ MED_NAME_SIZE + 1] = "";
1906                   med_geometry_type           geotype;
1907                   MEDmeshEntityInfo(myFile->Id(), &aMeshName, MED_NO_DT, MED_NO_IT,
1908                                     med_entity_type(anEntity), structType+1,
1909                                     geotypename, &geotype);
1910                   if (strcmp(geotypename, MED_BALL_NAME) == 0) {
1911                     aNbElem = GetNbCells(theMeshInfo, anEntity, EGeometrieElement(geotype),
1912                                          theConnMode, theErr);
1913                     if (aNbElem > 0)
1914                       anInfo[anEntity][EGeometrieElement(geotype)] = aNbElem;
1915                   }
1916                 }
1917               }
1918               else {
1919                 anInfo[anEntity][aGeom] = aNbElem;
1920               }
1921             }
1922           }
1923         }
1924       }
1925     }
1926     else { // eSTRUCTURE
1927       EGrilleType aGrilleType;
1928       TInt aNbNodes = 1;
1929       TInt aNbElem  = 1;
1930       TInt aNbSub   = 0;
1931       TInt aDim = theMeshInfo.GetDim();
1932       EGeometrieElement aGeom, aSubGeom;
1933       EEntiteMaillage aSubEntity = eMAILLE;
1934
1935       GetGrilleType(theMeshInfo, aGrilleType);
1936
1937       TIntVector aStruct(aDim);
1938       if (aGrilleType == eGRILLE_STANDARD)
1939         {
1940           GetGrilleStruct(theMeshInfo, aStruct, theErr);
1941         }
1942       else
1943         { // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
1944           ETable aTable[3] = { eCOOR_IND1, eCOOR_IND2, eCOOR_IND3 };
1945           for (med_int anAxis = 0; anAxis < aDim; anAxis++)
1946             aStruct[ anAxis ] = GetNbNodes(theMeshInfo, aTable[anAxis]);
1947         }
1948       for (med_int i = 0; i < aDim; i++) {
1949         aNbNodes = aNbNodes * aStruct[i];
1950         aNbElem = aNbElem * (aStruct[i] - 1);
1951       }
1952       switch (aDim) {
1953       case 1:
1954         aGeom = eSEG2;
1955         break;
1956       case 2:
1957         aGeom = eQUAD4;
1958         aSubGeom = eSEG2;
1959         aSubEntity = eARETE;
1960         aNbSub =
1961           (aStruct[0])   * (aStruct[1]-1) +
1962           (aStruct[0]-1) * (aStruct[1]);
1963         break;
1964       case 3:
1965         aGeom = eHEXA8;
1966         aSubGeom = eQUAD4;
1967         aSubEntity = eFACE;
1968         aNbSub =
1969           (aStruct[0])   * (aStruct[1]-1) * (aStruct[2]-1) +
1970           (aStruct[0]-1) * (aStruct[1])   * (aStruct[2]-1) +
1971           (aStruct[0]-1) * (aStruct[1]-1) * (aStruct[2]);
1972         break;
1973       }
1974       anInfo[eNOEUD][ePOINT1] = aNbNodes;
1975       anInfo[eMAILLE][aGeom] = aNbElem;
1976       if (aDim > 1)
1977         anInfo[aSubEntity][aSubGeom] = aNbSub;
1978     }
1979     return anInfo;
1980   }
1981
1982   //-----------------------------------------------------------------
1983   TInt
1984   TWrapper
1985   ::GetNbCells(const MED::TMeshInfo& theMeshInfo,
1986                EEntiteMaillage theEntity,
1987                EGeometrieElement theGeom,
1988                EConnectivite theConnMode,
1989                TErr* theErr)
1990   {
1991     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1992
1993     if (theErr && *theErr < 0)
1994       return -1;
1995
1996     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1997     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1998     med_bool chgt, trsf;
1999     switch (theGeom)
2000       {
2001       case MED::ePOLYGONE:
2002       case MED::ePOLYGON2:
2003         {
2004           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2005                                 MED_NO_DT, MED_NO_IT,
2006                                 med_entity_type(theEntity), med_geometry_type(theGeom),
2007                                 MED_INDEX_NODE, med_connectivity_mode(theConnMode),
2008                                 &chgt, &trsf)-1;
2009         }
2010       case MED::ePOLYEDRE:
2011         {
2012           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2013                                 MED_NO_DT, MED_NO_IT,
2014                                 med_entity_type(theEntity), MED_POLYHEDRON,
2015                                 MED_INDEX_FACE, med_connectivity_mode(theConnMode),
2016                                 &chgt, &trsf)-1;
2017         }
2018       case MED::eBALL:
2019         {
2020           return GetNbBalls(theMeshInfo);
2021         }
2022       default:
2023         {
2024           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2025                                 MED_NO_DT, MED_NO_IT,
2026                                 med_entity_type(theEntity), med_geometry_type(theGeom),
2027                                 MED_CONNECTIVITY, med_connectivity_mode(theConnMode),
2028                                 &chgt, &trsf);
2029         }
2030       }
2031     return 0;
2032   }
2033
2034   //----------------------------------------------------------------------------
2035   void
2036   TWrapper
2037   ::GetCellInfo(MED::TCellInfo& theInfo,
2038                 TErr* theErr)
2039   {
2040     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2041
2042     if (theErr && *theErr < 0)
2043       return;
2044
2045     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
2046
2047     TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
2048     TValueHolder<TElemNum, med_int>                    aConn        (theInfo.myConn);
2049     TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (theInfo.myModeSwitch);
2050     TValueHolder<TString, char>                        anElemNames  (theInfo.myElemNames);
2051     TValueHolder<EBooleen, med_bool>                   anIsElemNames(theInfo.myIsElemNames);
2052     TValueHolder<TElemNum, med_int>                    anElemNum    (theInfo.myElemNum);
2053     TValueHolder<EBooleen, med_bool>                   anIsElemNum  (theInfo.myIsElemNum);
2054     TValueHolder<TElemNum, med_int>                    aFamNum      (theInfo.myFamNum);
2055     TValueHolder<EBooleen, med_bool>                   anIsFamNum   (theInfo.myIsFamNum);
2056     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (theInfo.myEntity);
2057     TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (theInfo.myGeom);
2058     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (theInfo.myConnMode);
2059
2060     TErr aRet;
2061     aRet = MEDmeshElementRd(myFile->Id(),
2062                             &aMeshName,
2063                             MED_NO_DT,
2064                             MED_NO_IT,
2065                             anEntity,
2066                             aGeom,
2067                             aConnMode,
2068                             aModeSwitch,
2069                             &aConn,
2070                             &anIsElemNames,
2071                             &anElemNames,
2072                             &anIsElemNum,
2073                             &anElemNum,
2074                             &anIsFamNum,
2075                             &aFamNum);
2076
2077     if (theErr)
2078       *theErr = aRet;
2079     else if (aRet < 0)
2080       EXCEPTION(std::runtime_error, "GetCellInfo - MEDmeshElementRd(...)");
2081
2082     if (anIsFamNum == MED_FALSE)
2083       {
2084         int mySize = (int) theInfo.myFamNum->size();
2085         theInfo.myFamNum->clear();
2086         theInfo.myFamNum->resize(mySize, 0);
2087       }
2088
2089   }
2090
2091   //----------------------------------------------------------------------------
2092   void
2093   TWrapper
2094   ::SetCellInfo(const MED::TCellInfo& theInfo,
2095                 TErr* theErr)
2096   {
2097     SetCellInfo(theInfo, eLECTURE_ECRITURE, theErr);
2098   }
2099
2100   //----------------------------------------------------------------------------
2101   void
2102   TWrapper
2103   ::SetCellInfo(const MED::TCellInfo& theInfo,
2104                 EModeAcces theMode,
2105                 TErr* theErr)
2106   {
2107     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2108
2109     if (theErr && *theErr < 0)
2110       return;
2111
2112     MED::TCellInfo& anInfo    = const_cast<MED::TCellInfo&>(theInfo);
2113     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
2114
2115     TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
2116     TValueHolder<TElemNum, med_int>                    aConn        (anInfo.myConn);
2117     TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (anInfo.myModeSwitch);
2118     TValueHolder<TString, char>                        anElemNames  (anInfo.myElemNames);
2119     TValueHolder<EBooleen, med_bool>                   anIsElemNames(anInfo.myIsElemNames);
2120     TValueHolder<TElemNum, med_int>                    anElemNum    (anInfo.myElemNum);
2121     TValueHolder<EBooleen, med_bool>                   anIsElemNum  (anInfo.myIsElemNum);
2122     TValueHolder<TElemNum, med_int>                    aFamNum      (anInfo.myFamNum);
2123     TValueHolder<EBooleen, med_bool>                   anIsFamNum   (anInfo.myIsFamNum);
2124     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (anInfo.myEntity);
2125     TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (anInfo.myGeom);
2126     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (anInfo.myConnMode);
2127     TValueHolder<TInt, med_int>                        aNbElem      (anInfo.myNbElem);
2128
2129     TErr aRet;
2130     aRet = MEDmeshElementConnectivityWr(myFile->Id(),
2131                                         &aMeshName,
2132                                         MED_NO_DT,
2133                                         MED_NO_IT,
2134                                         MED_UNDEF_DT,
2135                                         anEntity,
2136                                         aGeom,
2137                                         aConnMode,
2138                                         aModeSwitch,
2139                                         aNbElem,
2140                                         &aConn);
2141
2142     MEDmeshEntityFamilyNumberWr(myFile->Id(),
2143                                 &aMeshName,
2144                                 MED_NO_DT,
2145                                 MED_NO_IT,
2146                                 anEntity,
2147                                 aGeom,
2148                                 aNbElem,
2149                                 &aFamNum);
2150     if (anIsElemNames)
2151       MEDmeshEntityNameWr(myFile->Id(),
2152                           &aMeshName,
2153                           MED_NO_DT,
2154                           MED_NO_IT,
2155                           anEntity,
2156                           aGeom,
2157                           aNbElem,
2158                           &anElemNames);
2159     if (anIsElemNum)
2160       MEDmeshEntityNumberWr(myFile->Id(),
2161                             &aMeshName,
2162                             MED_NO_DT,
2163                             MED_NO_IT,
2164                             anEntity,
2165                             aGeom,
2166                             aNbElem,
2167                             &anElemNum);
2168     if (theErr)
2169       *theErr = aRet;
2170     else if (aRet < 0)
2171       EXCEPTION(std::runtime_error, "SetCellInfo - MEDmeshElementWr(...), ret="<< aRet);
2172   }
2173
2174   //----------------------------------------------------------------------------
2175   PCellInfo
2176   TWrapper
2177   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2178                EEntiteMaillage theEntity,
2179                EGeometrieElement theGeom,
2180                TInt theNbElem,
2181                EConnectivite theConnMode,
2182                EBooleen theIsElemNum,
2183                EBooleen theIsElemNames,
2184                EModeSwitch theMode)
2185   {
2186     return PCellInfo(new TTCellInfo
2187                      (theMeshInfo,
2188                       theEntity,
2189                       theGeom,
2190                       theNbElem,
2191                       theConnMode,
2192                       theIsElemNum,
2193                       theIsElemNames,
2194                       theMode));
2195   }
2196
2197   //----------------------------------------------------------------------------
2198   PCellInfo
2199   TWrapper
2200   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2201                EEntiteMaillage theEntity,
2202                EGeometrieElement theGeom,
2203                const TIntVector& theConnectivities,
2204                EConnectivite theConnMode,
2205                const TIntVector& theFamilyNums,
2206                const TIntVector& theElemNums,
2207                const TStringVector& theElemNames,
2208                EModeSwitch theMode)
2209   {
2210     return PCellInfo(new TTCellInfo
2211                      (theMeshInfo,
2212                       theEntity,
2213                       theGeom,
2214                       theConnectivities,
2215                       theConnMode,
2216                       theFamilyNums,
2217                       theElemNums,
2218                       theElemNames,
2219                       theMode));
2220   }
2221
2222   //----------------------------------------------------------------------------
2223   PCellInfo
2224   TWrapper
2225   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2226                const PCellInfo& theInfo)
2227   {
2228     return PCellInfo(new TTCellInfo
2229                      (theMeshInfo,
2230                       theInfo));
2231   }
2232
2233   //----------------------------------------------------------------------------
2234   PCellInfo
2235   TWrapper
2236   ::GetPCellInfo(const PMeshInfo& theMeshInfo,
2237                  EEntiteMaillage theEntity,
2238                  EGeometrieElement theGeom,
2239                  EConnectivite theConnMode,
2240                  TErr* theErr)
2241   {
2242     if (theMeshInfo->GetType() != eNON_STRUCTURE)
2243       return PCellInfo();
2244     TInt aNbElem = GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode);
2245     PCellInfo anInfo = CrCellInfo(theMeshInfo, theEntity, theGeom, aNbElem, theConnMode);
2246     GetCellInfo(anInfo, theErr);
2247
2248 #ifdef _DEBUG_
2249     TInt aConnDim = anInfo->GetConnDim();
2250     INITMSG(MYDEBUG, "GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
2251     BEGMSG(MYDEBUG, "GetPCellInfo - aNbElem: "<<aNbElem<<": ");
2252     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2253       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
2254       for (TInt iConn = 0; iConn < aConnDim; iConn++) {
2255         ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
2256       }
2257       ADDMSG(MYVALUEDEBUG, " ");
2258     }
2259     ADDMSG(MYDEBUG, std::endl);
2260
2261     BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetFamNum: ");
2262     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2263       ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
2264     }
2265     ADDMSG(MYVALUEDEBUG, std::endl);
2266
2267     if (anInfo->IsElemNum()) {
2268       BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetElemNum: ");
2269       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2270         ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
2271       }
2272       ADDMSG(MYVALUEDEBUG, std::endl);
2273     }
2274     ADDMSG(MYDEBUG, std::endl);
2275 #endif
2276
2277     return anInfo;
2278   }
2279
2280   //----------------------------------------------------------------------------
2281   EGeometrieElement
2282   TWrapper
2283   ::GetBallGeom(const TMeshInfo& theMeshInfo)
2284   {
2285     TErr anError;
2286     TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
2287
2288     // read med_geometry_type of "MED_BALL" element
2289     char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2290     return EGeometrieElement(MEDstructElementGeotype(myFile->Id(), geotypename));
2291   }
2292
2293   //----------------------------------------------------------------------------
2294   TInt
2295   TWrapper
2296   ::GetNbBalls(const TMeshInfo& theMeshInfo)
2297   {
2298     TErr anError;
2299     TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
2300
2301     EGeometrieElement ballType = GetBallGeom(theMeshInfo);
2302     if (ballType < 0)
2303       return 0;
2304
2305     return GetNbCells(theMeshInfo, eSTRUCT_ELEMENT, ballType, eNOD);
2306   }
2307
2308   //----------------------------------------------------------------------------
2309   void
2310   TWrapper
2311   ::GetBallInfo(TBallInfo& theInfo,
2312                 TErr* theErr)
2313   {
2314     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2315
2316     // check geometry of MED_BALL
2317     if (theInfo.myGeom == eBALL)
2318       {
2319         theInfo.myGeom = GetBallGeom(*theInfo.myMeshInfo);
2320         if (theInfo.myGeom < 0) {
2321           if (!theErr)
2322             EXCEPTION(std::runtime_error, "GetBallInfo - no balls in the mesh");
2323           *theErr = theInfo.myGeom;
2324           return;
2325         }
2326       }
2327
2328     // read nodes ids
2329     GetCellInfo(theInfo);
2330
2331     // read diameters
2332     TValueHolder<TString, char>                        aMeshName (theInfo.myMeshInfo->myName);
2333     TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (theInfo.myGeom);
2334     TValueHolder<TFloatVector, void>                   aDiam     (theInfo.myDiameters);
2335     char varattname[ MED_NAME_SIZE + 1] = MED_BALL_DIAMETER;
2336
2337     TErr aRet = MEDmeshStructElementVarAttRd(myFile->Id(), &aMeshName,
2338                                              MED_NO_DT, MED_NO_IT,
2339                                              aGeom,
2340                                              varattname,
2341                                              &aDiam);
2342     if (theErr)
2343       *theErr = aRet;
2344     else if (aRet < 0)
2345       EXCEPTION(std::runtime_error, "GetBallInfo - pb at reading diameters");
2346   }
2347
2348   //----------------------------------------------------------------------------
2349   void
2350   TWrapper
2351   ::SetBallInfo(const TBallInfo& theInfo,
2352                 TErr* theErr)
2353   {
2354     SetBallInfo(theInfo, eLECTURE_ECRITURE, theErr);
2355   }
2356
2357   //----------------------------------------------------------------------------
2358   void
2359   TWrapper
2360   ::SetBallInfo(const TBallInfo& theInfo,
2361                 EModeAcces theMode,
2362                 TErr* theErr)
2363   {
2364     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2365
2366     TErr ret;
2367     char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH";
2368     EGeometrieElement ballGeom = GetBallGeom(*theInfo.myMeshInfo);
2369     if (ballGeom < 0)
2370       {
2371         // no ball model in the file, create support mesh for it
2372         char dummyname [MED_NAME_SIZE*3+1] = "";
2373         if ((ret = MEDsupportMeshCr(myFile->Id(),
2374                                     ballsupportname,
2375                                     theInfo.myMeshInfo->GetSpaceDim(),
2376                                     theInfo.myMeshInfo->GetDim(),
2377                                     "Support mesh for a ball model",
2378                                     MED_CARTESIAN,
2379                                     /*axisname=*/dummyname,
2380                                     /*unitname=*/dummyname)) < 0) {
2381           if (!theErr)
2382             EXCEPTION(std::runtime_error, "SetBallInfo - MEDsupportMeshCr");
2383           *theErr = ret;
2384           return;
2385         }
2386         // write coordinates of 1 node
2387         med_float coord[3] = {0, 0, 0};
2388         if ((ret = MEDmeshNodeCoordinateWr(myFile->Id(),
2389                                            ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
2390                                            MED_FULL_INTERLACE, /*nnode=*/1, coord)) < 0) {
2391           if (!theErr)
2392             EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshNodeCoordinateWr");
2393           *theErr = ret;
2394           return;
2395         }
2396         // ball model creation
2397         char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2398         if ((ballGeom = (EGeometrieElement) MEDstructElementCr(myFile->Id(),
2399                                                                geotypename,
2400                                                                theInfo.myMeshInfo->GetSpaceDim(),
2401                                                                ballsupportname,
2402                                                                MED_NODE,MED_NONE)) < 0) {
2403           if (!theErr)
2404             EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementCr");
2405           *theErr = ret;
2406           return;
2407         }
2408         // create diameter attribute
2409         if ((ret = MEDstructElementVarAttCr(myFile->Id(),
2410                                             geotypename, MED_BALL_DIAMETER,
2411                                             MED_ATT_FLOAT64, /*ncomp=*/1)) < 0) {
2412           if (!theErr)
2413             EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementVarAttCr");
2414           *theErr = ret;
2415           return;
2416         }
2417       } // ballGeom < 0
2418
2419     TBallInfo& aBallInfo = ((TBallInfo&) theInfo);
2420     aBallInfo.myGeom = ballGeom;
2421
2422     // write node ids
2423     SetCellInfo(theInfo, theMode, theErr);
2424     if (theErr && theErr < 0)
2425       return;
2426
2427     // write diameter
2428     TValueHolder<TString, char>                        aMeshName (aBallInfo.myMeshInfo->myName);
2429     TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (aBallInfo.myGeom);
2430     TValueHolder<TFloatVector, void>                   aDiam     (aBallInfo.myDiameters);
2431     ret = MEDmeshStructElementVarAttWr(myFile->Id(), &aMeshName,
2432                                        MED_NO_DT, MED_NO_IT,
2433                                        aGeom, MED_BALL_DIAMETER,
2434                                        theInfo.myNbElem, &aDiam);
2435     if (theErr)
2436       *theErr = ret;
2437     else if (ret < 0)
2438       EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshStructElementVarAttWr");
2439   }
2440
2441   //----------------------------------------------------------------------------
2442   PBallInfo
2443   TWrapper
2444   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2445                TInt theNbBalls,
2446                EBooleen theIsElemNum)
2447   {
2448     return PBallInfo(new TTBallInfo(theMeshInfo, theNbBalls, theIsElemNum));
2449   }
2450
2451   //----------------------------------------------------------------------------
2452   PBallInfo
2453   TWrapper
2454   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2455                const TIntVector& theNodes,
2456                TFloatVector& theDiameters,
2457                const TIntVector& theFamilyNums,
2458                const TIntVector& theElemNums)
2459   {
2460     return PBallInfo(new TTBallInfo(theMeshInfo, theNodes, theDiameters,
2461                                     theFamilyNums, theElemNums));
2462   }
2463
2464   //----------------------------------------------------------------------------
2465   PBallInfo
2466   TWrapper
2467   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2468                const PBallInfo& theInfo)
2469   {
2470     return PBallInfo(new TTBallInfo(theMeshInfo, theInfo));
2471   }
2472
2473   //----------------------------------------------------------------------------
2474   PBallInfo
2475   TWrapper
2476   ::GetPBallInfo(const PMeshInfo& theMeshInfo)
2477   {
2478     TInt nbBalls = GetNbBalls(theMeshInfo);
2479     if (nbBalls < 1) return PBallInfo();
2480
2481     PBallInfo anInfo = CrBallInfo(theMeshInfo, nbBalls);
2482     GetBallInfo(anInfo);
2483
2484     return anInfo;
2485   }
2486
2487   //-----------------------------------------------------------------
2488   TInt
2489   TWrapper
2490   ::GetNbFields(TErr* theErr)
2491   {
2492     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2493
2494     if (theErr && *theErr < 0)
2495       return -1;
2496
2497     return MEDnField(myFile->Id());
2498   }
2499
2500   //----------------------------------------------------------------------------
2501   TInt
2502   TWrapper
2503   ::GetNbComp(TInt theFieldId,
2504               TErr* theErr)
2505   {
2506     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2507
2508     if (theErr && *theErr < 0)
2509       return -1;
2510
2511     return MEDfieldnComponent(myFile->Id(), theFieldId);
2512   }
2513
2514   //----------------------------------------------------------------------------
2515   void
2516   TWrapper
2517   ::GetFieldInfo(TInt theFieldId,
2518                  MED::TFieldInfo& theInfo,
2519                  TErr* theErr)
2520   {
2521     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2522
2523     if (theErr && *theErr < 0)
2524       return;
2525
2526     TString aFieldName(256); // Protect from memory problems with too long names
2527     TValueHolder<ETypeChamp, med_field_type> aType(theInfo.myType);
2528     TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
2529     TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
2530     MED::TMeshInfo& aMeshInfo = theInfo.myMeshInfo;
2531
2532     TErr aRet;
2533     med_bool local;
2534     char dtunit[MED_SNAME_SIZE+1];
2535     char local_mesh_name[MED_NAME_SIZE+1]="";
2536     med_int nbofstp;
2537     theInfo.myNbComp = MEDfieldnComponent(myFile->Id(), theFieldId);
2538     aRet = MEDfieldInfo(myFile->Id(),
2539                         theFieldId,
2540                         &aFieldName[0],
2541                         local_mesh_name,
2542                         &local,
2543                         &aType,
2544                         &aCompNames,
2545                         &anUnitNames,
2546                         dtunit,
2547                         &nbofstp);
2548
2549     if (strcmp(&aMeshInfo.myName[0], local_mesh_name) != 0) {
2550       if (theErr)
2551         *theErr = -1;
2552       return;
2553     }
2554
2555     theInfo.SetName(aFieldName);
2556
2557     if (theErr)
2558       *theErr = aRet;
2559     else if (aRet < 0)
2560       EXCEPTION(std::runtime_error, "GetFieldInfo - MEDfieldInfo(...)");
2561   }
2562
2563   //----------------------------------------------------------------------------
2564   void
2565   TWrapper
2566   ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2567                  TErr* theErr)
2568   {
2569     TErr aRet;
2570     SetFieldInfo(theInfo, eLECTURE_ECRITURE, &aRet);
2571
2572     if (aRet < 0)
2573       SetFieldInfo(theInfo, eLECTURE_AJOUT, &aRet);
2574
2575     if (theErr)
2576       *theErr = aRet;
2577   }
2578
2579   //----------------------------------------------------------------------------
2580   void
2581   TWrapper
2582   ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2583                  EModeAcces theMode,
2584                  TErr* theErr)
2585   {
2586     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2587
2588     if (theErr && *theErr < 0)
2589       return;
2590
2591     MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2592
2593     TValueHolder<TString, char> aFieldName(anInfo.myName);
2594     TValueHolder<ETypeChamp, med_field_type> aType(anInfo.myType);
2595     TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
2596     TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
2597     MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2598     TErr aRet;
2599     char dtunit[MED_SNAME_SIZE+1];
2600     std::fill(dtunit, dtunit+MED_SNAME_SIZE+1, '\0');
2601     aRet = MEDfieldCr(myFile->Id(),
2602                       &aFieldName,
2603                       aType,
2604                       anInfo.myNbComp,
2605                       &aCompNames,
2606                       &anUnitNames,
2607                       dtunit,
2608                       &aMeshInfo.myName[0]);
2609     if (theErr)
2610       *theErr = aRet;
2611     else if (aRet < 0)
2612       EXCEPTION(std::runtime_error, "SetFieldInfo - MEDfieldCr(...)");
2613   }
2614
2615   //----------------------------------------------------------------------------
2616   PFieldInfo
2617   TWrapper
2618   ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2619                 TInt theNbComp,
2620                 ETypeChamp theType,
2621                 const std::string& theValue,
2622                 EBooleen theIsLocal,
2623                 TInt theNbRef)
2624   {
2625     return PFieldInfo(new TTFieldInfo
2626                       (theMeshInfo,
2627                        theNbComp,
2628                        theType,
2629                        theValue,
2630                        theIsLocal,
2631                        theNbRef));
2632   }
2633
2634   //----------------------------------------------------------------------------
2635   PFieldInfo
2636   TWrapper
2637   ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2638                 const PFieldInfo& theInfo)
2639   {
2640     return PFieldInfo(new TTFieldInfo
2641                       (theMeshInfo,
2642                        theInfo));
2643   }
2644
2645   //----------------------------------------------------------------------------
2646   PFieldInfo
2647   TWrapper
2648   ::GetPFieldInfo(const PMeshInfo& theMeshInfo,
2649                   TInt theId,
2650                   TErr* theErr)
2651   {
2652     TInt aNbComp = GetNbComp(theId);
2653     PFieldInfo anInfo = CrFieldInfo(theMeshInfo, aNbComp);
2654     GetFieldInfo(theId, *anInfo, theErr);
2655
2656 #ifdef _DEBUG_
2657     INITMSG(MYDEBUG,
2658             "GetPFieldInfo "<<
2659             "- aName = '"<<anInfo->GetName()<<"'"<<
2660             "; aType = "<<anInfo->GetType()<<
2661             "; aNbComp = "<<aNbComp<<
2662             std::endl);
2663 #endif
2664
2665     return anInfo;
2666   }
2667
2668   //----------------------------------------------------------------------------
2669   TInt
2670   TWrapper
2671   ::GetNbGauss(TErr* theErr)
2672   {
2673     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2674
2675     if (theErr && *theErr < 0)
2676       return -1;
2677
2678     return MEDnLocalization(myFile->Id());
2679   }
2680
2681   //----------------------------------------------------------------------------
2682   TGaussInfo::TInfo
2683   TWrapper
2684   ::GetGaussPreInfo(TInt theId,
2685                     TErr* theErr)
2686   {
2687     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2688
2689     if (theErr && *theErr < 0)
2690       return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0);
2691
2692     med_int aNbGaussPoints = med_int();
2693     TVector<char> aName(GetNOMLength()+1);
2694     med_geometry_type aGeom = MED_NONE;
2695
2696     TErr aRet;
2697     med_int dim;
2698     char geointerpname[MED_NAME_SIZE+1] = "";
2699     char ipointstructmeshname[MED_NAME_SIZE+1] = "";
2700     med_int nsectionmeshcell;
2701     med_geometry_type sectiongeotype;
2702     aRet = MEDlocalizationInfo (myFile->Id(),
2703                                 theId,
2704                                 &aName[0],
2705                                 &aGeom,
2706                                 &dim,
2707                                 &aNbGaussPoints,
2708                                 geointerpname,
2709                                 ipointstructmeshname,
2710                                 &nsectionmeshcell,
2711                                 &sectiongeotype);
2712     if (theErr)
2713       *theErr = aRet;
2714     else if (aRet < 0)
2715       EXCEPTION(std::runtime_error, "GetGaussPreInfo - MEDlocalizationInfo(...)");
2716     return TGaussInfo::TInfo(TGaussInfo::TKey(EGeometrieElement(aGeom), &aName[0]),
2717                              TInt(aNbGaussPoints));
2718   }
2719
2720   //----------------------------------------------------------------------------
2721   void
2722   TWrapper
2723   ::GetGaussInfo(TInt theId,
2724                  TGaussInfo& theInfo,
2725                  TErr* theErr)
2726   {
2727     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2728
2729     if (theErr && *theErr < 0)
2730       return;
2731
2732     TValueHolder<TNodeCoord, med_float> aRefCoord(theInfo.myRefCoord);
2733     TValueHolder<TNodeCoord, med_float> aGaussCoord(theInfo.myGaussCoord);
2734     TValueHolder<TWeight, med_float> aWeight(theInfo.myWeight);
2735     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
2736     TValueHolder<TString, char> aGaussName(theInfo.myName);
2737
2738     TErr aRet;
2739     aRet = MEDlocalizationRd(myFile->Id(),
2740                              &aGaussName,
2741                              aModeSwitch,
2742                              &aRefCoord,
2743                              &aGaussCoord,
2744                              &aWeight);
2745
2746     if (theErr)
2747       *theErr = aRet;
2748     else if (aRet < 0)
2749       EXCEPTION(std::runtime_error, "GetGaussInfo - MEDlocalizationRd(...)");
2750   }
2751
2752   //----------------------------------------------------------------------------
2753   PGaussInfo
2754   TWrapper
2755   ::CrGaussInfo(const TGaussInfo::TInfo& theInfo,
2756                 EModeSwitch theMode)
2757   {
2758     return PGaussInfo(new TTGaussInfo
2759                       (theInfo,
2760                        theMode));
2761   }
2762
2763   //-----------------------------------------------------------------
2764   TInt
2765   TWrapper
2766   ::GetNbTimeStamps(const MED::TFieldInfo& theInfo,
2767                     const MED::TEntityInfo& theEntityInfo,
2768                     EEntiteMaillage& theEntity,
2769                     TGeom2Size& theGeom2Size,
2770                     TErr* theErr)
2771   {
2772     theEntity = EEntiteMaillage(-1);
2773     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2774
2775     if (theErr) {
2776       if (theEntityInfo.empty())
2777         *theErr = -1;
2778       if (*theErr < 0)
2779         return -1;
2780     }
2781     else if (theEntityInfo.empty())
2782       EXCEPTION(std::runtime_error, "GetNbTimeStamps - There is no any Entity on the Mesh");
2783
2784     bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
2785
2786     theGeom2Size.clear();
2787     TInt aNbTimeStamps = 0;
2788     TIdt anId = myFile->Id();
2789
2790     MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2791     TValueHolder<TString, char> aFieldName(anInfo.myName);
2792     MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2793
2794     // workaround for IPAL13676
2795     MED::TEntityInfo localEntityInfo = theEntityInfo;
2796     TEntityInfo::iterator anLocalIter = localEntityInfo.find(eMAILLE);
2797     if (anLocalIter != localEntityInfo.end()) {
2798       localEntityInfo[eNOEUD_ELEMENT] = anLocalIter->second;
2799     }
2800
2801     TEntityInfo::const_iterator anIter = localEntityInfo.begin();
2802     for (; anIter != localEntityInfo.end(); anIter++) {
2803       med_entity_type anEntity = med_entity_type(anIter->first);
2804       const TGeom2Size& aGeom2Size = anIter->second;
2805       TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
2806       for (; anGeomIter != aGeom2Size.end(); anGeomIter++) {
2807         med_geometry_type aGeom = med_geometry_type(anGeomIter->first);
2808         char aMeshName[MED_NAME_SIZE+1];
2809         med_bool islocal;
2810         med_field_type ft;
2811         char dtunit[MED_SNAME_SIZE+1];
2812         med_int myNbComp = MEDfieldnComponentByName(anId, &aFieldName);
2813         char *cname=new char[myNbComp*MED_SNAME_SIZE+1];
2814         char *unitname=new char[myNbComp*MED_SNAME_SIZE+1];
2815         TInt aNbStamps;
2816         MEDfieldInfoByName(anId,
2817                            &aFieldName,
2818                            aMeshName,
2819                            &islocal,
2820                            &ft,
2821                            cname,
2822                            unitname,
2823                            dtunit,
2824                            &aNbStamps);
2825         delete [] cname;
2826         delete [] unitname;
2827         med_int nval = 0;
2828         med_int aNumDt;
2829         med_int aNumOrd;
2830         med_float aDt;
2831         if (aNbStamps > 0)
2832           {
2833             MEDfieldComputingStepInfo(anId,
2834                                       &aFieldName,
2835                                       1,
2836                                       &aNumDt,
2837                                       &aNumOrd,
2838                                       &aDt);
2839             char profilename[MED_NAME_SIZE+1];
2840             char locname[MED_NAME_SIZE+1];
2841             med_int profilsize;
2842             med_int aNbGauss;
2843
2844             // protection from crash (division by zero)
2845             // inside MEDfieldnValueWithProfile function
2846             // caused by the workaround for IPAL13676 (see above)
2847             if (anEntity == MED_NODE_ELEMENT && aGeom % 100 == 0)
2848               continue;
2849
2850             nval = MEDfieldnValueWithProfile(anId,
2851                                              &aFieldName,
2852                                              aNumDt,
2853                                              aNumOrd,
2854                                              anEntity,
2855                                              med_geometry_type(aGeom),
2856                                              1,
2857                                              MED_COMPACT_STMODE,
2858                                              profilename,
2859                                              &profilsize,
2860                                              locname,
2861                                              &aNbGauss);
2862           }
2863         bool anIsSatisfied =(nval > 0);
2864         if (anIsSatisfied) {
2865           INITMSG(MYDEBUG,
2866                   "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
2867                   "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
2868           if (anIsPerformAdditionalCheck) {
2869             anIsSatisfied = !strcmp(&aMeshName[0], &aMeshInfo.myName[0]);
2870             if (!anIsSatisfied) {
2871               INITMSG(MYDEBUG,
2872                       "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
2873                       "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
2874             }
2875           }
2876         }
2877         if (anIsSatisfied) {
2878           theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
2879           theEntity = EEntiteMaillage(anEntity);
2880           aNbTimeStamps = aNbStamps;
2881         }
2882       }
2883       if (!theGeom2Size.empty())
2884         break;
2885     }
2886     return aNbTimeStamps;
2887   }
2888
2889   //----------------------------------------------------------------------------
2890   void
2891   TWrapper
2892   ::GetTimeStampInfo(TInt theTimeStampId,
2893                      MED::TTimeStampInfo& theInfo,
2894                      TErr* theErr)
2895   {
2896     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2897
2898     const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
2899
2900     if (theErr) {
2901       if (aGeom2Size.empty())
2902         *theErr = -1;
2903       if (*theErr < 0)
2904         return;
2905     }
2906     else if (aGeom2Size.empty())
2907       EXCEPTION(std::runtime_error, "GetTimeStampInfo - There is no any cell");
2908
2909     MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
2910     MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
2911
2912     TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
2913     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(theInfo.myEntity);
2914     TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
2915     TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
2916     TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
2917     TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
2918     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2919     TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo.myIsLocal);
2920     TValueHolder<TInt, med_int> aNbRef(aFieldInfo.myNbRef);
2921
2922     TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
2923
2924     // just to get a time stamp unit (anUnitDt)
2925     med_field_type aFieldType;
2926     med_int aNbComp = MEDfieldnComponentByName(myFile->Id(), &aFieldName);
2927     char *aCompName = new char[aNbComp*MED_SNAME_SIZE+1];
2928     char *aCompUnit = new char[aNbComp*MED_SNAME_SIZE+1];
2929     TInt aNbStamps;
2930     MEDfieldInfoByName(myFile->Id(),
2931                        &aFieldName,
2932                        &aMeshName,
2933                        &anIsLocal,
2934                        &aFieldType,
2935                        aCompName,
2936                        aCompUnit,
2937                        &anUnitDt,
2938                        &aNbStamps);
2939     delete [] aCompName;
2940     delete [] aCompUnit;
2941
2942     TGeom2Size::const_iterator anIter = aGeom2Size.begin();
2943     for (; anIter != aGeom2Size.end(); anIter++) {
2944       const EGeometrieElement& aGeom = anIter->first;
2945       med_int aNbGauss = -1;
2946
2947       TErr aRet;
2948       aRet = MEDfieldComputingStepInfo(myFile->Id(),
2949                                        &aFieldName,
2950                                        theTimeStampId,
2951                                        &aNumDt,
2952                                        &aNumOrd,
2953                                        &aDt);
2954       char profilename[MED_NAME_SIZE+1];
2955       med_int profilsize;
2956       char locname[MED_NAME_SIZE+1];
2957       MEDfieldnValueWithProfile(myFile->Id(),
2958                                 &aFieldName,
2959                                 aNumDt,
2960                                 aNumOrd,
2961                                 anEntity,
2962                                 med_geometry_type(aGeom),
2963                                 1,
2964                                 MED_COMPACT_STMODE,
2965                                 profilename,
2966                                 &profilsize,
2967                                 locname,
2968                                 &aNbGauss);
2969
2970       static TInt MAX_NB_GAUSS_POINTS = 32;
2971       if (aNbGauss <= 0 || aNbGauss > MAX_NB_GAUSS_POINTS)
2972         aNbGauss = 1;
2973
2974       aGeom2NbGauss[aGeom] = aNbGauss;
2975
2976       if (theErr)
2977         *theErr = aRet;
2978       else if (aRet < 0)
2979         EXCEPTION(std::runtime_error, "GetTimeStampInfo - MEDfieldnValueWithProfile(...)");
2980     }
2981   }
2982
2983   //----------------------------------------------------------------------------
2984   PTimeStampInfo
2985   TWrapper
2986   ::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
2987                     EEntiteMaillage theEntity,
2988                     const TGeom2Size& theGeom2Size,
2989                     const TGeom2NbGauss& theGeom2NbGauss,
2990                     TInt theNumDt,
2991                     TInt theNumOrd,
2992                     TFloat theDt,
2993                     const std::string& theUnitDt,
2994                     const TGeom2Gauss& theGeom2Gauss)
2995   {
2996     return PTimeStampInfo(new TTTimeStampInfo
2997                           (theFieldInfo,
2998                            theEntity,
2999                            theGeom2Size,
3000                            theGeom2NbGauss,
3001                            theNumDt,
3002                            theNumOrd,
3003                            theDt,
3004                            theUnitDt,
3005                            theGeom2Gauss));
3006   }
3007
3008   //----------------------------------------------------------------------------
3009   PTimeStampInfo
3010   TWrapper
3011   ::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
3012                     const PTimeStampInfo& theInfo)
3013   {
3014     return PTimeStampInfo(new TTTimeStampInfo
3015                           (theFieldInfo,
3016                            theInfo));
3017   }
3018
3019   //----------------------------------------------------------------------------
3020   PTimeStampInfo
3021   TWrapper
3022   ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo,
3023                       EEntiteMaillage theEntity,
3024                       const TGeom2Size& theGeom2Size,
3025                       TInt theId,
3026                       TErr* theErr)
3027   {
3028     PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo, theEntity, theGeom2Size);
3029     GetTimeStampInfo(theId, *anInfo, theErr);
3030
3031 #ifdef _DEBUG_
3032     INITMSG(MYDEBUG, "GetPTimeStampInfo - anEntity = "<<anInfo->GetEntity()<<"\n");
3033     TGeom2NbGauss& aGeom2NbGauss = anInfo->myGeom2NbGauss;
3034     TGeom2NbGauss::const_iterator anIter = aGeom2NbGauss.begin();
3035     for (; anIter != aGeom2NbGauss.end(); anIter++) {
3036       const EGeometrieElement& aGeom = anIter->first;
3037       INITMSG(MYDEBUG, "aGeom = "<<aGeom<<" - "<<aGeom2NbGauss[aGeom]<<";\n");
3038     }
3039 #endif
3040
3041     return anInfo;
3042   }
3043
3044   //----------------------------------------------------------------------------
3045   TInt
3046   TWrapper
3047   ::GetNbProfiles(TErr* theErr)
3048   {
3049     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3050
3051     if (theErr && *theErr < 0)
3052       return -1;
3053
3054     return MEDnProfile(myFile->Id());
3055   }
3056
3057   //----------------------------------------------------------------------------
3058   TProfileInfo::TInfo
3059   TWrapper
3060   ::GetProfilePreInfo(TInt theId,
3061                       TErr* theErr)
3062   {
3063     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3064
3065     if (theErr && *theErr < 0)
3066       return TProfileInfo::TInfo();
3067
3068     med_int aSize = -1;
3069     TVector<char> aName(GetNOMLength()+1);
3070
3071     TErr aRet;
3072     aRet = MEDprofileInfo(myFile->Id(),
3073                           theId,
3074                           &aName[0],
3075                           &aSize);
3076     if (theErr)
3077       *theErr = aRet;
3078     else if (aRet < 0)
3079       EXCEPTION(std::runtime_error, "GetProfilePreInfo - MEDprofileInfo(...)");
3080
3081     return TProfileInfo::TInfo(&aName[0], aSize);
3082   }
3083
3084   //----------------------------------------------------------------------------
3085   void
3086   TWrapper
3087   ::GetProfileInfo(TInt theId,
3088                    TProfileInfo& theInfo,
3089                    TErr* theErr)
3090   {
3091     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3092
3093     if (theErr && *theErr < 0)
3094       return;
3095
3096     TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
3097     TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
3098     TValueHolder<TString, char> aProfileName(anInfo.myName);
3099
3100     TErr aRet;
3101     aRet = MEDprofileRd(myFile->Id(),
3102                         &aProfileName,
3103                         &anElemNum);
3104     if (theErr)
3105       *theErr = aRet;
3106     else if (aRet < 0)
3107       EXCEPTION(std::runtime_error, "GetProfileInfo - MEDprofileRd(...)");
3108   }
3109
3110   //----------------------------------------------------------------------------
3111   void
3112   TWrapper
3113   ::SetProfileInfo(const TProfileInfo& theInfo,
3114                    TErr* theErr)
3115   {
3116     TErr aRet;
3117     SetProfileInfo(theInfo, eLECTURE_ECRITURE, &aRet);
3118
3119     if (aRet < 0)
3120       SetProfileInfo(theInfo, eLECTURE_AJOUT, &aRet);
3121
3122     if (aRet < 0)
3123       SetProfileInfo(theInfo, eCREATION, &aRet);
3124
3125     if (theErr)
3126       *theErr = aRet;
3127   }
3128
3129   //----------------------------------------------------------------------------
3130   void
3131   TWrapper
3132   ::SetProfileInfo(const TProfileInfo& theInfo,
3133                    EModeAcces theMode,
3134                    TErr* theErr)
3135   {
3136     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
3137
3138     if (theErr && *theErr < 0)
3139       return;
3140
3141     TProfileInfo& anInfo = const_cast<TProfileInfo&>(theInfo);
3142     TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
3143     TValueHolder<TString, char>     aProfileName(anInfo.myName);
3144
3145     TErr aRet;
3146     aRet = MEDprofileWr(myFile->Id(),      // descripteur du fichier.
3147                         &aProfileName,     // tableau de valeurs du profil.
3148                         theInfo.GetSize(), // taille du profil.
3149                         &anElemNum);       // nom profil.
3150     if (theErr)
3151       *theErr = aRet;
3152     else if (aRet < 0)
3153       EXCEPTION(std::runtime_error, "SetProfileInfo - MEDprofileWr(...)");
3154   }
3155
3156   //----------------------------------------------------------------------------
3157   PProfileInfo
3158   TWrapper
3159   ::CrProfileInfo(const TProfileInfo::TInfo& theInfo,
3160                   EModeProfil theMode)
3161   {
3162     return PProfileInfo(new TTProfileInfo
3163                         (theInfo,
3164                          theMode));
3165   }
3166
3167   //----------------------------------------------------------------------------
3168   PProfileInfo
3169   TWrapper
3170   ::GetPProfileInfo(TInt theId,
3171                     EModeProfil theMode,
3172                     TErr* theErr)
3173   {
3174     TProfileInfo::TInfo aPreInfo = GetProfilePreInfo(theId);
3175     PProfileInfo anInfo = CrProfileInfo(aPreInfo, theMode);
3176     GetProfileInfo(theId, *anInfo, theErr);
3177
3178     return anInfo;
3179   }
3180
3181   //----------------------------------------------------------------------------
3182   void
3183   TWrapper
3184   ::GetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
3185                       const TMKey2Profile& theMKey2Profile,
3186                       const TKey2Gauss& theKey2Gauss,
3187                       TErr* theErr)
3188   {
3189     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3190
3191     if (theErr && *theErr < 0)
3192       return;
3193
3194     TIdt anId = myFile->Id();
3195
3196     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
3197     MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
3198
3199     MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
3200     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
3201     TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
3202     TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
3203
3204     MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
3205     TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
3206     TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo->myIsLocal);
3207
3208     MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
3209     TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
3210
3211     TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
3212     TVector<char> aGaussName(GetNOMLength()+1);
3213
3214     med_storage_mode aProfileMode = med_storage_mode(boost::get<0>(theMKey2Profile));
3215     MED::TKey2Profile aKey2Profile = boost::get<1>(theMKey2Profile);
3216     TVector<char> aProfileName(GetNOMLength()+1);
3217
3218     TGeom2Size& aGeom2Size = aTimeStampInfo->myGeom2Size;
3219     TGeom2Size::iterator anIter = aGeom2Size.begin();
3220     for (; anIter != aGeom2Size.end(); anIter++) {
3221       EGeometrieElement aGeom = anIter->first;
3222       TInt aNbElem = anIter->second;
3223       med_int profilesize, aNbGauss;
3224
3225       TInt aNbVal = MEDfieldnValueWithProfile(anId,
3226                                               &aFieldName,
3227                                               aNumDt,
3228                                               aNumOrd,
3229                                               anEntity,
3230                                               med_geometry_type(aGeom),
3231                                               1,
3232                                               aProfileMode,
3233                                               &aProfileName[0],
3234                                               &profilesize,
3235                                               &aGaussName[0],
3236                                               &aNbGauss);
3237
3238       if (aNbVal <= 0) {
3239         if (theErr) {
3240           *theErr = -1;
3241           return;
3242         }
3243         EXCEPTION(std::runtime_error, "GetTimeStampValue - MEDfieldnValueWithProfile(...) - aNbVal == "<<aNbVal<<" <= 0");
3244       }
3245
3246       TInt aNbComp = aFieldInfo->myNbComp;
3247       TInt aNbValue = aNbVal;// / aNbGauss; rules in MED changed
3248       theTimeStampValue->AllocateValue(aGeom,
3249                                        aNbValue,
3250                                        aNbGauss,
3251                                        aNbComp);
3252       TInt aValueSize = theTimeStampValue->GetValueSize(aGeom);
3253
3254       INITMSG(MYDEBUG,
3255               "TWrapper::GetTimeStampValue - aGeom = "<<aGeom<<
3256               "; aNbVal = "<<aNbVal<<
3257               "; aNbValue = "<<aNbValue<<
3258               "; aNbGauss = "<<aNbGauss<<
3259               "; aNbComp = "<<aNbComp<<
3260               std::endl);
3261
3262       TErr aRet = MEDfieldValueWithProfileRd(anId,
3263                                              &aFieldName,
3264                                              aNumDt,
3265                                              aNumOrd,
3266                                              anEntity,
3267                                              med_geometry_type(aGeom),
3268                                              aProfileMode,
3269                                              &aProfileName[0],
3270                                              aModeSwitch,
3271                                              MED_ALL_CONSTITUENT,
3272                                              theTimeStampValue->GetValuePtr(aGeom));
3273       if (aRet < 0) {
3274         if (theErr) {
3275           *theErr = MED_FALSE;
3276           return;
3277         }
3278         EXCEPTION(std::runtime_error, "GetTimeStampValue - MEDfieldValueWithProfileRd(...)");
3279       }
3280
3281       MED::PGaussInfo aGaussInfo;
3282       TGaussInfo::TKey aKey(aGeom, &aGaussName[0]);
3283       if (strcmp(&aGaussName[0], "") != 0) {
3284         MED::TKey2Gauss::const_iterator anIter = theKey2Gauss.find(aKey);
3285         if (anIter != theKey2Gauss.end()) {
3286           aGaussInfo = anIter->second;
3287           aGeom2Gauss[aGeom] = aGaussInfo;
3288         }
3289       }
3290
3291       MED::PProfileInfo aProfileInfo;
3292       if (strcmp(&aProfileName[0], MED_NO_PROFILE) != 0) {
3293         MED::TKey2Profile::const_iterator anIter = aKey2Profile.find(&aProfileName[0]);
3294         if (anIter != aKey2Profile.end()) {
3295           aProfileInfo = anIter->second;
3296           aGeom2Profile[aGeom] = aProfileInfo;
3297         }
3298       }
3299
3300       if (aGaussInfo && aNbGauss != aGaussInfo->GetNbGauss()) {
3301         if (theErr) {
3302           *theErr = MED_FALSE;
3303           return;
3304         }
3305         EXCEPTION(std::runtime_error, "GetTimeStampValue - aNbGauss != aGaussInfo->GetNbGauss()");
3306       }
3307
3308       if (aProfileInfo && aProfileInfo->IsPresent()) {
3309         TInt aNbSubElem = aProfileInfo->GetSize();
3310         TInt aProfileSize = aNbSubElem*aNbComp*aNbGauss;
3311         if (aProfileSize != aValueSize) {
3312           if (theErr) {
3313             *theErr = -1;
3314             return;
3315           }
3316           EXCEPTION(std::runtime_error,
3317                     "GetTimeStampValue - aProfileSize("<<aProfileSize<<
3318                     ") != aValueSize("<<aValueSize<<
3319                     "); aNbVal = "<<aNbVal<<
3320                     "; anEntity = "<<anEntity<<
3321                     "; aGeom = "<<aGeom<<
3322                     "; aNbElem = "<<aNbElem<<
3323                     "; aNbSubElem = "<<aNbSubElem<<
3324                     "; aNbComp = "<<aNbComp<<
3325                     "; aNbGauss = "<<aNbGauss<<
3326                     "");
3327         }
3328       }
3329       else{
3330         if ((aProfileMode == MED_GLOBAL_STMODE) && (aNbElem != aNbValue)) {
3331           if (theErr) {
3332             *theErr = -1;
3333             return;
3334           }
3335           EXCEPTION(std::runtime_error,
3336                     "GetTimeStampValue - aNbElem("<<aNbElem<<
3337                     ") != aNbValue("<<aNbValue<<
3338                     "); aNbVal = "<<aNbVal<<
3339                     "; anEntity = "<<anEntity<<
3340                     "; aGeom = "<<aGeom<<
3341                     "; aNbElem = "<<aNbElem<<
3342                     "; aNbComp = "<<aNbComp<<
3343                     "; aNbGauss = "<<aNbGauss<<
3344                     "");
3345         }
3346       }
3347     }
3348   }
3349
3350   //----------------------------------------------------------------------------
3351   void
3352   TWrapper
3353   ::SetTimeStampValue(const PTimeStampValueBase& theTimeStampValue,
3354                       TErr* theErr)
3355   {
3356     TErr aRet;
3357     SetTimeStampValue(theTimeStampValue, eLECTURE_ECRITURE, &aRet);
3358
3359     if (aRet < 0)
3360       SetTimeStampValue(theTimeStampValue, eLECTURE_AJOUT, &aRet);
3361
3362     if (theErr)
3363       *theErr = aRet;
3364   }
3365
3366   //----------------------------------------------------------------------------
3367   void
3368   TWrapper
3369   ::SetTimeStampValue(const MED::PTimeStampValueBase& theTimeStampValue,
3370                       EModeAcces theMode,
3371                       TErr* theErr)
3372   {
3373     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
3374
3375     if (theErr && *theErr < 0)
3376       return;
3377
3378     TErr aRet;
3379     TIdt anId = myFile->Id();
3380
3381     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theTimeStampValue->myModeSwitch);
3382     MED::TGeom2Profile& aGeom2Profile = theTimeStampValue->myGeom2Profile;
3383
3384     MED::PTimeStampInfo aTimeStampInfo = theTimeStampValue->myTimeStampInfo;
3385     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(aTimeStampInfo->myEntity);
3386     TValueHolder<TInt, med_int> aNumDt(aTimeStampInfo->myNumDt);
3387     TValueHolder<TInt, med_int> aNumOrd(aTimeStampInfo->myNumOrd);
3388     TValueHolder<TString, char> anUnitDt(aTimeStampInfo->myUnitDt);
3389     TValueHolder<TFloat, med_float> aDt(aTimeStampInfo->myDt);
3390     MED::TGeom2Gauss& aGeom2Gauss = aTimeStampInfo->myGeom2Gauss;
3391
3392     MED::PFieldInfo aFieldInfo = aTimeStampInfo->myFieldInfo;
3393     TValueHolder<TString, char> aFieldName(aFieldInfo->myName);
3394
3395     MED::PMeshInfo aMeshInfo = aFieldInfo->myMeshInfo;
3396     TValueHolder<TString, char> aMeshName(aMeshInfo->myName);
3397
3398     const TGeomSet& aGeomSet = theTimeStampValue->myGeomSet;
3399     TGeomSet::const_iterator anIter = aGeomSet.begin();
3400     for (; anIter != aGeomSet.end(); anIter++) {
3401       EGeometrieElement aGeom = *anIter;
3402
3403       TVector<char> aGaussName(GetNOMLength()+1);
3404       MED::TGeom2Gauss::const_iterator aGaussIter = aGeom2Gauss.find(aGeom);
3405       if (aGaussIter != aGeom2Gauss.end()) {
3406         MED::PGaussInfo aGaussInfo = aGaussIter->second;
3407         strcpy(&aGaussName[0], &aGaussInfo->myName[0]);
3408       }
3409
3410       TVector<char> aProfileName(GetNOMLength()+1);
3411       med_storage_mode aProfileMode = med_storage_mode(eNO_PFLMOD);
3412       MED::TGeom2Profile::const_iterator aProfileIter = aGeom2Profile.find(aGeom);
3413       if (aProfileIter != aGeom2Profile.end()) {
3414         MED::PProfileInfo aProfileInfo = aProfileIter->second;
3415         aProfileMode = med_storage_mode(aProfileInfo->myMode);
3416         strcpy(&aProfileName[0], &aProfileInfo->myName[0]);
3417       }
3418
3419       med_int aNbVal = theTimeStampValue->GetNbVal(aGeom);
3420
3421       aRet = MEDfieldValueWithProfileWr(anId,
3422                                         &aFieldName,
3423                                         aNumDt,
3424                                         aNumOrd,
3425                                         aDt,
3426                                         anEntity,
3427                                         med_geometry_type(aGeom),
3428                                         aProfileMode,
3429                                         &aProfileName[0],
3430                                         &aGaussName[0],
3431                                         aModeSwitch,
3432                                         MED_ALL_CONSTITUENT,
3433                                         aNbVal,
3434                                         theTimeStampValue->GetValuePtr(aGeom));
3435       if (aRet < 0) {
3436         if (theErr) {
3437           *theErr = MED_FALSE;
3438           break;
3439         }
3440         EXCEPTION(std::runtime_error, "SetTimeStampValue - MEDfieldValueWithProfileWr(...)");
3441       }
3442
3443     }
3444
3445     INITMSG(MYDEBUG, "TWrapper::SetTimeStampValue - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
3446   }
3447
3448   //----------------------------------------------------------------------------
3449   PTimeStampValueBase
3450   TWrapper
3451   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3452                      ETypeChamp theTypeChamp,
3453                      const TGeom2Profile& theGeom2Profile,
3454                      EModeSwitch theMode)
3455   {
3456     if (theTypeChamp == eFLOAT64)
3457       return PTimeStampValueBase(new TTTimeStampValue<TFloatMeshValue>
3458                                  (theTimeStampInfo,
3459                                   theTypeChamp,
3460                                   theGeom2Profile,
3461                                   theMode));
3462     return PTimeStampValueBase(new TTTimeStampValue<TIntMeshValue>
3463                                (theTimeStampInfo,
3464                                 theTypeChamp,
3465                                 theGeom2Profile,
3466                                 theMode));
3467   }
3468
3469   //----------------------------------------------------------------------------
3470   PTimeStampValueBase
3471   TWrapper
3472   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3473                      const TGeom2Profile& theGeom2Profile,
3474                      EModeSwitch theMode)
3475   {
3476     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3477     return CrTimeStampValue(theTimeStampInfo,
3478                             aFieldInfo->GetType(),
3479                             theGeom2Profile,
3480                             theMode);
3481   }
3482
3483   //----------------------------------------------------------------------------
3484   PTimeStampValueBase
3485   TWrapper
3486   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3487                      const PTimeStampValueBase& theInfo,
3488                      ETypeChamp theTypeChamp)
3489   {
3490     if (theTypeChamp == eFLOAT64)
3491       return PTimeStampValueBase(new TTTimeStampValue<TFloatMeshValue>
3492                                  (theTimeStampInfo,
3493                                   theInfo,
3494                                   theTypeChamp));
3495     return PTimeStampValueBase(new TTTimeStampValue<TIntMeshValue>
3496                                (theTimeStampInfo,
3497                                 theInfo,
3498                                 theTypeChamp));
3499   }
3500
3501   //----------------------------------------------------------------------------
3502   PTimeStampValueBase
3503   TWrapper
3504   ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3505                      const PTimeStampValueBase& theInfo)
3506   {
3507     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3508     return CrTimeStampValue(theTimeStampInfo,
3509                             theInfo,
3510                             aFieldInfo->GetType());
3511   }
3512
3513   //----------------------------------------------------------------------------
3514   PTimeStampValueBase
3515   TWrapper
3516   ::GetPTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
3517                        const TMKey2Profile& theMKey2Profile,
3518                        const TKey2Gauss& theKey2Gauss,
3519                        TErr* theErr)
3520   {
3521     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
3522     PTimeStampValueBase anInfo = CrTimeStampValue(theTimeStampInfo,
3523                                                   aFieldInfo->GetType());
3524     GetTimeStampValue(anInfo,
3525                       theMKey2Profile,
3526                       theKey2Gauss,
3527                       theErr);
3528 #ifdef _DEBUG_
3529     if (aFieldInfo->GetType() == eFLOAT64)
3530       Print<TFloatTimeStampValue>(anInfo);
3531     else
3532       Print<TIntTimeStampValue>(anInfo);
3533 #endif
3534     return anInfo;
3535   }
3536
3537   //----------------------------------------------------------------------------
3538   void
3539   TWrapper
3540   ::GetTimeStampVal(const PTimeStampVal& theVal,
3541                     const TMKey2Profile& theMKey2Profile,
3542                     const TKey2Gauss& theKey2Gauss,
3543                     TErr* theErr)
3544   {
3545     PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
3546     PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
3547     if (aFieldInfo->GetType() == eFLOAT64)
3548       GetTimeStampValue(theVal,
3549                         theMKey2Profile,
3550                         theKey2Gauss,
3551                         theErr);
3552     else{
3553       PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
3554                                                   theVal,
3555                                                   eINT);
3556       GetTimeStampValue(aVal,
3557                         theMKey2Profile,
3558                         theKey2Gauss,
3559                         theErr);
3560       CopyTimeStampValueBase(aVal, theVal);
3561     }
3562   }
3563
3564   //----------------------------------------------------------------------------
3565   void
3566   TWrapper
3567   ::SetTimeStamp(const PTimeStampVal& theVal,
3568                  TErr* theErr)
3569   {
3570     PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
3571     PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
3572     if (aFieldInfo->GetType() == eFLOAT64)
3573       SetTimeStampValue(theVal, theErr);
3574     else{
3575       PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
3576                                                   eINT,
3577                                                   theVal->GetGeom2Profile(),
3578                                                   theVal->GetModeSwitch());
3579       CopyTimeStampValueBase(theVal, aVal);
3580       SetTimeStampValue(aVal, theErr);
3581     }
3582   }
3583
3584   //----------------------------------------------------------------------------
3585   PTimeStampVal
3586   TWrapper
3587   ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3588                    const TGeom2Profile& theGeom2Profile,
3589                    EModeSwitch theMode)
3590   {
3591     return CrTimeStampValue(theTimeStampInfo,
3592                             eFLOAT64,
3593                             theGeom2Profile,
3594                             theMode);
3595   }
3596
3597   //----------------------------------------------------------------------------
3598   PTimeStampVal
3599   TWrapper
3600   ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3601                    const PTimeStampVal& theInfo)
3602   {
3603     return CrTimeStampValue(theTimeStampInfo,
3604                             theInfo,
3605                             eFLOAT64);
3606   }
3607
3608   //----------------------------------------------------------------------------
3609   PTimeStampVal
3610   TWrapper
3611   ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
3612                      const TMKey2Profile& theMKey2Profile,
3613                      const TKey2Gauss& theKey2Gauss,
3614                      TErr* theErr)
3615   {
3616     PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
3617     GetTimeStampVal(anInfo,
3618                     theMKey2Profile,
3619                     theKey2Gauss,
3620                     theErr);
3621     return anInfo;
3622   }
3623
3624   //----------------------------------------------------------------------------
3625   PGrilleInfo
3626   TWrapper
3627   ::GetPGrilleInfo(const PMeshInfo& theMeshInfo)
3628   {
3629     if (theMeshInfo->GetType() != eSTRUCTURE)
3630       return PGrilleInfo();
3631
3632     EGrilleType type;
3633     GetGrilleType(*theMeshInfo, type);
3634     PGrilleInfo anInfo;
3635     if (type == eGRILLE_STANDARD) {
3636       const TInt nnoeuds = GetNbNodes(*theMeshInfo);
3637       anInfo = CrGrilleInfo(theMeshInfo, type, nnoeuds);
3638     }
3639     else {
3640       TIntVector aVec;
3641       aVec.resize(theMeshInfo->GetDim());
3642       for (int aAxe=0;aAxe<theMeshInfo->GetDim();aAxe++) {
3643         ETable aATable = eCOOR_IND1;
3644         switch (aAxe) {
3645         case 0:
3646           aATable = eCOOR_IND1;
3647           break;
3648         case 1:
3649           aATable = eCOOR_IND2;
3650           break;
3651         case 2:
3652           aATable = eCOOR_IND3;
3653           break;
3654         }
3655         aVec[aAxe] = GetNbNodes(*theMeshInfo, aATable);
3656       }
3657       anInfo = CrGrilleInfo(theMeshInfo, type, aVec);
3658     }
3659
3660     GetGrilleInfo(anInfo);
3661     anInfo->SetGrilleType(type);
3662
3663 #ifdef _DEBUG_
3664     INITMSG(MYDEBUG, "GetPGrilleInfo: ");
3665     {
3666       TInt aNbElem = anInfo->GetNbNodes();
3667       BEGMSG(MYVALUEDEBUG, "GetFamNumNode: ");
3668       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
3669         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNumNode(iElem)<<", ");
3670       }
3671       TInt aNbCells = anInfo->GetNbCells();
3672       BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
3673       for (TInt iElem = 0; iElem < aNbCells; iElem++) {
3674         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
3675       }
3676       ADDMSG(MYVALUEDEBUG, std::endl);
3677       BEGMSG(MYVALUEDEBUG, "GetCoordName: ");
3678       for (TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++) {
3679         ADDMSG(MYVALUEDEBUG, anInfo->GetCoordName(iElem)<<", ");
3680       }
3681       ADDMSG(MYVALUEDEBUG, std::endl);
3682       BEGMSG(MYVALUEDEBUG, "GetCoordUnit: ");
3683       for (TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++) {
3684         ADDMSG(MYVALUEDEBUG, anInfo->GetCoordUnit(iElem)<<", ");
3685       }
3686       ADDMSG(MYVALUEDEBUG, std::endl);
3687
3688     }
3689 #endif
3690
3691     return anInfo;
3692   }
3693
3694   //----------------------------------------------------------------------------
3695   PGrilleInfo
3696   TWrapper
3697   ::GetPGrilleInfo(const PMeshInfo& theMeshInfo,
3698                    const PGrilleInfo& theInfo)
3699   {
3700     PGrilleInfo anInfo = CrGrilleInfo(theMeshInfo, theInfo);
3701     return anInfo;
3702   }
3703
3704   //----------------------------------------------------------------------------
3705   void
3706   TWrapper
3707   ::GetGrilleInfo(TGrilleInfo& theInfo,
3708                   TErr* theErr)
3709   {
3710     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
3711
3712     if (theErr && *theErr < 0)
3713       return;
3714
3715     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
3716     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
3717     EMaillage aMaillageType = aMeshInfo.myType;
3718
3719     GetGrilleType(aMeshInfo, theInfo.myGrilleType, theErr);
3720     EGrilleType aGrilleType = theInfo.myGrilleType;
3721
3722     TErr aRet = 0;
3723     if (aMaillageType == eSTRUCTURE && aGrilleType == eGRILLE_STANDARD) {
3724       GetGrilleStruct(aMeshInfo, theInfo.myGrilleStructure, theErr);
3725
3726       TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
3727       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
3728       TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
3729       TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
3730       //med_axis_type aRepere;
3731
3732       aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
3733                                      &aMeshName,
3734                                      MED_NO_DT,
3735                                      MED_NO_IT,
3736                                      aModeSwitch,
3737                                      &aCoord);
3738
3739       if (theErr)
3740         *theErr = aRet;
3741       else if (aRet < 0)
3742         EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshNodeCoordinateRd(...)");
3743
3744       //TInt aNbNodes = theInfo.GetNbNodes();//GetNbFamilies(aMeshInfo);
3745       TValueHolder<TElemNum, med_int> aFamNumNode(theInfo.myFamNumNode);
3746
3747       aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3748                                          &aMeshName,
3749                                          MED_NO_DT,
3750                                          MED_NO_IT,
3751                                          MED_NODE,
3752                                          MED_NO_GEOTYPE,
3753                                          &aFamNumNode);
3754
3755       if (aRet < 0) {
3756         //            if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
3757         {
3758           int mySize = (int)theInfo.myFamNumNode.size();
3759           theInfo.myFamNumNode.clear();
3760           theInfo.myFamNumNode.resize(mySize,0);
3761           aRet = 0;
3762         }
3763         //            else
3764         //              EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
3765       }
3766       if (theErr)
3767         *theErr = aRet;
3768
3769       //============================
3770     }
3771
3772     if (aMaillageType == eSTRUCTURE && aGrilleType != eGRILLE_STANDARD) {
3773       ETable aTable = eCOOR_IND1;
3774       for (med_int anAxis = 1; anAxis <= aMeshInfo.myDim; anAxis++) {
3775         switch (anAxis) {
3776         case 1:
3777           aTable = eCOOR_IND1;
3778           break;
3779         case 2:
3780           aTable = eCOOR_IND2;
3781           break;
3782         case 3:
3783           aTable = eCOOR_IND3;
3784           break;
3785         default:
3786           aRet = -1;
3787         }
3788
3789         if (theErr)
3790           *theErr = aRet;
3791         else if (aRet < 0)
3792           EXCEPTION(std::runtime_error, "GetGrilleInfo - anAxis number out of range(...)");
3793
3794         TInt aNbIndexes = GetNbNodes(aMeshInfo, aTable);
3795         if (aNbIndexes < 0)
3796           EXCEPTION(std::runtime_error, "GetGrilleInfo - Erreur a la lecture de la taille de l'indice");
3797
3798         TValueHolder<TFloatVector, med_float> anIndexes(theInfo.GetIndexes(anAxis-1));
3799         //TValueHolder<ETable, med_data_type > table(aTable);
3800         //char aCompNames[MED_SNAME_SIZE+1];
3801         //char anUnitNames[MED_SNAME_SIZE+1];
3802         aRet=MEDmeshGridIndexCoordinateRd(myFile->Id(),
3803                                           &aMeshName,
3804                                           MED_NO_DT,MED_NO_IT,
3805                                           anAxis,
3806                                           &anIndexes);
3807
3808         //theInfo.SetCoordName(anAxis-1, aCompNames);
3809         //theInfo.SetCoordUnit(anAxis-1, anUnitNames);
3810         theInfo.SetGrilleStructure(anAxis-1, aNbIndexes);
3811
3812         if (theErr)
3813           *theErr = aRet;
3814         else if (aRet < 0)
3815           EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDindicesCoordLire(...)");
3816       }
3817     }
3818
3819     EGeometrieElement aGeom = theInfo.GetGeom();
3820     EEntiteMaillage aEntity = theInfo.GetEntity();
3821     TInt aNbCells = theInfo.GetNbCells();
3822
3823     theInfo.myFamNum.resize(aNbCells);
3824     TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
3825
3826     aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3827                                        &aMeshName, MED_NO_DT, MED_NO_IT, med_entity_type(aEntity),
3828                                        med_geometry_type(aGeom), &aFamNum);
3829
3830     if (aMeshInfo.myDim == 3)
3831       {
3832         aGeom = theInfo.GetSubGeom();
3833         aEntity = theInfo.GetSubEntity();
3834         aNbCells = theInfo.GetNbSubCells();
3835
3836         theInfo.myFamSubNum.resize(aNbCells, 0);
3837         TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamSubNum);
3838
3839         aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
3840                                            &aMeshName,
3841                                            MED_NO_DT,
3842                                            MED_NO_IT,
3843                                            med_entity_type(aEntity),
3844                                            med_geometry_type(aGeom),
3845                                            &aFamNum);
3846       }
3847     if (aRet < 0) {
3848       //          if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
3849       {
3850         int mySize = (int)theInfo.myFamNumNode.size();
3851         theInfo.myFamNumNode.clear();
3852         theInfo.myFamNumNode.resize(mySize, 0);
3853         aRet = 0;
3854       }
3855       //          else
3856       //            EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...)");
3857     }
3858     if (theErr)
3859       *theErr = aRet;
3860   }
3861
3862   //----------------------------------------------------------------------------
3863   void
3864   TWrapper
3865   ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
3866                   TErr* theErr)
3867   {
3868     SetGrilleInfo(theInfo, eLECTURE_ECRITURE, theErr);
3869   }
3870
3871   //----------------------------------------------------------------------------
3872   void
3873   TWrapper
3874   ::SetGrilleInfo(const MED::TGrilleInfo& theInfo,
3875                   EModeAcces theMode,
3876                   TErr* theErr)
3877   {
3878     if (theInfo.myMeshInfo->myType != eSTRUCTURE)
3879       return;
3880     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
3881
3882     if (theErr && *theErr < 0)
3883       return;
3884
3885     MED::TGrilleInfo& anInfo = const_cast<MED::TGrilleInfo&>(theInfo);
3886
3887     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
3888     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
3889
3890     TValueHolder<EGrilleType, med_grid_type > aGrilleType(anInfo.myGrilleType);
3891
3892     TErr aRet = 0;
3893     aRet = MEDmeshGridTypeRd(myFile->Id(),
3894                              &aMeshName,
3895                              &aGrilleType);
3896     if (theErr)
3897       *theErr = aRet;
3898     else if (aRet < 0)
3899       EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridTypeRd(...)");
3900
3901     if (anInfo.myGrilleType == eGRILLE_STANDARD) {
3902       TValueHolder<TNodeCoord, med_float> aCoord(anInfo.myCoord);
3903       TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(anInfo.myModeSwitch);
3904       TValueHolder<TString, char> aCoordNames(anInfo.myCoordNames);
3905       TValueHolder<TString, char> aCoordUnits(anInfo.myCoordUnits);
3906       med_int aNbNoeuds = med_int(anInfo.myCoord.size() / aMeshInfo.myDim);
3907       //med_axis_type aRepere = MED_CARTESIAN;
3908
3909       aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
3910                                      &aMeshName,
3911                                      MED_NO_DT,
3912                                      MED_NO_IT,
3913                                      MED_UNDEF_DT,
3914                                      aModeSwitch,
3915                                      aNbNoeuds,
3916                                      &aCoord);
3917
3918       if (aRet < 0)
3919         EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshNodeCoordinateWr(...)");
3920
3921       TValueHolder<TIntVector, med_int> aGrilleStructure(anInfo.myGrilleStructure);
3922       aRet = MEDmeshGridStructWr(myFile->Id(),
3923                                  &aMeshName,
3924                                  MED_NO_DT,
3925                                  MED_NO_IT,
3926                                  MED_UNDEF_DT,
3927                                  &aGrilleStructure);
3928       if (aRet < 0)
3929         EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridStructWr(...)");
3930
3931     }
3932     else {
3933       for (med_int aAxis = 0; aAxis < aMeshInfo.myDim; aAxis++) {
3934         aRet = MEDmeshGridIndexCoordinateWr(myFile->Id(),
3935                                             &aMeshName,
3936                                             MED_NO_DT,
3937                                             MED_NO_IT,
3938                                             MED_UNDEF_DT,
3939                                             aAxis+1,
3940                                             anInfo.GetIndexes(aAxis).size(),
3941                                             &anInfo.GetIndexes(aAxis)[0]);
3942
3943         if (aRet < 0)
3944           EXCEPTION(std::runtime_error, "SetGrilleInfo - MEDmeshGridIndexCoordinateWr(...)");
3945       }
3946
3947     }
3948
3949     return;
3950   }
3951
3952   //----------------------------------------------------------------------------
3953   PGrilleInfo
3954   TWrapper
3955   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3956                  const PGrilleInfo& theInfo)
3957   {
3958     return PGrilleInfo(new TTGrilleInfo
3959                        (theMeshInfo,
3960                         theInfo));
3961   }
3962
3963   //----------------------------------------------------------------------------
3964   PGrilleInfo
3965   TWrapper
3966   ::CrGrilleInfo(const PMeshInfo& theMeshInfo)
3967   {
3968     return PGrilleInfo(); // not implemented????
3969   }
3970
3971   //----------------------------------------------------------------------------
3972   PGrilleInfo
3973   TWrapper
3974   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3975                  const EGrilleType& type)
3976   {
3977     return PGrilleInfo(new TTGrilleInfo
3978                        (theMeshInfo,
3979                         type));
3980   }
3981
3982   //----------------------------------------------------------------------------
3983   PGrilleInfo
3984   TWrapper
3985   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3986                  const EGrilleType& type,
3987                  const TInt& nbNodes)
3988   {
3989     return PGrilleInfo(new TTGrilleInfo
3990                        (theMeshInfo,
3991                         type,
3992                         nbNodes));
3993   }
3994
3995   //----------------------------------------------------------------------------
3996   PGrilleInfo
3997   TWrapper
3998   ::CrGrilleInfo(const PMeshInfo& theMeshInfo,
3999                  const EGrilleType& type,
4000                  const MED::TIntVector& nbNodeVec)
4001   {
4002     return PGrilleInfo(new TTGrilleInfo
4003                        (theMeshInfo,
4004                         type,
4005                         nbNodeVec));
4006   }
4007
4008   //----------------------------------------------------------------------------
4009   void
4010   TWrapper
4011   ::GetGrilleType(const MED::TMeshInfo& theMeshInfo,
4012                   EGrilleType& theGridType,
4013                   TErr* theErr)
4014   {
4015     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
4016
4017     if (theErr && *theErr < 0)
4018       EXCEPTION(std::runtime_error, " GetGrilleType - aFileWrapper (...)");
4019
4020     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
4021
4022     if (aMeshInfo.myType == eSTRUCTURE) {
4023       TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
4024       TValueHolder<EGrilleType, med_grid_type> aGridType(theGridType);
4025       TErr aRet = MEDmeshGridTypeRd(myFile->Id(),
4026                                     &aMeshName,
4027                                     &aGridType);
4028
4029       if (aRet < 0)
4030         EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshGridTypeRd(...)");
4031     }
4032   }
4033
4034   //----------------------------------------------------------------------------
4035   void
4036   TWrapper
4037   ::GetGrilleStruct(const MED::TMeshInfo& theMeshInfo,
4038                     TIntVector& theStruct,
4039                     TErr* theErr)
4040   {
4041     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
4042
4043     if (theErr && *theErr < 0)
4044       return;
4045
4046     TErr aRet;
4047     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
4048
4049     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
4050     TValueHolder<TIntVector, med_int> aGridStructure(theStruct);
4051
4052     aRet = MEDmeshGridStructRd(myFile->Id(),
4053                                &aMeshName,
4054                                MED_NO_DT,
4055                                MED_NO_IT,
4056                                &aGridStructure);
4057     if (theErr)
4058       *theErr = aRet;
4059     else if (aRet < 0)
4060       EXCEPTION(std::runtime_error, "GetGrilleInfo - MEDmeshGridStructRd(...)");
4061   }
4062 }