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