3 #ifndef GRAPH_DISPLAYER_CANVAS_H
4 #define GRAPH_DISPLAYER_CANVAS_H
6 class GraphDisplayerCanvas;
8 #include "all_include.h"
10 #include <libgnomecanvasmm.h>
11 #include <libgnomecanvasmm/polygon.h>
14 ///This class is the canvas, on which the graph can be drawn.
15 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
17 friend class BrokenEdge;
19 class BrokenEdge : public Gnome::Canvas::Line
22 GraphDisplayerCanvas & gdc;
23 Gnome::Canvas::Polygon * arrow;
25 ///Indicates whether the button of mouse is pressed or not
28 ///At this location was the mousebutton pressed.
29 ///It helps to calculate the distance of dragging.
30 double clicked_x, clicked_y;
32 ///event handler for forming edges
33 bool edgeFormerEventHandler(GdkEvent*);
35 BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &);
39 typedef Gnome::Canvas::CanvasAA Parent;
42 GraphDisplayerCanvas(NoteBookTab &);
43 virtual ~GraphDisplayerCanvas();
45 ///Changes the linewidth attribute according to the given map.
46 ///\param mapname is the name of the map which contains the new values
47 int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
48 int resetEdgeWidth (Edge new_item=INVALID);
50 ///Changes the linecolor attribute according to the given map.
51 ///\param mapname is the name of the map which contains the new values
52 int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
53 int resetEdgeColor (Edge new_item=INVALID);
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
57 int changeEdgeText (std::string mapname, Edge new_item=INVALID);
58 int resetEdgeText (Edge new_item=INVALID);
60 ///Changes the linewidth attribute according to the given map.
61 ///\param mapname is the name of the map which contains the new values
62 int changeNodeRadius (std::string mapname, Node new_item=INVALID);
63 int resetNodeRadius (Node new_item=INVALID);
65 ///Changes the linecolor attribute according to the given map.
66 ///\param mapname is the name of the map which contains the new values
67 int changeNodeColor (std::string mapname, Node new_item=INVALID);
68 int resetNodeColor (Node new_item=INVALID);
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
72 int changeNodeText (std::string mapname, Node new_item=INVALID);
73 int resetNodeText (Node new_item=INVALID);
75 void propertyChange(bool, int);
76 void propertyUpdate(Edge, int, int dummy=0);
77 void propertyUpdate(Node, int, int dummy=0);
79 void propertyUpdate(Edge);
80 void propertyUpdate(Node);
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();
93 ///This function changes the tool in the graph-editor's hand
94 void changeEditorialTool(int);
98 //maximizing, minimizing, restoring window, etc.
99 virtual bool on_expose_event(GdkEventExpose *);
103 ///This function is responsible for the correct
104 ///reaction of any action happened in the territory
107 bool eventHandler(GdkEvent* e, Node n);
109 ///actual event handler
111 ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
112 sigc::connection actual_handler;
114 ///event handler for the case when move-tool is active
115 bool moveEventHandler(GdkEvent*);
116 ///event handler for the case when create_node-tool is active
117 bool createNodeEventHandler(GdkEvent*);
118 ///event handler for the case when create_edge-tool is active
119 bool createEdgeEventHandler(GdkEvent*);
120 ///event handler for the case when eraser-tool is active
121 bool eraserEventHandler(GdkEvent*);
122 ///event handler for the case when edge map editor tool is active
123 bool edgeMapEditEventHandler(GdkEvent*);
124 ///event handler for the case when node map editor tool is active
125 bool nodeMapEditEventHandler(GdkEvent*);
128 ///Moves the text to new place
129 void textReposition(xy<double>);
130 ///Activates an edge belonging to a BrokenEdge
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).
137 void toggleEdgeActivity(BrokenEdge*, bool);
140 ///\return the actual tool in hand
146 ///creates a new Nodemap
147 int addNewNodeMap(double,std::string);
148 ///creates a new Edgemap
149 int addNewEdgeMap(double,std::string);
152 ///Deletes the given element.
153 void deleteItem(Node);
154 ///Deletes the given element.
155 void deleteItem(Edge);
159 ///Map of nodes of graph
160 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
162 ///Map of edges of graph
163 Graph::EdgeMap<BrokenEdge *> edgesmap;
165 ///Map of texts to write on edges
166 Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
168 ///Map of texts to write on nodes
169 Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
171 ///Group of graphical elements of displayed_graph
172 Gnome::Canvas::Group displayed_graph;
175 ///Indicates whether the button of mouse is pressed or not
178 ///Stores the actual tool in hand
181 ///At this location was the mousebutton pressed.
182 ///It helps to calculate the distance of dragging.
183 double clicked_x, clicked_y;
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
189 Gnome::Canvas::Item * active_item, * target_item;
194 std::string nodemap_to_edit, edgemap_to_edit;
196 static const int zoom_step = 5;
200 ///reference to the parent window
203 XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);
206 #endif //GRAPH_DISPLAYER_CANVAS_H