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