Workspace 7.0.2
|
Workflows consist of both Operations and DataTypes. The operations do the processing, and the data types encapsulate the data being passed from one operation to the next. In this tutorial, we are going to learn how to create our own custom data type.
In the previous tutorial, we used a code wizard to generate the code for a Workspace operation which was automatically added to our plugin. In this tutorial, we're going to use the Create DataType wizard to create our own custom data type to pass around between operations in workflows. Specifically, we're going to create our own Rectangle class. To start the wizard:
Development
menu and select Create Workspace datatype
and then Create composite datatype...
This wizard will generate the skeleton code required for a new Workspace data type. Let's fill out the fields on the form:
CSIRO
namespace, as we did in the previous two tutorials.CSIRO::SimplePlugin
.simpleplugin.h
Our form will now look like this:
If we now look at the bottom of the plugin wizard, we will see some derived values. Workspace is showing us the scoped class name of the new datatype, as well as the scoped class name of the plugin that it is going to be added to. Next:
The wizard will now show a screen for creating data members:
Our new datatype, Rectangle, is going to be a very basic representation of a geometric rectangle. This means we only need two data members: a width, and a height. We'll use the double
datatype to represent our width and height:
double
As we did with the plugin wizard, we will now get to select a copyright notice. We don't want one in this case.
Workspace will now generate the code for our new datatype and place it in the directory that we selected earlier (the same directory into which we generated our plugin). If you navigate to this directory, you'll see that it has the following contents:
For more details about the code generated, see Writing a Workspace Datatype - looking at the code or click on one of the links to individual files below.
These are the source and header files that are used to build the new datatype. The header contains our class declaration, and the source contains our class definition. See also Updating the plugin.cpp and CMakeLists files
Now that we've defined our Rectangle, let's update our CalculateRectangleArea operation that we created in the last tutorial. Instead of accepting two double inputs, it will now accept one Rectangle input. Let's have a look at the changes:
You will need to manually add an include directive for rectangle.h in this file. Notice that we now only have one input of type Rectangle
and one output of type double
. Let's have a look at the modified execute() function:
Previously, we were multiplying two doubles together here. Instead, we're now multiplying the two doubles contained within our rectangle datatype. If you wanted to, you could implement this by adding an area()
function to the Rectangle
class and simply have the RectangleArea
operation return the result of this function.
After we build the updated plugin and open up the Workspace editor, we should now be able to create a workflow that looks like this:
This tutorial has introduced you to the essential elements of creating a Workspace data type. The main points to remember are the following:
You may wish to read further about a number of topics related to Workspace data types: