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);
137 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
139 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
140 TInt aNbElems = aNodeInfo->GetNbElem();
141 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
142 DriverMED_FamilyPtr aFamily;
143 for(TInt iElem = 0; iElem < aNbElems; iElem++){
144 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
145 double aCoords[3] = {0.0, 0.0, 0.0};
146 for(TInt iDim = 0; iDim < 3; iDim++)
147 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
148 const SMDS_MeshNode* aNode;
150 aNode = myMesh->AddNodeWithID
151 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
153 aNode = myMesh->AddNode
154 (aCoords[0],aCoords[1],aCoords[2]);
156 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
158 // Save reference to this node from its family
159 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
160 if ( checkFamilyID ( aFamily, aFamNum ))
162 aFamily->AddElement(aNode);
163 aFamily->SetType(SMDSAbs_Node);
167 // Reading pre information about all MED cells
168 //--------------------------------------------
169 typedef MED::TVector<int> TNodeIds;
170 bool takeNumbers = true; // initially we trust the numbers from file
171 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
172 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
173 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
174 const EEntiteMaillage& anEntity = anEntityIter->first;
175 if(anEntity == eNOEUD) continue;
176 // Reading MED cells to the corresponding SMDS structure
177 //------------------------------------------------------
178 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
179 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
180 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
181 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
187 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
188 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
190 TInt aNbElem = aPolygoneInfo->GetNbElem();
191 for(TInt iElem = 0; iElem < aNbElem; iElem++){
192 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
193 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
194 TNodeIds aNodeIds(aNbConn);
195 #ifdef _EDF_NODE_IDS_
197 for(TInt iConn = 0; iConn < aNbConn; iConn++)
198 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
200 for(TInt iConn = 0; iConn < aNbConn; iConn++)
201 aNodeIds[iConn] = aConnSlice[iConn];
203 for(TInt iConn = 0; iConn < aNbConn; iConn++)
204 aNodeIds[iConn] = aConnSlice[iConn];
206 bool isRenum = false;
207 SMDS_MeshElement* anElement = NULL;
208 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
214 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
215 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
218 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
219 for(TInt iConn = 0; iConn < aNbConn; iConn++)
220 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
221 anElement = myMesh->AddPolygonalFace(aNodes);
222 isRenum = anIsElemNum;
225 }catch(const std::exception& exc){
232 aResult = DRS_WARN_SKIP_ELEM;
237 if(aResult < DRS_WARN_RENUMBER)
238 aResult = DRS_WARN_RENUMBER;
240 if ( checkFamilyID ( aFamily, aFamNum ))
242 // Save reference to this element from its family
243 aFamily->AddElement(anElement);
244 aFamily->SetType(anElement->GetType());
251 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
252 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
254 TInt aNbElem = aPolyedreInfo->GetNbElem();
255 for(TInt iElem = 0; iElem < aNbElem; iElem++){
256 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
257 TInt aNbFaces = aConnSliceArr.size();
258 typedef MED::TVector<int> TQuantities;
259 TQuantities aQuantities(aNbFaces);
260 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
261 TNodeIds aNodeIds(aNbNodes);
262 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
263 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
264 TInt aNbConn = aConnSlice.size();
265 aQuantities[iFace] = aNbConn;
266 #ifdef _EDF_NODE_IDS_
268 for(TInt iConn = 0; iConn < aNbConn; iConn++)
269 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
271 for(TInt iConn = 0; iConn < aNbConn; iConn++)
272 aNodeIds[iNode++] = aConnSlice[iConn];
274 for(TInt iConn = 0; iConn < aNbConn; iConn++)
275 aNodeIds[iNode++] = aConnSlice[iConn];
279 bool isRenum = false;
280 SMDS_MeshElement* anElement = NULL;
281 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
287 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
288 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
291 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
292 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
293 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
294 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
295 isRenum = anIsElemNum;
298 }catch(const std::exception& exc){
305 aResult = DRS_WARN_SKIP_ELEM;
310 if (aResult < DRS_WARN_RENUMBER)
311 aResult = DRS_WARN_RENUMBER;
313 if ( checkFamilyID ( aFamily, aFamNum )) {
314 // Save reference to this element from its family
315 aFamily->AddElement(anElement);
316 aFamily->SetType(anElement->GetType());
323 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
324 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
325 TInt aNbElems = aCellInfo->GetNbElem();
326 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
327 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
329 for(int iElem = 0; iElem < aNbElems; iElem++){
332 case eSEG2: aNbNodes = 2; break;
333 case eSEG3: aNbNodes = 3; break;
334 case eTRIA3: aNbNodes = 3; break;
335 case eTRIA6: aNbNodes = 6; break;
336 case eQUAD4: aNbNodes = 4; break;
337 case eQUAD8: aNbNodes = 8; break;
338 case eTETRA4: aNbNodes = 4; break;
339 case eTETRA10: aNbNodes = 10; break;
340 case ePYRA5: aNbNodes = 5; break;
341 case ePYRA13: aNbNodes = 13; break;
342 case ePENTA6: aNbNodes = 6; break;
343 case ePENTA15: aNbNodes = 15; break;
344 case eHEXA8: aNbNodes = 8; break;
345 case eHEXA20: aNbNodes = 20; break;
348 vector<TInt> aNodeIds(aNbNodes);
349 bool anIsValidConnect = false;
350 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
354 #ifdef _EDF_NODE_IDS_
356 for(int iNode = 0; iNode < aNbNodes; iNode++)
357 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
359 for(int iNode = 0; iNode < aNbNodes; iNode++)
360 aNodeIds[iNode] = aConnSlice[iNode];
362 for(int iNode = 0; iNode < aNbNodes; iNode++)
363 aNodeIds[iNode] = aConnSlice[iNode];
365 anIsValidConnect = true;
367 }catch(const std::exception& exc){
368 //INFOS("Follow exception was cought:\n\t"<<exc.what());
371 //INFOS("Unknown exception was cought !!!");
375 if(!anIsValidConnect)
378 bool isRenum = false;
379 SMDS_MeshElement* anElement = NULL;
380 TInt aFamNum = aCellInfo->GetFamNum(iElem);
384 //MESSAGE("Try to create element # " << iElem << " with id = "
385 // << aCellInfo->GetElemNum(iElem));
389 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
391 aCellInfo->GetElemNum(iElem));
393 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
394 FindNode(myMesh,aNodeIds[1]));
395 isRenum = anIsElemNum;
400 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
403 aCellInfo->GetElemNum(iElem));
405 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
406 FindNode(myMesh,aNodeIds[1]),
407 FindNode(myMesh,aNodeIds[2]));
408 isRenum = anIsElemNum;
414 anElement = myMesh->AddFaceWithID(aNodeIds[0],
417 aCellInfo->GetElemNum(iElem));
419 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
420 FindNode(myMesh,aNodeIds[1]),
421 FindNode(myMesh,aNodeIds[2]));
422 isRenum = anIsElemNum;
428 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
429 aNodeIds[2], aNodeIds[3],
430 aNodeIds[4], aNodeIds[5],
431 aCellInfo->GetElemNum(iElem));
433 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
434 FindNode(myMesh,aNodeIds[1]),
435 FindNode(myMesh,aNodeIds[2]),
436 FindNode(myMesh,aNodeIds[3]),
437 FindNode(myMesh,aNodeIds[4]),
438 FindNode(myMesh,aNodeIds[5]));
439 isRenum = anIsElemNum;
445 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
446 aNodeIds[2], aNodeIds[3],
447 aCellInfo->GetElemNum(iElem));
449 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
450 FindNode(myMesh,aNodeIds[1]),
451 FindNode(myMesh,aNodeIds[2]),
452 FindNode(myMesh,aNodeIds[3]));
453 isRenum = anIsElemNum;
459 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
460 aNodeIds[2], aNodeIds[3],
461 aNodeIds[4], aNodeIds[5],
462 aNodeIds[6], aNodeIds[7],
463 aCellInfo->GetElemNum(iElem));
465 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
466 FindNode(myMesh,aNodeIds[1]),
467 FindNode(myMesh,aNodeIds[2]),
468 FindNode(myMesh,aNodeIds[3]),
469 FindNode(myMesh,aNodeIds[4]),
470 FindNode(myMesh,aNodeIds[5]),
471 FindNode(myMesh,aNodeIds[6]),
472 FindNode(myMesh,aNodeIds[7]));
473 isRenum = anIsElemNum;
479 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
480 aNodeIds[2], aNodeIds[3],
481 aCellInfo->GetElemNum(iElem));
483 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
484 FindNode(myMesh,aNodeIds[1]),
485 FindNode(myMesh,aNodeIds[2]),
486 FindNode(myMesh,aNodeIds[3]));
487 isRenum = anIsElemNum;
493 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
494 aNodeIds[2], aNodeIds[3],
495 aNodeIds[4], aNodeIds[5],
496 aNodeIds[6], aNodeIds[7],
497 aNodeIds[8], aNodeIds[9],
498 aCellInfo->GetElemNum(iElem));
500 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
501 FindNode(myMesh,aNodeIds[1]),
502 FindNode(myMesh,aNodeIds[2]),
503 FindNode(myMesh,aNodeIds[3]),
504 FindNode(myMesh,aNodeIds[4]),
505 FindNode(myMesh,aNodeIds[5]),
506 FindNode(myMesh,aNodeIds[6]),
507 FindNode(myMesh,aNodeIds[7]),
508 FindNode(myMesh,aNodeIds[8]),
509 FindNode(myMesh,aNodeIds[9]));
510 isRenum = anIsElemNum;
515 // There is some differnce between SMDS and MED
517 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
518 aNodeIds[2], aNodeIds[3],
520 aCellInfo->GetElemNum(iElem));
522 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
523 FindNode(myMesh,aNodeIds[1]),
524 FindNode(myMesh,aNodeIds[2]),
525 FindNode(myMesh,aNodeIds[3]),
526 FindNode(myMesh,aNodeIds[4]));
527 isRenum = anIsElemNum;
532 // There is some differnce between SMDS and MED
534 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
535 aNodeIds[2], aNodeIds[3],
536 aNodeIds[4], aNodeIds[5],
537 aNodeIds[6], aNodeIds[7],
538 aNodeIds[8], aNodeIds[9],
539 aNodeIds[10], aNodeIds[11],
541 aCellInfo->GetElemNum(iElem));
543 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
544 FindNode(myMesh,aNodeIds[1]),
545 FindNode(myMesh,aNodeIds[2]),
546 FindNode(myMesh,aNodeIds[3]),
547 FindNode(myMesh,aNodeIds[4]),
548 FindNode(myMesh,aNodeIds[5]),
549 FindNode(myMesh,aNodeIds[6]),
550 FindNode(myMesh,aNodeIds[7]),
551 FindNode(myMesh,aNodeIds[8]),
552 FindNode(myMesh,aNodeIds[9]),
553 FindNode(myMesh,aNodeIds[10]),
554 FindNode(myMesh,aNodeIds[11]),
555 FindNode(myMesh,aNodeIds[12]));
556 isRenum = anIsElemNum;
562 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
568 aCellInfo->GetElemNum(iElem));
570 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
571 FindNode(myMesh,aNodeIds[1]),
572 FindNode(myMesh,aNodeIds[2]),
573 FindNode(myMesh,aNodeIds[3]),
574 FindNode(myMesh,aNodeIds[4]),
575 FindNode(myMesh,aNodeIds[5]));
576 isRenum = anIsElemNum;
582 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
583 aNodeIds[2], aNodeIds[3],
584 aNodeIds[4], aNodeIds[5],
585 aNodeIds[6], aNodeIds[7],
586 aNodeIds[8], aNodeIds[9],
587 aNodeIds[10], aNodeIds[11],
588 aNodeIds[12], aNodeIds[13],
590 aCellInfo->GetElemNum(iElem));
592 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
593 FindNode(myMesh,aNodeIds[1]),
594 FindNode(myMesh,aNodeIds[2]),
595 FindNode(myMesh,aNodeIds[3]),
596 FindNode(myMesh,aNodeIds[4]),
597 FindNode(myMesh,aNodeIds[5]),
598 FindNode(myMesh,aNodeIds[6]),
599 FindNode(myMesh,aNodeIds[7]),
600 FindNode(myMesh,aNodeIds[8]),
601 FindNode(myMesh,aNodeIds[9]),
602 FindNode(myMesh,aNodeIds[10]),
603 FindNode(myMesh,aNodeIds[11]),
604 FindNode(myMesh,aNodeIds[12]),
605 FindNode(myMesh,aNodeIds[13]),
606 FindNode(myMesh,aNodeIds[14]));
607 isRenum = anIsElemNum;
613 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
621 aCellInfo->GetElemNum(iElem));
623 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
624 FindNode(myMesh,aNodeIds[1]),
625 FindNode(myMesh,aNodeIds[2]),
626 FindNode(myMesh,aNodeIds[3]),
627 FindNode(myMesh,aNodeIds[4]),
628 FindNode(myMesh,aNodeIds[5]),
629 FindNode(myMesh,aNodeIds[6]),
630 FindNode(myMesh,aNodeIds[7]));
631 isRenum = anIsElemNum;
637 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
638 aNodeIds[2], aNodeIds[3],
639 aNodeIds[4], aNodeIds[5],
640 aNodeIds[6], aNodeIds[7],
641 aNodeIds[8], aNodeIds[9],
642 aNodeIds[10], aNodeIds[11],
643 aNodeIds[12], aNodeIds[13],
644 aNodeIds[14], aNodeIds[15],
645 aNodeIds[16], aNodeIds[17],
646 aNodeIds[18], aNodeIds[19],
647 aCellInfo->GetElemNum(iElem));
649 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
650 FindNode(myMesh,aNodeIds[1]),
651 FindNode(myMesh,aNodeIds[2]),
652 FindNode(myMesh,aNodeIds[3]),
653 FindNode(myMesh,aNodeIds[4]),
654 FindNode(myMesh,aNodeIds[5]),
655 FindNode(myMesh,aNodeIds[6]),
656 FindNode(myMesh,aNodeIds[7]),
657 FindNode(myMesh,aNodeIds[8]),
658 FindNode(myMesh,aNodeIds[9]),
659 FindNode(myMesh,aNodeIds[10]),
660 FindNode(myMesh,aNodeIds[11]),
661 FindNode(myMesh,aNodeIds[12]),
662 FindNode(myMesh,aNodeIds[13]),
663 FindNode(myMesh,aNodeIds[14]),
664 FindNode(myMesh,aNodeIds[15]),
665 FindNode(myMesh,aNodeIds[16]),
666 FindNode(myMesh,aNodeIds[17]),
667 FindNode(myMesh,aNodeIds[18]),
668 FindNode(myMesh,aNodeIds[19]));
669 isRenum = anIsElemNum;
674 }catch(const std::exception& exc){
675 //INFOS("Follow exception was cought:\n\t"<<exc.what());
678 //INFOS("Unknown exception was cought !!!");
683 aResult = DRS_WARN_SKIP_ELEM;
689 if (aResult < DRS_WARN_RENUMBER)
690 aResult = DRS_WARN_RENUMBER;
692 if ( checkFamilyID ( aFamily, aFamNum )) {
693 // Save reference to this element from its family
694 myFamilies[aFamNum]->AddElement(anElement);
695 myFamilies[aFamNum]->SetType(anElement->GetType());
705 }catch(const std::exception& exc){
706 INFOS("Follow exception was cought:\n\t"<<exc.what());
709 INFOS("Unknown exception was cought !!!");
713 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
717 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
719 list<string> aMeshNames;
722 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
724 PWrapper aMed = CrWrapper(myFile);
726 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
727 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
728 // Reading the MED mesh
729 //---------------------
730 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
731 aMeshNames.push_back(aMeshInfo->GetName());
734 }catch(const std::exception& exc){
735 INFOS("Follow exception was cought:\n\t"<<exc.what());
736 theStatus = DRS_FAIL;
738 INFOS("Unknown exception was cought !!!");
739 theStatus = DRS_FAIL;
745 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
747 list<TNameAndType> aResult;
748 set<TNameAndType> aResGroupNames;
750 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
751 for (; aFamsIter != myFamilies.end(); aFamsIter++)
753 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
754 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
755 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
756 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
758 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
759 // Check, if this is a Group or SubMesh name
760 //if (aName.substr(0, 5) == string("Group")) {
761 if ( aResGroupNames.insert( aNameAndType ).second ) {
762 aResult.push_back( aNameAndType );
771 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
773 string aGroupName (theGroup->GetStoreName());
774 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
776 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
777 for (; aFamsIter != myFamilies.end(); aFamsIter++)
779 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
780 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
782 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
783 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
784 const SMDS_MeshElement * element = 0;
785 for (; anElemsIter != anElements.end(); anElemsIter++)
787 element = *anElemsIter;
788 theGroup->SMDSGroup().Add(element);
791 theGroup->SetType( element->GetType() );
796 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
799 char submeshGrpName[ 30 ];
800 sprintf( submeshGrpName, "SubMesh %d", theId );
801 string aName (submeshGrpName);
802 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
803 for (; aFamsIter != myFamilies.end(); aFamsIter++)
805 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
806 if (aFamily->MemberOf(aName))
808 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
809 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
810 if (aFamily->GetType() == SMDSAbs_Node)
812 for (; anElemsIter != anElements.end(); anElemsIter++)
814 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
815 theSubMesh->AddNode(node);
820 for (; anElemsIter != anElements.end(); anElemsIter++)
822 theSubMesh->AddElement(*anElemsIter);
829 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
831 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
832 for (; aFamsIter != myFamilies.end(); aFamsIter++)
834 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
835 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
836 set<string>::iterator aGrNamesIter = aGroupNames.begin();
837 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
839 string aName = *aGrNamesIter;
840 // Check, if this is a Group or SubMesh name
841 if (aName.substr(0, 7) == string("SubMesh"))
843 int Id = atoi(string(aName).substr(7).c_str());
844 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
845 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
846 if (aFamily->GetType() == SMDSAbs_Node)
848 for (; anElemsIter != anElements.end(); anElemsIter++)
850 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
851 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
852 // find out a shape type
853 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
854 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
855 switch ( aShapeType ) {
857 myMesh->SetNodeOnFace(node, Id); break;
859 myMesh->SetNodeOnEdge(node, Id); break;
861 myMesh->SetNodeOnVertex(node, Id); break;
863 myMesh->SetNodeInVolume(node, Id);
869 for (; anElemsIter != anElements.end(); anElemsIter++)
871 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
879 * \brief Ensure aFamily to have required ID
880 * \param aFamily - a family to check and update
881 * \param anID - an ID aFamily should have
882 * \retval bool - true if successful
884 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
886 if ( !aFamily || aFamily->GetId() != anID ) {
887 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
888 if ( i_fam == myFamilies.end() )
890 aFamily = i_fam->second;
892 return ( aFamily->GetId() == anID );
896 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
897 * \param theWrapper - PWrapper const pointer
898 * \param theMeshInfo - PMeshInfo const pointer
899 * \return TRUE, if successfully. Else FALSE
901 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
902 const MED::PMeshInfo& theMeshInfo)
906 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
907 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
908 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
909 MED::TInt aMeshDim = theMeshInfo->GetDim();
910 DriverMED_FamilyPtr aFamily;
911 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
912 double aCoords[3] = {0.0, 0.0, 0.0};
913 const SMDS_MeshNode* aNode;
914 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
915 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
916 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
917 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
920 /* not implemented FAMILY
922 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
923 if ( checkFamilyID ( aFamily, aFamNum ))
925 aFamily->AddElement(aNode);
926 aFamily->SetType(SMDSAbs_Node);
931 SMDS_MeshElement* anElement = NULL;
932 MED::TIntVector aNodeIds;
933 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
934 aNodeIds = aGrilleInfo->GetConn(iCell);
935 switch(aGrilleInfo->GetGeom()){
937 if(aNodeIds.size() != 2){
939 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
941 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
946 if(aNodeIds.size() != 4){
948 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
950 anElement = myMesh->AddFaceWithID(aNodeIds[0],
957 if(aNodeIds.size() != 8){
959 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
961 anElement = myMesh->AddVolumeWithID(aNodeIds[0],