1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author : Julia DOROVSKIKH, Open CASCADE S.A.S.
24 ## @defgroup sketcher gsketcher - Wrapper to help the creation of simple sketches
27 # This module provides the user with a simple python API
28 # to realize various sketches from the GEOM text user interface.
32 # from salome.geom import geomBuilder
33 # geompy = geomBuilder.New(salome.myStudy)
35 # # create a wire for sketcher
36 # geomObj_1 = geompy.MakeMarker(0, 0, 0, 1, 0, 0, 0, 1, 0)
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)
45 # Sketch_1 = sk.wire(geomObj_1)
47 # # add objects in the study
48 # geompy.addToStudy( Sketch_1, 'Sketch_1' )
50 # # update object browser
51 # salome.sg.updateObjBrowser(1)
53 # @n Additionnal examples can be found as unit tests in the source code.
58 \brief 2D and 3D Sketcher interfaces
61 # This method is used by 3D Sketcher functionality
63 if isinstance(var, str):
68 ## An interface to build a 3D Sketcher step-by-step.
69 # Use geompy.Sketcher3D() method to obtain an instance of this class.
71 # @ref tui_3dsketcher_page "Example"
75 3D sketcher interface.
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')
84 a3D_Sketcher_1 = sk.wire()
87 def __init__(self, geompyD):
88 self.geompyD = geompyD
89 self.myCommand = "3DSketcher"
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):
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.
105 X1, Y1, Z1, X2, Y2, Z2, ... Coordinates of points
108 sk = geompy.Sketcher3D()
109 sk.addPointsAbsolute(0,0,0, 70,0,0)
110 a3D_Sketcher_1 = sk.wire()
113 for cc in listCoords:
115 self.myCommand = self.myCommand + ":TT"
116 self.myCommand = self.myCommand + " %s"%printVar(cc)
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):
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.
136 X1, Y1, Z1, X2, Y2, Z2, ... Relative coordinates of points
139 sk = geompy.Sketcher3D()
140 sk.addPointsRelative(0,0,130, 70,0,-130)
141 a3D_Sketcher_1 = sk.wire()
144 for cc in listCoords:
146 self.myCommand = self.myCommand + ":T"
147 self.myCommand = self.myCommand + " %s"%printVar(cc)
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
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"):
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.
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"
177 sk = geompy.Sketcher3D()
178 sk.addPointRadiusAnglesRelative(100, 50, 0, "OXY")
179 a3D_Sketcher_1 = sk.wire()
181 self.myCommand = self.myCommand + ":%s"%axes+"SR"+" %s %s %s" % (printVar(angle1), printVar(angle2), printVar(length))
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
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"):
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.
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"
207 sk = geompy.Sketcher3D()
208 sk.addPointRadiusAnglesAbsolute(100, 50, 0, "OXY")
209 a3D_Sketcher_1 = sk.wire()
211 self.myCommand = self.myCommand + ":%s"%axes+"SA"+" %s %s %s" % (printVar(angle1), printVar(angle2), printVar(radius))
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
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"):
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.
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"
237 sk = geompy.Sketcher3D()
238 sk.addPointRadiusAngleHRelative(100, 50, 40, "OXY")
239 a3D_Sketcher_1 = sk.wire()
241 self.myCommand = self.myCommand + ":%s"%axes+"CR"+" %s %s %s" % (printVar(angle), printVar(height), printVar(length))
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
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"):
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.
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
267 sk = geompy.Sketcher3D()
268 sk.addPointRadiusAngleHAbsolute( 100, 50, 40, "OXY")
269 a3D_Sketcher_1 = sk.wire()
271 self.myCommand = self.myCommand + ":%s"%axes+"CA"+" %s %s %s" % (printVar(angle), printVar(height), printVar(radius))
274 ## Set to close the wire
277 Set to close the wire
280 sk = geompy.Sketcher3D()
281 sk.addPointsRelative(0,0,130, 70,0,-130)
283 a3D_Sketcher_1 = sk.wire()
285 self.myCommand = self.myCommand + ":WW"
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.
293 # @return New GEOM_Object, containing the created wire
294 def wire (self, theName=None):
296 Obtain the sketcher result.
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.
304 New GEOM_Object, containing the created wire.
307 sk = geompy.Sketcher3D()
308 sk.addPointsRelative(0,0,130, 70,0,-130)
309 a3D_Sketcher_1 = sk.wire()
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")
320 ## An interface to build a 2D Sketcher step-by-step.
321 # Use geompy.Sketcher2D() method to obtain an instance of this class.
325 2D sketcher interface.
328 sk = geompy.Sketcher2D()
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)
336 Sketch_1 = sk.wire(geomObj_1)
338 def __init__(self, geompyD):
339 self.geompyD = geompyD
340 self.myCommand = "Sketcher"
345 # Used to set the starting point
347 # @param x, y - Coordinates of point
348 def addPoint (self, x, y):
351 Used to set the starting point
354 x, y - Coordinates of point
357 sk = geompy.Sketcher2D()
359 Sketcher_1 = sk.wire(geomObj_1)
361 self.myCommand = self.myCommand + ":F %s %s" % (printVar(x), printVar(y))
365 # Used to set the angle for further building
367 # @param angle - angle in a plane
368 def addAngle (self, angle):
371 Used to set the angle for further building
374 angle - angle in a plane
377 sk = geompy.Sketcher2D()
379 Sketcher_1 = sk.wire(geomObj_1)
381 self.myCommand = self.myCommand + ":RR %s" % (printVar(angle))
384 # Commands for creation of segment
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.
392 # @param x - Coordinate of point on axis Ox
393 def addSegmentParalX(self, x):
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.
402 x - Coordinate of point on axis Ox
405 sk = geompy.Sketcher2D()
406 sk.addSegmentParalX(40)
407 Sketcher_1 = sk.wire(geomObj_1)
409 self.myCommand = self.myCommand + ":X %s" % (printVar(x))
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):
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.
422 sk = geompy.Sketcher2D()
423 sk.addSegmentParalXToZero()
424 Sketcher_1 = sk.wire(geomObj_1)
426 self.myCommand = self.myCommand + ":XX"
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.
435 # @param y - Coordinate of point on axis Oy
436 def addSegmentParalY(self, y):
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.
445 y - Coordinate of point on axis Oy
448 sk = geompy.Sketcher2D()
449 sk.addSegmentParalY(80)
450 Sketcher_1 = sk.wire(geomObj_1)
452 self.myCommand = self.myCommand + ":Y %s" % (printVar(y))
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):
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.
465 sk = geompy.Sketcher2D()
466 sk.addSegmentParalYToZero()
467 Sketcher_1 = sk.wire(geomObj_1)
469 self.myCommand = self.myCommand + ":YY"
472 ## Add segment, which sequentially connects the given point with previous point
474 # Coordinates are considered as absolute.
475 # @param x, y - Coordinates of point
476 def addSegmentAbsolute (self, x, y):
478 Add segment, which sequentially connects the starting point with the given point
479 Coordinates are considered as absolute.
482 x, y - Coordinates of point
485 sk = geompy.Sketcher2D()
486 sk.addSegmentAbsolute(30, 50)
487 Sketcher_1 = sk.wire(geomObj_1)
489 self.myCommand = self.myCommand + ":TT %s %s" % (printVar(x), printVar(y))
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.
497 # @param dx, dy - Coordinates of point relative a previous point
498 def addSegmentRelative (self, dx, dy):
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.
506 dx, dy - Coordinates of point relative a previous point
509 sk = geompy.Sketcher2D()
510 sk.addSegmentRelative(60, 10)
511 Sketcher_1 = sk.wire(geomObj_1)
513 self.myCommand = self.myCommand + ":T %s %s" % (printVar(dx), printVar(dy))
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
522 # @param angle - angle in a plane
523 # @param length - length of the segment
524 def addSegmentAngleLength (self, angle, length ):
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
533 angle - angle in a plane
534 length - length of the segment
537 sk = geompy.Sketcher2D()
538 sk.addSegmentAngleLength(10, 30)
539 Sketcher_1 = sk.wire(geomObj_1)
541 self.myCommand = self.myCommand + ":R %s:L %s" % (printVar(angle), printVar(length))
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
550 # @param angle - angle in a plane
551 # @param x - value on the axis Ox
552 def addSegmentAngleX (self, angle, x ):
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
561 angle - angle in a plane
562 x - value on the axis Ox
565 sk = geompy.Sketcher2D()
566 sk.addSegmentAngleX(25, 90)
567 Sketcher_1 = sk.wire(geomObj_1)
569 self.myCommand = self.myCommand + ":R %s:IX %s" % (printVar(angle), printVar(x))
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
578 # @param angle - angle in a plane
579 # @param y - value on the axis Oy
580 def addSegmentAngleY (self, angle, y ):
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
589 angle - angle in a plane
590 y - value on the axis Oy
593 sk = geompy.Sketcher2D()
594 sk.addSegmentAngleY(40, 0)
595 Sketcher_1 = sk.wire(geomObj_1)
597 self.myCommand = self.myCommand + ":R %s:IY %s" % (printVar(angle), printVar(y))
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
607 # @param length - length of the segment
608 def addSegmentPerpLength (self, length ):
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
617 length - length of the segment
620 sk = geompy.Sketcher2D()
621 sk.addSegmentPerpLength(100)
622 Sketcher_1 = sk.wire(geomObj_1)
624 self.myCommand = self.myCommand + ":R 90:L %s" % (printVar(length))
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
633 # @param x - value on the axis Ox
634 def addSegmentPerpX (self, x ):
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
643 x - value on the axis Ox
646 sk = geompy.Sketcher2D()
647 sk.addSegmentPerpX(30)
648 Sketcher_1 = sk.wire(geomObj_1)
650 self.myCommand = self.myCommand + ":R 90:IX %s" % (printVar(x))
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
659 # @param y - value on the axis Oy
660 def addSegmentPerpY (self, y ):
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
669 y - value on the axis Oy
672 sk = geompy.Sketcher2D()
673 sk.addSegmentPerpY(10)
674 Sketcher_1 = sk.wire(geomObj_1)
676 self.myCommand = self.myCommand + ":R 90:IY %s" % (printVar(y))
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
686 # @param length - length of the segment
687 def addSegmentLength (self, length ):
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
696 length - length of the segment
699 sk = geompy.Sketcher2D()
700 sk.addSegmentLength(100)
701 Sketcher_1 = sk.wire(geomObj_1)
703 self.myCommand = self.myCommand + ":L %s" % (printVar(length))
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
712 # @param x - value on the axis Ox
713 def addSegmentX (self, x ):
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
722 x - value on the axis Ox
725 sk = geompy.Sketcher2D()
727 Sketcher_1 = sk.wire(geomObj_1)
729 self.myCommand = self.myCommand + ":IX %s" % (printVar(x))
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
738 # @param y - value on the axis Oy
739 def addSegmentY (self, y ):
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
748 y - value on the axis Oy
751 sk = geompy.Sketcher2D()
753 Sketcher_1 = sk.wire(geomObj_1)
755 self.myCommand = self.myCommand + ":IY %s" % (printVar(y))
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
765 # @param dx, dy - direction of the segment
766 # @param length - length of the segment
767 def addSegmentDirectionLength (self, dx, dy, length ):
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
776 dx, dy - direction of the segment
777 length - length of the segment
780 sk = geompy.Sketcher2D()
781 sk.addSegmentDirectionLength(20, 40, 30)
782 Sketcher_1 = sk.wire(geomObj_1)
784 self.myCommand = self.myCommand + ":D %s %s:L %s" % (printVar(dx), printVar(dy), printVar(length))
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
793 # @param dx, dy - direction of the segment
794 # @param x - value on the axis Ox
795 def addSegmentDirectionX (self, dx, dy, x ):
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
804 dx, dy - direction of the segment
805 x - value on the axis Ox
808 sk = geompy.Sketcher2D()
809 sk.addSegmentDirectionX(10, -40, 20)
810 Sketcher_1 = sk.wire(geomObj_1)
812 self.myCommand = self.myCommand + ":D %s %s:IX %s" % (printVar(dx), printVar(dy), printVar(x))
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
821 # @param dx, dy - direction of the segment
822 # @param y - value on the axis Oy
823 def addSegmentDirectionY (self, dx, dy, y ):
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
832 dx, dy - direction of the segment
833 y - value on the axis Oy
836 sk = geompy.Sketcher2D()
837 sk.addSegmentDirectionY(-10, -50, 20)
838 Sketcher_1 = sk.wire(geomObj_1)
840 self.myCommand = self.myCommand + ":D %s %s:IY %s" % (printVar(dx), printVar(dy), printVar(y))
843 # Commands for creation of arc
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.
850 # @param x, y - Coordinates of second point of arc
851 def addArcAbsolute (self, x, y ):
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.
859 param x, y - Coordinates of second point of arc
862 sk = geompy.Sketcher2D()
863 sk.addArcAbsolute(50, 10)
864 Sketcher_1 = sk.wire(geomObj_1)
866 self.myCommand = self.myCommand + ":AA %s %s" % (printVar(x), printVar(y))
869 ## Add arc, which connects the given point with previous point
870 # Coordinates are considered relative to the previous point.
872 # @param dx, dy - Coordinates of second point of arc relative to the previous point
873 def addArcRelative (self, dx, dy ):
875 Add arc, which connects the given point with previous point
876 Coordinates are considered relative to the previous point.
879 param dx, dy - Coordinates of second point of arc
882 sk = geompy.Sketcher2D()
883 sk.addArcRelative(50, 10)
884 Sketcher_1 = sk.wire(geomObj_1)
886 self.myCommand = self.myCommand + ":A %s %s" % (printVar(dx), printVar(dy))
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.
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 ):
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.
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)
914 sk = geompy.Sketcher2D()
915 sk.addArcRadiusAbsolute(50, 10, 20, 0)
916 Sketcher_1 = sk.wire(geomObj_1)
918 self.myCommand = self.myCommand + ":UU %s %s %s %s" % (printVar(x), printVar(y), printVar(radius), printVar(flag))
921 ## Add arc, defined by radius and coordinates of next point.
922 # Coordinates are considered relative to the previous point.
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 ):
931 Add arc, defined by radius and coordinates of next point.
932 Coordinates are considered relative to the previous point.
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)
942 sk = geompy.Sketcher2D()
943 sk.addArcRadiusRelative(-30, -15, 20, 2)
944 Sketcher_1 = sk.wire(geomObj_1)
946 self.myCommand = self.myCommand + ":U %s %s %s %s" % (printVar(dx), printVar(dy), printVar(radius), printVar(flag))
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.
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 ):
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.
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
978 sk = geompy.Sketcher2D()
979 sk.addArcCenterAbsolute(-30, -15, 20, 10, 0, 0)
980 Sketcher_1 = sk.wire(geomObj_1)
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))
986 ## Add arc, defined by coordinates of next point and coordinates of center.
987 # Coordinates are considered relative to the previous point.
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 ):
998 Add arc, defined by coordinates of next point and coordinates of center.
999 Coordinates are considered relative to the previous point.
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
1011 sk = geompy.Sketcher2D()
1012 sk.addArcCenterRelative(-30, -15, 20, 10, 2, 1)
1013 Sketcher_1 = sk.wire(geomObj_1)
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))
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.
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 ):
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.
1033 param angle - angle in a plane
1034 param radius - radius of the arc
1035 param length - length of the arc
1038 sk = geompy.Sketcher2D()
1039 sk.addArcAngleRadiusLength(30, 15, 40)
1040 Sketcher_1 = sk.wire(geomObj_1)
1042 self.myCommand = self.myCommand + ":R %s:C %s %s" % (printVar(angle), printVar(radius), printVar(length))
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.
1049 # @param radius - radius of the arc
1050 # @param length - length of the arc
1051 def addArcPerpRadiusLength (self, radius, length ):
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.
1058 param radius - radius of the arc
1059 param length - length of the arc
1062 sk = geompy.Sketcher2D()
1063 sk.addArcPerpRadiusLength(15, 40)
1064 Sketcher_1 = sk.wire(geomObj_1)
1066 self.myCommand = self.myCommand + ":R 90:C %s %s" % (printVar(radius), printVar(length))
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.
1073 # @param radius - radius of the arc
1074 # @param length - length of the arc
1075 def addArcRadiusLength (self, radius, length ):
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.
1082 param radius - radius of the arc
1083 param length - length of the arc
1086 sk = geompy.Sketcher2D()
1087 sk.addArcRadiusLength(15, 40)
1088 Sketcher_1 = sk.wire(geomObj_1)
1090 self.myCommand = self.myCommand + ":C %s %s" % (printVar(radius), printVar(length))
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.
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 ):
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.
1107 param dx, dy - direction of the arc
1108 param radius - radius of the arc
1109 param length - length of the arc
1112 sk = geompy.Sketcher2D()
1113 sk.addArcDirectionRadiusLength(-50, 40, 20, 3.5)
1114 Sketcher_1 = sk.wire(geomObj_1)
1116 self.myCommand = self.myCommand + ":D %s %s:C %s %s" % (printVar(dx), printVar(dy), printVar(radius), printVar(length))
1119 ## Set to close the wire
1122 Set to close the wire
1125 sk = geompy.Sketcher2D()
1126 sk.addPoint(15, 85.6)
1128 Sketcher_1 = sk.wire(geomObj_1)
1133 ## Obtain the sketcher result as a wire.
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.
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):
1143 Obtain the sketcher result as a wire.
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
1152 New GEOM_Object, containing the created wire.
1155 sk = geompy.Sketcher2D()
1157 a3D_Sketcher_1 = sk.wire(geomObj_1)
1161 self.myCommand = self.myCommand + ":WW"
1163 from salome.geom.geomBuilder import ParseSketcherCommand, RaiseIfFailed
1164 Command,Parameters = ParseSketcherCommand(self.myCommand)
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)
1170 self.myCommand = "Sketcher"
1171 RaiseIfFailed("Sketcher", self.geompyD.CurvesOp)
1172 wire.SetParameters(Parameters)
1173 self.geompyD._autoPublish(wire, theName, "wire")
1176 ## Obtain the sketcher result as a face.
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.
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):
1186 Obtain the sketcher result as a face.
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
1195 New GEOM_Object, containing the created face.
1198 sk = geompy.Sketcher2D()
1200 sk.addSegment(100, 0)
1201 sk.addSegment(100, 100)
1202 sk.addSegment(0, 100)
1204 a3D_Sketcher_1 = sk.face(geomObj_1)
1208 self.myCommand = self.myCommand + ":WF"
1210 raise RuntimeError, "Sketcher2D.close() : can't build face on unclosed wire"
1212 from salome.geom.geomBuilder import ParseSketcherCommand, RaiseIfFailed
1213 Command,Parameters = ParseSketcherCommand(self.myCommand)
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)
1219 self.myCommand = "Sketcher"
1220 RaiseIfFailed("Sketcher", self.geompyD.CurvesOp)
1221 face.SetParameters(Parameters)
1222 self.geompyD._autoPublish(face, theName, "face")
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
1229 # Use geompy.Polyline2D() method to obtain an instance of this class.
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
1237 Use geompy.Polyline2D() method to obtain an instance of this class.
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)
1247 def __init__(self, geompyD):
1248 self.geompyD = geompyD
1249 self.myNameList = []
1250 self.myTypeList = []
1251 self.myClosedList = []
1252 self.myCoordsList = []
1255 ## Add a new section to the polyline.
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):
1266 Add a new section to the polyline.
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.
1278 pl = geompy.Polyline2D()
1279 pl.addSection("section 1", GEOM.Polyline, True, [0, 0, 10, 0, 10, 10])
1280 resultObj = pl.result(WorkingPlane)
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([])
1289 self.myCoordsList.append(thePoints)
1292 ## Add a points to the last added section of the polyline. If there are
1293 # no sections in the polyline it does nothing.
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):
1299 Add a points to the last added section of the polyline. If there are
1300 no sections in the polyline it does nothing.
1303 thePoints the list of 2D points coordinates in the form:
1304 [x1, y1, x2, y2, ..., xN, yN] for N points.
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)
1314 self.myCoordsList[-1].extend(thePoints)
1317 ## Obtain the 2D polyline result as a wire or a compound of wires in case
1318 # of several sections defined.
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.
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):
1328 Obtain the 2D polyline result as a wire or a compound of wires in case
1329 of several sections defined.
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.
1338 New GEOM_Object, containing the created shape.
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)
1347 from salome.geom.geomBuilder import RaiseIfFailed
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)
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")