ladanyi@1442
|
1 |
#include <graph_displayer_canvas.h>
|
ladanyi@1442
|
2 |
#include <math.h>
|
ladanyi@1442
|
3 |
|
ladanyi@1442
|
4 |
GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
|
ladanyi@1442
|
5 |
{
|
hegyi@1468
|
6 |
Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
|
hegyi@1468
|
7 |
*origo << Gnome::Canvas::Properties::fill_color("black");
|
hegyi@1468
|
8 |
*origo << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@1468
|
9 |
|
hegyi@1468
|
10 |
actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
|
hegyi@1468
|
11 |
|
ladanyi@1442
|
12 |
//set_center_scroll_region(true);
|
ladanyi@1442
|
13 |
|
ladanyi@1442
|
14 |
//first edges are drawn, to hide joining with nodes later
|
ladanyi@1442
|
15 |
|
ladanyi@1442
|
16 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
ladanyi@1442
|
17 |
{
|
ladanyi@1442
|
18 |
|
ladanyi@1442
|
19 |
//drawing green lines, coordinates are from cm
|
ladanyi@1442
|
20 |
|
ladanyi@1442
|
21 |
Gnome::Canvas::Points coos;
|
ladanyi@1442
|
22 |
coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
|
ladanyi@1442
|
23 |
coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
|
ladanyi@1442
|
24 |
|
ladanyi@1442
|
25 |
edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
|
ladanyi@1442
|
26 |
*(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
|
ladanyi@1442
|
27 |
edgesmap[i]->property_width_pixels().set_value(10);
|
ladanyi@1442
|
28 |
|
ladanyi@1442
|
29 |
//initializing edge-text as well, to empty string
|
ladanyi@1442
|
30 |
|
ladanyi@1442
|
31 |
double x1, x2, y1, y2;
|
ladanyi@1442
|
32 |
edgesmap[i]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
33 |
|
ladanyi@1442
|
34 |
edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
|
ladanyi@1442
|
35 |
edgetextmap[i]->property_fill_color().set_value("black");
|
ladanyi@1442
|
36 |
}
|
ladanyi@1442
|
37 |
|
ladanyi@1442
|
38 |
//afterwards nodes come to be drawn
|
ladanyi@1442
|
39 |
|
ladanyi@1442
|
40 |
NodeIt i(g);
|
ladanyi@1442
|
41 |
int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
|
ladanyi@1442
|
42 |
|
ladanyi@1442
|
43 |
for (; i!=INVALID; ++i)
|
ladanyi@1442
|
44 |
{
|
ladanyi@1442
|
45 |
//minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
|
ladanyi@1442
|
46 |
|
ladanyi@1442
|
47 |
if(cm[i].x>maxx)maxx=(int)cm[i].x;
|
ladanyi@1442
|
48 |
if(cm[i].y>maxy)maxy=(int)cm[i].y;
|
ladanyi@1442
|
49 |
if(cm[i].x<minx)minx=(int)cm[i].x;
|
ladanyi@1442
|
50 |
if(cm[i].y<miny)miny=(int)cm[i].y;
|
ladanyi@1442
|
51 |
|
ladanyi@1442
|
52 |
//drawing bule nodes, with black line around them
|
ladanyi@1442
|
53 |
|
ladanyi@1442
|
54 |
nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
|
ladanyi@1442
|
55 |
*(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1442
|
56 |
*(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@1468
|
57 |
//!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
|
ladanyi@1442
|
58 |
}
|
ladanyi@1442
|
59 |
|
ladanyi@1442
|
60 |
updateScrollRegion();
|
ladanyi@1442
|
61 |
}
|
ladanyi@1442
|
62 |
|
ladanyi@1442
|
63 |
GraphDisplayerCanvas::~GraphDisplayerCanvas()
|
ladanyi@1442
|
64 |
{
|
ladanyi@1442
|
65 |
|
ladanyi@1442
|
66 |
//writing out the end state of the graph
|
ladanyi@1442
|
67 |
//\todo all the maps has to be write out!
|
ladanyi@1442
|
68 |
|
ladanyi@1442
|
69 |
Graph::NodeMap <int> id(g);
|
ladanyi@1442
|
70 |
Graph::NodeMap <double> xc(g);
|
ladanyi@1442
|
71 |
Graph::NodeMap <double> yc(g);
|
ladanyi@1442
|
72 |
|
ladanyi@1442
|
73 |
int j=1;
|
ladanyi@1442
|
74 |
|
ladanyi@1442
|
75 |
for (NodeIt i(g); i!=INVALID; ++i)
|
ladanyi@1442
|
76 |
{
|
ladanyi@1442
|
77 |
double x1,y1,x2,y2;
|
ladanyi@1442
|
78 |
nodesmap[i]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
79 |
|
ladanyi@1442
|
80 |
id[i]=j++;
|
ladanyi@1442
|
81 |
xc[i]=(x1+x2)/2;
|
ladanyi@1442
|
82 |
yc[i]=(y1+y2)/2;
|
ladanyi@1442
|
83 |
}
|
ladanyi@1442
|
84 |
|
ladanyi@1442
|
85 |
GraphWriter<Graph> writer(std::cout,g);
|
ladanyi@1442
|
86 |
|
ladanyi@1442
|
87 |
writer.writeNodeMap("id", id);
|
ladanyi@1442
|
88 |
writer.writeNodeMap("coordinates_x", xc);
|
ladanyi@1442
|
89 |
writer.writeNodeMap("coordinates_y", yc);
|
ladanyi@1442
|
90 |
writer.run();
|
ladanyi@1442
|
91 |
}
|
ladanyi@1442
|
92 |
|
ladanyi@1442
|
93 |
int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
|
ladanyi@1442
|
94 |
{
|
ladanyi@1442
|
95 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
ladanyi@1442
|
96 |
{
|
ladanyi@1442
|
97 |
int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
|
ladanyi@1442
|
98 |
edgesmap[i]->property_width_pixels().set_value(w);
|
ladanyi@1442
|
99 |
}
|
ladanyi@1442
|
100 |
return 0;
|
ladanyi@1442
|
101 |
};
|
ladanyi@1442
|
102 |
|
ladanyi@1442
|
103 |
int GraphDisplayerCanvas::changeColor (std::string mapname)
|
ladanyi@1442
|
104 |
{
|
ladanyi@1442
|
105 |
|
ladanyi@1442
|
106 |
//function maps the range of the maximum and
|
ladanyi@1442
|
107 |
//the minimum of the nodemap to the range of
|
ladanyi@1442
|
108 |
//green in RGB
|
ladanyi@1442
|
109 |
|
ladanyi@1442
|
110 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
ladanyi@1442
|
111 |
{
|
ladanyi@1442
|
112 |
double w=(*(mapstorage.edgemap_storage)[mapname])[i];
|
ladanyi@1442
|
113 |
double max=mapstorage.maxOfEdgeMap(mapname);
|
ladanyi@1442
|
114 |
double min=mapstorage.minOfEdgeMap(mapname);
|
ladanyi@1442
|
115 |
|
ladanyi@1442
|
116 |
//std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
|
ladanyi@1442
|
117 |
Gdk::Color color;
|
ladanyi@1442
|
118 |
if(max!=min)
|
ladanyi@1442
|
119 |
{
|
ladanyi@1442
|
120 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
ladanyi@1442
|
121 |
}
|
ladanyi@1442
|
122 |
else
|
ladanyi@1442
|
123 |
{
|
ladanyi@1442
|
124 |
color.set_rgb_p (0, 100, 0);
|
ladanyi@1442
|
125 |
}
|
ladanyi@1442
|
126 |
|
ladanyi@1442
|
127 |
edgesmap[i]->property_fill_color_gdk().set_value(color);
|
ladanyi@1442
|
128 |
}
|
ladanyi@1442
|
129 |
return 0;
|
ladanyi@1442
|
130 |
};
|
ladanyi@1442
|
131 |
|
ladanyi@1442
|
132 |
int GraphDisplayerCanvas::changeText (std::string mapname)
|
ladanyi@1442
|
133 |
{
|
ladanyi@1442
|
134 |
|
ladanyi@1442
|
135 |
//the number in the map will be written on the edge
|
ladanyi@1442
|
136 |
//EXCEPT when the name of the map is Text, because
|
ladanyi@1442
|
137 |
//in that case empty string will be written, because
|
ladanyi@1442
|
138 |
//that is the deleter map
|
ladanyi@1442
|
139 |
//\todo isn't it a bit woodcutter?
|
ladanyi@1442
|
140 |
|
ladanyi@1442
|
141 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
ladanyi@1442
|
142 |
{
|
ladanyi@1442
|
143 |
if(mapname!="Text")
|
ladanyi@1442
|
144 |
{
|
ladanyi@1442
|
145 |
double number=(*(mapstorage.edgemap_storage)[mapname])[i];
|
ladanyi@1442
|
146 |
int length=(int)(floor(log(number)/log(10)))+1;
|
ladanyi@1442
|
147 |
int maxpos=(int)(pow(10,length-1));
|
ladanyi@1442
|
148 |
int strl=length+1+RANGE;
|
ladanyi@1442
|
149 |
char * str=new char[strl];
|
ladanyi@1442
|
150 |
str[length]='.';
|
ladanyi@1442
|
151 |
str[strl]='\0';
|
ladanyi@1442
|
152 |
|
ladanyi@1442
|
153 |
for(int j=0;j<strl;j++)
|
ladanyi@1442
|
154 |
{
|
ladanyi@1442
|
155 |
if(j!=length)
|
ladanyi@1442
|
156 |
{
|
ladanyi@1442
|
157 |
int digit=(int)(number/maxpos);
|
ladanyi@1442
|
158 |
str[j]=(digit+'0');
|
ladanyi@1442
|
159 |
number-=digit*maxpos;
|
ladanyi@1442
|
160 |
number*=10;
|
ladanyi@1442
|
161 |
}
|
ladanyi@1442
|
162 |
}
|
ladanyi@1442
|
163 |
|
ladanyi@1442
|
164 |
edgetextmap[i]->property_text().set_value(str);
|
ladanyi@1442
|
165 |
}
|
ladanyi@1442
|
166 |
else
|
ladanyi@1442
|
167 |
{
|
ladanyi@1442
|
168 |
edgetextmap[i]->property_text().set_value("");
|
ladanyi@1442
|
169 |
}
|
ladanyi@1442
|
170 |
}
|
ladanyi@1442
|
171 |
return 0;
|
ladanyi@1442
|
172 |
};
|
ladanyi@1442
|
173 |
|
ladanyi@1442
|
174 |
bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
|
ladanyi@1442
|
175 |
{
|
ladanyi@1442
|
176 |
switch(e->type)
|
ladanyi@1442
|
177 |
{
|
ladanyi@1442
|
178 |
case GDK_BUTTON_PRESS:
|
ladanyi@1442
|
179 |
//we mark the location of the event to be able to calculate parameters of dragging
|
ladanyi@1442
|
180 |
clicked_x=e->button.x;
|
ladanyi@1442
|
181 |
clicked_y=e->button.y;
|
ladanyi@1442
|
182 |
active_item=(get_item_at(e->button.x, e->button.y));
|
ladanyi@1442
|
183 |
isbutton=true;
|
ladanyi@1442
|
184 |
break;
|
ladanyi@1442
|
185 |
case GDK_BUTTON_RELEASE:
|
ladanyi@1442
|
186 |
isbutton=false;
|
ladanyi@1442
|
187 |
active_item=NULL;
|
ladanyi@1444
|
188 |
updateScrollRegion();
|
ladanyi@1442
|
189 |
break;
|
ladanyi@1442
|
190 |
case GDK_MOTION_NOTIFY:
|
ladanyi@1442
|
191 |
//we only have to do sg. if the mouse button is pressed
|
ladanyi@1442
|
192 |
if(isbutton)
|
ladanyi@1442
|
193 |
{
|
ladanyi@1442
|
194 |
//new coordinates will be the old values,
|
ladanyi@1442
|
195 |
//because the item will be moved to the
|
ladanyi@1442
|
196 |
//new coordinate therefore the new movement
|
ladanyi@1442
|
197 |
//has to be calculated from here
|
ladanyi@1442
|
198 |
|
ladanyi@1442
|
199 |
double dx=e->motion.x-clicked_x;
|
ladanyi@1442
|
200 |
double dy=e->motion.y-clicked_y;
|
ladanyi@1442
|
201 |
active_item->move(dx, dy);
|
ladanyi@1442
|
202 |
clicked_x=e->motion.x;
|
ladanyi@1442
|
203 |
clicked_y=e->motion.y;
|
ladanyi@1442
|
204 |
|
ladanyi@1442
|
205 |
//all the edges connected to the moved point has to be redrawn
|
ladanyi@1442
|
206 |
|
ladanyi@1442
|
207 |
EdgeIt e;
|
ladanyi@1442
|
208 |
g.firstOut(e,n);
|
ladanyi@1442
|
209 |
for(;e!=INVALID;g.nextOut(e))
|
ladanyi@1442
|
210 |
{
|
ladanyi@1442
|
211 |
Gnome::Canvas::Points coos;
|
ladanyi@1442
|
212 |
double x1, x2, y1, y2;
|
ladanyi@1442
|
213 |
|
ladanyi@1442
|
214 |
nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
215 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
ladanyi@1442
|
216 |
|
ladanyi@1442
|
217 |
nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
218 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
ladanyi@1442
|
219 |
|
ladanyi@1442
|
220 |
edgesmap[e]->property_points().set_value(coos);
|
ladanyi@1442
|
221 |
|
ladanyi@1442
|
222 |
edgesmap[e]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
223 |
|
ladanyi@1442
|
224 |
edgetextmap[e]->property_x().set_value((x1+x2)/2);
|
ladanyi@1442
|
225 |
edgetextmap[e]->property_y().set_value((y1+y2)/2);
|
ladanyi@1442
|
226 |
}
|
ladanyi@1442
|
227 |
|
ladanyi@1442
|
228 |
g.firstIn(e,n);
|
ladanyi@1442
|
229 |
for(;e!=INVALID;g.nextIn(e))
|
ladanyi@1442
|
230 |
{
|
ladanyi@1442
|
231 |
Gnome::Canvas::Points coos;
|
ladanyi@1442
|
232 |
double x1, x2, y1, y2;
|
ladanyi@1442
|
233 |
|
ladanyi@1442
|
234 |
nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
235 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
ladanyi@1442
|
236 |
|
ladanyi@1442
|
237 |
nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
238 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
ladanyi@1442
|
239 |
|
ladanyi@1442
|
240 |
edgesmap[e]->property_points().set_value(coos);
|
ladanyi@1442
|
241 |
|
ladanyi@1442
|
242 |
edgesmap[e]->get_bounds(x1, y1, x2, y2);
|
ladanyi@1442
|
243 |
|
ladanyi@1442
|
244 |
edgetextmap[e]->property_x().set_value((x1+x2)/2);
|
ladanyi@1442
|
245 |
edgetextmap[e]->property_y().set_value((y1+y2)/2);
|
ladanyi@1442
|
246 |
}
|
ladanyi@1442
|
247 |
}
|
ladanyi@1442
|
248 |
default: break;
|
ladanyi@1442
|
249 |
}
|
ladanyi@1442
|
250 |
return true;
|
ladanyi@1442
|
251 |
}
|
ladanyi@1442
|
252 |
|
ladanyi@1442
|
253 |
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
|
ladanyi@1442
|
254 |
{
|
ladanyi@1442
|
255 |
Gnome::Canvas::CanvasAA::on_expose_event(event);
|
ladanyi@1442
|
256 |
//usleep(10000);
|
ladanyi@1442
|
257 |
//rezoom();
|
ladanyi@1442
|
258 |
return true;
|
ladanyi@1442
|
259 |
}
|
ladanyi@1442
|
260 |
|
ladanyi@1442
|
261 |
void GraphDisplayerCanvas::zoomIn()
|
ladanyi@1442
|
262 |
{
|
ladanyi@1442
|
263 |
set_pixels_per_unit(
|
ladanyi@1442
|
264 |
(1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
|
ladanyi@1442
|
265 |
}
|
ladanyi@1442
|
266 |
|
ladanyi@1442
|
267 |
void GraphDisplayerCanvas::zoomOut()
|
ladanyi@1442
|
268 |
{
|
ladanyi@1442
|
269 |
set_pixels_per_unit(
|
ladanyi@1442
|
270 |
(1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
|
ladanyi@1442
|
271 |
}
|
ladanyi@1442
|
272 |
|
ladanyi@1442
|
273 |
void GraphDisplayerCanvas::zoomFit()
|
ladanyi@1442
|
274 |
{
|
ladanyi@1442
|
275 |
// get the height and width of the canvas
|
ladanyi@1442
|
276 |
Gtk::Allocation a = get_allocation();
|
ladanyi@1442
|
277 |
int aw = a.get_width();
|
ladanyi@1442
|
278 |
int ah = a.get_height();
|
ladanyi@1442
|
279 |
// add some space
|
ladanyi@1442
|
280 |
aw -= 5; if (aw < 0) aw = 0;
|
ladanyi@1442
|
281 |
ah -= 5; if (ah < 0) ah = 0;
|
ladanyi@1442
|
282 |
|
ladanyi@1442
|
283 |
// get the bounding box of the graph
|
ladanyi@1442
|
284 |
double wx1, wy1, wx2, wy2;
|
ladanyi@1442
|
285 |
Gnome::Canvas::Item* pCanvasItem = root();
|
ladanyi@1442
|
286 |
pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
|
ladanyi@1442
|
287 |
|
ladanyi@1442
|
288 |
// fit the graph to the window
|
ladanyi@1444
|
289 |
double ppu1 = (double) aw / fabs(wx2 - wx1);
|
ladanyi@1444
|
290 |
double ppu2 = (double) ah / fabs(wy2 - wy1);
|
ladanyi@1444
|
291 |
set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
|
ladanyi@1442
|
292 |
}
|
ladanyi@1442
|
293 |
|
ladanyi@1442
|
294 |
void GraphDisplayerCanvas::zoom100()
|
ladanyi@1442
|
295 |
{
|
ladanyi@1442
|
296 |
set_pixels_per_unit(1.0);
|
ladanyi@1442
|
297 |
}
|
ladanyi@1442
|
298 |
|
ladanyi@1442
|
299 |
void GraphDisplayerCanvas::updateScrollRegion()
|
ladanyi@1442
|
300 |
{
|
ladanyi@1442
|
301 |
double wx1, wy1, wx2, wy2;
|
ladanyi@1442
|
302 |
Gnome::Canvas::Item* pCanvasItem = root();
|
ladanyi@1442
|
303 |
pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
|
ladanyi@1444
|
304 |
set_scroll_region(wx1, wy1, wx2, wy2);
|
ladanyi@1442
|
305 |
}
|
hegyi@1468
|
306 |
|
hegyi@1468
|
307 |
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
|
hegyi@1468
|
308 |
{
|
hegyi@1468
|
309 |
actual_handler.disconnect();
|
hegyi@1468
|
310 |
|
hegyi@1468
|
311 |
switch(newtool)
|
hegyi@1468
|
312 |
{
|
hegyi@1468
|
313 |
case MOVE:
|
hegyi@1468
|
314 |
actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
|
hegyi@1468
|
315 |
break;
|
hegyi@1468
|
316 |
case CREATE_NODE:
|
hegyi@1468
|
317 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
|
hegyi@1468
|
318 |
break;
|
hegyi@1468
|
319 |
case CREATE_EDGE:
|
hegyi@1468
|
320 |
actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
|
hegyi@1468
|
321 |
break;
|
hegyi@1468
|
322 |
default:
|
hegyi@1468
|
323 |
break;
|
hegyi@1468
|
324 |
}
|
hegyi@1468
|
325 |
}
|
hegyi@1468
|
326 |
|
hegyi@1468
|
327 |
bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
|
hegyi@1468
|
328 |
{
|
hegyi@1468
|
329 |
switch(e->type)
|
hegyi@1468
|
330 |
{
|
hegyi@1468
|
331 |
case GDK_BUTTON_PRESS:
|
hegyi@1468
|
332 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1468
|
333 |
clicked_x=e->button.x;
|
hegyi@1468
|
334 |
clicked_y=e->button.y;
|
hegyi@1468
|
335 |
active_item=(get_item_at(e->button.x, e->button.y));
|
hegyi@1468
|
336 |
active_node=INVALID;
|
hegyi@1468
|
337 |
for (NodeIt i(g); i!=INVALID; ++i)
|
hegyi@1468
|
338 |
{
|
hegyi@1468
|
339 |
if(nodesmap[i]==active_item)
|
hegyi@1468
|
340 |
{
|
hegyi@1468
|
341 |
active_node=i;
|
hegyi@1468
|
342 |
}
|
hegyi@1468
|
343 |
}
|
hegyi@1468
|
344 |
isbutton=true;
|
hegyi@1468
|
345 |
break;
|
hegyi@1468
|
346 |
case GDK_BUTTON_RELEASE:
|
hegyi@1468
|
347 |
isbutton=false;
|
hegyi@1468
|
348 |
active_item=NULL;
|
hegyi@1468
|
349 |
updateScrollRegion();
|
hegyi@1468
|
350 |
break;
|
hegyi@1468
|
351 |
case GDK_MOTION_NOTIFY:
|
hegyi@1468
|
352 |
//we only have to do sg. if the mouse button is pressed
|
hegyi@1468
|
353 |
if(isbutton)
|
hegyi@1468
|
354 |
{
|
hegyi@1468
|
355 |
//new coordinates will be the old values,
|
hegyi@1468
|
356 |
//because the item will be moved to the
|
hegyi@1468
|
357 |
//new coordinate therefore the new movement
|
hegyi@1468
|
358 |
//has to be calculated from here
|
hegyi@1468
|
359 |
|
hegyi@1468
|
360 |
double dx=e->motion.x-clicked_x;
|
hegyi@1468
|
361 |
double dy=e->motion.y-clicked_y;
|
hegyi@1468
|
362 |
|
hegyi@1468
|
363 |
active_item->move(dx, dy);
|
hegyi@1468
|
364 |
|
hegyi@1468
|
365 |
clicked_x=e->motion.x;
|
hegyi@1468
|
366 |
clicked_y=e->motion.y;
|
hegyi@1468
|
367 |
|
hegyi@1468
|
368 |
//all the edges connected to the moved point has to be redrawn
|
hegyi@1468
|
369 |
|
hegyi@1468
|
370 |
EdgeIt e;
|
hegyi@1468
|
371 |
|
hegyi@1468
|
372 |
g.firstOut(e,active_node);
|
hegyi@1468
|
373 |
|
hegyi@1468
|
374 |
for(;e!=INVALID;g.nextOut(e))
|
hegyi@1468
|
375 |
{
|
hegyi@1468
|
376 |
Gnome::Canvas::Points coos;
|
hegyi@1468
|
377 |
double x1, x2, y1, y2;
|
hegyi@1468
|
378 |
|
hegyi@1468
|
379 |
nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1468
|
380 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1468
|
381 |
|
hegyi@1468
|
382 |
nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1468
|
383 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1468
|
384 |
|
hegyi@1468
|
385 |
edgesmap[e]->property_points().set_value(coos);
|
hegyi@1468
|
386 |
|
hegyi@1468
|
387 |
edgesmap[e]->get_bounds(x1, y1, x2, y2);
|
hegyi@1468
|
388 |
|
hegyi@1468
|
389 |
edgetextmap[e]->property_x().set_value((x1+x2)/2);
|
hegyi@1468
|
390 |
edgetextmap[e]->property_y().set_value((y1+y2)/2);
|
hegyi@1468
|
391 |
}
|
hegyi@1468
|
392 |
|
hegyi@1468
|
393 |
g.firstIn(e,active_node);
|
hegyi@1468
|
394 |
for(;e!=INVALID;g.nextIn(e))
|
hegyi@1468
|
395 |
{
|
hegyi@1468
|
396 |
Gnome::Canvas::Points coos;
|
hegyi@1468
|
397 |
double x1, x2, y1, y2;
|
hegyi@1468
|
398 |
|
hegyi@1468
|
399 |
nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1468
|
400 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1468
|
401 |
|
hegyi@1468
|
402 |
nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1468
|
403 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1468
|
404 |
|
hegyi@1468
|
405 |
edgesmap[e]->property_points().set_value(coos);
|
hegyi@1468
|
406 |
|
hegyi@1468
|
407 |
edgesmap[e]->get_bounds(x1, y1, x2, y2);
|
hegyi@1468
|
408 |
|
hegyi@1468
|
409 |
edgetextmap[e]->property_x().set_value((x1+x2)/2);
|
hegyi@1468
|
410 |
edgetextmap[e]->property_y().set_value((y1+y2)/2);
|
hegyi@1468
|
411 |
}
|
hegyi@1468
|
412 |
}
|
hegyi@1468
|
413 |
default: break;
|
hegyi@1468
|
414 |
}
|
hegyi@1468
|
415 |
|
hegyi@1468
|
416 |
return true;
|
hegyi@1468
|
417 |
}
|
hegyi@1468
|
418 |
|
hegyi@1468
|
419 |
bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
|
hegyi@1468
|
420 |
{
|
hegyi@1468
|
421 |
switch(e->type)
|
hegyi@1468
|
422 |
{
|
hegyi@1468
|
423 |
case GDK_BUTTON_PRESS:
|
hegyi@1468
|
424 |
isbutton=true;
|
hegyi@1468
|
425 |
|
hegyi@1468
|
426 |
active_node=NodeIt(g,g.addNode());
|
hegyi@1468
|
427 |
|
hegyi@1468
|
428 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1468
|
429 |
|
hegyi@1468
|
430 |
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
|
hegyi@1468
|
431 |
active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
|
hegyi@1468
|
432 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1468
|
433 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
|
hegyi@1468
|
434 |
(nodesmap[active_node])->show();
|
hegyi@1468
|
435 |
break;
|
hegyi@1468
|
436 |
case GDK_MOTION_NOTIFY:
|
hegyi@1468
|
437 |
{
|
hegyi@1468
|
438 |
double world_motion_x, world_motion_y;
|
hegyi@1468
|
439 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1468
|
440 |
window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
|
hegyi@1468
|
441 |
generated->motion.x=world_motion_x;
|
hegyi@1468
|
442 |
generated->motion.y=world_motion_y;
|
hegyi@1468
|
443 |
generated->type=GDK_MOTION_NOTIFY;
|
hegyi@1468
|
444 |
move_event_handler(generated);
|
hegyi@1468
|
445 |
break;
|
hegyi@1468
|
446 |
}
|
hegyi@1468
|
447 |
case GDK_BUTTON_RELEASE:
|
hegyi@1468
|
448 |
isbutton=false;
|
hegyi@1468
|
449 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1468
|
450 |
active_item=NULL;
|
hegyi@1468
|
451 |
updateScrollRegion();
|
hegyi@1468
|
452 |
break;
|
hegyi@1468
|
453 |
default:
|
hegyi@1468
|
454 |
break;
|
hegyi@1468
|
455 |
}
|
hegyi@1468
|
456 |
return false;
|
hegyi@1468
|
457 |
}
|
hegyi@1468
|
458 |
|
hegyi@1468
|
459 |
bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
|
hegyi@1468
|
460 |
{
|
hegyi@1468
|
461 |
e=e;
|
hegyi@1468
|
462 |
return false;
|
hegyi@1468
|
463 |
}
|
hegyi@1468
|
464 |
|