graph_displayer_canvas.h
author hegyi
Fri, 17 Jun 2005 12:25:53 +0000
branchgui
changeset 21 44bb92014108
parent 20 a3bd39d50930
child 25 c45a34eaa118
permissions -rw-r--r--
Very small bug is corrected: if node creator tool is active, the small red arrows won't move, if you click on them and if you drag the newly created node... 'was hard to notice it :-)
     1 // -*- C++ -*- //
     2 
     3 #ifndef GRAPH_DISPLAYER_CANVAS_H
     4 #define GRAPH_DISPLAYER_CANVAS_H
     5 
     6 class GraphDisplayerCanvas;
     7 
     8 #include <all_include.h>
     9 #include <mapstorage.h>
    10 #include <broken_edge.h>
    11 #include <libgnomecanvasmm.h>
    12 #include <libgnomecanvasmm/polygon.h>
    13 
    14 ///This class is the canvas, on which the graph can be drawn.
    15 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
    16 {
    17   typedef Gnome::Canvas::CanvasAA Parent;
    18 
    19 public:
    20   GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
    21   virtual ~GraphDisplayerCanvas();
    22 
    23   ///Changes the linewidth attribute according to the given map.
    24   ///\param mapname is the name of the map which contains the new values
    25   int changeLineWidth (std::string mapname);
    26 
    27   ///Changes the linecolor attribute according to the given map.
    28   ///\param mapname is the name of the map which contains the new values
    29   int changeColor (std::string mapname);
    30 
    31   ///Changes the text of line attribute according to the given map.
    32   ///\param mapname is the name of the map which contains the new values
    33   int changeText (std::string mapname);
    34 
    35   ///Callback for 'ViewZoomIn' action.
    36   virtual void zoomIn();
    37   ///Callback for 'ViewZoomOut' action.
    38   virtual void zoomOut();
    39   ///Callback for 'ViewZoomFit' action.
    40   virtual void zoomFit();
    41   ///Callback for 'ViewZoom100' action.
    42   virtual void zoom100();
    43   ///Sets the scroll region of the convas to the bounding box of the graph.
    44   void updateScrollRegion();
    45 
    46   ///This function changes the tool in the graph-editor's hand
    47   void changeEditorialTool(int);
    48 
    49 protected:
    50 
    51   //maximizing, minimizing, restoring window, etc. 
    52   virtual bool on_expose_event(GdkEventExpose *);
    53 
    54 private:
    55 
    56   ///This function is responsible for the correct
    57   ///reaction of any action happened in the territory
    58   ///of the canvas
    59   bool event_handler(GdkEvent* e, Node n);
    60 
    61   ///actual event handler
    62   ///
    63   ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
    64   sigc::connection actual_handler;
    65 
    66   ///event handler for the case when move-tool is active
    67   bool move_event_handler(GdkEvent*);
    68   ///event handler for the case when create_node-tool is active
    69   bool create_node_event_handler(GdkEvent*);
    70   ///event handler for the case when create_edge-tool is active
    71   bool create_edge_event_handler(GdkEvent*);
    72   ///event handler for the case when eraser-tool is active
    73   bool eraser_event_handler(GdkEvent*);
    74   ///event handler for the case when eraser-tool is active
    75   bool edge_map_edit_event_handler(GdkEvent*);
    76 
    77 public:
    78   ///\return the actual tool in hand
    79   int get_actual_tool();
    80 
    81 private:
    82   ///Deletes the given element.
    83   void delete_item(NodeIt);
    84   ///Deletes the given element.
    85   void delete_item(EdgeIt);
    86   ///Deletes the given element.
    87   void delete_item(Graph::Edge);
    88 
    89 private:
    90 
    91   ///The graph, on which we work
    92   Graph g;
    93 
    94   ///Map of nodes of graph
    95   Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
    96 
    97   ///Map of edges of graph
    98   Graph::EdgeMap<BrokenEdge *> edgesmap;
    99 
   100   ///Map of texts to write on edges
   101   Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
   102 
   103   ///Group of graphical elements of displayed_graph
   104   Gnome::Canvas::Group displayed_graph;
   105 
   106   ///Here we store the maps that can be displayed through properties.
   107   MapStorage mapstorage;
   108 
   109   ///Indicates whether the button of mouse is pressed or not
   110   int isbutton;
   111 
   112   ///Stores the actual tool in hand
   113   int actual_tool;
   114 
   115   ///At this location was the mousebutton pressed.
   116   ///It helps to calculate the distance of dragging.
   117   double clicked_x, clicked_y;
   118 
   119   ///Remembers which Gnome::Canvas::Item was pressed.
   120   ///this variable is needed, because
   121   ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
   122   ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
   123   Gnome::Canvas::Item * active_item, * target_item;
   124   Graph::NodeIt active_node;
   125   Graph::EdgeIt active_edge;
   126 
   127   static const int zoom_step = 5;
   128 
   129 };
   130 
   131 #endif //GRAPH_DISPLAYER_CANVAS_H