Package PyFoam :: Package Paraview :: Module ServermanagerWrapper
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Paraview.ServermanagerWrapper

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