Commit 1f141463 authored by John Tourtellott's avatar John Tourtellott
Browse files

Add pqPluginLocationInterface for dynamically-loaded plugins

parent 91eaadc7
Pipeline #207276 failed with stages
......@@ -57,6 +57,8 @@ set(paraview_cmake_module_files
pqDockWindowImplementation.h.in
pqGraphLayoutStrategyImplementation.cxx.in
pqGraphLayoutStrategyImplementation.h.in
pqPluginLocationImplementation.cxx.in
pqPluginLocationImplementation.h.in
pqPropertyWidgetInterface.cxx.in
pqPropertyWidgetInterface.h.in
pqServerManagerModelImplementation.cxx.in
......
......@@ -1860,6 +1860,76 @@ function (paraview_plugin_add_auto_start)
PARENT_SCOPE)
endfunction ()
#[==[.md
### Location
The filesystem location of dynamically-loaded plugin.
```
paraview_plugin_add_location(
CLASS_NAME <name>
[STORE <function>]
INTERFACES <variable>
SOURCES <variable>)
```
* `CLASS_NAME`: The name of the location class.
* `STORE`: (Defaults to `StoreLocation`) The name of the method to call on
startup, passing in the plugin location (const char*).
* `INTERFACES`: The name of the generated interface.
* `SOURCES`: The source files generated by the interface.
#]==]
function (paraview_plugin_add_location)
cmake_parse_arguments(_paraview_location
""
"CLASS_NAME;INTERFACES;SOURCES"
""
${ARGN})
if (_paraview_location_UNPARSED_ARGUMENTS)
message(FATAL_ERROR
"Unparsed arguments for paraview_plugin_add_location: "
"${_paraview_location_UNPARSED_ARGUMENTS}")
endif ()
if (NOT DEFINED _paraview_location_CLASS_NAME)
message(FATAL_ERROR
"The `CLASS_NAME` argument is required.")
endif ()
if (NOT DEFINED _paraview_location_INTERFACES)
message(FATAL_ERROR
"The `INTERFACES` argument is required.")
endif ()
if (NOT DEFINED _paraview_location_SOURCES)
message(FATAL_ERROR
"The `SOURCES` argument is required.")
endif ()
if (NOT DEFINED _paraview_location_STORE)
set(_paraview_location_STORE "StoreLocation")
endif ()
configure_file(
"${_ParaViewPlugin_cmake_dir}/pqPluginLocationImplementation.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/${_paraview_location_CLASS_NAME}Implementation.h"
@ONLY)
configure_file(
"${_ParaViewPlugin_cmake_dir}/pqPluginLocationImplementation.cxx.in"
"${CMAKE_CURRENT_BINARY_DIR}/${_paraview_location_CLASS_NAME}Implementation.cxx"
@ONLY)
set("${_paraview_location_INTERFACES}"
"${_paraview_location_CLASS_NAME}Implementation"
PARENT_SCOPE)
set("${_paraview_location_SOURCES}"
"${CMAKE_CURRENT_BINARY_DIR}/${_paraview_location_CLASS_NAME}Implementation.cxx"
"${CMAKE_CURRENT_BINARY_DIR}/${_paraview_location_CLASS_NAME}Implementation.h"
PARENT_SCOPE)
endfunction ()
#[==[.md
### Tree layout strategy
......
// Generated file. Do not edit.
/*=========================================================================
Program: ParaView
Module: @_paraview_location_CLASS_NAME@Implementation.cxx
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 "@_paraview_location_CLASS_NAME@.h"
#include "@_paraview_location_CLASS_NAME@Implementation.h"
#include <vtkPVPlugin.h>
//-----------------------------------------------------------------------------
@_paraview_location_CLASS_NAME@Implementation::@_paraview_location_CLASS_NAME@Implementation(QObject* p)
: QObject(p)
{
this->UserImplementation = new @_paraview_location_CLASS_NAME@();
setObjectName("@_paraview_location_CLASS_NAME@");
vtkPVPlugin* plugin = dynamic_cast<vtkPVPlugin*>(p);
if (plugin != nullptr)
{
this->StoreLocation(plugin->GetFileName());
}
}
//-----------------------------------------------------------------------------
@_paraview_location_CLASS_NAME@Implementation::~@_paraview_location_CLASS_NAME@Implementation()
{
delete this->UserImplementation;
this->UserImplementation = nullptr;
}
//-----------------------------------------------------------------------------
void @_paraview_location_CLASS_NAME@Implementation::StoreLocation(const char* location)
{
this->UserImplementation->@_paraview_location_STORE@(location);
}
// Generated file. Do not edit.
/*=========================================================================
Program: ParaView
Module: @_paraview_location_CLASS_NAME@Implementation.h
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 @_paraview_location_CLASS_NAME@Implementation_h
#define @_paraview_location_CLASS_NAME@Implementation_h
#include "pqPluginLocationInterface.h"
#include <QObject>
class @_paraview_location_CLASS_NAME@;
class @_paraview_location_CLASS_NAME@Implementation : public QObject, public pqPluginLocationInterface
{
Q_OBJECT
Q_INTERFACES(pqPluginLocationInterface)
public:
@_paraview_location_CLASS_NAME@Implementation(QObject* p=0);
~@_paraview_location_CLASS_NAME@Implementation() override;
/// Called once after the ParaView starts. If ParaView is already running when
/// the plugin is loaded, this method will be called when the plugin is loaded.
void StoreLocation(const char* location) override;
protected:
@_paraview_location_CLASS_NAME@ *UserImplementation;
};
#endif
## Plugin Location Interface
Dynamically-loaded plugins can now get the file system location of the
plugin binary file (DLL, shared object) with the addition of the
`pqPluginLocationInterface` class and `paraview_add_plugin_location` cmake
function. This allows dynamic plugins to include text and/or data files
that can be located and loaded at runtime.
......@@ -76,6 +76,7 @@ set(classes
pqPipelineRepresentation
pqPipelineSource
pqPlotMatrixView
pqPluginLocationInterface
pqPluginManager
pqProgressManager
pqPropertyLinks
......
/*=========================================================================
Program: ParaView
Module: $RCSfile$
Copyright (c) 2005,2006 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 "pqPluginLocationInterface.h"
//-----------------------------------------------------------------------------
pqPluginLocationInterface::pqPluginLocationInterface()
{
}
/*=========================================================================
Program: ParaView
Module: pqPluginLocationInterface.h
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.
=========================================================================*/
/*
* Copyright (c) 2007, Sandia Corporation
* All rights reserved.
*
* 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 following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Sandia Corporation 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 Sandia Corporation ``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 Sandia Corporation 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 pqPluginLocationInterface_h
#define pqPluginLocationInterface_h
#include "pqCoreModule.h"
#include <QtPlugin>
/**
* Abstract interface for storing the file system location of a
* dyanamically-loaded plugin.
*/
class PQCORE_EXPORT pqPluginLocationInterface
{
public:
virtual ~pqPluginLocationInterface() = default;
/**
* Called once after the plugin is loaded. If `location` is null, the plugin
* is static and has no file system location.
*/
virtual void StoreLocation(const char* location) = 0;
protected:
pqPluginLocationInterface();
private:
Q_DISABLE_COPY(pqPluginLocationInterface)
};
Q_DECLARE_INTERFACE(pqPluginLocationInterface, "com.kitware/paraview/Location")
#endif // pqPluginLocationInterface_h
......@@ -1044,6 +1044,39 @@ paraview_add_plugin(Autostart
SOURCES pqMyApplicationStarter.cxx ${interfaces})
```
#### Getting the Location of a Dynamically-Loaded Plugin
Some dynamically-loaded plugins include data or text files in the same
directory as the plugin binary object (DLL or shared object). To locate
these files at runtime, plugins can register a callback that is notified
with the file system location of the plugin when it is loaded. To do this,
we need to provide a `QObject` subclass (`pqMyLocationPlugin`) with a
method to store the plugin location.
```cpp
class pqMyPluginLocation : public QObject
{
Q_OBJECT
public:
// Callback when plugin is loaded.
void StoreLocation(const char* location);
};
```
The `CMakeLists.txt` looks as follows:
```cmake
# Macro for adding the location callback. We specify the class name and the
# method to call with the filesystem location as `CLASS_NAME` and `STORE`
# arguments. It returns the interface and sources created in the variables
# passed to the `INTERFACES` and `SOURCES` arguments.
paraview_plugin_add_location(
CLASS_NAME pqMyPluginLocation # the class name for our class
STORE StoreLocation # the method to call when the plugin is loaded
INTERFACES interfaces
SOURCES sources)
```
#### Adding new Representations for 3D View using Plugins
ParaView's 3D view the most commonly used view for showing polygonal or
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment