COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas.h @ 1825:535d2eccfc03

Last change on this file since 1825:535d2eccfc03 was 1819:fd82adfbe905, checked in by Hegyi Péter, 14 years ago

Reorganizing.

File size: 6.5 KB
Line 
1// -*- C++ -*- //
2
3#ifndef GRAPH_DISPLAYER_CANVAS_H
4#define GRAPH_DISPLAYER_CANVAS_H
5
6class GraphDisplayerCanvas;
7
8#include "all_include.h"
9#include "mapstorage.h"
10#include "map_win.h"
11#include <libgnomecanvasmm.h>
12#include <libgnomecanvasmm/polygon.h>
13#include <lemon/xy.h>
14
15///This class is the canvas, on which the graph can be drawn.
16class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
17{
18  class BrokenEdge : public Gnome::Canvas::Line
19  {
20    GraphDisplayerCanvas & gdc;
21    Gnome::Canvas::Polygon * arrow;
22    Gnome::Art::Point * my_points;
23
24
25    ///Indicates whether the button of mouse is pressed or not
26    bool isbutton;
27
28    ///At this location was the mousebutton pressed.
29    ///It helps to calculate the distance of dragging.
30    double clicked_x, clicked_y;
31
32    ///event handler for forming edges
33    bool edgeFormerEventHandler(GdkEvent*);
34  public:
35    BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &);
36    ~BrokenEdge();
37    void setPoints(Gnome::Canvas::Points, bool move=false);
38    xy<double> getArrowPos();
39  };
40  typedef Gnome::Canvas::CanvasAA Parent;
41
42public:
43  GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *);
44  virtual ~GraphDisplayerCanvas();
45
46  ///Changes the linewidth attribute according to the given map.
47  ///\param mapname is the name of the map which contains the new values
48  int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
49  int resetEdgeWidth (Edge new_item=INVALID);
50
51  ///Changes the linecolor attribute according to the given map.
52  ///\param mapname is the name of the map which contains the new values
53  int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
54  int resetEdgeColor (Edge new_item=INVALID);
55
56  ///Changes the text of line attribute according to the given map.
57  ///\param mapname is the name of the map which contains the new values
58  int changeEdgeText (std::string mapname, Edge new_item=INVALID);
59  int resetEdgeText (Edge new_item=INVALID);
60
61  ///Changes the linewidth attribute according to the given map.
62  ///\param mapname is the name of the map which contains the new values
63  int changeNodeRadius (std::string mapname, Node new_item=INVALID);
64  int resetNodeRadius (Node new_item=INVALID);
65
66  ///Changes the linecolor attribute according to the given map.
67  ///\param mapname is the name of the map which contains the new values
68  int changeNodeColor (std::string mapname, Node new_item=INVALID);
69  int resetNodeColor (Node new_item=INVALID);
70
71  ///Changes the text of line attribute according to the given map.
72  ///\param mapname is the name of the map which contains the new values
73  int changeNodeText (std::string mapname, Node new_item=INVALID);
74  int resetNodeText (Node new_item=INVALID);
75
76  ///Callback for 'ViewZoomIn' action.
77  virtual void zoomIn();
78  ///Callback for 'ViewZoomOut' action.
79  virtual void zoomOut();
80  ///Callback for 'ViewZoomFit' action.
81  virtual void zoomFit();
82  ///Callback for 'ViewZoom100' action.
83  virtual void zoom100();
84  ///Sets the scroll region of the convas to the bounding box of the graph.
85  void updateScrollRegion();
86
87  ///This function changes the tool in the graph-editor's hand
88  void changeEditorialTool(int);
89
90protected:
91
92  //maximizing, minimizing, restoring window, etc.
93  virtual bool on_expose_event(GdkEventExpose *);
94
95private:
96
97  ///This function is responsible for the correct
98  ///reaction of any action happened in the territory
99  ///of the canvas
100  ///DEPRECATED!!!!
101  bool eventHandler(GdkEvent* e, Node n);
102
103  ///actual event handler
104  ///
105  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
106  sigc::connection actual_handler;
107
108  ///event handler for the case when move-tool is active
109  bool moveEventHandler(GdkEvent*);
110  ///event handler for the case when create_node-tool is active
111  bool createNodeEventHandler(GdkEvent*);
112  ///event handler for the case when create_edge-tool is active
113  bool createEdgeEventHandler(GdkEvent*);
114  ///event handler for the case when eraser-tool is active
115  bool eraserEventHandler(GdkEvent*);
116  ///event handler for the case when edge map editor tool is active
117  bool edgeMapEditEventHandler(GdkEvent*);
118  ///event handler for the case when node map editor tool is active
119  bool nodeMapEditEventHandler(GdkEvent*);
120
121public:
122  ///Moves the text to new place
123  void textReposition(xy<double>);
124  ///Activates an edge belonging to a BrokenEdge
125  ///
126  ///After we have activated an edge this way,
127  ///the GDC object will know, which edge is under forming
128  ///therefore it can redraw the necessarz elementy on the canvas,
129  ///for example the text belonging to the \ref BrokenEdge can be
130  ///redrawn (\ref textReposition).
131  void toggleEdgeActivity(BrokenEdge*, bool);
132
133public:
134  ///\return the actual tool in hand
135  int getActualTool();
136
137  void drawGraph();
138  void clear();
139
140  ///creates a new Nodemap
141  int addNewNodeMap(double,std::string);
142  ///creates a new Edgemap
143  int addNewEdgeMap(double,std::string);
144
145private:
146  ///Deletes the given element.
147  void deleteItem(Node);
148  ///Deletes the given element.
149  void deleteItem(Edge);
150
151private:
152
153  ///Map of nodes of graph
154  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
155
156  ///Map of edges of graph
157  Graph::EdgeMap<BrokenEdge *> edgesmap;
158
159  ///Map of texts to write on edges
160  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
161
162  ///Map of texts to write on nodes
163  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
164
165  ///Group of graphical elements of displayed_graph
166  Gnome::Canvas::Group displayed_graph;
167
168public:
169  ///Here we store the maps that can be displayed through properties.
170  MapStorage & mapstorage;
171
172private:
173  ///Indicates whether the button of mouse is pressed or not
174  int isbutton;
175
176  ///Stores the actual tool in hand
177  int actual_tool;
178
179  ///At this location was the mousebutton pressed.
180  ///It helps to calculate the distance of dragging.
181  double clicked_x, clicked_y;
182
183  ///Remembers which Gnome::Canvas::Item was pressed.
184  ///this variable is needed, because
185  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
186  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
187  Gnome::Canvas::Item * active_item, * target_item;
188  Node active_node;
189  Edge active_edge;
190  Edge forming_edge;
191
192  std::string nodemap_to_edit, edgemap_to_edit;
193
194  static const int zoom_step = 5;
195
196public:
197  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
198  MapWin & mapwin;
199
200private:
201
202  ///pointer to the parent window
203  Gtk::Window * parentwin;
204
205};
206
207#endif //GRAPH_DISPLAYER_CANVAS_H
Note: See TracBrowser for help on using the repository browser.