Salome HOME
a1aa7b887f20e4758955a2bed6ee96b4f2a0ede2
[modules/geom.git] / src / GEOM_SWIG / gsketcher.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 #  File   : gsketcher.py
21 #  Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
22 #  Module : GEOM_SWIG
23
24 ## @defgroup sketcher gsketcher - Wrapper to help the creation of simple sketches
25 #  @{ 
26 #  @details
27 #  This module provides the user with a simple python API 
28 #  to realize various sketches from the GEOM text user interface.
29 #  @n Example:
30 #  @code
31 #  import GEOM
32 #  from salome.geom import geomBuilder
33 #  geompy = geomBuilder.New()
34 #
35 #  # create a wire for sketcher
36 #  geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
37 #
38 #  # Create the sketch
39 #  sk = geompy.Sketcher2D()
40 #  sk.addPoint(0.000000, 0.000000)
41 #  sk.addSegmentAbsolute(50.000000, 50.000000)
42 #  sk.addSegmentPerpY(0.000000)
43 #  sk.addArcAbsolute(0.000000, 0.000000)
44 #  sk.close()
45 #  Sketch_1 = sk.wire(geomObj_1)
46 #
47 #  # add objects in the study
48 #  geompy.addToStudy( Sketch_1, 'Sketch_1' )
49 #
50 #  # update object browser
51 #  salome.sg.updateObjBrowser()
52 #  @endcode
53 #  @n Additional examples can be found as unit tests in the source code.
54 #  @}
55
56 """
57     \namespace geompy
58     \brief 2D and 3D Sketcher interfaces
59 """
60
61 # This method is used by 3D Sketcher functionality
62 def printVar (var):
63     if isinstance(var, str):
64         return "\'%s\'"%var
65     else:
66         return "%.7f"%var
67
68 ## An interface to build a 3D Sketcher step-by-step.
69 #  Use geompy.Sketcher3D() method to obtain an instance of this class.
70 #
71 #  @ref tui_3dsketcher_page "Example"
72 #  @ingroup sketcher
73 class Sketcher3D:
74     """
75     3D sketcher interface.
76
77     Example of usage:
78         sk = geompy.Sketcher3D()
79         sk.addPointsAbsolute(0,0,0, 70,0,0)
80         sk.addPointsRelative(0, 0, 130)
81         sk.addPointRadiusAnglesRelative(50, 0, 100, 'OXY')
82         sk.addPointRadiusAnglesRelative(30, 80, 130, 'OXZ')
83         sk.close()
84         a3D_Sketcher_1 = sk.wire()
85     """
86
87     def __init__(self, geompyD):
88         self.geompyD = geompyD
89         self.myCommand = "3DSketcher"
90         pass
91
92     ## Add one or more points, sequentially connected with straight segments.
93     #  Coordinates are considered as absolute.
94     #  If the first point of sketcher is not yet defined, the first point
95     #  from the listCoords will become the first sketcher point.
96     #  @param listCoords X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
97     def addPointsAbsolute (self, *listCoords):
98         """
99         Add one or more points, sequentially connected with straight segments.
100         Coordinates are considered as absolute.
101         If the first point of sketcher is not yet defined, the first point
102         from the listCoords will become the first sketcher point.
103
104         Parameters:
105             X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
106
107         Example of usage:
108             sk = geompy.Sketcher3D()
109             sk.addPointsAbsolute(0,0,0, 70,0,0)
110             a3D_Sketcher_1 = sk.wire()
111         """
112         ii = 1
113         for cc in listCoords:
114             if ii == 1:
115                 self.myCommand = self.myCommand + ":TT"
116             self.myCommand = self.myCommand + " %s"%printVar(cc)
117             if ii == 3:
118                 ii = 1
119             else:
120                 ii = ii + 1
121         pass
122
123     ## Add one or more points, sequentially connected with straight segments.
124     #  Coordinates are considered relative to the previous point.
125     #  If the first point of sketcher is not yet defined, the
126     #  origin (0, 0, 0) will become the first sketcher point.
127     #  @param listCoords X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
128     def addPointsRelative (self, *listCoords):
129         """
130         Add one or more points, sequentially connected with straight segments.
131         Coordinates are considered relative to the previous point.
132         If the first point of sketcher is not yet defined, the
133         origin (0, 0, 0) will become the first sketcher point.
134
135         Parameters:
136             X1, Y1, Z1, X2, Y2, Z2, ... Relative coordinates of points
137
138         Example of usage:
139             sk = geompy.Sketcher3D()
140             sk.addPointsRelative(0,0,130, 70,0,-130)
141             a3D_Sketcher_1 = sk.wire()
142         """
143         ii = 1
144         for cc in listCoords:
145             if ii == 1:
146                 self.myCommand = self.myCommand + ":T"
147             self.myCommand = self.myCommand + " %s"%printVar(cc)
148             if ii == 3:
149                 ii = 1
150             else:
151                 ii = ii + 1
152         pass
153
154     ## Add one straight segment, defined by two angles and length.
155     #  If the first point of sketcher is not yet defined, the
156     #  origin (0, 0, 0) will become the first sketcher point.
157     #  The radius and angles coordinates are defined 
158     #  in a local coordinate system which origin is the last point of the sketch
159     #
160     #  @param length length of the segment
161     #  @param angle1 angle in a plane, defined by the \a axes
162     #  @param angle2 angle from the plane, defined by the \a axes
163     #  @param axes can be: "OXY", "OYZ" or "OXZ"
164     def addPointRadiusAnglesRelative (self, length, angle1, angle2, axes="OXY"):
165         """
166         Add one straight segment, defined by two angles and length.
167         If the first point of sketcher is not yet defined, the
168         origin (0, 0, 0) will become the first sketcher point.
169
170         Parameters:
171             length length of the segment
172             angle1 angle in a plane, defined by the \a axes
173             angle2 angle from the plane, defined by the \a axes
174             axes can be: "OXY", "OYZ" or "OXZ"
175
176         Example of usage:
177             sk = geompy.Sketcher3D()
178             sk.addPointRadiusAnglesRelative(100, 50, 0, "OXY")
179             a3D_Sketcher_1 = sk.wire()
180         """
181         self.myCommand = self.myCommand + ":%s"%axes+"SR"+" %s %s %s" % (printVar(angle1), printVar(angle2), printVar(length))
182         pass
183     
184     ## Add one straight segment, defined by two angles and radius.
185     #  If the first point of sketcher is not yet defined, the
186     #  origin (0, 0, 0) will become the first sketcher point.
187     #  The radius and angles coordinates are defined 
188     #  in a coordinate system which origin is the global coordinate system origin
189     #  
190     #  @param radius distance to the coordinate system origin
191     #  @param angle1 angle in a plane, defined by the \a axes
192     #  @param angle2 angle from the plane, defined by the \a axes
193     #  @param axes can be: "OXY", "OYZ" or "OXZ"
194     def addPointRadiusAnglesAbsolute (self, radius, angle1, angle2, axes="OXY"):
195         """
196         Add one straight segment, defined by two angles and length.
197         If the first point of sketcher is not yet defined, the
198         origin (0, 0, 0) will become the first sketcher point.
199
200         Parameters:
201             radius distance to the coordinate system origin
202             angle1 angle in a plane, defined by the \a axes
203             angle2 angle from the plane, defined by the \a axes
204             axes can be: "OXY", "OYZ" or "OXZ"
205
206         Example of usage:
207             sk = geompy.Sketcher3D()
208             sk.addPointRadiusAnglesAbsolute(100, 50, 0, "OXY")
209             a3D_Sketcher_1 = sk.wire()
210         """
211         self.myCommand = self.myCommand + ":%s"%axes+"SA"+" %s %s %s" % (printVar(angle1), printVar(angle2), printVar(radius))
212         pass
213     
214     ## Add one straight segment, defined by an angle, a height and a radius.
215     #  If the first point of sketcher is not yet defined, the
216     #  origin (0, 0, 0) will become the first sketcher point.
217     #  The radius height and angle coordinates are defined 
218     #  in a local coordinate system which origin is the last point of the sketch
219     #  
220     #  @param axes can be: "OXY", "OYZ" or "OXZ"
221     #  @param angle angle in a plane, defined by the \a axes
222     #  @param height height from the plane, defined by the \a axes
223     #  @param length distance to the coordinate system origin
224     def addPointRadiusAngleHRelative (self, length, angle, height, axes="OXY"):
225         """
226         Add one straight segment, defined by two angles and length.
227         If the first point of sketcher is not yet defined, the
228         origin (0, 0, 0) will become the first sketcher point.
229
230         Parameters:
231             radius distance to the coordinate system origin
232             angle  angle in a plane, defined by the \a axes
233             height height from the plane, defined by the \a axes
234             axes can be: "OXY", "OYZ" or "OXZ"
235
236         Example of usage:
237             sk = geompy.Sketcher3D()
238             sk.addPointRadiusAngleHRelative(100, 50, 40, "OXY")
239             a3D_Sketcher_1 = sk.wire()
240         """
241         self.myCommand = self.myCommand + ":%s"%axes+"CR"+" %s %s %s" % (printVar(angle), printVar(height), printVar(length))
242         pass
243     
244     ## Add one straight segment, defined by an angle, a height and a radius.
245     #  If the first point of sketcher is not yet defined, the
246     #  origin (0, 0, 0) will become the first sketcher point.
247     #  The radius height and angle coordinates are defined 
248     #  in a coordinate system which origin is the global coordinate system origin
249     # 
250     #  @param radius distance to the coordinate system origin
251     #  @param angle angle in a plane, defined by the \a axes
252     #  @param height height from the plane, defined by the \a axes
253     #  @param axes can be: "OXY", "OYZ" or "OXZ"
254     def addPointRadiusAngleHAbsolute (self, radius, angle, height, axes="OXY"):
255         """
256         Add one straight segment, defined by two angles and length.
257         If the first point of sketcher is not yet defined, the
258         origin (0, 0, 0) will become the first sketcher point.
259
260         Parameters:
261             axes can be: "OXY", "OYZ" or "OXZ"
262             angle1 angle in a plane, defined by the \a axes
263             height height from the plane, defined by the \a axes
264             radius distance to the coordinate system origin
265
266         Example of usage:
267             sk = geompy.Sketcher3D()
268             sk.addPointRadiusAngleHAbsolute( 100, 50, 40, "OXY")
269             a3D_Sketcher_1 = sk.wire()
270         """
271         self.myCommand = self.myCommand + ":%s"%axes+"CA"+" %s %s %s" % (printVar(angle), printVar(height), printVar(radius))
272         pass
273
274     ## Set to close the wire
275     def close (self):
276         """
277         Set to close the wire
278
279         Example of usage:
280             sk = geompy.Sketcher3D()
281             sk.addPointsRelative(0,0,130, 70,0,-130)
282             sk.close()
283             a3D_Sketcher_1 = sk.wire()
284         """
285         self.myCommand = self.myCommand + ":WW"
286         pass
287
288     ## Obtain the sketcher result.
289     #  @param theName Object name; when specified, this parameter is used
290     #         for result publication in the study. Otherwise, if automatic
291     #         publication is switched on, default value is used for result name.
292     #
293     #  @return New GEOM_Object, containing the created wire
294     def wire (self, theName=None):
295         """
296         Obtain the sketcher result.
297
298         Parameters:
299             theName Object name; when specified, this parameter is used
300                     for result publication in the study. Otherwise, if automatic
301                     publication is switched on, default value is used for result name.
302
303         Returns:
304             New GEOM_Object, containing the created wire.
305
306         Example of usage:
307             sk = geompy.Sketcher3D()
308             sk.addPointsRelative(0,0,130, 70,0,-130)
309             a3D_Sketcher_1 = sk.wire()
310         """
311         from salome.geom.geomBuilder import ParseSketcherCommand, RaiseIfFailed
312         Command,Parameters = ParseSketcherCommand(self.myCommand)
313         wire = self.geompyD.CurvesOp.Make3DSketcherCommand(Command)
314         self.myCommand = "3DSketcher"
315         RaiseIfFailed("Sketcher3D", self.geompyD.CurvesOp)
316         wire.SetParameters(Parameters)
317         self.geompyD._autoPublish(wire, theName, "wire")
318         return wire
319
320 ##  An interface to build a 2D Sketcher step-by-step.
321 #  Use geompy.Sketcher2D() method to obtain an instance of this class.
322 #  @ingroup sketcher  
323 class Sketcher2D:
324     """
325     2D sketcher interface.
326
327     Example of usage:
328         sk = geompy.Sketcher2D()
329         sk.addPoint(20, 20)
330         sk.addSegmentRelative(15, 70)
331         sk.addSegmentPerpY(50)
332         sk.addArcRadiusRelative(25, 15, 14.5, 0)
333         sk.addArcCenterAbsolute(1, 1, 50, 50, 0, 0)
334         sk.addArcDirectionRadiusLength(20, 20, 101, 162.13)
335         sk.close()
336         Sketch_1 = sk.wire(geomObj_1)
337     """
338     def __init__(self, geompyD):
339         self.geompyD = geompyD
340         self.myCommand = "Sketcher"
341         self.closed = False
342         pass
343     
344     ## Add one point.
345     #  Used to set the starting point
346     #
347     #  @param x, y - Coordinates of point
348     def addPoint (self, x, y): 
349         """
350         Add one point.
351         Used to set the starting point
352
353         Parameters:
354             x, y - Coordinates of point
355
356         Example of usage:
357             sk = geompy.Sketcher2D()
358             sk.addPoint(20, 20)
359             Sketcher_1 = sk.wire(geomObj_1)
360         """
361         self.myCommand = self.myCommand + ":F %s %s" % (printVar(x), printVar(y))
362         pass
363     
364     ## Add angle.
365     #  Used to set the angle for further building
366     #
367     #  @param angle - angle in a plane
368     def addAngle (self, angle): 
369         """
370         Add angle.
371         Used to set the angle for further building
372
373         Parameters:
374             angle - angle in a plane
375
376         Example of usage:
377             sk = geompy.Sketcher2D()
378             sk.addAngle(70)
379             Sketcher_1 = sk.wire(geomObj_1)
380         """
381         self.myCommand = self.myCommand + ":RR %s" % (printVar(angle))
382         pass
383
384     #  Commands for creation of segment
385     
386     ## Add segment, which sequentially connects the previous point
387     #  with a point lying on a line parallel to the axis Ox and the value x = param x.
388     #  The current point will be the previous value to the coordinate y and 
389     #  new value to the coordinate x.
390     #  Coordinate is considered relative to the previous point.
391     #
392     #  @param x - Coordinate of point on axis Ox 
393     def addSegmentParalX(self, x):
394         """
395         Add segment, which sequentially connects the previous point
396         with a point lying on a line parallel to the axis Ox and the value x = param x.
397         The current point will be the previous value to the coordinate y and 
398         new value to the coordinate x.
399         Coordinate is considered relative to the previous point.
400
401         Parameters:
402             x - Coordinate of point on axis Ox 
403
404         Example of usage:
405             sk = geompy.Sketcher2D()
406             sk.addSegmentParalX(40)
407             Sketcher_1 = sk.wire(geomObj_1)
408         """
409         self.myCommand = self.myCommand + ":X %s" % (printVar(x))
410         pass
411     
412     ## Add segment, which sequentially connects the previous point
413     #  with a point lying on a line parallel to the axis Ox and the value x = 0
414     #  The current point will be the previous value to the coordinate y.
415     def addSegmentParalXToZero(self):
416         """
417         Add segment, which sequentially connects the previous point
418         with a point lying on a line parallel to the axis Ox and the value x = 0
419         The current point will be the previous value to the coordinate y.
420
421         Example of usage:
422             sk = geompy.Sketcher2D()
423             sk.addSegmentParalXToZero()
424             Sketcher_1 = sk.wire(geomObj_1)
425         """
426         self.myCommand = self.myCommand + ":XX"
427         pass    
428     
429     ## Add segment, which sequentially connects the previous point
430     #  with a point lying on a line parallel to the axis Oy and the value y = param y.
431     #  The current point will be the previous value to the coordinate x and 
432     #  new value to the coordinate y.
433     #  Coordinate is considered relative to the previous point.
434     #
435     #  @param y - Coordinate of point on axis Oy 
436     def addSegmentParalY(self, y):
437         """
438         Add segment, which sequentially connects the previous point
439         with a point lying on a line parallel to the axis Oy and the value y = param y.
440         The current point will be the previous value to the coordinate x and 
441         new value to the coordinate y.
442         Coordinate is considered relative to the previous point.
443
444         Parameters:
445             y - Coordinate of point on axis Oy 
446
447         Example of usage:
448             sk = geompy.Sketcher2D()
449             sk.addSegmentParalY(80)
450             Sketcher_1 = sk.wire(geomObj_1)
451         """
452         self.myCommand = self.myCommand + ":Y %s" % (printVar(y))
453         pass
454     
455     ## Add segment, which sequentially connects the previous point
456     #  with a point lying on a line parallel to the axis Ox and the value x = 0
457     #  The current point will be the previous value to the coordinate y.
458     def addSegmentParalYToZero(self):
459         """
460         Add segment, which sequentially connects the previous point
461         with a point lying on a line parallel to the axis Oy and the value y = 0
462         The current point will be the previous value to the coordinate x.
463
464         Example of usage:
465             sk = geompy.Sketcher2D()
466             sk.addSegmentParalYToZero()
467             Sketcher_1 = sk.wire(geomObj_1)
468         """
469         self.myCommand = self.myCommand + ":YY"
470         pass 
471            
472     ## Add segment, which sequentially connects the given point with previous point
473     #
474     #  Coordinates are considered as absolute.
475     #  @param x, y - Coordinates of point
476     def addSegmentAbsolute (self, x, y):
477         """
478         Add segment, which sequentially connects the starting point with the given point
479         Coordinates are considered as absolute.
480
481         Parameters:
482             x, y - Coordinates of point
483
484         Example of usage:
485             sk = geompy.Sketcher2D()
486             sk.addSegmentAbsolute(30, 50)
487             Sketcher_1 = sk.wire(geomObj_1)
488         """
489         self.myCommand = self.myCommand + ":TT %s %s" % (printVar(x), printVar(y))
490         pass
491
492     ## Add segment, which sequentially connects the given point with previous point
493     #  Coordinates are considered relative to the previous point.
494     #  If the first point of sketcher is not yet defined, the
495     #  origin (0, 0) will become the first sketcher point.
496     #
497     #  @param dx, dy - Coordinates of point relative a previous point
498     def addSegmentRelative (self, dx, dy):
499         """
500         Add segment, which sequentially connects the given point with previous point
501         Coordinates are considered relative to the previous point.
502         If the first point of sketcher is not yet defined, the
503         origin (0, 0) will become the first sketcher point.
504
505         Parameters:
506             dx, dy - Coordinates of point relative a previous point
507
508         Example of usage:
509             sk = geompy.Sketcher2D()
510             sk.addSegmentRelative(60, 10)
511             Sketcher_1 = sk.wire(geomObj_1)
512         """
513         self.myCommand = self.myCommand + ":T %s %s" % (printVar(dx), printVar(dy))
514         pass
515     
516     ## Add one straight segment, defined by angle and length.
517     #  If the first point of sketcher is not yet defined, the
518     #  origin (0, 0) will become the first sketcher point.
519     #  The angle and length coordinates are defined 
520     #  in a local coordinate system which origin is the last point of the sketch
521     #
522     #  @param angle - angle in a plane
523     #  @param length - length of the segment
524     def addSegmentAngleLength (self, angle, length ):
525         """
526         Add one straight segment, defined by angle and length.
527         If the first point of sketcher is not yet defined, the
528         origin (0, 0) will become the first sketcher point.
529         The radius and angles coordinates are defined 
530         in a local coordinate system which origin is the last point of the sketch
531
532         Parameters:
533             angle - angle in a plane
534             length - length of the segment
535
536         Example of usage:
537             sk = geompy.Sketcher2D()
538             sk.addSegmentAngleLength(10, 30)
539             Sketcher_1 = sk.wire(geomObj_1)
540         """
541         self.myCommand = self.myCommand + ":R %s:L %s" % (printVar(angle), printVar(length))
542         pass
543     
544     ## Add one straight segment, defined by angle and intersect straight x= param x.
545     #  If the first point of sketcher is not yet defined, the
546     #  origin (0, 0) will become the first sketcher point.
547     #  The angle and point's coordinates are defined 
548     #  in a local coordinate system which origin is the last point of the sketch
549     #
550     #  @param angle - angle in a plane
551     #  @param x - value on the axis Ox
552     def addSegmentAngleX (self, angle, x ):
553         """
554         Add one straight segment, defined by angle and intersect straight x= param x.
555         If the first point of sketcher is not yet defined, the
556         origin (0, 0) will become the first sketcher point.
557         The angle and point's coordinates are defined 
558         in a local coordinate system which origin is the last point of the sketch
559
560         Parameters:
561             angle - angle in a plane
562             x - value on the axis Ox
563
564         Example of usage:
565             sk = geompy.Sketcher2D()
566             sk.addSegmentAngleX(25, 90)
567             Sketcher_1 = sk.wire(geomObj_1)
568         """
569         self.myCommand = self.myCommand + ":R %s:IX %s" % (printVar(angle), printVar(x))
570         pass
571     
572     ## Add one straight segment, defined by angle and intersect straight y= param y.
573     #  If the first point of sketcher is not yet defined, the
574     #  origin (0, 0) will become the first sketcher point.
575     #  The angle and point's coordinates are defined 
576     #  in a local coordinate system which origin is the last point of the sketch
577     #
578     #  @param angle - angle in a plane
579     #  @param y - value on the axis Oy
580     def addSegmentAngleY (self, angle, y ):
581         """
582         Add one straight segment, defined by angle and intersect straight y= param y.
583         If the first point of sketcher is not yet defined, the
584         origin (0, 0) will become the first sketcher point.
585         The angle and point's coordinates are defined 
586         in a local coordinate system which origin is the last point of the sketch
587
588         Parameters:
589             angle - angle in a plane
590             y - value on the axis Oy
591
592         Example of usage:
593             sk = geompy.Sketcher2D()
594             sk.addSegmentAngleY(40, 0)
595             Sketcher_1 = sk.wire(geomObj_1)
596         """
597         self.myCommand = self.myCommand + ":R %s:IY %s" % (printVar(angle), printVar(y))
598         pass
599     
600     
601     ## Add one straight segment, defined by perpendicular(angle=90) and length.
602     #  If the first point of sketcher is not yet defined, the
603     #  origin (0, 0) will become the first sketcher point.
604     #  The length coordinates are defined 
605     #  in a local coordinate system which origin is the last point of the sketch
606     #
607     #  @param length - length of the segment
608     def addSegmentPerpLength (self, length ):
609         """
610         Add one straight segment, defined by perpendicular and length.
611         If the first point of sketcher is not yet defined, the
612         origin (0, 0) will become the first sketcher point.
613         The length coordinates are defined 
614         in a local coordinate system which origin is the last point of the sketch
615
616         Parameters:
617             length - length of the segment
618
619         Example of usage:
620             sk = geompy.Sketcher2D()
621             sk.addSegmentPerpLength(100)
622             Sketcher_1 = sk.wire(geomObj_1)
623         """
624         self.myCommand = self.myCommand + ":R 90:L %s" % (printVar(length))
625         pass
626     
627     ## Add one straight segment, defined by perpendicular(angle=90) and intersect straight x= param x.
628     #  If the first point of sketcher is not yet defined, the
629     #  origin (0, 0) will become the first sketcher point.
630     #  The point's coordinates are defined 
631     #  in a local coordinate system which origin is the last point of the sketch
632     #
633     #  @param x - value on the axis Ox
634     def addSegmentPerpX (self, x ):
635         """
636         Add one straight segment, defined by perpendicular(angle=90) and intersect straight x= param x.
637         If the first point of sketcher is not yet defined, the
638         origin (0, 0) will become the first sketcher point.
639         The point's coordinates are defined 
640         in a local coordinate system which origin is the last point of the sketch
641
642         Parameters:
643             x - value on the axis Ox
644
645         Example of usage:
646             sk = geompy.Sketcher2D()
647             sk.addSegmentPerpX(30)
648             Sketcher_1 = sk.wire(geomObj_1)
649         """
650         self.myCommand = self.myCommand + ":R 90:IX %s" % (printVar(x))
651         pass
652
653     ## Add one straight segment, defined by perpendicular(angle=90) and intersect straight y= param y.
654     #  If the first point of sketcher is not yet defined, the
655     #  origin (0, 0) will become the first sketcher point.
656     #  The point's coordinates are defined 
657     #  in a local coordinate system which origin is the last point of the sketch
658     #
659     #  @param y - value on the axis Oy    
660     def addSegmentPerpY (self, y ):
661         """
662         Add one straight segment, defined by perpendicular(angle=90) and intersect straight y= param y.
663         If the first point of sketcher is not yet defined, the
664         origin (0, 0) will become the first sketcher point.
665         The point's coordinates are defined 
666         in a local coordinate system which origin is the last point of the sketch
667
668         Parameters:
669             y - value on the axis Oy
670
671         Example of usage:
672             sk = geompy.Sketcher2D()
673             sk.addSegmentPerpY(10)
674             Sketcher_1 = sk.wire(geomObj_1)
675         """
676         self.myCommand = self.myCommand + ":R 90:IY %s" % (printVar(y))
677         pass
678     
679     
680     ## Add one straight segment, defined by previous direction and length.
681     #  If the first point of sketcher is not yet defined, the
682     #  origin (0, 0) will become the first sketcher point.
683     #  The length coordinates are defined 
684     #  in a local coordinate system which origin is the last point of the sketch
685     #
686     #  @param length - length of the segment
687     def addSegmentLength (self, length ):
688         """
689         Add one straight segment, defined by previous direction and length.
690         If the first point of sketcher is not yet defined, the
691         origin (0, 0) will become the first sketcher point.
692         The length coordinates are defined 
693         in a local coordinate system which origin is the last point of the sketch
694
695         Parameters:
696             length - length of the segment
697
698         Example of usage:
699             sk = geompy.Sketcher2D()
700             sk.addSegmentLength(100)
701             Sketcher_1 = sk.wire(geomObj_1)
702         """
703         self.myCommand = self.myCommand + ":L %s" % (printVar(length))
704         pass
705  
706     ## Add one straight segment, defined by previous direction and intersect straight x= param x.
707     #  If the first point of sketcher is not yet defined, the
708     #  origin (0, 0) will become the first sketcher point.
709     #  The point's coordinates are defined 
710     #  in a local coordinate system which origin is the last point of the sketch
711     #
712     #  @param x - value on the axis Ox   
713     def addSegmentX (self, x ):
714         """
715         Add one straight segment, defined by previous direction and intersect straight x= param x.
716         If the first point of sketcher is not yet defined, the
717         origin (0, 0) will become the first sketcher point.
718         The point's coordinates are defined 
719         in a local coordinate system which origin is the last point of the sketch
720
721         Parameters:
722             x - value on the axis Ox
723
724         Example of usage:
725             sk = geompy.Sketcher2D()
726             sk.addSegmentX(30)
727             Sketcher_1 = sk.wire(geomObj_1)
728         """
729         self.myCommand = self.myCommand + ":IX %s" % (printVar(x))
730         pass
731     
732     ## Add one straight segment, defined by previous direction and intersect straight y= param y.
733     #  If the first point of sketcher is not yet defined, the
734     #  origin (0, 0) will become the first sketcher point.
735     #  The point's coordinates are defined 
736     #  in a local coordinate system which origin is the last point of the sketch
737     #
738     #  @param y - value on the axis Oy   
739     def addSegmentY (self, y ):
740         """
741         Add one straight segment, defined by previous direction and intersect straight y= param y.
742         If the first point of sketcher is not yet defined, the
743         origin (0, 0) will become the first sketcher point.
744         The point's coordinates are defined 
745         in a local coordinate system which origin is the last point of the sketch
746
747         Parameters:
748             y - value on the axis Oy
749
750         Example of usage:
751             sk = geompy.Sketcher2D()
752             sk.addSegmentY(10)
753             Sketcher_1 = sk.wire(geomObj_1)
754         """
755         self.myCommand = self.myCommand + ":IY %s" % (printVar(y))
756         pass
757     
758
759     ## Add one straight segment, defined by direction and length.
760     #  If the first point of sketcher is not yet defined, the
761     #  origin (0, 0) will become the first sketcher point.
762     #  The direction and length coordinates are defined 
763     #  in a local coordinate system which origin is the last point of the sketch
764     #
765     #  @param dx, dy - direction of the segment    
766     #  @param length - length of the segment   
767     def addSegmentDirectionLength (self, dx, dy, length ):
768         """
769         Add one straight segment, defined by direction and length.
770         If the first point of sketcher is not yet defined, the
771         origin (0, 0) will become the first sketcher point.
772         The direction and length coordinates are defined 
773         in a local coordinate system which origin is the last point of the sketch
774
775         Parameters:
776             dx, dy - direction of the segment
777             length - length of the segment
778
779         Example of usage:
780             sk = geompy.Sketcher2D()
781             sk.addSegmentDirectionLength(20, 40, 30)
782             Sketcher_1 = sk.wire(geomObj_1)
783         """
784         self.myCommand = self.myCommand + ":D %s %s:L %s" % (printVar(dx), printVar(dy), printVar(length))
785         pass
786
787     ## Add one straight segment, defined by direction and intersect straight x= param x.
788     #  If the first point of sketcher is not yet defined, the
789     #  origin (0, 0) will become the first sketcher point.
790     #  The direction and point's coordinates are defined 
791     #  in a local coordinate system which origin is the last point of the sketch
792     #
793     #  @param dx, dy - direction of the segment
794     #  @param x - value on the axis Ox    
795     def addSegmentDirectionX (self, dx, dy, x ):
796         """
797         Add one straight segment, defined by direction and intersect straight x= param x.
798         If the first point of sketcher is not yet defined, the
799         origin (0, 0) will become the first sketcher point.
800         The direction and point's coordinates are defined 
801         in a local coordinate system which origin is the last point of the sketch
802
803         Parameters:
804             dx, dy - direction of the segment
805             x - value on the axis Ox
806
807         Example of usage:
808             sk = geompy.Sketcher2D()
809             sk.addSegmentDirectionX(10, -40, 20)
810             Sketcher_1 = sk.wire(geomObj_1)
811         """
812         self.myCommand = self.myCommand + ":D %s %s:IX %s" % (printVar(dx), printVar(dy), printVar(x))
813         pass
814     
815     ## Add one straight segment, defined by direction and intersect straight y= param y.
816     #  If the first point of sketcher is not yet defined, the
817     #  origin (0, 0) will become the first sketcher point.
818     #  The direction and point's coordinates are defined 
819     #  in a local coordinate system which origin is the last point of the sketch
820     #
821     #  @param dx, dy - direction of the segment
822     #  @param y - value on the axis Oy  
823     def addSegmentDirectionY (self, dx, dy, y ):
824         """
825         Add one straight segment, defined by direction and intersect straight y= param y.
826         If the first point of sketcher is not yet defined, the
827         origin (0, 0) will become the first sketcher point.
828         The direction and point's coordinates are defined 
829         in a local coordinate system which origin is the last point of the sketch
830
831         Parameters:
832             dx, dy - direction of the segment
833             y - value on the axis Oy 
834
835         Example of usage:
836             sk = geompy.Sketcher2D()
837             sk.addSegmentDirectionY(-10, -50, 20)
838             Sketcher_1 = sk.wire(geomObj_1)
839         """
840         self.myCommand = self.myCommand + ":D %s %s:IY %s" % (printVar(dx), printVar(dy), printVar(y))
841         pass
842     
843     #  Commands for creation of arc
844     
845     ## Add arc, which connects the given point with previous point
846     #  Coordinates are considered as absolute.
847     #  If the first point of sketcher is not yet defined, the
848     #  origin (0, 0) will become the first sketcher point.
849     #
850     #  @param x, y - Coordinates of second point of arc    
851     def addArcAbsolute (self, x, y ):
852         """
853         Add arc, which connects the given point with previous point
854         Coordinates are considered as absolute.
855         If the first point of sketcher is not yet defined, the
856         origin (0, 0) will become the first sketcher point. 
857
858         Parameters:
859             param x, y - Coordinates of second point of arc
860
861         Example of usage:
862             sk = geompy.Sketcher2D()
863             sk.addArcAbsolute(50, 10)
864             Sketcher_1 = sk.wire(geomObj_1)
865         """
866         self.myCommand = self.myCommand + ":AA %s %s" % (printVar(x), printVar(y))
867         pass
868  
869     ## Add arc, which connects the given point with previous point
870     #  Coordinates are considered relative to the previous point.
871     #
872     #  @param dx, dy - Coordinates of second point of arc relative to the previous point   
873     def addArcRelative (self, dx, dy ):
874         """
875         Add arc, which connects the given point with previous point
876         Coordinates are considered relative to the previous point. 
877
878         Parameters:
879             param dx, dy - Coordinates of second point of arc
880
881         Example of usage:
882             sk = geompy.Sketcher2D()
883             sk.addArcRelative(50, 10)
884             Sketcher_1 = sk.wire(geomObj_1)
885         """
886         self.myCommand = self.myCommand + ":A %s %s" % (printVar(dx), printVar(dy))
887         pass
888  
889     ## Add arc, defined by radius and coordinates of next point.
890     #  Coordinates are considered as absolute.
891     #  If the first point of sketcher is not yet defined, the
892     #  origin (0, 0) will become the first sketcher point.
893     #
894     #  @param x, y - Coordinates of second point of arc
895     #  @param radius - radius of arc 
896     #  @param flag - is 0 or 2
897     #                if 0 the drawn arc is the one of lower angle (<Pi)
898     #                if 2 the drawn arc is the one of greater angle (>Pi)
899     def addArcRadiusAbsolute (self, x, y, radius, flag ):
900         """
901         Add arc, defined by radius and coordinates of next point.
902         Coordinates are considered as absolute.
903         If the first point of sketcher is not yet defined, the
904         origin (0, 0) will become the first sketcher point.
905
906         Parameters:
907             param x, y - Coordinates of second point of arc
908             param radius - radius of arc 
909             param flag - is 0 or 2
910                          if 0 the drawn arc is the one of lower angle (<Pi)
911                          if 2 the drawn arc is the one of greater angle (>Pi)
912
913         Example of usage:
914             sk = geompy.Sketcher2D()
915             sk.addArcRadiusAbsolute(50, 10, 20, 0)
916             Sketcher_1 = sk.wire(geomObj_1)
917         """
918         self.myCommand = self.myCommand + ":UU %s %s %s %s" % (printVar(x), printVar(y), printVar(radius), printVar(flag))
919         pass
920  
921     ## Add arc, defined by radius and coordinates of next point.
922     #  Coordinates are considered relative to the previous point.
923     #
924     #  @param dx, dy - Coordinates of second point of arc
925     #  @param radius - radius of arc 
926     #  @param flag - is 0 or 2
927     #                if 0 the drawn arc is the one of lower angle (<Pi)
928     #                if 2 the drawn arc is the one of greater angle (>Pi)   
929     def addArcRadiusRelative (self, dx, dy, radius, flag ):
930         """
931         Add arc, defined by radius and coordinates of next point.
932         Coordinates are considered relative to the previous point.
933
934         Parameters:
935             param dx, dy - Coordinates of second point of arc
936             param radius - radius of arc 
937             param flag - is 0 or 2
938                          if 0 the drawn arc is the one of lower angle (<Pi)
939                          if 2 the drawn arc is the one of greater angle (>Pi)
940
941         Example of usage:
942             sk = geompy.Sketcher2D()
943             sk.addArcRadiusRelative(-30, -15, 20, 2)
944             Sketcher_1 = sk.wire(geomObj_1)
945         """
946         self.myCommand = self.myCommand + ":U %s %s %s %s" % (printVar(dx), printVar(dy), printVar(radius), printVar(flag))
947         pass
948  
949     ## Add arc, defined by coordinates of next point and coordinates of center.
950     #  Coordinates are considered as absolute.
951     #  If the first point of sketcher is not yet defined, the
952     #  origin (0, 0) will become the first sketcher point.
953     #
954     #  @param x, y - Coordinates of second point of arc
955     #  @param xc, yc - Coordinates of center
956     #  @param flag1 - (reverse) is 0 or 2
957     #                if 0 the drawn arc is the one of lower angle (<Pi)
958     #                if 2 the drawn arc is the one of greater angle (>Pi)  
959     #  @param flag2 - (control tolerance) is 0 or 1
960     #                if 0 the specified end point can be at a distance of the arc   
961     def addArcCenterAbsolute (self, x, y, xc, yc, flag1, flag2 ):
962         """
963         Add arc, defined by coordinates of next point and coordinates of center.
964         Coordinates are considered as absolute.
965         If the first point of sketcher is not yet defined, the
966         origin (0, 0) will become the first sketcher point.
967
968         Parameters:
969             param x, y - Coordinates of second point of arc
970             param xc, yc - Coordinates of center
971             param flag1 - is 0 or 2
972                          if 0 the drawn arc is the one of lower angle (<Pi)
973                          if 2 the drawn arc is the one of greater angle (>Pi)
974             param flag2 - (control tolerance) is 0 or 1
975                          if 0 the specified end point can be at a distance of the arc 
976
977         Example of usage:
978             sk = geompy.Sketcher2D()
979             sk.addArcCenterAbsolute(-30, -15, 20, 10, 0, 0)
980             Sketcher_1 = sk.wire(geomObj_1)
981         """
982         self.myCommand = self.myCommand + ":EE %s %s %s %s %s %s" % (printVar(xc), printVar(yc), printVar(x), printVar(y),  
983                                                                      printVar(flag1), printVar(flag2))
984         pass
985
986     ## Add arc, defined by coordinates of next point and coordinates of center.
987     #  Coordinates are considered relative to the previous point.
988     #
989     #  @param dx, dy - Coordinates of second point of arc
990     #  @param xc, yc - Coordinates of center
991     #  @param flag1 - (reverse) is 0 or 2
992     #                if 0 the drawn arc is the one of lower angle (<Pi)
993     #                if 2 the drawn arc is the one of greater angle (>Pi)  
994     #  @param flag2 - (control tolerance) is 0 or 1
995     #                if 0 the specified end point can be at a distance of the arc     
996     def addArcCenterRelative (self, dx, dy, xc, yc, flag1, flag2 ):
997         """
998         Add arc, defined by coordinates of next point and coordinates of center.
999         Coordinates are considered relative to the previous point.
1000
1001         Parameters:
1002             param dx, dy - Coordinates of second point of arc
1003             param xc, yc - Coordinates of center
1004             param flag1 - is 0 or 2
1005                          if 0 the drawn arc is the one of lower angle (<Pi)
1006                          if 2 the drawn arc is the one of greater angle (>Pi)
1007             param flag2 - (control tolerance) is 0 or 1
1008                          if 0 the specified end point can be at a distance of the arc 
1009
1010         Example of usage:
1011             sk = geompy.Sketcher2D()
1012             sk.addArcCenterRelative(-30, -15, 20, 10, 2, 1)
1013             Sketcher_1 = sk.wire(geomObj_1)
1014         """
1015         self.myCommand = self.myCommand + ":E %s %s %s %s %s %s" % (printVar(xc), printVar(yc), printVar(dx), printVar(dy), 
1016                                                                     printVar(flag1), printVar(flag2))
1017         pass
1018  
1019     ## Add arc, defined by angle, radius and length.
1020     #  If the first point of sketcher is not yet defined, the
1021     #  origin (0, 0) will become the first sketcher point.
1022     #
1023     #  @param angle - angle in a plane
1024     #  @param radius - radius of the arc 
1025     #  @param length - length of the arc     
1026     def addArcAngleRadiusLength (self, angle, radius, length ):
1027         """
1028         Add arc, defined by angle, radius and length.
1029         If the first point of sketcher is not yet defined, the
1030         origin (0, 0) will become the first sketcher point.
1031
1032         Parameters:
1033             param angle - angle in a plane
1034             param radius - radius of the arc 
1035             param length - length of the arc     
1036
1037         Example of usage:
1038             sk = geompy.Sketcher2D()
1039             sk.addArcAngleRadiusLength(30, 15, 40)
1040             Sketcher_1 = sk.wire(geomObj_1)
1041         """
1042         self.myCommand = self.myCommand + ":R %s:C %s %s" % (printVar(angle), printVar(radius), printVar(length))
1043         pass
1044
1045     ## Add arc, defined by perpendicular(angle=90), radius and length.
1046     #  If the first point of sketcher is not yet defined, the
1047     #  origin (0, 0) will become the first sketcher point.
1048     #
1049     #  @param radius - radius of the arc 
1050     #  @param length - length of the arc    
1051     def addArcPerpRadiusLength (self, radius, length ):
1052         """
1053         Add arc, defined by perpendicular(angle=90), radius and length.
1054         If the first point of sketcher is not yet defined, the
1055         origin (0, 0) will become the first sketcher point.
1056
1057         Parameters:
1058             param radius - radius of the arc 
1059             param length - length of the arc     
1060
1061         Example of usage:
1062             sk = geompy.Sketcher2D()
1063             sk.addArcPerpRadiusLength(15, 40)
1064             Sketcher_1 = sk.wire(geomObj_1)
1065         """
1066         self.myCommand = self.myCommand + ":R 90:C %s %s" % (printVar(radius), printVar(length))
1067         pass
1068
1069     ## Add arc, defined by previous direction, radius and length.
1070     #  If the first point of sketcher is not yet defined, the
1071     #  origin (0, 0) will become the first sketcher point.
1072     #
1073     #  @param radius - radius of the arc 
1074     #  @param length - length of the arc        
1075     def addArcRadiusLength (self, radius, length ):
1076         """
1077         Add arc, defined by previous direction, radius and length.
1078         If the first point of sketcher is not yet defined, the
1079         origin (0, 0) will become the first sketcher point.
1080
1081         Parameters:
1082             param radius - radius of the arc 
1083             param length - length of the arc     
1084
1085         Example of usage:
1086             sk = geompy.Sketcher2D()
1087             sk.addArcRadiusLength(15, 40)
1088             Sketcher_1 = sk.wire(geomObj_1)
1089         """
1090         self.myCommand = self.myCommand + ":C %s %s" % (printVar(radius), printVar(length))
1091         pass
1092  
1093     ## Add arc, defined by direction, radius and length.
1094     #  If the first point of sketcher is not yet defined, the
1095     #  origin (0, 0) will become the first sketcher point.
1096     #
1097     #  @param dx, dy - direction of the arc
1098     #  @param radius - radius of the arc 
1099     #  @param length - length of the arc     
1100     def addArcDirectionRadiusLength (self, dx, dy, radius, length ):
1101         """
1102         Add arc, defined by direction, radius and length.
1103         If the first point of sketcher is not yet defined, the
1104         origin (0, 0) will become the first sketcher point.
1105
1106         Parameters:
1107             param dx, dy - direction of the arc
1108             param radius - radius of the arc 
1109             param length - length of the arc     
1110
1111         Example of usage:
1112             sk = geompy.Sketcher2D()
1113             sk.addArcDirectionRadiusLength(-50, 40, 20, 3.5)
1114             Sketcher_1 = sk.wire(geomObj_1)
1115         """
1116         self.myCommand = self.myCommand + ":D %s %s:C %s %s" % (printVar(dx), printVar(dy), printVar(radius), printVar(length))
1117         pass
1118
1119     ## Set to close the wire    
1120     def close (self):
1121         """
1122         Set to close the wire
1123
1124         Example of usage:
1125             sk = geompy.Sketcher2D()
1126             sk.addPoint(15, 85.6)
1127             sk.close()
1128             Sketcher_1 = sk.wire(geomObj_1)
1129         """
1130         self.closed = True
1131         pass
1132
1133     ## Obtain the sketcher result as a wire.
1134     #
1135     #  @param WorkingPlane - current Working Plane used for this 2DSketcher
1136     #  @param theName Object name; when specified, this parameter is used
1137     #         for result publication in the study. Otherwise, if automatic
1138     #         publication is switched on, default value is used for result name.
1139     #
1140     #  @return New GEOM_Object, containing the created wire    
1141     def wire (self, WorkingPlane=[0, 0, 0, 0, 0, 1, 1, 0, 0], theName=None):
1142         """
1143         Obtain the sketcher result as a wire.
1144
1145         Parameters:
1146             theName Object name; when specified, this parameter is used
1147                     for result publication in the study. Otherwise, if automatic
1148                     publication is switched on, default value is used for result name
1149             param WorkingPlane - current Working Plane used for this 2DSketcher
1150
1151         Returns:
1152             New GEOM_Object, containing the created wire.
1153
1154         Example of usage:
1155             sk = geompy.Sketcher2D()
1156             sk.addPoint(30, 70)
1157             a3D_Sketcher_1 = sk.wire(geomObj_1)
1158         """
1159
1160         if self.closed:
1161             self.myCommand = self.myCommand + ":WW"
1162
1163         from salome.geom.geomBuilder import ParseSketcherCommand, RaiseIfFailed
1164         Command,Parameters = ParseSketcherCommand(self.myCommand)
1165
1166         import GEOM
1167         if isinstance(WorkingPlane, list): wire = self.geompyD.CurvesOp.MakeSketcher(Command, WorkingPlane)
1168         if isinstance(WorkingPlane, GEOM._objref_GEOM_Object): wire = self.geompyD.CurvesOp.MakeSketcherOnPlane(Command, WorkingPlane)
1169
1170         self.myCommand = "Sketcher"
1171         RaiseIfFailed("Sketcher", self.geompyD.CurvesOp)
1172         wire.SetParameters(Parameters)
1173         self.geompyD._autoPublish(wire, theName, "wire")
1174         return wire
1175         
1176     ## Obtain the sketcher result as a face.
1177     #
1178     #  @param WorkingPlane - current Working Plane used for this 2DSketcher
1179     #  @param theName Object name; when specified, this parameter is used
1180     #         for result publication in the study. Otherwise, if automatic
1181     #         publication is switched on, default value is used for result name.
1182     #
1183     #  @return New GEOM_Object, containing the created face    
1184     def face (self, WorkingPlane=[0, 0, 0, 0, 0, 1, 1, 0, 0], theName=None):
1185         """
1186         Obtain the sketcher result as a face.
1187
1188         Parameters:
1189             theName Object name; when specified, this parameter is used
1190                     for result publication in the study. Otherwise, if automatic
1191                     publication is switched on, default value is used for result name
1192             param WorkingPlane - current Working Plane used for this 2DSketcher
1193
1194         Returns:
1195             New GEOM_Object, containing the created face.
1196
1197         Example of usage:
1198             sk = geompy.Sketcher2D()
1199             sk.addPoint(0, 0)
1200             sk.addSegment(100, 0)
1201             sk.addSegment(100, 100)
1202             sk.addSegment(0, 100)
1203             sk.close()
1204             a3D_Sketcher_1 = sk.face(geomObj_1)
1205         """
1206     
1207         if self.closed:
1208             self.myCommand = self.myCommand + ":WF"
1209         else:
1210             raise RuntimeError("Sketcher2D.close() : can't build face on unclosed wire")
1211
1212         from salome.geom.geomBuilder import ParseSketcherCommand, RaiseIfFailed
1213         Command,Parameters = ParseSketcherCommand(self.myCommand)
1214
1215         import GEOM
1216         if isinstance(WorkingPlane, list): face = self.geompyD.CurvesOp.MakeSketcher(Command, WorkingPlane)
1217         if isinstance(WorkingPlane, GEOM._objref_GEOM_Object): face = self.geompyD.CurvesOp.MakeSketcherOnPlane(Command, WorkingPlane)
1218
1219         self.myCommand = "Sketcher"
1220         RaiseIfFailed("Sketcher", self.geompyD.CurvesOp)
1221         face.SetParameters(Parameters)
1222         self.geompyD._autoPublish(face, theName, "face")
1223         return face
1224
1225 ## An interface to build a 2D polyline step-by-step. The polyline can contain
1226 #  several sections. Each section represents a list of 2d points. As well it
1227 #  has a name, curve type, either polyline or interpolation (BSpline curve) and
1228 #  Closed flag.
1229 #  Use geompy.Polyline2D() method to obtain an instance of this class.
1230 #  @ingroup sketcher
1231 class Polyline2D:
1232     """
1233     An interface to build a 2D polyline step-by-step. The polyline can contain
1234     several sections. Each section represents a list of 2d points. As well it
1235     has a name, curve type, either polyline or interpolation (BSpline curve) and
1236     Closed flag.
1237     Use geompy.Polyline2D() method to obtain an instance of this class.
1238
1239     Example of usage:
1240         pl = geompy.Polyline2D()
1241         pl.addSection("section 1", GEOM.Polyline, True, [0, 0, 10, 0, 10, 10])
1242         pl.addSection("section 2", GEOM.Interpolation, False)
1243         pl.addPoints([20, 0, 30, 0, 30, 10])
1244         resultObj = pl.result(WorkingPlane)
1245     """
1246
1247     def __init__(self, geompyD):
1248         self.geompyD      = geompyD
1249         self.myNameList   = []
1250         self.myTypeList   = []
1251         self.myClosedList = []
1252         self.myCoordsList = []
1253         pass
1254
1255     ## Add a new section to the polyline.
1256     #
1257     #  @param theName the name
1258     #  @param theType the type. It can have either CORBA enumeration type
1259     #         GEOM.curve_type or a value of type long. Possible input values
1260     #         are: GEOM.Polyline(0) and GEOM.Interpolation(2).
1261     #  @param theClosed True for closed section; False otherwise
1262     #  @param thePoints the list of 2D points coordinates in the form:
1263     #         [x1, y1, x2, y2, ..., xN, yN] for N points.
1264     def addSection(self, theName, theType, theClosed, thePoints = None):
1265         """
1266         Add a new section to the polyline.
1267
1268         Parameters:
1269             theName the name
1270             theType the type. It can have either CORBA enumeration type
1271                     GEOM.curve_type or a value of type long. Possible input
1272                     values are: GEOM.Polyline(0) and GEOM.Interpolation(2).
1273             theClosed True for closed section; False otherwise
1274             thePoints the list of 2D points coordinates in the form:
1275                       [x1, y1, x2, y2, ..., xN, yN] for N points.
1276
1277         Example of usage:
1278             pl = geompy.Polyline2D()
1279             pl.addSection("section 1", GEOM.Polyline, True, [0, 0, 10, 0, 10, 10])
1280             resultObj = pl.result(WorkingPlane)
1281         """
1282         from salome.geom.geomBuilder import EnumToLong
1283         self.myNameList.append(theName)
1284         self.myTypeList.append(EnumToLong(theType))
1285         self.myClosedList.append(theClosed)
1286         if thePoints is None:
1287             self.myCoordsList.append([])
1288         else:
1289             self.myCoordsList.append(thePoints)
1290         pass
1291
1292     ## Add a points to the last added section of the polyline. If there are
1293     #  no sections in the polyline it does nothing.
1294     #
1295     #  @param thePoints the list of 2D points coordinates in the form:
1296     #         [x1, y1, x2, y2, ..., xN, yN] for N points.
1297     def addPoints(self, thePoints):
1298         """
1299         Add a points to the last added section of the polyline. If there are
1300         no sections in the polyline it does nothing.
1301
1302         Parameters:
1303             thePoints the list of 2D points coordinates in the form:
1304                       [x1, y1, x2, y2, ..., xN, yN] for N points.
1305
1306         Example of usage:
1307             pl = geompy.Polyline2D()
1308             pl.addSection("section 1", GEOM.Polyline, True)
1309             pl.addPoints([0, 0, 10, 0, 10, 10])
1310             pl.addPoints([20, 0, 30, 0, 30, 10])
1311             resultObj = pl.result(WorkingPlane)
1312         """
1313         if self.myNameList:
1314             self.myCoordsList[-1].extend(thePoints)
1315         pass
1316
1317     ## Obtain the 2D polyline result as a wire or a compound of wires in case
1318     #  of several sections defined.
1319     #
1320     #  @param theWorkingPlane - current Working Plane used for this 2D polyline
1321     #  @param theName Object name; when specified, this parameter is used
1322     #         for result publication in the study. Otherwise, if automatic
1323     #         publication is switched on, default value is used for result name.
1324     #
1325     #  @return New GEOM_Object, containing the created shape.
1326     def result(self, theWorkingPlane=[0, 0, 0, 0, 0, 1, 1, 0, 0], theName=None):
1327         """
1328         Obtain the 2D polyline result as a wire or a compound of wires in case
1329         of several sections defined.
1330
1331         Parameters:
1332             theWorkingPlane current Working Plane used for this 2D polyline
1333             theName Object name; when specified, this parameter is used
1334                     for result publication in the study. Otherwise, if automatic
1335                     publication is switched on, default value is used for result name.
1336
1337         Returns:
1338             New GEOM_Object, containing the created shape.
1339
1340         Example of usage:
1341             pl = geompy.Polyline2D()
1342             pl.addSection("section 1", GEOM.Polyline, True, [0, 0, 10, 0, 10, 10])
1343             pl.addSection("section 2", GEOM.Interpolation, False)
1344             pl.addPoints([20, 0, 30, 0, 30, 10])
1345             resultObj = pl.result(WorkingPlane)
1346         """
1347         from salome.geom.geomBuilder import RaiseIfFailed
1348         import GEOM
1349         if isinstance(theWorkingPlane, list):
1350             aResult = self.geompyD.CurvesOp.MakePolyline2D(
1351                          self.myCoordsList, self.myNameList, self.myTypeList,
1352                          self.myClosedList, theWorkingPlane)
1353         if isinstance(theWorkingPlane, GEOM._objref_GEOM_Object):
1354             aResult = self.geompyD.CurvesOp.MakePolyline2DOnPlane(
1355                         self.myCoordsList, self.myNameList, self.myTypeList,
1356                         self.myClosedList, theWorkingPlane)
1357
1358         self.myNameList   = []
1359         self.myTypeList   = []
1360         self.myClosedList = []
1361         self.myCoordsList = []
1362         RaiseIfFailed("Polyline2D.result", self.geompyD.CurvesOp)
1363         self.geompyD._autoPublish(aResult, theName, "polyline")
1364
1365         return aResult