gui/graph_displayer_canvas.cc
author hegyi
Sun, 07 Aug 2005 14:17:11 +0000
changeset 1614 350c1d8bb7cc
parent 1606 dc4ea2010dee
child 1632 93ac8c521fe5
permissions -rwxr-xr-x
Alpar had the key, focus can be set in the window class. But it is not enough, the focused widget has to be activated, as well! Was a hard task to find out... By the way, two compilation warnings are removed.
ladanyi@1606
     1
#include "graph_displayer_canvas.h"
ladanyi@1606
     2
#include "broken_edge.h"
ladanyi@1442
     3
#include <math.h>
ladanyi@1442
     4
hegyi@1614
     5
GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
ladanyi@1606
     6
  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
ladanyi@1606
     7
  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
ladanyi@1606
     8
  canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
ladanyi@1606
     9
  target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
ladanyi@1442
    10
{
hegyi@1614
    11
  parentwin=mainwin;
hegyi@1614
    12
ladanyi@1606
    13
  //base event handler is move tool
ladanyi@1606
    14
  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
ladanyi@1606
    15
  actual_tool=MOVE;
hegyi@1562
    16
hegyi@1562
    17
  //setting event handler for the editor widget
hegyi@1562
    18
  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
hegyi@1562
    19
ladanyi@1606
    20
  active_node=INVALID;
ladanyi@1606
    21
  active_edge=INVALID;
ladanyi@1606
    22
  forming_edge=INVALID;
ladanyi@1606
    23
}
hegyi@1468
    24
ladanyi@1606
    25
GraphDisplayerCanvas::~GraphDisplayerCanvas()
ladanyi@1606
    26
{
ladanyi@1606
    27
  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
ladanyi@1606
    28
  {
ladanyi@1606
    29
    delete nodesmap[n];
ladanyi@1606
    30
    delete nodetextmap[n];
ladanyi@1606
    31
  }
ladanyi@1442
    32
ladanyi@1606
    33
  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
ladanyi@1606
    34
  {
ladanyi@1606
    35
    delete edgesmap[e];
ladanyi@1606
    36
    delete edgetextmap[e];
ladanyi@1606
    37
  }
ladanyi@1606
    38
ladanyi@1606
    39
  if(canvasentrywidget)
ladanyi@1606
    40
  {
ladanyi@1606
    41
    delete(canvasentrywidget);
ladanyi@1606
    42
  }
ladanyi@1606
    43
}
ladanyi@1606
    44
ladanyi@1606
    45
void GraphDisplayerCanvas::drawGraph()
ladanyi@1606
    46
{
ladanyi@1442
    47
  //first edges are drawn, to hide joining with nodes later
ladanyi@1442
    48
ladanyi@1606
    49
  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
ladanyi@1442
    50
  {
ladanyi@1442
    51
ladanyi@1606
    52
    //drawing green lines, coordinates are from mapstorage.coords
ladanyi@1442
    53
ladanyi@1442
    54
    Gnome::Canvas::Points coos;
ladanyi@1606
    55
    coos.push_back(Gnome::Art::Point(
ladanyi@1606
    56
          mapstorage.coords[mapstorage.graph.source(i)].x,
ladanyi@1606
    57
          mapstorage.coords[mapstorage.graph.source(i)].y));
ladanyi@1606
    58
    coos.push_back(Gnome::Art::Point(
ladanyi@1606
    59
          mapstorage.coords[mapstorage.graph.target(i)].x,
ladanyi@1606
    60
          mapstorage.coords[mapstorage.graph.target(i)].y));
ladanyi@1442
    61
    
hegyi@1501
    62
    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
ladanyi@1442
    63
    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
hegyi@1598
    64
    edgesmap[i]->property_width_units().set_value(10);    
ladanyi@1442
    65
    
ladanyi@1442
    66
    //initializing edge-text as well, to empty string
ladanyi@1442
    67
hegyi@1524
    68
    xy<double> text_pos=edgesmap[i]->getArrowPos();
hegyi@1505
    69
    text_pos+=(xy<double>(10,10));
hegyi@1505
    70
hegyi@1505
    71
    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
hegyi@1512
    72
    edgetextmap[i]->property_fill_color().set_value("darkgreen");
hegyi@1599
    73
    edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
ladanyi@1442
    74
  }
ladanyi@1442
    75
ladanyi@1442
    76
  //afterwards nodes come to be drawn
ladanyi@1442
    77
ladanyi@1606
    78
  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
ladanyi@1442
    79
  {
ladanyi@1442
    80
    //drawing bule nodes, with black line around them
ladanyi@1442
    81
ladanyi@1606
    82
    nodesmap[i]=new Gnome::Canvas::Ellipse(
ladanyi@1606
    83
        displayed_graph,
ladanyi@1606
    84
        mapstorage.coords[i].x-20,
ladanyi@1606
    85
        mapstorage.coords[i].y-20,
ladanyi@1606
    86
        mapstorage.coords[i].x+20,
ladanyi@1606
    87
        mapstorage.coords[i].y+20);
ladanyi@1442
    88
    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
ladanyi@1442
    89
    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@1512
    90
hegyi@1512
    91
    //initializing edge-text as well, to empty string
hegyi@1512
    92
ladanyi@1606
    93
    xy<double> text_pos(
ladanyi@1606
    94
        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
ladanyi@1606
    95
        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
hegyi@1512
    96
ladanyi@1606
    97
    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
ladanyi@1606
    98
        text_pos.x, text_pos.y, "");
hegyi@1512
    99
    nodetextmap[i]->property_fill_color().set_value("darkblue");
hegyi@1599
   100
    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
ladanyi@1442
   101
  }
ladanyi@1442
   102
ladanyi@1442
   103
  updateScrollRegion();
ladanyi@1442
   104
}
ladanyi@1442
   105
ladanyi@1606
   106
void GraphDisplayerCanvas::clear()
ladanyi@1442
   107
{
ladanyi@1606
   108
  active_node=INVALID;
ladanyi@1606
   109
  active_edge=INVALID;
ladanyi@1606
   110
  forming_edge=INVALID;
ladanyi@1442
   111
ladanyi@1606
   112
  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
ladanyi@1442
   113
  {
ladanyi@1606
   114
    delete nodesmap[n];
ladanyi@1606
   115
    delete nodetextmap[n];
ladanyi@1442
   116
  }
ladanyi@1442
   117
ladanyi@1606
   118
  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
ladanyi@1606
   119
  {
ladanyi@1606
   120
    delete edgesmap[e];
ladanyi@1606
   121
    delete edgetextmap[e];
ladanyi@1606
   122
  }
ladanyi@1442
   123
}