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
RevLine 
[1442]1// -*- C++ -*- //
2
3#ifndef GRAPH_DISPLAYER_CANVAS_H
4#define GRAPH_DISPLAYER_CANVAS_H
5
[1501]6class GraphDisplayerCanvas;
7
[1606]8#include "all_include.h"
9#include "mapstorage.h"
10#include "map_win.h"
[1442]11#include <libgnomecanvasmm.h>
12#include <libgnomecanvasmm/polygon.h>
[1819]13#include <lemon/xy.h>
[1442]14
15///This class is the canvas, on which the graph can be drawn.
16class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
17{
[1819]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  };
[1442]40  typedef Gnome::Canvas::CanvasAA Parent;
41
42public:
[1614]43  GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *);
[1442]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
[1643]48  int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
[1731]49  int resetEdgeWidth (Edge new_item=INVALID);
[1442]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
[1643]53  int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
[1731]54  int resetEdgeColor (Edge new_item=INVALID);
[1442]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
[1643]58  int changeEdgeText (std::string mapname, Edge new_item=INVALID);
[1731]59  int resetEdgeText (Edge new_item=INVALID);
[1512]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
[1643]63  int changeNodeRadius (std::string mapname, Node new_item=INVALID);
[1731]64  int resetNodeRadius (Node new_item=INVALID);
[1512]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
[1643]68  int changeNodeColor (std::string mapname, Node new_item=INVALID);
[1731]69  int resetNodeColor (Node new_item=INVALID);
[1512]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
[1643]73  int changeNodeText (std::string mapname, Node new_item=INVALID);
[1731]74  int resetNodeText (Node new_item=INVALID);
[1442]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
[1468]87  ///This function changes the tool in the graph-editor's hand
88  void changeEditorialTool(int);
89
[1442]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
[1505]100  ///DEPRECATED!!!!
[1524]101  bool eventHandler(GdkEvent* e, Node n);
[1442]102
[1468]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
[1524]109  bool moveEventHandler(GdkEvent*);
[1468]110  ///event handler for the case when create_node-tool is active
[1524]111  bool createNodeEventHandler(GdkEvent*);
[1468]112  ///event handler for the case when create_edge-tool is active
[1524]113  bool createEdgeEventHandler(GdkEvent*);
[1485]114  ///event handler for the case when eraser-tool is active
[1524]115  bool eraserEventHandler(GdkEvent*);
[1550]116  ///event handler for the case when edge map editor tool is active
[1524]117  bool edgeMapEditEventHandler(GdkEvent*);
[1550]118  ///event handler for the case when node map editor tool is active
119  bool nodeMapEditEventHandler(GdkEvent*);
[1485]120
[1501]121public:
[1505]122  ///Moves the text to new place
[1524]123  void textReposition(xy<double>);
[1505]124  ///Activates an edge belonging to a BrokenEdge
[1579]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).
[1524]131  void toggleEdgeActivity(BrokenEdge*, bool);
[1505]132
133public:
[1501]134  ///\return the actual tool in hand
[1524]135  int getActualTool();
[1501]136
[1606]137  void drawGraph();
138  void clear();
139
[1585]140  ///creates a new Nodemap
[1597]141  int addNewNodeMap(double,std::string);
[1585]142  ///creates a new Edgemap
[1597]143  int addNewEdgeMap(double,std::string);
[1585]144
[1501]145private:
[1486]146  ///Deletes the given element.
[1643]147  void deleteItem(Node);
[1486]148  ///Deletes the given element.
[1643]149  void deleteItem(Edge);
[1468]150
[1501]151private:
152
[1442]153  ///Map of nodes of graph
154  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
155
156  ///Map of edges of graph
[1499]157  Graph::EdgeMap<BrokenEdge *> edgesmap;
[1442]158
159  ///Map of texts to write on edges
160  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
161
[1512]162  ///Map of texts to write on nodes
163  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
164
[1442]165  ///Group of graphical elements of displayed_graph
166  Gnome::Canvas::Group displayed_graph;
167
[1814]168public:
[1442]169  ///Here we store the maps that can be displayed through properties.
[1589]170  MapStorage & mapstorage;
[1442]171
[1814]172private:
[1442]173  ///Indicates whether the button of mouse is pressed or not
[1500]174  int isbutton;
[1442]175
[1501]176  ///Stores the actual tool in hand
177  int actual_tool;
178
[1442]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
[1474]187  Gnome::Canvas::Item * active_item, * target_item;
[1643]188  Node active_node;
189  Edge active_edge;
190  Edge forming_edge;
[1579]191
192  std::string nodemap_to_edit, edgemap_to_edit;
[1442]193
194  static const int zoom_step = 5;
[1499]195
[1814]196public:
[1512]197  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
[1606]198  MapWin & mapwin;
[1512]199
[1814]200private:
201
[1648]202  ///pointer to the parent window
[1614]203  Gtk::Window * parentwin;
204
[1442]205};
206
207#endif //GRAPH_DISPLAYER_CANVAS_H
Note: See TracBrowser for help on using the repository browser.