]> SALOME platform Git repositories - modules/med.git/blob - src/MEDWrapper/Base/MED_Wrapper.cxx
Salome HOME
Join modifications from branch CEAFor_V3_2_0
[modules/med.git] / src / MEDWrapper / Base / MED_Wrapper.cxx
1 //  Copyright (C) 2003  CEA/DEN, EDF R&D
2 //
3 //
4 //
5 //  File   : VISU_DatConvertor.cxx
6 //  Author : Alexey PETROV
7 //  Module : VISU
8
9 #include "MED_Wrapper.hxx"
10 #include "MED_Utilities.hxx"
11  
12 #ifdef _DEBUG_
13 static int MYDEBUG = 0;
14 static int MYVALUEDEBUG = 0;
15 #else
16 static int MYDEBUG = 0;
17 static int MYVALUEDEBUG = 0;
18 #endif
19
20 namespace MED
21 {
22   TLockProxy
23   ::TLockProxy(TWrapper* theWrapper):
24     myWrapper(theWrapper)
25   {
26     boost::detail::thread::lock_ops<TWrapper::TMutex>::lock(myWrapper->myMutex);
27     INITMSG(MYDEBUG,"TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<endl);
28   }
29   
30   TLockProxy
31   ::~TLockProxy()
32   {
33     INITMSG(MYDEBUG,"~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<endl);
34     boost::detail::thread::lock_ops<TWrapper::TMutex>::unlock(myWrapper->myMutex);
35   }
36   
37   TWrapper*
38   TLockProxy
39   ::operator-> () const // never throws
40   {
41     return myWrapper;
42   }
43
44   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45   PMeshInfo
46   TWrapper
47   ::GetPMeshInfo(TInt theId,
48                  TErr* theErr)
49   {
50     PMeshInfo anInfo = CrMeshInfo();
51     GetMeshInfo(theId,*anInfo,theErr);
52     return anInfo;
53   }
54
55
56   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57   PFamilyInfo 
58   TWrapper
59   ::GetPFamilyInfo(const PMeshInfo& theMeshInfo, 
60                    TInt theId,
61                    TErr* theErr)
62   {
63     // must be reimplemented in connection with mesh type eSTRUCTURE
64     //     if(theMeshInfo->GetType() != eNON_STRUCTURE)
65     //       return PFamilyInfo();
66     
67     TInt aNbAttr = GetNbFamAttr(theId,*theMeshInfo);
68     TInt aNbGroup = GetNbFamGroup(theId,*theMeshInfo);
69     PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo,aNbGroup,aNbAttr);
70     GetFamilyInfo(theId,*anInfo,theErr);
71
72 #ifdef _DEBUG_
73     string aName = anInfo->GetName();
74     INITMSG(MYDEBUG,"GetPFamilyInfo - aFamilyName = '"<<aName<<
75             "'; andId = "<<anInfo->GetId()<<
76             "; aNbAttr = "<<aNbAttr<<
77             "; aNbGroup = "<<aNbGroup<<"\n");
78     for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
79       aName = anInfo->GetGroupName(iGroup);
80       INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
81     }
82 #endif
83     
84     return anInfo;
85   }
86
87
88   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89   PNodeInfo
90   TWrapper
91   ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
92                  TErr* theErr)
93   {
94     TInt aNbElems = GetNbNodes(*theMeshInfo);
95     if(aNbElems == 0){
96       return PNodeInfo();
97     }
98
99     PNodeInfo anInfo = CrNodeInfo(theMeshInfo,aNbElems);
100     GetNodeInfo(*anInfo,theErr);
101
102 #ifdef _DEBUG_
103     TInt aDim = theMeshInfo->myDim;
104     TInt aNbElem = anInfo->GetNbElem();
105     INITMSG(MYDEBUG,"GetPNodeInfo: ");
106     {
107       INITMSG(MYDEBUG,"aCoords: "<<aNbElem<<": ");
108       TNodeCoord& aCoord = anInfo->myCoord;
109       for(TInt iElem = 0; iElem < aNbElem; iElem++){
110         for(TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++){
111           ADDMSG(MYVALUEDEBUG,aCoord[anId]<<",");
112         }
113         ADDMSG(MYVALUEDEBUG," ");
114       }
115       ADDMSG(MYDEBUG,endl);
116       
117       BEGMSG(MYVALUEDEBUG,"GetFamNum: ");
118       for(TInt iElem = 0; iElem < aNbElem; iElem++){
119         ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
120       }
121       ADDMSG(MYVALUEDEBUG,endl);
122       
123       if(anInfo->IsElemNum()){
124         BEGMSG(MYVALUEDEBUG,"GetElemNum: ");
125         for(TInt iElem = 0; iElem < aNbElem; iElem++){
126           ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
127         }
128         ADDMSG(MYVALUEDEBUG,endl);
129       }
130     }
131     ADDMSG(MYDEBUG,endl);
132 #endif
133     
134     return anInfo;
135   }
136
137   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138   PPolygoneInfo
139   TWrapper
140   ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
141                      EEntiteMaillage theEntity, 
142                      EGeometrieElement theGeom, 
143                      EConnectivite theConnMode)
144   {
145     if(theMeshInfo->GetType() != eNON_STRUCTURE)
146       return PPolygoneInfo();
147
148     TInt aNbElem = GetNbPolygones(theMeshInfo,theEntity,theGeom,theConnMode);
149     TInt aConnSize = GetPolygoneConnSize(theMeshInfo,theEntity,theGeom,theConnMode);
150     PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo,theEntity,theGeom,aNbElem,aConnSize,theConnMode);
151     GetPolygoneInfo(anInfo);
152
153 #ifdef _DEBUG_
154     INITMSG(MYDEBUG,"GetPPolygoneInfo"<<
155             " - theGeom = "<<theGeom<<
156             "; aNbElem = "<<aNbElem<<": ");
157     for(TInt iElem = 1; iElem < aNbElem; iElem++){
158       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
159       TInt aConnDim = aConnSlice.size();
160       for(TInt iConn = 0; iConn < aConnDim; iConn++){
161         ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
162       }
163       ADDMSG(MYDEBUG," ");
164     }
165     ADDMSG(MYDEBUG,endl);
166 #endif
167
168     return anInfo;
169   }
170   
171   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
172   PPolyedreInfo
173   TWrapper
174   ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
175                      EEntiteMaillage theEntity, 
176                      EGeometrieElement theGeom, 
177                      EConnectivite theConnMode)
178   {
179     if(theMeshInfo->GetType() != eNON_STRUCTURE)
180       return PPolyedreInfo();
181     TInt aNbElem  = GetNbPolyedres(theMeshInfo,theEntity,theGeom,theConnMode);
182     TInt aNbFaces, aConnSize;
183     GetPolyedreConnSize(theMeshInfo,aNbFaces,aConnSize,theConnMode);
184     PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo,theEntity,theGeom,aNbElem,aNbFaces,aConnSize,theConnMode);
185     GetPolyedreInfo(anInfo);
186
187 #ifdef _DEBUG_
188     INITMSG(MYDEBUG,"GetPPolyedreInfo"<<
189             " - theGeom = "<<theGeom<<
190             "; aNbElem = "<<aNbElem<<": ");
191     for(TInt iElem = 0; iElem < aNbElem; iElem++){
192       TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
193       TInt aNbFaces = aConnSliceArr.size();
194       ADDMSG(MYDEBUG,"{");
195       for(TInt iFace = 0; iFace < aNbFaces; iFace++){
196         TCConnSlice aConnSlice = aConnSliceArr[iFace];
197         TInt aNbConn = aConnSlice.size();
198         ADDMSG(MYDEBUG,"[");
199         for(TInt iConn = 0; iConn < aNbConn; iConn++){
200           ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
201         }
202         ADDMSG(MYDEBUG,"] ");
203       }
204       ADDMSG(MYDEBUG,"} ");
205     }
206     ADDMSG(MYDEBUG,endl);
207 #endif
208
209     return anInfo;
210   }
211   
212   PElemInfo 
213   TWrapper
214   ::GetPElemInfo(const PMeshInfo& theMeshInfo,
215                  EEntiteMaillage theEntity, 
216                  EGeometrieElement theGeom, 
217                  EConnectivite theConnMode,
218                  TErr* theErr)
219   {
220     EMaillage aType = theMeshInfo->GetType();
221     if(aType == eNON_STRUCTURE){
222       switch(theGeom){
223       case ePOINT1:
224         return GetPNodeInfo(theMeshInfo,theErr);
225         break;
226       case ePOLYGONE:
227         return GetPPolygoneInfo(theMeshInfo,theEntity,theGeom,theConnMode);
228         break;
229       case ePOLYEDRE:
230         return GetPPolyedreInfo(theMeshInfo,theEntity,theGeom,theConnMode);
231         break;
232       default:
233         return GetPCellInfo(theMeshInfo,theEntity,theGeom,theConnMode,theErr);
234       }
235     } else {
236       PGrilleInfo aGrille = GetPGrilleInfo(theMeshInfo);
237
238       TInt nbElems;
239       EBooleen theIsElemNum = eFAUX;
240       // nodes
241       switch(theGeom){
242       case ePOINT1:
243         nbElems = aGrille->GetNbNodes();
244         theIsElemNum = eVRAI;
245         break;
246       case eSEG2:
247       case eQUAD4:
248       case eHEXA8:
249         nbElems = aGrille->GetNbCells();
250         break;
251       default:
252         nbElems = 0;
253       }
254       
255       TIntVector aFamNum;
256       TIntVector aElemNum;
257       TStringVector aElemNames;
258       
259       PElemInfo aElemInfo;
260
261       if(theGeom == ePOINT1){
262         aElemInfo = CrElemInfo(theMeshInfo,
263                                nbElems,
264                                theIsElemNum);
265         MED::TElemInfo &aTElemInfo = *aElemInfo;
266
267         // must be reimplemente in connection with mesh type eSTRUCTURE
268 //      GetNumeration(aTElemInfo,
269 //                    nbElems,
270 //                    theEntity,
271 //                    theGeom,
272 //                    theErr);
273         
274         GetFamilies(aTElemInfo,
275                     nbElems,
276                     theEntity,
277                     theGeom,
278                     theErr);
279         
280         // must be reimplemente in connection with mesh type eSTRUCTURE
281 //      GetNames(aTElemInfo,
282 //               nbElems,
283 //               theEntity,
284 //               theGeom,
285 //               theErr);
286       } else {
287         aElemInfo = CrElemInfo(theMeshInfo,
288                                nbElems,
289                                aFamNum,
290                                aElemNum,
291                                aElemNames);
292       }
293       
294       return aElemInfo;
295     }
296     return PElemInfo();
297   }
298
299
300   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
301   PCellInfo 
302   TWrapper
303   ::GetPCellInfo(const PMeshInfo& theMeshInfo,
304                  EEntiteMaillage theEntity, 
305                  EGeometrieElement theGeom, 
306                  EConnectivite theConnMode,
307                  TErr* theErr)
308   {
309     if(theMeshInfo->GetType() != eNON_STRUCTURE)
310       return PCellInfo();
311     TInt aNbElem = GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode);
312     PCellInfo anInfo = CrCellInfo(theMeshInfo,theEntity,theGeom,aNbElem,theConnMode);
313     GetCellInfo(anInfo,theErr);
314
315 #ifdef _DEBUG_
316     TInt aConnDim = anInfo->GetConnDim();
317     INITMSG(MYDEBUG,"GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
318     BEGMSG(MYDEBUG,"GetPCellInfo - aNbElem: "<<aNbElem<<": ");
319     for(TInt iElem = 0; iElem < aNbElem; iElem++){
320       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
321       for(TInt iConn = 0; iConn < aConnDim; iConn++){
322         ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
323       }
324       ADDMSG(MYVALUEDEBUG," ");
325     }
326     ADDMSG(MYDEBUG,endl);
327
328     BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetFamNum: ");
329     for(TInt iElem = 0; iElem < aNbElem; iElem++){
330       ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
331     }
332     ADDMSG(MYVALUEDEBUG,endl);
333
334     if(anInfo->IsElemNum()){
335       BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetElemNum: ");
336       for(TInt iElem = 0; iElem < aNbElem; iElem++){
337         ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
338       }
339       ADDMSG(MYVALUEDEBUG,endl);
340     }
341     ADDMSG(MYDEBUG,endl);
342 #endif
343     
344     return anInfo;
345   }
346
347
348   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349   PFieldInfo
350   TWrapper
351   ::GetPFieldInfo(const PMeshInfo& theMeshInfo, 
352                   TInt theId,
353                   TErr* theErr)
354   {
355     TInt aNbComp = GetNbComp(theId);
356     PFieldInfo anInfo = CrFieldInfo(theMeshInfo,aNbComp);
357     GetFieldInfo(theId,*anInfo,theErr);
358
359 #ifdef _DEBUG_
360     INITMSG(MYDEBUG,
361             "GetPFieldInfo "<<
362             "- aName = '"<<anInfo->GetName()<<"'"<<
363             "; aType = "<<anInfo->GetType()<<
364             "; aNbComp = "<<aNbComp<<
365             endl);
366 #endif
367     
368     return anInfo;
369   }
370
371
372   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
373   PTimeStampInfo
374   TWrapper
375   ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo,
376                       EEntiteMaillage theEntity,
377                       const TGeom2Size& theGeom2Size,
378                       TInt theId,
379                       TErr* theErr)
380   {
381     PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo,theEntity,theGeom2Size);
382     GetTimeStampInfo(theId,*anInfo,theErr);
383
384 #ifdef _DEBUG_
385     INITMSG(MYDEBUG,"GetPTimeStampInfo - anEntity = "<<anInfo->GetEntity()<<"\n");
386     TGeom2NbGauss& aGeom2NbGauss = anInfo->myGeom2NbGauss;
387     TGeom2NbGauss::const_iterator anIter = aGeom2NbGauss.begin();
388     for(; anIter != aGeom2NbGauss.end(); anIter++){
389       const EGeometrieElement& aGeom = anIter->first;
390       INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aGeom2NbGauss[aGeom]<<";\n");
391     }
392 #endif
393
394     return anInfo;
395   }
396
397
398   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
399   PProfileInfo
400   TWrapper
401   ::GetPProfileInfo(TInt theId,
402                     EModeProfil theMode,
403                     TErr* theErr)
404   {
405     TProfileInfo::TInfo aPreInfo = GetProfilePreInfo(theId);
406     PProfileInfo anInfo = CrProfileInfo(aPreInfo,theMode);
407     GetProfileInfo(theId,*anInfo,theErr);
408
409     return anInfo;
410   }
411
412
413   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
414   PTimeStampVal 
415   TWrapper
416   ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
417                      const TMKey2Profile& theMKey2Profile,
418                      const TKey2Gauss& theKey2Gauss,
419                      TErr* theErr)
420   {
421     PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
422     GetTimeStampVal(*anInfo,theMKey2Profile,theKey2Gauss,theErr);
423
424 #ifdef _DEBUG_
425     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
426     INITMSG(MYDEBUG,"GetPTimeStampVal\n");
427     TGeom2Value& aGeom2Value = anInfo->myGeom2Value;
428     TGeom2Value::const_iterator anIter = aGeom2Value.begin();
429     for(; anIter != aGeom2Value.end(); anIter++){
430       const EGeometrieElement& aGeom = anIter->first;
431       const TMeshValue& aMeshValue = anIter->second;
432       TInt aNbElem = aMeshValue.myNbElem;
433       TInt aNbGauss = aMeshValue.myNbGauss;
434       TInt aNbComp = aMeshValue.myNbComp;
435       INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aNbElem<<": ");
436       for(TInt iElem = 0; iElem < aNbElem; iElem++){
437         TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
438         ADDMSG(MYVALUEDEBUG,"{");
439         for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
440           const TCValueSlice& aValueSlice = aValueSliceArr[iGauss];
441           for(TInt iComp = 0; iComp < aNbComp; iComp++){
442             ADDMSG(MYVALUEDEBUG,aValueSlice[iComp]<<" ");
443           }
444           ADDMSG(MYVALUEDEBUG,"| ");
445         }
446         ADDMSG(MYVALUEDEBUG,"} ");
447       }
448       ADDMSG(MYDEBUG,"\n");
449     }
450 #endif
451
452     return anInfo;
453   }
454
455   PGrilleInfo
456   TWrapper
457   ::GetPGrilleInfo(const PMeshInfo& theMeshInfo)
458   {
459     if(theMeshInfo->GetType() != eSTRUCTURE)
460       return PGrilleInfo();
461
462     EGrilleType type;
463     GetGrilleType(*theMeshInfo,type);
464     PGrilleInfo anInfo;
465     if(type == eGRILLE_STANDARD){
466       const TInt nnoeuds = GetNbNodes(*theMeshInfo);
467       anInfo = CrGrilleInfo(theMeshInfo,type,nnoeuds);
468     }
469     else {
470       TIntVector aVec;
471       aVec.resize(theMeshInfo->GetDim());
472       for(int aAxe=0;aAxe<theMeshInfo->GetDim();aAxe++){
473         ETable aATable;
474         switch(aAxe){
475         case 0:
476           aATable = eCOOR_IND1;
477           break;
478         case 1:
479           aATable = eCOOR_IND2;
480           break;
481         case 2:
482           aATable = eCOOR_IND3;
483           break;
484         }
485         aVec[aAxe] = GetNbNodes(*theMeshInfo,aATable);
486       }
487       anInfo = CrGrilleInfo(theMeshInfo,type,aVec);
488     }
489
490     GetGrilleInfo(anInfo);
491     anInfo->SetGrilleType(type);
492     return anInfo;
493   }
494   
495   PGrilleInfo
496   TWrapper
497   ::GetPGrilleInfo(const PMeshInfo& theMeshInfo,
498                    const PGrilleInfo& theInfo)
499   {
500     PGrilleInfo anInfo = CrGrilleInfo(theMeshInfo,theInfo);
501     return anInfo;
502   }
503 }