1 // SMESH DriverMED : driver to read and write 'med' files
3 // Copyright (C) 2003 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.
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
24 // File : DriverMED_R_SMESHDS_Mesh.cxx
27 #include "DriverMED_R_SMESHDS_Mesh.h"
28 #include "DriverMED_R_SMDS_Mesh.h"
29 #include "SMESHDS_Mesh.hxx"
30 #include "utilities.h"
32 #include "DriverMED_Family.h"
34 #include "SMESHDS_Group.hxx"
36 #include "MED_Factory.hxx"
37 #include "MED_CoordUtils.hxx"
38 #include "MED_Utilities.hxx"
43 static int MYDEBUG = 0;
46 static int MYDEBUG = 0;
49 #define _EDF_NODE_IDS_
55 DriverMED_R_SMESHDS_Mesh
56 ::SetMeshName(string theMeshName)
58 myMeshName = theMeshName;
61 static const SMDS_MeshNode*
62 FindNode(const SMDS_Mesh* theMesh, TInt theId){
63 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
64 if(aNode) return aNode;
65 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
70 DriverMED_R_SMESHDS_Mesh
73 Status aResult = DRS_FAIL;
78 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
79 PWrapper aMed = CrWrapper(myFile,true);
82 if(TInt aNbMeshes = aMed->GetNbMeshes()){
83 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
84 // Reading the MED mesh
85 //---------------------
86 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
90 ostringstream aMeshNameStr;
91 aMeshNameStr<<myMeshId;
92 aMeshName = aMeshNameStr.str();
94 aMeshName = myMeshName;
96 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
97 if(aMeshName != aMeshInfo->GetName()) continue;
100 //TInt aMeshDim = aMeshInfo->GetDim();
102 // Reading MED families to the temporary structure
103 //------------------------------------------------
105 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
106 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
107 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
108 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
110 TInt aFamId = aFamilyInfo->GetId();
111 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
113 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
115 TInt aNbGrp = aFamilyInfo->GetNbGroup();
116 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
117 bool isAttrOk = false;
118 if(aFamilyInfo->GetNbAttr() == aNbGrp)
120 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
121 string aGroupName = aFamilyInfo->GetGroupName(iGr);
123 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
124 aFamily->SetGroupAttributVal(anAttrVal);
127 if(MYDEBUG) MESSAGE(aGroupName);
128 aFamily->AddGroupName(aGroupName);
131 aFamily->SetId( aFamId );
132 myFamilies[aFamId] = aFamily;
136 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
137 /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
141 // Reading MED nodes to the corresponding SMDS structure
142 //------------------------------------------------------
143 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
149 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
151 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
152 TInt aNbElems = aNodeInfo->GetNbElem();
153 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
154 DriverMED_FamilyPtr aFamily;
155 for(TInt iElem = 0; iElem < aNbElems; iElem++){
156 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
157 double aCoords[3] = {0.0, 0.0, 0.0};
158 for(TInt iDim = 0; iDim < 3; iDim++)
159 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
160 const SMDS_MeshNode* aNode;
162 aNode = myMesh->AddNodeWithID
163 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
165 aNode = myMesh->AddNode
166 (aCoords[0],aCoords[1],aCoords[2]);
168 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
170 // Save reference to this node from its family
171 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
172 if ( checkFamilyID ( aFamily, aFamNum ))
174 aFamily->AddElement(aNode);
175 aFamily->SetType(SMDSAbs_Node);
179 // Reading pre information about all MED cells
180 //--------------------------------------------
181 typedef MED::TVector<int> TNodeIds;
182 bool takeNumbers = true; // initially we trust the numbers from file
183 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
184 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
185 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
186 const EEntiteMaillage& anEntity = anEntityIter->first;
187 if(anEntity == eNOEUD) continue;
188 // Reading MED cells to the corresponding SMDS structure
189 //------------------------------------------------------
190 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
191 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
192 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
193 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
196 // case ePOINT1: ## PAL16410
199 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
200 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
202 TInt aNbElem = aPolygoneInfo->GetNbElem();
203 for(TInt iElem = 0; iElem < aNbElem; iElem++){
204 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
205 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
206 TNodeIds aNodeIds(aNbConn);
207 #ifdef _EDF_NODE_IDS_
209 for(TInt iConn = 0; iConn < aNbConn; iConn++)
210 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
212 for(TInt iConn = 0; iConn < aNbConn; iConn++)
213 aNodeIds[iConn] = aConnSlice[iConn];
215 for(TInt iConn = 0; iConn < aNbConn; iConn++)
216 aNodeIds[iConn] = aConnSlice[iConn];
218 bool isRenum = false;
219 SMDS_MeshElement* anElement = NULL;
220 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
226 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
227 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
230 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
231 for(TInt iConn = 0; iConn < aNbConn; iConn++)
232 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
233 anElement = myMesh->AddPolygonalFace(aNodes);
234 isRenum = anIsElemNum;
237 }catch(const std::exception& exc){
244 aResult = DRS_WARN_SKIP_ELEM;
249 if(aResult < DRS_WARN_RENUMBER)
250 aResult = DRS_WARN_RENUMBER;
252 if ( checkFamilyID ( aFamily, aFamNum ))
254 // Save reference to this element from its family
255 aFamily->AddElement(anElement);
256 aFamily->SetType(anElement->GetType());
263 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
264 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
266 TInt aNbElem = aPolyedreInfo->GetNbElem();
267 for(TInt iElem = 0; iElem < aNbElem; iElem++){
268 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
269 TInt aNbFaces = aConnSliceArr.size();
270 typedef MED::TVector<int> TQuantities;
271 TQuantities aQuantities(aNbFaces);
272 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
273 TNodeIds aNodeIds(aNbNodes);
274 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
275 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
276 TInt aNbConn = aConnSlice.size();
277 aQuantities[iFace] = aNbConn;
278 #ifdef _EDF_NODE_IDS_
280 for(TInt iConn = 0; iConn < aNbConn; iConn++)
281 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
283 for(TInt iConn = 0; iConn < aNbConn; iConn++)
284 aNodeIds[iNode++] = aConnSlice[iConn];
286 for(TInt iConn = 0; iConn < aNbConn; iConn++)
287 aNodeIds[iNode++] = aConnSlice[iConn];
291 bool isRenum = false;
292 SMDS_MeshElement* anElement = NULL;
293 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
299 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
300 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
303 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
304 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
305 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
306 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
307 isRenum = anIsElemNum;
310 }catch(const std::exception& exc){
317 aResult = DRS_WARN_SKIP_ELEM;
322 if (aResult < DRS_WARN_RENUMBER)
323 aResult = DRS_WARN_RENUMBER;
325 if ( checkFamilyID ( aFamily, aFamNum )) {
326 // Save reference to this element from its family
327 aFamily->AddElement(anElement);
328 aFamily->SetType(anElement->GetType());
335 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
336 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
337 TInt aNbElems = aCellInfo->GetNbElem();
338 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
339 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
341 for(int iElem = 0; iElem < aNbElems; iElem++){
344 case eSEG2: aNbNodes = 2; break;
345 case eSEG3: aNbNodes = 3; break;
346 case eTRIA3: aNbNodes = 3; break;
347 case eTRIA6: aNbNodes = 6; break;
348 case eQUAD4: aNbNodes = 4; break;
349 case eQUAD8: aNbNodes = 8; break;
350 case eTETRA4: aNbNodes = 4; break;
351 case eTETRA10: aNbNodes = 10; break;
352 case ePYRA5: aNbNodes = 5; break;
353 case ePYRA13: aNbNodes = 13; break;
354 case ePENTA6: aNbNodes = 6; break;
355 case ePENTA15: aNbNodes = 15; break;
356 case eHEXA8: aNbNodes = 8; break;
357 case eHEXA20: aNbNodes = 20; break;
358 case ePOINT1: aNbNodes = 1; break;
361 vector<TInt> aNodeIds(aNbNodes);
362 bool anIsValidConnect = false;
363 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
367 #ifdef _EDF_NODE_IDS_
369 for(int iNode = 0; iNode < aNbNodes; iNode++)
370 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
372 for(int iNode = 0; iNode < aNbNodes; iNode++)
373 aNodeIds[iNode] = aConnSlice[iNode];
375 for(int iNode = 0; iNode < aNbNodes; iNode++)
376 aNodeIds[iNode] = aConnSlice[iNode];
378 anIsValidConnect = true;
380 }catch(const std::exception& exc){
381 //INFOS("Follow exception was cought:\n\t"<<exc.what());
384 //INFOS("Unknown exception was cought !!!");
388 if(!anIsValidConnect)
391 bool isRenum = false;
392 const SMDS_MeshElement* anElement = NULL;
393 TInt aFamNum = aCellInfo->GetFamNum(iElem);
397 //MESSAGE("Try to create element # " << iElem << " with id = "
398 // << aCellInfo->GetElemNum(iElem));
402 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
404 aCellInfo->GetElemNum(iElem));
406 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
407 FindNode(myMesh,aNodeIds[1]));
408 isRenum = anIsElemNum;
413 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
416 aCellInfo->GetElemNum(iElem));
418 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
419 FindNode(myMesh,aNodeIds[1]),
420 FindNode(myMesh,aNodeIds[2]));
421 isRenum = anIsElemNum;
427 anElement = myMesh->AddFaceWithID(aNodeIds[0],
430 aCellInfo->GetElemNum(iElem));
432 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
433 FindNode(myMesh,aNodeIds[1]),
434 FindNode(myMesh,aNodeIds[2]));
435 isRenum = anIsElemNum;
441 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
442 aNodeIds[2], aNodeIds[3],
443 aNodeIds[4], aNodeIds[5],
444 aCellInfo->GetElemNum(iElem));
446 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
447 FindNode(myMesh,aNodeIds[1]),
448 FindNode(myMesh,aNodeIds[2]),
449 FindNode(myMesh,aNodeIds[3]),
450 FindNode(myMesh,aNodeIds[4]),
451 FindNode(myMesh,aNodeIds[5]));
452 isRenum = anIsElemNum;
458 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
459 aNodeIds[2], aNodeIds[3],
460 aCellInfo->GetElemNum(iElem));
462 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
463 FindNode(myMesh,aNodeIds[1]),
464 FindNode(myMesh,aNodeIds[2]),
465 FindNode(myMesh,aNodeIds[3]));
466 isRenum = anIsElemNum;
472 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
473 aNodeIds[2], aNodeIds[3],
474 aNodeIds[4], aNodeIds[5],
475 aNodeIds[6], aNodeIds[7],
476 aCellInfo->GetElemNum(iElem));
478 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
479 FindNode(myMesh,aNodeIds[1]),
480 FindNode(myMesh,aNodeIds[2]),
481 FindNode(myMesh,aNodeIds[3]),
482 FindNode(myMesh,aNodeIds[4]),
483 FindNode(myMesh,aNodeIds[5]),
484 FindNode(myMesh,aNodeIds[6]),
485 FindNode(myMesh,aNodeIds[7]));
486 isRenum = anIsElemNum;
492 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
493 aNodeIds[2], aNodeIds[3],
494 aCellInfo->GetElemNum(iElem));
496 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
497 FindNode(myMesh,aNodeIds[1]),
498 FindNode(myMesh,aNodeIds[2]),
499 FindNode(myMesh,aNodeIds[3]));
500 isRenum = anIsElemNum;
506 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
507 aNodeIds[2], aNodeIds[3],
508 aNodeIds[4], aNodeIds[5],
509 aNodeIds[6], aNodeIds[7],
510 aNodeIds[8], aNodeIds[9],
511 aCellInfo->GetElemNum(iElem));
513 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
514 FindNode(myMesh,aNodeIds[1]),
515 FindNode(myMesh,aNodeIds[2]),
516 FindNode(myMesh,aNodeIds[3]),
517 FindNode(myMesh,aNodeIds[4]),
518 FindNode(myMesh,aNodeIds[5]),
519 FindNode(myMesh,aNodeIds[6]),
520 FindNode(myMesh,aNodeIds[7]),
521 FindNode(myMesh,aNodeIds[8]),
522 FindNode(myMesh,aNodeIds[9]));
523 isRenum = anIsElemNum;
528 // There is some differnce between SMDS and MED
530 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
531 aNodeIds[2], aNodeIds[3],
533 aCellInfo->GetElemNum(iElem));
535 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
536 FindNode(myMesh,aNodeIds[1]),
537 FindNode(myMesh,aNodeIds[2]),
538 FindNode(myMesh,aNodeIds[3]),
539 FindNode(myMesh,aNodeIds[4]));
540 isRenum = anIsElemNum;
545 // There is some differnce between SMDS and MED
547 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
548 aNodeIds[2], aNodeIds[3],
549 aNodeIds[4], aNodeIds[5],
550 aNodeIds[6], aNodeIds[7],
551 aNodeIds[8], aNodeIds[9],
552 aNodeIds[10], aNodeIds[11],
554 aCellInfo->GetElemNum(iElem));
556 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
557 FindNode(myMesh,aNodeIds[1]),
558 FindNode(myMesh,aNodeIds[2]),
559 FindNode(myMesh,aNodeIds[3]),
560 FindNode(myMesh,aNodeIds[4]),
561 FindNode(myMesh,aNodeIds[5]),
562 FindNode(myMesh,aNodeIds[6]),
563 FindNode(myMesh,aNodeIds[7]),
564 FindNode(myMesh,aNodeIds[8]),
565 FindNode(myMesh,aNodeIds[9]),
566 FindNode(myMesh,aNodeIds[10]),
567 FindNode(myMesh,aNodeIds[11]),
568 FindNode(myMesh,aNodeIds[12]));
569 isRenum = anIsElemNum;
575 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
581 aCellInfo->GetElemNum(iElem));
583 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
584 FindNode(myMesh,aNodeIds[1]),
585 FindNode(myMesh,aNodeIds[2]),
586 FindNode(myMesh,aNodeIds[3]),
587 FindNode(myMesh,aNodeIds[4]),
588 FindNode(myMesh,aNodeIds[5]));
589 isRenum = anIsElemNum;
595 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
596 aNodeIds[2], aNodeIds[3],
597 aNodeIds[4], aNodeIds[5],
598 aNodeIds[6], aNodeIds[7],
599 aNodeIds[8], aNodeIds[9],
600 aNodeIds[10], aNodeIds[11],
601 aNodeIds[12], aNodeIds[13],
603 aCellInfo->GetElemNum(iElem));
605 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
606 FindNode(myMesh,aNodeIds[1]),
607 FindNode(myMesh,aNodeIds[2]),
608 FindNode(myMesh,aNodeIds[3]),
609 FindNode(myMesh,aNodeIds[4]),
610 FindNode(myMesh,aNodeIds[5]),
611 FindNode(myMesh,aNodeIds[6]),
612 FindNode(myMesh,aNodeIds[7]),
613 FindNode(myMesh,aNodeIds[8]),
614 FindNode(myMesh,aNodeIds[9]),
615 FindNode(myMesh,aNodeIds[10]),
616 FindNode(myMesh,aNodeIds[11]),
617 FindNode(myMesh,aNodeIds[12]),
618 FindNode(myMesh,aNodeIds[13]),
619 FindNode(myMesh,aNodeIds[14]));
620 isRenum = anIsElemNum;
626 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
634 aCellInfo->GetElemNum(iElem));
636 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
637 FindNode(myMesh,aNodeIds[1]),
638 FindNode(myMesh,aNodeIds[2]),
639 FindNode(myMesh,aNodeIds[3]),
640 FindNode(myMesh,aNodeIds[4]),
641 FindNode(myMesh,aNodeIds[5]),
642 FindNode(myMesh,aNodeIds[6]),
643 FindNode(myMesh,aNodeIds[7]));
644 isRenum = anIsElemNum;
650 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
651 aNodeIds[2], aNodeIds[3],
652 aNodeIds[4], aNodeIds[5],
653 aNodeIds[6], aNodeIds[7],
654 aNodeIds[8], aNodeIds[9],
655 aNodeIds[10], aNodeIds[11],
656 aNodeIds[12], aNodeIds[13],
657 aNodeIds[14], aNodeIds[15],
658 aNodeIds[16], aNodeIds[17],
659 aNodeIds[18], aNodeIds[19],
660 aCellInfo->GetElemNum(iElem));
662 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
663 FindNode(myMesh,aNodeIds[1]),
664 FindNode(myMesh,aNodeIds[2]),
665 FindNode(myMesh,aNodeIds[3]),
666 FindNode(myMesh,aNodeIds[4]),
667 FindNode(myMesh,aNodeIds[5]),
668 FindNode(myMesh,aNodeIds[6]),
669 FindNode(myMesh,aNodeIds[7]),
670 FindNode(myMesh,aNodeIds[8]),
671 FindNode(myMesh,aNodeIds[9]),
672 FindNode(myMesh,aNodeIds[10]),
673 FindNode(myMesh,aNodeIds[11]),
674 FindNode(myMesh,aNodeIds[12]),
675 FindNode(myMesh,aNodeIds[13]),
676 FindNode(myMesh,aNodeIds[14]),
677 FindNode(myMesh,aNodeIds[15]),
678 FindNode(myMesh,aNodeIds[16]),
679 FindNode(myMesh,aNodeIds[17]),
680 FindNode(myMesh,aNodeIds[18]),
681 FindNode(myMesh,aNodeIds[19]));
682 isRenum = anIsElemNum;
687 anElement = FindNode(myMesh,aNodeIds[0]);
691 }catch(const std::exception& exc){
692 //INFOS("Follow exception was cought:\n\t"<<exc.what());
695 //INFOS("Unknown exception was cought !!!");
700 aResult = DRS_WARN_SKIP_ELEM;
706 if (aResult < DRS_WARN_RENUMBER)
707 aResult = DRS_WARN_RENUMBER;
709 if ( checkFamilyID ( aFamily, aFamNum )) {
710 // Save reference to this element from its family
711 myFamilies[aFamNum]->AddElement(anElement);
712 myFamilies[aFamNum]->SetType(anElement->GetType());
722 }catch(const std::exception& exc){
723 INFOS("Follow exception was cought:\n\t"<<exc.what());
726 INFOS("Unknown exception was cought !!!");
730 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
734 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
736 list<string> aMeshNames;
739 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
741 PWrapper aMed = CrWrapper(myFile);
743 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
744 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
745 // Reading the MED mesh
746 //---------------------
747 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
748 aMeshNames.push_back(aMeshInfo->GetName());
751 }catch(const std::exception& exc){
752 INFOS("Follow exception was cought:\n\t"<<exc.what());
753 theStatus = DRS_FAIL;
755 INFOS("Unknown exception was cought !!!");
756 theStatus = DRS_FAIL;
762 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
764 list<TNameAndType> aResult;
765 set<TNameAndType> aResGroupNames;
767 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
768 for (; aFamsIter != myFamilies.end(); aFamsIter++)
770 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
771 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
772 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
773 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
775 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
776 // Check, if this is a Group or SubMesh name
777 //if (aName.substr(0, 5) == string("Group")) {
778 if ( aResGroupNames.insert( aNameAndType ).second ) {
779 aResult.push_back( aNameAndType );
788 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
790 string aGroupName (theGroup->GetStoreName());
791 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
793 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
794 for (; aFamsIter != myFamilies.end(); aFamsIter++)
796 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
797 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
799 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
800 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
801 const SMDS_MeshElement * element = 0;
802 for (; anElemsIter != anElements.end(); anElemsIter++)
804 element = *anElemsIter;
805 theGroup->SMDSGroup().Add(element);
806 int aGroupAttrVal = aFamily->GetGroupAttributVal();
807 if( aGroupAttrVal != 0)
808 theGroup->SetColorGroup(aGroupAttrVal);
811 theGroup->SetType( theGroup->SMDSGroup().GetType() );
816 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
819 char submeshGrpName[ 30 ];
820 sprintf( submeshGrpName, "SubMesh %d", theId );
821 string aName (submeshGrpName);
822 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
823 for (; aFamsIter != myFamilies.end(); aFamsIter++)
825 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
826 if (aFamily->MemberOf(aName))
828 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
829 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
830 if (aFamily->GetType() == SMDSAbs_Node)
832 for (; anElemsIter != anElements.end(); anElemsIter++)
834 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
835 theSubMesh->AddNode(node);
840 for (; anElemsIter != anElements.end(); anElemsIter++)
842 theSubMesh->AddElement(*anElemsIter);
849 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
851 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
852 for (; aFamsIter != myFamilies.end(); aFamsIter++)
854 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
855 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
856 set<string>::iterator aGrNamesIter = aGroupNames.begin();
857 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
859 string aName = *aGrNamesIter;
860 // Check, if this is a Group or SubMesh name
861 if (aName.substr(0, 7) == string("SubMesh"))
863 int Id = atoi(string(aName).substr(7).c_str());
864 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
865 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
866 if (aFamily->GetType() == SMDSAbs_Node)
868 for (; anElemsIter != anElements.end(); anElemsIter++)
870 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
871 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
872 // find out a shape type
873 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
874 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
875 switch ( aShapeType ) {
877 myMesh->SetNodeOnFace(node, Id); break;
879 myMesh->SetNodeOnEdge(node, Id); break;
881 myMesh->SetNodeOnVertex(node, Id); break;
883 myMesh->SetNodeInVolume(node, Id);
889 for (; anElemsIter != anElements.end(); anElemsIter++)
891 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
899 * \brief Ensure aFamily to have required ID
900 * \param aFamily - a family to check and update
901 * \param anID - an ID aFamily should have
902 * \retval bool - true if successful
904 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
906 if ( !aFamily || aFamily->GetId() != anID ) {
907 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
908 if ( i_fam == myFamilies.end() )
910 aFamily = i_fam->second;
912 return ( aFamily->GetId() == anID );
916 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
917 * \param theWrapper - PWrapper const pointer
918 * \param theMeshInfo - PMeshInfo const pointer
919 * \return TRUE, if successfully. Else FALSE
921 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
922 const MED::PMeshInfo& theMeshInfo)
926 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
927 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
928 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
929 MED::TInt aMeshDim = theMeshInfo->GetDim();
930 DriverMED_FamilyPtr aFamily;
931 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
932 double aCoords[3] = {0.0, 0.0, 0.0};
933 const SMDS_MeshNode* aNode;
934 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
935 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
936 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
937 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
939 if((aGrilleInfo->myFamNumNode).size() > 0){
940 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
941 if ( checkFamilyID ( aFamily, aFamNum ))
943 aFamily->AddElement(aNode);
944 aFamily->SetType(SMDSAbs_Node);
950 SMDS_MeshElement* anElement = NULL;
951 MED::TIntVector aNodeIds;
952 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
953 aNodeIds = aGrilleInfo->GetConn(iCell);
954 switch(aGrilleInfo->GetGeom()){
956 if(aNodeIds.size() != 2){
958 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
960 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
965 if(aNodeIds.size() != 4){
967 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
969 anElement = myMesh->AddFaceWithID(aNodeIds[0],
976 if(aNodeIds.size() != 8){
978 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
980 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
994 if((aGrilleInfo->myFamNum).size() > 0){
995 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
996 if ( checkFamilyID ( aFamily, aFamNum )){
997 aFamily->AddElement(anElement);
998 aFamily->SetType(anElement->GetType());