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