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(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);
89 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 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;
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;
350 vector<TInt> aNodeIds(aNbNodes);
351 bool anIsValidConnect = false;
352 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
356 #ifdef _EDF_NODE_IDS_
358 for(int iNode = 0; iNode < aNbNodes; iNode++)
359 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
361 for(int iNode = 0; iNode < aNbNodes; iNode++)
362 aNodeIds[iNode] = aConnSlice[iNode];
364 for(int iNode = 0; iNode < aNbNodes; iNode++)
365 aNodeIds[iNode] = aConnSlice[iNode];
367 anIsValidConnect = true;
369 }catch(const std::exception& exc){
370 //INFOS("Follow exception was cought:\n\t"<<exc.what());
373 //INFOS("Unknown exception was cought !!!");
377 if(!anIsValidConnect)
380 bool isRenum = false;
381 SMDS_MeshElement* anElement = NULL;
382 TInt aFamNum = aCellInfo->GetFamNum(iElem);
386 //MESSAGE("Try to create element # " << iElem << " with id = "
387 // << aCellInfo->GetElemNum(iElem));
391 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
393 aCellInfo->GetElemNum(iElem));
395 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
396 FindNode(myMesh,aNodeIds[1]));
397 isRenum = anIsElemNum;
402 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
405 aCellInfo->GetElemNum(iElem));
407 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
408 FindNode(myMesh,aNodeIds[1]),
409 FindNode(myMesh,aNodeIds[2]));
410 isRenum = anIsElemNum;
416 anElement = myMesh->AddFaceWithID(aNodeIds[0],
419 aCellInfo->GetElemNum(iElem));
421 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
422 FindNode(myMesh,aNodeIds[1]),
423 FindNode(myMesh,aNodeIds[2]));
424 isRenum = anIsElemNum;
430 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
431 aNodeIds[2], aNodeIds[3],
432 aNodeIds[4], aNodeIds[5],
433 aCellInfo->GetElemNum(iElem));
435 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
436 FindNode(myMesh,aNodeIds[1]),
437 FindNode(myMesh,aNodeIds[2]),
438 FindNode(myMesh,aNodeIds[3]),
439 FindNode(myMesh,aNodeIds[4]),
440 FindNode(myMesh,aNodeIds[5]));
441 isRenum = anIsElemNum;
447 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
448 aNodeIds[2], aNodeIds[3],
449 aCellInfo->GetElemNum(iElem));
451 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
452 FindNode(myMesh,aNodeIds[1]),
453 FindNode(myMesh,aNodeIds[2]),
454 FindNode(myMesh,aNodeIds[3]));
455 isRenum = anIsElemNum;
461 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
462 aNodeIds[2], aNodeIds[3],
463 aNodeIds[4], aNodeIds[5],
464 aNodeIds[6], aNodeIds[7],
465 aCellInfo->GetElemNum(iElem));
467 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
468 FindNode(myMesh,aNodeIds[1]),
469 FindNode(myMesh,aNodeIds[2]),
470 FindNode(myMesh,aNodeIds[3]),
471 FindNode(myMesh,aNodeIds[4]),
472 FindNode(myMesh,aNodeIds[5]),
473 FindNode(myMesh,aNodeIds[6]),
474 FindNode(myMesh,aNodeIds[7]));
475 isRenum = anIsElemNum;
481 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
482 aNodeIds[2], aNodeIds[3],
483 aCellInfo->GetElemNum(iElem));
485 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
486 FindNode(myMesh,aNodeIds[1]),
487 FindNode(myMesh,aNodeIds[2]),
488 FindNode(myMesh,aNodeIds[3]));
489 isRenum = anIsElemNum;
495 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
496 aNodeIds[2], aNodeIds[3],
497 aNodeIds[4], aNodeIds[5],
498 aNodeIds[6], aNodeIds[7],
499 aNodeIds[8], aNodeIds[9],
500 aCellInfo->GetElemNum(iElem));
502 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
503 FindNode(myMesh,aNodeIds[1]),
504 FindNode(myMesh,aNodeIds[2]),
505 FindNode(myMesh,aNodeIds[3]),
506 FindNode(myMesh,aNodeIds[4]),
507 FindNode(myMesh,aNodeIds[5]),
508 FindNode(myMesh,aNodeIds[6]),
509 FindNode(myMesh,aNodeIds[7]),
510 FindNode(myMesh,aNodeIds[8]),
511 FindNode(myMesh,aNodeIds[9]));
512 isRenum = anIsElemNum;
517 // There is some differnce between SMDS and MED
519 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
520 aNodeIds[2], aNodeIds[3],
522 aCellInfo->GetElemNum(iElem));
524 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
525 FindNode(myMesh,aNodeIds[1]),
526 FindNode(myMesh,aNodeIds[2]),
527 FindNode(myMesh,aNodeIds[3]),
528 FindNode(myMesh,aNodeIds[4]));
529 isRenum = anIsElemNum;
534 // There is some differnce between SMDS and MED
536 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
537 aNodeIds[2], aNodeIds[3],
538 aNodeIds[4], aNodeIds[5],
539 aNodeIds[6], aNodeIds[7],
540 aNodeIds[8], aNodeIds[9],
541 aNodeIds[10], aNodeIds[11],
543 aCellInfo->GetElemNum(iElem));
545 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
546 FindNode(myMesh,aNodeIds[1]),
547 FindNode(myMesh,aNodeIds[2]),
548 FindNode(myMesh,aNodeIds[3]),
549 FindNode(myMesh,aNodeIds[4]),
550 FindNode(myMesh,aNodeIds[5]),
551 FindNode(myMesh,aNodeIds[6]),
552 FindNode(myMesh,aNodeIds[7]),
553 FindNode(myMesh,aNodeIds[8]),
554 FindNode(myMesh,aNodeIds[9]),
555 FindNode(myMesh,aNodeIds[10]),
556 FindNode(myMesh,aNodeIds[11]),
557 FindNode(myMesh,aNodeIds[12]));
558 isRenum = anIsElemNum;
564 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
570 aCellInfo->GetElemNum(iElem));
572 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
573 FindNode(myMesh,aNodeIds[1]),
574 FindNode(myMesh,aNodeIds[2]),
575 FindNode(myMesh,aNodeIds[3]),
576 FindNode(myMesh,aNodeIds[4]),
577 FindNode(myMesh,aNodeIds[5]));
578 isRenum = anIsElemNum;
584 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
585 aNodeIds[2], aNodeIds[3],
586 aNodeIds[4], aNodeIds[5],
587 aNodeIds[6], aNodeIds[7],
588 aNodeIds[8], aNodeIds[9],
589 aNodeIds[10], aNodeIds[11],
590 aNodeIds[12], aNodeIds[13],
592 aCellInfo->GetElemNum(iElem));
594 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
595 FindNode(myMesh,aNodeIds[1]),
596 FindNode(myMesh,aNodeIds[2]),
597 FindNode(myMesh,aNodeIds[3]),
598 FindNode(myMesh,aNodeIds[4]),
599 FindNode(myMesh,aNodeIds[5]),
600 FindNode(myMesh,aNodeIds[6]),
601 FindNode(myMesh,aNodeIds[7]),
602 FindNode(myMesh,aNodeIds[8]),
603 FindNode(myMesh,aNodeIds[9]),
604 FindNode(myMesh,aNodeIds[10]),
605 FindNode(myMesh,aNodeIds[11]),
606 FindNode(myMesh,aNodeIds[12]),
607 FindNode(myMesh,aNodeIds[13]),
608 FindNode(myMesh,aNodeIds[14]));
609 isRenum = anIsElemNum;
615 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
623 aCellInfo->GetElemNum(iElem));
625 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
626 FindNode(myMesh,aNodeIds[1]),
627 FindNode(myMesh,aNodeIds[2]),
628 FindNode(myMesh,aNodeIds[3]),
629 FindNode(myMesh,aNodeIds[4]),
630 FindNode(myMesh,aNodeIds[5]),
631 FindNode(myMesh,aNodeIds[6]),
632 FindNode(myMesh,aNodeIds[7]));
633 isRenum = anIsElemNum;
639 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
640 aNodeIds[2], aNodeIds[3],
641 aNodeIds[4], aNodeIds[5],
642 aNodeIds[6], aNodeIds[7],
643 aNodeIds[8], aNodeIds[9],
644 aNodeIds[10], aNodeIds[11],
645 aNodeIds[12], aNodeIds[13],
646 aNodeIds[14], aNodeIds[15],
647 aNodeIds[16], aNodeIds[17],
648 aNodeIds[18], aNodeIds[19],
649 aCellInfo->GetElemNum(iElem));
651 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
652 FindNode(myMesh,aNodeIds[1]),
653 FindNode(myMesh,aNodeIds[2]),
654 FindNode(myMesh,aNodeIds[3]),
655 FindNode(myMesh,aNodeIds[4]),
656 FindNode(myMesh,aNodeIds[5]),
657 FindNode(myMesh,aNodeIds[6]),
658 FindNode(myMesh,aNodeIds[7]),
659 FindNode(myMesh,aNodeIds[8]),
660 FindNode(myMesh,aNodeIds[9]),
661 FindNode(myMesh,aNodeIds[10]),
662 FindNode(myMesh,aNodeIds[11]),
663 FindNode(myMesh,aNodeIds[12]),
664 FindNode(myMesh,aNodeIds[13]),
665 FindNode(myMesh,aNodeIds[14]),
666 FindNode(myMesh,aNodeIds[15]),
667 FindNode(myMesh,aNodeIds[16]),
668 FindNode(myMesh,aNodeIds[17]),
669 FindNode(myMesh,aNodeIds[18]),
670 FindNode(myMesh,aNodeIds[19]));
671 isRenum = anIsElemNum;
676 }catch(const std::exception& exc){
677 //INFOS("Follow exception was cought:\n\t"<<exc.what());
680 //INFOS("Unknown exception was cought !!!");
685 aResult = DRS_WARN_SKIP_ELEM;
691 if (aResult < DRS_WARN_RENUMBER)
692 aResult = DRS_WARN_RENUMBER;
694 if ( checkFamilyID ( aFamily, aFamNum )) {
695 // Save reference to this element from its family
696 myFamilies[aFamNum]->AddElement(anElement);
697 myFamilies[aFamNum]->SetType(anElement->GetType());
707 }catch(const std::exception& exc){
708 INFOS("Follow exception was cought:\n\t"<<exc.what());
711 INFOS("Unknown exception was cought !!!");
715 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
719 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
721 list<string> aMeshNames;
724 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
726 PWrapper aMed = CrWrapper(myFile);
728 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
729 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
730 // Reading the MED mesh
731 //---------------------
732 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
733 aMeshNames.push_back(aMeshInfo->GetName());
736 }catch(const std::exception& exc){
737 INFOS("Follow exception was cought:\n\t"<<exc.what());
738 theStatus = DRS_FAIL;
740 INFOS("Unknown exception was cought !!!");
741 theStatus = DRS_FAIL;
747 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
749 list<TNameAndType> aResult;
750 set<TNameAndType> aResGroupNames;
752 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
753 for (; aFamsIter != myFamilies.end(); aFamsIter++)
755 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
756 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
757 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
758 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
760 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
761 // Check, if this is a Group or SubMesh name
762 //if (aName.substr(0, 5) == string("Group")) {
763 if ( aResGroupNames.insert( aNameAndType ).second ) {
764 aResult.push_back( aNameAndType );
773 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
775 string aGroupName (theGroup->GetStoreName());
776 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
778 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
779 for (; aFamsIter != myFamilies.end(); aFamsIter++)
781 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
782 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
784 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
785 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
786 const SMDS_MeshElement * element = 0;
787 for (; anElemsIter != anElements.end(); anElemsIter++)
789 element = *anElemsIter;
790 theGroup->SMDSGroup().Add(element);
793 theGroup->SetType( element->GetType() );
798 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
801 char submeshGrpName[ 30 ];
802 sprintf( submeshGrpName, "SubMesh %d", theId );
803 string aName (submeshGrpName);
804 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
805 for (; aFamsIter != myFamilies.end(); aFamsIter++)
807 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
808 if (aFamily->MemberOf(aName))
810 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
811 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
812 if (aFamily->GetType() == SMDSAbs_Node)
814 for (; anElemsIter != anElements.end(); anElemsIter++)
816 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
817 theSubMesh->AddNode(node);
822 for (; anElemsIter != anElements.end(); anElemsIter++)
824 theSubMesh->AddElement(*anElemsIter);
831 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
833 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
834 for (; aFamsIter != myFamilies.end(); aFamsIter++)
836 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
837 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
838 set<string>::iterator aGrNamesIter = aGroupNames.begin();
839 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
841 string aName = *aGrNamesIter;
842 // Check, if this is a Group or SubMesh name
843 if (aName.substr(0, 7) == string("SubMesh"))
845 int Id = atoi(string(aName).substr(7).c_str());
846 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
847 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
848 if (aFamily->GetType() == SMDSAbs_Node)
850 for (; anElemsIter != anElements.end(); anElemsIter++)
852 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
853 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
854 // find out a shape type
855 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
856 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
857 switch ( aShapeType ) {
859 myMesh->SetNodeOnFace(node, Id); break;
861 myMesh->SetNodeOnEdge(node, Id); break;
863 myMesh->SetNodeOnVertex(node, Id); break;
865 myMesh->SetNodeInVolume(node, Id);
871 for (; anElemsIter != anElements.end(); anElemsIter++)
873 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
881 * \brief Ensure aFamily to have required ID
882 * \param aFamily - a family to check and update
883 * \param anID - an ID aFamily should have
884 * \retval bool - true if successful
886 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
888 if ( !aFamily || aFamily->GetId() != anID ) {
889 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
890 if ( i_fam == myFamilies.end() )
892 aFamily = i_fam->second;
894 return ( aFamily->GetId() == anID );
898 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
899 * \param theWrapper - PWrapper const pointer
900 * \param theMeshInfo - PMeshInfo const pointer
901 * \return TRUE, if successfully. Else FALSE
903 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
904 const MED::PMeshInfo& theMeshInfo)
908 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
909 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
910 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
911 MED::TInt aMeshDim = theMeshInfo->GetDim();
912 DriverMED_FamilyPtr aFamily;
913 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
914 double aCoords[3] = {0.0, 0.0, 0.0};
915 const SMDS_MeshNode* aNode;
916 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
917 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
918 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
919 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
921 if((aGrilleInfo->myFamNumNode).size() > 0){
922 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
923 if ( checkFamilyID ( aFamily, aFamNum ))
925 aFamily->AddElement(aNode);
926 aFamily->SetType(SMDSAbs_Node);
932 SMDS_MeshElement* anElement = NULL;
933 MED::TIntVector aNodeIds;
934 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
935 aNodeIds = aGrilleInfo->GetConn(iCell);
936 switch(aGrilleInfo->GetGeom()){
938 if(aNodeIds.size() != 2){
940 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
942 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
947 if(aNodeIds.size() != 4){
949 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
951 anElement = myMesh->AddFaceWithID(aNodeIds[0],
958 if(aNodeIds.size() != 8){
960 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
962 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
976 if((aGrilleInfo->myFamNum).size() > 0){
977 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
978 if ( checkFamilyID ( aFamily, aFamNum )){
979 aFamily->AddElement(anElement);
980 aFamily->SetType(anElement->GetType());