Commit 7091737a authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Refactoring how view types are created and registered with ParaView.

This commits simplifies how views are added to ParaView. In past, we
need to create a pqView subclass and then add that using
pqViewModuleInterface implementation. After this change, one can add new
view types by simply defining new proxy types under the "views" group.
If you need to add a pqView subclass, or specify a pqView subclass to
use with your new view type, simply use add_pqproxy() macro, instead of
add_paraview_view_module() macro. Label used for the view is now
garnered from the proxy itself (vtkSMProxy::GetXMLLabel()).

Updating plugins, examples to use this new code.

Removed pqStandardViewModules since it's no longer relevant. If you're
using that class, simply remove it from your code and ParaView will
continue to work as expected.

Moved view XML definitions that were "internal" to "internal_views"
group. This keeps the list of "available" views clean. Plugins may have
to be updated if they are using "ViewBase" proxy definition.

Change-Id: I15b329ea13ce526ca3c1fe016da0201ac5826355
parent 4424b0a8
......@@ -380,8 +380,98 @@ MACRO(ADD_PARAVIEW_DISPLAY_PANEL OUTIFACES OUTSRCS)
)
ENDMACRO(ADD_PARAVIEW_DISPLAY_PANEL)
# create implementation for a custom view
#------------------------------------------------------------------------------
# Register a pqProxy subclass with ParaView. This macro is used to register
# pqProxy subclasses, including pqView subclasses, pqDataRepresentation
# subclasses, etc. to create when a particular type of proxy is registered with
# the application.
# Usage:
# add_pqproxy(OUTIFACES OUTSRCS
# TYPE <pqProxy subclass name>
# XML_GROUP <xml group used to identify the vtkSMProxy>
# XML_NAME <xml name used to indentify the vtkSMProxy>
# ...)
# The TYPE, XML_GROUP, and XML_NAME can be repeated to register multiple types
# of pqProxy subclasses or reuse the same pqProxy for multiple proxy types.
macro(add_pqproxy OUTIFACES OUTSRCS)
set (arg_types)
set (_doing)
set (_active_index)
foreach (arg ${ARGN})
if ((NOT _doing) AND ("${arg}" MATCHES "^(TYPE|XML_GROUP|XML_NAME)$"))
set (_doing "${arg}")
elseif (_doing STREQUAL "TYPE")
list(APPEND arg_types "${arg}")
list(LENGTH arg_types _active_index)
math(EXPR _active_index "${_active_index}-1")
set (_type_${_active_index}_xmlgroup)
set (_type_${_active_index}_xmlname)
set (_doing)
elseif (_doing STREQUAL "XML_GROUP")
set (_type_${_active_index}_xmlgroup "${arg}")
set (_doing)
elseif (_doing STREQUAL "XML_NAME")
set (_type_${_active_index}_xmlname "${arg}")
set (_doing)
else()
set (_doing)
endif()
endforeach()
list(LENGTH arg_types num_items)
math(EXPR max_index "${num_items}-1")
set (ARG_INCLUDES)
set (ARG_BODY)
foreach (index RANGE ${max_index})
list(GET arg_types ${index} arg_type)
set (arg_xml_group "${_type_${index}_xmlgroup}")
set (arg_xml_name "${_type_${index}_xmlname}")
set (ARG_INCLUDES "${ARG_INCLUDES}#include\"${arg_type}.h\"\n")
set (ARG_BODY "${ARG_BODY}
if (QString(\"${arg_xml_group}\") == proxy->GetXMLGroup() &&
QString(\"${arg_xml_name}\") == proxy->GetXMLName())
{
return new ${arg_type}(regGroup, regName, proxy, server, NULL);
}")
endforeach()
if (ARG_INCLUDES AND ARG_BODY)
list(GET arg_types 0 ARG_TYPE)
set (IMP_CLASS "${ARG_TYPE}ServerManagerModelImplementation")
configure_file(${ParaView_CMAKE_DIR}/pqServerManagerModelImplementation.h.in
${CMAKE_CURRENT_BINARY_DIR}/${IMP_CLASS}.h @ONLY)
configure_file(${ParaView_CMAKE_DIR}/pqServerManagerModelImplementation.cxx.in
${CMAKE_CURRENT_BINARY_DIR}/${IMP_CLASS}.cxx @ONLY)
set (_moc_srcs)
if (PARAVIEW_QT_VERSION VERSION_GREATER "4")
QT5_WRAP_CPP(_moc_srcs ${CMAKE_CURRENT_BINARY_DIR}/${IMP_CLASS}.h)
else()
QT4_WRAP_CPP(_moc_srcs ${CMAKE_CURRENT_BINARY_DIR}/${IMP_CLASS}.h)
endif()
set(${OUTIFACES} ${${OUTIFACES}} ${ARG_TYPE}ServerManagerModel) # don't add
# the extra "Implementation" here.
set(${OUTSRCS}
${${OUTSRCS}}
${_moc_srcs}
${CMAKE_CURRENT_BINARY_DIR}/${IMP_CLASS}.h
${CMAKE_CURRENT_BINARY_DIR}/${IMP_CLASS}.cxx
)
endif()
unset (ARG_TYPE)
unset (ARG_INCLUDES)
unset (ARG_BODY)
endmacro()
#------------------------------------------------------------------------------
# *** OBSOLETE *** : No longer supported.
# To add new view proxies (or representation proxies) simply add new proxies to
# "views" or "representations" groups. To add new pqView or pqDataRepresentation
# subclasses, use ADD_PQPROXY().
# create implementation for a custom view
# Obsolete Usage:
# ADD_PARAVIEW_VIEW_MODULE( OUTIFACES OUTSRCS
# VIEW_TYPE Type
# VIEW_XML_GROUP Group
......@@ -389,104 +479,13 @@ ENDMACRO(ADD_PARAVIEW_DISPLAY_PANEL)
# [VIEW_NAME Name]
# [DISPLAY_PANEL Display]
# [DISPLAY_TYPE Display]
# for the given server manager XML
# <SourceProxy name="MyFilter" class="MyFilter" label="My Filter">
# ...
# <Hints>
# <View type="MyView" />
# </Hints>
# </SourceProxy>
# ....
# <ProxyGroup name="plotmodules">
# <ViewProxy name="MyView"
# base_proxygroup="newviews" base_proxyname="ViewBase"
# representation_name="MyDisplay">
# </ViewProxy>
# </ProxyGroup>
# VIEW_TYPE = "MyView"
# VIEW_XML_GROUP = "plotmodules"
# VIEW_XML_NAME is optional and defaults to VIEW_TYPE
# VIEW_NAME is optional and gives a friendly name for the view type
# DISPLAY_TYPE is optional and defaults to pqDataRepresentation
# DISPLAY_PANEL gives the name of the display panel
# DISPLAY_XML is the XML name of the display for this view and is required if
# DISPLAY_PANEL is set
#
# if DISPLAY_PANEL is MyDisplay, then "MyDisplayPanel.h" is looked for.
# a class MyView derived from pqGenericViewModule is expected to be in "MyView.h"
MACRO(ADD_PARAVIEW_VIEW_MODULE OUTIFACES OUTSRCS)
SET(PANEL_SRCS)
SET(ARG_VIEW_TYPE)
SET(ARG_VIEW_NAME)
SET(ARG_VIEW_XML_GROUP)
SET(ARG_VIEW_XML_NAME)
SET(ARG_DISPLAY_PANEL)
SET(ARG_DISPLAY_XML)
SET(ARG_DISPLAY_TYPE)
PV_PLUGIN_PARSE_ARGUMENTS(ARG "VIEW_TYPE;VIEW_XML_GROUP;VIEW_XML_NAME;VIEW_NAME;DISPLAY_PANEL;DISPLAY_TYPE;DISPLAY_XML"
"" ${ARGN} )
IF(NOT ARG_VIEW_TYPE OR NOT ARG_VIEW_XML_GROUP)
MESSAGE(ERROR " ADD_PARAVIEW_VIEW_MODULE called without VIEW_TYPE or VIEW_XML_GROUP")
ENDIF(NOT ARG_VIEW_TYPE OR NOT ARG_VIEW_XML_GROUP)
IF(ARG_DISPLAY_PANEL)
IF(NOT ARG_DISPLAY_XML)
MESSAGE(ERROR " ADD_PARAVIEW_VIEW_MODULE called with DISPLAY_PANEL but DISPLAY_XML not specified")
ENDIF(NOT ARG_DISPLAY_XML)
ENDIF(ARG_DISPLAY_PANEL)
SET(${OUTIFACES} ${ARG_VIEW_TYPE})
IF(NOT ARG_VIEW_XML_NAME)
SET(ARG_VIEW_XML_NAME ${ARG_VIEW_TYPE})
ENDIF(NOT ARG_VIEW_XML_NAME)
IF(ARG_VIEW_NAME)
SET(VIEW_TYPE_NAME ${ARG_VIEW_NAME})
ELSE(ARG_VIEW_NAME)
SET(VIEW_TYPE_NAME ${ARG_VIEW_TYPE})
ENDIF(ARG_VIEW_NAME)
IF(NOT ARG_DISPLAY_TYPE)
SET(ARG_DISPLAY_TYPE "pqDataRepresentation")
ENDIF(NOT ARG_DISPLAY_TYPE)
CONFIGURE_FILE(${ParaView_CMAKE_DIR}/pqViewModuleImplementation.h.in
${CMAKE_CURRENT_BINARY_DIR}/${ARG_VIEW_TYPE}Implementation.h @ONLY)
CONFIGURE_FILE(${ParaView_CMAKE_DIR}/pqViewModuleImplementation.cxx.in
${CMAKE_CURRENT_BINARY_DIR}/${ARG_VIEW_TYPE}Implementation.cxx @ONLY)
IF(PARAVIEW_BUILD_QT_GUI)
SET(VIEW_MOC_SRCS)
IF (PARAVIEW_QT_VERSION VERSION_GREATER "4")
QT5_WRAP_CPP(VIEW_MOC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${ARG_VIEW_TYPE}Implementation.h)
ELSE ()
QT4_WRAP_CPP(VIEW_MOC_SRCS ${CMAKE_CURRENT_BINARY_DIR}/${ARG_VIEW_TYPE}Implementation.h)
ENDIF ()
ENDIF(PARAVIEW_BUILD_QT_GUI)
IF(ARG_DISPLAY_PANEL)
ADD_PARAVIEW_DISPLAY_PANEL(OUT_PANEL_IFACES PANEL_SRCS
CLASS_NAME ${ARG_DISPLAY_PANEL}
XML_NAME ${ARG_DISPLAY_XML})
SET(${OUTIFACES} ${ARG_VIEW_TYPE} ${OUT_PANEL_IFACES})
ENDIF(ARG_DISPLAY_PANEL)
SET(${OUTSRCS}
${CMAKE_CURRENT_BINARY_DIR}/${ARG_VIEW_TYPE}Implementation.cxx
${CMAKE_CURRENT_BINARY_DIR}/${ARG_VIEW_TYPE}Implementation.h
${VIEW_MOC_SRCS}
${PANEL_SRCS}
)
message(FATAL_ERROR
"'ADD_PARAVIEW_VIEW_MODULE' macro is no longer supported. To add new view proxies, or representation proxies, simply add new proxies to 'views' or 'representations' groups. To add new pqView or pqDataRepresentation subclasses, use 'ADD_PQPROXY' macro.")
ENDMACRO(ADD_PARAVIEW_VIEW_MODULE)
#------------------------------------------------------------------------
# DEPRECATED: create implementation for a custom view options interface
# OBSOLETE: create implementation for a custom view options interface
MACRO(ADD_PARAVIEW_VIEW_OPTIONS)
message(FATAL_ERROR
"'ADD_PARAVIEW_VIEW_OPTIONS' macro is no longer supported.
......
#include "@ARG_TYPE@ServerManagerModelImplementation.h"
#include "vtkSMProxy.h"
// begin includes
@ARG_INCLUDES@
// end includes
//-----------------------------------------------------------------------------
@ARG_TYPE@ServerManagerModelImplementation::@ARG_TYPE@ServerManagerModelImplementation(QObject* parentObject)
: QObject(parentObject)
{
}
//-----------------------------------------------------------------------------
@ARG_TYPE@ServerManagerModelImplementation::~@ARG_TYPE@ServerManagerModelImplementation()
{
}
//-----------------------------------------------------------------------------
pqProxy* @ARG_TYPE@ServerManagerModelImplementation::createPQProxy(
const QString& regGroup, const QString& regName, vtkSMProxy* proxy, pqServer* server) const
{
if (proxy!=NULL &&
proxy->GetXMLGroup() != NULL &&
proxy->GetXMLName() != NULL)
{
@ARG_BODY@
}
return NULL;
}
/// Generated file. Do not edit.
#ifndef __@ARG_TYPE@ServerManagerModelImplementation_h
#define __@ARG_TYPE@ServerManagerModelImplementation_h
#include "pqServerManagerModelInterface.h"
/// Used by add_pqproxy() macro.
class @ARG_TYPE@ServerManagerModelImplementation : public QObject,
public pqServerManagerModelInterface
{
Q_OBJECT;
Q_INTERFACES(pqServerManagerModelInterface);
public:
@ARG_TYPE@ServerManagerModelImplementation(QObject* parentObject=NULL);
virtual ~@ARG_TYPE@ServerManagerModelImplementation();
/// Creates a pqProxy subclass for the vtkSMProxy given the details for its
/// registration with the proxy manager.
/// \arg \c regGroup - registration group for the proxy.
/// \arg \c regName - registration name for the proxy.
/// \arg \c proxy - vtkSMProxy instance to create the pqProxy for.
/// \arg \c server - pqServer instance on which the proxy is present.
virtual pqProxy* createPQProxy(const QString& regGroup,
const QString& regName, vtkSMProxy* proxy, pqServer* server) const;
private:
Q_DISABLE_COPY(@ARG_TYPE@ServerManagerModelImplementation);
};
#endif // endif ifndef
// Generated file. Do not edit.
/*=========================================================================
Program: ParaView
Module: pqViewModuleImplementation.cxx.in
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
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 THE AUTHORS 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.
=========================================================================*/
#include "@ARG_VIEW_TYPE@Implementation.h"
#include "@ARG_VIEW_TYPE@.h"
#include "vtkSMSessionProxyManager.h"
#include "@ARG_DISPLAY_TYPE@.h"
#include "pqServer.h"
// configured with CMake
// requires: ARG_VIEW_TYPE, VIEW_TYPE_NAME, ARG_DISPLAY_TYPE, ARG_VIEW_XML_GROUP,
// ARG_VIEW_XML_NAME
@ARG_VIEW_TYPE@Implementation::@ARG_VIEW_TYPE@Implementation(QObject* o)
: QObject(o)
{
}
QStringList @ARG_VIEW_TYPE@Implementation::viewTypes() const
{
return QStringList() << "@ARG_VIEW_TYPE@";
}
QStringList @ARG_VIEW_TYPE@Implementation::displayTypes() const
{
return QStringList() << "@ARG_DISPLAY_TYPE@";
}
QString @ARG_VIEW_TYPE@Implementation::viewTypeName(const QString& /*type*/) const
{
return "@VIEW_TYPE_NAME@";
}
bool @ARG_VIEW_TYPE@Implementation::canCreateView(const QString& viewtype) const
{
return viewtype == "@ARG_VIEW_TYPE@";
}
vtkSMProxy* @ARG_VIEW_TYPE@Implementation::createViewProxy(const QString& viewtype,
pqServer *server)
{
vtkSMSessionProxyManager* pxm = server->proxyManager();
if(viewtype == "@ARG_VIEW_TYPE@")
{
// See what happens if we augment the type with View, in case this is
// how it is registered in XML.
if (pxm->HasDefinition("@ARG_VIEW_XML_GROUP@", "@ARG_VIEW_XML_NAME@View"))
{
return pxm->NewProxy("@ARG_VIEW_XML_GROUP@", "@ARG_VIEW_XML_NAME@View");
}
// Just return whatever objectis registered under the view name.
return pxm->NewProxy("@ARG_VIEW_XML_GROUP@", "@ARG_VIEW_XML_NAME@");
}
return NULL;
}
pqView* @ARG_VIEW_TYPE@Implementation::createView(const QString& viewtype,
const QString& group,
const QString& viewname,
vtkSMViewProxy* viewmodule,
pqServer* server,
QObject* p)
{
if( (viewtype == "@ARG_VIEW_TYPE@")
|| (viewtype == "@ARG_VIEW_XML_NAME@"))
{
return new @ARG_VIEW_TYPE@("@ARG_VIEW_TYPE@", group, viewname, viewmodule, server, p);
}
return NULL;
}
pqDataRepresentation* @ARG_VIEW_TYPE@Implementation::createDisplay(const QString& display_type,
const QString& group,
const QString& n,
vtkSMProxy* proxy,
pqServer* server,
QObject* p)
{
if(display_type == "@ARG_DISPLAY_TYPE@")
{
return new @ARG_DISPLAY_TYPE@(group, n, proxy, server, p);
}
return NULL;
}
// Generated file. Do not edit.
/*=========================================================================
Program: ParaView
Module: pqViewModuleImplementation.h.in
Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
All rights reserved.
ParaView is a free software; you can redistribute it and/or modify it
under the terms of the ParaView license version 1.2.
See License_v1.2.txt for the full ParaView license.
A copy of this license can be obtained by contacting
Kitware Inc.
28 Corporate Drive
Clifton Park, NY 12065
USA
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 THE AUTHORS 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.
=========================================================================*/
#ifndef _@ARG_VIEW_TYPE@Implementation_h
#define _@ARG_VIEW_TYPE@Implementation_h
#include <QObject>
#include "pqViewModuleInterface.h"
/// interface class for plugins that create view modules
class @ARG_VIEW_TYPE@Implementation : public QObject,
public pqViewModuleInterface
{
Q_OBJECT
Q_INTERFACES(pqViewModuleInterface)
public:
@ARG_VIEW_TYPE@Implementation(QObject* o);
QStringList viewTypes() const;
QStringList displayTypes() const;
QString viewTypeName(const QString&) const;
bool canCreateView(const QString& viewtype) const;
vtkSMProxy* createViewProxy(const QString& viewtype, pqServer *server);
pqView* createView(const QString& viewtype,
const QString& group,
const QString& name,
vtkSMViewProxy* viewmodule,
pqServer* server,
QObject* parent);
pqDataRepresentation* createDisplay(const QString& display_type,
const QString& group,
const QString& name,
vtkSMProxy* proxy,
pqServer* server,
QObject* parent);
};
#endif
......@@ -14,7 +14,6 @@ if (PARAVIEW_BUILD_QT_GUI)
add_subdirectory(Plugins/Autostart)
add_subdirectory(Plugins/DockWidget)
add_subdirectory(Plugins/GUIToolBar)
add_subdirectory(Plugins/GUIView)
add_subdirectory(Plugins/PropertyWidgets)
add_subdirectory(Plugins/Reader)
add_subdirectory(Plugins/ReaderXMLOnly)
......
......@@ -35,13 +35,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqHelpReaction.h"
#include "pqParaViewBehaviors.h"
#include "pqParaViewMenuBuilders.h"
#include "pqInterfaceTracker.h"
#include "pqDefaultViewBehavior.h"
#include "pqAlwaysConnectedBehavior.h"
//#include "pqDeleteBehavior.h"
#include "pqAutoLoadPluginXMLBehavior.h"
#include "pqApplicationCore.h"
#include "pqStandardViewModules.h"
//#include "pqPVNewSourceBehavior.h"
#include <QToolBar>
......@@ -129,8 +127,6 @@ myMainWindow::myMainWindow()
#if 0
new pqParaViewBehaviors(this, this);
#else
pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
pgm->addInterface(new pqStandardViewModules(pgm));
new pqDefaultViewBehavior(this);
new pqAlwaysConnectedBehavior(this);
// new pqPVNewSourceBehavior(this);
......
......@@ -33,8 +33,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ui_myMainWindow.h"
#include "pqApplicationCore.h"
#include "pqInterfaceTracker.h"
#include "pqStandardViewModules.h"
#include "pqRenderView.h"
#include "pqActiveObjects.h"
#include "pqObjectBuilder.h"
......@@ -47,10 +45,6 @@ myMainWindow::myMainWindow(QWidget* parentObject,
Ui::myMainWindow ui;
ui.setupUi(this);
// Get access to the for standard paraview views.
pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
pgm->addInterface(new pqStandardViewModules(pgm));
// Make a connection to the builtin server
pqApplicationCore* core = pqApplicationCore::instance();
core->getObjectBuilder()->createServer(pqServerResource("builtin:"));
......
......@@ -42,10 +42,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "pqOutputPort.h"
#include "pqPersistentMainWindowStateBehavior.h"
#include "pqPipelineSource.h"
#include "pqInterfaceTracker.h"
#include "pqSpreadSheetViewDecorator.h"
#include "pqSpreadSheetView.h"
#include "pqStandardViewModules.h"
#include "pqRecentFilesMenu.h"
//-----------------------------------------------------------------------------
......@@ -55,12 +53,6 @@ SpreadSheetMainWindow::SpreadSheetMainWindow(QWidget* parentObject,
Ui::SpreadSheetMainWindow ui;
ui.setupUi(this);
// Register ParaView interfaces.
pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
// * adds support for standard paraview views.
pgm->addInterface(new pqStandardViewModules(pgm));
// Define default behaviors - create only small subset, since this application
// is not really a ParaView-like application at all.
new pqAlwaysConnectedBehavior(this);
......
# create a plugin with a custom view that shows up in ParaView's multi-view
# manager. this plugin also contains a custom display panel
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(NOT ParaView_BINARY_DIR)
FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(${PARAVIEW_USE_FILE})
ENDIF(NOT ParaView_BINARY_DIR)
IF(PARAVIEW_BUILD_QT_GUI)
# moc the Qt based .h files
IF (PARAVIEW_QT_VERSION VERSION_GREATER "4")
QT5_WRAP_CPP(MOC_SRCS MyView.h MyDisplay.h)
ELSE ()
QT4_WRAP_CPP(MOC_SRCS MyView.h MyDisplay.h)
ENDIF ()
# invoke macro to create sources for our custom view and display panel
ADD_PARAVIEW_VIEW_MODULE(
# returns the interfaces defined (pass in
# GUI_INTERFACES parameter)
IFACES
# returns a list of source files for this interface
IFACE_SRCS
# give the view type
# With MyView.h implementing a
# pqGenericViewModule and MyView being the XML name
# for the view on the server side
VIEW_TYPE MyView
# the XML group of the view in the server manager xml
VIEW_XML_GROUP views
# the XML name of the display for this view
DISPLAY_XML MyDisplay
# the name of the display panel for this display
# With MyDisplay.h implementing pqDisplayPanel
DISPLAY_PANEL MyDisplay)
# Create a plugin with the new view and its options.
ADD_PARAVIEW_PLUGIN(MyView "1.0"
SERVER_MANAGER_XML MyViewSM.xml
GUI_INTERFACES ${IFACES}
GUI_SOURCES MyView.cxx MyDisplay.cxx
${MOC_SRCS} ${IFACE_SRCS}
)
ENDIF(PARAVIEW_BUILD_QT_GUI)
#include "MyDisplay.h"
#include <QVBoxLayout>
#include <QLabel>
MyDisplay::MyDisplay(pqRepresentation* d, QWidget* p)
: pqDisplayPanel(d,p)
{
// just make a label that shows we made it in the GUI
QVBoxLayout* l = new QVBoxLayout(this);
l->addWidget(new QLabel("From Plugin", this));
}
MyDisplay::~MyDisplay()
{
}
#ifndef MyDisplay_h
#define MyDisplay_h
#include "pqDisplayPanel.h"
/// a simple display panel widget
class MyDisplay : public pqDisplayPanel
{
Q_OBJECT
public:
/// constructor
MyDisplay(pqRepresentation* display, QWidget* p = NULL);
~MyDisplay();
};
#endif // MyDisplay_h
#include "MyView.h"
#include <QLabel>
#include <QVBoxLayout>
#include <QWidget>
#include <vtkSMProxy.h>
#include <pqOutputPort.h>
#include <pqPipelineSource.h>
#include <pqRepresentation.h>
#include <pqServer.h>
MyView::MyView(const QString& viewmoduletype,
const QString& group,
const QString& name,
vtkSMViewProxy* viewmodule,
pqServer* server,
QObject* p)
: pqView(viewmoduletype, group, name, viewmodule, server, p)
{
// our view is just a simple QWidget
this->MyWidget = new QWidget;
this->MyWidget->setAutoFillBackground(true);
new QVBoxLayout(this->MyWidget);
// connect to display creation so we can show them in our view
this->connect(this, SIGNAL(representationAdded(pqRepresentation*)),
SLOT(onRepresentationAdded(pqRepresentation*)));
this->connect(this, SIGNAL(representationRemoved(pqRepresentation*)),
SLOT(onRepresentationRemoved(pqRepresentation*)));
}
MyView::~MyView()
{
delete this->MyWidget;
}
QWidget* MyView::getWidget()
{
return this->MyWidget;
}
void MyView::onRepresentationAdded(pqRepresentation* d)
{
// add a label with the display id
QLabel* l = new QLabel(
QString("Display (%1)").arg(d->getProxy()->GetGlobalIDAsString()),
this->MyWidget);
this->MyWidget->layout()->addWidget(l);
this->Labels.insert(d, l);
}
void MyView::onRepresentationRemoved(pqRepresentation* d)
{
// remove the label
QLabel* l = this->Labels.take(d);
if(l)
{
this->MyWidget->layout()->removeWidget(l);
delete l;
}
}
void MyView::setBackground(const QColor& c)
{
QPalette p = this->MyWidget->palette();
p.setColor(QPalette::Window, c);
this->MyWidget->setPalette(p);
}
QColor MyView::background() const
{
return this->MyWidget->palette().color(QPalette::Window);
}
bool MyView::canDisplay(pqOutputPort* opPort) const
{
pqPipelineSource* source = opPort? opPort->getSource() : 0;