gui/graph_displayer_canvas.cc
author deba
Mon, 28 Nov 2005 11:14:01 +0000
changeset 1833 6d107b0b6b46
parent 1648 dd8672338691
child 1837 8dd6160ff699
permissions -rwxr-xr-x
Radix sort algorithm
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     3 
     4 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
     5   nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
     6   nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms),
     7   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
     8   edgemap_to_edit(""), mapwin(mw)
     9 {
    10   parentwin=mainwin;
    11 
    12   //base event handler is move tool
    13   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    14   actual_tool=MOVE;
    15 
    16   active_node=INVALID;
    17   active_edge=INVALID;
    18   forming_edge=INVALID;
    19 }
    20 
    21 GraphDisplayerCanvas::~GraphDisplayerCanvas()
    22 {
    23   for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
    24   {
    25     delete nodesmap[n];
    26     delete nodetextmap[n];
    27   }
    28 
    29   for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
    30   {
    31     delete edgesmap[e];
    32     delete edgetextmap[e];
    33   }
    34 }
    35 
    36 void GraphDisplayerCanvas::drawGraph()
    37 {
    38   //first edges are drawn, to hide joining with nodes later
    39 
    40   for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    41   {
    42 
    43     //drawing green lines, coordinates are from mapstorage.coords
    44 
    45     Gnome::Canvas::Points coos;
    46     coos.push_back(Gnome::Art::Point(
    47           mapstorage.coords[mapstorage.graph.source(i)].x,
    48           mapstorage.coords[mapstorage.graph.source(i)].y));
    49     coos.push_back(Gnome::Art::Point(
    50           mapstorage.coords[mapstorage.graph.target(i)].x,
    51           mapstorage.coords[mapstorage.graph.target(i)].y));
    52     
    53     edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
    54     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    55     edgesmap[i]->property_width_units().set_value(10);    
    56     edgesmap[i]->lower_to_bottom();
    57     
    58     //initializing edge-text as well, to empty string
    59 
    60     xy<double> text_pos=edgesmap[i]->getArrowPos();
    61     text_pos+=(xy<double>(10,10));
    62 
    63     edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    64     edgetextmap[i]->property_fill_color().set_value("darkgreen");
    65     edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
    66     edgetextmap[i]->raise_to_top();
    67   }
    68 
    69   //afterwards nodes come to be drawn
    70 
    71   for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    72   {
    73     //drawing bule nodes, with black line around them
    74 
    75     nodesmap[i]=new Gnome::Canvas::Ellipse(
    76         displayed_graph,
    77         mapstorage.coords[i].x-20,
    78         mapstorage.coords[i].y-20,
    79         mapstorage.coords[i].x+20,
    80         mapstorage.coords[i].y+20);
    81     *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    82     *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
    83     nodesmap[i]->raise_to_top();
    84 
    85     //initializing edge-text as well, to empty string
    86 
    87     xy<double> text_pos(
    88         (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
    89         (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
    90 
    91     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
    92         text_pos.x, text_pos.y, "");
    93     nodetextmap[i]->property_fill_color().set_value("darkblue");
    94     nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
    95     nodetextmap[i]->raise_to_top();
    96   }
    97 
    98   updateScrollRegion();
    99 }
   100 
   101 void GraphDisplayerCanvas::clear()
   102 {
   103   active_node=INVALID;
   104   active_edge=INVALID;
   105   forming_edge=INVALID;
   106 
   107   for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
   108   {
   109     delete nodesmap[n];
   110     delete nodetextmap[n];
   111   }
   112 
   113   for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
   114   {
   115     delete edgesmap[e];
   116     delete edgetextmap[e];
   117   }
   118 }