Commit a1539802 authored by hkrishna's avatar hkrishna

Adding PySide viewer embedding capabilities to trunk

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16595 18c085ea-50e0-402c-830e-de6fd14e8384
parent c0ac77b5
......@@ -48,6 +48,7 @@
vtkQtRenderWindow* (*QtVisWindow::windowCreationCallback)(void *) = 0;
void *QtVisWindow::windowCreationData = 0;
bool QtVisWindow::ownsAllWindows = false;
// ****************************************************************************
// Method: QtVisWindow constructor
......@@ -68,7 +69,7 @@ QtVisWindow::QtVisWindow(bool fullScreenMode) : VisWindow(false)
if(windowCreationCallback != 0)
{
renWin = windowCreationCallback(windowCreationData);
owns = false;
owns = ownsAllWindows; //false;
}
else
renWin = vtkQtRenderWindow::New();
......@@ -106,6 +107,33 @@ QtVisWindow::SetWindowCreationCallback(vtkQtRenderWindow *(*wcc)(void*), void *w
windowCreationData = wccdata;
}
// ****************************************************************************
// Method: QtVisWindow::SetOwnerShipOfWindows
//
// Purpose:
// Sets the owner of the windows.
//
// Arguments:
// isowner : True: VisIt owns the windows, False: User owns the windows.
//
// Returns: None.
//
// Note:
//
// Programmer: Hari Krishnan
// Creation: Mon Oct 25 16:24:18 PDT 2011
//
// Modifications:
//
// ****************************************************************************
void
QtVisWindow::SetOwnerShipOfAllWindows(bool isowner)
{
ownsAllWindows = isowner;
}
// ****************************************************************************
// Method: QtVisWindow::CreateToolColleague
//
......
......@@ -75,11 +75,13 @@ class QTVISWINDOW_API QtVisWindow : public VisWindow
QtVisWindow(bool fullScreenMode = false);
static void SetWindowCreationCallback(vtkQtRenderWindow *(*wcc)(void*), void *wccdata);
static void SetOwnerShipOfAllWindows(bool owner);
protected:
virtual void CreateToolColleague();
static vtkQtRenderWindow* (*windowCreationCallback)(void *);
static void *windowCreationData;
static bool ownsAllWindows;
};
#endif
......
......@@ -40,6 +40,7 @@
ADD_SUBDIRECTORY(rpc)
ADD_SUBDIRECTORY(proxy)
ADD_SUBDIRECTORY(subjectproxy)
IF(NOT VISIT_STATIC)
# "main" is handled from the top level in the static case so it can be
# created after we know which plugins are in use. This is needed for
......
......@@ -67,6 +67,39 @@
#include <cstring>
// ****************************************************************************
// Method: CreateViewerProxy
//
// Programmer: Hari Krishnan
// Creation: October 18, 2011
//
// Purpose:
// New method to construct ViewerProxy objects. Allows other libraries
// to override construction of the ViewerProxy method..
// if no other library has overriden the globalProxy variable
// then it simply constructs a new ViewerProxy class..
// Warning: Overriding more than one proxy will need care..
// Modifications:
// ****
ViewerProxy* ViewerProxy::CreateViewerProxy(ViewerProxy* proxy)
{
static ViewerProxy* globalProxy = NULL;
//if user has sent in a global proxy override the current one..
if(proxy)
globalProxy = proxy;
//if globalProxy has been assigned return that otherwise
//create a new ViewerProxy class..
if(globalProxy)
return globalProxy;
//construct default ViewerProxy
return new ViewerProxy();
}
// ****************************************************************************
// Method: ViewerProxy constructor
//
......
......@@ -75,6 +75,9 @@ class Xfer;
// Brad Whitlock, Tue Jun 24 11:21:40 PDT 2008
// Added plugin managers since they are no longer singletons.
//
// Hari Krishnan, Tue Oct 18 11:25:40 PDT 2011
// Virtualized several functions and added static class to create
// ViewerProxy.
// ****************************************************************************
class VIEWER_PROXY_API ViewerProxy : public SimpleObserver
......@@ -83,30 +86,30 @@ class VIEWER_PROXY_API ViewerProxy : public SimpleObserver
ViewerProxy();
virtual ~ViewerProxy();
Connection *GetReadConnection() const;
Connection *GetWriteConnection() const;
const std::string &GetLocalHostName() const;
const std::string &GetLocalUserName() const;
void ProcessInput();
virtual Connection *GetReadConnection() const;
virtual Connection *GetWriteConnection() const;
virtual const std::string &GetLocalHostName() const;
virtual const std::string &GetLocalUserName() const;
virtual void ProcessInput();
void AddArgument(const std::string &arg);
void Create(int *argc = 0, char ***argv = 0);
void Create(const char *, int *argc = 0, char ***argv = 0);
void Close();
void Detach();
virtual void AddArgument(const std::string &arg);
virtual void Create(int *argc = 0, char ***argv = 0);
virtual void Create(const char *, int *argc = 0, char ***argv = 0);
virtual void Close();
virtual void Detach();
void InitializePlugins(PluginManager::PluginCategory t, const char *pluginDir=0);
void LoadPlugins();
PlotPluginManager *GetPlotPluginManager() const;
OperatorPluginManager *GetOperatorPluginManager() const;
virtual void InitializePlugins(PluginManager::PluginCategory t, const char *pluginDir=0);
virtual void LoadPlugins();
virtual PlotPluginManager *GetPlotPluginManager() const;
virtual OperatorPluginManager *GetOperatorPluginManager() const;
// Get the proxy's ViewerState object which contains the state objects
// used in the viewer/client communication interface.
ViewerState *GetViewerState() const;
virtual ViewerState *GetViewerState() const;
// Get the proxy's ViewerMethods object which contains the methods that
// are converted into ViewerRPC calls in the viewer.
ViewerMethods *GetViewerMethods() const;
virtual ViewerMethods *GetViewerMethods() const;
// Methods for dealing with plot SIL restrictions.
avtSILRestriction_p GetPlotSILRestriction()
......@@ -124,6 +127,11 @@ class VIEWER_PROXY_API ViewerProxy : public SimpleObserver
// Don't use this method unless absolutely necessary.
void SetXferUpdate(bool val);
//Static function to create ViewerProxy
//this allows other libraries to override creation of ViewerProxy
//namely PySide which is dynamically loaded from a separate module
static ViewerProxy* CreateViewerProxy(ViewerProxy* = NULL);
protected:
virtual void Update(Subject *subj);
......
#*****************************************************************************
#
# Copyright (c) 2000 - 2011, Lawrence Livermore National Security, LLC
# Produced at the Lawrence Livermore National Laboratory
# LLNL-CODE-400142
# All rights reserved.
#
# This file is part of VisIt. For details, see https://visit.llnl.gov/. The
# full copyright notice is contained in the file COPYRIGHT located at the root
# of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaimer below.
# - Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the disclaimer (as noted below) in the
# documentation and/or other materials provided with the distribution.
# - Neither the name of the LLNS/LLNL nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
# Modifications:
#
#****************************************************************************/
#ADD_DEPENDENCIES(rpc)
#ADD_DEPENDENCIES(proxy)
#ADD_DEPENDENCIES(viewer)
SET(VIEWERLIB_SOURCES
ViewerSubjectProxy.C
)
# If the viewer is static then we need some static symbol lookup functions
#IF(VISIT_STATIC)
# SET(VIEWER_STATIC_SOURCES ViewerStaticSymbolLocator.C)
#ENDIF(VISIT_STATIC)
SET(VIEWERLIB_MOC_HEADERS
ViewerSubjectProxy.h
)
QT_WRAP_CPP(viewersubjectproxy VIEWERLIB_MOC_SOURCES ${VIEWERLIB_MOC_HEADERS})
#IF (NOT WIN32)
# This keeps comm's exceptions visible when using -fvisibility=hidden
# ADD_DEFINITIONS(-DCOMM_EXPORTS)
#ENDIF (NOT WIN32)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${VISIT_COMMON_INCLUDES}
${VISIT_SOURCE_DIR}/viewer/rpc
${VISIT_SOURCE_DIR}/viewer/proxy
${VISIT_SOURCE_DIR}/viewer/main
${VISIT_SOURCE_DIR}/avt/DBAtts/MetaData
${VISIT_SOURCE_DIR}/avt/DBAtts/SIL
${VISIT_SOURCE_DIR}/avt/Database/Database
${VISIT_SOURCE_DIR}/avt/FileWriter
${VISIT_SOURCE_DIR}/avt/Filters
${VISIT_SOURCE_DIR}/avt/Math
${VISIT_SOURCE_DIR}/avt/Pipeline/AbstractFilters
${VISIT_SOURCE_DIR}/avt/Pipeline/Data
${VISIT_SOURCE_DIR}/avt/Pipeline/Pipeline
${VISIT_SOURCE_DIR}/avt/Pipeline/Sinks
${VISIT_SOURCE_DIR}/avt/Pipeline/Sources
${VISIT_SOURCE_DIR}/avt/Plotter
${VISIT_SOURCE_DIR}/avt/Plotter/vtk
${VISIT_SOURCE_DIR}/avt/QtVisWindow
${VISIT_SOURCE_DIR}/avt/View
${VISIT_SOURCE_DIR}/avt/VisWindow/Colleagues
${VISIT_SOURCE_DIR}/avt/VisWindow/Interactors
${VISIT_SOURCE_DIR}/avt/VisWindow/Proxies
${VISIT_SOURCE_DIR}/avt/VisWindow/Tools
${VISIT_SOURCE_DIR}/avt/VisWindow/VisWindow
${VISIT_SOURCE_DIR}/engine/proxy
${VISIT_SOURCE_DIR}/engine/rpc
${VISIT_SOURCE_DIR}/launcher/proxy
${VISIT_SOURCE_DIR}/launcher/rpc
${VISIT_SOURCE_DIR}/mdserver/proxy
${VISIT_SOURCE_DIR}/mdserver/rpc
${VISIT_SOURCE_DIR}/visit_vtk/full
${VISIT_SOURCE_DIR}/vtkqt
${VISIT_SOURCE_DIR}/winutil
${QT_INCLUDE_DIR}
${QT_QTCORE_INCLUDE_DIR}
${QT_QTGUI_INCLUDE_DIR}
${QT_QTOPENGL_INCLUDE_DIR}
${VTK_INCLUDE_DIRS}
)
LINK_DIRECTORIES(${LIBRARY_OUTPUT_DIRECTORY} ${QT_LIBRARY_DIR} ${MESA_LIBRARY_DIR} ${GLEW_LIBRARY_DIR} ${VTK_LIBRARY_DIRS})
#*************************** The viewer library ******************************
ADD_LIBRARY(viewersubjectproxy ${VIEWERLIB_SOURCES} ${VIEWERLIB_MOC_SOURCES})
#IF (WIN32)
# SET_TARGET_PROPERTIES(viewersubject PROPERTIES OUTPUT_NAME viewersubjectlib)
#ENDIF (WIN32)
SET(VIEWER_QT_LIBS
${QT_QTGUI_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTCORE_LIBRARY}
)
IF(VISIT_STATIC)
SET(VIEWER_QT_LIBS
${VIEWER_QT_LIBS}
${QT_QTGUI_LIB_DEPENDENCIES}
${QT_QTOPENGL_LIB_DEPENDENCIES}
${QT_QTCORE_LIB_DEPENDENCIES}
)
ENDIF(VISIT_STATIC)
TARGET_LINK_LIBRARIES(viewersubjectproxy
viewer
viewerrpc
viewerproxy
visitcommon
mdserverrpc
mdserverproxy
vclrpc
vclproxy
enginerpc
engineproxy
avtdbatts
avtview
avtmath
avtpipeline_ser
avtplotter_ser
avtfilters_ser
avtviswindow_ser
avtwriter_ser
avtqtviswindow
winutil
${VIEWER_QT_LIBS}
)
VISIT_INSTALL_TARGETS(viewersubjectproxy)
#include <iostream>
#include <ViewerProxy.h>
#include <ViewerSubject.h>
#include <ViewerSubjectProxy.h>
#include <VisItInit.h>
#include <RuntimeSetting.h>
#include <ViewerState.h>
#include <ViewerMethods.h>
#include <PlotPluginManager.h>
#include <OperatorPluginManager.h>
#include <PluginManagerAttributes.h>
#include <PlotPluginInfo.h>
#include <OperatorPluginInfo.h>
#include <ClientInformation.h>
#include <ClientMethod.h>
#include <DebugStream.h>
#include <ImproperUseException.h>
#include <ParentProcess.h>
#include <PlotInfoAttributes.h>
#include <PluginManagerAttributes.h>
#include <RemoteProcess.h>
#include <SILRestrictionAttributes.h>
#include <SocketConnection.h>
#include <ViewerMethods.h>
#include <ViewerRPC.h>
#include <ViewerState.h>
#include <VisItException.h>
#include <Xfer.h>
#undef Always
#include <QtVisWindow.h>
std::map<int,vtkQtRenderWindow*> ViewerSubjectProxy::viswindows;
void ViewerSubjectProxy::InitializePlugins(PluginManager::PluginCategory t, const char *pluginDir)
{
//std::cout << "initializing plugins.." << " " << std::endl;
//t = PluginManager::GUI | PluginManager::Scripting;
// if(t == PluginManager::GUI)
// {
// std::cout << "now loading plugins" << std::endl;
// std::string dir = "/work/visit/branches/PySideIntegration/build/plugins/";
// cli_plotplugin->Initialize(t, false, dir.c_str());
// cli_operatorplugin->Initialize(t, false, dir.c_str());
// LoadPlugins();
// }
// else
// {
cli_plotplugin->Initialize(t, false, pluginDir);
cli_operatorplugin->Initialize(t, false, pluginDir);
// }
}
void ViewerSubjectProxy::LoadPlugins()
{
//std::cout << "Loading plugins" << std::endl;
//ViewerState* state = vissubject->GetViewerState();
ViewerState* state = gstate;
PlotPluginManager* plotPlugins = cli_plotplugin;
OperatorPluginManager* operatorPlugins = cli_operatorplugin;
int i;
int nPlots = state->GetNumPlotStateObjects();
int nOperators = state->GetNumOperatorStateObjects();
if (nPlots > 0 || nOperators > 0)
{
//std::cout << "path has stuff" << " " << nPlots << " " << nOperators << std::endl;
//return;
}
if(plotPlugins == 0 || operatorPlugins == 0)
{
EXCEPTION1(ImproperUseException, "ViewerProxy::InitializePlugins "
"must be called before ViewerProxy::LoadPlugins")
}
//
// Go through the plugin atts and en/disable the ones specified
// by the plugin attributes
//
PluginManagerAttributes *pluginManagerAttributes = state->GetPluginManagerAttributes();
for (i=0; i<pluginManagerAttributes->GetId().size(); i++)
{
if (! pluginManagerAttributes->GetEnabled()[i]) // not enabled
{
std::string id = pluginManagerAttributes->GetId()[i];
if (pluginManagerAttributes->GetType()[i] == "plot")
{
if (plotPlugins->PluginExists(id))
plotPlugins->DisablePlugin(id);
}
else if (pluginManagerAttributes->GetType()[i] == "operator")
{
if (operatorPlugins->PluginExists(id))
operatorPlugins->DisablePlugin(id);
}
}
else // is enabled -- it had better be available
{
std::string id = pluginManagerAttributes->GetId()[i];
if (pluginManagerAttributes->GetType()[i] == "plot")
{
if (plotPlugins->PluginExists(id))
plotPlugins->EnablePlugin(id);
else
{
std::string msg(std::string("The ") + id +
std::string(" plot plugin enabled by the viewer "
"was not available in the client."));
EXCEPTION1(VisItException, msg)
}
}
else if (pluginManagerAttributes->GetType()[i] == "operator")
{
if (operatorPlugins->PluginExists(id))
operatorPlugins->EnablePlugin(id);
else
{
std::string msg(std::string("The ") + id +
std::string(" operator plugin enabled by the viewer "
"was not available in the client."));
EXCEPTION1(VisItException, msg)
}
}
}
}
//
// Now load dynamic libraries
//
plotPlugins->LoadPluginsNow();
operatorPlugins->LoadPluginsNow();
//
// Initialize the plot attribute state objects.
//
nPlots = plotPlugins->GetNEnabledPlugins();
for (i = 0; i < nPlots; ++i)
{
CommonPlotPluginInfo *info =
plotPlugins->GetCommonPluginInfo(plotPlugins->GetEnabledID(i));
AttributeSubject *obj = info->AllocAttributes();
//std::cout << obj->TypeName() << std::endl;
state->RegisterPlotAttributes(obj);
}
//
// Initialize the operator attribute state objects.
//
nOperators = operatorPlugins->GetNEnabledPlugins();
for (i = 0; i < nOperators; ++i)
{
CommonOperatorPluginInfo *info =
operatorPlugins->GetCommonPluginInfo(operatorPlugins->GetEnabledID(i));
AttributeSubject *obj = info->AllocAttributes();
//std::cout << obj->TypeName() << std::endl;
state->RegisterOperatorAttributes(obj);
}
//std::cout << "ending" << std::endl;
}
//return the new cli plot and operator manager so that the visit cli works like normal..
PlotPluginManager* ViewerSubjectProxy::GetPlotPluginManager() const
{
//std::cout << "Getting plot plugins" << std::endl;
//return vissubject->GetPlotPluginManager();
return cli_plotplugin;
}
OperatorPluginManager *ViewerSubjectProxy::GetOperatorPluginManager() const
{
//std::cout << "operator plugins" << std::endl;
//return vissubject->GetOperatorPluginManager();
return cli_operatorplugin;
}
ViewerState *ViewerSubjectProxy::GetViewerState() const
{
//std::cout << "Getting viewer State" << " " << gstate << std::endl;
//return vissubject->GetViewerState();
return gstate;
}
ViewerMethods *ViewerSubjectProxy::GetViewerMethods() const
{
//std::cout << "Getting viewer Methods" << std::endl;
//return vissubject->GetViewerMethods();
return gmethods;
}
void ViewerSubjectProxy::Initialize(int argc,char* argv[])
{
//std::cout << "initializing" << std::endl;
//do not initialize if gstate or gmethods have already been set..
// if(gstate || gmethods)
// {
// std::cout << "Already Initialized" << std::endl;
// return;
// }
vissubject = new ViewerSubject();
testconn = new TestConnection();
cli_plotplugin = new PlotPluginManager();
cli_operatorplugin = new OperatorPluginManager();
gstate = vissubject->GetViewerState();
gmethods = vissubject->GetViewerMethods();
//std::cout << "here" << std::endl;
//std::string hostname = "localhost";
//stringVector args;
//GetViewerMethods()->ConnectToMetaDataServer(hostname,args);
//ViewerFileServer::Instance()->ConnectServer(hostname,args);
//std::cout << "and now here" << std::endl;
try
{
vissubject->GetViewerProperties()->SetUseWindowMetrics(false);
QtVisWindow::SetWindowCreationCallback(renderWindow, this);
//let VisIt own all actions as if it was its
QtVisWindow::SetOwnerShipOfAllWindows(true);
//std::cout << "initializing" << std::endl;
vissubject->ProcessCommandLine(argc,argv);
vissubject->Initialize();
}
catch(VisItException e)
{
std::cout << e.Message() << std::endl;
}
//std::cout << "blah" << std::endl;
}
vtkQtRenderWindow* ViewerSubjectProxy::GetRenderWindow(int i)
{
//VisIt has not initialized any windows..
if(viswindows.size() == 0)
return NULL;
if(viswindows.find(i) != viswindows.end())
return viswindows[i];
std::cerr << "Window " << i << " does not exist" << std::endl;
return NULL;
}
vtkQtRenderWindow* ViewerSubjectProxy::renderWindow(void* data)
{
vtkQtRenderWindow* win = new ViewerSubjectProxy::NonClosableQtRenderWindow();
//add signal to let us know when windowDeleted.
win->connect(win,SIGNAL(destroyed(QObject*)),(QObject*)data,SLOT(windowDeleted(QObject*)));
//find next free id (okay to do this loop since VisIt
//has very limited opengl windows it can support
int id = 1;
while(viswindows.count(id) > 0) id++;
viswindows[id] = win;
return viswindows[id];
}
void ViewerSubjectProxy::windowDeleted(QObject * obj)
{
std::map<int,vtkQtRenderWindow*>::iterator itr = viswindows.begin();