Definition
The abstract base class LayoutInterface defines the generic interface to access the graphical attributes of a graph. The LEDA graph class contains only the topology of a graph, e.g., the nodes and edges. If you want to produce a graphical representation of a graph, you need additional attributes such as the graphics and the position of each node, the line representation of each edge, and some more.
Our graphical model for graphs contains the following attributes:
The Coordinate System We assume a rectilinear coordinate system, where positive x is to the right, positive y is down, and the origin is in the upper left corner. We call this coordinate system the standard coordinate system.
#include < AGD/LayoutInterface.h >
Initialization
LayoutInterface | A(const leda_graph& G) | initializes a layout interface for graph G. |
LayoutInterface | A(const LayoutInterface& li) | |
copy constructor. |
Operations
a) Access to Graphical Attributes The following methods define the generic interface to the graphical attributes of a graph. All of them are pure virtual functions and must be overridden by a specific implementation of LayoutInterface, except for get_position() and set_position(), which have a default implementation.
double | A.get_x(leda_node v) | returns the x-coordinate of the position of node v. |
void | A.set_x(leda_node v, double new_x) | |
sets the x-coordinate of the position of node v to new_x. | ||
double | A.get_y(leda_node v) | returns the y-coordinate of the position of node v. |
void | A.set_y(leda_node v, double new_y) | |
sets the y-coordinate of the position of node v to new_y. | ||
DPoint | A.get_position(leda_node v) | |
returns the position of node v. | ||
void | A.set_position(leda_node v, const DPoint& pos) | |
sets the position of node v to pos. | ||
DPolyline | A.get_bend_points(leda_edge e) | |
returns the bend points of edge e. | ||
void | A.set_bend_points(leda_edge e, const DPolyline& l) | |
sets the bend points of edge e to l. | ||
double | A.get_width(leda_node v) | returns the width of the graphics of node v. |
void | A.set_width(leda_node v, double new_w) | |
sets the width of the graphics of node v to new_w. | ||
double | A.get_height(leda_node v) | returns the height of the graphics of node v. |
void | A.set_height(leda_node v, double new_h) | |
sets the height of the graphics of node v to new_h. | ||
DPoint | A.get_source_anchor(leda_edge e) | |
returns the source anchor position of edge e. | ||
void | A.set_source_anchor(leda_edge e, const DPoint& pos) | |
sets the source anchor position of edge e to pos. | ||
DPoint | A.get_target_anchor(leda_edge e) | |
returns the target anchor position of edge e. | ||
void | A.set_target_anchor(leda_edge e, const DPoint& pos) | |
sets the target anchor position of edge e to pos. |
b) Notification Methods
The following methods can be overridden by derived classes if
necessary. The default implementations do nothing.
c) Further Operations
const leda_graph& | A.get_graph() | returns the associated graph. |
DRect | A.bounding_box() | computes a tight bounding box. |
void | A.make_straight_line() | deletes all edge bends and sets all edge anchors to (0, 0). |
void | A.set_all_anchors(DPoint p = DPoint(0, 0)) | |
sets all source and target anchors to p. | ||
void | A.set_graph(const leda_graph& G) | |
protected method for setting the associated graph. |
Example
The following function translates all nodes displayed in a GraphWin gw by a vector p, removes all bends points, and returns the bounding box of the layout.
DRect translate(GraphWin &gw, DPoint p) { GraphWinInterface gwi(gw); // create layout interface const graph &g = gwi.get_graph(); gwi.make_straight_line(); // remove all bends // shift all nodes by p node v; forall_nodes(v,g) gwi.set_position(v, p + gwi.get_position()); gwi.update(); // update the display return gwi.area(); // compute bounding box }
© Copyright 1998-2001, Algorithmic Solutions Software GmbH. All rights reserved.
2001-08-13