Graph OperationsUpdate Operations of GraphWinGraphWin provides the following update operations of its associated graphnode gw.new_node(const point& p); void gw.del_node(node v); edge gw.new_edge(node v, node w); void gw.del_edge(edge e); void gw.clear_graph(); Using the Update Operations for GraphsThe update operations for graphs can be used for the graph associated with a GraphWin as followsgraph& G=gw.get_graph(); //some update operations on G, e.g., G.new_node(); gw.update_graph();Important Notice: gw.update_graph() informs gw
about the fact that its graph G was modified and allows it
to update its internal data structures. Without the statement G
and the internal data structures of gw will go out of sync
and serious errors may occur.
ExampleThe following example declaresGraphWin gw , defines two nodes
u and v and an edge between them. Then it displays
gw . It defines a reference
G for the graph of gw and creates a new node of G .
Only after a call of gw.update_graph() this node appears in gw .
#include <LEDA/graphics/graphwin.h> #include <LEDA/graph/graph_alg.h> using namespace leda; int main() { GraphWin gw("LEDA Graph Editor"); node u=gw.new_node(point(100,100)); node v=gw.new_node(point(100,200)); gw.new_edge(u,v); gw.display(); gw.get_window().read_mouse(); graph& G=gw.get_graph(); G.new_node(); gw.get_window().read_mouse(); gw.update_graph(); gw.get_window().read_mouse(); return 0; } |
See also:Basic Data Types for 2D Geometry Manual Pages: |