1 // Copyright (C) 2007-2011 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 "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 = 1;
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);
147 aMeshInfo->myDim=aMeshInfo->mySpaceDim;//Bug correction to ignore meshdim in MEDFile because can be false.
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));
163 //MESSAGE("AddNodeWithID " << aNodeInfo->GetElemNum(iElem));
165 aNode = myMesh->AddNodeWithID
166 (aCoords[0],aCoords[1],aCoords[2], iElem+1);
167 //MESSAGE("AddNode " << aNode->GetID());
169 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
171 // Save reference to this node from its family
172 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
173 if ( checkFamilyID ( aFamily, aFamNum ))
175 aFamily->AddElement(aNode);
176 aFamily->SetType(SMDSAbs_Node);
180 // Reading pre information about all MED cells
181 //--------------------------------------------
182 typedef MED::TVector<int> TNodeIds;
183 bool takeNumbers = true; // initially we trust the numbers from file
184 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
185 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
186 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
187 const EEntiteMaillage& anEntity = anEntityIter->first;
188 if(anEntity == eNOEUD) continue;
189 // Reading MED cells to the corresponding SMDS structure
190 //------------------------------------------------------
191 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
192 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
193 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
194 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
197 // case ePOINT1: ## PAL16410
200 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
201 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
203 TInt aNbElem = aPolygoneInfo->GetNbElem();
204 for(TInt iElem = 0; iElem < aNbElem; iElem++){
205 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
206 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
207 TNodeIds aNodeIds(aNbConn);
208 #ifdef _EDF_NODE_IDS_
210 for(TInt iConn = 0; iConn < aNbConn; iConn++)
211 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
213 for(TInt iConn = 0; iConn < aNbConn; iConn++)
214 aNodeIds[iConn] = aConnSlice[iConn];
216 for(TInt iConn = 0; iConn < aNbConn; iConn++)
217 aNodeIds[iConn] = aConnSlice[iConn];
219 bool isRenum = false;
220 SMDS_MeshElement* anElement = NULL;
221 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
227 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
228 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
229 //MESSAGE("AddPolygonalFaceWithID " << anElemId);
232 vector<const SMDS_MeshNode*> aNodes(aNbConn);
233 for(TInt iConn = 0; iConn < aNbConn; iConn++)
234 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
235 anElement = myMesh->AddPolygonalFace(aNodes);
236 //MESSAGE("AddPolygonalFace " << anElement->GetID());
237 isRenum = anIsElemNum;
240 }catch(const std::exception& exc){
247 aResult = DRS_WARN_SKIP_ELEM;
252 if(aResult < DRS_WARN_RENUMBER)
253 aResult = DRS_WARN_RENUMBER;
255 if ( checkFamilyID ( aFamily, aFamNum ))
257 // Save reference to this element from its family
258 aFamily->AddElement(anElement);
259 aFamily->SetType(anElement->GetType());
266 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
267 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
269 TInt aNbElem = aPolyedreInfo->GetNbElem();
270 for(TInt iElem = 0; iElem < aNbElem; iElem++){
271 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
272 TInt aNbFaces = aConnSliceArr.size();
273 typedef MED::TVector<int> TQuantities;
274 TQuantities aQuantities(aNbFaces);
275 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
276 //MESSAGE("--- aNbNodes " << aNbNodes);
277 TNodeIds aNodeIds(aNbNodes);
278 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
279 //MESSAGE("--- iface " << aNbFaces << " " << iFace);
280 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
281 TInt aNbConn = aConnSlice.size();
282 aQuantities[iFace] = aNbConn;
283 #ifdef _EDF_NODE_IDS_
284 //MESSAGE(anIsNodeNum);
286 for(TInt iConn = 0; iConn < aNbConn; iConn++)
288 //MESSAGE("iConn " << iConn << " aConnSlice[iConn] " << aConnSlice[iConn]);
289 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
290 //MESSAGE("aNodeIds[" << iNode << "]=" << aNodeIds[iNode]);
294 for(TInt iConn = 0; iConn < aNbConn; iConn++)
296 //MESSAGE("iConn " << iConn);
297 aNodeIds[iNode++] = aConnSlice[iConn];
300 for(TInt iConn = 0; iConn < aNbConn; iConn++)
302 //MESSAGE("iConn " << iConn);
303 aNodeIds[iNode++] = aConnSlice[iConn];
308 bool isRenum = false;
309 SMDS_MeshElement* anElement = NULL;
310 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
316 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
317 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
318 //MESSAGE("AddPolyhedralVolumeWithID " << anElemId);
321 vector<const SMDS_MeshNode*> aNodes(aNbNodes);
322 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
323 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
324 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
325 //MESSAGE("AddPolyhedralVolume " << anElement->GetID());
326 isRenum = anIsElemNum;
329 }catch(const std::exception& exc){
336 aResult = DRS_WARN_SKIP_ELEM;
341 if (aResult < DRS_WARN_RENUMBER)
342 aResult = DRS_WARN_RENUMBER;
344 if ( checkFamilyID ( aFamily, aFamNum )) {
345 // Save reference to this element from its family
346 aFamily->AddElement(anElement);
347 aFamily->SetType(anElement->GetType());
354 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
355 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
356 TInt aNbElems = aCellInfo->GetNbElem();
357 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
358 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
362 case eSEG2: aNbNodes = 2; break;
363 case eSEG3: aNbNodes = 3; break;
364 case eTRIA3: aNbNodes = 3; break;
365 case eTRIA6: aNbNodes = 6; break;
366 case eQUAD4: aNbNodes = 4; break;
367 case eQUAD8: aNbNodes = 8; break;
368 case eTETRA4: aNbNodes = 4; break;
369 case eTETRA10: aNbNodes = 10; break;
370 case ePYRA5: aNbNodes = 5; break;
371 case ePYRA13: aNbNodes = 13; break;
372 case ePENTA6: aNbNodes = 6; break;
373 case ePENTA15: aNbNodes = 15; break;
374 case eHEXA8: aNbNodes = 8; break;
375 case eHEXA20: aNbNodes = 20; break;
376 case ePOINT1: aNbNodes = 1; break;
379 vector<TInt> aNodeIds(aNbNodes);
380 for(int iElem = 0; iElem < aNbElems; iElem++){
381 bool anIsValidConnect = false;
382 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
386 #ifdef _EDF_NODE_IDS_
388 for(int iNode = 0; iNode < aNbNodes; iNode++)
389 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
391 for(int iNode = 0; iNode < aNbNodes; iNode++)
392 aNodeIds[iNode] = aConnSlice[iNode];
394 for(int iNode = 0; iNode < aNbNodes; iNode++)
395 aNodeIds[iNode] = aConnSlice[iNode];
397 anIsValidConnect = true;
399 }catch(const std::exception& exc){
400 INFOS("Following exception was caught:\n\t"<<exc.what());
403 INFOS("Unknown exception was cought !!!");
407 if(!anIsValidConnect)
410 bool isRenum = false;
411 const SMDS_MeshElement* anElement = NULL;
412 TInt aFamNum = aCellInfo->GetFamNum(iElem);
416 //MESSAGE("Try to create element # " << iElem << " with id = "
417 // << aCellInfo->GetElemNum(iElem));
420 //anElement = FindNode(myMesh,aNodeIds[0]);
422 anElement = myMesh->Add0DElementWithID
423 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
425 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
426 isRenum = anIsElemNum;
431 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
433 aCellInfo->GetElemNum(iElem));
435 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
436 FindNode(myMesh,aNodeIds[1]));
437 isRenum = anIsElemNum;
442 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
445 aCellInfo->GetElemNum(iElem));
447 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
448 FindNode(myMesh,aNodeIds[1]),
449 FindNode(myMesh,aNodeIds[2]));
450 isRenum = anIsElemNum;
456 anElement = myMesh->AddFaceWithID(aNodeIds[0],
459 aCellInfo->GetElemNum(iElem));
461 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
462 FindNode(myMesh,aNodeIds[1]),
463 FindNode(myMesh,aNodeIds[2]));
464 isRenum = anIsElemNum;
470 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
471 aNodeIds[2], aNodeIds[3],
472 aNodeIds[4], aNodeIds[5],
473 aCellInfo->GetElemNum(iElem));
475 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
476 FindNode(myMesh,aNodeIds[1]),
477 FindNode(myMesh,aNodeIds[2]),
478 FindNode(myMesh,aNodeIds[3]),
479 FindNode(myMesh,aNodeIds[4]),
480 FindNode(myMesh,aNodeIds[5]));
481 isRenum = anIsElemNum;
487 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
488 aNodeIds[2], aNodeIds[3],
489 aCellInfo->GetElemNum(iElem));
491 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
492 FindNode(myMesh,aNodeIds[1]),
493 FindNode(myMesh,aNodeIds[2]),
494 FindNode(myMesh,aNodeIds[3]));
495 isRenum = anIsElemNum;
501 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
502 aNodeIds[2], aNodeIds[3],
503 aNodeIds[4], aNodeIds[5],
504 aNodeIds[6], aNodeIds[7],
505 aCellInfo->GetElemNum(iElem));
507 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
508 FindNode(myMesh,aNodeIds[1]),
509 FindNode(myMesh,aNodeIds[2]),
510 FindNode(myMesh,aNodeIds[3]),
511 FindNode(myMesh,aNodeIds[4]),
512 FindNode(myMesh,aNodeIds[5]),
513 FindNode(myMesh,aNodeIds[6]),
514 FindNode(myMesh,aNodeIds[7]));
515 isRenum = anIsElemNum;
521 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
522 aNodeIds[2], aNodeIds[3],
523 aCellInfo->GetElemNum(iElem));
525 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
526 FindNode(myMesh,aNodeIds[1]),
527 FindNode(myMesh,aNodeIds[2]),
528 FindNode(myMesh,aNodeIds[3]));
529 isRenum = anIsElemNum;
535 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
536 aNodeIds[2], aNodeIds[3],
537 aNodeIds[4], aNodeIds[5],
538 aNodeIds[6], aNodeIds[7],
539 aNodeIds[8], aNodeIds[9],
540 aCellInfo->GetElemNum(iElem));
542 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
543 FindNode(myMesh,aNodeIds[1]),
544 FindNode(myMesh,aNodeIds[2]),
545 FindNode(myMesh,aNodeIds[3]),
546 FindNode(myMesh,aNodeIds[4]),
547 FindNode(myMesh,aNodeIds[5]),
548 FindNode(myMesh,aNodeIds[6]),
549 FindNode(myMesh,aNodeIds[7]),
550 FindNode(myMesh,aNodeIds[8]),
551 FindNode(myMesh,aNodeIds[9]));
552 isRenum = anIsElemNum;
557 // There is some differnce between SMDS and MED
559 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
560 aNodeIds[2], aNodeIds[3],
562 aCellInfo->GetElemNum(iElem));
564 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
565 FindNode(myMesh,aNodeIds[1]),
566 FindNode(myMesh,aNodeIds[2]),
567 FindNode(myMesh,aNodeIds[3]),
568 FindNode(myMesh,aNodeIds[4]));
569 isRenum = anIsElemNum;
574 // There is some difference between SMDS and MED
576 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
577 aNodeIds[2], aNodeIds[3],
578 aNodeIds[4], aNodeIds[5],
579 aNodeIds[6], aNodeIds[7],
580 aNodeIds[8], aNodeIds[9],
581 aNodeIds[10], aNodeIds[11],
583 aCellInfo->GetElemNum(iElem));
585 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
586 FindNode(myMesh,aNodeIds[1]),
587 FindNode(myMesh,aNodeIds[2]),
588 FindNode(myMesh,aNodeIds[3]),
589 FindNode(myMesh,aNodeIds[4]),
590 FindNode(myMesh,aNodeIds[5]),
591 FindNode(myMesh,aNodeIds[6]),
592 FindNode(myMesh,aNodeIds[7]),
593 FindNode(myMesh,aNodeIds[8]),
594 FindNode(myMesh,aNodeIds[9]),
595 FindNode(myMesh,aNodeIds[10]),
596 FindNode(myMesh,aNodeIds[11]),
597 FindNode(myMesh,aNodeIds[12]));
598 isRenum = anIsElemNum;
604 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
610 aCellInfo->GetElemNum(iElem));
612 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
613 FindNode(myMesh,aNodeIds[1]),
614 FindNode(myMesh,aNodeIds[2]),
615 FindNode(myMesh,aNodeIds[3]),
616 FindNode(myMesh,aNodeIds[4]),
617 FindNode(myMesh,aNodeIds[5]));
618 isRenum = anIsElemNum;
624 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
625 aNodeIds[2], aNodeIds[3],
626 aNodeIds[4], aNodeIds[5],
627 aNodeIds[6], aNodeIds[7],
628 aNodeIds[8], aNodeIds[9],
629 aNodeIds[10], aNodeIds[11],
630 aNodeIds[12], aNodeIds[13],
632 aCellInfo->GetElemNum(iElem));
634 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
635 FindNode(myMesh,aNodeIds[1]),
636 FindNode(myMesh,aNodeIds[2]),
637 FindNode(myMesh,aNodeIds[3]),
638 FindNode(myMesh,aNodeIds[4]),
639 FindNode(myMesh,aNodeIds[5]),
640 FindNode(myMesh,aNodeIds[6]),
641 FindNode(myMesh,aNodeIds[7]),
642 FindNode(myMesh,aNodeIds[8]),
643 FindNode(myMesh,aNodeIds[9]),
644 FindNode(myMesh,aNodeIds[10]),
645 FindNode(myMesh,aNodeIds[11]),
646 FindNode(myMesh,aNodeIds[12]),
647 FindNode(myMesh,aNodeIds[13]),
648 FindNode(myMesh,aNodeIds[14]));
649 isRenum = anIsElemNum;
655 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
663 aCellInfo->GetElemNum(iElem));
665 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
666 FindNode(myMesh,aNodeIds[1]),
667 FindNode(myMesh,aNodeIds[2]),
668 FindNode(myMesh,aNodeIds[3]),
669 FindNode(myMesh,aNodeIds[4]),
670 FindNode(myMesh,aNodeIds[5]),
671 FindNode(myMesh,aNodeIds[6]),
672 FindNode(myMesh,aNodeIds[7]));
673 isRenum = anIsElemNum;
679 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
680 aNodeIds[2], aNodeIds[3],
681 aNodeIds[4], aNodeIds[5],
682 aNodeIds[6], aNodeIds[7],
683 aNodeIds[8], aNodeIds[9],
684 aNodeIds[10], aNodeIds[11],
685 aNodeIds[12], aNodeIds[13],
686 aNodeIds[14], aNodeIds[15],
687 aNodeIds[16], aNodeIds[17],
688 aNodeIds[18], aNodeIds[19],
689 aCellInfo->GetElemNum(iElem));
691 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
692 FindNode(myMesh,aNodeIds[1]),
693 FindNode(myMesh,aNodeIds[2]),
694 FindNode(myMesh,aNodeIds[3]),
695 FindNode(myMesh,aNodeIds[4]),
696 FindNode(myMesh,aNodeIds[5]),
697 FindNode(myMesh,aNodeIds[6]),
698 FindNode(myMesh,aNodeIds[7]),
699 FindNode(myMesh,aNodeIds[8]),
700 FindNode(myMesh,aNodeIds[9]),
701 FindNode(myMesh,aNodeIds[10]),
702 FindNode(myMesh,aNodeIds[11]),
703 FindNode(myMesh,aNodeIds[12]),
704 FindNode(myMesh,aNodeIds[13]),
705 FindNode(myMesh,aNodeIds[14]),
706 FindNode(myMesh,aNodeIds[15]),
707 FindNode(myMesh,aNodeIds[16]),
708 FindNode(myMesh,aNodeIds[17]),
709 FindNode(myMesh,aNodeIds[18]),
710 FindNode(myMesh,aNodeIds[19]));
711 isRenum = anIsElemNum;
715 // if (anIsElemNum) {
716 // MESSAGE("add element with id " << aCellInfo->GetElemNum(iElem));
719 // MESSAGE("add element "<< anElement->GetID());
722 }catch(const std::exception& exc){
723 INFOS("The following exception was caught:\n\t"<<exc.what());
726 INFOS("Unknown exception was caught !!!");
731 aResult = DRS_WARN_SKIP_ELEM;
737 if (aResult < DRS_WARN_RENUMBER)
738 aResult = DRS_WARN_RENUMBER;
740 if ( checkFamilyID ( aFamily, aFamNum )) {
741 // Save reference to this element from its family
742 myFamilies[aFamNum]->AddElement(anElement);
743 myFamilies[aFamNum]->SetType(anElement->GetType());
753 }catch(const std::exception& exc){
754 INFOS("The following exception was caught:\n\t"<<exc.what());
757 INFOS("Unknown exception was caught !!!");
762 myMesh->compactMesh();
763 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
767 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
769 list<string> aMeshNames;
772 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
774 PWrapper aMed = CrWrapper(myFile);
776 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
777 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
778 // Reading the MED mesh
779 //---------------------
780 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
781 aMeshNames.push_back(aMeshInfo->GetName());
784 }catch(const std::exception& exc){
785 INFOS("Following exception was caught:\n\t"<<exc.what());
786 theStatus = DRS_FAIL;
788 INFOS("Unknown exception was caught !!!");
789 theStatus = DRS_FAIL;
795 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
797 list<TNameAndType> aResult;
798 set<TNameAndType> aResGroupNames;
800 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
801 for (; aFamsIter != myFamilies.end(); aFamsIter++)
803 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
804 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
805 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
806 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
808 const set< SMDSAbs_ElementType >& types = aFamily->GetTypes();
809 set< SMDSAbs_ElementType >::const_iterator type = types.begin();
810 for ( ; type != types.end(); ++type )
812 TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
813 if ( aResGroupNames.insert( aNameAndType ).second ) {
814 aResult.push_back( aNameAndType );
823 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
825 string aGroupName (theGroup->GetStoreName());
826 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
828 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
829 for (; aFamsIter != myFamilies.end(); aFamsIter++)
831 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
832 if (aFamily->GetTypes().count( theGroup->GetType() ) && aFamily->MemberOf(aGroupName))
834 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
835 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
836 for (; anElemsIter != anElements.end(); anElemsIter++)
838 const SMDS_MeshElement * element = *anElemsIter;
839 if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
840 theGroup->SMDSGroup().Add(element);
842 int aGroupAttrVal = aFamily->GetGroupAttributVal();
843 if( aGroupAttrVal != 0)
844 theGroup->SetColorGroup(aGroupAttrVal);
845 // if ( element ) -- Issue 0020576
846 // theGroup->SetType( theGroup->SMDSGroup().GetType() );
851 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
854 char submeshGrpName[ 30 ];
855 sprintf( submeshGrpName, "SubMesh %d", theId );
856 string aName (submeshGrpName);
857 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
858 for (; aFamsIter != myFamilies.end(); aFamsIter++)
860 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
861 if (aFamily->MemberOf(aName))
863 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
864 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
865 if (aFamily->GetType() == SMDSAbs_Node)
867 for (; anElemsIter != anElements.end(); anElemsIter++)
869 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
870 theSubMesh->AddNode(node);
875 for (; anElemsIter != anElements.end(); anElemsIter++)
877 theSubMesh->AddElement(*anElemsIter);
884 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
886 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
887 for (; aFamsIter != myFamilies.end(); aFamsIter++)
889 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
890 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
891 set<string>::iterator aGrNamesIter = aGroupNames.begin();
892 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
894 string aName = *aGrNamesIter;
895 // Check, if this is a Group or SubMesh name
896 if (aName.substr(0, 7) == string("SubMesh"))
898 int Id = atoi(string(aName).substr(7).c_str());
899 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
900 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
901 if (aFamily->GetType() == SMDSAbs_Node)
903 for (; anElemsIter != anElements.end(); anElemsIter++)
905 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
906 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
907 // find out a shape type
908 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
909 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
910 switch ( aShapeType ) {
912 myMesh->SetNodeOnFace(node, Id); break;
914 myMesh->SetNodeOnEdge(node, Id); break;
916 myMesh->SetNodeOnVertex(node, Id); break;
918 myMesh->SetNodeInVolume(node, Id);
924 for (; anElemsIter != anElements.end(); anElemsIter++)
926 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
934 * \brief Ensure aFamily to have required ID
935 * \param aFamily - a family to check and update
936 * \param anID - an ID aFamily should have
937 * \retval bool - true if successful
939 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
941 if ( !aFamily || aFamily->GetId() != anID ) {
942 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
943 if ( i_fam == myFamilies.end() )
945 aFamily = i_fam->second;
947 return ( aFamily->GetId() == anID );
951 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
952 * \param theWrapper - PWrapper const pointer
953 * \param theMeshInfo - PMeshInfo const pointer
954 * \return TRUE, if successfully. Else FALSE
956 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
957 const MED::PMeshInfo& theMeshInfo)
961 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
962 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
963 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
964 MED::TInt aMeshDim = theMeshInfo->GetDim();
965 DriverMED_FamilyPtr aFamily;
966 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
967 double aCoords[3] = {0.0, 0.0, 0.0};
968 const SMDS_MeshNode* aNode;
969 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
970 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
971 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
972 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
974 EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
977 if((aGrilleInfo->myFamNumNode).size() > 0){
978 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
979 if ( checkFamilyID ( aFamily, aFamNum ))
981 aFamily->AddElement(aNode);
982 aFamily->SetType(SMDSAbs_Node);
988 SMDS_MeshElement* anElement = NULL;
989 MED::TIntVector aNodeIds;
990 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
991 aNodeIds = aGrilleInfo->GetConn(iCell);
992 switch(aGrilleInfo->GetGeom()){
994 if(aNodeIds.size() != 2){
996 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
998 anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1003 if(aNodeIds.size() != 4){
1005 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1007 anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1014 if(aNodeIds.size() != 8){
1016 EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1018 anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1032 EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1034 if((aGrilleInfo->myFamNum).size() > 0){
1035 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1036 if ( checkFamilyID ( aFamily, aFamNum )){
1037 aFamily->AddElement(anElement);
1038 aFamily->SetType(anElement->GetType());