1 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 This module provides the user with a simple python API to realize
23 various sketches from the GEOM text user interface.
27 from salome.geom.sketcher import Sketcher
30 mysketcher = Sketcher()
31 mysketcher.startAtPoint(0,0)
32 mysketcher.translateToPoint(100,0)
33 mysketcher.translateWithAngleAndLength(30,100)
34 mysketcher.intersectYWithAngle(15,100)
38 wire = mysketcher.getGeomWire()
41 from salome.geom import geomBuilder
42 geompy = geomBuilder.New(salome.myStudy)
43 geompy.addToStudy( wire, 'mysketch' )
45 Additionnal examples can be found as unit tests in the source code.
47 from salome.kernel.deprecation import is_called_by_sphinx
49 if not is_called_by_sphinx():
53 from salome.geom import geomBuilder
54 geompy = geomBuilder.New(salome.myStudy)
63 self.__sketch = "Sketcher:"
65 def startAtPoint(self,x=0,y=0):
66 self.__sketch = "Sketcher:F "+str(x)+" "+str(y)
67 # the data x and y are registered to process the ending closure.
71 def translateToPoint(self,x=10,y=0):
72 '''segment->point->absolute'''
73 self.__sketch = self.__sketch + ":TT "+str(x)+" "+str(y)
75 def translateWithVector(self,deltax=10,deltay=0):
76 '''segment->point->relative'''
77 self.__sketch = self.__sketch + ":T "+str(deltax)+" "+str(deltay)
79 #def translateToSelection(self,vertex):
80 # '''segment->point->selection'''
81 # self.__sketch = self.__sketch + ":T "+str(deltax)+" "+str(deltay)
83 def translateWithAngleAndLength(self,angle=30,length=100):
84 '''segment->direction->angle+length'''
85 self.__sketch = self.__sketch + ":R "+str(angle)+":L "+str(length)
87 def intersectXWithAngle(self,angle=30,x=100):
88 '''segment->direction->angle+length'''
89 self.__sketch = self.__sketch + ":R "+str(angle)+":IX "+str(x)
91 def intersectYWithAngle(self,angle=30,y=100):
92 '''segment->direction->angle+length'''
93 self.__sketch = self.__sketch + ":R "+str(angle)+":IY "+str(y)
97 add a segment to reach the starting point and get a closed wire.
99 self.__sketch = self.__sketch + ":WW"
104 def getGeomWire(self):
107 wire = geompy.MakeSketcher(self.__sketch, [0, 0, 0, 0, 0, 1, 1, 0, -0])
110 # ===============================================================
111 # Use cases and unit tests
112 # ===============================================================
115 mysketcher = Sketcher()
117 mysketcher.startAtPoint(1.234,4.321)
118 mysketcher.translateToPoint(2.234,5.321)
120 expectedResult = "Sketcher:F 1.234 4.321:TT 2.234 5.321"
121 result = mysketcher.toString()
122 print "sketcher=",mysketcher.toString()
123 if result == expectedResult:
128 def TEST_usingGeom():
129 mysketcher = Sketcher()
130 mysketcher.startAtPoint(0,0)
131 mysketcher.translateToPoint(100,0)
132 mysketcher.translateWithAngleAndLength(30,100)
133 mysketcher.intersectYWithAngle(15,100)
135 wire = mysketcher.getGeomWire()
137 geompy.addToStudy( wire, "Sketch" )
140 if __name__ == "__main__":