Algorithmic Solutions > LEDA > LEDA Guide > GraphWin > Customizing the Interactive Interface > Adding Families of Functions

Adding Families of Functions to GraphWin

Sometimes, one wants to add an entire group of functions, all with the same interface, to a menu. Writing a wrapper for each function would be tedious. It is more convenient to write only a single caller function that can deal with all functions of the group. The caller for a function of type function_t has type
    void (*caller)(GraphWin&, function_t);
The gw_add_call() function template adds a function together with its caller to a menu.

Example

We use a family of graph drawing functions as an example. Assume we have a library of graph drawing algorithms and we want to build a graph_draw menu which makes all functions in the library available on a mouse click. We assume, for simplicity, that all graph drawing algorithms take a graph G and compute for every node v of G a position (xcoord[v],ycoord[v]).
    void draw_alg1(const graph& G, node_array<double> xcoord&,
                   node_array<double> xcoord&);
    void draw_alg2(const graph& G, node_array<double> xcoord&,
                   node_array<double> xcoord&);
    ...
A generic caller for this type of graph algorithm looks as follows
    typedef void (*draw_alg) (const graph&,
                              node_array<double> xcoord&, 
                              node_array<double> xcoord&);

    void call_draw_alg(GraphWin&, draw_alg draw)
    {
        //provide arguments
        graph& G=gw.get_graph();
        node_array<double> xcoord(G);
        node_array<double> ycoord(G);
		
        //call function
        draw(G,xcoord,ycoord);
		
        //display result
        gw.adjust_coords_to_win(xcoord,ycoord);
        gw.set_layout(xcoord,ycoord);
        if (!gw.get_flush()) gw.redraw();
    }
The menu is now easily created as follows
    int draw_menu=gw.add_menu("graph drawing");
    gw_add_call(gw,draw_alg1,call_draw_alg,
                "draw_alg1",draw_menu);
    gw_add_call(gw,draw_alg2,call_draw_alg,
                "draw_alg2",draw_menu);
    ...

See also:

Customizing the Interactive Interface

GraphWin

Interactive Interface


Adding New Menus

Adding Simple Functions

Adding GraphWin Member Functions

Complete Example for Customizing the Interface


Windows and Panels


Graph Data Types


Manual Pages:

Manual Page GraphWin




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