X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM_SWIG%2Fgeompy.py;h=089a39c6b411a5b785aa54335237634e30a3a1af;hb=1d4b5b2a08784fdcf51a4bb0aba832ead67e8d9a;hp=4e597a749269be5086dd63d26591b41b103eda55;hpb=6e638ed22140cb8c1a65e73c43541e44b2aa3bf5;p=modules%2Fgeom.git diff --git a/src/GEOM_SWIG/geompy.py b/src/GEOM_SWIG/geompy.py index 4e597a749..089a39c6b 100644 --- a/src/GEOM_SWIG/geompy.py +++ b/src/GEOM_SWIG/geompy.py @@ -26,7 +26,10 @@ # Module : GEOM # $Header$ +import salome +salome.salome_init() from salome import * + import GEOM """ @@ -140,6 +143,17 @@ def addToStudyInFather(aFather, aShape, aName): ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8} +# ----------------------------------------------------------------------------- +# enumeration shape_kind +# ----------------------------------------------------------------------------- + +kind = GEOM.GEOM_IKindOfShape + +class info: + UNKNOWN = 0 + CLOSED = 1 + UNCLOSED = 2 + # ----------------------------------------------------------------------------- # Basic primitives # ----------------------------------------------------------------------------- @@ -273,7 +287,7 @@ def MakePlaneThreePnt(thePnt1, thePnt2, thePnt3, theTrimSize): return anObj ## Create a plane, similar to the existing one, but with another size of representing face. -# @param theFace Referenced plane. +# @param theFace Referenced plane or LCS(Marker). # @param theTrimSize New half size of a side of quadrangle face, representing the plane. # @return New GEOM_Object, containing the created plane. # @@ -336,6 +350,19 @@ def MakeArc(thePnt1, thePnt2, thePnt3): print "MakeArc : ", CurvesOp.GetErrorCode() return anObj +## Create an arc of circle from a center and 2 points. +# @param thePnt1 Center of the arc +# @param thePnt2 Start point of the arc. (Gives also the radius of the arc) +# @param thePnt3 End point of the arc (Gives also a direction) +# @return New GEOM_Object, containing the created arc. +# +# Example: see GEOM_TestAll.py +def MakeArcCenter(thePnt1, thePnt2, thePnt3,theSense): + anObj = CurvesOp.MakeArcCenter(thePnt1, thePnt2, thePnt3,theSense) + if CurvesOp.IsDone() == 0: + print "MakeArcCenter : ", CurvesOp.GetErrorCode() + return anObj + ## Create a circle with given center, normal vector and radius. # @param thePnt Circle center. # @param theVec Vector, normal to the plane of the circle. @@ -452,7 +479,7 @@ def MakeSketcher(theCommand, theWorkingPlane = [0,0,0, 0,0,1, 1,0,0]): # 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. +# @param theWorkingPlane Planar Face or LCS(Marker) of the working plane. # @return New GEOM_Object, containing the created wire. def MakeSketcherOnPlane(theCommand, theWorkingPlane): anObj = CurvesOp.MakeSketcherOnPlane(theCommand, theWorkingPlane) @@ -713,6 +740,32 @@ def MakePipeWithDifferentSections(theSeqBases, theLocations,thePath,theWithConta print "MakePipeWithDifferentSections : ", PrimOp.GetErrorCode() return anObj +## Create a shape by extrusion of the profile shape along +# the path shape. The path shape can be a shell or a face. +# the several profiles can be specified in the several locations of path. +# @param theSeqBases - list of Bases shape to be extruded. +# @param theSeqSubBases - list of corresponding subshapes of section shapes. +# @param theLocations - list of locations on the path corresponding +# specified list of the Bases shapes. Number of locations +# should be equal to number of bases or list of locations can be empty. +# @param thePath - Path shape to extrude the base shape along it. +# @param theWithContact - the mode defining that the section is translated to be in +# contact with the spine. +# @param - WithCorrection - defining that the section is rotated to be +# orthogonal to the spine tangent in the correspondent point +# @return New GEOM_Object, containing the created solids. +# +# Example: see GEOM_TestAll.py +def MakePipeWithShellSections(theSeqBases, theSeqSubBases, + theLocations, thePath, + theWithContact, theWithCorrection): + anObj = PrimOp.MakePipeWithShellSections(theSeqBases, theSeqSubBases, + theLocations, thePath, + theWithContact, theWithCorrection) + if PrimOp.IsDone() == 0: + print "MakePipeWithShellSections : ", PrimOp.GetErrorCode() + return anObj + # ----------------------------------------------------------------------------- # Create base shapes # ----------------------------------------------------------------------------- @@ -741,7 +794,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 +807,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 +950,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. @@ -954,8 +1034,10 @@ def GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState) # the specified quadrangle 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 theCenter Point, specifying center of the sphere to find shapes on. -# @param theRadius Radius of the sphere to find shapes on. +# @param theTopLeftPoint Point, specifying top left corner of a quadrangle +# @param theTopRigthPoint Point, specifying top right corner of a quadrangle +# @param theBottomLeftPoint Point, specifying bottom left corner of a quadrangle +# @param theBottomRigthPoint Point, specifying bottom right corner of a quadrangle # @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. @@ -976,6 +1058,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. @@ -989,6 +1094,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. # ----------------------------------------------------------------------------- @@ -1058,7 +1175,7 @@ def SubShapeAllSortedIDs(aShape, aType): ListIDs = ShapesOp.SubShapeAllIDs(aShape,aType,1) if ShapesOp.IsDone() == 0: print "SubShapeAllSortedIDs : ", ShapesOp.GetErrorCode() - return ListObj + return ListIDs ## Obtain a compound of sub-shapes of , # selected by they indices in list of all sub-shapes of type . @@ -1197,6 +1314,23 @@ def DivideEdge(theObject, theEdgeIndex, theValue, isByParameter): print "DivideEdge : ", HealOp.GetErrorCode() return anObj +## Change orientation of the given object. +# @param theObject Shape to be processed. +# @update given shape +def ChangeOrientationShell(theObject): + theObject = HealOp.ChangeOrientation(theObject) + if HealOp.IsDone() == 0: + print "ChangeOrientation : ", HealOp.GetErrorCode() + +## Change orientation of the given object. +# @param theObject Shape to be processed. +# @return New GEOM_Object, containing processed shape. +def ChangeOrientationShellCopy(theObject): + anObj = HealOp.ChangeOrientationCopy(theObject) + if HealOp.IsDone() == 0: + print "ChangeOrientation : ", HealOp.GetErrorCode() + return anObj + ## Get a list of wires (wrapped in GEOM_Object-s), # that constitute a free boundary of the given shape. # @param theObject Shape to get free boundary of. @@ -1253,6 +1387,38 @@ def MakeGlueFaces(theShape, theTolerance): print "MakeGlueFaces : ", ShapesOp.GetErrorCode() return anObj + +## Find coincident faces in theShape for possible gluing. +# @param theShape Initial shape. +# @param theTolerance Maximum distance between faces, +# which can be considered as coincident. +# @return ListOfGO. +# +# Example: see GEOM_Spanner.py +def GetGlueFaces(theShape, theTolerance): + anObj = ShapesOp.GetGlueFaces(theShape, theTolerance) + if ShapesOp.IsDone() == 0: + print "GetGlueFaces : ", ShapesOp.GetErrorCode() + return anObj + + +## Replace coincident faces in theShape by one face +# in compliance with given list of faces +# @param theShape Initial shape. +# @param theTolerance Maximum distance between faces, +# which can be considered as coincident. +# @param theFaces List of faces for gluing. +# @return New GEOM_Object, containing a copy of theShape +# without some faces. +# +# Example: see GEOM_Spanner.py +def MakeGlueFacesByList(theShape, theTolerance, theFaces): + anObj = ShapesOp.MakeGlueFacesByList(theShape, theTolerance, theFaces) + if ShapesOp.IsDone() == 0: + print "MakeGlueFacesByList : ", ShapesOp.GetErrorCode() + return anObj + + # ----------------------------------------------------------------------------- # Boolean (Common, Cut, Fuse, Section) # ----------------------------------------------------------------------------- @@ -1298,13 +1464,23 @@ def MakeSection(s1, s2): ## 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. +# @param Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum). +# +# 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 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 @@ -1317,6 +1493,27 @@ def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside= print "MakePartition : ", BoolOp.GetErrorCode() return anObj +## 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: Passed compounds (via ListShapes or via ListTools) +# have to consist of nonintersecting shapes. +# +# @return New GEOM_Object, containing the result shapes. +# +def MakePartitionNonSelfIntersectedShape(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[], + Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]): + anObj = BoolOp.MakePartitionNonSelfIntersectedShape(ListShapes, ListTools, + ListKeepInside, ListRemoveInside, + Limit, RemoveWebs, ListMaterials); + if BoolOp.IsDone() == 0: + print "MakePartitionNonSelfIntersectedShape : ", BoolOp.GetErrorCode() + return anObj + ## Shortcut to MakePartition() # # Example: see GEOM_TestOthers.py @@ -1397,6 +1594,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. @@ -1449,8 +1661,16 @@ def MakeMirrorByPoint(theObject, thePoint): print "MirrorPointCopy : ", TrsfOp.GetErrorCode() return anObj -## Modify the Location of the given object by LCS -# creating its copy before the setting +## Modify the Location of the given object by LCS, +# creating its copy before the setting. +# @param theObject The object to be displaced. +# @param theStartLCS Coordinate system to perform displacement from it. +# If \a theStartLCS is NULL, displacement +# will be performed from global CS. +# If \a theObject itself is used as \a theStartLCS, +# its location will be changed to \a theEndLCS. +# @param theEndLCS Coordinate system to perform displacement to it. +# @return New GEOM_Object, containing the displaced shape. # # Example: see GEOM_TestAll.py def MakePosition(theObject, theStartLCS, theEndLCS): @@ -1794,6 +2014,95 @@ def CheckShape(theShape, theIsCheckGeom = 0): print Status return IsValid +## Get position (LCS) of theShape. +# +# Origin of the LCS is situated at the shape's center of mass. +# Axes of the LCS are obtained from shape's location or, +# if the shape is a planar face, from position of its plane. +# +# @param theShape Shape to calculate position of. +# @return [Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz]. +# Ox,Oy,Oz: Coordinates of shape's LCS origin. +# Zx,Zy,Zz: Coordinates of shape's LCS normal(main) direction. +# Xx,Xy,Xz: Coordinates of shape's LCS X direction. +# +# Example: see GEOM_TestMeasures.py +def GetPosition(theShape): + aTuple = MeasuOp.GetPosition(theShape) + if MeasuOp.IsDone() == 0: + print "GetPosition : ", MeasuOp.GetErrorCode() + return aTuple + +## Get kind of theShape. +# +# @param theShape Shape to get a kind of. +# @return Returns a kind of shape in terms of GEOM_IKindOfShape.shape_kind enumeration +# and a list of parameters, describing the shape. +# @note Concrete meaning of each value, returned via \a theIntegers +# or \a theDoubles list depends on the kind of the shape. +# The full list of possible outputs is: +# +# geompy.kind.COMPOUND nb_solids nb_faces nb_edges nb_vertices +# geompy.kind.COMPSOLID nb_solids nb_faces nb_edges nb_vertices +# +# geompy.kind.SHELL geompy.info.CLOSED nb_faces nb_edges nb_vertices +# geompy.kind.SHELL geompy.info.UNCLOSED nb_faces nb_edges nb_vertices +# +# geompy.kind.WIRE geompy.info.CLOSED nb_edges nb_vertices +# geompy.kind.WIRE geompy.info.UNCLOSED nb_edges nb_vertices +# +# geompy.kind.SPHERE xc yc zc R +# geompy.kind.CYLINDER xb yb zb dx dy dz R H +# geompy.kind.BOX xc yc zc ax ay az +# geompy.kind.ROTATED_BOX xc yc zc zx zy zz xx xy xz ax ay az +# geompy.kind.TORUS xc yc zc dx dy dz R_1 R_2 +# geompy.kind.CONE xb yb zb dx dy dz R_1 R_2 H +# geompy.kind.POLYHEDRON nb_faces nb_edges nb_vertices +# geompy.kind.SOLID nb_faces nb_edges nb_vertices +# +# geompy.kind.SPHERE2D xc yc zc R +# geompy.kind.CYLINDER2D xb yb zb dx dy dz R H +# geompy.kind.TORUS2D xc yc zc dx dy dz R_1 R_2 +# geompy.kind.CONE2D xc yc zc dx dy dz R_1 R_2 H +# geompy.kind.DISK_CIRCLE xc yc zc dx dy dz R +# geompy.kind.DISK_ELLIPSE xc yc zc dx dy dz R_1 R_2 +# geompy.kind.POLYGON xo yo zo dx dy dz nb_edges nb_vertices +# geompy.kind.PLANE xo yo zo dx dy dz +# geompy.kind.PLANAR xo yo zo dx dy dz nb_edges nb_vertices +# geompy.kind.FACE nb_edges nb_vertices +# +# geompy.kind.CIRCLE xc yc zc dx dy dz R +# geompy.kind.ARC_CIRCLE xc yc zc dx dy dz R x1 y1 z1 x2 y2 z2 +# geompy.kind.ELLIPSE xc yc zc dx dy dz R_1 R_2 +# geompy.kind.ARC_ELLIPSE xc yc zc dx dy dz R_1 R_2 x1 y1 z1 x2 y2 z2 +# geompy.kind.LINE xo yo zo dx dy dz +# geompy.kind.SEGMENT x1 y1 z1 x2 y2 z2 +# geompy.kind.EDGE nb_vertices +# +# geompy.kind.VERTEX x y z +# +# Example: see GEOM_TestMeasures.py +def KindOfShape(theShape): + aRoughTuple = MeasuOp.KindOfShape(theShape) + if MeasuOp.IsDone() == 0: + print "KindOfShape : ", MeasuOp.GetErrorCode() + return [] + + aKind = aRoughTuple[0] + anInts = aRoughTuple[1] + aDbls = aRoughTuple[2] + + # Now there is no exception from this rule: + aKindTuple = [aKind] + aDbls + anInts + + # If they are we will regroup parameters for such kind of shape. + # For example: + #if aKind == kind.SOME_KIND: + # # SOME_KIND int int double int double double + # aKindTuple = [aKind, anInts[0], anInts[1], aDbls[0], anInts[2], aDbls[1], aDbls[2]] + + return aKindTuple + # ----------------------------------------------------------------------------- # Import/Export objects # ----------------------------------------------------------------------------- @@ -2045,7 +2354,8 @@ def CheckCompoundOfBlocks(theCompound): return IsValid ## Remove all seam and degenerated edges from \a theShape. -# Unite faces and edges, sharing one surface. +# Unite faces and edges, sharing one surface. It means that +# this faces must have references to one C++ surface object (handle). # @param theShape The compound or single solid to remove irregular edges from. # @return Improved shape. #