COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas.cc @ 34:2cb1fc37f742

gui
Last change on this file since 34:2cb1fc37f742 was 34:2cb1fc37f742, checked in by Hegyi Péter, 19 years ago

EdgeMapEditor? is on its way, but it is far not yet ready.

  • Property exe set to *
File size: 3.3 KB
Line 
1#include <graph_displayer_canvas.h>
2#include <broken_edge.h>
3#include <math.h>
4
5GraphDisplayerCanvas::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),mapwin(mw)
6{
7 
8  active_node=INVALID;
9  active_edge=INVALID;
10
11  //setting event handler for the editor widget
12  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
13
14  //base event handler is move tool
15  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
16  actual_tool=CREATE_NODE;
17
18  //set_center_scroll_region(true);
19
20  //first edges are drawn, to hide joining with nodes later
21
22  for (EdgeIt i(g); i!=INVALID; ++i)
23  {
24
25    //drawing green lines, coordinates are from cm
26
27    Gnome::Canvas::Points coos;
28    coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
29    coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
30   
31    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
32    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
33    edgesmap[i]->property_width_pixels().set_value(10);   
34   
35    //initializing edge-text as well, to empty string
36
37    xy<double> text_pos=edgesmap[i]->getArrowPos();
38    text_pos+=(xy<double>(10,10));
39
40    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
41    edgetextmap[i]->property_fill_color().set_value("darkgreen");
42  }
43
44  //afterwards nodes come to be drawn
45
46  NodeIt i(g);
47  int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
48
49  for (; i!=INVALID; ++i)
50  {
51    //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
52
53    if(cm[i].x>maxx)maxx=(int)cm[i].x;
54    if(cm[i].y>maxy)maxy=(int)cm[i].y;
55    if(cm[i].x<minx)minx=(int)cm[i].x;
56    if(cm[i].y<miny)miny=(int)cm[i].y;
57
58    //drawing bule nodes, with black line around them
59
60    nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
61    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
62    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
63
64    //initializing edge-text as well, to empty string
65
66    xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
67
68    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
69    nodetextmap[i]->property_fill_color().set_value("darkblue");
70  }
71
72  updateScrollRegion();
73}
74
75GraphDisplayerCanvas::~GraphDisplayerCanvas()
76{
77  if(canvasentrywidget)
78    {
79      delete(canvasentrywidget);
80    }
81
82  //writing out the end state of the graph
83  //\todo all the maps has to be write out!
84
85  Graph::NodeMap <int> id(g);
86  Graph::NodeMap <double> xc(g);
87  Graph::NodeMap <double> yc(g);
88 
89  int j=1;
90 
91  for (NodeIt i(g); i!=INVALID; ++i)
92  {
93    double x1,y1,x2,y2;
94    nodesmap[i]->get_bounds(x1, y1, x2, y2);
95   
96    id[i]=j++;
97    xc[i]=(x1+x2)/2;
98    yc[i]=(y1+y2)/2;
99  }
100
101  GraphWriter<Graph> writer(std::cout,g);
102 
103  writer.writeNodeMap("id", id);
104  writer.writeNodeMap("coordinates_x", xc);
105  writer.writeNodeMap("coordinates_y", yc);
106  writer.run();
107}
Note: See TracBrowser for help on using the repository browser.