[1442] | 1 | // -*- C++ -*- // |
---|
| 2 | |
---|
| 3 | #ifndef GRAPH_DISPLAYER_CANVAS_H |
---|
| 4 | #define GRAPH_DISPLAYER_CANVAS_H |
---|
| 5 | |
---|
[1501] | 6 | class GraphDisplayerCanvas; |
---|
| 7 | |
---|
[1606] | 8 | #include "all_include.h" |
---|
| 9 | #include "mapstorage.h" |
---|
| 10 | #include "broken_edge.h" |
---|
| 11 | #include "map_win.h" |
---|
[1442] | 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: |
---|
[1614] | 21 | GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *); |
---|
[1442] | 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 |
---|
[1643] | 26 | int changeEdgeWidth (std::string mapname, Edge new_item=INVALID); |
---|
[1442] | 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 |
---|
[1643] | 30 | int changeEdgeColor (std::string mapname, Edge new_item=INVALID); |
---|
[1442] | 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 |
---|
[1643] | 34 | int changeEdgeText (std::string mapname, Edge new_item=INVALID); |
---|
[1512] | 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 |
---|
[1643] | 38 | int changeNodeRadius (std::string mapname, Node new_item=INVALID); |
---|
[1512] | 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 |
---|
[1643] | 42 | int changeNodeColor (std::string mapname, Node new_item=INVALID); |
---|
[1512] | 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 |
---|
[1643] | 46 | int changeNodeText (std::string mapname, Node new_item=INVALID); |
---|
[1442] | 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 | |
---|
[1468] | 59 | ///This function changes the tool in the graph-editor's hand |
---|
| 60 | void changeEditorialTool(int); |
---|
| 61 | |
---|
[1442] | 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 |
---|
[1505] | 72 | ///DEPRECATED!!!! |
---|
[1524] | 73 | bool eventHandler(GdkEvent* e, Node n); |
---|
[1442] | 74 | |
---|
[1468] | 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 |
---|
[1524] | 81 | bool moveEventHandler(GdkEvent*); |
---|
[1468] | 82 | ///event handler for the case when create_node-tool is active |
---|
[1524] | 83 | bool createNodeEventHandler(GdkEvent*); |
---|
[1468] | 84 | ///event handler for the case when create_edge-tool is active |
---|
[1524] | 85 | bool createEdgeEventHandler(GdkEvent*); |
---|
[1485] | 86 | ///event handler for the case when eraser-tool is active |
---|
[1524] | 87 | bool eraserEventHandler(GdkEvent*); |
---|
[1550] | 88 | ///event handler for the case when edge map editor tool is active |
---|
[1524] | 89 | bool edgeMapEditEventHandler(GdkEvent*); |
---|
[1550] | 90 | ///event handler for the case when node map editor tool is active |
---|
| 91 | bool nodeMapEditEventHandler(GdkEvent*); |
---|
[1485] | 92 | |
---|
[1501] | 93 | public: |
---|
[1505] | 94 | ///Moves the text to new place |
---|
[1524] | 95 | void textReposition(xy<double>); |
---|
[1505] | 96 | ///Activates an edge belonging to a BrokenEdge |
---|
[1579] | 97 | /// |
---|
| 98 | ///After we have activated an edge this way, |
---|
| 99 | ///the GDC object will know, which edge is under forming |
---|
| 100 | ///therefore it can redraw the necessarz elementy on the canvas, |
---|
| 101 | ///for example the text belonging to the \ref BrokenEdge can be |
---|
| 102 | ///redrawn (\ref textReposition). |
---|
[1524] | 103 | void toggleEdgeActivity(BrokenEdge*, bool); |
---|
[1505] | 104 | |
---|
| 105 | public: |
---|
[1501] | 106 | ///\return the actual tool in hand |
---|
[1524] | 107 | int getActualTool(); |
---|
[1501] | 108 | |
---|
[1606] | 109 | void drawGraph(); |
---|
| 110 | void clear(); |
---|
| 111 | |
---|
[1585] | 112 | ///creates a new Nodemap |
---|
[1597] | 113 | int addNewNodeMap(double,std::string); |
---|
[1585] | 114 | ///creates a new Edgemap |
---|
[1597] | 115 | int addNewEdgeMap(double,std::string); |
---|
[1585] | 116 | |
---|
[1501] | 117 | private: |
---|
[1486] | 118 | ///Deletes the given element. |
---|
[1643] | 119 | void deleteItem(Node); |
---|
[1486] | 120 | ///Deletes the given element. |
---|
[1643] | 121 | void deleteItem(Edge); |
---|
[1468] | 122 | |
---|
[1501] | 123 | private: |
---|
| 124 | |
---|
[1442] | 125 | ///Map of nodes of graph |
---|
| 126 | Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; |
---|
| 127 | |
---|
| 128 | ///Map of edges of graph |
---|
[1499] | 129 | Graph::EdgeMap<BrokenEdge *> edgesmap; |
---|
[1442] | 130 | |
---|
| 131 | ///Map of texts to write on edges |
---|
| 132 | Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap; |
---|
| 133 | |
---|
[1512] | 134 | ///Map of texts to write on nodes |
---|
| 135 | Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap; |
---|
| 136 | |
---|
[1442] | 137 | ///Group of graphical elements of displayed_graph |
---|
| 138 | Gnome::Canvas::Group displayed_graph; |
---|
| 139 | |
---|
| 140 | ///Here we store the maps that can be displayed through properties. |
---|
[1589] | 141 | MapStorage & mapstorage; |
---|
[1442] | 142 | |
---|
| 143 | ///Indicates whether the button of mouse is pressed or not |
---|
[1500] | 144 | int isbutton; |
---|
[1442] | 145 | |
---|
[1501] | 146 | ///Stores the actual tool in hand |
---|
| 147 | int actual_tool; |
---|
| 148 | |
---|
[1442] | 149 | ///At this location was the mousebutton pressed. |
---|
| 150 | ///It helps to calculate the distance of dragging. |
---|
| 151 | double clicked_x, clicked_y; |
---|
| 152 | |
---|
| 153 | ///Remembers which Gnome::Canvas::Item was pressed. |
---|
| 154 | ///this variable is needed, because |
---|
| 155 | ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault |
---|
| 156 | ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution |
---|
[1474] | 157 | Gnome::Canvas::Item * active_item, * target_item; |
---|
[1643] | 158 | Node active_node; |
---|
| 159 | Edge active_edge; |
---|
| 160 | Edge forming_edge; |
---|
[1579] | 161 | |
---|
| 162 | std::string nodemap_to_edit, edgemap_to_edit; |
---|
[1442] | 163 | |
---|
| 164 | static const int zoom_step = 5; |
---|
[1499] | 165 | |
---|
[1512] | 166 | ///We need to store mapwin, to be able to ask the appropriate values for properties of new items. |
---|
[1606] | 167 | MapWin & mapwin; |
---|
[1512] | 168 | |
---|
[1648] | 169 | ///pointer to the parent window |
---|
[1614] | 170 | Gtk::Window * parentwin; |
---|
| 171 | |
---|
[1442] | 172 | }; |
---|
| 173 | |
---|
| 174 | #endif //GRAPH_DISPLAYER_CANVAS_H |
---|