COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas.h @ 19:164783ceb9be

gui
Last change on this file since 19:164783ceb9be was 19:164783ceb9be, checked in by Hegyi Péter, 14 years ago

Little red arrows appear in breakpoints of edges.

File size: 3.7 KB
Line 
1// -*- C++ -*- //
2
3#ifndef GRAPH_DISPLAYER_CANVAS_H
4#define GRAPH_DISPLAYER_CANVAS_H
5
6#include <all_include.h>
7#include <mapstorage.h>
8#include <broken_edge.h>
9#include <libgnomecanvasmm.h>
10#include <libgnomecanvasmm/polygon.h>
11
12///This class is the canvas, on which the graph can be drawn.
13class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
14{
15  typedef Gnome::Canvas::CanvasAA Parent;
16
17public:
18  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
19  virtual ~GraphDisplayerCanvas();
20
21  ///Changes the linewidth attribute according to the given map.
22  ///\param mapname is the name of the map which contains the new values
23  int changeLineWidth (std::string mapname);
24
25  ///Changes the linecolor attribute according to the given map.
26  ///\param mapname is the name of the map which contains the new values
27  int changeColor (std::string mapname);
28
29  ///Changes the text of line attribute according to the given map.
30  ///\param mapname is the name of the map which contains the new values
31  int changeText (std::string mapname);
32
33  ///Callback for 'ViewZoomIn' action.
34  virtual void zoomIn();
35  ///Callback for 'ViewZoomOut' action.
36  virtual void zoomOut();
37  ///Callback for 'ViewZoomFit' action.
38  virtual void zoomFit();
39  ///Callback for 'ViewZoom100' action.
40  virtual void zoom100();
41  ///Sets the scroll region of the convas to the bounding box of the graph.
42  void updateScrollRegion();
43
44  ///This function changes the tool in the graph-editor's hand
45  void changeEditorialTool(int);
46
47protected:
48
49  //maximizing, minimizing, restoring window, etc.
50  virtual bool on_expose_event(GdkEventExpose *);
51
52private:
53
54  ///This function is responsible for the correct
55  ///reaction of any action happened in the territory
56  ///of the canvas
57  bool event_handler(GdkEvent* e, Node n);
58
59  ///actual event handler
60  ///
61  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
62  sigc::connection actual_handler;
63
64  ///event handler for the case when move-tool is active
65  bool move_event_handler(GdkEvent*);
66  ///event handler for the case when create_node-tool is active
67  bool create_node_event_handler(GdkEvent*);
68  ///event handler for the case when create_edge-tool is active
69  bool create_edge_event_handler(GdkEvent*);
70  ///event handler for the case when eraser-tool is active
71  bool eraser_event_handler(GdkEvent*);
72
73  ///Deletes the given element.
74  void delete_item(NodeIt);
75  ///Deletes the given element.
76  void delete_item(EdgeIt);
77  ///Deletes the given element.
78  void delete_item(Graph::Edge);
79
80  ///The graph, on which we work
81  Graph g;
82
83  ///Map of nodes of graph
84  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
85
86  ///Map of edges of graph
87  Graph::EdgeMap<BrokenEdge *> edgesmap;
88
89  ///Map of texts to write on edges
90  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
91
92  ///Group of graphical elements of displayed_graph
93  Gnome::Canvas::Group displayed_graph;
94
95  ///Here we store the maps that can be displayed through properties.
96  MapStorage mapstorage;
97
98  ///Indicates whether the button of mouse is pressed or not
99  bool isbutton;
100
101  ///At this location was the mousebutton pressed.
102  ///It helps to calculate the distance of dragging.
103  double clicked_x, clicked_y;
104
105  ///Remembers which Gnome::Canvas::Item was pressed.
106  ///this variable is needed, because
107  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
108  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
109  Gnome::Canvas::Item * active_item, * target_item;
110  Graph::NodeIt active_node;
111  Graph::EdgeIt active_edge;
112
113  static const int zoom_step = 5;
114
115};
116
117#endif //GRAPH_DISPLAYER_CANVAS_H
Note: See TracBrowser for help on using the repository browser.