diff --git a/src/Mod/Fem/App/FemMesh.cpp b/src/Mod/Fem/App/FemMesh.cpp index 5ea798208..ba1bb74ec 100644 --- a/src/Mod/Fem/App/FemMesh.cpp +++ b/src/Mod/Fem/App/FemMesh.cpp @@ -56,6 +56,10 @@ #include #include #include +#include +#include +#include +#include #include #include #include @@ -112,7 +116,7 @@ FemMesh::~FemMesh() FemMesh &FemMesh::operator=(const FemMesh& mesh) { if (this != &mesh) { - myMesh = getGenerator()->CreateMesh(0,true); + myMesh = getGenerator()->CreateMesh(0,true); copyMeshData(mesh); } return *this; @@ -309,6 +313,46 @@ void FemMesh::copyMeshData(const FemMesh& mesh) break; } } + + // Copy groups + std::list grpIds = mesh.myMesh->GetGroupIds(); + for (auto it : grpIds) { + // group of source mesh + SMESH_Group* sourceGroup = mesh.myMesh->GetGroup(it); + SMESHDS_GroupBase* sourceGroupDS = sourceGroup->GetGroupDS(); + + int aId; + if (sourceGroupDS->GetType() == SMDSAbs_Node) { + SMESH_Group* targetGroup = this->myMesh->AddGroup(SMDSAbs_Node, sourceGroupDS->GetStoreName(), aId); + if (targetGroup) { + SMESHDS_Group* targetGroupDS = dynamic_cast(targetGroup->GetGroupDS()); + if (targetGroupDS) { + SMDS_ElemIteratorPtr aIter = sourceGroupDS->GetElements(); + while (aIter->more()) { + const SMDS_MeshElement* aElem = aIter->next(); + const SMDS_MeshNode* aNode = meshds->FindNode(aElem->GetID()); + if (aNode) + targetGroupDS->SMDSGroup().Add(aNode); + } + } + } + } + else { + SMESH_Group* targetGroup = this->myMesh->AddGroup(sourceGroupDS->GetType(), sourceGroupDS->GetStoreName(), aId); + if (targetGroup) { + SMESHDS_Group* targetGroupDS = dynamic_cast(targetGroup->GetGroupDS()); + if (targetGroupDS) { + SMDS_ElemIteratorPtr aIter = sourceGroupDS->GetElements(); + while (aIter->more()) { + const SMDS_MeshElement* aElem = aIter->next(); + const SMDS_MeshElement* aElement = meshds->FindElement(aElem->GetID()); + if (aElement) + targetGroupDS->SMDSGroup().Add(aElement); + } + } + } + } + } } const SMESH_Mesh* FemMesh::getSMesh() const @@ -321,7 +365,6 @@ SMESH_Mesh* FemMesh::getSMesh() return myMesh; } - SMESH_Gen * FemMesh::getGenerator() { return SMESH_Gen::get();