1 # Copyright (C) 2014-2022 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from salome.shaper import model
23 from ModelAPI import *
25 class AxisTestCase(unittest.TestCase):
28 self.doc = model.moduleDocument()
32 assert(model.checkPythonDump())
33 ModelAPI_Session.get().closeAll()
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())
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)
45 self.assertAlmostEqual(p2.x(), x2, 6)
46 self.assertAlmostEqual(p2.y(), y2, 6)
47 self.assertAlmostEqual(p2.z(), z2, 6)
50 def test_axis_by_dimensions(self):
51 """ Test 1. Create axis starting from Origin with the given dimensions
53 axis = model.addAxis(self.doc, 10, 50, 100)
54 self.checkAxis(axis, 0, 0, 0, 10, 50, 100)
56 def test_axis_by_points(self):
57 """ Test 2. Create axis between pair of points
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)
63 def test_axis_by_point_and_plane(self):
64 """ Test 3. Create axis orthogonal to a plane and passing through a point
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)
70 def test_axis_by_line(self):
71 """ Test 4. Create axis by edge on a box
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)
78 def test_axis_by_cylinder(self):
79 """ Test 5. Create axis by cylindrical face
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)
86 def test_axis_by_point_and_direction(self):
87 """ Test 6. Create axis starting from a point with a given direction
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)
93 def test_axis_by_planes(self):
94 """ Test 7. Create axis as intersection of two planes
96 axis = model.addAxis(self.doc, model.selection("FACE", "XOZ"), model.selection("FACE", "YOZ"))
97 self.checkAxis(axis, 0, 0, 0, 0, 0, 100)
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)
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)
106 if __name__ == "__main__":
107 test_program = unittest.main(exit=False)
108 assert test_program.result.wasSuccessful(), "Test failed"