Salome HOME
Update copyright information
[modules/smesh.git] / src / Tools / padder / spadderpy / __init__.py
1 # Copyright (C) 2011-2012  EDF R&D
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Author(s): Guillaume Boulant (23/03/2011)
20 #
21
22 # TODO: put all this stuff in the unitests package
23
24 import os
25 def getRootDir():
26     '''
27     This returns the root directory where the module SPADDER is
28     installed. All test files are looked up from this location.
29     '''
30     return os.environ['SMESH_ROOT_DIR']
31
32 def getTestDataDir():
33     '''
34     This function gives the absolute path to the directory containing
35     the data files for test (realistic med files).
36     '''
37     datadir=os.path.join(getRootDir(),"share/salome/resources/smesh/padderexe")
38     return datadir
39
40 import MESHJOB # to get the enum constant values
41 from MESHJOB import MeshJobParameter, MeshJobParameterList
42
43 DEFAULT_CONCRETE_FILENAME=os.path.join(getTestDataDir(),'concrete.med')
44 DEFAULT_STEELBAR_LISTFILENAME=[
45     os.path.join(getTestDataDir(),'ferraill.med')
46     ]
47
48 def getMeshJobParameterList(concrete_filename=DEFAULT_CONCRETE_FILENAME,
49                             steelbar_listfilename=DEFAULT_STEELBAR_LISTFILENAME):
50     '''
51     This helper function creates a complete set of parameters (a
52     MeshJobParameterList) for a simple test case, i.e. a case with a
53     concrete filename and a single steelbar filename.
54     '''
55     # Note that a CORBA sequence (MeshJobParameterList) is mapped on a
56     # simple list in python
57     meshJobParameterList = []
58     # We can add some parameters
59     param = MeshJobParameter(
60         file_name  = concrete_filename,
61         file_type  = MESHJOB.MED_CONCRETE,
62         group_name = "concrete")
63     meshJobParameterList.append(param)
64
65     for steelbar_filename in steelbar_listfilename:
66         param = MeshJobParameter(
67             file_name  = steelbar_filename,
68             file_type  = MESHJOB.MED_STEELBAR,
69             group_name = "steelbar")
70         meshJobParameterList.append(param)
71
72     return meshJobParameterList
73
74
75 def getSpadderCatalogFilename():
76     filename=os.path.join(getRootDir(),"share/salome/resources/smesh/SPADDERCatalog.xml")
77     return filename
78
79 def loadSpadderCatalog():
80     import salome
81     salome.salome_init()
82     obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
83     import SALOME_ModuleCatalog
84     catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
85     if not catalog:
86         raise RuntimeError, "Can't accesss module catalog"
87
88     filename = getSpadderCatalogFilename()
89     catalog.ImportXmlCatalogFile(filename)
90
91     from salome.kernel import services
92     print "The list of SALOME components is now:" 
93     print services.getComponentList()