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);
88 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;
97 //TInt aMeshDim = aMeshInfo->GetDim();
99 // Reading MED families to the temporary structure
100 //------------------------------------------------
102 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
103 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
104 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
105 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
107 TInt aFamId = aFamilyInfo->GetId();
108 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
110 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
112 TInt aNbGrp = aFamilyInfo->GetNbGroup();
113 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
114 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
115 string aGroupName = aFamilyInfo->GetGroupName(iGr);
116 if(MYDEBUG) MESSAGE(aGroupName);
117 aFamily->AddGroupName(aGroupName);
119 aFamily->SetId( aFamId );
120 myFamilies[aFamId] = aFamily;
124 // Reading MED nodes to the corresponding SMDS structure
125 //------------------------------------------------------
126 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
130 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
132 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
133 TInt aNbElems = aNodeInfo->GetNbElem();
134 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
135 DriverMED_FamilyPtr aFamily;
136 for(TInt iElem = 0; iElem < aNbElems; iElem++){
137 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
138 double aCoords[3] = {0.0, 0.0, 0.0};
139 for(TInt iDim = 0; iDim < 3; iDim++)
140 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
141 const SMDS_MeshNode* aNode;
143 aNode = myMesh->AddNodeWithID
144 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
146 aNode = myMesh->AddNode
147 (aCoords[0],aCoords[1],aCoords[2]);
149 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
151 // Save reference to this node from its family
152 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
153 if ( checkFamilyID ( aFamily, aFamNum ))
155 aFamily->AddElement(aNode);
156 aFamily->SetType(SMDSAbs_Node);
160 // Reading pre information about all MED cells
161 //--------------------------------------------
162 typedef MED::TVector<int> TNodeIds;
163 bool takeNumbers = true; // initially we trust the numbers from file
164 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
165 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
166 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
167 const EEntiteMaillage& anEntity = anEntityIter->first;
168 if(anEntity == eNOEUD) continue;
169 // Reading MED cells to the corresponding SMDS structure
170 //------------------------------------------------------
171 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
172 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
173 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
174 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
180 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
181 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
183 TInt aNbElem = aPolygoneInfo->GetNbElem();
184 for(TInt iElem = 0; iElem < aNbElem; iElem++){
185 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
186 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
187 TNodeIds aNodeIds(aNbConn);
188 #ifdef _EDF_NODE_IDS_
190 for(TInt iConn = 0; iConn < aNbConn; iConn++)
191 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
193 for(TInt iConn = 0; iConn < aNbConn; iConn++)
194 aNodeIds[iConn] = aConnSlice[iConn];
196 for(TInt iConn = 0; iConn < aNbConn; iConn++)
197 aNodeIds[iConn] = aConnSlice[iConn];
199 bool isRenum = false;
200 SMDS_MeshElement* anElement = NULL;
201 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
207 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
208 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
211 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
212 for(TInt iConn = 0; iConn < aNbConn; iConn++)
213 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
214 anElement = myMesh->AddPolygonalFace(aNodes);
215 isRenum = anIsElemNum;
218 }catch(const std::exception& exc){
225 aResult = DRS_WARN_SKIP_ELEM;
230 if(aResult < DRS_WARN_RENUMBER)
231 aResult = DRS_WARN_RENUMBER;
233 if ( checkFamilyID ( aFamily, aFamNum ))
235 // Save reference to this element from its family
236 aFamily->AddElement(anElement);
237 aFamily->SetType(anElement->GetType());
244 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
245 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
247 TInt aNbElem = aPolyedreInfo->GetNbElem();
248 for(TInt iElem = 0; iElem < aNbElem; iElem++){
249 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
250 TInt aNbFaces = aConnSliceArr.size();
251 typedef MED::TVector<int> TQuantities;
252 TQuantities aQuantities(aNbFaces);
253 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
254 TNodeIds aNodeIds(aNbNodes);
255 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
256 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
257 TInt aNbConn = aConnSlice.size();
258 aQuantities[iFace] = aNbConn;
259 #ifdef _EDF_NODE_IDS_
261 for(TInt iConn = 0; iConn < aNbConn; iConn++)
262 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
264 for(TInt iConn = 0; iConn < aNbConn; iConn++)
265 aNodeIds[iNode++] = aConnSlice[iConn];
267 for(TInt iConn = 0; iConn < aNbConn; iConn++)
268 aNodeIds[iNode++] = aConnSlice[iConn];
272 bool isRenum = false;
273 SMDS_MeshElement* anElement = NULL;
274 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
280 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
281 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
284 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
285 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
286 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
287 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
288 isRenum = anIsElemNum;
291 }catch(const std::exception& exc){
298 aResult = DRS_WARN_SKIP_ELEM;
303 if (aResult < DRS_WARN_RENUMBER)
304 aResult = DRS_WARN_RENUMBER;
306 if ( checkFamilyID ( aFamily, aFamNum )) {
307 // Save reference to this element from its family
308 aFamily->AddElement(anElement);
309 aFamily->SetType(anElement->GetType());
316 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
317 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
318 TInt aNbElems = aCellInfo->GetNbElem();
319 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
320 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
322 for(int iElem = 0; iElem < aNbElems; iElem++){
325 case eSEG2: aNbNodes = 2; break;
326 case eSEG3: aNbNodes = 3; break;
327 case eTRIA3: aNbNodes = 3; break;
328 case eTRIA6: aNbNodes = 6; break;
329 case eQUAD4: aNbNodes = 4; break;
330 case eQUAD8: aNbNodes = 8; break;
331 case eTETRA4: aNbNodes = 4; break;
332 case eTETRA10: aNbNodes = 10; break;
333 case ePYRA5: aNbNodes = 5; break;
334 case ePYRA13: aNbNodes = 13; break;
335 case ePENTA6: aNbNodes = 6; break;
336 case ePENTA15: aNbNodes = 15; break;
337 case eHEXA8: aNbNodes = 8; break;
338 case eHEXA20: aNbNodes = 20; break;
341 vector<TInt> aNodeIds(aNbNodes);
342 bool anIsValidConnect = false;
343 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
347 #ifdef _EDF_NODE_IDS_
349 for(int iNode = 0; iNode < aNbNodes; iNode++)
350 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
352 for(int iNode = 0; iNode < aNbNodes; iNode++)
353 aNodeIds[iNode] = aConnSlice[iNode];
355 for(int iNode = 0; iNode < aNbNodes; iNode++)
356 aNodeIds[iNode] = aConnSlice[iNode];
358 anIsValidConnect = true;
360 }catch(const std::exception& exc){
361 //INFOS("Follow exception was cought:\n\t"<<exc.what());
364 //INFOS("Unknown exception was cought !!!");
368 if(!anIsValidConnect)
371 bool isRenum = false;
372 SMDS_MeshElement* anElement = NULL;
373 TInt aFamNum = aCellInfo->GetFamNum(iElem);
377 //MESSAGE("Try to create element # " << iElem << " with id = "
378 // << aCellInfo->GetElemNum(iElem));
382 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
384 aCellInfo->GetElemNum(iElem));
386 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
387 FindNode(myMesh,aNodeIds[1]));
388 isRenum = anIsElemNum;
393 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
396 aCellInfo->GetElemNum(iElem));
398 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
399 FindNode(myMesh,aNodeIds[1]),
400 FindNode(myMesh,aNodeIds[2]));
401 isRenum = anIsElemNum;
407 anElement = myMesh->AddFaceWithID(aNodeIds[0],
410 aCellInfo->GetElemNum(iElem));
412 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
413 FindNode(myMesh,aNodeIds[1]),
414 FindNode(myMesh,aNodeIds[2]));
415 isRenum = anIsElemNum;
421 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
422 aNodeIds[2], aNodeIds[3],
423 aNodeIds[4], aNodeIds[5],
424 aCellInfo->GetElemNum(iElem));
426 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
427 FindNode(myMesh,aNodeIds[1]),
428 FindNode(myMesh,aNodeIds[2]),
429 FindNode(myMesh,aNodeIds[3]),
430 FindNode(myMesh,aNodeIds[4]),
431 FindNode(myMesh,aNodeIds[5]));
432 isRenum = anIsElemNum;
438 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
439 aNodeIds[2], aNodeIds[3],
440 aCellInfo->GetElemNum(iElem));
442 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
443 FindNode(myMesh,aNodeIds[1]),
444 FindNode(myMesh,aNodeIds[2]),
445 FindNode(myMesh,aNodeIds[3]));
446 isRenum = anIsElemNum;
452 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
453 aNodeIds[2], aNodeIds[3],
454 aNodeIds[4], aNodeIds[5],
455 aNodeIds[6], aNodeIds[7],
456 aCellInfo->GetElemNum(iElem));
458 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
459 FindNode(myMesh,aNodeIds[1]),
460 FindNode(myMesh,aNodeIds[2]),
461 FindNode(myMesh,aNodeIds[3]),
462 FindNode(myMesh,aNodeIds[4]),
463 FindNode(myMesh,aNodeIds[5]),
464 FindNode(myMesh,aNodeIds[6]),
465 FindNode(myMesh,aNodeIds[7]));
466 isRenum = anIsElemNum;
472 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
473 aNodeIds[2], aNodeIds[3],
474 aCellInfo->GetElemNum(iElem));
476 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
477 FindNode(myMesh,aNodeIds[1]),
478 FindNode(myMesh,aNodeIds[2]),
479 FindNode(myMesh,aNodeIds[3]));
480 isRenum = anIsElemNum;
486 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
487 aNodeIds[2], aNodeIds[3],
488 aNodeIds[4], aNodeIds[5],
489 aNodeIds[6], aNodeIds[7],
490 aNodeIds[8], aNodeIds[9],
491 aCellInfo->GetElemNum(iElem));
493 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
494 FindNode(myMesh,aNodeIds[1]),
495 FindNode(myMesh,aNodeIds[2]),
496 FindNode(myMesh,aNodeIds[3]),
497 FindNode(myMesh,aNodeIds[4]),
498 FindNode(myMesh,aNodeIds[5]),
499 FindNode(myMesh,aNodeIds[6]),
500 FindNode(myMesh,aNodeIds[7]),
501 FindNode(myMesh,aNodeIds[8]),
502 FindNode(myMesh,aNodeIds[9]));
503 isRenum = anIsElemNum;
508 // There is some differnce between SMDS and MED
510 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
511 aNodeIds[2], aNodeIds[3],
513 aCellInfo->GetElemNum(iElem));
515 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
516 FindNode(myMesh,aNodeIds[1]),
517 FindNode(myMesh,aNodeIds[2]),
518 FindNode(myMesh,aNodeIds[3]),
519 FindNode(myMesh,aNodeIds[4]));
520 isRenum = anIsElemNum;
525 // There is some differnce between SMDS and MED
527 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
528 aNodeIds[2], aNodeIds[3],
529 aNodeIds[4], aNodeIds[5],
530 aNodeIds[6], aNodeIds[7],
531 aNodeIds[8], aNodeIds[9],
532 aNodeIds[10], aNodeIds[11],
534 aCellInfo->GetElemNum(iElem));
536 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
537 FindNode(myMesh,aNodeIds[1]),
538 FindNode(myMesh,aNodeIds[2]),
539 FindNode(myMesh,aNodeIds[3]),
540 FindNode(myMesh,aNodeIds[4]),
541 FindNode(myMesh,aNodeIds[5]),
542 FindNode(myMesh,aNodeIds[6]),
543 FindNode(myMesh,aNodeIds[7]),
544 FindNode(myMesh,aNodeIds[8]),
545 FindNode(myMesh,aNodeIds[9]),
546 FindNode(myMesh,aNodeIds[10]),
547 FindNode(myMesh,aNodeIds[11]),
548 FindNode(myMesh,aNodeIds[12]));
549 isRenum = anIsElemNum;
555 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
561 aCellInfo->GetElemNum(iElem));
563 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
564 FindNode(myMesh,aNodeIds[1]),
565 FindNode(myMesh,aNodeIds[2]),
566 FindNode(myMesh,aNodeIds[3]),
567 FindNode(myMesh,aNodeIds[4]),
568 FindNode(myMesh,aNodeIds[5]));
569 isRenum = anIsElemNum;
575 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
576 aNodeIds[2], aNodeIds[3],
577 aNodeIds[4], aNodeIds[5],
578 aNodeIds[6], aNodeIds[7],
579 aNodeIds[8], aNodeIds[9],
580 aNodeIds[10], aNodeIds[11],
581 aNodeIds[12], aNodeIds[13],
583 aCellInfo->GetElemNum(iElem));
585 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
586 FindNode(myMesh,aNodeIds[1]),
587 FindNode(myMesh,aNodeIds[2]),
588 FindNode(myMesh,aNodeIds[3]),
589 FindNode(myMesh,aNodeIds[4]),
590 FindNode(myMesh,aNodeIds[5]),
591 FindNode(myMesh,aNodeIds[6]),
592 FindNode(myMesh,aNodeIds[7]),
593 FindNode(myMesh,aNodeIds[8]),
594 FindNode(myMesh,aNodeIds[9]),
595 FindNode(myMesh,aNodeIds[10]),
596 FindNode(myMesh,aNodeIds[11]),
597 FindNode(myMesh,aNodeIds[12]),
598 FindNode(myMesh,aNodeIds[13]),
599 FindNode(myMesh,aNodeIds[14]));
600 isRenum = anIsElemNum;
606 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
614 aCellInfo->GetElemNum(iElem));
616 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
617 FindNode(myMesh,aNodeIds[1]),
618 FindNode(myMesh,aNodeIds[2]),
619 FindNode(myMesh,aNodeIds[3]),
620 FindNode(myMesh,aNodeIds[4]),
621 FindNode(myMesh,aNodeIds[5]),
622 FindNode(myMesh,aNodeIds[6]),
623 FindNode(myMesh,aNodeIds[7]));
624 isRenum = anIsElemNum;
630 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
631 aNodeIds[2], aNodeIds[3],
632 aNodeIds[4], aNodeIds[5],
633 aNodeIds[6], aNodeIds[7],
634 aNodeIds[8], aNodeIds[9],
635 aNodeIds[10], aNodeIds[11],
636 aNodeIds[12], aNodeIds[13],
637 aNodeIds[14], aNodeIds[15],
638 aNodeIds[16], aNodeIds[17],
639 aNodeIds[18], aNodeIds[19],
640 aCellInfo->GetElemNum(iElem));
642 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
643 FindNode(myMesh,aNodeIds[1]),
644 FindNode(myMesh,aNodeIds[2]),
645 FindNode(myMesh,aNodeIds[3]),
646 FindNode(myMesh,aNodeIds[4]),
647 FindNode(myMesh,aNodeIds[5]),
648 FindNode(myMesh,aNodeIds[6]),
649 FindNode(myMesh,aNodeIds[7]),
650 FindNode(myMesh,aNodeIds[8]),
651 FindNode(myMesh,aNodeIds[9]),
652 FindNode(myMesh,aNodeIds[10]),
653 FindNode(myMesh,aNodeIds[11]),
654 FindNode(myMesh,aNodeIds[12]),
655 FindNode(myMesh,aNodeIds[13]),
656 FindNode(myMesh,aNodeIds[14]),
657 FindNode(myMesh,aNodeIds[15]),
658 FindNode(myMesh,aNodeIds[16]),
659 FindNode(myMesh,aNodeIds[17]),
660 FindNode(myMesh,aNodeIds[18]),
661 FindNode(myMesh,aNodeIds[19]));
662 isRenum = anIsElemNum;
667 }catch(const std::exception& exc){
668 //INFOS("Follow exception was cought:\n\t"<<exc.what());
671 //INFOS("Unknown exception was cought !!!");
676 aResult = DRS_WARN_SKIP_ELEM;
682 if (aResult < DRS_WARN_RENUMBER)
683 aResult = DRS_WARN_RENUMBER;
685 if ( checkFamilyID ( aFamily, aFamNum )) {
686 // Save reference to this element from its family
687 myFamilies[aFamNum]->AddElement(anElement);
688 myFamilies[aFamNum]->SetType(anElement->GetType());
698 }catch(const std::exception& exc){
699 INFOS("Follow exception was cought:\n\t"<<exc.what());
702 INFOS("Unknown exception was cought !!!");
706 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
710 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
712 list<string> aMeshNames;
715 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
717 PWrapper aMed = CrWrapper(myFile);
719 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
720 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
721 // Reading the MED mesh
722 //---------------------
723 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
724 aMeshNames.push_back(aMeshInfo->GetName());
727 }catch(const std::exception& exc){
728 INFOS("Follow exception was cought:\n\t"<<exc.what());
729 theStatus = DRS_FAIL;
731 INFOS("Unknown exception was cought !!!");
732 theStatus = DRS_FAIL;
738 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
740 list<TNameAndType> aResult;
741 set<TNameAndType> aResGroupNames;
743 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
744 for (; aFamsIter != myFamilies.end(); aFamsIter++)
746 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
747 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
748 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
749 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
751 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
752 // Check, if this is a Group or SubMesh name
753 //if (aName.substr(0, 5) == string("Group")) {
754 if ( aResGroupNames.insert( aNameAndType ).second ) {
755 aResult.push_back( aNameAndType );
764 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
766 string aGroupName (theGroup->GetStoreName());
767 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
769 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
770 for (; aFamsIter != myFamilies.end(); aFamsIter++)
772 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
773 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
775 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
776 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
777 const SMDS_MeshElement * element = 0;
778 for (; anElemsIter != anElements.end(); anElemsIter++)
780 element = *anElemsIter;
781 theGroup->SMDSGroup().Add(element);
784 theGroup->SetType( element->GetType() );
789 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
792 char submeshGrpName[ 30 ];
793 sprintf( submeshGrpName, "SubMesh %d", theId );
794 string aName (submeshGrpName);
795 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
796 for (; aFamsIter != myFamilies.end(); aFamsIter++)
798 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
799 if (aFamily->MemberOf(aName))
801 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
802 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
803 if (aFamily->GetType() == SMDSAbs_Node)
805 for (; anElemsIter != anElements.end(); anElemsIter++)
807 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
808 theSubMesh->AddNode(node);
813 for (; anElemsIter != anElements.end(); anElemsIter++)
815 theSubMesh->AddElement(*anElemsIter);
822 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
824 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
825 for (; aFamsIter != myFamilies.end(); aFamsIter++)
827 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
828 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
829 set<string>::iterator aGrNamesIter = aGroupNames.begin();
830 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
832 string aName = *aGrNamesIter;
833 // Check, if this is a Group or SubMesh name
834 if (aName.substr(0, 7) == string("SubMesh"))
836 int Id = atoi(string(aName).substr(7).c_str());
837 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
838 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
839 if (aFamily->GetType() == SMDSAbs_Node)
841 for (; anElemsIter != anElements.end(); anElemsIter++)
843 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
844 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
845 // find out a shape type
846 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
847 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
848 switch ( aShapeType ) {
850 myMesh->SetNodeOnFace(node, Id); break;
852 myMesh->SetNodeOnEdge(node, Id); break;
854 myMesh->SetNodeOnVertex(node, Id); break;
856 myMesh->SetNodeInVolume(node, Id);
862 for (; anElemsIter != anElements.end(); anElemsIter++)
864 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
872 * \brief Ensure aFamily to have required ID
873 * \param aFamily - a family to check and update
874 * \param anID - an ID aFamily should have
875 * \retval bool - true if successful
877 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
879 if ( !aFamily || aFamily->GetId() != anID ) {
880 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
881 if ( i_fam == myFamilies.end() )
883 aFamily = i_fam->second;
885 return ( aFamily->GetId() == anID );