Salome HOME
b82b8e0fb490c1bb530350fbf836c07afc8e84d2
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPluginBuilder.py
1 # Copyright (C) 2012-2015  ALNEOS
2 # Copyright (C) 2016-2023  EDF R&D
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.alneos.com/ or email : contact@alneos.fr
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 ##
23 # @package GMSHPluginBuilder
24 # Python API for the GMSH meshing plug-in module.
25
26 from salome.smesh.smesh_algorithm import Mesh_Algorithm
27
28 # import GMSHPlugin module if possible
29 noGMSHPlugin = 0
30 try:
31     import GMSHPlugin
32 except ImportError:
33     noGMSHPlugin = 1
34     pass
35
36 # Types of algorithms
37 GMSH = "GMSH"
38 GMSH_3D       = "GMSH_3D"
39 GMSH_2D       = "GMSH_2D"
40
41 ## Base of all GMSH algorithms.
42 #
43 class GMSH_Algorithm(Mesh_Algorithm):
44     
45     meshMethod = "Tetrahedron"
46     algoType   = GMSH
47     
48     def __init__(self, mesh, geom=0):
49         Mesh_Algorithm.__init__(self)
50         if noGMSHPlugin: print("Warning: GMSHPlugin module unavailable")
51         self.Create(mesh, geom, self.algoType, "libGMSHEngine.so")
52         self.params = None
53
54     ## Defines hypothesis having several parameters
55     #
56     def Parameters(self):
57         if self.algoType == GMSH_2D:
58             hypType = "GMSH_Parameters_2D"
59         elif self.algoType == GMSH:
60             hypType = "GMSH_Parameters"
61         elif self.algoType == GMSH_3D:
62             hypType = "GMSH_Parameters_3D"
63
64         if self.params and self.params.GetName() != hypType:
65             self.mesh.RemoveHypothesis( self.params, self.geom )
66             self.params = None
67         if not self.params:
68             self.params = self.Hypothesis(hypType, [],"libGMSHEngine.so",UseExisting=0)
69         return self.params
70
71 class GMSH_2D_Algorithm(GMSH_Algorithm):
72     
73     meshMethod = "Triangle"
74     algoType   = GMSH_2D
75     
76     ## Private constructor.
77     def __init__(self, mesh, geom=0):
78         GMSH_Algorithm.__init__(self, mesh, geom)
79
80 class GMSH_3D_Algorithm(GMSH_Algorithm):
81     
82      meshMethod = "Tetrahedron"
83      algoType   = GMSH_3D
84
85      ## Private constructor.
86      def __init__(self, mesh, geom=0):
87          GMSH_Algorithm.__init__(self, mesh, geom)