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