From: skl Date: Thu, 7 Dec 2006 10:42:47 +0000 (+0000) Subject: Add new command GetShapesOnBox. X-Git-Tag: V3_2_4pre1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa13d2abfd59ac43b3529ab5aefdd8018eb4f55e;p=modules%2Fgeom.git Add new command GetShapesOnBox. --- diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 43904c69f..b617b3c0f 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -1240,6 +1240,32 @@ module GEOM in GEOM_Object theBottomRigthPoint, in shape_state theState); + /*! + * \brief Find subshapes complying with given status + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \return List of IDs of all found sub-shapes. + */ + ListOfLong GetShapesOnBoxIDs (in GEOM_Object theBox, + in GEOM_Object theShape, + in long theShapeType, + in shape_state theState); + + /*! + * \brief Find subshapes complying with given status + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \return List of all found sub-shapes. + */ + ListOfGO GetShapesOnBox (in GEOM_Object theBox, + in GEOM_Object theShape, + in long theShapeType, + in shape_state theState); + /*! * Get sub-shape(s) of theShapeWhere, which are * coincident with \a theShapeWhat or could be a part of it. diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx index 6262b41fa..199f2c0c5 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.cxx @@ -39,6 +39,9 @@ #include "GEOMAlgo_FinderShapeOn1.hxx" #include "GEOMAlgo_FinderShapeOnQuad.hxx" +#include "GEOMAlgo_FinderShapeOn2.hxx" +#include "GEOMAlgo_ClsfBox.hxx" +//#include "GEOMAlgo_ClsfSurf.hxx" #include "utilities.h" #include "OpUtil.hxx" @@ -1223,6 +1226,169 @@ Handle(Geom_Surface) GEOMImpl_IShapesOperations::makeCylinder(const TopoDS_Shape } +//======================================================================= +//function : getShapesOnBoxIDs + /*! + * \brief Find IDs of subshapes complying with given status about surface + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes + */ +//======================================================================= + +Handle(TColStd_HSequenceOfInteger) + GEOMImpl_IShapesOperations::getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox, + const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + GEOMAlgo_State theState) +{ + Handle(TColStd_HSequenceOfInteger) aSeqOfIDs; + + TopoDS_Shape aBox = theBox->GetValue(); + TopoDS_Shape aShape = theShape->GetValue(); + + // Call algo + GEOMAlgo_FinderShapeOn2 aFinder; + Standard_Real aTol = 0.0001; // default value + + Handle(GEOMAlgo_ClsfBox) aClsfBox = new GEOMAlgo_ClsfBox; + aClsfBox->SetBox(aBox); + + aFinder.SetShape(aShape); + aFinder.SetTolerance(aTol); + aFinder.SetClsf(aClsfBox); + aFinder.SetShapeType( (TopAbs_ShapeEnum)theShapeType ); + aFinder.SetState(theState); + aFinder.Perform(); + + // Interprete results + Standard_Integer iErr = aFinder.ErrorStatus(); + // the detailed description of error codes is in GEOMAlgo_FinderShapeOn1.cxx + if (iErr) { + MESSAGE(" iErr : " << iErr); + TCollection_AsciiString aMsg (" iErr : "); + aMsg += TCollection_AsciiString(iErr); + SetErrorCode(aMsg); + return aSeqOfIDs; + } + Standard_Integer iWrn = aFinder.WarningStatus(); + // the detailed description of warning codes is in GEOMAlgo_FinderShapeOn1.cxx + if (iWrn) { + MESSAGE(" *** iWrn : " << iWrn); + } + + const TopTools_ListOfShape& listSS = aFinder.Shapes(); // the result + + if (listSS.Extent() < 1) { + SetErrorCode("Not a single sub-shape of the requested type found on the given surface"); + return aSeqOfIDs; + } + + // Fill sequence of object IDs + aSeqOfIDs = new TColStd_HSequenceOfInteger; + + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(aShape, anIndices); + + TopTools_ListIteratorOfListOfShape itSub (listSS); + for (int index = 1; itSub.More(); itSub.Next(), ++index) { + int id = anIndices.FindIndex(itSub.Value()); + aSeqOfIDs->Append(id); + } + + return aSeqOfIDs; +} + + +//======================================================================= +//function : GetShapesOnBoxIDs +/*! + * \brief Find subshapes complying with given status about surface + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes + */ +//======================================================================= + +Handle(TColStd_HSequenceOfInteger) + GEOMImpl_IShapesOperations::GetShapesOnBoxIDs(const Handle(GEOM_Object)& theBox, + const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + GEOMAlgo_State theState) +{ + // Find subshapes ids + Handle(TColStd_HSequenceOfInteger) aSeqOfIDs = + getShapesOnBoxIDs (theBox, theShape, theShapeType, theState); + if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 ) + return NULL; + + // The GetShapesOnBox() doesn't change object so no new function is required. + Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theBox)->GetLastFunction(); + + // Make a Python command + GEOM::TPythonDump(aFunction) + << "listShapesOnBoxIDs = geompy.GetShapesOnQuadrangleIDs(" + << theBox << ", " + << theShape << ", " + << TopAbs_ShapeEnum(theShapeType) << ", " + << theState << ")"; + + SetErrorCode(OK); + return aSeqOfIDs; +} + +//======================================================================= +//function : GetShapesOnBox +/*! + * \brief Find subshapes complying with given status about surface + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \retval Handle(TColStd_HSequenceOfTransient) - found subshapes + */ +//======================================================================= + +Handle(TColStd_HSequenceOfTransient) + GEOMImpl_IShapesOperations::GetShapesOnBox(const Handle(GEOM_Object)& theBox, + const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + GEOMAlgo_State theState) +{ + // Find subshapes ids + Handle(TColStd_HSequenceOfInteger) aSeqOfIDs = + getShapesOnBoxIDs (theBox, theShape, theShapeType, theState); + if ( aSeqOfIDs.IsNull() || aSeqOfIDs->Length() == 0 ) + return NULL; + + // Find objects by indices + TCollection_AsciiString anAsciiList; + Handle(TColStd_HSequenceOfTransient) aSeq; + aSeq = getObjectsShapesOn( theShape, aSeqOfIDs, anAsciiList ); + if ( aSeq.IsNull() || aSeq->IsEmpty() ) + 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.GetShapesOnBox(" + << theBox << ", " + << theShape << ", " + << TopAbs_ShapeEnum(theShapeType) << ", " + << theState << ")"; + + SetErrorCode(OK); + return aSeq; +} + + //======================================================================= //function : getShapesOnSurfaceIDs /*! diff --git a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx index 546f7867f..09468c75c 100644 --- a/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IShapesOperations.hxx @@ -196,13 +196,42 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations { /*! * \brief Searches a shape equal to theWhat in the context of theWhere - * \param theShapeWhere - a context shap - * \param theShapeWhat - a sample shape - * \retval Handle(GEOM_Object) - found shape + * \param theShapeWhere - a context shap + * \param theShapeWhat - a sample shape + * \retval Handle(GEOM_Object) - found shape */ Standard_EXPORT Handle(GEOM_Object) GetSame(const Handle(GEOM_Object)& theShapeWhere, const Handle(GEOM_Object)& theShapeWhat); + /*! + * \brief Find IDs of subshapes complying with given status about surface + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes + */ + Standard_EXPORT Handle(TColStd_HSequenceOfInteger) + GEOMImpl_IShapesOperations::GetShapesOnBoxIDs(const Handle(GEOM_Object)& theBox, + const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + GEOMAlgo_State theState); + + /*! + * \brief Find subshapes complying with given status about surface + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes + */ + Standard_EXPORT Handle(TColStd_HSequenceOfTransient) + GEOMImpl_IShapesOperations::GetShapesOnBox(const Handle(GEOM_Object)& theBox, + const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + GEOMAlgo_State theState); + + private: Handle(GEOM_Object) MakeShape (list theShapes, const Standard_Integer theObjectType, @@ -289,6 +318,20 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations { const Handle(GEOM_Object)& theBottomRigthPoint, const GEOMAlgo_State theState); + /*! + * \brief Find IDs of subshapes complying with given status about surface + * \param theBox - the box to check state of subshapes against + * \param theShape - the shape to explore + * \param theShapeType - type of subshape of theShape + * \param theState - required state + * \retval Handle(TColStd_HSequenceOfInteger) - IDs of found subshapes + */ + Handle(TColStd_HSequenceOfInteger) + GEOMImpl_IShapesOperations::getShapesOnBoxIDs(const Handle(GEOM_Object)& theBox, + const Handle(GEOM_Object)& theShape, + const Standard_Integer theShapeType, + GEOMAlgo_State theState); + /*! * \brief Find shape objects and their entries by their ids * \param theShape - the main shape diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.cc b/src/GEOM_I/GEOM_IShapesOperations_i.cc index 41a5bfc01..b9893fd9c 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.cc +++ b/src/GEOM_I/GEOM_IShapesOperations_i.cc @@ -1118,6 +1118,90 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnQuadrangleIDs return aSeq._retn(); } +//============================================================================= +/*! + * GetShapesOnBox + */ +//============================================================================= +GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnBox + (GEOM::GEOM_Object_ptr theBox, + GEOM::GEOM_Object_ptr theShape, + CORBA::Long theShapeType, + GEOM::shape_state theState) +{ + GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO; + + //Set a not done flag + GetOperations()->SetNotDone(); + + if ( theShape == NULL || theBox == NULL ) + return aSeq._retn(); + + //Get the reference objects + Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject + (theShape->GetStudyID(), theShape->GetEntry()); + Handle(GEOM_Object) aBox = GetOperations()->GetEngine()->GetObject + (theShape->GetStudyID(), theBox->GetEntry()); + + if (aShape.IsNull() || aBox.IsNull() ) + return aSeq._retn(); + + //Get Shapes On Box + Handle(TColStd_HSequenceOfTransient) aHSeq = GetOperations()->GetShapesOnBox + (aBox,aShape, theShapeType,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(); +} + +//============================================================================= +/*! + * GetShapesOnQuadrangleIDs + */ +//============================================================================= +GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnBoxIDs + (GEOM::GEOM_Object_ptr theBox, + GEOM::GEOM_Object_ptr theShape, + CORBA::Long theShapeType, + GEOM::shape_state theState) +{ + GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong; + + //Set a not done flag + GetOperations()->SetNotDone(); + + if ( theShape == NULL || theBox == NULL ) + return aSeq._retn(); + + //Get the reference objects + Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject + (theShape->GetStudyID(), theShape->GetEntry()); + Handle(GEOM_Object) aBox = GetOperations()->GetEngine()->GetObject + (theShape->GetStudyID(), theBox->GetEntry()); + + if (aShape.IsNull() || aBox.IsNull() ) + return aSeq._retn(); + + //Get Shapes On Box + Handle(TColStd_HSequenceOfInteger) aHSeq = GetOperations()->GetShapesOnBoxIDs + (aBox,aShape, theShapeType,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(); +} + //============================================================================= /*! * GetInPlace diff --git a/src/GEOM_I/GEOM_IShapesOperations_i.hh b/src/GEOM_I/GEOM_IShapesOperations_i.hh index 58551a5b1..2b70daead 100644 --- a/src/GEOM_I/GEOM_IShapesOperations_i.hh +++ b/src/GEOM_I/GEOM_IShapesOperations_i.hh @@ -154,6 +154,16 @@ class GEOM_IShapesOperations_i : GEOM::GEOM_Object_ptr theBottomRigthPoint, GEOM::shape_state theState); + GEOM::ListOfGO* GetShapesOnBox (GEOM::GEOM_Object_ptr theBox, + GEOM::GEOM_Object_ptr theShape, + CORBA::Long theShapeType, + GEOM::shape_state theState); + + GEOM::ListOfLong* GetShapesOnBoxIDs (GEOM::GEOM_Object_ptr theBox, + GEOM::GEOM_Object_ptr theShape, + CORBA::Long theShapeType, + GEOM::shape_state theState); + GEOM::GEOM_Object_ptr GetInPlace (GEOM::GEOM_Object_ptr theShapeWhere, GEOM::GEOM_Object_ptr theShapeWhat); diff --git a/src/GEOM_SWIG/geompy.py b/src/GEOM_SWIG/geompy.py index 1e3c84e51..5ec3ceb7f 100644 --- a/src/GEOM_SWIG/geompy.py +++ b/src/GEOM_SWIG/geompy.py @@ -1008,6 +1008,29 @@ def GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigt print "GetShapesOnQuadrangleIDs : ", ShapesOp.GetErrorCode() return aList +## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively +# the specified \a theBox by the certain way, defined through \a theState parameter. +# @param theBox Shape for relative comparing. +# @param theShape Shape to find sub-shapes of. +# @param theShapeType Type of sub-shapes to be retrieved. +# @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. +# +def GetShapesOnBox(theBox, theShape, theShapeType, theState): + aList = ShapesOp.GetShapesOnBox(theBox, theShape, theShapeType, theState) + if ShapesOp.IsDone() == 0: + print "GetShapesOnBox : ", ShapesOp.GetErrorCode() + return aList + +## Works like the above method, but returns list of sub-shapes indices +# +def GetShapesOnBoxIDs(theBox, theShape, theShapeType, theState): + aList = ShapesOp.GetShapesOnBoxIDs(theBox, theShape, theShapeType, theState) + if ShapesOp.IsDone() == 0: + print "GetShapesOnBoxIDs : ", ShapesOp.GetErrorCode() + return aList + ## Get sub-shape(s) of theShapeWhere, which are # coincident with \a theShapeWhat or could be a part of it. # @param theShapeWhere Shape to find sub-shapes of.