1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SMESH DriverMED : driver to read and write 'med' files
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_
55 DriverMED_R_SMESHDS_Mesh
56 ::SetMeshName(string theMeshName)
58 myMeshName = theMeshName;
61 static const SMDS_MeshNode*
62 FindNode(const SMDS_Mesh* theMesh, TInt theId){
63 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
64 if(aNode) return aNode;
65 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
70 DriverMED_R_SMESHDS_Mesh
73 Status aResult = DRS_FAIL;
78 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
79 PWrapper aMed = CrWrapper(myFile,true);
82 if(TInt aNbMeshes = aMed->GetNbMeshes()){
83 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
84 // Reading the MED mesh
85 //---------------------
86 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
90 ostringstream aMeshNameStr;
91 aMeshNameStr<<myMeshId;
92 aMeshName = aMeshNameStr.str();
94 aMeshName = myMeshName;
96 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
97 if(aMeshName != aMeshInfo->GetName()) continue;
100 //TInt aMeshDim = aMeshInfo->GetDim();
102 // Reading MED families to the temporary structure
103 //------------------------------------------------
105 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
106 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
107 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
108 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
110 TInt aFamId = aFamilyInfo->GetId();
111 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
113 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
115 TInt aNbGrp = aFamilyInfo->GetNbGroup();
116 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
117 bool isAttrOk = false;
118 if(aFamilyInfo->GetNbAttr() == aNbGrp)
120 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
121 string aGroupName = aFamilyInfo->GetGroupName(iGr);
123 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
124 aFamily->SetGroupAttributVal(anAttrVal);
127 if(MYDEBUG) MESSAGE(aGroupName);
128 aFamily->AddGroupName(aGroupName);
131 aFamily->SetId( aFamId );
132 myFamilies[aFamId] = aFamily;
136 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
137 /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
141 // Reading MED nodes to the corresponding SMDS structure
142 //------------------------------------------------------
143 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
149 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
151 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
152 TInt aNbElems = aNodeInfo->GetNbElem();
153 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
154 DriverMED_FamilyPtr aFamily;
155 for(TInt iElem = 0; iElem < aNbElems; iElem++){
156 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
157 double aCoords[3] = {0.0, 0.0, 0.0};
158 for(TInt iDim = 0; iDim < 3; iDim++)
159 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
160 const SMDS_MeshNode* aNode;
162 aNode = myMesh->AddNodeWithID
163 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
165 aNode = myMesh->AddNode
166 (aCoords[0],aCoords[1],aCoords[2]);
168 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
170 // Save reference to this node from its family
171 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
172 if ( checkFamilyID ( aFamily, aFamNum ))
174 aFamily->AddElement(aNode);
175 aFamily->SetType(SMDSAbs_Node);
179 // Reading pre information about all MED cells
180 //--------------------------------------------
181 typedef MED::TVector<int> TNodeIds;
182 bool takeNumbers = true; // initially we trust the numbers from file
183 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
184 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
185 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
186 const EEntiteMaillage& anEntity = anEntityIter->first;
187 if(anEntity == eNOEUD) continue;
188 // Reading MED cells to the corresponding SMDS structure
189 //------------------------------------------------------
190 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
191 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
192 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
193 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
196 // case ePOINT1: ## PAL16410
199 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
200 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
202 TInt aNbElem = aPolygoneInfo->GetNbElem();
203 for(TInt iElem = 0; iElem < aNbElem; iElem++){
204 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
205 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
206 TNodeIds aNodeIds(aNbConn);
207 #ifdef _EDF_NODE_IDS_
209 for(TInt iConn = 0; iConn < aNbConn; iConn++)
210 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
212 for(TInt iConn = 0; iConn < aNbConn; iConn++)
213 aNodeIds[iConn] = aConnSlice[iConn];
215 for(TInt iConn = 0; iConn < aNbConn; iConn++)
216 aNodeIds[iConn] = aConnSlice[iConn];
218 bool isRenum = false;
219 SMDS_MeshElement* anElement = NULL;
220 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
226 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
227 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
230 vector<const SMDS_MeshNode*> aNodes(aNbConn);
231 for(TInt iConn = 0; iConn < aNbConn; iConn++)
232 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
233 anElement = myMesh->AddPolygonalFace(aNodes);
234 isRenum = anIsElemNum;
237 }catch(const std::exception& exc){
244 aResult = DRS_WARN_SKIP_ELEM;
249 if(aResult < DRS_WARN_RENUMBER)
250 aResult = DRS_WARN_RENUMBER;
252 if ( checkFamilyID ( aFamily, aFamNum ))
254 // Save reference to this element from its family
255 aFamily->AddElement(anElement);
256 aFamily->SetType(anElement->GetType());
263 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
264 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
266 TInt aNbElem = aPolyedreInfo->GetNbElem();
267 for(TInt iElem = 0; iElem < aNbElem; iElem++){
268 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
269 TInt aNbFaces = aConnSliceArr.size();
270 typedef MED::TVector<int> TQuantities;
271 TQuantities aQuantities(aNbFaces);
272 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
273 TNodeIds aNodeIds(aNbNodes);
274 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
275 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
276 TInt aNbConn = aConnSlice.size();
277 aQuantities[iFace] = aNbConn;
278 #ifdef _EDF_NODE_IDS_
280 for(TInt iConn = 0; iConn < aNbConn; iConn++)
281 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
283 for(TInt iConn = 0; iConn < aNbConn; iConn++)
284 aNodeIds[iNode++] = aConnSlice[iConn];
286 for(TInt iConn = 0; iConn < aNbConn; iConn++)
287 aNodeIds[iNode++] = aConnSlice[iConn];
291 bool isRenum = false;
292 SMDS_MeshElement* anElement = NULL;
293 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
299 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
300 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
303 vector<const SMDS_MeshNode*> aNodes(aNbNodes);
304 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
305 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
306 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
307 isRenum = anIsElemNum;
310 }catch(const std::exception& exc){
317 aResult = DRS_WARN_SKIP_ELEM;
322 if (aResult < DRS_WARN_RENUMBER)
323 aResult = DRS_WARN_RENUMBER;
325 if ( checkFamilyID ( aFamily, aFamNum )) {
326 // Save reference to this element from its family
327 aFamily->AddElement(anElement);
328 aFamily->SetType(anElement->GetType());
335 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
336 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
337 TInt aNbElems = aCellInfo->GetNbElem();
338 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
339 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
343 case eSEG2: aNbNodes = 2; break;
344 case eSEG3: aNbNodes = 3; break;
345 case eTRIA3: aNbNodes = 3; break;
346 case eTRIA6: aNbNodes = 6; break;
347 case eQUAD4: aNbNodes = 4; break;
348 case eQUAD8: aNbNodes = 8; break;
349 case eTETRA4: aNbNodes = 4; break;
350 case eTETRA10: aNbNodes = 10; break;
351 case ePYRA5: aNbNodes = 5; break;
352 case ePYRA13: aNbNodes = 13; break;
353 case ePENTA6: aNbNodes = 6; break;
354 case ePENTA15: aNbNodes = 15; break;
355 case eHEXA8: aNbNodes = 8; break;
356 case eHEXA20: aNbNodes = 20; break;
357 case ePOINT1: aNbNodes = 1; break;
360 vector<TInt> aNodeIds(aNbNodes);
361 for(int iElem = 0; iElem < aNbElems; iElem++){
362 bool anIsValidConnect = false;
363 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
367 #ifdef _EDF_NODE_IDS_
369 for(int iNode = 0; iNode < aNbNodes; iNode++)
370 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
372 for(int iNode = 0; iNode < aNbNodes; iNode++)
373 aNodeIds[iNode] = aConnSlice[iNode];
375 for(int iNode = 0; iNode < aNbNodes; iNode++)
376 aNodeIds[iNode] = aConnSlice[iNode];
378 anIsValidConnect = true;
380 }catch(const std::exception& exc){
381 //INFOS("Follow exception was cought:\n\t"<<exc.what());
384 //INFOS("Unknown exception was cought !!!");
388 if(!anIsValidConnect)
391 bool isRenum = false;
392 const SMDS_MeshElement* anElement = NULL;
393 TInt aFamNum = aCellInfo->GetFamNum(iElem);
397 //MESSAGE("Try to create element # " << iElem << " with id = "
398 // << aCellInfo->GetElemNum(iElem));
401 //anElement = FindNode(myMesh,aNodeIds[0]);
403 anElement = myMesh->Add0DElementWithID
404 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
406 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
407 isRenum = anIsElemNum;
412 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
414 aCellInfo->GetElemNum(iElem));
416 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
417 FindNode(myMesh,aNodeIds[1]));
418 isRenum = anIsElemNum;
423 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
426 aCellInfo->GetElemNum(iElem));
428 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
429 FindNode(myMesh,aNodeIds[1]),
430 FindNode(myMesh,aNodeIds[2]));
431 isRenum = anIsElemNum;
437 anElement = myMesh->AddFaceWithID(aNodeIds[0],
440 aCellInfo->GetElemNum(iElem));
442 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
443 FindNode(myMesh,aNodeIds[1]),
444 FindNode(myMesh,aNodeIds[2]));
445 isRenum = anIsElemNum;
451 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
452 aNodeIds[2], aNodeIds[3],
453 aNodeIds[4], aNodeIds[5],
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 isRenum = anIsElemNum;
468 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
469 aNodeIds[2], aNodeIds[3],
470 aCellInfo->GetElemNum(iElem));
472 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
473 FindNode(myMesh,aNodeIds[1]),
474 FindNode(myMesh,aNodeIds[2]),
475 FindNode(myMesh,aNodeIds[3]));
476 isRenum = anIsElemNum;
482 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
483 aNodeIds[2], aNodeIds[3],
484 aNodeIds[4], aNodeIds[5],
485 aNodeIds[6], aNodeIds[7],
486 aCellInfo->GetElemNum(iElem));
488 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
489 FindNode(myMesh,aNodeIds[1]),
490 FindNode(myMesh,aNodeIds[2]),
491 FindNode(myMesh,aNodeIds[3]),
492 FindNode(myMesh,aNodeIds[4]),
493 FindNode(myMesh,aNodeIds[5]),
494 FindNode(myMesh,aNodeIds[6]),
495 FindNode(myMesh,aNodeIds[7]));
496 isRenum = anIsElemNum;
502 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
503 aNodeIds[2], aNodeIds[3],
504 aCellInfo->GetElemNum(iElem));
506 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
507 FindNode(myMesh,aNodeIds[1]),
508 FindNode(myMesh,aNodeIds[2]),
509 FindNode(myMesh,aNodeIds[3]));
510 isRenum = anIsElemNum;
516 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
517 aNodeIds[2], aNodeIds[3],
518 aNodeIds[4], aNodeIds[5],
519 aNodeIds[6], aNodeIds[7],
520 aNodeIds[8], aNodeIds[9],
521 aCellInfo->GetElemNum(iElem));
523 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
524 FindNode(myMesh,aNodeIds[1]),
525 FindNode(myMesh,aNodeIds[2]),
526 FindNode(myMesh,aNodeIds[3]),
527 FindNode(myMesh,aNodeIds[4]),
528 FindNode(myMesh,aNodeIds[5]),
529 FindNode(myMesh,aNodeIds[6]),
530 FindNode(myMesh,aNodeIds[7]),
531 FindNode(myMesh,aNodeIds[8]),
532 FindNode(myMesh,aNodeIds[9]));
533 isRenum = anIsElemNum;
538 // There is some differnce between SMDS and MED
540 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
541 aNodeIds[2], aNodeIds[3],
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 isRenum = anIsElemNum;
555 // There is some differnce between SMDS and MED
557 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
558 aNodeIds[2], aNodeIds[3],
559 aNodeIds[4], aNodeIds[5],
560 aNodeIds[6], aNodeIds[7],
561 aNodeIds[8], aNodeIds[9],
562 aNodeIds[10], aNodeIds[11],
564 aCellInfo->GetElemNum(iElem));
566 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
567 FindNode(myMesh,aNodeIds[1]),
568 FindNode(myMesh,aNodeIds[2]),
569 FindNode(myMesh,aNodeIds[3]),
570 FindNode(myMesh,aNodeIds[4]),
571 FindNode(myMesh,aNodeIds[5]),
572 FindNode(myMesh,aNodeIds[6]),
573 FindNode(myMesh,aNodeIds[7]),
574 FindNode(myMesh,aNodeIds[8]),
575 FindNode(myMesh,aNodeIds[9]),
576 FindNode(myMesh,aNodeIds[10]),
577 FindNode(myMesh,aNodeIds[11]),
578 FindNode(myMesh,aNodeIds[12]));
579 isRenum = anIsElemNum;
585 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
591 aCellInfo->GetElemNum(iElem));
593 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
594 FindNode(myMesh,aNodeIds[1]),
595 FindNode(myMesh,aNodeIds[2]),
596 FindNode(myMesh,aNodeIds[3]),
597 FindNode(myMesh,aNodeIds[4]),
598 FindNode(myMesh,aNodeIds[5]));
599 isRenum = anIsElemNum;
605 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
606 aNodeIds[2], aNodeIds[3],
607 aNodeIds[4], aNodeIds[5],
608 aNodeIds[6], aNodeIds[7],
609 aNodeIds[8], aNodeIds[9],
610 aNodeIds[10], aNodeIds[11],
611 aNodeIds[12], aNodeIds[13],
613 aCellInfo->GetElemNum(iElem));
615 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
616 FindNode(myMesh,aNodeIds[1]),
617 FindNode(myMesh,aNodeIds[2]),
618 FindNode(myMesh,aNodeIds[3]),
619 FindNode(myMesh,aNodeIds[4]),
620 FindNode(myMesh,aNodeIds[5]),
621 FindNode(myMesh,aNodeIds[6]),
622 FindNode(myMesh,aNodeIds[7]),
623 FindNode(myMesh,aNodeIds[8]),
624 FindNode(myMesh,aNodeIds[9]),
625 FindNode(myMesh,aNodeIds[10]),
626 FindNode(myMesh,aNodeIds[11]),
627 FindNode(myMesh,aNodeIds[12]),
628 FindNode(myMesh,aNodeIds[13]),
629 FindNode(myMesh,aNodeIds[14]));
630 isRenum = anIsElemNum;
636 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
644 aCellInfo->GetElemNum(iElem));
646 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
647 FindNode(myMesh,aNodeIds[1]),
648 FindNode(myMesh,aNodeIds[2]),
649 FindNode(myMesh,aNodeIds[3]),
650 FindNode(myMesh,aNodeIds[4]),
651 FindNode(myMesh,aNodeIds[5]),
652 FindNode(myMesh,aNodeIds[6]),
653 FindNode(myMesh,aNodeIds[7]));
654 isRenum = anIsElemNum;
660 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
661 aNodeIds[2], aNodeIds[3],
662 aNodeIds[4], aNodeIds[5],
663 aNodeIds[6], aNodeIds[7],
664 aNodeIds[8], aNodeIds[9],
665 aNodeIds[10], aNodeIds[11],
666 aNodeIds[12], aNodeIds[13],
667 aNodeIds[14], aNodeIds[15],
668 aNodeIds[16], aNodeIds[17],
669 aNodeIds[18], aNodeIds[19],
670 aCellInfo->GetElemNum(iElem));
672 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
673 FindNode(myMesh,aNodeIds[1]),
674 FindNode(myMesh,aNodeIds[2]),
675 FindNode(myMesh,aNodeIds[3]),
676 FindNode(myMesh,aNodeIds[4]),
677 FindNode(myMesh,aNodeIds[5]),
678 FindNode(myMesh,aNodeIds[6]),
679 FindNode(myMesh,aNodeIds[7]),
680 FindNode(myMesh,aNodeIds[8]),
681 FindNode(myMesh,aNodeIds[9]),
682 FindNode(myMesh,aNodeIds[10]),
683 FindNode(myMesh,aNodeIds[11]),
684 FindNode(myMesh,aNodeIds[12]),
685 FindNode(myMesh,aNodeIds[13]),
686 FindNode(myMesh,aNodeIds[14]),
687 FindNode(myMesh,aNodeIds[15]),
688 FindNode(myMesh,aNodeIds[16]),
689 FindNode(myMesh,aNodeIds[17]),
690 FindNode(myMesh,aNodeIds[18]),
691 FindNode(myMesh,aNodeIds[19]));
692 isRenum = anIsElemNum;
698 }catch(const std::exception& exc){
699 //INFOS("Follow exception was cought:\n\t"<<exc.what());
702 //INFOS("Unknown exception was cought !!!");
707 aResult = DRS_WARN_SKIP_ELEM;
713 if (aResult < DRS_WARN_RENUMBER)
714 aResult = DRS_WARN_RENUMBER;
716 if ( checkFamilyID ( aFamily, aFamNum )) {
717 // Save reference to this element from its family
718 myFamilies[aFamNum]->AddElement(anElement);
719 myFamilies[aFamNum]->SetType(anElement->GetType());
729 }catch(const std::exception& exc){
730 INFOS("Follow exception was cought:\n\t"<<exc.what());
733 INFOS("Unknown exception was cought !!!");
737 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
741 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
743 list<string> aMeshNames;
746 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
748 PWrapper aMed = CrWrapper(myFile);
750 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
751 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
752 // Reading the MED mesh
753 //---------------------
754 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
755 aMeshNames.push_back(aMeshInfo->GetName());
758 }catch(const std::exception& exc){
759 INFOS("Follow exception was cought:\n\t"<<exc.what());
760 theStatus = DRS_FAIL;
762 INFOS("Unknown exception was cought !!!");
763 theStatus = DRS_FAIL;
769 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
771 list<TNameAndType> aResult;
772 set<TNameAndType> aResGroupNames;
774 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
775 for (; aFamsIter != myFamilies.end(); aFamsIter++)
777 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
778 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
779 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
780 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
782 const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
783 set< SMDSAbs_ElementType >::const_iterator type = types.begin();
784 for ( ; type != types.end(); ++type )
786 TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
787 if ( aResGroupNames.insert( aNameAndType ).second ) {
788 aResult.push_back( aNameAndType );
797 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
799 string aGroupName (theGroup->GetStoreName());
800 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
802 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
803 for (; aFamsIter != myFamilies.end(); aFamsIter++)
805 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
806 if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
808 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
809 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
810 for (; anElemsIter != anElements.end(); anElemsIter++)
812 const SMDS_MeshElement * element = *anElemsIter;
813 if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
814 theGroup->SMDSGroup().Add(element);
816 int aGroupAttrVal = aFamily->GetGroupAttributVal();
817 if( aGroupAttrVal != 0)
818 theGroup->SetColorGroup(aGroupAttrVal);
819 // if ( element ) -- Issue 0020576
820 // theGroup->SetType( theGroup->SMDSGroup().GetType() );
825 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
828 char submeshGrpName[ 30 ];
829 sprintf( submeshGrpName, "SubMesh %d", theId );
830 string aName (submeshGrpName);
831 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
832 for (; aFamsIter != myFamilies.end(); aFamsIter++)
834 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
835 if (aFamily->MemberOf(aName))
837 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
838 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
839 if (aFamily->GetType() == SMDSAbs_Node)
841 for (; anElemsIter != anElements.end(); anElemsIter++)
843 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
844 theSubMesh->AddNode(node);
849 for (; anElemsIter != anElements.end(); anElemsIter++)
851 theSubMesh->AddElement(*anElemsIter);
858 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
860 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
861 for (; aFamsIter != myFamilies.end(); aFamsIter++)
863 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
864 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
865 set<string>::iterator aGrNamesIter = aGroupNames.begin();
866 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
868 string aName = *aGrNamesIter;
869 // Check, if this is a Group or SubMesh name
870 if (aName.substr(0, 7) == string("SubMesh"))
872 int Id = atoi(string(aName).substr(7).c_str());
873 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
874 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
875 if (aFamily->GetType() == SMDSAbs_Node)
877 for (; anElemsIter != anElements.end(); anElemsIter++)
879 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
880 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
881 // find out a shape type
882 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
883 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
884 switch ( aShapeType ) {
886 myMesh->SetNodeOnFace(node, Id); break;
888 myMesh->SetNodeOnEdge(node, Id); break;
890 myMesh->SetNodeOnVertex(node, Id); break;
892 myMesh->SetNodeInVolume(node, Id);
898 for (; anElemsIter != anElements.end(); anElemsIter++)
900 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
908 * \brief Ensure aFamily to have required ID
909 * \param aFamily - a family to check and update
910 * \param anID - an ID aFamily should have
911 * \retval bool - true if successful
913 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
915 if ( !aFamily || aFamily->GetId() != anID ) {
916 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
917 if ( i_fam == myFamilies.end() )
919 aFamily = i_fam->second;
921 return ( aFamily->GetId() == anID );
925 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
926 * \param theWrapper - PWrapper const pointer
927 * \param theMeshInfo - PMeshInfo const pointer
928 * \return TRUE, if successfully. Else FALSE
930 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
931 const MED::PMeshInfo& theMeshInfo)
935 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
936 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
937 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
938 MED::TInt aMeshDim = theMeshInfo->GetDim();
939 DriverMED_FamilyPtr aFamily;
940 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
941 double aCoords[3] = {0.0, 0.0, 0.0};
942 const SMDS_MeshNode* aNode;
943 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
944 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
945 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
946 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
948 if((aGrilleInfo->myFamNumNode).size() > 0){
949 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
950 if ( checkFamilyID ( aFamily, aFamNum ))
952 aFamily->AddElement(aNode);
953 aFamily->SetType(SMDSAbs_Node);
959 SMDS_MeshElement* anElement = NULL;
960 MED::TIntVector aNodeIds;
961 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
962 aNodeIds = aGrilleInfo->GetConn(iCell);
963 switch(aGrilleInfo->GetGeom()){
965 if(aNodeIds.size() != 2){
967 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
969 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
974 if(aNodeIds.size() != 4){
976 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
978 anElement = myMesh->AddFaceWithID(aNodeIds[0],
985 if(aNodeIds.size() != 8){
987 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
989 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
1003 if((aGrilleInfo->myFamNum).size() > 0){
1004 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1005 if ( checkFamilyID ( aFamily, aFamNum )){
1006 aFamily->AddElement(anElement);
1007 aFamily->SetType(anElement->GetType());