1 // SMESH DriverMED : driver to read and write 'med' files
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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_Utilities.hxx"
42 static int MYDEBUG = 0;
44 static int MYDEBUG = 0;
47 #define _EDF_NODE_IDS_
51 void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName)
53 myMeshName = theMeshName;
56 static const SMDS_MeshNode*
57 FindNode(const SMDS_Mesh* theMesh, TInt theId){
58 const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
59 if(aNode) return aNode;
60 EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
64 enum ECoordName{eX, eY, eZ, eNone};
65 typedef TFloat (*TGetCoord)(MED::PNodeInfo&, TInt);
67 template<ECoordName TheCoordId>
68 TFloat GetCoord(MED::PNodeInfo& thePNodeInfo, TInt theElemId){
69 return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId);
73 TFloat GetCoord<eNone>(MED::PNodeInfo& thePNodeInfo, TInt theElemId){
78 static TGetCoord aXYZGetCoord[3] = {
85 static TGetCoord aXYGetCoord[3] = {
91 static TGetCoord aYZGetCoord[3] = {
97 static TGetCoord aXZGetCoord[3] = {
104 static TGetCoord aXGetCoord[3] = {
110 static TGetCoord aYGetCoord[3] = {
116 static TGetCoord aZGetCoord[3] = {
124 MED::PNodeInfo myPNodeInfo;
125 TGetCoord* myGetCoord;
127 TCoordHelper(const MED::PNodeInfo& thePNodeInfo,
128 TGetCoord* theGetCoord):
129 myPNodeInfo(thePNodeInfo),
130 myGetCoord(theGetCoord)
132 virtual ~TCoordHelper(){}
133 TFloat GetCoord(TInt theElemId, TInt theCoodId){
134 return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId);
137 typedef boost::shared_ptr<TCoordHelper> TCoordHelperPtr;
140 Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
142 Status aResult = DRS_FAIL;
145 if(MYDEBUG) MESSAGE("Perform - myFile : "<<myFile);
146 PWrapper aMed = CrWrapper(myFile);
149 if(TInt aNbMeshes = aMed->GetNbMeshes()){
150 for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
151 // Reading the MED mesh
152 //---------------------
153 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
155 if (myMeshId != -1) {
156 ostringstream aMeshNameStr;
157 aMeshNameStr<<myMeshId;
158 aMeshName = aMeshNameStr.str();
160 aMeshName = myMeshName;
162 if(MYDEBUG) MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
163 if(aMeshName != aMeshInfo->GetName()) continue;
165 //TInt aMeshDim = aMeshInfo->GetDim();
167 // Reading MED families to the temporary structure
168 //------------------------------------------------
170 TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
171 if(MYDEBUG) MESSAGE("Read " << aNbFams << " families");
172 for (TInt iFam = 0; iFam < aNbFams; iFam++) {
173 PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
175 TInt aFamId = aFamilyInfo->GetId();
176 if(MYDEBUG) MESSAGE("Family " << aFamId << " :");
178 DriverMED_FamilyPtr aFamily (new DriverMED_Family);
180 TInt aNbGrp = aFamilyInfo->GetNbGroup();
181 if(MYDEBUG) MESSAGE("belong to " << aNbGrp << " groups");
182 for (TInt iGr = 0; iGr < aNbGrp; iGr++) {
183 string aGroupName = aFamilyInfo->GetGroupName(iGr);
184 if(MYDEBUG) MESSAGE(aGroupName);
185 aFamily->AddGroupName(aGroupName);
187 myFamilies[aFamId] = aFamily;
191 // Reading MED nodes to the corresponding SMDS structure
192 //------------------------------------------------------
193 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
195 TCoordHelperPtr aCoordHelperPtr;
197 TInt aMeshDimension = aMeshInfo->GetDim();
198 bool anIsDimPresent[3] = {false, false, false};
199 for(TInt iDim = 0; iDim < aMeshDimension; iDim++){
200 string aDimName = aNodeInfo->GetCoordName(iDim);
201 if(aDimName == "x" || aDimName == "X")
202 anIsDimPresent[eX] = true;
203 else if(aDimName == "y" || aDimName == "Y")
204 anIsDimPresent[eY] = true;
205 else if(aDimName == "z" || aDimName == "Z")
206 anIsDimPresent[eZ] = true;
208 switch(aMeshDimension){
210 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYZGetCoord));
213 if(anIsDimPresent[eY] && anIsDimPresent[eZ])
214 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYZGetCoord));
215 else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
216 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXZGetCoord));
218 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYGetCoord));
221 if(anIsDimPresent[eY])
222 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYGetCoord));
223 else if(anIsDimPresent[eZ])
224 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aZGetCoord));
226 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXGetCoord));
231 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
232 TInt aNbElems = aNodeInfo->GetNbElem();
233 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
234 for(TInt iElem = 0; iElem < aNbElems; iElem++){
235 double aCoords[3] = {0.0, 0.0, 0.0};
236 for(TInt iDim = 0; iDim < 3; iDim++)
237 aCoords[iDim] = aCoordHelperPtr->GetCoord(iElem,iDim);
238 const SMDS_MeshNode* aNode;
240 aNode = myMesh->AddNodeWithID
241 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
243 aNode = myMesh->AddNode
244 (aCoords[0],aCoords[1],aCoords[2]);
246 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
248 // Save reference to this node from its family
249 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
250 if (myFamilies.find(aFamNum) != myFamilies.end())
252 myFamilies[aFamNum]->AddElement(aNode);
253 myFamilies[aFamNum]->SetType(SMDSAbs_Node);
257 // Reading pre information about all MED cells
258 //--------------------------------------------
259 bool takeNumbers = true; // initially we trust the numbers from file
260 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
261 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
262 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
263 const EEntiteMaillage& anEntity = anEntityIter->first;
264 if(anEntity == eNOEUD) continue;
265 // Reading MED cells to the corresponding SMDS structure
266 //------------------------------------------------------
267 const MED::TGeom& aTGeom = anEntityIter->second;
268 MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
269 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
270 const EGeometrieElement& aGeom = anTGeomIter->first;
272 if (aGeom == ePOINT1) {
275 } else if (aGeom == ePOLYGONE) {
276 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
277 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
279 TElemNum aConn = aPolygoneInfo->GetConnectivite();
280 TElemNum aIndex = aPolygoneInfo->GetIndex();
282 TInt nbPolygons = aPolygoneInfo->GetNbElem();
284 for (TInt iPG = 0; iPG < nbPolygons; iPG++) {
286 TInt aCurrPG_FirstNodeIndex = aIndex[iPG] - 1;
287 int nbNodes = aPolygoneInfo->GetNbConn(iPG);
288 std::vector<int> nodes_ids (nbNodes);
289 //for (TInt inode = 0; inode < nbNodes; inode++) {
290 // nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
292 #ifdef _EDF_NODE_IDS_
294 for (TInt inode = 0; inode < nbNodes; inode++) {
295 nodes_ids[inode] = aNodeInfo->GetElemNum(aConn[aCurrPG_FirstNodeIndex + inode] - 1);
298 for (TInt inode = 0; inode < nbNodes; inode++) {
299 nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
303 for (TInt inode = 0; inode < nbNodes; inode++) {
304 nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
308 bool isRenum = false;
309 SMDS_MeshElement* anElement = NULL;
310 TInt aFamNum = aPolygoneInfo->GetFamNum(iPG);
314 anElement = myMesh->AddPolygonalFaceWithID
315 (nodes_ids, aPolygoneInfo->GetElemNum(iPG));
318 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
319 for (int inode = 0; inode < nbNodes; inode++) {
320 nodes[inode] = FindNode(myMesh, nodes_ids[inode]);
322 anElement = myMesh->AddPolygonalFace(nodes);
323 isRenum = anIsElemNum;
325 } catch (const std::exception& exc) {
332 aResult = DRS_WARN_SKIP_ELEM;
337 if (aResult < DRS_WARN_RENUMBER)
338 aResult = DRS_WARN_RENUMBER;
340 if (myFamilies.find(aFamNum) != myFamilies.end()) {
341 // Save reference to this element from its family
342 myFamilies[aFamNum]->AddElement(anElement);
343 myFamilies[aFamNum]->SetType(anElement->GetType());
346 } // for (TInt iPG = 0; iPG < nbPolygons; iPG++)
349 } else if (aGeom == ePOLYEDRE) {
350 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
351 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
353 TElemNum aConn = aPolyedreInfo->GetConnectivite();
354 TElemNum aFacesIndex = aPolyedreInfo->GetFacesIndex();
355 TElemNum aIndex = aPolyedreInfo->GetIndex();
357 TInt nbPolyedres = aPolyedreInfo->GetNbElem();
359 for (int iPE = 0; iPE < nbPolyedres; iPE++) {
361 int aCurrPE_FirstFaceIndex = aIndex[iPE] - 1;
362 int aNextPE_FirstFaceIndex = aIndex[iPE + 1] - 1;
363 int nbFaces = aNextPE_FirstFaceIndex - aCurrPE_FirstFaceIndex;
364 std::vector<int> quantities (nbFaces);
365 for (int iFa = 0; iFa < nbFaces; iFa++) {
366 int aCurrFace_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex + iFa] - 1;
367 int aNextFace_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex + iFa + 1] - 1;
369 int nbNodes = aNextFace_FirstNodeIndex - aCurrFace_FirstNodeIndex;
370 quantities[iFa] = nbNodes;
374 int aCurrPE_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex] - 1;
375 int nbPENodes = aPolyedreInfo->GetNbConn(iPE);
376 std::vector<int> nodes_ids (nbPENodes);
377 //for (int inode = 0; inode < nbPENodes; inode++) {
378 // nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
380 #ifdef _EDF_NODE_IDS_
382 for (int inode = 0; inode < nbPENodes; inode++) {
383 nodes_ids[inode] = aNodeInfo->GetElemNum(aConn[aCurrPE_FirstNodeIndex + inode] - 1);
386 for (int inode = 0; inode < nbPENodes; inode++) {
387 nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
391 for (int inode = 0; inode < nbPENodes; inode++) {
392 nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
396 bool isRenum = false;
397 SMDS_MeshElement* anElement = NULL;
398 TInt aFamNum = aPolyedreInfo->GetFamNum(iPE);
402 anElement = myMesh->AddPolyhedralVolumeWithID
403 (nodes_ids, quantities, aPolyedreInfo->GetElemNum(iPE));
406 std::vector<const SMDS_MeshNode*> nodes (nbPENodes);
407 for (int inode = 0; inode < nbPENodes; inode++) {
408 nodes[inode] = FindNode(myMesh, nodes_ids[inode]);
410 anElement = myMesh->AddPolyhedralVolume(nodes, quantities);
411 isRenum = anIsElemNum;
413 } catch (const std::exception& exc) {
420 aResult = DRS_WARN_SKIP_ELEM;
425 if (aResult < DRS_WARN_RENUMBER)
426 aResult = DRS_WARN_RENUMBER;
428 if (myFamilies.find(aFamNum) != myFamilies.end()) {
429 // Save reference to this element from its family
430 myFamilies[aFamNum]->AddElement(anElement);
431 myFamilies[aFamNum]->SetType(anElement->GetType());
434 } // for (int iPE = 0; iPE < nbPolyedres; iPE++)
440 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
441 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
442 TInt aNbElems = aCellInfo->GetNbElem();
443 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
444 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
446 for(int iElem = 0; iElem < aNbElems; iElem++){
479 vector<TInt> aNodeIds(aNbNodes);
480 bool anIsValidConnect = false;
483 #ifdef _EDF_NODE_IDS_
485 for(int i = 0; i < aNbNodes; i++){
486 aNodeIds[i] = aNodeInfo->GetElemNum(aCellInfo->GetConn(iElem,i)-1);
489 for(int i = 0; i < aNbNodes; i++){
490 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
494 for(int i = 0; i < aNbNodes; i++){
495 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
498 anIsValidConnect = true;
499 }catch(const std::exception& exc){
500 //INFOS("Follow exception was cought:\n\t"<<exc.what());
503 //INFOS("Unknown exception was cought !!!");
507 if(!anIsValidConnect)
510 bool isRenum = false;
511 SMDS_MeshElement* anElement = NULL;
512 TInt aFamNum = aCellInfo->GetFamNum(iElem);
514 //MESSAGE("Try to create element # " << iElem << " with id = "
515 // << aCellInfo->GetElemNum(iElem));
520 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
522 aCellInfo->GetElemNum(iElem));
524 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
525 FindNode(myMesh,aNodeIds[1]));
526 isRenum = anIsElemNum;
533 anElement = myMesh->AddFaceWithID(aNodeIds[0],
536 aCellInfo->GetElemNum(iElem));
538 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
539 FindNode(myMesh,aNodeIds[1]),
540 FindNode(myMesh,aNodeIds[2]));
541 isRenum = anIsElemNum;
547 // There is some differnce between SMDS and MED
549 anElement = myMesh->AddFaceWithID(aNodeIds[0],
553 aCellInfo->GetElemNum(iElem));
555 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
556 FindNode(myMesh,aNodeIds[1]),
557 FindNode(myMesh,aNodeIds[2]),
558 FindNode(myMesh,aNodeIds[3]));
559 isRenum = anIsElemNum;
566 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
570 aCellInfo->GetElemNum(iElem));
572 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
573 FindNode(myMesh,aNodeIds[1]),
574 FindNode(myMesh,aNodeIds[2]),
575 FindNode(myMesh,aNodeIds[3]));
576 isRenum = anIsElemNum;
582 // There is some differnce between SMDS and MED
584 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 isRenum = anIsElemNum;
603 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
609 aCellInfo->GetElemNum(iElem));
611 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
612 FindNode(myMesh,aNodeIds[1]),
613 FindNode(myMesh,aNodeIds[2]),
614 FindNode(myMesh,aNodeIds[3]),
615 FindNode(myMesh,aNodeIds[4]),
616 FindNode(myMesh,aNodeIds[5]));
617 isRenum = anIsElemNum;
624 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
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 isRenum = anIsElemNum;
646 }catch(const std::exception& exc){
647 //INFOS("Follow exception was cought:\n\t"<<exc.what());
650 //INFOS("Unknown exception was cought !!!");
655 aResult = DRS_WARN_SKIP_ELEM;
661 if (aResult < DRS_WARN_RENUMBER)
662 aResult = DRS_WARN_RENUMBER;
664 if (myFamilies.find(aFamNum) != myFamilies.end()) {
665 // Save reference to this element from its family
666 myFamilies[aFamNum]->AddElement(anElement);
667 myFamilies[aFamNum]->SetType(anElement->GetType());
676 }catch(const std::exception& exc){
677 INFOS("Follow exception was cought:\n\t"<<exc.what());
680 INFOS("Unknown exception was cought !!!");
683 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
687 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
689 list<string> aMeshNames;
692 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
694 PWrapper aMed = CrWrapper(myFile);
696 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
697 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
698 // Reading the MED mesh
699 //---------------------
700 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
701 aMeshNames.push_back(aMeshInfo->GetName());
704 }catch(const std::exception& exc){
705 INFOS("Follow exception was cought:\n\t"<<exc.what());
706 theStatus = DRS_FAIL;
708 INFOS("Unknown exception was cought !!!");
709 theStatus = DRS_FAIL;
715 list<string> DriverMED_R_SMESHDS_Mesh::GetGroupNames()
717 list<string> aResult;
718 set<string> aResGroupNames;
720 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
721 for (; aFamsIter != myFamilies.end(); aFamsIter++)
723 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
724 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
725 set<string>::iterator aGrNamesIter = aGroupNames.begin();
726 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
728 string aName = *aGrNamesIter;
729 // Check, if this is a Group or SubMesh name
730 //if (aName.substr(0, 5) == string("Group")) {
731 if (aResGroupNames.find(aName) == aResGroupNames.end()) {
732 aResGroupNames.insert(aName);
733 aResult.push_back(aName);
742 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
744 string aGroupName (theGroup->GetStoreName());
745 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
747 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
748 for (; aFamsIter != myFamilies.end(); aFamsIter++)
750 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
751 if (aFamily->MemberOf(aGroupName))
753 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
754 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
755 const SMDS_MeshElement * element = 0;
756 for (; anElemsIter != anElements.end(); anElemsIter++)
758 element = *anElemsIter;
759 theGroup->SMDSGroup().Add(element);
762 theGroup->SetType( element->GetType() );
767 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
770 char submeshGrpName[ 30 ];
771 sprintf( submeshGrpName, "SubMesh %d", theId );
772 string aName (submeshGrpName);
773 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
774 for (; aFamsIter != myFamilies.end(); aFamsIter++)
776 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
777 if (aFamily->MemberOf(aName))
779 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
780 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
781 if (aFamily->GetType() == SMDSAbs_Node)
783 for (; anElemsIter != anElements.end(); anElemsIter++)
785 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
786 theSubMesh->AddNode(node);
791 for (; anElemsIter != anElements.end(); anElemsIter++)
793 theSubMesh->AddElement(*anElemsIter);
800 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
802 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
803 for (; aFamsIter != myFamilies.end(); aFamsIter++)
805 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
806 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
807 set<string>::iterator aGrNamesIter = aGroupNames.begin();
808 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
810 string aName = *aGrNamesIter;
811 // Check, if this is a Group or SubMesh name
812 if (aName.substr(0, 7) == string("SubMesh"))
814 int Id = atoi(string(aName).substr(7).c_str());
815 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
816 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
817 if (aFamily->GetType() == SMDSAbs_Node)
819 for (; anElemsIter != anElements.end(); anElemsIter++)
821 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
822 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
823 // find out a shape type
824 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
825 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
826 switch ( aShapeType ) {
828 myMesh->SetNodeOnFace(node, Id); break;
830 myMesh->SetNodeOnEdge(node, Id); break;
832 myMesh->SetNodeOnVertex(node, Id); break;
834 myMesh->SetNodeInVolume(node, Id);
840 for (; anElemsIter != anElements.end(); anElemsIter++)
842 myMesh->SetMeshElementOnShape(*anElemsIter, Id);