Salome HOME
[PY3] 2to3 results
[modules/smesh.git] / src / Tools / padder / spadderpy / __init__.py
1 # Copyright (C) 2011-2016  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, or (at your option) any later version.
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
20 # Author(s): Guillaume Boulant (23/03/2011)
21 #
22
23 # TODO: put all this stuff in the unitests package
24
25 import os
26 def getRootDir():
27     '''
28     This returns the root directory where the module SPADDER is
29     installed. All test files are looked up from this location.
30     '''
31     return os.environ['SMESH_ROOT_DIR']
32
33 def getTestDataDir():
34     '''
35     This function gives the absolute path to the SMESH directory
36     containing the data files for the padder plugin test (realistic
37     med files).
38     '''
39     datadir = os.path.join(getRootDir(),"share/salome/resources/smesh/padderdata")
40     return datadir
41
42 def getTestPadderDataDir():
43     """
44     This function gives the absolute path to the PADDER directory
45     containing the data files for the padder plugin test. WARNING:
46     this directory is a directory of the external program SpherePadder
47     that is wrapped by the padder plugin. We use the shell variable
48     PADDERHOME (defined by the SALOME environment) to localize this
49     folder. 
50     """
51     PADDERHOME = os.environ['PADDERHOME']
52     datadir = os.path.join(PADDERHOME,"tests")
53     return datadir
54
55 import MESHJOB # to get the enum constant values
56 from MESHJOB import MeshJobFile, MeshJobFileList
57
58 DEFAULT_CONCRETE_FILENAME=os.path.join(getTestDataDir(),'concrete.med')
59 DEFAULT_STEELBAR_LISTFILENAME=[
60     os.path.join(getTestDataDir(),'ferraill.med')
61     ]
62
63 def getMeshJobFileList(concrete_filename=DEFAULT_CONCRETE_FILENAME,
64                             steelbar_listfilename=DEFAULT_STEELBAR_LISTFILENAME):
65     '''
66     This helper function creates a complete set of parameters (a
67     MeshJobFileList) for a simple test case, i.e. a case with a
68     concrete filename and a single steelbar filename.
69     '''
70     # Note that a CORBA sequence (MeshJobFileList) is mapped on a
71     # simple list in python
72     meshJobFileList = []
73     # We can add some parameters
74     param = MeshJobFile(
75         file_name  = concrete_filename,
76         file_type  = MESHJOB.MED_CONCRETE,
77         group_name = "concrete")
78     meshJobFileList.append(param)
79
80     for steelbar_filename in steelbar_listfilename:
81         param = MeshJobFile(
82             file_name  = steelbar_filename,
83             file_type  = MESHJOB.MED_STEELBAR,
84             group_name = "steelbar")
85         meshJobFileList.append(param)
86
87     return meshJobFileList
88
89
90 def getSpadderCatalogFilename():
91     filename=os.path.join(getRootDir(),"share/salome/resources/smesh/SPADDERCatalog.xml")
92     return filename
93
94 def loadSpadderCatalog():
95     import salome
96     salome.salome_init()
97     obj = salome.naming_service.Resolve('Kernel/ModulCatalog')
98     import SALOME_ModuleCatalog
99     catalog = obj._narrow(SALOME_ModuleCatalog.ModuleCatalog)
100     if not catalog:
101         raise RuntimeError("Can't accesss module catalog")
102
103     filename = getSpadderCatalogFilename()
104     catalog.ImportXmlCatalogFile(filename)
105
106     from salome.kernel import services
107     print("The list of SALOME components is now:") 
108     print(services.getComponentList())