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@1501
|
88 |
///event handler for the case when eraser-tool is active
|
hegyi@1524
|
89 |
bool edgeMapEditEventHandler(GdkEvent*);
|
hegyi@1485
|
90 |
|
hegyi@1501
|
91 |
public:
|
hegyi@1505
|
92 |
///Moves the text to new place
|
hegyi@1524
|
93 |
void textReposition(xy<double>);
|
hegyi@1505
|
94 |
///Activates an edge belonging to a BrokenEdge
|
hegyi@1524
|
95 |
void toggleEdgeActivity(BrokenEdge*, bool);
|
hegyi@1505
|
96 |
|
hegyi@1505
|
97 |
public:
|
hegyi@1501
|
98 |
///\return the actual tool in hand
|
hegyi@1524
|
99 |
int getActualTool();
|
hegyi@1501
|
100 |
|
hegyi@1501
|
101 |
private:
|
hegyi@1486
|
102 |
///Deletes the given element.
|
hegyi@1524
|
103 |
void deleteItem(NodeIt);
|
hegyi@1486
|
104 |
///Deletes the given element.
|
hegyi@1524
|
105 |
void deleteItem(EdgeIt);
|
hegyi@1496
|
106 |
///Deletes the given element.
|
hegyi@1524
|
107 |
void deleteItem(Graph::Edge);
|
hegyi@1468
|
108 |
|
hegyi@1501
|
109 |
private:
|
hegyi@1501
|
110 |
|
ladanyi@1442
|
111 |
///The graph, on which we work
|
hegyi@1524
|
112 |
Graph & g;
|
ladanyi@1442
|
113 |
|
ladanyi@1442
|
114 |
///Map of nodes of graph
|
ladanyi@1442
|
115 |
Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
|
ladanyi@1442
|
116 |
|
ladanyi@1442
|
117 |
///Map of edges of graph
|
hegyi@1499
|
118 |
Graph::EdgeMap<BrokenEdge *> edgesmap;
|
ladanyi@1442
|
119 |
|
ladanyi@1442
|
120 |
///Map of texts to write on edges
|
ladanyi@1442
|
121 |
Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
|
ladanyi@1442
|
122 |
|
hegyi@1512
|
123 |
///Map of texts to write on nodes
|
hegyi@1512
|
124 |
Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
|
hegyi@1512
|
125 |
|
ladanyi@1442
|
126 |
///Group of graphical elements of displayed_graph
|
ladanyi@1442
|
127 |
Gnome::Canvas::Group displayed_graph;
|
ladanyi@1442
|
128 |
|
ladanyi@1442
|
129 |
///Here we store the maps that can be displayed through properties.
|
ladanyi@1442
|
130 |
MapStorage mapstorage;
|
ladanyi@1442
|
131 |
|
ladanyi@1442
|
132 |
///Indicates whether the button of mouse is pressed or not
|
hegyi@1500
|
133 |
int isbutton;
|
ladanyi@1442
|
134 |
|
hegyi@1501
|
135 |
///Stores the actual tool in hand
|
hegyi@1501
|
136 |
int actual_tool;
|
hegyi@1501
|
137 |
|
ladanyi@1442
|
138 |
///At this location was the mousebutton pressed.
|
ladanyi@1442
|
139 |
///It helps to calculate the distance of dragging.
|
ladanyi@1442
|
140 |
double clicked_x, clicked_y;
|
ladanyi@1442
|
141 |
|
ladanyi@1442
|
142 |
///Remembers which Gnome::Canvas::Item was pressed.
|
ladanyi@1442
|
143 |
///this variable is needed, because
|
ladanyi@1442
|
144 |
///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
|
ladanyi@1442
|
145 |
///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
|
hegyi@1474
|
146 |
Gnome::Canvas::Item * active_item, * target_item;
|
hegyi@1468
|
147 |
Graph::NodeIt active_node;
|
hegyi@1474
|
148 |
Graph::EdgeIt active_edge;
|
ladanyi@1442
|
149 |
|
ladanyi@1442
|
150 |
static const int zoom_step = 5;
|
hegyi@1499
|
151 |
|
hegyi@1512
|
152 |
///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
|
hegyi@1512
|
153 |
MapWin * mapwin;
|
hegyi@1512
|
154 |
|
ladanyi@1442
|
155 |
};
|
ladanyi@1442
|
156 |
|
ladanyi@1442
|
157 |
#endif //GRAPH_DISPLAYER_CANVAS_H
|