1 // Copyright (C) 2007-2008 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
22 // SMESH DriverMED : driver to read and write 'med' files
23 // File : DriverMED_R_SMESHDS_Mesh.cxx
26 #include "DriverMED_R_SMESHDS_Mesh.h"
27 #include "DriverMED_R_SMDS_Mesh.h"
28 #include "SMESHDS_Mesh.hxx"
29 #include "utilities.h"
31 #include "DriverMED_Family.h"
33 #include "SMESHDS_Group.hxx"
35 #include "MED_Factory.hxx"
36 #include "MED_CoordUtils.hxx"
37 #include "MED_Utilities.hxx"
42 static int MYDEBUG = 0;
45 static int MYDEBUG = 0;
48 #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 bool isAttrOk = false;
117 if(aFamilyInfo->GetNbAttr() == aNbGrp)
119 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
120 string aGroupName = aFamilyInfo->GetGroupName(iGr);
122 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
123 aFamily->SetGroupAttributVal(anAttrVal);
126 if(MYDEBUG) MESSAGE(aGroupName);
127 aFamily->AddGroupName(aGroupName);
130 aFamily->SetId( aFamId );
131 myFamilies[aFamId] = aFamily;
135 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
136 /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
140 // Reading MED nodes to the corresponding SMDS structure
141 //------------------------------------------------------
142 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
148 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
150 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
151 TInt aNbElems = aNodeInfo->GetNbElem();
152 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
153 DriverMED_FamilyPtr aFamily;
154 for(TInt iElem = 0; iElem < aNbElems; iElem++){
155 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
156 double aCoords[3] = {0.0, 0.0, 0.0};
157 for(TInt iDim = 0; iDim < 3; iDim++)
158 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
159 const SMDS_MeshNode* aNode;
161 aNode = myMesh->AddNodeWithID
162 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
164 aNode = myMesh->AddNode
165 (aCoords[0],aCoords[1],aCoords[2]);
167 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
169 // Save reference to this node from its family
170 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
171 if ( checkFamilyID ( aFamily, aFamNum ))
173 aFamily->AddElement(aNode);
174 aFamily->SetType(SMDSAbs_Node);
178 // Reading pre information about all MED cells
179 //--------------------------------------------
180 typedef MED::TVector<int> TNodeIds;
181 bool takeNumbers = true; // initially we trust the numbers from file
182 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
183 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
184 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
185 const EEntiteMaillage& anEntity = anEntityIter->first;
186 if(anEntity == eNOEUD) continue;
187 // Reading MED cells to the corresponding SMDS structure
188 //------------------------------------------------------
189 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
190 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
191 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
192 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
195 // case ePOINT1: ## PAL16410
198 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
199 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
201 TInt aNbElem = aPolygoneInfo->GetNbElem();
202 for(TInt iElem = 0; iElem < aNbElem; iElem++){
203 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
204 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
205 TNodeIds aNodeIds(aNbConn);
206 #ifdef _EDF_NODE_IDS_
208 for(TInt iConn = 0; iConn < aNbConn; iConn++)
209 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
211 for(TInt iConn = 0; iConn < aNbConn; iConn++)
212 aNodeIds[iConn] = aConnSlice[iConn];
214 for(TInt iConn = 0; iConn < aNbConn; iConn++)
215 aNodeIds[iConn] = aConnSlice[iConn];
217 bool isRenum = false;
218 SMDS_MeshElement* anElement = NULL;
219 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
225 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
226 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
229 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
230 for(TInt iConn = 0; iConn < aNbConn; iConn++)
231 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
232 anElement = myMesh->AddPolygonalFace(aNodes);
233 isRenum = anIsElemNum;
236 }catch(const std::exception& exc){
243 aResult = DRS_WARN_SKIP_ELEM;
248 if(aResult < DRS_WARN_RENUMBER)
249 aResult = DRS_WARN_RENUMBER;
251 if ( checkFamilyID ( aFamily, aFamNum ))
253 // Save reference to this element from its family
254 aFamily->AddElement(anElement);
255 aFamily->SetType(anElement->GetType());
262 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
263 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
265 TInt aNbElem = aPolyedreInfo->GetNbElem();
266 for(TInt iElem = 0; iElem < aNbElem; iElem++){
267 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
268 TInt aNbFaces = aConnSliceArr.size();
269 typedef MED::TVector<int> TQuantities;
270 TQuantities aQuantities(aNbFaces);
271 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
272 TNodeIds aNodeIds(aNbNodes);
273 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
274 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
275 TInt aNbConn = aConnSlice.size();
276 aQuantities[iFace] = aNbConn;
277 #ifdef _EDF_NODE_IDS_
279 for(TInt iConn = 0; iConn < aNbConn; iConn++)
280 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
282 for(TInt iConn = 0; iConn < aNbConn; iConn++)
283 aNodeIds[iNode++] = aConnSlice[iConn];
285 for(TInt iConn = 0; iConn < aNbConn; iConn++)
286 aNodeIds[iNode++] = aConnSlice[iConn];
290 bool isRenum = false;
291 SMDS_MeshElement* anElement = NULL;
292 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
298 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
299 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
302 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
303 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
304 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
305 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
306 isRenum = anIsElemNum;
309 }catch(const std::exception& exc){
316 aResult = DRS_WARN_SKIP_ELEM;
321 if (aResult < DRS_WARN_RENUMBER)
322 aResult = DRS_WARN_RENUMBER;
324 if ( checkFamilyID ( aFamily, aFamNum )) {
325 // Save reference to this element from its family
326 aFamily->AddElement(anElement);
327 aFamily->SetType(anElement->GetType());
334 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
335 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
336 TInt aNbElems = aCellInfo->GetNbElem();
337 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
338 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
340 for(int iElem = 0; iElem < aNbElems; iElem++){
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 bool anIsValidConnect = false;
362 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
366 #ifdef _EDF_NODE_IDS_
368 for(int iNode = 0; iNode < aNbNodes; iNode++)
369 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
371 for(int iNode = 0; iNode < aNbNodes; iNode++)
372 aNodeIds[iNode] = aConnSlice[iNode];
374 for(int iNode = 0; iNode < aNbNodes; iNode++)
375 aNodeIds[iNode] = aConnSlice[iNode];
377 anIsValidConnect = true;
379 }catch(const std::exception& exc){
380 //INFOS("Follow exception was cought:\n\t"<<exc.what());
383 //INFOS("Unknown exception was cought !!!");
387 if(!anIsValidConnect)
390 bool isRenum = false;
391 const SMDS_MeshElement* anElement = NULL;
392 TInt aFamNum = aCellInfo->GetFamNum(iElem);
396 //MESSAGE("Try to create element # " << iElem << " with id = "
397 // << aCellInfo->GetElemNum(iElem));
401 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
403 aCellInfo->GetElemNum(iElem));
405 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
406 FindNode(myMesh,aNodeIds[1]));
407 isRenum = anIsElemNum;
412 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
415 aCellInfo->GetElemNum(iElem));
417 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
418 FindNode(myMesh,aNodeIds[1]),
419 FindNode(myMesh,aNodeIds[2]));
420 isRenum = anIsElemNum;
426 anElement = myMesh->AddFaceWithID(aNodeIds[0],
429 aCellInfo->GetElemNum(iElem));
431 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
432 FindNode(myMesh,aNodeIds[1]),
433 FindNode(myMesh,aNodeIds[2]));
434 isRenum = anIsElemNum;
440 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
441 aNodeIds[2], aNodeIds[3],
442 aNodeIds[4], aNodeIds[5],
443 aCellInfo->GetElemNum(iElem));
445 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
446 FindNode(myMesh,aNodeIds[1]),
447 FindNode(myMesh,aNodeIds[2]),
448 FindNode(myMesh,aNodeIds[3]),
449 FindNode(myMesh,aNodeIds[4]),
450 FindNode(myMesh,aNodeIds[5]));
451 isRenum = anIsElemNum;
457 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
458 aNodeIds[2], aNodeIds[3],
459 aCellInfo->GetElemNum(iElem));
461 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
462 FindNode(myMesh,aNodeIds[1]),
463 FindNode(myMesh,aNodeIds[2]),
464 FindNode(myMesh,aNodeIds[3]));
465 isRenum = anIsElemNum;
471 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
472 aNodeIds[2], aNodeIds[3],
473 aNodeIds[4], aNodeIds[5],
474 aNodeIds[6], aNodeIds[7],
475 aCellInfo->GetElemNum(iElem));
477 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
478 FindNode(myMesh,aNodeIds[1]),
479 FindNode(myMesh,aNodeIds[2]),
480 FindNode(myMesh,aNodeIds[3]),
481 FindNode(myMesh,aNodeIds[4]),
482 FindNode(myMesh,aNodeIds[5]),
483 FindNode(myMesh,aNodeIds[6]),
484 FindNode(myMesh,aNodeIds[7]));
485 isRenum = anIsElemNum;
491 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
492 aNodeIds[2], aNodeIds[3],
493 aCellInfo->GetElemNum(iElem));
495 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
496 FindNode(myMesh,aNodeIds[1]),
497 FindNode(myMesh,aNodeIds[2]),
498 FindNode(myMesh,aNodeIds[3]));
499 isRenum = anIsElemNum;
505 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
506 aNodeIds[2], aNodeIds[3],
507 aNodeIds[4], aNodeIds[5],
508 aNodeIds[6], aNodeIds[7],
509 aNodeIds[8], aNodeIds[9],
510 aCellInfo->GetElemNum(iElem));
512 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
513 FindNode(myMesh,aNodeIds[1]),
514 FindNode(myMesh,aNodeIds[2]),
515 FindNode(myMesh,aNodeIds[3]),
516 FindNode(myMesh,aNodeIds[4]),
517 FindNode(myMesh,aNodeIds[5]),
518 FindNode(myMesh,aNodeIds[6]),
519 FindNode(myMesh,aNodeIds[7]),
520 FindNode(myMesh,aNodeIds[8]),
521 FindNode(myMesh,aNodeIds[9]));
522 isRenum = anIsElemNum;
527 // There is some differnce between SMDS and MED
529 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
530 aNodeIds[2], aNodeIds[3],
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 isRenum = anIsElemNum;
544 // There is some differnce between SMDS and MED
546 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
547 aNodeIds[2], aNodeIds[3],
548 aNodeIds[4], aNodeIds[5],
549 aNodeIds[6], aNodeIds[7],
550 aNodeIds[8], aNodeIds[9],
551 aNodeIds[10], aNodeIds[11],
553 aCellInfo->GetElemNum(iElem));
555 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
556 FindNode(myMesh,aNodeIds[1]),
557 FindNode(myMesh,aNodeIds[2]),
558 FindNode(myMesh,aNodeIds[3]),
559 FindNode(myMesh,aNodeIds[4]),
560 FindNode(myMesh,aNodeIds[5]),
561 FindNode(myMesh,aNodeIds[6]),
562 FindNode(myMesh,aNodeIds[7]),
563 FindNode(myMesh,aNodeIds[8]),
564 FindNode(myMesh,aNodeIds[9]),
565 FindNode(myMesh,aNodeIds[10]),
566 FindNode(myMesh,aNodeIds[11]),
567 FindNode(myMesh,aNodeIds[12]));
568 isRenum = anIsElemNum;
574 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
580 aCellInfo->GetElemNum(iElem));
582 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
583 FindNode(myMesh,aNodeIds[1]),
584 FindNode(myMesh,aNodeIds[2]),
585 FindNode(myMesh,aNodeIds[3]),
586 FindNode(myMesh,aNodeIds[4]),
587 FindNode(myMesh,aNodeIds[5]));
588 isRenum = anIsElemNum;
594 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
595 aNodeIds[2], aNodeIds[3],
596 aNodeIds[4], aNodeIds[5],
597 aNodeIds[6], aNodeIds[7],
598 aNodeIds[8], aNodeIds[9],
599 aNodeIds[10], aNodeIds[11],
600 aNodeIds[12], aNodeIds[13],
602 aCellInfo->GetElemNum(iElem));
604 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
605 FindNode(myMesh,aNodeIds[1]),
606 FindNode(myMesh,aNodeIds[2]),
607 FindNode(myMesh,aNodeIds[3]),
608 FindNode(myMesh,aNodeIds[4]),
609 FindNode(myMesh,aNodeIds[5]),
610 FindNode(myMesh,aNodeIds[6]),
611 FindNode(myMesh,aNodeIds[7]),
612 FindNode(myMesh,aNodeIds[8]),
613 FindNode(myMesh,aNodeIds[9]),
614 FindNode(myMesh,aNodeIds[10]),
615 FindNode(myMesh,aNodeIds[11]),
616 FindNode(myMesh,aNodeIds[12]),
617 FindNode(myMesh,aNodeIds[13]),
618 FindNode(myMesh,aNodeIds[14]));
619 isRenum = anIsElemNum;
625 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
633 aCellInfo->GetElemNum(iElem));
635 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
636 FindNode(myMesh,aNodeIds[1]),
637 FindNode(myMesh,aNodeIds[2]),
638 FindNode(myMesh,aNodeIds[3]),
639 FindNode(myMesh,aNodeIds[4]),
640 FindNode(myMesh,aNodeIds[5]),
641 FindNode(myMesh,aNodeIds[6]),
642 FindNode(myMesh,aNodeIds[7]));
643 isRenum = anIsElemNum;
649 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
650 aNodeIds[2], aNodeIds[3],
651 aNodeIds[4], aNodeIds[5],
652 aNodeIds[6], aNodeIds[7],
653 aNodeIds[8], aNodeIds[9],
654 aNodeIds[10], aNodeIds[11],
655 aNodeIds[12], aNodeIds[13],
656 aNodeIds[14], aNodeIds[15],
657 aNodeIds[16], aNodeIds[17],
658 aNodeIds[18], aNodeIds[19],
659 aCellInfo->GetElemNum(iElem));
661 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
662 FindNode(myMesh,aNodeIds[1]),
663 FindNode(myMesh,aNodeIds[2]),
664 FindNode(myMesh,aNodeIds[3]),
665 FindNode(myMesh,aNodeIds[4]),
666 FindNode(myMesh,aNodeIds[5]),
667 FindNode(myMesh,aNodeIds[6]),
668 FindNode(myMesh,aNodeIds[7]),
669 FindNode(myMesh,aNodeIds[8]),
670 FindNode(myMesh,aNodeIds[9]),
671 FindNode(myMesh,aNodeIds[10]),
672 FindNode(myMesh,aNodeIds[11]),
673 FindNode(myMesh,aNodeIds[12]),
674 FindNode(myMesh,aNodeIds[13]),
675 FindNode(myMesh,aNodeIds[14]),
676 FindNode(myMesh,aNodeIds[15]),
677 FindNode(myMesh,aNodeIds[16]),
678 FindNode(myMesh,aNodeIds[17]),
679 FindNode(myMesh,aNodeIds[18]),
680 FindNode(myMesh,aNodeIds[19]));
681 isRenum = anIsElemNum;
686 anElement = FindNode(myMesh,aNodeIds[0]);
690 }catch(const std::exception& exc){
691 //INFOS("Follow exception was cought:\n\t"<<exc.what());
694 //INFOS("Unknown exception was cought !!!");
699 aResult = DRS_WARN_SKIP_ELEM;
705 if (aResult < DRS_WARN_RENUMBER)
706 aResult = DRS_WARN_RENUMBER;
708 if ( checkFamilyID ( aFamily, aFamNum )) {
709 // Save reference to this element from its family
710 myFamilies[aFamNum]->AddElement(anElement);
711 myFamilies[aFamNum]->SetType(anElement->GetType());
721 }catch(const std::exception& exc){
722 INFOS("Follow exception was cought:\n\t"<<exc.what());
725 INFOS("Unknown exception was cought !!!");
729 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
733 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
735 list<string> aMeshNames;
738 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
740 PWrapper aMed = CrWrapper(myFile);
742 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
743 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
744 // Reading the MED mesh
745 //---------------------
746 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
747 aMeshNames.push_back(aMeshInfo->GetName());
750 }catch(const std::exception& exc){
751 INFOS("Follow exception was cought:\n\t"<<exc.what());
752 theStatus = DRS_FAIL;
754 INFOS("Unknown exception was cought !!!");
755 theStatus = DRS_FAIL;
761 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
763 list<TNameAndType> aResult;
764 set<TNameAndType> aResGroupNames;
766 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
767 for (; aFamsIter != myFamilies.end(); aFamsIter++)
769 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
770 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
771 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
772 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
774 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
775 // Check, if this is a Group or SubMesh name
776 //if (aName.substr(0, 5) == string("Group")) {
777 if ( aResGroupNames.insert( aNameAndType ).second ) {
778 aResult.push_back( aNameAndType );
787 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
789 string aGroupName (theGroup->GetStoreName());
790 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
792 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
793 for (; aFamsIter != myFamilies.end(); aFamsIter++)
795 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
796 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
798 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
799 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
800 const SMDS_MeshElement * element = 0;
801 for (; anElemsIter != anElements.end(); anElemsIter++)
803 element = *anElemsIter;
804 theGroup->SMDSGroup().Add(element);
805 int aGroupAttrVal = aFamily->GetGroupAttributVal();
806 if( aGroupAttrVal != 0)
807 theGroup->SetColorGroup(aGroupAttrVal);
810 theGroup->SetType( theGroup->SMDSGroup().GetType() );
815 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
818 char submeshGrpName[ 30 ];
819 sprintf( submeshGrpName, "SubMesh %d", theId );
820 string aName (submeshGrpName);
821 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
822 for (; aFamsIter != myFamilies.end(); aFamsIter++)
824 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
825 if (aFamily->MemberOf(aName))
827 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
828 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
829 if (aFamily->GetType() == SMDSAbs_Node)
831 for (; anElemsIter != anElements.end(); anElemsIter++)
833 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
834 theSubMesh->AddNode(node);
839 for (; anElemsIter != anElements.end(); anElemsIter++)
841 theSubMesh->AddElement(*anElemsIter);
848 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
850 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
851 for (; aFamsIter != myFamilies.end(); aFamsIter++)
853 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
854 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
855 set<string>::iterator aGrNamesIter = aGroupNames.begin();
856 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
858 string aName = *aGrNamesIter;
859 // Check, if this is a Group or SubMesh name
860 if (aName.substr(0, 7) == string("SubMesh"))
862 int Id = atoi(string(aName).substr(7).c_str());
863 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
864 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
865 if (aFamily->GetType() == SMDSAbs_Node)
867 for (; anElemsIter != anElements.end(); anElemsIter++)
869 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
870 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
871 // find out a shape type
872 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
873 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
874 switch ( aShapeType ) {
876 myMesh->SetNodeOnFace(node, Id); break;
878 myMesh->SetNodeOnEdge(node, Id); break;
880 myMesh->SetNodeOnVertex(node, Id); break;
882 myMesh->SetNodeInVolume(node, Id);
888 for (; anElemsIter != anElements.end(); anElemsIter++)
890 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
898 * \brief Ensure aFamily to have required ID
899 * \param aFamily - a family to check and update
900 * \param anID - an ID aFamily should have
901 * \retval bool - true if successful
903 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
905 if ( !aFamily || aFamily->GetId() != anID ) {
906 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
907 if ( i_fam == myFamilies.end() )
909 aFamily = i_fam->second;
911 return ( aFamily->GetId() == anID );
915 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
916 * \param theWrapper - PWrapper const pointer
917 * \param theMeshInfo - PMeshInfo const pointer
918 * \return TRUE, if successfully. Else FALSE
920 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
921 const MED::PMeshInfo& theMeshInfo)
925 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
926 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
927 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
928 MED::TInt aMeshDim = theMeshInfo->GetDim();
929 DriverMED_FamilyPtr aFamily;
930 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
931 double aCoords[3] = {0.0, 0.0, 0.0};
932 const SMDS_MeshNode* aNode;
933 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
934 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
935 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
936 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
938 if((aGrilleInfo->myFamNumNode).size() > 0){
939 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
940 if ( checkFamilyID ( aFamily, aFamNum ))
942 aFamily->AddElement(aNode);
943 aFamily->SetType(SMDSAbs_Node);
949 SMDS_MeshElement* anElement = NULL;
950 MED::TIntVector aNodeIds;
951 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
952 aNodeIds = aGrilleInfo->GetConn(iCell);
953 switch(aGrilleInfo->GetGeom()){
955 if(aNodeIds.size() != 2){
957 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
959 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
964 if(aNodeIds.size() != 4){
966 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
968 anElement = myMesh->AddFaceWithID(aNodeIds[0],
975 if(aNodeIds.size() != 8){
977 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
979 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
993 if((aGrilleInfo->myFamNum).size() > 0){
994 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
995 if ( checkFamilyID ( aFamily, aFamNum )){
996 aFamily->AddElement(anElement);
997 aFamily->SetType(anElement->GetType());