Salome HOME
Unit tests for B-splines in the sketcher.
[modules/shaper.git] / src / SketchPlugin / Test / TestProjectionBSpline.py
1 # Copyright (C) 2019-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 salome.shaper import model
21
22 model.begin()
23 partSet = model.moduleDocument()
24 Part_1 = model.addPart(partSet)
25 Part_1_doc = Part_1.document()
26 Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10, 180)
27 Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Cylinder_1_1/Face_5"))
28 SketchCircle_1 = Sketch_1.addCircle(-0.87355746875896, 7.873567272779828, 3.095312696967586)
29 model.do()
30 ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), [model.selection("SOLID", "Cylinder_1_1")])
31 Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "ExtrusionCut_1_1")], model.selection("EDGE", "PartSet/OX"), 45)
32 Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_1][(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_1)(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_5)(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_4)(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_3)2]")], False)
33
34 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
35 SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Edge_1_1"), True)
36 SketchBSpline_1 = SketchProjection_1.createdFeature()
37 model.do()
38
39 Sketch_3 = model.addSketch(Part_1_doc, model.standardPlane("XOZ"))
40 SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "Edge_1_1"), True)
41 SketchBSpline_2 = SketchProjection_2.createdFeature()
42 model.do()
43
44 Sketch_4 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
45 SketchProjection_3 = Sketch_4.addProjection(model.selection("EDGE", "Edge_1_1"), True)
46 SketchBSpline_3 = SketchProjection_3.createdFeature()
47 model.do()
48
49 model.end()
50
51 from GeomAPI import *
52 import math
53
54 TOLERANCE = 1.e-7
55
56 def checkProjection(theBSpline3D, theBSpline2D, theFlags):
57     assert(theBSpline2D.isEdge() and theBSpline2D.edge().isBSpline())
58     poles2D = GeomAPI_BSpline(GeomAPI_Curve(theBSpline2D)).poles()
59     poles3D = theBSpline3D.poles()
60     assert(poles2D.size() == poles3D.size())
61     for p2d, p3d in zip(poles2D, poles3D):
62         assert(math.fabs((p2d.x() - p3d.x()) * theFlags.x()) < TOLERANCE and
63                math.fabs((p2d.y() - p3d.y()) * theFlags.y()) < TOLERANCE and
64                math.fabs((p2d.z() - p3d.z()) * theFlags.z()) < TOLERANCE)
65
66
67 bspline0 = GeomAPI_BSpline(GeomAPI_Curve(Edge_1.results()[-1].resultSubShapePair()[0].shape()))
68
69 bsplineShape1 = SketchBSpline_1.results()[-1].resultSubShapePair()[0].shape()
70 checkProjection(bspline0, bsplineShape1, GeomAPI_Pnt(1, 1, 0))
71
72 bsplineShape2 = SketchBSpline_2.results()[-1].resultSubShapePair()[0].shape()
73 checkProjection(bspline0, bsplineShape2, GeomAPI_Pnt(1, 0, 1))
74
75 bsplineShape3 = SketchBSpline_3.results()[-1].resultSubShapePair()[0].shape()
76 checkProjection(bspline0, bsplineShape3, GeomAPI_Pnt(0, 1, 1))
77
78 assert(model.checkPythonDump())