Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestSketchCopy04.py
1 # Copyright (C) 2020-2023  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 GeomAPI import *
21 from SketchAPI import *
22
23 from salome.shaper import model
24
25 model.begin()
26 partSet = model.moduleDocument()
27 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
28 SketchLine_1 = Sketch_1.addLine(-40, -72, 0, -72)
29 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
30 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "OY"), False)
31 SketchLine_2 = SketchProjection_1.createdFeature()
32 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.result())
33 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "OX"), False)
34 SketchLine_3 = SketchProjection_2.createdFeature()
35 SketchArc_1 = Sketch_1.addArc(0, 0, 0, -72, 72, 0, False)
36 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_2).startPoint(), SketchArc_1.center())
37 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_3.result(), SketchArc_1.endPoint())
38 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_1.result(), 40)
39 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 72)
40 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_1.endPoint())
41 SketchEllipticArc_1 = Sketch_1.addEllipticArc(25, 0, 25, 74.98833242578475, 72, 0, 25, 88.5, False)
42 [SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_4, SketchLine_5] = SketchEllipticArc_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
43 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.result(), SketchEllipticArc_1.center())
44 SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchEllipticArc_1.startPoint())
45 SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchEllipticArc_1.endPoint(), SketchAPI_Line(SketchLine_4).endPoint())
46 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result())
47 SketchLine_6 = Sketch_1.addLine(7.834161075251729, 88.5, 25, 88.5)
48 SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchEllipticArc_1.majorAxisPositive(), SketchLine_6.endPoint())
49 SketchArc_2 = Sketch_1.addArc(-40, -8.616197183098587, -40, -72, -94.21171510314713, 24.22579430808612, True)
50 SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchArc_2.startPoint())
51 SketchArc_3 = Sketch_1.addArc(-60, 3.5, -94.21171510314713, 24.22579430808612, -60, 43.5, True)
52 SketchConstraintCoincidence_10 = Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchArc_3.startPoint())
53 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_2.results()[1], SketchArc_3.results()[1])
54 SketchConstraintRadius_2 = Sketch_1.setRadius(SketchArc_3.results()[1], 40)
55 SketchConstraintPerpendicular_1 = Sketch_1.setPerpendicular(SketchLine_4.result(), SketchLine_6.result())
56 SketchConstraintDistance_1 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_2).startPoint(), SketchAPI_Point(SketchPoint_1).coordinates(), 25, True)
57 SketchLine_7 = Sketch_1.addLine(-40, -72, -40, -8.616197183098587)
58 SketchLine_7.setAuxiliary(True)
59 SketchConstraintCoincidence_11 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_7.startPoint())
60 SketchConstraintCoincidence_12 = Sketch_1.setCoincident(SketchArc_2.center(), SketchLine_7.endPoint())
61 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_1.result(), SketchLine_7.result(), 90, type = "Direct")
62 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchArc_3.endPoint(), SketchAPI_Line(SketchLine_2).startPoint(), 60)
63 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchArc_3.endPoint(), SketchLine_6.startPoint(), 45)
64 SketchLine_8 = Sketch_1.addLine(-60, 3.5, -60, 43.5)
65 SketchLine_8.setAuxiliary(True)
66 SketchConstraintCoincidence_13 = Sketch_1.setCoincident(SketchArc_3.center(), SketchLine_8.startPoint())
67 SketchConstraintCoincidence_14 = Sketch_1.setCoincident(SketchArc_3.endPoint(), SketchLine_8.endPoint())
68 SketchConstraintParallel_1 = Sketch_1.setParallel(SketchLine_7.result(), SketchLine_8.result())
69 SketchCircle_1 = Sketch_1.addCircle(-60, 66, 22.5)
70 SketchCircle_1.setAuxiliary(True)
71 SketchConstraintCoincidence_15 = Sketch_1.setCoincident(SketchLine_8.endPoint(), SketchCircle_1.results()[1])
72 SketchConstraintCoincidence_16 = Sketch_1.setCoincident(SketchLine_8.result(), SketchCircle_1.center())
73 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchLine_6.result(), SketchCircle_1.results()[1])
74 SketchConstraintDistance_2 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_3.result(), 66, True)
75 SketchBSpline_1 = Sketch_1.addSpline(poles = [(-60, 43.5), (-40, 43.5), (-11.56553854601814, 88.5), (8.434461453981855, 88.5)], weights = [1, 3, 3, 1])
76 [SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11] = SketchBSpline_1.controlPoles(auxiliary = [0, 1, 2, 3])
77 [SketchLine_9, SketchLine_10, SketchLine_11] = SketchBSpline_1.controlPolygon(auxiliary = [0, 1, 2])
78 SketchConstraintCoincidence_17 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_11).coordinates(), SketchLine_6.result())
79 SketchConstraintEqual_1 = Sketch_1.setEqual(SketchLine_9.result(), SketchLine_11.result())
80 SketchConstraintCoincidence_18 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_8).coordinates(), SketchArc_3.endPoint())
81 SketchConstraintCoincidence_19 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_10).endPoint(), SketchLine_6.result())
82 SketchLine_12 = Sketch_1.addLine(-19.07878402833891, -6, -23.3, -6)
83 SketchLine_13 = Sketch_1.addLine(-23.3, -6, -23.3, 6)
84 SketchConstraintCoincidence_20 = Sketch_1.setCoincident(SketchLine_12.endPoint(), SketchLine_13.startPoint())
85 SketchLine_14 = Sketch_1.addLine(-23.3, 6, -19.07878402833891, 6)
86 SketchConstraintCoincidence_21 = Sketch_1.setCoincident(SketchLine_13.endPoint(), SketchLine_14.startPoint())
87 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_14.result())
88 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_13.result())
89 SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_12.result())
90 SketchArc_4 = Sketch_1.addArc(0, 0, -19.07878402833891, -6, -19.07878402833891, 6, False)
91 SketchConstraintCoincidence_22 = Sketch_1.setCoincident(SketchAPI_Line(SketchLine_2).startPoint(), SketchArc_4.center())
92 SketchConstraintCoincidence_23 = Sketch_1.setCoincident(SketchLine_14.endPoint(), SketchArc_4.endPoint())
93 SketchConstraintCoincidence_24 = Sketch_1.setCoincident(SketchLine_12.startPoint(), SketchArc_4.startPoint())
94 SketchPoint_12 = Sketch_1.addPoint(-23.3, 0)
95 SketchConstraintCoincidence_25 = Sketch_1.setCoincident(SketchPoint_12.coordinates(), SketchLine_3.result())
96 SketchConstraintMiddle_1 = Sketch_1.setMiddlePoint(SketchPoint_12.coordinates(), SketchLine_13.result())
97 SketchConstraintRadius_3 = Sketch_1.setRadius(SketchArc_4.results()[1], 20)
98 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_13.result(), 12)
99 SketchConstraintDistance_3 = Sketch_1.setDistance(SketchPoint_12.coordinates(), SketchAPI_Line(SketchLine_2).startPoint(), 23.3, True)
100 SketchBSplinePeriodic_1 = Sketch_1.addSpline(poles = [(-80, -23), (-80, 0), (-50, 0), (-50, -23)], periodic = True)
101 [SketchPoint_13, SketchPoint_14, SketchPoint_15, SketchPoint_16] = SketchBSplinePeriodic_1.controlPoles(auxiliary = [0, 1, 2, 3])
102 [SketchLine_15, SketchLine_16, SketchLine_17, SketchLine_18] = SketchBSplinePeriodic_1.controlPolygon(auxiliary = [0, 1, 2, 3])
103 SketchConstraintCollinear_1 = Sketch_1.setCollinear(SketchLine_16.result(), SketchLine_5.result())
104 SketchConstraintEqual_2 = Sketch_1.setEqual(SketchLine_18.result(), SketchLine_16.result())
105 SketchConstraintEqual_3 = Sketch_1.setEqual(SketchLine_15.result(), SketchLine_17.result())
106 SketchConstraintPerpendicular_2 = Sketch_1.setPerpendicular(SketchLine_18.result(), SketchLine_15.result())
107 SketchEllipse_1 = Sketch_1.addEllipse(35, 45, 35, 67.91287847483518, 10)
108 [SketchPoint_17, SketchPoint_18, SketchPoint_19, SketchPoint_20, SketchPoint_21, SketchPoint_22, SketchPoint_23, SketchLine_19, SketchLine_20] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
109 SketchConstraintParallel_2 = Sketch_1.setParallel(SketchLine_4.result(), SketchLine_19.result())
110 SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_16.result(), 30)
111 SketchConstraintLength_4 = Sketch_1.setLength(SketchLine_15.result(), 23)
112 SketchConstraintLength_5 = Sketch_1.setLength(SketchLine_19.result(), 50)
113 SketchConstraintLength_6 = Sketch_1.setLength(SketchLine_20.result(), 20)
114 SketchConstraintDistance_4 = Sketch_1.setDistance(SketchAPI_Line(SketchLine_17).startPoint(), SketchArc_4.center(), 50, True)
115 SketchConstraintCoincidence_26 = Sketch_1.setCoincident(SketchAPI_Point(SketchPoint_23).coordinates(), SketchLine_4.result())
116 SketchConstraintDistance_5 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_17).coordinates(), SketchLine_3.result(), 45, True)
117 SketchCircle_2 = Sketch_1.addCircle(0, 66, 12)
118 SketchConstraintCoincidence_27 = Sketch_1.setCoincident(SketchLine_2.result(), SketchCircle_2.center())
119 SketchConstraintRadius_4 = Sketch_1.setRadius(SketchCircle_2.results()[1], 12)
120 SketchLine_21 = Sketch_1.addLine(-60, 66, 0, 66)
121 SketchLine_21.setAuxiliary(True)
122 SketchConstraintCoincidence_28 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_21.startPoint())
123 SketchConstraintHorizontal_4 = Sketch_1.setHorizontal(SketchLine_21.result())
124 SketchConstraintCoincidence_29 = Sketch_1.setCoincident(SketchLine_21.endPoint(), SketchCircle_2.center())
125 model.do()
126
127 Part_1 = model.addPart(partSet)
128 Part_1_doc = Part_1.document()
129 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1/Face-SketchLine_1r-SketchArc_1_2f-SketchEllipticArc_1f-SketchLine_6r-SketchBSpline_1r-SketchArc_3_2f-SketchArc_2_2f-SketchLine_12f-SketchLine_13f-SketchLine_14f-SketchArc_4_2r-SketchBSplinePeriodic_1f-SketchEllipse_1r-SketchCircle_2_2r")], model.selection(), 10, 0)
130
131 # copy sketch to the partSet after the part
132 Sketch_1_Copy = model.copySketch(partSet, Sketch_1)
133
134 model.end()
135
136 error = model.compareSketches(Sketch_1, Sketch_1_Copy)
137 assert(error == ""), error
138
139 model.testNbResults(Extrusion_1, 1)
140 model.testNbSubResults(Extrusion_1, [0])
141 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.SOLID, [1])
142 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.FACE, [16])
143 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.EDGE, [84])
144 model.testNbSubShapes(Extrusion_1, GeomAPI_Shape.VERTEX, [168])
145 model.testResultsVolumes(Extrusion_1, [183140.3921289446])
146
147 assert(partSet.size("Features") == 3)
148 assert(Part_1_doc.size("Features") == 1)
149
150 assert(model.checkPythonDump())