EpsWin and DesignWin does not need to know NoteBookTab.
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 graph can be drawn.
29 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
31 friend class BrokenEdge;
32 friend class LoopEdge;
34 class EdgeBase : public Gnome::Canvas::Group
37 ///Reference to the canvas, on which the graph is drawn.
39 ///It is needed, because some datas needed from
40 ///graph can be accessed by this or should be sent
41 ///as parameter, but it would be complicated
42 GraphDisplayerCanvas& canvas;
44 ///The edge that the class displays.
46 ///It is needed, because some datas needed from
47 ///graph can be accessed by this or should be sent
48 ///as parameter, but it would be complicated
51 Gnome::Canvas::Polygon arrow;
55 EdgeBase(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
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 ///Edge displayer class
65 ///This class is responsible for displaying edges in graph.
66 ///The displayed edge is broken in the middle. The
67 ///aim of this is to be able to indicate direction of edges
68 ///and to be able to display more then one edges between the
69 ///same source and target
70 class BrokenEdge : public EdgeBase
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 edges
94 bool edgeFormerEventHandler(GdkEvent* event);
97 ///Constructor of broken edge class.
99 ///\param g the group to which the edge belongs
100 ///\param _edge the represented edge
101 ///\param gc the canvas
102 BrokenEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
104 ///Destructor of broken edge class
110 ///The function that draws the edge 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 LoopEdge : public EdgeBase
122 Gnome::Canvas::Ellipse line;
123 bool edgeFormerEventHandler(GdkEvent* e);
126 LoopEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
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 graph is drawn
135 typedef Gnome::Canvas::CanvasAA Parent;
140 ///\param nbt the tab of the window, in which the graph is displayed
141 GraphDisplayerCanvas(NoteBookTab & nbt);
143 ///destructor of the class
144 virtual ~GraphDisplayerCanvas();
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 edge(s) according to the given map.
153 ///\param mapname is the name of the map which contains the values to be set
154 ///\param edge if it is given, only the width of the given edge will be set, instead of all of them.
155 int changeEdgeWidth (std::string mapname, Edge edge=INVALID);
157 ///Resets width of edge(s) to the default value
159 ///\param edge if it is given, only the width of the
160 ///given edge will be reset, instead of all of them.
161 int resetEdgeWidth (Edge edge=INVALID);
163 ///Changes the color of edge(s) according to the given map.
165 ///\param mapname is the name of the map which contains the new values
166 ///\param edge if it is given, only the color of the given edge will be set, instead of all of them.
167 int changeEdgeColor (std::string mapname, Edge edge=INVALID);
169 ///Resets color of edge(s) to the default value
171 ///\param edge if it is given, only the color of the
172 ///given edge will be reset, instead of all of them.
173 int resetEdgeColor (Edge edge=INVALID);
175 ///Changes the label of edge(s) according to the given map.
177 ///\param mapname is the name of the map which contains the new values
178 ///\param edge if it is given, only the label of the given edge will be set, instead of all of them.
179 int changeEdgeText (std::string mapname, Edge edge=INVALID);
181 ///Resets label of edge(s) to the default value
183 ///\param edge if it is given, only the color of the
184 ///given edge will be reset, instead of all of them.
185 int resetEdgeText (Edge edge=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 itisedge if true, edge 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 itisedge, int prop);
229 ///updates the given property
231 ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them
232 ///\param prop the property to update
233 void propertyUpdate(Edge edge, 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 edge
242 void propertyUpdate(Edge);
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 graph.
256 void updateScrollRegion();
258 ///This function changes the tool in the graph-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_edge-tool is active
284 bool createEdgeEventHandler(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 edge belonging to an EdgeBase
302 ///After we have activated an edge this way,
303 ///the GDC object will know, which edge is under forming
304 ///therefore it can redraw the necessary elements on the canvas,
305 ///for example the text belonging to the \ref EdgeBase can be
306 ///redrawn (\ref textReposition).
307 void toggleEdgeActivity(EdgeBase*, 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 graph.
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 Edgemap
338 ///\param init initial value of the map
339 ///\param mapname name of new map
340 int addNewEdgeMap(double init,std::string mapname);
342 void reDesignGraph();
344 ///Show whether the graph is already drawn.
348 ///Deletes the given element.
349 void deleteItem(Node);
350 ///Deletes the given element.
351 void deleteItem(Edge);
355 ///Map of nodes of graph
356 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
358 ///Map of edges of graph
359 Graph::EdgeMap<EdgeBase*> edgesmap;
361 ///Map of texts to write on edges
362 Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
364 ///Map of texts to write on nodes
365 Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
367 ///Group of graphical 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 edge 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 edge 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 edge (for any editing)
402 ///the edge that is selected by clicking on the red arrow in the middle of it
404 ///This edge 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 edgemap_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 graph 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