ladanyi@1442: // -*- C++ -*- // ladanyi@1442: ladanyi@1442: #ifndef GRAPH_DISPLAYER_CANVAS_H ladanyi@1442: #define GRAPH_DISPLAYER_CANVAS_H ladanyi@1442: hegyi@1501: class GraphDisplayerCanvas; hegyi@1501: ladanyi@1606: #include "all_include.h" hegyi@1849: #include "nbtab.h" ladanyi@1442: #include ladanyi@1442: #include hegyi@1819: #include ladanyi@1442: ladanyi@1442: ///This class is the canvas, on which the graph can be drawn. ladanyi@1442: class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA ladanyi@1442: { ladanyi@1860: friend class BrokenEdge; ladanyi@1860: hegyi@1819: class BrokenEdge : public Gnome::Canvas::Line hegyi@1819: { ladanyi@1860: Edge edge; hegyi@1819: GraphDisplayerCanvas & gdc; hegyi@1819: Gnome::Canvas::Polygon * arrow; hegyi@1819: hegyi@1819: ///Indicates whether the button of mouse is pressed or not hegyi@1819: bool isbutton; hegyi@1819: hegyi@1819: ///At this location was the mousebutton pressed. hegyi@1819: ///It helps to calculate the distance of dragging. hegyi@1819: double clicked_x, clicked_y; hegyi@1819: hegyi@1819: ///event handler for forming edges hegyi@1819: bool edgeFormerEventHandler(GdkEvent*); hegyi@1819: public: ladanyi@1860: BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &); hegyi@1819: ~BrokenEdge(); ladanyi@1860: void draw(); hegyi@1819: }; ladanyi@1442: typedef Gnome::Canvas::CanvasAA Parent; ladanyi@1442: ladanyi@1442: public: hegyi@1849: GraphDisplayerCanvas(NoteBookTab &); ladanyi@1442: virtual ~GraphDisplayerCanvas(); ladanyi@1442: ladanyi@1442: ///Changes the linewidth attribute according to the given map. ladanyi@1442: ///\param mapname is the name of the map which contains the new values alpar@1643: int changeEdgeWidth (std::string mapname, Edge new_item=INVALID); hegyi@1731: int resetEdgeWidth (Edge new_item=INVALID); ladanyi@1442: ladanyi@1442: ///Changes the linecolor attribute according to the given map. ladanyi@1442: ///\param mapname is the name of the map which contains the new values alpar@1643: int changeEdgeColor (std::string mapname, Edge new_item=INVALID); hegyi@1731: int resetEdgeColor (Edge new_item=INVALID); ladanyi@1442: ladanyi@1442: ///Changes the text of line attribute according to the given map. ladanyi@1442: ///\param mapname is the name of the map which contains the new values alpar@1643: int changeEdgeText (std::string mapname, Edge new_item=INVALID); hegyi@1731: int resetEdgeText (Edge new_item=INVALID); hegyi@1512: hegyi@1512: ///Changes the linewidth attribute according to the given map. hegyi@1512: ///\param mapname is the name of the map which contains the new values alpar@1643: int changeNodeRadius (std::string mapname, Node new_item=INVALID); hegyi@1731: int resetNodeRadius (Node new_item=INVALID); hegyi@1512: hegyi@1512: ///Changes the linecolor attribute according to the given map. hegyi@1512: ///\param mapname is the name of the map which contains the new values alpar@1643: int changeNodeColor (std::string mapname, Node new_item=INVALID); hegyi@1731: int resetNodeColor (Node new_item=INVALID); hegyi@1512: hegyi@1512: ///Changes the text of line attribute according to the given map. hegyi@1512: ///\param mapname is the name of the map which contains the new values alpar@1643: int changeNodeText (std::string mapname, Node new_item=INVALID); hegyi@1731: int resetNodeText (Node new_item=INVALID); ladanyi@1442: hegyi@1837: void propertyChange(bool, int); hegyi@1837: void propertyUpdate(Edge, int, int dummy=0); hegyi@1837: void propertyUpdate(Node, int, int dummy=0); hegyi@1837: hegyi@1837: void propertyUpdate(Edge); hegyi@1837: void propertyUpdate(Node); hegyi@1837: ladanyi@1442: ///Callback for 'ViewZoomIn' action. ladanyi@1442: virtual void zoomIn(); ladanyi@1442: ///Callback for 'ViewZoomOut' action. ladanyi@1442: virtual void zoomOut(); ladanyi@1442: ///Callback for 'ViewZoomFit' action. ladanyi@1442: virtual void zoomFit(); ladanyi@1442: ///Callback for 'ViewZoom100' action. ladanyi@1442: virtual void zoom100(); ladanyi@1442: ///Sets the scroll region of the convas to the bounding box of the graph. ladanyi@1442: void updateScrollRegion(); ladanyi@1442: hegyi@1468: ///This function changes the tool in the graph-editor's hand hegyi@1468: void changeEditorialTool(int); hegyi@1468: ladanyi@1442: protected: ladanyi@1442: ladanyi@1442: //maximizing, minimizing, restoring window, etc. ladanyi@1442: virtual bool on_expose_event(GdkEventExpose *); ladanyi@1442: ladanyi@1442: private: ladanyi@1442: ladanyi@1442: ///This function is responsible for the correct ladanyi@1442: ///reaction of any action happened in the territory ladanyi@1442: ///of the canvas hegyi@1505: ///DEPRECATED!!!! hegyi@1524: bool eventHandler(GdkEvent* e, Node n); ladanyi@1442: hegyi@1468: ///actual event handler hegyi@1468: /// hegyi@1468: ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. hegyi@1468: sigc::connection actual_handler; hegyi@1468: hegyi@1468: ///event handler for the case when move-tool is active hegyi@1524: bool moveEventHandler(GdkEvent*); hegyi@1468: ///event handler for the case when create_node-tool is active hegyi@1524: bool createNodeEventHandler(GdkEvent*); hegyi@1468: ///event handler for the case when create_edge-tool is active hegyi@1524: bool createEdgeEventHandler(GdkEvent*); hegyi@1485: ///event handler for the case when eraser-tool is active hegyi@1524: bool eraserEventHandler(GdkEvent*); hegyi@1550: ///event handler for the case when edge map editor tool is active hegyi@1524: bool edgeMapEditEventHandler(GdkEvent*); hegyi@1550: ///event handler for the case when node map editor tool is active hegyi@1550: bool nodeMapEditEventHandler(GdkEvent*); hegyi@1485: hegyi@1501: public: hegyi@1505: ///Moves the text to new place hegyi@1524: void textReposition(xy); hegyi@1505: ///Activates an edge belonging to a BrokenEdge hegyi@1579: /// hegyi@1579: ///After we have activated an edge this way, hegyi@1579: ///the GDC object will know, which edge is under forming hegyi@1579: ///therefore it can redraw the necessarz elementy on the canvas, hegyi@1579: ///for example the text belonging to the \ref BrokenEdge can be hegyi@1579: ///redrawn (\ref textReposition). hegyi@1524: void toggleEdgeActivity(BrokenEdge*, bool); hegyi@1505: hegyi@1505: public: hegyi@1501: ///\return the actual tool in hand hegyi@1524: int getActualTool(); hegyi@1501: ladanyi@1606: void drawGraph(); ladanyi@1606: void clear(); ladanyi@1606: hegyi@1585: ///creates a new Nodemap hegyi@1597: int addNewNodeMap(double,std::string); hegyi@1585: ///creates a new Edgemap hegyi@1597: int addNewEdgeMap(double,std::string); hegyi@1585: hegyi@1501: private: hegyi@1486: ///Deletes the given element. alpar@1643: void deleteItem(Node); hegyi@1486: ///Deletes the given element. alpar@1643: void deleteItem(Edge); hegyi@1468: hegyi@1501: private: hegyi@1501: ladanyi@1442: ///Map of nodes of graph ladanyi@1442: Graph::NodeMap nodesmap; ladanyi@1442: ladanyi@1442: ///Map of edges of graph hegyi@1499: Graph::EdgeMap edgesmap; ladanyi@1442: ladanyi@1442: ///Map of texts to write on edges ladanyi@1442: Graph::EdgeMap edgetextmap; ladanyi@1442: hegyi@1512: ///Map of texts to write on nodes hegyi@1512: Graph::NodeMap nodetextmap; hegyi@1512: ladanyi@1442: ///Group of graphical elements of displayed_graph ladanyi@1442: Gnome::Canvas::Group displayed_graph; ladanyi@1442: hegyi@1814: private: ladanyi@1442: ///Indicates whether the button of mouse is pressed or not hegyi@1500: int isbutton; ladanyi@1442: hegyi@1501: ///Stores the actual tool in hand hegyi@1501: int actual_tool; hegyi@1501: ladanyi@1442: ///At this location was the mousebutton pressed. ladanyi@1442: ///It helps to calculate the distance of dragging. ladanyi@1442: double clicked_x, clicked_y; ladanyi@1442: ladanyi@1442: ///Remembers which Gnome::Canvas::Item was pressed. ladanyi@1442: ///this variable is needed, because ladanyi@1442: ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault ladanyi@1442: ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution hegyi@1474: Gnome::Canvas::Item * active_item, * target_item; alpar@1643: Node active_node; alpar@1643: Edge active_edge; alpar@1643: Edge forming_edge; hegyi@1579: hegyi@1579: std::string nodemap_to_edit, edgemap_to_edit; ladanyi@1442: ladanyi@1442: static const int zoom_step = 5; hegyi@1499: hegyi@1814: private: hegyi@1814: hegyi@1837: ///reference to the parent window hegyi@1849: NoteBookTab & mytab; hegyi@1614: ladanyi@1860: XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool); ladanyi@1442: }; ladanyi@1442: ladanyi@1442: #endif //GRAPH_DISPLAYER_CANVAS_H