1 # Copyright (C) 2021 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 from salome.shaper import model
21 from salome.shaper import geom
23 from SketchAPI import *
27 def checkRectangle(lines, center, corner, tolerance = 1.e-7):
28 dx = corner.x() - center.x()
29 dy = corner.y() - center.y()
30 points = [geom.Pnt2d(center.x() - dx, center.y() - dy),
31 geom.Pnt2d(center.x() - dx, center.y() + dy),
32 geom.Pnt2d(center.x() + dx, center.y() + dy),
33 geom.Pnt2d(center.x() + dx, center.y() - dy)]
35 line = SketchAPI_Line(lines[i])
36 sp = line.startPoint().pnt()
38 assert(sp.distance(sp_ref) <= tolerance)
39 ep = line.endPoint().pnt()
41 assert(ep.distance(ep_ref) <= tolerance)
45 partSet = model.moduleDocument()
46 part = model.addPart(partSet).document()
48 centerPoint = geom.Pnt2d(50, 50)
49 endPoint = geom.Pnt2d(100, 100)
51 sketch = model.addSketch(part, model.defaultPlane("XOY"))
52 rectangle_1 = sketch.addRectangleCentered(centerPoint, endPoint)
53 lines_1 = rectangle_1.lines()
56 checkRectangle(lines_1, centerPoint, endPoint)
59 projection_1 = sketch.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
60 point_1 = SketchAPI_Point(projection_1.createdFeature())
62 rectangle_2 = sketch.addRectangleCentered(point_1.coordinates(), endPoint)
63 lines_2 = rectangle_2.lines()
66 checkRectangle(lines_2, geom.Pnt2d(0.0, 0.0), endPoint)
69 rectangle_3 = sketch.addRectangleCentered(SketchAPI_Line(lines_1[0]).startPoint(), SketchAPI_Line(lines_2[0]).endPoint())
70 lines_3 = rectangle_3.lines()
73 checkRectangle(lines_3, SketchAPI_Line(lines_1[0]).startPoint().pnt(), SketchAPI_Line(lines_2[0]).endPoint().pnt())
75 # move center of rectangle
77 center = SketchAPI_Line(lines_1[0]).startPoint().pnt()
78 for i in range(0, 20):
79 center.setX(center.x() + SHIFT)
80 center.setY(center.y() + SHIFT)
82 sketch.move(SketchAPI_Line(lines_1[0]).startPoint(), center)
84 checkRectangle(lines_3, center, SketchAPI_Line(lines_2[0]).endPoint().pnt())
86 # move corner of rectangle
87 corner = SketchAPI_Line(lines_2[0]).endPoint().pnt()
88 for i in range(0, 20):
89 corner.setX(corner.x() + SHIFT)
90 corner.setY(corner.y() + SHIFT)
92 sketch.move(SketchAPI_Line(lines_2[0]).endPoint(), corner)
94 checkRectangle(lines_3, SketchAPI_Line(lines_1[0]).startPoint().pnt(), corner)
96 assert(model.checkPythonDump())