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