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