1 // Copyright (C) 2007-2008 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.
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 // SMESH DriverMED : driver to read and write 'med' files
23 // File : DriverMED_R_SMESHDS_Mesh.cxx
26 #include "DriverMED_R_SMESHDS_Mesh.h"
27 #include "DriverMED_R_SMDS_Mesh.h"
28 #include "SMESHDS_Mesh.hxx"
29 #include "utilities.h"
31 #include "DriverMED_Family.h"
33 #include "SMESHDS_Group.hxx"
35 #include "MED_Factory.hxx"
36 #include "MED_CoordUtils.hxx"
37 #include "MED_Utilities.hxx"
42 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 #define _EDF_NODE_IDS_
53 DriverMED_R_SMESHDS_Mesh
54 ::SetMeshName(std::string theMeshName)
56 myMeshName = theMeshName;
59 static const SMDS_MeshNode*
60 FindNode(const SMDS_Mesh* theMesh, TInt theId){
61 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
62 if(aNode) return aNode;
63 EXCEPTION(std::runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
68 DriverMED_R_SMESHDS_Mesh
71 Status aResult = DRS_FAIL;
76 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
77 PWrapper aMed = CrWrapper(myFile,true);
80 if(TInt aNbMeshes = aMed->GetNbMeshes()){
81 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
82 // Reading the MED mesh
83 //---------------------
84 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
86 std::string aMeshName;
88 std::ostringstream aMeshNameStr;
89 aMeshNameStr<<myMeshId;
90 aMeshName = aMeshNameStr.str();
92 aMeshName = myMeshName;
94 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
95 if(aMeshName != aMeshInfo->GetName()) continue;
98 //TInt aMeshDim = aMeshInfo->GetDim();
100 // Reading MED families to the temporary structure
101 //------------------------------------------------
103 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
104 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
105 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
106 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
108 TInt aFamId = aFamilyInfo->GetId();
109 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
111 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
113 TInt aNbGrp = aFamilyInfo->GetNbGroup();
114 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
115 bool isAttrOk = false;
116 if(aFamilyInfo->GetNbAttr() == aNbGrp)
118 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
119 std::string aGroupName = aFamilyInfo->GetGroupName(iGr);
121 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
122 aFamily->SetGroupAttributVal(anAttrVal);
125 if(MYDEBUG) MESSAGE(aGroupName);
126 aFamily->AddGroupName(aGroupName);
129 aFamily->SetId( aFamId );
130 myFamilies[aFamId] = aFamily;
134 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
135 /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
139 // Reading MED nodes to the corresponding SMDS structure
140 //------------------------------------------------------
141 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
147 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
149 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
150 TInt aNbElems = aNodeInfo->GetNbElem();
151 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
152 DriverMED_FamilyPtr aFamily;
153 for(TInt iElem = 0; iElem < aNbElems; iElem++){
154 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
155 double aCoords[3] = {0.0, 0.0, 0.0};
156 for(TInt iDim = 0; iDim < 3; iDim++)
157 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
158 const SMDS_MeshNode* aNode;
160 aNode = myMesh->AddNodeWithID
161 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
163 aNode = myMesh->AddNode
164 (aCoords[0],aCoords[1],aCoords[2]);
166 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
168 // Save reference to this node from its family
169 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
170 if ( checkFamilyID ( aFamily, aFamNum ))
172 aFamily->AddElement(aNode);
173 aFamily->SetType(SMDSAbs_Node);
177 // Reading pre information about all MED cells
178 //--------------------------------------------
179 typedef MED::TVector<int> TNodeIds;
180 bool takeNumbers = true; // initially we trust the numbers from file
181 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
182 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
183 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
184 const EEntiteMaillage& anEntity = anEntityIter->first;
185 if(anEntity == eNOEUD) continue;
186 // Reading MED cells to the corresponding SMDS structure
187 //------------------------------------------------------
188 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
189 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
190 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
191 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
194 // case ePOINT1: ## PAL16410
197 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
198 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
200 TInt aNbElem = aPolygoneInfo->GetNbElem();
201 for(TInt iElem = 0; iElem < aNbElem; iElem++){
202 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
203 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
204 TNodeIds aNodeIds(aNbConn);
205 #ifdef _EDF_NODE_IDS_
207 for(TInt iConn = 0; iConn < aNbConn; iConn++)
208 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
210 for(TInt iConn = 0; iConn < aNbConn; iConn++)
211 aNodeIds[iConn] = aConnSlice[iConn];
213 for(TInt iConn = 0; iConn < aNbConn; iConn++)
214 aNodeIds[iConn] = aConnSlice[iConn];
216 bool isRenum = false;
217 SMDS_MeshElement* anElement = NULL;
218 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
224 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
225 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
228 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
229 for(TInt iConn = 0; iConn < aNbConn; iConn++)
230 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
231 anElement = myMesh->AddPolygonalFace(aNodes);
232 isRenum = anIsElemNum;
235 }catch(const std::exception& exc){
242 aResult = DRS_WARN_SKIP_ELEM;
247 if(aResult < DRS_WARN_RENUMBER)
248 aResult = DRS_WARN_RENUMBER;
250 if ( checkFamilyID ( aFamily, aFamNum ))
252 // Save reference to this element from its family
253 aFamily->AddElement(anElement);
254 aFamily->SetType(anElement->GetType());
261 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
262 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
264 TInt aNbElem = aPolyedreInfo->GetNbElem();
265 for(TInt iElem = 0; iElem < aNbElem; iElem++){
266 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
267 TInt aNbFaces = aConnSliceArr.size();
268 typedef MED::TVector<int> TQuantities;
269 TQuantities aQuantities(aNbFaces);
270 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
271 TNodeIds aNodeIds(aNbNodes);
272 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
273 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
274 TInt aNbConn = aConnSlice.size();
275 aQuantities[iFace] = aNbConn;
276 #ifdef _EDF_NODE_IDS_
278 for(TInt iConn = 0; iConn < aNbConn; iConn++)
279 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
281 for(TInt iConn = 0; iConn < aNbConn; iConn++)
282 aNodeIds[iNode++] = aConnSlice[iConn];
284 for(TInt iConn = 0; iConn < aNbConn; iConn++)
285 aNodeIds[iNode++] = aConnSlice[iConn];
289 bool isRenum = false;
290 SMDS_MeshElement* anElement = NULL;
291 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
297 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
298 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
301 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
302 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
303 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
304 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
305 isRenum = anIsElemNum;
308 }catch(const std::exception& exc){
315 aResult = DRS_WARN_SKIP_ELEM;
320 if (aResult < DRS_WARN_RENUMBER)
321 aResult = DRS_WARN_RENUMBER;
323 if ( checkFamilyID ( aFamily, aFamNum )) {
324 // Save reference to this element from its family
325 aFamily->AddElement(anElement);
326 aFamily->SetType(anElement->GetType());
333 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
334 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
335 TInt aNbElems = aCellInfo->GetNbElem();
336 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
337 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
339 for(int iElem = 0; iElem < aNbElems; iElem++){
342 case eSEG2: aNbNodes = 2; break;
343 case eSEG3: aNbNodes = 3; break;
344 case eTRIA3: aNbNodes = 3; break;
345 case eTRIA6: aNbNodes = 6; break;
346 case eQUAD4: aNbNodes = 4; break;
347 case eQUAD8: aNbNodes = 8; break;
348 case eTETRA4: aNbNodes = 4; break;
349 case eTETRA10: aNbNodes = 10; break;
350 case ePYRA5: aNbNodes = 5; break;
351 case ePYRA13: aNbNodes = 13; break;
352 case ePENTA6: aNbNodes = 6; break;
353 case ePENTA15: aNbNodes = 15; break;
354 case eHEXA8: aNbNodes = 8; break;
355 case eHEXA20: aNbNodes = 20; break;
356 case ePOINT1: aNbNodes = 1; break;
359 std::vector<TInt> aNodeIds(aNbNodes);
360 bool anIsValidConnect = false;
361 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
365 #ifdef _EDF_NODE_IDS_
367 for(int iNode = 0; iNode < aNbNodes; iNode++)
368 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
370 for(int iNode = 0; iNode < aNbNodes; iNode++)
371 aNodeIds[iNode] = aConnSlice[iNode];
373 for(int iNode = 0; iNode < aNbNodes; iNode++)
374 aNodeIds[iNode] = aConnSlice[iNode];
376 anIsValidConnect = true;
378 }catch(const std::exception& exc){
379 //INFOS("Follow exception was cought:\n\t"<<exc.what());
382 //INFOS("Unknown exception was cought !!!");
386 if(!anIsValidConnect)
389 bool isRenum = false;
390 const SMDS_MeshElement* anElement = NULL;
391 TInt aFamNum = aCellInfo->GetFamNum(iElem);
395 //MESSAGE("Try to create element # " << iElem << " with id = "
396 // << aCellInfo->GetElemNum(iElem));
400 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
402 aCellInfo->GetElemNum(iElem));
404 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
405 FindNode(myMesh,aNodeIds[1]));
406 isRenum = anIsElemNum;
411 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
414 aCellInfo->GetElemNum(iElem));
416 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
417 FindNode(myMesh,aNodeIds[1]),
418 FindNode(myMesh,aNodeIds[2]));
419 isRenum = anIsElemNum;
425 anElement = myMesh->AddFaceWithID(aNodeIds[0],
428 aCellInfo->GetElemNum(iElem));
430 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
431 FindNode(myMesh,aNodeIds[1]),
432 FindNode(myMesh,aNodeIds[2]));
433 isRenum = anIsElemNum;
439 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
440 aNodeIds[2], aNodeIds[3],
441 aNodeIds[4], aNodeIds[5],
442 aCellInfo->GetElemNum(iElem));
444 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
445 FindNode(myMesh,aNodeIds[1]),
446 FindNode(myMesh,aNodeIds[2]),
447 FindNode(myMesh,aNodeIds[3]),
448 FindNode(myMesh,aNodeIds[4]),
449 FindNode(myMesh,aNodeIds[5]));
450 isRenum = anIsElemNum;
456 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
457 aNodeIds[2], aNodeIds[3],
458 aCellInfo->GetElemNum(iElem));
460 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
461 FindNode(myMesh,aNodeIds[1]),
462 FindNode(myMesh,aNodeIds[2]),
463 FindNode(myMesh,aNodeIds[3]));
464 isRenum = anIsElemNum;
470 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
471 aNodeIds[2], aNodeIds[3],
472 aNodeIds[4], aNodeIds[5],
473 aNodeIds[6], aNodeIds[7],
474 aCellInfo->GetElemNum(iElem));
476 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
477 FindNode(myMesh,aNodeIds[1]),
478 FindNode(myMesh,aNodeIds[2]),
479 FindNode(myMesh,aNodeIds[3]),
480 FindNode(myMesh,aNodeIds[4]),
481 FindNode(myMesh,aNodeIds[5]),
482 FindNode(myMesh,aNodeIds[6]),
483 FindNode(myMesh,aNodeIds[7]));
484 isRenum = anIsElemNum;
490 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
491 aNodeIds[2], aNodeIds[3],
492 aCellInfo->GetElemNum(iElem));
494 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
495 FindNode(myMesh,aNodeIds[1]),
496 FindNode(myMesh,aNodeIds[2]),
497 FindNode(myMesh,aNodeIds[3]));
498 isRenum = anIsElemNum;
504 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
505 aNodeIds[2], aNodeIds[3],
506 aNodeIds[4], aNodeIds[5],
507 aNodeIds[6], aNodeIds[7],
508 aNodeIds[8], aNodeIds[9],
509 aCellInfo->GetElemNum(iElem));
511 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
512 FindNode(myMesh,aNodeIds[1]),
513 FindNode(myMesh,aNodeIds[2]),
514 FindNode(myMesh,aNodeIds[3]),
515 FindNode(myMesh,aNodeIds[4]),
516 FindNode(myMesh,aNodeIds[5]),
517 FindNode(myMesh,aNodeIds[6]),
518 FindNode(myMesh,aNodeIds[7]),
519 FindNode(myMesh,aNodeIds[8]),
520 FindNode(myMesh,aNodeIds[9]));
521 isRenum = anIsElemNum;
526 // There is some differnce between SMDS and MED
528 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
529 aNodeIds[2], aNodeIds[3],
531 aCellInfo->GetElemNum(iElem));
533 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
534 FindNode(myMesh,aNodeIds[1]),
535 FindNode(myMesh,aNodeIds[2]),
536 FindNode(myMesh,aNodeIds[3]),
537 FindNode(myMesh,aNodeIds[4]));
538 isRenum = anIsElemNum;
543 // There is some differnce between SMDS and MED
545 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
546 aNodeIds[2], aNodeIds[3],
547 aNodeIds[4], aNodeIds[5],
548 aNodeIds[6], aNodeIds[7],
549 aNodeIds[8], aNodeIds[9],
550 aNodeIds[10], aNodeIds[11],
552 aCellInfo->GetElemNum(iElem));
554 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
555 FindNode(myMesh,aNodeIds[1]),
556 FindNode(myMesh,aNodeIds[2]),
557 FindNode(myMesh,aNodeIds[3]),
558 FindNode(myMesh,aNodeIds[4]),
559 FindNode(myMesh,aNodeIds[5]),
560 FindNode(myMesh,aNodeIds[6]),
561 FindNode(myMesh,aNodeIds[7]),
562 FindNode(myMesh,aNodeIds[8]),
563 FindNode(myMesh,aNodeIds[9]),
564 FindNode(myMesh,aNodeIds[10]),
565 FindNode(myMesh,aNodeIds[11]),
566 FindNode(myMesh,aNodeIds[12]));
567 isRenum = anIsElemNum;
573 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
579 aCellInfo->GetElemNum(iElem));
581 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
582 FindNode(myMesh,aNodeIds[1]),
583 FindNode(myMesh,aNodeIds[2]),
584 FindNode(myMesh,aNodeIds[3]),
585 FindNode(myMesh,aNodeIds[4]),
586 FindNode(myMesh,aNodeIds[5]));
587 isRenum = anIsElemNum;
593 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
594 aNodeIds[2], aNodeIds[3],
595 aNodeIds[4], aNodeIds[5],
596 aNodeIds[6], aNodeIds[7],
597 aNodeIds[8], aNodeIds[9],
598 aNodeIds[10], aNodeIds[11],
599 aNodeIds[12], aNodeIds[13],
601 aCellInfo->GetElemNum(iElem));
603 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
604 FindNode(myMesh,aNodeIds[1]),
605 FindNode(myMesh,aNodeIds[2]),
606 FindNode(myMesh,aNodeIds[3]),
607 FindNode(myMesh,aNodeIds[4]),
608 FindNode(myMesh,aNodeIds[5]),
609 FindNode(myMesh,aNodeIds[6]),
610 FindNode(myMesh,aNodeIds[7]),
611 FindNode(myMesh,aNodeIds[8]),
612 FindNode(myMesh,aNodeIds[9]),
613 FindNode(myMesh,aNodeIds[10]),
614 FindNode(myMesh,aNodeIds[11]),
615 FindNode(myMesh,aNodeIds[12]),
616 FindNode(myMesh,aNodeIds[13]),
617 FindNode(myMesh,aNodeIds[14]));
618 isRenum = anIsElemNum;
624 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
632 aCellInfo->GetElemNum(iElem));
634 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
635 FindNode(myMesh,aNodeIds[1]),
636 FindNode(myMesh,aNodeIds[2]),
637 FindNode(myMesh,aNodeIds[3]),
638 FindNode(myMesh,aNodeIds[4]),
639 FindNode(myMesh,aNodeIds[5]),
640 FindNode(myMesh,aNodeIds[6]),
641 FindNode(myMesh,aNodeIds[7]));
642 isRenum = anIsElemNum;
648 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
649 aNodeIds[2], aNodeIds[3],
650 aNodeIds[4], aNodeIds[5],
651 aNodeIds[6], aNodeIds[7],
652 aNodeIds[8], aNodeIds[9],
653 aNodeIds[10], aNodeIds[11],
654 aNodeIds[12], aNodeIds[13],
655 aNodeIds[14], aNodeIds[15],
656 aNodeIds[16], aNodeIds[17],
657 aNodeIds[18], aNodeIds[19],
658 aCellInfo->GetElemNum(iElem));
660 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
661 FindNode(myMesh,aNodeIds[1]),
662 FindNode(myMesh,aNodeIds[2]),
663 FindNode(myMesh,aNodeIds[3]),
664 FindNode(myMesh,aNodeIds[4]),
665 FindNode(myMesh,aNodeIds[5]),
666 FindNode(myMesh,aNodeIds[6]),
667 FindNode(myMesh,aNodeIds[7]),
668 FindNode(myMesh,aNodeIds[8]),
669 FindNode(myMesh,aNodeIds[9]),
670 FindNode(myMesh,aNodeIds[10]),
671 FindNode(myMesh,aNodeIds[11]),
672 FindNode(myMesh,aNodeIds[12]),
673 FindNode(myMesh,aNodeIds[13]),
674 FindNode(myMesh,aNodeIds[14]),
675 FindNode(myMesh,aNodeIds[15]),
676 FindNode(myMesh,aNodeIds[16]),
677 FindNode(myMesh,aNodeIds[17]),
678 FindNode(myMesh,aNodeIds[18]),
679 FindNode(myMesh,aNodeIds[19]));
680 isRenum = anIsElemNum;
685 anElement = FindNode(myMesh,aNodeIds[0]);
689 }catch(const std::exception& exc){
690 //INFOS("Follow exception was cought:\n\t"<<exc.what());
693 //INFOS("Unknown exception was cought !!!");
698 aResult = DRS_WARN_SKIP_ELEM;
704 if (aResult < DRS_WARN_RENUMBER)
705 aResult = DRS_WARN_RENUMBER;
707 if ( checkFamilyID ( aFamily, aFamNum )) {
708 // Save reference to this element from its family
709 myFamilies[aFamNum]->AddElement(anElement);
710 myFamilies[aFamNum]->SetType(anElement->GetType());
720 }catch(const std::exception& exc){
721 INFOS("Follow exception was cought:\n\t"<<exc.what());
724 INFOS("Unknown exception was cought !!!");
728 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
732 std::list<std::string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
734 std::list<std::string> aMeshNames;
737 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
739 PWrapper aMed = CrWrapper(myFile);
741 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
742 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
743 // Reading the MED mesh
744 //---------------------
745 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
746 aMeshNames.push_back(aMeshInfo->GetName());
749 }catch(const std::exception& exc){
750 INFOS("Follow exception was cought:\n\t"<<exc.what());
751 theStatus = DRS_FAIL;
753 INFOS("Unknown exception was cought !!!");
754 theStatus = DRS_FAIL;
760 std::list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
762 std::list<TNameAndType> aResult;
763 std::set<TNameAndType> aResGroupNames;
765 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
766 for (; aFamsIter != myFamilies.end(); aFamsIter++)
768 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
769 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
770 std::set<std::string>::const_iterator aGrNamesIter = aGroupNames.begin();
771 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
773 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
774 // Check, if this is a Group or SubMesh name
775 //if (aName.substr(0, 5) == string("Group")) {
776 if ( aResGroupNames.insert( aNameAndType ).second ) {
777 aResult.push_back( aNameAndType );
786 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
788 std::string aGroupName (theGroup->GetStoreName());
789 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
791 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
792 for (; aFamsIter != myFamilies.end(); aFamsIter++)
794 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
795 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
797 const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
798 std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
799 const SMDS_MeshElement * element = 0;
800 for (; anElemsIter != anElements.end(); anElemsIter++)
802 element = *anElemsIter;
803 theGroup->SMDSGroup().Add(element);
804 int aGroupAttrVal = aFamily->GetGroupAttributVal();
805 if( aGroupAttrVal != 0)
806 theGroup->SetColorGroup(aGroupAttrVal);
809 theGroup->SetType( theGroup->SMDSGroup().GetType() );
814 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
817 char submeshGrpName[ 30 ];
818 sprintf( submeshGrpName, "SubMesh %d", theId );
819 std::string aName (submeshGrpName);
820 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
821 for (; aFamsIter != myFamilies.end(); aFamsIter++)
823 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
824 if (aFamily->MemberOf(aName))
826 const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
827 std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
828 if (aFamily->GetType() == SMDSAbs_Node)
830 for (; anElemsIter != anElements.end(); anElemsIter++)
832 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
833 theSubMesh->AddNode(node);
838 for (; anElemsIter != anElements.end(); anElemsIter++)
840 theSubMesh->AddElement(*anElemsIter);
847 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
849 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
850 for (; aFamsIter != myFamilies.end(); aFamsIter++)
852 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
853 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
854 std::set<std::string>::iterator aGrNamesIter = aGroupNames.begin();
855 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
857 std::string aName = *aGrNamesIter;
858 // Check, if this is a Group or SubMesh name
859 if (aName.substr(0, 7) == std::string("SubMesh"))
861 int Id = atoi(std::string(aName).substr(7).c_str());
862 std::set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
863 std::set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
864 if (aFamily->GetType() == SMDSAbs_Node)
866 for (; anElemsIter != anElements.end(); anElemsIter++)
868 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
869 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
870 // find out a shape type
871 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
872 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
873 switch ( aShapeType ) {
875 myMesh->SetNodeOnFace(node, Id); break;
877 myMesh->SetNodeOnEdge(node, Id); break;
879 myMesh->SetNodeOnVertex(node, Id); break;
881 myMesh->SetNodeInVolume(node, Id);
887 for (; anElemsIter != anElements.end(); anElemsIter++)
889 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
897 * \brief Ensure aFamily to have required ID
898 * \param aFamily - a family to check and update
899 * \param anID - an ID aFamily should have
900 * \retval bool - true if successful
902 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
904 if ( !aFamily || aFamily->GetId() != anID ) {
905 std::map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
906 if ( i_fam == myFamilies.end() )
908 aFamily = i_fam->second;
910 return ( aFamily->GetId() == anID );
914 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
915 * \param theWrapper - PWrapper const pointer
916 * \param theMeshInfo - PMeshInfo const pointer
917 * \return TRUE, if successfully. Else FALSE
919 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
920 const MED::PMeshInfo& theMeshInfo)
924 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
925 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
926 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
927 MED::TInt aMeshDim = theMeshInfo->GetDim();
928 DriverMED_FamilyPtr aFamily;
929 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
930 double aCoords[3] = {0.0, 0.0, 0.0};
931 const SMDS_MeshNode* aNode;
932 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
933 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
934 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
935 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
937 if((aGrilleInfo->myFamNumNode).size() > 0){
938 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
939 if ( checkFamilyID ( aFamily, aFamNum ))
941 aFamily->AddElement(aNode);
942 aFamily->SetType(SMDSAbs_Node);
948 SMDS_MeshElement* anElement = NULL;
949 MED::TIntVector aNodeIds;
950 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
951 aNodeIds = aGrilleInfo->GetConn(iCell);
952 switch(aGrilleInfo->GetGeom()){
954 if(aNodeIds.size() != 2){
956 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
958 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
963 if(aNodeIds.size() != 4){
965 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
967 anElement = myMesh->AddFaceWithID(aNodeIds[0],
974 if(aNodeIds.size() != 8){
976 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
978 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
992 if((aGrilleInfo->myFamNum).size() > 0){
993 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
994 if ( checkFamilyID ( aFamily, aFamNum )){
995 aFamily->AddElement(anElement);
996 aFamily->SetType(anElement->GetType());