COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas.h @ 89:4042761b21e3

gui
Last change on this file since 89:4042761b21e3 was 89:4042761b21e3, checked in by Hegyi Péter, 18 years ago

Reorganizing.

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