Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / Test / Test20274_2.py
1 # Copyright (C) 2020-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 GeomAlgoAPI import *
21 from SketchAPI import *
22
23 from salome.shaper import model
24
25 import math
26
27 model.begin()
28 partSet = model.moduleDocument()
29
30 ### Create Part
31 Part_1 = model.addPart(partSet)
32 Part_1_doc = Part_1.document()
33
34 ### Create Sketch
35 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
36
37 ### Create SketchLine
38 SketchLine_1 = Sketch_1.addLine(50, 0, 41.0188620508502, 41.01886205085074)
39
40 ### Create SketchProjection
41 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
42 SketchLine_2 = SketchProjection_1.createdFeature()
43 Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_2.result())
44
45 ### Create SketchLine
46 SketchLine_3 = Sketch_1.addLine(41.0188620508502, 41.01886205085074, 0, 50)
47 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_3.startPoint())
48
49 ### Create SketchProjection
50 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
51 SketchLine_4 = SketchProjection_2.createdFeature()
52 Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.result())
53
54 ### Create SketchLine
55 SketchLine_5 = Sketch_1.addLine(41.0188620508502, 41.01886205085074, 70.71067811865088, 70.71067811866516)
56 Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_5.startPoint())
57
58 ### Create SketchCircle
59 SketchCircle_1 = Sketch_1.addCircle(0, 0, 100)
60 SketchCircle_1.setAuxiliary(True)
61 Sketch_1.setCoincident(SketchAPI_Line(SketchLine_2).startPoint(), SketchCircle_1.center())
62 Sketch_1.setCoincident(SketchAPI_Line(SketchLine_2).endPoint(), SketchCircle_1.results()[1])
63 Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchCircle_1.results()[1])
64 Sketch_1.setMiddlePoint(SketchLine_1.startPoint(), SketchLine_2.result())
65 Sketch_1.setMiddlePoint(SketchLine_3.endPoint(), SketchLine_4.result())
66 Sketch_1.setEqual(SketchLine_1.result(), SketchLine_3.result())
67 Sketch_1.setEqual(SketchLine_1.result(), SketchLine_5.result())
68 Sketch_1.setCoincident(SketchCircle_1.center(), SketchLine_5.result())
69
70 ### Create SketchMultiTranslation
71 SketchMultiTranslation_1_objects = [SketchLine_1.result(), SketchLine_3.result(), SketchLine_5.result()]
72 SketchMultiTranslation_1 = Sketch_1.addTranslation(SketchMultiTranslation_1_objects, SketchAPI_Line(SketchLine_4).startPoint(), SketchLine_5.endPoint(), 2)
73 [SketchLine_7, SketchLine_8, SketchLine_9] = SketchMultiTranslation_1.translatedList()
74 model.do()
75
76 ### Create Extrusion
77 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 0, "Edges")
78 model.end()
79
80 ### Store volumes of sub-shapes as a reference
81 TOLERANCE = 1.e-7
82 REFERENCE = []
83 resultExtrusion_1 = Extrusion_1.result()
84 for ind in range(resultExtrusion_1.numberOfSubs()):
85   REFERENCE.append(GeomAlgoAPI_ShapeTools.volume(resultExtrusion_1.subResult(ind).resultSubShapePair()[0].shape()))
86
87 ### Add new edges to Sketch_1 then check the Extrusion and update reference data
88 model.begin()
89 SketchLine_6 = Sketch_1.addLine(70.71067811865088, 70.71067811866516, 77.78174593052023, 77.78174593052023)
90 Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
91 Sketch_1.setCollinear(SketchLine_5.result(), SketchLine_6.result())
92 Sketch_1.setLength(SketchLine_6.result(), 10)
93
94 SketchMultiTranslation_1.translationList().append(SketchLine_6.defaultResult())
95 model.end()
96
97 resultExtrusion_1 = Extrusion_1.result()
98 for ind in range(resultExtrusion_1.numberOfSubs()):
99   area = GeomAlgoAPI_ShapeTools.volume(resultExtrusion_1.subResult(ind).resultSubShapePair()[0].shape())
100   if (ind < len(REFERENCE)):
101     assert(math.fabs(REFERENCE[ind] - area) < TOLERANCE)
102   else:
103     REFERENCE.append(area)
104
105 assert(model.checkPythonDump(model.CHECK_NAMING))
106
107 ### Check results after dump
108 resultExtrusion_1 = Extrusion_1.result()
109 assert(len(REFERENCE) == resultExtrusion_1.numberOfSubs())
110 for ind in range(resultExtrusion_1.numberOfSubs()):
111   area = GeomAlgoAPI_ShapeTools.volume(resultExtrusion_1.subResult(ind).resultSubShapePair()[0].shape())
112   assert(math.fabs(REFERENCE[ind] - area) < TOLERANCE)