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