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