1 | // -*- C++ -*- // |
---|
2 | |
---|
3 | #ifndef GRAPH_DISPLAYER_CANVAS_H |
---|
4 | #define GRAPH_DISPLAYER_CANVAS_H |
---|
5 | |
---|
6 | class GraphDisplayerCanvas; |
---|
7 | |
---|
8 | #include <all_include.h> |
---|
9 | #include <mapstorage.h> |
---|
10 | #include <broken_edge.h> |
---|
11 | #include <libgnomecanvasmm.h> |
---|
12 | #include <libgnomecanvasmm/polygon.h> |
---|
13 | |
---|
14 | ///This class is the canvas, on which the graph can be drawn. |
---|
15 | class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA |
---|
16 | { |
---|
17 | typedef Gnome::Canvas::CanvasAA Parent; |
---|
18 | |
---|
19 | public: |
---|
20 | GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &); |
---|
21 | virtual ~GraphDisplayerCanvas(); |
---|
22 | |
---|
23 | ///Changes the linewidth attribute according to the given map. |
---|
24 | ///\param mapname is the name of the map which contains the new values |
---|
25 | int changeLineWidth (std::string mapname); |
---|
26 | |
---|
27 | ///Changes the linecolor attribute according to the given map. |
---|
28 | ///\param mapname is the name of the map which contains the new values |
---|
29 | int changeColor (std::string mapname); |
---|
30 | |
---|
31 | ///Changes the text of line attribute according to the given map. |
---|
32 | ///\param mapname is the name of the map which contains the new values |
---|
33 | int changeText (std::string mapname); |
---|
34 | |
---|
35 | ///Callback for 'ViewZoomIn' action. |
---|
36 | virtual void zoomIn(); |
---|
37 | ///Callback for 'ViewZoomOut' action. |
---|
38 | virtual void zoomOut(); |
---|
39 | ///Callback for 'ViewZoomFit' action. |
---|
40 | virtual void zoomFit(); |
---|
41 | ///Callback for 'ViewZoom100' action. |
---|
42 | virtual void zoom100(); |
---|
43 | ///Sets the scroll region of the convas to the bounding box of the graph. |
---|
44 | void updateScrollRegion(); |
---|
45 | |
---|
46 | ///This function changes the tool in the graph-editor's hand |
---|
47 | void changeEditorialTool(int); |
---|
48 | |
---|
49 | protected: |
---|
50 | |
---|
51 | //maximizing, minimizing, restoring window, etc. |
---|
52 | virtual bool on_expose_event(GdkEventExpose *); |
---|
53 | |
---|
54 | private: |
---|
55 | |
---|
56 | ///This function is responsible for the correct |
---|
57 | ///reaction of any action happened in the territory |
---|
58 | ///of the canvas |
---|
59 | ///DEPRECATED!!!! |
---|
60 | bool event_handler(GdkEvent* e, Node n); |
---|
61 | |
---|
62 | ///actual event handler |
---|
63 | /// |
---|
64 | ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. |
---|
65 | sigc::connection actual_handler; |
---|
66 | |
---|
67 | ///event handler for the case when move-tool is active |
---|
68 | bool move_event_handler(GdkEvent*); |
---|
69 | ///event handler for the case when create_node-tool is active |
---|
70 | bool create_node_event_handler(GdkEvent*); |
---|
71 | ///event handler for the case when create_edge-tool is active |
---|
72 | bool create_edge_event_handler(GdkEvent*); |
---|
73 | ///event handler for the case when eraser-tool is active |
---|
74 | bool eraser_event_handler(GdkEvent*); |
---|
75 | ///event handler for the case when eraser-tool is active |
---|
76 | bool edge_map_edit_event_handler(GdkEvent*); |
---|
77 | |
---|
78 | public: |
---|
79 | ///Moves the text to new place |
---|
80 | void text_reposition(xy<double>); |
---|
81 | ///Activates an edge belonging to a BrokenEdge |
---|
82 | void toggle_edge_activity(BrokenEdge*, bool); |
---|
83 | |
---|
84 | public: |
---|
85 | ///\return the actual tool in hand |
---|
86 | int get_actual_tool(); |
---|
87 | |
---|
88 | private: |
---|
89 | ///Deletes the given element. |
---|
90 | void delete_item(NodeIt); |
---|
91 | ///Deletes the given element. |
---|
92 | void delete_item(EdgeIt); |
---|
93 | ///Deletes the given element. |
---|
94 | void delete_item(Graph::Edge); |
---|
95 | |
---|
96 | private: |
---|
97 | |
---|
98 | ///The graph, on which we work |
---|
99 | Graph g; |
---|
100 | |
---|
101 | ///Map of nodes of graph |
---|
102 | Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; |
---|
103 | |
---|
104 | ///Map of edges of graph |
---|
105 | Graph::EdgeMap<BrokenEdge *> edgesmap; |
---|
106 | |
---|
107 | ///Map of texts to write on edges |
---|
108 | Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap; |
---|
109 | |
---|
110 | ///Group of graphical elements of displayed_graph |
---|
111 | Gnome::Canvas::Group displayed_graph; |
---|
112 | |
---|
113 | ///Here we store the maps that can be displayed through properties. |
---|
114 | MapStorage mapstorage; |
---|
115 | |
---|
116 | ///Indicates whether the button of mouse is pressed or not |
---|
117 | int isbutton; |
---|
118 | |
---|
119 | ///Stores the actual tool in hand |
---|
120 | int actual_tool; |
---|
121 | |
---|
122 | ///At this location was the mousebutton pressed. |
---|
123 | ///It helps to calculate the distance of dragging. |
---|
124 | double clicked_x, clicked_y; |
---|
125 | |
---|
126 | ///Remembers which Gnome::Canvas::Item was pressed. |
---|
127 | ///this variable is needed, because |
---|
128 | ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault |
---|
129 | ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution |
---|
130 | Gnome::Canvas::Item * active_item, * target_item; |
---|
131 | Graph::NodeIt active_node; |
---|
132 | Graph::EdgeIt active_edge; |
---|
133 | |
---|
134 | static const int zoom_step = 5; |
---|
135 | |
---|
136 | }; |
---|
137 | |
---|
138 | #endif //GRAPH_DISPLAYER_CANVAS_H |
---|