// -*- C++ -*- // #ifndef GRAPH_DISPLAYER_CANVAS_H #define GRAPH_DISPLAYER_CANVAS_H class GraphDisplayerCanvas; #include #include #include #include #include ///This class is the canvas, on which the graph can be drawn. class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA { typedef Gnome::Canvas::CanvasAA Parent; public: GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &); virtual ~GraphDisplayerCanvas(); ///Changes the linewidth attribute according to the given map. ///\param mapname is the name of the map which contains the new values int changeLineWidth (std::string mapname); ///Changes the linecolor attribute according to the given map. ///\param mapname is the name of the map which contains the new values int changeColor (std::string mapname); ///Changes the text of line attribute according to the given map. ///\param mapname is the name of the map which contains the new values int changeText (std::string mapname); ///Callback for 'ViewZoomIn' action. virtual void zoomIn(); ///Callback for 'ViewZoomOut' action. virtual void zoomOut(); ///Callback for 'ViewZoomFit' action. virtual void zoomFit(); ///Callback for 'ViewZoom100' action. virtual void zoom100(); ///Sets the scroll region of the convas to the bounding box of the graph. void updateScrollRegion(); ///This function changes the tool in the graph-editor's hand void changeEditorialTool(int); protected: //maximizing, minimizing, restoring window, etc. virtual bool on_expose_event(GdkEventExpose *); private: ///This function is responsible for the correct ///reaction of any action happened in the territory ///of the canvas ///DEPRECATED!!!! bool event_handler(GdkEvent* e, Node n); ///actual event handler /// ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. sigc::connection actual_handler; ///event handler for the case when move-tool is active bool move_event_handler(GdkEvent*); ///event handler for the case when create_node-tool is active bool create_node_event_handler(GdkEvent*); ///event handler for the case when create_edge-tool is active bool create_edge_event_handler(GdkEvent*); ///event handler for the case when eraser-tool is active bool eraser_event_handler(GdkEvent*); ///event handler for the case when eraser-tool is active bool edge_map_edit_event_handler(GdkEvent*); public: ///Moves the text to new place void text_reposition(xy); ///Activates an edge belonging to a BrokenEdge void toggle_edge_activity(BrokenEdge*, bool); public: ///\return the actual tool in hand int get_actual_tool(); private: ///Deletes the given element. void delete_item(NodeIt); ///Deletes the given element. void delete_item(EdgeIt); ///Deletes the given element. void delete_item(Graph::Edge); private: ///The graph, on which we work Graph g; ///Map of nodes of graph Graph::NodeMap nodesmap; ///Map of edges of graph Graph::EdgeMap edgesmap; ///Map of texts to write on edges Graph::EdgeMap edgetextmap; ///Group of graphical elements of displayed_graph Gnome::Canvas::Group displayed_graph; ///Here we store the maps that can be displayed through properties. MapStorage mapstorage; ///Indicates whether the button of mouse is pressed or not int isbutton; ///Stores the actual tool in hand int actual_tool; ///At this location was the mousebutton pressed. ///It helps to calculate the distance of dragging. double clicked_x, clicked_y; ///Remembers which Gnome::Canvas::Item was pressed. ///this variable is needed, because ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution Gnome::Canvas::Item * active_item, * target_item; Graph::NodeIt active_node; Graph::EdgeIt active_edge; static const int zoom_step = 5; }; #endif //GRAPH_DISPLAYER_CANVAS_H