Salome HOME
Merge remote-tracking branch 'remotes/origin/2018_Lot1_Tasks'
[modules/shaper.git] / src / FeaturesPlugin / Test / TestMeasurementLength.py
1 ## Copyright (C) 2018-20xx  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 from salome.shaper import model
22
23 import math
24
25 model.begin()
26 partSet = model.moduleDocument()
27 Part_1 = model.addPart(partSet)
28 Part_1_doc = Part_1.document()
29 ParamR = model.addParameter(Part_1_doc, "R", "50")
30 ParamL = model.addParameter(Part_1_doc, "L", "40")
31 ParamH = model.addParameter(Part_1_doc, "H", "20")
32 Point_2 = model.addPoint(Part_1_doc, 0, 100, 100)
33 Plane_4 = model.addPlane(Part_1_doc, model.selection("EDGE", "PartSet/OX"), model.selection("VERTEX", "Point_1"), False)
34 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
35 SketchCircle_1 = Sketch_1.addCircle(50, 50, 50)
36 SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], "R")
37 SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OX"), False)
38 SketchLine_1 = SketchProjection_1.createdFeature()
39 SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_1.result(), SketchCircle_1.results()[1])
40 SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "PartSet/OY"), False)
41 SketchLine_2 = SketchProjection_2.createdFeature()
42 SketchConstraintTangent_2 = Sketch_1.setTangent(SketchLine_2.result(), SketchCircle_1.results()[1])
43 SketchLine_3 = Sketch_1.addLine(70, 40, 30, 40)
44 SketchLine_4 = Sketch_1.addLine(30, 40, 30, 60)
45 SketchLine_5 = Sketch_1.addLine(30, 60, 70, 60)
46 SketchLine_6 = Sketch_1.addLine(70, 60, 70, 40)
47 SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_6.endPoint(), SketchLine_3.startPoint())
48 SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
49 SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_5.startPoint())
50 SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_5.endPoint(), SketchLine_6.startPoint())
51 SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result())
52 SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_4.result())
53 SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_5.result())
54 SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_6.result())
55 SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_3.result(), "L")
56 SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_4.result(), "H")
57 SketchConstraintDistanceHorizontal_1 = Sketch_1.setHorizontalDistance(SketchLine_4.startPoint(), SketchCircle_1.center(), "L/2")
58 SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_4.startPoint(), SketchCircle_1.center(), "H/2")
59 model.do()
60 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2f-SketchLine_3f-SketchLine_4f-SketchLine_5f-SketchLine_6f")], model.selection(), model.selection("FACE", "Plane_1"), 0, model.selection(), 10)
61 model.do()
62
63 TOLERANCE = 1.e-6
64
65 # reference data
66 REF_DATA = [("Extrusion_1_1/From_Face_1&Extrusion_1_1/Generated_Face_1", ParamH.value()),
67             ("Extrusion_1_1/From_Face_1&Extrusion_1_1/Generated_Face_4", ParamL.value()),
68             ("Extrusion_1_1/Generated_Face_5&Extrusion_1_1/From_Face_1", ParamR.value() * 2.0 * math.pi),
69             ("Extrusion_1_1/Generated_Face_5&Extrusion_1_1/To_Face_1", 381.981436664),
70             ("Extrusion_1_1/Generated_Face_5", 60),
71             ("Sketch_1/Edge-SketchLine_3", ParamL.value()),
72             ("Sketch_1/Edge-SketchLine_4", ParamH.value()),
73             ("Sketch_1/Edge-SketchCircle_1_2", ParamR.value() * 2.0 * math.pi)
74            ]
75
76 for ref in REF_DATA:
77     length = model.measureLength(Part_1_doc, model.selection("EDGE", ref[0]))
78     assert(math.fabs(length - ref[1]) < TOLERANCE), "Length {} differs from expected value {}".format(length, ref[1])
79
80 # select incorrect data
81 length = model.measureLength(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face_5"))
82 assert(length == -1)
83
84 model.end()