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