Graph Layout > Using Advanced Features > Using Layout Event Listeners
 
Using Layout Event Listeners
The layout event listeners mechanism provides a way to inform the end user of what is happening during the layout. At times, a layout algorithm may take a long time to execute, especially when dealing with large graphs. In addition, an algorithm may not converge in some cases. No matter what the situation, the end user should be informed of the events that occur during the layout. This can be done by implementing a simple progress bar or by displaying appropriate information, such as the current cost function value, after each iteration or step.
The layout event listener is defined by the IlvGraphLayoutListener class. To receive the layout events delivered during the layout, a class must implement the IlvGraphLayoutListener interface and must register itself using the addGraphLayoutEventListener method of the IlvGraphLayout class.
When you subclass the IlvGraphLayoutListener class, you must implement the IlvGraphLayout::layoutStepPerformed method. The layout algorithm will call this method on all the registered layout event listeners, passing the layout report as an argument. In this way, you can read information about the current state of the layout report. (For example, you can read this information after each iteration or step of the layout algorithm).
The following example shows how to implement a layout event listener. This example uses the Orthogonal Link Layout.
class OrthogonalIterationListener
: public IlvGraphLayoutListener
{
public:
OrthogonalIterationListener()
: IlvGraphLayoutListener(), i(0)
{ }
void layoutStepPerformed(const IlvGraphLayoutEvent& event)
{
++i;
IlvOrthogonalLinkLayout* layout =
(IlvOrthogonalLinkLayout*)event.getLayout();
IlvPrint("iteration %d over %d",
i,
layout->getAllowedNumberOfIterations());
}
private:
IlUInt i;
};
 
Then, register the listener on the layout instance as follows:
IlvGraphLayout* layout = new IlvOrthogonalLinkLayout();
OrthogonalIterationListener* listener = new OrthogonalIterationListener();
 
layout->addGraphLayoutEventListener(listener);
 

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.