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_
53 DriverMED_R_SMESHDS_Mesh
54 ::SetMeshName(std::string theMeshName)
56 myMeshName = theMeshName;
59 static const SMDS_MeshNode*
60 FindNode(const SMDS_Mesh* theMesh, TInt theId){
61 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
62 if(aNode) return aNode;
63 EXCEPTION(std::runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
68 DriverMED_R_SMESHDS_Mesh
71 Status aResult = DRS_FAIL;
76 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
77 PWrapper aMed = CrWrapper(myFile,true);
80 if(TInt aNbMeshes = aMed->GetNbMeshes()){
81 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
82 // Reading the MED mesh
83 //---------------------
84 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
86 std::string aMeshName;
88 std::ostringstream aMeshNameStr;
89 aMeshNameStr<<myMeshId;
90 aMeshName = aMeshNameStr.str();
92 aMeshName = myMeshName;
94 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
95 if(aMeshName != aMeshInfo->GetName()) continue;
98 //TInt aMeshDim = aMeshInfo->GetDim();
100 // Reading MED families to the temporary structure
101 //------------------------------------------------
103 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
104 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
105 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
106 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
108 TInt aFamId = aFamilyInfo->GetId();
109 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
111 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
113 TInt aNbGrp = aFamilyInfo->GetNbGroup();
114 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
115 bool isAttrOk = false;
116 if(aFamilyInfo->GetNbAttr() == aNbGrp)
118 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
119 std::string aGroupName = aFamilyInfo->GetGroupName(iGr);
121 TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
122 aFamily->SetGroupAttributVal(anAttrVal);
125 if(MYDEBUG) MESSAGE(aGroupName);
126 aFamily->AddGroupName(aGroupName);
129 aFamily->SetId( aFamId );
130 myFamilies[aFamId] = aFamily;
134 if (aMeshInfo->GetType() == MED::eSTRUCTURE){
135 /*bool aRes = */buildMeshGrille(aMed,aMeshInfo);
139 // Reading MED nodes to the corresponding SMDS structure
140 //------------------------------------------------------
141 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
147 PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
149 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
150 TInt aNbElems = aNodeInfo->GetNbElem();
151 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
152 DriverMED_FamilyPtr aFamily;
153 for(TInt iElem = 0; iElem < aNbElems; iElem++){
154 TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
155 double aCoords[3] = {0.0, 0.0, 0.0};
156 for(TInt iDim = 0; iDim < 3; iDim++)
157 aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
158 const SMDS_MeshNode* aNode;
160 aNode = myMesh->AddNodeWithID
161 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
163 aNode = myMesh->AddNode
164 (aCoords[0],aCoords[1],aCoords[2]);
166 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
168 // Save reference to this node from its family
169 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
170 if ( checkFamilyID ( aFamily, aFamNum ))
172 aFamily->AddElement(aNode);
173 aFamily->SetType(SMDSAbs_Node);
177 // Reading pre information about all MED cells
178 //--------------------------------------------
179 typedef MED::TVector<int> TNodeIds;
180 bool takeNumbers = true; // initially we trust the numbers from file
181 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
182 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
183 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
184 const EEntiteMaillage& anEntity = anEntityIter->first;
185 if(anEntity == eNOEUD) continue;
186 // Reading MED cells to the corresponding SMDS structure
187 //------------------------------------------------------
188 const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
189 MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
190 for(; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++){
191 const EGeometrieElement& aGeom = aGeom2SizeIter->first;
194 // case ePOINT1: ## PAL16410
197 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
198 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
200 TInt aNbElem = aPolygoneInfo->GetNbElem();
201 for(TInt iElem = 0; iElem < aNbElem; iElem++){
202 MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
203 TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
204 TNodeIds aNodeIds(aNbConn);
205 #ifdef _EDF_NODE_IDS_
207 for(TInt iConn = 0; iConn < aNbConn; iConn++)
208 aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
210 for(TInt iConn = 0; iConn < aNbConn; iConn++)
211 aNodeIds[iConn] = aConnSlice[iConn];
213 for(TInt iConn = 0; iConn < aNbConn; iConn++)
214 aNodeIds[iConn] = aConnSlice[iConn];
216 bool isRenum = false;
217 SMDS_MeshElement* anElement = NULL;
218 TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
224 TInt anElemId = aPolygoneInfo->GetElemNum(iElem);
225 anElement = myMesh->AddPolygonalFaceWithID(aNodeIds,anElemId);
228 std::vector<const SMDS_MeshNode*> aNodes(aNbConn);
229 for(TInt iConn = 0; iConn < aNbConn; iConn++)
230 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
231 anElement = myMesh->AddPolygonalFace(aNodes);
232 isRenum = anIsElemNum;
235 }catch(const std::exception& exc){
242 aResult = DRS_WARN_SKIP_ELEM;
247 if(aResult < DRS_WARN_RENUMBER)
248 aResult = DRS_WARN_RENUMBER;
250 if ( checkFamilyID ( aFamily, aFamNum ))
252 // Save reference to this element from its family
253 aFamily->AddElement(anElement);
254 aFamily->SetType(anElement->GetType());
261 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
262 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
264 TInt aNbElem = aPolyedreInfo->GetNbElem();
265 for(TInt iElem = 0; iElem < aNbElem; iElem++){
266 MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
267 TInt aNbFaces = aConnSliceArr.size();
268 typedef MED::TVector<int> TQuantities;
269 TQuantities aQuantities(aNbFaces);
270 TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
271 TNodeIds aNodeIds(aNbNodes);
272 for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
273 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
274 TInt aNbConn = aConnSlice.size();
275 aQuantities[iFace] = aNbConn;
276 #ifdef _EDF_NODE_IDS_
278 for(TInt iConn = 0; iConn < aNbConn; iConn++)
279 aNodeIds[iNode++] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
281 for(TInt iConn = 0; iConn < aNbConn; iConn++)
282 aNodeIds[iNode++] = aConnSlice[iConn];
284 for(TInt iConn = 0; iConn < aNbConn; iConn++)
285 aNodeIds[iNode++] = aConnSlice[iConn];
289 bool isRenum = false;
290 SMDS_MeshElement* anElement = NULL;
291 TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
297 TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
298 anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,anElemId);
301 std::vector<const SMDS_MeshNode*> aNodes(aNbNodes);
302 for(TInt iConn = 0; iConn < aNbNodes; iConn++)
303 aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
304 anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
305 isRenum = anIsElemNum;
308 }catch(const std::exception& exc){
315 aResult = DRS_WARN_SKIP_ELEM;
320 if (aResult < DRS_WARN_RENUMBER)
321 aResult = DRS_WARN_RENUMBER;
323 if ( checkFamilyID ( aFamily, aFamNum )) {
324 // Save reference to this element from its family
325 aFamily->AddElement(anElement);
326 aFamily->SetType(anElement->GetType());
333 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
334 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
335 TInt aNbElems = aCellInfo->GetNbElem();
336 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
337 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
339 for(int iElem = 0; iElem < aNbElems; iElem++){
342 case eSEG2: aNbNodes = 2; break;
343 case eSEG3: aNbNodes = 3; break;
344 case eTRIA3: aNbNodes = 3; break;
345 case eTRIA6: aNbNodes = 6; break;
346 case eQUAD4: aNbNodes = 4; break;
347 case eQUAD8: aNbNodes = 8; break;
348 case eTETRA4: aNbNodes = 4; break;
349 case eTETRA10: aNbNodes = 10; break;
350 case ePYRA5: aNbNodes = 5; break;
351 case ePYRA13: aNbNodes = 13; break;
352 case ePENTA6: aNbNodes = 6; break;
353 case ePENTA15: aNbNodes = 15; break;
354 case eHEXA8: aNbNodes = 8; break;
355 case eHEXA20: aNbNodes = 20; break;
356 case ePOINT1: aNbNodes = 1; break;
359 std::vector<TInt> aNodeIds(aNbNodes);
360 bool anIsValidConnect = false;
361 TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
365 #ifdef _EDF_NODE_IDS_
367 for(int iNode = 0; iNode < aNbNodes; iNode++)
368 aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
370 for(int iNode = 0; iNode < aNbNodes; iNode++)
371 aNodeIds[iNode] = aConnSlice[iNode];
373 for(int iNode = 0; iNode < aNbNodes; iNode++)
374 aNodeIds[iNode] = aConnSlice[iNode];
376 anIsValidConnect = true;
378 }catch(const std::exception& exc){
379 //INFOS("Follow exception was cought:\n\t"<<exc.what());
382 //INFOS("Unknown exception was cought !!!");
386 if(!anIsValidConnect)
389 bool isRenum = false;
390 const SMDS_MeshElement* anElement = NULL;
391 TInt aFamNum = aCellInfo->GetFamNum(iElem);
395 //MESSAGE("Try to create element # " << iElem << " with id = "
396 // << aCellInfo->GetElemNum(iElem));
399 //anElement = FindNode(myMesh,aNodeIds[0]);
401 anElement = myMesh->Add0DElementWithID
402 (aNodeIds[0], aCellInfo->GetElemNum(iElem));
404 anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
405 isRenum = anIsElemNum;
410 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
412 aCellInfo->GetElemNum(iElem));
414 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
415 FindNode(myMesh,aNodeIds[1]));
416 isRenum = anIsElemNum;
421 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
424 aCellInfo->GetElemNum(iElem));
426 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
427 FindNode(myMesh,aNodeIds[1]),
428 FindNode(myMesh,aNodeIds[2]));
429 isRenum = anIsElemNum;
435 anElement = myMesh->AddFaceWithID(aNodeIds[0],
438 aCellInfo->GetElemNum(iElem));
440 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
441 FindNode(myMesh,aNodeIds[1]),
442 FindNode(myMesh,aNodeIds[2]));
443 isRenum = anIsElemNum;
449 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
450 aNodeIds[2], aNodeIds[3],
451 aNodeIds[4], aNodeIds[5],
452 aCellInfo->GetElemNum(iElem));
454 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
455 FindNode(myMesh,aNodeIds[1]),
456 FindNode(myMesh,aNodeIds[2]),
457 FindNode(myMesh,aNodeIds[3]),
458 FindNode(myMesh,aNodeIds[4]),
459 FindNode(myMesh,aNodeIds[5]));
460 isRenum = anIsElemNum;
466 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
467 aNodeIds[2], aNodeIds[3],
468 aCellInfo->GetElemNum(iElem));
470 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
471 FindNode(myMesh,aNodeIds[1]),
472 FindNode(myMesh,aNodeIds[2]),
473 FindNode(myMesh,aNodeIds[3]));
474 isRenum = anIsElemNum;
480 anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
481 aNodeIds[2], aNodeIds[3],
482 aNodeIds[4], aNodeIds[5],
483 aNodeIds[6], aNodeIds[7],
484 aCellInfo->GetElemNum(iElem));
486 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
487 FindNode(myMesh,aNodeIds[1]),
488 FindNode(myMesh,aNodeIds[2]),
489 FindNode(myMesh,aNodeIds[3]),
490 FindNode(myMesh,aNodeIds[4]),
491 FindNode(myMesh,aNodeIds[5]),
492 FindNode(myMesh,aNodeIds[6]),
493 FindNode(myMesh,aNodeIds[7]));
494 isRenum = anIsElemNum;
500 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
501 aNodeIds[2], aNodeIds[3],
502 aCellInfo->GetElemNum(iElem));
504 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
505 FindNode(myMesh,aNodeIds[1]),
506 FindNode(myMesh,aNodeIds[2]),
507 FindNode(myMesh,aNodeIds[3]));
508 isRenum = anIsElemNum;
514 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
515 aNodeIds[2], aNodeIds[3],
516 aNodeIds[4], aNodeIds[5],
517 aNodeIds[6], aNodeIds[7],
518 aNodeIds[8], aNodeIds[9],
519 aCellInfo->GetElemNum(iElem));
521 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
522 FindNode(myMesh,aNodeIds[1]),
523 FindNode(myMesh,aNodeIds[2]),
524 FindNode(myMesh,aNodeIds[3]),
525 FindNode(myMesh,aNodeIds[4]),
526 FindNode(myMesh,aNodeIds[5]),
527 FindNode(myMesh,aNodeIds[6]),
528 FindNode(myMesh,aNodeIds[7]),
529 FindNode(myMesh,aNodeIds[8]),
530 FindNode(myMesh,aNodeIds[9]));
531 isRenum = anIsElemNum;
536 // There is some differnce between SMDS and MED
538 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
539 aNodeIds[2], aNodeIds[3],
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 isRenum = anIsElemNum;
553 // There is some differnce between SMDS and MED
555 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
556 aNodeIds[2], aNodeIds[3],
557 aNodeIds[4], aNodeIds[5],
558 aNodeIds[6], aNodeIds[7],
559 aNodeIds[8], aNodeIds[9],
560 aNodeIds[10], aNodeIds[11],
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 FindNode(myMesh,aNodeIds[5]),
570 FindNode(myMesh,aNodeIds[6]),
571 FindNode(myMesh,aNodeIds[7]),
572 FindNode(myMesh,aNodeIds[8]),
573 FindNode(myMesh,aNodeIds[9]),
574 FindNode(myMesh,aNodeIds[10]),
575 FindNode(myMesh,aNodeIds[11]),
576 FindNode(myMesh,aNodeIds[12]));
577 isRenum = anIsElemNum;
583 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
589 aCellInfo->GetElemNum(iElem));
591 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
592 FindNode(myMesh,aNodeIds[1]),
593 FindNode(myMesh,aNodeIds[2]),
594 FindNode(myMesh,aNodeIds[3]),
595 FindNode(myMesh,aNodeIds[4]),
596 FindNode(myMesh,aNodeIds[5]));
597 isRenum = anIsElemNum;
603 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
604 aNodeIds[2], aNodeIds[3],
605 aNodeIds[4], aNodeIds[5],
606 aNodeIds[6], aNodeIds[7],
607 aNodeIds[8], aNodeIds[9],
608 aNodeIds[10], aNodeIds[11],
609 aNodeIds[12], aNodeIds[13],
611 aCellInfo->GetElemNum(iElem));
613 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
614 FindNode(myMesh,aNodeIds[1]),
615 FindNode(myMesh,aNodeIds[2]),
616 FindNode(myMesh,aNodeIds[3]),
617 FindNode(myMesh,aNodeIds[4]),
618 FindNode(myMesh,aNodeIds[5]),
619 FindNode(myMesh,aNodeIds[6]),
620 FindNode(myMesh,aNodeIds[7]),
621 FindNode(myMesh,aNodeIds[8]),
622 FindNode(myMesh,aNodeIds[9]),
623 FindNode(myMesh,aNodeIds[10]),
624 FindNode(myMesh,aNodeIds[11]),
625 FindNode(myMesh,aNodeIds[12]),
626 FindNode(myMesh,aNodeIds[13]),
627 FindNode(myMesh,aNodeIds[14]));
628 isRenum = anIsElemNum;
634 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
642 aCellInfo->GetElemNum(iElem));
644 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
645 FindNode(myMesh,aNodeIds[1]),
646 FindNode(myMesh,aNodeIds[2]),
647 FindNode(myMesh,aNodeIds[3]),
648 FindNode(myMesh,aNodeIds[4]),
649 FindNode(myMesh,aNodeIds[5]),
650 FindNode(myMesh,aNodeIds[6]),
651 FindNode(myMesh,aNodeIds[7]));
652 isRenum = anIsElemNum;
658 anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
659 aNodeIds[2], aNodeIds[3],
660 aNodeIds[4], aNodeIds[5],
661 aNodeIds[6], aNodeIds[7],
662 aNodeIds[8], aNodeIds[9],
663 aNodeIds[10], aNodeIds[11],
664 aNodeIds[12], aNodeIds[13],
665 aNodeIds[14], aNodeIds[15],
666 aNodeIds[16], aNodeIds[17],
667 aNodeIds[18], aNodeIds[19],
668 aCellInfo->GetElemNum(iElem));
670 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
671 FindNode(myMesh,aNodeIds[1]),
672 FindNode(myMesh,aNodeIds[2]),
673 FindNode(myMesh,aNodeIds[3]),
674 FindNode(myMesh,aNodeIds[4]),
675 FindNode(myMesh,aNodeIds[5]),
676 FindNode(myMesh,aNodeIds[6]),
677 FindNode(myMesh,aNodeIds[7]),
678 FindNode(myMesh,aNodeIds[8]),
679 FindNode(myMesh,aNodeIds[9]),
680 FindNode(myMesh,aNodeIds[10]),
681 FindNode(myMesh,aNodeIds[11]),
682 FindNode(myMesh,aNodeIds[12]),
683 FindNode(myMesh,aNodeIds[13]),
684 FindNode(myMesh,aNodeIds[14]),
685 FindNode(myMesh,aNodeIds[15]),
686 FindNode(myMesh,aNodeIds[16]),
687 FindNode(myMesh,aNodeIds[17]),
688 FindNode(myMesh,aNodeIds[18]),
689 FindNode(myMesh,aNodeIds[19]));
690 isRenum = anIsElemNum;
696 }catch(const std::exception& exc){
697 //INFOS("Follow exception was cought:\n\t"<<exc.what());
700 //INFOS("Unknown exception was cought !!!");
705 aResult = DRS_WARN_SKIP_ELEM;
711 if (aResult < DRS_WARN_RENUMBER)
712 aResult = DRS_WARN_RENUMBER;
714 if ( checkFamilyID ( aFamily, aFamNum )) {
715 // Save reference to this element from its family
716 myFamilies[aFamNum]->AddElement(anElement);
717 myFamilies[aFamNum]->SetType(anElement->GetType());
727 }catch(const std::exception& exc){
728 INFOS("Follow exception was cought:\n\t"<<exc.what());
731 INFOS("Unknown exception was cought !!!");
735 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
739 std::list<std::string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
741 std::list<std::string> aMeshNames;
744 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
746 PWrapper aMed = CrWrapper(myFile);
748 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
749 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
750 // Reading the MED mesh
751 //---------------------
752 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
753 aMeshNames.push_back(aMeshInfo->GetName());
756 }catch(const std::exception& exc){
757 INFOS("Follow exception was cought:\n\t"<<exc.what());
758 theStatus = DRS_FAIL;
760 INFOS("Unknown exception was cought !!!");
761 theStatus = DRS_FAIL;
767 std::list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
769 std::list<TNameAndType> aResult;
770 std::set<TNameAndType> aResGroupNames;
772 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
773 for (; aFamsIter != myFamilies.end(); aFamsIter++)
775 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
776 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
777 std::set<std::string>::const_iterator aGrNamesIter = aGroupNames.begin();
778 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
780 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
781 // Check, if this is a Group or SubMesh name
782 //if (aName.substr(0, 5) == string("Group")) {
783 if ( aResGroupNames.insert( aNameAndType ).second ) {
784 aResult.push_back( aNameAndType );
793 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
795 std::string aGroupName (theGroup->GetStoreName());
796 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
798 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
799 for (; aFamsIter != myFamilies.end(); aFamsIter++)
801 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
802 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
804 const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
805 std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
806 const SMDS_MeshElement * element = 0;
807 for (; anElemsIter != anElements.end(); anElemsIter++)
809 element = *anElemsIter;
810 theGroup->SMDSGroup().Add(element);
811 int aGroupAttrVal = aFamily->GetGroupAttributVal();
812 if( aGroupAttrVal != 0)
813 theGroup->SetColorGroup(aGroupAttrVal);
816 theGroup->SetType( theGroup->SMDSGroup().GetType() );
821 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
824 char submeshGrpName[ 30 ];
825 sprintf( submeshGrpName, "SubMesh %d", theId );
826 std::string aName (submeshGrpName);
827 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
828 for (; aFamsIter != myFamilies.end(); aFamsIter++)
830 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
831 if (aFamily->MemberOf(aName))
833 const std::set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
834 std::set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
835 if (aFamily->GetType() == SMDSAbs_Node)
837 for (; anElemsIter != anElements.end(); anElemsIter++)
839 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
840 theSubMesh->AddNode(node);
845 for (; anElemsIter != anElements.end(); anElemsIter++)
847 theSubMesh->AddElement(*anElemsIter);
854 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
856 std::map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
857 for (; aFamsIter != myFamilies.end(); aFamsIter++)
859 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
860 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
861 std::set<std::string>::iterator aGrNamesIter = aGroupNames.begin();
862 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
864 std::string aName = *aGrNamesIter;
865 // Check, if this is a Group or SubMesh name
866 if (aName.substr(0, 7) == std::string("SubMesh"))
868 int Id = atoi(std::string(aName).substr(7).c_str());
869 std::set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
870 std::set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
871 if (aFamily->GetType() == SMDSAbs_Node)
873 for (; anElemsIter != anElements.end(); anElemsIter++)
875 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
876 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
877 // find out a shape type
878 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
879 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
880 switch ( aShapeType ) {
882 myMesh->SetNodeOnFace(node, Id); break;
884 myMesh->SetNodeOnEdge(node, Id); break;
886 myMesh->SetNodeOnVertex(node, Id); break;
888 myMesh->SetNodeInVolume(node, Id);
894 for (; anElemsIter != anElements.end(); anElemsIter++)
896 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
904 * \brief Ensure aFamily to have required ID
905 * \param aFamily - a family to check and update
906 * \param anID - an ID aFamily should have
907 * \retval bool - true if successful
909 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
911 if ( !aFamily || aFamily->GetId() != anID ) {
912 std::map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
913 if ( i_fam == myFamilies.end() )
915 aFamily = i_fam->second;
917 return ( aFamily->GetId() == anID );
921 /*! \brief Reading the structured mesh and convert to non structured (by filling of smesh structure for non structured mesh)
922 * \param theWrapper - PWrapper const pointer
923 * \param theMeshInfo - PMeshInfo const pointer
924 * \return TRUE, if successfully. Else FALSE
926 bool DriverMED_R_SMESHDS_Mesh::buildMeshGrille(const MED::PWrapper& theWrapper,
927 const MED::PMeshInfo& theMeshInfo)
931 MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
932 MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
933 MED::TInt aNbCells = aGrilleInfo->GetNbCells();
934 MED::TInt aMeshDim = theMeshInfo->GetDim();
935 DriverMED_FamilyPtr aFamily;
936 for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
937 double aCoords[3] = {0.0, 0.0, 0.0};
938 const SMDS_MeshNode* aNode;
939 MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
940 for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
941 aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
942 aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],(int)iNode);
944 if((aGrilleInfo->myFamNumNode).size() > 0){
945 TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
946 if ( checkFamilyID ( aFamily, aFamNum ))
948 aFamily->AddElement(aNode);
949 aFamily->SetType(SMDSAbs_Node);
955 SMDS_MeshElement* anElement = NULL;
956 MED::TIntVector aNodeIds;
957 for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
958 aNodeIds = aGrilleInfo->GetConn(iCell);
959 switch(aGrilleInfo->GetGeom()){
961 if(aNodeIds.size() != 2){
963 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
965 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
970 if(aNodeIds.size() != 4){
972 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
974 anElement = myMesh->AddFaceWithID(aNodeIds[0],
981 if(aNodeIds.size() != 8){
983 EXCEPTION(std::runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
985 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
999 if((aGrilleInfo->myFamNum).size() > 0){
1000 TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1001 if ( checkFamilyID ( aFamily, aFamNum )){
1002 aFamily->AddElement(anElement);
1003 aFamily->SetType(anElement->GetType());