From dfb45c3e7bd1269a3a79a521d96a5b20316ef944 Mon Sep 17 00:00:00 2001 From: gdd Date: Mon, 9 May 2011 18:44:07 +0000 Subject: [PATCH] Started to add the possibility to add enforced vertex from geom vertex. In Compute with a geometry, rool back to previous methods WriteFaces and WritePoints. Bug: the enforced vertices do not work in this case. It seems to come from the version of Ghs3d. --- idl/GHS3DPlugin_Algorithm.idl | 22 +- src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx | 1278 ++++++++++++------ src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx | 21 +- src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx | 2 +- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx | 675 +++++---- src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx | 160 ++- src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx | 319 ++++- src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx | 21 +- src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx | 106 +- src/GUI/GHS3DPluginGUI_HypothesisCreator.h | 31 +- 10 files changed, 1770 insertions(+), 865 deletions(-) diff --git a/idl/GHS3DPlugin_Algorithm.idl b/idl/GHS3DPlugin_Algorithm.idl index 99db25e..7b8da88 100644 --- a/idl/GHS3DPlugin_Algorithm.idl +++ b/idl/GHS3DPlugin_Algorithm.idl @@ -33,10 +33,12 @@ */ module GHS3DPlugin { + typedef sequence TCoords; struct GHS3DEnforcedVertex { - double x; - double y; - double z; + string name; + string geomEntry; + TCoords coords; + string groupName; double size; }; @@ -46,7 +48,7 @@ module GHS3DPlugin */ interface GHS3DPlugin_GHS3D : SMESH::SMESH_3D_Algo { - boolean importGMFMesh(in string aGMFFileName); + SMESH::SMESH_Mesh importGMFMesh(in string aGMFFileName); }; /*! @@ -131,14 +133,18 @@ module GHS3DPlugin /*! * To set an enforced vertex */ - void SetEnforcedVertex(in double x, in double y, in double z, in double size); + boolean SetEnforcedVertex(in double x, in double y, in double z, in double size) raises (SALOME::SALOME_Exception); + boolean SetEnforcedVertexGeom(in GEOM::GEOM_Object theVertex, in double size) raises (SALOME::SALOME_Exception); + boolean SetEnforcedVertexGeomWithGroup(in GEOM::GEOM_Object theVertex, in double size, in string groupName) raises (SALOME::SALOME_Exception); double GetEnforcedVertex(in double x, in double y, in double z) raises (SALOME::SALOME_Exception); - void RemoveEnforcedVertex(in double x, in double y, in double z) raises (SALOME::SALOME_Exception); + double GetEnforcedVertexGeom(in GEOM::GEOM_Object theVertex) raises (SALOME::SALOME_Exception); + boolean RemoveEnforcedVertex(in double x, in double y, in double z) raises (SALOME::SALOME_Exception); + boolean RemoveEnforcedVertexGeom(in GEOM::GEOM_Object theVertex) raises (SALOME::SALOME_Exception); GHS3DEnforcedVertexList GetEnforcedVertices(); void ClearEnforcedVertices(); - void SetEnforcedMesh(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType) raises (SALOME::SALOME_Exception); - void SetEnforcedMeshSize(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in double size) raises (SALOME::SALOME_Exception); + boolean SetEnforcedMesh(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType) raises (SALOME::SALOME_Exception); + boolean SetEnforcedMeshSize(in SMESH::SMESH_IDSource theSource, in SMESH::ElementType elementType, in double size) raises (SALOME::SALOME_Exception); void ClearEnforcedMeshes(); }; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx index f9ba1c3..9d93c00 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D.cxx @@ -1266,12 +1266,12 @@ static bool writeGMFFile(const char* theMesh TIDSortedElemSet & theEnforcedEdges, TIDSortedElemSet & theEnforcedTriangles, // TIDSortedElemSet & theEnforcedQuadrangles, - GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices) + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices) { MESSAGE("writeGMFFile w/o geometry"); int idx, idxRequired, idxSol; const int dummyint = 0; - GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt; std::vector enfVertexSizes; const SMDS_MeshElement* elem; TIDSortedElemSet anElemSet, theKeptEnforcedEdges, theKeptEnforcedTriangles/*, theKeptEnforcedQuadrangles*/; @@ -1483,7 +1483,7 @@ static bool writeGMFFile(const char* theMesh theRequiredNodes.push_back(node); } - int requiredNodes = theRequiredNodes.size(); +// int requiredNodes = theRequiredNodes.size(); int solSize = 0; std::vector > ReqVerTab; if (nbEnforcedVertices) { @@ -1511,51 +1511,60 @@ static bool writeGMFFile(const char* theMesh // GmfVertices std::cout << "Begin writting required nodes in GmfVertices" << std::endl; - GmfSetKwd(idx, GmfVertices, theOrderedNodes.size()+solSize); + 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;i & theNodeId2NodeIndexMap, - std::map & theSmdsToGhs3dIdMap, - std::map & theGhs3dIdToNodeMap, - TIDSortedNodeSet & theEnforcedNodes, - TIDSortedElemSet & theEnforcedEdges, - TIDSortedElemSet & theEnforcedTriangles, -// TIDSortedElemSet & theEnforcedQuadrangles, - GHS3DPlugin_Hypothesis::TEnforcedVertexValues & theEnforcedVertices) +// static bool writeGMFFile(const char* theMeshFileName, +// const char* theRequiredFileName, +// const char* theSolFileName, +// SMESH_MesherHelper& theHelper, +// const SMESH_ProxyMesh& theProxyMesh, +// std::map & theNodeId2NodeIndexMap, +// std::map & theSmdsToGhs3dIdMap, +// std::map & theGhs3dIdToNodeMap, +// TIDSortedNodeSet & theEnforcedNodes, +// TIDSortedElemSet & theEnforcedEdges, +// TIDSortedElemSet & theEnforcedTriangles, +// // TIDSortedElemSet & theEnforcedQuadrangles, +// GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices) +// { +// MESSAGE("writeGMFFile with geometry"); +// int idx, idxRequired, idxSol; +// int nbv, nbev, nben, aGhs3dID = 0; +// const int dummyint = 0; +// GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt; +// std::vector enfVertexSizes; +// TIDSortedNodeSet::const_iterator enfNodeIt; +// const SMDS_MeshNode* node; +// SMDS_NodeIteratorPtr nodeIt; +// +// idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION); +// if (!idx) +// return false; +// +// SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS(); +// +// /* ========================== NODES ========================== */ +// // NB_NODES +// nbv = theMeshDS->NbNodes(); +// if ( nbv == 0 ) +// return false; +// nbev = theEnforcedVertices.size(); +// nben = theEnforcedNodes.size(); +// +// // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D +// // The problem is in nodes on degenerated edges, we need to skip nodes which are free +// // and replace not-free nodes on edges by the node on vertex +// TNodeNodeMap n2nDegen; // map a node on degenerated edge to a node on vertex +// TNodeNodeMap::iterator n2nDegenIt; +// if ( theHelper.HasDegeneratedEdges() ) +// { +// set checkedSM; +// for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next()) +// { +// SMESH_subMesh* sm = theHelper.GetMesh()->GetSubMesh( e.Current() ); +// if ( checkedSM.insert( sm->GetId() ).second && theHelper.IsDegenShape(sm->GetId() )) +// { +// if ( SMESHDS_SubMesh* smDS = sm->GetSubMeshDS() ) +// { +// TopoDS_Shape vertex = TopoDS_Iterator( e.Current() ).Value(); +// const SMDS_MeshNode* vNode = SMESH_Algo::VertexNode( TopoDS::Vertex( vertex ), theMeshDS); +// { +// SMDS_NodeIteratorPtr nIt = smDS->GetNodes(); +// while ( nIt->more() ) +// n2nDegen.insert( make_pair( nIt->next(), vNode )); +// } +// } +// } +// } +// } +// +// const bool isQuadMesh = +// theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) || +// theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) || +// theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC ); +// +// std::vector > VerTab; +// std::set > VerMap; +// VerTab.clear(); +// std::vector aVerTab; +// // Loop from 1 to NB_NODES +// +// nodeIt = theMeshDS->nodesIterator(); +// +// while ( nodeIt->more() ) +// { +// node = nodeIt->next(); +// if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238 +// continue; +// if ( n2nDegen.count( node ) ) // Issue 0020674 +// continue; +// +// std::vector coords; +// coords.push_back(node->X()); +// coords.push_back(node->Y()); +// coords.push_back(node->Z()); +// if (VerMap.find(coords) != VerMap.end()) { +// aGhs3dID = theSmdsToGhs3dIdMap[node->GetID()]; +// theGhs3dIdToNodeMap[theSmdsToGhs3dIdMap[node->GetID()]] = node; +// continue; +// } +// VerTab.push_back(coords); +// VerMap.insert(coords); +// aGhs3dID++; +// theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); +// theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node )); +// } +// +// +// /* ENFORCED NODES ========================== */ +// if (nben) { +// std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl; +// for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) { +// double x = (*enfNodeIt)->X(); +// double y = (*enfNodeIt)->Y(); +// double z = (*enfNodeIt)->Z(); +// // Test if point is inside shape to mesh +// gp_Pnt myPoint(x,y,z); +// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); +// scl.Perform(myPoint, 1e-7); +// TopAbs_State result = scl.State(); +// if ( result != TopAbs_IN ) +// continue; +// std::vector coords; +// coords.push_back(x); +// coords.push_back(y); +// coords.push_back(z); +// if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) +// continue; +// if (VerMap.find(coords) != VerMap.end()) +// continue; +// VerTab.push_back(coords); +// VerMap.insert(coords); +// aGhs3dID++; +// theNodeId2NodeIndexMap.insert( make_pair( (*enfNodeIt)->GetID(), aGhs3dID )); +// } +// } +// +// +// /* ENFORCED VERTICES ========================== */ +// int solSize = 0; +// std::vector > ReqVerTab; +// ReqVerTab.clear(); +// if (nbev) { +// std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl; +// for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { +// double x = vertexIt->first[0]; +// double y = vertexIt->first[1]; +// double z = vertexIt->first[2]; +// // Test if point is inside shape to mesh +// gp_Pnt myPoint(x,y,z); +// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); +// scl.Perform(myPoint, 1e-7); +// TopAbs_State result = scl.State(); +// if ( result != TopAbs_IN ) +// continue; +// enfVertexSizes.push_back(vertexIt->second); +// std::vector coords; +// coords.push_back(x); +// coords.push_back(y); +// coords.push_back(z); +// if (VerMap.find(coords) != VerMap.end()) +// continue; +// ReqVerTab.push_back(coords); +// VerMap.insert(coords); +// solSize++; +// } +// } +// +// +// /* ========================== FACES ========================== */ +// +// int nbTriangles = 0/*, nbQuadrangles = 0*/, aSmdsID; +// TopTools_IndexedMapOfShape facesMap, trianglesMap/*, quadranglesMap*/; +// TIDSortedElemSet::const_iterator elemIt; +// const SMESHDS_SubMesh* theSubMesh; +// TopoDS_Shape aShape; +// SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace; +// const SMDS_MeshElement* aFace; +// map::const_iterator itOnMap; +// std::vector > tt, qt,et; +// tt.clear(); +// qt.clear(); +// et.clear(); +// std::vector att, aqt, aet; +// +// TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap ); +// +// for ( int i = 1; i <= facesMap.Extent(); ++i ) +// if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i)))) +// { +// SMDS_ElemIteratorPtr it = theSubMesh->GetElements(); +// while (it->more()) +// { +// const SMDS_MeshElement *elem = it->next(); +// int nbCornerNodes = elem->NbCornerNodes(); +// if (nbCornerNodes == 3) +// { +// trianglesMap.Add(facesMap(i)); +// nbTriangles ++; +// } +// // else if (nbCornerNodes == 4) +// // { +// // quadranglesMap.Add(facesMap(i)); +// // nbQuadrangles ++; +// // } +// } +// } +// +// /* TRIANGLES ========================== */ +// if (nbTriangles) { +// for ( int i = 1; i <= trianglesMap.Extent(); i++ ) +// { +// aShape = trianglesMap(i); +// theSubMesh = theProxyMesh.GetSubMesh(aShape); +// if ( !theSubMesh ) continue; +// itOnSubMesh = theSubMesh->GetElements(); +// while ( itOnSubMesh->more() ) +// { +// aFace = itOnSubMesh->next(); +// itOnSubFace = aFace->nodesIterator(); +// att.clear(); +// for ( int j = 0; j < 3; ++j ) { +// // find GHS3D ID +// node = castToNode( itOnSubFace->next() ); +// if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) +// node = n2nDegenIt->second; +// aSmdsID = node->GetID(); +// itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); +// ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); +// att.push_back((*itOnMap).second); +// } +// tt.push_back(att); +// } +// } +// } +// +// if (theEnforcedTriangles.size()) { +// std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl; +// // Iterate over the enforced triangles +// for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { +// aFace = (*elemIt); +// itOnSubFace = aFace->nodesIterator(); +// bool isOK = true; +// att.clear(); +// +// for ( int j = 0; j < 3; ++j ) { +// node = castToNode( itOnSubFace->next() ); +// if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) +// node = n2nDegenIt->second; +// // std::cout << node; +// double x = node->X(); +// double y = node->Y(); +// double z = node->Z(); +// // Test if point is inside shape to mesh +// gp_Pnt myPoint(x,y,z); +// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); +// scl.Perform(myPoint, 1e-7); +// TopAbs_State result = scl.State(); +// if ( result != TopAbs_IN ) { +// isOK = false; +// theEnforcedTriangles.erase(elemIt); +// continue; +// } +// std::vector coords; +// coords.push_back(x); +// coords.push_back(y); +// coords.push_back(z); +// if (VerMap.find(coords) != VerMap.end()) { +// att.push_back(theNodeId2NodeIndexMap[node->GetID()]); +// continue; +// } +// VerTab.push_back(coords); +// VerMap.insert(coords); +// aGhs3dID++; +// theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID )); +// att.push_back(aGhs3dID); +// } +// if (isOK) +// tt.push_back(att); +// } +// } +// +// +// /* ========================== EDGES ========================== */ +// +// if (theEnforcedEdges.size()) { +// // Iterate over the enforced edges +// std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl; +// for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { +// aFace = (*elemIt); +// bool isOK = true; +// itOnSubFace = aFace->nodesIterator(); +// aet.clear(); +// for ( int j = 0; j < 2; ++j ) { +// node = castToNode( itOnSubFace->next() ); +// if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) +// node = n2nDegenIt->second; +// double x = node->X(); +// double y = node->Y(); +// double z = node->Z(); +// // Test if point is inside shape to mesh +// gp_Pnt myPoint(x,y,z); +// BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); +// scl.Perform(myPoint, 1e-7); +// TopAbs_State result = scl.State(); +// if ( result != TopAbs_IN ) { +// isOK = false; +// theEnforcedEdges.erase(elemIt); +// continue; +// } +// std::vector coords; +// coords.push_back(x); +// coords.push_back(y); +// coords.push_back(z); +// if (VerMap.find(coords) != VerMap.end()) { +// aet.push_back(theNodeId2NodeIndexMap[node->GetID()]); +// continue; +// } +// VerTab.push_back(coords); +// VerMap.insert(coords); +// +// aGhs3dID++; +// theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID )); +// aet.push_back(aGhs3dID); +// } +// if (isOK) +// et.push_back(aet); +// } +// } +// +// +// /* Write vertices number */ +// MESSAGE("Number of vertices: "<GetElements(); +// // for ( int j = 0; j < 4; ++j ) +// // { +// // aFace = itOnSubMesh->next(); +// // itOnSubFace = aFace->nodesIterator(); +// // aqt.clear(); +// // while ( itOnSubFace->more() ) { +// // // find GHS3D ID +// // aSmdsID = itOnSubFace->next()->GetID(); +// // itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); +// // ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); +// // aqt.push_back((*itOnMap).second); +// // } +// // qt.push_back(aqt); +// // } +// // } +// // } +// // +// // if (theEnforcedQuadrangles.size()) { +// // // Iterate over the enforced triangles +// // for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) { +// // aFace = (*elemIt); +// // bool isOK = true; +// // itOnSubFace = aFace->nodesIterator(); +// // aqt.clear(); +// // for ( int j = 0; j < 4; ++j ) { +// // int aNodeID = itOnSubFace->next()->GetID(); +// // itOnMap = theNodeId2NodeIndexMap.find(aNodeID); +// // if (itOnMap != theNodeId2NodeIndexMap.end()) +// // aqt.push_back((*itOnMap).second); +// // else { +// // isOK = false; +// // theEnforcedQuadrangles.erase(elemIt); +// // break; +// // } +// // } +// // if (isOK) +// // qt.push_back(aqt); +// // } +// // } +// // +// +// // /* Write quadrilaterals number */ +// // if (qt.size()) { +// // GmfSetKwd(idx, GmfQuadrilaterals, qt.size()); +// // for (int i=0;i & theSmdsToGhs3dIdMap, + const map & theEnforcedNodeIdToGhs3dIdMap, + TIDSortedElemSet & theEnforcedEdges, + TIDSortedElemSet & theEnforcedTriangles) { - MESSAGE("writeGMFFile with geometry"); - int idx, nbv, nbev, nben, aGhs3dID = 0; - const int dummyint = 0; - GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator vertexIt; - std::vector enfVertexSizes; - TIDSortedNodeSet::const_iterator enfNodeIt; - const SMDS_MeshNode* node; - SMDS_NodeIteratorPtr nodeIt; + // record structure: + // + // NB_ELEMS DUMMY_INT + // Loop from 1 to NB_ELEMS + // NB_NODES NODE_NB_1 NODE_NB_2 ... (NB_NODES + 1) times: DUMMY_INT - idx = GmfOpenMesh(theMeshFileName, GmfWrite, GMFVERSION, GMFDIMENSION); - if (!idx) - return false; + TopoDS_Shape aShape; + const SMESHDS_SubMesh* theSubMesh; + const SMDS_MeshElement* aFace; + const char* space = " "; + const int dummyint = 0; + map::const_iterator itOnMap; + SMDS_ElemIteratorPtr itOnSubMesh, itOnSubFace; + int nbNodes, aSmdsID; + + TIDSortedElemSet::const_iterator elemIt; + int nbEnforcedEdges = theEnforcedEdges.size(); + int nbEnforcedTriangles = theEnforcedTriangles.size(); + + // count triangles bound to geometry + int nbTriangles = 0; + + TopTools_IndexedMapOfShape facesMap, trianglesMap; + TopExp::MapShapes( theShape, TopAbs_FACE, facesMap ); + + for ( int i = 1; i <= facesMap.Extent(); ++i ) + if (( theSubMesh = theMesh.GetSubMesh( facesMap(i)))) + nbTriangles += theSubMesh->NbElements(); + + std::cout << " " << facesMap.Extent() << " shapes of 2D dimension and" << std::endl; + if (nbEnforcedEdges+nbEnforcedTriangles) + std::cout << " " << nbEnforcedEdges+nbEnforcedTriangles + << " enforced shapes:" << std::endl; + if (nbEnforcedEdges) + std::cout << " " << nbEnforcedEdges << " enforced edges" << std::endl; + if (nbEnforcedTriangles) + std::cout << " " << nbEnforcedTriangles << " enforced triangles" << std::endl; + std::cout << std::endl; + +// theFile << space << nbTriangles << space << dummyint << std::endl; + std::ostringstream globalStream, localStream, aStream; + + for ( int i = 1; i <= facesMap.Extent(); i++ ) + { + aShape = facesMap(i); + theSubMesh = theMesh.GetSubMesh(aShape); + if ( !theSubMesh ) continue; + itOnSubMesh = theSubMesh->GetElements(); + while ( itOnSubMesh->more() ) + { + aFace = itOnSubMesh->next(); + nbNodes = aFace->NbCornerNodes(); + + localStream << nbNodes << space; + + itOnSubFace = aFace->nodesIterator(); + for ( int j = 0; j < 3; ++j ) { + // find GHS3D ID + aSmdsID = itOnSubFace->next()->GetID(); + itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); + // if ( itOnMap == theSmdsToGhs3dIdMap.end() ) { + // cout << "not found node: " << aSmdsID << endl; + // return false; + // } + ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); + + localStream << (*itOnMap).second << space ; + } + + // (NB_NODES + 1) times: DUMMY_INT + for ( int j=0; j<=nbNodes; j++) + localStream << dummyint << space ; + + localStream << std::endl; + } + } - SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS(); + globalStream << localStream.str(); + localStream.str(""); + + // + // FACES : END + // + +// // +// // ENFORCED EDGES : BEGIN +// // +// +// // Iterate over the enforced edges +// int usedEnforcedEdges = 0; +// bool isOK; +// for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { +// aFace = (*elemIt); +// isOK = true; +// itOnSubFace = aFace->nodesIterator(); +// aStream.str(""); +// aStream << "2" << space ; +// for ( int j = 0; j < 2; ++j ) { +// aSmdsID = itOnSubFace->next()->GetID(); +// itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID); +// if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end()) +// aStream << (*itOnMap).second << space; +// else { +// isOK = false; +// break; +// } +// } +// if (isOK) { +// for ( int j=0; j<=2; j++) +// aStream << dummyint << space ; +// // aStream << dummyint << space << dummyint; +// localStream << aStream.str() << std::endl; +// usedEnforcedEdges++; +// } +// } +// +// if (usedEnforcedEdges) { +// globalStream << localStream.str(); +// localStream.str(""); +// } +// +// // +// // ENFORCED EDGES : END +// // +// // +// +// // +// // ENFORCED TRIANGLES : BEGIN +// // +// // Iterate over the enforced triangles +// int usedEnforcedTriangles = 0; +// for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { +// aFace = (*elemIt); +// nbNodes = aFace->NbCornerNodes(); +// isOK = true; +// itOnSubFace = aFace->nodesIterator(); +// aStream.str(""); +// aStream << nbNodes << space ; +// for ( int j = 0; j < 3; ++j ) { +// aSmdsID = itOnSubFace->next()->GetID(); +// itOnMap = theEnforcedNodeIdToGhs3dIdMap.find(aSmdsID); +// if (itOnMap != theEnforcedNodeIdToGhs3dIdMap.end()) +// aStream << (*itOnMap).second << space; +// else { +// isOK = false; +// break; +// } +// } +// if (isOK) { +// for ( int j=0; j<=3; j++) +// aStream << dummyint << space ; +// localStream << aStream.str() << std::endl; +// usedEnforcedTriangles++; +// } +// } +// +// if (usedEnforcedTriangles) { +// globalStream << localStream.str(); +// localStream.str(""); +// } +// +// // +// // ENFORCED TRIANGLES : END +// // - /* ========================== NODES ========================== */ + theFile + << nbTriangles/*+usedEnforcedTriangles+usedEnforcedEdges*/ + << " 0" << std::endl + << globalStream.str(); + + return true; +} + +//======================================================================= +//function : writePoints +//purpose : +//======================================================================= + +static bool writePoints (ofstream & theFile, + SMESH_MesherHelper& theHelper, + map & theSmdsToGhs3dIdMap, + map & theEnforcedNodeIdToGhs3dIdMap, + map & theGhs3dIdToNodeMap, + GHS3DPlugin_Hypothesis::TID2SizeMap & theNodeIDToSizeMap, + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues & theEnforcedVertices, + TIDSortedNodeSet & theEnforcedNodes, + TIDSortedElemSet & theEnforcedEdges, + TIDSortedElemSet & theEnforcedTriangles) +{ + // record structure: + // // NB_NODES - nbv = theMeshDS->NbNodes(); - if ( nbv == 0 ) + // Loop from 1 to NB_NODES + // X Y Z DUMMY_INT + + SMESHDS_Mesh * theMeshDS = theHelper.GetMeshDS(); + int nbNodes = theMeshDS->NbNodes(); + if ( nbNodes == 0 ) return false; - nbev = theEnforcedVertices.size(); - nben = theEnforcedNodes.size(); + int nbEnforcedVertices = theEnforcedVertices.size(); + int nbEnforcedNodes = theEnforcedNodes.size(); + + const TopoDS_Shape shapeToMesh = theMeshDS->ShapeToMesh(); + + int aGhs3dID = 1; + SMDS_NodeIteratorPtr it = theMeshDS->nodesIterator(); + const SMDS_MeshNode* node; +// // Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D // The problem is in nodes on degenerated edges, we need to skip nodes which are free // and replace not-free nodes on edges by the node on vertex @@ -1860,6 +2494,7 @@ static bool writeGMFFile(const char* theMeshF TNodeNodeMap::iterator n2nDegenIt; if ( theHelper.HasDegeneratedEdges() ) { + set checkedSM; for (TopExp_Explorer e(theMeshDS->ShapeToMesh(), TopAbs_EDGE ); e.More(); e.Next()) { @@ -1885,49 +2520,58 @@ static bool writeGMFFile(const char* theMeshF theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) || theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC ); - std::vector > VerTab; - std::set > VerMap; - VerTab.clear(); - std::vector aVerTab; + + const char* space = " "; + const int dummyint = 0; + + // NB_NODES + std::cout << std::endl; + std::cout << "The initial 2D mesh contains :" << std::endl; + std::cout << " " << nbNodes << " nodes" << std::endl; + if (nbEnforcedVertices > 0) + std::cout << " " << nbEnforcedVertices << " enforced vertices" << std::endl; + if (nbEnforcedNodes > 0) + std::cout << " " << nbEnforcedNodes << " enforced nodes" << std::endl; + std::cout << std::endl; + std::cout << "Start writing in 'points' file ..." << std::endl; + theFile << nbNodes << std::endl; + // Loop from 1 to NB_NODES - nodeIt = theMeshDS->nodesIterator(); - - while ( nodeIt->more() ) + while ( it->more() ) { - node = nodeIt->next(); + node = it->next(); if ( isQuadMesh && theHelper.IsMedium( node )) // Issue 0021238 continue; if ( n2nDegen.count( node ) ) // Issue 0020674 continue; - std::vector coords; - coords.push_back(node->X()); - coords.push_back(node->Y()); - coords.push_back(node->Z()); - if (VerMap.find(coords) != VerMap.end()) { - aGhs3dID = theSmdsToGhs3dIdMap[node->GetID()]; - theGhs3dIdToNodeMap[theSmdsToGhs3dIdMap[node->GetID()]] = node; - continue; - } - VerTab.push_back(coords); - VerMap.insert(coords); - aGhs3dID++; theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID )); theGhs3dIdToNodeMap.insert( make_pair( aGhs3dID, node )); + aGhs3dID++; + + // X Y Z DUMMY_INT + theFile + << node->X() << space + << node->Y() << space + << node->Z() << space + << dummyint; + + theFile << std::endl; + } - - /* ENFORCED NODES ========================== */ - if (nben) { - std::cout << "Add " << nben << " enforced nodes to input .mesh file" << std::endl; - for(enfNodeIt = theEnforcedNodes.begin() ; enfNodeIt != theEnforcedNodes.end() ; ++enfNodeIt) { - double x = (*enfNodeIt)->X(); - double y = (*enfNodeIt)->Y(); - double z = (*enfNodeIt)->Z(); + // Iterate over the enforced nodes + std::map enfVertexIndexSizeMap; + if (nbEnforcedNodes) { + TIDSortedNodeSet::const_iterator nodeIt = theEnforcedNodes.begin(); + for( ; nodeIt != theEnforcedNodes.end() ; ++nodeIt) { + double x = (*nodeIt)->X(); + double y = (*nodeIt)->Y(); + double z = (*nodeIt)->Z(); // Test if point is inside shape to mesh gp_Pnt myPoint(x,y,z); - BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); + BRepClass3d_SolidClassifier scl(shapeToMesh); scl.Perform(myPoint, 1e-7); TopAbs_State result = scl.State(); if ( result != TopAbs_IN ) @@ -1938,314 +2582,61 @@ static bool writeGMFFile(const char* theMeshF coords.push_back(z); if (theEnforcedVertices.find(coords) != theEnforcedVertices.end()) continue; - if (VerMap.find(coords) != VerMap.end()) - continue; - VerTab.push_back(coords); - VerMap.insert(coords); + + double size = theNodeIDToSizeMap.find((*nodeIt)->GetID())->second; + // theGhs3dIdToNodeMap.insert( make_pair( nbNodes + i, (*nodeIt) )); + // MESSAGE("Adding enforced node (" << x << "," << y <<"," << z << ")"); + // X Y Z PHY_SIZE DUMMY_INT + theFile + << x << space + << y << space + << z << space + << size << space + << dummyint << space; + theFile << std::endl; + theEnforcedNodeIdToGhs3dIdMap.insert( make_pair( (*nodeIt)->GetID(), aGhs3dID )); + enfVertexIndexSizeMap[aGhs3dID] = -1; aGhs3dID++; - theNodeId2NodeIndexMap.insert( make_pair( (*enfNodeIt)->GetID(), aGhs3dID )); + // else + // MESSAGE("Enforced vertex (" << x << "," << y <<"," << z << ") is not inside the geometry: it was not added "); } } - - /* ENFORCED VERTICES ========================== */ - if (nbev) { - std::cout << "Add " << nbev << " enforced vertices to input .mesh file" << std::endl; - std::vector > ReqVerTab; - ReqVerTab.clear(); - std::vector aReqVerTab; - int solSize = 0; - for(vertexIt = theEnforcedVertices.begin() ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { + if (nbEnforcedVertices) { + // Iterate over the enforced vertices + GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues::const_iterator vertexIt = theEnforcedVertices.begin(); + for( ; vertexIt != theEnforcedVertices.end() ; ++vertexIt) { double x = vertexIt->first[0]; double y = vertexIt->first[1]; double z = vertexIt->first[2]; // Test if point is inside shape to mesh gp_Pnt myPoint(x,y,z); - BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); + BRepClass3d_SolidClassifier scl(shapeToMesh); scl.Perform(myPoint, 1e-7); TopAbs_State result = scl.State(); if ( result != TopAbs_IN ) continue; - enfVertexSizes.push_back(vertexIt->second); - std::vector coords; - coords.push_back(x); - coords.push_back(y); - coords.push_back(z); - if (VerMap.find(coords) != VerMap.end()) - continue; - ReqVerTab.push_back(coords); - VerMap.insert(coords); - solSize++; - } - - if (solSize) { - int idxRequired = GmfOpenMesh(theRequiredFileName, GmfWrite, GMFVERSION, GMFDIMENSION); - if (!idxRequired) - return false; - int idxSol = GmfOpenMesh(theSolFileName, GmfWrite, GMFVERSION, GMFDIMENSION); - if (!idxSol) - return false; - - int TypTab[] = {GmfSca}; - GmfSetKwd(idxRequired, GmfVertices, solSize); - GmfSetKwd(idxSol, GmfSolAtVertices, solSize, 1, TypTab); - - for (int i=0;i::const_iterator itOnMap; - std::vector > tt, qt,et; - tt.clear(); - qt.clear(); - et.clear(); - std::vector att, aqt, aet; - - TopExp::MapShapes( theMeshDS->ShapeToMesh(), TopAbs_FACE, facesMap ); - - for ( int i = 1; i <= facesMap.Extent(); ++i ) - if (( theSubMesh = theProxyMesh.GetSubMesh( facesMap(i)))) - { - SMDS_ElemIteratorPtr it = theSubMesh->GetElements(); - while (it->more()) - { - const SMDS_MeshElement *elem = it->next(); - int nbCornerNodes = elem->NbCornerNodes(); - if (nbCornerNodes == 3) - { - trianglesMap.Add(facesMap(i)); - nbTriangles ++; - } -// else if (nbCornerNodes == 4) -// { -// quadranglesMap.Add(facesMap(i)); -// nbQuadrangles ++; -// } - } - } - - /* TRIANGLES ========================== */ - if (nbTriangles) { - for ( int i = 1; i <= trianglesMap.Extent(); i++ ) - { - aShape = trianglesMap(i); - theSubMesh = theProxyMesh.GetSubMesh(aShape); - if ( !theSubMesh ) continue; - itOnSubMesh = theSubMesh->GetElements(); - while ( itOnSubMesh->more() ) - { - aFace = itOnSubMesh->next(); - itOnSubFace = aFace->nodesIterator(); - att.clear(); - for ( int j = 0; j < 3; ++j ) { - // find GHS3D ID - node = castToNode( itOnSubFace->next() ); - if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) - node = n2nDegenIt->second; - aSmdsID = node->GetID(); - itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); - ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); - att.push_back((*itOnMap).second); - } - tt.push_back(att); - } - } - } - - if (theEnforcedTriangles.size()) { - std::cout << "Add " << theEnforcedTriangles.size() << " enforced triangles to input .mesh file" << std::endl; - // Iterate over the enforced triangles - for(elemIt = theEnforcedTriangles.begin() ; elemIt != theEnforcedTriangles.end() ; ++elemIt) { - aFace = (*elemIt); - itOnSubFace = aFace->nodesIterator(); - bool isOK = true; - att.clear(); - - for ( int j = 0; j < 3; ++j ) { - node = castToNode( itOnSubFace->next() ); - if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) - node = n2nDegenIt->second; -// std::cout << node; - double x = node->X(); - double y = node->Y(); - double z = node->Z(); - // Test if point is inside shape to mesh - gp_Pnt myPoint(x,y,z); - BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); - scl.Perform(myPoint, 1e-7); - TopAbs_State result = scl.State(); - if ( result != TopAbs_IN ) { - isOK = false; - theEnforcedTriangles.erase(elemIt); - continue; - } - std::vector coords; - coords.push_back(x); - coords.push_back(y); - coords.push_back(z); - if (VerMap.find(coords) != VerMap.end()) { - att.push_back(theNodeId2NodeIndexMap[node->GetID()]); - continue; - } - VerTab.push_back(coords); - VerMap.insert(coords); - aGhs3dID++; - theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID )); - att.push_back(aGhs3dID); - } - if (isOK) - tt.push_back(att); - } - } - - - /* ========================== EDGES ========================== */ - - if (theEnforcedEdges.size()) { - // Iterate over the enforced edges - std::cout << "Add " << theEnforcedEdges.size() << " enforced edges to input .mesh file" << std::endl; - for(elemIt = theEnforcedEdges.begin() ; elemIt != theEnforcedEdges.end() ; ++elemIt) { - aFace = (*elemIt); - bool isOK = true; - itOnSubFace = aFace->nodesIterator(); - aet.clear(); - for ( int j = 0; j < 2; ++j ) { - node = castToNode( itOnSubFace->next() ); - if (( n2nDegenIt = n2nDegen.find( node )) != n2nDegen.end() ) - node = n2nDegenIt->second; - double x = node->X(); - double y = node->Y(); - double z = node->Z(); - // Test if point is inside shape to mesh - gp_Pnt myPoint(x,y,z); - BRepClass3d_SolidClassifier scl(theMeshDS->ShapeToMesh()); - scl.Perform(myPoint, 1e-7); - TopAbs_State result = scl.State(); - if ( result != TopAbs_IN ) { - isOK = false; - theEnforcedEdges.erase(elemIt); - continue; - } - std::vector coords; - coords.push_back(x); - coords.push_back(y); - coords.push_back(z); - if (VerMap.find(coords) != VerMap.end()) { - aet.push_back(theNodeId2NodeIndexMap[node->GetID()]); - continue; - } - VerTab.push_back(coords); - VerMap.insert(coords); - - aGhs3dID++; - theNodeId2NodeIndexMap.insert( make_pair( node->GetID(), aGhs3dID )); - aet.push_back(aGhs3dID); - } - if (isOK) - et.push_back(aet); + MESSAGE("Adding enforced vertex (" << x << "," << y <<"," << z << ") = " << vertexIt->second); + // X Y Z PHY_SIZE DUMMY_INT + theFile + << x << space + << y << space + << z << space + << vertexIt->second << space + << dummyint << space; + theFile << std::endl; + enfVertexIndexSizeMap[aGhs3dID] = vertexIt->second; + aGhs3dID++; } } - - - /* Write vertices number */ - MESSAGE("Number of vertices: "<GetElements(); -// for ( int j = 0; j < 4; ++j ) -// { -// aFace = itOnSubMesh->next(); -// itOnSubFace = aFace->nodesIterator(); -// aqt.clear(); -// while ( itOnSubFace->more() ) { -// // find GHS3D ID -// aSmdsID = itOnSubFace->next()->GetID(); -// itOnMap = theSmdsToGhs3dIdMap.find( aSmdsID ); -// ASSERT( itOnMap != theSmdsToGhs3dIdMap.end() ); -// aqt.push_back((*itOnMap).second); -// } -// qt.push_back(aqt); -// } -// } -// } -// -// if (theEnforcedQuadrangles.size()) { -// // Iterate over the enforced triangles -// for(elemIt = theEnforcedQuadrangles.begin() ; elemIt != theEnforcedQuadrangles.end() ; ++elemIt) { -// aFace = (*elemIt); -// bool isOK = true; -// itOnSubFace = aFace->nodesIterator(); -// aqt.clear(); -// for ( int j = 0; j < 4; ++j ) { -// int aNodeID = itOnSubFace->next()->GetID(); -// itOnMap = theNodeId2NodeIndexMap.find(aNodeID); -// if (itOnMap != theNodeId2NodeIndexMap.end()) -// aqt.push_back((*itOnMap).second); -// else { -// isOK = false; -// theEnforcedQuadrangles.erase(elemIt); -// break; -// } -// } -// if (isOK) -// qt.push_back(aqt); -// } -// } -// -// /* Write quadrilaterals number */ -// if (qt.size()) { -// GmfSetKwd(idx, GmfQuadrilaterals, qt.size()); -// for (int i=0;iis_open() && aPointsFile.rdbuf()->is_open(); + if (!Ok) { + INFOS( "Can't write into " << aFacesFileName); + return error(SMESH_Comment("Can't write into ") << aFacesFileName); + } + std::map aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap; std::map aGhs3dIdToNodeMap; std::map nodeID2nodeIndexMap; - GHS3DPlugin_Hypothesis::TEnforcedVertexValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp); + 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); @@ -2716,11 +3123,19 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, return false; } - Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), - helper, *proxyMesh, - aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, - enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/ - enforcedVertices); + Ok = (writePoints( aPointsFile, helper, + aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, aGhs3dIdToNodeMap, + nodeIDToSizeMap, + enforcedVertices, enforcedNodes, enforcedEdges, enforcedTriangles) + && + writeFaces ( aFacesFile, *proxyMesh, theShape, + aSmdsToGhs3dIdMap, anEnforcedNodeIdToGhs3dIdMap, + enforcedEdges, enforcedTriangles )); +// Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(), +// helper, *proxyMesh, +// aNodeId2NodeIndexMap, aSmdsToGhs3dIdMap, aGhs3dIdToNodeMap, +// enforcedNodes, enforcedEdges, enforcedTriangles, /*enforcedQuadrangles,*/ +// enforcedVertices); } // Write aSmdsToGhs3dIdMap to temp file @@ -2740,12 +3155,16 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } aIdsFile.close(); + aFacesFile.close(); + aPointsFile.close(); if ( ! Ok ) { if ( !_keepFiles ) { - removeFile( aGMFFileName ); - removeFile( aRequiredVerticesFileName ); - removeFile( aSolFileName ); +// removeFile( aGMFFileName ); +// removeFile( aRequiredVerticesFileName ); +// removeFile( aSolFileName ); + removeFile( aFacesFileName ); + removeFile( aPointsFileName ); removeFile( aSmdsToGhs3dIdMapFileName ); } return error(COMPERR_BAD_INPUT_MESH); @@ -2757,13 +3176,13 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // ----------------- TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp ).c_str() ); - // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read - cmd += TCollection_AsciiString(" -IM "); + cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file + // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) // cmd += TCollection_AsciiString(" --in ") + aGenericName; -// cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; -// cmd += TCollection_AsciiString(" --out ") + aGenericName; - cmd += TCollection_AsciiString(" -Om 1>" ) + aLogFileName; // dump into file +// cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired; +// cmd += TCollection_AsciiString(" --out ") + aResultGMFFileName; +// cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file std::cout << std::endl; std::cout << "Ghs3d execution..." << std::endl; @@ -2849,14 +3268,17 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, } if ( !_keepFiles ) { - removeFile( aSmdsToGhs3dIdMapFileName ); - // The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2) - #ifdef WITH_SMESH_CANCEL_COMPUTE if (! Ok) if(_compute_canceled) removeFile( aLogFileName ); #endif + removeFile( aFacesFileName ); + removeFile( aPointsFileName ); + removeFile( aResultFileName ); + removeFile( aBadResFileName ); + removeFile( aBbResFileName ); + removeFile( aSmdsToGhs3dIdMapFileName ); } std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file "; if ( !Ok ) @@ -2888,6 +3310,7 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, // to avoid access to the same files by eg different users TCollection_AsciiString aGenericName = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str(); + TCollection_AsciiString aGenericNameRequired = aGenericName + "_required"; TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log TCollection_AsciiString aResultFileName; @@ -2897,17 +3320,17 @@ bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh, #ifdef _DEBUG_ aGMFFileName = aGenericName + ".mesh"; // GMF mesh file aResultFileName = aGenericName + "Vol.mesh"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.mesh"; // GMF required vertices mesh file - aSolFileName = aGenericName + "_required.sol"; // GMF solution file + aRequiredVerticesFileName = aGenericNameRequired + ".mesh"; // GMF required vertices mesh file + aSolFileName = aGenericNameRequired + ".sol"; // GMF solution file #else aGMFFileName = aGenericName + ".meshb"; // GMF mesh file aResultFileName = aGenericName + "Vol.meshb"; // GMF mesh file - aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file - aSolFileName = aGenericName + ".solb"; // GMF solution file + aRequiredVerticesFileName = aGenericNameRequired + ".meshb"; // GMF required vertices mesh file + aSolFileName = aGenericNameRequired + ".solb"; // GMF solution file #endif std::map nodeID2nodeIndexMap; - GHS3DPlugin_Hypothesis::TEnforcedVertexValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp); + 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); @@ -2944,7 +3367,8 @@ 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; -// cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName; + if ( nbEnforcedVertices + nbEnforcedVertices) + cmd += TCollection_AsciiString(" --required_vertices ") + aGenericNameRequired; cmd += TCollection_AsciiString(" --out ") + aResultFileName; cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx index cee9677..fd27aa2 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.cxx @@ -92,13 +92,13 @@ GHS3DPlugin_GHS3D_i::~GHS3DPlugin_GHS3D_i() */ //============================================================================= -bool GHS3DPlugin_GHS3D_i::importGMFMesh(const char* theGMFFileName) +SMESH::SMESH_Mesh_ptr GHS3DPlugin_GHS3D_i::importGMFMesh(const char* theGMFFileName) { MESSAGE( "GHS3DPlugin_GHS3D_i::importGMFMesh" ); - - SMESH::SMESH_Mesh_ptr theMesh = SMESH_Gen_i::GetSMESHGen()->CreateEmptyMesh(); - SMESH_Gen_i::GetSMESHGen()->RemoveLastFromPythonScript(SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy()->StudyId()); - SALOMEDS::SObject_ptr theSMesh = SMESH_Gen_i::GetSMESHGen()->ObjectToSObject(SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy(), theMesh); + SMESH_Gen_i* smeshGen = SMESH_Gen_i::GetSMESHGen(); + SMESH::SMESH_Mesh_ptr theMesh = smeshGen->CreateEmptyMesh(); + smeshGen->RemoveLastFromPythonScript(smeshGen->GetCurrentStudy()->StudyId()); + SALOMEDS::SObject_ptr theSMesh = smeshGen->ObjectToSObject(smeshGen->GetCurrentStudy(), theMesh); #ifdef WINNT #define SEP '\\' #else @@ -107,13 +107,12 @@ bool GHS3DPlugin_GHS3D_i::importGMFMesh(const char* theGMFFileName) string strFileName (theGMFFileName); strFileName = strFileName.substr(strFileName.rfind(SEP)+1); strFileName.erase(strFileName.rfind('.')); - SMESH_Gen_i::GetSMESHGen()->SetName(theSMesh, strFileName.c_str()); - SMESH_Mesh_i* meshServant = dynamic_cast( SMESH_Gen_i::GetSMESHGen()->GetServant( theMesh ).in() ); + smeshGen->SetName(theSMesh, strFileName.c_str()); + SMESH_Mesh_i* meshServant = dynamic_cast( smeshGen->GetServant( theMesh ).in() ); ASSERT( meshServant ); if ( meshServant ) { - bool res = GetImpl()->importGMFMesh(theGMFFileName, meshServant->GetImpl()); - SMESH::TPythonDump() << "isDone = " << _this() << ".importGMFMesh( \"" << theGMFFileName << "\")"; - return res; + if (GetImpl()->importGMFMesh(theGMFFileName, meshServant->GetImpl())) + SMESH::TPythonDump() << theSMesh << " = " << _this() << ".importGMFMesh( \"" << theGMFFileName << "\")"; } - return false; + return theMesh; } diff --git a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx index 9de897f..8c0987f 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_GHS3D_i.hxx @@ -50,7 +50,7 @@ public: // Get implementation ::GHS3DPlugin_GHS3D* GetImpl(); - virtual bool importGMFMesh(const char* theGMFFileName); + virtual SMESH::SMESH_Mesh_ptr importGMFMesh(const char* theGMFFileName); }; #endif diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx index c42eeb2..9793dfe 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.cxx @@ -51,19 +51,19 @@ GHS3DPlugin_Hypothesis::GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen myToUseBoundaryRecoveryVersion(DefaultToUseBoundaryRecoveryVersion()), myToUseFemCorrection(DefaultToUseFEMCorrection()), myToRemoveCentralPoint(DefaultToRemoveCentralPoint()), - myEnforcedVertices(DefaultEnforcedVertices()), + _enfVertexList(DefaultGHS3DEnforcedVertexList()), + _enfVertexCoordsSizeList(DefaultGHS3DEnforcedVertexCoordsValues()), + _enfVertexEntrySizeList(DefaultGHS3DEnforcedVertexEntryValues()), + _coordsEnfVertexMap(DefaultCoordsGHS3DEnforcedVertexMap()), + _geomEntryEnfVertexMap(DefaultGeomEntryGHS3DEnforcedVertexMap()), _enfNodes(DefaultIDSortedNodeSet()), _enfEdges(DefaultIDSortedElemSet()), _enfTriangles(DefaultIDSortedElemSet()), _nodeIDToSizeMap(DefaultID2SizeMap()), _elementIDToSizeMap(DefaultID2SizeMap()) -// _enfQuadrangles(DefaultIDSortedElemSet()) { _name = "GHS3D_Parameters"; _param_algo_dim = 3; -// _edgeID2nodeIDMap.clear(); -// _triID2nodeIDMap.clear(); -// _quadID2nodeIDMap.clear(); } //======================================================================= @@ -329,77 +329,118 @@ std::string GHS3DPlugin_Hypothesis::GetTextOption() const //function : SetEnforcedVertex //======================================================================= -void GHS3DPlugin_Hypothesis::SetEnforcedVertex(double x, double y, double z, double size) +bool GHS3DPlugin_Hypothesis::SetEnforcedVertex(std::string theName, std::string theEntry, std::string theGroupName, + double size, double x, double y, double z) { - std::vector coord(3); - coord[0] = x; - coord[1] = y; - coord[2] = z; - myEnforcedVertices[coord] = size; - NotifySubMeshesHypothesisModification(); + MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex("<< theName << ", "<< theEntry << ", " << theGroupName << ", " + << size << ", " << x << ", " << y << ", " << z << ")"); + + bool toNotify = false; + bool toCreate = true; + + TGHS3DEnforcedVertex *oldEnVertex; + TGHS3DEnforcedVertex *newEnfVertex = new TGHS3DEnforcedVertex(); + newEnfVertex->name = theName; + newEnfVertex->geomEntry = theEntry; + newEnfVertex->coords.clear(); + if (theEntry == "") { + newEnfVertex->coords.push_back(x); + newEnfVertex->coords.push_back(y); + newEnfVertex->coords.push_back(z); + } + newEnfVertex->groupName = theGroupName; + newEnfVertex->size = size; + + + // update _enfVertexList + TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(newEnfVertex); + if (it != _enfVertexList.end()) { + toCreate = false; + oldEnVertex = (*it); + MESSAGE("Enforced Vertex was found => Update"); + if (oldEnVertex->name != theName) { + MESSAGE("Update name from \"" << oldEnVertex->name << "\" to \"" << theName << "\""); + oldEnVertex->name = theName; + toNotify = true; + } + if (oldEnVertex->groupName != theGroupName) { + MESSAGE("Update group name from \"" << oldEnVertex->groupName << "\" to \"" << theGroupName << "\""); + oldEnVertex->groupName = theGroupName; + toNotify = true; + } + if (oldEnVertex->size != size) { + MESSAGE("Update size from \"" << oldEnVertex->size << "\" to \"" << size << "\""); + oldEnVertex->size = size; + toNotify = true; + } + if (toNotify) { + // update map coords / enf vertex if needed + if (oldEnVertex->coords.size()) { + _coordsEnfVertexMap[oldEnVertex->coords] = oldEnVertex; + _enfVertexCoordsSizeList[oldEnVertex->coords] = size; + } + + // update map geom entry / enf vertex if needed + if (oldEnVertex->geomEntry != "") { + _geomEntryEnfVertexMap[oldEnVertex->geomEntry] = oldEnVertex; + _enfVertexEntrySizeList[oldEnVertex->geomEntry] = size; + } + } + } + +// //////// CREATE //////////// + if (toCreate) { + toNotify = true; + MESSAGE("Creating new enforced vertex"); + _enfVertexList.insert(newEnfVertex); + if (theEntry == "") { + _coordsEnfVertexMap[newEnfVertex->coords] = newEnfVertex; + _enfVertexCoordsSizeList[newEnfVertex->coords] = size; + } + else { + _geomEntryEnfVertexMap[newEnfVertex->geomEntry] = newEnfVertex; + _enfVertexEntrySizeList[newEnfVertex->geomEntry] = size; + } + } + + if (toNotify) + NotifySubMeshesHypothesisModification(); + + MESSAGE("GHS3DPlugin_Hypothesis::SetEnforcedVertex END"); + return toNotify; } //======================================================================= //function : SetEnforcedMesh //======================================================================= -void GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size) +bool GHS3DPlugin_Hypothesis::SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size) { TIDSortedElemSet theElemSet; SMDS_ElemIteratorPtr eIt; -/* - if ((elementType == SMESH::FACE) && (theMesh.NbQuadrangles() > 0)) { - SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( theMesh )); - - StdMeshers_QuadToTriaAdaptor* aQuad2Trias = new StdMeshers_QuadToTriaAdaptor; - aQuad2Trias->Compute( theMesh ); - proxyMesh.reset(aQuad2Trias ); - -// std::cout << "proxyMesh->NbFaces(): " << proxyMesh->NbFaces() << std::endl; -// eIt = proxyMesh->GetFaces(); -// if (eIt) -// while ( eIt->more() ) -// theElemSet.insert( eIt->next() ); -// else { -// std::cout << "********************** eIt == 0 *****************" << std::endl; - eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType)); - while ( eIt->more() ) { - const SMDS_MeshElement* elem = eIt->next(); - theElemSet.insert( elem ); - } - } - - else - { - */ - eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType)); - while ( eIt->more() ) - theElemSet.insert( eIt->next() ); -/* - } -*/ + eIt = theMesh.GetMeshDS()->elementsIterator(SMDSAbs_ElementType(elementType)); + while ( eIt->more() ) + theElemSet.insert( eIt->next() ); MESSAGE("Add "<GetID()); - const SMDS_MeshNode* node = dynamic_cast(elem); switch (elementType) { case SMESH::NODE: + node = dynamic_cast(elem); if (node) { _enfNodes.insert(node); _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); @@ -417,12 +458,6 @@ void GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM if (elem->GetType() == SMDSAbs_Edge) { _enfEdges.insert(elem); _elementIDToSizeMap.insert(make_pair(elem->GetID(), size)); -// SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator(); -// for (int j = 0; j < 2; ++j) { -// node = dynamic_cast(nodeIt->next()); -// _edgeID2nodeIDMap[elem->GetID()].push_back(node->GetID()); -// _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); -// } added = true; } else if (elem->GetType() > SMDSAbs_Edge) { @@ -431,12 +466,6 @@ void GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM const SMDS_MeshElement* anEdge = it->next(); _enfEdges.insert(anEdge); _elementIDToSizeMap.insert(make_pair(anEdge->GetID(), size)); -// SMDS_ElemIteratorPtr nodeIt = anEdge->nodesIterator(); -// for (int j = 0; j < 2; ++j) { -// node = dynamic_cast(nodeIt->next()); -// _edgeID2nodeIDMap[anEdge->GetID()].push_back(node->GetID()); -// _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); -// } } added = true; } @@ -447,12 +476,6 @@ void GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM if (elem->NbCornerNodes() == 3) { _enfTriangles.insert(elem); _elementIDToSizeMap.insert(make_pair(elem->GetID(), size)); -// SMDS_ElemIteratorPtr nodeIt = elem->nodesIterator(); -// for ( int j = 0; j < 3; ++j ) { -// node = dynamic_cast(nodeIt->next()); -// _triID2nodeIDMap[elem->GetID()].push_back(node->GetID()); -// _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); -// } added = true; } } @@ -463,61 +486,104 @@ void GHS3DPlugin_Hypothesis::SetEnforcedElements(TIDSortedElemSet theElemSet, SM if (aFace->NbCornerNodes() == 3) { _enfTriangles.insert(aFace); _elementIDToSizeMap.insert(make_pair(aFace->GetID(), size)); -// SMDS_ElemIteratorPtr nodeIt = aFace->nodesIterator(); -// for (int j = 0; j < 3; ++j) { -// node = dynamic_cast(nodeIt->next()); -// _triID2nodeIDMap[aFace->GetID()].push_back(node->GetID()); -// _nodeIDToSizeMap.insert(make_pair(node->GetID(), size)); -// } added = true; } } } break; + default: + break; }; } if (added) NotifySubMeshesHypothesisModification(); + return added; } + //======================================================================= //function : GetEnforcedVertex //======================================================================= -double GHS3DPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z) +GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument) { std::vector coord(3); coord[0] = x; coord[1] = y; coord[2] = z; - if (myEnforcedVertices.count(coord)>0) - return myEnforcedVertices[coord]; + if (_coordsEnfVertexMap.count(coord)>0) + return _coordsEnfVertexMap[coord]; std::ostringstream msg ; msg << "No enforced vertex at " << x << ", " << y << ", " << z; throw std::invalid_argument(msg.str()); } +GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* GHS3DPlugin_Hypothesis::GetEnforcedVertex(const std::string theEntry) + throw (std::invalid_argument) +{ + if (_geomEntryEnfVertexMap.count(theEntry)>0) + return _geomEntryEnfVertexMap[theEntry]; + + std::ostringstream msg ; + msg << "No enforced vertex with entry " << theEntry; + throw std::invalid_argument(msg.str()); +} + //======================================================================= //function : RemoveEnforcedVertex //======================================================================= -void GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z) +bool GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z, const std::string theEntry) throw (std::invalid_argument) { - std::vector coord(3); - coord[0] = x; - coord[1] = y; - coord[2] = z; - TEnforcedVertexValues::iterator it = myEnforcedVertices.find(coord); - if (it != myEnforcedVertices.end()) { - myEnforcedVertices.erase(it); - NotifySubMeshesHypothesisModification(); - return; + bool toNotify = false; + std::ostringstream msg; + TGHS3DEnforcedVertex *oldEnfVertex; + std::vector coords(3); + coords[0] = x; + coords[1] = y; + coords[2] = z; + + // check that enf vertex with given enf vertex entry exists + TGeomEntryGHS3DEnforcedVertexMap::iterator it_enfVertexEntry = _geomEntryEnfVertexMap.find(theEntry); + if (it_enfVertexEntry != _geomEntryEnfVertexMap.end()) { + // Success + MESSAGE("Found enforced vertex with geom entry " << theEntry); + oldEnfVertex = it_enfVertexEntry->second; + _geomEntryEnfVertexMap.erase(it_enfVertexEntry); + } else { + // Fail + MESSAGE("Enforced vertex with geom entry " << theEntry << " not found"); + // check that enf vertex with given coords exists + TCoordsGHS3DEnforcedVertexMap::iterator it_coords_enf = _coordsEnfVertexMap.find(coords); + if (it_coords_enf != _coordsEnfVertexMap.end()) { + // Success + MESSAGE("Found enforced vertex with coords " << x << ", " << y << ", " << z); + oldEnfVertex = it_coords_enf->second; + _coordsEnfVertexMap.erase(it_coords_enf); + _enfVertexCoordsSizeList.erase(_enfVertexCoordsSizeList.find(coords)); + } else { + // Fail + MESSAGE("Enforced vertex with coords " << x << ", " << y << ", " << z << " not found"); + throw std::invalid_argument(msg.str()); } - std::ostringstream msg ; - msg << "No enforced vertex at " << x << ", " << y << ", " << z; - throw std::invalid_argument(msg.str()); + } + + MESSAGE("Remove enf vertex from _enfVertexList"); + + // update _enfVertexList + TGHS3DEnforcedVertexList::iterator it = _enfVertexList.find(oldEnfVertex); + if (it != _enfVertexList.end()) { + _enfVertexList.erase(it); + toNotify = true; + MESSAGE("Done"); + } + + if (toNotify) + NotifySubMeshesHypothesisModification(); + + return toNotify; } //======================================================================= @@ -525,7 +591,11 @@ void GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(double x, double y, double z) //======================================================================= void GHS3DPlugin_Hypothesis::ClearEnforcedVertices() { - myEnforcedVertices.clear(); + _enfVertexList.clear(); + _coordsEnfVertexMap.clear(); + _geomEntryEnfVertexMap.clear(); + _enfVertexCoordsSizeList.clear(); + _enfVertexEntrySizeList.clear(); NotifySubMeshesHypothesisModification(); } @@ -537,10 +607,6 @@ void GHS3DPlugin_Hypothesis::ClearEnforcedMeshes() _enfNodes.clear(); _enfEdges.clear(); _enfTriangles.clear(); -// _enfQuadrangles.clear(); -// _edgeID2nodeIDMap.clear(); -// _triID2nodeIDMap.clear(); -// _quadID2nodeIDMap.clear(); _nodeIDToSizeMap.clear(); _elementIDToSizeMap.clear(); NotifySubMeshesHypothesisModification(); @@ -686,29 +752,33 @@ bool GHS3DPlugin_Hypothesis::DefaultToRemoveCentralPoint() } //======================================================================= -//function : DefaultEnforcedVertices +//function : DefaultIDSortedNodeSet //======================================================================= -GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::DefaultEnforcedVertices() -{ - return GHS3DPlugin_Hypothesis::TEnforcedVertexValues(); -} - TIDSortedNodeSet GHS3DPlugin_Hypothesis::DefaultIDSortedNodeSet() { return TIDSortedNodeSet(); } +//======================================================================= +//function : DefaultIDSortedElemSet +//======================================================================= + TIDSortedElemSet GHS3DPlugin_Hypothesis::DefaultIDSortedElemSet() { return TIDSortedElemSet(); } +//======================================================================= +//function : DefaultID2SizeMap +//======================================================================= + GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::DefaultID2SizeMap() { return GHS3DPlugin_Hypothesis::TID2SizeMap(); } + //======================================================================= //function : SaveTo //======================================================================= @@ -733,14 +803,37 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save) } - TEnforcedVertexValues::iterator it = myEnforcedVertices.begin(); - if (it != myEnforcedVertices.end()) { + TGHS3DEnforcedVertexList::iterator it = _enfVertexList.begin(); + if (it != _enfVertexList.end()) { save << "__ENFORCED_VERTICES_BEGIN__ "; - for ( ; it != myEnforcedVertices.end(); ++it ) { - save << it->first[0] << " " - << it->first[1] << " " - << it->first[2] << " " - << it->second << " "; + for ( ; it != _enfVertexList.end(); ++it ) { + TGHS3DEnforcedVertex *enfVertex = (*it); + save << " " << "__BEGIN_VERTEX__"; + if (!enfVertex->name.empty()) { + save << " " << "__BEGIN_NAME__"; + save << " " << enfVertex->name; + save << " " << "__END_NAME__"; + } + if (!enfVertex->geomEntry.empty()) { + save << " " << "__BEGIN_ENTRY__"; + save << " " << enfVertex->geomEntry; + save << " " << "__END_ENTRY__"; + } + if (!enfVertex->groupName.empty()) { + save << " " << "__BEGIN_GROUP__"; + save << " " << enfVertex->groupName; + save << " " << "__END_GROUP__"; + } + if (enfVertex->coords.size()) { + save << " " << "__BEGIN_COORDS__"; + for (int i=0;icoords.size();i++) + save << " " << enfVertex->coords[i]; + save << " " << "__END_COORDS__"; + } + save << " " << "__BEGIN_SIZE__"; + save << " " << enfVertex->size; + save << " " << "__BEGIN_SIZE__"; + save << " " << "__END_VERTEX__"; } save << "__ENFORCED_VERTICES_END__ "; } @@ -754,145 +847,209 @@ std::ostream & GHS3DPlugin_Hypothesis::SaveTo(std::ostream & save) std::istream & GHS3DPlugin_Hypothesis::LoadFrom(std::istream & load) { - bool isOK = true; - int i; - - isOK = (load >> i); - if (isOK) - myToMeshHoles = i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> i); - if (isOK) - myMaximumMemory = i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> i); - if (isOK) - myInitialMemory = i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> i); - if (isOK) - myOptimizationLevel = i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> myWorkingDirectory); - if (isOK) { - if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty - myKeepFiles = false; - myWorkingDirectory.clear(); - } - else if ( myWorkingDirectory == "1" ) { - myKeepFiles = true; - myWorkingDirectory.clear(); - } + bool isOK = true; + int i; + + isOK = (load >> i); + if (isOK) + myToMeshHoles = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myMaximumMemory = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myInitialMemory = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myOptimizationLevel = i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> myWorkingDirectory); + if (isOK) { + if ( myWorkingDirectory == "0") { // myWorkingDirectory was empty + myKeepFiles = false; + myWorkingDirectory.clear(); } - else - load.clear(ios::badbit | load.rdstate()); - - if ( !myWorkingDirectory.empty() ) { - isOK = (load >> i); - if (isOK) - myKeepFiles = i; - else - load.clear(ios::badbit | load.rdstate()); + else if ( myWorkingDirectory == "1" ) { + myKeepFiles = true; + myWorkingDirectory.clear(); } - - isOK = (load >> i); - if (isOK) - myVerboseLevel = (short) i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> i); - if (isOK) - myToCreateNewNodes = (bool) i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> i); - if (isOK) - myToUseBoundaryRecoveryVersion = (bool) i; - else - load.clear(ios::badbit | load.rdstate()); - - isOK = (load >> i); - if (isOK) - myToUseFemCorrection = (bool) i; - else - load.clear(ios::badbit | load.rdstate()); - + } + else + load.clear(ios::badbit | load.rdstate()); + + if ( !myWorkingDirectory.empty() ) { isOK = (load >> i); if (isOK) - myToRemoveCentralPoint = (bool) i; + myKeepFiles = i; else - load.clear(ios::badbit | load.rdstate()); - - std::string separator; - bool hasOptions = false; - bool hasEnforcedVertices = false; - isOK = (load >> separator); - - if (isOK) { - if (separator == "__OPTIONS_BEGIN__") - hasOptions = true; - else if (separator == "__ENFORCED_VERTICES_BEGIN__") - hasEnforcedVertices = true; - } + load.clear(ios::badbit | load.rdstate()); + } + + isOK = (load >> i); + if (isOK) + myVerboseLevel = (short) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myToCreateNewNodes = (bool) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myToUseBoundaryRecoveryVersion = (bool) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myToUseFemCorrection = (bool) i; + else + load.clear(ios::badbit | load.rdstate()); + + isOK = (load >> i); + if (isOK) + myToRemoveCentralPoint = (bool) i; + else + load.clear(ios::badbit | load.rdstate()); + + std::string separator; + bool hasOptions = false; + bool hasEnforcedVertices = false; + isOK = (load >> separator); + + if (isOK) { + if (separator == "__OPTIONS_BEGIN__") + hasOptions = true; + else if (separator == "__ENFORCED_VERTICES_BEGIN__") + hasEnforcedVertices = true; + } - if (hasOptions) { - std::string txt; - while (isOK) { - isOK = (load >> txt); - if (isOK) { - if (txt == "__OPTIONS_END__") { - if (!myTextOption.empty()) { - // Remove last space - myTextOption.erase(myTextOption.end()-1); - } - isOK = false; - break; - } - myTextOption += txt; - myTextOption += " "; - } + if (hasOptions) { + std::string txt; + while (isOK) { + isOK = (load >> txt); + if (isOK) { + if (txt == "__OPTIONS_END__") { + if (!myTextOption.empty()) { + // Remove last space + myTextOption.erase(myTextOption.end()-1); + } + isOK = false; + break; } + myTextOption += txt; + myTextOption += " "; + } } + } - if (hasOptions) { - isOK = (load >> separator); - if (isOK) - if (separator == "__ENFORCED_VERTICES_BEGIN__") - hasEnforcedVertices = true; - } + if (hasOptions) { + isOK = (load >> separator); + if (isOK && separator == "__ENFORCED_VERTICES_BEGIN__") + hasEnforcedVertices = true; + } - if (hasEnforcedVertices) { - std::string txt; - double x,y,z,size; + if (hasEnforcedVertices) { + std::string txt, name, entry, groupName; + double size, coords[3]; + bool hasCoords = false; + while (isOK) { + isOK = (load >> txt); // __BEGIN_VERTEX__ + if (isOK) { + if (txt == "__ENFORCED_VERTICES_END__") + isOK = false; + + TGHS3DEnforcedVertex *enfVertex = new TGHS3DEnforcedVertex(); while (isOK) { - isOK = (load >> txt); - if (isOK) { - if (txt == "__ENFORCED_VERTICES_END__") { - isOK = false; - break; - } - x = atof(txt.c_str()); - isOK = (load >> y >> z >> size); + isOK = (load >> txt); + if (txt == "__END_VERTEX__") { + enfVertex->name = name; + enfVertex->geomEntry = entry; + enfVertex->groupName = groupName; + enfVertex->coords.clear(); + if (hasCoords) + enfVertex->coords.assign(coords,coords+3); + + _enfVertexList.insert(enfVertex); + + if (enfVertex->coords.size()) + _coordsEnfVertexMap[enfVertex->coords] = enfVertex; + if (!enfVertex->geomEntry.empty()) + _geomEntryEnfVertexMap[enfVertex->geomEntry] = enfVertex; + + name.clear(); + entry.clear(); + groupName.clear(); + hasCoords = false; + isOK = false; + } + + if (txt == "__BEGIN_NAME__") { // __BEGIN_NAME__ + while (isOK && (txt != "__END_NAME__")) { + isOK = (load >> txt); + if (txt != "__END_NAME__") { + if (!name.empty()) + name += " "; + name += txt; + } } - if (isOK) { - std::vector coord; - coord.push_back(x); - coord.push_back(y); - coord.push_back(z); - myEnforcedVertices[ coord ] = size; + MESSAGE("name: " <> entry); + isOK = (load >> txt); // __END_ENTRY__ + if (txt != "__END_ENTRY__") + throw std::exception(); + MESSAGE("entry: " << entry); + } + + if (txt == "__BEGIN_GROUP__") { // __BEGIN_GROUP__ + while (isOK && (txt != "__END_GROUP__")) { + isOK = (load >> txt); + if (txt != "__END_GROUP__") { + if (!groupName.empty()) + groupName += " "; + groupName += txt; + } } + MESSAGE("groupName: " << groupName); + } + + if (txt == "__BEGIN_COORDS__") { // __BEGIN_COORDS__ + hasCoords = true; + isOK = (load >> coords[0] >> coords[1] >> coords[2]); + isOK = (load >> txt); // __END_COORDS__ + if (txt != "__END_COORDS__") + throw std::exception(); + MESSAGE("coords: " << coords[0] <<","<< coords[1] <<","<< coords[2]); + } + + if (txt == "__BEGIN_SIZE__") { // __BEGIN_ENTRY__ + isOK = (load >> size); + isOK = (load >> txt); // __END_ENTRY__ + if (txt != "__END_SIZE__") + throw std::exception(); + MESSAGE("size: " << size); + } } + } } + } return load; } @@ -1060,52 +1217,52 @@ std::string GHS3DPlugin_Hypothesis::GetFileName(const GHS3DPlugin_Hypothesis* hy */ //================================================================================ -GHS3DPlugin_Hypothesis::TEnforcedVertexValues GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp) +GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList GHS3DPlugin_Hypothesis::GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedVertices():DefaultEnforcedVertices(); + return hyp ? hyp->_GetEnforcedVertices():DefaultGHS3DEnforcedVertexList(); +} + +GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexCoordsValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesCoordsSize (const GHS3DPlugin_Hypothesis* hyp) +{ + return hyp ? hyp->_GetEnforcedVerticesCoordsSize(): DefaultGHS3DEnforcedVertexCoordsValues(); +} + +GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexEntryValues GHS3DPlugin_Hypothesis::GetEnforcedVerticesEntrySize (const GHS3DPlugin_Hypothesis* hyp) +{ + return hyp ? hyp->_GetEnforcedVerticesEntrySize(): DefaultGHS3DEnforcedVertexEntryValues(); +} + +GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByCoords (const GHS3DPlugin_Hypothesis* hyp) +{ + return hyp ? hyp->_GetEnforcedVerticesByCoords(): DefaultCoordsGHS3DEnforcedVertexMap(); +} + +GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap GHS3DPlugin_Hypothesis::GetEnforcedVerticesByEntry (const GHS3DPlugin_Hypothesis* hyp) +{ + return hyp ? hyp->_GetEnforcedVerticesByEntry(): DefaultGeomEntryGHS3DEnforcedVertexMap(); } TIDSortedNodeSet GHS3DPlugin_Hypothesis::GetEnforcedNodes(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeSet(); + return hyp ? hyp->_GetEnforcedNodes():DefaultIDSortedNodeSet(); } TIDSortedElemSet GHS3DPlugin_Hypothesis::GetEnforcedEdges(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemSet(); + return hyp ? hyp->_GetEnforcedEdges():DefaultIDSortedElemSet(); } TIDSortedElemSet GHS3DPlugin_Hypothesis::GetEnforcedTriangles(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemSet(); + return hyp ? hyp->_GetEnforcedTriangles():DefaultIDSortedElemSet(); } -// TIDSortedElemSet GHS3DPlugin_Hypothesis::GetEnforcedQuadrangles(const GHS3DPlugin_Hypothesis* hyp) -// { -// return hyp ? hyp->_GetEnforcedQuadrangles():DefaultIDSortedElemSet(); -// } - -// GHS3DPlugin_Hypothesis::TElemID2NodeIDMap GHS3DPlugin_Hypothesis::GetEdgeID2NodeIDMap(const GHS3DPlugin_Hypothesis* hyp) -// { -// return hyp ? hyp->_GetEdgeID2NodeIDMap(): GHS3DPlugin_Hypothesis::TElemID2NodeIDMap(); -// } -// -// GHS3DPlugin_Hypothesis::TElemID2NodeIDMap GHS3DPlugin_Hypothesis::GetTri2NodeMap(const GHS3DPlugin_Hypothesis* hyp) -// { -// return hyp ? hyp->_GetTri2NodeMap(): GHS3DPlugin_Hypothesis::TElemID2NodeIDMap(); -// } - -// GHS3DPlugin_Hypothesis::TElemID2NodeIDMap GHS3DPlugin_Hypothesis::GetQuad2NodeMap(const GHS3DPlugin_Hypothesis* hyp) -// { -// return hyp ? hyp->_GetQuad2NodeMap(): GHS3DPlugin_Hypothesis::TElemID2NodeIDMap(); -// } - GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap(); + return hyp ? hyp->_GetNodeIDToSizeMap(): DefaultID2SizeMap(); } GHS3DPlugin_Hypothesis::TID2SizeMap GHS3DPlugin_Hypothesis::GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp) { - return hyp ? hyp->_GetElementIDToSizeMap(): DefaultID2SizeMap(); + return hyp ? hyp->_GetElementIDToSizeMap(): DefaultID2SizeMap(); } diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx index b978c6e..68f77eb 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis.hxx @@ -44,6 +44,38 @@ public: GHS3DPlugin_Hypothesis(int hypId, int studyId, SMESH_Gen * gen); + typedef std::map,double> TGHS3DEnforcedVertexCoordsValues; + typedef std::map TGHS3DEnforcedVertexEntryValues; + + struct TGHS3DEnforcedVertex { + std::string name; + std::string geomEntry; + std::vector coords; + std::string groupName; + double size; + }; + + struct CompareGHS3DEnforcedVertex { + bool operator () (const TGHS3DEnforcedVertex* e1, const TGHS3DEnforcedVertex* e2) const { + if (e1 && e2) { + if (e1->coords.size() && e2->coords.size()) + return (e1->coords < e2->coords); + else + return (e1->geomEntry < e2->geomEntry); + } + return false; + } + }; + typedef std::set< TGHS3DEnforcedVertex*, CompareGHS3DEnforcedVertex > TGHS3DEnforcedVertexList; + // Map Coords / Enforced node + typedef std::map< std::vector, TGHS3DEnforcedVertex* > TCoordsGHS3DEnforcedVertexMap; + // Map geom entry / Enforced ndoe + typedef std::map< std::string, TGHS3DEnforcedVertex* > TGeomEntryGHS3DEnforcedVertexMap; + // Map groupName / Enforced ndoe + typedef std::map< std::string, TGHS3DEnforcedVertex* > TGroupNameGHS3DEnforcedVertexMap; + + typedef std::map TID2SizeMap; + /*! * To mesh "holes" in a solid or not. Default is to mesh. */ @@ -117,34 +149,8 @@ public: */ void SetTextOption(const std::string& option); std::string GetTextOption() const; - /*! - * To set an enforced vertex - */ -// struct TEnforcedNode { -// std::vector coords; -// double size; -// std::string geomEntry; -// std::string groupName; -// }; -// -// struct CompareEnfNodes { -// bool operator () (const TEnforcedNode* e1, const TEnforcedNode* e2) const { -// if (e1 && e2) { -// if (e1->coords.size() && e2->coords.size()) -// return (e1->coords < e2->coords); -// else -// return (e1->geomEntry < e2->geomEntry); -// } -// return false; -// } -// }; -// typedef std::set< TEnforcedNode*, CompareEnfNodes > TEnforcedNodeList; -// // Map Coords / Enforced node -// typedef std::map< std::vector, TEnforcedNode* > TCoordsEnfNodeMap; -// // Map geom entry / Enforced ndoe -// typedef std::map< std::string, TEnforcedNode* > TGeomEntryEnfNodeMap; -// -// + + // struct TEnforcedEdge { // long ID; // long node1; @@ -152,32 +158,57 @@ public: // std::string groupName; // }; - - typedef std::map,double> TEnforcedVertexValues; - void SetEnforcedVertex(double x, double y, double z, double size); - double GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument); - void RemoveEnforcedVertex(double x, double y, double z) throw (std::invalid_argument); - const TEnforcedVertexValues _GetEnforcedVertices() const { return myEnforcedVertices; } + + /*! + * \brief Return command to run ghs3d mesher excluding file prefix (-f) + */ + static std::string CommandToRun(const GHS3DPlugin_Hypothesis* hyp, + const bool hasShapeToMesh=true); + /*! + * \brief Return a unique file name + */ + static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp); + + /*! + * To set an enforced vertex + */ + bool SetEnforcedVertex(std::string aName, std::string anEntry, std::string aGroupName, + double size, double x=0.0, double y=0.0, double z=0.0); + TGHS3DEnforcedVertex* GetEnforcedVertex(double x, double y, double z) throw (std::invalid_argument); + TGHS3DEnforcedVertex* GetEnforcedVertex(const std::string anEntry) throw (std::invalid_argument); + bool RemoveEnforcedVertex(double x=0.0, double y=0.0, double z=0.0, const std::string anEntry="" ) throw (std::invalid_argument); + const TGHS3DEnforcedVertexCoordsValues _GetEnforcedVerticesCoordsSize() const {return _enfVertexCoordsSizeList; } + const TGHS3DEnforcedVertexEntryValues _GetEnforcedVerticesEntrySize() const {return _enfVertexEntrySizeList; } + const TGHS3DEnforcedVertexList _GetEnforcedVertices() const { return _enfVertexList; } + const TCoordsGHS3DEnforcedVertexMap _GetEnforcedVerticesByCoords() const { return _coordsEnfVertexMap; } + const TGeomEntryGHS3DEnforcedVertexMap _GetEnforcedVerticesByEntry() const { return _geomEntryEnfVertexMap; } void ClearEnforcedVertices(); /*! * To set enforced elements */ - void SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size); - void SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size); + bool SetEnforcedMesh(SMESH_Mesh& theMesh, SMESH::ElementType elementType, double size); + bool SetEnforcedElements(TIDSortedElemSet theElemSet, SMESH::ElementType elementType, double size); void ClearEnforcedMeshes(); const TIDSortedNodeSet _GetEnforcedNodes() const { return _enfNodes; } const TIDSortedElemSet _GetEnforcedEdges() const { return _enfEdges; } const TIDSortedElemSet _GetEnforcedTriangles() const { return _enfTriangles; } -// const TIDSortedElemSet _GetEnforcedQuadrangles() const { return _enfQuadrangles; } -// typedef std::map > TElemID2NodeIDMap; -// const TElemID2NodeIDMap _GetEdgeID2NodeIDMap() const {return _edgeID2nodeIDMap; } -// const TElemID2NodeIDMap _GetTri2NodeMap() const {return _triID2nodeIDMap; } -// const TElemID2NodeIDMap _GetQuad2NodeMap() const {return _quadID2nodeIDMap; } - typedef std::map TID2SizeMap; const TID2SizeMap _GetNodeIDToSizeMap() const {return _nodeIDToSizeMap; } const TID2SizeMap _GetElementIDToSizeMap() const {return _elementIDToSizeMap; } - + /*! + * \brief Return the enforced vertices + */ + static TGHS3DEnforcedVertexList GetEnforcedVertices(const GHS3DPlugin_Hypothesis* hyp); + static TGHS3DEnforcedVertexCoordsValues GetEnforcedVerticesCoordsSize(const GHS3DPlugin_Hypothesis* hyp); + 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 TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); + static TID2SizeMap GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); + static bool DefaultMeshHoles(); static short DefaultMaximumMemory(); static short DefaultInitialMemory(); @@ -189,33 +220,16 @@ public: static bool DefaultToUseBoundaryRecoveryVersion(); static bool DefaultToUseFEMCorrection(); static bool DefaultToRemoveCentralPoint(); - static TEnforcedVertexValues DefaultEnforcedVertices(); + static TGHS3DEnforcedVertex DefaultGHS3DEnforcedVertex() {return TGHS3DEnforcedVertex();} + static TGHS3DEnforcedVertexList DefaultGHS3DEnforcedVertexList() {return TGHS3DEnforcedVertexList();} + static TGHS3DEnforcedVertexCoordsValues DefaultGHS3DEnforcedVertexCoordsValues() {return TGHS3DEnforcedVertexCoordsValues();} + static TGHS3DEnforcedVertexEntryValues DefaultGHS3DEnforcedVertexEntryValues() {return TGHS3DEnforcedVertexEntryValues();} + static TCoordsGHS3DEnforcedVertexMap DefaultCoordsGHS3DEnforcedVertexMap() {return TCoordsGHS3DEnforcedVertexMap();} + static TGeomEntryGHS3DEnforcedVertexMap DefaultGeomEntryGHS3DEnforcedVertexMap() {return TGeomEntryGHS3DEnforcedVertexMap();} + static TGroupNameGHS3DEnforcedVertexMap DefaultGroupNameGHS3DEnforcedVertexMap() {return TGroupNameGHS3DEnforcedVertexMap();} static TIDSortedNodeSet DefaultIDSortedNodeSet(); static TIDSortedElemSet DefaultIDSortedElemSet(); static TID2SizeMap DefaultID2SizeMap(); - - /*! - * \brief Return command to run ghs3d mesher excluding file prefix (-f) - */ - static std::string CommandToRun(const GHS3DPlugin_Hypothesis* hyp, - const bool hasShapeToMesh=true); - /*! - * \brief Return a unique file name - */ - static std::string GetFileName(const GHS3DPlugin_Hypothesis* hyp); - /*! - * \brief Return the enforced vertices - */ - static TEnforcedVertexValues GetEnforcedVertices(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 TIDSortedElemSet GetEnforcedQuadrangles(const GHS3DPlugin_Hypothesis* hyp); -// static TElemID2NodeIDMap GetEdgeID2NodeIDMap(const GHS3DPlugin_Hypothesis* hyp); -// static TElemID2NodeIDMap GetTri2NodeMap(const GHS3DPlugin_Hypothesis* hyp); -// static TElemID2NodeIDMap GetQuad2NodeMap(const GHS3DPlugin_Hypothesis* hyp); - static TID2SizeMap GetNodeIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); - static TID2SizeMap GetElementIDToSizeMap(const GHS3DPlugin_Hypothesis* hyp); // Persistence virtual std::ostream & SaveTo(std::ostream & save); @@ -247,14 +261,16 @@ private: bool myToUseFemCorrection; bool myToRemoveCentralPoint; std::string myTextOption; - TEnforcedVertexValues myEnforcedVertices; + TGHS3DEnforcedVertexList _enfVertexList; + TGHS3DEnforcedVertexCoordsValues _enfVertexCoordsSizeList; + TGHS3DEnforcedVertexEntryValues _enfVertexEntrySizeList; + // map to get "manual" enf vertex (through the coordinates) + TCoordsGHS3DEnforcedVertexMap _coordsEnfVertexMap; + // map to get "geom" enf vertex (through the geom entries) + TGeomEntryGHS3DEnforcedVertexMap _geomEntryEnfVertexMap; TIDSortedNodeSet _enfNodes; TIDSortedElemSet _enfEdges; TIDSortedElemSet _enfTriangles; -// TIDSortedElemSet _enfQuadrangles; -// TElemID2NodeIDMap _edgeID2nodeIDMap; -// TElemID2NodeIDMap _triID2nodeIDMap; -// TElemID2NodeIDMap _quadID2nodeIDMap; TID2SizeMap _nodeIDToSizeMap; TID2SizeMap _elementIDToSizeMap; }; diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx index 63952ba..102670a 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.cxx @@ -350,11 +350,160 @@ char* GHS3DPlugin_Hypothesis_i::GetTextOption() //function : SetEnforcedVertex //======================================================================= -void GHS3DPlugin_Hypothesis_i::SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size) -{ +bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size) + throw (SALOME::SALOME_Exception) { + ASSERT(myBaseImpl); + MESSAGE("IDL : SetEnforcedVertex( "<< x << ", " << y << ", " << z << ", " << size << ")"); + return _SetEnforcedVertex(size, x, y, z); +} + +bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theGroupName) + throw (SALOME::SALOME_Exception) { + ASSERT(myBaseImpl); + MESSAGE("IDL : SetEnforcedVertexWithGroup( "<< x << ", " << y << ", " << z << ", " << size << ", " << theGroupName << ")"); + return _SetEnforcedVertex(size, x, y, z, "", "", theGroupName); +} + +bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size) + throw (SALOME::SALOME_Exception) { + ASSERT(myBaseImpl); + + if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) { + MESSAGE("theVertex shape type is not VERTEX or COMPOUND"); + THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM); + } + + string theVertexEntry = theVertex->GetStudyEntry(); + if (theVertexEntry.empty()) { + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); + string aName; + if (theVertex->GetShapeType() == GEOM::VERTEX) + aName = "Vertex_"; + if (theVertex->GetShapeType() == GEOM::COMPOUND) + aName = "Compound_"; + aName += theVertex->GetEntry(); + SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + if (!theSVertex->_is_nil()) + theVertexEntry = theSVertex->GetID(); + } + if (theVertexEntry.empty()) + THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + + string theVertexName = theVertex->GetName(); + MESSAGE("IDL : SetEnforcedVertexGeom( "<< theVertexEntry << ", " << size<< ")"); + + return _SetEnforcedVertex(size, 0, 0, 0, theVertexName.c_str(), theVertexEntry.c_str()); +} + +bool GHS3DPlugin_Hypothesis_i::SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName) + throw (SALOME::SALOME_Exception) { + ASSERT(myBaseImpl); + + if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) { + MESSAGE("theVertex shape type is not VERTEX or COMPOUND"); + THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM); + } + + string theVertexEntry = theVertex->GetStudyEntry(); + if (theVertexEntry.empty()) { + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); + string aName; + if (theVertex->GetShapeType() == GEOM::VERTEX) + aName = "Vertex_"; + if (theVertex->GetShapeType() == GEOM::COMPOUND) + aName = "Compound_"; + aName += theVertex->GetEntry(); + SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + if (!theSVertex->_is_nil()) + theVertexEntry = theSVertex->GetID(); + } + if (theVertexEntry.empty()) + THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + + string theVertexName = theVertex->GetName(); + MESSAGE("IDL : SetEnforcedVertexGeomWithGroup( "<< theVertexEntry << ", " << size<< ", " << theGroupName << ")"); + + return _SetEnforcedVertex(size, 0, 0, 0, theVertexName.c_str(), theVertexEntry.c_str(), theGroupName); +} + +bool GHS3DPlugin_Hypothesis_i:: _SetEnforcedVertex(CORBA::Double size, CORBA::Double x, CORBA::Double y, CORBA::Double z, + const char* theVertexName, const char* theVertexEntry, const char* theGroupName) + throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); - this->GetImpl()->SetEnforcedVertex(x,y,z,size); - SMESH::TPythonDump() << _this() << ".SetEnforcedVertex( " << x << ", " << y << ", " << z << ", " << size << " )"; + MESSAGE("IDL : _SetEnforcedVertex(" << size << ", " << x << ", " << y << ", " << z << ", \"" << theVertexName << "\", \"" << theVertexEntry << "\", \"" << theGroupName << "\")"); + bool newValue = false; + + if (string(theVertexEntry).empty()) { + ::GHS3DPlugin_Hypothesis::TCoordsGHS3DEnforcedVertexMap coordsList = this->GetImpl()->_GetEnforcedVerticesByCoords(); + std::vector coords; + coords.push_back(x); + coords.push_back(y); + coords.push_back(z); + if (coordsList.find(coords) == coordsList.end()) { + MESSAGE("Coords not found: add it in coordsList"); + newValue = true; + } else { + MESSAGE("Coords already found, compare names"); + ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(x, y, z); + if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) { + MESSAGE("The names or size are different: update"); +// this->GetImpl()->ClearEnforcedVertex(theFaceEntry, x, y, z); + newValue = true; + } + else { + MESSAGE("The names and size are identical"); + } + } + + if (newValue) { + if (string(theVertexName).empty()) { + if (string(theGroupName).empty()) + SMESH::TPythonDump() << _this() << ".SetEnforcedVertex(" << x << ", " << y << ", " << z << ", " << size << ")"; + else + SMESH::TPythonDump() << _this() << ".SetEnforcedVertexWithGroup(" << x << ", " << y << ", " << z << ", " << size << ", \"" << theGroupName << "\")"; +// else +// if (string(theGroupName).empty()) +// SMESH::TPythonDump() << _this() << ".SetEnforcedVertexNamed(" << theFaceEntry << ", " << x << ", " << y << ", " << z << ", \"" << theVertexName << "\")"; +// else +// SMESH::TPythonDump() << _this() << ".SetEnforcedVertexNamedWithGroup(" << theFaceEntry << ", " << x << ", " << y << ", " << z << ", \"" +// << theVertexName << "\", \"" << theGroupName << "\")"; + } + } + } else { + ::GHS3DPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap enfVertexEntryList = this->GetImpl()->_GetEnforcedVerticesByEntry(); +// ::BLSURFPlugin_Hypothesis::TGeomEntryGHS3DEnforcedVertexMap::const_iterator it = enfVertexEntryList.find(theVertexEntry); + if ( enfVertexEntryList.find(theVertexEntry) == enfVertexEntryList.end()) { + MESSAGE("Geom entry not found: add it in enfVertexEntryList"); + newValue = true; + } + else { + MESSAGE("Geom entry already found, compare names"); + ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex *enfVertex = this->GetImpl()->GetEnforcedVertex(theVertexEntry); + if ((enfVertex->name != theVertexName) || (enfVertex->groupName != theGroupName) || (enfVertex->size != size)) { + MESSAGE("The names or size are different: update"); +// this->GetImpl()->ClearEnforcedVertex(theFaceEntry, x, y, z); + newValue = true; + } + else { + MESSAGE("The names and size are identical"); + } + } + + if (newValue) { + if (string(theGroupName).empty()) + SMESH::TPythonDump() << _this() << ".SetEnforcedVertexGeom(" << theVertexEntry << ", " << size << ")"; + else + SMESH::TPythonDump() << _this() << ".SetEnforcedVertexGeomWithGroup(" << theVertexEntry << ", " << size << ", \"" << theGroupName << "\")"; + } + } + + if (newValue) + this->GetImpl()->SetEnforcedVertex(theVertexName, theVertexEntry, theGroupName, size, x, y, z); + + MESSAGE("IDL : SetEnforcedVertexEntry END"); + return newValue; } //======================================================================= @@ -366,7 +515,7 @@ CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertex(CORBA::Double x, CORBA { ASSERT(myBaseImpl); try { - return this->GetImpl()->GetEnforcedVertex(x,y,z); + return this->GetImpl()->GetEnforcedVertex(x,y,z)->size; } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -382,6 +531,55 @@ CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertex(CORBA::Double x, CORBA return 0; } +//======================================================================= +//function : GetEnforcedVertex +//======================================================================= + +CORBA::Double GHS3DPlugin_Hypothesis_i::GetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + + if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) { + MESSAGE("theVertex shape type is not VERTEX or COMPOUND"); + THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM); + } + + string theVertexEntry = theVertex->GetStudyEntry(); + if (theVertexEntry.empty()) { + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); + string aName; + if (theVertex->GetShapeType() == GEOM::VERTEX) + aName = "Vertex_"; + if (theVertex->GetShapeType() == GEOM::COMPOUND) + aName = "Compound_"; + aName += theVertex->GetEntry(); + SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + if (!theSVertex->_is_nil()) + theVertexEntry = theSVertex->GetID(); + } + if (theVertexEntry.empty()) + THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + + string theVertexName = theVertex->GetName(); + + try { + return this->GetImpl()->GetEnforcedVertex(theVertexName)->size; + } + catch (const std::invalid_argument& ex) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = ex.what(); + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::GetEnforcedVertexGeom(theVertex)"; + ExDescription.lineNumber = 0; + throw SALOME::SALOME_Exception(ExDescription); + } + catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } +} + //======================================================================= //function : GetEnforcedVertices //======================================================================= @@ -391,20 +589,30 @@ GHS3DPlugin::GHS3DEnforcedVertexList* GHS3DPlugin_Hypothesis_i::GetEnforcedVerti ASSERT(myBaseImpl); GHS3DPlugin::GHS3DEnforcedVertexList_var result = new GHS3DPlugin::GHS3DEnforcedVertexList(); - const ::GHS3DPlugin_Hypothesis::TEnforcedVertexValues sizeMaps = this->GetImpl()->_GetEnforcedVertices(); - int size = sizeMaps.size(); - result->length( size ); - - ::GHS3DPlugin_Hypothesis::TEnforcedVertexValues::const_iterator it; - int i = 0; - for (it = sizeMaps.begin() ; it != sizeMaps.end(); it++ ) { - GHS3DPlugin::GHS3DEnforcedVertex_var myVertex = new GHS3DPlugin::GHS3DEnforcedVertex(); - myVertex->x = it->first[0]; - myVertex->y = it->first[1]; - myVertex->z = it->first[2]; - myVertex->size = it->second; - result[i]=myVertex; - i++; + const ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList enfVertexList = this->GetImpl()->_GetEnforcedVertices(); + result->length( enfVertexList.size() ); + + ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertexList::const_iterator it = enfVertexList.begin(); + + for (int i = 0 ; it != enfVertexList.end(); ++it, ++i ) { + ::GHS3DPlugin_Hypothesis::TGHS3DEnforcedVertex* currentVertex = (*it); + GHS3DPlugin::GHS3DEnforcedVertex_var enfVertex = new GHS3DPlugin::GHS3DEnforcedVertex(); + // Name + enfVertex->name = CORBA::string_dup(currentVertex->name.c_str()); + // Geom Vertex Entry + enfVertex->geomEntry = CORBA::string_dup(currentVertex->geomEntry.c_str()); + // Coords + GHS3DPlugin::TCoords_var coords = new GHS3DPlugin::TCoords(); + coords->length(currentVertex->coords.size()); + for (int ind = 0; ind < currentVertex->coords.size(); ind++) + coords[ind] = currentVertex->coords[ind]; + enfVertex->coords = coords; + // Group Name + enfVertex->groupName = CORBA::string_dup(currentVertex->groupName.c_str()); + // Size + enfVertex->size = currentVertex->size; + + result[i]=enfVertex; } return result._retn(); @@ -414,13 +622,60 @@ GHS3DPlugin::GHS3DEnforcedVertexList* GHS3DPlugin_Hypothesis_i::GetEnforcedVerti //function : RemoveEnforcedVertex //======================================================================= -void GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) +bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); + bool res = false; + try { + res = this->GetImpl()->RemoveEnforcedVertex(x,y,z); + SMESH::TPythonDump() << " isDone = " << _this() << ".RemoveEnforcedVertex( " << x << ", " << y << ", " << z << " )"; + } + catch (const std::invalid_argument& ex) { + SALOME::ExceptionStruct ExDescription; + ExDescription.text = ex.what(); + ExDescription.type = SALOME::BAD_PARAM; + ExDescription.sourceFile = "GHS3DPlugin_Hypothesis::RemoveEnforcedVertex(x,y,z)"; + ExDescription.lineNumber = 408; + throw SALOME::SALOME_Exception(ExDescription); + } + catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + return res; +} + +bool GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + + if ((theVertex->GetShapeType() != GEOM::VERTEX) && (theVertex->GetShapeType() != GEOM::COMPOUND)) { + MESSAGE("theVertex shape type is not VERTEX or COMPOUND"); + THROW_SALOME_CORBA_EXCEPTION("theVertex shape type is not VERTEX or COMPOUND", SALOME::BAD_PARAM); + } + + string theVertexEntry = theVertex->GetStudyEntry(); + if (theVertexEntry.empty()) { + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); + string aName; + if (theVertex->GetShapeType() == GEOM::VERTEX) + aName = "Vertex_"; + if (theVertex->GetShapeType() == GEOM::COMPOUND) + aName = "Compound_"; + aName += theVertex->GetEntry(); + SALOMEDS::SObject_ptr theSVertex = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, theVertex, aName.c_str()); + if (!theSVertex->_is_nil()) + theVertexEntry = theSVertex->GetID(); + } + if (theVertexEntry.empty()) + THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + + bool res = false; try { - this->GetImpl()->RemoveEnforcedVertex(x,y,z); - SMESH::TPythonDump() << _this() << ".RemoveEnforcedVertex( " << x << ", " << y << ", " << z << " )"; + res = this->GetImpl()->RemoveEnforcedVertex(0,0,0, theVertexEntry.c_str()); + SMESH::TPythonDump() << "isDone = " << _this() << ".RemoveEnforcedVertexGeom( " << theVertexEntry.c_str() << " )"; } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -433,6 +688,7 @@ void GHS3DPlugin_Hypothesis_i::RemoveEnforcedVertex(CORBA::Double x, CORBA::Doub catch (SALOME_Exception& ex) { THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); } + return res; } //======================================================================= @@ -460,11 +716,11 @@ void GHS3DPlugin_Hypothesis_i::ClearEnforcedMeshes() /*! * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource. */ -void GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType) +bool GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType) throw (SALOME::SALOME_Exception) { #if GHS3D_VERSION >= 42 - _SetEnforcedMesh(theSource, theType, -1.0); + 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) @@ -477,6 +733,7 @@ void GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSour SMESH::TPythonDump () << _this() << ".SetEnforcedMesh( " << theSource << ".GetMesh(), " << theType << " )"; } + return res; #else SALOME::ExceptionStruct ExDescription; ExDescription.text = "Bad version of GHS3D. It must >= 4.2."; @@ -490,7 +747,7 @@ void GHS3DPlugin_Hypothesis_i::SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSour /*! * \brief Adds enforced elements of type elementType using another mesh/sub-mesh/mesh group theSource and a size. */ -void GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize) +bool GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType theType, double theSize) throw (SALOME::SALOME_Exception) { if (theSize <= 0) { @@ -502,7 +759,7 @@ void GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr the throw SALOME::SALOME_Exception(ExDescription); } - _SetEnforcedMesh(theSource, theType, theSize); + 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) @@ -515,9 +772,10 @@ void GHS3DPlugin_Hypothesis_i::SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr the SMESH::TPythonDump () << _this() << ".SetEnforcedMeshSize( " << theSource << ".GetMesh(), " << theType << ", " << theSize << " )"; } + return res; } -void 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) throw (SALOME::SALOME_Exception) { ASSERT(myBaseImpl); @@ -561,7 +819,7 @@ void GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou if (anImplPtr) theMeshDS = anImplPtr->GetImpl().GetMeshDS(); else - return; + return false; SMESH_Mesh_i* theMesh_i = SMESH::DownCast( theSource); SMESH_Group_i* theGroup_i = SMESH::DownCast( theSource); @@ -570,7 +828,7 @@ void GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou if (theMesh_i) { try { - this->GetImpl()->SetEnforcedMesh(anImplPtr->GetImpl(), theType, theSize); + return this->GetImpl()->SetEnforcedMesh(anImplPtr->GetImpl(), theType, theSize); } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -617,7 +875,7 @@ void GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou MESSAGE("Add "<GetName()); try { - this->GetImpl()->SetEnforcedElements(theElemSet, theType, theSize); + return this->GetImpl()->SetEnforcedElements(theElemSet, theType, theSize); } catch (const std::invalid_argument& ex) { SALOME::ExceptionStruct ExDescription; @@ -631,6 +889,7 @@ void GHS3DPlugin_Hypothesis_i::_SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSou THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); } } + return false; } //============================================================================= /*! diff --git a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx index d9b5941..b3381bd 100644 --- a/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx +++ b/src/GHS3DPlugin/GHS3DPlugin_Hypothesis_i.hxx @@ -125,17 +125,24 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: /*! * To set an enforced vertex */ - void SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size); + bool _SetEnforcedVertex(CORBA::Double size, CORBA::Double x = 0, CORBA::Double y = 0, CORBA::Double z = 0, + const char* theVertexName = "", const char* theVertexEntry = "", const char* theGroupName = "") + throw (SALOME::SALOME_Exception); + bool SetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size) throw (SALOME::SALOME_Exception); + bool SetEnforcedVertexWithGroup(CORBA::Double x, CORBA::Double y, CORBA::Double z, CORBA::Double size, const char* theGroupName) throw (SALOME::SALOME_Exception); + bool SetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size) throw (SALOME::SALOME_Exception); // TODO + bool SetEnforcedVertexGeomWithGroup(GEOM::GEOM_Object_ptr theVertex, CORBA::Double size, const char* theGroupName) throw (SALOME::SALOME_Exception); // TODO CORBA::Double GetEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); - void RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); + CORBA::Double GetEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) throw (SALOME::SALOME_Exception); // TODO + bool RemoveEnforcedVertex(CORBA::Double x, CORBA::Double y, CORBA::Double z) throw (SALOME::SALOME_Exception); + bool RemoveEnforcedVertexGeom(GEOM::GEOM_Object_ptr theVertex) throw (SALOME::SALOME_Exception); // TODO GHS3DPlugin::GHS3DEnforcedVertexList* GetEnforcedVertices(); void ClearEnforcedVertices(); /*! * To set an enforced mesh */ - void SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType) throw (SALOME::SALOME_Exception); - void SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size) throw (SALOME::SALOME_Exception); - void _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) throw (SALOME::SALOME_Exception); + bool SetEnforcedMeshSize(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size) throw (SALOME::SALOME_Exception); void ClearEnforcedMeshes(); // Get implementation @@ -143,6 +150,10 @@ class GHS3DPLUGIN_EXPORT GHS3DPlugin_Hypothesis_i: // Verify whether hypothesis supports given entity type CORBA::Boolean IsDimSupported( SMESH::Dimension type ); + + private: + + bool _SetEnforcedMesh(SMESH::SMESH_IDSource_ptr theSource, SMESH::ElementType elementType, double size) throw (SALOME::SALOME_Exception); }; #endif diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx index e716b43..bc91a1e 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.cxx @@ -505,32 +505,35 @@ void GHS3DPluginGUI_HypothesisCreator::retrieveParams() const myFEMCorrectionCheck ->setChecked ( data.myFEMCorrection ); myTextOption ->setText ( data.myTextOption ); - TEnforcedVertexValues::const_iterator it; + TEnfVertexList::const_iterator it; int row = 0; for(it = data.myEnforcedVertices.begin() ; it != data.myEnforcedVertices.end(); it++ ) { - double x = it->at(0); - double y = it->at(1); - double z = it->at(2); - double size = it->at(3); - // ENF_VER_X_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x); - mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) ); - mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_Y_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y); - mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) ); - mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_Z_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z); - mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) ); - mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable ); - // ENF_VER_SIZE_COLUMN - mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size); - mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size)) ); - - MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size); - row++; + TEnfVertex* enfVertex = (*it); + if (enfVertex->coords.size()) { + double x = enfVertex->coords.at(0); + double y = enfVertex->coords.at(1); + double z = enfVertex->coords.at(2); + double size = enfVertex->size; + // ENF_VER_X_COLUMN + mySmpModel->setData(mySmpModel->index(row, ENF_VER_X_COLUMN),x); + mySmpModel->setItem( row, ENF_VER_X_COLUMN, new QStandardItem(QString::number(x)) ); + mySmpModel->item( row, ENF_VER_X_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // ENF_VER_Y_COLUMN + mySmpModel->setData(mySmpModel->index(row, ENF_VER_Y_COLUMN),y); + mySmpModel->setItem( row, ENF_VER_Y_COLUMN, new QStandardItem(QString::number(y)) ); + mySmpModel->item( row, ENF_VER_Y_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // ENF_VER_Z_COLUMN + mySmpModel->setData(mySmpModel->index(row, ENF_VER_Z_COLUMN),z); + mySmpModel->setItem( row, ENF_VER_Z_COLUMN, new QStandardItem(QString::number(z)) ); + mySmpModel->item( row, ENF_VER_Z_COLUMN )->setFlags( Qt::ItemIsSelectable ); + // ENF_VER_SIZE_COLUMN + mySmpModel->setData(mySmpModel->index(row, ENF_VER_SIZE_COLUMN),size); + mySmpModel->setItem( row, ENF_VER_SIZE_COLUMN, new QStandardItem(QString::number(size)) ); + + MESSAGE("Row " << row << ": (" << x << ","<< y << ","<< z << ") ="<< size); + row++; + } } GHS3DPluginGUI_HypothesisCreator* that = (GHS3DPluginGUI_HypothesisCreator*)this; @@ -630,13 +633,17 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromHypo( GHS3DHypothesisData& MESSAGE("vertices->length(): " << vertices->length()); h_data.myEnforcedVertices.clear(); for (int i=0 ; ilength() ; i++) { - GHS3DEnforcedVertex myVertex; - myVertex.push_back(vertices[i].x); - myVertex.push_back(vertices[i].y); - myVertex.push_back(vertices[i].z); - myVertex.push_back(vertices[i].size); - MESSAGE("Add enforced vertex ("<< myVertex[0] << ","<< myVertex[1] << ","<< myVertex[2] << ") ="<< myVertex[3]); - h_data.myEnforcedVertices.push_back(myVertex); + TEnfVertex* myVertex; + myVertex->name = vertices[i].name; + myVertex->geomEntry = vertices[i].geomEntry; + myVertex->groupName = vertices[i].groupName; + myVertex->size = vertices[i].size; + if (vertices[i].coords.length()) { + for (int c = 0; c < vertices[i].coords.length() ; c++) + myVertex->coords.push_back(vertices[i].coords[c]); + MESSAGE("Add enforced vertex ("<< myVertex->coords.at(0) << ","<< myVertex->coords.at(1) << ","<< myVertex->coords.at(2) << ") ="<< myVertex->size); + } + h_data.myEnforcedVertices.insert(myVertex); } return true; } @@ -694,9 +701,9 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD // else { // iterate over vertices of hypo for(int i = 0 ; i RemoveEnforcedVertex(x,y,z); @@ -704,12 +711,13 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD // } } - TEnforcedVertexValues::const_iterator it; + TEnfVertexList::const_iterator it; for(it = h_data.myEnforcedVertices.begin() ; it != h_data.myEnforcedVertices.end(); it++ ) { - double x = it->at(0); - double y = it->at(1); - double z = it->at(2); - double size = it->at(3); + TEnfVertex* enfVertex = (*it); + double x = enfVertex->coords.at(0); + double y = enfVertex->coords.at(1); + double z = enfVertex->coords.at(2); + double size = enfVertex->size; MESSAGE("(" << x << ", " << y << ", " << z << ") = " @@ -725,7 +733,7 @@ bool GHS3DPluginGUI_HypothesisCreator::storeParamsToHypo( const GHS3DHypothesisD } catch (...) { MESSAGE("Setting new size: " << size); - h->SetEnforcedVertex(x,y,z,size); + h->SetEnforcedVertex( x, y, z, size); } } } @@ -756,16 +764,16 @@ bool GHS3DPluginGUI_HypothesisCreator::readParamsFromWidgets( GHS3DHypothesisDat h_data.myEnforcedVertices.clear(); for (int i=0 ; irowCount() ; i++) { - GHS3DEnforcedVertex myVertex; - myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble()); - myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble()); - myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble()); - myVertex.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble()); - MESSAGE("Add new enforced vertex (" << myVertex[0] << ", " - << myVertex[1] << ", " - << myVertex[2] << ") = " - << myVertex[3]); - h_data.myEnforcedVertices.push_back(myVertex); + TEnfVertex *myVertex; + myVertex->coords.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_X_COLUMN)).toDouble()); + myVertex->coords.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Y_COLUMN)).toDouble()); + myVertex->coords.push_back(mySmpModel->data(mySmpModel->index(i,ENF_VER_Z_COLUMN)).toDouble()); + myVertex->size = mySmpModel->data(mySmpModel->index(i,ENF_VER_SIZE_COLUMN)).toDouble(); + MESSAGE("Add new enforced vertex (" << myVertex->coords.at(0) << ", " + << myVertex->coords.at(1) << ", " + << myVertex->coords.at(2) << ") = " + << myVertex->size); + h_data.myEnforcedVertices.insert(myVertex); } return true; diff --git a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h index de0359d..2423f15 100644 --- a/src/GUI/GHS3DPluginGUI_HypothesisCreator.h +++ b/src/GUI/GHS3DPluginGUI_HypothesisCreator.h @@ -41,6 +41,7 @@ #include #include #include +#include #include CORBA_SERVER_HEADER(GHS3DPlugin_Algorithm) class QWidget; @@ -55,8 +56,32 @@ class QDoubleSpinBox; class LightApp_SelectionMgr; -typedef std::vector GHS3DEnforcedVertex; -typedef std::vector TEnforcedVertexValues; +// Enforced vertex +struct TEnfVertex{ + std::string name; + std::string geomEntry; + std::vector coords; + std::string groupName; + double size; +}; + +struct CompareEnfVertices +{ + bool operator () (const TEnfVertex* e1, const TEnfVertex* e2) const { + if (e1 && e2) { + if (e1->coords.size() && e2->coords.size()) + return (e1->coords < e2->coords); + else + return (e1->geomEntry < e2->geomEntry); + } + return false; + } +}; + +// List of enforced vertices +typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList; + +// typedef std::vector TEnforcedVertexCoordsValues; typedef struct { @@ -64,7 +89,7 @@ typedef struct int myMaximumMemory,myInitialMemory,myOptimizationLevel; QString myName,myWorkingDir,myTextOption; short myVerboseLevel; - TEnforcedVertexValues myEnforcedVertices; + TEnfVertexList myEnforcedVertices; } GHS3DHypothesisData; /*! -- 2.39.2