Removed this extra widget thing, because it is now developed in my private branch.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include "graph_displayer_canvas.h"
22 GraphDisplayerCanvas::EdgeBase::EdgeBase(Gnome::Canvas::Group& _group, Edge _edge, GraphDisplayerCanvas& _canvas) :
23 Gnome::Canvas::Group(_group), edge(_edge), canvas(_canvas), arrow(*this)
25 arrow.property_fill_color().set_value("red");
26 arrow.lower_to_bottom();
30 GraphDisplayerCanvas::EdgeBase::~EdgeBase()
34 void GraphDisplayerCanvas::EdgeBase::drawArrow(XY unit_vector_in_dir)
36 MapStorage& ms = canvas.mytab.mapstorage;
37 XY center(ms.arrow_pos[edge]);
38 XY unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
42 // - - // c(enter)l(eft), ccl, ccr, cr
44 // || // b(ottom)l, br
48 XY bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
49 XY br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
50 XY ccl(center + unit_vector_in_dir * size + unit_norm_vector * size );
51 XY ccr(center + unit_vector_in_dir * size - unit_norm_vector * size );
52 XY cl (center + unit_vector_in_dir * size + unit_norm_vector * 2 * size );
53 XY cr (center + unit_vector_in_dir * size - unit_norm_vector * 2 * size );
54 XY top(center + unit_vector_in_dir * 3 * size);
56 Gnome::Canvas::Points arrow_points;
57 arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y ) );
58 arrow_points.push_back(Gnome::Art::Point( br.x , br.y ) );
59 arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
60 arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y ) );
61 arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
62 arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y ) );
63 arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
65 arrow.property_points().set_value(arrow_points);
68 GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g,
69 Edge _edge, GraphDisplayerCanvas & gc) : EdgeBase(g, _edge, gc),
70 isbutton(false), line(*this)
72 arrow.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler));
74 line.property_fill_color().set_value("green");
75 line.property_width_units().set_value(10);
76 line.lower_to_bottom();
81 GraphDisplayerCanvas::BrokenEdge::~BrokenEdge()
85 void GraphDisplayerCanvas::BrokenEdge::draw()
87 MapStorage& ms = canvas.mytab.mapstorage;
89 //calculating coordinates of the direction indicator arrow
90 XY head(ms.coords[ms.graph.target(edge)]);
91 XY center(ms.arrow_pos[edge]);
93 XY unit_vector_in_dir(head-center);
94 double length=sqrt( unit_vector_in_dir.normSquare() );
96 unit_vector_in_dir/=length;
99 drawArrow(unit_vector_in_dir);
102 Gnome::Canvas::Points points;
103 Node source = ms.graph.source(edge);
104 Node target = ms.graph.target(edge);
105 points.push_back(Gnome::Art::Point(ms.coords[source].x,
106 ms.coords[source].y));
107 points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x,
108 ms.arrow_pos[edge].y));
109 points.push_back(Gnome::Art::Point(ms.coords[target].x,
110 ms.coords[target].y));
111 line.property_points().set_value(points);
114 bool GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler(GdkEvent* e)
118 case GDK_BUTTON_PRESS:
119 //we mark the location of the event to be able to calculate parameters
121 if(canvas.getActualTool()!=CREATE_NODE)
123 canvas.toggleEdgeActivity(this, true);
124 clicked_x=e->button.x;
125 clicked_y=e->button.y;
129 case GDK_BUTTON_RELEASE:
130 if(canvas.getActualTool()!=CREATE_NODE)
132 canvas.toggleEdgeActivity(this, false);
136 case GDK_MOTION_NOTIFY:
137 //we only have to do sg. if the mouse button is pressed
140 //new coordinates will be the old values,
141 //because the item will be moved to the
142 //new coordinate therefore the new movement
143 //has to be calculated from here
145 double dx=e->motion.x-clicked_x;
146 double dy=e->motion.y-clicked_y;
148 Gnome::Canvas::Points points_new;
150 canvas.mytab.mapstorage.arrow_pos.set(edge, canvas.mytab.mapstorage.arrow_pos[edge] + XY(dx, dy));
153 canvas.textReposition(canvas.mytab.mapstorage.arrow_pos[edge]);
155 clicked_x=e->motion.x;
156 clicked_y=e->motion.y;
165 void GraphDisplayerCanvas::BrokenEdge::setLineWidth(int w)
167 line.property_width_units().set_value(w);
170 void GraphDisplayerCanvas::BrokenEdge::setFillColor(Gdk::Color c)
172 line.property_fill_color_gdk().set_value(c);
175 GraphDisplayerCanvas::LoopEdge::LoopEdge(Gnome::Canvas::Group& _group,
176 Edge _edge, GraphDisplayerCanvas& _canvas) :
177 EdgeBase(_group, _edge, _canvas), line(*this), isbutton(false)
179 arrow.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::LoopEdge::edgeFormerEventHandler));
181 line.property_outline_color().set_value("green");
182 line.property_width_units().set_value(10);
183 line.lower_to_bottom();
188 GraphDisplayerCanvas::LoopEdge::~LoopEdge()
192 void GraphDisplayerCanvas::LoopEdge::draw()
194 MapStorage& ms = canvas.mytab.mapstorage;
196 Node node = ms.graph.source(edge);
197 XY center = (ms.coords[node] + ms.arrow_pos[edge]) / 2.0;
199 XY unit_vector_in_dir(rot90(center - ms.arrow_pos[edge]));
200 double length = sqrt(unit_vector_in_dir.normSquare());
201 unit_vector_in_dir /= length;
203 drawArrow(unit_vector_in_dir);
206 sqrt((ms.arrow_pos[edge] - ms.coords[node]).normSquare()) / 2.0;
208 XY p1 = center + XY(-radius, radius);
209 XY p2 = center + XY( radius, -radius);
210 line.property_x1().set_value(p1.x);
211 line.property_y1().set_value(p1.y);
212 line.property_x2().set_value(p2.x);
213 line.property_y2().set_value(p2.y);
216 void GraphDisplayerCanvas::LoopEdge::setLineWidth(int w)
218 line.property_width_units().set_value(w);
221 void GraphDisplayerCanvas::LoopEdge::setFillColor(Gdk::Color c)
223 line.property_outline_color_gdk().set_value(c);
226 bool GraphDisplayerCanvas::LoopEdge::edgeFormerEventHandler(GdkEvent* e)
230 case GDK_BUTTON_PRESS:
231 if(canvas.getActualTool()!=CREATE_NODE)
233 canvas.toggleEdgeActivity(this, true);
237 case GDK_BUTTON_RELEASE:
238 if(canvas.getActualTool()!=CREATE_NODE)
240 canvas.toggleEdgeActivity(this, false);
244 case GDK_MOTION_NOTIFY:
247 canvas.mytab.mapstorage.arrow_pos.set(edge, XY(e->motion.x, e->motion.y));
250 canvas.textReposition(canvas.mytab.mapstorage.arrow_pos[edge]);