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 aFamily->SetId( aFamId );
188 myFamilies[aFamId] = aFamily;
192 // Reading MED nodes to the corresponding SMDS structure
193 //------------------------------------------------------
194 PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
196 TCoordHelperPtr aCoordHelperPtr;
198 TInt aMeshDimension = aMeshInfo->GetDim();
199 bool anIsDimPresent[3] = {false, false, false};
200 for(TInt iDim = 0; iDim < aMeshDimension; iDim++){
201 string aDimName = aNodeInfo->GetCoordName(iDim);
202 if(aDimName == "x" || aDimName == "X")
203 anIsDimPresent[eX] = true;
204 else if(aDimName == "y" || aDimName == "Y")
205 anIsDimPresent[eY] = true;
206 else if(aDimName == "z" || aDimName == "Z")
207 anIsDimPresent[eZ] = true;
209 switch(aMeshDimension){
211 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYZGetCoord));
214 if(anIsDimPresent[eY] && anIsDimPresent[eZ])
215 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYZGetCoord));
216 else if(anIsDimPresent[eX] && anIsDimPresent[eZ])
217 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXZGetCoord));
219 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYGetCoord));
222 if(anIsDimPresent[eY])
223 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYGetCoord));
224 else if(anIsDimPresent[eZ])
225 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aZGetCoord));
227 aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXGetCoord));
232 EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
233 TInt aNbElems = aNodeInfo->GetNbElem();
234 if(MYDEBUG) MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
235 DriverMED_FamilyPtr aFamily;
236 for(TInt iElem = 0; iElem < aNbElems; iElem++){
237 double aCoords[3] = {0.0, 0.0, 0.0};
238 for(TInt iDim = 0; iDim < 3; iDim++)
239 aCoords[iDim] = aCoordHelperPtr->GetCoord(iElem,iDim);
240 const SMDS_MeshNode* aNode;
242 aNode = myMesh->AddNodeWithID
243 (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
245 aNode = myMesh->AddNode
246 (aCoords[0],aCoords[1],aCoords[2]);
248 //cout<<aNode->GetID()<<": "<<aNode->X()<<", "<<aNode->Y()<<", "<<aNode->Z()<<endl;
250 // Save reference to this node from its family
251 TInt aFamNum = aNodeInfo->GetFamNum(iElem);
252 if ( checkFamilyID ( aFamily, aFamNum ))
254 aFamily->AddElement(aNode);
255 aFamily->SetType(SMDSAbs_Node);
259 // Reading pre information about all MED cells
260 //--------------------------------------------
261 bool takeNumbers = true; // initially we trust the numbers from file
262 MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo);
263 MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
264 for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
265 const EEntiteMaillage& anEntity = anEntityIter->first;
266 if(anEntity == eNOEUD) continue;
267 // Reading MED cells to the corresponding SMDS structure
268 //------------------------------------------------------
269 const MED::TGeom& aTGeom = anEntityIter->second;
270 MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
271 for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
272 const EGeometrieElement& aGeom = anTGeomIter->first;
274 if (aGeom == ePOINT1) {
277 } else if (aGeom == ePOLYGONE) {
278 PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
279 EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
281 TElemNum aConn = aPolygoneInfo->GetConnectivite();
282 TElemNum aIndex = aPolygoneInfo->GetIndex();
284 TInt nbPolygons = aPolygoneInfo->GetNbElem();
286 for (TInt iPG = 0; iPG < nbPolygons; iPG++) {
288 TInt aCurrPG_FirstNodeIndex = aIndex[iPG] - 1;
289 int nbNodes = aPolygoneInfo->GetNbConn(iPG);
290 std::vector<int> nodes_ids (nbNodes);
291 //for (TInt inode = 0; inode < nbNodes; inode++) {
292 // nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
294 #ifdef _EDF_NODE_IDS_
296 for (TInt inode = 0; inode < nbNodes; inode++) {
297 nodes_ids[inode] = aNodeInfo->GetElemNum(aConn[aCurrPG_FirstNodeIndex + inode] - 1);
300 for (TInt inode = 0; inode < nbNodes; inode++) {
301 nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
305 for (TInt inode = 0; inode < nbNodes; inode++) {
306 nodes_ids[inode] = aConn[aCurrPG_FirstNodeIndex + inode];
310 bool isRenum = false;
311 SMDS_MeshElement* anElement = NULL;
312 TInt aFamNum = aPolygoneInfo->GetFamNum(iPG);
316 anElement = myMesh->AddPolygonalFaceWithID
317 (nodes_ids, aPolygoneInfo->GetElemNum(iPG));
320 std::vector<const SMDS_MeshNode*> nodes (nbNodes);
321 for (int inode = 0; inode < nbNodes; inode++) {
322 nodes[inode] = FindNode(myMesh, nodes_ids[inode]);
324 anElement = myMesh->AddPolygonalFace(nodes);
325 isRenum = anIsElemNum;
327 } catch (const std::exception& exc) {
334 aResult = DRS_WARN_SKIP_ELEM;
339 if (aResult < DRS_WARN_RENUMBER)
340 aResult = DRS_WARN_RENUMBER;
342 if ( checkFamilyID ( aFamily, aFamNum ))
344 // Save reference to this element from its family
345 aFamily->AddElement(anElement);
346 aFamily->SetType(anElement->GetType());
349 } // for (TInt iPG = 0; iPG < nbPolygons; iPG++)
352 } else if (aGeom == ePOLYEDRE) {
353 PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
354 EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
356 TElemNum aConn = aPolyedreInfo->GetConnectivite();
357 TElemNum aFacesIndex = aPolyedreInfo->GetFacesIndex();
358 TElemNum aIndex = aPolyedreInfo->GetIndex();
360 TInt nbPolyedres = aPolyedreInfo->GetNbElem();
362 for (int iPE = 0; iPE < nbPolyedres; iPE++) {
364 int aCurrPE_FirstFaceIndex = aIndex[iPE] - 1;
365 int aNextPE_FirstFaceIndex = aIndex[iPE + 1] - 1;
366 int nbFaces = aNextPE_FirstFaceIndex - aCurrPE_FirstFaceIndex;
367 std::vector<int> quantities (nbFaces);
368 for (int iFa = 0; iFa < nbFaces; iFa++) {
369 int aCurrFace_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex + iFa] - 1;
370 int aNextFace_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex + iFa + 1] - 1;
372 int nbNodes = aNextFace_FirstNodeIndex - aCurrFace_FirstNodeIndex;
373 quantities[iFa] = nbNodes;
377 int aCurrPE_FirstNodeIndex = aFacesIndex[aCurrPE_FirstFaceIndex] - 1;
378 int nbPENodes = aPolyedreInfo->GetNbConn(iPE);
379 std::vector<int> nodes_ids (nbPENodes);
380 //for (int inode = 0; inode < nbPENodes; inode++) {
381 // nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
383 #ifdef _EDF_NODE_IDS_
385 for (int inode = 0; inode < nbPENodes; inode++) {
386 nodes_ids[inode] = aNodeInfo->GetElemNum(aConn[aCurrPE_FirstNodeIndex + inode] - 1);
389 for (int inode = 0; inode < nbPENodes; inode++) {
390 nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
394 for (int inode = 0; inode < nbPENodes; inode++) {
395 nodes_ids[inode] = aConn[aCurrPE_FirstNodeIndex + inode];
399 bool isRenum = false;
400 SMDS_MeshElement* anElement = NULL;
401 TInt aFamNum = aPolyedreInfo->GetFamNum(iPE);
405 anElement = myMesh->AddPolyhedralVolumeWithID
406 (nodes_ids, quantities, aPolyedreInfo->GetElemNum(iPE));
409 std::vector<const SMDS_MeshNode*> nodes (nbPENodes);
410 for (int inode = 0; inode < nbPENodes; inode++) {
411 nodes[inode] = FindNode(myMesh, nodes_ids[inode]);
413 anElement = myMesh->AddPolyhedralVolume(nodes, quantities);
414 isRenum = anIsElemNum;
416 } catch (const std::exception& exc) {
423 aResult = DRS_WARN_SKIP_ELEM;
428 if (aResult < DRS_WARN_RENUMBER)
429 aResult = DRS_WARN_RENUMBER;
431 if ( checkFamilyID ( aFamily, aFamNum ))
433 // Save reference to this element from its family
434 aFamily->AddElement(anElement);
435 aFamily->SetType(anElement->GetType());
438 } // for (int iPE = 0; iPE < nbPolyedres; iPE++)
444 PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
445 EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
446 TInt aNbElems = aCellInfo->GetNbElem();
447 if(MYDEBUG) MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
448 if(MYDEBUG) MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
450 for(int iElem = 0; iElem < aNbElems; iElem++){
483 vector<TInt> aNodeIds(aNbNodes);
484 bool anIsValidConnect = false;
487 #ifdef _EDF_NODE_IDS_
489 for(int i = 0; i < aNbNodes; i++){
490 aNodeIds[i] = aNodeInfo->GetElemNum(aCellInfo->GetConn(iElem,i)-1);
493 for(int i = 0; i < aNbNodes; i++){
494 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
498 for(int i = 0; i < aNbNodes; i++){
499 aNodeIds[i] = aCellInfo->GetConn(iElem,i);
502 anIsValidConnect = true;
503 }catch(const std::exception& exc){
504 //INFOS("Follow exception was cought:\n\t"<<exc.what());
507 //INFOS("Unknown exception was cought !!!");
511 if(!anIsValidConnect)
514 bool isRenum = false;
515 SMDS_MeshElement* anElement = NULL;
516 TInt aFamNum = aCellInfo->GetFamNum(iElem);
518 //MESSAGE("Try to create element # " << iElem << " with id = "
519 // << aCellInfo->GetElemNum(iElem));
524 anElement = myMesh->AddEdgeWithID(aNodeIds[0],
526 aCellInfo->GetElemNum(iElem));
528 anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
529 FindNode(myMesh,aNodeIds[1]));
530 isRenum = anIsElemNum;
537 anElement = myMesh->AddFaceWithID(aNodeIds[0],
540 aCellInfo->GetElemNum(iElem));
542 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
543 FindNode(myMesh,aNodeIds[1]),
544 FindNode(myMesh,aNodeIds[2]));
545 isRenum = anIsElemNum;
551 // There is some differnce between SMDS and MED
553 anElement = myMesh->AddFaceWithID(aNodeIds[0],
557 aCellInfo->GetElemNum(iElem));
559 anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
560 FindNode(myMesh,aNodeIds[1]),
561 FindNode(myMesh,aNodeIds[2]),
562 FindNode(myMesh,aNodeIds[3]));
563 isRenum = anIsElemNum;
570 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
574 aCellInfo->GetElemNum(iElem));
576 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
577 FindNode(myMesh,aNodeIds[1]),
578 FindNode(myMesh,aNodeIds[2]),
579 FindNode(myMesh,aNodeIds[3]));
580 isRenum = anIsElemNum;
586 // There is some differnce between SMDS and MED
588 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
593 aCellInfo->GetElemNum(iElem));
595 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
596 FindNode(myMesh,aNodeIds[1]),
597 FindNode(myMesh,aNodeIds[2]),
598 FindNode(myMesh,aNodeIds[3]),
599 FindNode(myMesh,aNodeIds[4]));
600 isRenum = anIsElemNum;
607 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
613 aCellInfo->GetElemNum(iElem));
615 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
616 FindNode(myMesh,aNodeIds[1]),
617 FindNode(myMesh,aNodeIds[2]),
618 FindNode(myMesh,aNodeIds[3]),
619 FindNode(myMesh,aNodeIds[4]),
620 FindNode(myMesh,aNodeIds[5]));
621 isRenum = anIsElemNum;
628 anElement = myMesh->AddVolumeWithID(aNodeIds[0],
636 aCellInfo->GetElemNum(iElem));
638 anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
639 FindNode(myMesh,aNodeIds[1]),
640 FindNode(myMesh,aNodeIds[2]),
641 FindNode(myMesh,aNodeIds[3]),
642 FindNode(myMesh,aNodeIds[4]),
643 FindNode(myMesh,aNodeIds[5]),
644 FindNode(myMesh,aNodeIds[6]),
645 FindNode(myMesh,aNodeIds[7]));
646 isRenum = anIsElemNum;
650 }catch(const std::exception& exc){
651 //INFOS("Follow exception was cought:\n\t"<<exc.what());
654 //INFOS("Unknown exception was cought !!!");
659 aResult = DRS_WARN_SKIP_ELEM;
665 if (aResult < DRS_WARN_RENUMBER)
666 aResult = DRS_WARN_RENUMBER;
668 if ( checkFamilyID ( aFamily, aFamNum ))
670 // Save reference to this element from its family
671 aFamily->AddElement(anElement);
672 aFamily->SetType(anElement->GetType());
681 }catch(const std::exception& exc){
682 INFOS("Follow exception was cought:\n\t"<<exc.what());
685 INFOS("Unknown exception was cought !!!");
688 if(MYDEBUG) MESSAGE("Perform - aResult status = "<<aResult);
692 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
694 list<string> aMeshNames;
697 if(MYDEBUG) MESSAGE("GetMeshNames - myFile : " << myFile);
699 PWrapper aMed = CrWrapper(myFile);
701 if (TInt aNbMeshes = aMed->GetNbMeshes()) {
702 for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
703 // Reading the MED mesh
704 //---------------------
705 PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
706 aMeshNames.push_back(aMeshInfo->GetName());
709 }catch(const std::exception& exc){
710 INFOS("Follow exception was cought:\n\t"<<exc.what());
711 theStatus = DRS_FAIL;
713 INFOS("Unknown exception was cought !!!");
714 theStatus = DRS_FAIL;
720 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
722 list<TNameAndType> aResult;
723 set<TNameAndType> aResGroupNames;
725 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
726 for (; aFamsIter != myFamilies.end(); aFamsIter++)
728 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
729 const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
730 set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
731 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
733 TNameAndType aNameAndType = make_pair( *aGrNamesIter, aFamily->GetType() );
734 // Check, if this is a Group or SubMesh name
735 //if (aName.substr(0, 5) == string("Group")) {
736 if ( aResGroupNames.insert( aNameAndType ).second ) {
737 aResult.push_back( aNameAndType );
746 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
748 string aGroupName (theGroup->GetStoreName());
749 if(MYDEBUG) MESSAGE("Get Group " << aGroupName);
751 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
752 for (; aFamsIter != myFamilies.end(); aFamsIter++)
754 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
755 if (aFamily->GetType() == theGroup->GetType() && aFamily->MemberOf(aGroupName))
757 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
758 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
759 const SMDS_MeshElement * element = 0;
760 for (; anElemsIter != anElements.end(); anElemsIter++)
762 element = *anElemsIter;
763 theGroup->SMDSGroup().Add(element);
766 theGroup->SetType( element->GetType() );
771 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
774 char submeshGrpName[ 30 ];
775 sprintf( submeshGrpName, "SubMesh %d", theId );
776 string aName (submeshGrpName);
777 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
778 for (; aFamsIter != myFamilies.end(); aFamsIter++)
780 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
781 if (aFamily->MemberOf(aName))
783 const set<const SMDS_MeshElement *>& anElements = aFamily->GetElements();
784 set<const SMDS_MeshElement *>::const_iterator anElemsIter = anElements.begin();
785 if (aFamily->GetType() == SMDSAbs_Node)
787 for (; anElemsIter != anElements.end(); anElemsIter++)
789 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
790 theSubMesh->AddNode(node);
795 for (; anElemsIter != anElements.end(); anElemsIter++)
797 theSubMesh->AddElement(*anElemsIter);
804 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
806 map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
807 for (; aFamsIter != myFamilies.end(); aFamsIter++)
809 DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
810 MED::TStringSet aGroupNames = aFamily->GetGroupNames();
811 set<string>::iterator aGrNamesIter = aGroupNames.begin();
812 for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
814 string aName = *aGrNamesIter;
815 // Check, if this is a Group or SubMesh name
816 if (aName.substr(0, 7) == string("SubMesh"))
818 int Id = atoi(string(aName).substr(7).c_str());
819 set<const SMDS_MeshElement *> anElements = aFamily->GetElements();
820 set<const SMDS_MeshElement *>::iterator anElemsIter = anElements.begin();
821 if (aFamily->GetType() == SMDSAbs_Node)
823 for (; anElemsIter != anElements.end(); anElemsIter++)
825 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>
826 ( static_cast<const SMDS_MeshNode*>( *anElemsIter ));
827 // find out a shape type
828 TopoDS_Shape aShape = myMesh->IndexToShape( Id );
829 int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
830 switch ( aShapeType ) {
832 myMesh->SetNodeOnFace(node, Id); break;
834 myMesh->SetNodeOnEdge(node, Id); break;
836 myMesh->SetNodeOnVertex(node, Id); break;
838 myMesh->SetNodeInVolume(node, Id);
844 for (; anElemsIter != anElements.end(); anElemsIter++)
846 myMesh->SetMeshElementOnShape(*anElemsIter, Id);
854 * \brief Ensure aFamily to have required ID
855 * \param aFamily - a family to check and update
856 * \param anID - an ID aFamily should have
857 * \retval bool - true if successful
859 bool DriverMED_R_SMESHDS_Mesh::checkFamilyID(DriverMED_FamilyPtr & aFamily, int anID) const
861 if ( !aFamily || aFamily->GetId() != anID ) {
862 map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
863 if ( i_fam == myFamilies.end() )
865 aFamily = i_fam->second;
867 return ( aFamily->GetId() == anID );