Salome HOME
update with the version in the OCC branch OCC_development_generic_2006.
[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     TInt aNbAttr = GetNbFamAttr(theId,*theMeshInfo);
64     TInt aNbGroup = GetNbFamGroup(theId,*theMeshInfo);
65     PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo,aNbGroup,aNbAttr);
66     GetFamilyInfo(theId,*anInfo,theErr);
67
68 #ifdef _DEBUG_
69     string aName = anInfo->GetName();
70     INITMSG(MYDEBUG,"GetPFamilyInfo - aFamilyName = '"<<aName<<
71             "'; andId = "<<anInfo->GetId()<<
72             "; aNbAttr = "<<aNbAttr<<
73             "; aNbGroup = "<<aNbGroup<<"\n");
74     for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
75       aName = anInfo->GetGroupName(iGroup);
76       INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
77     }
78 #endif
79     
80     return anInfo;
81   }
82
83
84   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
85   PNodeInfo
86   TWrapper
87   ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
88                  TErr* theErr)
89   {
90     TInt aNbElems = GetNbNodes(*theMeshInfo);
91     PNodeInfo anInfo = CrNodeInfo(theMeshInfo,aNbElems);
92     GetNodeInfo(*anInfo,theErr);
93
94 #ifdef _DEBUG_
95     TInt aDim = theMeshInfo->myDim;
96     TInt aNbElem = anInfo->GetNbElem();
97     INITMSG(MYDEBUG,"GetPNodeInfo: ");
98     {
99       INITMSG(MYDEBUG,"aCoords: "<<aNbElem<<": ");
100       TNodeCoord& aCoord = anInfo->myCoord;
101       for(TInt iElem = 0; iElem < aNbElem; iElem++){
102         for(TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++){
103           ADDMSG(MYVALUEDEBUG,aCoord[anId]<<",");
104         }
105         ADDMSG(MYVALUEDEBUG," ");
106       }
107       ADDMSG(MYDEBUG,endl);
108       
109       BEGMSG(MYVALUEDEBUG,"GetFamNum: ");
110       for(TInt iElem = 0; iElem < aNbElem; iElem++){
111         ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
112       }
113       ADDMSG(MYVALUEDEBUG,endl);
114       
115       if(anInfo->IsElemNum()){
116         BEGMSG(MYVALUEDEBUG,"GetElemNum: ");
117         for(TInt iElem = 0; iElem < aNbElem; iElem++){
118           ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
119         }
120         ADDMSG(MYVALUEDEBUG,endl);
121       }
122     }
123     ADDMSG(MYDEBUG,endl);
124 #endif
125     
126     return anInfo;
127   }
128
129   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130   PPolygoneInfo
131   TWrapper
132   ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
133                      EEntiteMaillage theEntity, 
134                      EGeometrieElement theGeom, 
135                      EConnectivite theConnMode)
136   {
137     TInt aNbElem = GetNbPolygones(theMeshInfo,theEntity,theGeom,theConnMode);
138     TInt aConnSize = GetPolygoneConnSize(theMeshInfo,theEntity,theGeom,theConnMode);
139     PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo,theEntity,theGeom,aNbElem,aConnSize,theConnMode);
140     GetPolygoneInfo(anInfo);
141
142 #ifdef _DEBUG_
143     INITMSG(MYDEBUG,"GetPPolygoneInfo"<<
144             " - theGeom = "<<theGeom<<
145             "; aNbElem = "<<aNbElem<<": ");
146     for(TInt iElem = 1; iElem < aNbElem; iElem++){
147       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
148       TInt aConnDim = aConnSlice.size();
149       for(TInt iConn = 0; iConn < aConnDim; iConn++){
150         ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
151       }
152       ADDMSG(MYDEBUG," ");
153     }
154     ADDMSG(MYDEBUG,endl);
155 #endif
156
157     return anInfo;
158   }
159   
160   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
161   PPolyedreInfo
162   TWrapper
163   ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
164                      EEntiteMaillage theEntity, 
165                      EGeometrieElement theGeom, 
166                      EConnectivite theConnMode)
167   {
168     TInt aNbElem  = GetNbPolyedres(theMeshInfo,theEntity,theGeom,theConnMode);
169     TInt aNbFaces, aConnSize;
170     GetPolyedreConnSize(theMeshInfo,aNbFaces,aConnSize,theConnMode);
171     PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo,theEntity,theGeom,aNbElem,aNbFaces,aConnSize,theConnMode);
172     GetPolyedreInfo(anInfo);
173
174 #ifdef _DEBUG_
175     INITMSG(MYDEBUG,"GetPPolyedreInfo"<<
176             " - theGeom = "<<theGeom<<
177             "; aNbElem = "<<aNbElem<<": ");
178     for(TInt iElem = 0; iElem < aNbElem; iElem++){
179       TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
180       TInt aNbFaces = aConnSliceArr.size();
181       ADDMSG(MYDEBUG,"{");
182       for(TInt iFace = 0; iFace < aNbFaces; iFace++){
183         TCConnSlice aConnSlice = aConnSliceArr[iFace];
184         TInt aNbConn = aConnSlice.size();
185         ADDMSG(MYDEBUG,"[");
186         for(TInt iConn = 0; iConn < aNbConn; iConn++){
187           ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
188         }
189         ADDMSG(MYDEBUG,"] ");
190       }
191       ADDMSG(MYDEBUG,"} ");
192     }
193     ADDMSG(MYDEBUG,endl);
194 #endif
195
196     return anInfo;
197   }
198   
199   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200   PCellInfo 
201   TWrapper
202   ::GetPCellInfo(const PMeshInfo& theMeshInfo,
203                  EEntiteMaillage theEntity, 
204                  EGeometrieElement theGeom, 
205                  EConnectivite theConnMode,
206                  TErr* theErr)
207   {
208     TInt aNbElem = GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode);
209     PCellInfo anInfo = CrCellInfo(theMeshInfo,theEntity,theGeom,aNbElem,theConnMode);
210     GetCellInfo(anInfo,theErr);
211
212 #ifdef _DEBUG_
213     TInt aConnDim = anInfo->GetConnDim();
214     INITMSG(MYDEBUG,"GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
215     BEGMSG(MYDEBUG,"GetPCellInfo - aNbElem: "<<aNbElem<<": ");
216     for(TInt iElem = 0; iElem < aNbElem; iElem++){
217       TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
218       for(TInt iConn = 0; iConn < aConnDim; iConn++){
219         ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
220       }
221       ADDMSG(MYVALUEDEBUG," ");
222     }
223     ADDMSG(MYDEBUG,endl);
224
225     BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetFamNum: ");
226     for(TInt iElem = 0; iElem < aNbElem; iElem++){
227       ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
228     }
229     ADDMSG(MYVALUEDEBUG,endl);
230
231     if(anInfo->IsElemNum()){
232       BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetElemNum: ");
233       for(TInt iElem = 0; iElem < aNbElem; iElem++){
234         ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
235       }
236       ADDMSG(MYVALUEDEBUG,endl);
237     }
238     ADDMSG(MYDEBUG,endl);
239 #endif
240     
241     return anInfo;
242   }
243
244
245   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
246   PFieldInfo
247   TWrapper
248   ::GetPFieldInfo(const PMeshInfo& theMeshInfo, 
249                   TInt theId,
250                   TErr* theErr)
251   {
252     TInt aNbComp = GetNbComp(theId);
253     PFieldInfo anInfo = CrFieldInfo(theMeshInfo,aNbComp);
254     GetFieldInfo(theId,*anInfo,theErr);
255
256 #ifdef _DEBUG_
257     INITMSG(MYDEBUG,
258             "GetPFieldInfo "<<
259             "- aName = '"<<anInfo->GetName()<<"'"<<
260             "; aType = "<<anInfo->GetType()<<
261             "; aNbComp = "<<aNbComp<<
262             endl);
263 #endif
264     
265     return anInfo;
266   }
267
268
269   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270   PTimeStampInfo
271   TWrapper
272   ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo,
273                       EEntiteMaillage theEntity,
274                       const TGeom2Size& theGeom2Size,
275                       TInt theId,
276                       TErr* theErr)
277   {
278     PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo,theEntity,theGeom2Size);
279     GetTimeStampInfo(theId,*anInfo,theErr);
280
281 #ifdef _DEBUG_
282     INITMSG(MYDEBUG,"GetPTimeStampInfo - anEntity = "<<anInfo->GetEntity()<<"\n");
283     TGeom2NbGauss& aGeom2NbGauss = anInfo->myGeom2NbGauss;
284     TGeom2NbGauss::const_iterator anIter = aGeom2NbGauss.begin();
285     for(; anIter != aGeom2NbGauss.end(); anIter++){
286       const EGeometrieElement& aGeom = anIter->first;
287       INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aGeom2NbGauss[aGeom]<<";\n");
288     }
289 #endif
290
291     return anInfo;
292   }
293
294
295   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
296   PProfileInfo
297   TWrapper
298   ::GetPProfileInfo(TInt theId,
299                     EModeProfil theMode,
300                     TErr* theErr)
301   {
302     TProfileInfo::TInfo aPreInfo = GetProfilePreInfo(theId);
303     PProfileInfo anInfo = CrProfileInfo(aPreInfo,theMode);
304     GetProfileInfo(theId,*anInfo,theErr);
305
306     return anInfo;
307   }
308
309
310   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
311   PTimeStampVal 
312   TWrapper
313   ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
314                      const TMKey2Profile& theMKey2Profile,
315                      const TKey2Gauss& theKey2Gauss,
316                      TErr* theErr)
317   {
318     PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
319     GetTimeStampVal(*anInfo,theMKey2Profile,theKey2Gauss,theErr);
320
321 #ifdef _DEBUG_
322     PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
323     INITMSG(MYDEBUG,"GetPTimeStampVal\n");
324     TGeom2Value& aGeom2Value = anInfo->myGeom2Value;
325     TGeom2Value::const_iterator anIter = aGeom2Value.begin();
326     for(; anIter != aGeom2Value.end(); anIter++){
327       const EGeometrieElement& aGeom = anIter->first;
328       const TMeshValue& aMeshValue = anIter->second;
329       TInt aNbElem = aMeshValue.myNbElem;
330       TInt aNbGauss = aMeshValue.myNbGauss;
331       TInt aNbComp = aMeshValue.myNbComp;
332       INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aNbElem<<": ");
333       for(TInt iElem = 0; iElem < aNbElem; iElem++){
334         TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
335         ADDMSG(MYVALUEDEBUG,"{");
336         for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
337           const TCValueSlice& aValueSlice = aValueSliceArr[iGauss];
338           for(TInt iComp = 0; iComp < aNbComp; iComp++){
339             ADDMSG(MYVALUEDEBUG,aValueSlice[iComp]<<" ");
340           }
341           ADDMSG(MYVALUEDEBUG,"| ");
342         }
343         ADDMSG(MYVALUEDEBUG,"} ");
344       }
345       ADDMSG(MYDEBUG,"\n");
346     }
347 #endif
348
349     return anInfo;
350   }
351 }