[6] | 1 | // -*- C++ -*- // |
---|
| 2 | |
---|
| 3 | #ifndef GRAPH_DISPLAYER_CANVAS_H |
---|
| 4 | #define GRAPH_DISPLAYER_CANVAS_H |
---|
| 5 | |
---|
[21] | 6 | class GraphDisplayerCanvas; |
---|
| 7 | |
---|
[6] | 8 | #include <all_include.h> |
---|
| 9 | #include <mapstorage.h> |
---|
[19] | 10 | #include <broken_edge.h> |
---|
[6] | 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 | |
---|
[9] | 46 | ///This function changes the tool in the graph-editor's hand |
---|
| 47 | void changeEditorialTool(int); |
---|
| 48 | |
---|
[6] | 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 | bool event_handler(GdkEvent* e, Node n); |
---|
| 60 | |
---|
[9] | 61 | ///actual event handler |
---|
| 62 | /// |
---|
| 63 | ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. |
---|
| 64 | sigc::connection actual_handler; |
---|
| 65 | |
---|
| 66 | ///event handler for the case when move-tool is active |
---|
| 67 | bool move_event_handler(GdkEvent*); |
---|
| 68 | ///event handler for the case when create_node-tool is active |
---|
| 69 | bool create_node_event_handler(GdkEvent*); |
---|
| 70 | ///event handler for the case when create_edge-tool is active |
---|
| 71 | bool create_edge_event_handler(GdkEvent*); |
---|
[13] | 72 | ///event handler for the case when eraser-tool is active |
---|
| 73 | bool eraser_event_handler(GdkEvent*); |
---|
[21] | 74 | ///event handler for the case when eraser-tool is active |
---|
| 75 | bool edge_map_edit_event_handler(GdkEvent*); |
---|
[13] | 76 | |
---|
[21] | 77 | public: |
---|
| 78 | ///\return the actual tool in hand |
---|
| 79 | int get_actual_tool(); |
---|
| 80 | |
---|
| 81 | private: |
---|
[14] | 82 | ///Deletes the given element. |
---|
| 83 | void delete_item(NodeIt); |
---|
| 84 | ///Deletes the given element. |
---|
| 85 | void delete_item(EdgeIt); |
---|
[16] | 86 | ///Deletes the given element. |
---|
| 87 | void delete_item(Graph::Edge); |
---|
[9] | 88 | |
---|
[21] | 89 | private: |
---|
| 90 | |
---|
[6] | 91 | ///The graph, on which we work |
---|
| 92 | Graph g; |
---|
| 93 | |
---|
| 94 | ///Map of nodes of graph |
---|
| 95 | Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; |
---|
| 96 | |
---|
| 97 | ///Map of edges of graph |
---|
[19] | 98 | Graph::EdgeMap<BrokenEdge *> edgesmap; |
---|
[6] | 99 | |
---|
| 100 | ///Map of texts to write on edges |
---|
| 101 | Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap; |
---|
| 102 | |
---|
| 103 | ///Group of graphical elements of displayed_graph |
---|
| 104 | Gnome::Canvas::Group displayed_graph; |
---|
| 105 | |
---|
| 106 | ///Here we store the maps that can be displayed through properties. |
---|
| 107 | MapStorage mapstorage; |
---|
| 108 | |
---|
| 109 | ///Indicates whether the button of mouse is pressed or not |
---|
[20] | 110 | int isbutton; |
---|
[6] | 111 | |
---|
[21] | 112 | ///Stores the actual tool in hand |
---|
| 113 | int actual_tool; |
---|
| 114 | |
---|
[6] | 115 | ///At this location was the mousebutton pressed. |
---|
| 116 | ///It helps to calculate the distance of dragging. |
---|
| 117 | double clicked_x, clicked_y; |
---|
| 118 | |
---|
| 119 | ///Remembers which Gnome::Canvas::Item was pressed. |
---|
| 120 | ///this variable is needed, because |
---|
| 121 | ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault |
---|
| 122 | ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution |
---|
[11] | 123 | Gnome::Canvas::Item * active_item, * target_item; |
---|
[9] | 124 | Graph::NodeIt active_node; |
---|
[11] | 125 | Graph::EdgeIt active_edge; |
---|
[6] | 126 | |
---|
| 127 | static const int zoom_step = 5; |
---|
[19] | 128 | |
---|
[6] | 129 | }; |
---|
| 130 | |
---|
| 131 | #endif //GRAPH_DISPLAYER_CANVAS_H |
---|