[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" |
---|
[1849] | 9 | #include "nbtab.h" |
---|
[1442] | 10 | #include <libgnomecanvasmm.h> |
---|
| 11 | #include <libgnomecanvasmm/polygon.h> |
---|
[1819] | 12 | #include <lemon/xy.h> |
---|
[1442] | 13 | |
---|
| 14 | ///This class is the canvas, on which the graph can be drawn. |
---|
| 15 | class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA |
---|
| 16 | { |
---|
[1860] | 17 | friend class BrokenEdge; |
---|
| 18 | |
---|
[1819] | 19 | class BrokenEdge : public Gnome::Canvas::Line |
---|
| 20 | { |
---|
[1860] | 21 | Edge edge; |
---|
[1819] | 22 | GraphDisplayerCanvas & gdc; |
---|
| 23 | Gnome::Canvas::Polygon * arrow; |
---|
| 24 | |
---|
| 25 | ///Indicates whether the button of mouse is pressed or not |
---|
| 26 | bool isbutton; |
---|
| 27 | |
---|
| 28 | ///At this location was the mousebutton pressed. |
---|
| 29 | ///It helps to calculate the distance of dragging. |
---|
| 30 | double clicked_x, clicked_y; |
---|
| 31 | |
---|
| 32 | ///event handler for forming edges |
---|
| 33 | bool edgeFormerEventHandler(GdkEvent*); |
---|
| 34 | public: |
---|
[1860] | 35 | BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &); |
---|
[1819] | 36 | ~BrokenEdge(); |
---|
[1860] | 37 | void draw(); |
---|
[1819] | 38 | }; |
---|
[1442] | 39 | typedef Gnome::Canvas::CanvasAA Parent; |
---|
| 40 | |
---|
| 41 | public: |
---|
[1849] | 42 | GraphDisplayerCanvas(NoteBookTab &); |
---|
[1442] | 43 | virtual ~GraphDisplayerCanvas(); |
---|
| 44 | |
---|
| 45 | ///Changes the linewidth attribute according to the given map. |
---|
| 46 | ///\param mapname is the name of the map which contains the new values |
---|
[1643] | 47 | int changeEdgeWidth (std::string mapname, Edge new_item=INVALID); |
---|
[1731] | 48 | int resetEdgeWidth (Edge new_item=INVALID); |
---|
[1442] | 49 | |
---|
| 50 | ///Changes the linecolor attribute according to the given map. |
---|
| 51 | ///\param mapname is the name of the map which contains the new values |
---|
[1643] | 52 | int changeEdgeColor (std::string mapname, Edge new_item=INVALID); |
---|
[1731] | 53 | int resetEdgeColor (Edge new_item=INVALID); |
---|
[1442] | 54 | |
---|
| 55 | ///Changes the text of line attribute according to the given map. |
---|
| 56 | ///\param mapname is the name of the map which contains the new values |
---|
[1643] | 57 | int changeEdgeText (std::string mapname, Edge new_item=INVALID); |
---|
[1731] | 58 | int resetEdgeText (Edge new_item=INVALID); |
---|
[1512] | 59 | |
---|
| 60 | ///Changes the linewidth attribute according to the given map. |
---|
| 61 | ///\param mapname is the name of the map which contains the new values |
---|
[1643] | 62 | int changeNodeRadius (std::string mapname, Node new_item=INVALID); |
---|
[1731] | 63 | int resetNodeRadius (Node new_item=INVALID); |
---|
[1512] | 64 | |
---|
| 65 | ///Changes the linecolor attribute according to the given map. |
---|
| 66 | ///\param mapname is the name of the map which contains the new values |
---|
[1643] | 67 | int changeNodeColor (std::string mapname, Node new_item=INVALID); |
---|
[1731] | 68 | int resetNodeColor (Node new_item=INVALID); |
---|
[1512] | 69 | |
---|
| 70 | ///Changes the text of line attribute according to the given map. |
---|
| 71 | ///\param mapname is the name of the map which contains the new values |
---|
[1643] | 72 | int changeNodeText (std::string mapname, Node new_item=INVALID); |
---|
[1731] | 73 | int resetNodeText (Node new_item=INVALID); |
---|
[1442] | 74 | |
---|
[1837] | 75 | void propertyChange(bool, int); |
---|
| 76 | void propertyUpdate(Edge, int, int dummy=0); |
---|
| 77 | void propertyUpdate(Node, int, int dummy=0); |
---|
| 78 | |
---|
| 79 | void propertyUpdate(Edge); |
---|
| 80 | void propertyUpdate(Node); |
---|
| 81 | |
---|
[1442] | 82 | ///Callback for 'ViewZoomIn' action. |
---|
| 83 | virtual void zoomIn(); |
---|
| 84 | ///Callback for 'ViewZoomOut' action. |
---|
| 85 | virtual void zoomOut(); |
---|
| 86 | ///Callback for 'ViewZoomFit' action. |
---|
| 87 | virtual void zoomFit(); |
---|
| 88 | ///Callback for 'ViewZoom100' action. |
---|
| 89 | virtual void zoom100(); |
---|
| 90 | ///Sets the scroll region of the convas to the bounding box of the graph. |
---|
| 91 | void updateScrollRegion(); |
---|
| 92 | |
---|
[1468] | 93 | ///This function changes the tool in the graph-editor's hand |
---|
| 94 | void changeEditorialTool(int); |
---|
| 95 | |
---|
[1442] | 96 | protected: |
---|
| 97 | |
---|
| 98 | //maximizing, minimizing, restoring window, etc. |
---|
| 99 | virtual bool on_expose_event(GdkEventExpose *); |
---|
| 100 | |
---|
| 101 | private: |
---|
| 102 | |
---|
| 103 | ///This function is responsible for the correct |
---|
| 104 | ///reaction of any action happened in the territory |
---|
| 105 | ///of the canvas |
---|
[1505] | 106 | ///DEPRECATED!!!! |
---|
[1524] | 107 | bool eventHandler(GdkEvent* e, Node n); |
---|
[1442] | 108 | |
---|
[1468] | 109 | ///actual event handler |
---|
| 110 | /// |
---|
| 111 | ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. |
---|
| 112 | sigc::connection actual_handler; |
---|
| 113 | |
---|
| 114 | ///event handler for the case when move-tool is active |
---|
[1524] | 115 | bool moveEventHandler(GdkEvent*); |
---|
[1468] | 116 | ///event handler for the case when create_node-tool is active |
---|
[1524] | 117 | bool createNodeEventHandler(GdkEvent*); |
---|
[1468] | 118 | ///event handler for the case when create_edge-tool is active |
---|
[1524] | 119 | bool createEdgeEventHandler(GdkEvent*); |
---|
[1485] | 120 | ///event handler for the case when eraser-tool is active |
---|
[1524] | 121 | bool eraserEventHandler(GdkEvent*); |
---|
[1550] | 122 | ///event handler for the case when edge map editor tool is active |
---|
[1524] | 123 | bool edgeMapEditEventHandler(GdkEvent*); |
---|
[1550] | 124 | ///event handler for the case when node map editor tool is active |
---|
| 125 | bool nodeMapEditEventHandler(GdkEvent*); |
---|
[1485] | 126 | |
---|
[1501] | 127 | public: |
---|
[1505] | 128 | ///Moves the text to new place |
---|
[1524] | 129 | void textReposition(xy<double>); |
---|
[1505] | 130 | ///Activates an edge belonging to a BrokenEdge |
---|
[1579] | 131 | /// |
---|
| 132 | ///After we have activated an edge this way, |
---|
| 133 | ///the GDC object will know, which edge is under forming |
---|
| 134 | ///therefore it can redraw the necessarz elementy on the canvas, |
---|
| 135 | ///for example the text belonging to the \ref BrokenEdge can be |
---|
| 136 | ///redrawn (\ref textReposition). |
---|
[1524] | 137 | void toggleEdgeActivity(BrokenEdge*, bool); |
---|
[1505] | 138 | |
---|
| 139 | public: |
---|
[1501] | 140 | ///\return the actual tool in hand |
---|
[1524] | 141 | int getActualTool(); |
---|
[1501] | 142 | |
---|
[1606] | 143 | void drawGraph(); |
---|
| 144 | void clear(); |
---|
| 145 | |
---|
[1585] | 146 | ///creates a new Nodemap |
---|
[1597] | 147 | int addNewNodeMap(double,std::string); |
---|
[1585] | 148 | ///creates a new Edgemap |
---|
[1597] | 149 | int addNewEdgeMap(double,std::string); |
---|
[1585] | 150 | |
---|
[1501] | 151 | private: |
---|
[1486] | 152 | ///Deletes the given element. |
---|
[1643] | 153 | void deleteItem(Node); |
---|
[1486] | 154 | ///Deletes the given element. |
---|
[1643] | 155 | void deleteItem(Edge); |
---|
[1468] | 156 | |
---|
[1501] | 157 | private: |
---|
| 158 | |
---|
[1442] | 159 | ///Map of nodes of graph |
---|
| 160 | Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; |
---|
| 161 | |
---|
| 162 | ///Map of edges of graph |
---|
[1499] | 163 | Graph::EdgeMap<BrokenEdge *> edgesmap; |
---|
[1442] | 164 | |
---|
| 165 | ///Map of texts to write on edges |
---|
| 166 | Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap; |
---|
| 167 | |
---|
[1512] | 168 | ///Map of texts to write on nodes |
---|
| 169 | Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap; |
---|
| 170 | |
---|
[1442] | 171 | ///Group of graphical elements of displayed_graph |
---|
| 172 | Gnome::Canvas::Group displayed_graph; |
---|
| 173 | |
---|
[1814] | 174 | private: |
---|
[1442] | 175 | ///Indicates whether the button of mouse is pressed or not |
---|
[1500] | 176 | int isbutton; |
---|
[1442] | 177 | |
---|
[1501] | 178 | ///Stores the actual tool in hand |
---|
| 179 | int actual_tool; |
---|
| 180 | |
---|
[1442] | 181 | ///At this location was the mousebutton pressed. |
---|
| 182 | ///It helps to calculate the distance of dragging. |
---|
| 183 | double clicked_x, clicked_y; |
---|
| 184 | |
---|
| 185 | ///Remembers which Gnome::Canvas::Item was pressed. |
---|
| 186 | ///this variable is needed, because |
---|
| 187 | ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault |
---|
| 188 | ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution |
---|
[1474] | 189 | Gnome::Canvas::Item * active_item, * target_item; |
---|
[1643] | 190 | Node active_node; |
---|
| 191 | Edge active_edge; |
---|
| 192 | Edge forming_edge; |
---|
[1579] | 193 | |
---|
| 194 | std::string nodemap_to_edit, edgemap_to_edit; |
---|
[1442] | 195 | |
---|
| 196 | static const int zoom_step = 5; |
---|
[1499] | 197 | |
---|
[1814] | 198 | private: |
---|
| 199 | |
---|
[1837] | 200 | ///reference to the parent window |
---|
[1849] | 201 | NoteBookTab & mytab; |
---|
[1614] | 202 | |
---|
[1860] | 203 | XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool); |
---|
[1442] | 204 | }; |
---|
| 205 | |
---|
| 206 | #endif //GRAPH_DISPLAYER_CANVAS_H |
---|