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