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