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_
54 DriverMED_R_SMESHDS_Mesh
55 ::SetMeshName(std::string theMeshName)
57 myMeshName = theMeshName;
60 static const SMDS_MeshNode*
61 FindNode(const SMDS_Mesh* theMesh, TInt theId){
62 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
63 if(aNode) return aNode;
64 EXCEPTION(std::runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
69 DriverMED_R_SMESHDS_Mesh
72 Status aResult = DRS_FAIL;
77 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
78 PWrapper aMed = CrWrapper(myFile,true);
81 if(TInt aNbMeshes = aMed->GetNbMeshes()){
82 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
83 // Reading the MED mesh
84 //---------------------
85 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
87 std::string aMeshName;
89 std::ostringstream aMeshNameStr;
90 aMeshNameStr<<myMeshId;
91 aMeshName = aMeshNameStr.str();
93 aMeshName = myMeshName;
95 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
96 if(aMeshName != aMeshInfo->GetName()) continue;
99 //TInt aMeshDim = aMeshInfo->GetDim();
101 // Reading MED families to the temporary structure
102 //------------------------------------------------
104 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
105 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
106 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
107 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
109 TInt aFamId = aFamilyInfo->GetId();
110 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
112 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
114 TInt aNbGrp = aFamilyInfo->GetNbGroup();
115 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
116 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
117 std::string aGroupName = aFamilyInfo->GetGroupName(iGr);
118 if(MYDEBUG) MESSAGE(aGroupName);
119 aFamily->AddGroupName(aGroupName);
121 aFamily->SetId( aFamId );
122 myFamilies[aFamId] = aFamily;
126 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
127 bool aRes = buildMeshGrille(aMed,aMeshInfo);
131 // Reading MED nodes to the corresponding SMDS structure
132 //------------------------------------------------------
133 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
139 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
141 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
142 TInt aNbElems = aNodeInfo->GetNbElem();
143 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
144 DriverMED_FamilyPtr aFamily;
145 for(TInt iElem = 0; iElem < aNbElems; iElem++){
146 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
147 double aCoords[3] = {0.0, 0.0, 0.0};
148 for(TInt iDim = 0; iDim < 3; iDim++)
149 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
150 const SMDS_MeshNode* aNode;
152 aNode = myMesh->AddNodeWithID
153 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
155 aNode = myMesh->AddNode
156 (aCoords[0],aCoords[1],aCoords[2]);
158 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
160 // Save reference to this node from its family
161 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
162 if ( checkFamilyID ( aFamily, aFamNum ))
164 aFamily->AddElement(aNode);
165 aFamily->SetType(SMDSAbs_Node);
169 // Reading pre information about all MED cells
170 //--------------------------------------------
171 typedef MED::TVector<int> TNodeIds;
172 bool takeNumbers = true; // initially we trust the numbers from file
173 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
174 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
175 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
176 const EEntiteMaillage& anEntity = anEntityIter->first;
177 if(anEntity == eNOEUD) continue;
178 // Reading MED cells to the corresponding SMDS structure
179 //------------------------------------------------------
180 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
181 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
182 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
183 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
186 // case ePOINT1: ## PAL16410
189 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
190 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
192 TInt aNbElem = aPolygoneInfo->GetNbElem();
193 for(TInt iElem = 0; iElem < aNbElem; iElem++){
194 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
195 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
196 TNodeIds aNodeIds(aNbConn);
197 #ifdef _EDF_NODE_IDS_
199 for(TInt iConn = 0; iConn < aNbConn; iConn++)
200 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
202 for(TInt iConn = 0; iConn < aNbConn; iConn++)
203 aNodeIds[iConn] = aConnSlice[iConn];
205 for(TInt iConn = 0; iConn < aNbConn; iConn++)
206 aNodeIds[iConn] = aConnSlice[iConn];
208 bool isRenum = false;
209 SMDS_MeshElement* anElement = NULL;
210 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
216 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
217 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
220 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
221 for(TInt iConn = 0; iConn < aNbConn; iConn++)
222 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
223 anElement = myMesh->AddPolygonalFace(aNodes);
224 isRenum = anIsElemNum;
227 }catch(const std::exception& exc){
234 aResult = DRS_WARN_SKIP_ELEM;
239 if(aResult < DRS_WARN_RENUMBER)
240 aResult = DRS_WARN_RENUMBER;
242 if ( checkFamilyID ( aFamily, aFamNum ))
244 // Save reference to this element from its family
245 aFamily->AddElement(anElement);
246 aFamily->SetType(anElement->GetType());
253 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
254 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
256 TInt aNbElem = aPolyedreInfo->GetNbElem();
257 for(TInt iElem = 0; iElem < aNbElem; iElem++){
258 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
259 TInt aNbFaces = aConnSliceArr.size();
260 typedef MED::TVector<int> TQuantities;
261 TQuantities aQuantities(aNbFaces);
262 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
263 TNodeIds aNodeIds(aNbNodes);
264 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
265 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
266 TInt aNbConn = aConnSlice.size();
267 aQuantities[iFace] = aNbConn;
268 #ifdef _EDF_NODE_IDS_
270 for(TInt iConn = 0; iConn < aNbConn; iConn++)
271 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
273 for(TInt iConn = 0; iConn < aNbConn; iConn++)
274 aNodeIds[iNode++] = aConnSlice[iConn];
276 for(TInt iConn = 0; iConn < aNbConn; iConn++)
277 aNodeIds[iNode++] = aConnSlice[iConn];
281 bool isRenum = false;
282 SMDS_MeshElement* anElement = NULL;
283 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
289 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
290 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
293 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
294 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
295 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
296 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
297 isRenum = anIsElemNum;
300 }catch(const std::exception& exc){
307 aResult = DRS_WARN_SKIP_ELEM;
312 if (aResult < DRS_WARN_RENUMBER)
313 aResult = DRS_WARN_RENUMBER;
315 if ( checkFamilyID ( aFamily, aFamNum )) {
316 // Save reference to this element from its family
317 aFamily->AddElement(anElement);
318 aFamily->SetType(anElement->GetType());
325 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
326 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
327 TInt aNbElems = aCellInfo->GetNbElem();
328 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
329 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
331 for(int iElem = 0; iElem < aNbElems; iElem++){
334 case eSEG2: aNbNodes = 2; break;
335 case eSEG3: aNbNodes = 3; break;
336 case eTRIA3: aNbNodes = 3; break;
337 case eTRIA6: aNbNodes = 6; break;
338 case eQUAD4: aNbNodes = 4; break;
339 case eQUAD8: aNbNodes = 8; break;
340 case eTETRA4: aNbNodes = 4; break;
341 case eTETRA10: aNbNodes = 10; break;
342 case ePYRA5: aNbNodes = 5; break;
343 case ePYRA13: aNbNodes = 13; break;
344 case ePENTA6: aNbNodes = 6; break;
345 case ePENTA15: aNbNodes = 15; break;
346 case eHEXA8: aNbNodes = 8; break;
347 case eHEXA20: aNbNodes = 20; break;
348 case ePOINT1: aNbNodes = 1; break;
351 std::vector<TInt> aNodeIds(aNbNodes);
352 bool anIsValidConnect = false;
353 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
357 #ifdef _EDF_NODE_IDS_
359 for(int iNode = 0; iNode < aNbNodes; iNode++)
360 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
362 for(int iNode = 0; iNode < aNbNodes; iNode++)
363 aNodeIds[iNode] = aConnSlice[iNode];
365 for(int iNode = 0; iNode < aNbNodes; iNode++)
366 aNodeIds[iNode] = aConnSlice[iNode];
368 anIsValidConnect = true;
370 }catch(const std::exception& exc){
371 //INFOS("Follow exception was cought:\n\t"<<exc.what());
374 //INFOS("Unknown exception was cought !!!");
378 if(!anIsValidConnect)
381 bool isRenum = false;
382 const SMDS_MeshElement* anElement = NULL;
383 TInt aFamNum = aCellInfo->GetFamNum(iElem);
387 //MESSAGE("Try to create element # " << iElem << " with id = "
388 // << aCellInfo->GetElemNum(iElem));
392 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
394 aCellInfo->GetElemNum(iElem));
396 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
397 FindNode(myMesh,aNodeIds[1]));
398 isRenum = anIsElemNum;
403 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
406 aCellInfo->GetElemNum(iElem));
408 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
409 FindNode(myMesh,aNodeIds[1]),
410 FindNode(myMesh,aNodeIds[2]));
411 isRenum = anIsElemNum;
417 anElement = myMesh->AddFaceWithID(aNodeIds[0],
420 aCellInfo->GetElemNum(iElem));
422 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
423 FindNode(myMesh,aNodeIds[1]),
424 FindNode(myMesh,aNodeIds[2]));
425 isRenum = anIsElemNum;
431 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
432 aNodeIds[2], aNodeIds[3],
433 aNodeIds[4], aNodeIds[5],
434 aCellInfo->GetElemNum(iElem));
436 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
437 FindNode(myMesh,aNodeIds[1]),
438 FindNode(myMesh,aNodeIds[2]),
439 FindNode(myMesh,aNodeIds[3]),
440 FindNode(myMesh,aNodeIds[4]),
441 FindNode(myMesh,aNodeIds[5]));
442 isRenum = anIsElemNum;
448 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
449 aNodeIds[2], aNodeIds[3],
450 aCellInfo->GetElemNum(iElem));
452 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
453 FindNode(myMesh,aNodeIds[1]),
454 FindNode(myMesh,aNodeIds[2]),
455 FindNode(myMesh,aNodeIds[3]));
456 isRenum = anIsElemNum;
462 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
463 aNodeIds[2], aNodeIds[3],
464 aNodeIds[4], aNodeIds[5],
465 aNodeIds[6], aNodeIds[7],
466 aCellInfo->GetElemNum(iElem));
468 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
469 FindNode(myMesh,aNodeIds[1]),
470 FindNode(myMesh,aNodeIds[2]),
471 FindNode(myMesh,aNodeIds[3]),
472 FindNode(myMesh,aNodeIds[4]),
473 FindNode(myMesh,aNodeIds[5]),
474 FindNode(myMesh,aNodeIds[6]),
475 FindNode(myMesh,aNodeIds[7]));
476 isRenum = anIsElemNum;
482 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
483 aNodeIds[2], aNodeIds[3],
484 aCellInfo->GetElemNum(iElem));
486 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
487 FindNode(myMesh,aNodeIds[1]),
488 FindNode(myMesh,aNodeIds[2]),
489 FindNode(myMesh,aNodeIds[3]));
490 isRenum = anIsElemNum;
496 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
497 aNodeIds[2], aNodeIds[3],
498 aNodeIds[4], aNodeIds[5],
499 aNodeIds[6], aNodeIds[7],
500 aNodeIds[8], aNodeIds[9],
501 aCellInfo->GetElemNum(iElem));
503 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
504 FindNode(myMesh,aNodeIds[1]),
505 FindNode(myMesh,aNodeIds[2]),
506 FindNode(myMesh,aNodeIds[3]),
507 FindNode(myMesh,aNodeIds[4]),
508 FindNode(myMesh,aNodeIds[5]),
509 FindNode(myMesh,aNodeIds[6]),
510 FindNode(myMesh,aNodeIds[7]),
511 FindNode(myMesh,aNodeIds[8]),
512 FindNode(myMesh,aNodeIds[9]));
513 isRenum = anIsElemNum;
518 // There is some differnce between SMDS and MED
520 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
521 aNodeIds[2], aNodeIds[3],
523 aCellInfo->GetElemNum(iElem));
525 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
526 FindNode(myMesh,aNodeIds[1]),
527 FindNode(myMesh,aNodeIds[2]),
528 FindNode(myMesh,aNodeIds[3]),
529 FindNode(myMesh,aNodeIds[4]));
530 isRenum = anIsElemNum;
535 // There is some differnce between SMDS and MED
537 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
538 aNodeIds[2], aNodeIds[3],
539 aNodeIds[4], aNodeIds[5],
540 aNodeIds[6], aNodeIds[7],
541 aNodeIds[8], aNodeIds[9],
542 aNodeIds[10], aNodeIds[11],
544 aCellInfo->GetElemNum(iElem));
546 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
547 FindNode(myMesh,aNodeIds[1]),
548 FindNode(myMesh,aNodeIds[2]),
549 FindNode(myMesh,aNodeIds[3]),
550 FindNode(myMesh,aNodeIds[4]),
551 FindNode(myMesh,aNodeIds[5]),
552 FindNode(myMesh,aNodeIds[6]),
553 FindNode(myMesh,aNodeIds[7]),
554 FindNode(myMesh,aNodeIds[8]),
555 FindNode(myMesh,aNodeIds[9]),
556 FindNode(myMesh,aNodeIds[10]),
557 FindNode(myMesh,aNodeIds[11]),
558 FindNode(myMesh,aNodeIds[12]));
559 isRenum = anIsElemNum;
565 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
571 aCellInfo->GetElemNum(iElem));
573 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
574 FindNode(myMesh,aNodeIds[1]),
575 FindNode(myMesh,aNodeIds[2]),
576 FindNode(myMesh,aNodeIds[3]),
577 FindNode(myMesh,aNodeIds[4]),
578 FindNode(myMesh,aNodeIds[5]));
579 isRenum = anIsElemNum;
585 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
586 aNodeIds[2], aNodeIds[3],
587 aNodeIds[4], aNodeIds[5],
588 aNodeIds[6], aNodeIds[7],
589 aNodeIds[8], aNodeIds[9],
590 aNodeIds[10], aNodeIds[11],
591 aNodeIds[12], aNodeIds[13],
593 aCellInfo->GetElemNum(iElem));
595 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
596 FindNode(myMesh,aNodeIds[1]),
597 FindNode(myMesh,aNodeIds[2]),
598 FindNode(myMesh,aNodeIds[3]),
599 FindNode(myMesh,aNodeIds[4]),
600 FindNode(myMesh,aNodeIds[5]),
601 FindNode(myMesh,aNodeIds[6]),
602 FindNode(myMesh,aNodeIds[7]),
603 FindNode(myMesh,aNodeIds[8]),
604 FindNode(myMesh,aNodeIds[9]),
605 FindNode(myMesh,aNodeIds[10]),
606 FindNode(myMesh,aNodeIds[11]),
607 FindNode(myMesh,aNodeIds[12]),
608 FindNode(myMesh,aNodeIds[13]),
609 FindNode(myMesh,aNodeIds[14]));
610 isRenum = anIsElemNum;
616 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
624 aCellInfo->GetElemNum(iElem));
626 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
627 FindNode(myMesh,aNodeIds[1]),
628 FindNode(myMesh,aNodeIds[2]),
629 FindNode(myMesh,aNodeIds[3]),
630 FindNode(myMesh,aNodeIds[4]),
631 FindNode(myMesh,aNodeIds[5]),
632 FindNode(myMesh,aNodeIds[6]),
633 FindNode(myMesh,aNodeIds[7]));
634 isRenum = anIsElemNum;
640 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
641 aNodeIds[2], aNodeIds[3],
642 aNodeIds[4], aNodeIds[5],
643 aNodeIds[6], aNodeIds[7],
644 aNodeIds[8], aNodeIds[9],
645 aNodeIds[10], aNodeIds[11],
646 aNodeIds[12], aNodeIds[13],
647 aNodeIds[14], aNodeIds[15],
648 aNodeIds[16], aNodeIds[17],
649 aNodeIds[18], aNodeIds[19],
650 aCellInfo->GetElemNum(iElem));
652 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
653 FindNode(myMesh,aNodeIds[1]),
654 FindNode(myMesh,aNodeIds[2]),
655 FindNode(myMesh,aNodeIds[3]),
656 FindNode(myMesh,aNodeIds[4]),
657 FindNode(myMesh,aNodeIds[5]),
658 FindNode(myMesh,aNodeIds[6]),
659 FindNode(myMesh,aNodeIds[7]),
660 FindNode(myMesh,aNodeIds[8]),
661 FindNode(myMesh,aNodeIds[9]),
662 FindNode(myMesh,aNodeIds[10]),
663 FindNode(myMesh,aNodeIds[11]),
664 FindNode(myMesh,aNodeIds[12]),
665 FindNode(myMesh,aNodeIds[13]),
666 FindNode(myMesh,aNodeIds[14]),
667 FindNode(myMesh,aNodeIds[15]),
668 FindNode(myMesh,aNodeIds[16]),
669 FindNode(myMesh,aNodeIds[17]),
670 FindNode(myMesh,aNodeIds[18]),
671 FindNode(myMesh,aNodeIds[19]));
672 isRenum = anIsElemNum;
677 anElement = FindNode(myMesh,aNodeIds[0]);
681 }catch(const std::exception& exc){
682 //INFOS("Follow exception was cought:\n\t"<<exc.what());
685 //INFOS("Unknown exception was cought !!!");
690 aResult = DRS_WARN_SKIP_ELEM;
696 if (aResult < DRS_WARN_RENUMBER)
697 aResult = DRS_WARN_RENUMBER;
699 if ( checkFamilyID ( aFamily, aFamNum )) {
700 // Save reference to this element from its family
701 myFamilies[aFamNum]->AddElement(anElement);
702 myFamilies[aFamNum]->SetType(anElement->GetType());
712 }catch(const std::exception& exc){
713 INFOS("Follow exception was cought:\n\t"<<exc.what());
716 INFOS("Unknown exception was cought !!!");
720 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
724 std::list<std::string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
726 std::list<std::string> aMeshNames;
729 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
731 PWrapper aMed = CrWrapper(myFile);
733 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
734 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
735 // Reading the MED mesh
736 //---------------------
737 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
738 aMeshNames.push_back(aMeshInfo->GetName());
741 }catch(const std::exception& exc){
742 INFOS("Follow exception was cought:\n\t"<<exc.what());
743 theStatus = DRS_FAIL;
745 INFOS("Unknown exception was cought !!!");
746 theStatus = DRS_FAIL;
752 std::list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
754 std::list<TNameAndType> aResult;
755 std::set<TNameAndType> aResGroupNames;
757 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
758 for (; aFamsIter != myFamilies.end(); aFamsIter++)
760 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
761 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
762 std::set<std::string>::const_iterator aGrNamesIter = aGroupNames.begin();
763 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
765 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
766 // Check, if this is a Group or SubMesh name
767 //if (aName.substr(0, 5) == string("Group")) {
768 if ( aResGroupNames.insert( aNameAndType ).second ) {
769 aResult.push_back( aNameAndType );
778 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
780 std::string aGroupName (theGroup->GetStoreName());
781 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
783 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
784 for (; aFamsIter != myFamilies.end(); aFamsIter++)
786 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
787 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
789 const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
790 std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
791 const SMDS_MeshElement * element = 0;
792 for (; anElemsIter != anElements.end(); anElemsIter++)
794 element = *anElemsIter;
795 theGroup->SMDSGroup().Add(element);
798 theGroup->SetType( theGroup->SMDSGroup().GetType() );
803 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
806 char submeshGrpName[ 30 ];
807 sprintf( submeshGrpName, "SubMesh %d", theId );
808 std::string aName (submeshGrpName);
809 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
810 for (; aFamsIter != myFamilies.end(); aFamsIter++)
812 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
813 if (aFamily->MemberOf(aName))
815 const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
816 std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
817 if (aFamily->GetType() == SMDSAbs_Node)
819 for (; anElemsIter != anElements.end(); anElemsIter++)
821 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
822 theSubMesh->AddNode(node);
827 for (; anElemsIter != anElements.end(); anElemsIter++)
829 theSubMesh->AddElement(*anElemsIter);
836 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
838 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
839 for (; aFamsIter != myFamilies.end(); aFamsIter++)
841 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
842 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
843 std::set<std::string>::iterator aGrNamesIter = aGroupNames.begin();
844 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
846 std::string aName = *aGrNamesIter;
847 // Check, if this is a Group or SubMesh name
848 if (aName.substr(0, 7) == std::string("SubMesh"))
850 int Id = atoi(std::string(aName).substr(7).c_str());
851 std::set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
852 std::set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
853 if (aFamily->GetType() == SMDSAbs_Node)
855 for (; anElemsIter != anElements.end(); anElemsIter++)
857 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
858 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
859 // find out a shape type
860 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
861 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
862 switch ( aShapeType ) {
864 myMesh->SetNodeOnFace(node, Id); break;
866 myMesh->SetNodeOnEdge(node, Id); break;
868 myMesh->SetNodeOnVertex(node, Id); break;
870 myMesh->SetNodeInVolume(node, Id);
876 for (; anElemsIter != anElements.end(); anElemsIter++)
878 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
886 * \brief Ensure aFamily to have required ID
887 * \param aFamily - a family to check and update
888 * \param anID - an ID aFamily should have
889 * \retval bool - true if successful
891 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
893 if ( !aFamily || aFamily->GetId() != anID ) {
894 std::map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
895 if ( i_fam == myFamilies.end() )
897 aFamily = i_fam->second;
899 return ( aFamily->GetId() == anID );
903 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
904 * \param theWrapper - PWrapper const pointer
905 * \param theMeshInfo - PMeshInfo const pointer
906 * \return TRUE, if successfully. Else FALSE
908 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
909 const MED::PMeshInfo& theMeshInfo)
913 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
914 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
915 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
916 MED::TInt aMeshDim = theMeshInfo->GetDim();
917 DriverMED_FamilyPtr aFamily;
918 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
919 double aCoords[3] = {0.0, 0.0, 0.0};
920 const SMDS_MeshNode* aNode;
921 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
922 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
923 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
924 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
926 if((aGrilleInfo->myFamNumNode).size() > 0){
927 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
928 if ( checkFamilyID ( aFamily, aFamNum ))
930 aFamily->AddElement(aNode);
931 aFamily->SetType(SMDSAbs_Node);
937 SMDS_MeshElement* anElement = NULL;
938 MED::TIntVector aNodeIds;
939 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
940 aNodeIds = aGrilleInfo->GetConn(iCell);
941 switch(aGrilleInfo->GetGeom()){
943 if(aNodeIds.size() != 2){
945 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
947 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
952 if(aNodeIds.size() != 4){
954 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
956 anElement = myMesh->AddFaceWithID(aNodeIds[0],
963 if(aNodeIds.size() != 8){
965 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
967 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
981 if((aGrilleInfo->myFamNum).size() > 0){
982 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
983 if ( checkFamilyID ( aFamily, aFamNum )){
984 aFamily->AddElement(anElement);
985 aFamily->SetType(anElement->GetType());