From 3b4b4bf830e1e9570c1e4e6c1b6b0549547e39a0 Mon Sep 17 00:00:00 2001 From: bourcier Date: Mon, 3 Jun 2013 08:33:28 +0000 Subject: [PATCH] Adding periodicity to BLSURF plugin (no GUI for now), as described in CadSurf user manual: - basic: periodicity must be defined face by face, edge by edge, vertex by vertex - advanced: periodicity can be defined with two groups of faces. --- idl/BLSURFPlugin_Algorithm.idl | 14 + resources/BLSURFPlugin.xml | 3 +- src/BLSURFPlugin/BLSURFPluginDC.py | 73 ++- src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx | 444 +++++++++++++++++- src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx | 52 ++ src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx | 135 +++++- src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx | 66 +++ .../BLSURFPlugin_Hypothesis_i.cxx | 322 +++++++++++++ .../BLSURFPlugin_Hypothesis_i.hxx | 44 ++ 9 files changed, 1144 insertions(+), 9 deletions(-) diff --git a/idl/BLSURFPlugin_Algorithm.idl b/idl/BLSURFPlugin_Algorithm.idl index c03c31c..0549426 100644 --- a/idl/BLSURFPlugin_Algorithm.idl +++ b/idl/BLSURFPlugin_Algorithm.idl @@ -426,6 +426,20 @@ module BLSURFPlugin // TFaceEntryInternalVerticesList GetAllInternalEnforcedVerticesFaces(); /////////////////////// + + /////////////////////// + // PERIODICITY // + /////////////////////// + + void AddPreCadFacesPeriodicity(in GEOM::GEOM_Object faces1, in GEOM::GEOM_Object faces2, in string f_transf) raises (SALOME::SALOME_Exception); + void AddPreCadEdgesPeriodicity(in GEOM::GEOM_Object edges1, in GEOM::GEOM_Object edges2, in string f_transf) raises (SALOME::SALOME_Exception); + void AddFacePeriodicity(in GEOM::GEOM_Object face1, in GEOM::GEOM_Object face2) raises (SALOME::SALOME_Exception); + void AddEdgePeriodicity(in GEOM::GEOM_Object face1, in GEOM::GEOM_Object edge1, in GEOM::GEOM_Object face2, in GEOM::GEOM_Object edge2, in long edge_orientation) raises (SALOME::SALOME_Exception); + void AddEdgePeriodicityWithoutFaces(in GEOM::GEOM_Object edge1, in GEOM::GEOM_Object edge2, in long edge_orientation) raises (SALOME::SALOME_Exception); + void AddVertexPeriodicity(in GEOM::GEOM_Object edge1, in GEOM::GEOM_Object Vertex1, in GEOM::GEOM_Object edge2, in GEOM::GEOM_Object vertex2) raises (SALOME::SALOME_Exception); + + /////////////////////// + /*! * Sets the file for export resulting mesh in GMF format */ diff --git a/resources/BLSURFPlugin.xml b/resources/BLSURFPlugin.xml index ec9402d..2939655 100644 --- a/resources/BLSURFPlugin.xml +++ b/resources/BLSURFPlugin.xml @@ -55,7 +55,8 @@ SetEnforcedVertexGeomWithGroup, UnsetEnforcedVertex, UnsetEnforcedVertexGeom, - UnsetEnforcedVertices + UnsetEnforcedVertices, + AddPreCadFacesPeriodicity diff --git a/src/BLSURFPlugin/BLSURFPluginDC.py b/src/BLSURFPlugin/BLSURFPluginDC.py index 0ae068d..d6fa328 100644 --- a/src/BLSURFPlugin/BLSURFPluginDC.py +++ b/src/BLSURFPlugin/BLSURFPluginDC.py @@ -424,6 +424,77 @@ class BLSURF_Algorithm(Mesh_Algorithm): pass return self.params + #----------------------------------------- + # Periodicity (BLSURF) + #----------------------------------------- + + ## Defines periodicity between two groups of faces + # @param faces1: group of faces to associate with faces2 + # @param faces2: group of faces associated with faces1 + # @param f_transf (optionnal): the transformation function from faces1 to faces2. + # If None, PreCAD tries to find a simple translation + + def AddPreCadFacesPeriodicity(self, faces1, faces2, f_transf= ""): + """calls preCad function: + status_t cad_add_face_multiple_periodicity_with_transformation_function(cad t *cad, + integer *fid1, integer size1, integer *fid2, integer size2, + periodicity_transformation_t transf, void *user data); + """ + self.Parameters().AddPreCadFacesPeriodicity(faces1, faces2, f_transf) + pass + + ## Defines periodicity between two groups of edges + # @param edges1: group of edges to associate with edges2 + # @param edges2: group of edges associated with edges1 + # @param f_transf (optionnal): the transformation function from edges1 to edges2. + # If None, PreCAD tries to find a simple translation + + def AddPreCadEdgesPeriodicity(self, edges1, edges2, f_transf= ""): + """calls preCad function: + status_t cad_add_edge_multiple_periodicity_with_transformation_function(cad t *cad, + integer *eid1, integer size1, integer *eid2, integer size2, + periodicity_transformation_t transf, void *user data); + """ + self.Parameters().AddPreCadEdgesPeriodicity(edges1, edges2, f_transf) + pass + + ## Defines periodicity between two groups of faces. + # This macro defines periodicity with the CADSurf API on each sub face, sub edge and sub vertex. + # PreCAD is not needed. + # @param faces1: group of faces to associate with faces2 + # @param faces2: group of faces associated with faces1 + # @param f_transf: the transformation function from faces1 to faces2. + def AddAdvancedFacesPeriodicity(faces1, faces2, f_transf): + self.Parameters().AddAdvancedFacesPeriodicity(faces1, faces2, f_transf) + pass + + + ## Defines periodicity between two faces + # User has to call AddEdgePeriodicity with the edges of the face + # and AddVertexPeriodicity with the vertices of each edge + def AddFacePeriodicity(self, face1, face2): + self.Parameters().AddFacePeriodicity(face1, face2) + pass + + ## Defines periodicity between two edges belonging to two periodic faces + # @param edge_orientation: -1 (reversed), 0 (unknown) or 1 (forward) + # User has to call AddVertexPeriodicity with the vertices of each edge + def AddEdgePeriodicity(self, face1, edge1, face2, edge2, edge_orientation=0): + self.Parameters().AddEdgePeriodicity(face1, edge1, face2, edge2, edge_orientation) + pass + + ## Defines periodicity between two edges without face periodicity + # @param edge_orientation: -1 (reversed), 0 (unknown) or 1 (forward) + # User has to call AddVertexPeriodicity with the vertices of each edge + def AddEdgePeriodicityWithoutFaces(self, edge1, edge2, edge_orientation=0): + self.Parameters().AddEdgePeriodicityWithoutFaces(edge1, edge2, edge_orientation) + pass + + ## Defines periodicity between two vertices + def AddVertexPeriodicity(self, edge1, vertex1, edge2, vertex2): + self.Parameters().AddVertexPeriodicity(edge1, vertex1, edge2, vertex2) + pass + #===================== # Obsolete methods #===================== @@ -486,4 +557,4 @@ class BLSURF_Algorithm(Mesh_Algorithm): pass - pass # end of BLSURF_Algorithm class \ No newline at end of file + pass # end of BLSURF_Algorithm class diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx index 41ce976..721cb86 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx @@ -689,6 +689,190 @@ void createAttractorOnFace(TopoDS_Shape GeomShape, std::string AttractorFunction // MESSAGE("point OK"); } +// One sub-shape to get ids from +BLSURFPlugin_BLSURF::TListOfIDs _getSubShapeIDsInMainShape(TopoDS_Shape theMainShape, TopoDS_Shape theSubShape, + TopAbs_ShapeEnum theShapeType) +{ + BLSURFPlugin_BLSURF::TListOfIDs face_ids; + TopTools_IndexedMapOfShape anIndices; + anIndices.Clear(); + TopExp::MapShapes(theMainShape, theShapeType, anIndices); + +// Standard_Boolean result = BRepTools::Write(theMainShape,"main_shape.brep"); + + for (TopExp_Explorer face_iter(theSubShape,theShapeType);face_iter.More();face_iter.Next()) + { + int face_id = anIndices.FindIndex(face_iter.Current()); + if (face_id == 0) + throw SALOME_Exception ( SMESH_Comment("Sub_shape not found in main_shape")); + face_ids.push_back(face_id); +// std::ostringstream o; +// o << "face_" << face_id << ".brep"; +// std::string face_name = o.str(); +// const TopoDS_Face& face = TopoDS::Face(face_iter.Current()); +// Standard_Boolean result = BRepTools::Write(face,face_name.c_str()); + } + + return face_ids; +} + + +///////////////////////////////////////////////////////// +void BLSURFPlugin_BLSURF::createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry faces1, + BLSURFPlugin_Hypothesis::TEntry faces2, const char* f_funct) +{ + MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity"); + + TopoDS_Shape geomShape1 = entryToShape(faces1); + TopoDS_Shape geomShape2 = entryToShape(faces2); + + TListOfIDs faces1_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape1, TopAbs_FACE); + TListOfIDs faces2_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape2, TopAbs_FACE); + + TPreCadPeriodicityIDs preCaDFacesPeriodicityIDs; + preCaDFacesPeriodicityIDs.shape1IDs = faces1_ids; + preCaDFacesPeriodicityIDs.shape2IDs = faces2_ids; + preCaDFacesPeriodicityIDs.f_funct = f_funct; + + + _preCadFacesIDsPeriodicityVector.push_back(preCaDFacesPeriodicityIDs); + MESSAGE("_preCadFacesIDsPeriodicityVector.size() = " << _preCadFacesIDsPeriodicityVector.size()); + MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity END"); + +} + +///////////////////////////////////////////////////////// +void BLSURFPlugin_BLSURF::createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry edges1, + BLSURFPlugin_Hypothesis::TEntry edges2, const char* f_funct) +{ + MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity"); + + TopoDS_Shape geomShape1 = entryToShape(edges1); + TopoDS_Shape geomShape2 = entryToShape(edges2); + + TListOfIDs edges1_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape1, TopAbs_EDGE); + TListOfIDs edges2_ids = _getSubShapeIDsInMainShape(theGeomShape, geomShape2, TopAbs_EDGE); + + TPreCadPeriodicityIDs preCaDEdgesPeriodicityIDs; + preCaDEdgesPeriodicityIDs.shape1IDs = edges1_ids; + preCaDEdgesPeriodicityIDs.shape2IDs = edges2_ids; + preCaDEdgesPeriodicityIDs.f_funct = f_funct; + + + _preCadEdgesIDsPeriodicityVector.push_back(preCaDEdgesPeriodicityIDs); + MESSAGE("_preCadEdgesIDsPeriodicityVector.size() = " << _preCadEdgesIDsPeriodicityVector.size()); + MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity END"); + +} + +///////////////////////////////////////////////////////// +void BLSURFPlugin_BLSURF::createFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry face1, BLSURFPlugin_Hypothesis::TEntry face2) +{ + MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity"); + + TopoDS_Shape GeomShape1 = entryToShape(face1); + TopoDS_Shape GeomShape2 = entryToShape(face2); + + TListOfIDs faces1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomShape1, TopAbs_FACE); + TListOfIDs faces2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomShape2, TopAbs_FACE); + + // Only one face id, since only a face can be selected + int face1_id = faces1_ids[0]; + int face2_id = faces2_ids[0]; + + std::pair pairOfFacesID = std::make_pair(face1_id, face2_id); + + _facesIDsPeriodicityVector.push_back(pairOfFacesID); + MESSAGE("_facesIDsPeriodicityVector.size() = " << _facesIDsPeriodicityVector.size()); + MESSAGE("BLSURFPlugin_BLSURF::createFacesPeriodicity END"); + +} + + +///////////////////////////////////////////////////////// +void BLSURFPlugin_BLSURF::createEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry face1, BLSURFPlugin_Hypothesis::TEntry edge1, + BLSURFPlugin_Hypothesis::TEntry face2, BLSURFPlugin_Hypothesis::TEntry edge2, int edge_orientation) +{ + MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity"); + + TEdgePeriodicityIDs edgePeriodicityIDs; + + if (face1 != "") + { + TopoDS_Shape GeomFace1 = entryToShape(face1); + TListOfIDs faces1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomFace1, TopAbs_FACE); + // Only one face id, since only a face can be selected + edgePeriodicityIDs.face1ID = faces1_ids[0]; + } + else + edgePeriodicityIDs.face1ID = 0; + if (face2 != "") + { + TopoDS_Shape GeomFace2 = entryToShape(face2); + TListOfIDs faces2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomFace2, TopAbs_FACE); + edgePeriodicityIDs.face2ID = faces2_ids[0]; + } + else + edgePeriodicityIDs.face2ID = 0; + + TopoDS_Shape GeomEdge1 = entryToShape(edge1); + TopoDS_Shape GeomEdge2 = entryToShape(edge2); + + TListOfIDs edges1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge1, TopAbs_EDGE); + TListOfIDs edges2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge2, TopAbs_EDGE); + + if (edge_orientation == 0 and GeomEdge1.Closed()) + { + // if edge is closed, we have to set its orientation + MESSAGE("GeomEdge1.Orientation() = " << GeomEdge1.Orientation()); + MESSAGE("GeomEdge2.Orientation() = " << GeomEdge2.Orientation()); + if(GeomEdge1.Orientation() == TopAbs_FORWARD) + edge_orientation = CAD_ORIENTATION_REVERSED; + else + edge_orientation = CAD_ORIENTATION_FORWARD; + } + + // Only one edge id, since only a edge can be selected + edgePeriodicityIDs.edge1ID = edges1_ids[0]; + edgePeriodicityIDs.edge2ID = edges2_ids[0]; + edgePeriodicityIDs.edge_orientation = edge_orientation; + + _edgesIDsPeriodicityVector.push_back(edgePeriodicityIDs); + MESSAGE("_edgesIDsPeriodicityVector.size() = " << _edgesIDsPeriodicityVector.size()); + MESSAGE("BLSURFPlugin_BLSURF::createEdgesPeriodicity END"); + +} + + +///////////////////////////////////////////////////////// +void BLSURFPlugin_BLSURF::createVerticesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry edge1, BLSURFPlugin_Hypothesis::TEntry vertex1, + BLSURFPlugin_Hypothesis::TEntry edge2, BLSURFPlugin_Hypothesis::TEntry vertex2) +{ + MESSAGE("BLSURFPlugin_BLSURF::createVerticesPeriodicity"); + + TopoDS_Shape GeomEdge1 = entryToShape(edge1); + TopoDS_Shape GeomVertex1 = entryToShape(vertex1); + TopoDS_Shape GeomEdge2 = entryToShape(edge2); + TopoDS_Shape GeomVertex2 = entryToShape(vertex2); + + TListOfIDs edges1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge1, TopAbs_EDGE); + TListOfIDs vertices1_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomVertex1, TopAbs_VERTEX); + TListOfIDs edges2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomEdge2, TopAbs_EDGE); + TListOfIDs vertices2_ids = _getSubShapeIDsInMainShape(theGeomShape, GeomVertex2, TopAbs_VERTEX); + + // Only one vertex id, since only a vertex can be selected + TVertexPeriodicityIDs vertexPeriodicityIDs; + vertexPeriodicityIDs.edge1ID = edges1_ids[0]; + vertexPeriodicityIDs.vertex1ID = vertices1_ids[0]; + vertexPeriodicityIDs.edge2ID = edges2_ids[0]; + vertexPeriodicityIDs.vertex2ID = vertices2_ids[0]; + + _verticesIDsPeriodicityVector.push_back(vertexPeriodicityIDs); + MESSAGE("_verticesIDsPeriodicityVector.size() = " << _verticesIDsPeriodicityVector.size()); + MESSAGE("BLSURFPlugin_BLSURF::createVerticesPeriodicity END"); + +} + ///////////////////////////////////////////////////////// void BLSURFPlugin_BLSURF::SetParameters( @@ -1199,6 +1383,64 @@ void BLSURFPlugin_BLSURF::SetParameters( // #endif } } + + // PERIODICITY + MESSAGE("SetParameters preCadFacesPeriodicityVector"); + const BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector preCadFacesPeriodicityVector = BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector(hyp); + + for (std::size_t i = 0; iIsMeshComputed() ) edgeSubmeshes.insert( sm->GetSubMeshDS() ); } + + std::string aFileName = "fmap_vertex_"; + aFileName.append(to_string(*ip)); + aFileName.append(".brep"); + BRepTools::Write(v,aFileName.c_str()); + if (HasSizeMapOnVertex){ vertexKey = VerticesWithSizeMap.FindIndex(v); if (VertexId2SizeMap.find(vertexKey)!=VertexId2SizeMap.end()){ @@ -2140,8 +2410,150 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh& aMesh, } } + /////////////////////// + // PERIODICITY // + /////////////////////// + + MESSAGE("BEFORE PERIODICITY"); + MESSAGE("_preCadFacesIDsPeriodicityVector.size() = " << _preCadFacesIDsPeriodicityVector.size()); + if (! _preCadFacesIDsPeriodicityVector.empty()){ + MESSAGE("INTO PRECAD FACES PERIODICITY"); + for (std::size_t i=0; i < _preCadFacesIDsPeriodicityVector.size(); i++){ + std::vector faces1_ids = _preCadFacesIDsPeriodicityVector[i].shape1IDs; + std::vector faces2_ids = _preCadFacesIDsPeriodicityVector[i].shape2IDs; + // TODO: récupérer _preCadFacesIDsPeriodicityVector[i].f_funct + meshgems_cad_periodicity_transformation_t periodicity_transformation = NULL; + int* faces1_ids_c = &faces1_ids[0]; + int* faces2_ids_c = &faces2_ids[0]; + std::ostringstream o; + o << "_preCadFacesIDsPeriodicityVector[" << i << "] = ["; + for (std::size_t j=0; j < faces1_ids.size(); j++) + o << faces1_ids[j] << ", "; + o << "], ["; + for (std::size_t j=0; j < faces2_ids.size(); j++) + o << faces2_ids[j] << ", "; + o << "]"; + MESSAGE(o.str()); + MESSAGE("faces1_ids.size(): " << faces1_ids.size()); + MESSAGE("faces2_ids.size(): " << faces2_ids.size()); + status = cad_add_face_multiple_periodicity_with_transformation_function(c, faces1_ids_c, faces1_ids.size(), + faces2_ids_c, faces2_ids.size(), periodicity_transformation, NULL); +// double p1[] = {0, 0, 0, 100, 0, 0, 0, 0, 100}; +// double p2[] = {0, 100, 0, 100, 100, 0, 0, 100, 100}; +// double (*ptr1)[9]; +// double (*ptr2)[9]; +// ptr1 = &p1; +// ptr2 = &p2; +// status = cad_add_face_multiple_periodicity_with_transformation_function_by_points(c, faces1_ids_c, faces1_ids.size(), +// faces2_ids_c, faces2_ids.size(), &p1[0], 3, &p2[0], 3); + if(status != STATUS_OK){ + cout << "cad_add_face_multiple_periodicity_with_transformation_function failed with error code " << status << "\n"; + } + } + + MESSAGE("END PRECAD FACES PERIODICITY"); + } + + MESSAGE("_preCadEdgesIDsPeriodicityVector.size() = " << _preCadEdgesIDsPeriodicityVector.size()); + if (! _preCadEdgesIDsPeriodicityVector.empty()){ + MESSAGE("INTO PRECAD EDGES PERIODICITY"); + for (std::size_t i=0; i < _preCadEdgesIDsPeriodicityVector.size(); i++){ + // TODO: plutôt que d'utiliser une paire edge1, edge2, utiliser un struct avec edge1, edge2 et f_transf + std::vector edges1_ids = _preCadEdgesIDsPeriodicityVector[i].shape1IDs; + std::vector edges2_ids = _preCadEdgesIDsPeriodicityVector[i].shape2IDs; + // TODO: récupérer _preCadEdgesIDsPeriodicityVector[i].f_funct + meshgems_cad_periodicity_transformation_t periodicity_transformation = NULL; + // Use the address of the first element of the vector to initialise the array +// int* edges1_ids_c = &edges1_ids[0]; +// int* edges2_ids_c = &edges2_ids[0]; + + // Copy the vector into an array + int edges1_ids_c[edges1_ids.size()]; + std::copy(edges1_ids.begin(), edges1_ids.end(), edges1_ids_c); + int edges2_ids_c[edges2_ids.size()]; + std::copy(edges2_ids.begin(), edges2_ids.end(), edges2_ids_c); + + std::ostringstream o; + o << "_preCadEdgesIDsPeriodicityVector[" << i << "] = ["; + for (std::size_t j=0; j < edges1_ids.size(); j++) + o << edges1_ids[j] << ", "; + o << "], ["; + for (std::size_t j=0; j < edges2_ids.size(); j++) + o << edges2_ids[j] << ", "; + o << "]"; + MESSAGE(o.str()); + MESSAGE("edges1_ids.size(): " << edges1_ids.size()); + MESSAGE("edges2_ids.size(): " << edges2_ids.size()); + status = cad_add_edge_multiple_periodicity_with_transformation_function(c, edges1_ids_c, edges1_ids.size(), + edges2_ids_c, edges2_ids.size(), periodicity_transformation, NULL); +// double p1[] = {0, 0, 0, 100, 0, 0, 0, 0, 100}; +// double p2[] = {0, 100, 0, 100, 100, 0, 0, 100, 100}; +// double (*ptr1)[9]; +// double (*ptr2)[9]; +// ptr1 = &p1; +// ptr2 = &p2; +// status = cad_add_edge_multiple_periodicity_with_transformation_function_by_points(c, edges1_ids_c, edges1_ids.size(), +// edges2_ids_c, edges2_ids.size(), &p1[0], 3, &p2[0], 3); + if(status != STATUS_OK){ + cout << "cad_add_edge_multiple_periodicity_with_transformation_function failed with error code " << status << "\n"; + } + } + + MESSAGE("END PRECAD EDGES PERIODICITY"); + } + + if (! _facesIDsPeriodicityVector.empty()){ + MESSAGE("INTO FACE PERIODICITY"); + for (std::size_t i=0; i < _facesIDsPeriodicityVector.size(); i++){ + int face1 = _facesIDsPeriodicityVector[i].first; + int face2 = _facesIDsPeriodicityVector[i].second; + MESSAGE("_facesIDsPeriodicityVector[" << i << "] = (" << face1 << ", " << face2 << ")"); + status = cad_add_face_periodicity(c, face1, face2); + if(status != STATUS_OK){ + cout << "cad_add_face_periodicity failed with error code " << status << "\n"; + } + } + MESSAGE("END FACE PERIODICITY"); + } + + + if (! _edgesIDsPeriodicityVector.empty()){ + MESSAGE("INTO EDGE PERIODICITY"); + for (std::size_t i=0; i < _edgesIDsPeriodicityVector.size(); i++){ + int face1 = _edgesIDsPeriodicityVector[i].face1ID; + int edge1 = _edgesIDsPeriodicityVector[i].edge1ID; + int face2 = _edgesIDsPeriodicityVector[i].face2ID; + int edge2 = _edgesIDsPeriodicityVector[i].edge2ID; + int edge_orientation = _edgesIDsPeriodicityVector[i].edge_orientation; + MESSAGE("_edgesIDsPeriodicityVector[" << i << "] = (" << face1 << ", " << edge1 << ", " << face2 << ", " << edge2 << ", " << edge_orientation << ")"); + status = cad_add_edge_periodicity(c, face1, edge1, face2, edge2, edge_orientation); + if(status != STATUS_OK){ + cout << "cad_add_edge_periodicity failed with error code " << status << "\n"; + } + } + MESSAGE("END EDGE PERIODICITY"); + } + + if (! _verticesIDsPeriodicityVector.empty()){ + MESSAGE("INTO VERTEX PERIODICITY"); + for (std::size_t i=0; i < _verticesIDsPeriodicityVector.size(); i++){ + int edge1 = _verticesIDsPeriodicityVector[i].edge1ID; + int vertex1 = _verticesIDsPeriodicityVector[i].vertex1ID; + int edge2 = _verticesIDsPeriodicityVector[i].edge2ID; + int vertex2 = _verticesIDsPeriodicityVector[i].vertex2ID; + MESSAGE("_verticesIDsPeriodicityVector[" << i << "] = (" << edge1 << ", " << vertex1 << ", " << edge2 << ", " << vertex2 << ")"); + status = cad_add_point_periodicity(c, edge1, vertex1, edge2, vertex2); + if(status != STATUS_OK){ + cout << "cad_add_vertex_periodicity failed with error code " << status << "\n"; + } + } + MESSAGE("END VERTEX PERIODICITY"); + } + + //// if (use_precad) { + MESSAGE("use_precad"); /* Now launch the PreCAD process */ status = precad_process(pcs); if(status != STATUS_OK){ @@ -2149,11 +2561,22 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh& aMesh, } else { // retrieve the pre-processed CAD object + + // dcad + cleandc = precad_new_dcad(pcs); + if(!cleandc){ + cout << "Unable to retrieve PreCAD result on dcad \n"; + } + else + cout << "PreCAD processing successfull on dcad \n"; + + // cad cleanc = precad_new_cad(pcs); if(!cleanc){ - cout << "Unable to retrieve PreCAD result \n"; + cout << "Unable to retrieve PreCAD result on cad \n"; } - cout << "PreCAD processing successfull \n"; + else + cout << "PreCAD processing successfull on cad \n"; // #if BLSURF_VERSION_LONG >= "3.1.1" // /* We can now get the updated sizemaps (if any) */ @@ -2177,9 +2600,18 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh& aMesh, precad_session_delete(pcs); } - cadsurf_data_set_dcad(css, dcad); + if (cleandc) { + cout << "Give the pre-processed dcad object to the current BLSurf session \n"; + cadsurf_data_set_dcad(css, cleandc); + } + else { + // Use the original one + cadsurf_data_set_dcad(css, dcad); + } + if (cleanc) { // Give the pre-processed CAD object to the current BLSurf session + cout << "Give the pre-processed CAD object to the current BLSurf session \n"; cadsurf_data_set_cad(css, cleanc); } else { diff --git a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx index 5ebbd56..8e667bf 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_BLSURF.hxx @@ -94,10 +94,55 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo { virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape, MapShapeNbElems& aResMap); + // List of ids + typedef std::vector TListOfIDs; + + // PreCad Edges periodicity + struct TPreCadPeriodicityIDs { + TListOfIDs shape1IDs; + TListOfIDs shape2IDs; + const char* f_funct; + }; + + // Edge periodicity + struct TEdgePeriodicityIDs { + int face1ID; + int edge1ID; + int face2ID; + int edge2ID; + int edge_orientation; + }; + + // Vertex periodicity + struct TVertexPeriodicityIDs { + int edge1ID; + int vertex1ID; + int edge2ID; + int vertex2ID; + }; + + // pair of shapes + typedef std::pair TPairOfShapes; + typedef std::pair TPairOfListOfIDs; + // Vector of pairs of ids + typedef std::vector< TPreCadPeriodicityIDs > TPreCadIDsPeriodicityVector; + typedef std::vector< std::pair > TShapesIDsPeriodicityVector; + typedef std::vector< TEdgePeriodicityIDs > TEdgesIDsPeriodicityVector; + typedef std::vector< TVertexPeriodicityIDs > TVerticesIDsPeriodicityVector; + + + protected: const BLSURFPlugin_Hypothesis* _hypothesis; bool _haveViscousLayers; + TPreCadIDsPeriodicityVector _preCadFacesIDsPeriodicityVector; + TPreCadIDsPeriodicityVector _preCadEdgesIDsPeriodicityVector; + + TShapesIDsPeriodicityVector _facesIDsPeriodicityVector; + TEdgesIDsPeriodicityVector _edgesIDsPeriodicityVector; + TVerticesIDsPeriodicityVector _verticesIDsPeriodicityVector; + private: bool compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape); @@ -108,6 +153,13 @@ class BLSURFPlugin_BLSURF: public SMESH_2D_Algo { TopoDS_Shape entryToShape(std::string entry); void createEnforcedVertexOnFace(TopoDS_Shape FaceShape, BLSURFPlugin_Hypothesis::TEnfVertexList enfVertexList); + void createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry faces1, BLSURFPlugin_Hypothesis::TEntry faces2, const char* f_funct = ""); + void createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry edges1, BLSURFPlugin_Hypothesis::TEntry edges2, const char* f_funct = ""); + void createFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry face1, BLSURFPlugin_Hypothesis::TEntry face2); + void createEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry face1, BLSURFPlugin_Hypothesis::TEntry edge1, + BLSURFPlugin_Hypothesis::TEntry face2, BLSURFPlugin_Hypothesis::TEntry edge2, int edge_orientation = 0); + void createVerticesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry edge1, BLSURFPlugin_Hypothesis::TEntry vertex1, + BLSURFPlugin_Hypothesis::TEntry edge2, BLSURFPlugin_Hypothesis::TEntry vertex2); void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, SMDS_MeshNode* node, const TopoDS_Shape& ed); void BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, const TopoDS_Face& face, const gp_Pnt& P, const Standard_Real Tol); diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx index 172b898..2111730 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx @@ -78,7 +78,9 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G _enfVertexEntryEnfVertexMap(GetDefaultEnfVertexEntryEnfVertexMap()), _groupNameNodeIDMap(GetDefaultGroupNameNodeIDMap()), _GMFFileName(GetDefaultGMFFile()), - _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()) + _enforcedInternalVerticesAllFaces(GetDefaultInternalEnforcedVertex()), + _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()), + _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector()) { _name = "BLSURF_Parameters"; _param_algo_dim = 2; @@ -1203,6 +1205,137 @@ void BLSURFPlugin_Hypothesis::SetInternalEnforcedVertexAllFacesGroup(BLSURFPlugi } } +//============================================================================= +BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadFacesPeriodicityVector( + const BLSURFPlugin_Hypothesis* hyp) { + return hyp ? hyp->_GetPreCadFacesPeriodicityVector() : GetDefaultPreCadFacesPeriodicityVector(); +} + +//============================================================================= +BLSURFPlugin_Hypothesis::TPreCadPeriodicityVector BLSURFPlugin_Hypothesis::GetPreCadEdgesPeriodicityVector( + const BLSURFPlugin_Hypothesis* hyp) { + return hyp ? hyp->_GetPreCadEdgesPeriodicityVector() : GetDefaultPreCadEdgesPeriodicityVector(); +} + +//============================================================================= +BLSURFPlugin_Hypothesis::TFacesPeriodicityVector BLSURFPlugin_Hypothesis::GetFacesPeriodicityVector( + const BLSURFPlugin_Hypothesis* hyp) { + return hyp ? hyp->_GetFacesPeriodicityVector() : GetDefaultFacesPeriodicityVector(); +} + +//============================================================================= +BLSURFPlugin_Hypothesis::TEdgesPeriodicityVector BLSURFPlugin_Hypothesis::GetEdgesPeriodicityVector( + const BLSURFPlugin_Hypothesis* hyp){ + return hyp ? hyp->_GetEdgesPeriodicityVector() : GetDefaultEdgesPeriodicityVector(); +} + +//============================================================================= +BLSURFPlugin_Hypothesis::TVerticesPeriodicityVector BLSURFPlugin_Hypothesis::GetVerticesPeriodicityVector( + const BLSURFPlugin_Hypothesis* hyp){ + return hyp ? hyp->_GetVerticesPeriodicityVector() : GetDefaultVerticesPeriodicityVector(); +} + +//======================================================================= +//function : AddPreCadFacesPeriodicity +//======================================================================= +void BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity(TEntry faces1Entry, TEntry faces2Entry, const char* f_funct) { + + MESSAGE("BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity("<< faces1Entry << ", " + << faces2Entry << ", " << f_funct << ")"); + + TPreCadPeriodicity preCadFacesPeriodicity; + preCadFacesPeriodicity.shape1Entry = faces1Entry; + preCadFacesPeriodicity.shape2Entry = faces2Entry; + preCadFacesPeriodicity.f_funct = f_funct; + + _preCadFacesPeriodicityVector.push_back(preCadFacesPeriodicity); + + NotifySubMeshesHypothesisModification(); + + MESSAGE("BLSURFPlugin_Hypothesis::AddPreCadFacesPeriodicity END"); +} + +//======================================================================= +//function : AddPreCadEdgesPeriodicity +//======================================================================= +void BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity(TEntry edges1Entry, TEntry edges2Entry, const char* f_funct) { + + MESSAGE("BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity("<< edges1Entry << ", " + << edges2Entry << ", " << f_funct << ")"); + + TPreCadPeriodicity preCadEdgesPeriodicity; + preCadEdgesPeriodicity.shape1Entry = edges1Entry; + preCadEdgesPeriodicity.shape2Entry = edges2Entry; + preCadEdgesPeriodicity.f_funct = f_funct; + + _preCadEdgesPeriodicityVector.push_back(preCadEdgesPeriodicity); + + NotifySubMeshesHypothesisModification(); + + MESSAGE("BLSURFPlugin_Hypothesis::AddPreCadEdgesPeriodicity END"); +} + +//======================================================================= +//function : AddFacePeriodicity +//======================================================================= +void BLSURFPlugin_Hypothesis::AddFacePeriodicity(TEntry face1Entry, TEntry face2Entry) { + + MESSAGE("BLSURFPlugin_Hypothesis::AddFacePeriodicity("<< face1Entry << ", " + << face2Entry << ")"); + + std::pair< TEntry, TEntry > pairOfFacesEntries = std::make_pair(face1Entry, face2Entry); + + _facesPeriodicityVector.push_back(pairOfFacesEntries); + + NotifySubMeshesHypothesisModification(); + + MESSAGE("BLSURFPlugin_Hypothesis::AddFacePeriodicity END"); +} + + +//======================================================================= +//function : AddEdgePeriodicity +//======================================================================= +void BLSURFPlugin_Hypothesis::AddEdgePeriodicity(TEntry face1Entry, TEntry edge1Entry, TEntry face2Entry, TEntry edge2Entry, int edge_orientation) { + + MESSAGE("BLSURFPlugin_Hypothesis::AddEdgePeriodicity("<< edge1Entry << ", " + << edge2Entry << ")"); + + TEdgePeriodicity edgePeriodicity; + edgePeriodicity.face1Entry = face1Entry; + edgePeriodicity.edge1Entry = edge1Entry; + edgePeriodicity.face2Entry = face2Entry; + edgePeriodicity.edge2Entry = edge2Entry; + edgePeriodicity.edge_orientation = edge_orientation; + + _edgesPeriodicityVector.push_back(edgePeriodicity); + + NotifySubMeshesHypothesisModification(); + + MESSAGE("BLSURFPlugin_Hypothesis::AddEdgePeriodicity END"); +} + +//======================================================================= +//function : AddVertexPeriodicity +//======================================================================= +void BLSURFPlugin_Hypothesis::AddVertexPeriodicity(TEntry edge1Entry, TEntry vertex1Entry, TEntry edge2Entry, TEntry vertex2Entry) { + + MESSAGE("BLSURFPlugin_Hypothesis::AddVertexPeriodicity("<< vertex1Entry << ", " + << vertex2Entry << ")"); + + TVertexPeriodicity vertexPeriodicity; + vertexPeriodicity.edge1Entry = edge1Entry; + vertexPeriodicity.vertex1Entry = vertex1Entry; + vertexPeriodicity.edge2Entry = edge2Entry; + vertexPeriodicity.vertex2Entry = vertex2Entry; + + _verticesPeriodicityVector.push_back(vertexPeriodicity); + + NotifySubMeshesHypothesisModification(); + + MESSAGE("BLSURFPlugin_Hypothesis::AddVertexPeriodicity END"); +} + //============================================================================= std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) { // We must keep at least the same number of arguments when increasing the SALOME version diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx index 885bb90..2ad4eaf 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx @@ -216,6 +216,32 @@ public: } }; + // PreCad Face and Edge periodicity + struct TPreCadPeriodicity { + TEntry shape1Entry; + TEntry shape2Entry; + const char* f_funct; + }; + + // Edge periodicity + struct TEdgePeriodicity { + TEntry face1Entry; + TEntry edge1Entry; + TEntry face2Entry; + TEntry edge2Entry; + int edge_orientation; + }; + + // Vertex periodicity + struct TVertexPeriodicity { + TEntry edge1Entry; + TEntry vertex1Entry; + TEntry edge2Entry; + TEntry vertex2Entry; + }; + + typedef std::pair< TEntry, TEntry > TFacesPeriodicity; + // List of enforced vertices typedef std::set< TEnfVertex*, CompareEnfVertices > TEnfVertexList; @@ -243,7 +269,13 @@ public: typedef std::map< TEnfGroupName , TEnfVertexList > TGroupNameEnfVertexListMap; */ + // Vector of pairs of entries + typedef std::vector< TPreCadPeriodicity > TPreCadPeriodicityVector; + typedef std::vector< TFacesPeriodicity > TFacesPeriodicityVector; + typedef std::vector< TEdgePeriodicity > TEdgesPeriodicityVector; + typedef std::vector< TVertexPeriodicity > TVerticesPeriodicityVector; + bool SetEnforcedVertex(TEntry theFaceEntry, TEnfName theVertexName, TEntry theVertexEntry, TEnfGroupName theGroupName, double x = 0.0, double y = 0.0, double z = 0.0); TEnfVertexList GetEnfVertexList(const TEntry& theFaceEntry) throw (std::invalid_argument); @@ -354,6 +386,33 @@ public: static TEnfVertexGroupNameMap GetDefaultEnfVertexGroupNameMap() { return TEnfVertexGroupNameMap(); } */ + static TPreCadPeriodicityVector GetDefaultPreCadFacesPeriodicityVector() { return TPreCadPeriodicityVector(); } + const TPreCadPeriodicityVector _GetPreCadFacesPeriodicityVector() const { return _preCadFacesPeriodicityVector; } + static TPreCadPeriodicityVector GetPreCadFacesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp); + + static TPreCadPeriodicityVector GetDefaultPreCadEdgesPeriodicityVector() { return TPreCadPeriodicityVector(); } + const TPreCadPeriodicityVector _GetPreCadEdgesPeriodicityVector() const { return _preCadEdgesPeriodicityVector; } + static TPreCadPeriodicityVector GetPreCadEdgesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp); + + static TFacesPeriodicityVector GetDefaultFacesPeriodicityVector() { return TFacesPeriodicityVector(); } + const TFacesPeriodicityVector _GetFacesPeriodicityVector() const { return _facesPeriodicityVector; } + static TFacesPeriodicityVector GetFacesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp); + + static TEdgesPeriodicityVector GetDefaultEdgesPeriodicityVector() { return TEdgesPeriodicityVector(); } + const TEdgesPeriodicityVector _GetEdgesPeriodicityVector() const { return _edgesPeriodicityVector; } + static TEdgesPeriodicityVector GetEdgesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp); + + static TVerticesPeriodicityVector GetDefaultVerticesPeriodicityVector() { return TVerticesPeriodicityVector(); } + const TVerticesPeriodicityVector _GetVerticesPeriodicityVector() const { return _verticesPeriodicityVector; } + static TVerticesPeriodicityVector GetVerticesPeriodicityVector(const BLSURFPlugin_Hypothesis* hyp); + + void AddPreCadFacesPeriodicity(TEntry faces1Entry, TEntry faces2Entry, const char* f_funct); + void AddPreCadEdgesPeriodicity(TEntry edges1Entry, TEntry edges2Entry, const char* f_funct); + + void AddFacePeriodicity(TEntry face1Entry, TEntry face2Entry); + void AddEdgePeriodicity(TEntry face1Entry, TEntry edge1Entry, TEntry face2Entry, TEntry edge2Entry, int edge_orientation = 0); + void AddVertexPeriodicity(TEntry edge1Entry, TEntry vertex1Entry, TEntry edge2Entry, TEntry vertex2Entry); + static double undefinedDouble() { return -1.0; } typedef std::map< std::string, std::string > TOptionValues; @@ -451,6 +510,13 @@ private: bool _enforcedInternalVerticesAllFaces; TEnfGroupName _enforcedInternalVerticesAllFacesGroup; + TPreCadPeriodicityVector _preCadFacesPeriodicityVector; + TPreCadPeriodicityVector _preCadEdgesPeriodicityVector; + + TFacesPeriodicityVector _facesPeriodicityVector; + TEdgesPeriodicityVector _edgesPeriodicityVector; + TVerticesPeriodicityVector _verticesPeriodicityVector; + std::string _GMFFileName; // bool _GMFFileMode; diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx index 496cf40..303c360 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx @@ -2584,6 +2584,328 @@ void BLSURFPlugin_Hypothesis_i::SetInternalEnforcedVertexEntry(const char* theFa */ /////////////////////// +/////////////////////// +// PERIODICITY // +/////////////////////// + + +std::string BLSURFPlugin_Hypothesis_i::ShapeTypeToString(GEOM::shape_type theShapeType) +{ +//enum shape_type { COMPOUND, COMPSOLID, SOLID, SHELL, FACE, WIRE, EDGE, VERTEX, SHAPE /*, __max_shape_type=0xffffffff */ }; + std::map MapShapeTypeToString; + MapShapeTypeToString[GEOM::COMPOUND] = std::string("COMPOUND"); + MapShapeTypeToString[GEOM::COMPSOLID] = std::string("COMPSOLID"); + MapShapeTypeToString[GEOM::SOLID] = std::string("SOLID"); + MapShapeTypeToString[GEOM::SHELL] = std::string("SHELL"); + MapShapeTypeToString[GEOM::FACE] = std::string("FACE"); + MapShapeTypeToString[GEOM::WIRE] = std::string("WIRE"); + MapShapeTypeToString[GEOM::EDGE] = std::string("EDGE"); + MapShapeTypeToString[GEOM::VERTEX] = std::string("VERTEX"); + MapShapeTypeToString[GEOM::SHAPE] = std::string("SHAPE"); + std::string txtShapeType = MapShapeTypeToString[theShapeType]; + return txtShapeType; +} + +void BLSURFPlugin_Hypothesis_i::CheckShapeTypes(GEOM::GEOM_Object_ptr shape, std::vector theShapeTypes) +{ + // Check shape types + bool ok = false; + std::stringstream typesTxt; + for (std::size_t i=0; iGetShapeType() == theShapeType) + ok = true; + typesTxt << ShapeTypeToString(theShapeType); + if (i < theShapeTypes.size()-1 ) + typesTxt << ", "; + } + if (!ok){ + std::stringstream msg; + msg << "shape shape type is not in" << typesTxt; + MESSAGE(msg); + THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(), SALOME::BAD_PARAM); + } +} + +void BLSURFPlugin_Hypothesis_i::CheckShapeType(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType) +{ + // Check shape type + if (shape->GetShapeType() != theShapeType) { + std::stringstream msg; + msg << "shape shape type is not " << ShapeTypeToString(theShapeType); + MESSAGE(msg); + THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(), SALOME::BAD_PARAM); + } +} + +std::string BLSURFPlugin_Hypothesis_i::PublishIfNeeded(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType, std::string prefix) +{ + // Check shape is published in the object browser + string shapeEntry = shape->GetStudyEntry(); + + GEOM::GEOM_Gen_ptr geomGen = SMESH_Gen_i::GetGeomEngine(); + SMESH_Gen_i *smeshGen = SMESH_Gen_i::GetSMESHGen(); + string aName; + + // Publish shape if needed + if (shapeEntry.empty()) { + if (shape->GetShapeType() == theShapeType) + aName = prefix; + aName += shape->GetEntry(); + SALOMEDS::SObject_wrap theSFace1 = geomGen->PublishInStudy(smeshGen->GetCurrentStudy(), NULL, shape, aName.c_str()); + if (!theSFace1->_is_nil()) + shapeEntry = theSFace1->GetID(); + } + if (shapeEntry.empty()) + THROW_SALOME_CORBA_EXCEPTION( "Geom object is not published in study" ,SALOME::BAD_PARAM ); + return shapeEntry; +} + +void BLSURFPlugin_Hypothesis_i::AddPreCadFacesPeriodicity(GEOM::GEOM_Object_ptr faces1, GEOM::GEOM_Object_ptr faces2, const char* f_transf) +throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + + std::vector allowedShapeTypes; + allowedShapeTypes.push_back(GEOM::FACE); + allowedShapeTypes.push_back(GEOM::COMPOUND); + + string prefix1 = "Source_face_"; + CheckShapeTypes(faces1, allowedShapeTypes); + string faces1Entry = PublishIfNeeded(faces1, GEOM::FACE, prefix1); + string prefix2 = "Target_face_"; + CheckShapeTypes(faces2, allowedShapeTypes); + string faces2Entry = PublishIfNeeded(faces2, GEOM::FACE, prefix2); + + string faces2Name = faces2->GetName(); + MESSAGE("IDL : faces1->GetName : " << faces1->GetName()); + MESSAGE("IDL : faces2->GetName : " << faces2->GetName()); + MESSAGE("IDL : AddPreCadFacesPeriodicity( "<< faces1Entry << ", " << faces2Entry << ", " << f_transf << ")"); + try { + AddPreCadFacesPeriodicityEntry(faces1Entry.c_str(), faces2Entry.c_str(), f_transf); + } catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } +} + +void BLSURFPlugin_Hypothesis_i::AddPreCadFacesPeriodicityEntry(const char* faces1Entry, const char* faces2Entry, const char* f_transf) + throw (SALOME::SALOME_Exception) +{ + + ASSERT(myBaseImpl); + + MESSAGE("IDL : AddPreCadFacesPeriodicityEntry(" << faces1Entry << ", " << faces2Entry << ", \"" << f_transf << "\")"); + this->GetImpl()->AddPreCadFacesPeriodicity(faces1Entry, faces2Entry, f_transf); + SMESH::TPythonDump pd; + pd << _this() << ".AddPreCadFacesPeriodicity(" << faces1Entry << ", " << faces2Entry; + if (f_transf != "") + pd << ", \"" << f_transf << "\""; + pd << ")"; + MESSAGE("IDL : AddPreCadFacesPeriodicityEntry END"); +} + +void BLSURFPlugin_Hypothesis_i::AddPreCadEdgesPeriodicity(GEOM::GEOM_Object_ptr edges1, GEOM::GEOM_Object_ptr edges2, const char* f_transf) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + + std::vector allowedShapeTypes; + allowedShapeTypes.push_back(GEOM::EDGE); + allowedShapeTypes.push_back(GEOM::COMPOUND); + + string prefix1 = "Source_edge_"; + CheckShapeTypes(edges1, allowedShapeTypes); + string edges1Entry = PublishIfNeeded(edges1, GEOM::EDGE, prefix1); + string prefix2 = "Target_edge_"; + CheckShapeTypes(edges2, allowedShapeTypes); + string edges2Entry = PublishIfNeeded(edges2, GEOM::EDGE, prefix2); + + string edges2Name = edges2->GetName(); + MESSAGE("IDL : edges1->GetName : " << edges1->GetName()); + MESSAGE("IDL : edges2->GetName : " << edges2->GetName()); + MESSAGE("IDL : AddPreCadEdgesPeriodicity( "<< edges1Entry << ", " << edges2Entry << ", " << f_transf << ")"); + try { + AddPreCadEdgesPeriodicityEntry(edges1Entry.c_str(), edges2Entry.c_str(), f_transf); + } catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } +} + + +void BLSURFPlugin_Hypothesis_i::AddPreCadEdgesPeriodicityEntry(const char* edges1Entry, const char* edges2Entry, const char* f_transf) + throw (SALOME::SALOME_Exception) +{ + + ASSERT(myBaseImpl); + + MESSAGE("IDL : AddPreCadEdgesPeriodicityEntry(" << edges1Entry << ", " << edges2Entry << ", \"" << f_transf << "\")"); + this->GetImpl()->AddPreCadEdgesPeriodicity(edges1Entry, edges2Entry, f_transf); + SMESH::TPythonDump pd; + pd << _this() << ".AddPreCadEdgesPeriodicity(" << edges1Entry << ", " << edges2Entry; + if (f_transf != "") + pd << ", \"" << f_transf << "\""; + pd << ")"; + MESSAGE("IDL : AddPreCadEdgesPeriodicityEntry END"); +} + +void BLSURFPlugin_Hypothesis_i::AddFacePeriodicity(GEOM::GEOM_Object_ptr face1, GEOM::GEOM_Object_ptr face2) + throw (SALOME::SALOME_Exception) +{ + ASSERT(myBaseImpl); + + string prefix1 = "Source_face_"; + CheckShapeType(face1, GEOM::FACE); + string face1Entry = PublishIfNeeded(face1, GEOM::FACE, prefix1); + string prefix2 = "Target_face_"; + CheckShapeType(face2, GEOM::FACE); + string face2Entry = PublishIfNeeded(face2, GEOM::FACE, prefix2); + + MESSAGE("IDL : face1->GetName : " << face1->GetName()); + MESSAGE("IDL : face2->GetName : " << face2->GetName()); + MESSAGE("IDL : AddFacePeriodicity( "<< face1Entry << ", " << face2Entry << ")"); + try { + AddFacePeriodicityEntry(face1Entry.c_str(), face2Entry.c_str()); + } catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + + +} + +void BLSURFPlugin_Hypothesis_i::AddFacePeriodicityEntry(const char* face1Entry, const char* face2Entry) + throw (SALOME::SALOME_Exception){ + + ASSERT(myBaseImpl); + + MESSAGE("IDL : AddFacePeriodicityEntry(" << face1Entry << ", " << face2Entry << ")"); + this->GetImpl()->AddFacePeriodicity(face1Entry, face2Entry); + SMESH::TPythonDump pd; + pd << _this() << ".AddFacePeriodicity(" << face1Entry << ", " << face2Entry << ")"; + MESSAGE("IDL : AddFacePeriodicityEntry END"); +} + + +void BLSURFPlugin_Hypothesis_i::AddEdgePeriodicity(GEOM::GEOM_Object_ptr face1, GEOM::GEOM_Object_ptr edge1, + GEOM::GEOM_Object_ptr face2, GEOM::GEOM_Object_ptr edge2, int edge_orientation) + throw (SALOME::SALOME_Exception){ + ASSERT(myBaseImpl); + + string prefix_face1 = "Source_face_"; + CheckShapeType(face1, GEOM::FACE); + string face1Entry = PublishIfNeeded(face1, GEOM::FACE, prefix_face1); + string prefix_face2 = "Target_face_"; + CheckShapeType(face2, GEOM::FACE); + string face2Entry = PublishIfNeeded(face2, GEOM::FACE, prefix_face2); + + string prefix_edge1 = "Source_edge_"; + CheckShapeType(edge1, GEOM::EDGE); + string edge1Entry = PublishIfNeeded(edge1, GEOM::EDGE, prefix_edge1); + string prefix_edge2 = "Target_edge_"; + CheckShapeType(edge2, GEOM::EDGE); + string edge2Entry = PublishIfNeeded(edge2, GEOM::EDGE, prefix_edge2); + + MESSAGE("IDL : face1->GetName : " << face1->GetName()); + MESSAGE("IDL : edge1->GetName : " << edge1->GetName()); + MESSAGE("IDL : face2->GetName : " << face2->GetName()); + MESSAGE("IDL : edge2->GetName : " << edge2->GetName()); + MESSAGE("IDL : AddEdgePeriodicity( "<< face1Entry << ", " << edge1Entry << ", " << face2Entry << ", " << edge2Entry << ", " << edge_orientation << ")"); + try { + AddEdgePeriodicityEntry(face1Entry.c_str(), edge1Entry.c_str(), face2Entry.c_str(), edge2Entry.c_str(), edge_orientation); + } catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + + +} + +void BLSURFPlugin_Hypothesis_i::AddEdgePeriodicityWithoutFaces(GEOM::GEOM_Object_ptr edge1, + GEOM::GEOM_Object_ptr edge2, int edge_orientation) + throw (SALOME::SALOME_Exception){ + ASSERT(myBaseImpl); + + string face1Entry = ""; + string face2Entry = ""; + + string prefix_edge1 = "Source_edge_"; + CheckShapeType(edge1, GEOM::EDGE); + string edge1Entry = PublishIfNeeded(edge1, GEOM::EDGE, prefix_edge1); + string prefix_edge2 = "Target_edge_"; + CheckShapeType(edge2, GEOM::EDGE); + string edge2Entry = PublishIfNeeded(edge2, GEOM::EDGE, prefix_edge2); + + MESSAGE("IDL : edge1->GetName : " << edge1->GetName()); + MESSAGE("IDL : edge2->GetName : " << edge2->GetName()); + MESSAGE("IDL : AddEdgePeriodicity( "<< face1Entry << ", " << edge1Entry << ", " << face2Entry << ", " << edge2Entry << ", " << edge_orientation << ")"); + try { + AddEdgePeriodicityEntry(face1Entry.c_str(), edge1Entry.c_str(), face2Entry.c_str(), edge2Entry.c_str(), edge_orientation); + } catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + + +} + +void BLSURFPlugin_Hypothesis_i::AddEdgePeriodicityEntry(const char* face1Entry, const char* edge1Entry, const char* face2Entry, const char* edge2Entry, const int edge_orientation) + throw (SALOME::SALOME_Exception){ + + ASSERT(myBaseImpl); + + MESSAGE("IDL : AddEdgePeriodicityEntry(" << face1Entry << ", " << edge1Entry << ", " << face2Entry << ", " << edge2Entry << ", " << edge_orientation << ")"); + this->GetImpl()->AddEdgePeriodicity(face1Entry, edge1Entry, face2Entry, edge2Entry, edge_orientation); + SMESH::TPythonDump pd; + if (face1Entry) + pd << _this() << ".AddEdgePeriodicity(" << face1Entry << ", " << edge1Entry << ", " << face2Entry << ", " << edge2Entry << ", " << edge_orientation <<")"; + else + pd << _this() << ".AddEdgePeriodicityWithoutFaces(" << edge1Entry << ", " << edge2Entry << ", " << edge_orientation <<")"; + MESSAGE("IDL : AddEdgePeriodicityEntry END"); +} + +void BLSURFPlugin_Hypothesis_i::AddVertexPeriodicity(GEOM::GEOM_Object_ptr edge1, GEOM::GEOM_Object_ptr vertex1, + GEOM::GEOM_Object_ptr edge2, GEOM::GEOM_Object_ptr vertex2) + throw (SALOME::SALOME_Exception){ + ASSERT(myBaseImpl); + + string prefix_edge1 = "Source_edge_"; + CheckShapeType(edge1, GEOM::EDGE); + string edge1Entry = PublishIfNeeded(edge1, GEOM::EDGE, prefix_edge1); + string prefix_edge2 = "Target_edge_"; + CheckShapeType(edge2, GEOM::EDGE); + string edge2Entry = PublishIfNeeded(edge2, GEOM::EDGE, prefix_edge2); + + string prefix_vertex1 = "Source_vertex_"; + CheckShapeType(vertex1, GEOM::VERTEX); + string vertex1Entry = PublishIfNeeded(vertex1, GEOM::VERTEX, prefix_vertex1); + string prefix_vertex2 = "Target_vertex_"; + CheckShapeType(vertex2, GEOM::VERTEX); + string vertex2Entry = PublishIfNeeded(vertex2, GEOM::VERTEX, prefix_vertex2); + + MESSAGE("IDL : edge1->GetName : " << edge1->GetName()); + MESSAGE("IDL : vertex1->GetName : " << vertex1->GetName()); + MESSAGE("IDL : edge2->GetName : " << edge2->GetName()); + MESSAGE("IDL : vertex2->GetName : " << vertex2->GetName()); + MESSAGE("IDL : AddVertexPeriodicity( "<< edge1Entry << ", " << vertex1Entry << ", " << edge2Entry << ", " << vertex2Entry << ")"); + try { + AddVertexPeriodicityEntry(edge1Entry.c_str(), vertex1Entry.c_str(), edge2Entry.c_str(), vertex2Entry.c_str()); + } catch (SALOME_Exception& ex) { + THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM ); + } + + +} + +void BLSURFPlugin_Hypothesis_i::AddVertexPeriodicityEntry(const char* edge1Entry, const char* vertex1Entry, const char* edge2Entry, const char* vertex2Entry) + throw (SALOME::SALOME_Exception){ + + ASSERT(myBaseImpl); + + MESSAGE("IDL : AddVertexPeriodicityEntry(" << edge1Entry << ", " << vertex1Entry << ", " << edge2Entry << ", " << vertex2Entry << ")"); + this->GetImpl()->AddVertexPeriodicity(edge1Entry, vertex1Entry, edge2Entry, vertex2Entry); + SMESH::TPythonDump pd; + pd << _this() << ".AddVertexPeriodicity(" << edge1Entry << ", " << vertex1Entry << ", " << edge2Entry << ", " << vertex2Entry << ")"; + MESSAGE("IDL : AddVertexPeriodicityEntry END"); +} + //================================================================================ /*! diff --git a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx index 62cb657..fe46de2 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx @@ -254,6 +254,50 @@ public: // CORBA::Boolean GetInternalEnforcedVertex(GEOM::GEOM_Object_ptr theFace) throw (SALOME::SALOME_Exception); // CORBA::Boolean GetInternalEnforcedVertexEntry(const char* theFaceEntry) throw (SALOME::SALOME_Exception); + /////////////////////// + // PERIODICITY // + /////////////////////// + + std::string ShapeTypeToString(GEOM::shape_type theShapeType); + void CheckShapeType(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType); + void CheckShapeTypes(GEOM::GEOM_Object_ptr shape, std::vector theShapeTypes); + std::string PublishIfNeeded(GEOM::GEOM_Object_ptr shape, GEOM::shape_type theShapeType, std::string prefix); + + void AddPreCadFacesPeriodicity(GEOM::GEOM_Object_ptr faces1, GEOM::GEOM_Object_ptr faces2, const char* f_transf = "") + throw (SALOME::SALOME_Exception); + + void AddPreCadFacesPeriodicityEntry(const char* faces1Entry, const char* faces2Entry, const char* f_transf = "") + throw (SALOME::SALOME_Exception); + + void AddPreCadEdgesPeriodicity(GEOM::GEOM_Object_ptr edges1, GEOM::GEOM_Object_ptr edges2, const char* f_transf = "") + throw (SALOME::SALOME_Exception); + + void AddPreCadEdgesPeriodicityEntry(const char* edges1Entry, const char* edges2Entry, const char* f_transf = "") + throw (SALOME::SALOME_Exception); + + void AddFacePeriodicity(GEOM::GEOM_Object_ptr face1, GEOM::GEOM_Object_ptr face2) + throw (SALOME::SALOME_Exception); + + void AddFacePeriodicityEntry(const char* face1Entry, const char* face2Entry) + throw (SALOME::SALOME_Exception); + + void AddEdgePeriodicity(GEOM::GEOM_Object_ptr face1, GEOM::GEOM_Object_ptr edge1, + GEOM::GEOM_Object_ptr face2, GEOM::GEOM_Object_ptr edge2, int edge_orientation = 0) + throw (SALOME::SALOME_Exception); + + void AddEdgePeriodicityWithoutFaces(GEOM::GEOM_Object_ptr edge1, GEOM::GEOM_Object_ptr edge2, int edge_orientation = 0) + throw (SALOME::SALOME_Exception); + + void AddEdgePeriodicityEntry(const char* face1Entry, const char* edge1Entry, const char* face2Entry, const char* edge2Entry, int edge_orientation = 0) + throw (SALOME::SALOME_Exception); + + void AddVertexPeriodicity(GEOM::GEOM_Object_ptr edge1, GEOM::GEOM_Object_ptr vertex1, + GEOM::GEOM_Object_ptr edge2, GEOM::GEOM_Object_ptr vertex2) + throw (SALOME::SALOME_Exception); + + void AddVertexPeriodicityEntry(const char* edge1Entry, const char* vertex1Entry, const char* edge2Entry, const char* vertex2Entry) + throw (SALOME::SALOME_Exception); + /////////////////////// /*! -- 2.39.2