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();
283 for (TInt iPG = 0; iPG < nbPolygons; iPG++) {
285 TInt aCurrPG_FirstNodeIndex = aIndex[iPG] - 1;
286 int aNbNodes = aPolygoneInfo->GetNbConn(iPG);
287 std::vector<int> nodes_ids (aNbNodes);
288 for (TInt inode = 0; inode < aNbNodes; inode++) {
289 nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
292 bool isRenum = false;
293 SMDS_MeshElement* anElement = NULL;
294 TInt aFamNum = aPolygoneInfo->GetFamNum(iPG);
298 anElement = myMesh->AddPolygonalFaceWithID
299 (nodes_ids, aPolygoneInfo->GetElemNum(iPG));
302 std::vector<const SMDS_MeshNode*> nodes (aNbNodes);
303 for (int inode = 0; inode < aNbNodes; inode++) {
304 nodes[inode] = FindNode(myMesh, nodes_ids[inode]);
306 anElement = myMesh->AddPolygonalFace(nodes);
307 isRenum = anIsElemNum;
310 } catch (const std::exception& exc) {
312 INFOS("Follow exception was cought:\n\t"<<exc.what());
315 INFOS("Follow unknown exception was cought!");
319 aResult = DRS_WARN_SKIP_ELEM;
324 if (aResult < DRS_WARN_RENUMBER)
325 aResult = DRS_WARN_RENUMBER;
327 if (myFamilies.find(aFamNum) != myFamilies.end()) {
328 // Save reference to this element from its family
330 cout<<"myFamilies["<<aFamNum
331 <<"] IsPoly()="<<anElement->IsPoly()
332 <<"; GetType="<<anElement->GetType()
333 <<"; aNbNodes="<<aNbNodes<<endl;
335 myFamilies[aFamNum]->AddElement(anElement);
336 myFamilies[aFamNum]->SetType(anElement->GetType());
342 } else if (aGeom == ePOLYEDRE) {
343 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
344 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
346 TElemNum aConn = aPolyedreInfo->GetConnectivite();
347 TElemNum aFacesIndex = aPolyedreInfo->GetFacesIndex();
348 TElemNum aIndex = aPolyedreInfo->GetIndex();
350 TInt nbPolyedres = aPolyedreInfo->GetNbElem();
352 for (int iPE = 0; iPE < nbPolyedres; iPE++) {
354 int aCurrPE_FirstFaceIndex = aIndex[iPE] - 1;
355 int aNextPE_FirstFaceIndex = aIndex[iPE + 1] - 1;
356 int nbFaces = aNextPE_FirstFaceIndex - aCurrPE_FirstFaceIndex;
357 std::vector<int> quantities (nbFaces);
358 for (int iFa = 0; iFa < nbFaces; iFa++) {
359 int aCurrFace_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex + iFa] - 1;
360 int aNextFace_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex + iFa + 1] - 1;
362 int aNbNodes = aNextFace_FirstNodeIndex - aCurrFace_FirstNodeIndex;
363 quantities[iFa] = aNbNodes;
367 int aCurrPE_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex] - 1;
368 int nbPENodes = aPolyedreInfo->GetNbConn(iPE);
369 std::vector<int> nodes_ids (nbPENodes);
370 for (int inode = 0; inode < nbPENodes; inode++) {
371 nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
374 bool isRenum = false;
375 SMDS_MeshElement* anElement = NULL;
376 TInt aFamNum = aPolyedreInfo->GetFamNum(iPE);
380 anElement = myMesh->AddPolyhedralVolumeWithID
381 (nodes_ids, quantities, aPolyedreInfo->GetElemNum(iPE));
384 std::vector<const SMDS_MeshNode*> nodes (nbPENodes);
385 for (int inode = 0; inode < nbPENodes; inode++) {
386 nodes[inode] = FindNode(myMesh, nodes_ids[inode]);
388 anElement = myMesh->AddPolyhedralVolume(nodes, quantities);
389 isRenum = anIsElemNum;
391 } catch (const std::exception& exc) {
393 INFOS("Follow exception was cought:\n\t"<<exc.what());
396 INFOS("Follow unknown exception was cought!");
400 aResult = DRS_WARN_SKIP_ELEM;
405 if (aResult < DRS_WARN_RENUMBER)
406 aResult = DRS_WARN_RENUMBER;
408 if (myFamilies.find(aFamNum) != myFamilies.end()) {
409 // Save reference to this element from its family
411 cout<<"myFamilies["<<aFamNum
412 <<"] IsPoly()="<<anElement->IsPoly()
413 <<"; GetType="<<anElement->GetType()
414 <<"; aNbNodes="<<nbPENodes<<endl;
416 myFamilies[aFamNum]->AddElement(anElement);
417 myFamilies[aFamNum]->SetType(anElement->GetType());
425 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
426 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
427 TInt aNbElems = aCellInfo->GetNbElem();
428 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
429 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
431 for(int iElem = 0; iElem < aNbElems; iElem++){
464 vector<TInt> aNodeIds(aNbNodes);
465 bool anIsValidConnect = false;
468 #ifdef _EDF_NODE_IDS_
470 for(int i = 0; i < aNbNodes; i++){
471 aNodeIds[i] = aNodeInfo->GetElemNum(aCellInfo->GetConn(iElem,i)-1);
474 for(int i = 0; i < aNbNodes; i++){
475 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
479 for(int i = 0; i < aNbNodes; i++){
480 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
483 anIsValidConnect = true;
484 }catch(const std::exception& exc){
485 //INFOS("Follow exception was cought:\n\t"<<exc.what());
488 //INFOS("Unknown exception was cought !!!");
492 if(!anIsValidConnect)
495 bool isRenum = false;
496 SMDS_MeshElement* anElement = NULL;
497 TInt aFamNum = aCellInfo->GetFamNum(iElem);
503 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
505 aCellInfo->GetElemNum(iElem));
507 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
508 FindNode(myMesh,aNodeIds[1]));
509 isRenum = anIsElemNum;
516 anElement = myMesh->AddFaceWithID(aNodeIds[0],
519 aCellInfo->GetElemNum(iElem));
521 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
522 FindNode(myMesh,aNodeIds[1]),
523 FindNode(myMesh,aNodeIds[2]));
524 isRenum = anIsElemNum;
530 // There is some differnce between SMDS and MED
532 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 FindNode(myMesh,aNodeIds[3]));
542 isRenum = anIsElemNum;
549 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
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 isRenum = anIsElemNum;
565 // There is some differnce between SMDS and MED
567 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
572 aCellInfo->GetElemNum(iElem));
574 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
575 FindNode(myMesh,aNodeIds[1]),
576 FindNode(myMesh,aNodeIds[2]),
577 FindNode(myMesh,aNodeIds[3]),
578 FindNode(myMesh,aNodeIds[4]));
579 isRenum = anIsElemNum;
586 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
592 aCellInfo->GetElemNum(iElem));
594 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
595 FindNode(myMesh,aNodeIds[1]),
596 FindNode(myMesh,aNodeIds[2]),
597 FindNode(myMesh,aNodeIds[3]),
598 FindNode(myMesh,aNodeIds[4]),
599 FindNode(myMesh,aNodeIds[5]));
600 isRenum = anIsElemNum;
607 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
615 aCellInfo->GetElemNum(iElem));
617 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
618 FindNode(myMesh,aNodeIds[1]),
619 FindNode(myMesh,aNodeIds[2]),
620 FindNode(myMesh,aNodeIds[3]),
621 FindNode(myMesh,aNodeIds[4]),
622 FindNode(myMesh,aNodeIds[5]),
623 FindNode(myMesh,aNodeIds[6]),
624 FindNode(myMesh,aNodeIds[7]));
625 isRenum = anIsElemNum;
629 }catch(const std::exception& exc){
630 //INFOS("Follow exception was cought:\n\t"<<exc.what());
633 //INFOS("Unknown exception was cought !!!");
638 aResult = DRS_WARN_SKIP_ELEM;
644 if (aResult < DRS_WARN_RENUMBER)
645 aResult = DRS_WARN_RENUMBER;
647 if (myFamilies.find(aFamNum) != myFamilies.end()) {
648 // Save reference to this element from its family
649 myFamilies[aFamNum]->AddElement(anElement);
650 myFamilies[aFamNum]->SetType(anElement->GetType());
659 }catch(const std::exception& exc){
660 INFOS("Follow exception was cought:\n\t"<<exc.what());
663 INFOS("Unknown exception was cought !!!");
666 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
670 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
672 list<string> aMeshNames;
675 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
677 PWrapper aMed = CrWrapper(myFile);
679 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
680 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
681 // Reading the MED mesh
682 //---------------------
683 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
684 aMeshNames.push_back(aMeshInfo->GetName());
687 }catch(const std::exception& exc){
688 INFOS("Follow exception was cought:\n\t"<<exc.what());
689 theStatus = DRS_FAIL;
691 INFOS("Unknown exception was cought !!!");
692 theStatus = DRS_FAIL;
698 list<string> DriverMED_R_SMESHDS_Mesh::GetGroupNames()
700 list<string> aResult;
701 set<string> aResGroupNames;
703 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
704 for (; aFamsIter != myFamilies.end(); aFamsIter++)
706 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
707 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
708 set<string>::iterator aGrNamesIter = aGroupNames.begin();
709 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
711 string aName = *aGrNamesIter;
712 // Check, if this is a Group or SubMesh name
713 //if (aName.substr(0, 5) == string("Group")) {
714 if (aResGroupNames.find(aName) == aResGroupNames.end()) {
715 aResGroupNames.insert(aName);
716 aResult.push_back(aName);
725 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
727 string aGroupName (theGroup->GetStoreName());
728 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
730 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
731 for (; aFamsIter != myFamilies.end(); aFamsIter++)
733 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
734 if (aFamily->MemberOf(aGroupName))
736 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
737 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
738 const SMDS_MeshElement * element = 0;
739 for (; anElemsIter != anElements.end(); anElemsIter++)
741 element = *anElemsIter;
742 theGroup->SMDSGroup().Add(element);
745 theGroup->SetType( element->GetType() );
750 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
753 char submeshGrpName[ 30 ];
754 sprintf( submeshGrpName, "SubMesh %d", theId );
755 string aName (submeshGrpName);
756 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
757 for (; aFamsIter != myFamilies.end(); aFamsIter++)
759 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
760 if (aFamily->MemberOf(aName))
762 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
763 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
764 if (aFamily->GetType() == SMDSAbs_Node)
766 for (; anElemsIter != anElements.end(); anElemsIter++)
768 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
769 theSubMesh->AddNode(node);
774 for (; anElemsIter != anElements.end(); anElemsIter++)
776 theSubMesh->AddElement(*anElemsIter);
783 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
785 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
786 for (; aFamsIter != myFamilies.end(); aFamsIter++)
788 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
789 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
790 set<string>::iterator aGrNamesIter = aGroupNames.begin();
791 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
793 string aName = *aGrNamesIter;
794 // Check, if this is a Group or SubMesh name
795 if (aName.substr(0, 7) == string("SubMesh"))
797 int Id = atoi(string(aName).substr(7).c_str());
798 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
799 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
800 if (aFamily->GetType() == SMDSAbs_Node)
802 for (; anElemsIter != anElements.end(); anElemsIter++)
804 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
805 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
806 // find out a shape type
807 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
808 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
809 switch ( aShapeType ) {
811 myMesh->SetNodeOnFace(node, Id); break;
813 myMesh->SetNodeOnEdge(node, Id); break;
815 myMesh->SetNodeOnVertex(node, Id); break;
817 myMesh->SetNodeInVolume(node, Id);
823 for (; anElemsIter != anElements.end(); anElemsIter++)
825 myMesh->SetMeshElementOnShape(*anElemsIter, Id);