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