// -*- C++ -*- // #ifndef GRAPH_DISPLAYER_CANVAS_H #define GRAPH_DISPLAYER_CANVAS_H class GraphDisplayerCanvas; #include "all_include.h" #include "nbtab.h" #include #include #include ///This class is the canvas, on which the graph can be drawn. class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA { friend class BrokenEdge; friend class LoopEdge; class EdgeBase : public Gnome::Canvas::Group { protected: ///Reference to the canvas, on which the graph is drawn. ///It is needed, because some datas needed from ///graph can be accessed by this or should be sent ///as parameter, but it would be complicated GraphDisplayerCanvas& canvas; ///The edge that the class displays. ///It is needed, because some datas needed from ///graph can be accessed by this or should be sent ///as parameter, but it would be complicated Edge edge; Gnome::Canvas::Polygon arrow; void drawArrow(XY); public: EdgeBase(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&); virtual ~EdgeBase(); virtual void draw() = 0; virtual void setLineWidth(int) = 0; virtual void setFillColor(Gdk::Color) = 0; virtual Gnome::Canvas::Item * getLine() = 0; }; ///Edge displayer class ///This class is responsible for displaying edges in graph. ///The displayed edge is broken in the middle. The ///aim of this is to be able to indicate direction of edges ///and to be able to display more then one edges between the ///same source and target class BrokenEdge : public EdgeBase { private: Gnome::Canvas::Line line; ///Indicates whether the button of mouse is pressed or not at the moment. bool isbutton; ///At this location was the mousebutton pressed. Horizontal component. ///It helps to calculate the ///distance of dragging. double clicked_x; ///At this location was the mousebutton pressed. Vertical component. ///It helps to calculate the ///distance of dragging. double clicked_y; ///event handler for forming broken edges ///\param event the ///event to handle bool edgeFormerEventHandler(GdkEvent* event); public: ///Constructor of broken edge class. ///\param g the group to which the edge belongs ///\param _edge the represented edge ///\param gc the canvas BrokenEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&); ///Destructor of broken edge class ///Frees up ///reserved memory ~BrokenEdge(); ///The function that draws the edge based on collected data void draw(); void setLineWidth(int); void setFillColor(Gdk::Color); Gnome::Canvas::Item * getLine() { return (Gnome::Canvas::Item *)(&line); }; }; class LoopEdge : public EdgeBase { private: Gnome::Canvas::Ellipse line; bool edgeFormerEventHandler(GdkEvent* e); bool isbutton; public: LoopEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&); ~LoopEdge(); void draw(); void setLineWidth(int); void setFillColor(Gdk::Color); Gnome::Canvas::Item * getLine() { return (Gnome::Canvas::Item *)(&line); }; }; ///Type of canvas, on which the graph is drawn typedef Gnome::Canvas::CanvasAA Parent; public: ///Constructor ///\param nbt the tab of the window, in which the graph is displayed GraphDisplayerCanvas(NoteBookTab & nbt); ///destructor of the class virtual ~GraphDisplayerCanvas(); ///Changes the width of edge(s) according to the given map. ///\param mapname is the name of the map which contains the values to be set ///\param edge if it is given, only the width of the given edge will be set, instead of all of them. int changeEdgeWidth (std::string mapname, Edge edge=INVALID); ///Resets width of edge(s) to the default value ///\param edge if it is given, only the width of the ///given edge will be reset, instead of all of them. int resetEdgeWidth (Edge edge=INVALID); ///Changes the color of edge(s) according to the given map. ///\param mapname is the name of the map which contains the new values ///\param edge if it is given, only the color of the given edge will be set, instead of all of them. int changeEdgeColor (std::string mapname, Edge edge=INVALID); ///Resets color of edge(s) to the default value ///\param edge if it is given, only the color of the ///given edge will be reset, instead of all of them. int resetEdgeColor (Edge edge=INVALID); ///Changes the label of edge(s) according to the given map. ///\param mapname is the name of the map which contains the new values ///\param edge if it is given, only the label of the given edge will be set, instead of all of them. int changeEdgeText (std::string mapname, Edge edge=INVALID); ///Resets label of edge(s) to the default value ///\param edge if it is given, only the color of the ///given edge will be reset, instead of all of them. int resetEdgeText (Edge edge=INVALID); ///Changes the radius of node(s) according to the given map. ///\param mapname is the name of the map which contains the new values ///\param node if it is given, only the radius of the given node will be set, instead of all of them. int changeNodeRadius (std::string mapname, Node node=INVALID); ///Resets radius of node(s) to the default value ///\param node if it is given, only the radius of the ///given node will be reset, instead of all of them. int resetNodeRadius (Node node=INVALID); ///Changes the color of node(s) according to the given map. ///\param mapname is the name of the map which contains the new values ///\param node if it is given, only the color of the given node will be set, instead of all of them. int changeNodeColor (std::string mapname, Node node=INVALID); ///Resets color of node(s) to the default value ///\param node if it is given, only the color of the ///given node will be reset, instead of all of them. int resetNodeColor (Node node=INVALID); ///Changes the label of node(s) according to the given map. ///\param mapname is the name of the map which contains the new values ///\param node if it is given, only the label of the given node will be set, instead of all of them. int changeNodeText (std::string mapname, Node node=INVALID); ///Resets label of node(s) to the default value ///\param node if it is given, only the label of the ///given node will be reset, instead of all of them. int resetNodeText (Node node=INVALID); ///This function is called, when any of the displayed attributes have to be updated, or changed ///\param itisedge if true, edge property has to be changed, else node property ///\param prop the id of property that has to changed or updated void propertyChange(bool itisedge, int prop); ///updates the given property ///\param edge if it is not INVALID, only the property of the given edge will be updated, instead of all of them ///\param prop the property to update void propertyUpdate(Edge edge, int prop); ///updates the given property ///\param node if it is not INVALID, only the property of the given node will be updated, instead of all of them ///\param prop the property to update void propertyUpdate(Node node, int prop); ///updates all the property for the given edge void propertyUpdate(Edge); ///updates all the property for the given node void propertyUpdate(Node); ///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 map editor tool is active bool mapEditEventHandler(GdkEvent*); public: ///Moves the text to new place void textReposition(XY); ///Activates an edge belonging to an EdgeBase ///After we have activated an edge this way, ///the GDC object will know, which edge is under forming ///therefore it can redraw the necessary elements on the canvas, ///for example the text belonging to the \ref EdgeBase can be ///redrawn (\ref textReposition). void toggleEdgeActivity(EdgeBase*, bool); public: ///Returns the actual tool in hand int getActualTool(); ///Sets node representation settings void setView(bool, bool, double, double); ///Gets node representation settings void getView(bool &, bool &, double&, double&); ///draws the graph ///Called when opening a file. void drawGraph(); ///Clears the canvas ///It achieves this by deleting all data ///structure used to help handle the displayed graph. void clear(); ///creates a new Nodemap ///\param init initial value of the map ///\param mapname name of new map int addNewNodeMap(double init,std::string mapname); ///creates a new Edgemap ///\param init initial value of the map ///\param mapname name of new map int addNewEdgeMap(double init,std::string mapname); 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; 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, to work on it after selection Gnome::Canvas::Item * active_item; ///Remembers which Gnome::Canvas::Item was pressed. ///this variable is used at edge creation, it will ///be the secondly selected node. No local variable ///can be used for this purpose inside the function, ///because the node selected by button press, and ///the edge is created by button release. Both of ///them is different function call. Gnome::Canvas::Item * target_item; ///selected node (for any editing) Node active_node; ///selected edge (for any editing) Edge active_edge; ///the edge that is selected by clicking on the red arrow in the middle of it ///This edge is stored only for the purpose of reshape it. ///That is why it is selected in a different manner. Edge forming_edge; ///Map displayed by label can be edited. std::string nodemap_to_edit; ///Map displayed by label can be edited. std::string edgemap_to_edit; static const int zoom_step = 5; ///Is node radius autoscaled bool autoscale; ///Should we track zoomfactor changes bool zoomtrack; ///to store the zoom factor when it was "fixed" double fixed_zoom_factor; ///Node radius size double radius_size; ///Edge width double edge_width; private: ///reference to the container, in which the canvas is NoteBookTab & mytab; XY calcArrowPos(XY, XY, XY, XY, int); }; #endif //GRAPH_DISPLAYER_CANVAS_H