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