geom/src/GEOM_SWIG/batchmode_geompy.py

877 lines
29 KiB
Python
Raw Normal View History

2003-07-09 20:33:44 +06:00
# GEOM GEOM_SWIG : binding of C++ omplementaion with Python
#
2004-12-01 15:39:14 +05:00
# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# 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
2003-07-09 20:33:44 +06:00
#
#
#
# File : geompy.py
# Author : Paul RASCLE, EDF
# Module : GEOM
2003-05-12 21:24:23 +06:00
# $Header$
from batchmode_salome import *
2003-07-16 21:54:32 +06:00
import GEOM
2003-05-12 21:24:23 +06:00
2004-12-01 15:39:14 +05:00
g=None
step = 0
while step < 50 and g == None:
g = lcc.FindOrLoadComponent("FactoryServer", "GEOM")
step = step + 1
time.sleep(4)
geom = g._narrow( GEOM.GEOM_Gen )
2003-05-12 21:24:23 +06:00
myBuilder = myStudy.NewBuilder()
father = myStudy.FindComponent("GEOM")
if father is None:
father = myBuilder.NewComponent("GEOM")
2004-12-01 15:39:14 +05:00
A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName")
2003-05-12 21:24:23 +06:00
FName = A1._narrow(SALOMEDS.AttributeName)
2004-12-01 15:39:14 +05:00
FName.SetValue("Geometry")
A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap")
aPixmap = A2._narrow(SALOMEDS.AttributePixMap)
aPixmap.SetPixMap("ICON_OBJBROWSER_Geometry")
2003-05-12 21:24:23 +06:00
myBuilder.DefineComponentInstance(father,geom)
2004-12-17 16:18:33 +05:00
# * Get name for sub-shape aSubObj of shape aMainObj
#
2004-12-01 15:39:14 +05:00
def SubShapeName(aSubObj, aMainObj):
name = "SubShape"
2003-05-12 21:24:23 +06:00
print name
return name
2004-12-17 16:18:33 +05:00
# * Publish in study aShape with name aName
#
2003-05-12 21:24:23 +06:00
def addToStudy(aShape, aName):
2004-12-01 15:39:14 +05:00
try:
aSObject = geom.AddInStudy(myStudy, aShape, aName, None)
2003-05-12 21:24:23 +06:00
except:
2004-12-01 15:39:14 +05:00
print "addToStudy() failed"
return ""
return aShape.GetStudyEntry()
2003-05-12 21:24:23 +06:00
2004-12-17 16:18:33 +05:00
# * Publish in study aShape with name aName as sub-object of previously published aFather
#
2003-05-12 21:24:23 +06:00
def addToStudyInFather(aFather, aShape, aName):
2004-12-01 15:39:14 +05:00
try:
aSObject = geom.AddInStudy(myStudy, aShape, aName, aFather)
except:
print "addToStudyInFather() failed"
return ""
return aShape.GetStudyEntry()
# -----------------------------------------------------------------------------
# enumeration ShapeType as a dictionary
# -----------------------------------------------------------------------------
ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# 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
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
def MakeVertex(x,y,z):
2004-12-01 15:39:14 +05:00
anObj = BasicOp.MakePointXYZ(x,y,z)
if BasicOp.IsDone() == 0:
print "MakePointXYZ : ", BasicOp.GetErrorCode()
return anObj
def MakeVertexWithRef(vertex,x,y,z):
anObj = BasicOp.MakePointWithReference(vertex,x,y,z)
if BasicOp.IsDone() == 0:
print "MakePointWithReference : ", BasicOp.GetErrorCode()
return anObj
def MakeVertexOnCurve(curve,par):
anObj = BasicOp.MakePointOnCurve(curve,par)
if BasicOp.IsDone() == 0:
print "MakePointOnCurve : ", BasicOp.GetErrorCode()
return anObj
def MakeVectorDXDYDZ(dx,dy,dz):
anObj = BasicOp.MakeVectorDXDYDZ(dx,dy,dz)
if BasicOp.IsDone() == 0:
print "MakeVectorDXDYDZ : ", BasicOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeVector(p1,p2):
2004-12-01 15:39:14 +05:00
anObj = BasicOp.MakeVectorTwoPnt(p1, p2)
if BasicOp.IsDone() == 0:
print "MakeVectorTwoPnt : ", BasicOp.GetErrorCode()
return anObj
def MakeLine(p1, d1):
anObj = BasicOp.MakeLine(p1,d1)
if BasicOp.IsDone() == 0:
print "MakeLine : ", BasicOp.GetErrorCode()
return anObj
def MakeLineTwoPnt(p1, p2):
anObj = BasicOp.MakeLineTwoPnt(p1,p2)
if BasicOp.IsDone() == 0:
print "MakeLineTwoPnt : ", BasicOp.GetErrorCode()
return anObj
def MakePlane(p1,v1,trimsize):
anObj = BasicOp.MakePlanePntVec(p1,v1,trimsize)
if BasicOp.IsDone() == 0:
print "MakePlanePntVec : ", BasicOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakePlaneThreePnt(p1,p2,p3,trimsize):
anObj = BasicOp.MakePlaneThreePnt(p1,p2,p3,trimsize)
if BasicOp.IsDone() == 0:
print "MakePlaneThreePnt : ", BasicOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakePlaneFace(face,trimsize):
anObj = BasicOp.MakePlaneFace(face,trimsize)
if BasicOp.IsDone() == 0:
print "MakePlaneFace : ", BasicOp.GetErrorCode()
return anObj
def MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ):
anObj = BasicOp.MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ)
if BasicOp.IsDone() == 0:
print "MakeMarker : ", BasicOp.GetErrorCode()
return anObj
# -----------------------------------------------------------------------------
# Curves
# -----------------------------------------------------------------------------
2003-05-12 21:24:23 +06:00
def MakeArc(p1,p2,p3):
2004-12-01 15:39:14 +05:00
anObj = CurvesOp.MakeArc(p1,p2,p3)
if CurvesOp.IsDone() == 0:
print "MakeArc : ", CurvesOp.GetErrorCode()
return anObj
def MakeCircle(p1,v1,radius):
anObj = CurvesOp.MakeCirclePntVecR(p1,v1,radius)
if CurvesOp.IsDone() == 0:
print "MakeCirclePntVecR : ", CurvesOp.GetErrorCode()
return anObj
def MakeCircleThreePnt(p1,p2,p3):
anObj = CurvesOp.MakeCircleThreePnt(p1,p2,p3)
if CurvesOp.IsDone() == 0:
print "MakeCircleThreePnt : ", CurvesOp.GetErrorCode()
return anObj
def MakeEllipse(p1,v1,radiusMaj,radiusMin):
anObj = CurvesOp.MakeEllipse(p1,v1,radiusMaj, radiusMin)
if CurvesOp.IsDone() == 0:
print "MakeEllipse : ", CurvesOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakePolyline(ListShape):
anObj = CurvesOp.MakePolyline(ListShape)
if CurvesOp.IsDone() == 0:
print "MakePolyline : ", CurvesOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeBezier(ListShape):
anObj = CurvesOp.MakeSplineBezier(ListShape)
if CurvesOp.IsDone() == 0:
print "MakeSplineBezier : ", CurvesOp.GetErrorCode()
2004-06-16 21:24:55 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeInterpol(ListShape):
anObj = CurvesOp.MakeSplineInterpolation(ListShape)
if CurvesOp.IsDone() == 0:
print "MakeSplineInterpolation : ", CurvesOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
# <WPL>: Nine double values, defining origin,
# OZ and OX directions of the working plane.
def MakeSketcher(Cmd, WPL = [0,0,0, 0,0,1, 1,0,0]):
anObj = CurvesOp.MakeSketcher(Cmd, WPL)
if CurvesOp.IsDone() == 0:
print "MakeSketcher : ", CurvesOp.GetErrorCode()
2004-06-16 21:24:55 +06:00
return anObj
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Create 3D Primitives
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
def MakeBox(x1,y1,z1,x2,y2,z2):
2004-12-01 15:39:14 +05:00
pnt1 = MakeVertex(x1,y1,z1)
pnt2 = MakeVertex(x2,y2,z2)
return MakeBoxTwoPnt(pnt1,pnt2)
def MakeBoxDXDYDZ(dx,dy,dz):
anObj = PrimOp.MakeBoxDXDYDZ(dx,dy,dz)
if PrimOp.IsDone() == 0:
print "MakeBoxDXDYDZ : ", PrimOp.GetErrorCode()
return anObj
def MakeBoxTwoPnt(point1, point2):
anObj = PrimOp.MakeBoxTwoPnt(point1, point2)
if PrimOp.IsDone() == 0:
print "MakeBoxTwoPnt : ", PrimOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeCylinder(p1,v1,radius,height):
anObj = PrimOp.MakeCylinderPntVecRH(p1,v1,radius,height)
if PrimOp.IsDone() == 0:
print "MakeCylinderPntVecRH : ", PrimOp.GetErrorCode()
return anObj
def MakeCylinderRH(radius,height):
anObj = PrimOp.MakeCylinderRH(radius,height)
if PrimOp.IsDone() == 0:
print "MakeCylinderRH : ", PrimOp.GetErrorCode()
return anObj
def MakeSpherePntR(point,radius):
anObj = PrimOp.MakeSpherePntR(point,radius)
if PrimOp.IsDone() == 0:
print "MakeSpherePntR : ", PrimOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeSphere(x,y,z,radius):
2004-12-01 15:39:14 +05:00
point = MakeVertex(x,y,z)
anObj = MakeSpherePntR(point,radius)
return anObj
def MakeSphereR(radius):
anObj = PrimOp.MakeSphereR(radius)
if PrimOp.IsDone() == 0:
print "MakeSphereR : ", PrimOp.GetErrorCode()
return anObj
def MakeCone(p1,v1,radius1,radius2,height):
anObj = PrimOp.MakeConePntVecR1R2H(p1,v1,radius1,radius2,height)
if PrimOp.IsDone() == 0:
print "MakeConePntVecR1R2H : ", PrimOp.GetErrorCode()
return anObj
def MakeConeR1R2H(radius1,radius2,height):
anObj = PrimOp.MakeConeR1R2H(radius1,radius2,height)
if PrimOp.IsDone() == 0:
print "MakeConeR1R2H : ", PrimOp.GetErrorCode()
return anObj
def MakeTorus(p1,v1,major_radius,minor_radius):
anObj = PrimOp.MakeTorusPntVecRR(p1,v1,major_radius,minor_radius)
if PrimOp.IsDone() == 0:
print "MakeTorusPntVecRR : ", PrimOp.GetErrorCode()
return anObj
def MakeTorusRR(major_radius,minor_radius):
anObj = PrimOp.MakeTorusRR(major_radius,minor_radius)
if PrimOp.IsDone() == 0:
print "MakeTorusRR : ", PrimOp.GetErrorCode()
return anObj
def MakePrism(baseShape,point1,point2):
anObj = PrimOp.MakePrismTwoPnt(baseShape,point1,point2)
if PrimOp.IsDone() == 0:
print "MakePrismTwoPnt : ", PrimOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakePrismVecH(baseShape,vector,height):
anObj = PrimOp.MakePrismVecH(baseShape,vector,height)
if PrimOp.IsDone() == 0:
print "MakePrismVecH : ", PrimOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakePipe(baseShape,pathShape):
anObj = PrimOp.MakePipe(baseShape,pathShape)
if PrimOp.IsDone() == 0:
print "MakePipe : ", PrimOp.GetErrorCode()
return anObj
def MakeRevolution(aShape,axis,angle):
anObj = PrimOp.MakeRevolutionAxisAngle(aShape,axis,angle)
if PrimOp.IsDone() == 0:
print "MakeRevolutionAxisAngle : ", PrimOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Create base shapes
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
def MakeEdge(p1,p2):
2004-12-01 15:39:14 +05:00
anObj = ShapesOp.MakeEdge(p1,p2)
if ShapesOp.IsDone() == 0:
print "MakeEdge : ", ShapesOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeWire(ListShape):
2004-12-01 15:39:14 +05:00
anObj = ShapesOp.MakeWire(ListShape)
if ShapesOp.IsDone() == 0:
print "MakeWire : ", ShapesOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeFace(aShapeWire,WantPlanarFace):
2004-12-01 15:39:14 +05:00
anObj = ShapesOp.MakeFace(aShapeWire,WantPlanarFace)
if ShapesOp.IsDone() == 0:
print "MakeFace : ", ShapesOp.GetErrorCode()
return anObj
def MakeFaceWires(ListWires,WantPlanarFace):
anObj = ShapesOp.MakeFaceWires(ListWires,WantPlanarFace)
if ShapesOp.IsDone() == 0:
print "MakeFaceWires : ", ShapesOp.GetErrorCode()
return anObj
def MakeFaces(ListWires,WantPlanarFace):
anObj = MakeFaceWires(ListWires,WantPlanarFace)
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeShell(ListOfShapes):
anObj = ShapesOp.MakeShell(ListOfShapes)
if ShapesOp.IsDone() == 0:
print "MakeShell : ", ShapesOp.GetErrorCode()
return anObj
def MakeSolid(ListOfShells):
anObj = ShapesOp.MakeSolidShells(ListOfShells)
if ShapesOp.IsDone() == 0:
print "MakeSolid : ", ShapesOp.GetErrorCode()
2004-06-16 21:24:55 +06:00
return anObj
2003-05-12 21:24:23 +06:00
def MakeCompound(ListShape):
2004-12-01 15:39:14 +05:00
anObj = ShapesOp.MakeCompound(ListShape)
if ShapesOp.IsDone() == 0:
print "MakeCompound : ", ShapesOp.GetErrorCode()
return anObj
def ChangeOrientation(Shape):
anObj = ShapesOp.ChangeOrientation(Shape)
if ShapesOp.IsDone() == 0:
print "ChangeOrientation : ", ShapesOp.GetErrorCode()
return anObj
def OrientationChange(Shape):
anObj = ChangeOrientation(Shape)
2003-05-12 21:24:23 +06:00
return anObj
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Access to sub-shapes by their unique IDs inside the main shape.
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Obtain a composite sub-shape of <aShape>, composed from sub-shapes
# of <aShape>, selected by their unique IDs inside <aShape>
def GetSubShape(aShape, ListOfID):
anObj = geom.AddSubShape(aShape,ListOfID)
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
# Obtain unique ID of sub-shape <aSubShape> inside <aShape>
def GetSubShapeID(aShape, aSubShape):
anID = LocalOp.GetSubShapeIndex(aShape, aSubShape)
if LocalOp.IsDone() == 0:
print "GetSubShapeIndex : ", LocalOp.GetErrorCode()
return anID
# -----------------------------------------------------------------------------
# Decompose objects
# -----------------------------------------------------------------------------
def SubShapeAll(aShape, aType):
ListObj = ShapesOp.MakeExplode(aShape,aType,0)
if ShapesOp.IsDone() == 0:
print "MakeExplode : ", ShapesOp.GetErrorCode()
return ListObj
def SubShapeAllSorted(aShape,aType):
ListObj = ShapesOp.MakeExplode(aShape,aType,1)
if ShapesOp.IsDone() == 0:
print "MakeExplode : ", ShapesOp.GetErrorCode()
return ListObj
# Obtain a compound of sub-shapes of <aShape>,
# selected by they indices in list of all sub-shapes of type <aType>
def SubShape(aShape, aType, ListOfInd):
ListOfIDs = []
AllShapeList = SubShapeAll(aShape, aType)
for ind in ListOfInd:
ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
anObj = GetSubShape(aShape, ListOfIDs)
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
# Obtain a compound of sub-shapes of <aShape>,
# selected by they indices in sorted list of all sub-shapes of type <aType>
def SubShapeSorted(aShape, aType, ListOfInd):
ListOfIDs = []
AllShapeList = SubShapeAllSorted(aShape, aType)
for ind in ListOfInd:
ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
anObj = GetSubShape(aShape, ListOfIDs)
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
# -----------------------------------------------------------------------------
# Healing operations
# -----------------------------------------------------------------------------
def ProcessShape(Shape, Operators, Parameters, Values):
anObj = HealOp.ProcessShape(Shape, Operators, Parameters, Values)
if HealOp.IsDone() == 0:
print "ProcessShape : ", HealOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def SuppressFaces(aShape,ListOfId):
anObj = HealOp.SuppressFaces(aShape,ListOfId)
if HealOp.IsDone() == 0:
print "SuppressFaces : ", HealOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeSewing(ListShape,precision):
2004-12-01 15:39:14 +05:00
comp = MakeCompound(ListShape)
anObj = Sew(comp,precision)
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def Sew(aShape,precision):
anObj = HealOp.Sew(aShape,precision)
if HealOp.IsDone() == 0:
print "Sew : ", HealOp.GetErrorCode()
return anObj
2003-05-12 21:24:23 +06:00
2004-12-01 15:39:14 +05:00
def SuppressInternalWires(aShape, Wires):
anObj = HealOp.RemoveIntWires(aShape, Wires)
if HealOp.IsDone() == 0:
print "SuppressInternalWires : ", HealOp.GetErrorCode()
return anObj
def SuppressHoles(aShape, ListOfId):
anObj = HealOp.FillHoles(aShape,ListOfId)
if HealOp.IsDone() == 0:
print "SuppressHoles : ", HealOp.GetErrorCode()
return anObj
def CloseContour(aShape, Wires, IsCommonVertex):
anObj = HealOp.CloseContour(aShape, Wires, IsCommonVertex)
if HealOp.IsDone() == 0:
print "CloseContour : ", HealOp.GetErrorCode()
return anObj
def DivideEdge(aShape, EdgeID, Value, IsByParameter):
anObj = HealOp.DivideEdge(aShape, EdgeID, Value, IsByParameter)
if HealOp.IsDone() == 0:
print "DivideEdge : ", HealOp.GetErrorCode()
return anObj
def GetFreeBoundary(Shape):
anObj = HealOp.GetFreeBoundary(Shape)
if HealOp.IsDone() == 0:
print "GetFreeBoundaries : ", HealOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Create advanced objects
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
def MakeCopy(aShape):
anObj = InsertOp.MakeCopy(aShape)
if InsertOp.IsDone() == 0:
print "MakeCopy : ", InsertOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeFilling(aShape,mindeg,maxdeg,tol2d,tol3d,nbiter):
anObj = PrimOp.MakeFilling(aShape,mindeg,maxdeg,tol2d,tol3d,nbiter)
if PrimOp.IsDone() == 0:
print "MakeFilling : ", PrimOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeGlueFaces(aShape,aTolerance):
anObj = ShapesOp.MakeGlueFaces(aShape,aTolerance)
if ShapesOp.IsDone() == 0:
print "MakeGlueFaces : ", ShapesOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
# -----------------------------------------------------------------------------
# Boolean (Common, Cut, Fuse, Section)
# -----------------------------------------------------------------------------
2003-05-12 21:24:23 +06:00
2004-12-01 15:39:14 +05:00
def MakeBoolean(shape1,shape2,operation):
anObj = BoolOp.MakeBoolean(shape1,shape2,operation)
if BoolOp.IsDone() == 0:
print "MakeBoolean : ", BoolOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeCommon(s1, s2):
return MakeBoolean(s1, s2, 1)
def MakeCut(s1, s2):
return MakeBoolean(s1, s2, 2)
def MakeFuse(s1, s2):
return MakeBoolean(s1, s2, 3)
def MakeSection(s1, s2):
return MakeBoolean(s1, s2, 4)
def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
anObj = BoolOp.MakePartition(ListShapes, ListTools,
ListKeepInside, ListRemoveInside,
Limit, RemoveWebs, ListMaterials);
if BoolOp.IsDone() == 0:
print "MakePartition : ", BoolOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def Partition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
anObj = MakePartition(ListShapes, ListTools,
ListKeepInside, ListRemoveInside,
Limit, RemoveWebs, ListMaterials);
2003-05-12 21:24:23 +06:00
return anObj
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Transform objects
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
def MakeTranslationTwoPoints(aShape,point1,point2):
anObj = TrsfOp.TranslateTwoPointsCopy(aShape,point1,point2)
if TrsfOp.IsDone() == 0:
print "TranslateTwoPointsCopy : ", TrsfOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeTranslation(aShape,dx,dy,dz):
anObj = TrsfOp.TranslateDXDYDZCopy(aShape,dx,dy,dz)
if TrsfOp.IsDone() == 0:
print "TranslateDXDYDZCopy : ", TrsfOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeRotation(aShape,axis,angle):
anObj = TrsfOp.RotateCopy(aShape,axis,angle)
if TrsfOp.IsDone() == 0:
print "RotateCopy : ", TrsfOp.GetErrorCode()
return anObj
2003-05-12 21:24:23 +06:00
2004-12-01 15:39:14 +05:00
def MakeScaleTransform(aShape,theCenterofScale,factor):
anObj = TrsfOp.ScaleShapeCopy(aShape,theCenterofScale,factor)
if TrsfOp.IsDone() == 0:
print "ScaleShapeCopy : ", TrsfOp.GetErrorCode()
return anObj
2003-05-12 21:24:23 +06:00
2004-12-01 15:39:14 +05:00
def MakeMirrorByPlane(aShape,aPlane):
anObj = TrsfOp.MirrorPlaneCopy(aShape,aPlane)
if TrsfOp.IsDone() == 0:
print "MirrorPlaneCopy : ", TrsfOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakePosition(aShape,theStartLCS,theEndLCS):
anObj = TrsfOp.PositionShapeCopy(aShape,theStartLCS,theEndLCS)
if TrsfOp.IsDone() == 0:
print "PositionShapeCopy : ", TrsfOp.GetErrorCode()
return anObj
2003-05-12 21:24:23 +06:00
2004-12-01 15:39:14 +05:00
def MakeOffset(aShape, anOffset):
anObj = TrsfOp.OffsetShapeCopy(aShape, anOffset)
if TrsfOp.IsDone() == 0:
print "OffsetShapeCopy : ", TrsfOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
# -----------------------------------------------------------------------------
# Patterns
# -----------------------------------------------------------------------------
def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
2004-12-01 15:39:14 +05:00
anObj = TrsfOp.MultiTranslate1D(aShape,aDir,aStep,aNbTimes)
if TrsfOp.IsDone() == 0:
print "MultiTranslate1D : ", TrsfOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2):
2004-12-01 15:39:14 +05:00
anObj = TrsfOp.MultiTranslate2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2)
if TrsfOp.IsDone() == 0:
print "MultiTranslate2D : ", TrsfOp.GetErrorCode()
return anObj
def MultiRotate1D(aShape,aVec,aNbTimes):
anObj = TrsfOp.MultiRotate1D(aShape,aVec,aNbTimes)
if TrsfOp.IsDone() == 0:
print "MultiRotate1D : ", TrsfOp.GetErrorCode()
return anObj
def MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2):
anObj = TrsfOp.MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
if TrsfOp.IsDone() == 0:
print "MultiRotate2D : ", TrsfOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
2004-12-01 15:39:14 +05:00
aVec = MakeLine(aPoint,aDir)
anObj = MultiRotate1D(aShape,aVec,aNbTimes)
2003-05-12 21:24:23 +06:00
return anObj
def MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2):
2004-12-01 15:39:14 +05:00
aVec = MakeLine(aPoint,aDir)
anObj = MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
2003-05-12 21:24:23 +06:00
return anObj
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Local operations
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
def MakeFilletAll(aShape,radius):
anObj = LocalOp.MakeFilletAll(aShape,radius)
if LocalOp.IsDone() == 0:
print "MakeFilletAll : ", LocalOp.GetErrorCode()
return anObj
def MakeFillet(aShape,radius,aShapeType,ListShape):
anObj = None
if aShapeType == ShapeType["EDGE"]:
anObj = LocalOp.MakeFilletEdges(aShape,radius,ListShape)
else:
anObj = LocalOp.MakeFilletFaces(aShape,radius,ListShape)
if LocalOp.IsDone() == 0:
print "MakeFillet : ", LocalOp.GetErrorCode()
return anObj
def MakeChamferAll(aShape,d):
anObj = LocalOp.MakeChamferAll(aShape,d)
if LocalOp.IsDone() == 0:
print "MakeChamferAll : ", LocalOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeChamferEdge(aShape,d1,d2,face1,face2):
anObj = LocalOp.MakeChamferEdge(aShape,d1,d2,face1,face2)
if LocalOp.IsDone() == 0:
print "MakeChamferEdge : ", LocalOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeChamferFaces(aShape,d1,d2,ListShape):
anObj = LocalOp.MakeChamferFaces(aShape,d1,d2,ListShape)
if LocalOp.IsDone() == 0:
print "MakeChamferFaces : ", LocalOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeChamfer(aShape,d1,d2,aShapeType,ListShape):
anObj = None
if aShapeType == ShapeType["EDGE"]:
anObj = MakeChamferEdge(aShape,d1,d2,ListShape[0],ListShape[1])
else:
anObj = MakeChamferFaces(aShape,d1,d2,ListShape)
return anObj
def Archimede(aShape,weight,WaterDensity,MeshingDeflection):
anObj = LocalOp.MakeArchimede(aShape,weight,WaterDensity,MeshingDeflection)
if LocalOp.IsDone() == 0:
print "MakeArchimede : ", LocalOp.GetErrorCode()
return anObj
# -----------------------------------------------------------------------------
# Information objects
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
def PointCoordinates(Point):
aTuple = MeasuOp.PointCoordinates(Point)
if MeasuOp.IsDone() == 0:
print "PointCoordinates : ", MeasuOp.GetErrorCode()
return aTuple
def BasicProperties(Shape):
aTuple = MeasuOp.GetBasicProperties(Shape)
if MeasuOp.IsDone() == 0:
print "BasicProperties : ", MeasuOp.GetErrorCode()
return aTuple
def BoundingBox(Shape):
aTuple = MeasuOp.GetBoundingBox(Shape)
if MeasuOp.IsDone() == 0:
print "BoundingBox : ", MeasuOp.GetErrorCode()
return aTuple
def Inertia(Shape):
aTuple = MeasuOp.GetInertia(Shape)
if MeasuOp.IsDone() == 0:
print "Inertia : ", MeasuOp.GetErrorCode()
return aTuple
def MinDistance(Shape1, Shape2):
aTuple = MeasuOp.GetMinDistance(Shape1, Shape2)
if MeasuOp.IsDone() == 0:
print "MinDistance : ", MeasuOp.GetErrorCode()
return aTuple[0]
def Tolerance(Shape):
aTuple = MeasuOp.GetTolerance(Shape)
if MeasuOp.IsDone() == 0:
print "Tolerance : ", MeasuOp.GetErrorCode()
return aTuple
def WhatIs(Shape):
aDescr = MeasuOp.WhatIs(Shape)
if MeasuOp.IsDone() == 0:
print "WhatIs : ", MeasuOp.GetErrorCode()
return aDescr
def MakeCDG(aShape):
anObj = MeasuOp.GetCentreOfMass(aShape)
if MeasuOp.IsDone() == 0:
print "GetCentreOfMass : ", MeasuOp.GetErrorCode()
return anObj
def CheckShape(aShape):
(IsValid, Status) = MeasuOp.CheckShape(aShape)
if MeasuOp.IsDone() == 0:
print "CheckShape : ", MeasuOp.GetErrorCode()
else:
if IsValid == 0:
print Status
return IsValid
# -----------------------------------------------------------------------------
# Import/Export objects
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
def Import(filename, formatname):
anObj = InsertOp.Import(filename, formatname)
if InsertOp.IsDone() == 0:
print "Import : ", InsertOp.GetErrorCode()
return anObj
2003-05-12 21:24:23 +06:00
2004-12-17 16:18:33 +05:00
def ImportBREP(theFileName):
return Import(theFileName, "BREP")
def ImportIGES(theFileName):
return Import(theFileName, "IGES")
def ImportSTEP(theFileName):
return Import(theFileName, "STEP")
2004-12-01 15:39:14 +05:00
def Export(aShape, filename, formatname):
InsertOp.Export(aShape, filename, formatname)
if InsertOp.IsDone() == 0:
print "Export : ", InsertOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
2004-12-17 16:18:33 +05:00
def ExportBREP(theObject, theFileName):
return Export(theObject, theFileName, "BREP")
def ExportIGES(theObject, theFileName):
return Export(theObject, theFileName, "IGES")
def ExportSTEP(theObject, theFileName):
return Export(theObject, theFileName, "STEP")
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
# Block operations
2003-05-12 21:24:23 +06:00
# -----------------------------------------------------------------------------
2004-12-01 15:39:14 +05:00
def MakeQuad(E1, E2, E3, E4):
anObj = BlocksOp.MakeQuad(E1, E2, E3, E4)
if BlocksOp.IsDone() == 0:
print "MakeQuad : ", BlocksOp.GetErrorCode()
return anObj
def MakeQuad2Edges(E1, E2):
anObj = BlocksOp.MakeQuad2Edges(E1, E2)
if BlocksOp.IsDone() == 0:
print "MakeQuad2Edges : ", BlocksOp.GetErrorCode()
return anObj
def MakeQuad4Vertices(V1, V2, V3, V4):
anObj = BlocksOp.MakeQuad4Vertices(V1, V2, V3, V4)
if BlocksOp.IsDone() == 0:
print "MakeQuad4Vertices : ", BlocksOp.GetErrorCode()
return anObj
def MakeHexa(F1, F2, F3, F4, F5, F6):
anObj = BlocksOp.MakeHexa(F1, F2, F3, F4, F5, F6)
if BlocksOp.IsDone() == 0:
print "MakeHexa : ", BlocksOp.GetErrorCode()
return anObj
def MakeHexa2Faces(F1, F2):
anObj = BlocksOp.MakeHexa2Faces(F1, F2)
if BlocksOp.IsDone() == 0:
print "MakeHexa2Faces : ", BlocksOp.GetErrorCode()
return anObj
def MakeMultiTransformation1D(Block, DirFaceID1, DirFaceID2, NbTimes):
anObj = BlocksOp.MakeMultiTransformation1D(Block, DirFaceID1, DirFaceID2, NbTimes)
if BlocksOp.IsDone() == 0:
print "MakeMultiTransformation1D : ", BlocksOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeMultiTransformation2D(Block, DirFaceID1U, DirFaceID2U, NbTimesU,
DirFaceID1V, DirFaceID2V, NbTimesV):
anObj = BlocksOp.MakeMultiTransformation2D(Block, DirFaceID1U, DirFaceID2U, NbTimesU,
DirFaceID1V, DirFaceID2V, NbTimesV)
if BlocksOp.IsDone() == 0:
print "MakeMultiTransformation2D : ", BlocksOp.GetErrorCode()
2003-05-12 21:24:23 +06:00
return anObj
2004-12-01 15:39:14 +05:00
def MakeBlockExplode(Compound, MinNbFaces, MaxNbFaces):
aList = BlocksOp.ExplodeCompoundOfBlocks(Compound, MinNbFaces, MaxNbFaces)
if BlocksOp.IsDone() == 0:
print "MakeBlockExplode : ", BlocksOp.GetErrorCode()
return aList
def CheckCompoundOfBlocks(Compound):
(IsValid, BCErrors) = BlocksOp.CheckCompoundOfBlocks(Compound)
if BlocksOp.IsDone() == 0:
print "CheckCompoundOfBlocks : ", BlocksOp.GetErrorCode()
else:
if IsValid == 0:
Descr = BlocksOp.PrintBCErrors(Compound, BCErrors)
print Descr
return IsValid
# -----------------------------------------------------------------------------
# Group operations
# -----------------------------------------------------------------------------
def CreateGroup(MainShape, ShapeType):
anObj = GroupOp.CreateGroup(MainShape, ShapeType)
if GroupOp.IsDone() == 0:
print "CreateGroup : ", GroupOp.GetErrorCode()
return anObj
def AddObject(Group, SubShapeID):
GroupOp.AddObject(Group, SubShapeID)
if GroupOp.IsDone() == 0:
print "AddObject : ", GroupOp.GetErrorCode()
def RemoveObject(Group, SubShapeID):
GroupOp.RemoveObject(Group, SubShapeID)
if GroupOp.IsDone() == 0:
print "RemoveObject : ", GroupOp.GetErrorCode()
def GetObjectIDs(Group):
ListIDs = GroupOp.GetObjects(Group)
if GroupOp.IsDone() == 0:
print "GetObjectIDs : ", GroupOp.GetErrorCode()
return ListIDs
def addPath(Path):
if (sys.path.count(Path) < 1):
sys.path.append(Path)