Salome HOME
NPAL 16548, 16820, 16218, 16547
[modules/geom.git] / src / GEOM_SWIG / batchmode_geompy.py
1 #  GEOM GEOM_SWIG : binding of C++ omplementaion with Python
2 #
3 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 #
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.
10 #
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.
15 #
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
19 #
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #
22 #
23 #
24 #  File   : geompy.py
25 #  Author : Paul RASCLE, EDF
26 #  Module : GEOM
27 #  $Header$
28
29 from batchmode_salome import *
30 import GEOM
31
32 g=None
33 step = 0
34 sleeping_time = 0.01
35 sleeping_time_max = 1.0
36 while 1:
37     g = lcc.FindOrLoadComponent("FactoryServer", "GEOM")
38     if g is not None: break
39     step = step + 1
40     if step > 100: break
41     time.sleep(sleeping_time)
42     sleeping_time = max(sleeping_time_max, 2*sleeping_time)
43     pass
44 geom = g._narrow( GEOM.GEOM_Gen )
45
46 myBuilder = None
47 myStudyId = 0
48 father    = None
49
50 BasicOp  = None
51 CurvesOp = None
52 PrimOp   = None
53 ShapesOp = None
54 HealOp   = None
55 InsertOp = None
56 BoolOp   = None
57 TrsfOp   = None
58 LocalOp  = None
59 MeasuOp  = None
60 BlocksOp = None
61 GroupOp  = None
62
63 def init_geom(theStudy):
64
65     global myStudy, myBuilder, myStudyId, BasicOp, CurvesOp, PrimOp, ShapesOp, HealOp
66     global InsertOp, BoolOp, TrsfOp, LocalOp, MeasuOp, BlocksOp, GroupOp, father
67
68     myStudy = theStudy
69     myStudyId = myStudy._get_StudyId()
70     myBuilder = myStudy.NewBuilder()
71     father = myStudy.FindComponent("GEOM")
72     if father is None:
73         father = myBuilder.NewComponent("GEOM")
74         A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName")
75         FName = A1._narrow(SALOMEDS.AttributeName)
76         FName.SetValue("Geometry")
77         A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap")
78         aPixmap = A2._narrow(SALOMEDS.AttributePixMap)
79         aPixmap.SetPixMap("ICON_OBJBROWSER_Geometry")
80         myBuilder.DefineComponentInstance(father,geom)
81         pass
82
83     # -----------------------------------------------------------------------------
84     # Assign Operations Interfaces
85     # -----------------------------------------------------------------------------
86
87     BasicOp  = geom.GetIBasicOperations    (myStudyId)
88     CurvesOp = geom.GetICurvesOperations   (myStudyId)
89     PrimOp   = geom.GetI3DPrimOperations   (myStudyId)
90     ShapesOp = geom.GetIShapesOperations   (myStudyId)
91     HealOp   = geom.GetIHealingOperations  (myStudyId)
92     InsertOp = geom.GetIInsertOperations   (myStudyId)
93     BoolOp   = geom.GetIBooleanOperations  (myStudyId)
94     TrsfOp   = geom.GetITransformOperations(myStudyId)
95     LocalOp  = geom.GetILocalOperations    (myStudyId)
96     MeasuOp  = geom.GetIMeasureOperations  (myStudyId)
97     BlocksOp = geom.GetIBlocksOperations   (myStudyId)
98     GroupOp  = geom.GetIGroupOperations   (myStudyId)
99     pass
100
101 init_geom(myStudy)
102
103 #     *  Get name for sub-shape aSubObj of shape aMainObj
104 #
105 def SubShapeName(aSubObj, aMainObj):
106     name = "SubShape"
107     print name
108     return name
109
110 #     *  Publish in study aShape with name aName
111 #
112 def addToStudy(aShape, aName):
113     try:
114         aSObject = geom.AddInStudy(myStudy, aShape, aName, None)
115     except:
116         print "addToStudy() failed"
117         return ""
118     return aShape.GetStudyEntry()
119
120 #     *  Publish in study aShape with name aName as sub-object of previously published aFather
121 #
122 def addToStudyInFather(aFather, aShape, aName):
123     try:
124         aSObject = geom.AddInStudy(myStudy, aShape, aName, aFather)
125     except:
126         print "addToStudyInFather() failed"
127         return ""
128     return aShape.GetStudyEntry()
129
130 # -----------------------------------------------------------------------------
131 # enumeration ShapeType as a dictionary
132 # -----------------------------------------------------------------------------
133
134 ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
135
136 # -----------------------------------------------------------------------------
137 # Basic primitives
138 # -----------------------------------------------------------------------------
139
140 def MakeVertex(theX, theY, theZ):
141     anObj = BasicOp.MakePointXYZ(theX, theY, theZ)
142     if BasicOp.IsDone() == 0:
143       print "MakePointXYZ : ", BasicOp.GetErrorCode()
144     return anObj
145
146 def MakeVertexWithRef(vertex,x,y,z):
147     anObj = BasicOp.MakePointWithReference(vertex,x,y,z)
148     if BasicOp.IsDone() == 0:
149       print "MakePointWithReference : ", BasicOp.GetErrorCode()
150     return anObj
151
152 def MakeVertexOnCurve(curve,par):
153     anObj = BasicOp.MakePointOnCurve(curve,par)
154     if BasicOp.IsDone() == 0:
155       print "MakePointOnCurve : ", BasicOp.GetErrorCode()
156     return anObj
157
158 def MakeVertexOnLinesIntersection(line1,line2):
159     anObj = BasicOp.MakePointOnLinesIntersection(line1,line2)
160     if BasicOp.IsDone() == 0:
161       print "MakePointOnLinesIntersection : ", BasicOp.GetErrorCode()
162     return anObj
163
164 def MakeVectorDXDYDZ(dx,dy,dz):
165     anObj = BasicOp.MakeVectorDXDYDZ(dx,dy,dz)
166     if BasicOp.IsDone() == 0:
167       print "MakeVectorDXDYDZ : ", BasicOp.GetErrorCode()
168     return anObj
169
170 def MakeVector(p1,p2):
171     anObj = BasicOp.MakeVectorTwoPnt(p1, p2)
172     if BasicOp.IsDone() == 0:
173       print "MakeVectorTwoPnt : ", BasicOp.GetErrorCode()
174     return anObj
175
176 def MakeLine(p1, d1):
177     anObj = BasicOp.MakeLine(p1,d1)
178     if BasicOp.IsDone() == 0:
179       print "MakeLine : ", BasicOp.GetErrorCode()
180     return anObj
181
182 def MakeLineTwoPnt(p1, p2):
183     anObj = BasicOp.MakeLineTwoPnt(p1,p2)
184     if BasicOp.IsDone() == 0:
185       print "MakeLineTwoPnt : ", BasicOp.GetErrorCode()
186     return anObj
187
188 def MakeLineTwoFaces(f1, f2):
189     anObj = BasicOp.MakeLineTwoFaces(f1,f2)
190     if BasicOp.IsDone() == 0:
191       print "MakeLineTwoFaces : ", BasicOp.GetErrorCode()
192     return anObj
193
194 def MakePlane(p1,v1,trimsize):
195     anObj = BasicOp.MakePlanePntVec(p1,v1,trimsize)
196     if BasicOp.IsDone() == 0:
197       print "MakePlanePntVec : ", BasicOp.GetErrorCode()
198     return anObj
199
200 def MakePlaneThreePnt(p1,p2,p3,trimsize):
201     anObj = BasicOp.MakePlaneThreePnt(p1,p2,p3,trimsize)
202     if BasicOp.IsDone() == 0:
203       print "MakePlaneThreePnt : ", BasicOp.GetErrorCode()
204     return anObj
205
206 def MakePlaneFace(face,trimsize):
207     anObj = BasicOp.MakePlaneFace(face,trimsize)
208     if BasicOp.IsDone() == 0:
209       print "MakePlaneFace : ", BasicOp.GetErrorCode()
210     return anObj
211
212 def MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ):
213     anObj = BasicOp.MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ)
214     if BasicOp.IsDone() == 0:
215       print "MakeMarker : ", BasicOp.GetErrorCode()
216     return anObj
217
218 def MakeMarkerPntTwoVec(theOrigin, theXVec, theYVec):
219     """
220      *  Create a local coordinate system.
221      *  \param theOrigin Point of coordinate system origin.
222      *  \param theXVec Vector of X direction
223      *  \param theYVec Vector of Y direction
224      *  \return New GEOM_Object, containing the created coordinate system.
225     """
226     O = PointCoordinates( theOrigin )
227     OXOY = []
228     for vec in [ theXVec, theYVec ]:
229         v1, v2 = SubShapeAll( vec, ShapeType["VERTEX"] )
230         p1 = PointCoordinates( v1 )
231         p2 = PointCoordinates( v2 )
232         for i in range( 0, 3 ):
233              OXOY.append( p2[i] - p1[i] )
234     #
235     anObj = BasicOp.MakeMarker( O[0], O[1], O[2],
236                                 OXOY[0], OXOY[1], OXOY[2],
237                                 OXOY[3], OXOY[4], OXOY[5], )
238     if BasicOp.IsDone() == 0:
239       print "MakeMarker : ", BasicOp.GetErrorCode()
240     return anObj
241
242 # -----------------------------------------------------------------------------
243 # Curves
244 # -----------------------------------------------------------------------------
245
246 def MakeArc(p1,p2,p3):
247     anObj = CurvesOp.MakeArc(p1,p2,p3)
248     if CurvesOp.IsDone() == 0:
249       print "MakeArc : ", CurvesOp.GetErrorCode()
250     return anObj
251
252 def MakeCircle(p1,v1,radius):
253     anObj = CurvesOp.MakeCirclePntVecR(p1,v1,radius)
254     if CurvesOp.IsDone() == 0:
255       print "MakeCirclePntVecR : ", CurvesOp.GetErrorCode()
256     return anObj
257
258 def MakeCircleThreePnt(p1,p2,p3):
259     anObj = CurvesOp.MakeCircleThreePnt(p1,p2,p3)
260     if CurvesOp.IsDone() == 0:
261       print "MakeCircleThreePnt : ", CurvesOp.GetErrorCode()
262     return anObj
263
264 def MakeCircleCenter2Pnt(p1,p2,p3):
265     anObj = CurvesOp.MakeCircleCenter2Pnt(p1,p2,p3)
266     if CurvesOp.IsDone() == 0:
267       print "MakeCircleCenter2Pnt : ", CurvesOp.GetErrorCode()
268     return anObj
269
270 def MakeEllipse(p1,v1,radiusMaj,radiusMin):
271     anObj = CurvesOp.MakeEllipse(p1,v1,radiusMaj, radiusMin)
272     if CurvesOp.IsDone() == 0:
273       print "MakeEllipse : ", CurvesOp.GetErrorCode()
274     return anObj
275
276 def MakePolyline(ListShape):
277     anObj = CurvesOp.MakePolyline(ListShape)
278     if CurvesOp.IsDone() == 0:
279       print "MakePolyline : ", CurvesOp.GetErrorCode()
280     return anObj
281
282 def MakeBezier(ListShape):
283     anObj = CurvesOp.MakeSplineBezier(ListShape)
284     if CurvesOp.IsDone() == 0:
285       print "MakeSplineBezier : ", CurvesOp.GetErrorCode()
286     return anObj
287
288 def MakeInterpol(ListShape):
289     anObj = CurvesOp.MakeSplineInterpolation(ListShape)
290     if CurvesOp.IsDone() == 0:
291       print "MakeSplineInterpolation : ", CurvesOp.GetErrorCode()
292     return anObj
293
294 # <WPL>: Nine double values, defining origin,
295 # OZ and OX directions of the working plane.
296 def MakeSketcher(Cmd, WPL = [0,0,0, 0,0,1, 1,0,0]):
297     anObj = CurvesOp.MakeSketcher(Cmd, WPL)
298     if CurvesOp.IsDone() == 0:
299       print "MakeSketcher : ", CurvesOp.GetErrorCode()
300     return anObj
301
302 def MakeSketcherOnPlane(theCommand, theWorkingPlane):
303     """
304      *  Create a sketcher (wire or face), following the textual description,
305      *  passed through \a theCommand argument. \n
306      *  For format of the description string see the previous method.\n
307      *  \param theCommand String, defining the sketcher in local
308      *                    coordinates of the working plane.
309      *  \param theWorkingPlane Planar Face of the working plane.
310      *  \return New GEOM_Object, containing the created wire.
311     """
312     anObj = CurvesOp.MakeSketcherOnPlane(theCommand, theWorkingPlane)
313     if CurvesOp.IsDone() == 0:
314       print "MakeSketcher : ", CurvesOp.GetErrorCode()
315     return anObj
316
317 # -----------------------------------------------------------------------------
318 # Create 3D Primitives
319 # -----------------------------------------------------------------------------
320
321 def MakeBox(x1,y1,z1,x2,y2,z2):
322     pnt1 = MakeVertex(x1,y1,z1)
323     pnt2 = MakeVertex(x2,y2,z2)
324     return MakeBoxTwoPnt(pnt1,pnt2)
325
326 def MakeBoxDXDYDZ(dx,dy,dz):
327     anObj = PrimOp.MakeBoxDXDYDZ(dx,dy,dz)
328     if PrimOp.IsDone() == 0:
329       print "MakeBoxDXDYDZ : ", PrimOp.GetErrorCode()
330     return anObj
331
332 def MakeBoxTwoPnt(point1, point2):
333     anObj = PrimOp.MakeBoxTwoPnt(point1, point2)
334     if PrimOp.IsDone() == 0:
335       print "MakeBoxTwoPnt : ", PrimOp.GetErrorCode()
336     return anObj
337
338 def MakeCylinder(p1,v1,radius,height):
339     anObj = PrimOp.MakeCylinderPntVecRH(p1,v1,radius,height)
340     if PrimOp.IsDone() == 0:
341       print "MakeCylinderPntVecRH : ", PrimOp.GetErrorCode()
342     return anObj
343
344 def MakeCylinderRH(radius,height):
345     anObj = PrimOp.MakeCylinderRH(radius,height)
346     if PrimOp.IsDone() == 0:
347       print "MakeCylinderRH : ", PrimOp.GetErrorCode()
348     return anObj
349
350 def MakeSpherePntR(point,radius):
351     anObj = PrimOp.MakeSpherePntR(point,radius)
352     if PrimOp.IsDone() == 0:
353       print "MakeSpherePntR : ", PrimOp.GetErrorCode()
354     return anObj
355
356 def MakeSphere(x,y,z,radius):
357     point = MakeVertex(x,y,z)
358     anObj = MakeSpherePntR(point,radius)
359     return anObj
360
361 def MakeSphereR(radius):
362     anObj = PrimOp.MakeSphereR(radius)
363     if PrimOp.IsDone() == 0:
364       print "MakeSphereR : ", PrimOp.GetErrorCode()
365     return anObj
366
367 def MakeCone(p1,v1,radius1,radius2,height):
368     anObj = PrimOp.MakeConePntVecR1R2H(p1,v1,radius1,radius2,height)
369     if PrimOp.IsDone() == 0:
370       print "MakeConePntVecR1R2H : ", PrimOp.GetErrorCode()
371     return anObj
372
373 def MakeConeR1R2H(radius1,radius2,height):
374     anObj = PrimOp.MakeConeR1R2H(radius1,radius2,height)
375     if PrimOp.IsDone() == 0:
376       print "MakeConeR1R2H : ", PrimOp.GetErrorCode()
377     return anObj
378
379 def MakeTorus(p1,v1,major_radius,minor_radius):
380     anObj = PrimOp.MakeTorusPntVecRR(p1,v1,major_radius,minor_radius)
381     if PrimOp.IsDone() == 0:
382       print "MakeTorusPntVecRR : ", PrimOp.GetErrorCode()
383     return anObj
384
385 def MakeTorusRR(major_radius,minor_radius):
386     anObj = PrimOp.MakeTorusRR(major_radius,minor_radius)
387     if PrimOp.IsDone() == 0:
388       print "MakeTorusRR : ", PrimOp.GetErrorCode()
389     return anObj
390
391 def MakePrism(baseShape,point1,point2):
392     anObj = PrimOp.MakePrismTwoPnt(baseShape,point1,point2)
393     if PrimOp.IsDone() == 0:
394       print "MakePrismTwoPnt : ", PrimOp.GetErrorCode()
395     return anObj
396
397 def MakePrism2Ways(baseShape,point1,point2):
398     anObj = PrimOp.MakePrismTwoPnt2Ways(baseShape,point1,point2)
399     if PrimOp.IsDone() == 0:
400       print "MakePrismTwoPnt2Ways : ", PrimOp.GetErrorCode()
401     return anObj
402
403 def MakePrismVecH(baseShape,vector,height):
404     anObj = PrimOp.MakePrismVecH(baseShape,vector,height)
405     if PrimOp.IsDone() == 0:
406       print "MakePrismVecH : ", PrimOp.GetErrorCode()
407     return anObj
408
409 def MakePrismVecH2Ways(baseShape,vector,height):
410     anObj = PrimOp.MakePrismVecH2Ways(baseShape,vector,height)
411     if PrimOp.IsDone() == 0:
412       print "MakePrismVecH2Ways : ", PrimOp.GetErrorCode()
413     return anObj
414
415 def MakePipe(baseShape,pathShape):
416     anObj = PrimOp.MakePipe(baseShape,pathShape)
417     if PrimOp.IsDone() == 0:
418       print "MakePipe : ", PrimOp.GetErrorCode()
419     return anObj
420
421 def MakeRevolution(aShape,axis,angle):
422     anObj = PrimOp.MakeRevolutionAxisAngle(aShape,axis,angle)
423     if PrimOp.IsDone() == 0:
424       print "MakeRevolutionAxisAngle : ", PrimOp.GetErrorCode()
425     return anObj
426
427 def MakeRevolution2Ways(aShape,axis,angle):
428     anObj = PrimOp.MakeRevolutionAxisAngle2Ways(aShape,axis,angle)
429     if PrimOp.IsDone() == 0:
430       print "MakeRevolutionAxisAngle2Ways : ", PrimOp.GetErrorCode()
431     return anObj
432
433 # -----------------------------------------------------------------------------
434 # Create base shapes
435 # -----------------------------------------------------------------------------
436
437 def MakeEdge(p1,p2):
438     anObj = ShapesOp.MakeEdge(p1,p2)
439     if ShapesOp.IsDone() == 0:
440       print "MakeEdge : ", ShapesOp.GetErrorCode()
441     return anObj
442
443 def MakeWire(ListShape):
444     anObj = ShapesOp.MakeWire(ListShape)
445     if ShapesOp.IsDone() == 0:
446       print "MakeWire : ", ShapesOp.GetErrorCode()
447     return anObj
448
449 def MakeFace(aShapeWire,WantPlanarFace):
450     anObj = ShapesOp.MakeFace(aShapeWire,WantPlanarFace)
451     if ShapesOp.IsDone() == 0:
452       print "MakeFace : ", ShapesOp.GetErrorCode()
453     return anObj
454
455 def MakeFaceWires(ListWires,WantPlanarFace):
456     anObj = ShapesOp.MakeFaceWires(ListWires,WantPlanarFace)
457     if ShapesOp.IsDone() == 0:
458       print "MakeFaceWires : ", ShapesOp.GetErrorCode()
459     return anObj
460
461 def MakeFaces(ListWires,WantPlanarFace):
462     anObj = MakeFaceWires(ListWires,WantPlanarFace)
463     return anObj
464
465 def MakeShell(ListOfShapes):
466     anObj = ShapesOp.MakeShell(ListOfShapes)
467     if ShapesOp.IsDone() == 0:
468         print "MakeShell : ", ShapesOp.GetErrorCode()
469     return anObj
470
471 def MakeSolid(ListOfShells):
472     anObj = ShapesOp.MakeSolidShells(ListOfShells)
473     if ShapesOp.IsDone() == 0:
474         print "MakeSolid : ", ShapesOp.GetErrorCode()
475     return anObj
476
477 def MakeCompound(ListShape):
478     anObj = ShapesOp.MakeCompound(ListShape)
479     if ShapesOp.IsDone() == 0:
480       print "MakeCompound : ", ShapesOp.GetErrorCode()
481     return anObj
482
483 def NumberOfFaces(theShape):
484     nb_faces = ShapesOp.NumberOfFaces(theShape)
485     if ShapesOp.IsDone() == 0:
486       print "NumberOfFaces : ", ShapesOp.GetErrorCode()
487     return nb_faces
488
489 def NumberOfEdges(theShape):
490     nb_edges = ShapesOp.NumberOfEdges(theShape)
491     if ShapesOp.IsDone() == 0:
492       print "NumberOfEdges : ", ShapesOp.GetErrorCode()
493     return nb_edges
494
495 def ChangeOrientation(Shape):
496     anObj = ShapesOp.ChangeOrientation(Shape)
497     if ShapesOp.IsDone() == 0:
498       print "ChangeOrientation : ", ShapesOp.GetErrorCode()
499     return anObj
500
501 def OrientationChange(Shape):
502     anObj = ChangeOrientation(Shape)
503     return anObj
504
505 def GetFreeFacesIDs(theShape):
506     anIDs = ShapesOp.GetFreeFacesIDs(theShape)
507     if ShapesOp.IsDone() == 0:
508       print "GetFreeFacesIDs : ", ShapesOp.GetErrorCode()
509     return anIDs
510
511 def GetSharedShapes(theShape1, theShape2, theShapeType):
512     aList = ShapesOp.GetSharedShapes(theShape1, theShape2, theShapeType)
513     if ShapesOp.IsDone() == 0:
514       print "GetSharedShapes : ", ShapesOp.GetErrorCode()
515     return aList
516
517 def GetShapesOnPlane(theShape, theShapeType, theAx1, theState):
518     aList = ShapesOp.GetShapesOnPlane(theShape, theShapeType, theAx1, theState)
519     if ShapesOp.IsDone() == 0:
520       print "GetShapesOnPlane : ", ShapesOp.GetErrorCode()
521     return aList
522
523 def GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState):
524     aList = ShapesOp.GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState)
525     if ShapesOp.IsDone() == 0:
526         print "GetShapesOnPlaneIDs : ", ShapesOp.GetErrorCode()
527     return aList
528
529 def GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState):
530     aList = ShapesOp.GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState)
531     if ShapesOp.IsDone() == 0:
532       print "GetShapesOnCylinder : ", ShapesOp.GetErrorCode()
533     return aList
534
535 def GetShapesOnCylinderIDs(theShape, theShapeType, theAxis, theRadius, theState):
536     aList = ShapesOp.GetShapesOnCylinderIDs(theShape, theShapeType, theAxis, theRadius, theState)
537     if ShapesOp.IsDone() == 0:
538         print "GetShapesOnCylinderIDs : ", ShapesOp.GetErrorCode()
539     return aList
540
541 def GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState):
542     aList = ShapesOp.GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState)
543     if ShapesOp.IsDone() == 0:
544       print "GetShapesOnSphere : ", ShapesOp.GetErrorCode()
545     return aList
546
547 def GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState):
548     aList = ShapesOp.GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState)
549     if ShapesOp.IsDone() == 0:
550         print "GetShapesOnSphereIDs : ", ShapesOp.GetErrorCode()
551     return aList
552
553 def GetShapesOnQuadrangle(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState):
554     aList = ShapesOp.GetShapesOnQuadrangle(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState)
555     if ShapesOp.IsDone() == 0:
556       print "GetShapesOnQuadrangle : ", ShapesOp.GetErrorCode()
557     return aList
558
559 def GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState):
560     aList = ShapesOp.GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState)
561     if ShapesOp.IsDone() == 0:
562         print "GetShapesOnQuadrangleIDs : ", ShapesOp.GetErrorCode()
563     return aList
564
565 def GetInPlace(theShapeWhere, theShapeWhat):
566     anObj = ShapesOp.GetInPlace(theShapeWhere, theShapeWhat)
567     if ShapesOp.IsDone() == 0:
568       print "GetInPlace : ", ShapesOp.GetErrorCode()
569     return anObj
570
571 # -----------------------------------------------------------------------------
572 # Access to sub-shapes by their unique IDs inside the main shape.
573 # -----------------------------------------------------------------------------
574
575 # Obtain a composite sub-shape of <aShape>, composed from sub-shapes
576 # of <aShape>, selected by their unique IDs inside <aShape>
577 def GetSubShape(aShape, ListOfID):
578     anObj = geom.AddSubShape(aShape,ListOfID)
579     return anObj
580
581 # Obtain unique ID of sub-shape <aSubShape> inside <aShape>
582 def GetSubShapeID(aShape, aSubShape):
583     anID = LocalOp.GetSubShapeIndex(aShape, aSubShape)
584     if LocalOp.IsDone() == 0:
585       print "GetSubShapeIndex : ", LocalOp.GetErrorCode()
586     return anID
587
588 # -----------------------------------------------------------------------------
589 # Decompose objects
590 # -----------------------------------------------------------------------------
591
592 def SubShapeAll(aShape, aType):
593     ListObj = ShapesOp.MakeExplode(aShape,aType,0)
594     if ShapesOp.IsDone() == 0:
595       print "MakeExplode : ", ShapesOp.GetErrorCode()
596     return ListObj
597
598 def SubShapeAllIDs(aShape, aType):
599     ListObj = ShapesOp.SubShapeAllIDs(aShape,aType,0)
600     if ShapesOp.IsDone() == 0:
601       print "SubShapeAllIDs : ", ShapesOp.GetErrorCode()
602     return ListObj
603
604 def SubShapeAllSorted(aShape, aType):
605     ListObj = ShapesOp.MakeExplode(aShape,aType,1)
606     if ShapesOp.IsDone() == 0:
607       print "MakeExplode : ", ShapesOp.GetErrorCode()
608     return ListObj
609
610 def SubShapeAllSortedIDs(aShape, aType):
611     ListIDs = ShapesOp.SubShapeAllIDs(aShape,aType,1)
612     if ShapesOp.IsDone() == 0:
613       print "SubShapeAllSortedIDs : ", ShapesOp.GetErrorCode()
614     return ListObj
615
616 # Obtain a compound of sub-shapes of <aShape>,
617 # selected by they indices in list of all sub-shapes of type <aType>
618 def SubShape(aShape, aType, ListOfInd):
619     ListOfIDs = []
620     AllShapeList = SubShapeAll(aShape, aType)
621     for ind in ListOfInd:
622         ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
623     anObj = GetSubShape(aShape, ListOfIDs)
624     return anObj
625
626 # Obtain a compound of sub-shapes of <aShape>,
627 # selected by they indices in sorted list of all sub-shapes of type <aType>
628 def SubShapeSorted(aShape, aType, ListOfInd):
629     ListOfIDs = []
630     AllShapeList = SubShapeAllSorted(aShape, aType)
631     for ind in ListOfInd:
632         ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
633     anObj = GetSubShape(aShape, ListOfIDs)
634     return anObj
635
636 # -----------------------------------------------------------------------------
637 # Healing operations
638 # -----------------------------------------------------------------------------
639
640 def ProcessShape(Shape, Operators, Parameters, Values):
641     anObj = HealOp.ProcessShape(Shape, Operators, Parameters, Values)
642     if HealOp.IsDone() == 0:
643         print "ProcessShape : ", HealOp.GetErrorCode()
644     return anObj
645
646 def SuppressFaces(aShape,ListOfId):
647     anObj = HealOp.SuppressFaces(aShape,ListOfId)
648     if HealOp.IsDone() == 0:
649       print "SuppressFaces : ", HealOp.GetErrorCode()
650     return anObj
651
652 def MakeSewing(ListShape,precision):
653     comp = MakeCompound(ListShape)
654     anObj = Sew(comp,precision)
655     return anObj
656
657 def Sew(aShape,precision):
658     anObj = HealOp.Sew(aShape,precision)
659     if HealOp.IsDone() == 0:
660       print "Sew : ", HealOp.GetErrorCode()
661     return anObj
662
663 def SuppressInternalWires(aShape, Wires):
664     anObj = HealOp.RemoveIntWires(aShape, Wires)
665     if HealOp.IsDone() == 0:
666       print "SuppressInternalWires : ", HealOp.GetErrorCode()
667     return anObj
668
669 def SuppressHoles(aShape, ListOfId):
670     anObj = HealOp.FillHoles(aShape,ListOfId)
671     if HealOp.IsDone() == 0:
672       print "SuppressHoles : ", HealOp.GetErrorCode()
673     return anObj
674
675 def CloseContour(aShape, Wires, IsCommonVertex):
676     anObj = HealOp.CloseContour(aShape, Wires, IsCommonVertex)
677     if HealOp.IsDone() == 0:
678       print "CloseContour : ", HealOp.GetErrorCode()
679     return anObj
680
681 def DivideEdge(aShape, EdgeID, Value, IsByParameter):
682     anObj = HealOp.DivideEdge(aShape, EdgeID, Value, IsByParameter)
683     if HealOp.IsDone() == 0:
684       print "DivideEdge : ", HealOp.GetErrorCode()
685     return anObj
686
687 def GetFreeBoundary(Shape):
688     anObj = HealOp.GetFreeBoundary(Shape)
689     if HealOp.IsDone() == 0:
690       print "GetFreeBoundaries : ", HealOp.GetErrorCode()
691     return anObj
692
693 # -----------------------------------------------------------------------------
694 # Create advanced objects
695 # -----------------------------------------------------------------------------
696
697 def MakeCopy(aShape):
698     anObj = InsertOp.MakeCopy(aShape)
699     if InsertOp.IsDone() == 0:
700       print "MakeCopy : ", InsertOp.GetErrorCode()
701     return anObj
702
703 def MakeFilling(aShape,mindeg,maxdeg,tol2d,tol3d,nbiter):
704     anObj = PrimOp.MakeFilling(aShape,mindeg,maxdeg,tol2d,tol3d,nbiter)
705     if PrimOp.IsDone() == 0:
706       print "MakeFilling : ", PrimOp.GetErrorCode()
707     return anObj
708
709 def MakeGlueFaces(aShape,aTolerance):
710     anObj = ShapesOp.MakeGlueFaces(aShape,aTolerance)
711     if ShapesOp.IsDone() == 0:
712       print "MakeGlueFaces : ", ShapesOp.GetErrorCode()
713     return anObj
714
715 # -----------------------------------------------------------------------------
716 # Boolean (Common, Cut, Fuse, Section)
717 # -----------------------------------------------------------------------------
718
719 def MakeBoolean(shape1,shape2,operation):
720     anObj = BoolOp.MakeBoolean(shape1,shape2,operation)
721     if BoolOp.IsDone() == 0:
722       print "MakeBoolean : ", BoolOp.GetErrorCode()
723     return anObj
724
725 def MakeCommon(s1, s2):
726     return MakeBoolean(s1, s2, 1)
727
728 def MakeCut(s1, s2):
729     return MakeBoolean(s1, s2, 2)
730
731 def MakeFuse(s1, s2):
732     return MakeBoolean(s1, s2, 3)
733
734 def MakeSection(s1, s2):
735     return MakeBoolean(s1, s2, 4)
736
737 def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
738                   Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[],
739                   KeepNonlimitShapes=0):
740     anObj = BoolOp.MakePartition(ListShapes, ListTools,
741                                  ListKeepInside, ListRemoveInside,
742                                  Limit, RemoveWebs, ListMaterials,
743                                  KeepNonlimitShapes);
744     if BoolOp.IsDone() == 0:
745       print "MakePartition : ", BoolOp.GetErrorCode()
746     return anObj
747
748 def Partition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
749               Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[],
750               KeepNonlimitShapes=0):
751     anObj = MakePartition(ListShapes, ListTools,
752                           ListKeepInside, ListRemoveInside,
753                           Limit, RemoveWebs, ListMaterials,
754                           KeepNonlimitShapes);
755     return anObj
756
757 def MakeHalfPartition(theShape, thePlane):
758     anObj = BoolOp.MakeHalfPartition(theShape, thePlane)
759     if BoolOp.IsDone() == 0:
760       print "MakeHalfPartition : ", BoolOp.GetErrorCode()
761     return anObj
762
763 # -----------------------------------------------------------------------------
764 # Transform objects
765 # -----------------------------------------------------------------------------
766
767 def MakeTranslationTwoPoints(aShape,point1,point2):
768     anObj = TrsfOp.TranslateTwoPointsCopy(aShape,point1,point2)
769     if TrsfOp.IsDone() == 0:
770       print "TranslateTwoPointsCopy : ", TrsfOp.GetErrorCode()
771     return anObj
772
773 def MakeTranslation(aShape,dx,dy,dz):
774     anObj = TrsfOp.TranslateDXDYDZCopy(aShape,dx,dy,dz)
775     if TrsfOp.IsDone() == 0:
776       print "TranslateDXDYDZCopy : ", TrsfOp.GetErrorCode()
777     return anObj
778
779 def MakeTranslationVector(theObject, theVector):
780     anObj = TrsfOp.TranslateVectorCopy(theObject, theVector)
781     if TrsfOp.IsDone() == 0:
782       print "TranslateVectorCopy : ", TrsfOp.GetErrorCode()
783     return anObj
784
785 def MakeRotation(aShape,axis,angle):
786     anObj = TrsfOp.RotateCopy(aShape,axis,angle)
787     if TrsfOp.IsDone() == 0:
788       print "RotateCopy : ", TrsfOp.GetErrorCode()
789     return anObj
790
791 def MakeRotationThreePoints(aShape, centpoint, point1, point2):
792     anObj = TrsfOp.RotateThreePointsCopy(aShape, centpoint, point1, point2)
793     if TrsfOp.IsDone() == 0:
794       print "RotateThreePointsCopy : ", TrsfOp.GetErrorCode()
795     return anObj
796
797 def MakeScaleTransform(aShape,theCenterofScale,factor):
798     anObj = TrsfOp.ScaleShapeCopy(aShape,theCenterofScale,factor)
799     if TrsfOp.IsDone() == 0:
800       print "ScaleShapeCopy : ", TrsfOp.GetErrorCode()
801     return anObj
802
803 def MakeMirrorByPlane(aShape,aPlane):
804     anObj = TrsfOp.MirrorPlaneCopy(aShape,aPlane)
805     if TrsfOp.IsDone() == 0:
806       print "MirrorPlaneCopy : ", TrsfOp.GetErrorCode()
807     return anObj
808
809 def MakeMirrorByAxis(theObject, theAxis):
810     anObj = TrsfOp.MirrorAxisCopy(theObject, theAxis)
811     if TrsfOp.IsDone() == 0:
812       print "MirrorAxisCopy : ", TrsfOp.GetErrorCode()
813     return anObj
814
815 def MakeMirrorByPoint(theObject, thePoint):
816     anObj = TrsfOp.MirrorPointCopy(theObject, thePoint)
817     if TrsfOp.IsDone() == 0:
818       print "MirrorPointCopy : ", TrsfOp.GetErrorCode()
819     return anObj
820
821 def MakePosition(aShape,theStartLCS,theEndLCS):
822     anObj = TrsfOp.PositionShapeCopy(aShape,theStartLCS,theEndLCS)
823     if TrsfOp.IsDone() == 0:
824       print "PositionShapeCopy : ", TrsfOp.GetErrorCode()
825     return anObj
826
827 def MakeOffset(aShape, anOffset):
828     anObj = TrsfOp.OffsetShapeCopy(aShape, anOffset)
829     if TrsfOp.IsDone() == 0:
830       print "OffsetShapeCopy : ", TrsfOp.GetErrorCode()
831     return anObj
832
833 # -----------------------------------------------------------------------------
834 # Patterns
835 # -----------------------------------------------------------------------------
836
837 def MakeMultiTranslation1D(aShape,aDir,aStep,aNbTimes):
838     anObj = TrsfOp.MultiTranslate1D(aShape,aDir,aStep,aNbTimes)
839     if TrsfOp.IsDone() == 0:
840       print "MultiTranslate1D : ", TrsfOp.GetErrorCode()
841     return anObj
842
843 def MakeMultiTranslation2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2):
844     anObj = TrsfOp.MultiTranslate2D(aShape,d1,step1,nbtimes1,d2,step2,nbtimes2)
845     if TrsfOp.IsDone() == 0:
846       print "MultiTranslate2D : ", TrsfOp.GetErrorCode()
847     return anObj
848
849 def MultiRotate1D(aShape,aVec,aNbTimes):
850     anObj = TrsfOp.MultiRotate1D(aShape,aVec,aNbTimes)
851     if TrsfOp.IsDone() == 0:
852       print "MultiRotate1D : ", TrsfOp.GetErrorCode()
853     return anObj
854
855 def MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2):
856     anObj = TrsfOp.MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
857     if TrsfOp.IsDone() == 0:
858       print "MultiRotate2D : ", TrsfOp.GetErrorCode()
859     return anObj
860
861 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
862     aVec = MakeLine(aPoint,aDir)
863     anObj = MultiRotate1D(aShape,aVec,aNbTimes)
864     return anObj
865
866 def MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2):
867     aVec = MakeLine(aPoint,aDir)
868     anObj = MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
869     return anObj
870
871 # -----------------------------------------------------------------------------
872 # Local operations
873 # -----------------------------------------------------------------------------
874
875 def MakeFilletAll(aShape,radius):
876     anObj = LocalOp.MakeFilletAll(aShape,radius)
877     if LocalOp.IsDone() == 0:
878       print "MakeFilletAll : ", LocalOp.GetErrorCode()
879     return anObj
880
881 def MakeFillet(aShape,radius,aShapeType,ListShape):
882     anObj = None
883     if aShapeType == ShapeType["EDGE"]:
884         anObj = LocalOp.MakeFilletEdges(aShape,radius,ListShape)
885     else:
886         anObj = LocalOp.MakeFilletFaces(aShape,radius,ListShape)
887     if LocalOp.IsDone() == 0:
888       print "MakeFillet : ", LocalOp.GetErrorCode()
889     return anObj
890
891 def MakeFilletR1R2(aShape,radius1,radius2,aShapeType,ListShape):
892     anObj = None
893     if aShapeType == ShapeType["EDGE"]:
894         anObj = LocalOp.MakeFilletEdgesR1R2(aShape,radius1,radius2,ListShape)
895     else:
896         anObj = LocalOp.MakeFilletFacesR1R2(aShape,radius1,radius2,ListShape)
897     if LocalOp.IsDone() == 0:
898       print "MakeFilletR1R2 : ", LocalOp.GetErrorCode()
899     return anObj
900
901 def MakeChamferAll(aShape,d):
902     anObj = LocalOp.MakeChamferAll(aShape,d)
903     if LocalOp.IsDone() == 0:
904       print "MakeChamferAll : ", LocalOp.GetErrorCode()
905     return anObj
906
907 def MakeChamferEdge(aShape,d1,d2,face1,face2):
908     anObj = LocalOp.MakeChamferEdge(aShape,d1,d2,face1,face2)
909     if LocalOp.IsDone() == 0:
910       print "MakeChamferEdge : ", LocalOp.GetErrorCode()
911     return anObj
912
913 def MakeChamferEdgeAD(aShape,d,angle,face1,face2):
914     anObj = LocalOp.MakeChamferEdgeAD(aShape,d,angle,face1,face2)
915     if LocalOp.IsDone() == 0:
916       print "MakeChamferEdgeAD : ", LocalOp.GetErrorCode()
917     return anObj
918
919 def MakeChamferFaces(aShape,d1,d2,ListShape):
920     anObj = LocalOp.MakeChamferFaces(aShape,d1,d2,ListShape)
921     if LocalOp.IsDone() == 0:
922       print "MakeChamferFaces : ", LocalOp.GetErrorCode()
923     return anObj
924
925 def MakeChamferFacesAD(aShape,d,angle,ListShape):
926     anObj = LocalOp.MakeChamferFacesAD(aShape,d,angle,ListShape)
927     if LocalOp.IsDone() == 0:
928       print "MakeChamferFacesAD : ", LocalOp.GetErrorCode()
929     return anObj
930
931 def MakeChamferEdges(aShape,d1,d2,ListShape):
932     anObj = LocalOp.MakeChamferEdges(aShape,d1,d2,ListShape)
933     if LocalOp.IsDone() == 0:
934       print "MakeChamferEdges : ", LocalOp.GetErrorCode()
935     return anObj
936
937 def MakeChamferEdgesAD(aShape,d,angle,ListShape):
938     anObj = LocalOp.MakeChamferEdgesAD(aShape,d,angle,ListShape)
939     if LocalOp.IsDone() == 0:
940       print "MakeChamferEdgesAD : ", LocalOp.GetErrorCode()
941     return anObj
942
943 def MakeChamfer(aShape,d1,d2,aShapeType,ListShape):
944     anObj = None
945     if aShapeType == ShapeType["EDGE"]:
946         anObj = MakeChamferEdge(aShape,d1,d2,ListShape[0],ListShape[1])
947     else:
948         anObj = MakeChamferFaces(aShape,d1,d2,ListShape)
949     return anObj
950
951 def Archimede(aShape,weight,WaterDensity,MeshingDeflection):
952     anObj = LocalOp.MakeArchimede(aShape,weight,WaterDensity,MeshingDeflection)
953     if LocalOp.IsDone() == 0:
954       print "MakeArchimede : ", LocalOp.GetErrorCode()
955     return anObj
956
957 # -----------------------------------------------------------------------------
958 # Information objects
959 # -----------------------------------------------------------------------------
960
961 def PointCoordinates(Point):
962     aTuple = MeasuOp.PointCoordinates(Point)
963     if MeasuOp.IsDone() == 0:
964       print "PointCoordinates : ", MeasuOp.GetErrorCode()
965     return aTuple
966
967 def BasicProperties(Shape):
968     aTuple = MeasuOp.GetBasicProperties(Shape)
969     if MeasuOp.IsDone() == 0:
970       print "BasicProperties : ", MeasuOp.GetErrorCode()
971     return aTuple
972
973 def BoundingBox(Shape):
974     aTuple = MeasuOp.GetBoundingBox(Shape)
975     if MeasuOp.IsDone() == 0:
976       print "BoundingBox : ", MeasuOp.GetErrorCode()
977     return aTuple
978
979 def Inertia(Shape):
980     aTuple = MeasuOp.GetInertia(Shape)
981     if MeasuOp.IsDone() == 0:
982       print "Inertia : ", MeasuOp.GetErrorCode()
983     return aTuple
984
985 def MinDistance(Shape1, Shape2):
986     aTuple = MeasuOp.GetMinDistance(Shape1, Shape2)
987     if MeasuOp.IsDone() == 0:
988       print "MinDistance : ", MeasuOp.GetErrorCode()
989     return aTuple[0]
990
991 def Tolerance(Shape):
992     aTuple = MeasuOp.GetTolerance(Shape)
993     if MeasuOp.IsDone() == 0:
994       print "Tolerance : ", MeasuOp.GetErrorCode()
995     return aTuple
996
997 def WhatIs(Shape):
998     aDescr = MeasuOp.WhatIs(Shape)
999     if MeasuOp.IsDone() == 0:
1000       print "WhatIs : ", MeasuOp.GetErrorCode()
1001     return aDescr
1002
1003 def MakeCDG(aShape):
1004     anObj = MeasuOp.GetCentreOfMass(aShape)
1005     if MeasuOp.IsDone() == 0:
1006       print "GetCentreOfMass : ", MeasuOp.GetErrorCode()
1007     return anObj
1008
1009 def CheckShape(theShape, theIsCheckGeom = 0):
1010     if theIsCheckGeom:
1011         (IsValid, Status) = MeasuOp.CheckShapeWithGeometry(theShape)
1012     else:
1013         (IsValid, Status) = MeasuOp.CheckShape(theShape)
1014
1015     if MeasuOp.IsDone() == 0:
1016       print "CheckShape : ", MeasuOp.GetErrorCode()
1017     else:
1018       if IsValid == 0:
1019         print Status
1020     return IsValid
1021
1022 # -----------------------------------------------------------------------------
1023 # Import/Export objects
1024 # -----------------------------------------------------------------------------
1025
1026 def Import(filename, formatname):
1027     anObj = InsertOp.Import(filename, formatname)
1028     if InsertOp.IsDone() == 0:
1029       print "Import : ", InsertOp.GetErrorCode()
1030     return anObj
1031
1032 def ImportBREP(theFileName):
1033     return Import(theFileName, "BREP")
1034
1035 def ImportIGES(theFileName):
1036     return Import(theFileName, "IGES")
1037
1038 def ImportSTEP(theFileName):
1039     return Import(theFileName, "STEP")
1040
1041 def Export(aShape, filename, formatname):
1042     InsertOp.Export(aShape, filename, formatname)
1043     if InsertOp.IsDone() == 0:
1044       print "Export : ", InsertOp.GetErrorCode()
1045
1046 def ExportBREP(theObject, theFileName):
1047     return Export(theObject, theFileName, "BREP")
1048
1049 def ExportIGES(theObject, theFileName):
1050     return Export(theObject, theFileName, "IGES")
1051
1052 def ExportSTEP(theObject, theFileName):
1053     return Export(theObject, theFileName, "STEP")
1054
1055 # -----------------------------------------------------------------------------
1056 # Block operations
1057 # -----------------------------------------------------------------------------
1058
1059 def MakeQuad(E1, E2, E3, E4):
1060     anObj = BlocksOp.MakeQuad(E1, E2, E3, E4)
1061     if BlocksOp.IsDone() == 0:
1062       print "MakeQuad : ", BlocksOp.GetErrorCode()
1063     return anObj
1064
1065 def MakeQuad2Edges(E1, E2):
1066     anObj = BlocksOp.MakeQuad2Edges(E1, E2)
1067     if BlocksOp.IsDone() == 0:
1068       print "MakeQuad2Edges : ", BlocksOp.GetErrorCode()
1069     return anObj
1070
1071 def MakeQuad4Vertices(V1, V2, V3, V4):
1072     anObj = BlocksOp.MakeQuad4Vertices(V1, V2, V3, V4)
1073     if BlocksOp.IsDone() == 0:
1074       print "MakeQuad4Vertices : ", BlocksOp.GetErrorCode()
1075     return anObj
1076
1077 def MakeHexa(F1, F2, F3, F4, F5, F6):
1078     anObj = BlocksOp.MakeHexa(F1, F2, F3, F4, F5, F6)
1079     if BlocksOp.IsDone() == 0:
1080       print "MakeHexa : ", BlocksOp.GetErrorCode()
1081     return anObj
1082
1083 def MakeHexa2Faces(F1, F2):
1084     anObj = BlocksOp.MakeHexa2Faces(F1, F2)
1085     if BlocksOp.IsDone() == 0:
1086       print "MakeHexa2Faces : ", BlocksOp.GetErrorCode()
1087     return anObj
1088
1089 def GetPoint(theShape, theX, theY, theZ, theEpsilon):
1090     anObj = BlocksOp.GetPoint(theShape, theX, theY, theZ, theEpsilon)
1091     if BlocksOp.IsDone() == 0:
1092       print "GetPoint : ", BlocksOp.GetErrorCode()
1093     return anObj
1094
1095 def GetEdge(theShape, thePoint1, thePoint2):
1096     anObj = BlocksOp.GetEdge(theShape, thePoint1, thePoint2)
1097     if BlocksOp.IsDone() == 0:
1098       print "GetEdge : ", BlocksOp.GetErrorCode()
1099     return anObj
1100
1101 def GetEdgeNearPoint(theShape, thePoint):
1102     anObj = BlocksOp.GetEdgeNearPoint(theShape, thePoint)
1103     if BlocksOp.IsDone() == 0:
1104       print "GetEdgeNearPoint : ", BlocksOp.GetErrorCode()
1105     return anObj
1106
1107 def GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4):
1108     anObj = BlocksOp.GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4)
1109     if BlocksOp.IsDone() == 0:
1110       print "GetFaceByPoints : ", BlocksOp.GetErrorCode()
1111     return anObj
1112
1113 def GetFaceByEdges(theShape, theEdge1, theEdge2):
1114     anObj = BlocksOp.GetFaceByEdges(theShape, theEdge1, theEdge2)
1115     if BlocksOp.IsDone() == 0:
1116       print "GetFaceByEdges : ", BlocksOp.GetErrorCode()
1117     return anObj
1118
1119 def GetOppositeFace(theBlock, theFace):
1120     anObj = BlocksOp.GetOppositeFace(theBlock, theFace)
1121     if BlocksOp.IsDone() == 0:
1122       print "GetOppositeFace : ", BlocksOp.GetErrorCode()
1123     return anObj
1124
1125 def GetFaceNearPoint(theShape, thePoint):
1126     anObj = BlocksOp.GetFaceNearPoint(theShape, thePoint)
1127     if BlocksOp.IsDone() == 0:
1128       print "GetFaceNearPoint : ", BlocksOp.GetErrorCode()
1129     return anObj
1130
1131 def GetFaceByNormale(theBlock, theVector):
1132     anObj = BlocksOp.GetFaceByNormale(theBlock, theVector)
1133     if BlocksOp.IsDone() == 0:
1134       print "GetFaceByNormale : ", BlocksOp.GetErrorCode()
1135     return anObj
1136
1137 def CheckCompoundOfBlocks(theCompound):
1138     (IsValid, BCErrors) = BlocksOp.CheckCompoundOfBlocks(theCompound)
1139     if BlocksOp.IsDone() == 0:
1140       print "CheckCompoundOfBlocks : ", BlocksOp.GetErrorCode()
1141     else:
1142       if IsValid == 0:
1143         Descr = BlocksOp.PrintBCErrors(theCompound, BCErrors)
1144         print Descr
1145     return IsValid
1146
1147 def RemoveExtraEdges(theShape):
1148     anObj = BlocksOp.RemoveExtraEdges(theShape)
1149     if BlocksOp.IsDone() == 0:
1150       print "RemoveExtraEdges : ", BlocksOp.GetErrorCode()
1151     return anObj
1152
1153 def CheckAndImprove(theShape):
1154     anObj = BlocksOp.CheckAndImprove(theShape)
1155     if BlocksOp.IsDone() == 0:
1156       print "CheckAndImprove : ", BlocksOp.GetErrorCode()
1157     return anObj
1158
1159 def MakeBlockExplode(theCompound, theMinNbFaces, theMaxNbFaces):
1160     aList = BlocksOp.ExplodeCompoundOfBlocks(theCompound, theMinNbFaces, theMaxNbFaces)
1161     if BlocksOp.IsDone() == 0:
1162       print "MakeBlockExplode : ", BlocksOp.GetErrorCode()
1163     return aList
1164
1165 def GetBlockNearPoint(theCompound, thePoint):
1166     anObj = BlocksOp.GetBlockNearPoint(theCompound, thePoint)
1167     if BlocksOp.IsDone() == 0:
1168       print "GetBlockNearPoint : ", BlocksOp.GetErrorCode()
1169     return anObj
1170
1171 def GetBlockByParts(theCompound, theParts):
1172     anObj = BlocksOp.GetBlockByParts(theCompound, theParts)
1173     if BlocksOp.IsDone() == 0:
1174       print "GetBlockByParts : ", BlocksOp.GetErrorCode()
1175     return anObj
1176
1177 def GetBlocksByParts(theCompound, theParts):
1178     aList = BlocksOp.GetBlocksByParts(theCompound, theParts)
1179     if BlocksOp.IsDone() == 0:
1180       print "GetBlocksByParts : ", BlocksOp.GetErrorCode()
1181     return aList
1182
1183 def MakeMultiTransformation1D(Block, DirFaceID1, DirFaceID2, NbTimes):
1184     anObj = BlocksOp.MakeMultiTransformation1D(Block, DirFaceID1, DirFaceID2, NbTimes)
1185     if BlocksOp.IsDone() == 0:
1186       print "MakeMultiTransformation1D : ", BlocksOp.GetErrorCode()
1187     return anObj
1188
1189 def MakeMultiTransformation2D(Block, DirFaceID1U, DirFaceID2U, NbTimesU,
1190                                      DirFaceID1V, DirFaceID2V, NbTimesV):
1191     anObj = BlocksOp.MakeMultiTransformation2D(Block, DirFaceID1U, DirFaceID2U, NbTimesU,
1192                                                       DirFaceID1V, DirFaceID2V, NbTimesV)
1193     if BlocksOp.IsDone() == 0:
1194       print "MakeMultiTransformation2D : ", BlocksOp.GetErrorCode()
1195     return anObj
1196
1197 def Propagate(theShape):
1198     listChains = BlocksOp.Propagate(theShape)
1199     if BlocksOp.IsDone() == 0:
1200       print "Propagate : ", BlocksOp.GetErrorCode()
1201     return listChains
1202
1203 # -----------------------------------------------------------------------------
1204 # Group operations
1205 # -----------------------------------------------------------------------------
1206
1207 def CreateGroup(MainShape, ShapeType):
1208     anObj = GroupOp.CreateGroup(MainShape, ShapeType)
1209     if GroupOp.IsDone() == 0:
1210        print "CreateGroup : ", GroupOp.GetErrorCode()
1211     return anObj
1212
1213 def AddObject(Group, SubShapeID):
1214     GroupOp.AddObject(Group, SubShapeID)
1215     if GroupOp.IsDone() == 0:
1216       print "AddObject : ", GroupOp.GetErrorCode()
1217
1218 def RemoveObject(Group, SubShapeID):
1219     GroupOp.RemoveObject(Group, SubShapeID)
1220     if GroupOp.IsDone() == 0:
1221       print "RemoveObject : ", GroupOp.GetErrorCode()
1222
1223 def UnionList (theGroup, theSubShapes):
1224     GroupOp.UnionList(theGroup, theSubShapes)
1225     if GroupOp.IsDone() == 0:
1226       print "UnionList : ", GroupOp.GetErrorCode()
1227
1228 def UnionIDs(theGroup, theSubShapes):
1229     GroupOp.UnionIDs(theGroup, theSubShapes)
1230     if GroupOp.IsDone() == 0:
1231         print "UnionIDs : ", GroupOp.GetErrorCode()
1232
1233 def DifferenceList (theGroup, theSubShapes):
1234     GroupOp.DifferenceList(theGroup, theSubShapes)
1235     if GroupOp.IsDone() == 0:
1236       print "DifferenceList : ", GroupOp.GetErrorCode()
1237
1238 def DifferenceIDs(theGroup, theSubShapes):
1239     GroupOp.DifferenceIDs(theGroup, theSubShapes)
1240     if GroupOp.IsDone() == 0:
1241         print "DifferenceIDs : ", GroupOp.GetErrorCode()
1242
1243 def GetObjectIDs(Group):
1244     ListIDs = GroupOp.GetObjects(Group)
1245     if GroupOp.IsDone() == 0:
1246       print "GetObjectIDs : ", GroupOp.GetErrorCode()
1247     return ListIDs
1248
1249 def GetType(theGroup):
1250     aType = GroupOp.GetType(theGroup)
1251     if GroupOp.IsDone() == 0:
1252       print "GetType : ", GroupOp.GetErrorCode()
1253     return aType
1254
1255 def GetMainShape(theGroup):
1256     anObj = GroupOp.GetMainShape(theGroup)
1257     if GroupOp.IsDone() == 0:
1258       print "GetMainShape : ", GroupOp.GetErrorCode()
1259     return anObj
1260
1261 def GetEdgesByLength (theShape, min_length, max_length, include_min = 1, include_max = 1):
1262     """
1263     Create group of edges of theShape, whose length is in range [min_length, max_length].
1264     If include_min/max == 0, edges with length == min/max_length will not be included in result.
1265     """
1266
1267     edges = SubShapeAll(theShape, ShapeType["EDGE"])
1268     edges_in_range = []
1269     for edge in edges:
1270         Props = BasicProperties(edge)
1271         if min_length <= Props[0] and Props[0] <= max_length:
1272             if (not include_min) and (min_length == Props[0]):
1273                 skip = 1
1274             else:
1275                 if (not include_max) and (Props[0] == max_length):
1276                     skip = 1
1277                 else:
1278                     edges_in_range.append(edge)
1279
1280     if len(edges_in_range) <= 0:
1281         print "No edges found by given criteria"
1282         return 0
1283
1284     group_edges = CreateGroup(theShape, ShapeType["EDGE"])
1285     UnionList(group_edges, edges_in_range)
1286
1287     return group_edges
1288
1289 # Add Path to the system path
1290 #
1291 def addPath(Path):
1292     if (sys.path.count(Path) < 1):
1293         sys.path.append(Path)