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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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(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(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 if (aMeshInfo->GetType() != MED::eNON_STRUCTURE)
88 continue; // not implemented yet
92 ostringstream aMeshNameStr;
93 aMeshNameStr<<myMeshId;
94 aMeshName = aMeshNameStr.str();
96 aMeshName = myMeshName;
98 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
99 if(aMeshName != aMeshInfo->GetName()) continue;
102 //TInt aMeshDim = aMeshInfo->GetDim();
104 // Reading MED families to the temporary structure
105 //------------------------------------------------
107 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
108 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
109 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
110 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
112 TInt aFamId = aFamilyInfo->GetId();
113 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
115 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
117 TInt aNbGrp = aFamilyInfo->GetNbGroup();
118 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
119 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
120 string aGroupName = aFamilyInfo->GetGroupName(iGr);
121 if(MYDEBUG) MESSAGE(aGroupName);
122 aFamily->AddGroupName(aGroupName);
124 aFamily->SetId( aFamId );
125 myFamilies[aFamId] = aFamily;
129 // Reading MED nodes to the corresponding SMDS structure
130 //------------------------------------------------------
131 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
135 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
137 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
138 TInt aNbElems = aNodeInfo->GetNbElem();
139 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
140 DriverMED_FamilyPtr aFamily;
141 for(TInt iElem = 0; iElem < aNbElems; iElem++){
142 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
143 double aCoords[3] = {0.0, 0.0, 0.0};
144 for(TInt iDim = 0; iDim < 3; iDim++)
145 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
146 const SMDS_MeshNode* aNode;
148 aNode = myMesh->AddNodeWithID
149 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
151 aNode = myMesh->AddNode
152 (aCoords[0],aCoords[1],aCoords[2]);
154 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
156 // Save reference to this node from its family
157 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
158 if ( checkFamilyID ( aFamily, aFamNum ))
160 aFamily->AddElement(aNode);
161 aFamily->SetType(SMDSAbs_Node);
165 // Reading pre information about all MED cells
166 //--------------------------------------------
167 typedef MED::TVector<int> TNodeIds;
168 bool takeNumbers = true; // initially we trust the numbers from file
169 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
170 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
171 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
172 const EEntiteMaillage& anEntity = anEntityIter->first;
173 if(anEntity == eNOEUD) continue;
174 // Reading MED cells to the corresponding SMDS structure
175 //------------------------------------------------------
176 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
177 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
178 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
179 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
185 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
186 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
188 TInt aNbElem = aPolygoneInfo->GetNbElem();
189 for(TInt iElem = 0; iElem < aNbElem; iElem++){
190 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
191 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
192 TNodeIds aNodeIds(aNbConn);
193 #ifdef _EDF_NODE_IDS_
195 for(TInt iConn = 0; iConn < aNbConn; iConn++)
196 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
198 for(TInt iConn = 0; iConn < aNbConn; iConn++)
199 aNodeIds[iConn] = aConnSlice[iConn];
201 for(TInt iConn = 0; iConn < aNbConn; iConn++)
202 aNodeIds[iConn] = aConnSlice[iConn];
204 bool isRenum = false;
205 SMDS_MeshElement* anElement = NULL;
206 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
212 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
213 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
216 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
217 for(TInt iConn = 0; iConn < aNbConn; iConn++)
218 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
219 anElement = myMesh->AddPolygonalFace(aNodes);
220 isRenum = anIsElemNum;
223 }catch(const std::exception& exc){
230 aResult = DRS_WARN_SKIP_ELEM;
235 if(aResult < DRS_WARN_RENUMBER)
236 aResult = DRS_WARN_RENUMBER;
238 if ( checkFamilyID ( aFamily, aFamNum ))
240 // Save reference to this element from its family
241 aFamily->AddElement(anElement);
242 aFamily->SetType(anElement->GetType());
249 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
250 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
252 TInt aNbElem = aPolyedreInfo->GetNbElem();
253 for(TInt iElem = 0; iElem < aNbElem; iElem++){
254 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
255 TInt aNbFaces = aConnSliceArr.size();
256 typedef MED::TVector<int> TQuantities;
257 TQuantities aQuantities(aNbFaces);
258 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
259 TNodeIds aNodeIds(aNbNodes);
260 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
261 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
262 TInt aNbConn = aConnSlice.size();
263 aQuantities[iFace] = aNbConn;
264 #ifdef _EDF_NODE_IDS_
266 for(TInt iConn = 0; iConn < aNbConn; iConn++)
267 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
269 for(TInt iConn = 0; iConn < aNbConn; iConn++)
270 aNodeIds[iNode++] = aConnSlice[iConn];
272 for(TInt iConn = 0; iConn < aNbConn; iConn++)
273 aNodeIds[iNode++] = aConnSlice[iConn];
277 bool isRenum = false;
278 SMDS_MeshElement* anElement = NULL;
279 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
285 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
286 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
289 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
290 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
291 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
292 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
293 isRenum = anIsElemNum;
296 }catch(const std::exception& exc){
303 aResult = DRS_WARN_SKIP_ELEM;
308 if (aResult < DRS_WARN_RENUMBER)
309 aResult = DRS_WARN_RENUMBER;
311 if ( checkFamilyID ( aFamily, aFamNum )) {
312 // Save reference to this element from its family
313 aFamily->AddElement(anElement);
314 aFamily->SetType(anElement->GetType());
321 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
322 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
323 TInt aNbElems = aCellInfo->GetNbElem();
324 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
325 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
327 for(int iElem = 0; iElem < aNbElems; iElem++){
330 case eSEG2: aNbNodes = 2; break;
331 case eSEG3: aNbNodes = 3; break;
332 case eTRIA3: aNbNodes = 3; break;
333 case eTRIA6: aNbNodes = 6; break;
334 case eQUAD4: aNbNodes = 4; break;
335 case eQUAD8: aNbNodes = 8; break;
336 case eTETRA4: aNbNodes = 4; break;
337 case eTETRA10: aNbNodes = 10; break;
338 case ePYRA5: aNbNodes = 5; break;
339 case ePYRA13: aNbNodes = 13; break;
340 case ePENTA6: aNbNodes = 6; break;
341 case ePENTA15: aNbNodes = 15; break;
342 case eHEXA8: aNbNodes = 8; break;
343 case eHEXA20: aNbNodes = 20; break;
346 vector<TInt> aNodeIds(aNbNodes);
347 bool anIsValidConnect = false;
348 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
352 #ifdef _EDF_NODE_IDS_
354 for(int iNode = 0; iNode < aNbNodes; iNode++)
355 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
357 for(int iNode = 0; iNode < aNbNodes; iNode++)
358 aNodeIds[iNode] = aConnSlice[iNode];
360 for(int iNode = 0; iNode < aNbNodes; iNode++)
361 aNodeIds[iNode] = aConnSlice[iNode];
363 anIsValidConnect = true;
365 }catch(const std::exception& exc){
366 //INFOS("Follow exception was cought:\n\t"<<exc.what());
369 //INFOS("Unknown exception was cought !!!");
373 if(!anIsValidConnect)
376 bool isRenum = false;
377 SMDS_MeshElement* anElement = NULL;
378 TInt aFamNum = aCellInfo->GetFamNum(iElem);
382 //MESSAGE("Try to create element # " << iElem << " with id = "
383 // << aCellInfo->GetElemNum(iElem));
387 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
389 aCellInfo->GetElemNum(iElem));
391 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
392 FindNode(myMesh,aNodeIds[1]));
393 isRenum = anIsElemNum;
398 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
401 aCellInfo->GetElemNum(iElem));
403 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
404 FindNode(myMesh,aNodeIds[1]),
405 FindNode(myMesh,aNodeIds[2]));
406 isRenum = anIsElemNum;
412 anElement = myMesh->AddFaceWithID(aNodeIds[0],
415 aCellInfo->GetElemNum(iElem));
417 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
418 FindNode(myMesh,aNodeIds[1]),
419 FindNode(myMesh,aNodeIds[2]));
420 isRenum = anIsElemNum;
426 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
427 aNodeIds[2], aNodeIds[3],
428 aNodeIds[4], aNodeIds[5],
429 aCellInfo->GetElemNum(iElem));
431 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
432 FindNode(myMesh,aNodeIds[1]),
433 FindNode(myMesh,aNodeIds[2]),
434 FindNode(myMesh,aNodeIds[3]),
435 FindNode(myMesh,aNodeIds[4]),
436 FindNode(myMesh,aNodeIds[5]));
437 isRenum = anIsElemNum;
443 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
444 aNodeIds[2], aNodeIds[3],
445 aCellInfo->GetElemNum(iElem));
447 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
448 FindNode(myMesh,aNodeIds[1]),
449 FindNode(myMesh,aNodeIds[2]),
450 FindNode(myMesh,aNodeIds[3]));
451 isRenum = anIsElemNum;
457 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
458 aNodeIds[2], aNodeIds[3],
459 aNodeIds[4], aNodeIds[5],
460 aNodeIds[6], aNodeIds[7],
461 aCellInfo->GetElemNum(iElem));
463 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
464 FindNode(myMesh,aNodeIds[1]),
465 FindNode(myMesh,aNodeIds[2]),
466 FindNode(myMesh,aNodeIds[3]),
467 FindNode(myMesh,aNodeIds[4]),
468 FindNode(myMesh,aNodeIds[5]),
469 FindNode(myMesh,aNodeIds[6]),
470 FindNode(myMesh,aNodeIds[7]));
471 isRenum = anIsElemNum;
477 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
478 aNodeIds[2], aNodeIds[3],
479 aCellInfo->GetElemNum(iElem));
481 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
482 FindNode(myMesh,aNodeIds[1]),
483 FindNode(myMesh,aNodeIds[2]),
484 FindNode(myMesh,aNodeIds[3]));
485 isRenum = anIsElemNum;
491 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
492 aNodeIds[2], aNodeIds[3],
493 aNodeIds[4], aNodeIds[5],
494 aNodeIds[6], aNodeIds[7],
495 aNodeIds[8], aNodeIds[9],
496 aCellInfo->GetElemNum(iElem));
498 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
499 FindNode(myMesh,aNodeIds[1]),
500 FindNode(myMesh,aNodeIds[2]),
501 FindNode(myMesh,aNodeIds[3]),
502 FindNode(myMesh,aNodeIds[4]),
503 FindNode(myMesh,aNodeIds[5]),
504 FindNode(myMesh,aNodeIds[6]),
505 FindNode(myMesh,aNodeIds[7]),
506 FindNode(myMesh,aNodeIds[8]),
507 FindNode(myMesh,aNodeIds[9]));
508 isRenum = anIsElemNum;
513 // There is some differnce between SMDS and MED
515 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
516 aNodeIds[2], aNodeIds[3],
518 aCellInfo->GetElemNum(iElem));
520 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
521 FindNode(myMesh,aNodeIds[1]),
522 FindNode(myMesh,aNodeIds[2]),
523 FindNode(myMesh,aNodeIds[3]),
524 FindNode(myMesh,aNodeIds[4]));
525 isRenum = anIsElemNum;
530 // There is some differnce between SMDS and MED
532 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
533 aNodeIds[2], aNodeIds[3],
534 aNodeIds[4], aNodeIds[5],
535 aNodeIds[6], aNodeIds[7],
536 aNodeIds[8], aNodeIds[9],
537 aNodeIds[10], aNodeIds[11],
539 aCellInfo->GetElemNum(iElem));
541 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
542 FindNode(myMesh,aNodeIds[1]),
543 FindNode(myMesh,aNodeIds[2]),
544 FindNode(myMesh,aNodeIds[3]),
545 FindNode(myMesh,aNodeIds[4]),
546 FindNode(myMesh,aNodeIds[5]),
547 FindNode(myMesh,aNodeIds[6]),
548 FindNode(myMesh,aNodeIds[7]),
549 FindNode(myMesh,aNodeIds[8]),
550 FindNode(myMesh,aNodeIds[9]),
551 FindNode(myMesh,aNodeIds[10]),
552 FindNode(myMesh,aNodeIds[11]),
553 FindNode(myMesh,aNodeIds[12]));
554 isRenum = anIsElemNum;
560 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
566 aCellInfo->GetElemNum(iElem));
568 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
569 FindNode(myMesh,aNodeIds[1]),
570 FindNode(myMesh,aNodeIds[2]),
571 FindNode(myMesh,aNodeIds[3]),
572 FindNode(myMesh,aNodeIds[4]),
573 FindNode(myMesh,aNodeIds[5]));
574 isRenum = anIsElemNum;
580 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
581 aNodeIds[2], aNodeIds[3],
582 aNodeIds[4], aNodeIds[5],
583 aNodeIds[6], aNodeIds[7],
584 aNodeIds[8], aNodeIds[9],
585 aNodeIds[10], aNodeIds[11],
586 aNodeIds[12], aNodeIds[13],
588 aCellInfo->GetElemNum(iElem));
590 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
591 FindNode(myMesh,aNodeIds[1]),
592 FindNode(myMesh,aNodeIds[2]),
593 FindNode(myMesh,aNodeIds[3]),
594 FindNode(myMesh,aNodeIds[4]),
595 FindNode(myMesh,aNodeIds[5]),
596 FindNode(myMesh,aNodeIds[6]),
597 FindNode(myMesh,aNodeIds[7]),
598 FindNode(myMesh,aNodeIds[8]),
599 FindNode(myMesh,aNodeIds[9]),
600 FindNode(myMesh,aNodeIds[10]),
601 FindNode(myMesh,aNodeIds[11]),
602 FindNode(myMesh,aNodeIds[12]),
603 FindNode(myMesh,aNodeIds[13]),
604 FindNode(myMesh,aNodeIds[14]));
605 isRenum = anIsElemNum;
611 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
619 aCellInfo->GetElemNum(iElem));
621 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
622 FindNode(myMesh,aNodeIds[1]),
623 FindNode(myMesh,aNodeIds[2]),
624 FindNode(myMesh,aNodeIds[3]),
625 FindNode(myMesh,aNodeIds[4]),
626 FindNode(myMesh,aNodeIds[5]),
627 FindNode(myMesh,aNodeIds[6]),
628 FindNode(myMesh,aNodeIds[7]));
629 isRenum = anIsElemNum;
635 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
636 aNodeIds[2], aNodeIds[3],
637 aNodeIds[4], aNodeIds[5],
638 aNodeIds[6], aNodeIds[7],
639 aNodeIds[8], aNodeIds[9],
640 aNodeIds[10], aNodeIds[11],
641 aNodeIds[12], aNodeIds[13],
642 aNodeIds[14], aNodeIds[15],
643 aNodeIds[16], aNodeIds[17],
644 aNodeIds[18], aNodeIds[19],
645 aCellInfo->GetElemNum(iElem));
647 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
648 FindNode(myMesh,aNodeIds[1]),
649 FindNode(myMesh,aNodeIds[2]),
650 FindNode(myMesh,aNodeIds[3]),
651 FindNode(myMesh,aNodeIds[4]),
652 FindNode(myMesh,aNodeIds[5]),
653 FindNode(myMesh,aNodeIds[6]),
654 FindNode(myMesh,aNodeIds[7]),
655 FindNode(myMesh,aNodeIds[8]),
656 FindNode(myMesh,aNodeIds[9]),
657 FindNode(myMesh,aNodeIds[10]),
658 FindNode(myMesh,aNodeIds[11]),
659 FindNode(myMesh,aNodeIds[12]),
660 FindNode(myMesh,aNodeIds[13]),
661 FindNode(myMesh,aNodeIds[14]),
662 FindNode(myMesh,aNodeIds[15]),
663 FindNode(myMesh,aNodeIds[16]),
664 FindNode(myMesh,aNodeIds[17]),
665 FindNode(myMesh,aNodeIds[18]),
666 FindNode(myMesh,aNodeIds[19]));
667 isRenum = anIsElemNum;
672 }catch(const std::exception& exc){
673 //INFOS("Follow exception was cought:\n\t"<<exc.what());
676 //INFOS("Unknown exception was cought !!!");
681 aResult = DRS_WARN_SKIP_ELEM;
687 if (aResult < DRS_WARN_RENUMBER)
688 aResult = DRS_WARN_RENUMBER;
690 if ( checkFamilyID ( aFamily, aFamNum )) {
691 // Save reference to this element from its family
692 myFamilies[aFamNum]->AddElement(anElement);
693 myFamilies[aFamNum]->SetType(anElement->GetType());
703 }catch(const std::exception& exc){
704 INFOS("Follow exception was cought:\n\t"<<exc.what());
707 INFOS("Unknown exception was cought !!!");
711 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
715 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
717 list<string> aMeshNames;
720 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
722 PWrapper aMed = CrWrapper(myFile);
724 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
725 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
726 // Reading the MED mesh
727 //---------------------
728 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
729 aMeshNames.push_back(aMeshInfo->GetName());
732 }catch(const std::exception& exc){
733 INFOS("Follow exception was cought:\n\t"<<exc.what());
734 theStatus = DRS_FAIL;
736 INFOS("Unknown exception was cought !!!");
737 theStatus = DRS_FAIL;
743 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
745 list<TNameAndType> aResult;
746 set<TNameAndType> aResGroupNames;
748 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
749 for (; aFamsIter != myFamilies.end(); aFamsIter++)
751 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
752 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
753 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
754 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
756 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
757 // Check, if this is a Group or SubMesh name
758 //if (aName.substr(0, 5) == string("Group")) {
759 if ( aResGroupNames.insert( aNameAndType ).second ) {
760 aResult.push_back( aNameAndType );
769 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
771 string aGroupName (theGroup->GetStoreName());
772 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
774 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
775 for (; aFamsIter != myFamilies.end(); aFamsIter++)
777 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
778 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
780 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
781 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
782 const SMDS_MeshElement * element = 0;
783 for (; anElemsIter != anElements.end(); anElemsIter++)
785 element = *anElemsIter;
786 theGroup->SMDSGroup().Add(element);
789 theGroup->SetType( element->GetType() );
794 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
797 char submeshGrpName[ 30 ];
798 sprintf( submeshGrpName, "SubMesh %d", theId );
799 string aName (submeshGrpName);
800 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
801 for (; aFamsIter != myFamilies.end(); aFamsIter++)
803 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
804 if (aFamily->MemberOf(aName))
806 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
807 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
808 if (aFamily->GetType() == SMDSAbs_Node)
810 for (; anElemsIter != anElements.end(); anElemsIter++)
812 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
813 theSubMesh->AddNode(node);
818 for (; anElemsIter != anElements.end(); anElemsIter++)
820 theSubMesh->AddElement(*anElemsIter);
827 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
829 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
830 for (; aFamsIter != myFamilies.end(); aFamsIter++)
832 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
833 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
834 set<string>::iterator aGrNamesIter = aGroupNames.begin();
835 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
837 string aName = *aGrNamesIter;
838 // Check, if this is a Group or SubMesh name
839 if (aName.substr(0, 7) == string("SubMesh"))
841 int Id = atoi(string(aName).substr(7).c_str());
842 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
843 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
844 if (aFamily->GetType() == SMDSAbs_Node)
846 for (; anElemsIter != anElements.end(); anElemsIter++)
848 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
849 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
850 // find out a shape type
851 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
852 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
853 switch ( aShapeType ) {
855 myMesh->SetNodeOnFace(node, Id); break;
857 myMesh->SetNodeOnEdge(node, Id); break;
859 myMesh->SetNodeOnVertex(node, Id); break;
861 myMesh->SetNodeInVolume(node, Id);
867 for (; anElemsIter != anElements.end(); anElemsIter++)
869 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
877 * \brief Ensure aFamily to have required ID
878 * \param aFamily - a family to check and update
879 * \param anID - an ID aFamily should have
880 * \retval bool - true if successful
882 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
884 if ( !aFamily || aFamily->GetId() != anID ) {
885 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
886 if ( i_fam == myFamilies.end() )
888 aFamily = i_fam->second;
890 return ( aFamily->GetId() == anID );