]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Implement improvement PAL9905: Incoherence in the GEOM API
authorrnv <rnv@opencascade.com>
Wed, 27 Sep 2006 11:04:58 +0000 (11:04 +0000)
committerrnv <rnv@opencascade.com>
Wed, 27 Sep 2006 11:04:58 +0000 (11:04 +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/GEOM_TestOthers.py
src/GEOM_SWIG/geompy.py

index 95391389bc8bbba0bcb2f9a900bed9df73cf2234..6094c841e69f3752316a248ce147be26a28f7810 100644 (file)
@@ -884,7 +884,7 @@ module GEOM
 
     /*!
      *  Create a face on the given wire.
-     *  \param theWire Wire to build the face on.
+     *  \param theWire closed Wire or Edge to build the face on.
      *  \param isPlanarWanted If TRUE, only planar face will be built.
      *                        If impossible, NULL object will be returned.
      *  \return New GEOM_Object, containing the created face.
@@ -893,7 +893,7 @@ module GEOM
 
     /*!
      *  Create a face on the given wires set.
-     *  \param theWires List of wires to build the face on.
+     *  \param theWires List of closed wires or edges to build the face on.
      *  \param isPlanarWanted If TRUE, only planar face will be built.
      *                        If impossible, NULL object will be returned.
      *  \return New GEOM_Object, containing the created face.
@@ -1053,6 +1053,24 @@ module GEOM
                               in long        theShapeType,
                               in GEOM_Object theAx1,
                               in shape_state theState);
+    /*!
+     *  Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
+     *  the specified plane 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 theAx1 Vector (or line, or linear edge), specifying normal
+     *                direction of the plane to find shapes on.
+     *  \param thePnt Point specifying location of the plane to find shapes on.
+     *  \param theState The state of the subshapes to find.
+     *  \return List of all found sub-shapes.
+     */
+    ListOfGO GetShapesOnPlaneWithLocation (in GEOM_Object theShape,
+                                          in long        theShapeType,
+                                          in GEOM_Object theAx1,
+                                          in GEOM_Object thePnt,
+                                          in shape_state theState);
+
+
 
     /*!
      *  Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
@@ -1121,6 +1139,23 @@ module GEOM
                                    in long        theShapeType,
                                    in GEOM_Object theAx1,
                                    in shape_state theState);
+                                   
+    /*!
+     *  Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
+     *  the specified plane 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 theAx1 Vector (or line, or linear edge), specifying normal
+     *                direction of the plane to find shapes on.
+     *  \param thePnt Point specifying location of the plane to find shapes on.     
+     *  \param theState The state of the subshapes to find.
+     *  \return List of IDs of all found sub-shapes.
+     */
+    ListOfLong GetShapesOnPlaneWithLocationIDs (in GEOM_Object theShape,
+                                               in long        theShapeType,
+                                               in GEOM_Object theAx1,
+                                               in GEOM_Object thePnt,
+                                               in shape_state theState);
 
     /*!
      *  Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
index a9c567a11be962c21033f3c2e75a608f77122033..67e8f436282b3354ed682780ec422987d3aa1114 100644 (file)
@@ -1417,6 +1417,80 @@ Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlan
   return aSeq;
 }
 
+//=============================================================================
+/*!
+ *  GetShapesOnPlaneWithLocation
+ */
+//=============================================================================
+Handle(TColStd_HSequenceOfTransient) GEOMImpl_IShapesOperations::GetShapesOnPlaneWithLocation
+                                        (const Handle(GEOM_Object)& theShape,
+                                         const Standard_Integer     theShapeType,
+                                         const Handle(GEOM_Object)& theAx1,
+                                        const Handle(GEOM_Object)& thePnt,
+                                         const GEOMAlgo_State       theState)
+{
+  SetErrorCode(KO);
+
+  if (theShape.IsNull() || theAx1.IsNull() || thePnt.IsNull()) return NULL;
+
+  TopoDS_Shape aShape = theShape->GetValue();
+  TopoDS_Shape anAx1  = theAx1->GetValue();
+  TopoDS_Shape anPnt = thePnt->GetValue();
+
+  if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return NULL;
+
+  TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
+  if ( !checkTypeShapesOn( theShapeType ))
+    return NULL;
+
+  // Create plane
+  if ( anAx1.ShapeType() != TopAbs_EDGE || anPnt.ShapeType() != TopAbs_VERTEX ) return NULL;
+  TopoDS_Vertex V1, V2, V3;
+  TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
+  TopExp::Vertices(anEdge, V1, V2, Standard_True);
+
+  if (V1.IsNull() || V2.IsNull()) {
+    SetErrorCode("Bad edge given for the plane normal vector");
+    return NULL;
+  }
+  V3 = TopoDS::Vertex(anPnt);
+
+  if(V3.IsNull()) {
+    SetErrorCode("Bad vertex given for the plane location");
+      return NULL;
+  }
+  gp_Pnt aLoc = BRep_Tool::Pnt(V3);
+  gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2));
+
+  if (aVec.Magnitude() < Precision::Confusion()) {
+     SetErrorCode("Vector with null magnitude given");
+    return NULL;
+  }
+  Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec);
+
+  if ( aPlane.IsNull() )
+    return NULL;
+  
+  // Find objects
+  TCollection_AsciiString anAsciiList;
+  Handle(TColStd_HSequenceOfTransient) aSeq;
+  aSeq = getShapesOnSurface( aPlane, 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.GetShapesOnPlaneWithLocation(" << theShape << ", "
+    << aShapeType << ", " << theAx1 << ", "<< thePnt <<", " << theState << ")";
+
+  SetErrorCode(OK);
+  return aSeq;
+}
+
 //=============================================================================
 /*!
  *  GetShapesOnCylinder
@@ -1565,6 +1639,73 @@ Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneI
   return aSeq;
 }
 
+//=============================================================================
+/*!
+ *  GetShapesOnPlaneWithLocationIDs
+ */
+//=============================================================================
+Handle(TColStd_HSequenceOfInteger) GEOMImpl_IShapesOperations::GetShapesOnPlaneWithLocationIDs
+                                        (const Handle(GEOM_Object)& theShape,
+                                         const Standard_Integer     theShapeType,
+                                         const Handle(GEOM_Object)& theAx1,
+                                        const Handle(GEOM_Object)& thePnt,
+                                         const GEOMAlgo_State       theState)
+{
+  SetErrorCode(KO);
+
+  if (theShape.IsNull() || theAx1.IsNull() || thePnt.IsNull()) return NULL;
+
+  TopoDS_Shape aShape = theShape->GetValue();
+  TopoDS_Shape anAx1  = theAx1->GetValue();
+  TopoDS_Shape anPnt  = thePnt->GetValue();
+
+  if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return NULL;
+
+  TopAbs_ShapeEnum aShapeType = TopAbs_ShapeEnum(theShapeType);
+  if ( !checkTypeShapesOn( aShapeType ))
+    return NULL;
+
+  // Create plane
+  if (anAx1.ShapeType() != TopAbs_EDGE || anPnt.ShapeType() != TopAbs_VERTEX) return NULL;
+  TopoDS_Edge anEdge = TopoDS::Edge(anAx1);
+  TopoDS_Vertex V1, V2, V3;
+  TopExp::Vertices(anEdge, V1, V2, Standard_True);
+  if (V1.IsNull() || V2.IsNull()) {
+    SetErrorCode("Bad edge given for the plane normal vector");
+    return NULL;
+  }
+  V3 = TopoDS::Vertex(anPnt);
+  if(V3.IsNull()) {
+    SetErrorCode("Bad vertex given for the plane location");
+      return NULL;
+  }
+  gp_Pnt aLoc = BRep_Tool::Pnt(V3);
+  gp_Vec aVec(BRep_Tool::Pnt(V1),BRep_Tool::Pnt(V2));
+  if (aVec.Magnitude() < Precision::Confusion()) {
+    SetErrorCode("Vector with null magnitude given");
+    return NULL;
+  }
+  
+  Handle(Geom_Surface) aPlane = new Geom_Plane(aLoc, aVec);  
+  if ( aPlane.IsNull() )
+    return NULL;
+
+  // Find object IDs
+  Handle(TColStd_HSequenceOfInteger) aSeq;
+  aSeq = getShapesOnSurfaceIDs( aPlane, aShape, aShapeType, theState );
+
+  // The GetShapesOnPlaneIDs() doesn't change object so no new function is required.
+  Handle(GEOM_Function) aFunction = GEOM::GetCreatedLast(theShape,theAx1)->GetLastFunction();
+
+  // Make a Python command
+  GEOM::TPythonDump(aFunction, /*append=*/true)
+    << "listShapesOnPlane = geompy.GetShapesOnPlaneWithLocationIDs"
+    << "(" << theShape << ", " << aShapeType << ", " << theAx1 << ", "<< thePnt << ", "  << theState << ")";
+
+  SetErrorCode(OK);
+  return aSeq;
+}
+
 //=============================================================================
 /*!
  *  GetShapesOnCylinderIDs
index d18b35c12716a0eac26c393832c9ee5c969e4024..f24d1d03cd0190d769b58e235392b62e3cfa2b29 100644 (file)
@@ -97,6 +97,13 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations {
                                                          const Handle(GEOM_Object)& theAx1,
                                                          const GEOMAlgo_State       theState);
 
+  Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnPlaneWithLocation (const Handle(GEOM_Object)& theShape,
+                                                                    const Standard_Integer     theShapeType,
+                                                                    const Handle(GEOM_Object)& theAx1,
+                                                                    const Handle(GEOM_Object)& thePnt,
+                                                                    const GEOMAlgo_State       theState);
+
+
   Standard_EXPORT Handle(TColStd_HSequenceOfTransient) GetShapesOnCylinder (const Handle(GEOM_Object)& theShape,
                                                             const Standard_Integer     theShapeType,
                                                             const Handle(GEOM_Object)& theAxis,
@@ -114,6 +121,12 @@ class GEOMImpl_IShapesOperations : public GEOM_IOperations {
                                                           const Handle(GEOM_Object)& theAx1,
                                                           const GEOMAlgo_State       theState);
 
+  Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetShapesOnPlaneWithLocationIDs (const Handle(GEOM_Object)& theShape,
+                                                     const Standard_Integer     theShapeType,
+                                                          const Handle(GEOM_Object)& theAx1,
+                                                         const Handle(GEOM_Object)& thePnt,
+                                                          const GEOMAlgo_State       theState);
+
   Standard_EXPORT Handle(TColStd_HSequenceOfInteger) GetShapesOnCylinderIDs (const Handle(GEOM_Object)& theShape,
                                                              const Standard_Integer     theShapeType,
                                                              const Handle(GEOM_Object)& theAxis,
index e26bc84ce391858f574946e52c3c20ad14ab0ef5..23afcacbefdbcf71a2c68930cf489c43a4ec0f4f 100644 (file)
@@ -706,6 +706,49 @@ GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlane
   return aSeq._retn();
 }
 
+//=============================================================================
+/*!
+ *  GetShapesOnPlaneWithLocation
+ */
+//=============================================================================
+GEOM::ListOfGO* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocation
+                                                (GEOM::GEOM_Object_ptr   theShape,
+                                                const CORBA::Long       theShapeType,
+                                                GEOM::GEOM_Object_ptr   theAx1,
+                                                GEOM::GEOM_Object_ptr   thePnt,
+                                                const GEOM::shape_state theState)
+{
+  GEOM::ListOfGO_var aSeq = new GEOM::ListOfGO;
+
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  if (theShape == NULL || theAx1 == NULL || thePnt == NULL) return aSeq._retn();
+
+  //Get the reference objects
+  Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
+    (theShape->GetStudyID(), theShape->GetEntry());
+  Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
+    (theAx1->GetStudyID(), theAx1->GetEntry());
+  Handle(GEOM_Object) anPnt = GetOperations()->GetEngine()->GetObject
+    (thePnt->GetStudyID(), thePnt->GetEntry());
+
+  if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
+
+  //Get Shapes On Plane
+  Handle(TColStd_HSequenceOfTransient) aHSeq =
+    GetOperations()->GetShapesOnPlaneWithLocation(aShape, theShapeType, anAx1, anPnt, 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();
+}
+
 //=============================================================================
 /*!
  *  GetShapesOnCylinder
@@ -889,6 +932,49 @@ GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneIDs
   return aSeq._retn();
 }
 
+//=============================================================================
+/*!
+ *  GetShapesOnPlaneWithLocationIDs
+ */
+//=============================================================================
+GEOM::ListOfLong* GEOM_IShapesOperations_i::GetShapesOnPlaneWithLocationIDs
+                                                (GEOM::GEOM_Object_ptr   theShape,
+                                                const CORBA::Long       theShapeType,
+                                                GEOM::GEOM_Object_ptr   theAx1,
+                                                GEOM::GEOM_Object_ptr   thePnt,
+                                                const GEOM::shape_state theState)
+{
+  GEOM::ListOfLong_var aSeq = new GEOM::ListOfLong;
+
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+
+  if (theShape == NULL || theAx1 == NULL || thePnt == NULL) return aSeq._retn();
+
+  //Get the reference objects
+  Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
+    (theShape->GetStudyID(), theShape->GetEntry());
+  Handle(GEOM_Object) anAx1 = GetOperations()->GetEngine()->GetObject
+    (theAx1->GetStudyID(), theAx1->GetEntry());
+  Handle(GEOM_Object) anPnt = GetOperations()->GetEngine()->GetObject
+    (thePnt->GetStudyID(), thePnt->GetEntry());
+
+  if (aShape.IsNull() || anAx1.IsNull() || anPnt.IsNull()) return aSeq._retn();
+
+  //Get Shapes On Plane
+  Handle(TColStd_HSequenceOfInteger) aHSeq =
+    GetOperations()->GetShapesOnPlaneWithLocationIDs(aShape, theShapeType, anAx1, anPnt, 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();
+}
+
 //=============================================================================
 /*!
  *  GetShapesOnCylinderIDs
index 39bd16c316f4495d27be930aa0c7c975490e24bf..3cbb9b3d2cb6af4cf3d236e2c066935e004b38bf 100644 (file)
@@ -97,6 +97,12 @@ class GEOM_IShapesOperations_i :
                                    GEOM::GEOM_Object_ptr theAx1,
                                    GEOM::shape_state     theState);
 
+  GEOM::ListOfGO* GetShapesOnPlaneWithLocation(GEOM::GEOM_Object_ptr theShape,
+                                              CORBA::Long           theShapeType,
+                                              GEOM::GEOM_Object_ptr theAx1,
+                                              GEOM::GEOM_Object_ptr thePnt,
+                                              GEOM::shape_state     theState);
+
   GEOM::ListOfGO* GetShapesOnCylinder (GEOM::GEOM_Object_ptr theShape,
                                       CORBA::Long           theShapeType,
                                       GEOM::GEOM_Object_ptr theAxis,
@@ -122,6 +128,12 @@ class GEOM_IShapesOperations_i :
                                         GEOM::GEOM_Object_ptr theAx1,
                                         GEOM::shape_state     theState);
 
+  GEOM::ListOfLong* GetShapesOnPlaneWithLocationIDs (GEOM::GEOM_Object_ptr theShape,
+                                                    CORBA::Long           theShapeType,
+                                                    GEOM::GEOM_Object_ptr theAx1,
+                                                    GEOM::GEOM_Object_ptr thePnt,
+                                                    GEOM::shape_state     theState);
+
   GEOM::ListOfLong* GetShapesOnCylinderIDs (GEOM::GEOM_Object_ptr theShape,
                                            CORBA::Long           theShapeType,
                                            GEOM::GEOM_Object_ptr theAxis,
index dff28b812ae23603a9436809f94462f74ce3ed27..f3a92293f0dc39a393532da64423709968ea6343 100644 (file)
@@ -303,6 +303,7 @@ def TestOtherOperations (geompy, math):
   v_n0p = geompy.MakeVectorDXDYDZ(-1,  0,  1)
   v_pp0 = geompy.MakeVectorDXDYDZ( 1,  1,  0)
   v_np0 = geompy.MakeVectorDXDYDZ(-1,  1,  0)
+  v_0n0 = geompy.MakeVectorDXDYDZ( 0, -1,  0)
 
   pln_0pp = geompy.MakePlane(p0, v_0pp, 300)
   pln_0np = geompy.MakePlane(p0, v_0np, 300)
@@ -418,6 +419,20 @@ def TestOtherOperations (geompy, math):
   geompy.UnionIDs(faces_above, faces_above_pln_ids)
   geompy.addToStudy(faces_above, "Group of faces above Plane (N = (0, 1, 1))")
 
+  # GetShapesOnPlaneWithLocation
+  Loc = geompy.MakeVertex(0, -50, 0)
+  edges_on_pln = geompy.GetShapesOnPlaneWithLocation(blocksComp, geompy.ShapeType["EDGE"],
+                                                     v_0n0, Loc, geompy.GEOM.ST_ON)
+  for edge_i in edges_on_pln:
+    geompy.addToStudy(edge_i, "Edge on Plane (N = (0, -1, 0) & Location = (0, -50, 0)")
+    
+  # GetShapesOnPlaneWithLocationIDs
+  edges_on_pln_ids = geompy.GetShapesOnPlaneWithLocationIDs(blocksComp, geompy.ShapeType["EDGE"],
+                                                            v_0n0, Loc, geompy.GEOM.ST_ON)
+  group_edges_on_pln = geompy.CreateGroup(blocksComp, geompy.ShapeType["EDGE"])
+  geompy.UnionIDs(group_edges_on_pln, edges_on_pln_ids)
+  geompy.addToStudy(group_edges_on_pln, "Group of edges on Plane (N = (0, -1, 0) & Location = (0, -50, 0))")
+  
   # GetShapesOnCylinder
   edges_out_cyl = geompy.GetShapesOnCylinder(blocksComp, geompy.ShapeType["EDGE"],
                                              vy, 55, geompy.GEOM.ST_OUT)
index 055c7f9e3293269145bbe85d28e37443ed258d5f..2247928c1974fdf066f39fd6ae1d51a8ce2fca64 100644 (file)
@@ -744,7 +744,7 @@ def MakeWire(theEdgesAndWires):
     return anObj
 
 ## Create a face on the given wire.
-#  @param theWire Wire to build the face on.
+#  @param theWire closed Wire or Edge to build the face on.
 #  @param isPlanarWanted If TRUE, only planar face will be built.
 #                        If impossible, NULL object will be returned.
 #  @return New GEOM_Object, containing the created face.
@@ -757,7 +757,7 @@ def MakeFace(theWire, isPlanarWanted):
     return anObj
 
 ## Create a face on the given wires set.
-#  @param theWires List of wires to build the face on.
+#  @param theWires List of closed wires or edges to build the face on.
 #  @param isPlanarWanted If TRUE, only planar face will be built.
 #                        If impossible, NULL object will be returned.
 #  @return New GEOM_Object, containing the created face.
@@ -900,6 +900,33 @@ def GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState):
         print "GetShapesOnPlaneIDs : ", ShapesOp.GetErrorCode()
     return aList
 
+## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
+#  the specified plane 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 theAx1 Vector (or line, or linear edge), specifying normal
+#                direction of the plane to find shapes on.
+#  @param thePnt Point specifying location of the plane 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.
+#
+#  Example: see GEOM_TestOthers.py
+def GetShapesOnPlaneWithLocation(theShape, theShapeType, theAx1, thePnt, theState):
+    aList = ShapesOp.GetShapesOnPlaneWithLocation(theShape, theShapeType, theAx1, thePnt, theState)
+    if ShapesOp.IsDone() == 0:
+      print "GetShapesOnPlaneWithLocation : ", ShapesOp.GetErrorCode()
+    return aList
+
+## Works like the above method, but returns list of sub-shapes indices
+#
+#  Example: see GEOM_TestOthers.py
+def GetShapesOnPlaneWithLocationIDs(theShape, theShapeType, theAx1, thePnt, theState):
+    aList = ShapesOp.GetShapesOnPlaneWithLocationIDs(theShape, theShapeType, theAx1, thePnt, theState)
+    if ShapesOp.IsDone() == 0:
+        print "GetShapesOnPlaneWithLocationIDs : ", ShapesOp.GetErrorCode()
+    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.