Grapher > Features of the Grapher Package > Grapher Links > Base Class for Links
 
Base Class for Links
Figure 2.1 illustrates a straight link connecting two nodes:
Figure 2.1    Direct Link Between Two Nodes
An IlvLinkImage instance is a graphic object that represents the connection between two nodes. By default, it is drawn as a straight line joining the two nodes. The constructor of the IlvLinkImage class is as follows:
IlvLinkImage(IlvDisplay* display,
IlBoolean oriented,
IlvGraphic* from,
IlvGraphic* to,
IlvPalette* palette=0);
The from parameter is an object of type IlvGraphic that represents the start node of the link. The to parameter is an object of type IlvGraphic object that represents its end node. The oriented parameter specifies whether the link ends with an arrow-head.
Several member functions, prefixed by set and get, let you access these properties. For example, the end node can be accessed with the IlvLinkImage::getTo and IlvLinkImage::setTo methods. Similarly, you can change the oriented mode of the link with the IlvLinkImage::setOriented method.
Besides storing these properties, the purpose of the IlvLinkImage class is to:
*Compute the shape of the link as a function of its associated nodes and define how the link behaves when the geometry of the nodes changes. This task is carried out by the IlvLinkImage::getLinkPoints virtual method.
*Define how the link is drawn. This is done using the computed shape and is implemented in the virtual methods inherited from the IlvGraphic class.
Subclassing IlvLinkImage is useful when you want to create a link with a different behavior and/or drawing aspect. To change the behavior, overload the getLinkPoints method:
virtual IlvPoint* getLinkPoints(IlUInt& count,
const IlvTransformer* t) const;
The returned array should not be deleted by the caller. You need to allocate this array on a common memory pool by using the IlvPointPool class. In this method, you can query the geometry of the start and end nodes to determine the points defining the shape of the link. There are two categories of such points:
*The end points of the link. These define where the link starts and ends.
*The intermediate points. These define the overall aspect of the link.
The IlvLinkImage class uses the computePoints method to compute the location of the end points of the link:
virtual void computePoints(IlvPoint& src,
IlvPoint& dst,
const IlvTransformer* t = 0) const;
The default implementation first checks whether the link is associated with a connection pin on the nodes. (See section Connection Pin Management Class for more information.) If no connection pin is defined, the intersection of the link with the bounding boxes of the start and end nodes is computed. This is illustrated in Figure 2.2:
Figure 2.2    End point Location When No Connection Pin is Defined

Version 5.5.1
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.