graph_displayer_canvas.h
author hegyi
Thu, 21 Jul 2005 19:28:29 +0000
branchgui
changeset 35 79bffdf6aea2
parent 34 2cb1fc37f742
child 37 1dc5b49457c0
permissions -rw-r--r--
Edge and nodemap edition is done.
ladanyi@6
     1
// -*- C++ -*- //
ladanyi@6
     2
ladanyi@6
     3
#ifndef GRAPH_DISPLAYER_CANVAS_H
ladanyi@6
     4
#define GRAPH_DISPLAYER_CANVAS_H
ladanyi@6
     5
hegyi@21
     6
class GraphDisplayerCanvas;
hegyi@21
     7
ladanyi@6
     8
#include <all_include.h>
hegyi@28
     9
#include <map_win.h>
ladanyi@6
    10
#include <mapstorage.h>
hegyi@19
    11
#include <broken_edge.h>
ladanyi@6
    12
#include <libgnomecanvasmm.h>
ladanyi@6
    13
#include <libgnomecanvasmm/polygon.h>
ladanyi@6
    14
ladanyi@6
    15
///This class is the canvas, on which the graph can be drawn.
ladanyi@6
    16
class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
ladanyi@6
    17
{
ladanyi@6
    18
  typedef Gnome::Canvas::CanvasAA Parent;
ladanyi@6
    19
ladanyi@6
    20
public:
hegyi@28
    21
  GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &, MapWin *);
ladanyi@6
    22
  virtual ~GraphDisplayerCanvas();
ladanyi@6
    23
ladanyi@6
    24
  ///Changes the linewidth attribute according to the given map.
ladanyi@6
    25
  ///\param mapname is the name of the map which contains the new values
hegyi@28
    26
  int changeEdgeWidth (std::string mapname, Graph::Edge new_item=INVALID);
ladanyi@6
    27
ladanyi@6
    28
  ///Changes the linecolor attribute according to the given map.
ladanyi@6
    29
  ///\param mapname is the name of the map which contains the new values
hegyi@28
    30
  int changeEdgeColor (std::string mapname, Graph::Edge new_item=INVALID);
ladanyi@6
    31
ladanyi@6
    32
  ///Changes the text of line attribute according to the given map.
ladanyi@6
    33
  ///\param mapname is the name of the map which contains the new values
hegyi@28
    34
  int changeEdgeText (std::string mapname, Graph::Edge new_item=INVALID);
hegyi@28
    35
hegyi@28
    36
  ///Changes the linewidth attribute according to the given map.
hegyi@28
    37
  ///\param mapname is the name of the map which contains the new values
hegyi@28
    38
  int changeNodeRadius (std::string mapname, Graph::Node new_item=INVALID);
hegyi@28
    39
hegyi@28
    40
  ///Changes the linecolor attribute according to the given map.
hegyi@28
    41
  ///\param mapname is the name of the map which contains the new values
hegyi@28
    42
  int changeNodeColor (std::string mapname, Graph::Node new_item=INVALID);
hegyi@28
    43
hegyi@28
    44
  ///Changes the text of line attribute according to the given map.
hegyi@28
    45
  ///\param mapname is the name of the map which contains the new values
hegyi@28
    46
  int changeNodeText (std::string mapname, Graph::Node new_item=INVALID);
ladanyi@6
    47
ladanyi@6
    48
  ///Callback for 'ViewZoomIn' action.
ladanyi@6
    49
  virtual void zoomIn();
ladanyi@6
    50
  ///Callback for 'ViewZoomOut' action.
ladanyi@6
    51
  virtual void zoomOut();
ladanyi@6
    52
  ///Callback for 'ViewZoomFit' action.
ladanyi@6
    53
  virtual void zoomFit();
ladanyi@6
    54
  ///Callback for 'ViewZoom100' action.
ladanyi@6
    55
  virtual void zoom100();
ladanyi@6
    56
  ///Sets the scroll region of the convas to the bounding box of the graph.
ladanyi@6
    57
  void updateScrollRegion();
ladanyi@6
    58
hegyi@9
    59
  ///This function changes the tool in the graph-editor's hand
hegyi@9
    60
  void changeEditorialTool(int);
hegyi@9
    61
ladanyi@6
    62
protected:
ladanyi@6
    63
ladanyi@6
    64
  //maximizing, minimizing, restoring window, etc. 
ladanyi@6
    65
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@6
    66
ladanyi@6
    67
private:
ladanyi@6
    68
ladanyi@6
    69
  ///This function is responsible for the correct
ladanyi@6
    70
  ///reaction of any action happened in the territory
ladanyi@6
    71
  ///of the canvas
hegyi@25
    72
  ///DEPRECATED!!!!
hegyi@30
    73
  bool eventHandler(GdkEvent* e, Node n);
ladanyi@6
    74
hegyi@9
    75
  ///actual event handler
hegyi@9
    76
  ///
hegyi@9
    77
  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
hegyi@9
    78
  sigc::connection actual_handler;
hegyi@9
    79
hegyi@9
    80
  ///event handler for the case when move-tool is active
hegyi@30
    81
  bool moveEventHandler(GdkEvent*);
hegyi@9
    82
  ///event handler for the case when create_node-tool is active
hegyi@30
    83
  bool createNodeEventHandler(GdkEvent*);
hegyi@9
    84
  ///event handler for the case when create_edge-tool is active
hegyi@30
    85
  bool createEdgeEventHandler(GdkEvent*);
hegyi@13
    86
  ///event handler for the case when eraser-tool is active
hegyi@30
    87
  bool eraserEventHandler(GdkEvent*);
hegyi@32
    88
  ///event handler for the case when edge map editor tool is active
hegyi@30
    89
  bool edgeMapEditEventHandler(GdkEvent*);
hegyi@32
    90
  ///event handler for the case when node map editor tool is active
hegyi@32
    91
  bool nodeMapEditEventHandler(GdkEvent*);
hegyi@13
    92
hegyi@34
    93
  ///event handler for the case when the entry widget is changed
hegyi@34
    94
  bool entryWidgetChangeHandler(GdkEvent*);
hegyi@34
    95
hegyi@21
    96
public:
hegyi@25
    97
  ///Moves the text to new place
hegyi@30
    98
  void textReposition(xy<double>);
hegyi@25
    99
  ///Activates an edge belonging to a BrokenEdge
hegyi@35
   100
  ///
hegyi@35
   101
  ///After we have activated an edge this way,
hegyi@35
   102
  ///the GDC object will know, which edge is under forming
hegyi@35
   103
  ///therefore it can redraw the necessarz elementy on the canvas,
hegyi@35
   104
  ///for example the text belonging to the \ref BrokenEdge can be
hegyi@35
   105
  ///redrawn (\ref textReposition).
hegyi@30
   106
  void toggleEdgeActivity(BrokenEdge*, bool);
hegyi@25
   107
hegyi@25
   108
public:
hegyi@21
   109
  ///\return the actual tool in hand
hegyi@30
   110
  int getActualTool();
hegyi@21
   111
hegyi@21
   112
private:
hegyi@14
   113
  ///Deletes the given element.
hegyi@30
   114
  void deleteItem(NodeIt);
hegyi@14
   115
  ///Deletes the given element.
hegyi@30
   116
  void deleteItem(EdgeIt);
hegyi@16
   117
  ///Deletes the given element.
hegyi@30
   118
  void deleteItem(Graph::Edge);
hegyi@9
   119
hegyi@21
   120
private:
hegyi@21
   121
ladanyi@6
   122
  ///The graph, on which we work
hegyi@30
   123
  Graph & g;
ladanyi@6
   124
ladanyi@6
   125
  ///Map of nodes of graph
ladanyi@6
   126
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@6
   127
ladanyi@6
   128
  ///Map of edges of graph
hegyi@19
   129
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@6
   130
ladanyi@6
   131
  ///Map of texts to write on edges
ladanyi@6
   132
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@6
   133
hegyi@28
   134
  ///Map of texts to write on nodes
hegyi@28
   135
  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
hegyi@28
   136
ladanyi@6
   137
  ///Group of graphical elements of displayed_graph
ladanyi@6
   138
  Gnome::Canvas::Group displayed_graph;
ladanyi@6
   139
hegyi@32
   140
  ///Map editor entry
hegyi@32
   141
  Gtk::Entry entrywidget;
hegyi@32
   142
hegyi@32
   143
  ///GnomeCanvas holder for entry
hegyi@32
   144
  Gnome::Canvas::Widget * canvasentrywidget;
hegyi@32
   145
ladanyi@6
   146
  ///Here we store the maps that can be displayed through properties.
ladanyi@6
   147
  MapStorage mapstorage;
ladanyi@6
   148
ladanyi@6
   149
  ///Indicates whether the button of mouse is pressed or not
hegyi@20
   150
  int isbutton;
ladanyi@6
   151
hegyi@21
   152
  ///Stores the actual tool in hand
hegyi@21
   153
  int actual_tool;
hegyi@21
   154
ladanyi@6
   155
  ///At this location was the mousebutton pressed.
ladanyi@6
   156
  ///It helps to calculate the distance of dragging.
ladanyi@6
   157
  double clicked_x, clicked_y;
ladanyi@6
   158
ladanyi@6
   159
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@6
   160
  ///this variable is needed, because
ladanyi@6
   161
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@6
   162
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@11
   163
  Gnome::Canvas::Item * active_item, * target_item;
hegyi@9
   164
  Graph::NodeIt active_node;
hegyi@11
   165
  Graph::EdgeIt active_edge;
hegyi@35
   166
  Graph::EdgeIt forming_edge;
hegyi@35
   167
hegyi@35
   168
  std::string nodemap_to_edit, edgemap_to_edit;
ladanyi@6
   169
ladanyi@6
   170
  static const int zoom_step = 5;
hegyi@19
   171
hegyi@28
   172
  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
hegyi@28
   173
  MapWin * mapwin;
hegyi@28
   174
ladanyi@6
   175
};
ladanyi@6
   176
ladanyi@6
   177
#endif //GRAPH_DISPLAYER_CANVAS_H