]> SALOME platform Git repositories - modules/paravis.git/blob - src/PV_SWIG/no_wrap/pvsimple.py
Salome HOME
Merge branch 'abn/port_pv42' into abn/rearch
[modules/paravis.git] / src / PV_SWIG / no_wrap / pvsimple.py
1 # Copyright (C) 2010-2014  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19 # Author: Adrien Bruneton (CEA)
20
21 r""" This module is a direct forward to the initial 'simple' module of ParaView.
22 On top of that it also establishes a connection to a valid PVServer whose address
23 is provided by the PARAVIS engine.
24 """
25
26 from paraview.simple import *
27 import paraview.servermanager  # local import - see test on 'fromGUI' below
28 import paravis        ## Triggers the "FindOrLoadCompo(PARAVIS)"
29
30 def __my_log(msg):
31     print "[PARAVIS] %s" % msg
32
33 def SalomeConnectToPVServer():
34     __my_log("Connecting to PVServer ...")
35     server_url = ""
36     try:
37         server_url = paravis.myParavisEngine.FindOrStartPVServer(0)
38         # Extract host and port from URL:
39         a = server_url.split(':')
40         b = a[1].split('//')
41         host, port = b[-1], int(a[-1])
42         Connect(host, port)
43     except Exception as e:
44         __my_log("*******************************************")
45         __my_log("** Could not connect to a running PVServer!")
46         __my_log("*******************************************")
47         raise e
48     __my_log("Connected to %s!" % server_url)
49
50 # Automatically connect to the right PVServer when not inside SALOME GUI:
51 if not paraview.fromGUI: 
52   SalomeConnectToPVServer()