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