1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : MED_Wrapper.cxx
23 // Author : Alexey PETROV
25 #include "MED_Wrapper.hxx"
26 #include "MED_Utilities.hxx"
28 #include <boost/version.hpp>
31 static int MYDEBUG = 0;
32 static int MYVALUEDEBUG = 0;
34 // static int MYDEBUG = 0;
35 // static int MYVALUEDEBUG = 0;
41 ::TLockProxy(TWrapper* theWrapper):
44 #if BOOST_VERSION >= 103500
45 myWrapper->myMutex.lock();
47 boost::detail::thread::lock_ops<TWrapper::TMutex>::lock(myWrapper->myMutex);
49 INITMSG(MYDEBUG,"TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
55 INITMSG(MYDEBUG,"~TLockProxy() - this -"<<this<<"; myWrapper = "<<myWrapper<<std::endl);
56 #if BOOST_VERSION >= 103500
57 myWrapper->myMutex.unlock();
59 boost::detail::thread::lock_ops<TWrapper::TMutex>::unlock(myWrapper->myMutex);
65 ::operator-> () const // never throws
70 //----------------------------------------------------------------------------
75 //----------------------------------------------------------------------------
78 ::GetPMeshInfo(TInt theId,
81 PMeshInfo anInfo = CrMeshInfo();
82 GetMeshInfo(theId,*anInfo,theErr);
87 //----------------------------------------------------------------------------
90 ::GetPFamilyInfo(const PMeshInfo& theMeshInfo,
94 // must be reimplemented in connection with mesh type eSTRUCTURE
95 // if(theMeshInfo->GetType() != eNON_STRUCTURE)
96 // return PFamilyInfo();
98 TInt aNbAttr = GetNbFamAttr(theId,*theMeshInfo);
99 TInt aNbGroup = GetNbFamGroup(theId,*theMeshInfo);
100 PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo,aNbGroup,aNbAttr);
101 GetFamilyInfo(theId,*anInfo,theErr);
104 std::string aName = anInfo->GetName();
105 INITMSG(MYDEBUG,"GetPFamilyInfo - aFamilyName = '"<<aName<<
106 "'; andId = "<<anInfo->GetId()<<
107 "; aNbAttr = "<<aNbAttr<<
108 "; aNbGroup = "<<aNbGroup<<"\n");
109 for(TInt iGroup = 0; iGroup < aNbGroup; iGroup++){
110 aName = anInfo->GetGroupName(iGroup);
111 INITMSG(MYDEBUG,"aGroupName = '"<<aName<<"'\n");
119 //----------------------------------------------------------------------------
122 ::GetPNodeInfo(const PMeshInfo& theMeshInfo,
125 TInt aNbElems = GetNbNodes(*theMeshInfo);
130 PNodeInfo anInfo = CrNodeInfo(theMeshInfo,aNbElems);
131 GetNodeInfo(*anInfo,theErr);
134 TInt aDim = theMeshInfo->myDim;
135 TInt aNbElem = anInfo->GetNbElem();
136 INITMSG(MYDEBUG,"GetPNodeInfo: ");
138 INITMSG(MYDEBUG,"aCoords: "<<aNbElem<<": ");
139 TNodeCoord& aCoord = anInfo->myCoord;
140 for(TInt iElem = 0; iElem < aNbElem; iElem++){
141 for(TInt iDim = 0, anId = iElem*aDim; iDim < aDim; iDim++, anId++){
142 ADDMSG(MYVALUEDEBUG,aCoord[anId]<<",");
144 ADDMSG(MYVALUEDEBUG," ");
146 ADDMSG(MYDEBUG, std::endl);
148 BEGMSG(MYVALUEDEBUG, "GetFamNum: ");
149 for(TInt iElem = 0; iElem < aNbElem; iElem++){
150 ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
152 ADDMSG(MYVALUEDEBUG, std::endl);
154 if(anInfo->IsElemNum()){
155 BEGMSG(MYVALUEDEBUG,"GetElemNum: ");
156 for(TInt iElem = 0; iElem < aNbElem; iElem++){
157 ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
159 ADDMSG(MYVALUEDEBUG, std::endl);
162 ADDMSG(MYDEBUG, std::endl);
168 //----------------------------------------------------------------------------
171 ::GetPPolygoneInfo(const PMeshInfo& theMeshInfo,
172 EEntiteMaillage theEntity,
173 EGeometrieElement theGeom,
174 EConnectivite theConnMode)
176 if(theMeshInfo->GetType() != eNON_STRUCTURE)
177 return PPolygoneInfo();
179 TInt aNbElem = GetNbPolygones(theMeshInfo,theEntity,theGeom,theConnMode);
180 TInt aConnSize = GetPolygoneConnSize(theMeshInfo,theEntity,theGeom,theConnMode);
181 PPolygoneInfo anInfo = CrPolygoneInfo(theMeshInfo,theEntity,theGeom,aNbElem,aConnSize,theConnMode);
182 GetPolygoneInfo(anInfo);
185 INITMSG(MYDEBUG,"GetPPolygoneInfo"<<
186 " - theGeom = "<<theGeom<<
187 "; aNbElem = "<<aNbElem<<": ");
188 for(TInt iElem = 1; iElem < aNbElem; iElem++){
189 TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
190 TInt aConnDim = aConnSlice.size();
191 for(TInt iConn = 0; iConn < aConnDim; iConn++){
192 ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
196 ADDMSG(MYDEBUG, std::endl);
202 //----------------------------------------------------------------------------
205 ::GetPPolyedreInfo(const PMeshInfo& theMeshInfo,
206 EEntiteMaillage theEntity,
207 EGeometrieElement theGeom,
208 EConnectivite theConnMode)
210 if(theMeshInfo->GetType() != eNON_STRUCTURE)
211 return PPolyedreInfo();
212 TInt aNbElem = GetNbPolyedres(theMeshInfo,theEntity,theGeom,theConnMode);
213 TInt aNbFaces, aConnSize;
214 GetPolyedreConnSize(theMeshInfo,aNbFaces,aConnSize,theConnMode);
215 PPolyedreInfo anInfo = CrPolyedreInfo(theMeshInfo,theEntity,theGeom,aNbElem,aNbFaces,aConnSize,theConnMode);
216 GetPolyedreInfo(anInfo);
219 INITMSG(MYDEBUG,"GetPPolyedreInfo"<<
220 " - theGeom = "<<theGeom<<
221 "; aNbElem = "<<aNbElem<<": ");
222 for(TInt iElem = 0; iElem < aNbElem; iElem++){
223 TCConnSliceArr aConnSliceArr = anInfo->GetConnSliceArr(iElem);
224 TInt aNbFaces = aConnSliceArr.size();
226 for(TInt iFace = 0; iFace < aNbFaces; iFace++){
227 TCConnSlice aConnSlice = aConnSliceArr[iFace];
228 TInt aNbConn = aConnSlice.size();
230 for(TInt iConn = 0; iConn < aNbConn; iConn++){
231 ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
233 ADDMSG(MYDEBUG,"] ");
235 ADDMSG(MYDEBUG,"} ");
237 ADDMSG(MYDEBUG, std::endl);
243 //----------------------------------------------------------------------------
246 ::GetPElemInfo(const PMeshInfo& theMeshInfo,
247 EEntiteMaillage theEntity,
248 EGeometrieElement theGeom,
249 EConnectivite theConnMode,
252 EMaillage aType = theMeshInfo->GetType();
253 if(aType == eNON_STRUCTURE){
256 if(theEntity == eNOEUD)
257 return GetPNodeInfo(theMeshInfo,theErr);
258 return GetPCellInfo(theMeshInfo,theEntity,theGeom,theConnMode,theErr);
261 return GetPPolygoneInfo(theMeshInfo,theEntity,theGeom,theConnMode);
264 return GetPPolyedreInfo(theMeshInfo,theEntity,theGeom,theConnMode);
267 return GetPCellInfo(theMeshInfo,theEntity,theGeom,theConnMode,theErr);
270 PGrilleInfo aGrille = GetPGrilleInfo(theMeshInfo);
273 EBooleen theIsElemNum = eFAUX;
277 nbElems = aGrille->GetNbNodes();
278 theIsElemNum = eVRAI;
283 nbElems = aGrille->GetNbCells();
291 TStringVector aElemNames;
295 if(theGeom == ePOINT1){
296 aElemInfo = CrElemInfo(theMeshInfo,
299 MED::TElemInfo &aTElemInfo = *aElemInfo;
301 // must be reimplemente in connection with mesh type eSTRUCTURE
302 // GetNumeration(aTElemInfo,
308 GetFamilies(aTElemInfo,
314 // must be reimplemente in connection with mesh type eSTRUCTURE
315 // GetNames(aTElemInfo,
321 aElemInfo = CrElemInfo(theMeshInfo,
334 //----------------------------------------------------------------------------
337 ::GetPCellInfo(const PMeshInfo& theMeshInfo,
338 EEntiteMaillage theEntity,
339 EGeometrieElement theGeom,
340 EConnectivite theConnMode,
343 if(theMeshInfo->GetType() != eNON_STRUCTURE)
345 TInt aNbElem = GetNbCells(theMeshInfo,theEntity,theGeom,theConnMode);
346 PCellInfo anInfo = CrCellInfo(theMeshInfo,theEntity,theGeom,aNbElem,theConnMode);
347 GetCellInfo(anInfo,theErr);
350 TInt aConnDim = anInfo->GetConnDim();
351 INITMSG(MYDEBUG,"GetPCellInfo - theEntity = "<<theEntity<<"; theGeom = "<<theGeom<<"; aConnDim: "<<aConnDim<<"\n");
352 BEGMSG(MYDEBUG,"GetPCellInfo - aNbElem: "<<aNbElem<<": ");
353 for(TInt iElem = 0; iElem < aNbElem; iElem++){
354 TCConnSlice aConnSlice = anInfo->GetConnSlice(iElem);
355 for(TInt iConn = 0; iConn < aConnDim; iConn++){
356 ADDMSG(MYVALUEDEBUG,aConnSlice[iConn]<<",");
358 ADDMSG(MYVALUEDEBUG," ");
360 ADDMSG(MYDEBUG, std::endl);
362 BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetFamNum: ");
363 for(TInt iElem = 0; iElem < aNbElem; iElem++){
364 ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
366 ADDMSG(MYVALUEDEBUG, std::endl);
368 if(anInfo->IsElemNum()){
369 BEGMSG(MYVALUEDEBUG,"GetPCellInfo - GetElemNum: ");
370 for(TInt iElem = 0; iElem < aNbElem; iElem++){
371 ADDMSG(MYVALUEDEBUG,anInfo->GetElemNum(iElem)<<", ");
373 ADDMSG(MYVALUEDEBUG, std::endl);
375 ADDMSG(MYDEBUG, std::endl);
381 //----------------------------------------------------------------------------
382 //! Read a MEDWrapped representation of MED Balls from the MED file
385 ::GetPBallInfo(const PMeshInfo& theMeshInfo)
387 TInt nbBalls = GetNbBalls(theMeshInfo);
388 if ( nbBalls < 1 ) return PBallInfo();
390 PBallInfo anInfo = CrBallInfo( theMeshInfo, nbBalls );
395 //----------------------------------------------------------------------------
398 ::GetPFieldInfo(const PMeshInfo& theMeshInfo,
402 TInt aNbComp = GetNbComp(theId);
403 PFieldInfo anInfo = CrFieldInfo(theMeshInfo,aNbComp);
404 GetFieldInfo(theId,*anInfo,theErr);
409 "- aName = '"<<anInfo->GetName()<<"'"<<
410 "; aType = "<<anInfo->GetType()<<
411 "; aNbComp = "<<aNbComp<<
419 //----------------------------------------------------------------------------
422 ::GetPTimeStampInfo(const PFieldInfo& theFieldInfo,
423 EEntiteMaillage theEntity,
424 const TGeom2Size& theGeom2Size,
428 PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo,theEntity,theGeom2Size);
429 GetTimeStampInfo(theId,*anInfo,theErr);
432 INITMSG(MYDEBUG,"GetPTimeStampInfo - anEntity = "<<anInfo->GetEntity()<<"\n");
433 TGeom2NbGauss& aGeom2NbGauss = anInfo->myGeom2NbGauss;
434 TGeom2NbGauss::const_iterator anIter = aGeom2NbGauss.begin();
435 for(; anIter != aGeom2NbGauss.end(); anIter++){
436 const EGeometrieElement& aGeom = anIter->first;
437 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aGeom2NbGauss[aGeom]<<";\n");
445 //----------------------------------------------------------------------------
448 ::GetPProfileInfo(TInt theId,
452 TProfileInfo::TInfo aPreInfo = GetProfilePreInfo(theId);
453 PProfileInfo anInfo = CrProfileInfo(aPreInfo,theMode);
454 GetProfileInfo(theId,*anInfo,theErr);
460 //----------------------------------------------------------------------------
463 ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
464 const TGeom2Profile& theGeom2Profile,
467 PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
468 return CrTimeStampValue(theTimeStampInfo,
469 aFieldInfo->GetType(),
474 //----------------------------------------------------------------------------
477 ::CrTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
478 const PTimeStampValueBase& theInfo)
480 PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
481 return CrTimeStampValue(theTimeStampInfo,
483 aFieldInfo->GetType());
486 //----------------------------------------------------------------------------
487 template<class TimeStampValueType>
489 Print(SharedPtr<TimeStampValueType> theTimeStampValue)
491 INITMSG(MYDEBUG,"Print - TimeStampValue\n");
492 typename TimeStampValueType::TTGeom2Value& aGeom2Value = theTimeStampValue->myGeom2Value;
493 typename TimeStampValueType::TTGeom2Value::const_iterator anIter = aGeom2Value.begin();
494 for(; anIter != aGeom2Value.end(); anIter++){
495 const EGeometrieElement& aGeom = anIter->first;
496 const typename TimeStampValueType::TTMeshValue& aMeshValue = anIter->second;
497 TInt aNbElem = aMeshValue.myNbElem;
498 TInt aNbGauss = aMeshValue.myNbGauss;
499 TInt aNbComp = aMeshValue.myNbComp;
500 INITMSG(MYDEBUG,"aGeom = "<<aGeom<<" - "<<aNbElem<<": ");
501 for(TInt iElem = 0; iElem < aNbElem; iElem++){
502 typename TimeStampValueType::TTMeshValue::TCValueSliceArr aValueSliceArr = aMeshValue.GetGaussValueSliceArr(iElem);
503 ADDMSG(MYVALUEDEBUG,"{");
504 for(TInt iGauss = 0; iGauss < aNbGauss; iGauss++){
505 const typename TimeStampValueType::TTMeshValue::TCValueSlice& aValueSlice = aValueSliceArr[iGauss];
506 for(TInt iComp = 0; iComp < aNbComp; iComp++){
507 ADDMSG(MYVALUEDEBUG,aValueSlice[iComp]<<" ");
509 ADDMSG(MYVALUEDEBUG,"| ");
511 ADDMSG(MYVALUEDEBUG,"} ");
513 ADDMSG(MYDEBUG,"\n");
517 //----------------------------------------------------------------------------
520 ::GetPTimeStampValue(const PTimeStampInfo& theTimeStampInfo,
521 const TMKey2Profile& theMKey2Profile,
522 const TKey2Gauss& theKey2Gauss,
525 PFieldInfo aFieldInfo = theTimeStampInfo->GetFieldInfo();
526 PTimeStampValueBase anInfo = CrTimeStampValue(theTimeStampInfo,
527 aFieldInfo->GetType());
528 GetTimeStampValue(anInfo,
533 if(aFieldInfo->GetType() == eFLOAT64)
534 Print<TFloatTimeStampValue>(anInfo);
536 Print<TIntTimeStampValue>(anInfo);
541 //----------------------------------------------------------------------------
544 ::GetTimeStampVal(const PTimeStampVal& theVal,
545 const TMKey2Profile& theMKey2Profile,
546 const TKey2Gauss& theKey2Gauss,
549 PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
550 PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
551 if(aFieldInfo->GetType() == eFLOAT64)
552 GetTimeStampValue(theVal,
557 PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
560 GetTimeStampValue(aVal,
564 CopyTimeStampValueBase(aVal, theVal);
568 //----------------------------------------------------------------------------
571 ::SetTimeStamp(const PTimeStampVal& theVal,
574 PTimeStampInfo aTimeStampInfo = theVal->GetTimeStampInfo();
575 PFieldInfo aFieldInfo = aTimeStampInfo->GetFieldInfo();
576 if(aFieldInfo->GetType() == eFLOAT64)
577 SetTimeStampValue(theVal, theErr);
579 PTimeStampValueBase aVal = CrTimeStampValue(aTimeStampInfo,
581 theVal->GetGeom2Profile(),
582 theVal->GetModeSwitch());
583 CopyTimeStampValueBase(theVal, aVal);
584 SetTimeStampValue(aVal, theErr);
588 //----------------------------------------------------------------------------
591 ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
592 const TGeom2Profile& theGeom2Profile,
595 return CrTimeStampValue(theTimeStampInfo,
601 //----------------------------------------------------------------------------
604 ::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
605 const PTimeStampVal& theInfo)
607 return CrTimeStampValue(theTimeStampInfo,
612 //----------------------------------------------------------------------------
615 ::GetPTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
616 const TMKey2Profile& theMKey2Profile,
617 const TKey2Gauss& theKey2Gauss,
620 PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
621 GetTimeStampVal(anInfo,
628 //----------------------------------------------------------------------------
631 ::GetPGrilleInfo(const PMeshInfo& theMeshInfo)
633 if(theMeshInfo->GetType() != eSTRUCTURE)
634 return PGrilleInfo();
637 GetGrilleType(*theMeshInfo,type);
639 if(type == eGRILLE_STANDARD){
640 const TInt nnoeuds = GetNbNodes(*theMeshInfo);
641 anInfo = CrGrilleInfo(theMeshInfo,type,nnoeuds);
645 aVec.resize(theMeshInfo->GetDim());
646 for(int aAxe=0;aAxe<theMeshInfo->GetDim();aAxe++){
647 ETable aATable = eCOOR_IND1;
650 aATable = eCOOR_IND1;
653 aATable = eCOOR_IND2;
656 aATable = eCOOR_IND3;
659 aVec[aAxe] = GetNbNodes(*theMeshInfo,aATable);
661 anInfo = CrGrilleInfo(theMeshInfo,type,aVec);
664 GetGrilleInfo(anInfo);
665 anInfo->SetGrilleType(type);
668 INITMSG(MYDEBUG,"GetPGrilleInfo: ");
670 TInt aNbElem = anInfo->GetNbNodes();
671 BEGMSG(MYVALUEDEBUG,"GetFamNumNode: ");
672 for(TInt iElem = 0; iElem < aNbElem; iElem++){
673 ADDMSG(MYVALUEDEBUG,anInfo->GetFamNumNode(iElem)<<", ");
675 TInt aNbCells = anInfo->GetNbCells();
676 BEGMSG(MYVALUEDEBUG,"GetFamNum: ");
677 for(TInt iElem = 0; iElem < aNbCells; iElem++){
678 ADDMSG(MYVALUEDEBUG,anInfo->GetFamNum(iElem)<<", ");
680 ADDMSG(MYVALUEDEBUG, std::endl);
681 BEGMSG(MYVALUEDEBUG,"GetCoordName: ");
682 for(TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++){
683 ADDMSG(MYVALUEDEBUG,anInfo->GetCoordName(iElem)<<", ");
685 ADDMSG(MYVALUEDEBUG, std::endl);
686 BEGMSG(MYVALUEDEBUG,"GetCoordUnit: ");
687 for(TInt iElem = 0; iElem < theMeshInfo->GetDim(); iElem++){
688 ADDMSG(MYVALUEDEBUG,anInfo->GetCoordUnit(iElem)<<", ");
690 ADDMSG(MYVALUEDEBUG, std::endl);
698 //----------------------------------------------------------------------------
701 ::GetPGrilleInfo(const PMeshInfo& theMeshInfo,
702 const PGrilleInfo& theInfo)
704 PGrilleInfo anInfo = CrGrilleInfo(theMeshInfo,theInfo);