1 # Copyright (C) 2010-2015 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 # Author: Adrien Bruneton (CEA)
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 PVSERVER engine.
26 __DEBUG = 0 # increase if you want more verbosity
30 print "[PARAVIS] %s" % msg
33 """ Identify if we are running inside SALOME's embedded interpreter.
34 @return a value strictly greater than 0 if we are in SALOME's embedded interpreter
35 @return 2 if we are in Salome embedded Python console.
39 if salome_iapp.IN_SALOME_GUI:
42 if __IN_SALOME_GUI_CONSOLE: # only defined if we are in SALOME's embedded console (not only GUI)
48 def ShowParaviewView():
50 If the import is made from SALOME embedded console, the ParaView application needs to
51 be instanciated to avoid a future crash.
54 __my_log("Initializing ParaView main elements, please be patient ...")
56 sgPyQt = SalomePyQt.SalomePyQt()
57 viewIds = sgPyQt.findViews("ParaView")
59 sgPyQt.setViewVisible(viewIds[0], True)
60 sgPyQt.activateView(viewIds[0])
62 sgPyQt.createView("ParaView")
63 # Now let the GUI main loop process the initialization event posted above
64 sgPyQt.processEvents()
65 __my_log("ParaView initialized.")
67 ## The below has to called BEFORE importing paraview!!! This is crazy, but it has to be.
72 from paraview import simple
74 def SalomeConnectToPVServer():
76 Automatically connect to the right PVServer when not ("inside SALOME GUI" and "already connected").
78 __my_log("Connecting to PVServer ...")
81 isGUIConnected = pvserver.myPVServerService.GetGUIConnected()
82 if isGUIConnected and __getFromGUI():
83 __my_log("Importing pvsimple from GUI and already connected. Won't reconnect.")
85 server_url = pvserver.myPVServerService.FindOrStartPVServer(0)
86 # Extract host and port from URL:
87 a = server_url.split(':')
89 host, port = b[-1], int(a[-1])
90 simple.Connect(host, port)
91 __my_log("Connected to %s!" % server_url)
93 pvserver.myPVServerService.SetGUIConnected(True)
94 except Exception as e:
95 __my_log("*******************************************")
96 __my_log("** Could not connect to a running PVServer!")
97 __my_log("*******************************************")
101 if __getFromGUI() < 1:
102 # Only if not in GUI (otherwise the createView will do the connection)
103 SalomeConnectToPVServer()
104 del SalomeConnectToPVServer
106 # Forward namespace of simple into current pvsimple:
107 for name in dir(simple):
108 if not name.startswith("__"):
109 globals()[name] = getattr(simple, name)