Salome HOME
Add tests for connection with SHAPERSTUDY
[modules/smesh.git] / bin / smesh_test.py
1 #  -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2018-2019  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 TestMesh(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_mesh(self):
37         """Quick test for Mesh module"""
38
39         print()
40         print('Testing Mesh module')
41
42         # ==== Geometry part ====
43
44         from salome.geom import geomBuilder
45         geompy = geomBuilder.New()
46
47         # ---- create box
48         print('... Create box')
49         box = geompy.MakeBox(0., 0., 0., 100., 200., 300)
50         self.assertIsNotNone(box)
51         self.processGuiEvents()
52
53         # ==== Mesh part ====
54
55         import SMESH
56         from salome.smesh import smeshBuilder
57         smesh = smeshBuilder.New()
58         lib = 'StdMeshersEngine'
59         self.processGuiEvents()
60
61         # ---- create hypotheses 
62         print('... Create hypotheses')
63
64         # **** create local length 
65         print('...... Local Length')
66         local_length = smesh.CreateHypothesis('LocalLength', lib)
67         self.assertIsNotNone(local_length)
68         local_length.SetLength(100)
69         self.assertEqual(local_length.GetName(), 'LocalLength')
70         self.assertEqual(local_length.GetLength(), 100)
71         self.processGuiEvents()
72
73         # **** create number of segments
74         print('...... Number Of Segments')
75         nb_segments= smesh.CreateHypothesis('NumberOfSegments', lib)
76         self.assertIsNotNone(nb_segments)
77         nb_segments.SetNumberOfSegments(7)
78         self.assertEqual(nb_segments.GetName(), 'NumberOfSegments')
79         self.assertEqual(nb_segments.GetNumberOfSegments(), 7)
80         self.processGuiEvents()
81
82         # **** create max element area
83         print('...... Max Element Area')
84         max_area = smesh.CreateHypothesis('MaxElementArea', lib)
85         max_area.SetMaxElementArea(2500)
86         self.assertEqual(max_area.GetName(), 'MaxElementArea')
87         self.assertEqual(max_area.GetMaxElementArea(), 2500)
88         self.processGuiEvents()
89
90         # ---- create algorithms
91         print('... Create algorithms')
92
93         # **** create regular 1d
94         print('...... Regular 1D')
95         regular = smesh.CreateHypothesis('Regular_1D', lib)
96         listHyp = regular.GetCompatibleHypothesis()
97         self.assertEqual(regular.GetName(), 'Regular_1D')
98         self.processGuiEvents()
99
100         # **** create mefisto 2d
101         print('...... Mefisto 2D')
102         mefisto = smesh.CreateHypothesis( 'MEFISTO_2D', lib )
103         listHyp = mefisto.GetCompatibleHypothesis()
104         self.assertEqual(mefisto.GetName(), 'MEFISTO_2D')
105         self.processGuiEvents()
106
107         # ---- create mesh on box
108         print('... Create mesh on box')
109         mesh = smesh.CreateMesh(box)
110         self.assertEqual(mesh.AddHypothesis(box, regular)[0], SMESH.HYP_OK)
111         self.assertEqual(mesh.AddHypothesis(box, mefisto)[0], SMESH.HYP_OK)
112         self.assertEqual(mesh.AddHypothesis(box, nb_segments)[0], SMESH.HYP_OK)
113         self.assertEqual(mesh.AddHypothesis(box, max_area)[0], SMESH.HYP_OK)
114         self.processGuiEvents()
115
116         # ---- compute mesh
117         print('... Compute mesh')
118         self.assertEqual(smesh.Compute(mesh, box), True)
119         self.processGuiEvents()
120
121 if __name__ == '__main__':
122     unittest.main()