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