Salome HOME
e200943c1664d73f026fe423c0423b9675d6716e
[modules/geom.git] / bin / geom_test.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2023  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import unittest
22
23 class TestGeometry(unittest.TestCase):
24
25     def setUp(self):
26         import salome
27         salome.salome_init()
28
29     def processGuiEvents(self):
30         import salome
31         if salome.sg.hasDesktop():
32             salome.sg.updateObjBrowser();
33             import SalomePyQt
34             SalomePyQt.SalomePyQt().processEvents()
35
36     def test_geometry(self):
37         """Quick test for Geometry module"""
38
39         print()
40         print('Testing Geometry module')
41
42         from salome.geom import geomBuilder
43         geompy = geomBuilder.New()
44
45         # ---- create box
46         print('... Create box')
47         box = geompy.MakeBox(0., 0., 0., 100., 200., 300, theName='box')
48         self.assertIsNotNone(box)
49         self.assertEqual(box.GetName(), 'box')
50         self.processGuiEvents()
51
52         # ---- extract shell from box
53         print('... Extract shell from box')
54         shells = geompy.SubShapeAll(box, geompy.ShapeType['SHELL'], theName=['shell'])
55         self.assertEqual(len(shells), 1)
56         shell = shells[0]
57         self.assertIsNotNone(shell)
58         self.assertEqual(shell.GetName(), 'shell')
59         self.processGuiEvents()
60
61         # ---- extract faces from box
62         print('... Extract faces from box')
63         faces = geompy.SubShapeAll(box, geompy.ShapeType['FACE'], theName='face')
64         self.assertEqual(len(faces), 6)
65         for i, face in enumerate(faces):
66             self.assertIsNotNone(face)
67             self.assertEqual(face.GetName(), 'face_{}'.format(i+1))
68         self.processGuiEvents()
69
70         # ---- extract edges from 1st face
71         print('... Extract edges from 1st face')
72         edges = geompy.SubShapeAll(faces[0], geompy.ShapeType['EDGE'], theName='edge')
73         self.assertEqual(len(edges), 4)
74         for i, edge in enumerate(edges):
75             self.assertIsNotNone(edge)
76             self.assertEqual(edge.GetName(), 'edge_{}'.format(i+1))
77         self.processGuiEvents()
78
79 if __name__ == '__main__':
80     unittest.main()