Salome HOME
Add new command GetShapesOnBox.
[modules/geom.git] / src / GEOM_SWIG / geompy.py
index 5e49204c4145c015e1fe725c75968d7004853662..5ec3ceb7f71044c008fb25bcff798e3d0681cf8c 100644 (file)
 #  Module : GEOM
 #  $Header$
 
+import salome
+salome.salome_init()
 from salome import *
+
 import GEOM
 
 """
@@ -741,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.
@@ -754,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.
@@ -897,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.
@@ -978,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.
@@ -991,6 +1044,18 @@ def GetInPlace(theShapeWhere, theShapeWhat):
       print "GetInPlace : ", ShapesOp.GetErrorCode()
     return anObj
 
+## Get sub-shape of theShapeWhere, which is
+#  equal to \a theShapeWhat.
+#  @param theShapeWhere Shape to find sub-shape of.
+#  @param theShapeWhat Shape, specifying what to find.
+#  @return New GEOM_Object for found sub-shape.
+#
+def GetSame(theShapeWhere, theShapeWhat):
+    anObj = ShapesOp.GetSame(theShapeWhere, theShapeWhat)
+    if ShapesOp.IsDone() == 0:
+      print "GetSame : ", ShapesOp.GetErrorCode()
+    return anObj
+
 # -----------------------------------------------------------------------------
 # Access to sub-shapes by their unique IDs inside the main shape.
 # -----------------------------------------------------------------------------
@@ -1314,21 +1379,84 @@ def MakeFuse(s1, s2):
 def MakeSection(s1, s2):
     return MakeBoolean(s1, s2, 4)
 
+## Perform explode of compound
+#  Auxilary method for MakePartition
+def ExplodeCompound(aComp):
+    ResListShapes = []
+    shapes = SubShapeAll(aComp,ShapeType["SHAPE"])
+    nbss = len(shapes)
+    for i in range(0,nbss):
+        if shapes[i].GetShapeType()==GEOM.COMPOUND:
+            ResListShapes.extend(ExplodeCompound(shapes[i]))
+        else:
+            ResListShapes.append(shapes[i])
+            pass
+        pass
+    return ResListShapes
+  
 ## Perform partition operation.
 #  @param ListShapes Shapes to be intersected.
 #  @param ListTools Shapes to intersect theShapes.
-#  @param ListKeepInside Shapes, outside which the results will be deleted.
+#  !!!NOTE: Each compound from ListShapes and ListTools will be exploded
+#           in order to avoid possible intersection between shapes from
+#           this compound.
+#
+#  After implementation new version of PartitionAlgo (October 2006)
+#  other parameters are ignored by current functionality. They are kept
+#  in this function only for support old versions.
+#  Ignored parameters:
+#      @param ListKeepInside Shapes, outside which the results will be deleted.
 #         Each shape from theKeepInside must belong to theShapes also.
-#  @param ListRemoveInside Shapes, inside which the results will be deleted.
+#      @param ListRemoveInside Shapes, inside which the results will be deleted.
 #         Each shape from theRemoveInside must belong to theShapes also.
-#  @param Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum).
-#  @param RemoveWebs If TRUE, perform Glue 3D algorithm.
-#  @param ListMaterials Material indices for each shape. Make sence, only if theRemoveWebs is TRUE.
+#      @param Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum).
+#      @param RemoveWebs If TRUE, perform Glue 3D algorithm.
+#      @param ListMaterials Material indices for each shape. Make sence,
+#         only if theRemoveWebs is TRUE.
+#
 #  @return New GEOM_Object, containing the result shapes.
 #
 #  Example: see GEOM_TestAll.py
 def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
                   Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
+
+    NewListShapes = []
+    nbs = len(ListShapes)
+    for i in range(0,nbs):
+        if ListShapes[i].GetShapeType()==GEOM.COMPOUND:
+            # need to explode
+            NewListShapes.extend(ExplodeCompound(ListShapes[i]))
+        else: NewListShapes.append(ListShapes[i])
+        pass
+      
+    NewListTools = []
+    nbs = len(ListTools)
+    for i in range(0,nbs):
+        if ListTools[i].GetShapeType()==GEOM.COMPOUND:
+            # need to explode
+            NewListTools.extend(ExplodeCompound(ListTools[i]))
+        else: NewListTools.append(ListTools[i])
+        pass
+      
+    return MakePartitionNonSelfIntersectedShape(NewListShapes, NewListTools,
+                                                ListKeepInside, ListRemoveInside,
+                                                Limit, RemoveWebs, ListMaterials)
+
+## Perform partition operation.
+#  This method may be useful if it is needed to make a partition for
+#  compound contains nonintersected shapes. Performance will be better
+#  since intersection between shapes from compound is not performed.
+#
+#  Description of all parameters as in previous method MakePartition()
+#
+#  !!!NOTE: Compounds from ListShapes can not have intersections with each
+#           other and compounds from ListTools can not have intersections
+#           with each other.
+#
+#  @return New GEOM_Object, containing the result shapes.
+#
+def MakePartitionNonSelfIntersectedShape(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
+                  Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
     anObj = BoolOp.MakePartition(ListShapes, ListTools,
                                  ListKeepInside, ListRemoveInside,
                                  Limit, RemoveWebs, ListMaterials);
@@ -1416,6 +1544,21 @@ def MakeRotation(theObject, theAxis, theAngle):
       print "RotateCopy : ", TrsfOp.GetErrorCode()
     return anObj
 
+## Rotate given object around vector perpendicular to plane
+#  containing three points, creating its copy before the rotatation.
+#  @param theObject The object to be rotated.
+#  @param theCentPoint central point - the axis is the vector perpendicular to the plane
+#  containing the three points.
+#  @param thePoint1 and thePoint2 - in a perpendicular plan of the axis.
+#  @return New GEOM_Object, containing the rotated object.
+#
+#  Example: see GEOM_TestAll.py
+def MakeRotationThreePoints(theObject, theCentPoint, thePoint1, thePoint2):
+    anObj = TrsfOp.RotateThreePointsCopy(theObject, theCentPoint, thePoint1, thePoint2)
+    if TrsfOp.IsDone() == 0:
+      print "RotateThreePointsCopy : ", TrsfOp.GetErrorCode()
+    return anObj
+
 ## Scale the given object by the factor, creating its copy before the scaling.
 #  @param theObject The object to be scaled.
 #  @param thePoint Center point for scaling.