/pvxmlgen

Generate ParaView Server Manager XML from C++ headers

Primary LanguagePythonMIT LicenseMIT

pvxmlgen

License: MIT Travis CI Coveralls

Generates ParaView Server Manager XML from C++ headers with specially crafted comments. Full documentation at https://lhofmann.github.io/pvxmlgen/.

Developing ParaView plugins requires the definition of the plugin's interface in an XML format (Server Manager XML). For example, names, labels, data types and default values of the plugin's parameters need to be specified there. Not only does this mean writing lots of boilerplate, but also definitions already specified in the C++ code are duplicated and often desynchronized.

pvxmlgen provides the following features:

  • Fast and less error-prone generation of XML by a sequence of Python commands,
  • Simple integration by adding comments in the C++ header files,
  • Automatic synchronization of default values and names between C++ and XML,
  • Integration with CMake build systems.

Example

A plugin, that has a parameter Position, which is a 3-element double array, needs the following XML definition:

<DoubleVectorProperty command="SetPosition"
                      default_values="1.0 1.0 0.0"
                      name="Position"
                      label="Starting Position"
                      number_of_elements="3"/>

Above XML block has been generated by pvxmlgen from this C++ code:

// pv_( autovector(label='Starting Position') )pv_
double Position[3] {1.0, 1.0, 0.0};

Type, variable name and default values can all be automatically deduced from its C++ definition! Find out more in the documentation.

Usage

Requires Python 3.5+ or 2.7 to run.

Standalone

$ python pvxmlgen.py [input.h] [output.xml]

The result is printed to standard output, if - is passed as output file.

CMake

Add the root directory of pvxmlgen to your CMake project with add_subdirectory. This makes the CMake function pvxmlgen_generate available, which (re-)generates a XML file from a header whenever it is modified. Note, that the XML file in the source directory is overwritten! An example is provided in the subdirectory example/.

add_paraview_plugin(MyFilter 1.0
    SERVER_MANAGER_XML MyFilter.xml
    SERVER_MANAGER_SOURCES vtkMyFilter.cxx)
pvxmlgen_generate(MyFilter INPUT vtkMyFilter.h OUTPUT MyFilter.xml)

Contributing

Run unit tests with pytest and linter with flake8.

$ pip install pytest flake8
$ py.test tests
$ flake8

The directory tests/testcases contains pairs of file.h, file.h.xml, which are automatically tested against each other. Upon test failure, a diff is printed.