Salome HOME
Merge from V6_main 13/12/2012
[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 SMESH directory
35     containing the data files for the padder plugin test (realistic
36     med files).
37     '''
38     datadir = os.path.join(getRootDir(),"share/salome/resources/smesh/padderdata")
39     return datadir
40
41 def getTestPadderDataDir():
42     """
43     This function gives the absolute path to the PADDER directory
44     containing the data files for the padder plugin test. WARNING:
45     this directory is a directory of the external program SpherePadder
46     that is wrapped by the padder plugin. We use the shell variable
47     PADDERHOME (defined by the SALOME environment) to localize this
48     folder. 
49     """
50     PADDERHOME = os.environ['PADDERHOME']
51     datadir = os.path.join(PADDERHOME,"tests")
52     return datadir
53
54 import MESHJOB # to get the enum constant values
55 from MESHJOB import MeshJobParameter, MeshJobParameterList
56
57 DEFAULT_CONCRETE_FILENAME=os.path.join(getTestDataDir(),'concrete.med')
58 DEFAULT_STEELBAR_LISTFILENAME=[
59     os.path.join(getTestDataDir(),'ferraill.med')
60     ]
61
62 def getMeshJobParameterList(concrete_filename=DEFAULT_CONCRETE_FILENAME,
63                             steelbar_listfilename=DEFAULT_STEELBAR_LISTFILENAME):
64     '''
65     This helper function creates a complete set of parameters (a
66     MeshJobParameterList) for a simple test case, i.e. a case with a
67     concrete filename and a single steelbar filename.
68     '''
69     # Note that a CORBA sequence (MeshJobParameterList) is mapped on a
70     # simple list in python
71     meshJobParameterList = []
72     # We can add some parameters
73     param = MeshJobParameter(
74         file_name  = concrete_filename,
75         file_type  = MESHJOB.MED_CONCRETE,
76         group_name = "concrete")
77     meshJobParameterList.append(param)
78
79     for steelbar_filename in steelbar_listfilename:
80         param = MeshJobParameter(
81             file_name  = steelbar_filename,
82             file_type  = MESHJOB.MED_STEELBAR,
83             group_name = "steelbar")
84         meshJobParameterList.append(param)
85
86     return meshJobParameterList
87
88
89 def getSpadderCatalogFilename():
90     filename=os.path.join(getRootDir(),"share/salome/resources/smesh/SPADDERCatalog.xml")
91     return filename
92
93 def loadSpadderCatalog():
94     import salome
95     salome.salome_init()
96     obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
97     import SALOME_ModuleCatalog
98     catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
99     if not catalog:
100         raise RuntimeError, "Can't accesss module catalog"
101
102     filename = getSpadderCatalogFilename()
103     catalog.ImportXmlCatalogFile(filename)
104
105     from salome.kernel import services
106     print "The list of SALOME components is now:" 
107     print services.getComponentList()