Remove lemon/graph_utils.h include.
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 #ifndef GRAPH_DISPLAYER_CANVAS_H
20 #define GRAPH_DISPLAYER_CANVAS_H
24 #include "all_include.h"
25 #include <libgnomecanvasmm.h>
26 #include <libgnomecanvasmm/polygon.h>
28 ///This class is the canvas, on which the digraph can be drawn.
29 class DigraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
31 friend class BrokenArc;
34 class ArcBase : public Gnome::Canvas::Group
37 ///Reference to the canvas, on which the digraph is drawn.
39 ///It is needed, because some datas needed from
40 ///digraph can be accessed by this or should be sent
41 ///as parameter, but it would be complicated
42 DigraphDisplayerCanvas& canvas;
44 ///The arc that the class displays.
46 ///It is needed, because some datas needed from
47 ///digraph can be accessed by this or should be sent
48 ///as parameter, but it would be complicated
51 Gnome::Canvas::Polygon arrow;
55 ArcBase(Gnome::Canvas::Group&, Arc, DigraphDisplayerCanvas&);
57 virtual void draw() = 0;
58 virtual void setLineWidth(int) = 0;
59 virtual void setFillColor(Gdk::Color) = 0;
60 virtual Gnome::Canvas::Item * getLine() = 0;
63 ///Arc displayer class
65 ///This class is responsible for displaying arcs in digraph.
66 ///The displayed arc is broken in the middle. The
67 ///aim of this is to be able to indicate direction of arcs
68 ///and to be able to display more then one arcs between the
69 ///same source and target
70 class BrokenArc : public ArcBase
73 Gnome::Canvas::Line line;
75 ///Indicates whether the button of mouse is pressed or not at the moment.
78 ///At this location was the mousebutton pressed. Horizontal component.
80 ///It helps to calculate the
81 ///distance of dragging.
84 ///At this location was the mousebutton pressed. Vertical component.
86 ///It helps to calculate the
87 ///distance of dragging.
90 ///event handler for forming broken arcs
94 bool arcFormerEventHandler(GdkEvent* event);
97 ///Constructor of broken arc class.
99 ///\param g the group to which the arc belongs
100 ///\param _arc the represented arc
101 ///\param gc the canvas
102 BrokenArc(Gnome::Canvas::Group&, Arc, DigraphDisplayerCanvas&);
104 ///Destructor of broken arc class
110 ///The function that draws the arc based on collected data
113 void setLineWidth(int);
114 void setFillColor(Gdk::Color);
116 Gnome::Canvas::Item * getLine() { return (Gnome::Canvas::Item *)(&line); };
119 class LoopArc : public ArcBase
122 Gnome::Canvas::Ellipse line;
123 bool arcFormerEventHandler(GdkEvent* e);
126 LoopArc(Gnome::Canvas::Group&, Arc, DigraphDisplayerCanvas&);
129 void setLineWidth(int);
130 void setFillColor(Gdk::Color);
131 Gnome::Canvas::Item * getLine() { return (Gnome::Canvas::Item *)(&line); };
134 ///Type of canvas, on which the digraph is drawn
135 typedef Gnome::Canvas::CanvasAA Parent;
140 ///\param nbt the tab of the window, in which the digraph is displayed
141 DigraphDisplayerCanvas(NoteBookTab & nbt);
143 ///destructor of the class
144 virtual ~DigraphDisplayerCanvas();
146 ///Returns a color of the rainbow based on a map value and the min and max value of the given map
148 ///min and max is purple, between them there is a linear assign
149 Gdk::Color rainbowColorCounter(double, double, double);
151 ///Changes the width of arc(s) according to the given map.
153 ///\param mapname is the name of the map which contains the values to be set
154 ///\param arc if it is given, only the width of the given arc will be set, instead of all of them.
155 int changeArcWidth (std::string mapname, Arc arc=INVALID);
157 ///Resets width of arc(s) to the default value
159 ///\param arc if it is given, only the width of the
160 ///given arc will be reset, instead of all of them.
161 int resetArcWidth (Arc arc=INVALID);
163 ///Changes the color of arc(s) according to the given map.
165 ///\param mapname is the name of the map which contains the new values
166 ///\param arc if it is given, only the color of the given arc will be set, instead of all of them.
167 int changeArcColor (std::string mapname, Arc arc=INVALID);
169 ///Resets color of arc(s) to the default value
171 ///\param arc if it is given, only the color of the
172 ///given arc will be reset, instead of all of them.
173 int resetArcColor (Arc arc=INVALID);
175 ///Changes the label of arc(s) according to the given map.
177 ///\param mapname is the name of the map which contains the new values
178 ///\param arc if it is given, only the label of the given arc will be set, instead of all of them.
179 int changeArcText (std::string mapname, Arc arc=INVALID);
181 ///Resets label of arc(s) to the default value
183 ///\param arc if it is given, only the color of the
184 ///given arc will be reset, instead of all of them.
185 int resetArcText (Arc arc=INVALID);
187 ///Changes the radius of node(s) according to the given map.
189 ///\param mapname is the name of the map which contains the new values
190 ///\param node if it is given, only the radius of the given node will be set, instead of all of them.
191 int changeNodeRadius (std::string mapname, Node node=INVALID);
193 ///Resets radius of node(s) to the default value
195 ///\param node if it is given, only the radius of the
196 ///given node will be reset, instead of all of them.
197 int resetNodeRadius (Node node=INVALID);
199 ///Changes the color of node(s) according to the given map.
201 ///\param mapname is the name of the map which contains the new values
202 ///\param node if it is given, only the color of the given node will be set, instead of all of them.
203 int changeNodeColor (std::string mapname, Node node=INVALID);
205 ///Resets color of node(s) to the default value
207 ///\param node if it is given, only the color of the
208 ///given node will be reset, instead of all of them.
209 int resetNodeColor (Node node=INVALID);
211 ///Changes the label of node(s) according to the given map.
213 ///\param mapname is the name of the map which contains the new values
214 ///\param node if it is given, only the label of the given node will be set, instead of all of them.
215 int changeNodeText (std::string mapname, Node node=INVALID);
217 ///Resets label of node(s) to the default value
219 ///\param node if it is given, only the label of the
220 ///given node will be reset, instead of all of them.
221 int resetNodeText (Node node=INVALID);
223 ///This function is called, when any of the displayed attributes have to be updated, or changed
225 ///\param itisarc if true, arc property has to be changed, else node property
226 ///\param prop the id of property that has to changed or updated
227 void propertyChange(bool itisarc, int prop);
229 ///updates the given property
231 ///\param arc if it is not INVALID, only the property of the given arc will be updated, instead of all of them
232 ///\param prop the property to update
233 void propertyUpdate(Arc arc, int prop);
235 ///updates the given property
237 ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them
238 ///\param prop the property to update
239 void propertyUpdate(Node node, int prop);
241 ///updates all the property for the given arc
242 void propertyUpdate(Arc);
244 ///updates all the property for the given node
245 void propertyUpdate(Node);
247 ///Callback for 'ViewZoomIn' action.
248 virtual void zoomIn();
249 ///Callback for 'ViewZoomOut' action.
250 virtual void zoomOut();
251 ///Callback for 'ViewZoomFit' action.
252 virtual void zoomFit();
253 ///Callback for 'ViewZoom100' action.
254 virtual void zoom100();
255 ///Sets the scroll region of the convas to the bounding box of the digraph.
256 void updateScrollRegion();
258 ///This function changes the tool in the digraph-editor's hand
259 void changeEditorialTool(int);
263 //maximizing, minimizing, restoring window, etc.
264 virtual bool on_expose_event(GdkEventExpose *);
268 ///This function is responsible for the correct
269 ///reaction of any action happened in the territory
272 bool eventHandler(GdkEvent* e, Node n);
274 ///actual event handler
276 ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
277 sigc::connection actual_handler;
279 ///event handler for the case when move-tool is active
280 bool moveEventHandler(GdkEvent*);
281 ///event handler for the case when create_node-tool is active
282 bool createNodeEventHandler(GdkEvent*);
283 ///event handler for the case when create_arc-tool is active
284 bool createArcEventHandler(GdkEvent*);
285 ///event handler for the case when eraser-tool is active
286 bool eraserEventHandler(GdkEvent*);
287 ///event handler for the case when map editor tool is active
288 bool mapEditEventHandler(GdkEvent*);
289 ///event handler for the case when user scrolls the mouse
290 bool scrollEventHandler(GdkEvent*);
293 ///moves node according to the given parameters
294 void moveNode(double, double, Gnome::Canvas::Item * item=NULL, Node node=INVALID);
297 ///Moves the text to new place
298 void textReposition(XY);
300 ///Activates an arc belonging to an ArcBase
302 ///After we have activated an arc this way,
303 ///the GDC object will know, which arc is under forming
304 ///therefore it can redraw the necessary elements on the canvas,
305 ///for example the text belonging to the \ref ArcBase can be
306 ///redrawn (\ref textReposition).
307 void toggleArcActivity(ArcBase*, bool);
311 ///Returns the actual tool in hand
314 ///Sets node representation settings
315 void setView(bool, bool, double, double);
317 ///Gets node representation settings
318 void getView(bool &, bool &, double&, double&);
322 ///Called when opening a file.
327 ///It achieves this by deleting all data
328 ///structure used to help handle the displayed digraph.
331 ///creates a new Nodemap
333 ///\param init initial value of the map
334 ///\param mapname name of new map
335 int addNewNodeMap(double init,std::string mapname);
336 ///creates a new Arcmap
338 ///\param init initial value of the map
339 ///\param mapname name of new map
340 int addNewArcMap(double init,std::string mapname);
342 void reDesignDigraph();
344 ///Show whether the digraph is already drawn.
348 ///Deletes the given element.
349 void deleteItem(Node);
350 ///Deletes the given element.
351 void deleteItem(Arc);
355 ///Map of nodes of digraph
356 Digraph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
358 ///Map of arcs of digraph
359 Digraph::ArcMap<ArcBase*> arcsmap;
361 ///Map of texts to write on arcs
362 Digraph::ArcMap<Gnome::Canvas::Text *> arctextmap;
364 ///Map of texts to write on nodes
365 Digraph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
367 ///Group of digraphical elements of displayed_graph
368 Gnome::Canvas::Group displayed_graph;
371 ///Indicates whether the button of mouse is pressed or not
374 ///Stores the actual tool in hand
377 ///At this location was the mousebutton pressed.
378 ///It helps to calculate the distance of dragging.
379 double clicked_x, clicked_y;
381 ///Remembers which Gnome::Canvas::Item was pressed.
383 ///this variable is needed, to work on it after selection
384 Gnome::Canvas::Item * active_item;
386 ///Remembers which Gnome::Canvas::Item was pressed.
388 ///this variable is used at arc creation, it will
389 ///be the secondly selected node. No local variable
390 ///can be used for this purpose inside the function,
391 ///because the node selected by button press, and
392 ///the arc is created by button release. Both of
393 ///them is different function call.
394 Gnome::Canvas::Item * target_item;
396 ///selected node (for any editing)
399 ///selected arc (for any editing)
402 ///the arc that is selected by clicking on the red arrow in the middle of it
404 ///This arc is stored only for the purpose of reshape it.
405 ///That is why it is selected in a different manner.
408 ///Map displayed by label can be edited.
409 std::string nodemap_to_edit;
411 ///Map displayed by label can be edited.
412 std::string arcmap_to_edit;
414 static const int zoom_step = 5;
416 ///Is node radius autoscaled
419 ///Should we track zoomfactor changes
422 ///to store the zoom factor when it was "fixed"
423 double fixed_zoom_factor;
431 ///Was redesign run on this digraph already?
433 ///If not, the layout will be modified randomly
434 ///to avoid frozen layout because of wrong
440 ///reference to the container, in which the canvas is
443 XY calcArrowPos(XY, XY, XY, XY, int);
446 Glib::RefPtr<Gdk::Pixbuf> refBackground;
447 Gnome::Canvas::Pixbuf *background;
449 void setBackground();
452 #endif //GRAPH_DISPLAYER_CANVAS_H