Graph Management
This section describes the management of graphs in Rogue Wave Views. It is divided into two parts:
Description of the IlvGrapher Class
Graphic objects representing graphs are stored in instances of the
IlvGrapher class. This class derives from the
IlvManager class and inherits all its features. The constructors of
IlvManager (the base class) and
IlvGrapher have the same parameters:
IlvGrapher(IlvDisplay* display, int layers = 2, IlBoolean useacc = IlTrue, IlvUShort maxInList = IlvMaxObjectsInList, IlvUShort maxInNode = IlvMaxObjectsInList); |
In addition to the
IlvManager concepts, the
IlvGrapher class introduces a distinction between three types of graphic objects:
Nodes - Nodes are the visual reference points in a hierarchy of information. A node is a graphic object—a subtype of the
IlvGraphic class—that takes on a particular functionality when added to the grapher with the
addNode method. This functionality allows links and nodes to stay connected when a node is moved.
Links - Links are the visual representation of connections between nodes. A link is an instance of the
IlvLinkImage class or one of its subclasses. It is added to the grapher with the
IlvGrapher::addLink method. Since links can only exist between two existing nodes, you must create them with two graphic objects that are known as nodes by the grapher. You can use
ghost nodes (added with the
IlvGrapher::addGhostNode method) to create free-end links.
Ordinary graphic objects - As is the case in a regular
IlvManager instance, you can incorporate in your graph any
IlvGraphic objects that represent neither nodes nor links.
The
IlvGrapher class provides a set of member functions to manage links and nodes. You can, for example, replace a link with another one through a call to the
changeLink method.
You can also transform a graphic object stored in the grapher into a node by calling the
makeNode method. You can apply this method to a grapher link. This allows you to connect the link to other nodes. When dealing with a link that has a node behavior, you must make sure that there is no cycle in the geometric dependencies that govern the position of this link. Similarly, you can transform a graphic object into a grapher link with the
makeLink method. The created link will be an instance of the
IlvLinkHandle class, which is described in section
Grapher Links.
Once objects are stored in an
IlvGrapher, you can make a distinction between nodes, links, and ordinary graphic instances by using the
isNode and
isLink methods.
The
IlvGrapher API also provides several methods to query the topology of your graph. For example, you can test whether two given nodes are connected by using the
isLinkBetween method. You can also retrieve all the outgoing or incoming links of a node by using the
getLinks method.
The sample code below shows how to use the
IlvGrapher::mapLinks method to select all the outgoing links of a node:
static void SelectLink(IlvGraphic* g, IlAny arg)
{
ILVCAST(IlvGrapher*,arg)->setSelected(g,IlTrue);
}
{
...
IlvGrapher* graph = ....;
IlvGraphic* node = ....; // The node being considered
//== Call the SelectLink function on all outgoing links of <node>
graph->mapLinks(node,SelectLink,graph,IlvLinkFrom);
...
}
Finally, the
IlvGrapher class provides two predefined layout methods to arrange nodes in a vertical or horizontal tree structure. These layouts are implemented in the
nodeXPretty and
nodeYPretty methods.
An example showing how to create a simple grapher is provided in the
<ILVHOME>/samples/grapher/simple directory. Also, you can refer to the
Rogue Wave Views Grapher Reference Manual for more information on the member functions of the
IlvGrapher class.
Loading and Saving Graph Descriptions
The
IlvGrapher class reads graphs by using the
IlvGraphInputFile class, and saves graphs by using the
IlvGraphOutputFile class.
IlvGraphOutputFile
The
IlvGraphOutputFile class is a subclass of
IlvManagerOutputFile. In this subclass, the virtual method
IlvGraphOutputFile::writeObject has been redefined to add specific information about each object before its description block. In our case, this information is the layer index, the type of the object (node, link, both, or an ordinary object), as well as the connection pins. Connection pins are described in section
Grapher Links.
IlvGraphInputFile
The
IlvGraphInputFile class is a subclass of
IlvManagerInputFile. In this subclass the virtual method
IlvGraphInputFile::readObject has been redefined to read the specific information written by the
IlvGraphOutputFile::writeObject method.
Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.