2. Interactors

An interactor is construct to interact with a view

In node link diagram view we have many interactors, for example : node builder interactor, selection interactor ... All these interactors have icons and this icons are visible in the toolbar

In interactor Tulip system we have two main classes : InteractorComponent and Interactor itself

Interactor is assembling a set of several interactor component

Interactor example

If you want, you can download an interactor example here

Extract archive, go in the directory, modify your PATH environment varialbe, run make and make install

PATH environment variable must contain the directory where you install you tulip. Here you have an example to modify this variable : export PATH=/home/user/install/tulip/bin:$PATH

All the code of this interactor is commented inside

Interactor Component

An interactor component is the basic building block of the interactor system

To construct an interactor component you have to build a class that inherits InteractorComponent class

InteractorComponent class

In InteractorComponent class we have 7 functions, but 4 of them are implemented on InteractorComponent. So if you want to create a new InteractorComponent, you have to implement 3 functions (4 if you count the eventFilter function)

  • compute : This function is call before the rendering of the scene. It can be used to add GlEntities in the scene

  • draw : This function is call just after the graph rendering. It can be used to add some OpenGL object directly on the OpenGL view

    For example : selection interactor use this function to draw the selection rectangle

  • clone : This function must be implemented to return a copy of the interactor component

  • eventFilter : More important function ! This function is call by Qt to treat the event. You must reimplement this function and treat the event if you can

Interactor itself

You have two options to create an interactor :

  • Directly implement Interactor interface

  • Implement InteractorChainOfResponsibility class

InteractorChainOfResponsibility class is a first partial implementation of Interactor class with chain of responsibility system

InteractorChainOfResponsibility concept

In this class the interactor system is build with the chain of responsibility pattern

Here we have a chain of responsibility of InteractorComponent

You have a list of InteractorComponent. When Qt have an event, this event is passed to first element of this list, if InteractorComponent don't treat this event (function eventFilter return false) the event is passed to second element of the list ...

InteractorChainOfResponsibility class

If you want to use InteractorChainOfResponsibility system, you have some class to implement :

  • In you constructor :

    • Call InteractorChainOfResponsibility constructor with two string. First is the path to interactor icon, second is the interactor tooltip text.

    • Call setPriority(int) function to set the priority of the interactor in the toolbar : if priority is high ( >5 for example) interactor icon is placed at left side of the toolbar

    • Call setConfigurationWidgetText("Text displayed in the configuration widget of the interactor"), an other solution is to reimplement the getConfigurationWidget function who return the QWidget used to configure this interactor

  • Implement construct() function : in this function you have to call pushInteractorComponent(new nameOfYourInteractorComponent) to add interactor component in the chain of responsibility

  • Implement isCompatible(string viewName) function, if your interactor is compatible with view (with name viewName) this function must return true, else return false

Interactor class

If you want to directly use Interactor class (if you doesn't want the chain of responsibility system), you have to implement function :

setView(View *), install(QWidget *), remove(), isCompatible(string), getAction(), compute() and draw()

And you have to call setConfigurationWidgetText(string) (or reimplement getConfigurationWidget()) and setPriority(int)

Interactor function documentation is available in the Library API page

INTERACTORPLUGIN macro

After inplementation of InteractorComponent and Interactor, you have to add you interactor to plugin system :

To do that you have to call INTERACTORPLUGIN macro

INTERACTORPLUGIN(InteractorPluginClassName, "InteractorPluginName", "Authors", "Date", "Interactor plugin full name", "plugin release");