Grapher > Features of the Grapher Package > Grapher Interactors
 
Grapher Interactors
The IlvManager class provides a wide range of interactors that are used to create objects and change their shape. The IlvGrapher class contains specific interactors designed to create new nodes and links and change the way they are connected:
*Selection Interactor
*Creating Nodes
*Creating Links
*Editing Connection Pins
*Editing Links
Selection Interactor
The IlvGraphSelectInteractor class derives from the IlvSelectInteractor class. It contains additional member functions used to manage the drawing of ghost images for links attached to nodes that are moved or enlarged. This class has the following constructor:
IlvGraphSelectInteractor(IlvManager* manager, IlvView* view);
This constructor initializes a new instance of the IlvGraphSelectInteractor class that lets you select individual objects or groups of objects in the view view connected to the manager manager. This manager is assumed to be an instance of the IlvGrapher class.
Creating Nodes
The IlvMakeNodeInteractor class is the base class for interactors that allow the user to interactively create nodes in a grapher. Instances of this class must be attached to a grapher and one of its connected views, as shown here:
IlvGrapher* graph = ...;
IlvView* view = ...;
IlvMakeNodeInteractor * inter = new IlvMakeNodeInteractor(graph, view);
graph->setInteractor(inter);
To create a node, drag a rectangular region in the working view. There are two ways to specify what type of graphic object is created:
*Subtype the IlvMakeNodeInteractor class and overload its createNode method.
*Subtype the IlvMakeNodeInteractorFactory class and overload its createNode method. You can associate a node factory with an interactor by using the IlvMakeNodeInteractor::setFactory method.
The grapher library provides predefined subclasses of IlvMakeNodeInteractor:
*IlvMakeShadowNodeInteractor - This interactor creates instances of the IlvShadowLabel class and stores them as nodes in the grapher.
*IlvMakeReliefNodeInteractor - This interactor creates instances of the IlvReliefLabel class and stores them as nodes in the grapher.
Creating Links
The IlvMakeLinkInteractor class is the base class for interactors that allow the user to interactively connect nodes in a grapher. Its constructor is as follows:
IlvMakeLinkInteractor(IlvManager* manager,
IlvView* view,
IlBoolean oriented = IlTrue);
The oriented parameter specifies whether created links are oriented. An example of how to create an interactor of this type and connect it to a grapher and one of its view is presented here:
IlvGrapher* graph = ...;
IlvView* view = graph->getFirstView();
IlvMakeLinkInteractor * inter = new IlvMakeLinkInteractor(graph, view);
graph->setInteractor(inter);
To connect two nodes, perform the following steps:
1. Click the starting node. This node is highlighted if it is considered valid by the interactor.
2. Drag the mouse until it is positioned over the ending node. If this node is valid, it is also highlighted.
3. Release the mouse button to create the link.
You can control which node is valid by overloading the IlvMakeLinkInteractor::acceptFrom and IlvMakeLinkInteractor::acceptTo methods. There are two ways of specifying what type of link should be created:
*Subtype the IlvMakeLinkInteractor class and overload its createLink method.
*Subtype the IlvMakeLinkInteractorFactory class and overload its createLink method. You can associate a link factory with an interactor by using the IlvMakeLinkInteractor::setFactory method.
The Grapher library provides several predefined subclasses of IlvMakeLinkInteractor:
*IlvMakeLinkImageInteractor - This class is used to create a link of type IlvLinkImage.
*IlvMakeLabelLinkImageInteractor - This class is used to create a link of type IlvLinkLabel.
*IlvMakeOneLinkImageInteractor - This class is used to create a link of type IlvOneLinkImage.
*IlvMakeOneSplineLinkImageInteractor - This class is used to create a link of type IlvOneSplineLinkImage.
*IlvMakeDoubleLinkImageInteractor - This class is used to create a link of type IlvDoubleLinkImage.
*IlvMakeDoubleSplineLinkImageInteractor - This class is used to create a link of type IlvDoubleSplineLinkImage.
Creating Polyline Links
The IlvMakePolyLinkInteractor class is a special kind of interactor that does not derive from IlvMakeLinkInteractor.
This interactor is used to create links whose intermediate points can be explicitly defined. It lets you control the shape drawn by the user by means of the IlvMakePolyLinkInteractor::accept method:
virtual IlBoolean accept(IlvPoint& point);
By overloading this method, you can add specific constraints on the position of the intermediate points of the link. Once these points have been defined, the link is created with the IlvMakePolyLinkInteractor::makeLink method, which must be defined in subclasses to return the appropriate link instance. The grapher library provides one predefined subclass, IlvMakePolylineLinkInteractor, which is used to create links of the IlvPolylineLinkImage type.
Editing Connection Pins
The IlvPinEditorInteractor class lets the user interactively edit the connection pins of a grapher node. When this interactor is active, selecting a node will highlight its connection pins, as shown in Figure 2.11:
Figure 2.11    Highlighted Connection Pins
Once a grapher node is selected, you can:
*Add a new connection pin by clicking inside the node.
*Remove a connection pin. To do this, select the pin with the mouse and press the Delete key.
*Move an existing connection pin. To do this, select the pin with the mouse and drag it to its desired location.
*Connect and disconnect links to or from a pin. To do this, first select a connection pin, and then click the considered link.
Note: If the working node is already associated with a pin management object, this object must be of the IlvGenericPin type. If the node does not define any connection pin, then an IlvGenericPin instance is automatically created.
Editing Links
When a link is selected, its selection object draws handles that you can use to change its shape or edit the way it is connected. Figure 2.12 shows a link that has been selected:
Figure 2.12    A Selected Link
An end point handle can be dragged to:
*Change the connection pin to which the link is attached. When the handle is dragged near a connection pin, the pin is highlighted and the link uses its position to compute the location of its end point.
*Connect the link to another node.
The intermediate point handles can be used to edit the shape of the link. The kind of interaction allowed by these handles depends on the kind of link being edited.
Note: Link editing can be turned off by using the IlvGrapher::setLinksEditable method. When an IlvGrapher instance is created, link editing is disabled by default.

Version 5.7
Copyright © 2013, Rogue Wave Software, Inc. All Rights Reserved.