gui/graph_displayer_canvas.cc
changeset 1606 dc4ea2010dee
parent 1599 c2f95eac652b
child 1614 350c1d8bb7cc
     1.1 --- a/gui/graph_displayer_canvas.cc	Thu Jul 28 19:09:39 2005 +0000
     1.2 +++ b/gui/graph_displayer_canvas.cc	Fri Jul 29 12:01:37 2005 +0000
     1.3 @@ -1,34 +1,61 @@
     1.4 -#include <graph_displayer_canvas.h>
     1.5 -#include <broken_edge.h>
     1.6 +#include "graph_displayer_canvas.h"
     1.7 +#include "broken_edge.h"
     1.8  #include <math.h>
     1.9  
    1.10 -GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),nodemap_to_edit(""),edgemap_to_edit(""),mapwin(mw)
    1.11 +GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) :
    1.12 +  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
    1.13 +  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
    1.14 +  canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
    1.15 +  target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
    1.16  {
    1.17 -  
    1.18 -  //Initializing values.
    1.19 -  active_node=INVALID;
    1.20 -  active_edge=INVALID;
    1.21 -  forming_edge=INVALID;
    1.22 +  //base event handler is move tool
    1.23 +  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    1.24 +  actual_tool=MOVE;
    1.25  
    1.26    //setting event handler for the editor widget
    1.27    entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
    1.28  
    1.29 -  //base event handler is move tool
    1.30 -  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    1.31 -  actual_tool=MOVE;
    1.32 +  active_node=INVALID;
    1.33 +  active_edge=INVALID;
    1.34 +  forming_edge=INVALID;
    1.35 +}
    1.36  
    1.37 -  //set_center_scroll_region(true);
    1.38 +GraphDisplayerCanvas::~GraphDisplayerCanvas()
    1.39 +{
    1.40 +  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
    1.41 +  {
    1.42 +    delete nodesmap[n];
    1.43 +    delete nodetextmap[n];
    1.44 +  }
    1.45  
    1.46 +  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
    1.47 +  {
    1.48 +    delete edgesmap[e];
    1.49 +    delete edgetextmap[e];
    1.50 +  }
    1.51 +
    1.52 +  if(canvasentrywidget)
    1.53 +  {
    1.54 +    delete(canvasentrywidget);
    1.55 +  }
    1.56 +}
    1.57 +
    1.58 +void GraphDisplayerCanvas::drawGraph()
    1.59 +{
    1.60    //first edges are drawn, to hide joining with nodes later
    1.61  
    1.62 -  for (EdgeIt i(g); i!=INVALID; ++i)
    1.63 +  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    1.64    {
    1.65  
    1.66 -    //drawing green lines, coordinates are from cm
    1.67 +    //drawing green lines, coordinates are from mapstorage.coords
    1.68  
    1.69      Gnome::Canvas::Points coos;
    1.70 -    coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
    1.71 -    coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
    1.72 +    coos.push_back(Gnome::Art::Point(
    1.73 +          mapstorage.coords[mapstorage.graph.source(i)].x,
    1.74 +          mapstorage.coords[mapstorage.graph.source(i)].y));
    1.75 +    coos.push_back(Gnome::Art::Point(
    1.76 +          mapstorage.coords[mapstorage.graph.target(i)].x,
    1.77 +          mapstorage.coords[mapstorage.graph.target(i)].y));
    1.78      
    1.79      edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
    1.80      *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
    1.81 @@ -46,29 +73,27 @@
    1.82  
    1.83    //afterwards nodes come to be drawn
    1.84  
    1.85 -  NodeIt i(g);
    1.86 -  int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
    1.87 -
    1.88 -  for (; i!=INVALID; ++i)
    1.89 +  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    1.90    {
    1.91 -    //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
    1.92 -
    1.93 -    if(cm[i].x>maxx)maxx=(int)cm[i].x;
    1.94 -    if(cm[i].y>maxy)maxy=(int)cm[i].y;
    1.95 -    if(cm[i].x<minx)minx=(int)cm[i].x;
    1.96 -    if(cm[i].y<miny)miny=(int)cm[i].y;
    1.97 -
    1.98      //drawing bule nodes, with black line around them
    1.99  
   1.100 -    nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
   1.101 +    nodesmap[i]=new Gnome::Canvas::Ellipse(
   1.102 +        displayed_graph,
   1.103 +        mapstorage.coords[i].x-20,
   1.104 +        mapstorage.coords[i].y-20,
   1.105 +        mapstorage.coords[i].x+20,
   1.106 +        mapstorage.coords[i].y+20);
   1.107      *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
   1.108      *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
   1.109  
   1.110      //initializing edge-text as well, to empty string
   1.111  
   1.112 -    xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
   1.113 +    xy<double> text_pos(
   1.114 +        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
   1.115 +        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
   1.116  
   1.117 -    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
   1.118 +    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
   1.119 +        text_pos.x, text_pos.y, "");
   1.120      nodetextmap[i]->property_fill_color().set_value("darkblue");
   1.121      nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
   1.122    }
   1.123 @@ -76,36 +101,21 @@
   1.124    updateScrollRegion();
   1.125  }
   1.126  
   1.127 -GraphDisplayerCanvas::~GraphDisplayerCanvas()
   1.128 +void GraphDisplayerCanvas::clear()
   1.129  {
   1.130 -  if(canvasentrywidget)
   1.131 -    {
   1.132 -      delete(canvasentrywidget);
   1.133 -    }
   1.134 +  active_node=INVALID;
   1.135 +  active_edge=INVALID;
   1.136 +  forming_edge=INVALID;
   1.137  
   1.138 -  //writing out the end state of the graph
   1.139 -  //\todo all the maps has to be write out!
   1.140 -
   1.141 -  Graph::NodeMap <int> id(g);
   1.142 -  Graph::NodeMap <double> xc(g);
   1.143 -  Graph::NodeMap <double> yc(g);
   1.144 -  
   1.145 -  int j=1;
   1.146 -  
   1.147 -  for (NodeIt i(g); i!=INVALID; ++i)
   1.148 +  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
   1.149    {
   1.150 -    double x1,y1,x2,y2;
   1.151 -    nodesmap[i]->get_bounds(x1, y1, x2, y2);
   1.152 -    
   1.153 -    id[i]=j++;
   1.154 -    xc[i]=(x1+x2)/2;
   1.155 -    yc[i]=(y1+y2)/2;
   1.156 +    delete nodesmap[n];
   1.157 +    delete nodetextmap[n];
   1.158    }
   1.159  
   1.160 -  GraphWriter<Graph> writer(std::cout,g);
   1.161 -  
   1.162 -  writer.writeNodeMap("id", id);
   1.163 -  writer.writeNodeMap("coordinates_x", xc);
   1.164 -  writer.writeNodeMap("coordinates_y", yc);
   1.165 -  writer.run();
   1.166 +  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
   1.167 +  {
   1.168 +    delete edgesmap[e];
   1.169 +    delete edgetextmap[e];
   1.170 +  }
   1.171  }