From: gdd Date: Tue, 10 May 2011 17:58:20 +0000 (+0000) Subject: Enforced vertices and elements X-Git-Tag: V6_3_0~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f400c2b4f940d6de8b41cdd8546254dcb986af8c;p=plugins%2Fhybridplugin.git Enforced vertices and elements --- diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index 7b8da88..f9c59ee 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -144,7 +144,9 @@ module GHS3DPlugin void ClearEnforcedVertices(); boolean SetEnforcedMesh(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType) raises (SALOME::SALOME_Exception); + boolean SetEnforcedMeshWithGroup(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in string groupName) raises (SALOME::SALOME_Exception); boolean SetEnforcedMeshSize(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in double size) raises (SALOME::SALOME_Exception); + boolean SetEnforcedMeshSizeWithGroup(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in double size, in string groupName) raises (SALOME::SALOME_Exception); void ClearEnforcedMeshes(); }; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index 7001def..b64b50a 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -36,12 +36,15 @@ #include "SMESH_MesherHelper.hxx" #include "SMESH_MeshEditor.hxx" #include "SMESH_OctreeNode.hxx" +#include "SMESH_Group.hxx" #include "SMDS_MeshElement.hxx" #include "SMDS_MeshNode.hxx" #include "SMDS_FaceOfNodes.hxx" #include "SMDS_VolumeOfNodes.hxx" +#include "SMESHDS_Group.hxx" + #include #include @@ -65,6 +68,7 @@ #include #include #include +#include //#include #include #include @@ -138,7 +142,19 @@ GHS3DPlugin_GHS3D::GHS3DPlugin_GHS3D(int hypId, int studyId, SMESH_Gen* gen) _nbShape=0; _compatibleHypothesis.push_back("GHS3D_Parameters"); _compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() ); - _requireShape = false; // can work without shape + _requireShape = false; // can work without shape_studyId + + smeshGen_i = SMESH_Gen_i::GetSMESHGen(); + CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager"); + SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject); + + MESSAGE("studyid = " << _studyId); + + myStudy = NULL; + myStudy = aStudyMgr->GetStudyByID(_studyId); + if (myStudy) + MESSAGE("myStudy->StudyId() = " << myStudy->StudyId()); + #ifdef WITH_SMESH_CANCEL_COMPUTE _compute_canceled = false; #endif @@ -188,6 +204,30 @@ bool GHS3DPlugin_GHS3D::CheckHypothesis ( SMESH_Mesh& aMesh, } +//======================================================================= +//function : entryToShape +//purpose : +//======================================================================= + +TopoDS_Shape GHS3DPlugin_GHS3D::entryToShape(std::string entry) +{ + MESSAGE("GHS3DPlugin_GHS3D::entryToShape "<FindObjectID( entry.c_str() ); + SALOMEDS::GenericAttribute_var anAttr; + + if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { + SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); + CORBA::String_var aVal = anIOR->Value(); + CORBA::Object_var obj = myStudy->ConvertIORToObject(aVal); + aGeomObj = GEOM::GEOM_Object::_narrow(obj); + } + if ( !aGeomObj->_is_nil() ) + S = smeshGen_i->GeomObjectToShape( aGeomObj.in() ); + return S; +} + //======================================================================= //function : findShape //purpose : @@ -955,12 +995,54 @@ static int findShapeID(SMESH_Mesh& mesh, // } +//======================================================================= +//function : updateMeshGroups +//purpose : Update or create groups in mesh +//======================================================================= + +static void updateMeshGroups(SMESH_Mesh* theMesh, + const SMDS_MeshElement* anElem, + std::string groupName) +{ + bool groupDone = false; + SMESH_Mesh::GroupIteratorPtr grIt = theMesh->GetGroups(); + 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; + } + } + if (!groupDone) + { + int groupId; + SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId); + aGroup->SetName( groupName.c_str() ); + SMESHDS_Group* aGroupDS = static_cast( aGroup->GetGroupDS() ); + aGroupDS->SMDSGroup().Add(anElem); + MESSAGE("Successfully created enforced vertex group " << groupName); + groupDone = true; + } + if (!groupDone) + throw SALOME_Exception(LOCALIZED("A enforced vertex node was not added to a group")); +} + //======================================================================= //function : readGMFFile //purpose : read GMF file w/o geometry associated to mesh //======================================================================= - static bool readGMFFile(const char* theFile, #ifdef WITH_SMESH_CANCEL_COMPUTE GHS3DPlugin_GHS3D* theAlgo, @@ -968,7 +1050,10 @@ static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper, TopoDS_Shape theSolid, vector & theNodeByGhs3dId, - map & theNodeToGhs3dIdMap) + map & theNodeToGhs3dIdMap, + std::map, std::string> & enfVerticesWithGroup, + std::vector & anEdgeGroupByGhs3dId, + std::vector & aFaceGroupByGhs3dId) { SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS(); @@ -993,7 +1078,7 @@ static bool readGMFFile(const char* theFile, int nbElem = 0, nbRef = 0; int aGMFNodeID = 0, shapeID; int *nodeAssigne; - SMDS_MeshNode** GMFNode; + const SMDS_MeshNode** GMFNode; std::map tabRef; tabRef[GmfVertices] = 3; // for new nodes and enforced nodes @@ -1020,7 +1105,7 @@ static bool readGMFFile(const char* theFile, elemSearcher = SMESH_MeshEditor( theHelper->GetMesh() ).GetElementSearcher(); int nbVertices = GmfStatKwd(InpMsh, GmfVertices) - nbInitialNodes; - GMFNode = new SMDS_MeshNode*[ nbVertices + 1 ]; + GMFNode = new const SMDS_MeshNode*[ nbVertices + 1 ]; nodeAssigne = new int[ nbVertices + 1 ]; std::map ::const_iterator it = tabRef.begin(); @@ -1046,7 +1131,7 @@ static bool readGMFFile(const char* theFile, else continue; - vector id (nbElem*tabRef[token]); // node ids + std::vector id (nbElem*tabRef[token]); // node ids if (token == GmfVertices) { std::cout << " vertices" << std::endl; @@ -1069,7 +1154,9 @@ static bool readGMFFile(const char* theFile, float VerTab_f[nbElem][3]; double VerTab_d[nbElem][3]; - SMDS_MeshNode * aGMFNode; + double x, y, z; + std::vector coords; + const SMDS_MeshNode * aGMFNode; shapeID = theMeshDS->ShapeToIndex( theSolid ); for ( int iElem = 0; iElem < nbElem; iElem++ ) { @@ -1081,43 +1168,34 @@ static bool readGMFFile(const char* theFile, return false; } #endif - if (iElem >= nbInitialNodes) - aGMFID = iElem -nbInitialNodes +1; + coords.clear(); if (ver == GmfFloat) { GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &dummy); - if (iElem >= nbInitialNodes) - { - if ( elemSearcher && - elemSearcher->FindElementsByPoint( gp_Pnt(VerTab_f[nbElem][0], - VerTab_f[nbElem][1], - VerTab_f[nbElem][2]), - SMDSAbs_Volume, foundVolumes )) - aGMFNode = 0; - else - aGMFNode = theMeshDS->AddNode(VerTab_f[nbElem][0], - VerTab_f[nbElem][1], - VerTab_f[nbElem][2]); - } + x = (double) VerTab_f[nbElem][0]; + y = (double) VerTab_f[nbElem][1]; + z = (double) VerTab_f[nbElem][2]; } else { GmfGetLin(InpMsh, token, &VerTab_d[nbElem][0], &VerTab_d[nbElem][1], &VerTab_d[nbElem][2], &dummy); - if (iElem >= nbInitialNodes) - { - if ( elemSearcher && - elemSearcher->FindElementsByPoint( gp_Pnt(VerTab_d[nbElem][0], - VerTab_d[nbElem][1], - VerTab_d[nbElem][2]), - SMDSAbs_Volume, foundVolumes )) - aGMFNode = 0; - else - aGMFNode = theMeshDS->AddNode(VerTab_d[nbElem][0], - VerTab_d[nbElem][1], - VerTab_d[nbElem][2]); - } + x = VerTab_d[nbElem][0]; + y = VerTab_d[nbElem][1]; + z = VerTab_d[nbElem][2]; } if (iElem >= nbInitialNodes) { + if ( elemSearcher && + elemSearcher->FindElementsByPoint( gp_Pnt(x, y, z), SMDSAbs_Node, foundVolumes )) + aGMFNode = 0; + else + aGMFNode = theHelper->AddNode(x, y, z); + + aGMFID = iElem -nbInitialNodes +1; GMFNode[ aGMFID ] = aGMFNode; nodeAssigne[ aGMFID ] = 0; + coords.push_back(x); + coords.push_back(y); + coords.push_back(z); + if (enfVerticesWithGroup.find(coords) != enfVerticesWithGroup.end()) + updateMeshGroups(theHelper->GetMesh(), aGMFNode, enfVerticesWithGroup[coords]); } } } @@ -1171,6 +1249,7 @@ static bool readGMFFile(const char* theFile, std::vector< const SMDS_MeshNode* > node( nbRef ); std::vector< int > nodeID( nbRef ); std::vector< SMDS_MeshNode* > enfNode( nbRef ); + const SMDS_MeshElement* aCreatedElem; for ( int iElem = 0; iElem < nbElem; iElem++ ) { @@ -1204,14 +1283,17 @@ static bool readGMFFile(const char* theFile, switch (token) { case GmfEdges: - if (fullyCreatedElement) - theHelper->AddEdge( node[0], node[1], /*id =*/0, /*force3d =*/false ); + if (fullyCreatedElement) { + aCreatedElem = theHelper->AddEdge( node[0], node[1], /*id =*/0, /*force3d =*/false ); + updateMeshGroups(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByGhs3dId[iElem]); + } break; case GmfTriangles: if (fullyCreatedElement) { - theHelper->AddFace( node[0], node[1], node[2], /*id =*/0, /*force3d =*/false ); + 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]); } break; case GmfQuadrilaterals: @@ -1281,13 +1363,14 @@ static bool writeGMFFile(const char* theMesh const char* theSolFileName, const SMESH_ProxyMesh& theProxyMesh, SMESH_Mesh * theMesh, - vector & theNodeByGhs3dId, - vector & theEnforcedNodeByGhs3dId, - map & aNodeToGhs3dIdMap, - TIDSortedNodeSet & theEnforcedNodes, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles, -// TIDSortedElemSet & theEnforcedQuadrangles, + std::vector & theNodeByGhs3dId, + std::vector & theEnforcedNodeByGhs3dId, + std::map & aNodeToGhs3dIdMap, + std::vector & anEdgeGroupByGhs3dId, + std::vector & aFaceGroupByGhs3dId, + GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles, GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices) { MESSAGE("writeGMFFile w/o geometry"); @@ -1301,7 +1384,8 @@ static bool writeGMFFile(const char* theMesh // TIDSortedElemSet aQuadElemSet, aQuadEnforcedEdgeSet, aQuadEnforcedTriangleSet, aQuadEnforcedQuadrangleSet; SMDS_ElemIteratorPtr nodeIt; map /*aNodeToGhs3dIdMap,*/ anEnforcedNodeToGhs3dIdMap; - TIDSortedElemSet::iterator elemIt; + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::iterator elemIt; + TIDSortedElemSet::iterator elemSetIt; bool isOK; auto_ptr< SMESH_ElementSearcher > pntCls ( SMESH_MeshEditor( theMesh ).GetElementSearcher()); @@ -1344,7 +1428,7 @@ static bool writeGMFFile(const char* theMesh // Iterate over the enforced edges for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { - elem = (*elemIt); + elem = elemIt->first; isOK = true; nodeIt = elem->nodesIterator(); nbNodes = 2; @@ -1380,7 +1464,7 @@ static bool writeGMFFile(const char* theMesh // Iterate over the enforced triangles for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { - elem = (*elemIt); + elem = elemIt->first; isOK = true; nodeIt = elem->nodesIterator(); nbNodes = 3; @@ -1452,11 +1536,11 @@ static bool writeGMFFile(const char* theMesh } // Iterate over the enforced nodes - TIDSortedNodeSet::const_iterator enfNodeIt; + 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 = *enfNodeIt; + const SMDS_MeshNode* node = enfNodeIt->first; std::vector coords; coords.push_back(node->X()); coords.push_back(node->Y()); @@ -1633,16 +1717,18 @@ static bool writeGMFFile(const char* theMesh // GHS3D does not accept quadratic elements in input mesh file (Ghs3d 4.2) int nedge[2], ntri[3]/*, nquad[4]*/ /*, nedgeP2[3], ntriP2[6], nquadQ2[9]*/; + // GmfEdges int usedEnforcedEdges = 0; if (theKeptEnforcedEdges.size()) { + anEdgeGroupByGhs3dId.resize( theKeptEnforcedEdges.size() ); // idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION); // if (!idxRequired) // return false; GmfSetKwd(idx, GmfEdges, theKeptEnforcedEdges.size()); // GmfSetKwd(idxRequired, GmfEdges, theKeptEnforcedEdges.size()); - for(elemIt = theKeptEnforcedEdges.begin() ; elemIt != theKeptEnforcedEdges.end() ; ++elemIt) { - elem = (*elemIt); + for(elemSetIt = theKeptEnforcedEdges.begin() ; elemSetIt != theKeptEnforcedEdges.end() ; ++elemSetIt) { + elem = (*elemSetIt); nodeIt = elem->nodesIterator(); int index=0; while ( nodeIt->more() ) { @@ -1655,6 +1741,7 @@ static bool writeGMFFile(const char* theMesh index++; } GmfSetLin(idx, GmfEdges, nedge[0], nedge[1], dummyint); + anEdgeGroupByGhs3dId[usedEnforcedEdges] = theEnforcedEdges.find(elem)->second; // GmfSetLin(idxRequired, GmfEdges, nedge[0], nedge[1], dummyint); usedEnforcedEdges++; } @@ -1700,9 +1787,11 @@ static bool writeGMFFile(const char* theMesh // GmfTriangles int usedEnforcedTriangles = 0; if (anElemSet.size()+theKeptEnforcedTriangles.size()) { + aFaceGroupByGhs3dId.resize( anElemSet.size()+theKeptEnforcedTriangles.size() ); GmfSetKwd(idx, GmfTriangles, anElemSet.size()+theKeptEnforcedTriangles.size()); - for(elemIt = anElemSet.begin() ; elemIt != anElemSet.end() ; ++elemIt) { - elem = (*elemIt); + int k=0; + for(elemSetIt = anElemSet.begin() ; elemSetIt != anElemSet.end() ; ++elemSetIt,++k) { + elem = (*elemSetIt); nodeIt = elem->nodesIterator(); int index=0; for ( int j = 0; j < 3; ++j ) { @@ -1715,10 +1804,11 @@ static bool writeGMFFile(const char* theMesh index++; } GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint); + aFaceGroupByGhs3dId[k] = ""; } if (theKeptEnforcedTriangles.size()) { - for(elemIt = theKeptEnforcedTriangles.begin() ; elemIt != theKeptEnforcedTriangles.end() ; ++elemIt) { - elem = (*elemIt); + for(elemSetIt = theKeptEnforcedTriangles.begin() ; elemSetIt != theKeptEnforcedTriangles.end() ; ++elemSetIt,++k) { + elem = (*elemSetIt); nodeIt = elem->nodesIterator(); int index=0; for ( int j = 0; j < 3; ++j ) { @@ -1731,6 +1821,7 @@ static bool writeGMFFile(const char* theMesh index++; } GmfSetLin(idx, GmfTriangles, ntri[0], ntri[1], ntri[2], dummyint); + aFaceGroupByGhs3dId[k] = theEnforcedTriangles.find(elem)->second; usedEnforcedTriangles++; } } @@ -2292,13 +2383,13 @@ static bool writeGMFFile(const char* theMesh //purpose : //======================================================================= -static bool writeFaces (ofstream & theFile, - const SMESH_ProxyMesh& theMesh, - const TopoDS_Shape& theShape, - const map & theSmdsToGhs3dIdMap, - const map & theEnforcedNodeIdToGhs3dIdMap, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles) +static bool writeFaces (ofstream & theFile, + const SMESH_ProxyMesh& theMesh, + const TopoDS_Shape& theShape, + const map & theSmdsToGhs3dIdMap, + const map & theEnforcedNodeIdToGhs3dIdMap, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles) { // record structure: // @@ -2485,9 +2576,9 @@ static bool writePoints (ofstream & theFile, map & theGhs3dIdToNodeMap, GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap, GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices, - TIDSortedNodeSet & theEnforcedNodes, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles) + GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap & theEnforcedNodes, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles) { // record structure: // @@ -2597,11 +2688,11 @@ static bool writePoints (ofstream & theFile, // Iterate over the enforced nodes std::map enfVertexIndexSizeMap; if (nbEnforcedNodes) { - TIDSortedNodeSet::const_iterator nodeIt = theEnforcedNodes.begin(); + GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap::const_iterator nodeIt = theEnforcedNodes.begin(); for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) { - double x = (*nodeIt)->X(); - double y = (*nodeIt)->Y(); - double z = (*nodeIt)->Z(); + double x = nodeIt->first->X(); + double y = nodeIt->first->Y(); + double z = nodeIt->first->Z(); // Test if point is inside shape to mesh gp_Pnt myPoint(x,y,z); BRepClass3d_SolidClassifier scl(shapeToMesh); @@ -2616,7 +2707,7 @@ static bool writePoints (ofstream & theFile, if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) continue; - double size = theNodeIDToSizeMap.find((*nodeIt)->GetID())->second; + double size = theNodeIDToSizeMap.find(nodeIt->first->GetID())->second; // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) )); // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")"); // X Y Z PHY_SIZE DUMMY_INT @@ -2627,7 +2718,7 @@ static bool writePoints (ofstream & theFile, << size << space << dummyint << space; theFile << std::endl; - theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( (*nodeIt)->GetID(), aGhs3dID )); + theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( nodeIt->first->GetID(), aGhs3dID )); enfVertexIndexSizeMap[aGhs3dID] = -1; aGhs3dID++; // else @@ -2691,8 +2782,8 @@ static bool readResultFile(const int fileOpen, bool toMeshHoles, int nbEnforcedVertices, int nbEnforcedNodes, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles) + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedEdges, + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap & theEnforcedTriangles) { MESSAGE("GHS3DPlugin_GHS3D::readResultFile()"); Kernel_Utils::Localizer loc; @@ -2914,7 +3005,7 @@ static bool readResultFile(const int fileOpen, } // Add enforced elements - TIDSortedElemSet::const_iterator elemIt; + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap::const_iterator elemIt; const SMDS_MeshElement* anElem; SMDS_ElemIteratorPtr itOnEnfElem; map::const_iterator itOnMap; @@ -2925,7 +3016,7 @@ static bool readResultFile(const int fileOpen, std::vector< const SMDS_MeshNode* > node( 2 ); // Iterate over the enforced edges for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { - anElem = (*elemIt); + anElem = elemIt->first; bool addElem = true; itOnEnfElem = anElem->nodesIterator(); for ( int j = 0; j < 2; ++j ) { @@ -2955,7 +3046,7 @@ static bool readResultFile(const int fileOpen, std::vector< const SMDS_MeshNode* > node( 3 ); // Iterate over the enforced triangles for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { - anElem = (*elemIt); + anElem = elemIt->first; bool addElem = true; itOnEnfElem = anElem->nodesIterator(); for ( int j = 0; j < 3; ++j ) { @@ -3112,14 +3203,14 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, std::map aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap; std::map aGhs3dIdToNodeMap; std::map nodeID2nodeIndexMap; - GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp); - TIDSortedNodeSet enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp); - TIDSortedElemSet enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp); - TIDSortedElemSet enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp); + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp); + GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp); + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp); + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp); // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp); GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); - int nbEnforcedVertices = enforcedVertices.size(); + int nbEnforcedVertices = coordsSizeMap.size(); int nbEnforcedNodes = enforcedNodes.size(); std::cout << nbEnforcedNodes << " enforced nodes from hypo" << std::endl; std::cout << nbEnforcedVertices << " enforced vertices from hypo" << std::endl; @@ -3159,7 +3250,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = (writePoints( aPointsFile, helper, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap, nodeIDToSizeMap, - enforcedVertices, enforcedNodes, enforcedEdges, enforcedTriangles) + coordsSizeMap, enforcedNodes, enforcedEdges, enforcedTriangles) && writeFaces ( aFacesFile, *proxyMesh, theShape, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, @@ -3168,7 +3259,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // helper, *proxyMesh, // aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, // enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/ -// enforcedVertices); +// coordsSizeMap); } // Write aSmdsToGhs3dIdMap to temp file @@ -3363,20 +3454,86 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, #endif std::map nodeID2nodeIndexMap; - GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize(_hyp); - TIDSortedNodeSet enforcedNodes = GHS3DPlugin_Hypothesis::GetEnforcedNodes(_hyp); - TIDSortedElemSet enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp); - TIDSortedElemSet enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp); + std::map, std::string> enfVerticesWithGroup; + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues coordsSizeMap; + TopoDS_Shape GeomShape; + TopAbs_ShapeEnum GeomType; + std::vector coords; + gp_Pnt aPnt; + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* enfVertex; + + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp); + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator enfVerIt = enfVertices.begin(); + for ( ; enfVerIt != enfVertices.end() ; ++enfVerIt) + { + enfVertex = (*enfVerIt); + if (enfVertex->geomEntry.empty() && enfVertex->coords.size()) { + coordsSizeMap.insert(make_pair(enfVertex->coords,enfVertex->size)); + enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); + } + if (!enfVertex->geomEntry.empty()) { + GeomShape = entryToShape(enfVertex->geomEntry); + GeomType = GeomShape.ShapeType(); + + if (GeomType == TopAbs_VERTEX) { + coords.clear(); + aPnt = BRep_Tool::Pnt(TopoDS::Vertex(GeomShape)); + coords.push_back(aPnt.X()); + coords.push_back(aPnt.Y()); + coords.push_back(aPnt.Z()); + if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { + coordsSizeMap.insert(make_pair(coords,enfVertex->size)); + enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); + } + } + + // Group Management + if (GeomType == TopAbs_COMPOUND){ + for (TopoDS_Iterator it (GeomShape); it.More(); it.Next()){ + coords.clear(); + if (it.Value().ShapeType() == TopAbs_VERTEX){ + aPnt = BRep_Tool::Pnt(TopoDS::Vertex(it.Value())); + coords.push_back(aPnt.X()); + coords.push_back(aPnt.Y()); + coords.push_back(aPnt.Z()); + if (coordsSizeMap.find(coords) == coordsSizeMap.end()) { + coordsSizeMap.insert(make_pair(coords,enfVertex->size)); + enfVerticesWithGroup.insert(make_pair(coords,enfVertex->groupName)); + } + } + } + } + } + } + + 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::TIDSortedElemGroupMap enforcedEdges = GHS3DPlugin_Hypothesis::GetEnforcedEdges(_hyp); + GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap enforcedTriangles = GHS3DPlugin_Hypothesis::GetEnforcedTriangles(_hyp); // TIDSortedElemSet enforcedQuadrangles = GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(_hyp); GHS3DPlugin_Hypothesis::TID2SizeMap nodeIDToSizeMap = GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(_hyp); - int nbEnforcedVertices = enforcedVertices.size(); + int nbEnforcedVertices = coordsSizeMap.size(); int nbEnforcedNodes = enforcedNodes.size(); std::cout << nbEnforcedNodes << " enforced nodes from hypo" << std::endl; std::cout << nbEnforcedVertices << " enforced vertices from hypo" << std::endl; - vector aNodeByGhs3dId, anEnforcedNodeByGhs3dId; - map aNodeToGhs3dIdMap; + std::vector aNodeByGhs3dId, anEnforcedNodeByGhs3dId; + std::map aNodeToGhs3dIdMap; + std::vector anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId; { SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh )); if ( theMesh.NbQuadrangles() > 0 ) @@ -3388,9 +3545,9 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), *proxyMesh, &theMesh, - aNodeByGhs3dId, anEnforcedNodeByGhs3dId, aNodeToGhs3dIdMap, + aNodeByGhs3dId, anEnforcedNodeByGhs3dId, aNodeToGhs3dIdMap, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId, enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/ - enforcedVertices); + coordsSizeMap); } // ----------------- @@ -3426,7 +3583,8 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, #ifdef WITH_SMESH_CANCEL_COMPUTE this, #endif - theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap); + theHelper, theShape, aNodeByGhs3dId, aNodeToGhs3dIdMap, + enfVerticesWithGroup, anEdgeGroupByGhs3dId, aFaceGroupByGhs3dId); // --------------------- // remove working files @@ -4061,13 +4219,16 @@ bool GHS3DPlugin_GHS3D::importGMFMesh(const char* theGMFFileName, SMESH_Mesh& th { SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh ); // TopoDS_Shape theShape = theMesh.GetShapeToMesh(); - vector dummyNodeVector; - map dummyNodeMap; + std::vector dummyNodeVector; + std::map dummyNodeMap; + std::map, std::string> dummyEnfVertGroup; + std::vector dummyElemGroup1, dummyElemGroup2; + bool ok = readGMFFile(theGMFFileName, #ifdef WITH_SMESH_CANCEL_COMPUTE this, #endif - helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap); + helper, theMesh.GetShapeToMesh(), dummyNodeVector, dummyNodeMap, dummyEnfVertGroup, dummyElemGroup1, dummyElemGroup2); theMesh.GetMeshDS()->Modified(); return ok; } diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx index 3888942..ae15003 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.hxx @@ -28,6 +28,7 @@ #include "SMESH_3D_Algo.hxx" #include "SMESH_Gen.hxx" +#include "SMESH_Gen_i.hxx" #include #include @@ -48,6 +49,7 @@ class SMESH_Mesh; class StdMeshers_ViscousLayers; class TCollection_AsciiString; class _Ghs2smdsConvertor; +class TopoDS_Shape; class GHS3DPlugin_GHS3D: public SMESH_3D_Algo { @@ -79,12 +81,15 @@ private: bool storeErrorDescription(const TCollection_AsciiString& logFile, const _Ghs2smdsConvertor & toSmdsConvertor ); - + TopoDS_Shape entryToShape(std::string entry); + int _iShape; int _nbShape; bool _keepFiles; const GHS3DPlugin_Hypothesis* _hyp; const StdMeshers_ViscousLayers* _viscousLayersHyp; + SALOMEDS::Study_var myStudy; + SMESH_Gen_i* smeshGen_i; #ifdef WITH_SMESH_CANCEL_COMPUTE volatile bool _compute_canceled; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index 9793dfe..b518b34 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -56,9 +56,9 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()), _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()), _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()), - _enfNodes(DefaultIDSortedNodeSet()), - _enfEdges(DefaultIDSortedElemSet()), - _enfTriangles(DefaultIDSortedElemSet()), + _enfNodes(TIDSortedNodeGroupMap()), + _enfEdges(TIDSortedElemGroupMap()), + _enfTriangles(TIDSortedElemGroupMap()), _nodeIDToSizeMap(DefaultID2SizeMap()), _elementIDToSizeMap(DefaultID2SizeMap()) { @@ -414,7 +414,7 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string //======================================================================= //function : SetEnforcedMesh //======================================================================= -bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size) +bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size, std::string groupName) { TIDSortedElemSet theElemSet; SMDS_ElemIteratorPtr eIt; @@ -422,13 +422,13 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::Element while ( eIt->more() ) theElemSet.insert( eIt->next() ); MESSAGE("Add "<(elem); if (node) { - _enfNodes.insert(node); + _enfNodes.insert(make_pair(node,groupName)); _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); added = true; } else { - _enfNodes.insert(elem->begin_nodes(),elem->end_nodes()); +// _enfNodes.insert(elem->begin_nodes(),elem->end_nodes()); SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator(); - for (;nodeIt->more();) - _nodeIDToSizeMap.insert(make_pair(nodeIt->next()->GetID(), size)); + for (;nodeIt->more();) { + node = dynamic_cast(nodeIt->next()); + _enfNodes.insert(make_pair(node,groupName)); + _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); + } added = true; } break; case SMESH::EDGE: if (elem->GetType() == SMDSAbs_Edge) { - _enfEdges.insert(elem); + _enfEdges.insert(make_pair(elem,groupName)); _elementIDToSizeMap.insert(make_pair(elem->GetID(), size)); added = true; } @@ -464,7 +467,7 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM SMDS_ElemIteratorPtr it = elem->edgesIterator(); for (;it->more();) { const SMDS_MeshElement* anEdge = it->next(); - _enfEdges.insert(anEdge); + _enfEdges.insert(make_pair(anEdge,groupName)); _elementIDToSizeMap.insert(make_pair(anEdge->GetID(), size)); } added = true; @@ -474,7 +477,7 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM if (elem->GetType() == SMDSAbs_Face) { if (elem->NbCornerNodes() == 3) { - _enfTriangles.insert(elem); + _enfTriangles.insert(make_pair(elem,groupName)); _elementIDToSizeMap.insert(make_pair(elem->GetID(), size)); added = true; } @@ -484,7 +487,7 @@ bool GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM for (;it->more();) { const SMDS_MeshElement* aFace = it->next(); if (aFace->NbCornerNodes() == 3) { - _enfTriangles.insert(aFace); + _enfTriangles.insert(make_pair(aFace,groupName)); _elementIDToSizeMap.insert(make_pair(aFace->GetID(), size)); added = true; } @@ -751,24 +754,6 @@ bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint() return false; } -//======================================================================= -//function : DefaultIDSortedNodeSet -//======================================================================= - -TIDSortedNodeSet GHS3DPlugin_Hypothesis::DefaultIDSortedNodeSet() -{ - return TIDSortedNodeSet(); -} - -//======================================================================= -//function : DefaultIDSortedElemSet -//======================================================================= - -TIDSortedElemSet GHS3DPlugin_Hypothesis::DefaultIDSortedElemSet() -{ - return TIDSortedElemSet(); -} - //======================================================================= //function : DefaultID2SizeMap //======================================================================= @@ -1085,7 +1070,11 @@ bool GHS3DPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/ std::string GHS3DPlugin_Hypothesis::CommandToRun(const GHS3DPlugin_Hypothesis* hyp, const bool hasShapeToMesh) { - TCollection_AsciiString cmd( "ghs3d" ); // ghs3dV4.1_32bits (to permit the .mesh output) + TCollection_AsciiString cmd; + if (hasShapeToMesh) + cmd = "ghs3d-41"; // to use old mesh2 format + else + cmd = "ghs3d"; // to use new mesh format // check if any option is overridden by hyp->myTextOption bool m = hyp ? ( hyp->myTextOption.find("-m") == std::string::npos ) : true; bool M = hyp ? ( hyp->myTextOption.find("-M") == std::string::npos ) : true; @@ -1242,19 +1231,19 @@ GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis: return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryGHS3DEnforcedVertexMap(); } -TIDSortedNodeSet GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp) +GHS3DPlugin_Hypothesis::TIDSortedNodeGroupMap GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeSet(); + return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeGroupMap(); } -TIDSortedElemSet GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp) +GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemSet(); + return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemGroupMap(); } -TIDSortedElemSet GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp) +GHS3DPlugin_Hypothesis::TIDSortedElemGroupMap GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemSet(); + return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemGroupMap(); } GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp) diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index 68f77eb..8532002 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -27,6 +27,8 @@ #include "GHS3DPlugin_Defs.hxx" +#include + #include "SMESH_Hypothesis.hxx" #include "SMESH_Mesh_i.hxx" #include "SMESH_Gen_i.hxx" @@ -76,6 +78,9 @@ public: typedef std::map TID2SizeMap; + typedef std::map TIDSortedElemGroupMap; + typedef std::map TIDSortedNodeGroupMap; + /*! * To mesh "holes" in a solid or not. Default is to mesh. */ @@ -187,12 +192,12 @@ public: /*! * To set enforced elements */ - bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size); - bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size); + bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size, std::string groupName = ""); + bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size, std::string groupName = ""); void ClearEnforcedMeshes(); - const TIDSortedNodeSet _GetEnforcedNodes() const { return _enfNodes; } - const TIDSortedElemSet _GetEnforcedEdges() const { return _enfEdges; } - const TIDSortedElemSet _GetEnforcedTriangles() const { return _enfTriangles; } + const TIDSortedNodeGroupMap _GetEnforcedNodes() const { return _enfNodes; } + const TIDSortedElemGroupMap _GetEnforcedEdges() const { return _enfEdges; } + const TIDSortedElemGroupMap _GetEnforcedTriangles() const { return _enfTriangles; } const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; } const TID2SizeMap _GetElementIDToSizeMap() const {return _elementIDToSizeMap; } /*! @@ -203,9 +208,9 @@ public: static TGHS3DEnforcedVertexEntryValues GetEnforcedVerticesEntrySize(const GHS3DPlugin_Hypothesis* hyp); static TCoordsGHS3DEnforcedVertexMap GetEnforcedVerticesByCoords(const GHS3DPlugin_Hypothesis* hyp); static TGeomEntryGHS3DEnforcedVertexMap GetEnforcedVerticesByEntry(const GHS3DPlugin_Hypothesis* hyp); - static TIDSortedNodeSet GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp); - static TIDSortedElemSet GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp); - static TIDSortedElemSet GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp); + static TIDSortedNodeGroupMap GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp); + static TIDSortedElemGroupMap GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp); + static TIDSortedElemGroupMap GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp); static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); static TID2SizeMap GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); @@ -227,8 +232,8 @@ public: static TCoordsGHS3DEnforcedVertexMap DefaultCoordsGHS3DEnforcedVertexMap() {return TCoordsGHS3DEnforcedVertexMap();} static TGeomEntryGHS3DEnforcedVertexMap DefaultGeomEntryGHS3DEnforcedVertexMap() {return TGeomEntryGHS3DEnforcedVertexMap();} static TGroupNameGHS3DEnforcedVertexMap DefaultGroupNameGHS3DEnforcedVertexMap() {return TGroupNameGHS3DEnforcedVertexMap();} - static TIDSortedNodeSet DefaultIDSortedNodeSet(); - static TIDSortedElemSet DefaultIDSortedElemSet(); + static TIDSortedNodeGroupMap DefaultIDSortedNodeGroupMap() {return TIDSortedNodeGroupMap();} + static TIDSortedElemGroupMap DefaultIDSortedElemGroupMap() {return TIDSortedElemGroupMap();} static TID2SizeMap DefaultID2SizeMap(); // Persistence @@ -268,9 +273,9 @@ private: TCoordsGHS3DEnforcedVertexMap _coordsEnfVertexMap; // map to get "geom" enf vertex (through the geom entries) TGeomEntryGHS3DEnforcedVertexMap _geomEntryEnfVertexMap; - TIDSortedNodeSet _enfNodes; - TIDSortedElemSet _enfEdges; - TIDSortedElemSet _enfTriangles; + TIDSortedNodeGroupMap _enfNodes; + TIDSortedElemGroupMap _enfEdges; + TIDSortedElemGroupMap _enfTriangles; TID2SizeMap _nodeIDToSizeMap; TID2SizeMap _elementIDToSizeMap; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index 102670a..f62b5dd 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -713,6 +713,37 @@ void GHS3DPlugin_Hypothesis_i::ClearEnforcedMeshes() SMESH::TPythonDump () << _this() << ".ClearEnforcedMeshes() "; } +/*! + * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource. The elements will be grouped in theGroupName. + */ +bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, const char* theGroupName) + throw (SALOME::SALOME_Exception) +{ +#if GHS3D_VERSION >= 42 + 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::TPythonDump () << _this() << ".SetEnforcedMeshWithGroup( " + << theSource << ", " << theType << ", \"" << theGroupName << "\" )"; + } + else if (theMesh_i) + { + SMESH::TPythonDump () << _this() << ".SetEnforcedMeshWithGroup( " + << theSource << ".GetMesh(), " << theType << ", \"" << theGroupName << "\" )"; + } + return res; +#else + 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; + throw SALOME::SALOME_Exception(ExDescription); +#endif +} + /*! * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource. */ @@ -744,6 +775,37 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSour #endif } +/*! + * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size. The elements will be grouped in theGroupName. + */ +bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName) + throw (SALOME::SALOME_Exception) +{ + if (theSize <= 0) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = "Size cannot be negative"; + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::SetEnforcedMeshSize(theSource, theType)"; + ExDescription.lineNumber = 475; + 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::TPythonDump () << _this() << ".SetEnforcedMeshSizeWithGroup( " + << theSource << ", " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + else if (theMesh_i) + { + SMESH::TPythonDump () << _this() << ".SetEnforcedMeshSizeWithGroup( " + << theSource << ".GetMesh(), " << theType << ", " << theSize << ", \"" << theGroupName << "\" )"; + } + return res; +} + /*! * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size. */ @@ -775,7 +837,7 @@ bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr the return res; } -bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize) +bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize, const char* theGroupName) throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); @@ -785,8 +847,8 @@ 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)"; - ExDescription.lineNumber = 502; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } @@ -795,8 +857,8 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou SALOME::ExceptionStruct ExDescription; ExDescription.text = "Bad elementType"; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize)"; - ExDescription.lineNumber = 502; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } @@ -809,8 +871,8 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou SALOME::ExceptionStruct ExDescription; ExDescription.text = "The source mesh has bad type"; ExDescription.type = SALOME::BAD_PARAM; - ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize)"; - ExDescription.lineNumber = 502; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } @@ -828,14 +890,14 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou if (theMesh_i) { try { - return this->GetImpl()->SetEnforcedMesh(anImplPtr->GetImpl(), theType, theSize); + return this->GetImpl()->SetEnforcedMesh(anImplPtr->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)"; - ExDescription.lineNumber = 502; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { @@ -875,14 +937,14 @@ bool GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou MESSAGE("Add "<GetName()); try { - return this->GetImpl()->SetEnforcedElements(theElemSet, theType, theSize); + return this->GetImpl()->SetEnforcedElements(theElemSet, 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)"; - ExDescription.lineNumber = 502; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::_SetEnforcedMesh(theSource, theType, theSize, theGroupName)"; + ExDescription.lineNumber = 840; throw SALOME::SALOME_Exception(ExDescription); } catch (SALOME_Exception& ex) { diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx index b3381bd..f6e3947 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx @@ -142,7 +142,9 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: * To set an enforced mesh */ bool SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType) throw (SALOME::SALOME_Exception); + bool SetEnforcedMeshWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, const char* theGroupName) throw (SALOME::SALOME_Exception); bool SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size) throw (SALOME::SALOME_Exception); + bool SetEnforcedMeshSizeWithGroup(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size, const char* theGroupName) throw (SALOME::SALOME_Exception); void ClearEnforcedMeshes(); // Get implementation @@ -153,7 +155,7 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: private: - bool _SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size) throw (SALOME::SALOME_Exception); + bool _SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size, const char* theGroupName="") throw (SALOME::SALOME_Exception); }; #endif