[6] | 1 | // -*- C++ -*- // |
---|
| 2 | |
---|
| 3 | #ifndef GRAPH_DISPLAYER_CANVAS_H |
---|
| 4 | #define GRAPH_DISPLAYER_CANVAS_H |
---|
| 5 | |
---|
[21] | 6 | class GraphDisplayerCanvas; |
---|
| 7 | |
---|
[53] | 8 | #include "all_include.h" |
---|
| 9 | #include "mapstorage.h" |
---|
| 10 | #include "broken_edge.h" |
---|
| 11 | #include "map_win.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: |
---|
[55] | 21 | GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *); |
---|
[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 |
---|
[62] | 26 | int changeEdgeWidth (std::string mapname, 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 |
---|
[62] | 30 | int changeEdgeColor (std::string mapname, 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 |
---|
[62] | 34 | int changeEdgeText (std::string mapname, Edge new_item=INVALID); |
---|
[28] | 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 |
---|
[62] | 38 | int changeNodeRadius (std::string mapname, Node new_item=INVALID); |
---|
[28] | 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 |
---|
[62] | 42 | int changeNodeColor (std::string mapname, Node new_item=INVALID); |
---|
[28] | 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 |
---|
[62] | 46 | int changeNodeText (std::string mapname, 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 | |
---|
[34] | 93 | ///event handler for the case when the entry widget is changed |
---|
| 94 | bool entryWidgetChangeHandler(GdkEvent*); |
---|
| 95 | |
---|
[21] | 96 | public: |
---|
[25] | 97 | ///Moves the text to new place |
---|
[30] | 98 | void textReposition(xy<double>); |
---|
[25] | 99 | ///Activates an edge belonging to a BrokenEdge |
---|
[35] | 100 | /// |
---|
| 101 | ///After we have activated an edge this way, |
---|
| 102 | ///the GDC object will know, which edge is under forming |
---|
| 103 | ///therefore it can redraw the necessarz elementy on the canvas, |
---|
| 104 | ///for example the text belonging to the \ref BrokenEdge can be |
---|
| 105 | ///redrawn (\ref textReposition). |
---|
[30] | 106 | void toggleEdgeActivity(BrokenEdge*, bool); |
---|
[25] | 107 | |
---|
| 108 | public: |
---|
[21] | 109 | ///\return the actual tool in hand |
---|
[30] | 110 | int getActualTool(); |
---|
[21] | 111 | |
---|
[53] | 112 | void drawGraph(); |
---|
| 113 | void clear(); |
---|
| 114 | |
---|
[37] | 115 | ///creates a new Nodemap |
---|
[46] | 116 | int addNewNodeMap(double,std::string); |
---|
[37] | 117 | ///creates a new Edgemap |
---|
[46] | 118 | int addNewEdgeMap(double,std::string); |
---|
[37] | 119 | |
---|
[21] | 120 | private: |
---|
[14] | 121 | ///Deletes the given element. |
---|
[62] | 122 | void deleteItem(Node); |
---|
[14] | 123 | ///Deletes the given element. |
---|
[62] | 124 | void deleteItem(Edge); |
---|
[9] | 125 | |
---|
[21] | 126 | private: |
---|
| 127 | |
---|
[6] | 128 | ///Map of nodes of graph |
---|
| 129 | Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; |
---|
| 130 | |
---|
| 131 | ///Map of edges of graph |
---|
[19] | 132 | Graph::EdgeMap<BrokenEdge *> edgesmap; |
---|
[6] | 133 | |
---|
| 134 | ///Map of texts to write on edges |
---|
| 135 | Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap; |
---|
| 136 | |
---|
[28] | 137 | ///Map of texts to write on nodes |
---|
| 138 | Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap; |
---|
| 139 | |
---|
[6] | 140 | ///Group of graphical elements of displayed_graph |
---|
| 141 | Gnome::Canvas::Group displayed_graph; |
---|
| 142 | |
---|
[32] | 143 | ///Map editor entry |
---|
| 144 | Gtk::Entry entrywidget; |
---|
| 145 | |
---|
| 146 | ///GnomeCanvas holder for entry |
---|
| 147 | Gnome::Canvas::Widget * canvasentrywidget; |
---|
| 148 | |
---|
[6] | 149 | ///Here we store the maps that can be displayed through properties. |
---|
[40] | 150 | MapStorage & mapstorage; |
---|
[6] | 151 | |
---|
| 152 | ///Indicates whether the button of mouse is pressed or not |
---|
[20] | 153 | int isbutton; |
---|
[6] | 154 | |
---|
[21] | 155 | ///Stores the actual tool in hand |
---|
| 156 | int actual_tool; |
---|
| 157 | |
---|
[6] | 158 | ///At this location was the mousebutton pressed. |
---|
| 159 | ///It helps to calculate the distance of dragging. |
---|
| 160 | double clicked_x, clicked_y; |
---|
| 161 | |
---|
| 162 | ///Remembers which Gnome::Canvas::Item was pressed. |
---|
| 163 | ///this variable is needed, because |
---|
| 164 | ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault |
---|
| 165 | ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution |
---|
[11] | 166 | Gnome::Canvas::Item * active_item, * target_item; |
---|
[62] | 167 | Node active_node; |
---|
| 168 | Edge active_edge; |
---|
| 169 | Edge forming_edge; |
---|
[35] | 170 | |
---|
| 171 | std::string nodemap_to_edit, edgemap_to_edit; |
---|
[6] | 172 | |
---|
| 173 | static const int zoom_step = 5; |
---|
[19] | 174 | |
---|
[28] | 175 | ///We need to store mapwin, to be able to ask the appropriate values for properties of new items. |
---|
[53] | 176 | MapWin & mapwin; |
---|
[28] | 177 | |
---|
[55] | 178 | ///We need to store the parent window to be able to set the focus on a given widget |
---|
| 179 | ///We will use this variable to activate the set focus on entry widget in the case of editing map values. |
---|
| 180 | Gtk::Window * parentwin; |
---|
| 181 | |
---|
[6] | 182 | }; |
---|
| 183 | |
---|
| 184 | #endif //GRAPH_DISPLAYER_CANVAS_H |
---|