From: eap Date: Mon, 28 Dec 2009 07:41:33 +0000 (+0000) Subject: 0020081: EDF 886 GEOM : GetShapesOnCylinderWithLocation function in TUI X-Git-Tag: V6_0_0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ec1c5fd3a4cdefe6fa0f6d33fd1b6f1821eec9eb;p=modules%2Fgeom.git 0020081: EDF 886 GEOM : GetShapesOnCylinderWithLocation function in TUI + ListOfGO GetShapesOnCylinderWithLocation (in GEOM_Object theShape, --- diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 978cde0d2..0763fb493 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -1516,6 +1516,25 @@ module GEOM in double theRadius, in shape_state theState); + /*! + * Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively + * the specified cylinder by the certain way, defined through \a theState parameter. + * \param theShape Shape to find sub-shapes of. + * \param theShapeType Type of sub-shapes to be retrieved. + * \param theAxis Vector (or line, or linear edge), specifying + * axis of the cylinder to find shapes on. + * \param thePnt Point specifying location of the bottom of the cylinder. + * \param theRadius Radius of the cylinder to find shapes on. + * \param theState The state of the subshapes to find. + * \return List of all found sub-shapes. + */ + ListOfGO GetShapesOnCylinderWithLocation (in GEOM_Object theShape, + in long theShapeType, + in GEOM_Object theAxis, + in GEOM_Object thePnt, + in double theRadius, + in shape_state theState); + /*! * Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively * the specified sphere by the certain way, defined through \a theState parameter. @@ -1601,6 +1620,25 @@ module GEOM in double theRadius, in shape_state theState); + /*! + * Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively + * the specified cylinder by the certain way, defined through \a theState parameter. + * \param theShape Shape to find sub-shapes of. + * \param theShapeType Type of sub-shapes to be retrieved. + * \param theAxis Vector (or line, or linear edge), specifying + * axis of the cylinder to find shapes on. + * \param thePnt Point specifying location of the bottom of the cylinder. + * \param theRadius Radius of the cylinder to find shapes on. + * \param theState The state of the subshapes to find. + * \return List of IDs all found sub-shapes. + */ + ListOfLong GetShapesOnCylinderWithLocationIDs (in GEOM_Object theShape, + in long theShapeType, + in GEOM_Object theAxis, + in GEOM_Object thePnt, + in double theRadius, + in shape_state theState); + /*! * Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively * the specified sphere by the certain way, defined through \a theState parameter. diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index ecfdffee7..7e247e126 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -109,12 +109,13 @@ #include #include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include #include @@ -2153,7 +2154,7 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlan gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2)); if (aVec.Magnitude() < Precision::Confusion()) { - SetErrorCode("Vector with null magnitude given"); + SetErrorCode("Vector with null magnitude given"); return NULL; } Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec); @@ -2231,6 +2232,77 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnCyli return aSeq; } +//============================================================================= +/*! + * GetShapesOnCylinderWithLocation + */ +//============================================================================= +Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnCylinderWithLocation + (const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + const Handle(GEOM_Object)& theAxis, + const Handle(GEOM_Object)& thePnt, + const Standard_Real theRadius, + const GEOMAlgo_State theState) +{ + SetErrorCode(KO); + + if (theShape.IsNull() || theAxis.IsNull() || thePnt.IsNull()) return NULL; + + TopoDS_Shape aShape = theShape->GetValue(); + TopoDS_Shape anAxis = theAxis->GetValue(); + TopoDS_Shape aPnt = thePnt->GetValue(); + + if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return NULL; + + if (aPnt.ShapeType() != TopAbs_VERTEX ) + { + SetErrorCode("Bottom location point must be vertex"); + return NULL; + } + + TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType); + if ( !checkTypeShapesOn( aShapeType )) + return NULL; + + // Create a cylinder surface + Handle(Geom_Surface) aCylinder = makeCylinder( anAxis, theRadius ); + if ( aCylinder.IsNull() ) + return NULL; + + // translate the surface + Handle(Geom_CylindricalSurface) aCylSurface = + Handle(Geom_CylindricalSurface)::DownCast( aCylinder ); + if ( aCylSurface.IsNull() ) + { + SetErrorCode("Unexpected surface type instead of Geom_CylindricalSurface"); + return NULL; + } + gp_Pnt fromLoc = aCylSurface->Cylinder().Location(); + gp_Pnt toLoc = BRep_Tool::Pnt( TopoDS::Vertex( aPnt )); + aCylinder->Translate( fromLoc, toLoc ); + + // Find objects + TCollection_AsciiString anAsciiList; + Handle(TColStd_HSequenceOfTransient) aSeq; + aSeq = getShapesOnSurface( aCylinder, theShape, aShapeType, theState, anAsciiList ); + if ( aSeq.IsNull() || aSeq->Length() == 0 ) + return NULL; + + // Make a Python command + + Handle(GEOM_Object) anObj = Handle(GEOM_Object)::DownCast( aSeq->Value( 1 )); + Handle(GEOM_Function) aFunction = anObj->GetLastFunction(); + + GEOM::TPythonDump(aFunction) + << "[" << anAsciiList.ToCString() + << "] = geompy.GetShapesOnCylinderWithLocation(" << theShape << ", " << aShapeType << ", " + << theAxis << ", " << thePnt << ", " << theRadius << ", " << theState << ")"; + + SetErrorCode(OK); + return aSeq; +} + //============================================================================= /*! * GetShapesOnSphere @@ -2443,6 +2515,74 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnCylind return aSeq; } +//============================================================================= +/*! + * GetShapesOnCylinderWithLocationIDs + */ +//============================================================================= +Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnCylinderWithLocationIDs + (const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + const Handle(GEOM_Object)& theAxis, + const Handle(GEOM_Object)& thePnt, + const Standard_Real theRadius, + const GEOMAlgo_State theState) +{ + SetErrorCode(KO); + + if (theShape.IsNull() || theAxis.IsNull() || thePnt.IsNull()) return NULL; + + TopoDS_Shape aShape = theShape->GetValue(); + TopoDS_Shape anAxis = theAxis->GetValue(); + TopoDS_Shape aPnt = thePnt->GetValue(); + + if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return NULL; + + if (aPnt.ShapeType() != TopAbs_VERTEX ) + { + SetErrorCode("Bottom location point must be vertex"); + return NULL; + } + + TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType); + if ( !checkTypeShapesOn( aShapeType )) + return NULL; + + // Create a cylinder surface + Handle(Geom_Surface) aCylinder = makeCylinder( anAxis, theRadius ); + if ( aCylinder.IsNull() ) + return NULL; + + // translate the surface + Handle(Geom_CylindricalSurface) aCylSurface = + Handle(Geom_CylindricalSurface)::DownCast( aCylinder ); + if ( aCylSurface.IsNull() ) + { + SetErrorCode("Unexpected surface type instead of Geom_CylindricalSurface"); + return NULL; + } + gp_Pnt fromLoc = aCylSurface->Cylinder().Location(); + gp_Pnt toLoc = BRep_Tool::Pnt( TopoDS::Vertex( aPnt )); + aCylinder->Translate( fromLoc, toLoc ); + + // Find object IDs + Handle(TColStd_HSequenceOfInteger) aSeq; + aSeq = getShapesOnSurfaceIDs( aCylinder, aShape, aShapeType, theState ); + + // The GetShapesOnCylinder() doesn't change object so no new function is required. + Handle(GEOM_Function) aFunction = + GEOM::GetCreatedLast(theShape, GEOM::GetCreatedLast(thePnt,theAxis))->GetLastFunction(); + + // Make a Python command + GEOM::TPythonDump(aFunction, /*append=*/true) + << "listShapesOnCylinder = geompy.GetShapesOnCylinderWithLocationIDs" + << "(" << theShape << ", " << aShapeType << ", " << theAxis << ", " + << thePnt << ", " << theRadius << ", " << theState << ")"; + + SetErrorCode(OK); + return aSeq; +} + //============================================================================= /*! * GetShapesOnSphereIDs diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index 859fb6ead..27da52b1f 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -134,6 +134,14 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations const Standard_Real theRadius, const GEOMAlgo_State theState); + Standard_EXPORT Handle(TColStd_HSequenceOfTransient) + GetShapesOnCylinderWithLocation (const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + const Handle(GEOM_Object)& theAxis, + const Handle(GEOM_Object)& thePnt, + const Standard_Real theRadius, + const GEOMAlgo_State theState); + Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnSphere (const Handle(GEOM_Object)& theShape, const Standard_Integer theShapeType, @@ -161,6 +169,14 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations const Standard_Real theRadius, const GEOMAlgo_State theState); + Standard_EXPORT Handle(TColStd_HSequenceOfInteger) + GetShapesOnCylinderWithLocationIDs (const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + const Handle(GEOM_Object)& theAxis, + const Handle(GEOM_Object)& thePnt, + const Standard_Real theRadius, + const GEOMAlgo_State theState); + Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetShapesOnSphereIDs (const Handle(GEOM_Object)& theShape, const Standard_Integer theShapeType, diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index 7013c56fd..3681742ca 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -809,6 +809,45 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinder return aSeq._retn(); } +//============================================================================= +/*! + * GetShapesOnCylinderWithLocation + */ +//============================================================================= +GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnCylinderWithLocation + (GEOM::GEOM_Object_ptr theShape, + const CORBA::Long theShapeType, + GEOM::GEOM_Object_ptr theAxis, + GEOM::GEOM_Object_ptr thePnt, + const CORBA::Double theRadius, + const GEOM::shape_state theState) +{ + GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference objects + Handle(GEOM_Object) aShape = GetObjectImpl(theShape); + Handle(GEOM_Object) anAxis = GetObjectImpl(theAxis); + Handle(GEOM_Object) aPnt = GetObjectImpl(thePnt); + + if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return aSeq._retn(); + + //Get Shapes On Cylinder + Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnCylinderWithLocation + (aShape, theShapeType, anAxis, aPnt, theRadius, ShapeState(theState)); + if (!GetOperations()->IsDone() || aHSeq.IsNull()) + return aSeq._retn(); + + Standard_Integer aLength = aHSeq->Length(); + aSeq->length(aLength); + for (Standard_Integer i = 1; i <= aLength; i++) + aSeq[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aHSeq->Value(i))); + + return aSeq._retn(); +} + //============================================================================= /*! * GetShapesOnSphere @@ -1007,6 +1046,45 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderIDs return aSeq._retn(); } +//============================================================================= +/*! + * GetShapesOnCylinderWithLocationIDs + */ +//============================================================================= +GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnCylinderWithLocationIDs + (GEOM::GEOM_Object_ptr theShape, + const CORBA::Long theShapeType, + GEOM::GEOM_Object_ptr theAxis, + GEOM::GEOM_Object_ptr thePnt, + const CORBA::Double theRadius, + const GEOM::shape_state theState) +{ + GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference objects + Handle(GEOM_Object) aShape = GetObjectImpl(theShape); + Handle(GEOM_Object) anAxis = GetObjectImpl(theAxis); + Handle(GEOM_Object) aPnt = GetObjectImpl(thePnt); + + if (aShape.IsNull() || anAxis.IsNull() || aPnt.IsNull()) return aSeq._retn(); + + //Get Shapes On Cylinder + Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnCylinderWithLocationIDs + (aShape, theShapeType, anAxis, aPnt, theRadius, ShapeState(theState)); + if (!GetOperations()->IsDone() || aHSeq.IsNull()) + return aSeq._retn(); + + Standard_Integer aLength = aHSeq->Length(); + aSeq->length(aLength); + for (Standard_Integer i = 1; i <= aLength; i++) + aSeq[i-1] = aHSeq->Value(i); + + return aSeq._retn(); +} + //============================================================================= /*! * GetShapesOnSphereIDs diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.hh b/src/GEOM_I/GEOM_IShapesOperations_i.hh index 61747cc36..acc80263f 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.hh +++ b/src/GEOM_I/GEOM_IShapesOperations_i.hh @@ -124,6 +124,13 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i : CORBA::Double theRadius, GEOM::shape_state theState); + GEOM::ListOfGO* GetShapesOnCylinderWithLocation (GEOM::GEOM_Object_ptr theShape, + CORBA::Long theShapeType, + GEOM::GEOM_Object_ptr theAxis, + GEOM::GEOM_Object_ptr thePnt, + CORBA::Double theRadius, + GEOM::shape_state theState); + GEOM::ListOfGO* GetShapesOnSphere (GEOM::GEOM_Object_ptr theShape, CORBA::Long theShapeType, GEOM::GEOM_Object_ptr theCenter, @@ -155,6 +162,13 @@ class GEOM_I_EXPORT GEOM_IShapesOperations_i : CORBA::Double theRadius, GEOM::shape_state theState); + GEOM::ListOfLong* GetShapesOnCylinderWithLocationIDs (GEOM::GEOM_Object_ptr theShape, + CORBA::Long theShapeType, + GEOM::GEOM_Object_ptr theAxis, + GEOM::GEOM_Object_ptr thePnt, + CORBA::Double theRadius, + GEOM::shape_state theState); + GEOM::ListOfLong* GetShapesOnSphereIDs (GEOM::GEOM_Object_ptr theShape, CORBA::Long theShapeType, GEOM::GEOM_Object_ptr theCenter, diff --git a/src/GEOM_SWIG/GEOM_TestOthers.py b/src/GEOM_SWIG/GEOM_TestOthers.py index fb8c18bf8..dc3ac505d 100644 --- a/src/GEOM_SWIG/GEOM_TestOthers.py +++ b/src/GEOM_SWIG/GEOM_TestOthers.py @@ -551,6 +551,19 @@ def TestOtherOperations (geompy, math): geompy.UnionIDs(edges_in, edges_in_cyl_ids) geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)") + # GetShapesOnCylinderWithLocation + edges_out_cyl = geompy.GetShapesOnCylinderWithLocation(blocksComp, geompy.ShapeType["EDGE"], + vy, 55, geompy.GEOM.ST_OUT) + for edge_i in edges_out_cyl: + geompy.addToStudy(edge_i, "Edge out of Cylinder (axis = (0, 1, 0), r = 55)") + + # GetShapesOnCylinderIDs + edges_in_cyl_ids = geompy.GetShapesOnCylinderIDs(blocksComp, geompy.ShapeType["EDGE"], + vy, 80, geompy.GEOM.ST_IN) + edges_in = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"]) + geompy.UnionIDs(edges_in, edges_in_cyl_ids) + geompy.addToStudy(edges_in, "Group of edges inside Cylinder (axis = (0, 1, 0), r = 55)") + # GetShapesOnSphere vertices_on_sph = geompy.GetShapesOnSphere(blocksComp, geompy.ShapeType["VERTEX"], p0, 100, geompy.GEOM.ST_ON) diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index c8ef92793..4e05cc58d 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -1774,6 +1774,34 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("GetShapesOnCylinderIDs", self.ShapesOp) return aList + ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively + # the specified cylinder by the certain way, defined through \a theState parameter. + # @param theShape Shape to find sub-shapes of. + # @param theShapeType Type of sub-shapes to be retrieved. + # @param theAxis Vector (or line, or linear edge), specifying + # axis of the cylinder to find shapes on. + # @param thePnt Point specifying location of the bottom of the cylinder. + # @param theRadius Radius of the cylinder to find shapes on. + # @param theState The state of the subshapes to find. It can be one of + # ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN. + # @return List of all found sub-shapes. + # + # @ref swig_GetShapesOnCylinderWithLocation "Example" + def GetShapesOnCylinderWithLocation(self, theShape, theShapeType, theAxis, thePnt, theRadius, theState): + # Example: see GEOM_TestOthers.py + aList = self.ShapesOp.GetShapesOnCylinderWithLocation(theShape, theShapeType, theAxis, thePnt, theRadius, theState) + RaiseIfFailed("GetShapesOnCylinderWithLocation", self.ShapesOp) + return aList + + ## Works like the above method, but returns list of sub-shapes indices + # + # @ref swig_GetShapesOnCylinderWithLocationIDs "Example" + def GetShapesOnCylinderWithLocationIDs(self, theShape, theShapeType, theAxis, thePnt, theRadius, theState): + # Example: see GEOM_TestOthers.py + aList = self.ShapesOp.GetShapesOnCylinderWithLocationIDs(theShape, theShapeType, theAxis, thePnt, theRadius, theState) + RaiseIfFailed("GetShapesOnCylinderWithLocationIDs", self.ShapesOp) + return aList + ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively # the specified sphere by the certain way, defined through \a theState parameter. # @param theShape Shape to find sub-shapes of.