Salome HOME
Implementation of gluing faces by given list (for PAL13191).
[modules/geom.git] / src / GEOM_SWIG / batchmode_geompy.py
index 452023fcfd17f498c700e480df19db87031312fa..0f91c8c9dcf4b9e4210e32176a133cf95ea46771 100644 (file)
@@ -17,7 +17,7 @@
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-#  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 #
 #
@@ -31,15 +31,45 @@ import GEOM
 
 g=None
 step = 0
-while step < 50 and g == None:
+sleeping_time = 0.01
+sleeping_time_max = 1.0
+while 1:
     g = lcc.FindOrLoadComponent("FactoryServer", "GEOM")
+    if g is not None: break
     step = step + 1
-    time.sleep(4)
+    if step > 100: break
+    time.sleep(sleeping_time)
+    sleeping_time = max(sleeping_time_max, 2*sleeping_time)
+    pass
 geom = g._narrow( GEOM.GEOM_Gen )
-myBuilder = myStudy.NewBuilder()
 
-father = myStudy.FindComponent("GEOM")
-if father is None:
+myBuilder = None
+myStudyId = 0
+father    = None
+
+BasicOp  = None
+CurvesOp = None
+PrimOp   = None
+ShapesOp = None
+HealOp   = None
+InsertOp = None
+BoolOp   = None
+TrsfOp   = None
+LocalOp  = None
+MeasuOp  = None
+BlocksOp = None
+GroupOp  = None
+
+def init_geom(theStudy):
+
+    global myStudy, myBuilder, myStudyId, BasicOp, CurvesOp, PrimOp, ShapesOp, HealOp
+    global InsertOp, BoolOp, TrsfOp, LocalOp, MeasuOp, BlocksOp, GroupOp, father
+
+    myStudy = theStudy
+    myStudyId = myStudy._get_StudyId()
+    myBuilder = myStudy.NewBuilder()
+    father = myStudy.FindComponent("GEOM")
+    if father is None:
         father = myBuilder.NewComponent("GEOM")
         A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName")
         FName = A1._narrow(SALOMEDS.AttributeName)
@@ -48,6 +78,27 @@ if father is None:
        aPixmap = A2._narrow(SALOMEDS.AttributePixMap)
        aPixmap.SetPixMap("ICON_OBJBROWSER_Geometry")
        myBuilder.DefineComponentInstance(father,geom)
+        pass
+
+    # -----------------------------------------------------------------------------
+    # Assign Operations Interfaces
+    # -----------------------------------------------------------------------------
+
+    BasicOp  = geom.GetIBasicOperations    (myStudyId)
+    CurvesOp = geom.GetICurvesOperations   (myStudyId)
+    PrimOp   = geom.GetI3DPrimOperations   (myStudyId)
+    ShapesOp = geom.GetIShapesOperations   (myStudyId)
+    HealOp   = geom.GetIHealingOperations  (myStudyId)
+    InsertOp = geom.GetIInsertOperations   (myStudyId)
+    BoolOp   = geom.GetIBooleanOperations  (myStudyId)
+    TrsfOp   = geom.GetITransformOperations(myStudyId)
+    LocalOp  = geom.GetILocalOperations    (myStudyId)
+    MeasuOp  = geom.GetIMeasureOperations  (myStudyId)
+    BlocksOp = geom.GetIBlocksOperations   (myStudyId)
+    GroupOp  = geom.GetIGroupOperations   (myStudyId)
+    pass
+
+init_geom(myStudy)
 
 #     *  Get name for sub-shape aSubObj of shape aMainObj
 #
@@ -82,23 +133,6 @@ def addToStudyInFather(aFather, aShape, aName):
 
 ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
 
-# -----------------------------------------------------------------------------
-# Get Operations Interfaces
-# -----------------------------------------------------------------------------
-
-BasicOp  = geom.GetIBasicOperations    (myStudyId)
-CurvesOp = geom.GetICurvesOperations   (myStudyId)
-PrimOp   = geom.GetI3DPrimOperations   (myStudyId)
-ShapesOp = geom.GetIShapesOperations   (myStudyId)
-HealOp   = geom.GetIHealingOperations  (myStudyId)
-InsertOp = geom.GetIInsertOperations   (myStudyId)
-BoolOp   = geom.GetIBooleanOperations  (myStudyId)
-TrsfOp   = geom.GetITransformOperations(myStudyId)
-LocalOp  = geom.GetILocalOperations    (myStudyId)
-MeasuOp  = geom.GetIMeasureOperations  (myStudyId)
-BlocksOp = geom.GetIBlocksOperations   (myStudyId)
-GroupOp  = geom.GetIGroupOperations   (myStudyId)
-
 # -----------------------------------------------------------------------------
 # Basic primitives
 # -----------------------------------------------------------------------------
@@ -169,6 +203,30 @@ def MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ):
       print "MakeMarker : ", BasicOp.GetErrorCode()
     return anObj
 
+def MakeMarkerPntTwoVec(theOrigin, theXVec, theYVec):
+    """
+     *  Create a local coordinate system.
+     *  \param theOrigin Point of coordinate system origin.
+     *  \param theXVec Vector of X direction
+     *  \param theYVec Vector of Y direction
+     *  \return New GEOM_Object, containing the created coordinate system.
+    """
+    O = PointCoordinates( theOrigin )
+    OXOY = []
+    for vec in [ theXVec, theYVec ]:
+        v1, v2 = SubShapeAll( vec, ShapeType["VERTEX"] )
+        p1 = PointCoordinates( v1 )
+        p2 = PointCoordinates( v2 )
+        for i in range( 0, 3 ):
+             OXOY.append( p2[i] - p1[i] )
+    #
+    anObj = BasicOp.MakeMarker( O[0], O[1], O[2],
+                                OXOY[0], OXOY[1], OXOY[2],
+                                OXOY[3], OXOY[4], OXOY[5], )
+    if BasicOp.IsDone() == 0:
+      print "MakeMarker : ", BasicOp.GetErrorCode()
+    return anObj
+
 # -----------------------------------------------------------------------------
 # Curves
 # -----------------------------------------------------------------------------
@@ -223,6 +281,21 @@ def MakeSketcher(Cmd, WPL = [0,0,0, 0,0,1, 1,0,0]):
       print "MakeSketcher : ", CurvesOp.GetErrorCode()
     return anObj
 
+def MakeSketcherOnPlane(theCommand, theWorkingPlane):
+    """
+     *  Create a sketcher (wire or face), following the textual description,
+     *  passed through \a theCommand argument. \n
+     *  For format of the description string see the previous method.\n
+     *  \param theCommand String, defining the sketcher in local
+     *                    coordinates of the working plane.
+     *  \param theWorkingPlane Planar Face of the working plane.
+     *  \return New GEOM_Object, containing the created wire.
+    """
+    anObj = CurvesOp.MakeSketcherOnPlane(theCommand, theWorkingPlane)
+    if CurvesOp.IsDone() == 0:
+      print "MakeSketcher : ", CurvesOp.GetErrorCode()
+    return anObj
+
 # -----------------------------------------------------------------------------
 # Create 3D Primitives
 # -----------------------------------------------------------------------------
@@ -411,18 +484,48 @@ def GetShapesOnPlane(theShape, theShapeType, theAx1, theState):
       print "GetShapesOnPlane : ", ShapesOp.GetErrorCode()
     return aList
 
+def GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState):
+    aList = ShapesOp.GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState)
+    if ShapesOp.IsDone() == 0:
+        print "GetShapesOnPlaneIDs : ", ShapesOp.GetErrorCode()
+    return aList
+
 def GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState):
     aList = ShapesOp.GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState)
     if ShapesOp.IsDone() == 0:
       print "GetShapesOnCylinder : ", ShapesOp.GetErrorCode()
     return aList
 
+def GetShapesOnCylinderIDs(theShape, theShapeType, theAxis, theRadius, theState):
+    aList = ShapesOp.GetShapesOnCylinderIDs(theShape, theShapeType, theAxis, theRadius, theState)
+    if ShapesOp.IsDone() == 0:
+        print "GetShapesOnCylinderIDs : ", ShapesOp.GetErrorCode()
+    return aList
+
 def GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState):
     aList = ShapesOp.GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState)
     if ShapesOp.IsDone() == 0:
       print "GetShapesOnSphere : ", ShapesOp.GetErrorCode()
     return aList
 
+def GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState):
+    aList = ShapesOp.GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState)
+    if ShapesOp.IsDone() == 0:
+        print "GetShapesOnSphereIDs : ", ShapesOp.GetErrorCode()
+    return aList
+
+def GetShapesOnQuadrangle(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState):
+    aList = ShapesOp.GetShapesOnQuadrangle(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState)
+    if ShapesOp.IsDone() == 0:
+      print "GetShapesOnQuadrangle : ", ShapesOp.GetErrorCode()
+    return aList
+
+def GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState):
+    aList = ShapesOp.GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState)
+    if ShapesOp.IsDone() == 0:
+        print "GetShapesOnQuadrangleIDs : ", ShapesOp.GetErrorCode()
+    return aList
+
 def GetInPlace(theShapeWhere, theShapeWhat):
     anObj = ShapesOp.GetInPlace(theShapeWhere, theShapeWhat)
     if ShapesOp.IsDone() == 0:
@@ -645,6 +748,12 @@ def MakeRotation(aShape,axis,angle):
       print "RotateCopy : ", TrsfOp.GetErrorCode()
     return anObj
 
+def MakeRotationThreePoints(aShape, centpoint, point1, point2):
+    anObj = TrsfOp.RotateThreePointsCopy(aShape, centpoint, point1, point2)
+    if TrsfOp.IsDone() == 0:
+      print "RotateThreePointsCopy : ", TrsfOp.GetErrorCode()
+    return anObj
+
 def MakeScaleTransform(aShape,theCenterofScale,factor):
     anObj = TrsfOp.ScaleShapeCopy(aShape,theCenterofScale,factor)
     if TrsfOp.IsDone() == 0:
@@ -823,8 +932,12 @@ def MakeCDG(aShape):
       print "GetCentreOfMass : ", MeasuOp.GetErrorCode()
     return anObj
 
-def CheckShape(aShape):
-    (IsValid, Status) = MeasuOp.CheckShape(aShape)
+def CheckShape(theShape, theIsCheckGeom = 0):
+    if theIsCheckGeom:
+        (IsValid, Status) = MeasuOp.CheckShapeWithGeometry(theShape)
+    else:
+        (IsValid, Status) = MeasuOp.CheckShape(theShape)
+
     if MeasuOp.IsDone() == 0:
       print "CheckShape : ", MeasuOp.GetErrorCode()
     else:
@@ -1038,11 +1151,21 @@ def UnionList (theGroup, theSubShapes):
     if GroupOp.IsDone() == 0:
       print "UnionList : ", GroupOp.GetErrorCode()
 
+def UnionIDs(theGroup, theSubShapes):
+    GroupOp.UnionIDs(theGroup, theSubShapes)
+    if GroupOp.IsDone() == 0:
+        print "UnionIDs : ", GroupOp.GetErrorCode()
+
 def DifferenceList (theGroup, theSubShapes):
     GroupOp.DifferenceList(theGroup, theSubShapes)
     if GroupOp.IsDone() == 0:
       print "DifferenceList : ", GroupOp.GetErrorCode()
 
+def DifferenceIDs(theGroup, theSubShapes):
+    GroupOp.DifferenceIDs(theGroup, theSubShapes)
+    if GroupOp.IsDone() == 0:
+        print "DifferenceIDs : ", GroupOp.GetErrorCode()
+
 def GetObjectIDs(Group):
     ListIDs = GroupOp.GetObjects(Group)
     if GroupOp.IsDone() == 0:
@@ -1061,6 +1184,34 @@ def GetMainShape(theGroup):
       print "GetMainShape : ", GroupOp.GetErrorCode()
     return anObj
 
+def GetEdgesByLength (theShape, min_length, max_length, include_min = 1, include_max = 1):
+    """
+    Create group of edges of theShape, whose length is in range [min_length, max_length].
+    If include_min/max == 0, edges with length == min/max_length will not be included in result.
+    """
+
+    edges = SubShapeAll(theShape, ShapeType["EDGE"])
+    edges_in_range = []
+    for edge in edges:
+        Props = BasicProperties(edge)
+       if min_length <= Props[0] and Props[0] <= max_length:
+           if (not include_min) and (min_length == Props[0]):
+               skip = 1
+            else:
+               if (not include_max) and (Props[0] == max_length):
+                   skip = 1
+                else:
+                   edges_in_range.append(edge)
+
+    if len(edges_in_range) <= 0:
+        print "No edges found by given criteria"
+       return 0
+
+    group_edges = CreateGroup(theShape, ShapeType["EDGE"])
+    UnionList(group_edges, edges_in_range)
+
+    return group_edges
+
 # Add Path to the system path
 #
 def addPath(Path):