Salome HOME
8e72e50d965a498a274a53c701117d2298579c9e
[modules/geom.git] / src / GEOM_SWIG / gsketcher.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2014  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 """
25     \namespace geompy
26     \brief 2D and 3D Sketcher interfaces
27 """
28
29 # This method is used by 3D Sketcher functionality
30 def printVar (var):
31     if isinstance(var, str):
32         return "\'%s\'"%var
33     else:
34         return "%.7f"%var
35
36 ## An interface to build a 3D Sketcher step-by-step.
37 #  Use geompy.Sketcher3D() method to obtain an instance of this class.
38 #
39 #  @ref tui_3dsketcher_page "Example"
40 class Sketcher3D:
41     """
42     3D sketcher interface.
43
44     Example of usage:
45         sk = geompy.Sketcher3D()
46         sk.addPointsAbsolute(0,0,0, 70,0,0)
47         sk.addPointsRelative(0, 0, 130)
48         sk.addPointRadiusAnglesRelative(50, 0, 100, 'OXY')
49         sk.addPointRadiusAnglesRelative(30, 80, 130, 'OXZ')
50         sk.close()
51         a3D_Sketcher_1 = sk.wire()
52     """
53
54     def __init__(self, geompyD):
55         self.geompyD = geompyD
56         self.myCommand = "3DSketcher"
57         pass
58
59     ## Add one or more points, sequentially connected with straight segments.
60     #  Coordinates are considered as absolute.
61     #  If the first point of sketcher is not yet defined, the first point
62     #  from the listCoords will become the first sketcher point.
63     #  @param listCoords X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
64     def addPointsAbsolute (self, *listCoords):
65         """
66         Add one or more points, sequentially connected with straight segments.
67         Coordinates are considered as absolute.
68         If the first point of sketcher is not yet defined, the first point
69         from the listCoords will become the first sketcher point.
70
71         Parameters:
72             X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
73
74         Example of usage:
75             sk = geompy.Sketcher3D()
76             sk.addPointsAbsolute(0,0,0, 70,0,0)
77             a3D_Sketcher_1 = sk.wire()
78         """
79         ii = 1
80         for cc in listCoords:
81             if ii == 1:
82                 self.myCommand = self.myCommand + ":TT"
83             self.myCommand = self.myCommand + " %s"%printVar(cc)
84             if ii == 3:
85                 ii = 1
86             else:
87                 ii = ii + 1
88         pass
89
90     ## Add one or more points, sequentially connected with straight segments.
91     #  Coordinates are considered relative to the previous point.
92     #  If the first point of sketcher is not yet defined, the
93     #  origin (0, 0, 0) will become the first sketcher point.
94     #  @param listCoords X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
95     def addPointsRelative (self, *listCoords):
96         """
97         Add one or more points, sequentially connected with straight segments.
98         Coordinates are considered relative to the previous point.
99         If the first point of sketcher is not yet defined, the
100         origin (0, 0, 0) will become the first sketcher point.
101
102         Parameters:
103             X1, Y1, Z1, X2, Y2, Z2, ... Relative coordinates of points
104
105         Example of usage:
106             sk = geompy.Sketcher3D()
107             sk.addPointsRelative(0,0,130, 70,0,-130)
108             a3D_Sketcher_1 = sk.wire()
109         """
110         ii = 1
111         for cc in listCoords:
112             if ii == 1:
113                 self.myCommand = self.myCommand + ":T"
114             self.myCommand = self.myCommand + " %s"%printVar(cc)
115             if ii == 3:
116                 ii = 1
117             else:
118                 ii = ii + 1
119         pass
120
121     ## Add one straight segment, defined by two angles and length.
122     #  If the first point of sketcher is not yet defined, the
123     #  origin (0, 0, 0) will become the first sketcher point.
124     #  The radius and angles coordinates are defined 
125     #  in a local coordinate system which origin is the last point of the sketch
126     #
127     #  @param length length of the segment
128     #  @param angle1 angle in a plane, defined by the \a axes
129     #  @param angle2 angle from the plane, defined by the \a axes
130     #  @param axes can be: "OXY", "OYZ" or "OXZ"
131     def addPointRadiusAnglesRelative (self, length, angle1, angle2, axes="OXY"):
132         """
133         Add one straight segment, defined by two angles and length.
134         If the first point of sketcher is not yet defined, the
135         origin (0, 0, 0) will become the first sketcher point.
136
137         Parameters:
138             length length of the segment
139             angle1 angle in a plane, defined by the \a axes
140             angle2 angle from the plane, defined by the \a axes
141             axes can be: "OXY", "OYZ" or "OXZ"
142
143         Example of usage:
144             sk = geompy.Sketcher3D()
145             sk.addPointRadiusAnglesRelative(100, 50, 0, "OXY")
146             a3D_Sketcher_1 = sk.wire()
147         """
148         self.myCommand = self.myCommand + ":%s"%axes+"SR"+" %s %s %s" % (printVar(angle1), printVar(angle2), printVar(length))
149         pass
150     
151     ## Add one straight segment, defined by two angles and radius.
152     #  If the first point of sketcher is not yet defined, the
153     #  origin (0, 0, 0) will become the first sketcher point.
154     #  The radius and angles coordinates are defined 
155     #  in a coordinate system which origin is the global coordinate system origin
156     #  
157     #  @param radius distance to the coordinate system origin
158     #  @param angle1 angle in a plane, defined by the \a axes
159     #  @param angle2 angle from the plane, defined by the \a axes
160     #  @param axes can be: "OXY", "OYZ" or "OXZ"
161     def addPointRadiusAnglesAbsolute (self, radius, angle1, angle2, axes="OXY"):
162         """
163         Add one straight segment, defined by two angles and length.
164         If the first point of sketcher is not yet defined, the
165         origin (0, 0, 0) will become the first sketcher point.
166
167         Parameters:
168             radius distance to the coordinate system origin
169             angle1 angle in a plane, defined by the \a axes
170             angle2 angle from the plane, defined by the \a axes
171             axes can be: "OXY", "OYZ" or "OXZ"
172
173         Example of usage:
174             sk = geompy.Sketcher3D()
175             sk.addPointRadiusAnglesAbsolute(100, 50, 0, "OXY")
176             a3D_Sketcher_1 = sk.wire()
177         """
178         self.myCommand = self.myCommand + ":%s"%axes+"SA"+" %s %s %s" % (printVar(angle1), printVar(angle2), printVar(radius))
179         pass
180     
181     ## Add one straight segment, defined by an angle, a height and a radius.
182     #  If the first point of sketcher is not yet defined, the
183     #  origin (0, 0, 0) will become the first sketcher point.
184     #  The radius height and angle coordinates are defined 
185     #  in a local coordinate system which origin is the last point of the sketch
186     #  
187     #  @param axes can be: "OXY", "OYZ" or "OXZ"
188     #  @param angle angle in a plane, defined by the \a axes
189     #  @param height height from the plane, defined by the \a axes
190     #  @param length distance to the coordinate system origin
191     def addPointRadiusAngleHRelative (self, length, angle, height, axes="OXY"):
192         """
193         Add one straight segment, defined by two angles and length.
194         If the first point of sketcher is not yet defined, the
195         origin (0, 0, 0) will become the first sketcher point.
196
197         Parameters:
198             radius distance to the coordinate system origin
199             angle  angle in a plane, defined by the \a axes
200             height height from the plane, defined by the \a axes
201             axes can be: "OXY", "OYZ" or "OXZ"
202
203         Example of usage:
204             sk = geompy.Sketcher3D()
205             sk.addPointRadiusAngleHRelative(100, 50, 40, "OXY")
206             a3D_Sketcher_1 = sk.wire()
207         """
208         self.myCommand = self.myCommand + ":%s"%axes+"CR"+" %s %s %s" % (printVar(angle), printVar(height), printVar(length))
209         pass
210     
211     ## Add one straight segment, defined by an angle, a height and a radius.
212     #  If the first point of sketcher is not yet defined, the
213     #  origin (0, 0, 0) will become the first sketcher point.
214     #  The radius height and angle coordinates are defined 
215     #  in a coordinate system which origin is the global coordinate system origin
216     # 
217     #  @param radius distance to the coordinate system origin
218     #  @param angle angle in a plane, defined by the \a axes
219     #  @param height height from the plane, defined by the \a axes
220     #  @param axes can be: "OXY", "OYZ" or "OXZ"
221     def addPointRadiusAngleHAbsolute (self, radius, angle, height, axes="OXY"):
222         """
223         Add one straight segment, defined by two angles and length.
224         If the first point of sketcher is not yet defined, the
225         origin (0, 0, 0) will become the first sketcher point.
226
227         Parameters:
228             axes can be: "OXY", "OYZ" or "OXZ"
229             angle1 angle in a plane, defined by the \a axes
230             height height from the plane, defined by the \a axes
231             radius distance to the coordinate system origin
232
233         Example of usage:
234             sk = geompy.Sketcher3D()
235             sk.addPointRadiusAngleHAbsolute( 100, 50, 40, "OXY")
236             a3D_Sketcher_1 = sk.wire()
237         """
238         self.myCommand = self.myCommand + ":%s"%axes+"CA"+" %s %s %s" % (printVar(angle), printVar(height), printVar(radius))
239         pass
240
241     ## Set to close the wire
242     def close (self):
243         """
244         Set to close the wire
245
246         Example of usage:
247             sk = geompy.Sketcher3D()
248             sk.addPointsRelative(0,0,130, 70,0,-130)
249             sk.close()
250             a3D_Sketcher_1 = sk.wire()
251         """
252         self.myCommand = self.myCommand + ":WW"
253         pass
254
255     ## Obtain the sketcher result.
256     #  @param theName Object name; when specified, this parameter is used
257     #         for result publication in the study. Otherwise, if automatic
258     #         publication is switched on, default value is used for result name.
259     #
260     #  @return New GEOM_Object, containing the created wire
261     def wire (self, theName=None):
262         """
263         Obtain the sketcher result.
264
265         Parameters:
266             theName Object name; when specified, this parameter is used
267                     for result publication in the study. Otherwise, if automatic
268                     publication is switched on, default value is used for result name.
269
270         Returns:
271             New GEOM_Object, containing the created wire.
272
273         Example of usage:
274             sk = geompy.Sketcher3D()
275             sk.addPointsRelative(0,0,130, 70,0,-130)
276             a3D_Sketcher_1 = sk.wire()
277         """
278         from salome.geom.geomBuilder import ParseSketcherCommand, RaiseIfFailed
279         Command,Parameters = ParseSketcherCommand(self.myCommand)
280         wire = self.geompyD.CurvesOp.Make3DSketcherCommand(Command)
281         self.myCommand = "3DSketcher"
282         RaiseIfFailed("Sketcher3D", self.geompyD.CurvesOp)
283         wire.SetParameters(Parameters)
284         self.geompyD._autoPublish(wire, theName, "wire")
285         return wire
286
287 #  An interface to build a 2D Sketcher step-by-step.
288 #  Use geompy.Sketcher2D() method to obtain an instance of this class.
289   
290 class Sketcher2D:
291     """
292     2D sketcher interface.
293
294     Example of usage:
295         sk = geompy.Sketcher2D()
296         sk.addPoint(20, 20)
297         sk.addSegmentRelative(15, 70)
298         sk.addSegmentPerpY(50)
299         sk.addArcRadiusRelative(25, 15, 14.5, 0)
300         sk.addArcCenterAbsolute(1, 1, 50, 50, 0, 0)
301         sk.addArcDirectionRadiusLength(20, 20, 101, 162.13)
302         sk.close()
303         Sketch_1 = sk.wire(geomObj_1)
304     """
305     def __init__(self, geompyD):
306         self.geompyD = geompyD
307         self.myCommand = "Sketcher"
308         self.closed = False
309         pass
310     
311     ## Add one point.
312     #  Used to set the starting point
313     #
314     #  @param x, y - Coordinates of point
315     def addPoint (self, x, y): 
316         """
317         Add one point.
318         Used to set the starting point
319
320         Parameters:
321             x, y - Coordinates of point
322
323         Example of usage:
324             sk = geompy.Sketcher2D()
325             sk.addPoint(20, 20)
326             Sketcher_1 = sk.wire(geomObj_1)
327         """
328         self.myCommand = self.myCommand + ":F %s %s" % (printVar(x), printVar(y))
329         pass
330     
331     ## Add angle.
332     #  Used to set the angle for further building
333     #
334     #  @param angle - angle in a plane
335     def addAngle (self, angle): 
336         """
337         Add angle.
338         Used to set the angle for further building
339
340         Parameters:
341             angle - angle in a plane
342
343         Example of usage:
344             sk = geompy.Sketcher2D()
345             sk.addAngle(70)
346             Sketcher_1 = sk.wire(geomObj_1)
347         """
348         self.myCommand = self.myCommand + ":RR %s" % (printVar(angle))
349         pass
350
351     #  Commands for creation of segment
352     
353     ## Add segment, which sequentially connects the previous point
354     #  with a point lying on a line parallel to the axis Ox and the value x = param x.
355     #  The current point will be the previous value to the coordinate y and 
356     #  new value to the coordinate x.
357     #  Coordinate is considered relative to the previous point.
358     #
359     #  @param x - Coordinate of point on axis Ox 
360     def addSegmentParalX(self, x):
361         """
362         Add segment, which sequentially connects the previous point
363         with a point lying on a line parallel to the axis Ox and the value x = param x.
364         The current point will be the previous value to the coordinate y and 
365         new value to the coordinate x.
366         Coordinate is considered relative to the previous point.
367
368         Parameters:
369             x - Coordinate of point on axis Ox 
370
371         Example of usage:
372             sk = geompy.Sketcher2D()
373             sk.addSegmentParalX(40)
374             Sketcher_1 = sk.wire(geomObj_1)
375         """
376         self.myCommand = self.myCommand + ":X %s" % (printVar(x))
377         pass
378     
379     ## Add segment, which sequentially connects the previous point
380     #  with a point lying on a line parallel to the axis Ox and the value x = 0
381     #  The current point will be the previous value to the coordinate y.
382     def addSegmentParalXToZero(self):
383         """
384         Add segment, which sequentially connects the previous point
385         with a point lying on a line parallel to the axis Ox and the value x = 0
386         The current point will be the previous value to the coordinate y.
387
388         Example of usage:
389             sk = geompy.Sketcher2D()
390             sk.addSegmentParalXToZero()
391             Sketcher_1 = sk.wire(geomObj_1)
392         """
393         self.myCommand = self.myCommand + ":XX"
394         pass    
395     
396     ## Add segment, which sequentially connects the previous point
397     #  with a point lying on a line parallel to the axis Oy and the value y = param y.
398     #  The current point will be the previous value to the coordinate x and 
399     #  new value to the coordinate y.
400     #  Coordinate is considered relative to the previous point.
401     #
402     #  @param y - Coordinate of point on axis Oy 
403     def addSegmentParalY(self, y):
404         """
405         Add segment, which sequentially connects the previous point
406         with a point lying on a line parallel to the axis Oy and the value y = param y.
407         The current point will be the previous value to the coordinate x and 
408         new value to the coordinate y.
409         Coordinate is considered relative to the previous point.
410
411         Parameters:
412             y - Coordinate of point on axis Oy 
413
414         Example of usage:
415             sk = geompy.Sketcher2D()
416             sk.addSegmentParalY(80)
417             Sketcher_1 = sk.wire(geomObj_1)
418         """
419         self.myCommand = self.myCommand + ":Y %s" % (printVar(y))
420         pass
421     
422     ## Add segment, which sequentially connects the previous point
423     #  with a point lying on a line parallel to the axis Ox and the value x = 0
424     #  The current point will be the previous value to the coordinate y.
425     def addSegmentParalYToZero(self):
426         """
427         Add segment, which sequentially connects the previous point
428         with a point lying on a line parallel to the axis Oy and the value y = 0
429         The current point will be the previous value to the coordinate x.
430
431         Example of usage:
432             sk = geompy.Sketcher2D()
433             sk.addSegmentParalYToZero()
434             Sketcher_1 = sk.wire(geomObj_1)
435         """
436         self.myCommand = self.myCommand + ":YY"
437         pass 
438            
439     ## Add segment, which sequentially connects the given point with previous point
440     #
441     #  Coordinates are considered as absolute.
442     #  @param x, y - Coordinates of point
443     def addSegmentAbsolute (self, x, y):
444         """
445         Add segment, which sequentially connects the starting point with the given point
446         Coordinates are considered as absolute.
447
448         Parameters:
449             x, y - Coordinates of point
450
451         Example of usage:
452             sk = geompy.Sketcher2D()
453             sk.addSegmentAbsolute(30, 50)
454             Sketcher_1 = sk.wire(geomObj_1)
455         """
456         self.myCommand = self.myCommand + ":TT %s %s" % (printVar(x), printVar(y))
457         pass
458
459     ## Add segment, which sequentially connects the given point with previous point
460     #  Coordinates are considered relative to the previous point.
461     #  If the first point of sketcher is not yet defined, the
462     #  origin (0, 0) will become the first sketcher point.
463     #
464     #  @param dx, dy - Coordinates of point relative a previous point
465     def addSegmentRelative (self, dx, dy):
466         """
467         Add segment, which sequentially connects the given point with previous point
468         Coordinates are considered relative to the previous point.
469         If the first point of sketcher is not yet defined, the
470         origin (0, 0) will become the first sketcher point.
471
472         Parameters:
473             dx, dy - Coordinates of point relative a previous point
474
475         Example of usage:
476             sk = geompy.Sketcher2D()
477             sk.addSegmentRelative(60, 10)
478             Sketcher_1 = sk.wire(geomObj_1)
479         """
480         self.myCommand = self.myCommand + ":T %s %s" % (printVar(dx), printVar(dy))
481         pass
482     
483     ## Add one straight segment, defined by angle and length.
484     #  If the first point of sketcher is not yet defined, the
485     #  origin (0, 0) will become the first sketcher point.
486     #  The angle and length coordinates are defined 
487     #  in a local coordinate system which origin is the last point of the sketch
488     #
489     #  @param angle - angle in a plane
490     #  @param length - length of the segment
491     def addSegmentAngleLength (self, angle, length ):
492         """
493         Add one straight segment, defined by angle and length.
494         If the first point of sketcher is not yet defined, the
495         origin (0, 0) will become the first sketcher point.
496         The radius and angles coordinates are defined 
497         in a local coordinate system which origin is the last point of the sketch
498
499         Parameters:
500             angle - angle in a plane
501             length - length of the segment
502
503         Example of usage:
504             sk = geompy.Sketcher2D()
505             sk.addSegmentAngleLength(10, 30)
506             Sketcher_1 = sk.wire(geomObj_1)
507         """
508         self.myCommand = self.myCommand + ":R %s:L %s" % (printVar(angle), printVar(length))
509         pass
510     
511     ## Add one straight segment, defined by angle and intersect straight x= param x.
512     #  If the first point of sketcher is not yet defined, the
513     #  origin (0, 0) will become the first sketcher point.
514     #  The angle and point's coordinates are defined 
515     #  in a local coordinate system which origin is the last point of the sketch
516     #
517     #  @param angle - angle in a plane
518     #  @param x - value on the axis Ox
519     def addSegmentAngleX (self, angle, x ):
520         """
521         Add one straight segment, defined by angle and intersect straight x= param x.
522         If the first point of sketcher is not yet defined, the
523         origin (0, 0) will become the first sketcher point.
524         The angle and point's coordinates are defined 
525         in a local coordinate system which origin is the last point of the sketch
526
527         Parameters:
528             angle - angle in a plane
529             x - value on the axis Ox
530
531         Example of usage:
532             sk = geompy.Sketcher2D()
533             sk.addSegmentAngleX(25, 90)
534             Sketcher_1 = sk.wire(geomObj_1)
535         """
536         self.myCommand = self.myCommand + ":R %s:IX %s" % (printVar(angle), printVar(x))
537         pass
538     
539     ## Add one straight segment, defined by angle and intersect straight y= param y.
540     #  If the first point of sketcher is not yet defined, the
541     #  origin (0, 0) will become the first sketcher point.
542     #  The angle and point's coordinates are defined 
543     #  in a local coordinate system which origin is the last point of the sketch
544     #
545     #  @param angle - angle in a plane
546     #  @param y - value on the axis Oy
547     def addSegmentAngleY (self, angle, y ):
548         """
549         Add one straight segment, defined by angle and intersect straight y= param y.
550         If the first point of sketcher is not yet defined, the
551         origin (0, 0) will become the first sketcher point.
552         The angle and point's coordinates are defined 
553         in a local coordinate system which origin is the last point of the sketch
554
555         Parameters:
556             angle - angle in a plane
557             y - value on the axis Oy
558
559         Example of usage:
560             sk = geompy.Sketcher2D()
561             sk.addSegmentAngleY(40, 0)
562             Sketcher_1 = sk.wire(geomObj_1)
563         """
564         self.myCommand = self.myCommand + ":R %s:IY %s" % (printVar(angle), printVar(y))
565         pass
566     
567     
568     ## Add one straight segment, defined by perpendicular(angle=90) and length.
569     #  If the first point of sketcher is not yet defined, the
570     #  origin (0, 0) will become the first sketcher point.
571     #  The length coordinates are defined 
572     #  in a local coordinate system which origin is the last point of the sketch
573     #
574     #  @param length - length of the segment
575     def addSegmentPerpLength (self, length ):
576         """
577         Add one straight segment, defined by perpendicular and length.
578         If the first point of sketcher is not yet defined, the
579         origin (0, 0) will become the first sketcher point.
580         The length coordinates are defined 
581         in a local coordinate system which origin is the last point of the sketch
582
583         Parameters:
584             length - length of the segment
585
586         Example of usage:
587             sk = geompy.Sketcher2D()
588             sk.addSegmentPerpLength(100)
589             Sketcher_1 = sk.wire(geomObj_1)
590         """
591         self.myCommand = self.myCommand + ":R 90:L %s" % (printVar(length))
592         pass
593     
594     ## Add one straight segment, defined by perpendicular(angle=90) and intersect straight x= param x.
595     #  If the first point of sketcher is not yet defined, the
596     #  origin (0, 0) will become the first sketcher point.
597     #  The point's coordinates are defined 
598     #  in a local coordinate system which origin is the last point of the sketch
599     #
600     #  @param x - value on the axis Ox
601     def addSegmentPerpX (self, x ):
602         """
603         Add one straight segment, defined by perpendicular(angle=90) and intersect straight x= param x.
604         If the first point of sketcher is not yet defined, the
605         origin (0, 0) will become the first sketcher point.
606         The point's coordinates are defined 
607         in a local coordinate system which origin is the last point of the sketch
608
609         Parameters:
610             x - value on the axis Ox
611
612         Example of usage:
613             sk = geompy.Sketcher2D()
614             sk.addSegmentPerpX(30)
615             Sketcher_1 = sk.wire(geomObj_1)
616         """
617         self.myCommand = self.myCommand + ":R 90:IX %s" % (printVar(x))
618         pass
619
620     ## Add one straight segment, defined by perpendicular(angle=90) and intersect straight y= param y.
621     #  If the first point of sketcher is not yet defined, the
622     #  origin (0, 0) will become the first sketcher point.
623     #  The point's coordinates are defined 
624     #  in a local coordinate system which origin is the last point of the sketch
625     #
626     #  @param y - value on the axis Oy    
627     def addSegmentPerpY (self, y ):
628         """
629         Add one straight segment, defined by perpendicular(angle=90) and intersect straight y= param y.
630         If the first point of sketcher is not yet defined, the
631         origin (0, 0) will become the first sketcher point.
632         The point's coordinates are defined 
633         in a local coordinate system which origin is the last point of the sketch
634
635         Parameters:
636             y - value on the axis Oy
637
638         Example of usage:
639             sk = geompy.Sketcher2D()
640             sk.addSegmentPerpY(10)
641             Sketcher_1 = sk.wire(geomObj_1)
642         """
643         self.myCommand = self.myCommand + ":R 90:IY %s" % (printVar(y))
644         pass
645     
646     
647     ## Add one straight segment, defined by previous direction and length.
648     #  If the first point of sketcher is not yet defined, the
649     #  origin (0, 0) will become the first sketcher point.
650     #  The length coordinates are defined 
651     #  in a local coordinate system which origin is the last point of the sketch
652     #
653     #  @param length - length of the segment
654     def addSegmentLength (self, length ):
655         """
656         Add one straight segment, defined by previous direction and length.
657         If the first point of sketcher is not yet defined, the
658         origin (0, 0) will become the first sketcher point.
659         The length coordinates are defined 
660         in a local coordinate system which origin is the last point of the sketch
661
662         Parameters:
663             length - length of the segment
664
665         Example of usage:
666             sk = geompy.Sketcher2D()
667             sk.addSegmentLength(100)
668             Sketcher_1 = sk.wire(geomObj_1)
669         """
670         self.myCommand = self.myCommand + ":L %s" % (printVar(length))
671         pass
672  
673     ## Add one straight segment, defined by previous direction and intersect straight x= param x.
674     #  If the first point of sketcher is not yet defined, the
675     #  origin (0, 0) will become the first sketcher point.
676     #  The point's coordinates are defined 
677     #  in a local coordinate system which origin is the last point of the sketch
678     #
679     #  @param x - value on the axis Ox   
680     def addSegmentX (self, x ):
681         """
682         Add one straight segment, defined by previous direction and intersect straight x= param x.
683         If the first point of sketcher is not yet defined, the
684         origin (0, 0) will become the first sketcher point.
685         The point's coordinates are defined 
686         in a local coordinate system which origin is the last point of the sketch
687
688         Parameters:
689             x - value on the axis Ox
690
691         Example of usage:
692             sk = geompy.Sketcher2D()
693             sk.addSegmentX(30)
694             Sketcher_1 = sk.wire(geomObj_1)
695         """
696         self.myCommand = self.myCommand + ":IX %s" % (printVar(x))
697         pass
698     
699     ## Add one straight segment, defined by previous direction and intersect straight y= param y.
700     #  If the first point of sketcher is not yet defined, the
701     #  origin (0, 0) will become the first sketcher point.
702     #  The point's coordinates are defined 
703     #  in a local coordinate system which origin is the last point of the sketch
704     #
705     #  @param y - value on the axis Oy   
706     def addSegmentY (self, y ):
707         """
708         Add one straight segment, defined by previous direction and intersect straight y= param y.
709         If the first point of sketcher is not yet defined, the
710         origin (0, 0) will become the first sketcher point.
711         The point's coordinates are defined 
712         in a local coordinate system which origin is the last point of the sketch
713
714         Parameters:
715             y - value on the axis Oy
716
717         Example of usage:
718             sk = geompy.Sketcher2D()
719             sk.addSegmentY(10)
720             Sketcher_1 = sk.wire(geomObj_1)
721         """
722         self.myCommand = self.myCommand + ":IY %s" % (printVar(y))
723         pass
724     
725
726     ## Add one straight segment, defined by direction and length.
727     #  If the first point of sketcher is not yet defined, the
728     #  origin (0, 0) will become the first sketcher point.
729     #  The direction and length coordinates are defined 
730     #  in a local coordinate system which origin is the last point of the sketch
731     #
732     #  @param dx, dy - direction of the segment    
733     #  @param length - length of the segment   
734     def addSegmentDirectionLength (self, dx, dy, length ):
735         """
736         Add one straight segment, defined by direction and length.
737         If the first point of sketcher is not yet defined, the
738         origin (0, 0) will become the first sketcher point.
739         The direction and length coordinates are defined 
740         in a local coordinate system which origin is the last point of the sketch
741
742         Parameters:
743             dx, dy - direction of the segment
744             length - length of the segment
745
746         Example of usage:
747             sk = geompy.Sketcher2D()
748             sk.addSegmentDirectionLength(20, 40, 30)
749             Sketcher_1 = sk.wire(geomObj_1)
750         """
751         self.myCommand = self.myCommand + ":D %s %s:L %s" % (printVar(dx), printVar(dy), printVar(length))
752         pass
753
754     ## Add one straight segment, defined by direction and intersect straight x= param x.
755     #  If the first point of sketcher is not yet defined, the
756     #  origin (0, 0) will become the first sketcher point.
757     #  The direction and point's coordinates are defined 
758     #  in a local coordinate system which origin is the last point of the sketch
759     #
760     #  @param dx, dy - direction of the segment
761     #  @param x - value on the axis Ox    
762     def addSegmentDirectionX (self, dx, dy, x ):
763         """
764         Add one straight segment, defined by direction and intersect straight x= param x.
765         If the first point of sketcher is not yet defined, the
766         origin (0, 0) will become the first sketcher point.
767         The direction and point's coordinates are defined 
768         in a local coordinate system which origin is the last point of the sketch
769
770         Parameters:
771             dx, dy - direction of the segment
772             x - value on the axis Ox
773
774         Example of usage:
775             sk = geompy.Sketcher2D()
776             sk.addSegmentDirectionX(10, -40, 20)
777             Sketcher_1 = sk.wire(geomObj_1)
778         """
779         self.myCommand = self.myCommand + ":D %s %s:IX %s" % (printVar(dx), printVar(dy), printVar(x))
780         pass
781     
782     ## Add one straight segment, defined by direction and intersect straight y= param y.
783     #  If the first point of sketcher is not yet defined, the
784     #  origin (0, 0) will become the first sketcher point.
785     #  The direction and point's coordinates are defined 
786     #  in a local coordinate system which origin is the last point of the sketch
787     #
788     #  @param dx, dy - direction of the segment
789     #  @param y - value on the axis Oy  
790     def addSegmentDirectionY (self, dx, dy, y ):
791         """
792         Add one straight segment, defined by direction and intersect straight y= param y.
793         If the first point of sketcher is not yet defined, the
794         origin (0, 0) will become the first sketcher point.
795         The direction and point's coordinates are defined 
796         in a local coordinate system which origin is the last point of the sketch
797
798         Parameters:
799             dx, dy - direction of the segment
800             y - value on the axis Oy 
801
802         Example of usage:
803             sk = geompy.Sketcher2D()
804             sk.addSegmentDirectionY(-10, -50, 20)
805             Sketcher_1 = sk.wire(geomObj_1)
806         """
807         self.myCommand = self.myCommand + ":D %s %s:IY %s" % (printVar(dx), printVar(dy), printVar(y))
808         pass
809     
810     #  Commands for creation of arc
811     
812     ## Add arc, which connects the given point with previous point
813     #  Coordinates are considered as absolute.
814     #  If the first point of sketcher is not yet defined, the
815     #  origin (0, 0) will become the first sketcher point.
816     #
817     #  @param x, y - Coordinates of second point of arc    
818     def addArcAbsolute (self, x, y ):
819         """
820         Add arc, which connects the given point with previous point
821         Coordinates are considered as absolute.
822         If the first point of sketcher is not yet defined, the
823         origin (0, 0) will become the first sketcher point. 
824
825         Parameters:
826             param x, y - Coordinates of second point of arc
827
828         Example of usage:
829             sk = geompy.Sketcher2D()
830             sk.addArcAbsolute(50, 10)
831             Sketcher_1 = sk.wire(geomObj_1)
832         """
833         self.myCommand = self.myCommand + ":AA %s %s" % (printVar(x), printVar(y))
834         pass
835  
836     ## Add arc, which connects the given point with previous point
837     #  Coordinates are considered relative to the previous point.
838     #
839     #  @param dx, dy - Coordinates of second point of arc relative to the previous point   
840     def addArcRelative (self, dx, dy ):
841         """
842         Add arc, which connects the given point with previous point
843         Coordinates are considered relative to the previous point. 
844
845         Parameters:
846             param dx, dy - Coordinates of second point of arc
847
848         Example of usage:
849             sk = geompy.Sketcher2D()
850             sk.addArcRelative(50, 10)
851             Sketcher_1 = sk.wire(geomObj_1)
852         """
853         self.myCommand = self.myCommand + ":A %s %s" % (printVar(dx), printVar(dy))
854         pass
855  
856     ## Add arc, defined by radius and coordinates of next point.
857     #  Coordinates are considered as absolute.
858     #  If the first point of sketcher is not yet defined, the
859     #  origin (0, 0) will become the first sketcher point.
860     #
861     #  @param x, y - Coordinates of second point of arc
862     #  @param radius - radius of arc 
863     #  @param flag - is 0 or 2
864     #                if 0 the drawn arc is the one of lower angle (<Pi)
865     #                if 2 the drawn arc is the one of greater angle (>Pi)
866     def addArcRadiusAbsolute (self, x, y, radius, flag ):
867         """
868         Add arc, defined by radius and coordinates of next point.
869         Coordinates are considered as absolute.
870         If the first point of sketcher is not yet defined, the
871         origin (0, 0) will become the first sketcher point.
872
873         Parameters:
874             param x, y - Coordinates of second point of arc
875             param radius - radius of arc 
876             param flag - is 0 or 2
877                          if 0 the drawn arc is the one of lower angle (<Pi)
878                          if 2 the drawn arc is the one of greater angle (>Pi)
879
880         Example of usage:
881             sk = geompy.Sketcher2D()
882             sk.addArcRadiusAbsolute(50, 10, 20, 0)
883             Sketcher_1 = sk.wire(geomObj_1)
884         """
885         self.myCommand = self.myCommand + ":UU %s %s %s %s" % (printVar(x), printVar(y), printVar(radius), printVar(flag))
886         pass
887  
888     ## Add arc, defined by radius and coordinates of next point.
889     #  Coordinates are considered relative to the previous point.
890     #
891     #  @param dx, dy - Coordinates of second point of arc
892     #  @param radius - radius of arc 
893     #  @param flag - is 0 or 2
894     #                if 0 the drawn arc is the one of lower angle (<Pi)
895     #                if 2 the drawn arc is the one of greater angle (>Pi)   
896     def addArcRadiusRelative (self, dx, dy, radius, flag ):
897         """
898         Add arc, defined by radius and coordinates of next point.
899         Coordinates are considered relative to the previous point.
900
901         Parameters:
902             param dx, dy - Coordinates of second point of arc
903             param radius - radius of arc 
904             param flag - is 0 or 2
905                          if 0 the drawn arc is the one of lower angle (<Pi)
906                          if 2 the drawn arc is the one of greater angle (>Pi)
907
908         Example of usage:
909             sk = geompy.Sketcher2D()
910             sk.addArcRadiusRelative(-30, -15, 20, 2)
911             Sketcher_1 = sk.wire(geomObj_1)
912         """
913         self.myCommand = self.myCommand + ":U %s %s %s %s" % (printVar(dx), printVar(dy), printVar(radius), printVar(flag))
914         pass
915  
916     ## Add arc, defined by coordinates of next point and coordinates of center.
917     #  Coordinates are considered as absolute.
918     #  If the first point of sketcher is not yet defined, the
919     #  origin (0, 0) will become the first sketcher point.
920     #
921     #  @param x, y - Coordinates of second point of arc
922     #  @param xc, yc - Coordinates of center
923     #  @param flag1 - (reverse) is 0 or 2
924     #                if 0 the drawn arc is the one of lower angle (<Pi)
925     #                if 2 the drawn arc is the one of greater angle (>Pi)  
926     #  @param flag2 - (control tolerance) is 0 or 1
927     #                if 0 the specified end point can be at a distance of the arc   
928     def addArcCenterAbsolute (self, x, y, xc, yc, flag1, flag2 ):
929         """
930         Add arc, defined by coordinates of next point and coordinates of center.
931         Coordinates are considered as absolute.
932         If the first point of sketcher is not yet defined, the
933         origin (0, 0) will become the first sketcher point.
934
935         Parameters:
936             param x, y - Coordinates of second point of arc
937             param xc, yc - Coordinates of center
938             param flag1 - is 0 or 2
939                          if 0 the drawn arc is the one of lower angle (<Pi)
940                          if 2 the drawn arc is the one of greater angle (>Pi)
941             param flag2 - (control tolerance) is 0 or 1
942                          if 0 the specified end point can be at a distance of the arc 
943
944         Example of usage:
945             sk = geompy.Sketcher2D()
946             sk.addArcCenterAbsolute(-30, -15, 20, 10, 0, 0)
947             Sketcher_1 = sk.wire(geomObj_1)
948         """
949         self.myCommand = self.myCommand + ":EE %s %s %s %s %s %s" % (printVar(xc), printVar(yc), printVar(x), printVar(y),  
950                                                                      printVar(flag1), printVar(flag2))
951         pass
952
953     ## Add arc, defined by coordinates of next point and coordinates of center.
954     #  Coordinates are considered relative to the previous point.
955     #
956     #  @param dx, dy - Coordinates of second point of arc
957     #  @param xc, yc - Coordinates of center
958     #  @param flag1 - (reverse) is 0 or 2
959     #                if 0 the drawn arc is the one of lower angle (<Pi)
960     #                if 2 the drawn arc is the one of greater angle (>Pi)  
961     #  @param flag2 - (control tolerance) is 0 or 1
962     #                if 0 the specified end point can be at a distance of the arc     
963     def addArcCenterRelative (self, dx, dy, xc, yc, flag1, flag2 ):
964         """
965         Add arc, defined by coordinates of next point and coordinates of center.
966         Coordinates are considered relative to the previous point.
967
968         Parameters:
969             param dx, dy - 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.addArcCenterRelative(-30, -15, 20, 10, 2, 1)
980             Sketcher_1 = sk.wire(geomObj_1)
981         """
982         self.myCommand = self.myCommand + ":E %s %s %s %s %s %s" % (printVar(xc), printVar(yc), printVar(dx), printVar(dy), 
983                                                                     printVar(flag1), printVar(flag2))
984         pass
985  
986     ## Add arc, defined by angle, radius and length.
987     #  If the first point of sketcher is not yet defined, the
988     #  origin (0, 0) will become the first sketcher point.
989     #
990     #  @param angle - angle in a plane
991     #  @param radius - radius of the arc 
992     #  @param length - length of the arc     
993     def addArcAngleRadiusLength (self, angle, radius, length ):
994         """
995         Add arc, defined by angle, radius and length.
996         If the first point of sketcher is not yet defined, the
997         origin (0, 0) will become the first sketcher point.
998
999         Parameters:
1000             param angle - angle in a plane
1001             param radius - radius of the arc 
1002             param length - length of the arc     
1003
1004         Example of usage:
1005             sk = geompy.Sketcher2D()
1006             sk.addArcAngleRadiusLength(30, 15, 40)
1007             Sketcher_1 = sk.wire(geomObj_1)
1008         """
1009         self.myCommand = self.myCommand + ":R %s:C %s %s" % (printVar(angle), printVar(radius), printVar(length))
1010         pass
1011
1012     ## Add arc, defined by perpendicular(angle=90), radius and length.
1013     #  If the first point of sketcher is not yet defined, the
1014     #  origin (0, 0) will become the first sketcher point.
1015     #
1016     #  @param radius - radius of the arc 
1017     #  @param length - length of the arc    
1018     def addArcPerpRadiusLength (self, radius, length ):
1019         """
1020         Add arc, defined by perpendicular(angle=90), radius and length.
1021         If the first point of sketcher is not yet defined, the
1022         origin (0, 0) will become the first sketcher point.
1023
1024         Parameters:
1025             param radius - radius of the arc 
1026             param length - length of the arc     
1027
1028         Example of usage:
1029             sk = geompy.Sketcher2D()
1030             sk.addArcPerpRadiusLength(15, 40)
1031             Sketcher_1 = sk.wire(geomObj_1)
1032         """
1033         self.myCommand = self.myCommand + ":R 90:C %s %s" % (printVar(radius), printVar(length))
1034         pass
1035
1036     ## Add arc, defined by previous direction, radius and length.
1037     #  If the first point of sketcher is not yet defined, the
1038     #  origin (0, 0) will become the first sketcher point.
1039     #
1040     #  @param radius - radius of the arc 
1041     #  @param length - length of the arc        
1042     def addArcRadiusLength (self, radius, length ):
1043         """
1044         Add arc, defined by previous direction, radius and length.
1045         If the first point of sketcher is not yet defined, the
1046         origin (0, 0) will become the first sketcher point.
1047
1048         Parameters:
1049             param radius - radius of the arc 
1050             param length - length of the arc     
1051
1052         Example of usage:
1053             sk = geompy.Sketcher2D()
1054             sk.addArcRadiusLength(15, 40)
1055             Sketcher_1 = sk.wire(geomObj_1)
1056         """
1057         self.myCommand = self.myCommand + ":C %s %s" % (printVar(radius), printVar(length))
1058         pass
1059  
1060     ## Add arc, defined by direction, radius and length.
1061     #  If the first point of sketcher is not yet defined, the
1062     #  origin (0, 0) will become the first sketcher point.
1063     #
1064     #  @param dx, dy - direction of the arc
1065     #  @param radius - radius of the arc 
1066     #  @param length - length of the arc     
1067     def addArcDirectionRadiusLength (self, dx, dy, radius, length ):
1068         """
1069         Add arc, defined by 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         Parameters:
1074             param dx, dy - direction of the arc
1075             param radius - radius of the arc 
1076             param length - length of the arc     
1077
1078         Example of usage:
1079             sk = geompy.Sketcher2D()
1080             sk.addArcDirectionRadiusLength(-50, 40, 20, 3.5)
1081             Sketcher_1 = sk.wire(geomObj_1)
1082         """
1083         self.myCommand = self.myCommand + ":D %s %s:C %s %s" % (printVar(dx), printVar(dy), printVar(radius), printVar(length))
1084         pass
1085
1086     ## Set to close the wire    
1087     def close (self):
1088         """
1089         Set to close the wire
1090
1091         Example of usage:
1092             sk = geompy.Sketcher2D()
1093             sk.addPoint(15, 85.6)
1094             sk.close()
1095             Sketcher_1 = sk.wire(geomObj_1)
1096         """
1097         self.closed = True
1098         pass
1099
1100     ## Obtain the sketcher result as a wire.
1101     #
1102     #  @param WorkingPlane - current Working Plane used for this 2DSketcher
1103     #  @param theName Object name; when specified, this parameter is used
1104     #         for result publication in the study. Otherwise, if automatic
1105     #         publication is switched on, default value is used for result name.
1106     #
1107     #  @return New GEOM_Object, containing the created wire    
1108     def wire (self, WorkingPlane=[0, 0, 0, 0, 0, 1, 1, 0, 0], theName=None):
1109         """
1110         Obtain the sketcher result as a wire.
1111
1112         Parameters:
1113             theName Object name; when specified, this parameter is used
1114                     for result publication in the study. Otherwise, if automatic
1115                     publication is switched on, default value is used for result name
1116             param WorkingPlane - current Working Plane used for this 2DSketcher
1117
1118         Returns:
1119             New GEOM_Object, containing the created wire.
1120
1121         Example of usage:
1122             sk = geompy.Sketcher2D()
1123             sk.addPoint(30, 70)
1124             a3D_Sketcher_1 = sk.wire(geomObj_1)
1125         """
1126
1127         if self.closed:
1128             self.myCommand = self.myCommand + ":WW"
1129
1130         import GEOM
1131         if isinstance(WorkingPlane, list): wire = self.geompyD.CurvesOp.MakeSketcher(self.myCommand, WorkingPlane)
1132         if isinstance(WorkingPlane, GEOM._objref_GEOM_Object): wire = self.geompyD.CurvesOp.MakeSketcherOnPlane(self.myCommand, WorkingPlane)
1133
1134         self.myCommand = "Sketcher"
1135         self.geompyD._autoPublish(wire, theName, "wire")
1136         return wire
1137         
1138     ## Obtain the sketcher result as a face.
1139     #
1140     #  @param WorkingPlane - current Working Plane used for this 2DSketcher
1141     #  @param theName Object name; when specified, this parameter is used
1142     #         for result publication in the study. Otherwise, if automatic
1143     #         publication is switched on, default value is used for result name.
1144     #
1145     #  @return New GEOM_Object, containing the created face    
1146     def face (self, WorkingPlane=[0, 0, 0, 0, 0, 1, 1, 0, 0], theName=None):
1147         """
1148         Obtain the sketcher result as a face.
1149
1150         Parameters:
1151             theName Object name; when specified, this parameter is used
1152                     for result publication in the study. Otherwise, if automatic
1153                     publication is switched on, default value is used for result name
1154             param WorkingPlane - current Working Plane used for this 2DSketcher
1155
1156         Returns:
1157             New GEOM_Object, containing the created face.
1158
1159         Example of usage:
1160             sk = geompy.Sketcher2D()
1161             sk.addPoint(0, 0)
1162             sk.addSegment(100, 0)
1163             sk.addSegment(100, 100)
1164             sk.addSegment(0, 100)
1165             sk.close()
1166             a3D_Sketcher_1 = sk.face(geomObj_1)
1167         """
1168     
1169         if self.closed:
1170             self.myCommand = self.myCommand + ":WF"
1171         else:
1172             raise RuntimeError, "Sketcher2D.close() : can't build face on unclosed wire"
1173
1174         import GEOM
1175         if isinstance(WorkingPlane, list): face = self.geompyD.CurvesOp.MakeSketcher(self.myCommand, WorkingPlane)
1176         if isinstance(WorkingPlane, GEOM._objref_GEOM_Object): face = self.geompyD.CurvesOp.MakeSketcherOnPlane(self.myCommand, WorkingPlane)
1177
1178         self.myCommand = "Sketcher"
1179         self.geompyD._autoPublish(face, theName, "face")
1180         return face