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