Algorithmic Solutions > LEDA > LEDA Guide > GraphWin > Programming Interface > Create and Open

Creating and Opening a GraphWin

Creating a GraphWin

A GraphWin has an associated graph and an associated window. Either one of them may or may not be specified in the constructor of the GraphWin.
    GraphWin gw;
constructs a GraphWin gw with a private graph and a private window. Graph and window of gw can be accessed by the operation gw.get_graph(), respectively, gw.get_window().
    GraphWin gw(graph& G);

associates graph G with GraphWin gw.

Remark: G may also be a parameterized graph of some type GRAPH<vtype,etype>. In this case every node and edge has an additional data label attribute in the GraphWin that contains a string representation of the corresponding value.

    GraphWin gw(window & W);
    GraphWin gw(graph& G, window& W);
use window W for displaying the associated graph of gw.

Opening a GraphWin

A GraphWin is opened and displayed by calling
    gw.display();
The interactive interface of GraphWin is started by
    gw.edit();
Remark: In the interactive interface the menus of gw are enabled and the graph associated with gw may be changed interactively. Pressing done terminates the session and returns true, exit in the file menu also terminates the session, but returns false.

Example

The following example declares and displays a GraphWin gw, starts an edit loop that lets the user construct or modify the graph G associated with gw. When done is pressed, G is tested for planarity, exit terminates the loop and the program.
#include <LEDA/graphics/graphwin.h>
#include <LEDA/graph/graph_alg.h>

using namespace leda;

int main()
{
  GraphWin gw("LEDA Graph Editor");
  graph& G=gw.get_graph();
  gw.display(window::center,window::center);

  while (gw.edit()) {
    if (PLANAR(G)) std::cout << "This graph is planar." << std::endl;
    else std::cout << "This graph is non-planar." << std::endl;
  }
		
  return 0;
}

See also:

Programming Interface

GraphWin

Interactive Interface


Graph Data Types

Parameterized Graphs


Windows and Panels

Panel Buttons


Strings


Manual Pages:

Manual Page GraphWin




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH