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