/
pvw-flow.py
123 lines (92 loc) · 5.1 KB
/
pvw-flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
r"""
This module is a ParaViewWeb server application.
The following command line illustrates how to use it::
$ pvpython -dr /.../pvw-flow.py --data /path/to/pfmetadata/file
--data /.../
Path to a pfmetadata file
Any ParaViewWeb executable script comes with a set of standard arguments that can be overriden if need be::
--port 8080
Port number on which the HTTP server will listen.
--content /path-to-web-content/
Directory that you want to serve as static web content.
By default, this variable is empty which means that we rely on another
server to deliver the static content and the current process only
focuses on the WebSocket connectivity of clients.
--authKey vtkweb-secret
Secret key that should be provided by the client to allow it to make
any WebSocket communication. The client will assume if none is given
that the server expects "vtkweb-secret" as secret key.
"""
# import to process args
import os
import sys
import argparse
# Try handle virtual env if provided
if '--virtual-env' in sys.argv:
virtualEnvPath = sys.argv[sys.argv.index('--virtual-env') + 1]
virtualEnv = virtualEnvPath + '/bin/activate_this.py'
execfile(virtualEnv, dict(__file__=virtualEnv))
# import paraview modules.
from paraview.web import pv_wslink
from paraview.web import protocols as pv_protocols
# import RPC annotation
from wslink import register as exportRpc
from paraview import simple
from wslink import server
from flow import api as flow_protocols
# =============================================================================
# Create custom Pipeline Manager class to handle clients requests
# =============================================================================
class _Server(pv_wslink.PVServerProtocol):
authKey = "wslink-secret"
viewportScale=1.0
viewportMaxWidth=2560
viewportMaxHeight=1440
settingsLODThreshold = 102400
@staticmethod
def add_arguments(parser):
parser.add_argument("--data", default=os.getcwd(), help="path to the base directory", dest="path")
parser.add_argument("--load-file", default=None, help="File to load if any based on data-dir base path", dest="file")
parser.add_argument("--virtual-env", default=None, help="Path to virtual environment to use")
parser.add_argument("--viewport-scale", default=1.0, type=float, help="Viewport scaling factor", dest="viewportScale")
parser.add_argument("--viewport-max-width", default=2560, type=int, help="Viewport maximum size in width", dest="viewportMaxWidth")
parser.add_argument("--viewport-max-height", default=1440, type=int, help="Viewport maximum size in height", dest="viewportMaxHeight")
parser.add_argument("--settings-lod-threshold", default=102400, type=int, help="LOD Threshold in Megabytes", dest="settingsLODThreshold")
@staticmethod
def configure(args):
_Server.dataset = os.path.join(args.path, args.file)
_Server.authKey = args.authKey
_Server.viewportScale = args.viewportScale
_Server.viewportMaxWidth = args.viewportMaxWidth
_Server.viewportMaxHeight = args.viewportMaxHeight
_Server.settingsLODThreshold = args.settingsLODThreshold
def initialize(self):
# Bring used components from ParaView
self.registerVtkWebProtocol(pv_protocols.ParaViewWebMouseHandler())
self.registerVtkWebProtocol(pv_protocols.ParaViewWebViewPort(_Server.viewportScale, _Server.viewportMaxWidth, _Server.viewportMaxHeight))
self.registerVtkWebProtocol(pv_protocols.ParaViewWebPublishImageDelivery(decode=False))
# Bring used components from ParaView Lite
self.registerVtkWebProtocol(flow_protocols.FlowProtocol(filepath = _Server.dataset))
# Update authentication key to use
self.updateSecret(_Server.authKey)
# tell the C++ web app to use no encoding. ParaViewWebPublishImageDelivery must be set to decode=False to match.
self.getApplication().SetImageEncoding(0);
# ProxyManager helper
pxm = simple.servermanager.ProxyManager()
renderingSettings = pxm.GetProxy('settings', 'RenderViewSettings')
renderingSettings.LODThreshold = _Server.settingsLODThreshold
interactionProxy = pxm.GetProxy('settings', 'RenderViewInteractionSettings')
interactionProxy.Camera3DManipulators = ['Rotate', 'Pan', 'Zoom', 'Pan', 'Roll', 'Pan', 'Zoom', 'Rotate', 'Zoom']
# =============================================================================
# Main: Parse args and start server
# =============================================================================
if __name__ == "__main__":
# Create argument parser
parser = argparse.ArgumentParser(description="ParaView Flow - ParaViewWeb viewer for ParFlow data")
# Add arguments
server.add_arguments(parser)
_Server.add_arguments(parser)
args = parser.parse_args()
_Server.configure(args)
# Start server
server.start_webserver(options=args, protocol=_Server)