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);
128 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
130 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
131 TInt aNbElems = aNodeInfo->GetNbElem();
132 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
133 DriverMED_FamilyPtr aFamily;
134 for(TInt iElem = 0; iElem < aNbElems; iElem++){
135 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
136 double aCoords[3] = {0.0, 0.0, 0.0};
137 for(TInt iDim = 0; iDim < 3; iDim++)
138 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
139 const SMDS_MeshNode* aNode;
141 aNode = myMesh->AddNodeWithID
142 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
144 aNode = myMesh->AddNode
145 (aCoords[0],aCoords[1],aCoords[2]);
147 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
149 // Save reference to this node from its family
150 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
151 if ( checkFamilyID ( aFamily, aFamNum ))
153 aFamily->AddElement(aNode);
154 aFamily->SetType(SMDSAbs_Node);
158 // Reading pre information about all MED cells
159 //--------------------------------------------
160 typedef MED::TVector<int> TNodeIds;
161 bool takeNumbers = true; // initially we trust the numbers from file
162 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
163 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
164 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
165 const EEntiteMaillage& anEntity = anEntityIter->first;
166 if(anEntity == eNOEUD) continue;
167 // Reading MED cells to the corresponding SMDS structure
168 //------------------------------------------------------
169 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
170 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
171 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
172 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
178 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
179 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
181 TInt aNbElem = aPolygoneInfo->GetNbElem();
182 for(TInt iElem = 0; iElem < aNbElem; iElem++){
183 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
184 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
185 TNodeIds aNodeIds(aNbConn);
186 #ifdef _EDF_NODE_IDS_
188 for(TInt iConn = 0; iConn < aNbConn; iConn++)
189 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
191 for(TInt iConn = 0; iConn < aNbConn; iConn++)
192 aNodeIds[iConn] = aConnSlice[iConn];
194 for(TInt iConn = 0; iConn < aNbConn; iConn++)
195 aNodeIds[iConn] = aConnSlice[iConn];
197 bool isRenum = false;
198 SMDS_MeshElement* anElement = NULL;
199 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
205 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
206 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
209 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
210 for(TInt iConn = 0; iConn < aNbConn; iConn++)
211 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
212 anElement = myMesh->AddPolygonalFace(aNodes);
213 isRenum = anIsElemNum;
216 }catch(const std::exception& exc){
223 aResult = DRS_WARN_SKIP_ELEM;
228 if(aResult < DRS_WARN_RENUMBER)
229 aResult = DRS_WARN_RENUMBER;
231 if ( checkFamilyID ( aFamily, aFamNum ))
233 // Save reference to this element from its family
234 aFamily->AddElement(anElement);
235 aFamily->SetType(anElement->GetType());
242 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
243 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
245 TInt aNbElem = aPolyedreInfo->GetNbElem();
246 for(TInt iElem = 0; iElem < aNbElem; iElem++){
247 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
248 TInt aNbFaces = aConnSliceArr.size();
249 typedef MED::TVector<int> TQuantities;
250 TQuantities aQuantities(aNbFaces);
251 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
252 TNodeIds aNodeIds(aNbNodes);
253 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
254 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
255 TInt aNbConn = aConnSlice.size();
256 aQuantities[iFace] = aNbConn;
257 #ifdef _EDF_NODE_IDS_
259 for(TInt iConn = 0; iConn < aNbConn; iConn++)
260 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
262 for(TInt iConn = 0; iConn < aNbConn; iConn++)
263 aNodeIds[iNode++] = aConnSlice[iConn];
265 for(TInt iConn = 0; iConn < aNbConn; iConn++)
266 aNodeIds[iNode++] = aConnSlice[iConn];
270 bool isRenum = false;
271 SMDS_MeshElement* anElement = NULL;
272 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
278 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
279 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
282 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
283 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
284 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
285 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
286 isRenum = anIsElemNum;
289 }catch(const std::exception& exc){
296 aResult = DRS_WARN_SKIP_ELEM;
301 if (aResult < DRS_WARN_RENUMBER)
302 aResult = DRS_WARN_RENUMBER;
304 if ( checkFamilyID ( aFamily, aFamNum )) {
305 // Save reference to this element from its family
306 aFamily->AddElement(anElement);
307 aFamily->SetType(anElement->GetType());
314 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
315 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
316 TInt aNbElems = aCellInfo->GetNbElem();
317 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
318 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
320 for(int iElem = 0; iElem < aNbElems; iElem++){
323 case eSEG2: aNbNodes = 2; break;
324 case eSEG3: aNbNodes = 3; break;
325 case eTRIA3: aNbNodes = 3; break;
326 case eTRIA6: aNbNodes = 6; break;
327 case eQUAD4: aNbNodes = 4; break;
328 case eQUAD8: aNbNodes = 8; break;
329 case eTETRA4: aNbNodes = 4; break;
330 case eTETRA10: aNbNodes = 10; break;
331 case ePYRA5: aNbNodes = 5; break;
332 case ePYRA13: aNbNodes = 13; break;
333 case ePENTA6: aNbNodes = 6; break;
334 case ePENTA15: aNbNodes = 15; break;
335 case eHEXA8: aNbNodes = 8; break;
336 case eHEXA20: aNbNodes = 20; break;
339 vector<TInt> aNodeIds(aNbNodes);
340 bool anIsValidConnect = false;
341 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
345 #ifdef _EDF_NODE_IDS_
347 for(int iNode = 0; iNode < aNbNodes; iNode++)
348 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
350 for(int iNode = 0; iNode < aNbNodes; iNode++)
351 aNodeIds[iNode] = aConnSlice[iNode];
353 for(int iNode = 0; iNode < aNbNodes; iNode++)
354 aNodeIds[iNode] = aConnSlice[iNode];
356 anIsValidConnect = true;
358 }catch(const std::exception& exc){
359 //INFOS("Follow exception was cought:\n\t"<<exc.what());
362 //INFOS("Unknown exception was cought !!!");
366 if(!anIsValidConnect)
369 bool isRenum = false;
370 SMDS_MeshElement* anElement = NULL;
371 TInt aFamNum = aCellInfo->GetFamNum(iElem);
375 //MESSAGE("Try to create element # " << iElem << " with id = "
376 // << aCellInfo->GetElemNum(iElem));
380 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
382 aCellInfo->GetElemNum(iElem));
384 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
385 FindNode(myMesh,aNodeIds[1]));
386 isRenum = anIsElemNum;
391 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
394 aCellInfo->GetElemNum(iElem));
396 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
397 FindNode(myMesh,aNodeIds[1]),
398 FindNode(myMesh,aNodeIds[2]));
399 isRenum = anIsElemNum;
405 anElement = myMesh->AddFaceWithID(aNodeIds[0],
408 aCellInfo->GetElemNum(iElem));
410 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
411 FindNode(myMesh,aNodeIds[1]),
412 FindNode(myMesh,aNodeIds[2]));
413 isRenum = anIsElemNum;
419 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
420 aNodeIds[2], aNodeIds[3],
421 aNodeIds[4], aNodeIds[5],
422 aCellInfo->GetElemNum(iElem));
424 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
425 FindNode(myMesh,aNodeIds[1]),
426 FindNode(myMesh,aNodeIds[2]),
427 FindNode(myMesh,aNodeIds[3]),
428 FindNode(myMesh,aNodeIds[4]),
429 FindNode(myMesh,aNodeIds[5]));
430 isRenum = anIsElemNum;
436 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
437 aNodeIds[2], aNodeIds[3],
438 aCellInfo->GetElemNum(iElem));
440 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
441 FindNode(myMesh,aNodeIds[1]),
442 FindNode(myMesh,aNodeIds[2]),
443 FindNode(myMesh,aNodeIds[3]));
444 isRenum = anIsElemNum;
450 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
451 aNodeIds[2], aNodeIds[3],
452 aNodeIds[4], aNodeIds[5],
453 aNodeIds[6], aNodeIds[7],
454 aCellInfo->GetElemNum(iElem));
456 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
457 FindNode(myMesh,aNodeIds[1]),
458 FindNode(myMesh,aNodeIds[2]),
459 FindNode(myMesh,aNodeIds[3]),
460 FindNode(myMesh,aNodeIds[4]),
461 FindNode(myMesh,aNodeIds[5]),
462 FindNode(myMesh,aNodeIds[6]),
463 FindNode(myMesh,aNodeIds[7]));
464 isRenum = anIsElemNum;
470 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
471 aNodeIds[2], aNodeIds[3],
472 aCellInfo->GetElemNum(iElem));
474 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
475 FindNode(myMesh,aNodeIds[1]),
476 FindNode(myMesh,aNodeIds[2]),
477 FindNode(myMesh,aNodeIds[3]));
478 isRenum = anIsElemNum;
484 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
485 aNodeIds[2], aNodeIds[3],
486 aNodeIds[4], aNodeIds[5],
487 aNodeIds[6], aNodeIds[7],
488 aNodeIds[8], aNodeIds[9],
489 aCellInfo->GetElemNum(iElem));
491 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
492 FindNode(myMesh,aNodeIds[1]),
493 FindNode(myMesh,aNodeIds[2]),
494 FindNode(myMesh,aNodeIds[3]),
495 FindNode(myMesh,aNodeIds[4]),
496 FindNode(myMesh,aNodeIds[5]),
497 FindNode(myMesh,aNodeIds[6]),
498 FindNode(myMesh,aNodeIds[7]),
499 FindNode(myMesh,aNodeIds[8]),
500 FindNode(myMesh,aNodeIds[9]));
501 isRenum = anIsElemNum;
506 // There is some differnce between SMDS and MED
508 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
509 aNodeIds[2], aNodeIds[3],
511 aCellInfo->GetElemNum(iElem));
513 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
514 FindNode(myMesh,aNodeIds[1]),
515 FindNode(myMesh,aNodeIds[2]),
516 FindNode(myMesh,aNodeIds[3]),
517 FindNode(myMesh,aNodeIds[4]));
518 isRenum = anIsElemNum;
523 // There is some differnce between SMDS and MED
525 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
526 aNodeIds[2], aNodeIds[3],
527 aNodeIds[4], aNodeIds[5],
528 aNodeIds[6], aNodeIds[7],
529 aNodeIds[8], aNodeIds[9],
530 aNodeIds[10], aNodeIds[11],
532 aCellInfo->GetElemNum(iElem));
534 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
535 FindNode(myMesh,aNodeIds[1]),
536 FindNode(myMesh,aNodeIds[2]),
537 FindNode(myMesh,aNodeIds[3]),
538 FindNode(myMesh,aNodeIds[4]),
539 FindNode(myMesh,aNodeIds[5]),
540 FindNode(myMesh,aNodeIds[6]),
541 FindNode(myMesh,aNodeIds[7]),
542 FindNode(myMesh,aNodeIds[8]),
543 FindNode(myMesh,aNodeIds[9]),
544 FindNode(myMesh,aNodeIds[10]),
545 FindNode(myMesh,aNodeIds[11]),
546 FindNode(myMesh,aNodeIds[12]));
547 isRenum = anIsElemNum;
553 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
559 aCellInfo->GetElemNum(iElem));
561 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
562 FindNode(myMesh,aNodeIds[1]),
563 FindNode(myMesh,aNodeIds[2]),
564 FindNode(myMesh,aNodeIds[3]),
565 FindNode(myMesh,aNodeIds[4]),
566 FindNode(myMesh,aNodeIds[5]));
567 isRenum = anIsElemNum;
573 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
574 aNodeIds[2], aNodeIds[3],
575 aNodeIds[4], aNodeIds[5],
576 aNodeIds[6], aNodeIds[7],
577 aNodeIds[8], aNodeIds[9],
578 aNodeIds[10], aNodeIds[11],
579 aNodeIds[12], aNodeIds[13],
581 aCellInfo->GetElemNum(iElem));
583 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
584 FindNode(myMesh,aNodeIds[1]),
585 FindNode(myMesh,aNodeIds[2]),
586 FindNode(myMesh,aNodeIds[3]),
587 FindNode(myMesh,aNodeIds[4]),
588 FindNode(myMesh,aNodeIds[5]),
589 FindNode(myMesh,aNodeIds[6]),
590 FindNode(myMesh,aNodeIds[7]),
591 FindNode(myMesh,aNodeIds[8]),
592 FindNode(myMesh,aNodeIds[9]),
593 FindNode(myMesh,aNodeIds[10]),
594 FindNode(myMesh,aNodeIds[11]),
595 FindNode(myMesh,aNodeIds[12]),
596 FindNode(myMesh,aNodeIds[13]),
597 FindNode(myMesh,aNodeIds[14]));
598 isRenum = anIsElemNum;
604 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
612 aCellInfo->GetElemNum(iElem));
614 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
615 FindNode(myMesh,aNodeIds[1]),
616 FindNode(myMesh,aNodeIds[2]),
617 FindNode(myMesh,aNodeIds[3]),
618 FindNode(myMesh,aNodeIds[4]),
619 FindNode(myMesh,aNodeIds[5]),
620 FindNode(myMesh,aNodeIds[6]),
621 FindNode(myMesh,aNodeIds[7]));
622 isRenum = anIsElemNum;
628 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
629 aNodeIds[2], aNodeIds[3],
630 aNodeIds[4], aNodeIds[5],
631 aNodeIds[6], aNodeIds[7],
632 aNodeIds[8], aNodeIds[9],
633 aNodeIds[10], aNodeIds[11],
634 aNodeIds[12], aNodeIds[13],
635 aNodeIds[14], aNodeIds[15],
636 aNodeIds[16], aNodeIds[17],
637 aNodeIds[18], aNodeIds[19],
638 aCellInfo->GetElemNum(iElem));
640 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
641 FindNode(myMesh,aNodeIds[1]),
642 FindNode(myMesh,aNodeIds[2]),
643 FindNode(myMesh,aNodeIds[3]),
644 FindNode(myMesh,aNodeIds[4]),
645 FindNode(myMesh,aNodeIds[5]),
646 FindNode(myMesh,aNodeIds[6]),
647 FindNode(myMesh,aNodeIds[7]),
648 FindNode(myMesh,aNodeIds[8]),
649 FindNode(myMesh,aNodeIds[9]),
650 FindNode(myMesh,aNodeIds[10]),
651 FindNode(myMesh,aNodeIds[11]),
652 FindNode(myMesh,aNodeIds[12]),
653 FindNode(myMesh,aNodeIds[13]),
654 FindNode(myMesh,aNodeIds[14]),
655 FindNode(myMesh,aNodeIds[15]),
656 FindNode(myMesh,aNodeIds[16]),
657 FindNode(myMesh,aNodeIds[17]),
658 FindNode(myMesh,aNodeIds[18]),
659 FindNode(myMesh,aNodeIds[19]));
660 isRenum = anIsElemNum;
665 }catch(const std::exception& exc){
666 //INFOS("Follow exception was cought:\n\t"<<exc.what());
669 //INFOS("Unknown exception was cought !!!");
674 aResult = DRS_WARN_SKIP_ELEM;
680 if (aResult < DRS_WARN_RENUMBER)
681 aResult = DRS_WARN_RENUMBER;
683 if ( checkFamilyID ( aFamily, aFamNum )) {
684 // Save reference to this element from its family
685 myFamilies[aFamNum]->AddElement(anElement);
686 myFamilies[aFamNum]->SetType(anElement->GetType());
696 }catch(const std::exception& exc){
697 INFOS("Follow exception was cought:\n\t"<<exc.what());
700 INFOS("Unknown exception was cought !!!");
704 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
708 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
710 list<string> aMeshNames;
713 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
715 PWrapper aMed = CrWrapper(myFile);
717 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
718 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
719 // Reading the MED mesh
720 //---------------------
721 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
722 aMeshNames.push_back(aMeshInfo->GetName());
725 }catch(const std::exception& exc){
726 INFOS("Follow exception was cought:\n\t"<<exc.what());
727 theStatus = DRS_FAIL;
729 INFOS("Unknown exception was cought !!!");
730 theStatus = DRS_FAIL;
736 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
738 list<TNameAndType> aResult;
739 set<TNameAndType> aResGroupNames;
741 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
742 for (; aFamsIter != myFamilies.end(); aFamsIter++)
744 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
745 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
746 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
747 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
749 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
750 // Check, if this is a Group or SubMesh name
751 //if (aName.substr(0, 5) == string("Group")) {
752 if ( aResGroupNames.insert( aNameAndType ).second ) {
753 aResult.push_back( aNameAndType );
762 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
764 string aGroupName (theGroup->GetStoreName());
765 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
767 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
768 for (; aFamsIter != myFamilies.end(); aFamsIter++)
770 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
771 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
773 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
774 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
775 const SMDS_MeshElement * element = 0;
776 for (; anElemsIter != anElements.end(); anElemsIter++)
778 element = *anElemsIter;
779 theGroup->SMDSGroup().Add(element);
782 theGroup->SetType( element->GetType() );
787 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
790 char submeshGrpName[ 30 ];
791 sprintf( submeshGrpName, "SubMesh %d", theId );
792 string aName (submeshGrpName);
793 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
794 for (; aFamsIter != myFamilies.end(); aFamsIter++)
796 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
797 if (aFamily->MemberOf(aName))
799 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
800 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
801 if (aFamily->GetType() == SMDSAbs_Node)
803 for (; anElemsIter != anElements.end(); anElemsIter++)
805 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
806 theSubMesh->AddNode(node);
811 for (; anElemsIter != anElements.end(); anElemsIter++)
813 theSubMesh->AddElement(*anElemsIter);
820 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
822 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
823 for (; aFamsIter != myFamilies.end(); aFamsIter++)
825 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
826 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
827 set<string>::iterator aGrNamesIter = aGroupNames.begin();
828 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
830 string aName = *aGrNamesIter;
831 // Check, if this is a Group or SubMesh name
832 if (aName.substr(0, 7) == string("SubMesh"))
834 int Id = atoi(string(aName).substr(7).c_str());
835 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
836 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
837 if (aFamily->GetType() == SMDSAbs_Node)
839 for (; anElemsIter != anElements.end(); anElemsIter++)
841 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
842 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
843 // find out a shape type
844 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
845 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
846 switch ( aShapeType ) {
848 myMesh->SetNodeOnFace(node, Id); break;
850 myMesh->SetNodeOnEdge(node, Id); break;
852 myMesh->SetNodeOnVertex(node, Id); break;
854 myMesh->SetNodeInVolume(node, Id);
860 for (; anElemsIter != anElements.end(); anElemsIter++)
862 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
870 * \brief Ensure aFamily to have required ID
871 * \param aFamily - a family to check and update
872 * \param anID - an ID aFamily should have
873 * \retval bool - true if successful
875 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
877 if ( !aFamily || aFamily->GetId() != anID ) {
878 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
879 if ( i_fam == myFamilies.end() )
881 aFamily = i_fam->second;
883 return ( aFamily->GetId() == anID );