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