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
9 from paraview import servermanager
10 from PyFoam.Paraview import version
11 from PyFoam.FoamInformation import foamVersion
12
13 if version()>=(3,6):
14 from paraview.simple import LoadPlugin
15 from paraview import simple
16
17 from os import environ,path,uname
18
19 from PyFoam.Error import error,warning
20
22 """Wrapper class for the servermanager
23
24 Load the plugins and build a connection"""
25
26 - def __init__(self,requiredReader="PV3FoamReader"):
27 """Sets up the Servermanager in such a way that it is usable
28 with OpenFOAM-data.
29 @param requiredReader: Reader that is needed. If not found, try to load plugins"""
30
31 self.con=self.module().Connect()
32
33 dyExt="so"
34 if uname()[0]=="Darwin":
35 dyExt="dylib"
36
37 if requiredReader in dir(simple) and not "OpenFOAMReader":
38 warning("Reader",requiredReader,"already present. No plugins loaded")
39 return
40
41 if requiredReader=="PV3FoamReader":
42 if uname()[0]=="Darwin":
43 import ctypes
44
45 lib=ctypes.CDLL(path.join(environ["FOAM_LIBBIN"],"libOpenFOAM.dylib"),mode=ctypes.RTLD_GLOBAL)
46
47 print lib
48 elif uname()[0]=="Linux":
49 try:
50 import ctypes
51 dirs=[environ["FOAM_LIBBIN"]]+environ["PV_PLUGIN_PATH"].split(":")
52 lib=None
53 for d in dirs:
54 try:
55 lib=ctypes.CDLL(path.join(d,"libPV3FoamReader.so"),mode=ctypes.RTLD_GLOBAL)
56 break
57 except OSError:
58 pass
59 if not lib:
60 warning("Could not find libPV3FoamReader.so in",dirs)
61 except ImportError:
62 error("The Workaround for Linux-Systems won't work because there is no ctypes library")
63
64 plug1="libPV3FoamReader."+dyExt
65 if foamVersion()>=(1,7):
66 plug1=None
67
68 plug2="libPV3FoamReader_SM."+dyExt
69
70 loaded=False
71 for p in environ["PV_PLUGIN_PATH"].split(":"):
72 if path.exists(path.join(p,plug2)):
73 if version()>=(3,6):
74 LoadPlugin(path.join(p,plug2),ns=globals())
75 try:
76 if plug1:
77 LoadPlugin(path.join(p,plug1),ns=globals())
78 pass
79 except NameError:
80 print dir(self.module())
81 pass
82 else:
83 if plug1:
84 servermanager.LoadPlugin(path.join(p,plug1))
85 servermanager.LoadPlugin(path.join(p,plug2))
86 loaded=True
87 break
88
89 if not loaded:
90 error("The plugin",plug2,"was not found in the PV_PLUGIN_PATH",environ["PV_PLUGIN_PATH"])
91 if not "PV3FoamReader" in dir(servermanager.sources):
92 error("The plugin was not properly loaded. PV3FoamReader not found in the list of sources")
93 elif requiredReader=="OpenFOAMReader":
94 if "ParaView_DIR" in environ:
95 hasPlug=False
96 for d in ["plugins","Plugins"]:
97 plug=path.join(environ["ParaView_DIR"],"bin",d,"libPOpenFOAMReaderPlugin."+dyExt)
98 if path.exists(plug):
99 LoadPlugin(plug)
100 hasPlug=True
101 break
102 if not hasPlug:
103 warning("Can't find expected plugin 'libPOpenFOAMReaderPlugin' assuming that correct reader is compiled in. Wish me luck")
104 else:
105 warning("Can't plugin without ParaView_DIR-variable. Continuing without")
106 else:
107 warning("Loading of plugins for reader",requiredReader,"not implemented")
108
110 """Delegate Attributes to the servermanager-module"""
111
112 return getattr(servermanager,attr)
113
115 """Delegate Attributes to the servermanager-module"""
116
117 return setattr(servermanager,attr,val)
118
120 """Return the actual module (for developing)"""
121 return servermanager
122
124 """Make sure that everything gets thrown out. Doesn't work"""
125
126 for v in servermanager.GetRenderViews():
127 del v
128 self.module().Disconnect(self.con)
129 self.con=None
130
131