Salome HOME
updated copyright message
[modules/shaper.git] / src / ConstructionAPI / Test / TestAxis.py
1 # Copyright (C) 2014-2023  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 import unittest
21 from salome.shaper import model
22 from GeomAPI import *
23 from ModelAPI import *
24
25 class AxisTestCase(unittest.TestCase):
26
27     def setUp(self):
28         self.doc = model.moduleDocument()
29
30     def tearDown(self):
31         model.end()
32         assert(model.checkPythonDump())
33         ModelAPI_Session.get().closeAll()
34
35     def checkAxis(self, axis, x1, y1, z1, x2, y2, z2):
36         edge = GeomAPI_Edge(axis.results()[0].resultSubShapePair()[0].shape())
37         self.assertTrue(edge.isLine())
38
39         p1 = edge.firstPoint()
40         self.assertAlmostEqual(p1.x(), x1, 6)
41         self.assertAlmostEqual(p1.y(), y1, 6)
42         self.assertAlmostEqual(p1.z(), z1, 6)
43
44         p2 = edge.lastPoint()
45         self.assertAlmostEqual(p2.x(), x2, 6)
46         self.assertAlmostEqual(p2.y(), y2, 6)
47         self.assertAlmostEqual(p2.z(), z2, 6)
48
49
50     def test_axis_by_dimensions(self):
51         """ Test 1. Create axis starting from Origin with the given dimensions
52         """
53         axis = model.addAxis(self.doc, 10, 50, 100)
54         self.checkAxis(axis, 0, 0, 0, 10, 50, 100)
55
56     def test_axis_by_points(self):
57         """ Test 2. Create axis between pair of points
58         """
59         model.addPoint(self.doc, 10, 0, 0)
60         axis = model.addAxis(self.doc, model.selection("VERTEX", "Origin"), model.selection("VERTEX", "Point_2"))
61         self.checkAxis(axis, 0, 0, 0, 10, 0, 0)
62
63     def test_axis_by_point_and_plane(self):
64         """ Test 3. Create axis orthogonal to a plane and passing through a point
65         """
66         model.addPoint(self.doc, 10, 0, 0)
67         axis = model.addAxis(self.doc, model.selection("FACE", "YOZ"), model.selection("VERTEX", "Point_2"))
68         self.checkAxis(axis, 10, 0, 0, 0, 0, 0)
69
70     def test_axis_by_line(self):
71         """ Test 4. Create axis by edge on a box
72         """
73         partDoc = model.addPart(self.doc).document()
74         model.addBox(partDoc, 10, 10, 10)
75         axis = model.addAxis(partDoc, model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Left]"))
76         self.checkAxis(axis, 10, 0, 0, 10, 0, 10)
77
78     def test_axis_by_cylinder(self):
79         """ Test 5. Create axis by cylindrical face
80         """
81         partDoc = model.addPart(self.doc).document()
82         model.addCylinder(partDoc, 5, 10)
83         axis = model.addAxis(partDoc, model.selection("FACE", "Cylinder_1_1/Face_1"))
84         self.checkAxis(axis, 0, 0, -1, 0, 0, 11)
85
86     def test_axis_by_point_and_direction(self):
87         """ Test 6. Create axis starting from a point with a given direction
88         """
89         model.addPoint(self.doc, 10, 0, 0)
90         axis = model.addAxis(self.doc, model.selection("VERTEX", "Point_2"), 10, 20, 30)
91         self.checkAxis(axis, 10, 0, 0, 20, 20, 30)
92
93     def test_axis_by_planes(self):
94         """ Test 7. Create axis as intersection of two planes
95         """
96         axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), model.selection("FACE", "YOZ"))
97         self.checkAxis(axis, 0, 0, 0, 0, 0, 100)
98
99         axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), 10, False, model.selection("FACE", "YOZ"))
100         self.checkAxis(axis, 0, -10, 0, 0, -10, 100)
101
102         axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), model.selection("FACE", "YOZ"), 10, False)
103         self.checkAxis(axis, 10, 0, 0, 10, 0, 100)
104
105
106 if __name__ == "__main__":
107     test_program = unittest.main(exit=False)
108     assert test_program.result.wasSuccessful(), "Test failed"