// -*- C++ -*- // #ifndef GRAPH_DISPLAYER_CANVAS_H #define GRAPH_DISPLAYER_CANVAS_H class GraphDisplayerCanvas; #include #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 &, MapWin *); 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 changeEdgeWidth (std::string mapname, Graph::Edge new_item=INVALID); ///Changes the linecolor attribute according to the given map. ///\param mapname is the name of the map which contains the new values int changeEdgeColor (std::string mapname, Graph::Edge new_item=INVALID); ///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 changeEdgeText (std::string mapname, Graph::Edge new_item=INVALID); ///Changes the linewidth attribute according to the given map. ///\param mapname is the name of the map which contains the new values int changeNodeRadius (std::string mapname, Graph::Node new_item=INVALID); ///Changes the linecolor attribute according to the given map. ///\param mapname is the name of the map which contains the new values int changeNodeColor (std::string mapname, Graph::Node new_item=INVALID); ///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 changeNodeText (std::string mapname, Graph::Node new_item=INVALID); ///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 eventHandler(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 moveEventHandler(GdkEvent*); ///event handler for the case when create_node-tool is active bool createNodeEventHandler(GdkEvent*); ///event handler for the case when create_edge-tool is active bool createEdgeEventHandler(GdkEvent*); ///event handler for the case when eraser-tool is active bool eraserEventHandler(GdkEvent*); ///event handler for the case when eraser-tool is active bool edgeMapEditEventHandler(GdkEvent*); public: ///Moves the text to new place void textReposition(xy); ///Activates an edge belonging to a BrokenEdge void toggleEdgeActivity(BrokenEdge*, bool); public: ///\return the actual tool in hand int getActualTool(); private: ///Deletes the given element. void deleteItem(NodeIt); ///Deletes the given element. void deleteItem(EdgeIt); ///Deletes the given element. void deleteItem(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; ///Map of texts to write on nodes Graph::NodeMap nodetextmap; ///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; ///We need to store mapwin, to be able to ask the appropriate values for properties of new items. MapWin * mapwin; }; #endif //GRAPH_DISPLAYER_CANVAS_H