]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Add new command GetShapesOnBox. V3_2_4pre1
authorskl <skl@opencascade.com>
Thu, 7 Dec 2006 10:42:47 +0000 (10:42 +0000)
committerskl <skl@opencascade.com>
Thu, 7 Dec 2006 10:42:47 +0000 (10:42 +0000)
idl/GEOM_Gen.idl
src/GEOMImpl/GEOMImpl_IShapesOperations.cxx
src/GEOMImpl/GEOMImpl_IShapesOperations.hxx
src/GEOM_I/GEOM_IShapesOperations_i.cc
src/GEOM_I/GEOM_IShapesOperations_i.hh
src/GEOM_SWIG/geompy.py

index 43904c69fc3067d2ab88410c1415aa1100f0600e..b617b3c0f9646e14c927e480f4a2ecfd8befef35 100644 (file)
@@ -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.
index 6262b41fa6fc84df4836da2f35000b76eb941b88..199f2c0c569191aa0b8b2afd31a26333d5a36d99 100644 (file)
@@ -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
   /*!
index 546f7867fbfc2f898ce6967fd2d2a91e45480b4a..09468c75cb803599781f1d6824dbd9ddd94d8fc7 100644 (file)
@@ -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<Handle(GEOM_Object)>      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
index 41a5bfc01f7a1798c34267ae19c82b2039efa2c9..b9893fd9ca1d3b46fe748b110595a42e893dff9a 100644 (file)
@@ -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
index 58551a5b18d9e29999e9ebc6f0983bcff7ebbad2..2b70daead3f948a1580d0c3195f0b6a92aff8c9e 100644 (file)
@@ -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);
 
index 1e3c84e51babee2b1a3bb7e0c7aa9bd4b5c78f39..5ec3ceb7f71044c008fb25bcff798e3d0681cf8c 100644 (file)
@@ -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.