1 # Copyright (C) 2010-2014 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 PARAVIS engine.
27 print "[PARAVIS] %s" % msg
30 """ Identify if we are running inside SALOME's embedded console.
35 fromGUI = salome.fromEmbeddedConsole
36 except AttributeError:
40 def InitParaViewForGUI():
42 If the import is made from SALOME embedded console, the ParaView application needs to
43 be instanciated to avoid a future crash.
46 __my_log("Initializing ParaView main elements, please be patient ...")
48 sgPyQt = SalomePyQt.SalomePyQt()
49 sgPyQt.createView("ParaView")
50 # Now let the GUI main loop process the initialization event posted above
51 sgPyQt.processEvents()
52 __my_log("ParaView initialized.")
54 ## The below has to called BEFORE importing paraview!!! This is crazy, but it has to be.
56 del InitParaViewForGUI
61 # Forward namespace of simple into current pvsimple:
62 from paraview import simple
63 for name in dir(simple):
64 if not name.startswith("__"):
65 globals()[name] = getattr(simple, name)
68 def SalomeConnectToPVServer():
70 Automatically connect to the right PVServer when not ("inside SALOME GUI" and "already connected").
72 __my_log("Connecting to PVServer ...")
75 isGUIConnected = paravis.myParavisEngine.GetGUIConnected()
76 if isGUIConnected and __getFromGUI():
77 __my_log("Importing pvsimple from GUI and already connected. Won't reconnect.")
79 server_url = paravis.myParavisEngine.FindOrStartPVServer(0)
80 # Extract host and port from URL:
81 a = server_url.split(':')
83 host, port = b[-1], int(a[-1])
85 __my_log("Connected to %s!" % server_url)
87 paravis.myParavisEngine.SetGUIConnected(True)
88 except Exception as e:
89 __my_log("*******************************************")
90 __my_log("** Could not connect to a running PVServer!")
91 __my_log("*******************************************")
95 SalomeConnectToPVServer()