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 7608 2011-10-11T16:50:42.194214Z 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  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   
21 -class ServermanagerWrapper(object):
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 # 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) 45 lib=ctypes.CDLL(path.join(environ["FOAM_LIBBIN"],"libOpenFOAM.dylib"),mode=ctypes.RTLD_GLOBAL) 46 # lib=ctypes.CDLL(path.join(environ["FOAM_LIBBIN"],"paraview","libPV3FoamReader.dylib"),mode=ctypes.RTLD_GLOBAL) 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
109 - def __getattr__(self,attr):
110 """Delegate Attributes to the servermanager-module""" 111 112 return getattr(servermanager,attr)
113
114 - def __setattr__(self,attr,val):
115 """Delegate Attributes to the servermanager-module""" 116 117 return setattr(servermanager,attr,val)
118
119 - def module(self):
120 """Return the actual module (for developing)""" 121 return servermanager
122
123 - def __del__(self):
124 """Make sure that everything gets thrown out. Doesn't work""" 125 # print dir(servermanager) 126 for v in servermanager.GetRenderViews(): 127 del v 128 self.module().Disconnect(self.con) 129 self.con=None
130 # self.module().Finalize() 131