From 0027cfadbd7b3f42b6655bc0e352f5360752c228 Mon Sep 17 00:00:00 2001 From: gdd Date: Wed, 11 May 2011 18:06:56 +0000 Subject: [PATCH] Fix SetEnforcedMesh to work correctly with groups and groups on geom. --- src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx | 358 +++++-------------- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx | 37 +- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx | 2 + src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx | 144 ++++---- 4 files changed, 189 insertions(+), 352 deletions(-) diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index e22d8ac..6a7df36 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -1009,16 +1009,11 @@ static void updateMeshGroups(SMESH_Mesh* theMesh, while (grIt->more()) { SMESH_Group * group = grIt->next(); if ( !group ) continue; - MESSAGE("Group: " << group->GetName()); SMESHDS_GroupBase* groupDS = group->GetGroupDS(); if ( !groupDS ) continue; - MESSAGE("group->SMDSGroup().GetType(): " << (groupDS->GetType())); - MESSAGE("group->SMDSGroup().GetType()==anElem->GetType(): " << (groupDS->GetType()==anElem->GetType())); - MESSAGE("currentEnfVertex->grpName.compare(group->GetStoreName())==0: " << (groupName.compare(group->GetName())==0)); if ( groupDS->GetType()==anElem->GetType() && groupName.compare(group->GetName())==0) { SMESHDS_Group* aGroupDS = static_cast( groupDS ); aGroupDS->SMDSGroup().Add(anElem); - MESSAGE("Elem ID added in group: " << anElem->GetID()); groupDone = true; MESSAGE("Successfully added enforced element to existing group " << groupName); break; @@ -1051,7 +1046,7 @@ static bool readGMFFile(const char* theFile, TopoDS_Shape theSolid, vector & theNodeByGhs3dId, map & theNodeToGhs3dIdMap, - std::map, std::string> & enfVerticesWithGroup, + std::vector & aNodeGroupByGhs3dId, std::vector & anEdgeGroupByGhs3dId, std::vector & aFaceGroupByGhs3dId) { @@ -1194,8 +1189,8 @@ static bool readGMFFile(const char* theFile, coords.push_back(x); coords.push_back(y); coords.push_back(z); - if (enfVerticesWithGroup.find(coords) != enfVerticesWithGroup.end()) - updateMeshGroups(theHelper->GetMesh(), aGMFNode, enfVerticesWithGroup[coords]); + if (aGMFID-1 < aNodeGroupByGhs3dId.size() && !aNodeGroupByGhs3dId.at(aGMFID-1).empty()) + updateMeshGroups(theHelper->GetMesh(), aGMFNode, aNodeGroupByGhs3dId.at(aGMFID-1)); } } } @@ -1285,7 +1280,8 @@ static bool readGMFFile(const char* theFile, case GmfEdges: if (fullyCreatedElement) { aCreatedElem = theHelper->AddEdge( node[0], node[1], /*id =*/0, /*force3d =*/false ); - updateMeshGroups(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem]); + if (!anEdgeGroupByGhs3dId[iElem].empty()) + updateMeshGroups(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem]); } break; case GmfTriangles: @@ -1293,7 +1289,8 @@ static bool readGMFFile(const char* theFile, aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], /*id =*/0, /*force3d =*/false ); for ( int iRef = 0; iRef < nbRef; iRef++ ) nodeAssigne[ nodeID[ iRef ]] = 1; - updateMeshGroups(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem]); + if (!aFaceGroupByGhs3dId[iElem].empty()) + updateMeshGroups(theHelper->GetMesh(), aCreatedElem, aFaceGroupByGhs3dId[iElem]); } break; case GmfQuadrilaterals: @@ -1366,11 +1363,13 @@ static bool writeGMFFile(const char* theMesh std::vector & theNodeByGhs3dId, std::vector & theEnforcedNodeByGhs3dId, std::map & aNodeToGhs3dIdMap, + std::vector & aNodeGroupByGhs3dId, std::vector & anEdgeGroupByGhs3dId, std::vector & aFaceGroupByGhs3dId, GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes, GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles, + std::map, std::string> & enfVerticesWithGroup, GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices) { MESSAGE("writeGMFFile w/o geometry"); @@ -1379,11 +1378,9 @@ static bool writeGMFFile(const char* theMesh GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt; std::vector enfVertexSizes; const SMDS_MeshElement* elem; - TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles/*, theKeptEnforcedQuadrangles*/; - // GHS3D does not accept EdgesP2 in input mesh file (Ghs3d 4.2) -// TIDSortedElemSet aQuadElemSet, aQuadEnforcedEdgeSet, aQuadEnforcedTriangleSet, aQuadEnforcedQuadrangleSet; + TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles; SMDS_ElemIteratorPtr nodeIt; - map /*aNodeToGhs3dIdMap,*/ anEnforcedNodeToGhs3dIdMap; + map anEnforcedNodeToGhs3dIdMap; GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt; TIDSortedElemSet::iterator elemSetIt; bool isOK; @@ -1408,10 +1405,6 @@ static bool writeGMFFile(const char* theMesh while ( eIt->more() ) { elem = eIt->next(); - // GHS3D does not accept EdgesP2 in input mesh file (Ghs3d 4.2) -// if (elem->IsQuadratic()) -// aQuadElemSet.insert(elem); -// else anElemSet.insert(elem); nodeIt = elem->nodesIterator(); nbNodes = elem->NbCornerNodes(); @@ -1452,10 +1445,6 @@ static bool writeGMFFile(const char* theMesh int newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId )); } - // GHS3D does not accept EdgesP2 in input mesh file (Ghs3d 4.2) -// if (elem->IsQuadratic()) -// aQuadEnforcedEdgeSet.insert(elem); -// else theKeptEnforcedEdges.insert(elem); } } @@ -1488,10 +1477,6 @@ static bool writeGMFFile(const char* theMesh int newId = aNodeToGhs3dIdMap.size() + anEnforcedNodeToGhs3dIdMap.size() + 1; // ghs3d ids count from 1 anEnforcedNodeToGhs3dIdMap.insert( make_pair( node, newId )); } - // GHS3D does not accept TrianglesP2 in input mesh file (Ghs3d 4.2) -// if (elem->IsQuadratic()) -// aQuadEnforcedTriangleSet.insert(elem); -// else theKeptEnforcedTriangles.insert(elem); } } @@ -1535,12 +1520,13 @@ static bool writeGMFFile(const char* theMesh theOrderedNodes.push_back(node); } - // Iterate over the enforced nodes - GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt; - std::cout << theEnforcedNodes.size() << " nodes from enforced nodes ..." << std::endl; - for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) + // Iterate over the enforced nodes given by enforced elements + ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin(); + after = theEnforcedNodeByGhs3dId.end(); + std::cout << theEnforcedNodeByGhs3dId.size() << " nodes from enforced elements ..." << std::endl; + for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt ) { - const SMDS_MeshNode* node = enfNodeIt->first; + const SMDS_MeshNode* node = *ghs3dNodeIt; std::vector coords; coords.push_back(node->X()); coords.push_back(node->Y()); @@ -1550,27 +1536,22 @@ static bool writeGMFFile(const char* theMesh std::cout << "Node at " << node->X()<<", " <Y()<<", " <Z() << " found" << std::endl; continue; } - - if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) - continue; - // Test if point is inside shape to mesh - gp_Pnt myPoint(node->X(),node->Y(),node->Z()); - TopAbs_State result = pntCls->GetPointState( myPoint ); - if ( result != TopAbs_IN ) + if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) continue; nodesCoords.insert(coords); theOrderedNodes.push_back(node); - theRequiredNodes.push_back(node); +// theRequiredNodes.push_back(node); } - // Iterate over the enforced nodes given by enforced elements - ghs3dNodeIt = theEnforcedNodeByGhs3dId.begin(); - after = theEnforcedNodeByGhs3dId.end(); - std::cout << theEnforcedNodeByGhs3dId.size() << " nodes from enforced elements ..." << std::endl; - for ( ; ghs3dNodeIt != after; ++ghs3dNodeIt ) + + + // Iterate over the enforced nodes + GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt; + std::cout << theEnforcedNodes.size() << " nodes from enforced nodes ..." << std::endl; + for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) { - const SMDS_MeshNode* node = *ghs3dNodeIt; + const SMDS_MeshNode* node = enfNodeIt->first; std::vector coords; coords.push_back(node->X()); coords.push_back(node->Y()); @@ -1580,16 +1561,22 @@ static bool writeGMFFile(const char* theMesh std::cout << "Node at " << node->X()<<", " <Y()<<", " <Z() << " found" << std::endl; continue; } - + if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) continue; + // Test if point is inside shape to mesh + gp_Pnt myPoint(node->X(),node->Y(),node->Z()); + TopAbs_State result = pntCls->GetPointState( myPoint ); + if ( result != TopAbs_IN ) + continue; + nodesCoords.insert(coords); - theOrderedNodes.push_back(node); +// theOrderedNodes.push_back(node); theRequiredNodes.push_back(node); } + int requiredNodes = theRequiredNodes.size(); -// int requiredNodes = theRequiredNodes.size(); int solSize = 0; std::vector > ReqVerTab; if (nbEnforcedVertices) { @@ -1620,32 +1607,12 @@ static bool writeGMFFile(const char* theMesh GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()/*+solSize*/); for (ghs3dNodeIt = theOrderedNodes.begin();ghs3dNodeIt != theOrderedNodes.end();++ghs3dNodeIt) GmfSetLin(idx, GmfVertices, (*ghs3dNodeIt)->X(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint); -// for (int i=0;iX(), (*ghs3dNodeIt)->Y(), (*ghs3dNodeIt)->Z(), dummyint); + GmfSetLin(idxSol, GmfSolAtVertices, 0.0); + aNodeGroupByGhs3dId[usedEnforcedNodes] = theEnforcedNodes.find((*ghs3dNodeIt))->second; + usedEnforcedNodes++; + } + for (int i=0;isecond; + std::cout << "aNodeGroupByGhs3dId["<second<<"\""<nodesIterator(); -// int index=0; -// while ( nodeIt->more() ) { -// // find GHS3D ID -// const SMDS_MeshNode* node = castToNode( nodeIt->next() ); -// map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node); -// if (it == anEnforcedNodeToGhs3dIdMap.end()) -// throw "Node not found"; -// nedgeP2[index] = it->second; -// index++; -// } -// GmfSetLin(idx, GmfEdgesP2, nedgeP2[0], nedgeP2[1], nedgeP2[2], dummyint); -// // GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint); -// usedEnforcedEdgesP2++; -// } -// // GmfCloseMesh(idxRequired); -// } - if (usedEnforcedEdges/*+usedEnforcedEdgesP2*/) { - GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges/*+usedEnforcedEdgesP2*/); - for (int enfID=1;enfID<=usedEnforcedEdges/*+usedEnforcedEdgesP2*/;enfID++) { + + if (usedEnforcedEdges) { + GmfSetKwd(idx, GmfRequiredEdges, usedEnforcedEdges); + for (int enfID=1;enfID<=usedEnforcedEdges;enfID++) { GmfSetLin(idx, GmfRequiredEdges, enfID); } } @@ -1826,108 +1731,14 @@ static bool writeGMFFile(const char* theMesh } } } + - // GHS3D does not accept EdgesP2 in input mesh file (Ghs3d 4.2) -// // GmfTrianglesP2 -// int usedEnforcedTrianglesP2 = 0; -// if (aQuadElemSet.size()+aQuadEnforcedTriangleSet.size()) { -// GmfSetKwd(idx, GmfTrianglesP2, aQuadElemSet.size()+aQuadEnforcedTriangleSet.size()); -// for(elemIt = aQuadElemSet.begin() ; elemIt != aQuadElemSet.end() ; ++elemIt) { -// elem = (*elemIt); -// nodeIt = elem->nodesIterator(); -// int index=0; -// while ( nodeIt->more() ) { -// // find GHS3D ID -// const SMDS_MeshNode* node = castToNode( nodeIt->next() ); -// map< const SMDS_MeshNode*,int >::iterator it = aNodeToGhs3dIdMap.find(node); -// if (it == aNodeToGhs3dIdMap.end()) -// throw "Node not found"; -// ntriP2[index] = it->second; -// index++; -// } -// GmfSetLin(idx, GmfTrianglesP2, ntriP2[0], ntriP2[1], ntriP2[2], ntriP2[3], ntriP2[4], ntriP2[5], dummyint); -// } -// if (aQuadEnforcedTriangleSet.size()) { -// for(elemIt = aQuadEnforcedTriangleSet.begin() ; elemIt != aQuadEnforcedTriangleSet.end() ; ++elemIt) { -// elem = (*elemIt); -// nodeIt = elem->nodesIterator(); -// int index=0; -// while ( nodeIt->more() ) { -// // find GHS3D ID -// const SMDS_MeshNode* node = castToNode( nodeIt->next() ); -// map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node); -// if (it == anEnforcedNodeToGhs3dIdMap.end()) -// throw "Node not found"; -// ntriP2[index] = it->second; -// index++; -// } -// GmfSetLin(idx, GmfTrianglesP2, ntriP2[0], ntriP2[1], ntriP2[2], ntriP2[3], ntriP2[4], ntriP2[5], dummyint); -// usedEnforcedTrianglesP2++; -// } -// } -// } - - if (usedEnforcedTriangles/*+usedEnforcedTrianglesP2*/) { - GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles/*+usedEnforcedTrianglesP2*/); - for (int enfID=1;enfID<=usedEnforcedTriangles/*+usedEnforcedTrianglesP2*/;enfID++) - GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()/*+aQuadElemSet.size()*/+enfID); + if (usedEnforcedTriangles) { + GmfSetKwd(idx, GmfRequiredTriangles, usedEnforcedTriangles); + for (int enfID=1;enfID<=usedEnforcedTriangles;enfID++) + GmfSetLin(idx, GmfRequiredTriangles, anElemSet.size()+enfID); } - // TODO -// // GmfQuadrangles -// int usedEnforcedQuadrilaterals = 0; -// if (anEnforcedQuadrangleSet.size()) { -// GmfSetKwd(idx, GmfQuadrilaterals, anEnforcedQuadrangleSet.size()); -// for(elemIt = anEnforcedQuadrangleSet.begin() ; elemIt != anEnforcedQuadrangleSet.end() ; ++elemIt) { -// elem = (*elemIt); -// nodeIt = elem->nodesIterator(); -// int index=0; -// for ( int j = 0; j < 4; ++j ) { -// // find GHS3D ID -// const SMDS_MeshNode* node = castToNode( nodeIt->next() ); -// map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node); -// if (it == anEnforcedNodeToGhs3dIdMap.end()) -// throw "Node not found"; -// nquad[index] = it->second; -// index++; -// } -// GmfSetLin(idx, GmfQuadrilaterals, nquad[0], nquad[1], nquad[2], nquad[3], dummyint); -// usedEnforcedQuadrilaterals++; -// } -// } -// -// // GHS3D does not accept EdgesP2 in input mesh file (Ghs3d 4.2) -// // GmfQuadranglesQ2 -// int usedEnforcedQuadrilateralsQ2 = 0; -// if (aQuadEnforcedQuadrangleSet.size()) { -// GmfSetKwd(idx, GmfQuadrilateralsQ2, aQuadEnforcedQuadrangleSet.size()); -// for(elemIt = aQuadEnforcedQuadrangleSet.begin() ; elemIt != aQuadEnforcedQuadrangleSet.end() ; ++elemIt) { -// elem = (*elemIt); -// nodeIt = elem->nodesIterator(); -// int index=0; -// while ( nodeIt->more() ) { -// // find GHS3D ID -// const SMDS_MeshNode* node = castToNode( nodeIt->next() ); -// map< const SMDS_MeshNode*,int >::iterator it = anEnforcedNodeToGhs3dIdMap.find(node); -// if (it == anEnforcedNodeToGhs3dIdMap.end()) -// throw "Node not found"; -// nquadQ2[index] = it->second; -// index++; -// } -// // -// // !!! The last value in nquadQ2 is missing because in Salome the quadratic quadrilaterals have only 8 points !!! -// // -// GmfSetLin(idx, GmfQuadrilateralsQ2, nquadQ2[0], nquadQ2[1], nquadQ2[2], nquadQ2[3], nquadQ2[4], nquadQ2[5], nquadQ2[6], nquadQ2[7], nquadQ2[8], dummyint); -// usedEnforcedQuadrilateralsQ2++; -// } -// } -// -// if (usedEnforcedQuadrilaterals+usedEnforcedQuadrilateralsQ2) { -// GmfSetKwd(idx, GmfRequiredQuadrilaterals, usedEnforcedQuadrilaterals+usedEnforcedQuadrilateralsQ2); -// for (int enfID=1;enfID<=usedEnforcedQuadrilaterals+usedEnforcedQuadrilateralsQ2;enfID++) -// GmfSetLin(idx, GmfRequiredQuadrilaterals, enfID); -// } - GmfCloseMesh(idx); if (idxRequired) GmfCloseMesh(idxRequired); @@ -3506,19 +3317,19 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } } - const SMDS_MeshNode* enfNode; +// const SMDS_MeshNode* enfNode; GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp); - GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin(); - for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt) - { - enfNode = enfNodeIt->first; - coords.clear(); - coords.push_back(enfNode->X()); - coords.push_back(enfNode->Y()); - coords.push_back(enfNode->Z()); - if (enfVerticesWithGroup.find(coords) == enfVerticesWithGroup.end()) - enfVerticesWithGroup.insert(make_pair(coords,enfNodeIt->second)); - } +// GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator enfNodeIt = enforcedNodes.begin(); +// for ( ; enfNodeIt != enforcedNodes.end() ; ++enfNodeIt) +// { +// enfNode = enfNodeIt->first; +// coords.clear(); +// coords.push_back(enfNode->X()); +// coords.push_back(enfNode->Y()); +// coords.push_back(enfNode->Z()); +// if (enfVerticesWithGro +// enfVerticesWithGroup.insert(make_pair(coords,enfNodeIt->second)); +// } GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp); @@ -3533,7 +3344,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, std::vector aNodeByGhs3dId, anEnforcedNodeByGhs3dId; std::map aNodeToGhs3dIdMap; - std::vector anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId; + std::vector aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId; { SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh )); if ( theMesh.NbQuadrangles() > 0 ) @@ -3545,9 +3356,10 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), *proxyMesh, &theMesh, - aNodeByGhs3dId, anEnforcedNodeByGhs3dId, aNodeToGhs3dIdMap, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId, - enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/ - coordsSizeMap); + aNodeByGhs3dId, anEnforcedNodeByGhs3dId, aNodeToGhs3dIdMap, + aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId, + enforcedNodes, enforcedEdges, enforcedTriangles, + enfVerticesWithGroup, coordsSizeMap); } // ----------------- @@ -3557,7 +3369,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str()); cmd += TCollection_AsciiString(" --in ") + aGenericName; - if ( nbEnforcedVertices + nbEnforcedVertices) + if ( nbEnforcedVertices + nbEnforcedNodes) cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired; cmd += TCollection_AsciiString(" --out ") + aResultFileName; cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file @@ -3584,7 +3396,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, this, #endif theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap, - enfVerticesWithGroup, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId); + aNodeGroupByGhs3dId, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId); // --------------------- // remove working files @@ -4222,13 +4034,13 @@ bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& th std::vector dummyNodeVector; std::map dummyNodeMap; std::map, std::string> dummyEnfVertGroup; - std::vector dummyElemGroup1, dummyElemGroup2; + std::vector dummyElemGroup; bool ok = readGMFFile(theGMFFileName, #ifdef WITH_SMESH_CANCEL_COMPUTE this, #endif - helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyEnfVertGroup, dummyElemGroup1, dummyElemGroup2); + helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyElemGroup, dummyElemGroup, dummyElemGroup); theMesh.GetMeshDS()->Modified(); return ok; } diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index b518b34..8f33646 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -25,6 +25,7 @@ // #include "GHS3DPlugin_Hypothesis.hxx" #include +#include #include #include @@ -417,14 +418,45 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size, std::string groupName) { TIDSortedElemSet theElemSet; - SMDS_ElemIteratorPtr eIt; - eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType)); + SMDS_ElemIteratorPtr eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType)); while ( eIt->more() ) theElemSet.insert( eIt->next() ); MESSAGE("Add "<length() == 0 ){MESSAGE("The source group is empty");} + for (int i=0; i < theIDs->length(); i++) { + CORBA::Long ind = theIDs[i]; + if (elementType == SMESH::NODE) + { + const SMDS_MeshNode * node = theMeshDS->FindNode(ind); + if (node) + theElemSet.insert( node ); + } + else + { + const SMDS_MeshElement * elem = theMeshDS->FindElement(ind); + if (elem) + theElemSet.insert( elem ); + } + } + +// SMDS_ElemIteratorPtr it = theGroup->GetGroupDS()->GetElements(); +// while ( it->more() ) +// theElemSet.insert( it->next() ); + + MESSAGE("Add "<begin_nodes(),elem->end_nodes()); SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator(); for (;nodeIt->more();) { node = dynamic_cast(nodeIt->next()); diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index 8532002..2063e6e 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -193,6 +193,7 @@ public: * To set enforced elements */ bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size, std::string groupName = ""); + bool SetEnforcedGroup(const SMESHDS_Mesh* theMeshDS, SMESH::long_array_var theIDs, SMESH::ElementType elementType, double size, std::string groupName = ""); bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size, std::string groupName = ""); void ClearEnforcedMeshes(); const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; } @@ -278,6 +279,7 @@ private: TIDSortedElemGroupMap _enfTriangles; TID2SizeMap _nodeIDToSizeMap; TID2SizeMap _elementIDToSizeMap; + std::map _entryToElemsMap; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index f62b5dd..e7a2d4c 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -35,6 +35,7 @@ #include "SMESH_Group_i.hxx" #include "SMESH_Gen_i.hxx" #include "SMESH_TypeDefs.hxx" +#include "SMESHDS_GroupBase.hxx" #ifndef GHS3D_VERSION #define GHS3D_VERSION 41 @@ -521,8 +522,8 @@ CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertex(CORBA::Double x, CORBA SALOME::ExceptionStruct ExDescription; ExDescription.text = ex.what(); ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::GetEnforcedVertex(x,y,z)"; - ExDescription.lineNumber = 0; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 513; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { @@ -571,8 +572,8 @@ CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertexGeom(GEOM::GEOM_Object_ SALOME::ExceptionStruct ExDescription; ExDescription.text = ex.what(); ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::GetEnforcedVertexGeom(theVertex)"; - ExDescription.lineNumber = 0; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 538; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { @@ -635,8 +636,8 @@ bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Doub SALOME::ExceptionStruct ExDescription; ExDescription.text = ex.what(); ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(x,y,z)"; - ExDescription.lineNumber = 408; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 625; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { @@ -681,8 +682,8 @@ bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr th SALOME::ExceptionStruct ExDescription; ExDescription.text = ex.what(); ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(x,y,z)"; - ExDescription.lineNumber = 408; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 648; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { @@ -723,7 +724,8 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_pt bool res = _SetEnforcedMesh(theSource, theType, -1.0, theGroupName); SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - if (theGroup_i) + SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); + if (theGroup_i or theGroupOnGeom_i) { SMESH::TPythonDump () << _this() << ".SetEnforcedMeshWithGroup( " << theSource << ", " << theType << ", \"" << theGroupName << "\" )"; @@ -738,8 +740,8 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_pt SALOME::ExceptionStruct ExDescription; ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::SetEnforcedMesh(theSource, theType)"; - ExDescription.lineNumber = 463; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 719; throw SALOME::SALOME_Exception(ExDescription); #endif } @@ -750,11 +752,13 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_pt bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType) throw (SALOME::SALOME_Exception) { + MESSAGE("GHS3DPlugin_Hypothesis_i::SetEnforcedMesh"); #if GHS3D_VERSION >= 42 bool res = _SetEnforcedMesh(theSource, theType, -1.0); SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - if (theGroup_i) + SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); + if (theGroup_i or theGroupOnGeom_i) { SMESH::TPythonDump () << _this() << ".SetEnforcedMesh( " << theSource << ", " << theType << " )"; @@ -769,8 +773,8 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSour SALOME::ExceptionStruct ExDescription; ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::SetEnforcedMesh(theSource, theType)"; - ExDescription.lineNumber = 463; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 750; throw SALOME::SALOME_Exception(ExDescription); #endif } @@ -785,15 +789,16 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSourc SALOME::ExceptionStruct ExDescription; ExDescription.text = "Size cannot be negative"; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::SetEnforcedMeshSize(theSource, theType)"; - ExDescription.lineNumber = 475; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 781; throw SALOME::SALOME_Exception(ExDescription); } bool res = _SetEnforcedMesh(theSource, theType, theSize,theGroupName); SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - if (theGroup_i) + SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); + if (theGroup_i or theGroupOnGeom_i) { SMESH::TPythonDump () << _this() << ".SetEnforcedMeshSizeWithGroup( " << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; @@ -816,15 +821,16 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr the SALOME::ExceptionStruct ExDescription; ExDescription.text = "Size cannot be negative"; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::SetEnforcedMeshSize(theSource, theType)"; - ExDescription.lineNumber = 475; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 812; throw SALOME::SALOME_Exception(ExDescription); } bool res = _SetEnforcedMesh(theSource, theType, theSize); SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); - if (theGroup_i) + SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); + if (theGroup_i or theGroupOnGeom_i) { SMESH::TPythonDump () << _this() << ".SetEnforcedMeshSize( " << theSource << ", " << theType << ", " << theSize << " )"; @@ -840,6 +846,7 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr the bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName) throw (SALOME::SALOME_Exception) { + MESSAGE("GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh"); ASSERT(myBaseImpl); if (CORBA::is_nil( theSource )) @@ -847,103 +854,88 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou SALOME::ExceptionStruct ExDescription; ExDescription.text = "The source mesh CORBA object is NULL"; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } if ((theType != SMESH::NODE) && (theType != SMESH::EDGE) && (theType != SMESH::FACE)) { - SALOME::ExceptionStruct ExDescription; - ExDescription.text = "Bad elementType"; - ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; - ExDescription.lineNumber = 840; - throw SALOME::SALOME_Exception(ExDescription); + return 0; +// SALOME::ExceptionStruct ExDescription; +// ExDescription.text = "Bad elementType"; +// ExDescription.type = SALOME::BAD_PARAM; +// ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; +// ExDescription.lineNumber = 840; +// throw SALOME::SALOME_Exception(ExDescription); } SMESH::array_of_ElementType_var types = theSource->GetTypes(); -// MESSAGE("Required type is "<length();i++){MESSAGE(types[i]);} + MESSAGE("Required type is "<length();i++){MESSAGE(types[i]);} if ( types->length() >= 1 && types[types->length()-1] < theType) { - SALOME::ExceptionStruct ExDescription; - ExDescription.text = "The source mesh has bad type"; - ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; - ExDescription.lineNumber = 840; - throw SALOME::SALOME_Exception(ExDescription); + return 0; +// SALOME::ExceptionStruct ExDescription; +// ExDescription.text = "The source mesh has bad type"; +// ExDescription.type = SALOME::BAD_PARAM; +// ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; +// ExDescription.lineNumber = 840; +// throw SALOME::SALOME_Exception(ExDescription); } - SMESHDS_Mesh* theMeshDS; - SMESH_Mesh_i* anImplPtr = SMESH::DownCast(theSource->GetMesh()); - if (anImplPtr) - theMeshDS = anImplPtr->GetImpl().GetMeshDS(); - else - return false; - SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); + SMESH_GroupOnGeom_i* theGroupOnGeom_i = SMESH::DownCast( theSource); TIDSortedElemSet theElemSet; if (theMesh_i) { try { - return this->GetImpl()->SetEnforcedMesh(anImplPtr->GetImpl(), theType, theSize, theGroupName); + return this->GetImpl()->SetEnforcedMesh(theMesh_i->GetImpl(), theType, theSize, theGroupName); } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; ExDescription.text = ex.what(); ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); } -// -// SMESH::long_array_var anIDs = theMesh_i->GetElementsByType(theType); -// if ( anIDs->length() == 0 ){MESSAGE("The source mesh is empty");} -// for (int i=0; ilength(); i++) { -// CORBA::Long ind = anIDs[i]; -// const SMDS_MeshElement * elem = theMeshDS->FindElement(ind); -// if (elem) -// theElemSet.insert( elem ); -// } -//// } -// MESSAGE("Add "<length() == 1 && types[0] == theType) { - SMESH::long_array_var anIDs = theGroup_i->GetListOfID(); - if ( anIDs->length() == 0 ){MESSAGE("The source group is empty");} - for (int i=0; ilength(); i++) { - CORBA::Long ind = anIDs[i]; - if (theType == SMESH::NODE) - { - const SMDS_MeshNode * node = theMeshDS->FindNode(ind); - if (node) - theElemSet.insert( node ); - } - else - { - const SMDS_MeshElement * elem = theMeshDS->FindElement(ind); - if (elem) - theElemSet.insert( elem ); - } + MESSAGE("The source is a group") + try { + return this->GetImpl()->SetEnforcedGroup(theGroup_i->GetGroupDS()->GetMesh(),theGroup_i->GetListOfID(), theType, theSize, theGroupName); } - MESSAGE("Add "<GetName()); - + catch (const std::invalid_argument& ex) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = ex.what(); + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; + ExDescription.lineNumber = 840; + throw SALOME::SALOME_Exception(ExDescription); + } + catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + } + else if (theGroupOnGeom_i && types->length() == 1 && types[0] == theType) + { + MESSAGE("The source is a group on geom") try { - return this->GetImpl()->SetEnforcedElements(theElemSet, theType, theSize, theGroupName); + return this->GetImpl()->SetEnforcedGroup(theGroupOnGeom_i->GetGroupDS()->GetMesh(),theGroupOnGeom_i->GetListOfID(), theType, theSize, theGroupName); } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; ExDescription.text = ex.what(); ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis_i.cxx"; ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } -- 2.39.2