Suurballe algorithm is implemented in glemon.
3 #ifndef GRAPH_DISPLAYER_CANVAS_H
4 #define GRAPH_DISPLAYER_CANVAS_H
6 class GraphDisplayerCanvas;
8 #include "all_include.h"
10 #include <libgnomecanvasmm.h>
11 #include <libgnomecanvasmm/polygon.h>
12 #include <lemon/dim2.h>
14 ///This class is the canvas, on which the graph can be drawn.
15 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
17 friend class BrokenEdge;
18 friend class LoopEdge;
20 class EdgeBase : public Gnome::Canvas::Group
23 ///Reference to the canvas, on which the graph is drawn.
25 ///It is needed, because some datas needed from
26 ///graph can be accessed by this or should be sent
27 ///as parameter, but it would be complicated
28 GraphDisplayerCanvas& canvas;
30 ///The edge that the class displays.
32 ///It is needed, because some datas needed from
33 ///graph can be accessed by this or should be sent
34 ///as parameter, but it would be complicated
37 Gnome::Canvas::Polygon arrow;
41 EdgeBase(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
43 virtual void draw() = 0;
44 virtual void setLineWidth(int) = 0;
45 virtual void setFillColor(Gdk::Color) = 0;
46 virtual Gnome::Canvas::Item * getLine() = 0;
49 ///Edge displayer class
51 ///This class is responsible for displaying edges in graph.
52 ///The displayed edge is broken in the middle. The
53 ///aim of this is to be able to indicate direction of edges
54 ///and to be able to display more then one edges between the
55 ///same source and target
56 class BrokenEdge : public EdgeBase
59 Gnome::Canvas::Line line;
61 ///Indicates whether the button of mouse is pressed or not at the moment.
64 ///At this location was the mousebutton pressed. Horizontal component.
66 ///It helps to calculate the
67 ///distance of dragging.
70 ///At this location was the mousebutton pressed. Vertical component.
72 ///It helps to calculate the
73 ///distance of dragging.
76 ///event handler for forming broken edges
80 bool edgeFormerEventHandler(GdkEvent* event);
83 ///Constructor of broken edge class.
85 ///\param g the group to which the edge belongs
86 ///\param _edge the represented edge
87 ///\param gc the canvas
88 BrokenEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
90 ///Destructor of broken edge class
96 ///The function that draws the edge based on collected data
99 void setLineWidth(int);
100 void setFillColor(Gdk::Color);
102 Gnome::Canvas::Item * getLine() { return (Gnome::Canvas::Item *)(&line); };
105 class LoopEdge : public EdgeBase
108 Gnome::Canvas::Ellipse line;
109 bool edgeFormerEventHandler(GdkEvent* e);
112 LoopEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
115 void setLineWidth(int);
116 void setFillColor(Gdk::Color);
117 Gnome::Canvas::Item * getLine() { return (Gnome::Canvas::Item *)(&line); };
120 ///Type of canvas, on which the graph is drawn
121 typedef Gnome::Canvas::CanvasAA Parent;
126 ///\param nbt the tab of the window, in which the graph is displayed
127 GraphDisplayerCanvas(NoteBookTab & nbt);
129 ///destructor of the class
130 virtual ~GraphDisplayerCanvas();
132 ///Changes the width of edge(s) according to the given map.
134 ///\param mapname is the name of the map which contains the values to be set
135 ///\param edge if it is given, only the width of the given edge will be set, instead of all of them.
136 int changeEdgeWidth (std::string mapname, Edge edge=INVALID);
138 ///Resets width of edge(s) to the default value
140 ///\param edge if it is given, only the width of the
141 ///given edge will be reset, instead of all of them.
142 int resetEdgeWidth (Edge edge=INVALID);
144 ///Changes the color of edge(s) according to the given map.
146 ///\param mapname is the name of the map which contains the new values
147 ///\param edge if it is given, only the color of the given edge will be set, instead of all of them.
148 int changeEdgeColor (std::string mapname, Edge edge=INVALID);
150 ///Resets color of edge(s) to the default value
152 ///\param edge if it is given, only the color of the
153 ///given edge will be reset, instead of all of them.
154 int resetEdgeColor (Edge edge=INVALID);
156 ///Changes the label of edge(s) according to the given map.
158 ///\param mapname is the name of the map which contains the new values
159 ///\param edge if it is given, only the label of the given edge will be set, instead of all of them.
160 int changeEdgeText (std::string mapname, Edge edge=INVALID);
162 ///Resets label of edge(s) to the default value
164 ///\param edge if it is given, only the color of the
165 ///given edge will be reset, instead of all of them.
166 int resetEdgeText (Edge edge=INVALID);
168 ///Changes the radius of node(s) according to the given map.
170 ///\param mapname is the name of the map which contains the new values
171 ///\param node if it is given, only the radius of the given node will be set, instead of all of them.
172 int changeNodeRadius (std::string mapname, Node node=INVALID);
174 ///Resets radius of node(s) to the default value
176 ///\param node if it is given, only the radius of the
177 ///given node will be reset, instead of all of them.
178 int resetNodeRadius (Node node=INVALID);
180 ///Changes the color of node(s) according to the given map.
182 ///\param mapname is the name of the map which contains the new values
183 ///\param node if it is given, only the color of the given node will be set, instead of all of them.
184 int changeNodeColor (std::string mapname, Node node=INVALID);
186 ///Resets color of node(s) to the default value
188 ///\param node if it is given, only the color of the
189 ///given node will be reset, instead of all of them.
190 int resetNodeColor (Node node=INVALID);
192 ///Changes the label of node(s) according to the given map.
194 ///\param mapname is the name of the map which contains the new values
195 ///\param node if it is given, only the label of the given node will be set, instead of all of them.
196 int changeNodeText (std::string mapname, Node node=INVALID);
198 ///Resets label of node(s) to the default value
200 ///\param node if it is given, only the label of the
201 ///given node will be reset, instead of all of them.
202 int resetNodeText (Node node=INVALID);
204 ///This function is called, when any of the displayed attributes have to be updated, or changed
206 ///\param itisedge if true, edge property has to be changed, else node property
207 ///\param prop the id of property that has to changed or updated
208 void propertyChange(bool itisedge, int prop);
210 ///updates the given property
212 ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them
213 ///\param prop the property to update
214 void propertyUpdate(Edge edge, int prop);
216 ///updates the given property
218 ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them
219 ///\param prop the property to update
220 void propertyUpdate(Node node, int prop);
222 ///updates all the property for the given edge
223 void propertyUpdate(Edge);
225 ///updates all the property for the given node
226 void propertyUpdate(Node);
228 ///Callback for 'ViewZoomIn' action.
229 virtual void zoomIn();
230 ///Callback for 'ViewZoomOut' action.
231 virtual void zoomOut();
232 ///Callback for 'ViewZoomFit' action.
233 virtual void zoomFit();
234 ///Callback for 'ViewZoom100' action.
235 virtual void zoom100();
236 ///Sets the scroll region of the convas to the bounding box of the graph.
237 void updateScrollRegion();
239 ///This function changes the tool in the graph-editor's hand
240 void changeEditorialTool(int);
244 //maximizing, minimizing, restoring window, etc.
245 virtual bool on_expose_event(GdkEventExpose *);
249 ///This function is responsible for the correct
250 ///reaction of any action happened in the territory
253 bool eventHandler(GdkEvent* e, Node n);
255 ///actual event handler
257 ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
258 sigc::connection actual_handler;
260 ///event handler for the case when move-tool is active
261 bool moveEventHandler(GdkEvent*);
262 ///event handler for the case when create_node-tool is active
263 bool createNodeEventHandler(GdkEvent*);
264 ///event handler for the case when create_edge-tool is active
265 bool createEdgeEventHandler(GdkEvent*);
266 ///event handler for the case when eraser-tool is active
267 bool eraserEventHandler(GdkEvent*);
268 ///event handler for the case when map editor tool is active
269 bool mapEditEventHandler(GdkEvent*);
272 ///moves node according to the given parameters
273 void moveNode(double, double, Gnome::Canvas::Item * item=NULL, Node node=INVALID);
276 ///Moves the text to new place
277 void textReposition(XY);
279 ///Activates an edge belonging to an EdgeBase
281 ///After we have activated an edge this way,
282 ///the GDC object will know, which edge is under forming
283 ///therefore it can redraw the necessary elements on the canvas,
284 ///for example the text belonging to the \ref EdgeBase can be
285 ///redrawn (\ref textReposition).
286 void toggleEdgeActivity(EdgeBase*, bool);
290 ///Returns the actual tool in hand
293 ///Sets node representation settings
294 void setView(bool, bool, double, double);
296 ///Gets node representation settings
297 void getView(bool &, bool &, double&, double&);
301 ///Called when opening a file.
306 ///It achieves this by deleting all data
307 ///structure used to help handle the displayed graph.
310 ///creates a new Nodemap
312 ///\param init initial value of the map
313 ///\param mapname name of new map
314 int addNewNodeMap(double init,std::string mapname);
315 ///creates a new Edgemap
317 ///\param init initial value of the map
318 ///\param mapname name of new map
319 int addNewEdgeMap(double init,std::string mapname);
321 void reDesignGraph();
323 void get_design_data(double &, double &, int &);
324 void set_attraction(double);
325 void set_propulsation(double);
326 void set_iteration(int);
329 ///Deletes the given element.
330 void deleteItem(Node);
331 ///Deletes the given element.
332 void deleteItem(Edge);
336 ///Map of nodes of graph
337 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
339 ///Map of edges of graph
340 Graph::EdgeMap<EdgeBase*> edgesmap;
342 ///Map of texts to write on edges
343 Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
345 ///Map of texts to write on nodes
346 Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
348 ///Group of graphical elements of displayed_graph
349 Gnome::Canvas::Group displayed_graph;
352 ///Indicates whether the button of mouse is pressed or not
355 ///Stores the actual tool in hand
358 ///At this location was the mousebutton pressed.
359 ///It helps to calculate the distance of dragging.
360 double clicked_x, clicked_y;
362 ///Remembers which Gnome::Canvas::Item was pressed.
364 ///this variable is needed, to work on it after selection
365 Gnome::Canvas::Item * active_item;
367 ///Remembers which Gnome::Canvas::Item was pressed.
369 ///this variable is used at edge creation, it will
370 ///be the secondly selected node. No local variable
371 ///can be used for this purpose inside the function,
372 ///because the node selected by button press, and
373 ///the edge is created by button release. Both of
374 ///them is different function call.
375 Gnome::Canvas::Item * target_item;
377 ///selected node (for any editing)
380 ///selected edge (for any editing)
383 ///the edge that is selected by clicking on the red arrow in the middle of it
385 ///This edge is stored only for the purpose of reshape it.
386 ///That is why it is selected in a different manner.
389 ///Map displayed by label can be edited.
390 std::string nodemap_to_edit;
392 ///Map displayed by label can be edited.
393 std::string edgemap_to_edit;
395 static const int zoom_step = 5;
397 ///Is node radius autoscaled
400 ///Should we track zoomfactor changes
403 ///to store the zoom factor when it was "fixed"
404 double fixed_zoom_factor;
412 ///Iteration number during graph design
415 ///Attraction factor during graph design
418 ///Propulsation factor during graph design
423 ///reference to the container, in which the canvas is
426 XY calcArrowPos(XY, XY, XY, XY, int);
429 #endif //GRAPH_DISPLAYER_CANVAS_H