1
2 """ Wrapper class for the paraview servermanager
3
4 Sets up the servermanager to be used with OpenFOAM-Data. Especially makes sure that
5 the plugins for the OpenFOAM-Data are loaded"""
6
7 from math import sqrt
8 from paraview import servermanager
9 from PyFoam.Paraview import version
10 if version()>=(3,6):
11 from paraview import simple
12
13 from os import environ,path,uname
14
15 from PyFoam.Error import error
16
18 """Wrapper class for the servermanager
19
20 Load the plugins and build a connection"""
21
23 """Sets up the Servermanager in such a way that it is usable
24 with OpenFOAM-data."""
25
26 self.con=servermanager.Connect()
27
28 dyExt="so"
29 if uname()[0]=="Darwin":
30 dyExt="dylib"
31 elif uname()[0]=="Linux":
32 try:
33 import ctypes
34 lib=ctypes.CDLL(path.join(environ["FOAM_LIBBIN"],"libPV3FoamReader.so"),mode=ctypes.RTLD_GLOBAL)
35 except ImportError:
36 error("The Workaround for Linux-Systems won't work because there is no ctypes library")
37
38 plug1="libPV3FoamReader."+dyExt
39 plug2="libPV3FoamReader_SM."+dyExt
40
41 loaded=False
42 for p in environ["PV_PLUGIN_PATH"].split(":"):
43 if path.exists(path.join(p,plug1)):
44 if version()>=(3,6):
45 simple.LoadPlugin(path.join(p,plug1),ns=globals())
46 try:
47 simple.LoadPlugin(path.join(p,plug2),ns=globals())
48 except NameError:
49 print dir(self.module())
50 pass
51 else:
52 servermanager.LoadPlugin(path.join(p,plug1))
53 servermanager.LoadPlugin(path.join(p,plug2))
54 loaded=True
55 break
56
57 if not loaded:
58 error("The plugin",plug1,"was not found in the PV_PLUGIN_PATH",environ["PV_PLUGIN_PATH"])
59 if not "PV3FoamReader" in dir(servermanager.sources):
60 error("The plugin was not properly loaded. PV3FoamReader not found in the list of sources")
61
63 """Delegate Attributes to the servermanager-module"""
64
65 return getattr(servermanager,attr)
66
68 """Delegate Attributes to the servermanager-module"""
69
70 return setattr(servermanager,attr,val)
71
73 """Return the actual module (for developing)"""
74 return servermanager
75