1 # GEOM GEOM_SWIG : binding of C++ omplementaion with Python
3 # Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
25 # Author : Paul RASCLE, EDF
29 from batchmode_salome import *
34 while step < 50 and g == None:
35 g = lcc.FindOrLoadComponent("FactoryServer", "GEOM")
38 geom = g._narrow( GEOM.GEOM_Gen )
57 def init_geom(theStudy):
59 global myStudy, myBuilder, myStudyId, BasicOp, CurvesOp, PrimOp, ShapesOp, HealOp
60 global InsertOp, BoolOp, TrsfOp, LocalOp, MeasuOp, BlocksOp, GroupOp, father
63 myStudyId = myStudy._get_StudyId()
64 myBuilder = myStudy.NewBuilder()
65 father = myStudy.FindComponent("GEOM")
67 father = myBuilder.NewComponent("GEOM")
68 A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName")
69 FName = A1._narrow(SALOMEDS.AttributeName)
70 FName.SetValue("Geometry")
71 A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap")
72 aPixmap = A2._narrow(SALOMEDS.AttributePixMap)
73 aPixmap.SetPixMap("ICON_OBJBROWSER_Geometry")
74 myBuilder.DefineComponentInstance(father,geom)
77 # -----------------------------------------------------------------------------
78 # Assign Operations Interfaces
79 # -----------------------------------------------------------------------------
81 BasicOp = geom.GetIBasicOperations (myStudyId)
82 CurvesOp = geom.GetICurvesOperations (myStudyId)
83 PrimOp = geom.GetI3DPrimOperations (myStudyId)
84 ShapesOp = geom.GetIShapesOperations (myStudyId)
85 HealOp = geom.GetIHealingOperations (myStudyId)
86 InsertOp = geom.GetIInsertOperations (myStudyId)
87 BoolOp = geom.GetIBooleanOperations (myStudyId)
88 TrsfOp = geom.GetITransformOperations(myStudyId)
89 LocalOp = geom.GetILocalOperations (myStudyId)
90 MeasuOp = geom.GetIMeasureOperations (myStudyId)
91 BlocksOp = geom.GetIBlocksOperations (myStudyId)
92 GroupOp = geom.GetIGroupOperations (myStudyId)
97 # * Get name for sub-shape aSubObj of shape aMainObj
99 def SubShapeName(aSubObj, aMainObj):
104 # * Publish in study aShape with name aName
106 def addToStudy(aShape, aName):
108 aSObject = geom.AddInStudy(myStudy, aShape, aName, None)
110 print "addToStudy() failed"
112 return aShape.GetStudyEntry()
114 # * Publish in study aShape with name aName as sub-object of previously published aFather
116 def addToStudyInFather(aFather, aShape, aName):
118 aSObject = geom.AddInStudy(myStudy, aShape, aName, aFather)
120 print "addToStudyInFather() failed"
122 return aShape.GetStudyEntry()
124 # -----------------------------------------------------------------------------
125 # enumeration ShapeType as a dictionary
126 # -----------------------------------------------------------------------------
128 ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
130 # -----------------------------------------------------------------------------
132 # -----------------------------------------------------------------------------
134 def MakeVertex(theX, theY, theZ):
135 anObj = BasicOp.MakePointXYZ(theX, theY, theZ)
136 if BasicOp.IsDone() == 0:
137 print "MakePointXYZ : ", BasicOp.GetErrorCode()
140 def MakeVertexWithRef(vertex,x,y,z):
141 anObj = BasicOp.MakePointWithReference(vertex,x,y,z)
142 if BasicOp.IsDone() == 0:
143 print "MakePointWithReference : ", BasicOp.GetErrorCode()
146 def MakeVertexOnCurve(curve,par):
147 anObj = BasicOp.MakePointOnCurve(curve,par)
148 if BasicOp.IsDone() == 0:
149 print "MakePointOnCurve : ", BasicOp.GetErrorCode()
152 def MakeVectorDXDYDZ(dx,dy,dz):
153 anObj = BasicOp.MakeVectorDXDYDZ(dx,dy,dz)
154 if BasicOp.IsDone() == 0:
155 print "MakeVectorDXDYDZ : ", BasicOp.GetErrorCode()
158 def MakeVector(p1,p2):
159 anObj = BasicOp.MakeVectorTwoPnt(p1, p2)
160 if BasicOp.IsDone() == 0:
161 print "MakeVectorTwoPnt : ", BasicOp.GetErrorCode()
164 def MakeLine(p1, d1):
165 anObj = BasicOp.MakeLine(p1,d1)
166 if BasicOp.IsDone() == 0:
167 print "MakeLine : ", BasicOp.GetErrorCode()
170 def MakeLineTwoPnt(p1, p2):
171 anObj = BasicOp.MakeLineTwoPnt(p1,p2)
172 if BasicOp.IsDone() == 0:
173 print "MakeLineTwoPnt : ", BasicOp.GetErrorCode()
176 def MakePlane(p1,v1,trimsize):
177 anObj = BasicOp.MakePlanePntVec(p1,v1,trimsize)
178 if BasicOp.IsDone() == 0:
179 print "MakePlanePntVec : ", BasicOp.GetErrorCode()
182 def MakePlaneThreePnt(p1,p2,p3,trimsize):
183 anObj = BasicOp.MakePlaneThreePnt(p1,p2,p3,trimsize)
184 if BasicOp.IsDone() == 0:
185 print "MakePlaneThreePnt : ", BasicOp.GetErrorCode()
188 def MakePlaneFace(face,trimsize):
189 anObj = BasicOp.MakePlaneFace(face,trimsize)
190 if BasicOp.IsDone() == 0:
191 print "MakePlaneFace : ", BasicOp.GetErrorCode()
194 def MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ):
195 anObj = BasicOp.MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ)
196 if BasicOp.IsDone() == 0:
197 print "MakeMarker : ", BasicOp.GetErrorCode()
200 def MakeMarkerPntTwoVec(theOrigin, theXVec, theYVec):
202 * Create a local coordinate system.
203 * \param theOrigin Point of coordinate system origin.
204 * \param theXVec Vector of X direction
205 * \param theYVec Vector of Y direction
206 * \return New GEOM_Object, containing the created coordinate system.
208 O = PointCoordinates( theOrigin )
210 for vec in [ theXVec, theYVec ]:
211 v1, v2 = SubShapeAll( vec, ShapeType["VERTEX"] )
212 p1 = PointCoordinates( v1 )
213 p2 = PointCoordinates( v2 )
214 for i in range( 0, 3 ):
215 OXOY.append( p2[i] - p1[i] )
217 anObj = BasicOp.MakeMarker( O[0], O[1], O[2],
218 OXOY[0], OXOY[1], OXOY[2],
219 OXOY[3], OXOY[4], OXOY[5], )
220 if BasicOp.IsDone() == 0:
221 print "MakeMarker : ", BasicOp.GetErrorCode()
224 # -----------------------------------------------------------------------------
226 # -----------------------------------------------------------------------------
228 def MakeArc(p1,p2,p3):
229 anObj = CurvesOp.MakeArc(p1,p2,p3)
230 if CurvesOp.IsDone() == 0:
231 print "MakeArc : ", CurvesOp.GetErrorCode()
234 def MakeCircle(p1,v1,radius):
235 anObj = CurvesOp.MakeCirclePntVecR(p1,v1,radius)
236 if CurvesOp.IsDone() == 0:
237 print "MakeCirclePntVecR : ", CurvesOp.GetErrorCode()
240 def MakeCircleThreePnt(p1,p2,p3):
241 anObj = CurvesOp.MakeCircleThreePnt(p1,p2,p3)
242 if CurvesOp.IsDone() == 0:
243 print "MakeCircleThreePnt : ", CurvesOp.GetErrorCode()
246 def MakeEllipse(p1,v1,radiusMaj,radiusMin):
247 anObj = CurvesOp.MakeEllipse(p1,v1,radiusMaj, radiusMin)
248 if CurvesOp.IsDone() == 0:
249 print "MakeEllipse : ", CurvesOp.GetErrorCode()
252 def MakePolyline(ListShape):
253 anObj = CurvesOp.MakePolyline(ListShape)
254 if CurvesOp.IsDone() == 0:
255 print "MakePolyline : ", CurvesOp.GetErrorCode()
258 def MakeBezier(ListShape):
259 anObj = CurvesOp.MakeSplineBezier(ListShape)
260 if CurvesOp.IsDone() == 0:
261 print "MakeSplineBezier : ", CurvesOp.GetErrorCode()
264 def MakeInterpol(ListShape):
265 anObj = CurvesOp.MakeSplineInterpolation(ListShape)
266 if CurvesOp.IsDone() == 0:
267 print "MakeSplineInterpolation : ", CurvesOp.GetErrorCode()
270 # <WPL>: Nine double values, defining origin,
271 # OZ and OX directions of the working plane.
272 def MakeSketcher(Cmd, WPL = [0,0,0, 0,0,1, 1,0,0]):
273 anObj = CurvesOp.MakeSketcher(Cmd, WPL)
274 if CurvesOp.IsDone() == 0:
275 print "MakeSketcher : ", CurvesOp.GetErrorCode()
278 def MakeSketcherOnPlane(theCommand, theWorkingPlane):
280 * Create a sketcher (wire or face), following the textual description,
281 * passed through \a theCommand argument. \n
282 * For format of the description string see the previous method.\n
283 * \param theCommand String, defining the sketcher in local
284 * coordinates of the working plane.
285 * \param theWorkingPlane Planar Face of the working plane.
286 * \return New GEOM_Object, containing the created wire.
288 anObj = CurvesOp.MakeSketcherOnPlane(theCommand, theWorkingPlane)
289 if CurvesOp.IsDone() == 0:
290 print "MakeSketcher : ", CurvesOp.GetErrorCode()
293 # -----------------------------------------------------------------------------
294 # Create 3D Primitives
295 # -----------------------------------------------------------------------------
297 def MakeBox(x1,y1,z1,x2,y2,z2):
298 pnt1 = MakeVertex(x1,y1,z1)
299 pnt2 = MakeVertex(x2,y2,z2)
300 return MakeBoxTwoPnt(pnt1,pnt2)
302 def MakeBoxDXDYDZ(dx,dy,dz):
303 anObj = PrimOp.MakeBoxDXDYDZ(dx,dy,dz)
304 if PrimOp.IsDone() == 0:
305 print "MakeBoxDXDYDZ : ", PrimOp.GetErrorCode()
308 def MakeBoxTwoPnt(point1, point2):
309 anObj = PrimOp.MakeBoxTwoPnt(point1, point2)
310 if PrimOp.IsDone() == 0:
311 print "MakeBoxTwoPnt : ", PrimOp.GetErrorCode()
314 def MakeCylinder(p1,v1,radius,height):
315 anObj = PrimOp.MakeCylinderPntVecRH(p1,v1,radius,height)
316 if PrimOp.IsDone() == 0:
317 print "MakeCylinderPntVecRH : ", PrimOp.GetErrorCode()
320 def MakeCylinderRH(radius,height):
321 anObj = PrimOp.MakeCylinderRH(radius,height)
322 if PrimOp.IsDone() == 0:
323 print "MakeCylinderRH : ", PrimOp.GetErrorCode()
326 def MakeSpherePntR(point,radius):
327 anObj = PrimOp.MakeSpherePntR(point,radius)
328 if PrimOp.IsDone() == 0:
329 print "MakeSpherePntR : ", PrimOp.GetErrorCode()
332 def MakeSphere(x,y,z,radius):
333 point = MakeVertex(x,y,z)
334 anObj = MakeSpherePntR(point,radius)
337 def MakeSphereR(radius):
338 anObj = PrimOp.MakeSphereR(radius)
339 if PrimOp.IsDone() == 0:
340 print "MakeSphereR : ", PrimOp.GetErrorCode()
343 def MakeCone(p1,v1,radius1,radius2,height):
344 anObj = PrimOp.MakeConePntVecR1R2H(p1,v1,radius1,radius2,height)
345 if PrimOp.IsDone() == 0:
346 print "MakeConePntVecR1R2H : ", PrimOp.GetErrorCode()
349 def MakeConeR1R2H(radius1,radius2,height):
350 anObj = PrimOp.MakeConeR1R2H(radius1,radius2,height)
351 if PrimOp.IsDone() == 0:
352 print "MakeConeR1R2H : ", PrimOp.GetErrorCode()
355 def MakeTorus(p1,v1,major_radius,minor_radius):
356 anObj = PrimOp.MakeTorusPntVecRR(p1,v1,major_radius,minor_radius)
357 if PrimOp.IsDone() == 0:
358 print "MakeTorusPntVecRR : ", PrimOp.GetErrorCode()
361 def MakeTorusRR(major_radius,minor_radius):
362 anObj = PrimOp.MakeTorusRR(major_radius,minor_radius)
363 if PrimOp.IsDone() == 0:
364 print "MakeTorusRR : ", PrimOp.GetErrorCode()
367 def MakePrism(baseShape,point1,point2):
368 anObj = PrimOp.MakePrismTwoPnt(baseShape,point1,point2)
369 if PrimOp.IsDone() == 0:
370 print "MakePrismTwoPnt : ", PrimOp.GetErrorCode()
373 def MakePrismVecH(baseShape,vector,height):
374 anObj = PrimOp.MakePrismVecH(baseShape,vector,height)
375 if PrimOp.IsDone() == 0:
376 print "MakePrismVecH : ", PrimOp.GetErrorCode()
379 def MakePipe(baseShape,pathShape):
380 anObj = PrimOp.MakePipe(baseShape,pathShape)
381 if PrimOp.IsDone() == 0:
382 print "MakePipe : ", PrimOp.GetErrorCode()
385 def MakeRevolution(aShape,axis,angle):
386 anObj = PrimOp.MakeRevolutionAxisAngle(aShape,axis,angle)
387 if PrimOp.IsDone() == 0:
388 print "MakeRevolutionAxisAngle : ", PrimOp.GetErrorCode()
391 # -----------------------------------------------------------------------------
393 # -----------------------------------------------------------------------------
396 anObj = ShapesOp.MakeEdge(p1,p2)
397 if ShapesOp.IsDone() == 0:
398 print "MakeEdge : ", ShapesOp.GetErrorCode()
401 def MakeWire(ListShape):
402 anObj = ShapesOp.MakeWire(ListShape)
403 if ShapesOp.IsDone() == 0:
404 print "MakeWire : ", ShapesOp.GetErrorCode()
407 def MakeFace(aShapeWire,WantPlanarFace):
408 anObj = ShapesOp.MakeFace(aShapeWire,WantPlanarFace)
409 if ShapesOp.IsDone() == 0:
410 print "MakeFace : ", ShapesOp.GetErrorCode()
413 def MakeFaceWires(ListWires,WantPlanarFace):
414 anObj = ShapesOp.MakeFaceWires(ListWires,WantPlanarFace)
415 if ShapesOp.IsDone() == 0:
416 print "MakeFaceWires : ", ShapesOp.GetErrorCode()
419 def MakeFaces(ListWires,WantPlanarFace):
420 anObj = MakeFaceWires(ListWires,WantPlanarFace)
423 def MakeShell(ListOfShapes):
424 anObj = ShapesOp.MakeShell(ListOfShapes)
425 if ShapesOp.IsDone() == 0:
426 print "MakeShell : ", ShapesOp.GetErrorCode()
429 def MakeSolid(ListOfShells):
430 anObj = ShapesOp.MakeSolidShells(ListOfShells)
431 if ShapesOp.IsDone() == 0:
432 print "MakeSolid : ", ShapesOp.GetErrorCode()
435 def MakeCompound(ListShape):
436 anObj = ShapesOp.MakeCompound(ListShape)
437 if ShapesOp.IsDone() == 0:
438 print "MakeCompound : ", ShapesOp.GetErrorCode()
441 def NumberOfFaces(theShape):
442 nb_faces = ShapesOp.NumberOfFaces(theShape)
443 if ShapesOp.IsDone() == 0:
444 print "NumberOfFaces : ", ShapesOp.GetErrorCode()
447 def NumberOfEdges(theShape):
448 nb_edges = ShapesOp.NumberOfEdges(theShape)
449 if ShapesOp.IsDone() == 0:
450 print "NumberOfEdges : ", ShapesOp.GetErrorCode()
453 def ChangeOrientation(Shape):
454 anObj = ShapesOp.ChangeOrientation(Shape)
455 if ShapesOp.IsDone() == 0:
456 print "ChangeOrientation : ", ShapesOp.GetErrorCode()
459 def OrientationChange(Shape):
460 anObj = ChangeOrientation(Shape)
463 def GetFreeFacesIDs(theShape):
464 anIDs = ShapesOp.GetFreeFacesIDs(theShape)
465 if ShapesOp.IsDone() == 0:
466 print "GetFreeFacesIDs : ", ShapesOp.GetErrorCode()
469 def GetSharedShapes(theShape1, theShape2, theShapeType):
470 aList = ShapesOp.GetSharedShapes(theShape1, theShape2, theShapeType)
471 if ShapesOp.IsDone() == 0:
472 print "GetSharedShapes : ", ShapesOp.GetErrorCode()
475 def GetShapesOnPlane(theShape, theShapeType, theAx1, theState):
476 aList = ShapesOp.GetShapesOnPlane(theShape, theShapeType, theAx1, theState)
477 if ShapesOp.IsDone() == 0:
478 print "GetShapesOnPlane : ", ShapesOp.GetErrorCode()
481 def GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState):
482 aList = ShapesOp.GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState)
483 if ShapesOp.IsDone() == 0:
484 print "GetShapesOnCylinder : ", ShapesOp.GetErrorCode()
487 def GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState):
488 aList = ShapesOp.GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState)
489 if ShapesOp.IsDone() == 0:
490 print "GetShapesOnSphere : ", ShapesOp.GetErrorCode()
493 def GetInPlace(theShapeWhere, theShapeWhat):
494 anObj = ShapesOp.GetInPlace(theShapeWhere, theShapeWhat)
495 if ShapesOp.IsDone() == 0:
496 print "GetInPlace : ", ShapesOp.GetErrorCode()
499 # -----------------------------------------------------------------------------
500 # Access to sub-shapes by their unique IDs inside the main shape.
501 # -----------------------------------------------------------------------------
503 # Obtain a composite sub-shape of <aShape>, composed from sub-shapes
504 # of <aShape>, selected by their unique IDs inside <aShape>
505 def GetSubShape(aShape, ListOfID):
506 anObj = geom.AddSubShape(aShape,ListOfID)
509 # Obtain unique ID of sub-shape <aSubShape> inside <aShape>
510 def GetSubShapeID(aShape, aSubShape):
511 anID = LocalOp.GetSubShapeIndex(aShape, aSubShape)
512 if LocalOp.IsDone() == 0:
513 print "GetSubShapeIndex : ", LocalOp.GetErrorCode()
516 # -----------------------------------------------------------------------------
518 # -----------------------------------------------------------------------------
520 def SubShapeAll(aShape, aType):
521 ListObj = ShapesOp.MakeExplode(aShape,aType,0)
522 if ShapesOp.IsDone() == 0:
523 print "MakeExplode : ", ShapesOp.GetErrorCode()
526 def SubShapeAllIDs(aShape, aType):
527 ListObj = ShapesOp.SubShapeAllIDs(aShape,aType,0)
528 if ShapesOp.IsDone() == 0:
529 print "SubShapeAllIDs : ", ShapesOp.GetErrorCode()
532 def SubShapeAllSorted(aShape, aType):
533 ListObj = ShapesOp.MakeExplode(aShape,aType,1)
534 if ShapesOp.IsDone() == 0:
535 print "MakeExplode : ", ShapesOp.GetErrorCode()
538 def SubShapeAllSortedIDs(aShape, aType):
539 ListIDs = ShapesOp.SubShapeAllIDs(aShape,aType,1)
540 if ShapesOp.IsDone() == 0:
541 print "SubShapeAllSortedIDs : ", ShapesOp.GetErrorCode()
544 # Obtain a compound of sub-shapes of <aShape>,
545 # selected by they indices in list of all sub-shapes of type <aType>
546 def SubShape(aShape, aType, ListOfInd):
548 AllShapeList = SubShapeAll(aShape, aType)
549 for ind in ListOfInd:
550 ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
551 anObj = GetSubShape(aShape, ListOfIDs)
554 # Obtain a compound of sub-shapes of <aShape>,
555 # selected by they indices in sorted list of all sub-shapes of type <aType>
556 def SubShapeSorted(aShape, aType, ListOfInd):
558 AllShapeList = SubShapeAllSorted(aShape, aType)
559 for ind in ListOfInd:
560 ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
561 anObj = GetSubShape(aShape, ListOfIDs)
564 # -----------------------------------------------------------------------------
566 # -----------------------------------------------------------------------------
568 def ProcessShape(Shape, Operators, Parameters, Values):
569 anObj = HealOp.ProcessShape(Shape, Operators, Parameters, Values)
570 if HealOp.IsDone() == 0:
571 print "ProcessShape : ", HealOp.GetErrorCode()
574 def SuppressFaces(aShape,ListOfId):
575 anObj = HealOp.SuppressFaces(aShape,ListOfId)
576 if HealOp.IsDone() == 0:
577 print "SuppressFaces : ", HealOp.GetErrorCode()
580 def MakeSewing(ListShape,precision):
581 comp = MakeCompound(ListShape)
582 anObj = Sew(comp,precision)
585 def Sew(aShape,precision):
586 anObj = HealOp.Sew(aShape,precision)
587 if HealOp.IsDone() == 0:
588 print "Sew : ", HealOp.GetErrorCode()
591 def SuppressInternalWires(aShape, Wires):
592 anObj = HealOp.RemoveIntWires(aShape, Wires)
593 if HealOp.IsDone() == 0:
594 print "SuppressInternalWires : ", HealOp.GetErrorCode()
597 def SuppressHoles(aShape, ListOfId):
598 anObj = HealOp.FillHoles(aShape,ListOfId)
599 if HealOp.IsDone() == 0:
600 print "SuppressHoles : ", HealOp.GetErrorCode()
603 def CloseContour(aShape, Wires, IsCommonVertex):
604 anObj = HealOp.CloseContour(aShape, Wires, IsCommonVertex)
605 if HealOp.IsDone() == 0:
606 print "CloseContour : ", HealOp.GetErrorCode()
609 def DivideEdge(aShape, EdgeID, Value, IsByParameter):
610 anObj = HealOp.DivideEdge(aShape, EdgeID, Value, IsByParameter)
611 if HealOp.IsDone() == 0:
612 print "DivideEdge : ", HealOp.GetErrorCode()
615 def GetFreeBoundary(Shape):
616 anObj = HealOp.GetFreeBoundary(Shape)
617 if HealOp.IsDone() == 0:
618 print "GetFreeBoundaries : ", HealOp.GetErrorCode()
621 # -----------------------------------------------------------------------------
622 # Create advanced objects
623 # -----------------------------------------------------------------------------
625 def MakeCopy(aShape):
626 anObj = InsertOp.MakeCopy(aShape)
627 if InsertOp.IsDone() == 0:
628 print "MakeCopy : ", InsertOp.GetErrorCode()
631 def MakeFilling(aShape,mindeg,maxdeg,tol2d,tol3d,nbiter):
632 anObj = PrimOp.MakeFilling(aShape,mindeg,maxdeg,tol2d,tol3d,nbiter)
633 if PrimOp.IsDone() == 0:
634 print "MakeFilling : ", PrimOp.GetErrorCode()
637 def MakeGlueFaces(aShape,aTolerance):
638 anObj = ShapesOp.MakeGlueFaces(aShape,aTolerance)
639 if ShapesOp.IsDone() == 0:
640 print "MakeGlueFaces : ", ShapesOp.GetErrorCode()
643 # -----------------------------------------------------------------------------
644 # Boolean (Common, Cut, Fuse, Section)
645 # -----------------------------------------------------------------------------
647 def MakeBoolean(shape1,shape2,operation):
648 anObj = BoolOp.MakeBoolean(shape1,shape2,operation)
649 if BoolOp.IsDone() == 0:
650 print "MakeBoolean : ", BoolOp.GetErrorCode()
653 def MakeCommon(s1, s2):
654 return MakeBoolean(s1, s2, 1)
657 return MakeBoolean(s1, s2, 2)
659 def MakeFuse(s1, s2):
660 return MakeBoolean(s1, s2, 3)
662 def MakeSection(s1, s2):
663 return MakeBoolean(s1, s2, 4)
665 def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
666 Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
667 anObj = BoolOp.MakePartition(ListShapes, ListTools,
668 ListKeepInside, ListRemoveInside,
669 Limit, RemoveWebs, ListMaterials);
670 if BoolOp.IsDone() == 0:
671 print "MakePartition : ", BoolOp.GetErrorCode()
674 def Partition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
675 Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
676 anObj = MakePartition(ListShapes, ListTools,
677 ListKeepInside, ListRemoveInside,
678 Limit, RemoveWebs, ListMaterials);
681 def MakeHalfPartition(theShape, thePlane):
682 anObj = BoolOp.MakeHalfPartition(theShape, thePlane)
683 if BoolOp.IsDone() == 0:
684 print "MakeHalfPartition : ", BoolOp.GetErrorCode()
687 # -----------------------------------------------------------------------------
689 # -----------------------------------------------------------------------------
691 def MakeTranslationTwoPoints(aShape,point1,point2):
692 anObj = TrsfOp.TranslateTwoPointsCopy(aShape,point1,point2)
693 if TrsfOp.IsDone() == 0:
694 print "TranslateTwoPointsCopy : ", TrsfOp.GetErrorCode()
697 def MakeTranslation(aShape,dx,dy,dz):
698 anObj = TrsfOp.TranslateDXDYDZCopy(aShape,dx,dy,dz)
699 if TrsfOp.IsDone() == 0:
700 print "TranslateDXDYDZCopy : ", TrsfOp.GetErrorCode()
703 def MakeTranslationVector(theObject, theVector):
704 anObj = TrsfOp.TranslateVectorCopy(theObject, theVector)
705 if TrsfOp.IsDone() == 0:
706 print "TranslateVectorCopy : ", TrsfOp.GetErrorCode()
709 def MakeRotation(aShape,axis,angle):
710 anObj = TrsfOp.RotateCopy(aShape,axis,angle)
711 if TrsfOp.IsDone() == 0:
712 print "RotateCopy : ", TrsfOp.GetErrorCode()
715 def MakeScaleTransform(aShape,theCenterofScale,factor):
716 anObj = TrsfOp.ScaleShapeCopy(aShape,theCenterofScale,factor)
717 if TrsfOp.IsDone() == 0:
718 print "ScaleShapeCopy : ", TrsfOp.GetErrorCode()
721 def MakeMirrorByPlane(aShape,aPlane):
722 anObj = TrsfOp.MirrorPlaneCopy(aShape,aPlane)
723 if TrsfOp.IsDone() == 0:
724 print "MirrorPlaneCopy : ", TrsfOp.GetErrorCode()
727 def MakeMirrorByAxis(theObject, theAxis):
728 anObj = TrsfOp.MirrorAxisCopy(theObject, theAxis)
729 if TrsfOp.IsDone() == 0:
730 print "MirrorAxisCopy : ", TrsfOp.GetErrorCode()
733 def MakeMirrorByPoint(theObject, thePoint):
734 anObj = TrsfOp.MirrorPointCopy(theObject, thePoint)
735 if TrsfOp.IsDone() == 0:
736 print "MirrorPointCopy : ", TrsfOp.GetErrorCode()
739 def MakePosition(aShape,theStartLCS,theEndLCS):
740 anObj = TrsfOp.PositionShapeCopy(aShape,theStartLCS,theEndLCS)
741 if TrsfOp.IsDone() == 0:
742 print "PositionShapeCopy : ", TrsfOp.GetErrorCode()
745 def MakeOffset(aShape, anOffset):
746 anObj = TrsfOp.OffsetShapeCopy(aShape, anOffset)
747 if TrsfOp.IsDone() == 0:
748 print "OffsetShapeCopy : ", TrsfOp.GetErrorCode()
751 # -----------------------------------------------------------------------------
753 # -----------------------------------------------------------------------------
755 def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
756 anObj = TrsfOp.MultiTranslate1D(aShape,aDir,aStep,aNbTimes)
757 if TrsfOp.IsDone() == 0:
758 print "MultiTranslate1D : ", TrsfOp.GetErrorCode()
761 def MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2):
762 anObj = TrsfOp.MultiTranslate2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2)
763 if TrsfOp.IsDone() == 0:
764 print "MultiTranslate2D : ", TrsfOp.GetErrorCode()
767 def MultiRotate1D(aShape,aVec,aNbTimes):
768 anObj = TrsfOp.MultiRotate1D(aShape,aVec,aNbTimes)
769 if TrsfOp.IsDone() == 0:
770 print "MultiRotate1D : ", TrsfOp.GetErrorCode()
773 def MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2):
774 anObj = TrsfOp.MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
775 if TrsfOp.IsDone() == 0:
776 print "MultiRotate2D : ", TrsfOp.GetErrorCode()
779 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
780 aVec = MakeLine(aPoint,aDir)
781 anObj = MultiRotate1D(aShape,aVec,aNbTimes)
784 def MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2):
785 aVec = MakeLine(aPoint,aDir)
786 anObj = MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
789 # -----------------------------------------------------------------------------
791 # -----------------------------------------------------------------------------
793 def MakeFilletAll(aShape,radius):
794 anObj = LocalOp.MakeFilletAll(aShape,radius)
795 if LocalOp.IsDone() == 0:
796 print "MakeFilletAll : ", LocalOp.GetErrorCode()
799 def MakeFillet(aShape,radius,aShapeType,ListShape):
801 if aShapeType == ShapeType["EDGE"]:
802 anObj = LocalOp.MakeFilletEdges(aShape,radius,ListShape)
804 anObj = LocalOp.MakeFilletFaces(aShape,radius,ListShape)
805 if LocalOp.IsDone() == 0:
806 print "MakeFillet : ", LocalOp.GetErrorCode()
809 def MakeChamferAll(aShape,d):
810 anObj = LocalOp.MakeChamferAll(aShape,d)
811 if LocalOp.IsDone() == 0:
812 print "MakeChamferAll : ", LocalOp.GetErrorCode()
815 def MakeChamferEdge(aShape,d1,d2,face1,face2):
816 anObj = LocalOp.MakeChamferEdge(aShape,d1,d2,face1,face2)
817 if LocalOp.IsDone() == 0:
818 print "MakeChamferEdge : ", LocalOp.GetErrorCode()
821 def MakeChamferFaces(aShape,d1,d2,ListShape):
822 anObj = LocalOp.MakeChamferFaces(aShape,d1,d2,ListShape)
823 if LocalOp.IsDone() == 0:
824 print "MakeChamferFaces : ", LocalOp.GetErrorCode()
827 def MakeChamfer(aShape,d1,d2,aShapeType,ListShape):
829 if aShapeType == ShapeType["EDGE"]:
830 anObj = MakeChamferEdge(aShape,d1,d2,ListShape[0],ListShape[1])
832 anObj = MakeChamferFaces(aShape,d1,d2,ListShape)
835 def Archimede(aShape,weight,WaterDensity,MeshingDeflection):
836 anObj = LocalOp.MakeArchimede(aShape,weight,WaterDensity,MeshingDeflection)
837 if LocalOp.IsDone() == 0:
838 print "MakeArchimede : ", LocalOp.GetErrorCode()
841 # -----------------------------------------------------------------------------
842 # Information objects
843 # -----------------------------------------------------------------------------
845 def PointCoordinates(Point):
846 aTuple = MeasuOp.PointCoordinates(Point)
847 if MeasuOp.IsDone() == 0:
848 print "PointCoordinates : ", MeasuOp.GetErrorCode()
851 def BasicProperties(Shape):
852 aTuple = MeasuOp.GetBasicProperties(Shape)
853 if MeasuOp.IsDone() == 0:
854 print "BasicProperties : ", MeasuOp.GetErrorCode()
857 def BoundingBox(Shape):
858 aTuple = MeasuOp.GetBoundingBox(Shape)
859 if MeasuOp.IsDone() == 0:
860 print "BoundingBox : ", MeasuOp.GetErrorCode()
864 aTuple = MeasuOp.GetInertia(Shape)
865 if MeasuOp.IsDone() == 0:
866 print "Inertia : ", MeasuOp.GetErrorCode()
869 def MinDistance(Shape1, Shape2):
870 aTuple = MeasuOp.GetMinDistance(Shape1, Shape2)
871 if MeasuOp.IsDone() == 0:
872 print "MinDistance : ", MeasuOp.GetErrorCode()
875 def Tolerance(Shape):
876 aTuple = MeasuOp.GetTolerance(Shape)
877 if MeasuOp.IsDone() == 0:
878 print "Tolerance : ", MeasuOp.GetErrorCode()
882 aDescr = MeasuOp.WhatIs(Shape)
883 if MeasuOp.IsDone() == 0:
884 print "WhatIs : ", MeasuOp.GetErrorCode()
888 anObj = MeasuOp.GetCentreOfMass(aShape)
889 if MeasuOp.IsDone() == 0:
890 print "GetCentreOfMass : ", MeasuOp.GetErrorCode()
893 def CheckShape(aShape):
894 (IsValid, Status) = MeasuOp.CheckShape(aShape)
895 if MeasuOp.IsDone() == 0:
896 print "CheckShape : ", MeasuOp.GetErrorCode()
902 # -----------------------------------------------------------------------------
903 # Import/Export objects
904 # -----------------------------------------------------------------------------
906 def Import(filename, formatname):
907 anObj = InsertOp.Import(filename, formatname)
908 if InsertOp.IsDone() == 0:
909 print "Import : ", InsertOp.GetErrorCode()
912 def ImportBREP(theFileName):
913 return Import(theFileName, "BREP")
915 def ImportIGES(theFileName):
916 return Import(theFileName, "IGES")
918 def ImportSTEP(theFileName):
919 return Import(theFileName, "STEP")
921 def Export(aShape, filename, formatname):
922 InsertOp.Export(aShape, filename, formatname)
923 if InsertOp.IsDone() == 0:
924 print "Export : ", InsertOp.GetErrorCode()
926 def ExportBREP(theObject, theFileName):
927 return Export(theObject, theFileName, "BREP")
929 def ExportIGES(theObject, theFileName):
930 return Export(theObject, theFileName, "IGES")
932 def ExportSTEP(theObject, theFileName):
933 return Export(theObject, theFileName, "STEP")
935 # -----------------------------------------------------------------------------
937 # -----------------------------------------------------------------------------
939 def MakeQuad(E1, E2, E3, E4):
940 anObj = BlocksOp.MakeQuad(E1, E2, E3, E4)
941 if BlocksOp.IsDone() == 0:
942 print "MakeQuad : ", BlocksOp.GetErrorCode()
945 def MakeQuad2Edges(E1, E2):
946 anObj = BlocksOp.MakeQuad2Edges(E1, E2)
947 if BlocksOp.IsDone() == 0:
948 print "MakeQuad2Edges : ", BlocksOp.GetErrorCode()
951 def MakeQuad4Vertices(V1, V2, V3, V4):
952 anObj = BlocksOp.MakeQuad4Vertices(V1, V2, V3, V4)
953 if BlocksOp.IsDone() == 0:
954 print "MakeQuad4Vertices : ", BlocksOp.GetErrorCode()
957 def MakeHexa(F1, F2, F3, F4, F5, F6):
958 anObj = BlocksOp.MakeHexa(F1, F2, F3, F4, F5, F6)
959 if BlocksOp.IsDone() == 0:
960 print "MakeHexa : ", BlocksOp.GetErrorCode()
963 def MakeHexa2Faces(F1, F2):
964 anObj = BlocksOp.MakeHexa2Faces(F1, F2)
965 if BlocksOp.IsDone() == 0:
966 print "MakeHexa2Faces : ", BlocksOp.GetErrorCode()
969 def GetPoint(theShape, theX, theY, theZ, theEpsilon):
970 anObj = BlocksOp.GetPoint(theShape, theX, theY, theZ, theEpsilon)
971 if BlocksOp.IsDone() == 0:
972 print "GetPoint : ", BlocksOp.GetErrorCode()
975 def GetEdge(theShape, thePoint1, thePoint2):
976 anObj = BlocksOp.GetEdge(theShape, thePoint1, thePoint2)
977 if BlocksOp.IsDone() == 0:
978 print "GetEdge : ", BlocksOp.GetErrorCode()
981 def GetEdgeNearPoint(theShape, thePoint):
982 anObj = BlocksOp.GetEdgeNearPoint(theShape, thePoint)
983 if BlocksOp.IsDone() == 0:
984 print "GetEdgeNearPoint : ", BlocksOp.GetErrorCode()
987 def GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4):
988 anObj = BlocksOp.GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4)
989 if BlocksOp.IsDone() == 0:
990 print "GetFaceByPoints : ", BlocksOp.GetErrorCode()
993 def GetFaceByEdges(theShape, theEdge1, theEdge2):
994 anObj = BlocksOp.GetFaceByEdges(theShape, theEdge1, theEdge2)
995 if BlocksOp.IsDone() == 0:
996 print "GetFaceByEdges : ", BlocksOp.GetErrorCode()
999 def GetOppositeFace(theBlock, theFace):
1000 anObj = BlocksOp.GetOppositeFace(theBlock, theFace)
1001 if BlocksOp.IsDone() == 0:
1002 print "GetOppositeFace : ", BlocksOp.GetErrorCode()
1005 def GetFaceNearPoint(theShape, thePoint):
1006 anObj = BlocksOp.GetFaceNearPoint(theShape, thePoint)
1007 if BlocksOp.IsDone() == 0:
1008 print "GetFaceNearPoint : ", BlocksOp.GetErrorCode()
1011 def GetFaceByNormale(theBlock, theVector):
1012 anObj = BlocksOp.GetFaceByNormale(theBlock, theVector)
1013 if BlocksOp.IsDone() == 0:
1014 print "GetFaceByNormale : ", BlocksOp.GetErrorCode()
1017 def CheckCompoundOfBlocks(theCompound):
1018 (IsValid, BCErrors) = BlocksOp.CheckCompoundOfBlocks(theCompound)
1019 if BlocksOp.IsDone() == 0:
1020 print "CheckCompoundOfBlocks : ", BlocksOp.GetErrorCode()
1023 Descr = BlocksOp.PrintBCErrors(theCompound, BCErrors)
1027 def RemoveExtraEdges(theShape):
1028 anObj = BlocksOp.RemoveExtraEdges(theShape)
1029 if BlocksOp.IsDone() == 0:
1030 print "RemoveExtraEdges : ", BlocksOp.GetErrorCode()
1033 def CheckAndImprove(theShape):
1034 anObj = BlocksOp.CheckAndImprove(theShape)
1035 if BlocksOp.IsDone() == 0:
1036 print "CheckAndImprove : ", BlocksOp.GetErrorCode()
1039 def MakeBlockExplode(theCompound, theMinNbFaces, theMaxNbFaces):
1040 aList = BlocksOp.ExplodeCompoundOfBlocks(theCompound, theMinNbFaces, theMaxNbFaces)
1041 if BlocksOp.IsDone() == 0:
1042 print "MakeBlockExplode : ", BlocksOp.GetErrorCode()
1045 def GetBlockNearPoint(theCompound, thePoint):
1046 anObj = BlocksOp.GetBlockNearPoint(theCompound, thePoint)
1047 if BlocksOp.IsDone() == 0:
1048 print "GetBlockNearPoint : ", BlocksOp.GetErrorCode()
1051 def GetBlockByParts(theCompound, theParts):
1052 anObj = BlocksOp.GetBlockByParts(theCompound, theParts)
1053 if BlocksOp.IsDone() == 0:
1054 print "GetBlockByParts : ", BlocksOp.GetErrorCode()
1057 def GetBlocksByParts(theCompound, theParts):
1058 aList = BlocksOp.GetBlocksByParts(theCompound, theParts)
1059 if BlocksOp.IsDone() == 0:
1060 print "GetBlocksByParts : ", BlocksOp.GetErrorCode()
1063 def MakeMultiTransformation1D(Block, DirFaceID1, DirFaceID2, NbTimes):
1064 anObj = BlocksOp.MakeMultiTransformation1D(Block, DirFaceID1, DirFaceID2, NbTimes)
1065 if BlocksOp.IsDone() == 0:
1066 print "MakeMultiTransformation1D : ", BlocksOp.GetErrorCode()
1069 def MakeMultiTransformation2D(Block, DirFaceID1U, DirFaceID2U, NbTimesU,
1070 DirFaceID1V, DirFaceID2V, NbTimesV):
1071 anObj = BlocksOp.MakeMultiTransformation2D(Block, DirFaceID1U, DirFaceID2U, NbTimesU,
1072 DirFaceID1V, DirFaceID2V, NbTimesV)
1073 if BlocksOp.IsDone() == 0:
1074 print "MakeMultiTransformation2D : ", BlocksOp.GetErrorCode()
1077 def Propagate(theShape):
1078 listChains = BlocksOp.Propagate(theShape)
1079 if BlocksOp.IsDone() == 0:
1080 print "Propagate : ", BlocksOp.GetErrorCode()
1083 # -----------------------------------------------------------------------------
1085 # -----------------------------------------------------------------------------
1087 def CreateGroup(MainShape, ShapeType):
1088 anObj = GroupOp.CreateGroup(MainShape, ShapeType)
1089 if GroupOp.IsDone() == 0:
1090 print "CreateGroup : ", GroupOp.GetErrorCode()
1093 def AddObject(Group, SubShapeID):
1094 GroupOp.AddObject(Group, SubShapeID)
1095 if GroupOp.IsDone() == 0:
1096 print "AddObject : ", GroupOp.GetErrorCode()
1098 def RemoveObject(Group, SubShapeID):
1099 GroupOp.RemoveObject(Group, SubShapeID)
1100 if GroupOp.IsDone() == 0:
1101 print "RemoveObject : ", GroupOp.GetErrorCode()
1103 def UnionList (theGroup, theSubShapes):
1104 GroupOp.UnionList(theGroup, theSubShapes)
1105 if GroupOp.IsDone() == 0:
1106 print "UnionList : ", GroupOp.GetErrorCode()
1108 def DifferenceList (theGroup, theSubShapes):
1109 GroupOp.DifferenceList(theGroup, theSubShapes)
1110 if GroupOp.IsDone() == 0:
1111 print "DifferenceList : ", GroupOp.GetErrorCode()
1113 def GetObjectIDs(Group):
1114 ListIDs = GroupOp.GetObjects(Group)
1115 if GroupOp.IsDone() == 0:
1116 print "GetObjectIDs : ", GroupOp.GetErrorCode()
1119 def GetType(theGroup):
1120 aType = GroupOp.GetType(theGroup)
1121 if GroupOp.IsDone() == 0:
1122 print "GetType : ", GroupOp.GetErrorCode()
1125 def GetMainShape(theGroup):
1126 anObj = GroupOp.GetMainShape(theGroup)
1127 if GroupOp.IsDone() == 0:
1128 print "GetMainShape : ", GroupOp.GetErrorCode()
1131 def GetEdgesByLength (theShape, min_length, max_length, include_min = 1, include_max = 1):
1133 Create group of edges of theShape, whose length is in range [min_length, max_length].
1134 If include_min/max == 0, edges with length == min/max_length will not be included in result.
1137 edges = SubShapeAll(theShape, ShapeType["EDGE"])
1140 Props = BasicProperties(edge)
1141 if min_length <= Props[0] and Props[0] <= max_length:
1142 if (not include_min) and (min_length == Props[0]):
1145 if (not include_max) and (Props[0] == max_length):
1148 edges_in_range.append(edge)
1150 if len(edges_in_range) <= 0:
1151 print "No edges found by given criteria"
1154 group_edges = CreateGroup(theShape, ShapeType["EDGE"])
1155 UnionList(group_edges, edges_in_range)
1159 # Add Path to the system path
1162 if (sys.path.count(Path) < 1):
1163 sys.path.append(Path)