X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGEOM_SWIG%2FgeompyDC.py;h=c8ef92793f9a967e0a405260321f5ad3903b1394;hb=cb234e246225d575d6682ca4587e54b5f6f30497;hp=8214e3403626f994aec12151ee6993dc6124125e;hpb=19bf0c8c6a504a20768d856e7c91ce3b9d521bc0;p=modules%2Fgeom.git diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 8214e3403..c8ef92793 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -1,3 +1,4 @@ +# -*- coding: iso-8859-1 -*- # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE # # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, @@ -92,9 +93,9 @@ ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE" def RaiseIfFailed (Method_name, Operation): if Operation.IsDone() == 0 and Operation.GetErrorCode() != "NOT_FOUND_ANY": raise RuntimeError, Method_name + " : " + Operation.GetErrorCode() - + ## Return list of variables value from salome notebook -## @ingroup l1_geompy_auxiliary +## @ingroup l1_geompy_auxiliary def ParseParameters(*parameters): Result = [] StringResult = "" @@ -107,16 +108,16 @@ def ParseParameters(*parameters): else: Result.append(parameter) pass - + StringResult = StringResult + str(parameter) StringResult = StringResult + ":" pass StringResult = StringResult[:len(StringResult)-1] Result.append(StringResult) return Result - + ## Return list of variables value from salome notebook -## @ingroup l1_geompy_auxiliary +## @ingroup l1_geompy_auxiliary def ParseList(list): Result = [] StringResult = "" @@ -127,15 +128,15 @@ def ParseList(list): else: Result.append(str(parameter)) pass - + StringResult = StringResult + str(parameter) StringResult = StringResult + ":" pass StringResult = StringResult[:len(StringResult)-1] return Result, StringResult - + ## Return list of variables value from salome notebook -## @ingroup l1_geompy_auxiliary +## @ingroup l1_geompy_auxiliary def ParseSketcherCommand(command): Result = "" StringResult = "" @@ -167,6 +168,88 @@ def ParseSketcherCommand(command): Result = Result[:len(Result)-1] return Result, StringResult +## Helper function which can be used to pack the passed string to the byte data. +## Only '1' an '0' symbols are valid for the string. The missing bits are replaced by zeroes. +## If the string contains invalid symbol (neither '1' nor '0'), the function raises an exception. +## For example, +## \code +## val = PackData("10001110") # val = 0xAE +## val = PackData("1") # val = 0x80 +## \endcode +## @param data unpacked data - a string containing '1' and '0' symbols +## @return data packed to the byte stream +## @ingroup l1_geompy_auxiliary +def PackData(data): + bytes = len(data)/8 + if len(data)%8: bytes += 1 + res = "" + for b in range(bytes): + d = data[b*8:(b+1)*8] + val = 0 + for i in range(8): + val *= 2 + if i < len(d): + if d[i] == "1": val += 1 + elif d[i] != "0": + raise "Invalid symbol %s" % d[i] + pass + pass + res += chr(val) + pass + return res + +## Read bitmap texture from the text file. +## In that file, any non-zero symbol represents '1' opaque pixel of the bitmap. +## A zero symbol ('0') represents transparent pixel of the texture bitmap. +## The function returns width and height of the pixmap in pixels and byte stream representing +## texture bitmap itself. +## +## This function can be used to read the texture to the byte stream in order to pass it to +## the AddTexture() function of geompy class. +## For example, +## \code +## import geompy +## geompy.init_geom(salome.myStudy) +## texture = geompy.readtexture('mytexture.dat') +## texture = geompy.AddTexture(*texture) +## obj.SetMarkerTexture(texture) +## \endcode +## @param fname texture file name +## @return sequence of tree values: texture's width, height in pixels and its byte stream +## @ingroup l1_geompy_auxiliary +def ReadTexture(fname): + try: + f = open(fname) + lines = [ l.strip() for l in f.readlines()] + f.close() + maxlen = 0 + if lines: maxlen = max([len(x) for x in lines]) + lenbytes = maxlen/8 + if maxlen%8: lenbytes += 1 + bytedata="" + for line in lines: + if len(line)%8: + lenline = (len(line)/8+1)*8 + pass + else: + lenline = (len(line)/8)*8 + pass + for i in range(lenline/8): + byte="" + for j in range(8): + if i*8+j < len(line) and line[i*8+j] != "0": byte += "1" + else: byte += "0" + pass + bytedata += PackData(byte) + pass + for i in range(lenline/8, lenbytes): + bytedata += PackData("0") + pass + return lenbytes*8, len(lines), bytedata + except: + pass + return 0, 0, "" + ## Kinds of shape enumeration # @ingroup l1_geompy_auxiliary kind = GEOM.GEOM_IKindOfShape @@ -178,7 +261,6 @@ class info: CLOSED = 1 UNCLOSED = 2 - class geompyDC(GEOM._objref_GEOM_Gen): def __init__(self): @@ -305,7 +387,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # operations, where only the first argument has to be considered. # If theObject has only one argument shape, this flag is automatically # considered as True, not regarding really passed value. - # \return True in case of success, False otherwise. + # \return list of published sub-shapes # # @ref tui_restore_prs_params "Example" def RestoreSubShapes (self, theObject, theArgs=[], @@ -366,6 +448,22 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj.SetParameters(Parameters) return anObj + ## Create a point by projection give coordinates on the given curve + # @param theRefCurve The referenced curve. + # @param theX X-coordinate in 3D space + # @param theY Y-coordinate in 3D space + # @param theZ Z-coordinate in 3D space + # @return New GEOM_Object, containing the created point. + # + # @ref tui_creation_point "Example" + def MakeVertexOnCurveByCoord(self,theRefCurve, theX, theY, theZ): + # Example: see GEOM_TestAll.py + theX, theY, theZ, Parameters = ParseParameters(theX, theY, theZ) + anObj = self.BasicOp.MakePointOnCurveByCoord(theRefCurve, theX, theY, theZ) + RaiseIfFailed("MakeVertexOnCurveByCoord", self.BasicOp) + anObj.SetParameters(Parameters) + return anObj + ## Create a point, corresponding to the given parameters on the # given surface. # @param theRefSurf The referenced surface. @@ -382,6 +480,22 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj.SetParameters(Parameters); return anObj + ## Create a point by projection give coordinates on the given surface + # @param theRefSurf The referenced surface. + # @param theX X-coordinate in 3D space + # @param theY Y-coordinate in 3D space + # @param theZ Z-coordinate in 3D space + # @return New GEOM_Object, containing the created point. + # + # @ref swig_MakeVertexOnSurfaceByCoord "Example" + def MakeVertexOnSurfaceByCoord(self, theRefSurf, theX, theY, theZ): + theX, theY, theZ, Parameters = ParseParameters(theX, theY, theZ) + # Example: see GEOM_TestAll.py + anObj = self.BasicOp.MakePointOnSurfaceByCoord(theRefSurf, theX, theY, theZ) + RaiseIfFailed("MakeVertexOnSurfaceByCoord", self.BasicOp) + anObj.SetParameters(Parameters); + return anObj + ## Create a point on intersection of two lines. # @param theRefLine1, theRefLine2 The referenced lines. # @return New GEOM_Object, containing the created point. @@ -403,14 +517,15 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj = self.BasicOp.MakeTangentOnCurve(theRefCurve, theParameter) RaiseIfFailed("MakeTangentOnCurve", self.BasicOp) return anObj - - ## Create a tangent plane to specified face in the point with specified parameters. - # @param theFace - face for which tangent plane shuold be built. - # @param theParameterU - value of parameter by U - # @param theParameterV - value of parameter Vthe - # @param theTrimSize - defines sizes of created face - # Values of parameters should be between 0. and 1.0 - # return New GEOM_Object, containing the face built on tangent plane. + + ## Create a tangent plane, corresponding to the given parameter on the given face. + # @param theFace The face for which tangent plane should be built. + # @param theParameterV vertical value of the center point (0.0 - 1.0). + # @param theParameterU horisontal value of the center point (0.0 - 1.0). + # @param theTrimSize the size of plane. + # @return New GEOM_Object, containing the created tangent. + # + # @ref swig_MakeTangentPlaneOnFace "Example" def MakeTangentPlaneOnFace(self, theFace, theParameterU, theParameterV, theTrimSize): anObj = self.BasicOp.MakeTangentPlaneOnFace(theFace, theParameterU, theParameterV, theTrimSize) RaiseIfFailed("MakeTangentPlaneOnFace", self.BasicOp) @@ -526,6 +641,37 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj.SetParameters(Parameters) return anObj + ## Create a plane, passing through the 2 vectors + # with center in a start point of the first vector. + # @param theVec1 Vector, defining center point and plane direction. + # @param theVec2 Vector, defining the plane normal direction. + # @param theTrimSize Half size of a side of quadrangle face, representing the plane. + # @return New GEOM_Object, containing the created plane. + # + # @ref tui_creation_plane "Example" + def MakePlane2Vec(self,theVec1, theVec2, theTrimSize): + # Example: see GEOM_TestAll.py + theTrimSize, Parameters = ParseParameters(theTrimSize); + anObj = self.BasicOp.MakePlane2Vec(theVec1, theVec2, theTrimSize) + RaiseIfFailed("MakePlane2Vec", self.BasicOp) + anObj.SetParameters(Parameters) + return anObj + + ## Create a plane, based on a Local coordinate system. + # @param theLCS coordinate system, defining plane. + # @param theTrimSize Half size of a side of quadrangle face, representing the plane. + # @param theOrientation OXY, OYZ or OZX orientation - (1, 2 or 3) + # @return New GEOM_Object, containing the created plane. + # + # @ref tui_creation_plane "Example" + def MakePlaneLCS(self,theLCS, theTrimSize, theOrientation): + # Example: see GEOM_TestAll.py + theTrimSize, Parameters = ParseParameters(theTrimSize); + anObj = self.BasicOp.MakePlaneLCS(theLCS, theTrimSize, theOrientation) + RaiseIfFailed("MakePlaneLCS", self.BasicOp) + anObj.SetParameters(Parameters) + return anObj + ## Create a local coordinate system. # @param OX,OY,OZ Three coordinates of coordinate system origin. # @param XDX,XDY,XDZ Three components of OX direction @@ -535,7 +681,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @ref swig_MakeMarker "Example" def MakeMarker(self, OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ): # Example: see GEOM_TestAll.py - OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ, Parameters = ParseParameters(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ); + OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ, Parameters = ParseParameters(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ); anObj = self.BasicOp.MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ) RaiseIfFailed("MakeMarker", self.BasicOp) anObj.SetParameters(Parameters) @@ -715,12 +861,13 @@ class geompyDC(GEOM._objref_GEOM_Gen): ## Create B-Spline curve on the set of points. # @param thePoints Sequence of points for the B-Spline curve. + # @param theIsClosed If True, build a closed curve. # @return New GEOM_Object, containing the created B-Spline curve. # # @ref tui_creation_curve "Example" - def MakeInterpol(self,thePoints): + def MakeInterpol(self, thePoints, theIsClosed=False): # Example: see GEOM_TestAll.py - anObj = self.CurvesOp.MakeSplineInterpolation(thePoints) + anObj = self.CurvesOp.MakeSplineInterpolation(thePoints, theIsClosed) RaiseIfFailed("MakeSplineInterpolation", self.CurvesOp) return anObj @@ -785,7 +932,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj = self.CurvesOp.MakeSketcherOnPlane(theCommand, theWorkingPlane) RaiseIfFailed("MakeSketcherOnPlane", self.CurvesOp) return anObj - + ## Create a sketcher wire, following the numerical description, # passed through theCoordinates argument. \n # @param theCoordinates double values, defining points to create a wire, @@ -842,12 +989,12 @@ class geompyDC(GEOM._objref_GEOM_Gen): anObj = self.PrimOp.MakeBoxTwoPnt(thePnt1, thePnt2) RaiseIfFailed("MakeBoxTwoPnt", self.PrimOp) return anObj - + ## Create a face with specified dimensions along OX-OY coordinate axes, # with edges, parallel to this coordinate axes. # @param theH height of Face. # @param theW width of Face. - # @param theOrientation orientation belong axis OXY OYZ OZX + # @param theOrientation orientation belong axis OXY OYZ OZX # @return New GEOM_Object, containing the created face. # # @ref tui_creation_face "Example" @@ -904,7 +1051,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): ## Create a disk with specified dimensions along OX-OY coordinate axes. # @param theR Radius of Face. - # @param theOrientation set the orientation belong axis OXY or OYZ or OZX + # @param theOrientation set the orientation belong axis OXY or OYZ or OZX # @return New GEOM_Object, containing the created disk. # # @ref tui_creation_face "Example" @@ -1107,7 +1254,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("MakePrismVecH2Ways", self.PrimOp) anObj.SetParameters(Parameters) return anObj - + ## Create a shape by extrusion of the base shape along the dx, dy, dz direction # @param theBase Base shape to be extruded. # @param theDX, theDY, theDZ Directions of extrusion. @@ -1121,7 +1268,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("MakePrismDXDYDZ", self.PrimOp) anObj.SetParameters(Parameters) return anObj - + ## Create a shape by extrusion of the base shape along the dx, dy, dz direction # i.e. all the space, transfixed by the base shape during its translation # along the vector on the given distance in 2 Ways (forward/backward) . @@ -1357,12 +1504,14 @@ class geompyDC(GEOM._objref_GEOM_Gen): ## Create a wire from the set of edges and wires. # @param theEdgesAndWires List of edges and/or wires. + # @param theTolerance Maximum distance between vertices, that will be merged. + # Values less than 1e-07 are equivalent to 1e-07 (Precision::Confusion()). # @return New GEOM_Object, containing the created wire. # # @ref tui_creation_wire "Example" - def MakeWire(self,theEdgesAndWires): + def MakeWire(self, theEdgesAndWires, theTolerance = 1e-07): # Example: see GEOM_TestAll.py - anObj = self.ShapesOp.MakeWire(theEdgesAndWires) + anObj = self.ShapesOp.MakeWire(theEdgesAndWires, theTolerance) RaiseIfFailed("MakeWire", self.ShapesOp) return anObj @@ -1444,8 +1593,8 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @param theShape Shape to count faces of. # @return Quantity of faces. # - # @ref swig_NumberOfFaces "Example" - def NumberOfFaces(self,theShape): + # @ref swig_NumberOf "Example" + def NumberOfFaces(self, theShape): # Example: see GEOM_TestOthers.py nb_faces = self.ShapesOp.NumberOfFaces(theShape) RaiseIfFailed("NumberOfFaces", self.ShapesOp) @@ -1455,13 +1604,36 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @param theShape Shape to count edges of. # @return Quantity of edges. # - # @ref swig_NumberOfEdges "Example" - def NumberOfEdges(self,theShape): + # @ref swig_NumberOf "Example" + def NumberOfEdges(self, theShape): # Example: see GEOM_TestOthers.py nb_edges = self.ShapesOp.NumberOfEdges(theShape) RaiseIfFailed("NumberOfEdges", self.ShapesOp) return nb_edges + ## Gives quantity of subshapes of type theShapeType in the given shape. + # @param theShape Shape to count subshapes of. + # @param theShapeType Type of subshapes to count. + # @return Quantity of subshapes of given type. + # + # @ref swig_NumberOf "Example" + def NumberOfSubShapes(self, theShape, theShapeType): + # Example: see GEOM_TestOthers.py + nb_ss = self.ShapesOp.NumberOfSubShapes(theShape, theShapeType) + RaiseIfFailed("NumberOfSubShapes", self.ShapesOp) + return nb_ss + + ## Gives quantity of solids in the given shape. + # @param theShape Shape to count solids in. + # @return Quantity of solids. + # + # @ref swig_NumberOf "Example" + def NumberOfSolids(self, theShape): + # Example: see GEOM_TestOthers.py + nb_solids = self.ShapesOp.NumberOfSubShapes(theShape, ShapeType["SOLID"]) + RaiseIfFailed("NumberOfSolids", self.ShapesOp) + return nb_solids + # end of l2_measure ## @} @@ -2658,7 +2830,23 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("MakeFilletFacesR1R2", self.LocalOp) anObj.SetParameters(Parameters) return anObj - + + ## Perform a fillet on the specified edges of the given shape + # @param theShape - Wire Shape to perform fillet on. + # @param theR - Fillet radius. + # @param theListOfVertexes Global indices of vertexes to perform fillet on. + # \note Global index of sub-shape can be obtained, using method geompy.GetSubShapeID(). + # \note The list of vertices could be empty, + # in this case fillet will done done at all vertices in wire + # @return New GEOM_Object, containing the result shape. + # + # @ref tui_fillet2d "Example" + def MakeFillet1D(self,theShape, theR, theListOfVertexes): + # Example: see GEOM_TestAll.py + anObj = self.LocalOp.MakeFillet1D(theShape, theR, theListOfVertexes) + RaiseIfFailed("MakeFillet1D", self.LocalOp) + return anObj + ## Perform a fillet on the specified edges/faces of the given shape # @param theShape - Face Shape to perform fillet on. # @param theR - Fillet radius. @@ -3148,6 +3336,8 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @param theFileName The file, containing the shape. # @param theFormatName Specify format for the file reading. # Available formats can be obtained with InsertOp.ImportTranslators() method. + # If format 'IGES_SCALE' is used instead 'IGES' length unit will be + # set to 'meter' and result model will be scaled. # @return New GEOM_Object, containing the imported shape. # # @ref swig_Import_Export "Example" @@ -3171,6 +3361,24 @@ class geompyDC(GEOM._objref_GEOM_Gen): # Example: see GEOM_TestOthers.py return self.Import(theFileName, "IGES") + ## Return length unit from given IGES file + # + # @ref swig_Import_Export "Example" + def GetIGESUnit(self,theFileName): + # Example: see GEOM_TestOthers.py + anObj = self.InsertOp.Import(theFileName, "IGES_UNIT") + #RaiseIfFailed("Import", self.InsertOp) + # recieve name using returned vertex + UnitName = "M" + vertices = self.SubShapeAll(anObj,ShapeType["VERTEX"]) + if len(vertices)>0: + p = self.PointCoordinates(vertices[0]) + if abs(p[0]-0.01) < 1.e-6: + UnitName = "CM" + elif abs(p[0]-0.001) < 1.e-6: + UnitName = "MM" + return UnitName + ## Shortcut to Import() for STEP format # # @ref swig_Import_Export "Example" @@ -3419,16 +3627,16 @@ class geompyDC(GEOM._objref_GEOM_Gen): # 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. - # @param theOptimumNbFaces If more than zero, unite faces only for those solids, - # that have more than theOptimumNbFaces faces. If zero, unite faces always, - # regardsless their quantity in the solid. If negative (the default value), - # do not unite faces at all. For blocks repairing recommended value is 6. + # @param doUnionFaces If True, then unite faces. If False (the default value), + # do not unite faces. # @return Improved shape. # # @ref swig_RemoveExtraEdges "Example" - def RemoveExtraEdges(self,theShape,theOptimumNbFaces=-1): + def RemoveExtraEdges(self, theShape, doUnionFaces=False): # Example: see GEOM_TestOthers.py - anObj = self.BlocksOp.RemoveExtraEdges(theShape,theOptimumNbFaces) + nbFacesOptimum = -1 # -1 means do not unite faces + if doUnionFaces is True: nbFacesOptimum = 0 # 0 means unite faces + anObj = self.BlocksOp.RemoveExtraEdges(theShape, nbFacesOptimum) RaiseIfFailed("RemoveExtraEdges", self.BlocksOp) return anObj @@ -3749,6 +3957,37 @@ class geompyDC(GEOM._objref_GEOM_Gen): def addPath(self,Path): if (sys.path.count(Path) < 1): sys.path.append(Path) + pass + pass + + ## Load marker texture from the file + # @param Path a path to the texture file + # @return unique texture identifier + # @ingroup l1_geompy_auxiliary + def LoadTexture(self, Path): + # Example: see GEOM_TestAll.py + ID = self.InsertOp.LoadTexture(Path) + RaiseIfFailed("LoadTexture", self.InsertOp) + return ID + + ## Add marker texture. @a Width and @a Height parameters + # specify width and height of the texture in pixels. + # If @a RowData is @c True, @a Texture parameter should represent texture data + # packed into the byte array. If @a RowData is @c False (default), @a Texture + # parameter should be unpacked string, in which '1' symbols represent opaque + # pixels and '0' represent transparent pixels of the texture bitmap. + # + # @param Width texture width in pixels + # @param Height texture height in pixels + # @param Texture texture data + # @param RowData if @c True, @a Texture data are packed in the byte stream + # @ingroup l1_geompy_auxiliary + def AddTexture(self, Width, Height, Texture, RowData=False): + # Example: see GEOM_TestAll.py + if not RowData: Texture = PackData(Texture) + ID = self.InsertOp.AddTexture(Width, Height, Texture) + RaiseIfFailed("AddTexture", self.InsertOp) + return ID import omniORB #Register the new proxy for GEOM_Gen