GUI Plugins: RobWorkStudio

The RobWorkStudio GUI is based on Qt, and through the use of Qt plugins, it is possible to extend RobWorkStudio with user-defined features and behavior. Notice that this is very different from the RobWork plugins that makes it possible to extend the core libraries with new features. Please see plugins_sdurw for more information about that subject.

GUI plugins must inherit the rws::RobWorkStudioPlugin class (see C++ API) and implement at least some of its functions. In this section we present two common project templates for creating a GUI plugin:

  • A simple template where Qt gui functionality needs to be added in the hpp/cpp plugin files.

  • An example where Qt designer is used to create an ui file which describe the graphical layout.

Common to both templates is how to load the plugin into RobWorkStudio when they have compiled. The compiled output will be a dynamically linkable file (in Windows it is a .dll file and in Linux it is .so). To use the plugin in your RobWorkStudio installation add the following lines to the RobWorkStudio.ini file in the directory where you start RobWorkStudio from:

SamplePlugin\DockArea=2
SamplePlugin\Filename=libSamplePlugin
SamplePlugin\Path=PATH_TO_PLUGIN
SamplePlugin\Visible=true

Without Qt Designer

This template can be found in the folder RobWorkStudio/example/pluginapp . The files include:

  • SamplePlugin.hpp: the header file of the plugin

  • SamplePlugin.cpp: the source file of the plugin

  • SamplePlugin.json: used by Qt5 for metainformation about the plugin (name, version etc.)

  • resources.qrc: a Qt resource file that enables compiling images directly into exe/dll/so

  • pa_icon.png: a sample icon used in the toolbar of RobWorkStudio

  • CMakeLists.txt: the CMake project file

This example shows how to create a plugin without the use of a ui file from Qt Designer. The header file for the plugin is shown below. The plugin must inherit the RobWorkStudioPlugin class. The open and close functions is called when a WorkCell is opened or closed in RobWorkStudio. The initialize function is called initially when the RobWorkStudio instance is valid. It can be used to initialize values that depend on the RobWorkStudio instance.

RobWorkStudio/example/pluginapp/SamplePlugin.hpp
 1#ifndef SAMPLEPLUGIN_HPP
 2#define SAMPLEPLUGIN_HPP
 3
 4#include <rws/RobWorkStudioPlugin.hpp>
 5
 6class QPushButton;
 7
 8class SamplePlugin: public rws::RobWorkStudioPlugin
 9{
10Q_OBJECT
11Q_INTERFACES( rws::RobWorkStudioPlugin )
12Q_PLUGIN_METADATA(IID "dk.sdu.mip.Robwork.RobWorkStudioPlugin/0.1" FILE "SamplePlugin.json")
13public:
14    SamplePlugin();
15	virtual ~SamplePlugin();
16
17    virtual void open(rw::models::WorkCell* workcell);
18
19    virtual void close();
20
21    virtual void initialize();
22
23private slots:
24    void clickEvent();
25
26    void stateChangedListener(const rw::kinematics::State& state);
27private:
28    QPushButton* _btn0,*_btn1;
29};
30
31#endif /*SAMPLEPLUGIN_HPP*/

In the hpp file the Q_PLUGIN_METADATA macro refers to the file SamplePlugin.json. This file must look like the following:

RobWorkStudio/example/pluginapp/SamplePlugin.json
1{
2            "name" : "SamplePlugin",
3         "version" : "1.0.0",
4    "dependencies" : []
5}

The implementation of the plugin is shown below. In the constructor two pushbuttons are added to the plugin. Each button is connected to the clickEvent function. Qt operates with signals and slots, and in this case the clicked() signal from the pushbutton is connect to the clickEvent() slot defined in the plugin. In the initialize function, a stateChangedListener is registered in RobWorkStudio. This function will be called every time the state changes. In the clickEvent() function we can do different computations depending on the which button was pushed. This can be determined based on the Qt sender().

RobWorkStudio/example/pluginapp/SamplePlugin.cpp
 1#include "SamplePlugin.hpp"
 2
 3#include <QPushButton>
 4#include <QGridLayout>
 5
 6#include <rw/geometry/QHullND.hpp>
 7#include <rw/math/Random.hpp>
 8#include <RobWorkStudio.hpp>
 9
10#include <boost/bind/bind.hpp>
11
12using rw::geometry::QHullND;
13using rw::kinematics::State;
14using namespace rw::math;
15using rw::models::WorkCell;
16
17using rws::RobWorkStudioPlugin;
18
19SamplePlugin::SamplePlugin():
20    RobWorkStudioPlugin("Sample", QIcon(":/pa_icon.png"))
21{
22    QWidget* base = new QWidget(this);
23    QGridLayout* pLayout = new QGridLayout(base);
24    base->setLayout(pLayout);
25    this->setWidget(base);
26
27    int row = 0;
28
29    _btn0 = new QPushButton("Button0");
30    pLayout->addWidget(_btn0, row++, 0);
31    connect(_btn0, SIGNAL(clicked()), this, SLOT(clickEvent()));
32
33    _btn1 = new QPushButton("Button1");
34    pLayout->addWidget(_btn1, row++, 0);
35    connect(_btn1, SIGNAL(clicked()), this, SLOT(clickEvent()));
36
37    pLayout->setRowStretch(row,1);
38}
39
40
41SamplePlugin::~SamplePlugin()
42{
43}
44
45void SamplePlugin::initialize() {
46    getRobWorkStudio()->stateChangedEvent().add(boost::bind(&SamplePlugin::stateChangedListener, this, boost::arg<1>()), this);
47}
48
49void SamplePlugin::open(WorkCell* workcell)
50{
51}
52
53void SamplePlugin::close() {
54}
55
56void SamplePlugin::clickEvent() {
57    QObject *obj = sender();
58    if(obj == _btn0){
59        log().info() << "Button 0 pressed!\n";
60    } else if(obj == _btn1){
61        log().info() << "Button 1 pressed!\n";
62
63
64        std::vector<VectorND<2> > vertices, hullvertices;
65        vertices.resize(100);
66
67        for(size_t i=0;i<vertices.size();i++){
68            vertices[i][0] = Random::ran(-10,10);
69            vertices[i][1] = Random::ran(-10,10);
70        }
71
72        QHullND<2> qhull;
73        qhull.rebuild(vertices);
74
75        hullvertices = qhull.getHullVertices();
76
77        std::cout << "\n INPUT: \n";
78        for(size_t i=0; i<vertices.size();i++){
79            std::cout << vertices[i][0] << "\t" << vertices[i][1] << "\n";
80        }
81
82        std::cout << "\n OUTPUT: \n";
83        for(size_t i=0; i<hullvertices.size();i++){
84            std::cout << hullvertices[i][0] << "\t" << hullvertices[i][1] << "\n";
85        }
86
87
88
89    }
90}
91
92void SamplePlugin::stateChangedListener(const State& state) {
93    log().info() << "State changed!";
94}

In the cpp file the constructor refers to the path “:/pa_icon.png”. This is using the Qt resource system. A resources.qrc file is used to define the files that can be used in the plugin. By using this system, the graphics will be compiled into the plugin binary (the .dll or .so files). It is up to the user to define a plugin icon.

RobWorkStudio/example/pluginapp/resources.qrc
1<!DOCTYPE RCC><RCC version="1.0">
2<qresource>
3<file>pa_icon.png</file>
4</qresource>
5</RCC>

The CMake file used for compiling the plugin is shown below:

RobWorkStudio/example/pluginapp/CMakeLists.txt
 1# Test CMake version
 2cmake_minimum_required(VERSION 3.10  )
 3
 4# The name of the project.
 5project(PluginApp)
 6
 7set(CMAKE_CXX_STANDARD 17)
 8
 9# Used to resolve absolute path names
10set(ROOT ${CMAKE_CURRENT_SOURCE_DIR})
11
12# Now set the RW/RWS root (edit this if necessary)
13if(DEFINED ENV{RW_ROOT} AND DEFINED ENV{RWS_ROOT})
14  file(TO_CMAKE_PATH "$ENV{RW_ROOT}" RW_ROOT)
15  file(TO_CMAKE_PATH "$ENV{RWS_ROOT}" RWSTUDIO_ROOT)
16else()
17  set(RW_ROOT "${ROOT}/../../../RobWork")
18  set(RWSTUDIO_ROOT "${ROOT}/../../../RobWorkStudio")
19endif()
20
21# If not the -DCMAKE_BUILD_TYPE option is given when running CMake, use Release as default.
22if( NOT DEFINED CMAKE_BUILD_TYPE )
23    set(CMAKE_BUILD_TYPE Release)
24endif()
25message("-- Build type: " ${CMAKE_BUILD_TYPE})
26
27# Include default settings for constructing a RobWork dependent project
28set(RobWork_DIR ${RW_ROOT}/cmake) 
29find_package(RobWork REQUIRED)
30message("-- RobWork found: " ${RW_ROOT})
31
32# Include default settings for constructing a RobWorkStudio dependent project
33set(RobWorkStudio_DIR ${RWSTUDIO_ROOT}/cmake)
34find_package(RobWorkStudio REQUIRED)
35message("-- RobWorkStudio found: " ${RWSTUDIO_ROOT})
36
37
38set(CMAKE_AUTOMOC ON)
39set(CMAKE_AUTORCC ON)
40
41# Add the source files to build
42set(SrcFiles SamplePlugin.cpp resources.qrc)
43
44# The shared library to build:
45add_library(PluginApp MODULE ${SrcFiles})
46target_link_libraries(PluginApp PUBLIC RWS::sdurws RW::sdurw)
47
48message("-- " ${PROJECT_NAME} " done!")

The CMake script will look for RobWork and RobWorkStudio, and it will set the output directories for libraries and executables. In the last few lines, the CMAKE_AUTOMOC and CMAKE_AUTORCC is enabled, before the library is added and linked to RobWork and RobWorkStudio. AUTOMOC and AUTORCC are CMake features that takes care of some Qt specific stuff automatically.

Before running CMake, you should set the RW_ROOT and RWS_ROOT environment variables to the path for RobWork and RobWorkStudio respectively.

To compile the plugin you should first create a separate build directory and run CMake from there:

cmake -DCMAKE_BUILD_TYPE=Release path/to/plugin

On Windows you should specify the generator:

cmake -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 15 2017 Win64" path/to/plugin

You need to set the build type to the same build type that you used for compiling RobWork. Insert the correct path to the plugin code.

Build the plugin with make (on Linux):

make

In Windows, open the SamplePlugin solution in Visual Studio (solution was generated with CMake).

When the .dll or .so file is generated it can be loaded from the RobWorkStudio menu Plugins->Load Plugin. Alternatively it can be added to RobWorkStudio.ini to be automatically loaded at startup.

With Qt Designer

This template can be found in the folder RobWorkStudio/example/pluginUIapp. It involves the same files as the template Without Qt Designer, but with the additional file SamplePlugin.ui. The .ui file is a Qt Designer file. Qt Designer makes it possible to develop the graphical layout of the plugin in a drag and drop fashion. For more complex plugins this is much more intuitive, than programming it up in C++.

In the following we will discuss the changes compared to the template Without Qt Designer, so please refer to this section for more details.

The header file for the plugin is shown below. Compared to the template Without Qt Designer, the header file does not have QPushButton objects defined as private members. These buttons are instead defined in the .ui file. By including ui_SamplePlugin.hpp and inheriting from Ui::SamplePlugin, these buttons can be accessed from our C++ code.

RobWorkStudio/example/pluginUIapp/SamplePlugin.hpp
 1#ifndef SAMPLEPLUGIN_HPP
 2#define SAMPLEPLUGIN_HPP
 3
 4#include <rws/RobWorkStudioPlugin.hpp>
 5
 6#include "ui_SamplePlugin.h"
 7
 8class SamplePlugin: public rws::RobWorkStudioPlugin, private Ui::SamplePlugin
 9{
10Q_OBJECT
11Q_INTERFACES( rws::RobWorkStudioPlugin )
12Q_PLUGIN_METADATA(IID "dk.sdu.mip.Robwork.RobWorkStudioPlugin/0.1" FILE "plugin.json")
13public:
14    SamplePlugin();
15	virtual ~SamplePlugin();
16
17    virtual void open(rw::models::WorkCell* workcell);
18
19    virtual void close();
20
21    virtual void initialize();
22
23private slots:
24    void btnPressed();
25
26    void stateChangedListener(const rw::kinematics::State& state);
27};
28
29#endif /*SAMPLEPLUGIN_HPP*/

The implementation of the plugin is shown below. The constructor is more simple, since the buttons are easily set up with the setupUi(this) call. All we need to do is to connect the signals and slots.

RobWorkStudio/example/pluginUIapp/SamplePlugin.cpp
 1#include "SamplePlugin.hpp"
 2
 3#include <RobWorkStudio.hpp>
 4
 5#include <boost/bind/bind.hpp>
 6
 7using rw::kinematics::State;
 8using rw::models::WorkCell;
 9using rws::RobWorkStudioPlugin;
10
11SamplePlugin::SamplePlugin():
12    RobWorkStudioPlugin("SamplePluginUI", QIcon(":/pa_icon.png"))
13{
14    setupUi(this);
15
16    // now connect stuff from the ui component
17    connect(_btn0    ,SIGNAL(pressed()), this, SLOT(btnPressed()) );
18    connect(_btn1    ,SIGNAL(pressed()), this, SLOT(btnPressed()) );
19    connect(_spinBox  ,SIGNAL(valueChanged(int)), this, SLOT(btnPressed()) );
20
21}
22
23SamplePlugin::~SamplePlugin()
24{
25}
26
27void SamplePlugin::initialize() {
28    getRobWorkStudio()->stateChangedEvent().add(boost::bind(&SamplePlugin::stateChangedListener, this, boost::arg<1>()), this);
29}
30
31void SamplePlugin::open(WorkCell* workcell)
32{
33}
34
35void SamplePlugin::close() {
36}
37
38void SamplePlugin::btnPressed() {
39    QObject *obj = sender();
40    if(obj==_btn0){
41        log().info() << "Button 0\n";
42    } else if(obj==_btn1){
43        log().info() << "Button 1\n";
44    } else if(obj==_spinBox){
45        log().info() << "spin value:" << _spinBox->value() << "\n";
46    }
47
48
49}
50
51void SamplePlugin::stateChangedListener(const State& state) {
52
53}

The CMake file used for compiling the plugin is shown below:

RobWorkStudio/example/pluginapp/CMakeLists.txt
 1# Test CMake version
 2cmake_minimum_required(VERSION 3.10  )
 3
 4# The name of the project.
 5project(PluginUIApp)
 6
 7set(CMAKE_CXX_STANDARD 17)
 8
 9
10# If not the -DCMAKE_BUILD_TYPE option is given when running CMake, use Release as default.
11if( NOT DEFINED CMAKE_BUILD_TYPE )
12    set(CMAKE_BUILD_TYPE Release)
13endif()
14message("-- Build type: " ${CMAKE_BUILD_TYPE})
15
16# Include default settings for constructing a RobWork dependent project
17set(RobWork_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../RobWork/cmake)
18find_package(RobWork REQUIRED)
19message("-- RobWork found: " ${RW_ROOT})
20
21# Include default settings for constructing a RobWorkStudio dependent project
22set(RobWorkStudio_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)
23find_package(RobWorkStudio REQUIRED)
24message("-- RobWorkStudio found: " ${RWSTUDIO_ROOT})
25
26set(CMAKE_AUTOMOC ON)
27set(CMAKE_AUTORCC ON)
28set(CMAKE_AUTOUIC ON)
29
30# Add the source files to build
31set(SrcFiles SamplePlugin.cpp resources.qrc)
32
33# The shared library to build:
34add_library(PluginUIApp MODULE ${SrcFiles})
35target_link_libraries(PluginUIApp PUBLIC RWS::sdurws RW::sdurw)
36
37if(CMAKE_VERSION VERSION_LESS 3.9)
38    # Required in CMake < 3.9 to find generated ui_SamplePlugin.h file 
39    target_include_directories(PluginUIApp PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
40endif()
41
42message("-- " ${PROJECT_NAME} " done!")

The CMake script is almost identical to the one for the Without Qt Designer template. Since we have .ui files, we also enable the CMAKE_AUTOUIC feature. This way CMake and Qt automatically generates the ui_SamplePlugin.h file that we include in the SamplePlugin.hpp file.

With Python

** OBS This only works for older versions of PySide2 that doesn’t ship with QT ** Plugins can also be made, in form of a python script. To Enable this feature Python3-dev must be installed on the system, before compiling RobWorkStudio. Python plugins are in actuality a c++ plugin with a python interpreter loaded into it. To allow modification of the pluginGUI the c++ plugin starts by running a script in the python interpreter, before calling the user written python plugin.

from sdurws import *
import sys
from PySide2 import QtCore

class cpp_link(QtCore.QObject): ... #Class used by the cpp plugin to make calls to python plugins
rws_cpp_link = cpp_link #           #Object used to facilitate the calls

class rwsplugin(QtCore.QObject):    #inherit from this class to access RobworkStudio and QtWidget
    def __init__(self,link):
    def getWidget(self):            #Returns a widget to be used by PiSide2
    def getRobWorkStudio(self):     #Returns a pointer to RobworkStudio
    def getWorkCell(self):          #Returns a pointer to the currently loaded WorkCell
    def log(self):                  #Returns a pointer to the current Log

As can be seen from the code it relies on PySide2 as a wrapper to qt. So to make a python plugin PySide must be installed.

pip3 install PySide2

PySide2 often relies on the newest version of QT. To test if you have the right version open a python interpreter and run:

from PySide2 import QtCore

If something is wrong this should give you an error with incompatible QT versions. To get the correct Version of QT you need to do a proper install and get the required QT version. This can be done by downloading the QT installer from https://www.qt.io/download/ . At the Select component phase of the installation, make sure that you are installing the version required by PySide2.

Ones the correct version of QT is installed, if PySide still gives the same error, it means that it can’t find the correct QT installation. For Linux users the path can be specified by the QT library path to LD_LIBRARY_PATH. This can be done by adding the following line to .bashrc or calling the line from the terminal

#example -------------||----------------/Path/To/Qt/<Version_number>/<compiler>/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/Qt/5.13.1/gcc_64/lib

With this, the setup is complete and you should be able to run your own or one of the example plugins for python.

Designing a python plugin

Make sure that the Python file used is called something unique, as currently the pluginWidget is named the same as the python file, and is found by searching for it’s name when calling rwsplugin.getWidget().

The simplest plugin, that can be made with full functionality, can be seen in the code below. Using the rws_cpp_link, three different methods is called, in the registered plugin(if they exist). Inheriting from the rwsplugin class, gives you the some of the same functionality as a cpp plugin

class samplePlugin(rwsplugin):
  def __init__(self,link):
    super().__init__(link)              #initialize the underlying rwsplugin
    self.widget = super().getWidget()   #get the widget
  def open(self,workcell):              #this method is called by rws_cpp_link when a new workcell is opened in RobWorkStudio
    pass
  def close(self):                      #this method is called by rws_cpp_link when current workcell is closed
    pass
  def stateChangedListener(self,state): #this method is called by rws_cpp_link when the state changes in RobWorkStudio
  pass

if __name__ == '__main__':
  pl = Plugin(rws_cpp_link)
  rws_cpp_link.register_plugin(pl)

Due to the rwsplugin and rws_cpp_link is automatically imported upon loading a python plugin, the above plugin runs without importing any modules

Tips & Examples

Here are some small useful examples that can be used from a plugin

Get CollisionDetector

Get the collision detector that is currently used in your RobWorkStudio instance:

CollisionDetector *detector = getRobWorkStudio()->getCollisionDetector();

Communication between plugins

RobWorkStudio has a number of events which can be used by the plugins. A plugin can register for an event, for example by:

getRobWorkStudio()->stateChangedEvent().add(boost::bind(&MyPlugin::stateChangedListener, this,_1), this);

which binds the stateChangedListener method of MyPlugin to listen for state changed event.

To see more information about the different event please consult the RobWorkStudio API documentation.

Adding new frames to the workcell from a plugin

This example describe how one can add his own frames to the workcell through a user plugin.

Adding frames to the workcell is possible through the StateStructure instance that is located in a WorkCell. It is important to understand that adding frames to the state structure will change the static state structure of the workcell (the dynamic state is that which is located in the State object). Changing the static structure will not directly influence State objects, that is they are still valid for all frames except the newly added frames. There exist two methods of making an old state valid for new frames. One is to just assign the old state with a new one. Though, this will also overwrite any state information that was saved in the old state, say the configuration of your robot. If you want to preserve the information in the old state and still make it valid for newly added frames you would need to upgrade it. You can upgrade a state oldstate using either StateStructure instance stateStruct or another state newstate. Following is an example of how:

// using another state to upgrade
oldstate.upgradeTo(newstate); // oldstate is upgraded to the structure of the newstate
// using state structure to upgrade
oldstate = stateStruct.upgrade( oldstate );

Following is an example of how to add a new frame to the workcell from your own plugin

State oldState; // this is your old state
Frame *newFrame = make_new_frame(); // create your frame
getRobWorkStudio()->getWorkcell()->getStructure()->addFrame(newFrame,parentFrame);
// now update the oldState with the new state
oldState = getRobWorkStudio()->getWorkCell()->getStructure()->upgradeState(oldState);
// now this is VERY important, remember to update the RobWorkStudio state
getRobWorkStudio()->setState(oldState);

Adding Drawable from a plugin

Before considering the example, a bit of background is needed about the RobWork and RobWorkStudio scene model.

The most abstract model of a scene in RobWork is defined in rw::graphics. It is based on the SceneGraph model. SceneGraph defines elements in a scene for visualization. It is independent from the usual RobWork structure of frames. As such it is a more generic model of a scene. A SceneGraph contains:

  • CameraGroups: A group of cameras can be used, for instance, to render background, render scene elements and render foreground. Each camera in the group is a SceneCamera (see below).

  • Tree of SceneNodes with a root GroupNode.

    • GroupNode: Groups other SceneNodes (it is a non-leaf node)

    • DrawableNode: A node with something that can be drawn in the scene. It has a draw mask to distinguish between different groups to be shown in the scene.

      • DrawableGeometryNode: A DrawableNode that draws a rw::geometry::Geometry.

      • DrawableNodeClone: A node that reuses another DrawableNodes data, but has its own visualization settings.

    • SceneCamera: A node representing a camera in the scene.

    • Other user defined node types

WorkCellScene is a wrapper for the more generic SceneGraph. It uses the Frame structure from a WorkCell and State, to maintain a corresponding underlying SceneGraph. In the WorkCellScene, DrawableNodes can be added and retrieved for each Frame in the WorkCell. It has convenience functions, for instance, for adding Renders or Drawables and Geometries from files. WorkCellScene keeps track of the visualization of frames and visibility of frames in the WorkCell.

SceneViewer is an interface for the actual visualization of a SceneGraph. Implementations should allow for:

  • A main view: The SceneCamera that is mainly used to visualize the scene.

  • A current view: The currently selected view.

  • Function for updating view(s).

  • Zoom functions.

  • WorkCellScene (optional): if the SceneGraph is wrapped by a WorkCellScene.

The code for adding a Drawable from a plugin could look like the following (here we make a DrawableNode for a Render):

using namespace rw::graphics;
using rw::kinematics::Frame;
using rws::RWStudioView3D;

const RWStudioView3D::Ptr rwsview = getRobWorkStudio()->getView();
const SceneViewer::Ptr viewer = rwsview->getSceneViewer();
const SceneGraph::Ptr graph = viewer->getScene();
const WorkCellScene::Ptr wcscene = rwsview->getWorkCellScene();

const Render::Ptr render = ownedPtr(new MyRender());
Frame* const myFrame = getRobWorkStudio()->getWorkCell()->findFrame("myFrame");

// Method 1
const DrawableNode::Ptr drawableNode = graph->makeDrawable("Render", render, DrawableNode::Physical);
wcscene->addDrawable(drawableNode, myFrame);

// Method 2 (use convenience method on WorkCellScene)
wcscene->addRender("Render", render, myFrame, DrawableNode::Physical);

The RWStudioView3D is the main visualization area in RobWorkStudio. This visualization uses the SceneViewer model (with the underlying SceneGraph). The SceneGraph model is wrapped in a WorkCellScene that can also be retrieved from RWStudioView3D. The WorkCellScene takes care of maintaining the underlying SceneGraph. In RobWorkStudio, getWorkCellScene actually returns a SceneOpenGLViewer. SceneOpenGLViewer is a specialization that uses Qt and OpenGL. It adds background to the scene, the pivot point and the default RobWorkStudio view. It also controls which DrawableNode types to draw (Physical, Virtual etc) based on the chosen settings in RobWorkStudio. First step is to retrieve these entities from the RWStudioView3D.

Next, we create a render. Render is an interface that defines a draw function. It is up to the user to implement the Render class. In rwlibs::opengl, many Render types are implemented for drawing in OpenGL (as we currently use in RobWorkStudio). This is types for rendering images, geometries, point-clouds, lines, vectors, and much more.

A DrawableNode is then created in the SceneGraph for the Render. This node is not yet connected to any child or parent nodes. By calling addDrawable on the WorkCellScene, we let the WorkCellScene take care of attaching the DrawableNode correctly to the tree, based on the Frame given to addDrawable.

Notice that the code is completely independent from OpenGL (except if we create the Render from types in rwlibs::opengl). The framework would allow RobWorkStudio to change to something else than OpenGL, and our plugin would still work.

Getting Drawables from a Frame

This code snippet will copy all Drawables associated with the Frame frameWithDrawables into the vector drawables:

using namespace rw::graphics;
using rw::kinematics::Frame;
using rws::RWStudioView3D;

const RWStudioView3D::Ptr rwsview = getRobWorkStudio()->getView();
const WorkCellScene::Ptr wcscene = rwsview->getWorkCellScene();

Frame *frameWithDrawables; // specify the frame where your drawables are placed
std::vector<DrawableNode::Ptr> drawables = wcscene->getDrawables(frameWithDrawables);

The next code snippet will copy all drawables associated to any frame in the WorkCell into the vector drawables.

using namespace rw::graphics;
using rws::RWStudioView3D;

const RWStudioView3D::Ptr rwsview = getRobWorkStudio()->getView();
const WorkCellScene::Ptr wcscene = rwsview->getWorkCellScene();

std::vector<DrawableNode::Ptr> drawables = wcscene->getDrawables();