]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModelAPI/Test/TestBlockRecalculation.py
Salome HOME
Added a unit-test for #21537 : Dumped file not loadable
[modules/shaper.git] / src / ModelAPI / Test / TestBlockRecalculation.py
1 # Copyright (C) 2014-2020  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 from timeit import default_timer as timer
24
25 # initial time value
26 startTime = timer()
27
28 model.begin()
29 partSet = model.moduleDocument()
30 param_l1 = model.addParameter(partSet, "l1", "20")
31 param_l2 = model.addParameter(partSet, "l2", "5")
32 param_a1 = model.addParameter(partSet, "a1", "35")
33 param_a2 = model.addParameter(partSet, "a2", "150")
34 Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
35 SketchLine_1 = Sketch_1.addLine(0, 35.14523516719186, 10, 35.14523516719186)
36 SketchLine_2 = Sketch_1.addLine(10.57357643635423, 33.32608312288851, 6.47781621490927, 30.45820094113327)
37 SketchLine_3 = Sketch_1.addLine(6.47781621490927, 30.45820094113327, 3, 23)
38 SketchLine_4 = Sketch_1.addLine(3, 23, 3, 3)
39 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
40 SketchConstraintCoincidence_1.setName("SketchConstraintCoincidence_3")
41 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "OX"), False)
42 SketchLine_5 = SketchProjection_1.createdFeature()
43 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_3.startPoint(), SketchLine_2.endPoint())
44 SketchConstraintCoincidence_2.setName("SketchConstraintCoincidence_4")
45 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result())
46 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "OY"), False)
47 SketchLine_6 = SketchProjection_2.createdFeature()
48 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_4.result(), "l1")
49 SketchArc_1 = Sketch_1.addArc(10.00000000000669, 34.14523516718319, 10.57357643635423, 33.32608312288851, 10, 35.14523516719186, False)
50 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchArc_1.startPoint(), SketchLine_2.startPoint())
51 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchLine_1.endPoint())
52 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_1.result())
53 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchLine_2.result())
54 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchArc_1.results()[1], 1)
55 SketchConstraintAngle_1 = Sketch_1.setAngle(SketchLine_3.result(), SketchLine_2.result(), "a2")
56 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_2.result(), "l2")
57 SketchConstraintAngle_2 = Sketch_1.setAngleBackward(SketchLine_2.result(), SketchLine_1.result(), "a1")
58 SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_1.startPoint(), SketchLine_6.result())
59 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result())
60 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_4.endPoint(), SketchAPI_Line(SketchLine_6).startPoint(), 3)
61 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_4.endPoint(), SketchAPI_Line(SketchLine_6).startPoint(), 3)
62 SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_1.result(), "l1/2")
63 SketchConstraintMirror_1_objects = [SketchLine_1.result(), SketchArc_1.results()[1], SketchLine_2.result(), SketchLine_3.result(), SketchLine_4.result()]
64 SketchConstraintMirror_1 = Sketch_1.addMirror(SketchLine_6.result(), SketchConstraintMirror_1_objects)
65 [SketchLine_7, SketchArc_2, SketchLine_8, SketchLine_9, SketchLine_10] = SketchConstraintMirror_1.mirrored()
66 SketchMultiRotation_1_objects = [SketchLine_10.result(), SketchLine_9.result(), SketchLine_8.result(), SketchArc_2.results()[1], SketchLine_7.result(), SketchLine_1.result(), SketchArc_1.results()[1], SketchLine_2.result(), SketchLine_3.result(), SketchLine_4.result()]
67 SketchMultiRotation_1 = Sketch_1.addRotation(SketchMultiRotation_1_objects, SketchAPI_Line(SketchLine_6).startPoint(), 360, 4, True)
68 [SketchLine_10, SketchLine_11, SketchLine_12, SketchLine_13, SketchLine_9, SketchLine_14, SketchLine_15, SketchLine_16, SketchLine_8, SketchLine_17, SketchLine_18, SketchLine_19, SketchArc_2, SketchArc_3, SketchArc_4, SketchArc_5, SketchLine_7, SketchLine_20, SketchLine_21, SketchLine_22, SketchLine_23, SketchLine_24, SketchLine_25, SketchArc_6, SketchArc_7, SketchArc_8, SketchLine_26, SketchLine_27, SketchLine_28, SketchLine_29, SketchLine_30, SketchLine_31, SketchLine_32, SketchLine_33, SketchLine_34] = SketchMultiRotation_1.rotated()
69 model.do()
70 Part_1 = model.addPart(partSet)
71 Part_1_doc = Part_1.document()
72 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "PartSet/Sketch_1")], model.selection(), 5, 0)
73 Fillet_1 = model.addFillet(Part_1_doc, [model.selection("FACE", "Extrusion_1_1/To_Face_1"), model.selection("FACE", "Extrusion_1_1/From_Face_1")], 1)
74 model.end()
75
76 # creation of the model time
77 creationTime = timer() - startTime
78 print("Creation time: {0}".format(creationTime))
79
80 # disable automatic recalculation, so, modification of parameters cause norecomputation immediately
81 from ModelAPI import *
82 aSession = ModelAPI_Session.get()
83 aSession.blockAutoUpdate(True)
84
85 #update parameters one by one
86 model.begin()
87 param_l1.setValue(15)
88 model.do()
89 param_l2.setValue(3)
90 model.do()
91 param_a1.setValue(20)
92 model.do()
93 param_a2.setValue(145)
94 model.end()
95
96 aSession.blockAutoUpdate(False)
97
98 # compute update parameters and recomputation of the model time
99 modificationTime = timer() - startTime - creationTime
100 print("Modification time: {0}".format(modificationTime))
101
102 # check that volume was recomputed in accordance to parameters
103 model.testResultsVolumes(Fillet_1, [3242.917586105217651493148878217])
104
105 # check that 4 modification of parameters was not slower than 2 update of model (without block it is minimum 3 times of creation time)
106 assert(modificationTime < 2. * creationTime)