Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / Test / TestSketchDrawer.py
1 # Copyright (C) 2018-2022  CEA/DEN, EDF R&D
2 #
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.
7 #
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.
12 #
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
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 from SketchAPI import *
21
22 from salome.shaper import model
23
24 model.begin()
25 partSet = model.moduleDocument()
26 Part_1 = model.addPart(partSet)
27 Part_1_doc = Part_1.document()
28 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
29 SketchLine_1 = Sketch_1.addLine(-14.48008258397498, -13.79591274114419, 5.519917416025022, -13.79591274114419)
30 SketchLine_2 = Sketch_1.addLine(10.51991741602502, -8.795912741144186, 10.51991741602502, 18.20408725885581)
31 SketchLine_3 = Sketch_1.addLine(10.51991741602502, 18.20408725885581, -14.48008258397498, 13.79591274114419)
32 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
33 SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_2")
34 SketchLine_4 = Sketch_1.addLine(-14.48008258397498, 13.79591274114419, -14.48008258397498, -13.79591274114419)
35 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
36 SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_3")
37 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_4.endPoint())
38 SketchConstraintCoincidence_3.setName("SketchConstraintCoincidence_4")
39 SketchArc_1 = Sketch_1.addArc(5.519917416025022, -8.795912741144186, 5.519917416025022, -13.79591274114419, 10.51991741602502, -8.795912741144186, False)
40 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
41 SketchConstraintCoincidence_4.setName("SketchConstraintCoincidence_5")
42 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_2.startPoint())
43 SketchConstraintCoincidence_5.setName("SketchConstraintCoincidence_6")
44 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_1.result())
45 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_2.result())
46 SketchCircle_1 = Sketch_1.addCircle(0, 0, 5)
47 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
48 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
49 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_4.result(), SketchLine_3.result(), 100)
50 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_2.result(), 27)
51 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_1.startPoint(), SketchLine_2.result(), 25, True)
52 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 5)
53 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_1.result(), SketchLine_4.result())
54 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_4.startPoint(), SketchCircle_1.center(), 20, True)
55 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchLine_4.endPoint(), SketchCircle_1.center(), 20, True)
56 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
57 SketchPoint_1 = SketchProjection_1.createdFeature()
58 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_1).coordinates(), SketchCircle_1.center())
59 SketchConstraintCoincidence_6.setName("SketchConstraintCoincidence_7")
60 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchCircle_1.results()[1], 5)
61 model.do()
62 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchLine_1r-SketchArc_1_2f-SketchLine_2f-SketchLine_3f-SketchLine_4f-SketchCircle_1_2r")], model.selection(), 10, 0)
63 model.do()
64 # create a drawer feature of the extrusion and upper face, without dimensions
65 Drawer1 = Part_1_doc.addFeature("SketchDrawer")
66 Drawer1.selection("base_shape").setValue(Extrusion_1.feature(), None)
67 Drawer1.boolean("add_dimensions").setValue(False)
68 PlaneSelection = model.selection("FACE", "Extrusion_1_1/To_Face")
69 PlaneSelection.fillAttribute(Drawer1.selection("plane"))
70 model.do()
71 # create a drawer feature of the extrusion and upper face, with dimensions
72 Drawer2 = Part_1_doc.addFeature("SketchDrawer")
73 Drawer2.selection("base_shape").setValue(Extrusion_1.feature(), None)
74 Drawer2.boolean("add_dimensions").setValue(True)
75 PlaneSelection = model.selection("FACE", "Extrusion_1_1/To_Face")
76 PlaneSelection.fillAttribute(Drawer2.selection("plane"))
77 model.end()
78
79 # check that a sketch is created with valid elements
80 assert(Part_1_doc.size("Construction") == 3) # three sketches: base of extrusion and drawer's two
81
82 from ModelAPI import *
83 aFactory = ModelAPI_Session.get().validators()
84
85 Sketch1 = objectToFeature(Part_1_doc.object("Features", 2)) # the first created sketch feature
86 assert(aFactory.validate(Sketch1))
87 assert(len(Sketch1.results()) == 1)
88
89 Sketch2 = objectToFeature(Part_1_doc.object("Features", 3)) # the second created sketch feature
90 assert(aFactory.validate(Sketch2))
91 assert(len(Sketch2.results()) == 1)