// -*- C++ -*- // #ifndef GRAPH_DISPLAYER_CANVAS_H #define GRAPH_DISPLAYER_CANVAS_H class GraphDisplayerCanvas; #include "all_include.h" #include "mapstorage.h" #include "map_win.h" #include #include #include ///This class is the canvas, on which the graph can be drawn. class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA { class BrokenEdge : public Gnome::Canvas::Line { GraphDisplayerCanvas & gdc; Gnome::Canvas::Polygon * arrow; Gnome::Art::Point * my_points; ///Indicates whether the button of mouse is pressed or not bool isbutton; ///At this location was the mousebutton pressed. ///It helps to calculate the distance of dragging. double clicked_x, clicked_y; ///event handler for forming edges bool edgeFormerEventHandler(GdkEvent*); public: BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &); ~BrokenEdge(); void setPoints(Gnome::Canvas::Points, bool move=false); xy getArrowPos(); }; typedef Gnome::Canvas::CanvasAA Parent; public: GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *); 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, Edge new_item=INVALID); int resetEdgeWidth (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, Edge new_item=INVALID); int resetEdgeColor (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, Edge new_item=INVALID); int resetEdgeText (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, Node new_item=INVALID); int resetNodeRadius (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, Node new_item=INVALID); int resetNodeColor (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, Node new_item=INVALID); int resetNodeText (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 edge map editor tool is active bool edgeMapEditEventHandler(GdkEvent*); ///event handler for the case when node map editor tool is active bool nodeMapEditEventHandler(GdkEvent*); public: ///Moves the text to new place void textReposition(xy); ///Activates an edge belonging to a BrokenEdge /// ///After we have activated an edge this way, ///the GDC object will know, which edge is under forming ///therefore it can redraw the necessarz elementy on the canvas, ///for example the text belonging to the \ref BrokenEdge can be ///redrawn (\ref textReposition). void toggleEdgeActivity(BrokenEdge*, bool); public: ///\return the actual tool in hand int getActualTool(); void drawGraph(); void clear(); ///creates a new Nodemap int addNewNodeMap(double,std::string); ///creates a new Edgemap int addNewEdgeMap(double,std::string); private: ///Deletes the given element. void deleteItem(Node); ///Deletes the given element. void deleteItem(Edge); private: ///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; public: ///Here we store the maps that can be displayed through properties. MapStorage & mapstorage; private: ///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; Node active_node; Edge active_edge; Edge forming_edge; std::string nodemap_to_edit, edgemap_to_edit; static const int zoom_step = 5; public: ///We need to store mapwin, to be able to ask the appropriate values for properties of new items. MapWin & mapwin; private: ///pointer to the parent window Gtk::Window * parentwin; }; #endif //GRAPH_DISPLAYER_CANVAS_H