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