Salome HOME
#16662 EDF - ExportMED : too long (bis)
[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, TInt theMinor):
191     myFile(new TFile(theFileName, theMinor)),
192     myMinor(theMinor)
193   {
194     TErr aRet;
195     myFile->Open(eLECTURE_ECRITURE, &aRet);
196     // if (aRet < 0)
197     //   myFile->Close();
198     //   myFile->Open(eLECTURE_AJOUT, &aRet);
199     // }
200     if (aRet < 0) {
201       myFile->Close();
202       myFile->Open(eLECTURE, &aRet);
203     }
204     if (aRet < 0) {
205       myFile->Close();
206       myFile->Open(eCREATION, &aRet);
207     }
208   }
209
210   //----------------------------------------------------------------------------
211   TWrapper::
212   ~TWrapper()
213   {
214   }
215
216   //----------------------------------------------------------------------------
217   TInt
218   TWrapper
219   ::GetNbMeshes(TErr* theErr)
220   {
221     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
222
223     if (theErr && *theErr < 0)
224       return -1;
225
226     return MEDnMesh(myFile->Id());
227   }
228
229   //----------------------------------------------------------------------------
230   void
231   TWrapper
232   ::GetMeshInfo(TInt theMeshId,
233                 MED::TMeshInfo& theInfo,
234                 TErr* theErr)
235   {
236     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
237
238     if (theErr && *theErr < 0)
239       return;
240
241     TValueHolder<TString, char> aMeshName(theInfo.myName);
242     TValueHolder<TInt, med_int> aDim(theInfo.myDim);
243     TValueHolder<TInt, med_int> aSpaceDim(theInfo.mySpaceDim);
244     TValueHolder<EMaillage, med_mesh_type> aType(theInfo.myType);
245     char dtunit[MED_SNAME_SIZE+1];
246     med_sorting_type sorttype;
247     med_int nstep;
248     med_axis_type at;
249     int naxis = MEDmeshnAxis(myFile->Id(), theMeshId);
250     char *axisname = new char[naxis*MED_SNAME_SIZE+1];
251     char *axisunit = new char[naxis*MED_SNAME_SIZE+1];
252     TErr aRet = MEDmeshInfo(myFile->Id(),
253                             theMeshId,
254                             &aMeshName,
255                             &aSpaceDim,
256                             &aDim,
257                             &aType,
258                             &theInfo.myDesc[0],
259                             dtunit,
260                             &sorttype,
261                             &nstep,
262                             &at,
263                             axisname,
264                             axisunit);
265     delete [] axisname;
266     delete [] axisunit;
267     if (aRet < 0)
268       EXCEPTION(std::runtime_error, "GetMeshInfo - MEDmeshInfo(...)");
269   }
270
271   //----------------------------------------------------------------------------
272   void
273   TWrapper
274   ::SetMeshInfo(const MED::TMeshInfo& theInfo,
275                 TErr* theErr)
276   {
277     TErr aRet;
278     SetMeshInfo(theInfo, eLECTURE_ECRITURE, &aRet);
279
280     if (aRet < 0)
281       SetMeshInfo(theInfo, eLECTURE_AJOUT, &aRet);
282
283     if (aRet < 0)
284       SetMeshInfo(theInfo, eCREATION, &aRet);
285
286     if (theErr)
287       *theErr = aRet;
288   }
289
290   //----------------------------------------------------------------------------
291   void
292   TWrapper
293   ::SetMeshInfo(const MED::TMeshInfo& theInfo,
294                 EModeAcces theMode,
295                 TErr* theErr)
296   {
297     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
298
299     if (theErr && *theErr < 0)
300       return;
301
302     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
303
304     TValueHolder<TString, char> aMeshName(anInfo.myName);
305     TValueHolder<TInt, med_int> aDim(anInfo.myDim);
306     TValueHolder<TInt, med_int> aSpaceDim(anInfo.mySpaceDim);
307     TValueHolder<EMaillage, med_mesh_type> aType(anInfo.myType);
308     TValueHolder<TString, char> aDesc(anInfo.myDesc);
309
310     char *nam = new char[aSpaceDim*MED_SNAME_SIZE+1];
311     std::fill(nam, nam+aSpaceDim*MED_SNAME_SIZE+1, '\0');
312     char *unit = new char[aSpaceDim*MED_SNAME_SIZE+1];
313     std::fill(unit, unit+aSpaceDim*MED_SNAME_SIZE+1, '\0');
314     TErr aRet = MEDmeshCr(myFile->Id(),
315                           &aMeshName,
316                           aSpaceDim,
317                           aDim,
318                           aType,
319                           &aDesc,
320                           "",
321                           MED_SORT_DTIT,
322                           MED_CARTESIAN,
323                           nam,
324                           unit);
325     delete [] nam;
326     delete [] unit;
327
328     //if (aRet == 0)
329     //  aRet = MEDunvCr(myFile->Id(),&aMeshName);
330
331     INITMSG(MYDEBUG, "TWrapper::SetMeshInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
332
333     if (theErr)
334       *theErr = aRet;
335     else if (aRet < 0)
336       EXCEPTION(std::runtime_error, "SetMeshInfo - MEDmeshCr(...)");
337   }
338
339   //----------------------------------------------------------------------------
340   PMeshInfo
341   TWrapper
342   ::CrMeshInfo(TInt theDim,
343                TInt theSpaceDim,
344                const std::string& theValue,
345                EMaillage theType,
346                const std::string& theDesc)
347   {
348     return PMeshInfo(new TTMeshInfo
349                      (theDim,
350                       theSpaceDim,
351                       theValue,
352                       theType,
353                       theDesc));
354   }
355
356   //----------------------------------------------------------------------------
357   PMeshInfo
358   TWrapper
359   ::CrMeshInfo(const PMeshInfo& theInfo)
360   {
361     return PMeshInfo(new TTMeshInfo(theInfo));
362   }
363
364   //----------------------------------------------------------------------------
365   PMeshInfo
366   TWrapper
367   ::GetPMeshInfo(TInt theId,
368                  TErr* theErr)
369   {
370     PMeshInfo anInfo = CrMeshInfo();
371     GetMeshInfo(theId, *anInfo, theErr);
372     return anInfo;
373   }
374
375   //----------------------------------------------------------------------------
376   TInt
377   TWrapper
378   ::GetNbFamilies(const MED::TMeshInfo& theInfo,
379                   TErr* theErr)
380   {
381     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
382
383     if (theErr && *theErr < 0)
384       return -1;
385
386     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
387     TValueHolder<TString, char> aName(anInfo.myName);
388     return MEDnFamily(myFile->Id(), &aName);
389   }
390
391   //----------------------------------------------------------------------------
392   TInt
393   TWrapper
394   ::GetNbFamAttr(TInt theFamId,
395                  const MED::TMeshInfo& theInfo,
396                  TErr* theErr)
397   {
398     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
399
400     if (theErr && *theErr < 0)
401       return -1;
402
403     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
404
405     TValueHolder<TString, char> aName(anInfo.myName);
406
407     return MEDnFamily23Attribute(myFile->Id(), &aName, theFamId);
408   }
409
410   //----------------------------------------------------------------------------
411   TInt
412   TWrapper
413   ::GetNbFamGroup(TInt theFamId,
414                   const MED::TMeshInfo& theInfo,
415                   TErr* theErr)
416   {
417     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
418
419     if (theErr && *theErr < 0)
420       return -1;
421
422     MED::TMeshInfo& anInfo = const_cast<MED::TMeshInfo&>(theInfo);
423
424     TValueHolder<TString, char> aName(anInfo.myName);
425
426     return MEDnFamilyGroup(myFile->Id(), &aName, theFamId);
427   }
428
429   //----------------------------------------------------------------------------
430   void
431   TWrapper
432   ::GetFamilyInfo(TInt theFamId,
433                   MED::TFamilyInfo& theInfo,
434                   TErr* theErr)
435   {
436     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
437
438     if (theErr && *theErr < 0)
439       return;
440
441     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
442
443     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
444     TValueHolder<TString, char> aFamilyName(theInfo.myName);
445     TValueHolder<TInt, med_int> aFamilyId(theInfo.myId);
446     TValueHolder<TFamAttr, med_int> anAttrId(theInfo.myAttrId);
447     TValueHolder<TFamAttr, med_int> anAttrVal(theInfo.myAttrVal);
448     TValueHolder<TString, char> anAttrDesc(theInfo.myAttrDesc);
449     TValueHolder<TString, char> aGroupNames(theInfo.myGroupNames);
450
451     TErr aRet = MEDfamily23Info(myFile->Id(),
452                                 &aMeshName,
453                                 theFamId,
454                                 &aFamilyName,
455                                 &anAttrId,
456                                 &anAttrVal,
457                                 &anAttrDesc,
458                                 &aFamilyId,
459                                 &aGroupNames);
460
461     if (theErr)
462       *theErr = aRet;
463     else if (aRet < 0)
464       EXCEPTION(std::runtime_error, "GetFamilyInfo - MEDfamily23Info(...) - "<<
465                 " aMeshInfo.myName = '"<<&aMeshName<<
466                 "'; theFamId = "<<theFamId<<
467                 "; theInfo.myNbGroup = "<<theInfo.myNbGroup<<
468                 "; theInfo.myNbAttr = "<<theInfo.myNbAttr);
469   }
470
471   //----------------------------------------------------------------------------
472   void
473   TWrapper
474   ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
475                   TErr* theErr)
476   {
477     TErr aRet;
478     SetFamilyInfo(theInfo, eLECTURE_ECRITURE, &aRet);
479
480     if (aRet < 0)
481       SetFamilyInfo(theInfo, eLECTURE_AJOUT, &aRet);
482
483     if (theErr)
484       *theErr = aRet;
485   }
486
487   //----------------------------------------------------------------------------
488   void
489   TWrapper
490   ::SetFamilyInfo(const MED::TFamilyInfo& theInfo,
491                   EModeAcces theMode,
492                   TErr* theErr)
493   {
494     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
495
496     if (theErr && *theErr < 0)
497       return;
498
499     MED::TFamilyInfo& anInfo = const_cast<MED::TFamilyInfo&>(theInfo);
500     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
501
502     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
503     TValueHolder<TString, char> aFamilyName(anInfo.myName);
504     TValueHolder<TInt, med_int> aFamilyId(anInfo.myId);
505     TValueHolder<TFamAttr, med_int> anAttrId(anInfo.myAttrId);
506     TValueHolder<TFamAttr, med_int> anAttrVal(anInfo.myAttrVal);
507     TValueHolder<TInt, med_int> aNbAttr(anInfo.myNbAttr);
508     TValueHolder<TString, char> anAttrDesc(anInfo.myAttrDesc);
509     TValueHolder<TInt, med_int> aNbGroup(anInfo.myNbGroup);
510     TValueHolder<TString, char> aGroupNames(anInfo.myGroupNames);
511
512     TErr aRet = MEDfamilyCr(myFile->Id(),
513                             &aMeshName,
514                             &aFamilyName,
515                             aFamilyId,
516                             aNbGroup,
517                             &aGroupNames);
518
519     INITMSG(MYDEBUG, "TWrapper::SetFamilyInfo - MED_MODE_ACCES = "<<theMode<<"; aRet = "<<aRet<<std::endl);
520
521     if (theErr)
522       *theErr = aRet;
523     else if (aRet < 0)
524       EXCEPTION(std::runtime_error, "SetFamilyInfo - MEDfamilyCr(...)");
525   }
526
527   //----------------------------------------------------------------------------
528   PFamilyInfo
529   TWrapper
530   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
531                  TInt theNbGroup,
532                  TInt theNbAttr,
533                  TInt theId,
534                  const std::string& theValue)
535   {
536     return PFamilyInfo(new TTFamilyInfo
537                        (theMeshInfo,
538                         theNbGroup,
539                         theNbAttr,
540                         theId,
541                         theValue));
542   }
543
544   //----------------------------------------------------------------------------
545   PFamilyInfo
546   TWrapper
547   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
548                  const std::string& theValue,
549                  TInt theId,
550                  const MED::TStringSet& theGroupNames,
551                  const MED::TStringVector& theAttrDescs,
552                  const MED::TIntVector& theAttrIds,
553                  const MED::TIntVector& theAttrVals)
554   {
555     return PFamilyInfo(new TTFamilyInfo
556                        (theMeshInfo,
557                         theValue,
558                         theId,
559                         theGroupNames,
560                         theAttrDescs,
561                         theAttrIds,
562                         theAttrVals));
563   }
564
565   //----------------------------------------------------------------------------
566   PFamilyInfo
567   TWrapper
568   ::CrFamilyInfo(const PMeshInfo& theMeshInfo,
569                  const PFamilyInfo& theInfo)
570   {
571     return PFamilyInfo(new TTFamilyInfo
572                        (theMeshInfo,
573                         theInfo));
574   }
575
576   //----------------------------------------------------------------------------
577   PFamilyInfo
578   TWrapper
579   ::GetPFamilyInfo(const PMeshInfo& theMeshInfo,
580                    TInt theId,
581                    TErr* theErr)
582   {
583     // must be reimplemented in connection with mesh type eSTRUCTURE
584     //     if (theMeshInfo->GetType() != eNON_STRUCTURE)
585     //       return PFamilyInfo();
586
587     TInt aNbAttr = GetNbFamAttr(theId, *theMeshInfo);
588     TInt aNbGroup = GetNbFamGroup(theId, *theMeshInfo);
589     PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo, aNbGroup, aNbAttr);
590     GetFamilyInfo(theId, *anInfo, theErr);
591
592 #ifdef _DEBUG_
593     std::string aName = anInfo->GetName();
594     INITMSG(MYDEBUG, "GetPFamilyInfo - aFamilyName = '"<<aName<<
595             "'; andId = "<<anInfo->GetId()<<
596             "; aNbAttr = "<<aNbAttr<<
597             "; aNbGroup = "<<aNbGroup<<"\n");
598     for (TInt iGroup = 0; iGroup < aNbGroup; iGroup++) {
599       aName = anInfo->GetGroupName(iGroup);
600       INITMSG(MYDEBUG, "aGroupName = '"<<aName<<"'\n");
601     }
602 #endif
603
604     return anInfo;
605   }
606
607   //----------------------------------------------------------------------------
608   void
609   TWrapper
610   ::GetNames(TElemInfo& theInfo,
611              TInt theNb,
612              EEntiteMaillage theEntity,
613              EGeometrieElement theGeom,
614              TErr* theErr)
615   {
616     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
617
618     if (theErr && *theErr < 0)
619       return;
620
621     if (theGeom == eBALL)
622       theGeom = GetBallGeom(theInfo.myMeshInfo);
623
624     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
625
626     TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
627     TValueHolder<TString, char>                        anElemNames(theInfo.myElemNames);
628     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
629     TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
630
631     TErr aRet = MEDmeshEntityNameRd(myFile->Id(),
632                                     &aMeshName,
633                                     MED_NO_DT,
634                                     MED_NO_IT,
635                                     anEntity,
636                                     aGeom,
637                                     &anElemNames);
638
639     theInfo.myIsElemNames = aRet != 0? eFAUX : eVRAI ;
640
641     if (theErr)
642       *theErr = aRet;
643   }
644
645   //----------------------------------------------------------------------------
646   void
647   TWrapper
648   ::SetNames(const TElemInfo& theInfo,
649              EEntiteMaillage theEntity,
650              EGeometrieElement theGeom,
651              TErr* theErr)
652   {
653     SetNames(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
654   }
655
656   //----------------------------------------------------------------------------
657   void
658   TWrapper
659   ::SetNames(const TElemInfo& theInfo,
660              EModeAcces theMode,
661              EEntiteMaillage theEntity,
662              EGeometrieElement theGeom,
663              TErr* theErr)
664   {
665     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
666
667     if (theErr && *theErr < 0)
668       return;
669
670     if (theGeom == eBALL)
671       theGeom = GetBallGeom(theInfo.myMeshInfo);
672
673     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
674     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
675
676     TErr aRet = 0;
677     if (theInfo.myIsElemNames) {
678       TValueHolder<TString, char>                        aMeshName  (aMeshInfo.myName);
679       TValueHolder<TString, char>                        anElemNames(anInfo.myElemNames);
680       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity   (theEntity);
681       TValueHolder<EGeometrieElement, med_geometry_type> aGeom      (theGeom);
682
683       aRet = MEDmeshEntityNameWr(myFile->Id(),
684                                  &aMeshName,
685                                  MED_NO_DT,
686                                  MED_NO_IT,
687                                  anEntity,
688                                   aGeom,
689                                  (TInt)anInfo.myElemNames->size(),
690                                  &anElemNames);
691       if (theErr)
692         *theErr = aRet;
693       else if (aRet < 0)
694         EXCEPTION(std::runtime_error, "SetNames - MEDmeshEntityNameWr(...)");
695     }
696   }
697
698   //----------------------------------------------------------------------------
699   void
700   TWrapper
701   ::GetNumeration(TElemInfo& theInfo,
702                   TInt theNb,
703                   EEntiteMaillage theEntity,
704                   EGeometrieElement theGeom,
705                   TErr* theErr)
706   {
707     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
708
709     if (theErr && *theErr < 0)
710       return;
711
712     if (theGeom == eBALL)
713       theGeom = GetBallGeom(theInfo.myMeshInfo);
714
715     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
716
717     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
718     TValueHolder<TElemNum, med_int>                    anElemNum(theInfo.myElemNum);
719     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
720     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
721
722     TErr aRet = MEDmeshEntityNumberRd(myFile->Id(),
723                                       &aMeshName,
724                                       MED_NO_DT,
725                                       MED_NO_IT,
726                                       anEntity,
727                                       aGeom,
728                                       &anElemNum);
729
730     theInfo.myIsElemNum = aRet != 0? eFAUX : eVRAI;
731
732     if (theErr)
733       *theErr = aRet;
734   }
735
736   //----------------------------------------------------------------------------
737   void
738   TWrapper
739   ::SetNumeration(const TElemInfo& theInfo,
740                   EEntiteMaillage theEntity,
741                   EGeometrieElement theGeom,
742                   TErr* theErr)
743   {
744     SetNumeration(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
745   }
746
747   //----------------------------------------------------------------------------
748   void
749   TWrapper
750   ::SetNumeration(const TElemInfo& theInfo,
751                   EModeAcces theMode,
752                   EEntiteMaillage theEntity,
753                   EGeometrieElement theGeom,
754                   TErr* theErr)
755   {
756     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
757
758     if (theErr && *theErr < 0)
759       return;
760
761     if (theGeom == eBALL)
762       theGeom = GetBallGeom(theInfo.myMeshInfo);
763
764     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
765     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
766
767     TErr aRet = 0;
768     if (theInfo.myIsElemNum) {
769       TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
770       TValueHolder<TElemNum, med_int>                    anElemNum(anInfo.myElemNum);
771       TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
772       TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
773
774       aRet = MEDmeshEntityNumberWr(myFile->Id(),
775                                    &aMeshName,
776                                    MED_NO_DT,
777                                    MED_NO_IT,
778                                    anEntity,
779                                    aGeom,
780                                    (TInt)anInfo.myElemNum->size(),
781                                    &anElemNum);
782       if (theErr)
783         *theErr = aRet;
784       else if (aRet < 0)
785         EXCEPTION(std::runtime_error, "SetNumeration - MEDmeshEntityNumberWr(...)");
786     }
787   }
788
789   //----------------------------------------------------------------------------
790   void
791   TWrapper
792   ::GetFamilies(TElemInfo& theInfo,
793                 TInt theNb,
794                 EEntiteMaillage theEntity,
795                 EGeometrieElement theGeom,
796                 TErr* theErr)
797   {
798     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
799
800     if (theErr && *theErr < 0)
801       return;
802
803     if (theGeom == eBALL)
804       theGeom = GetBallGeom(theInfo.myMeshInfo);
805
806     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
807
808     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
809     TValueHolder<TElemNum, med_int>                    aFamNum  (theInfo.myFamNum);
810     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
811     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
812
813     TErr aRet = MEDmeshEntityFamilyNumberRd(myFile->Id(),
814                                             &aMeshName,
815                                             MED_NO_DT,
816                                             MED_NO_IT,
817                                             anEntity,
818                                             aGeom,
819                                             &aFamNum);
820
821     if (aRet < 0) {
822       //        if (aRet == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
823       {
824         int aSize = (int)theInfo.myFamNum->size();
825         theInfo.myFamNum->clear();
826         theInfo.myFamNum->resize(aSize,0);
827         aRet = 0;
828       }
829       //        else
830       //          EXCEPTION(std::runtime_error,"GetGrilleInfo - MEDmeshEntityFamilyNumberRd(...) of CELLS");
831     }
832     if (theErr)
833       *theErr = aRet;
834   }
835
836   //----------------------------------------------------------------------------
837   void
838   TWrapper
839   ::SetFamilies(const TElemInfo& theInfo,
840                 EEntiteMaillage theEntity,
841                 EGeometrieElement theGeom,
842                 TErr* theErr)
843   {
844     SetFamilies(theInfo, eLECTURE_ECRITURE, theEntity, theGeom, theErr);
845   }
846
847   //----------------------------------------------------------------------------
848   void
849   TWrapper
850   ::SetFamilies(const TElemInfo& theInfo,
851                 EModeAcces theMode,
852                 EEntiteMaillage theEntity,
853                 EGeometrieElement theGeom,
854                 TErr* theErr)
855   {
856     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
857
858     if (theErr && *theErr < 0)
859       return;
860
861     if (theGeom == eBALL)
862       theGeom = GetBallGeom(theInfo.myMeshInfo);
863
864     MED::TElemInfo& anInfo = const_cast<MED::TElemInfo&>(theInfo);
865     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
866
867     TValueHolder<TString, char>                        aMeshName(aMeshInfo.myName);
868     TValueHolder<TElemNum, med_int>                    aFamNum  (anInfo.myFamNum);
869     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity (theEntity);
870     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theGeom);
871
872     TErr aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
873                                             &aMeshName,
874                                             MED_NO_DT,
875                                             MED_NO_IT,
876                                             anEntity,
877                                             aGeom,
878                                             (TInt)anInfo.myFamNum->size(),
879                                             &aFamNum);
880
881     if (theErr)
882       *theErr = aRet;
883     else if (aRet < 0)
884       EXCEPTION(std::runtime_error, "SetFamilies - MEDmeshEntityFamilyNumberWr(...)");
885   }
886
887   //----------------------------------------------------------------------------
888   TInt
889   TWrapper
890   ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
891                TErr* theErr)
892   {
893     return GetNbNodes(theMeshInfo, eCOOR, theErr);
894   }
895
896   //----------------------------------------------------------------------------
897   TInt
898   TWrapper
899   ::GetNbNodes(const MED::TMeshInfo& theMeshInfo,
900                ETable theTable,
901                TErr* theErr)
902   {
903     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
904
905     if (theErr && *theErr < 0)
906       return -1;
907
908     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
909
910     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
911     TValueHolder<ETable, med_data_type > aTable(theTable);
912     med_bool chgt,trsf;
913     return MEDmeshnEntity(myFile->Id(),
914                           &aMeshName,
915                           MED_NO_DT,
916                           MED_NO_IT,
917                           MED_NODE,
918                           MED_NO_GEOTYPE,
919                           aTable,
920                           MED_NO_CMODE,
921                           &chgt,
922                           &trsf);
923   }
924
925   //----------------------------------------------------------------------------
926   void
927   TWrapper
928   ::GetNodeInfo(MED::TNodeInfo& theInfo,
929                 TErr* theErr)
930   {
931     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
932
933     if (theErr && *theErr < 0)
934       return;
935
936     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
937
938     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
939     TValueHolder<TInt, med_int> aDim(aMeshInfo.myDim);
940     TValueHolder<TNodeCoord, med_float> aCoord(theInfo.myCoord);
941     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
942     TValueHolder<ERepere, med_axis_type> aSystem(theInfo.mySystem);
943     TValueHolder<TString, char> aCoordNames(theInfo.myCoordNames);
944     TValueHolder<TString, char> aCoordUnits(theInfo.myCoordUnits);
945     TValueHolder<TString, char> anElemNames(theInfo.myElemNames);
946     //TValueHolder<EBooleen, med_bool> anIsElemNames(theInfo.myIsElemNames);
947     TValueHolder<TElemNum, med_int> anElemNum(theInfo.myElemNum);
948     //TValueHolder<EBooleen, med_bool> anIsElemNum(theInfo.myIsElemNum);
949     TValueHolder<TElemNum, med_int> aFamNum(theInfo.myFamNum);
950     TValueHolder<TInt, med_int> aNbElem(theInfo.myNbElem);
951
952     TErr aRet = MEDmeshNodeCoordinateRd(myFile->Id(),
953                                         &aMeshName,
954                                         MED_NO_DT,
955                                         MED_NO_IT,
956                                         aModeSwitch,
957                                         &aCoord);
958
959     TErr aRet2 =MEDmeshEntityFamilyNumberRd(myFile->Id(),
960                                             &aMeshName,
961                                             MED_NO_DT,
962                                             MED_NO_IT,
963                                             MED_NODE,
964                                             MED_NO_GEOTYPE,
965                                             &aFamNum);
966     if (aRet2 < 0) {
967       //        if (aRet2 == MED_ERR_DOESNTEXIST) // --- only valid with MED3.x files
968       {
969         int mySize = (int)theInfo.myFamNum->size();
970         theInfo.myFamNum->clear();
971         theInfo.myFamNum->resize(mySize,0);
972       }
973       //        else
974       //          EXCEPTION(std::runtime_error,"GetNodeInfo - MEDmeshEntityFamilyNumberRd(...)");
975     }
976
977     if (MEDmeshEntityNameRd(myFile->Id(),
978                             &aMeshName,
979                             MED_NO_DT,
980                             MED_NO_IT,
981                             MED_NODE,
982                             MED_NO_GEOTYPE,
983                             &anElemNames) < 0) theInfo.myIsElemNames=eFAUX;
984
985     if (MEDmeshEntityNumberRd(myFile->Id(),
986                               &aMeshName,
987                               MED_NO_DT,
988                               MED_NO_IT,
989                               MED_NODE,
990                               MED_NO_GEOTYPE,
991                               &anElemNum) < 0) theInfo.myIsElemNum=eFAUX;
992
993     if (theErr)
994       *theErr = aRet;
995     else if (aRet < 0)
996       EXCEPTION(std::runtime_error, "GetNodeInfo - MEDmeshNodeCoordinateRd(...)");
997   }
998
999   //----------------------------------------------------------------------------
1000   void
1001   TWrapper
1002   ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1003                 TErr* theErr)
1004   {
1005     TErr aRet;
1006     SetNodeInfo(theInfo, eLECTURE_ECRITURE, &aRet);
1007
1008     if (aRet < 0)
1009       SetNodeInfo(theInfo, eLECTURE_AJOUT, &aRet);
1010
1011     if (theErr)
1012       *theErr = aRet;
1013   }
1014
1015   //----------------------------------------------------------------------------
1016   void
1017   TWrapper
1018   ::SetNodeInfo(const MED::TNodeInfo& theInfo,
1019                 EModeAcces theMode,
1020                 TErr* theErr)
1021   {
1022     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1023
1024     if (theErr && *theErr < 0)
1025       return;
1026
1027     MED::TNodeInfo& anInfo = const_cast<MED::TNodeInfo&>(theInfo);
1028     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1029
1030     TValueHolder<TString, char>                aMeshName    (aMeshInfo.myName);
1031     TValueHolder<TNodeCoord, med_float>        aCoord       (anInfo.myCoord);
1032     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch  (anInfo.myModeSwitch);
1033     TValueHolder<ERepere, med_axis_type>       aSystem      (anInfo.mySystem);
1034     TValueHolder<TString, char>                aCoordNames  (anInfo.myCoordNames);
1035     TValueHolder<TString, char>                aCoordUnits  (anInfo.myCoordUnits);
1036     TValueHolder<TString, char>                anElemNames  (anInfo.myElemNames);
1037     TValueHolder<EBooleen, med_bool>           anIsElemNames(anInfo.myIsElemNames);
1038     TValueHolder<TElemNum, med_int>            anElemNum    (anInfo.myElemNum);
1039     TValueHolder<EBooleen, med_bool>           anIsElemNum  (anInfo.myIsElemNum);
1040     TValueHolder<TElemNum, med_int>            aFamNum      (anInfo.myFamNum);
1041     TValueHolder<TInt, med_int>                aNbElem      (anInfo.myNbElem);
1042
1043     TErr aRet = MEDmeshNodeCoordinateWr(myFile->Id(),
1044                                         &aMeshName,
1045                                         MED_NO_DT,
1046                                         MED_NO_IT,
1047                                         MED_NO_DT,
1048                                         aModeSwitch,
1049                                         aNbElem,
1050                                         &aCoord);
1051
1052     MEDmeshEntityFamilyNumberWr(myFile->Id(),
1053                                 &aMeshName,
1054                                 MED_NO_DT,
1055                                 MED_NO_IT,
1056                                 MED_NODE,
1057                                 MED_NO_GEOTYPE,
1058                                 aNbElem,
1059                                 &aFamNum);
1060     if (anIsElemNames)
1061       MEDmeshEntityNameWr(myFile->Id(),
1062                           &aMeshName,
1063                           MED_NO_DT,
1064                           MED_NO_IT,
1065                           MED_NODE,
1066                           MED_NO_GEOTYPE,
1067                           aNbElem,
1068                           &anElemNames);
1069     if (anIsElemNum)
1070       MEDmeshEntityNumberWr(myFile->Id(),
1071                             &aMeshName,
1072                             MED_NO_DT,
1073                             MED_NO_IT,
1074                             MED_NODE,
1075                             MED_NO_GEOTYPE,
1076                             aNbElem,
1077                             &anElemNum);
1078     if (theErr)
1079       *theErr = aRet;
1080     else if (aRet < 0)
1081       EXCEPTION(std::runtime_error, "SetNodeInfo - MEDmeshNodeCoordinateWr(...)");
1082   }
1083
1084   //----------------------------------------------------------------------------
1085   PNodeInfo
1086   TWrapper
1087   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1088                TInt theNbElem,
1089                EModeSwitch theMode,
1090                ERepere theSystem,
1091                EBooleen theIsElemNum,
1092                EBooleen theIsElemNames)
1093   {
1094     return PNodeInfo(new TTNodeInfo
1095                      (theMeshInfo,
1096                       theNbElem,
1097                       theMode,
1098                       theSystem,
1099                       theIsElemNum,
1100                       theIsElemNames));
1101   }
1102
1103   //----------------------------------------------------------------------------
1104   PNodeInfo
1105   TWrapper
1106   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1107                const TFloatVector& theNodeCoords,
1108                EModeSwitch theMode,
1109                ERepere theSystem,
1110                const TStringVector& theCoordNames,
1111                const TStringVector& theCoordUnits,
1112                const TIntVector& theFamilyNums,
1113                const TIntVector& theElemNums,
1114                const TStringVector& theElemNames)
1115   {
1116     return PNodeInfo(new TTNodeInfo
1117                      (theMeshInfo,
1118                       theNodeCoords,
1119                       theMode,
1120                       theSystem,
1121                       theCoordNames,
1122                       theCoordUnits,
1123                       theFamilyNums,
1124                       theElemNums,
1125                       theElemNames));
1126   }
1127
1128   //----------------------------------------------------------------------------
1129   PNodeInfo
1130   TWrapper
1131   ::CrNodeInfo(const PMeshInfo& theMeshInfo,
1132                const PNodeInfo& theInfo)
1133   {
1134     return PNodeInfo(new TTNodeInfo
1135                      (theMeshInfo,
1136                       theInfo));
1137   }
1138
1139   //----------------------------------------------------------------------------
1140   PNodeInfo
1141   TWrapper
1142   ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
1143                  TErr* theErr)
1144   {
1145     TInt aNbElems = GetNbNodes(*theMeshInfo);
1146     if (aNbElems == 0) {
1147       return PNodeInfo();
1148     }
1149
1150     PNodeInfo anInfo = CrNodeInfo(theMeshInfo, aNbElems);
1151     GetNodeInfo(*anInfo, theErr);
1152
1153 #ifdef _DEBUG_
1154     TInt aDim = theMeshInfo->myDim;
1155     TInt aNbElem = anInfo->GetNbElem();
1156     INITMSG(MYDEBUG, "GetPNodeInfo: ");
1157     {
1158       INITMSG(MYDEBUG, "aCoords: "<<aNbElem<<": ");
1159       TNodeCoord& aCoord = anInfo->myCoord;
1160       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1161         for (TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++) {
1162           ADDMSG(MYVALUEDEBUG, aCoord[anId]<<",");
1163         }
1164         ADDMSG(MYVALUEDEBUG, " ");
1165       }
1166       ADDMSG(MYDEBUG, std::endl);
1167
1168       BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
1169       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1170         ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
1171       }
1172       ADDMSG(MYVALUEDEBUG, std::endl);
1173
1174       if (anInfo->IsElemNum()) {
1175         BEGMSG(MYVALUEDEBUG, "GetElemNum: ");
1176         for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1177           ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
1178         }
1179         ADDMSG(MYVALUEDEBUG, std::endl);
1180       }
1181     }
1182     ADDMSG(MYDEBUG, std::endl);
1183 #endif
1184
1185     return anInfo;
1186   }
1187
1188   //----------------------------------------------------------------------------
1189   PElemInfo
1190   TWrapper
1191   ::CrElemInfo(const PMeshInfo& theMeshInfo,
1192                TInt theNbElem,
1193                EBooleen theIsElemNum,
1194                EBooleen theIsElemNames)
1195   {
1196     return PElemInfo(new TTElemInfo
1197                      (theMeshInfo,
1198                       theNbElem,
1199                       theIsElemNum,
1200                       theIsElemNames));
1201   }
1202
1203   //----------------------------------------------------------------------------
1204   PElemInfo
1205   TWrapper
1206   ::CrElemInfo(const PMeshInfo& theMeshInfo,
1207                TInt theNbElem,
1208                const TIntVector& theFamNum,
1209                const TIntVector& aElemNum,
1210                const TStringVector& aElemNames)
1211   {
1212     return PElemInfo(new TTElemInfo
1213                      (theMeshInfo,
1214                       theNbElem,
1215                       theFamNum,
1216                       aElemNum,
1217                       aElemNames));
1218   }
1219
1220   //----------------------------------------------------------------------------
1221   PElemInfo
1222   TWrapper
1223   ::GetPElemInfo(const PMeshInfo& theMeshInfo,
1224                  EEntiteMaillage theEntity,
1225                  EGeometrieElement theGeom,
1226                  EConnectivite theConnMode,
1227                  TErr* theErr)
1228   {
1229     EMaillage aType = theMeshInfo->GetType();
1230     if (aType == eNON_STRUCTURE) {
1231       switch (theGeom) {
1232       case ePOINT1:
1233         if (theEntity == eNOEUD)
1234           return GetPNodeInfo(theMeshInfo, theErr);
1235         return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1236         break;
1237       case ePOLYGONE:
1238         return GetPPolygoneInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1239         break;
1240       case ePOLYEDRE:
1241         return GetPPolyedreInfo(theMeshInfo, theEntity, theGeom, theConnMode);
1242         break;
1243       default:
1244         return GetPCellInfo(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1245       }
1246     }
1247     else {
1248       PGrilleInfo aGrille = GetPGrilleInfo(theMeshInfo);
1249
1250       TInt nbElems;
1251       EBooleen theIsElemNum = eFAUX;
1252       // nodes
1253       switch (theGeom) {
1254       case ePOINT1:
1255         nbElems = aGrille->GetNbNodes();
1256         theIsElemNum = eVRAI;
1257         break;
1258       case eSEG2:
1259       case eQUAD4:
1260       case eHEXA8:
1261         nbElems = aGrille->GetNbCells();
1262         break;
1263       default:
1264         nbElems = 0;
1265       }
1266
1267       TIntVector aFamNum;
1268       TIntVector aElemNum;
1269       TStringVector aElemNames;
1270
1271       PElemInfo aElemInfo;
1272
1273       if (theGeom == ePOINT1) {
1274         aElemInfo = CrElemInfo(theMeshInfo,
1275                                nbElems,
1276                                theIsElemNum);
1277         MED::TElemInfo &aTElemInfo = *aElemInfo;
1278
1279         // must be reimplemente in connection with mesh type eSTRUCTURE
1280         //      GetNumeration(aTElemInfo,
1281         //                    nbElems,
1282         //                    theEntity,
1283         //                    theGeom,
1284         //                    theErr);
1285
1286         GetFamilies(aTElemInfo,
1287                     nbElems,
1288                     theEntity,
1289                     theGeom,
1290                     theErr);
1291
1292         // must be reimplemente in connection with mesh type eSTRUCTURE
1293         //      GetNames(aTElemInfo,
1294         //               nbElems,
1295         //               theEntity,
1296         //               theGeom,
1297         //               theErr);
1298       }
1299       else {
1300         aElemInfo = CrElemInfo(theMeshInfo,
1301                                nbElems,
1302                                aFamNum,
1303                                aElemNum,
1304                                aElemNames);
1305       }
1306
1307       return aElemInfo;
1308     }
1309     return PElemInfo();
1310   }
1311
1312   //----------------------------------------------------------------------------
1313   TInt
1314   TWrapper
1315   ::GetNbPolygones(const MED::TMeshInfo& theMeshInfo,
1316                    EEntiteMaillage theEntity,
1317                    EGeometrieElement theGeom,
1318                    EConnectivite theConnMode,
1319                    TErr* theErr)
1320   {
1321     return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1322   }
1323
1324   //----------------------------------------------------------------------------
1325   TInt
1326   TWrapper
1327   ::GetPolygoneConnSize(const MED::TMeshInfo& theMeshInfo,
1328                         EEntiteMaillage theEntity,
1329                         EGeometrieElement theGeom,
1330                         EConnectivite theConnMode,
1331                         TErr* theErr)
1332   {
1333     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1334
1335     if (theErr && *theErr < 0)
1336       return 0;
1337
1338     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1339
1340     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1341     med_int aTaille = 0;
1342     med_bool chgt,trsf;
1343     aTaille=MEDmeshnEntity(myFile->Id(),
1344                            &aMeshName,
1345                            MED_NO_DT,
1346                            MED_NO_IT,
1347                            med_entity_type(theEntity),
1348                            med_geometry_type(theGeom),
1349                            MED_CONNECTIVITY,
1350                            med_connectivity_mode(theConnMode),
1351                            &chgt,
1352                            &trsf);
1353
1354     if (aTaille < 0)
1355       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1356
1357     return TInt(aTaille);
1358   }
1359
1360   //-----------------------------------------------------------------
1361   void
1362   TWrapper
1363   ::GetPolygoneInfo(MED::TPolygoneInfo& theInfo,
1364                     TErr* theErr)
1365   {
1366     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1367
1368     if (theErr && *theErr < 0)
1369       return;
1370
1371     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1372
1373     TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
1374     TValueHolder<TElemNum, med_int                   > anIndex  (theInfo.myIndex);
1375     TValueHolder<TElemNum, med_int                   > aConn    (theInfo.myConn);
1376     TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (theInfo.myEntity);
1377     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (theInfo.myGeom);
1378     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1379     TInt aNbElem = (TInt)theInfo.myElemNum->size();
1380
1381     TErr aRet;
1382     aRet = MEDmeshPolygon2Rd(myFile->Id(), &aMeshName,
1383                              MED_NO_DT, MED_NO_IT,
1384                              anEntity, aGeom,
1385                              aConnMode, &anIndex, &aConn);
1386
1387     if (theErr)
1388       *theErr = aRet;
1389     else if (aRet < 0)
1390       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolygonRd(...)");
1391
1392     if (theInfo.myIsElemNames) {
1393       GetNames(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1394       if (theErr)
1395         *theErr = aRet;
1396     }
1397
1398     if (theInfo.myIsElemNum) {
1399       GetNumeration(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1400       if (theErr)
1401         *theErr = aRet;
1402     }
1403
1404     GetFamilies(theInfo, aNbElem, theInfo.myEntity, theInfo.myGeom, &aRet);
1405     if (theErr)
1406       *theErr = aRet;
1407   }
1408
1409   //----------------------------------------------------------------------------
1410   void
1411   TWrapper
1412   ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1413                     TErr* theErr)
1414   {
1415     SetPolygoneInfo(theInfo, eLECTURE_ECRITURE, theErr);
1416   }
1417
1418   //----------------------------------------------------------------------------
1419   void
1420   TWrapper
1421   ::SetPolygoneInfo(const MED::TPolygoneInfo& theInfo,
1422                     EModeAcces theMode,
1423                     TErr* theErr)
1424   {
1425     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1426
1427     if (theErr && *theErr < 0)
1428       return;
1429
1430     MED::TPolygoneInfo& anInfo = const_cast<MED::TPolygoneInfo&>(theInfo);
1431     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1432
1433     TValueHolder<TString, char                       > aMeshName(aMeshInfo.myName);
1434     TValueHolder<TElemNum, med_int                   > anIndex  (anInfo.myIndex);
1435     TValueHolder<TElemNum, med_int                   > aConn    (anInfo.myConn);
1436     TValueHolder<EEntiteMaillage, med_entity_type    > anEntity (anInfo.myEntity);
1437     TValueHolder<EGeometrieElement, med_geometry_type> aGeom    (anInfo.myGeom);
1438     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1439
1440     TErr aRet = MEDmeshPolygon2Wr(myFile->Id(), &aMeshName,
1441                                   MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
1442                                   anEntity, aGeom,
1443                                   aConnMode, anInfo.myNbElem + 1,
1444                                   &anIndex, &aConn);
1445     if (theErr)
1446       *theErr = aRet;
1447     else if (aRet < 0)
1448       EXCEPTION(std::runtime_error, "SetPolygoneInfo - MEDmeshPolygonWr(...)");
1449
1450     SetNames(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1451     if (theErr)
1452       *theErr = aRet;
1453
1454     SetNumeration(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1455     if (theErr)
1456       *theErr = aRet;
1457
1458     SetFamilies(anInfo, theInfo.myEntity, anInfo.myGeom, &aRet);
1459     if (theErr)
1460       *theErr = aRet;
1461   }
1462
1463   //----------------------------------------------------------------------------
1464   PPolygoneInfo
1465   TWrapper
1466   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1467                    EEntiteMaillage theEntity,
1468                    EGeometrieElement theGeom,
1469                    TInt theNbElem,
1470                    TInt theConnSize,
1471                    EConnectivite theConnMode,
1472                    EBooleen theIsElemNum,
1473                    EBooleen theIsElemNames)
1474   {
1475     return PPolygoneInfo(new TTPolygoneInfo
1476                          (theMeshInfo,
1477                           theEntity,
1478                           theGeom,
1479                           theNbElem,
1480                           theConnSize,
1481                           theConnMode,
1482                           theIsElemNum,
1483                           theIsElemNames));
1484   }
1485
1486   //----------------------------------------------------------------------------
1487   PPolygoneInfo
1488   TWrapper
1489   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1490                    EEntiteMaillage theEntity,
1491                    EGeometrieElement theGeom,
1492                    const TIntVector& theIndexes,
1493                    const TIntVector& theConnectivities,
1494                    EConnectivite theConnMode,
1495                    const TIntVector& theFamilyNums,
1496                    const TIntVector& theElemNums,
1497                    const TStringVector& theElemNames)
1498   {
1499     return PPolygoneInfo(new TTPolygoneInfo
1500                          (theMeshInfo,
1501                           theEntity,
1502                           theGeom,
1503                           theIndexes,
1504                           theConnectivities,
1505                           theConnMode,
1506                           theFamilyNums,
1507                           theElemNums,
1508                           theElemNames));
1509   }
1510
1511   //----------------------------------------------------------------------------
1512   PPolygoneInfo
1513   TWrapper
1514   ::CrPolygoneInfo(const PMeshInfo& theMeshInfo,
1515                    const PPolygoneInfo& theInfo)
1516   {
1517     return PPolygoneInfo(new TTPolygoneInfo
1518                          (theMeshInfo,
1519                           theInfo));
1520   }
1521
1522   //----------------------------------------------------------------------------
1523   PPolygoneInfo
1524   TWrapper
1525   ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
1526                      EEntiteMaillage theEntity,
1527                      EGeometrieElement theGeom,
1528                      EConnectivite theConnMode)
1529   {
1530     if (theMeshInfo->GetType() != eNON_STRUCTURE)
1531       return PPolygoneInfo();
1532
1533     TInt aNbElem = GetNbPolygones(theMeshInfo, theEntity, theGeom, theConnMode);
1534     TInt aConnSize = GetPolygoneConnSize(theMeshInfo, theEntity, theGeom, theConnMode);
1535     PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo, theEntity, theGeom, aNbElem, aConnSize, theConnMode);
1536     GetPolygoneInfo(anInfo);
1537
1538 #ifdef _DEBUG_
1539     INITMSG(MYDEBUG, "GetPPolygoneInfo"<<
1540             " - theGeom = "<<theGeom<<
1541             "; aNbElem = "<<aNbElem<<": ");
1542     for (TInt iElem = 1; iElem < aNbElem; iElem++) {
1543       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
1544       TInt aConnDim = aConnSlice.size();
1545       for (TInt iConn = 0; iConn < aConnDim; iConn++) {
1546         ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1547       }
1548       ADDMSG(MYDEBUG, " ");
1549     }
1550     ADDMSG(MYDEBUG, std::endl);
1551 #endif
1552
1553     return anInfo;
1554   }
1555
1556   //----------------------------------------------------------------------------
1557   TInt
1558   TWrapper
1559   ::GetNbPolyedres(const MED::TMeshInfo& theMeshInfo,
1560                    EEntiteMaillage theEntity,
1561                    EGeometrieElement theGeom,
1562                    EConnectivite theConnMode,
1563                    TErr* theErr)
1564   {
1565     return GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode, theErr);
1566   }
1567
1568   //----------------------------------------------------------------------------
1569   void
1570   TWrapper
1571   ::GetPolyedreConnSize(const TMeshInfo& theMeshInfo,
1572                         TInt& theNbFaces,
1573                         TInt& theConnSize,
1574                         EConnectivite theConnMode,
1575                         TErr* theErr)
1576   {
1577     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1578
1579     if (theErr && *theErr < 0)
1580       EXCEPTION(std::runtime_error, "GetPolyedreConnSize - (...)");
1581
1582     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
1583
1584     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1585     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theConnMode);
1586     //TValueHolder<TInt, med_int> aNbFaces(theNbFaces);
1587     //TValueHolder<TInt, med_int> aConnSize(theConnSize);
1588
1589     med_bool chgt, trsf;
1590     theNbFaces = MEDmeshnEntity(myFile->Id(),
1591                                 &aMeshName,
1592                                 MED_NO_DT,
1593                                 MED_NO_IT,
1594                                 MED_CELL,
1595                                 MED_POLYHEDRON,
1596                                 MED_INDEX_NODE,
1597                                 aConnMode,
1598                                 &chgt,
1599                                 &trsf);
1600
1601     theConnSize = MEDmeshnEntity(myFile->Id(),
1602                                  &aMeshName,
1603                                  MED_NO_DT,
1604                                  MED_NO_IT,
1605                                  MED_CELL,
1606                                  MED_POLYHEDRON,
1607                                  MED_CONNECTIVITY,
1608                                  aConnMode,
1609                                  &chgt,
1610                                  &trsf);
1611
1612     if (theNbFaces < 0 || theConnSize<0)
1613       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshnEntity(...)");
1614
1615   }
1616
1617   //-----------------------------------------------------------------
1618   void
1619   TWrapper
1620   ::GetPolyedreInfo(TPolyedreInfo& theInfo,
1621                     TErr* theErr)
1622   {
1623     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1624
1625     if (theErr && *theErr < 0)
1626       return;
1627
1628     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
1629
1630     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1631     TInt aNbElem = (TInt)theInfo.myElemNum->size();
1632     TValueHolder<TElemNum, med_int> anIndex(theInfo.myIndex);
1633     TValueHolder<TElemNum, med_int> aFaces(theInfo.myFaces);
1634     TValueHolder<TElemNum, med_int> aConn(theInfo.myConn);
1635     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(theInfo.myConnMode);
1636
1637     TErr aRet;
1638     aRet = MEDmeshPolyhedronRd(myFile->Id(),
1639                                &aMeshName,
1640                                MED_NO_DT,
1641                                MED_NO_IT,
1642                                MED_CELL,
1643                                aConnMode,
1644                                &anIndex,
1645                                &aFaces,
1646                                &aConn);
1647
1648     if (theErr)
1649       *theErr = aRet;
1650     else if (aRet < 0)
1651       EXCEPTION(std::runtime_error, "GetPolygoneInfo - MEDmeshPolyhedronRd(...)");
1652
1653     if (theInfo.myIsElemNames) {
1654       GetNames(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1655       if (theErr)
1656         *theErr = aRet;
1657     }
1658
1659     if (theInfo.myIsElemNum) {
1660       GetNumeration(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1661       if (theErr)
1662         *theErr = aRet;
1663     }
1664
1665     GetFamilies(theInfo, aNbElem, theInfo.myEntity, ePOLYEDRE, &aRet);
1666     if (theErr)
1667       *theErr = aRet;
1668   }
1669
1670   //----------------------------------------------------------------------------
1671   void
1672   TWrapper
1673   ::SetPolyedreInfo(const TPolyedreInfo& theInfo,
1674                     TErr* theErr)
1675   {
1676     SetPolyedreInfo(theInfo, eLECTURE_ECRITURE, theErr);
1677   }
1678
1679   //----------------------------------------------------------------------------
1680   void
1681   TWrapper
1682   ::SetPolyedreInfo(const MED::TPolyedreInfo& theInfo,
1683                     EModeAcces theMode,
1684                     TErr* theErr)
1685   {
1686     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
1687
1688     if (theErr && *theErr < 0)
1689       return;
1690
1691     MED::TPolyedreInfo& anInfo = const_cast<MED::TPolyedreInfo&>(theInfo);
1692     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
1693
1694     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
1695     TValueHolder<TElemNum, med_int> anIndex(anInfo.myIndex);
1696     TValueHolder<TElemNum, med_int> aFaces(anInfo.myFaces);
1697     TValueHolder<TElemNum, med_int> aConn(anInfo.myConn);
1698     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode(anInfo.myConnMode);
1699
1700     TErr aRet;
1701     aRet = MEDmeshPolyhedronWr(myFile->Id(),
1702                                &aMeshName,
1703                                MED_NO_DT,
1704                                MED_NO_IT,
1705                                MED_UNDEF_DT,
1706                                MED_CELL,
1707                                aConnMode,
1708                                anInfo.myNbElem+1,
1709                                &anIndex,
1710                                (TInt)anInfo.myFaces->size(),
1711                                &aFaces,
1712                                &aConn);
1713
1714     if (theErr)
1715       *theErr = aRet;
1716     else if (aRet < 0)
1717       EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshPolyhedronWr(...)");
1718
1719     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(anInfo.myEntity);
1720
1721     if (theInfo.myIsElemNames) {
1722       TValueHolder<TString, char> anElemNames(anInfo.myElemNames);
1723       aRet = MEDmeshEntityNameWr(myFile->Id(),
1724                                  &aMeshName,
1725                                  MED_NO_DT,
1726                                  MED_NO_IT,
1727                                  anEntity,
1728                                  MED_POLYHEDRON,
1729                                  (TInt)anInfo.myElemNames->size(),
1730                                  &anElemNames);
1731       if (theErr)
1732         *theErr = aRet;
1733       else if (aRet < 0)
1734         EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNameWr(...)");
1735     }
1736
1737     if (theInfo.myIsElemNum) {
1738       TValueHolder<TElemNum, med_int> anElemNum(anInfo.myElemNum);
1739       aRet = MEDmeshEntityNumberWr(myFile->Id(),
1740                                    &aMeshName,
1741                                    MED_NO_DT,
1742                                    MED_NO_IT,
1743                                    anEntity,
1744                                    MED_POLYHEDRON,
1745                                    (TInt)anInfo.myElemNum->size(),
1746                                    &anElemNum);
1747       if (theErr)
1748         *theErr = aRet;
1749       else if (aRet < 0)
1750         EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityNumberWr(...)");
1751     }
1752
1753     TValueHolder<TElemNum, med_int> aFamNum(anInfo.myFamNum);
1754     aRet = MEDmeshEntityFamilyNumberWr(myFile->Id(),
1755                                        &aMeshName,
1756                                        MED_NO_DT,
1757                                        MED_NO_IT,
1758                                        anEntity,
1759                                        MED_POLYHEDRON,
1760                                        (TInt)anInfo.myFamNum->size(),
1761                                        &aFamNum);
1762
1763     if (theErr)
1764       *theErr = aRet;
1765     else if (aRet < 0)
1766       EXCEPTION(std::runtime_error, "SetPolyedreInfo - MEDmeshEntityFamilyNumberWr(...)");
1767   }
1768
1769   //----------------------------------------------------------------------------
1770   PPolyedreInfo
1771   TWrapper
1772   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1773                    EEntiteMaillage theEntity,
1774                    EGeometrieElement theGeom,
1775                    TInt theNbElem,
1776                    TInt theNbFaces,
1777                    TInt theConnSize,
1778                    EConnectivite theConnMode,
1779                    EBooleen theIsElemNum,
1780                    EBooleen theIsElemNames)
1781   {
1782     return PPolyedreInfo(new TTPolyedreInfo
1783                          (theMeshInfo,
1784                           theEntity,
1785                           theGeom,
1786                           theNbElem,
1787                           theNbFaces,
1788                           theConnSize,
1789                           theConnMode,
1790                           theIsElemNum,
1791                           theIsElemNames));
1792   }
1793
1794   //----------------------------------------------------------------------------
1795   PPolyedreInfo
1796   TWrapper
1797   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1798                    EEntiteMaillage theEntity,
1799                    EGeometrieElement theGeom,
1800                    const TIntVector& theIndexes,
1801                    const TIntVector& theFaces,
1802                    const TIntVector& theConnectivities,
1803                    EConnectivite theConnMode,
1804                    const TIntVector& theFamilyNums,
1805                    const TIntVector& theElemNums,
1806                    const TStringVector& theElemNames)
1807   {
1808     return PPolyedreInfo(new TTPolyedreInfo
1809                          (theMeshInfo,
1810                           theEntity,
1811                           theGeom,
1812                           theIndexes,
1813                           theFaces,
1814                           theConnectivities,
1815                           theConnMode,
1816                           theFamilyNums,
1817                           theElemNums,
1818                           theElemNames));
1819   }
1820
1821   //----------------------------------------------------------------------------
1822   PPolyedreInfo
1823   TWrapper
1824   ::CrPolyedreInfo(const PMeshInfo& theMeshInfo,
1825                    const PPolyedreInfo& theInfo)
1826   {
1827     return PPolyedreInfo(new TTPolyedreInfo
1828                          (theMeshInfo,
1829                           theInfo));
1830   }
1831
1832   //----------------------------------------------------------------------------
1833   PPolyedreInfo
1834   TWrapper
1835   ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
1836                      EEntiteMaillage theEntity,
1837                      EGeometrieElement theGeom,
1838                      EConnectivite theConnMode)
1839   {
1840     if (theMeshInfo->GetType() != eNON_STRUCTURE)
1841       return PPolyedreInfo();
1842     TInt aNbElem = GetNbPolyedres(theMeshInfo, theEntity, theGeom, theConnMode);
1843     TInt aNbFaces, aConnSize;
1844     GetPolyedreConnSize(theMeshInfo, aNbFaces, aConnSize, theConnMode);
1845     PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo, theEntity, theGeom, aNbElem, aNbFaces, aConnSize, theConnMode);
1846     GetPolyedreInfo(anInfo);
1847
1848 #ifdef _DEBUG_
1849     INITMSG(MYDEBUG, "GetPPolyedreInfo"<<
1850             " - theGeom = "<<theGeom<<
1851             "; aNbElem = "<<aNbElem<<": ");
1852     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
1853       TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
1854       TInt aNbFaces = aConnSliceArr.size();
1855       ADDMSG(MYDEBUG, "{");
1856       for (TInt iFace = 0; iFace < aNbFaces; iFace++) {
1857         TCConnSlice aConnSlice = aConnSliceArr[iFace];
1858         TInt aNbConn = aConnSlice.size();
1859         ADDMSG(MYDEBUG, "[");
1860         for (TInt iConn = 0; iConn < aNbConn; iConn++) {
1861           ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
1862         }
1863         ADDMSG(MYDEBUG, "] ");
1864       }
1865       ADDMSG(MYDEBUG, "} ");
1866     }
1867     ADDMSG(MYDEBUG, std::endl);
1868 #endif
1869
1870     return anInfo;
1871   }
1872
1873   //-----------------------------------------------------------------
1874   TEntityInfo
1875   TWrapper
1876   ::GetEntityInfo(const MED::TMeshInfo& theMeshInfo,
1877                   EConnectivite theConnMode,
1878                   TErr* theErr)
1879   {
1880     TEntityInfo anInfo;
1881
1882     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1883
1884     if (theErr && *theErr < 0)
1885       return anInfo;
1886
1887     if (theMeshInfo.GetType() == eNON_STRUCTURE) {
1888       TInt aNbElem = GetNbNodes(theMeshInfo);
1889       if (aNbElem > 0) {
1890         anInfo[eNOEUD][ePOINT1] = aNbElem;
1891         const TEntity2GeomSet& anEntity2GeomSet = GetEntity2GeomSet();
1892         TEntity2GeomSet::const_iterator anIter = anEntity2GeomSet.begin();
1893         TEntity2GeomSet::const_iterator anIterEnd = anEntity2GeomSet.end();
1894         for (; anIter != anIterEnd; anIter++) {
1895           const EEntiteMaillage& anEntity = anIter->first;
1896           const TGeomSet& aGeomSet = anIter->second;
1897           TGeomSet::const_iterator anIter2 = aGeomSet.begin();
1898           TGeomSet::const_iterator anIterEnd2 = aGeomSet.end();
1899           for (; anIter2 != anIterEnd2; anIter2++) {
1900             const EGeometrieElement& aGeom = *anIter2;
1901             aNbElem = GetNbCells(theMeshInfo, anEntity, aGeom, theConnMode, theErr);
1902             if (aNbElem > 0) {
1903               if (anEntity == eSTRUCT_ELEMENT) {
1904                 const TInt nbStructTypes = aNbElem;
1905                 for (TInt structType = 0; structType < nbStructTypes; ++structType) {
1906                   // check type name to keep only "MED_BALL" structured element
1907                   TValueHolder<TString, char> aMeshName((TString&) theMeshInfo.myName);
1908                   char                        geotypename[ MED_NAME_SIZE + 1] = "";
1909                   med_geometry_type           geotype;
1910                   MEDmeshEntityInfo(myFile->Id(), &aMeshName, MED_NO_DT, MED_NO_IT,
1911                                     med_entity_type(anEntity), structType+1,
1912                                     geotypename, &geotype);
1913                   if (strcmp(geotypename, MED_BALL_NAME) == 0) {
1914                     aNbElem = GetNbCells(theMeshInfo, anEntity, EGeometrieElement(geotype),
1915                                          theConnMode, theErr);
1916                     if (aNbElem > 0)
1917                       anInfo[anEntity][EGeometrieElement(geotype)] = aNbElem;
1918                   }
1919                 }
1920               }
1921               else {
1922                 anInfo[anEntity][aGeom] = aNbElem;
1923               }
1924             }
1925           }
1926         }
1927       }
1928     }
1929     else { // eSTRUCTURE
1930       EGrilleType aGrilleType;
1931       TInt aNbNodes = 1;
1932       TInt aNbElem  = 1;
1933       TInt aNbSub   = 0;
1934       TInt aDim = theMeshInfo.GetDim();
1935       EGeometrieElement aGeom, aSubGeom;
1936       EEntiteMaillage aSubEntity = eMAILLE;
1937
1938       GetGrilleType(theMeshInfo, aGrilleType);
1939
1940       TIntVector aStruct(aDim);
1941       if (aGrilleType == eGRILLE_STANDARD)
1942         {
1943           GetGrilleStruct(theMeshInfo, aStruct, theErr);
1944         }
1945       else
1946         { // eGRILLE_CARTESIENNE and eGRILLE_POLAIRE
1947           ETable aTable[3] = { eCOOR_IND1, eCOOR_IND2, eCOOR_IND3 };
1948           for (med_int anAxis = 0; anAxis < aDim; anAxis++)
1949             aStruct[ anAxis ] = GetNbNodes(theMeshInfo, aTable[anAxis]);
1950         }
1951       for (med_int i = 0; i < aDim; i++) {
1952         aNbNodes = aNbNodes * aStruct[i];
1953         aNbElem = aNbElem * (aStruct[i] - 1);
1954       }
1955       switch (aDim) {
1956       case 1:
1957         aGeom = eSEG2;
1958         break;
1959       case 2:
1960         aGeom = eQUAD4;
1961         aSubGeom = eSEG2;
1962         aSubEntity = eARETE;
1963         aNbSub =
1964           (aStruct[0])   * (aStruct[1]-1) +
1965           (aStruct[0]-1) * (aStruct[1]);
1966         break;
1967       case 3:
1968         aGeom = eHEXA8;
1969         aSubGeom = eQUAD4;
1970         aSubEntity = eFACE;
1971         aNbSub =
1972           (aStruct[0])   * (aStruct[1]-1) * (aStruct[2]-1) +
1973           (aStruct[0]-1) * (aStruct[1])   * (aStruct[2]-1) +
1974           (aStruct[0]-1) * (aStruct[1]-1) * (aStruct[2]);
1975         break;
1976       }
1977       anInfo[eNOEUD][ePOINT1] = aNbNodes;
1978       anInfo[eMAILLE][aGeom] = aNbElem;
1979       if (aDim > 1)
1980         anInfo[aSubEntity][aSubGeom] = aNbSub;
1981     }
1982     return anInfo;
1983   }
1984
1985   //-----------------------------------------------------------------
1986   TInt
1987   TWrapper
1988   ::GetNbCells(const MED::TMeshInfo& theMeshInfo,
1989                EEntiteMaillage theEntity,
1990                EGeometrieElement theGeom,
1991                EConnectivite theConnMode,
1992                TErr* theErr)
1993   {
1994     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
1995
1996     if (theErr && *theErr < 0)
1997       return -1;
1998
1999     MED::TMeshInfo& aMeshInfo = const_cast<MED::TMeshInfo&>(theMeshInfo);
2000     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2001     med_bool chgt, trsf;
2002     switch (theGeom)
2003       {
2004       case MED::ePOLYGONE:
2005       case MED::ePOLYGON2:
2006         {
2007           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2008                                 MED_NO_DT, MED_NO_IT,
2009                                 med_entity_type(theEntity), med_geometry_type(theGeom),
2010                                 MED_INDEX_NODE, med_connectivity_mode(theConnMode),
2011                                 &chgt, &trsf)-1;
2012         }
2013       case MED::ePOLYEDRE:
2014         {
2015           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2016                                 MED_NO_DT, MED_NO_IT,
2017                                 med_entity_type(theEntity), MED_POLYHEDRON,
2018                                 MED_INDEX_FACE, med_connectivity_mode(theConnMode),
2019                                 &chgt, &trsf)-1;
2020         }
2021       case MED::eBALL:
2022         {
2023           return GetNbBalls(theMeshInfo);
2024         }
2025       default:
2026         {
2027           return MEDmeshnEntity(myFile->Id(), &aMeshName,
2028                                 MED_NO_DT, MED_NO_IT,
2029                                 med_entity_type(theEntity), med_geometry_type(theGeom),
2030                                 MED_CONNECTIVITY, med_connectivity_mode(theConnMode),
2031                                 &chgt, &trsf);
2032         }
2033       }
2034     return 0;
2035   }
2036
2037   //----------------------------------------------------------------------------
2038   void
2039   TWrapper
2040   ::GetCellInfo(MED::TCellInfo& theInfo,
2041                 TErr* theErr)
2042   {
2043     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2044
2045     if (theErr && *theErr < 0)
2046       return;
2047
2048     MED::TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
2049
2050     TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
2051     TValueHolder<TElemNum, med_int>                    aConn        (theInfo.myConn);
2052     TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (theInfo.myModeSwitch);
2053     TValueHolder<TString, char>                        anElemNames  (theInfo.myElemNames);
2054     TValueHolder<EBooleen, med_bool>                   anIsElemNames(theInfo.myIsElemNames);
2055     TValueHolder<TElemNum, med_int>                    anElemNum    (theInfo.myElemNum);
2056     TValueHolder<EBooleen, med_bool>                   anIsElemNum  (theInfo.myIsElemNum);
2057     TValueHolder<TElemNum, med_int>                    aFamNum      (theInfo.myFamNum);
2058     TValueHolder<EBooleen, med_bool>                   anIsFamNum   (theInfo.myIsFamNum);
2059     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (theInfo.myEntity);
2060     TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (theInfo.myGeom);
2061     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (theInfo.myConnMode);
2062
2063     TErr aRet;
2064     aRet = MEDmeshElementRd(myFile->Id(),
2065                             &aMeshName,
2066                             MED_NO_DT,
2067                             MED_NO_IT,
2068                             anEntity,
2069                             aGeom,
2070                             aConnMode,
2071                             aModeSwitch,
2072                             &aConn,
2073                             &anIsElemNames,
2074                             &anElemNames,
2075                             &anIsElemNum,
2076                             &anElemNum,
2077                             &anIsFamNum,
2078                             &aFamNum);
2079
2080     if (theErr)
2081       *theErr = aRet;
2082     else if (aRet < 0)
2083       EXCEPTION(std::runtime_error, "GetCellInfo - MEDmeshElementRd(...)");
2084
2085     if (anIsFamNum == MED_FALSE)
2086       {
2087         int mySize = (int) theInfo.myFamNum->size();
2088         theInfo.myFamNum->clear();
2089         theInfo.myFamNum->resize(mySize, 0);
2090       }
2091
2092   }
2093
2094   //----------------------------------------------------------------------------
2095   void
2096   TWrapper
2097   ::SetCellInfo(const MED::TCellInfo& theInfo,
2098                 TErr* theErr)
2099   {
2100     SetCellInfo(theInfo, eLECTURE_ECRITURE, theErr);
2101   }
2102
2103   //----------------------------------------------------------------------------
2104   void
2105   TWrapper
2106   ::SetCellInfo(const MED::TCellInfo& theInfo,
2107                 EModeAcces theMode,
2108                 TErr* theErr)
2109   {
2110     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2111
2112     if (theErr && *theErr < 0)
2113       return;
2114
2115     MED::TCellInfo& anInfo    = const_cast<MED::TCellInfo&>(theInfo);
2116     MED::TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
2117
2118     TValueHolder<TString, char>                        aMeshName    (aMeshInfo.myName);
2119     TValueHolder<TElemNum, med_int>                    aConn        (anInfo.myConn);
2120     TValueHolder<EModeSwitch, med_switch_mode>         aModeSwitch  (anInfo.myModeSwitch);
2121     TValueHolder<TString, char>                        anElemNames  (anInfo.myElemNames);
2122     TValueHolder<EBooleen, med_bool>                   anIsElemNames(anInfo.myIsElemNames);
2123     TValueHolder<TElemNum, med_int>                    anElemNum    (anInfo.myElemNum);
2124     TValueHolder<EBooleen, med_bool>                   anIsElemNum  (anInfo.myIsElemNum);
2125     TValueHolder<TElemNum, med_int>                    aFamNum      (anInfo.myFamNum);
2126     TValueHolder<EBooleen, med_bool>                   anIsFamNum   (anInfo.myIsFamNum);
2127     TValueHolder<EEntiteMaillage, med_entity_type>     anEntity     (anInfo.myEntity);
2128     TValueHolder<EGeometrieElement, med_geometry_type> aGeom        (anInfo.myGeom);
2129     TValueHolder<EConnectivite, med_connectivity_mode> aConnMode    (anInfo.myConnMode);
2130     TValueHolder<TInt, med_int>                        aNbElem      (anInfo.myNbElem);
2131
2132     TErr aRet;
2133     aRet = MEDmeshElementConnectivityWr(myFile->Id(),
2134                                         &aMeshName,
2135                                         MED_NO_DT,
2136                                         MED_NO_IT,
2137                                         MED_UNDEF_DT,
2138                                         anEntity,
2139                                         aGeom,
2140                                         aConnMode,
2141                                         aModeSwitch,
2142                                         aNbElem,
2143                                         &aConn);
2144
2145     MEDmeshEntityFamilyNumberWr(myFile->Id(),
2146                                 &aMeshName,
2147                                 MED_NO_DT,
2148                                 MED_NO_IT,
2149                                 anEntity,
2150                                 aGeom,
2151                                 aNbElem,
2152                                 &aFamNum);
2153     if (anIsElemNames)
2154       MEDmeshEntityNameWr(myFile->Id(),
2155                           &aMeshName,
2156                           MED_NO_DT,
2157                           MED_NO_IT,
2158                           anEntity,
2159                           aGeom,
2160                           aNbElem,
2161                           &anElemNames);
2162     if (anIsElemNum)
2163       MEDmeshEntityNumberWr(myFile->Id(),
2164                             &aMeshName,
2165                             MED_NO_DT,
2166                             MED_NO_IT,
2167                             anEntity,
2168                             aGeom,
2169                             aNbElem,
2170                             &anElemNum);
2171     if (theErr)
2172       *theErr = aRet;
2173     else if (aRet < 0)
2174       EXCEPTION(std::runtime_error, "SetCellInfo - MEDmeshElementWr(...), ret="<< aRet);
2175   }
2176
2177   //----------------------------------------------------------------------------
2178   PCellInfo
2179   TWrapper
2180   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2181                EEntiteMaillage theEntity,
2182                EGeometrieElement theGeom,
2183                TInt theNbElem,
2184                EConnectivite theConnMode,
2185                EBooleen theIsElemNum,
2186                EBooleen theIsElemNames,
2187                EModeSwitch theMode)
2188   {
2189     return PCellInfo(new TTCellInfo
2190                      (theMeshInfo,
2191                       theEntity,
2192                       theGeom,
2193                       theNbElem,
2194                       theConnMode,
2195                       theIsElemNum,
2196                       theIsElemNames,
2197                       theMode));
2198   }
2199
2200   //----------------------------------------------------------------------------
2201   PCellInfo
2202   TWrapper
2203   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2204                EEntiteMaillage theEntity,
2205                EGeometrieElement theGeom,
2206                const TIntVector& theConnectivities,
2207                EConnectivite theConnMode,
2208                const TIntVector& theFamilyNums,
2209                const TIntVector& theElemNums,
2210                const TStringVector& theElemNames,
2211                EModeSwitch theMode)
2212   {
2213     return PCellInfo(new TTCellInfo
2214                      (theMeshInfo,
2215                       theEntity,
2216                       theGeom,
2217                       theConnectivities,
2218                       theConnMode,
2219                       theFamilyNums,
2220                       theElemNums,
2221                       theElemNames,
2222                       theMode));
2223   }
2224
2225   //----------------------------------------------------------------------------
2226   PCellInfo
2227   TWrapper
2228   ::CrCellInfo(const PMeshInfo& theMeshInfo,
2229                const PCellInfo& theInfo)
2230   {
2231     return PCellInfo(new TTCellInfo
2232                      (theMeshInfo,
2233                       theInfo));
2234   }
2235
2236   //----------------------------------------------------------------------------
2237   PCellInfo
2238   TWrapper
2239   ::GetPCellInfo(const PMeshInfo& theMeshInfo,
2240                  EEntiteMaillage theEntity,
2241                  EGeometrieElement theGeom,
2242                  EConnectivite theConnMode,
2243                  TErr* theErr)
2244   {
2245     if (theMeshInfo->GetType() != eNON_STRUCTURE)
2246       return PCellInfo();
2247     TInt aNbElem = GetNbCells(theMeshInfo, theEntity, theGeom, theConnMode);
2248     PCellInfo anInfo = CrCellInfo(theMeshInfo, theEntity, theGeom, aNbElem, theConnMode);
2249     GetCellInfo(anInfo, theErr);
2250
2251 #ifdef _DEBUG_
2252     TInt aConnDim = anInfo->GetConnDim();
2253     INITMSG(MYDEBUG, "GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
2254     BEGMSG(MYDEBUG, "GetPCellInfo - aNbElem: "<<aNbElem<<": ");
2255     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2256       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
2257       for (TInt iConn = 0; iConn < aConnDim; iConn++) {
2258         ADDMSG(MYVALUEDEBUG, aConnSlice[iConn]<<",");
2259       }
2260       ADDMSG(MYVALUEDEBUG, " ");
2261     }
2262     ADDMSG(MYDEBUG, std::endl);
2263
2264     BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetFamNum: ");
2265     for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2266       ADDMSG(MYVALUEDEBUG, anInfo->GetFamNum(iElem)<<", ");
2267     }
2268     ADDMSG(MYVALUEDEBUG, std::endl);
2269
2270     if (anInfo->IsElemNum()) {
2271       BEGMSG(MYVALUEDEBUG, "GetPCellInfo - GetElemNum: ");
2272       for (TInt iElem = 0; iElem < aNbElem; iElem++) {
2273         ADDMSG(MYVALUEDEBUG, anInfo->GetElemNum(iElem)<<", ");
2274       }
2275       ADDMSG(MYVALUEDEBUG, std::endl);
2276     }
2277     ADDMSG(MYDEBUG, std::endl);
2278 #endif
2279
2280     return anInfo;
2281   }
2282
2283   //----------------------------------------------------------------------------
2284   EGeometrieElement
2285   TWrapper
2286   ::GetBallGeom(const TMeshInfo& theMeshInfo)
2287   {
2288     TErr anError;
2289     TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
2290
2291     // read med_geometry_type of "MED_BALL" element
2292     char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2293     return EGeometrieElement(MEDstructElementGeotype(myFile->Id(), geotypename));
2294   }
2295
2296   //----------------------------------------------------------------------------
2297   TInt
2298   TWrapper
2299   ::GetNbBalls(const TMeshInfo& theMeshInfo)
2300   {
2301     TErr anError;
2302     TFileWrapper aFileWrapper(myFile, eLECTURE, &anError, myMinor);
2303
2304     EGeometrieElement ballType = GetBallGeom(theMeshInfo);
2305     if (ballType < 0)
2306       return 0;
2307
2308     return GetNbCells(theMeshInfo, eSTRUCT_ELEMENT, ballType, eNOD);
2309   }
2310
2311   //----------------------------------------------------------------------------
2312   void
2313   TWrapper
2314   ::GetBallInfo(TBallInfo& theInfo,
2315                 TErr* theErr)
2316   {
2317     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2318
2319     // check geometry of MED_BALL
2320     if (theInfo.myGeom == eBALL)
2321       {
2322         theInfo.myGeom = GetBallGeom(*theInfo.myMeshInfo);
2323         if (theInfo.myGeom < 0) {
2324           if (!theErr)
2325             EXCEPTION(std::runtime_error, "GetBallInfo - no balls in the mesh");
2326           *theErr = theInfo.myGeom;
2327           return;
2328         }
2329       }
2330
2331     // read nodes ids
2332     GetCellInfo(theInfo);
2333
2334     // read diameters
2335     TValueHolder<TString, char>                        aMeshName (theInfo.myMeshInfo->myName);
2336     TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (theInfo.myGeom);
2337     TValueHolder<TFloatVector, void>                   aDiam     (theInfo.myDiameters);
2338     char varattname[ MED_NAME_SIZE + 1] = MED_BALL_DIAMETER;
2339
2340     TErr aRet = MEDmeshStructElementVarAttRd(myFile->Id(), &aMeshName,
2341                                              MED_NO_DT, MED_NO_IT,
2342                                              aGeom,
2343                                              varattname,
2344                                              &aDiam);
2345     if (theErr)
2346       *theErr = aRet;
2347     else if (aRet < 0)
2348       EXCEPTION(std::runtime_error, "GetBallInfo - pb at reading diameters");
2349   }
2350
2351   //----------------------------------------------------------------------------
2352   void
2353   TWrapper
2354   ::SetBallInfo(const TBallInfo& theInfo,
2355                 TErr* theErr)
2356   {
2357     SetBallInfo(theInfo, eLECTURE_ECRITURE, theErr);
2358   }
2359
2360   //----------------------------------------------------------------------------
2361   void
2362   TWrapper
2363   ::SetBallInfo(const TBallInfo& theInfo,
2364                 EModeAcces theMode,
2365                 TErr* theErr)
2366   {
2367     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2368
2369     TErr ret;
2370     char ballsupportname[MED_NAME_SIZE+1] = "BALL_SUPPORT_MESH";
2371     EGeometrieElement ballGeom = GetBallGeom(*theInfo.myMeshInfo);
2372     if (ballGeom < 0)
2373       {
2374         // no ball model in the file, create support mesh for it
2375         char dummyname [MED_NAME_SIZE*3+1] = "";
2376         if ((ret = MEDsupportMeshCr(myFile->Id(),
2377                                     ballsupportname,
2378                                     theInfo.myMeshInfo->GetSpaceDim(),
2379                                     theInfo.myMeshInfo->GetDim(),
2380                                     "Support mesh for a ball model",
2381                                     MED_CARTESIAN,
2382                                     /*axisname=*/dummyname,
2383                                     /*unitname=*/dummyname)) < 0) {
2384           if (!theErr)
2385             EXCEPTION(std::runtime_error, "SetBallInfo - MEDsupportMeshCr");
2386           *theErr = ret;
2387           return;
2388         }
2389         // write coordinates of 1 node
2390         med_float coord[3] = {0, 0, 0};
2391         if ((ret = MEDmeshNodeCoordinateWr(myFile->Id(),
2392                                            ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
2393                                            MED_FULL_INTERLACE, /*nnode=*/1, coord)) < 0) {
2394           if (!theErr)
2395             EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshNodeCoordinateWr");
2396           *theErr = ret;
2397           return;
2398         }
2399         // ball model creation
2400         char geotypename[ MED_NAME_SIZE + 1] = MED_BALL_NAME;
2401         if ((ballGeom = (EGeometrieElement) MEDstructElementCr(myFile->Id(),
2402                                                                geotypename,
2403                                                                theInfo.myMeshInfo->GetSpaceDim(),
2404                                                                ballsupportname,
2405                                                                MED_NODE,MED_NONE)) < 0) {
2406           if (!theErr)
2407             EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementCr");
2408           *theErr = ret;
2409           return;
2410         }
2411         // create diameter attribute
2412         if ((ret = MEDstructElementVarAttCr(myFile->Id(),
2413                                             geotypename, MED_BALL_DIAMETER,
2414                                             MED_ATT_FLOAT64, /*ncomp=*/1)) < 0) {
2415           if (!theErr)
2416             EXCEPTION(std::runtime_error, "SetBallInfo - MEDstructElementVarAttCr");
2417           *theErr = ret;
2418           return;
2419         }
2420       } // ballGeom < 0
2421
2422     TBallInfo& aBallInfo = ((TBallInfo&) theInfo);
2423     aBallInfo.myGeom = ballGeom;
2424
2425     // write node ids
2426     SetCellInfo(theInfo, theMode, theErr);
2427     if (theErr && theErr < 0)
2428       return;
2429
2430     // write diameter
2431     TValueHolder<TString, char>                        aMeshName (aBallInfo.myMeshInfo->myName);
2432     TValueHolder<EGeometrieElement, med_geometry_type> aGeom     (aBallInfo.myGeom);
2433     TValueHolder<TFloatVector, void>                   aDiam     (aBallInfo.myDiameters);
2434     ret = MEDmeshStructElementVarAttWr(myFile->Id(), &aMeshName,
2435                                        MED_NO_DT, MED_NO_IT,
2436                                        aGeom, MED_BALL_DIAMETER,
2437                                        theInfo.myNbElem, &aDiam);
2438     if (theErr)
2439       *theErr = ret;
2440     else if (ret < 0)
2441       EXCEPTION(std::runtime_error, "SetBallInfo - MEDmeshStructElementVarAttWr");
2442   }
2443
2444   //----------------------------------------------------------------------------
2445   PBallInfo
2446   TWrapper
2447   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2448                TInt theNbBalls,
2449                EBooleen theIsElemNum)
2450   {
2451     return PBallInfo(new TTBallInfo(theMeshInfo, theNbBalls, theIsElemNum));
2452   }
2453
2454   //----------------------------------------------------------------------------
2455   PBallInfo
2456   TWrapper
2457   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2458                const TIntVector& theNodes,
2459                TFloatVector& theDiameters,
2460                const TIntVector& theFamilyNums,
2461                const TIntVector& theElemNums)
2462   {
2463     return PBallInfo(new TTBallInfo(theMeshInfo, theNodes, theDiameters,
2464                                     theFamilyNums, theElemNums));
2465   }
2466
2467   //----------------------------------------------------------------------------
2468   PBallInfo
2469   TWrapper
2470   ::CrBallInfo(const PMeshInfo& theMeshInfo,
2471                const PBallInfo& theInfo)
2472   {
2473     return PBallInfo(new TTBallInfo(theMeshInfo, theInfo));
2474   }
2475
2476   //----------------------------------------------------------------------------
2477   PBallInfo
2478   TWrapper
2479   ::GetPBallInfo(const PMeshInfo& theMeshInfo)
2480   {
2481     TInt nbBalls = GetNbBalls(theMeshInfo);
2482     if (nbBalls < 1) return PBallInfo();
2483
2484     PBallInfo anInfo = CrBallInfo(theMeshInfo, nbBalls);
2485     GetBallInfo(anInfo);
2486
2487     return anInfo;
2488   }
2489
2490   //-----------------------------------------------------------------
2491   TInt
2492   TWrapper
2493   ::GetNbFields(TErr* theErr)
2494   {
2495     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2496
2497     if (theErr && *theErr < 0)
2498       return -1;
2499
2500     return MEDnField(myFile->Id());
2501   }
2502
2503   //----------------------------------------------------------------------------
2504   TInt
2505   TWrapper
2506   ::GetNbComp(TInt theFieldId,
2507               TErr* theErr)
2508   {
2509     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2510
2511     if (theErr && *theErr < 0)
2512       return -1;
2513
2514     return MEDfieldnComponent(myFile->Id(), theFieldId);
2515   }
2516
2517   //----------------------------------------------------------------------------
2518   void
2519   TWrapper
2520   ::GetFieldInfo(TInt theFieldId,
2521                  MED::TFieldInfo& theInfo,
2522                  TErr* theErr)
2523   {
2524     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2525
2526     if (theErr && *theErr < 0)
2527       return;
2528
2529     TString aFieldName(256); // Protect from memory problems with too long names
2530     TValueHolder<ETypeChamp, med_field_type> aType(theInfo.myType);
2531     TValueHolder<TString, char> aCompNames(theInfo.myCompNames);
2532     TValueHolder<TString, char> anUnitNames(theInfo.myUnitNames);
2533     MED::TMeshInfo& aMeshInfo = theInfo.myMeshInfo;
2534
2535     TErr aRet;
2536     med_bool local;
2537     char dtunit[MED_SNAME_SIZE+1];
2538     char local_mesh_name[MED_NAME_SIZE+1]="";
2539     med_int nbofstp;
2540     theInfo.myNbComp = MEDfieldnComponent(myFile->Id(), theFieldId);
2541     aRet = MEDfieldInfo(myFile->Id(),
2542                         theFieldId,
2543                         &aFieldName[0],
2544                         local_mesh_name,
2545                         &local,
2546                         &aType,
2547                         &aCompNames,
2548                         &anUnitNames,
2549                         dtunit,
2550                         &nbofstp);
2551
2552     if (strcmp(&aMeshInfo.myName[0], local_mesh_name) != 0) {
2553       if (theErr)
2554         *theErr = -1;
2555       return;
2556     }
2557
2558     theInfo.SetName(aFieldName);
2559
2560     if (theErr)
2561       *theErr = aRet;
2562     else if (aRet < 0)
2563       EXCEPTION(std::runtime_error, "GetFieldInfo - MEDfieldInfo(...)");
2564   }
2565
2566   //----------------------------------------------------------------------------
2567   void
2568   TWrapper
2569   ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2570                  TErr* theErr)
2571   {
2572     TErr aRet;
2573     SetFieldInfo(theInfo, eLECTURE_ECRITURE, &aRet);
2574
2575     if (aRet < 0)
2576       SetFieldInfo(theInfo, eLECTURE_AJOUT, &aRet);
2577
2578     if (theErr)
2579       *theErr = aRet;
2580   }
2581
2582   //----------------------------------------------------------------------------
2583   void
2584   TWrapper
2585   ::SetFieldInfo(const MED::TFieldInfo& theInfo,
2586                  EModeAcces theMode,
2587                  TErr* theErr)
2588   {
2589     TFileWrapper aFileWrapper(myFile, theMode, theErr, myMinor);
2590
2591     if (theErr && *theErr < 0)
2592       return;
2593
2594     MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2595
2596     TValueHolder<TString, char> aFieldName(anInfo.myName);
2597     TValueHolder<ETypeChamp, med_field_type> aType(anInfo.myType);
2598     TValueHolder<TString, char> aCompNames(anInfo.myCompNames);
2599     TValueHolder<TString, char> anUnitNames(anInfo.myUnitNames);
2600     MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2601     TErr aRet;
2602     char dtunit[MED_SNAME_SIZE+1];
2603     std::fill(dtunit, dtunit+MED_SNAME_SIZE+1, '\0');
2604     aRet = MEDfieldCr(myFile->Id(),
2605                       &aFieldName,
2606                       aType,
2607                       anInfo.myNbComp,
2608                       &aCompNames,
2609                       &anUnitNames,
2610                       dtunit,
2611                       &aMeshInfo.myName[0]);
2612     if (theErr)
2613       *theErr = aRet;
2614     else if (aRet < 0)
2615       EXCEPTION(std::runtime_error, "SetFieldInfo - MEDfieldCr(...)");
2616   }
2617
2618   //----------------------------------------------------------------------------
2619   PFieldInfo
2620   TWrapper
2621   ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2622                 TInt theNbComp,
2623                 ETypeChamp theType,
2624                 const std::string& theValue,
2625                 EBooleen theIsLocal,
2626                 TInt theNbRef)
2627   {
2628     return PFieldInfo(new TTFieldInfo
2629                       (theMeshInfo,
2630                        theNbComp,
2631                        theType,
2632                        theValue,
2633                        theIsLocal,
2634                        theNbRef));
2635   }
2636
2637   //----------------------------------------------------------------------------
2638   PFieldInfo
2639   TWrapper
2640   ::CrFieldInfo(const PMeshInfo& theMeshInfo,
2641                 const PFieldInfo& theInfo)
2642   {
2643     return PFieldInfo(new TTFieldInfo
2644                       (theMeshInfo,
2645                        theInfo));
2646   }
2647
2648   //----------------------------------------------------------------------------
2649   PFieldInfo
2650   TWrapper
2651   ::GetPFieldInfo(const PMeshInfo& theMeshInfo,
2652                   TInt theId,
2653                   TErr* theErr)
2654   {
2655     TInt aNbComp = GetNbComp(theId);
2656     PFieldInfo anInfo = CrFieldInfo(theMeshInfo, aNbComp);
2657     GetFieldInfo(theId, *anInfo, theErr);
2658
2659 #ifdef _DEBUG_
2660     INITMSG(MYDEBUG,
2661             "GetPFieldInfo "<<
2662             "- aName = '"<<anInfo->GetName()<<"'"<<
2663             "; aType = "<<anInfo->GetType()<<
2664             "; aNbComp = "<<aNbComp<<
2665             std::endl);
2666 #endif
2667
2668     return anInfo;
2669   }
2670
2671   //----------------------------------------------------------------------------
2672   TInt
2673   TWrapper
2674   ::GetNbGauss(TErr* theErr)
2675   {
2676     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2677
2678     if (theErr && *theErr < 0)
2679       return -1;
2680
2681     return MEDnLocalization(myFile->Id());
2682   }
2683
2684   //----------------------------------------------------------------------------
2685   TGaussInfo::TInfo
2686   TWrapper
2687   ::GetGaussPreInfo(TInt theId,
2688                     TErr* theErr)
2689   {
2690     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2691
2692     if (theErr && *theErr < 0)
2693       return TGaussInfo::TInfo(TGaussInfo::TKey(ePOINT1, ""), 0);
2694
2695     med_int aNbGaussPoints = med_int();
2696     TVector<char> aName(GetNOMLength()+1);
2697     med_geometry_type aGeom = MED_NONE;
2698
2699     TErr aRet;
2700     med_int dim;
2701     char geointerpname[MED_NAME_SIZE+1] = "";
2702     char ipointstructmeshname[MED_NAME_SIZE+1] = "";
2703     med_int nsectionmeshcell;
2704     med_geometry_type sectiongeotype;
2705     aRet = MEDlocalizationInfo (myFile->Id(),
2706                                 theId,
2707                                 &aName[0],
2708                                 &aGeom,
2709                                 &dim,
2710                                 &aNbGaussPoints,
2711                                 geointerpname,
2712                                 ipointstructmeshname,
2713                                 &nsectionmeshcell,
2714                                 &sectiongeotype);
2715     if (theErr)
2716       *theErr = aRet;
2717     else if (aRet < 0)
2718       EXCEPTION(std::runtime_error, "GetGaussPreInfo - MEDlocalizationInfo(...)");
2719     return TGaussInfo::TInfo(TGaussInfo::TKey(EGeometrieElement(aGeom), &aName[0]),
2720                              TInt(aNbGaussPoints));
2721   }
2722
2723   //----------------------------------------------------------------------------
2724   void
2725   TWrapper
2726   ::GetGaussInfo(TInt theId,
2727                  TGaussInfo& theInfo,
2728                  TErr* theErr)
2729   {
2730     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2731
2732     if (theErr && *theErr < 0)
2733       return;
2734
2735     TValueHolder<TNodeCoord, med_float> aRefCoord(theInfo.myRefCoord);
2736     TValueHolder<TNodeCoord, med_float> aGaussCoord(theInfo.myGaussCoord);
2737     TValueHolder<TWeight, med_float> aWeight(theInfo.myWeight);
2738     TValueHolder<EModeSwitch, med_switch_mode> aModeSwitch(theInfo.myModeSwitch);
2739     TValueHolder<TString, char> aGaussName(theInfo.myName);
2740
2741     TErr aRet;
2742     aRet = MEDlocalizationRd(myFile->Id(),
2743                              &aGaussName,
2744                              aModeSwitch,
2745                              &aRefCoord,
2746                              &aGaussCoord,
2747                              &aWeight);
2748
2749     if (theErr)
2750       *theErr = aRet;
2751     else if (aRet < 0)
2752       EXCEPTION(std::runtime_error, "GetGaussInfo - MEDlocalizationRd(...)");
2753   }
2754
2755   //----------------------------------------------------------------------------
2756   PGaussInfo
2757   TWrapper
2758   ::CrGaussInfo(const TGaussInfo::TInfo& theInfo,
2759                 EModeSwitch theMode)
2760   {
2761     return PGaussInfo(new TTGaussInfo
2762                       (theInfo,
2763                        theMode));
2764   }
2765
2766   //-----------------------------------------------------------------
2767   TInt
2768   TWrapper
2769   ::GetNbTimeStamps(const MED::TFieldInfo& theInfo,
2770                     const MED::TEntityInfo& theEntityInfo,
2771                     EEntiteMaillage& theEntity,
2772                     TGeom2Size& theGeom2Size,
2773                     TErr* theErr)
2774   {
2775     theEntity = EEntiteMaillage(-1);
2776     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2777
2778     if (theErr) {
2779       if (theEntityInfo.empty())
2780         *theErr = -1;
2781       if (*theErr < 0)
2782         return -1;
2783     }
2784     else if (theEntityInfo.empty())
2785       EXCEPTION(std::runtime_error, "GetNbTimeStamps - There is no any Entity on the Mesh");
2786
2787     bool anIsPerformAdditionalCheck = GetNbMeshes() > 1;
2788
2789     theGeom2Size.clear();
2790     TInt aNbTimeStamps = 0;
2791     TIdt anId = myFile->Id();
2792
2793     MED::TFieldInfo& anInfo = const_cast<MED::TFieldInfo&>(theInfo);
2794     TValueHolder<TString, char> aFieldName(anInfo.myName);
2795     MED::TMeshInfo& aMeshInfo = anInfo.myMeshInfo;
2796
2797     // workaround for IPAL13676
2798     MED::TEntityInfo localEntityInfo = theEntityInfo;
2799     TEntityInfo::iterator anLocalIter = localEntityInfo.find(eMAILLE);
2800     if (anLocalIter != localEntityInfo.end()) {
2801       localEntityInfo[eNOEUD_ELEMENT] = anLocalIter->second;
2802     }
2803
2804     TEntityInfo::const_iterator anIter = localEntityInfo.begin();
2805     for (; anIter != localEntityInfo.end(); anIter++) {
2806       med_entity_type anEntity = med_entity_type(anIter->first);
2807       const TGeom2Size& aGeom2Size = anIter->second;
2808       TGeom2Size::const_iterator anGeomIter = aGeom2Size.begin();
2809       for (; anGeomIter != aGeom2Size.end(); anGeomIter++) {
2810         med_geometry_type aGeom = med_geometry_type(anGeomIter->first);
2811         char aMeshName[MED_NAME_SIZE+1];
2812         med_bool islocal;
2813         med_field_type ft;
2814         char dtunit[MED_SNAME_SIZE+1];
2815         med_int myNbComp = MEDfieldnComponentByName(anId, &aFieldName);
2816         char *cname=new char[myNbComp*MED_SNAME_SIZE+1];
2817         char *unitname=new char[myNbComp*MED_SNAME_SIZE+1];
2818         TInt aNbStamps;
2819         MEDfieldInfoByName(anId,
2820                            &aFieldName,
2821                            aMeshName,
2822                            &islocal,
2823                            &ft,
2824                            cname,
2825                            unitname,
2826                            dtunit,
2827                            &aNbStamps);
2828         delete [] cname;
2829         delete [] unitname;
2830         med_int nval = 0;
2831         med_int aNumDt;
2832         med_int aNumOrd;
2833         med_float aDt;
2834         if (aNbStamps > 0)
2835           {
2836             MEDfieldComputingStepInfo(anId,
2837                                       &aFieldName,
2838                                       1,
2839                                       &aNumDt,
2840                                       &aNumOrd,
2841                                       &aDt);
2842             char profilename[MED_NAME_SIZE+1];
2843             char locname[MED_NAME_SIZE+1];
2844             med_int profilsize;
2845             med_int aNbGauss;
2846
2847             // protection from crash (division by zero)
2848             // inside MEDfieldnValueWithProfile function
2849             // caused by the workaround for IPAL13676 (see above)
2850             if (anEntity == MED_NODE_ELEMENT && aGeom % 100 == 0)
2851               continue;
2852
2853             nval = MEDfieldnValueWithProfile(anId,
2854                                              &aFieldName,
2855                                              aNumDt,
2856                                              aNumOrd,
2857                                              anEntity,
2858                                              med_geometry_type(aGeom),
2859                                              1,
2860                                              MED_COMPACT_STMODE,
2861                                              profilename,
2862                                              &profilsize,
2863                                              locname,
2864                                              &aNbGauss);
2865           }
2866         bool anIsSatisfied =(nval > 0);
2867         if (anIsSatisfied) {
2868           INITMSG(MYDEBUG,
2869                   "GetNbTimeStamps aNbTimeStamps = "<<aNbStamps<<
2870                   "; aGeom = "<<aGeom<<"; anEntity = "<<anEntity<<"\n");
2871           if (anIsPerformAdditionalCheck) {
2872             anIsSatisfied = !strcmp(&aMeshName[0], &aMeshInfo.myName[0]);
2873             if (!anIsSatisfied) {
2874               INITMSG(MYDEBUG,
2875                       "GetNbTimeStamps aMeshName = '"<<&aMeshName[0]<<"' != "<<
2876                       "; aMeshInfo.myName = '"<<&aMeshInfo.myName[0]<<"'\n");
2877             }
2878           }
2879         }
2880         if (anIsSatisfied) {
2881           theGeom2Size[EGeometrieElement(aGeom)] = anGeomIter->second;
2882           theEntity = EEntiteMaillage(anEntity);
2883           aNbTimeStamps = aNbStamps;
2884         }
2885       }
2886       if (!theGeom2Size.empty())
2887         break;
2888     }
2889     return aNbTimeStamps;
2890   }
2891
2892   //----------------------------------------------------------------------------
2893   void
2894   TWrapper
2895   ::GetTimeStampInfo(TInt theTimeStampId,
2896                      MED::TTimeStampInfo& theInfo,
2897                      TErr* theErr)
2898   {
2899     TFileWrapper aFileWrapper(myFile, eLECTURE, theErr, myMinor);
2900
2901     const TGeom2Size& aGeom2Size = theInfo.myGeom2Size;
2902
2903     if (theErr) {
2904       if (aGeom2Size.empty())
2905         *theErr = -1;
2906       if (*theErr < 0)
2907         return;
2908     }
2909     else if (aGeom2Size.empty())
2910       EXCEPTION(std::runtime_error, "GetTimeStampInfo - There is no any cell");
2911
2912     MED::TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
2913     MED::TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
2914
2915     TValueHolder<TString, char> aFieldName(aFieldInfo.myName);
2916     TValueHolder<EEntiteMaillage, med_entity_type> anEntity(theInfo.myEntity);
2917     TValueHolder<TInt, med_int> aNumDt(theInfo.myNumDt);
2918     TValueHolder<TInt, med_int> aNumOrd(theInfo.myNumOrd);
2919     TValueHolder<TString, char> anUnitDt(theInfo.myUnitDt);
2920     TValueHolder<TFloat, med_float> aDt(theInfo.myDt);
2921     TValueHolder<TString, char> aMeshName(aMeshInfo.myName);
2922     TValueHolder<EBooleen, med_bool> anIsLocal(aFieldInfo.myIsLocal);
2923     TValueHolder<TInt, med_int> aNbRef(aFieldInfo.myNbRef);
2924
2925     TGeom2NbGauss& aGeom2NbGauss = theInfo.myGeom2NbGauss;
2926
2927     // just to get a time stamp unit (anUnitDt)
2928     med_field_type aFieldType;
2929     med_int aNbComp = MEDfieldnComponentByName(myFile->Id(), &aFieldName);
2930     char *aCompName = new char[aNbComp*MED_SNAME_SIZE+1];
2931     char *aCompUnit = new char[aNbComp*MED_SNAME_SIZE+1];
2932     TInt aNbStamps;
2933     MEDfieldInfoByName(myFile->Id(),
2934                        &aFieldName,
2935                        &aMeshName,
2936                        &anIsLocal,
2937                        &aFieldType,
2938                        aCompName,
2939                        aCompUnit,
2940                        &anUnitDt,
2941                        &aNbStamps);
2942     delete [] aCompName;
2943     delete [] aCompUnit;
2944
2945     TGeom2Size::const_iterator anIter = aGeom2Size.begin();
2946     for (; anIter != aGeom2Size.end(); anIter++) {
2947       const EGeometrieElement& aGeom = anIter->first;
2948       med_int aNbGauss = -1;
2949
2950       TErr aRet;
2951       aRet = MEDfieldComputingStepInfo(myFile->Id(),
2952                                        &aFieldName,
2953                                        theTimeStampId,
2954                                        &aNumDt,
2955                                        &aNumOrd,
2956                                        &aDt);
2957       char profilename[MED_NAME_SIZE+1];
2958       med_int profilsize;
2959       char locname[MED_NAME_SIZE+1];
2960       MEDfieldnValueWithProfile(myFile->Id(),
2961                                 &aFieldName,
2962                                 aNumDt,
2963                                 aNumOrd,
2964                                 anEntity,
2965                                 med_geometry_type(aGeom),