From: jfa Date: Tue, 28 Dec 2004 13:57:11 +0000 (+0000) Subject: PAL7508: Complete implementation of GetShapesOn*() methods X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e4a1315bddca5810291cf6958ab92d2c5e65c1ec;p=modules%2Fgeom.git PAL7508: Complete implementation of GetShapesOn*() methods --- diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index e4b31bfae..71ff1b32d 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -27,8 +27,12 @@ using namespace std; #include #include +#include + #include #include +#include +#include #include #include @@ -39,6 +43,7 @@ using namespace std; #include #include #include +#include #include #include #include @@ -48,6 +53,9 @@ using namespace std; #include #include #include +#include + +#include #include #include @@ -1061,11 +1069,30 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnPlane break; case TopAbs_EDGE: { - TopoDS_Edge anE = TopoDS::Edge(aSS); - Standard_Real pf, pl; - Handle(Geom_Curve) cur_curve = BRep_Tool::Curve(anE, pf, pl); - if (true) { - listSS.Append(aSS); + TopoDS_Edge anEdge = TopoDS::Edge(aSS); + Standard_Real f, l; + Handle(Geom2d_Curve) PC; + Handle(Geom_Surface) cur_surf; + TopLoc_Location L; + Standard_Integer i = 0; + + // iterate on the surfaces of the edge + while (Standard_True) { + i++; + BRep_Tool::CurveOnSurface(anEdge, PC , cur_surf, L, f, l, i); + if (cur_surf.IsNull()) break; + + Handle(Geom_Plane) cur_pln = Handle(Geom_Plane)::DownCast(cur_surf); + if (!cur_pln.IsNull()) { + const gp_Ax3 cur_pos = cur_pln->Position(); + const gp_Pnt cur_loc = cur_pos.Location(); + const gp_Dir cur_dir = cur_pos.Direction(); + gp_Vec vecToLoc (cur_loc, loc); + if (vecToLoc.IsNormal(dir, Precision::Angular()) && + cur_dir.IsParallel(dir, Precision::Angular())) { + listSS.Append(aSS); + } + } } } break; @@ -1092,6 +1119,11 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnPlane } } + if (listSS.Extent() < 1) { + SetErrorCode("Not a single sub-shape of the requested type found on the given plane"); + return NULL; + } + //Fill array of indices TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(aShape, anIndices); @@ -1195,11 +1227,33 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnCylinder break; case TopAbs_EDGE: { - TopoDS_Edge anE = TopoDS::Edge(aSS); - Standard_Real pf, pl; - Handle(Geom_Curve) cur_curve = BRep_Tool::Curve(anE, pf, pl); - if (true) { - listSS.Append(aSS); + TopoDS_Edge anEdge = TopoDS::Edge(aSS); + Standard_Real f, l; + Handle(Geom2d_Curve) PC; + Handle(Geom_Surface) cur_surf; + TopLoc_Location L; + Standard_Integer i = 0; + + // iterate on the surfaces of the edge + while (Standard_True) { + i++; + BRep_Tool::CurveOnSurface(anEdge, PC , cur_surf, L, f, l, i); + if (cur_surf.IsNull()) break; + + Handle(Geom_CylindricalSurface) cur_cyl = + Handle(Geom_CylindricalSurface)::DownCast(cur_surf); + if (!cur_cyl.IsNull()) { + const gp_Ax3 cur_pos = cur_cyl->Position(); + const gp_Pnt cur_loc = cur_pos.Location(); + const gp_Dir cur_dir = cur_pos.Direction(); + const Standard_Real cur_rad = cur_cyl->Radius(); + gp_Vec vecToLoc (cur_loc, loc); + if (vecToLoc.IsParallel(dir, Precision::Angular()) && + cur_dir.IsParallel(dir, Precision::Angular()) && + Abs(cur_rad - theRadius) < Precision::Confusion()) { + listSS.Append(aSS); + } + } } } break; @@ -1229,6 +1283,11 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnCylinder } } + if (listSS.Extent() < 1) { + SetErrorCode("Not a single sub-shape of the requested type found on the given cylinder"); + return NULL; + } + //Fill array of indices TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(aShape, anIndices); @@ -1319,11 +1378,30 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnSphere break; case TopAbs_EDGE: { - TopoDS_Edge anE = TopoDS::Edge(aSS); - Standard_Real pf, pl; - Handle(Geom_Curve) cur_curve = BRep_Tool::Curve(anE, pf, pl); - if (true) { - listSS.Append(aSS); + TopoDS_Edge anEdge = TopoDS::Edge(aSS); + Standard_Real f, l; + Handle(Geom2d_Curve) PC; + Handle(Geom_Surface) cur_surf; + TopLoc_Location L; + Standard_Integer i = 0; + + // iterate on the surfaces of the edge + while (Standard_True) { + i++; + BRep_Tool::CurveOnSurface(anEdge, PC , cur_surf, L, f, l, i); + if (cur_surf.IsNull()) break; + + Handle(Geom_SphericalSurface) cur_sph = + Handle(Geom_SphericalSurface)::DownCast(cur_surf); + if (!cur_sph.IsNull()) { + const gp_Ax3 cur_pos = cur_sph->Position(); + const gp_Pnt cur_loc = cur_pos.Location(); + const Standard_Real cur_rad = cur_sph->Radius(); + if (cur_loc.Distance(aC) < Precision::Confusion() && + Abs(cur_rad - theRadius) < Precision::Confusion()) { + listSS.Append(aSS); + } + } } } break; @@ -1350,6 +1428,11 @@ Handle(GEOM_Object) GEOMImpl_IShapesOperations::GetShapesOnSphere } } + if (listSS.Extent() < 1) { + SetErrorCode("Not a single sub-shape of the requested type found on the given sphere"); + return NULL; + } + //Fill array of indices TopTools_IndexedMapOfShape anIndices; TopExp::MapShapes(aShape, anIndices);