view import/network.d @ 0:e907d2c54ec3

Initial import
author David Bryant <daveb@acres.com.au>
date Wed, 13 May 2009 15:42:39 +0930
parents
children
line wrap: on
line source

module presentation.network;

import presentation.model;

enum EdgeEnd {
    Source,
    Target
};

interface NetworkObserver {
    // Node changes

    void node_added(GraphNode node,
                    GraphElement container);
    void node_changed(GraphNode node);
    void node_relocated(GraphNode node,
                        GraphElement container);
    void node_removed(GraphNode node,
                      GraphElement container);

    // Edge changes

    void edge_added(GraphEdge node,
                    GraphConnector anchor1, GraphConnector anchor2);
    void edge_changed(GraphEdge edge);
    void edge_rerouted();
    void edge_removed();
}

interface Network {
    void add_observer(NetworkObserver observer);
    void remove_observer(NetworkObserver observer);

    //
    // Interrogation:
    //

    GraphNode[] get_root_nodes();

    // Inquire whether in principle a node of node_type
    // can be added at the given point, possibly nested
    // within the nest node. The nest can be null.
    bool can_add(char[] node_type,
                 Point point,           // necessary?
                 GraphNode nest);

    bool can_relocate(GraphNode node);

    bool can_remove(GraphNode node);

    // Inquire whether in principle the source element can
    // be connected to the target element using
    // an edge of edge_type. This might return true even
    // though the real operation would fail due to deeper checking.
    bool can_connect(char[] edge_type,
                     GraphElement source_element, Point source_point,
                     GraphElement target_element, Point target_point);

    // Inquire whether in principle a given end of an existing edge
    // can be rerouted from old_element to new_element at new_point.
    // old_element and new_element may be the same element.
    bool can_reroute(GraphEdge edge, EdgeEnd end,
                     GraphElement old_element,
                     GraphElement new_element, Point new_point);

    bool can_disconnect(GraphEdge edge);

    //
    // Manipulation:
    //

    // Attempt to really add a node...
    GraphNode add(char[] node_type, /* initial properties, */
                  Point point,
                  GraphNode nest);

    void relocate(GraphNode node,
                  GraphElement old_container,
                  GraphElement new_container, Point new_point);

    // Attempt to really remove a node
    void remove(GraphNode node);

    // Attempt to really connect the source element to the target element
    // using an edge of the given type with the given initial properties.
    GraphEdge connect(char[] edge_type, /* initial properties, */
                      GraphElement source_element, Point source_point,
                      GraphElement target_element, Point target_point);

    // Attempt to really reroute..
    void reroute(GraphEdge edge, EdgeEnd end,
                 GraphElement old_element,
                 GraphElement new_element, Point new_point);

    // Attempt to really remove an edge...
    void disconnect(GraphEdge edge);
}