Salome HOME
Updated copyright comment
[modules/shaper.git] / src / SketchPlugin / Test / TestProjectionBSplinePeriodic.py
1 # Copyright (C) 2019-2024  CEA, EDF
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 Point_2 = model.addPoint(Part_1_doc, -10, 5, 10)
27 Point_3 = model.addPoint(Part_1_doc, -5, 10, 15)
28 Point_4 = model.addPoint(Part_1_doc, 10, 0, 20)
29 Point_5 = model.addPoint(Part_1_doc, 10, -10, 15)
30 Point_6 = model.addPoint(Part_1_doc, -5, -5, 12)
31 Interpolation_1_objects = [model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"), model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_4"), model.selection("VERTEX", "Point_5")]
32 Interpolation_1 = model.addInterpolation(Part_1_doc, Interpolation_1_objects, True, False)
33
34 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
35 SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Interpolation_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", "Interpolation_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", "Interpolation_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(Interpolation_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())