Salome HOME
11ef9bb6d6f183b00046a1fdf7bcf5fdac2013e7
[modules/geom.git] / src / GEOM_SWIG / gsketcher.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2012  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.
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 3D Sketcher interface
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.addPointAnglesLength("OXY", 50, 0, 100)
49         sk.addPointAnglesLength("OXZ", 30, 80, 130)
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 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 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 radius 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     #  @return New GEOM_Object, containing the created wire
257     def wire (self):
258         """
259         Obtain the sketcher result.
260
261         Returns:
262             New GEOM_Object, containing the created wire.
263
264         Example of usage:
265             sk = geompy.Sketcher3D()
266             sk.addPointsRelative(0,0,130, 70,0,-130)
267             a3D_Sketcher_1 = sk.wire()
268         """
269         from geompyDC import ParseSketcherCommand, RaiseIfFailed
270         Command,Parameters = ParseSketcherCommand(self.myCommand)
271         wire = self.geompyD.CurvesOp.Make3DSketcherCommand(Command)
272         self.myCommand = "3DSketcher"
273         RaiseIfFailed("Sketcher3D", self.geompyD.CurvesOp)
274         wire.SetParameters(Parameters)
275         return wire