Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelAPI / Test / TestSelectionInPart.py
1 # Copyright (C) 2014-2023  CEA, EDF
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 model.addParameter(partSet, "ShaftSize", "16")
27 model.addParameter(partSet, "ShaftChamfer", "0.2")
28 model.addParameter(partSet, "ToolHeight", "5")
29 model.addParameter(partSet, "ToolDraftAngle", "11")
30 model.addParameter(partSet, "ScrewDiam", "3.5")
31 model.addParameter(partSet, "ThreadDiam", "ScrewDiam+1")
32 model.addParameter(partSet, "ScrewHeight", "12")
33 model.addParameter(partSet, "ToolEdgeSize", "9")
34 Sketch_1 = model.addSketch(partSet, model.defaultPlane("YOZ"))
35 SketchLine_1 = Sketch_1.addLine(7.8, 0, -7.8, 0)
36 SketchLine_2 = Sketch_1.addLine(-8, 0.2, -8, 15.8)
37 SketchLine_3 = Sketch_1.addLine(-7.8, 16, 7.8, 16)
38 SketchLine_4 = Sketch_1.addLine(8, 15.8, 8, 0.2)
39 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
40 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
41 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result())
42 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result())
43 SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "Origin"), False)
44 SketchPoint_1 = SketchProjection_1.createdFeature()
45 SketchConstraintMiddle_1 = Sketch_1.setMiddlePoint(SketchAPI_Point(SketchPoint_1).coordinates(), SketchLine_1.result())
46 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_1.result())
47 SketchLine_5 = Sketch_1.addLine(-8, 0.2, -7.8, 0)
48 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchLine_5.startPoint())
49 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_5.endPoint())
50 SketchLine_6 = Sketch_1.addLine(7.8, 0, 8, 0.2)
51 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_6.startPoint())
52 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_6.endPoint())
53 SketchLine_7 = Sketch_1.addLine(-8, 15.8, -7.8, 16)
54 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_7.startPoint())
55 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_7.endPoint())
56 SketchLine_8 = Sketch_1.addLine(7.8, 16, 8, 15.8)
57 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_8.startPoint())
58 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchLine_4.startPoint(), SketchLine_8.endPoint())
59 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_2.result(), SketchLine_3.result())
60 SketchConstraintEqual_3 = Sketch_1.setEqual(SketchLine_3.result(), SketchLine_4.result())
61 SketchConstraintEqual_4 = Sketch_1.setEqual(SketchLine_5.result(), SketchLine_6.result())
62 SketchConstraintEqual_5 = Sketch_1.setEqual(SketchLine_6.result(), SketchLine_7.result())
63 SketchConstraintEqual_6 = Sketch_1.setEqual(SketchLine_7.result(), SketchLine_8.result())
64 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchLine_5.startPoint(), SketchLine_4.result(), "ShaftSize", True)
65 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchLine_1.endPoint(), SketchLine_3.result(), "ShaftSize", True)
66 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_5.startPoint(), SketchLine_1.endPoint(), "ShaftChamfer")
67 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_1.endPoint(), SketchLine_5.startPoint(), "ShaftChamfer")
68 model.do()
69 Part_1 = model.addPart(partSet)
70 Part_1.setName("TurnShaft")
71 Part_1.result().setName("TurnShaft")
72 Part_1.result().setColor(75, 75, 75)
73 Part_1_doc = Part_1.document()
74 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_6f-SketchLine_4r-SketchLine_8r-SketchLine_3r-SketchLine_7r-SketchLine_2r-SketchLine_5f-SketchLine_1r")], model.selection(), 100, 0)
75 ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection("FACE", "Extrusion_1_1/Generated_Face&PartSet/Sketch_1/SketchLine_4"), 0, model.selection(), 0, [model.selection("SOLID", "Extrusion_1_1")])
76 Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&PartSet/Sketch_1/SketchLine_2"))
77 SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/Sketch_1/SketchLine_7"), True)
78 SketchLine_9 = SketchProjection_2.createdFeature()
79 SketchLine_10 = Sketch_2.addLine(0, 15.8, 0.2, 16)
80 SketchConstraintCoincidence_9 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_9).startPoint(), SketchLine_10.startPoint())
81 SketchLine_11 = Sketch_2.addLine(0.2, 16, 0, 16)
82 SketchConstraintCoincidence_10 = Sketch_2.setCoincident(SketchLine_10.endPoint(), SketchLine_11.startPoint())
83 SketchConstraintCoincidence_11 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_9).endPoint(), SketchLine_11.endPoint())
84 SketchConstraintHorizontal_3 = Sketch_2.setHorizontal(SketchLine_11.result())
85 SketchConstraintEqual_7 = Sketch_2.setEqual(SketchLine_9.result(), SketchLine_11.result())
86 SketchProjection_3 = Sketch_2.addProjection(model.selection("EDGE", "PartSet/Sketch_1/SketchLine_5"), True)
87 SketchLine_12 = SketchProjection_3.createdFeature()
88 SketchLine_13 = Sketch_2.addLine(0, 0.2, 0.2, 0)
89 SketchConstraintCoincidence_12 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_12).startPoint(), SketchLine_13.startPoint())
90 SketchLine_14 = Sketch_2.addLine(0.2, 0, 0, 0)
91 SketchConstraintCoincidence_13 = Sketch_2.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
92 SketchConstraintCoincidence_14 = Sketch_2.setCoincident(SketchAPI_Line(SketchLine_12).endPoint(), SketchLine_14.endPoint())
93 SketchConstraintHorizontal_4 = Sketch_2.setHorizontal(SketchLine_14.result())
94 SketchConstraintEqual_8 = Sketch_2.setEqual(SketchLine_12.result(), SketchLine_14.result())
95 ExtrusionCut_1.setNestedSketch(Sketch_2)
96 ExtrusionCut_2 = model.addExtrusionCut(Part_1_doc, [], model.selection(), model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_1"), 0, model.selection(), 0, [model.selection("SOLID", "ExtrusionCut_1_1")])
97 Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_3"))
98 SketchProjection_4 = Sketch_3.addProjection(model.selection("EDGE", "[ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_3][ExtrusionCut_1_1/Generated_Face&Sketch_1/SketchLine_2]"), False)
99 SketchLine_15 = SketchProjection_4.createdFeature()
100 SketchProjection_5 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_2_EndVertex"), False)
101 SketchPoint_2 = SketchProjection_5.createdFeature()
102 SketchLine_16 = Sketch_3.addLine(0, -8, 0.2, -8)
103 SketchConstraintCoincidence_15 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_16.startPoint())
104 SketchLine_17 = Sketch_3.addLine(0.2, -8, 0, -7.8)
105 SketchConstraintCoincidence_16 = Sketch_3.setCoincident(SketchLine_16.endPoint(), SketchLine_17.startPoint())
106 SketchLine_18 = Sketch_3.addLine(0, -7.8, 0, -8)
107 SketchConstraintCoincidence_17 = Sketch_3.setCoincident(SketchLine_17.endPoint(), SketchLine_18.startPoint())
108 SketchConstraintCoincidence_18 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_2).coordinates(), SketchLine_18.endPoint())
109 SketchConstraintHorizontal_5 = Sketch_3.setHorizontal(SketchLine_16.result())
110 SketchConstraintVertical_3 = Sketch_3.setVertical(SketchLine_18.result())
111 SketchConstraintEqual_9 = Sketch_3.setEqual(SketchLine_16.result(), SketchLine_18.result())
112 SketchConstraintCoincidence_19 = Sketch_3.setCoincident(SketchLine_16.endPoint(), SketchLine_15.result())
113 SketchProjection_6 = Sketch_3.addProjection(model.selection("VERTEX", "PartSet/Sketch_1/SketchLine_8_EndVertex"), False)
114 SketchPoint_3 = SketchProjection_6.createdFeature()
115 SketchLine_19 = Sketch_3.addLine(0, 8, 0, 7.8)
116 SketchConstraintCoincidence_20 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_19.startPoint())
117 SketchLine_20 = Sketch_3.addLine(0, 7.8, 0.2, 8)
118 SketchConstraintCoincidence_21 = Sketch_3.setCoincident(SketchLine_19.endPoint(), SketchLine_20.startPoint())
119 SketchLine_21 = Sketch_3.addLine(0.2, 8, 0, 8)
120 SketchConstraintCoincidence_22 = Sketch_3.setCoincident(SketchLine_20.endPoint(), SketchLine_21.startPoint())
121 SketchConstraintCoincidence_23 = Sketch_3.setCoincident(SketchAPI_Point(SketchPoint_3).coordinates(), SketchLine_21.endPoint())
122 SketchConstraintVertical_4 = Sketch_3.setVertical(SketchLine_19.result())
123 SketchConstraintHorizontal_6 = Sketch_3.setHorizontal(SketchLine_21.result())
124 SketchConstraintEqual_10 = Sketch_3.setEqual(SketchLine_19.result(), SketchLine_21.result())
125 SketchConstraintCoincidence_24 = Sketch_3.setCoincident(SketchLine_20.endPoint(), SketchLine_15.result())
126 ExtrusionCut_2.setNestedSketch(Sketch_3)
127 ExtrusionCut_3 = model.addExtrusionCut(Part_1_doc, [], model.selection(), 0, 3, [model.selection("SOLID", "ExtrusionCut_2_1")])
128 Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "ExtrusionCut_1_1/Modified_Face&PartSet/Sketch_1/SketchLine_3"))
129 SketchCircle_1 = Sketch_4.addCircle(10, 0, 5)
130 SketchProjection_7 = Sketch_4.addProjection(model.selection("EDGE", "[ExtrusionCut_2_1/Modified_Face&Extrusion_1_1/From_Face][ExtrusionCut_2_1/Modified_Face&Sketch_1/SketchLine_2]"), False)
131 SketchLine_22 = SketchProjection_7.createdFeature()
132 SketchLine_23 = Sketch_4.addLine(10, 0, 0, 0)
133 SketchLine_23.setAuxiliary(True)
134 SketchConstraintCoincidence_25 = Sketch_4.setCoincident(SketchCircle_1.center(), SketchLine_23.startPoint())
135 SketchConstraintCoincidence_26 = Sketch_4.setCoincident(SketchLine_23.endPoint(), SketchLine_22.result())
136 SketchConstraintMiddle_2 = Sketch_4.setMiddlePoint(SketchLine_23.endPoint(), SketchLine_22.result())
137 SketchConstraintPerpendicular_1 = Sketch_4.setPerpendicular(SketchLine_23.result(), SketchLine_22.result())
138 SketchConstraintRadius_1 = Sketch_4.setRadius(SketchCircle_1.results()[1], 5)
139 SketchConstraintLength_1 = Sketch_4.setLength(SketchLine_23.result(), 10)
140 ExtrusionCut_3.setNestedSketch(Sketch_4)
141 model.do()
142 Part_2 = model.addPart(partSet)
143 Part_2.setName("Stamp")
144 Part_2.result().setName("Stamp")
145 Part_2_doc = Part_2.document()
146 Sketch_5 = model.addSketch(Part_2_doc, model.defaultPlane("XOZ"))
147 SketchProjection_8 = Sketch_5.addProjection(model.selection("VERTEX", "PartSet/Origin"), False)
148 SketchPoint_4 = SketchProjection_8.createdFeature()
149 SketchCircle_2 = Sketch_5.addCircle(0, 0, 5)
150 SketchConstraintCoincidence_27 = Sketch_5.setCoincident(SketchPoint_4.result(), SketchCircle_2.center())
151 SketchConstraintRadius_2 = Sketch_5.setRadius(SketchCircle_2.results()[1], 5)
152 model.do()
153 Extrusion_2 = model.addExtrusion(Part_2_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f")], model.selection(), 10, 0)
154 model.do()
155 Placement_1 = model.addPlacement(partSet, [model.selection("COMPOUND", "Stamp/")], model.selection("FACE", "Stamp/Extrusion_1_1/To_Face"), model.selection("FACE", "TurnShaft/ExtrusionCut_3_1/From_Face"), False, True)
156 model.end()
157
158 # check that names of selection are exported and imported correctly
159 assert(model.checkPythonDump())