Salome HOME
PAL 12719 : Add an arc constructor
[modules/geom.git] / src / GEOM_SWIG / 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 import salome
30 salome.salome_init()
31 from salome import *
32
33 import GEOM
34
35 """
36     \namespace geompy
37     \brief Module geompy
38 """
39
40 g = lcc.FindOrLoadComponent("FactoryServer", "GEOM")
41 geom = g._narrow( GEOM.GEOM_Gen )
42 #gg = ImportComponentGUI("GEOM")
43 #gg.initGeomGen()
44
45 #SRN: modified on Mar 18, 2005
46
47 myBuilder = None
48 myStudyId = 0
49 father    = None
50
51 BasicOp  = None
52 CurvesOp = None
53 PrimOp   = None
54 ShapesOp = None
55 HealOp   = None
56 InsertOp = None
57 BoolOp   = None
58 TrsfOp   = None
59 LocalOp  = None
60 MeasuOp  = None
61 BlocksOp = None
62 GroupOp  = None
63
64 def init_geom(theStudy):
65
66     global myStudy, myBuilder, myStudyId, BasicOp, CurvesOp, PrimOp, ShapesOp, HealOp
67     global InsertOp, BoolOp, TrsfOp, LocalOp, MeasuOp, BlocksOp, GroupOp, father
68
69     myStudy = theStudy
70     myStudyId = myStudy._get_StudyId()
71     myBuilder = myStudy.NewBuilder()
72     father = myStudy.FindComponent("GEOM")
73     if father is None:
74         father = myBuilder.NewComponent("GEOM")
75         A1 = myBuilder.FindOrCreateAttribute(father, "AttributeName")
76         FName = A1._narrow(SALOMEDS.AttributeName)
77         FName.SetValue("Geometry")
78         A2 = myBuilder.FindOrCreateAttribute(father, "AttributePixMap")
79         aPixmap = A2._narrow(SALOMEDS.AttributePixMap)
80         aPixmap.SetPixMap("ICON_OBJBROWSER_Geometry")
81         myBuilder.DefineComponentInstance(father,geom)
82         pass
83
84     # -----------------------------------------------------------------------------
85     # Assign Operations Interfaces
86     # -----------------------------------------------------------------------------
87
88     BasicOp  = geom.GetIBasicOperations    (myStudyId)
89     CurvesOp = geom.GetICurvesOperations   (myStudyId)
90     PrimOp   = geom.GetI3DPrimOperations   (myStudyId)
91     ShapesOp = geom.GetIShapesOperations   (myStudyId)
92     HealOp   = geom.GetIHealingOperations  (myStudyId)
93     InsertOp = geom.GetIInsertOperations   (myStudyId)
94     BoolOp   = geom.GetIBooleanOperations  (myStudyId)
95     TrsfOp   = geom.GetITransformOperations(myStudyId)
96     LocalOp  = geom.GetILocalOperations    (myStudyId)
97     MeasuOp  = geom.GetIMeasureOperations  (myStudyId)
98     BlocksOp = geom.GetIBlocksOperations   (myStudyId)
99     GroupOp  = geom.GetIGroupOperations   (myStudyId)
100     pass
101
102 init_geom(myStudy)
103
104 #SRN: end of modifications
105
106 ## Get name for sub-shape aSubObj of shape aMainObj
107 #
108 #  Example: see GEOM_TestAll.py
109 def SubShapeName(aSubObj, aMainObj):
110     #aSubId  = orb.object_to_string(aSubObj)
111     #aMainId = orb.object_to_string(aMainObj)
112     #index = gg.getIndexTopology(aSubId, aMainId)
113     #name = gg.getShapeTypeString(aSubId) + "_%d"%(index)
114     index = ShapesOp.GetTopologyIndex(aMainObj, aSubObj)
115     name = ShapesOp.GetShapeTypeString(aSubObj) + "_%d"%(index)
116     return name
117
118 ## Publish in study aShape with name aName
119 #
120 #  Example: see GEOM_TestAll.py
121 def addToStudy(aShape, aName):
122     try:
123         aSObject = geom.AddInStudy(myStudy, aShape, aName, None)
124     except:
125         print "addToStudy() failed"
126         return ""
127     return aShape.GetStudyEntry()
128
129 ## Publish in study aShape with name aName as sub-object of previously published aFather
130 #
131 #  Example: see GEOM_TestAll.py
132 def addToStudyInFather(aFather, aShape, aName):
133     try:
134         aSObject = geom.AddInStudy(myStudy, aShape, aName, aFather)
135     except:
136         print "addToStudyInFather() failed"
137         return ""
138     return aShape.GetStudyEntry()
139
140 # -----------------------------------------------------------------------------
141 # enumeration ShapeType as a dictionary
142 # -----------------------------------------------------------------------------
143
144 ShapeType = {"COMPOUND":0, "COMPSOLID":1, "SOLID":2, "SHELL":3, "FACE":4, "WIRE":5, "EDGE":6, "VERTEX":7, "SHAPE":8}
145
146 # -----------------------------------------------------------------------------
147 # Basic primitives
148 # -----------------------------------------------------------------------------
149
150 ## Create point by three coordinates.
151 #  @param theX The X coordinate of the point.
152 #  @param theY The Y coordinate of the point.
153 #  @param theZ The Z coordinate of the point.
154 #  @return New GEOM_Object, containing the created point.
155 #
156 #  Example: see GEOM_TestAll.py
157 def MakeVertex(theX, theY, theZ):
158     anObj = BasicOp.MakePointXYZ(theX, theY, theZ)
159     if BasicOp.IsDone() == 0:
160       print "MakePointXYZ : ", BasicOp.GetErrorCode()
161     return anObj
162
163 ## Create a point, distant from the referenced point
164 #  on the given distances along the coordinate axes.
165 #  @param theReference The referenced point.
166 #  @param theX Displacement from the referenced point along OX axis.
167 #  @param theY Displacement from the referenced point along OY axis.
168 #  @param theZ Displacement from the referenced point along OZ axis.
169 #  @return New GEOM_Object, containing the created point.
170 #
171 #  Example: see GEOM_TestAll.py
172 def MakeVertexWithRef(theReference, theX, theY, theZ):
173     anObj = BasicOp.MakePointWithReference(theReference, theX, theY, theZ)
174     if BasicOp.IsDone() == 0:
175       print "MakePointWithReference : ", BasicOp.GetErrorCode()
176     return anObj
177
178 ## Create a point, corresponding to the given parameter on the given curve.
179 #  @param theRefCurve The referenced curve.
180 #  @param theParameter Value of parameter on the referenced curve.
181 #  @return New GEOM_Object, containing the created point.
182 #
183 #  Example: see GEOM_TestAll.py
184 def MakeVertexOnCurve(theRefCurve, theParameter):
185     anObj = BasicOp.MakePointOnCurve(theRefCurve, theParameter)
186     if BasicOp.IsDone() == 0:
187       print "MakePointOnCurve : ", BasicOp.GetErrorCode()
188     return anObj
189
190 ## Create a tangent, corresponding to the given parameter on the given curve.
191 #  @param theRefCurve The referenced curve.
192 #  @param theParameter Value of parameter on the referenced curve.
193 #  @return New GEOM_Object, containing the created tangent.
194 def MakeTangentOnCurve(theRefCurve, theParameter):
195     anObj = BasicOp.MakeTangentOnCurve(theRefCurve, theParameter)
196     if BasicOp.IsDone() == 0:
197       print "MakeTangentOnCurve : ", BasicOp.GetErrorCode()
198     return anObj
199
200 ## Create a vector with the given components.
201 #  @param theDX X component of the vector.
202 #  @param theDY Y component of the vector.
203 #  @param theDZ Z component of the vector.
204 #  @return New GEOM_Object, containing the created vector.
205 #
206 #  Example: see GEOM_TestAll.py
207 def MakeVectorDXDYDZ(theDX, theDY, theDZ):
208     anObj = BasicOp.MakeVectorDXDYDZ(theDX, theDY, theDZ)
209     if BasicOp.IsDone() == 0:
210       print "MakeVectorDXDYDZ : ", BasicOp.GetErrorCode()
211     return anObj
212
213 ## Create a vector between two points.
214 #  @param thePnt1 Start point for the vector.
215 #  @param thePnt2 End point for the vector.
216 #  @return New GEOM_Object, containing the created vector.
217
218 #  Example: see GEOM_TestAll.py
219 def MakeVector(thePnt1, thePnt2):
220     anObj = BasicOp.MakeVectorTwoPnt(thePnt1, thePnt2)
221     if BasicOp.IsDone() == 0:
222       print "MakeVectorTwoPnt : ", BasicOp.GetErrorCode()
223     return anObj
224
225 ## Create a line, passing through the given point
226 #  and parrallel to the given direction
227 #  @param thePnt Point. The resulting line will pass through it.
228 #  @param theDir Direction. The resulting line will be parallel to it.
229 #  @return New GEOM_Object, containing the created line.
230 #
231 #  Example: see GEOM_TestAll.py
232 def MakeLine(thePnt, theDir):
233     anObj = BasicOp.MakeLine(thePnt, theDir)
234     if BasicOp.IsDone() == 0:
235       print "MakeLine : ", BasicOp.GetErrorCode()
236     return anObj
237
238 ## Create a line, passing through the given points
239 #  @param thePnt1 First of two points, defining the line.
240 #  @param thePnt2 Second of two points, defining the line.
241 #  @return New GEOM_Object, containing the created line.
242 #
243 #  Example: see GEOM_TestAll.py
244 def MakeLineTwoPnt(thePnt1, thePnt2):
245     anObj = BasicOp.MakeLineTwoPnt(thePnt1, thePnt2)
246     if BasicOp.IsDone() == 0:
247       print "MakeLineTwoPnt : ", BasicOp.GetErrorCode()
248     return anObj
249
250 ## Create a plane, passing through the given point
251 #  and normal to the given vector.
252 #  @param thePnt Point, the plane has to pass through.
253 #  @param theVec Vector, defining the plane normal direction.
254 #  @param theTrimSize Half size of a side of quadrangle face, representing the plane.
255 #  @return New GEOM_Object, containing the created plane.
256 #
257 #  Example: see GEOM_TestAll.py
258 def MakePlane(thePnt, theVec, theTrimSize):
259     anObj = BasicOp.MakePlanePntVec(thePnt, theVec, theTrimSize)
260     if BasicOp.IsDone() == 0:
261       print "MakePlanePntVec : ", BasicOp.GetErrorCode()
262     return anObj
263
264 ## Create a plane, passing through the three given points
265 #  @param thePnt1 First of three points, defining the plane.
266 #  @param thePnt2 Second of three points, defining the plane.
267 #  @param thePnt3 Fird of three points, defining the plane.
268 #  @param theTrimSize Half size of a side of quadrangle face, representing the plane.
269 #  @return New GEOM_Object, containing the created plane.
270 #
271 #  Example: see GEOM_TestAll.py
272 def MakePlaneThreePnt(thePnt1, thePnt2, thePnt3, theTrimSize):
273     anObj = BasicOp.MakePlaneThreePnt(thePnt1, thePnt2, thePnt3, theTrimSize)
274     if BasicOp.IsDone() == 0:
275       print "MakePlaneThreePnt : ", BasicOp.GetErrorCode()
276     return anObj
277
278 ## Create a plane, similar to the existing one, but with another size of representing face.
279 #  @param theFace Referenced plane or LCS(Marker).
280 #  @param theTrimSize New half size of a side of quadrangle face, representing the plane.
281 #  @return New GEOM_Object, containing the created plane.
282 #
283 #  Example: see GEOM_TestAll.py
284 def MakePlaneFace(theFace, theTrimSize):
285     anObj = BasicOp.MakePlaneFace(theFace, theTrimSize)
286     if BasicOp.IsDone() == 0:
287       print "MakePlaneFace : ", BasicOp.GetErrorCode()
288     return anObj
289
290 ## Create a local coordinate system.
291 #  @param OX,OY,OZ Three coordinates of coordinate system origin.
292 #  @param XDX,XDY,XDZ Three components of OX direction
293 #  @param YDX,YDY,YDZ Three components of OY direction
294 #  @return New GEOM_Object, containing the created coordinate system.
295 #
296 #  Example: see GEOM_TestAll.py
297 def MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ):
298     anObj = BasicOp.MakeMarker(OX,OY,OZ, XDX,XDY,XDZ, YDX,YDY,YDZ)
299     if BasicOp.IsDone() == 0:
300       print "MakeMarker : ", BasicOp.GetErrorCode()
301     return anObj
302
303 ## Create a local coordinate system.
304 #  @param theOrigin Point of coordinate system origin.
305 #  @param theXVec Vector of X direction
306 #  @param theYVec Vector of Y direction
307 #  @return New GEOM_Object, containing the created coordinate system.
308 def MakeMarkerPntTwoVec(theOrigin, theXVec, theYVec):
309     O = PointCoordinates( theOrigin )
310     OXOY = []
311     for vec in [ theXVec, theYVec ]:
312         v1, v2 = SubShapeAll( vec, ShapeType["VERTEX"] )
313         p1 = PointCoordinates( v1 )
314         p2 = PointCoordinates( v2 )
315         for i in range( 0, 3 ):
316              OXOY.append( p2[i] - p1[i] )
317     #
318     anObj = BasicOp.MakeMarker( O[0], O[1], O[2],
319                                 OXOY[0], OXOY[1], OXOY[2],
320                                 OXOY[3], OXOY[4], OXOY[5], )
321     if BasicOp.IsDone() == 0:
322       print "MakeMarker : ", BasicOp.GetErrorCode()
323     return anObj
324
325 # -----------------------------------------------------------------------------
326 # Curves
327 # -----------------------------------------------------------------------------
328
329 ##  Create an arc of circle, passing through three given points.
330 #  @param thePnt1 Start point of the arc.
331 #  @param thePnt2 Middle point of the arc.
332 #  @param thePnt3 End point of the arc.
333 #  @return New GEOM_Object, containing the created arc.
334 #
335 #  Example: see GEOM_TestAll.py
336 def MakeArc(thePnt1, thePnt2, thePnt3):
337     anObj = CurvesOp.MakeArc(thePnt1, thePnt2, thePnt3)
338     if CurvesOp.IsDone() == 0:
339       print "MakeArc : ", CurvesOp.GetErrorCode()
340     return anObj
341
342 ##  Create an arc of circle from a center and 2 points.
343 #  @param thePnt1 Center of the arc
344 #  @param thePnt2 Start point of the arc. (Gives also the radius of the arc)
345 #  @param thePnt3 End point of the arc (Gives also a direction)
346 #  @return New GEOM_Object, containing the created arc.
347 #
348 #  Example: see GEOM_TestAll.py
349 def MakeArcCenter(thePnt1, thePnt2, thePnt3,theSense):
350     anObj = CurvesOp.MakeArcCenter(thePnt1, thePnt2, thePnt3,theSense)
351     if CurvesOp.IsDone() == 0:
352       print "MakeArcCenter : ", CurvesOp.GetErrorCode()
353     return anObj
354
355 ## Create a circle with given center, normal vector and radius.
356 #  @param thePnt Circle center.
357 #  @param theVec Vector, normal to the plane of the circle.
358 #  @param theR Circle radius.
359 #  @return New GEOM_Object, containing the created circle.
360 #
361 #  Example: see GEOM_TestAll.py
362 def MakeCircle(thePnt, theVec, theR):
363     anObj = CurvesOp.MakeCirclePntVecR(thePnt, theVec, theR)
364     if CurvesOp.IsDone() == 0:
365       print "MakeCirclePntVecR : ", CurvesOp.GetErrorCode()
366     return anObj
367
368 ## Create a circle, passing through three given points
369 #  @param thePnt1,thePnt2,thePnt3 Points, defining the circle.
370 #  @return New GEOM_Object, containing the created circle.
371 #
372 #  Example: see GEOM_TestAll.py
373 def MakeCircleThreePnt(thePnt1, thePnt2, thePnt3):
374     anObj = CurvesOp.MakeCircleThreePnt(thePnt1, thePnt2, thePnt3)
375     if CurvesOp.IsDone() == 0:
376       print "MakeCircleThreePnt : ", CurvesOp.GetErrorCode()
377     return anObj
378
379 ## Create an ellipse with given center, normal vector and radiuses.
380 #  @param thePnt Ellipse center.
381 #  @param theVec Vector, normal to the plane of the ellipse.
382 #  @param theRMajor Major ellipse radius.
383 #  @param theRMinor Minor ellipse radius.
384 #  @return New GEOM_Object, containing the created ellipse.
385 #
386 #  Example: see GEOM_TestAll.py
387 def MakeEllipse(thePnt, theVec, theRMajor, theRMinor):
388     anObj = CurvesOp.MakeEllipse(thePnt, theVec, theRMajor, theRMinor)
389     if CurvesOp.IsDone() == 0:
390       print "MakeEllipse : ", CurvesOp.GetErrorCode()
391     return anObj
392
393 ## Create a polyline on the set of points.
394 #  @param thePoints Sequence of points for the polyline.
395 #  @return New GEOM_Object, containing the created polyline.
396 #
397 #  Example: see GEOM_TestAll.py
398 def MakePolyline(thePoints):
399     anObj = CurvesOp.MakePolyline(thePoints)
400     if CurvesOp.IsDone() == 0:
401       print "MakePolyline : ", CurvesOp.GetErrorCode()
402     return anObj
403
404 ## Create bezier curve on the set of points.
405 #  @param thePoints Sequence of points for the bezier curve.
406 #  @return New GEOM_Object, containing the created bezier curve.
407 #
408 #  Example: see GEOM_TestAll.py
409 def MakeBezier(thePoints):
410     anObj = CurvesOp.MakeSplineBezier(thePoints)
411     if CurvesOp.IsDone() == 0:
412       print "MakeSplineBezier : ", CurvesOp.GetErrorCode()
413     return anObj
414
415 ## Create B-Spline curve on the set of points.
416 #  @param thePoints Sequence of points for the B-Spline curve.
417 #  @return New GEOM_Object, containing the created B-Spline curve.
418 #
419 #  Example: see GEOM_TestAll.py
420 def MakeInterpol(thePoints):
421     anObj = CurvesOp.MakeSplineInterpolation(thePoints)
422     if CurvesOp.IsDone() == 0:
423       print "MakeSplineInterpolation : ", CurvesOp.GetErrorCode()
424     return anObj
425
426 ## Create a sketcher (wire or face), following the textual description,
427 #  passed through \a theCommand argument. \n
428 #  Edges of the resulting wire or face will be arcs of circles and/or linear segments. \n
429 #  Format of the description string have to be the following:
430 #
431 #  "Sketcher[:F x1 y1]:CMD[:CMD[:CMD...]]"
432 #
433 #  Where:
434 #  - x1, y1 are coordinates of the first sketcher point (zero by default),
435 #  - CMD is one of
436 #     - "R angle" : Set the direction by angle
437 #     - "D dx dy" : Set the direction by DX & DY
438 #     .
439 #       \n
440 #     - "TT x y" : Create segment by point at X & Y
441 #     - "T dx dy" : Create segment by point with DX & DY
442 #     - "L length" : Create segment by direction & Length
443 #     - "IX x" : Create segment by direction & Intersect. X
444 #     - "IY y" : Create segment by direction & Intersect. Y
445 #     .
446 #       \n
447 #     - "C radius length" : Create arc by direction, radius and length(in degree)
448 #     .
449 #       \n
450 #     - "WW" : Close Wire (to finish)
451 #     - "WF" : Close Wire and build face (to finish)
452 #
453 #  @param theCommand String, defining the sketcher in local
454 #                    coordinates of the working plane.
455 #  @param theWorkingPlane Nine double values, defining origin,
456 #                         OZ and OX directions of the working plane.
457 #  @return New GEOM_Object, containing the created wire.
458 #
459 #  Example: see GEOM_TestAll.py
460 def MakeSketcher(theCommand, theWorkingPlane = [0,0,0, 0,0,1, 1,0,0]):
461     anObj = CurvesOp.MakeSketcher(theCommand, theWorkingPlane)
462     if CurvesOp.IsDone() == 0:
463       print "MakeSketcher : ", CurvesOp.GetErrorCode()
464     return anObj
465
466 ## Create a sketcher (wire or face), following the textual description,
467 #  passed through \a theCommand argument. \n
468 #  For format of the description string see the previous method.\n
469 #  @param theCommand String, defining the sketcher in local
470 #                    coordinates of the working plane.
471 #  @param theWorkingPlane Planar Face or LCS(Marker) of the working plane.
472 #  @return New GEOM_Object, containing the created wire.
473 def MakeSketcherOnPlane(theCommand, theWorkingPlane):
474     anObj = CurvesOp.MakeSketcherOnPlane(theCommand, theWorkingPlane)
475     if CurvesOp.IsDone() == 0:
476       print "MakeSketcher : ", CurvesOp.GetErrorCode()
477     return anObj
478
479 # -----------------------------------------------------------------------------
480 # Create 3D Primitives
481 # -----------------------------------------------------------------------------
482
483 ## Create a box by coordinates of two opposite vertices.
484 #
485 #  Example: see GEOM_TestAll.py
486 def MakeBox(x1,y1,z1,x2,y2,z2):
487     pnt1 = MakeVertex(x1,y1,z1)
488     pnt2 = MakeVertex(x2,y2,z2)
489     return MakeBoxTwoPnt(pnt1,pnt2)
490
491 ## Create a box with specified dimensions along the coordinate axes
492 #  and with edges, parallel to the coordinate axes.
493 #  Center of the box will be at point (DX/2, DY/2, DZ/2).
494 #  @param theDX Length of Box edges, parallel to OX axis.
495 #  @param theDY Length of Box edges, parallel to OY axis.
496 #  @param theDZ Length of Box edges, parallel to OZ axis.
497 #  @return New GEOM_Object, containing the created box.
498 #
499 #  Example: see GEOM_TestAll.py
500 def MakeBoxDXDYDZ(theDX, theDY, theDZ):
501     anObj = PrimOp.MakeBoxDXDYDZ(theDX, theDY, theDZ)
502     if PrimOp.IsDone() == 0:
503       print "MakeBoxDXDYDZ : ", PrimOp.GetErrorCode()
504     return anObj
505
506 ## Create a box with two specified opposite vertices,
507 #  and with edges, parallel to the coordinate axes
508 #  @param thePnt1 First of two opposite vertices.
509 #  @param thePnt2 Second of two opposite vertices.
510 #  @return New GEOM_Object, containing the created box.
511 #
512 #  Example: see GEOM_TestAll.py
513 def MakeBoxTwoPnt(thePnt1, thePnt2):
514     anObj = PrimOp.MakeBoxTwoPnt(thePnt1, thePnt2)
515     if PrimOp.IsDone() == 0:
516       print "MakeBoxTwoPnt : ", PrimOp.GetErrorCode()
517     return anObj
518
519 ## Create a cylinder with given base point, axis, radius and height.
520 #  @param thePnt Central point of cylinder base.
521 #  @param theAxis Cylinder axis.
522 #  @param theR Cylinder radius.
523 #  @param theH Cylinder height.
524 #  @return New GEOM_Object, containing the created cylinder.
525 #
526 #  Example: see GEOM_TestAll.py
527 def MakeCylinder(thePnt, theAxis, theR, theH):
528     anObj = PrimOp.MakeCylinderPntVecRH(thePnt, theAxis, theR, theH)
529     if PrimOp.IsDone() == 0:
530       print "MakeCylinderPntVecRH : ", PrimOp.GetErrorCode()
531     return anObj
532
533 ## Create a cylinder with given radius and height at
534 #  the origin of coordinate system. Axis of the cylinder
535 #  will be collinear to the OZ axis of the coordinate system.
536 #  @param theR Cylinder radius.
537 #  @param theH Cylinder height.
538 #  @return New GEOM_Object, containing the created cylinder.
539 #
540 #  Example: see GEOM_TestAll.py
541 def MakeCylinderRH(theR, theH):
542     anObj = PrimOp.MakeCylinderRH(theR, theH)
543     if PrimOp.IsDone() == 0:
544       print "MakeCylinderRH : ", PrimOp.GetErrorCode()
545     return anObj
546
547 ## Create a sphere with given center and radius.
548 #  @param thePnt Sphere center.
549 #  @param theR Sphere radius.
550 #  @return New GEOM_Object, containing the created sphere.
551 #
552 #  Example: see GEOM_TestAll.py
553 def MakeSpherePntR(thePnt, theR):
554     anObj = PrimOp.MakeSpherePntR(thePnt, theR)
555     if PrimOp.IsDone() == 0:
556       print "MakeSpherePntR : ", PrimOp.GetErrorCode()
557     return anObj
558
559 ## Create a sphere with given center and radius.
560 #  @param x,y,z Coordinates of sphere center.
561 #  @param theR Sphere radius.
562 #  @return New GEOM_Object, containing the created sphere.
563 #
564 #  Example: see GEOM_TestAll.py
565 def MakeSphere(x, y, z, theR):
566     point = MakeVertex(x, y, z)
567     anObj = MakeSpherePntR(point, theR)
568     return anObj
569
570 ## Create a sphere with given radius at the origin of coordinate system.
571 #  @param theR Sphere radius.
572 #  @return New GEOM_Object, containing the created sphere.
573 #
574 #  Example: see GEOM_TestAll.py
575 def MakeSphereR(theR):
576     anObj = PrimOp.MakeSphereR(theR)
577     if PrimOp.IsDone() == 0:
578       print "MakeSphereR : ", PrimOp.GetErrorCode()
579     return anObj
580
581 ## Create a cone with given base point, axis, height and radiuses.
582 #  @param thePnt Central point of the first cone base.
583 #  @param theAxis Cone axis.
584 #  @param theR1 Radius of the first cone base.
585 #  @param theR2 Radius of the second cone base.
586 #    \note If both radiuses are non-zero, the cone will be truncated.
587 #    \note If the radiuses are equal, a cylinder will be created instead.
588 #  @param theH Cone height.
589 #  @return New GEOM_Object, containing the created cone.
590 #
591 #  Example: see GEOM_TestAll.py
592 def MakeCone(thePnt, theAxis, theR1, theR2, theH):
593     anObj = PrimOp.MakeConePntVecR1R2H(thePnt, theAxis, theR1, theR2, theH)
594     if PrimOp.IsDone() == 0:
595       print "MakeConePntVecR1R2H : ", PrimOp.GetErrorCode()
596     return anObj
597
598 ## Create a cone with given height and radiuses at
599 #  the origin of coordinate system. Axis of the cone will
600 #  be collinear to the OZ axis of the coordinate system.
601 #  @param theR1 Radius of the first cone base.
602 #  @param theR2 Radius of the second cone base.
603 #    \note If both radiuses are non-zero, the cone will be truncated.
604 #    \note If the radiuses are equal, a cylinder will be created instead.
605 #  @param theH Cone height.
606 #  @return New GEOM_Object, containing the created cone.
607 #
608 #  Example: see GEOM_TestAll.py
609 def MakeConeR1R2H(theR1, theR2, theH):
610     anObj = PrimOp.MakeConeR1R2H(theR1, theR2, theH)
611     if PrimOp.IsDone() == 0:
612       print "MakeConeR1R2H : ", PrimOp.GetErrorCode()
613     return anObj
614
615 ## Create a torus with given center, normal vector and radiuses.
616 #  @param thePnt Torus central point.
617 #  @param theVec Torus axis of symmetry.
618 #  @param theRMajor Torus major radius.
619 #  @param theRMinor Torus minor radius.
620 #  @return New GEOM_Object, containing the created torus.
621 #
622 #  Example: see GEOM_TestAll.py
623 def MakeTorus(thePnt, theVec, theRMajor, theRMinor):
624     anObj = PrimOp.MakeTorusPntVecRR(thePnt, theVec, theRMajor, theRMinor)
625     if PrimOp.IsDone() == 0:
626       print "MakeTorusPntVecRR : ", PrimOp.GetErrorCode()
627     return anObj
628
629 ## Create a torus with given radiuses at the origin of coordinate system.
630 #  @param theRMajor Torus major radius.
631 #  @param theRMinor Torus minor radius.
632 #  @return New GEOM_Object, containing the created torus.
633 #
634 #  Example: see GEOM_TestAll.py
635 def MakeTorusRR(theRMajor, theRMinor):
636     anObj = PrimOp.MakeTorusRR(theRMajor, theRMinor)
637     if PrimOp.IsDone() == 0:
638       print "MakeTorusRR : ", PrimOp.GetErrorCode()
639     return anObj
640
641 ## Create a shape by extrusion of the base shape along a vector, defined by two points.
642 #  @param theBase Base shape to be extruded.
643 #  @param thePoint1 First end of extrusion vector.
644 #  @param thePoint2 Second end of extrusion vector.
645 #  @return New GEOM_Object, containing the created prism.
646 #
647 #  Example: see GEOM_TestAll.py
648 def MakePrism(theBase, thePoint1, thePoint2):
649     anObj = PrimOp.MakePrismTwoPnt(theBase, thePoint1, thePoint2)
650     if PrimOp.IsDone() == 0:
651       print "MakePrismTwoPnt : ", PrimOp.GetErrorCode()
652     return anObj
653
654 ## Create a shape by extrusion of the base shape along the vector,
655 #  i.e. all the space, transfixed by the base shape during its translation
656 #  along the vector on the given distance.
657 #  @param theBase Base shape to be extruded.
658 #  @param theVec Direction of extrusion.
659 #  @param theH Prism dimension along theVec.
660 #  @return New GEOM_Object, containing the created prism.
661 #
662 #  Example: see GEOM_TestAll.py
663 def MakePrismVecH(theBase, theVec, theH):
664     anObj = PrimOp.MakePrismVecH(theBase, theVec, theH)
665     if PrimOp.IsDone() == 0:
666       print "MakePrismVecH : ", PrimOp.GetErrorCode()
667     return anObj
668
669 ## Create a shape by extrusion of the base shape along
670 #  the path shape. The path shape can be a wire or an edge.
671 #  @param theBase Base shape to be extruded.
672 #  @param thePath Path shape to extrude the base shape along it.
673 #  @return New GEOM_Object, containing the created pipe.
674 #
675 #  Example: see GEOM_TestAll.py
676 def MakePipe(theBase, thePath):
677     anObj = PrimOp.MakePipe(theBase, thePath)
678     if PrimOp.IsDone() == 0:
679       print "MakePipe : ", PrimOp.GetErrorCode()
680     return anObj
681
682 ## Create a shape by revolution of the base shape around the axis
683 #  on the given angle, i.e. all the space, transfixed by the base
684 #  shape during its rotation around the axis on the given angle.
685 #  @param theBase Base shape to be rotated.
686 #  @param theAxis Rotation axis.
687 #  @param theAngle Rotation angle in radians.
688 #  @return New GEOM_Object, containing the created revolution.
689 #
690 #  Example: see GEOM_TestAll.py
691 def MakeRevolution(theBase, theAxis, theAngle):
692     anObj = PrimOp.MakeRevolutionAxisAngle(theBase, theAxis, theAngle)
693     if PrimOp.IsDone() == 0:
694       print "MakeRevolutionAxisAngle : ", PrimOp.GetErrorCode()
695     return anObj
696
697 ## Create a shell or solid passing through set of sections.Sections should be wires,edges or vertices.
698 #  @param theSeqSections - set of specified sections.
699 #  @param theModeSolid - mode defining building solid or shell
700 #  @param thePreci - precision 3D used for smoothing by default 1.e-6
701 #  @param theRuled - mode defining type of the result surfaces (ruled or smoothed).
702 #  @return New GEOM_Object, containing the created shell or solid.
703 #
704 #  Example: see GEOM_TestAll.py
705 def MakeThruSections(theSeqSections,theModeSolid,thePreci,theRuled):
706     anObj = PrimOp.MakeThruSections(theSeqSections,theModeSolid,thePreci,theRuled)
707     if PrimOp.IsDone() == 0:
708       print "MakeThruSections : ", PrimOp.GetErrorCode()
709     return anObj
710
711 ## Create a shape by extrusion of the profile shape along
712 #  the path shape. The path shape can be a wire or an edge.
713 #  the several profiles can be specified in the several locations of path.      
714 #  @param theSeqBases - list of  Bases shape to be extruded.
715 #  @param theLocations - list of locations on the path corresponding
716 #                        specified list of the Bases shapes. Number of locations
717 #                        should be equal to number of bases or list of locations can be empty.
718 #  @param thePath - Path shape to extrude the base shape along it.
719 #  @param theWithContact - the mode defining that the section is translated to be in
720 #                          contact with the spine.
721 #  @param - WithCorrection - defining that the section is rotated to be
722 #                            orthogonal to the spine tangent in the correspondent point
723 #  @return New GEOM_Object, containing the created pipe.
724 #
725 #  Example: see GEOM_TestAll.py
726 def MakePipeWithDifferentSections(theSeqBases, theLocations,thePath,theWithContact,theWithCorrection):
727     anObj = PrimOp.MakePipeWithDifferentSections(theSeqBases, theLocations,thePath,theWithContact,theWithCorrection)
728     if PrimOp.IsDone() == 0:
729       print "MakePipeWithDifferentSections : ", PrimOp.GetErrorCode()
730     return anObj
731
732 # -----------------------------------------------------------------------------
733 # Create base shapes
734 # -----------------------------------------------------------------------------
735
736 ## Create a linear edge with specified ends.
737 #  @param thePnt1 Point for the first end of edge.
738 #  @param thePnt2 Point for the second end of edge.
739 #  @return New GEOM_Object, containing the created edge.
740 #
741 #  Example: see GEOM_TestAll.py
742 def MakeEdge(thePnt1, thePnt2):
743     anObj = ShapesOp.MakeEdge(thePnt1, thePnt2)
744     if ShapesOp.IsDone() == 0:
745       print "MakeEdge : ", ShapesOp.GetErrorCode()
746     return anObj
747
748 ## Create a wire from the set of edges and wires.
749 #  @param theEdgesAndWires List of edges and/or wires.
750 #  @return New GEOM_Object, containing the created wire.
751 #
752 #  Example: see GEOM_TestAll.py
753 def MakeWire(theEdgesAndWires):
754     anObj = ShapesOp.MakeWire(theEdgesAndWires)
755     if ShapesOp.IsDone() == 0:
756       print "MakeWire : ", ShapesOp.GetErrorCode()
757     return anObj
758
759 ## Create a face on the given wire.
760 #  @param theWire closed Wire or Edge to build the face on.
761 #  @param isPlanarWanted If TRUE, only planar face will be built.
762 #                        If impossible, NULL object will be returned.
763 #  @return New GEOM_Object, containing the created face.
764 #
765 #  Example: see GEOM_TestAll.py
766 def MakeFace(theWire, isPlanarWanted):
767     anObj = ShapesOp.MakeFace(theWire, isPlanarWanted)
768     if ShapesOp.IsDone() == 0:
769       print "MakeFace : ", ShapesOp.GetErrorCode()
770     return anObj
771
772 ## Create a face on the given wires set.
773 #  @param theWires List of closed wires or edges to build the face on.
774 #  @param isPlanarWanted If TRUE, only planar face will be built.
775 #                        If impossible, NULL object will be returned.
776 #  @return New GEOM_Object, containing the created face.
777 #
778 #  Example: see GEOM_TestAll.py
779 def MakeFaceWires(theWires, isPlanarWanted):
780     anObj = ShapesOp.MakeFaceWires(theWires, isPlanarWanted)
781     if ShapesOp.IsDone() == 0:
782       print "MakeFaceWires : ", ShapesOp.GetErrorCode()
783     return anObj
784
785 ## Shortcut to MakeFaceWires()
786 #
787 #  Example: see GEOM_TestOthers.py
788 def MakeFaces(theWires, isPlanarWanted):
789     anObj = MakeFaceWires(theWires, isPlanarWanted)
790     return anObj
791
792 ## Create a shell from the set of faces and shells.
793 #  @param theFacesAndShells List of faces and/or shells.
794 #  @return New GEOM_Object, containing the created shell.
795 #
796 #  Example: see GEOM_TestAll.py
797 def MakeShell(theFacesAndShells):
798     anObj = ShapesOp.MakeShell(theFacesAndShells)
799     if ShapesOp.IsDone() == 0:
800         print "MakeShell : ", ShapesOp.GetErrorCode()
801     return anObj
802
803 ## Create a solid, bounded by the given shells.
804 #  @param theShells Sequence of bounding shells.
805 #  @return New GEOM_Object, containing the created solid.
806 #
807 #  Example: see GEOM_TestAll.py
808 def MakeSolid(theShells):
809     anObj = ShapesOp.MakeSolidShells(theShells)
810     if ShapesOp.IsDone() == 0:
811         print "MakeSolid : ", ShapesOp.GetErrorCode()
812     return anObj
813
814 ## Create a compound of the given shapes.
815 #  @param theShapes List of shapes to put in compound.
816 #  @return New GEOM_Object, containing the created compound.
817 #
818 #  Example: see GEOM_TestAll.py
819 def MakeCompound(theShapes):
820     anObj = ShapesOp.MakeCompound(theShapes)
821     if ShapesOp.IsDone() == 0:
822       print "MakeCompound : ", ShapesOp.GetErrorCode()
823     return anObj
824
825 ## Gives quantity of faces in the given shape.
826 #  @param theShape Shape to count faces of.
827 #  @return Quantity of faces.
828 #
829 #  Example: see GEOM_TestOthers.py
830 def NumberOfFaces(theShape):
831     nb_faces = ShapesOp.NumberOfFaces(theShape)
832     if ShapesOp.IsDone() == 0:
833       print "NumberOfFaces : ", ShapesOp.GetErrorCode()
834     return nb_faces
835
836 ## Gives quantity of edges in the given shape.
837 #  @param theShape Shape to count edges of.
838 #  @return Quantity of edges.
839 #
840 #  Example: see GEOM_TestOthers.py
841 def NumberOfEdges(theShape):
842     nb_edges = ShapesOp.NumberOfEdges(theShape)
843     if ShapesOp.IsDone() == 0:
844       print "NumberOfEdges : ", ShapesOp.GetErrorCode()
845     return nb_edges
846
847 ## Reverses an orientation the given shape.
848 #  @param theShape Shape to be reversed.
849 #  @return The reversed copy of theShape.
850 #
851 #  Example: see GEOM_TestAll.py
852 def ChangeOrientation(theShape):
853     anObj = ShapesOp.ChangeOrientation(theShape)
854     if ShapesOp.IsDone() == 0:
855       print "ChangeOrientation : ", ShapesOp.GetErrorCode()
856     return anObj
857
858 ## Shortcut to ChangeOrientation()
859 #
860 #  Example: see GEOM_TestOthers.py
861 def OrientationChange(theShape):
862     anObj = ChangeOrientation(theShape)
863     return anObj
864
865 ## Retrieve all free faces from the given shape.
866 #  Free face is a face, which is not shared between two shells of the shape.
867 #  @param theShape Shape to find free faces in.
868 #  @return List of IDs of all free faces, contained in theShape.
869 #
870 #  Example: see GEOM_TestOthers.py
871 def GetFreeFacesIDs(theShape):
872     anIDs = ShapesOp.GetFreeFacesIDs(theShape)
873     if ShapesOp.IsDone() == 0:
874       print "GetFreeFacesIDs : ", ShapesOp.GetErrorCode()
875     return anIDs
876
877 ## Get all sub-shapes of theShape1 of the given type, shared with theShape2.
878 #  @param theShape1 Shape to find sub-shapes in.
879 #  @param theShape2 Shape to find shared sub-shapes with.
880 #  @param theShapeType Type of sub-shapes to be retrieved.
881 #  @return List of sub-shapes of theShape1, shared with theShape2.
882 #
883 #  Example: see GEOM_TestOthers.py
884 def GetSharedShapes(theShape1, theShape2, theShapeType):
885     aList = ShapesOp.GetSharedShapes(theShape1, theShape2, theShapeType)
886     if ShapesOp.IsDone() == 0:
887       print "GetSharedShapes : ", ShapesOp.GetErrorCode()
888     return aList
889
890 ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
891 #  the specified plane by the certain way, defined through \a theState parameter.
892 #  @param theShape Shape to find sub-shapes of.
893 #  @param theShapeType Type of sub-shapes to be retrieved.
894 #  @param theAx1 Vector (or line, or linear edge), specifying normal
895 #                direction and location of the plane to find shapes on.
896 #  @param theState The state of the subshapes to find. It can be one of
897 #   ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
898 #  @return List of all found sub-shapes.
899 #
900 #  Example: see GEOM_TestOthers.py
901 def GetShapesOnPlane(theShape, theShapeType, theAx1, theState):
902     aList = ShapesOp.GetShapesOnPlane(theShape, theShapeType, theAx1, theState)
903     if ShapesOp.IsDone() == 0:
904       print "GetShapesOnPlane : ", ShapesOp.GetErrorCode()
905     return aList
906
907 ## Works like the above method, but returns list of sub-shapes indices
908 #
909 #  Example: see GEOM_TestOthers.py
910 def GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState):
911     aList = ShapesOp.GetShapesOnPlaneIDs(theShape, theShapeType, theAx1, theState)
912     if ShapesOp.IsDone() == 0:
913         print "GetShapesOnPlaneIDs : ", ShapesOp.GetErrorCode()
914     return aList
915
916 ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
917 #  the specified plane by the certain way, defined through \a theState parameter.
918 #  @param theShape Shape to find sub-shapes of.
919 #  @param theShapeType Type of sub-shapes to be retrieved.
920 #  @param theAx1 Vector (or line, or linear edge), specifying normal
921 #                direction of the plane to find shapes on.
922 #  @param thePnt Point specifying location of the plane to find shapes on.
923 #  @param theState The state of the subshapes to find. It can be one of
924 #   ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
925 #  @return List of all found sub-shapes.
926 #
927 #  Example: see GEOM_TestOthers.py
928 def GetShapesOnPlaneWithLocation(theShape, theShapeType, theAx1, thePnt, theState):
929     aList = ShapesOp.GetShapesOnPlaneWithLocation(theShape, theShapeType, theAx1, thePnt, theState)
930     if ShapesOp.IsDone() == 0:
931       print "GetShapesOnPlaneWithLocation : ", ShapesOp.GetErrorCode()
932     return aList
933
934 ## Works like the above method, but returns list of sub-shapes indices
935 #
936 #  Example: see GEOM_TestOthers.py
937 def GetShapesOnPlaneWithLocationIDs(theShape, theShapeType, theAx1, thePnt, theState):
938     aList = ShapesOp.GetShapesOnPlaneWithLocationIDs(theShape, theShapeType, theAx1, thePnt, theState)
939     if ShapesOp.IsDone() == 0:
940         print "GetShapesOnPlaneWithLocationIDs : ", ShapesOp.GetErrorCode()
941     return aList
942
943 ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
944 #  the specified cylinder by the certain way, defined through \a theState parameter.
945 #  @param theShape Shape to find sub-shapes of.
946 #  @param theShapeType Type of sub-shapes to be retrieved.
947 #  @param theAxis Vector (or line, or linear edge), specifying
948 #                 axis of the cylinder to find shapes on.
949 #  @param theRadius Radius of the cylinder to find shapes on.
950 #  @param theState The state of the subshapes to find. It can be one of
951 #   ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
952 #  @return List of all found sub-shapes.
953 #
954 #  Example: see GEOM_TestOthers.py
955 def GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState):
956     aList = ShapesOp.GetShapesOnCylinder(theShape, theShapeType, theAxis, theRadius, theState)
957     if ShapesOp.IsDone() == 0:
958       print "GetShapesOnCylinder : ", ShapesOp.GetErrorCode()
959     return aList
960
961 ## Works like the above method, but returns list of sub-shapes indices
962 #
963 #  Example: see GEOM_TestOthers.py
964 def GetShapesOnCylinderIDs(theShape, theShapeType, theAxis, theRadius, theState):
965     aList = ShapesOp.GetShapesOnCylinderIDs(theShape, theShapeType, theAxis, theRadius, theState)
966     if ShapesOp.IsDone() == 0:
967         print "GetShapesOnCylinderIDs : ", ShapesOp.GetErrorCode()
968     return aList
969
970 ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
971 #  the specified sphere by the certain way, defined through \a theState parameter.
972 #  @param theShape Shape to find sub-shapes of.
973 #  @param theShapeType Type of sub-shapes to be retrieved.
974 #  @param theCenter Point, specifying center of the sphere to find shapes on.
975 #  @param theRadius Radius of the sphere to find shapes on.
976 #  @param theState The state of the subshapes to find. It can be one of
977 #   ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
978 #  @return List of all found sub-shapes.
979 #
980 #  Example: see GEOM_TestOthers.py
981 def GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState):
982     aList = ShapesOp.GetShapesOnSphere(theShape, theShapeType, theCenter, theRadius, theState)
983     if ShapesOp.IsDone() == 0:
984       print "GetShapesOnSphere : ", ShapesOp.GetErrorCode()
985     return aList
986
987 ## Works like the above method, but returns list of sub-shapes indices
988 #
989 #  Example: see GEOM_TestOthers.py
990 def GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState):
991     aList = ShapesOp.GetShapesOnSphereIDs(theShape, theShapeType, theCenter, theRadius, theState)
992     if ShapesOp.IsDone() == 0:
993         print "GetShapesOnSphereIDs : ", ShapesOp.GetErrorCode()
994     return aList
995
996 ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
997 #  the specified quadrangle by the certain way, defined through \a theState parameter.
998 #  @param theShape Shape to find sub-shapes of.
999 #  @param theShapeType Type of sub-shapes to be retrieved.
1000 #  @param theTopLeftPoint Point, specifying top left corner of a quadrangle
1001 #  @param theTopRigthPoint Point, specifying top right corner of a quadrangle
1002 #  @param theBottomLeftPoint Point, specifying bottom left corner of a quadrangle
1003 #  @param theBottomRigthPoint Point, specifying bottom right corner of a quadrangle
1004 #  @param theState The state of the subshapes to find. It can be one of
1005 #   ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
1006 #  @return List of all found sub-shapes.
1007 #
1008 #  Example: see GEOM_TestOthers.py
1009 def GetShapesOnQuadrangle(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState):
1010     aList = ShapesOp.GetShapesOnQuadrangle(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState)
1011     if ShapesOp.IsDone() == 0:
1012       print "GetShapesOnQuadrangle : ", ShapesOp.GetErrorCode()
1013     return aList
1014
1015 ## Works like the above method, but returns list of sub-shapes indices
1016 #
1017 #  Example: see GEOM_TestOthers.py
1018 def GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState):
1019     aList = ShapesOp.GetShapesOnQuadrangleIDs(theShape, theShapeType, theTopLeftPoint, theTopRigthPoint, theBottomLeftPoint, theBottomRigthPoint, theState)
1020     if ShapesOp.IsDone() == 0:
1021         print "GetShapesOnQuadrangleIDs : ", ShapesOp.GetErrorCode()
1022     return aList
1023
1024 ## Find in \a theShape all sub-shapes of type \a theShapeType, situated relatively
1025 #  the specified \a theBox by the certain way, defined through \a theState parameter.
1026 #  @param theBox Shape for relative comparing.
1027 #  @param theShape Shape to find sub-shapes of.
1028 #  @param theShapeType Type of sub-shapes to be retrieved.
1029 #  @param theState The state of the subshapes to find. It can be one of
1030 #   ST_ON, ST_OUT, ST_ONOUT, ST_IN, ST_ONIN.
1031 #  @return List of all found sub-shapes.
1032 #
1033 def GetShapesOnBox(theBox, theShape, theShapeType, theState):
1034     aList = ShapesOp.GetShapesOnBox(theBox, theShape, theShapeType, theState)
1035     if ShapesOp.IsDone() == 0:
1036       print "GetShapesOnBox : ", ShapesOp.GetErrorCode()
1037     return aList
1038
1039 ## Works like the above method, but returns list of sub-shapes indices
1040 #
1041 def GetShapesOnBoxIDs(theBox, theShape, theShapeType, theState):
1042     aList = ShapesOp.GetShapesOnBoxIDs(theBox, theShape, theShapeType, theState)
1043     if ShapesOp.IsDone() == 0:
1044         print "GetShapesOnBoxIDs : ", ShapesOp.GetErrorCode()
1045     return aList
1046
1047 ## Get sub-shape(s) of theShapeWhere, which are
1048 #  coincident with \a theShapeWhat or could be a part of it.
1049 #  @param theShapeWhere Shape to find sub-shapes of.
1050 #  @param theShapeWhat Shape, specifying what to find.
1051 #  @return Group of all found sub-shapes or a single found sub-shape.
1052 #
1053 #  Example: see GEOM_TestOthers.py
1054 def GetInPlace(theShapeWhere, theShapeWhat):
1055     anObj = ShapesOp.GetInPlace(theShapeWhere, theShapeWhat)
1056     if ShapesOp.IsDone() == 0:
1057       print "GetInPlace : ", ShapesOp.GetErrorCode()
1058     return anObj
1059
1060 ## Get sub-shape of theShapeWhere, which is
1061 #  equal to \a theShapeWhat.
1062 #  @param theShapeWhere Shape to find sub-shape of.
1063 #  @param theShapeWhat Shape, specifying what to find.
1064 #  @return New GEOM_Object for found sub-shape.
1065 #
1066 def GetSame(theShapeWhere, theShapeWhat):
1067     anObj = ShapesOp.GetSame(theShapeWhere, theShapeWhat)
1068     if ShapesOp.IsDone() == 0:
1069       print "GetSame : ", ShapesOp.GetErrorCode()
1070     return anObj
1071
1072 # -----------------------------------------------------------------------------
1073 # Access to sub-shapes by their unique IDs inside the main shape.
1074 # -----------------------------------------------------------------------------
1075
1076 ## Obtain a composite sub-shape of <aShape>, composed from sub-shapes
1077 #  of <aShape>, selected by their unique IDs inside <aShape>
1078 #
1079 #  Example: see GEOM_TestAll.py
1080 def GetSubShape(aShape, ListOfID):
1081     anObj = geom.AddSubShape(aShape,ListOfID)
1082     return anObj
1083
1084 ## Obtain unique ID of sub-shape <aSubShape> inside <aShape>
1085 #
1086 #  Example: see GEOM_TestAll.py
1087 def GetSubShapeID(aShape, aSubShape):
1088     anID = LocalOp.GetSubShapeIndex(aShape, aSubShape)
1089     if LocalOp.IsDone() == 0:
1090       print "GetSubShapeIndex : ", LocalOp.GetErrorCode()
1091     return anID
1092
1093 # -----------------------------------------------------------------------------
1094 # Decompose objects
1095 # -----------------------------------------------------------------------------
1096
1097 ## Explode a shape on subshapes of a given type.
1098 #  @param theShape Shape to be exploded.
1099 #  @param theShapeType Type of sub-shapes to be retrieved.
1100 #  @return List of sub-shapes of type theShapeType, contained in theShape.
1101 #
1102 #  Example: see GEOM_TestAll.py
1103 def SubShapeAll(aShape, aType):
1104     ListObj = ShapesOp.MakeExplode(aShape,aType,0)
1105     if ShapesOp.IsDone() == 0:
1106       print "MakeExplode : ", ShapesOp.GetErrorCode()
1107     return ListObj
1108
1109 ## Explode a shape on subshapes of a given type.
1110 #  @param theShape Shape to be exploded.
1111 #  @param theShapeType Type of sub-shapes to be retrieved.
1112 #  @return List of IDs of sub-shapes.
1113 def SubShapeAllIDs(aShape, aType):
1114     ListObj = ShapesOp.SubShapeAllIDs(aShape,aType,0)
1115     if ShapesOp.IsDone() == 0:
1116       print "SubShapeAllIDs : ", ShapesOp.GetErrorCode()
1117     return ListObj
1118
1119 ## Explode a shape on subshapes of a given type.
1120 #  Sub-shapes will be sorted by coordinates of their gravity centers.
1121 #  @param theShape Shape to be exploded.
1122 #  @param theShapeType Type of sub-shapes to be retrieved.
1123 #  @return List of sub-shapes of type theShapeType, contained in theShape.
1124 #
1125 #  Example: see GEOM_TestAll.py
1126 def SubShapeAllSorted(aShape, aType):
1127     ListObj = ShapesOp.MakeExplode(aShape,aType,1)
1128     if ShapesOp.IsDone() == 0:
1129       print "MakeExplode : ", ShapesOp.GetErrorCode()
1130     return ListObj
1131
1132 ## Explode a shape on subshapes of a given type.
1133 #  Sub-shapes will be sorted by coordinates of their gravity centers.
1134 #  @param theShape Shape to be exploded.
1135 #  @param theShapeType Type of sub-shapes to be retrieved.
1136 #  @return List of IDs of sub-shapes.
1137 def SubShapeAllSortedIDs(aShape, aType):
1138     ListIDs = ShapesOp.SubShapeAllIDs(aShape,aType,1)
1139     if ShapesOp.IsDone() == 0:
1140       print "SubShapeAllSortedIDs : ", ShapesOp.GetErrorCode()
1141     return ListIDs
1142
1143 ## Obtain a compound of sub-shapes of <aShape>,
1144 #  selected by they indices in list of all sub-shapes of type <aType>.
1145 #  Each index is in range [1, Nb_Sub-Shapes_Of_Given_Type]
1146 #
1147 #  Example: see GEOM_TestAll.py
1148 def SubShape(aShape, aType, ListOfInd):
1149     ListOfIDs = []
1150     AllShapeList = SubShapeAll(aShape, aType)
1151     for ind in ListOfInd:
1152         ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
1153     anObj = GetSubShape(aShape, ListOfIDs)
1154     return anObj
1155
1156 ## Obtain a compound of sub-shapes of <aShape>,
1157 #  selected by they indices in sorted list of all sub-shapes of type <aType>.
1158 #  Each index is in range [1, Nb_Sub-Shapes_Of_Given_Type]
1159 #
1160 #  Example: see GEOM_TestAll.py
1161 def SubShapeSorted(aShape, aType, ListOfInd):
1162     ListOfIDs = []
1163     AllShapeList = SubShapeAllSorted(aShape, aType)
1164     for ind in ListOfInd:
1165         ListOfIDs.append(GetSubShapeID(aShape, AllShapeList[ind - 1]))
1166     anObj = GetSubShape(aShape, ListOfIDs)
1167     return anObj
1168
1169 # -----------------------------------------------------------------------------
1170 # Healing operations
1171 # -----------------------------------------------------------------------------
1172
1173 ## Apply a sequence of Shape Healing operators to the given object.
1174 #  @param theShape Shape to be processed.
1175 #  @param theOperators List of names of operators ("FixShape", "SplitClosedFaces", etc.).
1176 #  @param theParameters List of names of parameters
1177 #                    ("FixShape.Tolerance3d", "SplitClosedFaces.NbSplitPoints", etc.).
1178 #  @param theValues List of values of parameters, in the same order
1179 #                    as parameters are listed in \a theParameters list.
1180 #  @return New GEOM_Object, containing processed shape.
1181 #
1182 #  Example: see GEOM_TestHealing.py
1183 def ProcessShape(theShape, theOperators, theParameters, theValues):
1184     anObj = HealOp.ProcessShape(theShape, theOperators, theParameters, theValues)
1185     if HealOp.IsDone() == 0:
1186         print "ProcessShape : ", HealOp.GetErrorCode()
1187     return anObj
1188
1189 ## Remove faces from the given object (shape).
1190 #  @param theObject Shape to be processed.
1191 #  @param theFaces Indices of faces to be removed, if EMPTY then the method
1192 #                  removes ALL faces of the given object.
1193 #  @return New GEOM_Object, containing processed shape.
1194 #
1195 #  Example: see GEOM_TestHealing.py
1196 def SuppressFaces(theObject, theFaces):
1197     anObj = HealOp.SuppressFaces(theObject, theFaces)
1198     if HealOp.IsDone() == 0:
1199       print "SuppressFaces : ", HealOp.GetErrorCode()
1200     return anObj
1201
1202 ## Sewing of some shapes into single shape.
1203 #
1204 #  Example: see GEOM_TestHealing.py
1205 def MakeSewing(ListShape, theTolerance):
1206     comp = MakeCompound(ListShape)
1207     anObj = Sew(comp, theTolerance)
1208     return anObj
1209
1210 ## Sewing of the given object.
1211 #  @param theObject Shape to be processed.
1212 #  @param theTolerance Required tolerance value.
1213 #  @return New GEOM_Object, containing processed shape.
1214 #
1215 #  Example: see MakeSewing() above
1216 def Sew(theObject, theTolerance):
1217     anObj = HealOp.Sew(theObject, theTolerance)
1218     if HealOp.IsDone() == 0:
1219       print "Sew : ", HealOp.GetErrorCode()
1220     return anObj
1221
1222 ## Remove internal wires and edges from the given object (face).
1223 #  @param theObject Shape to be processed.
1224 #  @param theWires Indices of wires to be removed, if EMPTY then the method
1225 #                  removes ALL internal wires of the given object.
1226 #  @return New GEOM_Object, containing processed shape.
1227 #
1228 #  Example: see GEOM_TestHealing.py
1229 def SuppressInternalWires(theObject, theWires):
1230     anObj = HealOp.RemoveIntWires(theObject, theWires)
1231     if HealOp.IsDone() == 0:
1232       print "SuppressInternalWires : ", HealOp.GetErrorCode()
1233     return anObj
1234
1235 ## Remove internal closed contours (holes) from the given object.
1236 #  @param theObject Shape to be processed.
1237 #  @param theWires Indices of wires to be removed, if EMPTY then the method
1238 #                  removes ALL internal holes of the given object
1239 #  @return New GEOM_Object, containing processed shape.
1240 #
1241 #  Example: see GEOM_TestHealing.py
1242 def SuppressHoles(theObject, theWires):
1243     anObj = HealOp.FillHoles(theObject, theWires)
1244     if HealOp.IsDone() == 0:
1245       print "SuppressHoles : ", HealOp.GetErrorCode()
1246     return anObj
1247
1248 ## Close an open wire.
1249 #  @param theObject Shape to be processed.
1250 #  @param theWires Indexes of edge(s) and wire(s) to be closed within <VAR>theObject</VAR>'s shape,
1251 #                  if -1, then theObject itself is a wire.
1252 #  @param isCommonVertex If TRUE : closure by creation of a common vertex,
1253 #                        If FALS : closure by creation of an edge between ends.
1254 #  @return New GEOM_Object, containing processed shape.
1255 #
1256 #  Example: see GEOM_TestHealing.py
1257 def CloseContour(theObject, theWires, isCommonVertex):
1258     anObj = HealOp.CloseContour(theObject, theWires, isCommonVertex)
1259     if HealOp.IsDone() == 0:
1260       print "CloseContour : ", HealOp.GetErrorCode()
1261     return anObj
1262
1263 ## Addition of a point to a given edge object.
1264 #  @param theObject Shape to be processed.
1265 #  @param theEdgeIndex Index of edge to be divided within theObject's shape,
1266 #                      if -1, then theObject itself is the edge.
1267 #  @param theValue Value of parameter on edge or length parameter,
1268 #                  depending on \a isByParameter.
1269 #  @param isByParameter If TRUE : \a theValue is treated as a curve parameter [0..1],
1270 #                       if FALSE : \a theValue is treated as a length parameter [0..1]
1271 #  @return New GEOM_Object, containing processed shape.
1272 #
1273 #  Example: see GEOM_TestHealing.py
1274 def DivideEdge(theObject, theEdgeIndex, theValue, isByParameter):
1275     anObj = HealOp.DivideEdge(theObject, theEdgeIndex, theValue, isByParameter)
1276     if HealOp.IsDone() == 0:
1277       print "DivideEdge : ", HealOp.GetErrorCode()
1278     return anObj
1279
1280 ## Change orientation of the given object.
1281 #  @param theObject Shape to be processed.
1282 #  @update given shape
1283 def ChangeOrientationShell(theObject):
1284     theObject = HealOp.ChangeOrientation(theObject)
1285     if HealOp.IsDone() == 0:
1286       print "ChangeOrientation : ", HealOp.GetErrorCode()
1287
1288 ## Change orientation of the given object.
1289 #  @param theObject Shape to be processed.
1290 #  @return New GEOM_Object, containing processed shape.
1291 def ChangeOrientationShellCopy(theObject):
1292     anObj = HealOp.ChangeOrientationCopy(theObject)
1293     if HealOp.IsDone() == 0:
1294       print "ChangeOrientation : ", HealOp.GetErrorCode()
1295     return anObj
1296
1297 ## Get a list of wires (wrapped in GEOM_Object-s),
1298 #  that constitute a free boundary of the given shape.
1299 #  @param theObject Shape to get free boundary of.
1300 #  @return [status, theClosedWires, theOpenWires]
1301 #  status: FALSE, if an error(s) occured during the method execution.
1302 #  theClosedWires: Closed wires on the free boundary of the given shape.
1303 #  theOpenWires: Open wires on the free boundary of the given shape.
1304 #
1305 #  Example: see GEOM_TestHealing.py
1306 def GetFreeBoundary(theObject):
1307     anObj = HealOp.GetFreeBoundary(theObject)
1308     if HealOp.IsDone() == 0:
1309       print "GetFreeBoundaries : ", HealOp.GetErrorCode()
1310     return anObj
1311
1312 # -----------------------------------------------------------------------------
1313 # Create advanced objects
1314 # -----------------------------------------------------------------------------
1315
1316 ## Create a copy of the given object
1317 #
1318 #  Example: see GEOM_TestAll.py
1319 def MakeCopy(theOriginal):
1320     anObj = InsertOp.MakeCopy(theOriginal)
1321     if InsertOp.IsDone() == 0:
1322       print "MakeCopy : ", InsertOp.GetErrorCode()
1323     return anObj
1324
1325 ## Create a filling from the given compound of contours.
1326 #  @param theShape the compound of contours
1327 #  @param theMinDeg a minimal degree
1328 #  @param theMaxDeg a maximal degree
1329 #  @param theTol2D a 2d tolerance
1330 #  @param theTol3D a 3d tolerance
1331 #  @param theNbIter a number of iteration
1332 #  @return New GEOM_Object, containing the created filling surface.
1333 #
1334 #  Example: see GEOM_TestAll.py
1335 def MakeFilling(theShape, theMinDeg, theMaxDeg, theTol2D, theTol3D, theNbIter):
1336     anObj = PrimOp.MakeFilling(theShape, theMinDeg, theMaxDeg, theTol2D, theTol3D, theNbIter)
1337     if PrimOp.IsDone() == 0:
1338       print "MakeFilling : ", PrimOp.GetErrorCode()
1339     return anObj
1340
1341 ## Replace coincident faces in theShape by one face.
1342 #  @param theShape Initial shape.
1343 #  @param theTolerance Maximum distance between faces, which can be considered as coincident.
1344 #  @return New GEOM_Object, containing a copy of theShape without coincident faces.
1345 #
1346 #  Example: see GEOM_Spanner.py
1347 def MakeGlueFaces(theShape, theTolerance):
1348     anObj = ShapesOp.MakeGlueFaces(theShape, theTolerance)
1349     if ShapesOp.IsDone() == 0:
1350       print "MakeGlueFaces : ", ShapesOp.GetErrorCode()
1351     return anObj
1352
1353 # -----------------------------------------------------------------------------
1354 # Boolean (Common, Cut, Fuse, Section)
1355 # -----------------------------------------------------------------------------
1356
1357 ## Perform one of boolean operations on two given shapes.
1358 #  @param theShape1 First argument for boolean operation.
1359 #  @param theShape2 Second argument for boolean operation.
1360 #  @param theOperation Indicates the operation to be done:
1361 #                      1 - Common, 2 - Cut, 3 - Fuse, 4 - Section.
1362 #  @return New GEOM_Object, containing the result shape.
1363 #
1364 #  Example: see GEOM_TestAll.py
1365 def MakeBoolean(theShape1, theShape2, theOperation):
1366     anObj = BoolOp.MakeBoolean(theShape1, theShape2, theOperation)
1367     if BoolOp.IsDone() == 0:
1368       print "MakeBoolean : ", BoolOp.GetErrorCode()
1369     return anObj
1370
1371 ## Shortcut to MakeBoolean(s1, s2, 1)
1372 #
1373 #  Example: see GEOM_TestOthers.py
1374 def MakeCommon(s1, s2):
1375     return MakeBoolean(s1, s2, 1)
1376
1377 ## Shortcut to MakeBoolean(s1, s2, 2)
1378 #
1379 #  Example: see GEOM_TestOthers.py
1380 def MakeCut(s1, s2):
1381     return MakeBoolean(s1, s2, 2)
1382
1383 ## Shortcut to MakeBoolean(s1, s2, 3)
1384 #
1385 #  Example: see GEOM_TestOthers.py
1386 def MakeFuse(s1, s2):
1387     return MakeBoolean(s1, s2, 3)
1388
1389 ## Shortcut to MakeBoolean(s1, s2, 4)
1390 #
1391 #  Example: see GEOM_TestOthers.py
1392 def MakeSection(s1, s2):
1393     return MakeBoolean(s1, s2, 4)
1394
1395 ## Perform partition operation.
1396 #  @param ListShapes Shapes to be intersected.
1397 #  @param ListTools Shapes to intersect theShapes.
1398 #  !!!NOTE: Each compound from ListShapes and ListTools will be exploded
1399 #           in order to avoid possible intersection between shapes from
1400 #           this compound.
1401 #  @param Limit Type of resulting shapes (corresponding to TopAbs_ShapeEnum).
1402 #
1403 #  After implementation new version of PartitionAlgo (October 2006)
1404 #  other parameters are ignored by current functionality. They are kept
1405 #  in this function only for support old versions.
1406 #  Ignored parameters:
1407 #      @param ListKeepInside Shapes, outside which the results will be deleted.
1408 #         Each shape from theKeepInside must belong to theShapes also.
1409 #      @param ListRemoveInside Shapes, inside which the results will be deleted.
1410 #         Each shape from theRemoveInside must belong to theShapes also.
1411 #      @param RemoveWebs If TRUE, perform Glue 3D algorithm.
1412 #      @param ListMaterials Material indices for each shape. Make sence,
1413 #         only if theRemoveWebs is TRUE.
1414 #
1415 #  @return New GEOM_Object, containing the result shapes.
1416 #
1417 #  Example: see GEOM_TestAll.py
1418 def MakePartition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
1419                   Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
1420     anObj = BoolOp.MakePartition(ListShapes, ListTools,
1421                                  ListKeepInside, ListRemoveInside,
1422                                  Limit, RemoveWebs, ListMaterials);
1423     if BoolOp.IsDone() == 0:
1424       print "MakePartition : ", BoolOp.GetErrorCode()
1425     return anObj
1426
1427 ## Perform partition operation.
1428 #  This method may be useful if it is needed to make a partition for
1429 #  compound contains nonintersected shapes. Performance will be better
1430 #  since intersection between shapes from compound is not performed.
1431 #
1432 #  Description of all parameters as in previous method MakePartition()
1433 #
1434 #  !!!NOTE: Passed compounds (via ListShapes or via ListTools)
1435 #           have to consist of nonintersecting shapes.
1436 #
1437 #  @return New GEOM_Object, containing the result shapes.
1438 #
1439 def MakePartitionNonSelfIntersectedShape(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
1440                   Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
1441     anObj = BoolOp.MakePartitionNonSelfIntersectedShape(ListShapes, ListTools,
1442                                                         ListKeepInside, ListRemoveInside,
1443                                                         Limit, RemoveWebs, ListMaterials);
1444     if BoolOp.IsDone() == 0:
1445       print "MakePartitionNonSelfIntersectedShape : ", BoolOp.GetErrorCode()
1446     return anObj
1447
1448 ## Shortcut to MakePartition()
1449 #
1450 #  Example: see GEOM_TestOthers.py
1451 def Partition(ListShapes, ListTools=[], ListKeepInside=[], ListRemoveInside=[],
1452               Limit=ShapeType["SHAPE"], RemoveWebs=0, ListMaterials=[]):
1453     anObj = MakePartition(ListShapes, ListTools,
1454                           ListKeepInside, ListRemoveInside,
1455                           Limit, RemoveWebs, ListMaterials);
1456     return anObj
1457
1458 ## Perform partition of the Shape with the Plane
1459 #  @param theShape Shape to be intersected.
1460 #  @param thePlane Tool shape, to intersect theShape.
1461 #  @return New GEOM_Object, containing the result shape.
1462 #
1463 #  Example: see GEOM_TestAll.py
1464 def MakeHalfPartition(theShape, thePlane):
1465     anObj = BoolOp.MakeHalfPartition(theShape, thePlane)
1466     if BoolOp.IsDone() == 0:
1467       print "MakeHalfPartition : ", BoolOp.GetErrorCode()
1468     return anObj
1469
1470 # -----------------------------------------------------------------------------
1471 # Transform objects
1472 # -----------------------------------------------------------------------------
1473
1474 ## Translate the given object along the vector, specified
1475 #  by its end points, creating its copy before the translation.
1476 #  @param theObject The object to be translated.
1477 #  @param thePoint1 Start point of translation vector.
1478 #  @param thePoint2 End point of translation vector.
1479 #  @return New GEOM_Object, containing the translated object.
1480 #
1481 #  Example: see GEOM_TestAll.py
1482 def MakeTranslationTwoPoints(theObject, thePoint1, thePoint2):
1483     anObj = TrsfOp.TranslateTwoPointsCopy(theObject, thePoint1, thePoint2)
1484     if TrsfOp.IsDone() == 0:
1485       print "TranslateTwoPointsCopy : ", TrsfOp.GetErrorCode()
1486     return anObj
1487
1488 ## Translate the given object along the vector, specified
1489 #  by its components, creating its copy before the translation.
1490 #  @param theObject The object to be translated.
1491 #  @param theDX,theDY,theDZ Components of translation vector.
1492 #  @return New GEOM_Object, containing the translated object.
1493 #
1494 #  Example: see GEOM_TestAll.py
1495 def MakeTranslation(theObject, theDX, theDY, theDZ):
1496     anObj = TrsfOp.TranslateDXDYDZCopy(theObject, theDX, theDY, theDZ)
1497     if TrsfOp.IsDone() == 0:
1498       print "TranslateDXDYDZCopy : ", TrsfOp.GetErrorCode()
1499     return anObj
1500
1501 ## Translate the given object along the given vector,
1502 #  creating its copy before the translation.
1503 #  @param theObject The object to be translated.
1504 #  @param theVector The translation vector.
1505 #  @return New GEOM_Object, containing the translated object.
1506 #
1507 #  Example: see GEOM_TestAll.py
1508 def MakeTranslationVector(theObject, theVector):
1509     anObj = TrsfOp.TranslateVectorCopy(theObject, theVector)
1510     if TrsfOp.IsDone() == 0:
1511       print "TranslateVectorCopy : ", TrsfOp.GetErrorCode()
1512     return anObj
1513
1514 ## Rotate the given object around the given axis
1515 #  on the given angle, creating its copy before the rotatation.
1516 #  @param theObject The object to be rotated.
1517 #  @param theAxis Rotation axis.
1518 #  @param theAngle Rotation angle in radians.
1519 #  @return New GEOM_Object, containing the rotated object.
1520 #
1521 #  Example: see GEOM_TestAll.py
1522 def MakeRotation(theObject, theAxis, theAngle):
1523     anObj = TrsfOp.RotateCopy(theObject, theAxis, theAngle)
1524     if TrsfOp.IsDone() == 0:
1525       print "RotateCopy : ", TrsfOp.GetErrorCode()
1526     return anObj
1527
1528 ## Rotate given object around vector perpendicular to plane
1529 #  containing three points, creating its copy before the rotatation.
1530 #  @param theObject The object to be rotated.
1531 #  @param theCentPoint central point - the axis is the vector perpendicular to the plane
1532 #  containing the three points.
1533 #  @param thePoint1 and thePoint2 - in a perpendicular plan of the axis.
1534 #  @return New GEOM_Object, containing the rotated object.
1535 #
1536 #  Example: see GEOM_TestAll.py
1537 def MakeRotationThreePoints(theObject, theCentPoint, thePoint1, thePoint2):
1538     anObj = TrsfOp.RotateThreePointsCopy(theObject, theCentPoint, thePoint1, thePoint2)
1539     if TrsfOp.IsDone() == 0:
1540       print "RotateThreePointsCopy : ", TrsfOp.GetErrorCode()
1541     return anObj
1542
1543 ## Scale the given object by the factor, creating its copy before the scaling.
1544 #  @param theObject The object to be scaled.
1545 #  @param thePoint Center point for scaling.
1546 #  @param theFactor Scaling factor value.
1547 #  @return New GEOM_Object, containing the scaled shape.
1548 #
1549 #  Example: see GEOM_TestAll.py
1550 def MakeScaleTransform(theObject, thePoint, theFactor):
1551     anObj = TrsfOp.ScaleShapeCopy(theObject, thePoint, theFactor)
1552     if TrsfOp.IsDone() == 0:
1553       print "ScaleShapeCopy : ", TrsfOp.GetErrorCode()
1554     return anObj
1555
1556 ## Create an object, symmetrical
1557 #  to the given one relatively the given plane.
1558 #  @param theObject The object to be mirrored.
1559 #  @param thePlane Plane of symmetry.
1560 #  @return New GEOM_Object, containing the mirrored shape.
1561 #
1562 #  Example: see GEOM_TestAll.py
1563 def MakeMirrorByPlane(theObject, thePlane):
1564     anObj = TrsfOp.MirrorPlaneCopy(theObject, thePlane)
1565     if TrsfOp.IsDone() == 0:
1566       print "MirrorPlaneCopy : ", TrsfOp.GetErrorCode()
1567     return anObj
1568
1569 ## Create an object, symmetrical
1570 #  to the given one relatively the given axis.
1571 #  @param theObject The object to be mirrored.
1572 #  @param theAxis Axis of symmetry.
1573 #  @return New GEOM_Object, containing the mirrored shape.
1574 #
1575 #  Example: see GEOM_TestAll.py
1576 def MakeMirrorByAxis(theObject, theAxis):
1577     anObj = TrsfOp.MirrorAxisCopy(theObject, theAxis)
1578     if TrsfOp.IsDone() == 0:
1579       print "MirrorAxisCopy : ", TrsfOp.GetErrorCode()
1580     return anObj
1581
1582 ## Create an object, symmetrical
1583 #  to the given one relatively the given point.
1584 #  @param theObject The object to be mirrored.
1585 #  @param thePoint Point of symmetry.
1586 #  @return New GEOM_Object, containing the mirrored shape.
1587 #
1588 #  Example: see GEOM_TestAll.py
1589 def MakeMirrorByPoint(theObject, thePoint):
1590     anObj = TrsfOp.MirrorPointCopy(theObject, thePoint)
1591     if TrsfOp.IsDone() == 0:
1592       print "MirrorPointCopy : ", TrsfOp.GetErrorCode()
1593     return anObj
1594
1595 ## Modify the Location of the given object by LCS,
1596 #  creating its copy before the setting.
1597 #  @param theObject The object to be displaced.
1598 #  @param theStartLCS Coordinate system to perform displacement from it.
1599 #                     If \a theStartLCS is NULL, displacement
1600 #                     will be performed from global CS.
1601 #                     If \a theObject itself is used as \a theStartLCS,
1602 #                     its location will be changed to \a theEndLCS.
1603 #  @param theEndLCS Coordinate system to perform displacement to it.
1604 #  @return New GEOM_Object, containing the displaced shape.
1605 #
1606 #  Example: see GEOM_TestAll.py
1607 def MakePosition(theObject, theStartLCS, theEndLCS):
1608     anObj = TrsfOp.PositionShapeCopy(theObject, theStartLCS, theEndLCS)
1609     if TrsfOp.IsDone() == 0:
1610       print "PositionShapeCopy : ", TrsfOp.GetErrorCode()
1611     return anObj
1612
1613 ## Create new object as offset of the given one.
1614 #  @param theObject The base object for the offset.
1615 #  @param theOffset Offset value.
1616 #  @return New GEOM_Object, containing the offset object.
1617 #
1618 #  Example: see GEOM_TestAll.py
1619 def MakeOffset(theObject, theOffset):
1620     anObj = TrsfOp.OffsetShapeCopy(theObject, theOffset)
1621     if TrsfOp.IsDone() == 0:
1622       print "OffsetShapeCopy : ", TrsfOp.GetErrorCode()
1623     return anObj
1624
1625 # -----------------------------------------------------------------------------
1626 # Patterns
1627 # -----------------------------------------------------------------------------
1628
1629 ## Translate the given object along the given vector a given number times
1630 #  @param theObject The object to be translated.
1631 #  @param theVector Direction of the translation.
1632 #  @param theStep Distance to translate on.
1633 #  @param theNbTimes Quantity of translations to be done.
1634 #  @return New GEOM_Object, containing compound of all
1635 #          the shapes, obtained after each translation.
1636 #
1637 #  Example: see GEOM_TestAll.py
1638 def MakeMultiTranslation1D(theObject, theVector, theStep, theNbTimes):
1639     anObj = TrsfOp.MultiTranslate1D(theObject, theVector, theStep, theNbTimes)
1640     if TrsfOp.IsDone() == 0:
1641       print "MultiTranslate1D : ", TrsfOp.GetErrorCode()
1642     return anObj
1643
1644 ## Conseqently apply two specified translations to theObject specified number of times.
1645 #  @param theObject The object to be translated.
1646 #  @param theVector1 Direction of the first translation.
1647 #  @param theStep1 Step of the first translation.
1648 #  @param theNbTimes1 Quantity of translations to be done along theVector1.
1649 #  @param theVector2 Direction of the second translation.
1650 #  @param theStep2 Step of the second translation.
1651 #  @param theNbTimes2 Quantity of translations to be done along theVector2.
1652 #  @return New GEOM_Object, containing compound of all
1653 #          the shapes, obtained after each translation.
1654 #
1655 #  Example: see GEOM_TestAll.py
1656 def MakeMultiTranslation2D(theObject, theVector1, theStep1, theNbTimes1,
1657                                       theVector2, theStep2, theNbTimes2):
1658     anObj = TrsfOp.MultiTranslate2D(theObject, theVector1, theStep1, theNbTimes1,
1659                                                theVector2, theStep2, theNbTimes2)
1660     if TrsfOp.IsDone() == 0:
1661       print "MultiTranslate2D : ", TrsfOp.GetErrorCode()
1662     return anObj
1663
1664 ## Rotate the given object around the given axis a given number times.
1665 #  Rotation angle will be 2*PI/theNbTimes.
1666 #  @param theObject The object to be rotated.
1667 #  @param theAxis The rotation axis.
1668 #  @param theNbTimes Quantity of rotations to be done.
1669 #  @return New GEOM_Object, containing compound of all the
1670 #          shapes, obtained after each rotation.
1671 #
1672 #  Example: see GEOM_TestAll.py
1673 def MultiRotate1D(theObject, theAxis, theNbTimes):
1674     anObj = TrsfOp.MultiRotate1D(theObject, theAxis, theNbTimes)
1675     if TrsfOp.IsDone() == 0:
1676       print "MultiRotate1D : ", TrsfOp.GetErrorCode()
1677     return anObj
1678
1679 ## Rotate the given object around the
1680 #  given axis on the given angle a given number
1681 #  times and multi-translate each rotation result.
1682 #  Translation direction passes through center of gravity
1683 #  of rotated shape and its projection on the rotation axis.
1684 #  @param theObject The object to be rotated.
1685 #  @param theAxis Rotation axis.
1686 #  @param theAngle Rotation angle in graduces.
1687 #  @param theNbTimes1 Quantity of rotations to be done.
1688 #  @param theStep Translation distance.
1689 #  @param theNbTimes2 Quantity of translations to be done.
1690 #  @return New GEOM_Object, containing compound of all the
1691 #          shapes, obtained after each transformation.
1692 #
1693 #  Example: see GEOM_TestAll.py
1694 def MultiRotate2D(theObject, theAxis, theAngle, theNbTimes1, theStep, theNbTimes2):
1695     anObj = TrsfOp.MultiRotate2D(theObject, theAxis, theAngle, theNbTimes1, theStep, theNbTimes2)
1696     if TrsfOp.IsDone() == 0:
1697       print "MultiRotate2D : ", TrsfOp.GetErrorCode()
1698     return anObj
1699
1700 ## The same, as MultiRotate1D(), but axis is given by direction and point
1701 #
1702 #  Example: see GEOM_TestOthers.py
1703 def MakeMultiRotation1D(aShape,aDir,aPoint,aNbTimes):
1704     aVec = MakeLine(aPoint,aDir)
1705     anObj = MultiRotate1D(aShape,aVec,aNbTimes)
1706     return anObj
1707
1708 ## The same, as MultiRotate2D(), but axis is given by direction and point
1709 #
1710 #  Example: see GEOM_TestOthers.py
1711 def MakeMultiRotation2D(aShape,aDir,aPoint,anAngle,nbtimes1,aStep,nbtimes2):
1712     aVec = MakeLine(aPoint,aDir)
1713     anObj = MultiRotate2D(aShape,aVec,anAngle,nbtimes1,aStep,nbtimes2)
1714     return anObj
1715
1716 # -----------------------------------------------------------------------------
1717 # Local operations
1718 # -----------------------------------------------------------------------------
1719
1720 ## Perform a fillet on all edges of the given shape.
1721 #  @param theShape Shape, to perform fillet on.
1722 #  @param theR Fillet radius.
1723 #  @return New GEOM_Object, containing the result shape.
1724 #
1725 #  Example: see GEOM_TestOthers.py
1726 def MakeFilletAll(theShape, theR):
1727     anObj = LocalOp.MakeFilletAll(theShape, theR)
1728     if LocalOp.IsDone() == 0:
1729       print "MakeFilletAll : ", LocalOp.GetErrorCode()
1730     return anObj
1731
1732 ## Perform a fillet on the specified edges/faces of the given shape
1733 #  @param theShape Shape, to perform fillet on.
1734 #  @param theR Fillet radius.
1735 #  @param theShapeType Type of shapes in <theListShapes>.
1736 #  @param theListShapes Global indices of edges/faces to perform fillet on.
1737 #    \note Global index of sub-shape can be obtained, using method geompy.GetSubShapeID().
1738 #  @return New GEOM_Object, containing the result shape.
1739 #
1740 #  Example: see GEOM_TestAll.py
1741 def MakeFillet(theShape, theR, theShapeType, theListShapes):
1742     anObj = None
1743     if theShapeType == ShapeType["EDGE"]:
1744         anObj = LocalOp.MakeFilletEdges(theShape, theR, theListShapes)
1745     else:
1746         anObj = LocalOp.MakeFilletFaces(theShape, theR, theListShapes)
1747     if LocalOp.IsDone() == 0:
1748       print "MakeFillet : ", LocalOp.GetErrorCode()
1749     return anObj
1750
1751 ## Perform a symmetric chamfer on all edges of the given shape.
1752 #  @param theShape Shape, to perform chamfer on.
1753 #  @param theD Chamfer size along each face.
1754 #  @return New GEOM_Object, containing the result shape.
1755 #
1756 #  Example: see GEOM_TestOthers.py
1757 def MakeChamferAll(theShape, theD):
1758     anObj = LocalOp.MakeChamferAll(theShape, theD)
1759     if LocalOp.IsDone() == 0:
1760       print "MakeChamferAll : ", LocalOp.GetErrorCode()
1761     return anObj
1762
1763 ## Perform a chamfer on edges, common to the specified faces,
1764 #  with distance D1 on the Face1
1765 #  @param theShape Shape, to perform chamfer on.
1766 #  @param theD1 Chamfer size along \a theFace1.
1767 #  @param theD2 Chamfer size along \a theFace2.
1768 #  @param theFace1,theFace2 Global indices of two faces of \a theShape.
1769 #    \note Global index of sub-shape can be obtained, using method geompy.GetSubShapeID().
1770 #  @return New GEOM_Object, containing the result shape.
1771 #
1772 #  Example: see GEOM_TestAll.py
1773 def MakeChamferEdge(theShape, theD1, theD2, theFace1, theFace2):
1774     anObj = LocalOp.MakeChamferEdge(theShape, theD1, theD2, theFace1, theFace2)
1775     if LocalOp.IsDone() == 0:
1776       print "MakeChamferEdge : ", LocalOp.GetErrorCode()
1777     return anObj
1778
1779 ## Perform a chamfer on all edges of the specified faces,
1780 #  with distance D1 on the first specified face (if several for one edge)
1781 #  @param theShape Shape, to perform chamfer on.
1782 #  @param theD1 Chamfer size along face from \a theFaces. If both faces,
1783 #               connected to the edge, are in \a theFaces, \a theD1
1784 #               will be get along face, which is nearer to \a theFaces beginning.
1785 #  @param theD2 Chamfer size along another of two faces, connected to the edge.
1786 #  @param theFaces Sequence of global indices of faces of \a theShape.
1787 #    \note Global index of sub-shape can be obtained, using method geompy.GetSubShapeID().
1788 #  @return New GEOM_Object, containing the result shape.
1789 #
1790 #  Example: see GEOM_TestAll.py
1791 def MakeChamferFaces(theShape, theD1, theD2, theFaces):
1792     anObj = LocalOp.MakeChamferFaces(theShape, theD1, theD2, theFaces)
1793     if LocalOp.IsDone() == 0:
1794       print "MakeChamferFaces : ", LocalOp.GetErrorCode()
1795     return anObj
1796
1797 ## Shortcut to MakeChamferEdge() and MakeChamferFaces()
1798 #
1799 #  Example: see GEOM_TestOthers.py
1800 def MakeChamfer(aShape,d1,d2,aShapeType,ListShape):
1801     anObj = None
1802     if aShapeType == ShapeType["EDGE"]:
1803         anObj = MakeChamferEdge(aShape,d1,d2,ListShape[0],ListShape[1])
1804     else:
1805         anObj = MakeChamferFaces(aShape,d1,d2,ListShape)
1806     return anObj
1807
1808 ## Perform an Archimde operation on the given shape with given parameters.
1809 #  The object presenting the resulting face is returned.
1810 #  @param theShape Shape to be put in water.
1811 #  @param theWeight Weight og the shape.
1812 #  @param theWaterDensity Density of the water.
1813 #  @param theMeshDeflection Deflection of the mesh, using to compute the section.
1814 #  @return New GEOM_Object, containing a section of \a theShape
1815 #          by a plane, corresponding to water level.
1816 #
1817 #  Example: see GEOM_TestAll.py
1818 def Archimede(theShape, theWeight, theWaterDensity, theMeshDeflection):
1819     anObj = LocalOp.MakeArchimede(theShape, theWeight, theWaterDensity, theMeshDeflection)
1820     if LocalOp.IsDone() == 0:
1821       print "MakeArchimede : ", LocalOp.GetErrorCode()
1822     return anObj
1823
1824 # -----------------------------------------------------------------------------
1825 # Information objects
1826 # -----------------------------------------------------------------------------
1827
1828 ## Get point coordinates
1829 #  @return [x, y, z]
1830 #
1831 #  Example: see GEOM_TestMeasures.py
1832 def PointCoordinates(Point):
1833     aTuple = MeasuOp.PointCoordinates(Point)
1834     if MeasuOp.IsDone() == 0:
1835       print "PointCoordinates : ", MeasuOp.GetErrorCode()
1836     return aTuple
1837
1838 ## Get summarized length of all wires,
1839 #  area of surface and volume of the given shape.
1840 #  @param theShape Shape to define properties of.
1841 #  @return [theLength, theSurfArea, theVolume]
1842 #  theLength:   Summarized length of all wires of the given shape.
1843 #  theSurfArea: Area of surface of the given shape.
1844 #  theVolume:   Volume of the given shape.
1845 #
1846 #  Example: see GEOM_TestMeasures.py
1847 def BasicProperties(theShape):
1848     aTuple = MeasuOp.GetBasicProperties(theShape)
1849     if MeasuOp.IsDone() == 0:
1850       print "BasicProperties : ", MeasuOp.GetErrorCode()
1851     return aTuple
1852
1853 ## Get parameters of bounding box of the given shape
1854 #  @param theShape Shape to obtain bounding box of.
1855 #  @return [Xmin,Xmax, Ymin,Ymax, Zmin,Zmax]
1856 #  Xmin,Xmax: Limits of shape along OX axis.
1857 #  Ymin,Ymax: Limits of shape along OY axis.
1858 #  Zmin,Zmax: Limits of shape along OZ axis.
1859 #
1860 #  Example: see GEOM_TestMeasures.py
1861 def BoundingBox(theShape):
1862     aTuple = MeasuOp.GetBoundingBox(theShape)
1863     if MeasuOp.IsDone() == 0:
1864       print "BoundingBox : ", MeasuOp.GetErrorCode()
1865     return aTuple
1866
1867 ## Get inertia matrix and moments of inertia of theShape.
1868 #  @param theShape Shape to calculate inertia of.
1869 #  @return [I11,I12,I13, I21,I22,I23, I31,I32,I33, Ix,Iy,Iz]
1870 #  I(1-3)(1-3): Components of the inertia matrix of the given shape.
1871 #  Ix,Iy,Iz:    Moments of inertia of the given shape.
1872 #
1873 #  Example: see GEOM_TestMeasures.py
1874 def Inertia(theShape):
1875     aTuple = MeasuOp.GetInertia(theShape)
1876     if MeasuOp.IsDone() == 0:
1877       print "Inertia : ", MeasuOp.GetErrorCode()
1878     return aTuple
1879
1880 ## Get minimal distance between the given shapes.
1881 #  @param theShape1,theShape2 Shapes to find minimal distance between.
1882 #  @return Value of the minimal distance between the given shapes.
1883 #
1884 #  Example: see GEOM_TestMeasures.py
1885 def MinDistance(theShape1, theShape2):
1886     aTuple = MeasuOp.GetMinDistance(theShape1, theShape2)
1887     if MeasuOp.IsDone() == 0:
1888       print "MinDistance : ", MeasuOp.GetErrorCode()
1889     return aTuple[0]
1890
1891 ## Get min and max tolerances of sub-shapes of theShape
1892 #  @param theShape Shape, to get tolerances of.
1893 #  @return [FaceMin,FaceMax, EdgeMin,EdgeMax, VertMin,VertMax]
1894 #  FaceMin,FaceMax: Min and max tolerances of the faces.
1895 #  EdgeMin,EdgeMax: Min and max tolerances of the edges.
1896 #  VertMin,VertMax: Min and max tolerances of the vertices.
1897 #
1898 #  Example: see GEOM_TestMeasures.py
1899 def Tolerance(theShape):
1900     aTuple = MeasuOp.GetTolerance(theShape)
1901     if MeasuOp.IsDone() == 0:
1902       print "Tolerance : ", MeasuOp.GetErrorCode()
1903     return aTuple
1904
1905 ## Obtain description of the given shape (number of sub-shapes of each type)
1906 #  @param theShape Shape to be described.
1907 #  @return Description of the given shape.
1908 #
1909 #  Example: see GEOM_TestMeasures.py
1910 def WhatIs(theShape):
1911     aDescr = MeasuOp.WhatIs(theShape)
1912     if MeasuOp.IsDone() == 0:
1913       print "WhatIs : ", MeasuOp.GetErrorCode()
1914     return aDescr
1915
1916 ## Get a point, situated at the centre of mass of theShape.
1917 #  @param theShape Shape to define centre of mass of.
1918 #  @return New GEOM_Object, containing the created point.
1919 #
1920 #  Example: see GEOM_TestMeasures.py
1921 def MakeCDG(theShape):
1922     anObj = MeasuOp.GetCentreOfMass(theShape)
1923     if MeasuOp.IsDone() == 0:
1924       print "GetCentreOfMass : ", MeasuOp.GetErrorCode()
1925     return anObj
1926
1927 ## Check a topology of the given shape.
1928 #  @param theShape Shape to check validity of.
1929 #  @param theIsCheckGeom If FALSE, only the shape's topology will be checked,
1930 #                        if TRUE, the shape's geometry will be checked also.
1931 #  @return TRUE, if the shape "seems to be valid".
1932 #  If theShape is invalid, prints a description of problem.
1933 #
1934 #  Example: see GEOM_TestMeasures.py
1935 def CheckShape(theShape, theIsCheckGeom = 0):
1936     if theIsCheckGeom:
1937         (IsValid, Status) = MeasuOp.CheckShapeWithGeometry(theShape)
1938     else:
1939         (IsValid, Status) = MeasuOp.CheckShape(theShape)
1940
1941     if MeasuOp.IsDone() == 0:
1942       print "CheckShape : ", MeasuOp.GetErrorCode()
1943     else:
1944       if IsValid == 0:
1945         print Status
1946     return IsValid
1947
1948 ## Get position (LCS) of theShape.
1949 #
1950 #  Origin of the LCS is situated at the shape's center of mass.
1951 #  Axes of the LCS are obtained from shape's location or,
1952 #  if the shape is a planar face, from position of its plane.
1953 #
1954 #  @param theShape Shape to calculate position of.
1955 #  @return [Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz].
1956 #          Ox,Oy,Oz: Coordinates of shape's LCS origin.
1957 #          Zx,Zy,Zz: Coordinates of shape's LCS normal(main) direction.
1958 #          Xx,Xy,Xz: Coordinates of shape's LCS X direction.
1959 #
1960 #  Example: see GEOM_TestMeasures.py
1961 def GetPosition(theShape):
1962     aTuple = MeasuOp.GetPosition(theShape)
1963     if MeasuOp.IsDone() == 0:
1964       print "GetPosition : ", MeasuOp.GetErrorCode()
1965     return aTuple
1966
1967 # -----------------------------------------------------------------------------
1968 # Import/Export objects
1969 # -----------------------------------------------------------------------------
1970
1971 ## Import a shape from the BREP or IGES or STEP file
1972 #  (depends on given format) with given name.
1973 #  @param theFileName The file, containing the shape.
1974 #  @param theFormatName Specify format for the file reading.
1975 #         Available formats can be obtained with InsertOp.ImportTranslators() method.
1976 #  @return New GEOM_Object, containing the imported shape.
1977 #
1978 #  Example: see GEOM_TestOthers.py
1979 def Import(theFileName, theFormatName):
1980     anObj = InsertOp.Import(theFileName, theFormatName)
1981     if InsertOp.IsDone() == 0:
1982       print "Import : ", InsertOp.GetErrorCode()
1983     return anObj
1984
1985 ## Shortcut to Import() for BREP format
1986 #
1987 #  Example: see GEOM_TestOthers.py
1988 def ImportBREP(theFileName):
1989     return Import(theFileName, "BREP")
1990
1991 ## Shortcut to Import() for IGES format
1992 #
1993 #  Example: see GEOM_TestOthers.py
1994 def ImportIGES(theFileName):
1995     return Import(theFileName, "IGES")
1996
1997 ## Shortcut to Import() for STEP format
1998 #
1999 #  Example: see GEOM_TestOthers.py
2000 def ImportSTEP(theFileName):
2001     return Import(theFileName, "STEP")
2002
2003 ## Export the given shape into a file with given name.
2004 #  @param theObject Shape to be stored in the file.
2005 #  @param theFileName Name of the file to store the given shape in.
2006 #  @param theFormatName Specify format for the shape storage.
2007 #         Available formats can be obtained with InsertOp.ImportTranslators() method.
2008 #
2009 #  Example: see GEOM_TestOthers.py
2010 def Export(theObject, theFileName, theFormatName):
2011     InsertOp.Export(theObject, theFileName, theFormatName)
2012     if InsertOp.IsDone() == 0:
2013       print "Export : ", InsertOp.GetErrorCode()
2014
2015 ## Shortcut to Export() for BREP format
2016 #
2017 #  Example: see GEOM_TestOthers.py
2018 def ExportBREP(theObject, theFileName):
2019     return Export(theObject, theFileName, "BREP")
2020
2021 ## Shortcut to Export() for IGES format
2022 #
2023 #  Example: see GEOM_TestOthers.py
2024 def ExportIGES(theObject, theFileName):
2025     return Export(theObject, theFileName, "IGES")
2026
2027 ## Shortcut to Export() for STEP format
2028 #
2029 #  Example: see GEOM_TestOthers.py
2030 def ExportSTEP(theObject, theFileName):
2031     return Export(theObject, theFileName, "STEP")
2032
2033 # -----------------------------------------------------------------------------
2034 # Block operations
2035 # -----------------------------------------------------------------------------
2036
2037 ## Create a quadrangle face from four edges. Order of Edges is not
2038 #  important. It is  not necessary that edges share the same vertex.
2039 #  @param E1,E2,E3,E4 Edges for the face bound.
2040 #  @return New GEOM_Object, containing the created face.
2041 #
2042 #  Example: see GEOM_Spanner.py
2043 def MakeQuad(E1, E2, E3, E4):
2044     anObj = BlocksOp.MakeQuad(E1, E2, E3, E4)
2045     if BlocksOp.IsDone() == 0:
2046       print "MakeQuad : ", BlocksOp.GetErrorCode()
2047     return anObj
2048
2049 ## Create a quadrangle face on two edges.
2050 #  The missing edges will be built by creating the shortest ones.
2051 #  @param E1,E2 Two opposite edges for the face.
2052 #  @return New GEOM_Object, containing the created face.
2053 #
2054 #  Example: see GEOM_Spanner.py
2055 def MakeQuad2Edges(E1, E2):
2056     anObj = BlocksOp.MakeQuad2Edges(E1, E2)
2057     if BlocksOp.IsDone() == 0:
2058       print "MakeQuad2Edges : ", BlocksOp.GetErrorCode()
2059     return anObj
2060
2061 ## Create a quadrangle face with specified corners.
2062 #  The missing edges will be built by creating the shortest ones.
2063 #  @param V1,V2,V3,V4 Corner vertices for the face.
2064 #  @return New GEOM_Object, containing the created face.
2065 #
2066 #  Example: see GEOM_Spanner.py
2067 def MakeQuad4Vertices(V1, V2, V3, V4):
2068     anObj = BlocksOp.MakeQuad4Vertices(V1, V2, V3, V4)
2069     if BlocksOp.IsDone() == 0:
2070       print "MakeQuad4Vertices : ", BlocksOp.GetErrorCode()
2071     return anObj
2072
2073 ## Create a hexahedral solid, bounded by the six given faces. Order of
2074 #  faces is not important. It is  not necessary that Faces share the same edge.
2075 #  @param F1,F2,F3,F4,F5,F6 Faces for the hexahedral solid.
2076 #  @return New GEOM_Object, containing the created solid.
2077 #
2078 #  Example: see GEOM_Spanner.py
2079 def MakeHexa(F1, F2, F3, F4, F5, F6):
2080     anObj = BlocksOp.MakeHexa(F1, F2, F3, F4, F5, F6)
2081     if BlocksOp.IsDone() == 0:
2082       print "MakeHexa : ", BlocksOp.GetErrorCode()
2083     return anObj
2084
2085 ## Create a hexahedral solid between two given faces.
2086 #  The missing faces will be built by creating the smallest ones.
2087 #  @param F1,F2 Two opposite faces for the hexahedral solid.
2088 #  @return New GEOM_Object, containing the created solid.
2089 #
2090 #  Example: see GEOM_Spanner.py
2091 def MakeHexa2Faces(F1, F2):
2092     anObj = BlocksOp.MakeHexa2Faces(F1, F2)
2093     if BlocksOp.IsDone() == 0:
2094       print "MakeHexa2Faces : ", BlocksOp.GetErrorCode()
2095     return anObj
2096
2097 ## Get a vertex, found in the given shape by its coordinates.
2098 #  @param theShape Block or a compound of blocks.
2099 #  @param theX,theY,theZ Coordinates of the sought vertex.
2100 #  @param theEpsilon Maximum allowed distance between the resulting
2101 #                    vertex and point with the given coordinates.
2102 #  @return New GEOM_Object, containing the found vertex.
2103 #
2104 #  Example: see GEOM_TestOthers.py
2105 def GetPoint(theShape, theX, theY, theZ, theEpsilon):
2106     anObj = BlocksOp.GetPoint(theShape, theX, theY, theZ, theEpsilon)
2107     if BlocksOp.IsDone() == 0:
2108       print "GetPoint : ", BlocksOp.GetErrorCode()
2109     return anObj
2110
2111 ## Get an edge, found in the given shape by two given vertices.
2112 #  @param theShape Block or a compound of blocks.
2113 #  @param thePoint1,thePoint2 Points, close to the ends of the desired edge.
2114 #  @return New GEOM_Object, containing the found edge.
2115 #
2116 #  Example: see GEOM_Spanner.py
2117 def GetEdge(theShape, thePoint1, thePoint2):
2118     anObj = BlocksOp.GetEdge(theShape, thePoint1, thePoint2)
2119     if BlocksOp.IsDone() == 0:
2120       print "GetEdge : ", BlocksOp.GetErrorCode()
2121     return anObj
2122
2123 ## Find an edge of the given shape, which has minimal distance to the given point.
2124 #  @param theShape Block or a compound of blocks.
2125 #  @param thePoint Point, close to the desired edge.
2126 #  @return New GEOM_Object, containing the found edge.
2127 #
2128 #  Example: see GEOM_TestOthers.py
2129 def GetEdgeNearPoint(theShape, thePoint):
2130     anObj = BlocksOp.GetEdgeNearPoint(theShape, thePoint)
2131     if BlocksOp.IsDone() == 0:
2132       print "GetEdgeNearPoint : ", BlocksOp.GetErrorCode()
2133     return anObj
2134
2135 ## Returns a face, found in the given shape by four given corner vertices.
2136 #  @param theShape Block or a compound of blocks.
2137 #  @param thePoint1-thePoint4 Points, close to the corners of the desired face.
2138 #  @return New GEOM_Object, containing the found face.
2139 #
2140 #  Example: see GEOM_Spanner.py
2141 def GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4):
2142     anObj = BlocksOp.GetFaceByPoints(theShape, thePoint1, thePoint2, thePoint3, thePoint4)
2143     if BlocksOp.IsDone() == 0:
2144       print "GetFaceByPoints : ", BlocksOp.GetErrorCode()
2145     return anObj
2146
2147 ## Get a face of block, found in the given shape by two given edges.
2148 #  @param theShape Block or a compound of blocks.
2149 #  @param theEdge1,theEdge2 Edges, close to the edges of the desired face.
2150 #  @return New GEOM_Object, containing the found face.
2151 #
2152 #  Example: see GEOM_Spanner.py
2153 def GetFaceByEdges(theShape, theEdge1, theEdge2):
2154     anObj = BlocksOp.GetFaceByEdges(theShape, theEdge1, theEdge2)
2155     if BlocksOp.IsDone() == 0:
2156       print "GetFaceByEdges : ", BlocksOp.GetErrorCode()
2157     return anObj
2158
2159 ## Find a face, opposite to the given one in the given block.
2160 #  @param theBlock Must be a hexahedral solid.
2161 #  @param theFace Face of \a theBlock, opposite to the desired face.
2162 #  @return New GEOM_Object, containing the found face.
2163 #
2164 #  Example: see GEOM_Spanner.py
2165 def GetOppositeFace(theBlock, theFace):
2166     anObj = BlocksOp.GetOppositeFace(theBlock, theFace)
2167     if BlocksOp.IsDone() == 0:
2168       print "GetOppositeFace : ", BlocksOp.GetErrorCode()
2169     return anObj
2170
2171 ## Find a face of the given shape, which has minimal distance to the given point.
2172 #  @param theShape Block or a compound of blocks.
2173 #  @param thePoint Point, close to the desired face.
2174 #  @return New GEOM_Object, containing the found face.
2175 #
2176 #  Example: see GEOM_Spanner.py
2177 def GetFaceNearPoint(theShape, thePoint):
2178     anObj = BlocksOp.GetFaceNearPoint(theShape, thePoint)
2179     if BlocksOp.IsDone() == 0:
2180       print "GetFaceNearPoint : ", BlocksOp.GetErrorCode()
2181     return anObj
2182
2183 ## Find a face of block, whose outside normale has minimal angle with the given vector.
2184 #  @param theShape Block or a compound of blocks.
2185 #  @param theVector Vector, close to the normale of the desired face.
2186 #  @return New GEOM_Object, containing the found face.
2187 #
2188 #  Example: see GEOM_Spanner.py
2189 def GetFaceByNormale(theBlock, theVector):
2190     anObj = BlocksOp.GetFaceByNormale(theBlock, theVector)
2191     if BlocksOp.IsDone() == 0:
2192       print "GetFaceByNormale : ", BlocksOp.GetErrorCode()
2193     return anObj
2194
2195 ## Check, if the compound of blocks is given.
2196 #  To be considered as a compound of blocks, the
2197 #  given shape must satisfy the following conditions:
2198 #  - Each element of the compound should be a Block (6 faces and 12 edges).
2199 #  - A connection between two Blocks should be an entire quadrangle face or an entire edge.
2200 #  - The compound should be connexe.
2201 #  - The glue between two quadrangle faces should be applied.
2202 #  @param theCompound The compound to check.
2203 #  @return TRUE, if the given shape is a compound of blocks.
2204 #  If theCompound is not valid, prints all discovered errors.
2205 #
2206 #  Example: see GEOM_Spanner.py
2207 def CheckCompoundOfBlocks(theCompound):
2208     (IsValid, BCErrors) = BlocksOp.CheckCompoundOfBlocks(theCompound)
2209     if BlocksOp.IsDone() == 0:
2210       print "CheckCompoundOfBlocks : ", BlocksOp.GetErrorCode()
2211     else:
2212       if IsValid == 0:
2213         Descr = BlocksOp.PrintBCErrors(theCompound, BCErrors)
2214         print Descr
2215     return IsValid
2216
2217 ## Remove all seam and degenerated edges from \a theShape.
2218 #  Unite faces and edges, sharing one surface. It means that
2219 #  this faces must have references to one C++ surface object (handle).
2220 #  @param theShape The compound or single solid to remove irregular edges from.
2221 #  @return Improved shape.
2222 #
2223 #  Example: see GEOM_TestOthers.py
2224 def RemoveExtraEdges(theShape):
2225     anObj = BlocksOp.RemoveExtraEdges(theShape)
2226     if BlocksOp.IsDone() == 0:
2227       print "RemoveExtraEdges : ", BlocksOp.GetErrorCode()
2228     return anObj
2229
2230 ## Check, if the given shape is a blocks compound.
2231 #  Fix all detected errors.
2232 #    \note Single block can be also fixed by this method.
2233 #  @param theCompound The compound to check and improve.
2234 #  @return Improved compound.
2235 #
2236 #  Example: see GEOM_TestOthers.py
2237 def CheckAndImprove(theShape):
2238     anObj = BlocksOp.CheckAndImprove(theShape)
2239     if BlocksOp.IsDone() == 0:
2240       print "CheckAndImprove : ", BlocksOp.GetErrorCode()
2241     return anObj
2242
2243 ## Get all the blocks, contained in the given compound.
2244 #  @param theCompound The compound to explode.
2245 #  @param theMinNbFaces If solid has lower number of faces, it is not a block.
2246 #  @param theMaxNbFaces If solid has higher number of faces, it is not a block.
2247 #    \note If theMaxNbFaces = 0, the maximum number of faces is not restricted.
2248 #  @return List of GEOM_Objects, containing the retrieved blocks.
2249 #
2250 #  Example: see GEOM_TestOthers.py
2251 def MakeBlockExplode(theCompound, theMinNbFaces, theMaxNbFaces):
2252     aList = BlocksOp.ExplodeCompoundOfBlocks(theCompound, theMinNbFaces, theMaxNbFaces)
2253     if BlocksOp.IsDone() == 0:
2254       print "MakeBlockExplode : ", BlocksOp.GetErrorCode()
2255     return aList
2256
2257 ## Find block, containing the given point inside its volume or on boundary.
2258 #  @param theCompound Compound, to find block in.
2259 #  @param thePoint Point, close to the desired block. If the point lays on
2260 #         boundary between some blocks, we return block with nearest center.
2261 #  @return New GEOM_Object, containing the found block.
2262 #
2263 #  Example: see GEOM_Spanner.py
2264 def GetBlockNearPoint(theCompound, thePoint):
2265     anObj = BlocksOp.GetBlockNearPoint(theCompound, thePoint)
2266     if BlocksOp.IsDone() == 0:
2267       print "GetBlockNearPoint : ", BlocksOp.GetErrorCode()
2268     return anObj
2269
2270 ## Find block, containing all the elements, passed as the parts, or maximum quantity of them.
2271 #  @param theCompound Compound, to find block in.
2272 #  @param theParts List of faces and/or edges and/or vertices to be parts of the found block.
2273 #  @return New GEOM_Object, containing the found block.
2274 #
2275 #  Example: see GEOM_TestOthers.py
2276 def GetBlockByParts(theCompound, theParts):
2277     anObj = BlocksOp.GetBlockByParts(theCompound, theParts)
2278     if BlocksOp.IsDone() == 0:
2279       print "GetBlockByParts : ", BlocksOp.GetErrorCode()
2280     return anObj
2281
2282 ## Return all blocks, containing all the elements, passed as the parts.
2283 #  @param theCompound Compound, to find blocks in.
2284 #  @param theParts List of faces and/or edges and/or vertices to be parts of the found blocks.
2285 #  @return List of GEOM_Objects, containing the found blocks.
2286 #
2287 #  Example: see GEOM_Spanner.py
2288 def GetBlocksByParts(theCompound, theParts):
2289     aList = BlocksOp.GetBlocksByParts(theCompound, theParts)
2290     if BlocksOp.IsDone() == 0:
2291       print "GetBlocksByParts : ", BlocksOp.GetErrorCode()
2292     return aList
2293
2294 ## Multi-transformate block and glue the result.
2295 #  Transformation is defined so, as to superpose direction faces.
2296 #  @param Block Hexahedral solid to be multi-transformed.
2297 #  @param DirFace1 ID of First direction face.
2298 #  @param DirFace2 ID of Second direction face.
2299 #  @param NbTimes Quantity of transformations to be done.
2300 #    \note Unique ID of sub-shape can be obtained, using method GetSubShapeID().
2301 #  @return New GEOM_Object, containing the result shape.
2302 #
2303 #  Example: see GEOM_Spanner.py
2304 def MakeMultiTransformation1D(Block, DirFace1, DirFace2, NbTimes):
2305     anObj = BlocksOp.MakeMultiTransformation1D(Block, DirFace1, DirFace2, NbTimes)
2306     if BlocksOp.IsDone() == 0:
2307       print "MakeMultiTransformation1D : ", BlocksOp.GetErrorCode()
2308     return anObj
2309
2310 ## Multi-transformate block and glue the result.
2311 #  @param Block Hexahedral solid to be multi-transformed.
2312 #  @param DirFace1U,DirFace2U IDs of Direction faces for the first transformation.
2313 #  @param DirFace1V,DirFace2V IDs of Direction faces for the second transformation.
2314 #  @param NbTimesU,NbTimesV Quantity of transformations to be done.
2315 #  @return New GEOM_Object, containing the result shape.
2316 #
2317 #  Example: see GEOM_Spanner.py
2318 def MakeMultiTransformation2D(Block, DirFace1U, DirFace2U, NbTimesU,
2319                                      DirFace1V, DirFace2V, NbTimesV):
2320     anObj = BlocksOp.MakeMultiTransformation2D(Block, DirFace1U, DirFace2U, NbTimesU,
2321                                                       DirFace1V, DirFace2V, NbTimesV)
2322     if BlocksOp.IsDone() == 0:
2323       print "MakeMultiTransformation2D : ", BlocksOp.GetErrorCode()
2324     return anObj
2325
2326 ## Build all possible propagation groups.
2327 #  Propagation group is a set of all edges, opposite to one (main)
2328 #  edge of this group directly or through other opposite edges.
2329 #  Notion of Opposite Edge make sence only on quadrangle face.
2330 #  @param theShape Shape to build propagation groups on.
2331 #  @return List of GEOM_Objects, each of them is a propagation group.
2332 #
2333 #  Example: see GEOM_TestOthers.py
2334 def Propagate(theShape):
2335     listChains = BlocksOp.Propagate(theShape)
2336     if BlocksOp.IsDone() == 0:
2337       print "Propagate : ", BlocksOp.GetErrorCode()
2338     return listChains
2339
2340 # -----------------------------------------------------------------------------
2341 # Group operations
2342 # -----------------------------------------------------------------------------
2343
2344 ## Creates a new group which will store sub shapes of theMainShape
2345 #  @param theMainShape is a GEOM object on which the group is selected
2346 #  @param theShapeType defines a shape type of the group
2347 #  @return a newly created GEOM group
2348 #
2349 #  Example: see GEOM_TestOthers.py
2350 def CreateGroup(theMainShape, theShapeType):
2351     anObj = GroupOp.CreateGroup(theMainShape, theShapeType)
2352     if GroupOp.IsDone() == 0:
2353        print "CreateGroup : ", GroupOp.GetErrorCode()
2354     return anObj
2355
2356 ## Adds a sub object with ID theSubShapeId to the group
2357 #  @param theGroup is a GEOM group to which the new sub shape is added
2358 #  @param theSubShapeID is a sub shape ID in the main object.
2359 #  \note Use method GetSubShapeID() to get an unique ID of the sub shape
2360 #
2361 #  Example: see GEOM_TestOthers.py
2362 def AddObject(theGroup, theSubShapeID):
2363     GroupOp.AddObject(theGroup, theSubShapeID)
2364     if GroupOp.IsDone() == 0:
2365       print "AddObject : ", GroupOp.GetErrorCode()
2366
2367 ## Removes a sub object with ID \a theSubShapeId from the group
2368 #  @param theGroup is a GEOM group from which the new sub shape is removed
2369 #  @param theSubShapeID is a sub shape ID in the main object.
2370 #  \note Use method GetSubShapeID() to get an unique ID of the sub shape
2371 #
2372 #  Example: see GEOM_TestOthers.py
2373 def RemoveObject(theGroup, theSubShapeID):
2374     GroupOp.RemoveObject(theGroup, theSubShapeID)
2375     if GroupOp.IsDone() == 0:
2376       print "RemoveObject : ", GroupOp.GetErrorCode()
2377
2378 ## Adds to the group all the given shapes. No errors, if some shapes are alredy included.
2379 #  @param theGroup is a GEOM group to which the new sub shapes are added.
2380 #  @param theSubShapes is a list of sub shapes to be added.
2381 #
2382 #  Example: see GEOM_TestOthers.py
2383 def UnionList (theGroup, theSubShapes):
2384     GroupOp.UnionList(theGroup, theSubShapes)
2385     if GroupOp.IsDone() == 0:
2386       print "UnionList : ", GroupOp.GetErrorCode()
2387
2388 ## Works like the above method, but argument
2389 #  theSubShapes here is a list of sub-shapes indices
2390 #
2391 #  Example: see GEOM_TestOthers.py
2392 def UnionIDs(theGroup, theSubShapes):
2393     GroupOp.UnionIDs(theGroup, theSubShapes)
2394     if GroupOp.IsDone() == 0:
2395         print "UnionIDs : ", GroupOp.GetErrorCode()
2396
2397 ## Removes from the group all the given shapes. No errors, if some shapes are not included.
2398 #  @param theGroup is a GEOM group from which the sub-shapes are removed.
2399 #  @param theSubShapes is a list of sub-shapes to be removed.
2400 #
2401 #  Example: see GEOM_TestOthers.py
2402 def DifferenceList (theGroup, theSubShapes):
2403     GroupOp.DifferenceList(theGroup, theSubShapes)
2404     if GroupOp.IsDone() == 0:
2405       print "DifferenceList : ", GroupOp.GetErrorCode()
2406
2407 ## Works like the above method, but argument
2408 #  theSubShapes here is a list of sub-shapes indices
2409 #
2410 #  Example: see GEOM_TestOthers.py
2411 def DifferenceIDs(theGroup, theSubShapes):
2412     GroupOp.DifferenceIDs(theGroup, theSubShapes)
2413     if GroupOp.IsDone() == 0:
2414         print "DifferenceIDs : ", GroupOp.GetErrorCode()
2415
2416 ## Returns a list of sub objects ID stored in the group
2417 #  @param theGroup is a GEOM group for which a list of IDs is requested
2418 #
2419 #  Example: see GEOM_TestOthers.py
2420 def GetObjectIDs(theGroup):
2421     ListIDs = GroupOp.GetObjects(theGroup)
2422     if GroupOp.IsDone() == 0:
2423       print "GetObjectIDs : ", GroupOp.GetErrorCode()
2424     return ListIDs
2425
2426 ## Returns a type of sub objects stored in the group
2427 #  @param theGroup is a GEOM group which type is returned.
2428 #
2429 #  Example: see GEOM_TestOthers.py
2430 def GetType(theGroup):
2431     aType = GroupOp.GetType(theGroup)
2432     if GroupOp.IsDone() == 0:
2433       print "GetType : ", GroupOp.GetErrorCode()
2434     return aType
2435
2436 ## Returns a main shape associated with the group
2437 #  @param theGroup is a GEOM group for which a main shape object is requested
2438 #  @return a GEOM object which is a main shape for theGroup
2439 #
2440 #  Example: see GEOM_TestOthers.py
2441 def GetMainShape(theGroup):
2442     anObj = GroupOp.GetMainShape(theGroup)
2443     if GroupOp.IsDone() == 0:
2444       print "GetMainShape : ", GroupOp.GetErrorCode()
2445     return anObj
2446
2447 ## Create group of edges of theShape, whose length is in range [min_length, max_length].
2448 #  If include_min/max == 0, edges with length == min/max_length will not be included in result.
2449 def GetEdgesByLength (theShape, min_length, max_length, include_min = 1, include_max = 1):
2450     edges = SubShapeAll(theShape, ShapeType["EDGE"])
2451     edges_in_range = []
2452     for edge in edges:
2453         Props = BasicProperties(edge)
2454         if min_length <= Props[0] and Props[0] <= max_length:
2455             if (not include_min) and (min_length == Props[0]):
2456                 skip = 1
2457             else:
2458                 if (not include_max) and (Props[0] == max_length):
2459                     skip = 1
2460                 else:
2461                     edges_in_range.append(edge)
2462
2463     if len(edges_in_range) <= 0:
2464         print "No edges found by given criteria"
2465         return 0
2466
2467     group_edges = CreateGroup(theShape, ShapeType["EDGE"])
2468     UnionList(group_edges, edges_in_range)
2469
2470     return group_edges
2471
2472 ## Create group of edges of selected shape, whose length is in range [min_length, max_length].
2473 #  If include_min/max == 0, edges with length == min/max_length will not be included in result.
2474 def SelectEdges (min_length, max_length, include_min = 1, include_max = 1):
2475     nb_selected = sg.SelectedCount()
2476     if nb_selected < 1:
2477         print "Select a shape before calling this function, please."
2478         return 0
2479     if nb_selected > 1:
2480         print "Only one shape must be selected"
2481         return 0
2482
2483     id_shape = sg.getSelected(0)
2484     shape = IDToObject( id_shape )
2485
2486     group_edges = GetEdgesByLength(shape, min_length, max_length, include_min, include_max)
2487
2488     left_str  = " < "
2489     right_str = " < "
2490     if include_min: left_str  = " <= "
2491     if include_max: right_str  = " <= "
2492
2493     addToStudyInFather(shape, group_edges, "Group of edges with " + `min_length`
2494                        + left_str + "length" + right_str + `max_length`)
2495
2496     sg.updateObjBrowser(1)
2497
2498     return group_edges
2499
2500 ## Add Path to load python scripts from
2501 def addPath(Path):
2502     if (sys.path.count(Path) < 1):
2503         sys.path.append(Path)