gui/graph_displayer_canvas.h
author alpar
Mon, 24 Oct 2005 08:11:21 +0000
changeset 1735 41e96cd91d6d
parent 1648 dd8672338691
child 1814 0f02ced2e2ba
permissions -rw-r--r--
New version of XML reader/writer.
Now, there are only a single XmlIo class both for reading and writing.
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@1606
     8
#include "all_include.h"
ladanyi@1606
     9
#include "mapstorage.h"
ladanyi@1606
    10
#include "broken_edge.h"
ladanyi@1606
    11
#include "map_win.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@1614
    21
  GraphDisplayerCanvas(MapStorage &, MapWin &, Gtk::Window *);
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
alpar@1643
    26
  int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
hegyi@1731
    27
  int resetEdgeWidth (Edge new_item=INVALID);
ladanyi@1442
    28
ladanyi@1442
    29
  ///Changes the linecolor attribute according to the given map.
ladanyi@1442
    30
  ///\param mapname is the name of the map which contains the new values
alpar@1643
    31
  int changeEdgeColor (std::string mapname, Edge new_item=INVALID);
hegyi@1731
    32
  int resetEdgeColor (Edge new_item=INVALID);
ladanyi@1442
    33
ladanyi@1442
    34
  ///Changes the text of line attribute according to the given map.
ladanyi@1442
    35
  ///\param mapname is the name of the map which contains the new values
alpar@1643
    36
  int changeEdgeText (std::string mapname, Edge new_item=INVALID);
hegyi@1731
    37
  int resetEdgeText (Edge new_item=INVALID);
hegyi@1512
    38
hegyi@1512
    39
  ///Changes the linewidth attribute according to the given map.
hegyi@1512
    40
  ///\param mapname is the name of the map which contains the new values
alpar@1643
    41
  int changeNodeRadius (std::string mapname, Node new_item=INVALID);
hegyi@1731
    42
  int resetNodeRadius (Node new_item=INVALID);
hegyi@1512
    43
hegyi@1512
    44
  ///Changes the linecolor attribute according to the given map.
hegyi@1512
    45
  ///\param mapname is the name of the map which contains the new values
alpar@1643
    46
  int changeNodeColor (std::string mapname, Node new_item=INVALID);
hegyi@1731
    47
  int resetNodeColor (Node new_item=INVALID);
hegyi@1512
    48
hegyi@1512
    49
  ///Changes the text of line attribute according to the given map.
hegyi@1512
    50
  ///\param mapname is the name of the map which contains the new values
alpar@1643
    51
  int changeNodeText (std::string mapname, Node new_item=INVALID);
hegyi@1731
    52
  int resetNodeText (Node new_item=INVALID);
ladanyi@1442
    53
ladanyi@1442
    54
  ///Callback for 'ViewZoomIn' action.
ladanyi@1442
    55
  virtual void zoomIn();
ladanyi@1442
    56
  ///Callback for 'ViewZoomOut' action.
ladanyi@1442
    57
  virtual void zoomOut();
ladanyi@1442
    58
  ///Callback for 'ViewZoomFit' action.
ladanyi@1442
    59
  virtual void zoomFit();
ladanyi@1442
    60
  ///Callback for 'ViewZoom100' action.
ladanyi@1442
    61
  virtual void zoom100();
ladanyi@1442
    62
  ///Sets the scroll region of the convas to the bounding box of the graph.
ladanyi@1442
    63
  void updateScrollRegion();
ladanyi@1442
    64
hegyi@1468
    65
  ///This function changes the tool in the graph-editor's hand
hegyi@1468
    66
  void changeEditorialTool(int);
hegyi@1468
    67
ladanyi@1442
    68
protected:
ladanyi@1442
    69
ladanyi@1442
    70
  //maximizing, minimizing, restoring window, etc. 
ladanyi@1442
    71
  virtual bool on_expose_event(GdkEventExpose *);
ladanyi@1442
    72
ladanyi@1442
    73
private:
ladanyi@1442
    74
ladanyi@1442
    75
  ///This function is responsible for the correct
ladanyi@1442
    76
  ///reaction of any action happened in the territory
ladanyi@1442
    77
  ///of the canvas
hegyi@1505
    78
  ///DEPRECATED!!!!
hegyi@1524
    79
  bool eventHandler(GdkEvent* e, Node n);
ladanyi@1442
    80
hegyi@1468
    81
  ///actual event handler
hegyi@1468
    82
  ///
hegyi@1468
    83
  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
hegyi@1468
    84
  sigc::connection actual_handler;
hegyi@1468
    85
hegyi@1468
    86
  ///event handler for the case when move-tool is active
hegyi@1524
    87
  bool moveEventHandler(GdkEvent*);
hegyi@1468
    88
  ///event handler for the case when create_node-tool is active
hegyi@1524
    89
  bool createNodeEventHandler(GdkEvent*);
hegyi@1468
    90
  ///event handler for the case when create_edge-tool is active
hegyi@1524
    91
  bool createEdgeEventHandler(GdkEvent*);
hegyi@1485
    92
  ///event handler for the case when eraser-tool is active
hegyi@1524
    93
  bool eraserEventHandler(GdkEvent*);
hegyi@1550
    94
  ///event handler for the case when edge map editor tool is active
hegyi@1524
    95
  bool edgeMapEditEventHandler(GdkEvent*);
hegyi@1550
    96
  ///event handler for the case when node map editor tool is active
hegyi@1550
    97
  bool nodeMapEditEventHandler(GdkEvent*);
hegyi@1485
    98
hegyi@1501
    99
public:
hegyi@1505
   100
  ///Moves the text to new place
hegyi@1524
   101
  void textReposition(xy<double>);
hegyi@1505
   102
  ///Activates an edge belonging to a BrokenEdge
hegyi@1579
   103
  ///
hegyi@1579
   104
  ///After we have activated an edge this way,
hegyi@1579
   105
  ///the GDC object will know, which edge is under forming
hegyi@1579
   106
  ///therefore it can redraw the necessarz elementy on the canvas,
hegyi@1579
   107
  ///for example the text belonging to the \ref BrokenEdge can be
hegyi@1579
   108
  ///redrawn (\ref textReposition).
hegyi@1524
   109
  void toggleEdgeActivity(BrokenEdge*, bool);
hegyi@1505
   110
hegyi@1505
   111
public:
hegyi@1501
   112
  ///\return the actual tool in hand
hegyi@1524
   113
  int getActualTool();
hegyi@1501
   114
ladanyi@1606
   115
  void drawGraph();
ladanyi@1606
   116
  void clear();
ladanyi@1606
   117
hegyi@1585
   118
  ///creates a new Nodemap
hegyi@1597
   119
  int addNewNodeMap(double,std::string);
hegyi@1585
   120
  ///creates a new Edgemap
hegyi@1597
   121
  int addNewEdgeMap(double,std::string);
hegyi@1585
   122
hegyi@1501
   123
private:
hegyi@1486
   124
  ///Deletes the given element.
alpar@1643
   125
  void deleteItem(Node);
hegyi@1486
   126
  ///Deletes the given element.
alpar@1643
   127
  void deleteItem(Edge);
hegyi@1468
   128
hegyi@1501
   129
private:
hegyi@1501
   130
ladanyi@1442
   131
  ///Map of nodes of graph
ladanyi@1442
   132
  Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
ladanyi@1442
   133
ladanyi@1442
   134
  ///Map of edges of graph
hegyi@1499
   135
  Graph::EdgeMap<BrokenEdge *> edgesmap;
ladanyi@1442
   136
ladanyi@1442
   137
  ///Map of texts to write on edges
ladanyi@1442
   138
  Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
ladanyi@1442
   139
hegyi@1512
   140
  ///Map of texts to write on nodes
hegyi@1512
   141
  Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
hegyi@1512
   142
ladanyi@1442
   143
  ///Group of graphical elements of displayed_graph
ladanyi@1442
   144
  Gnome::Canvas::Group displayed_graph;
ladanyi@1442
   145
ladanyi@1442
   146
  ///Here we store the maps that can be displayed through properties.
hegyi@1589
   147
  MapStorage & mapstorage;
ladanyi@1442
   148
ladanyi@1442
   149
  ///Indicates whether the button of mouse is pressed or not
hegyi@1500
   150
  int isbutton;
ladanyi@1442
   151
hegyi@1501
   152
  ///Stores the actual tool in hand
hegyi@1501
   153
  int actual_tool;
hegyi@1501
   154
ladanyi@1442
   155
  ///At this location was the mousebutton pressed.
ladanyi@1442
   156
  ///It helps to calculate the distance of dragging.
ladanyi@1442
   157
  double clicked_x, clicked_y;
ladanyi@1442
   158
ladanyi@1442
   159
  ///Remembers which Gnome::Canvas::Item was pressed.
ladanyi@1442
   160
  ///this variable is needed, because
ladanyi@1442
   161
  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
ladanyi@1442
   162
  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
hegyi@1474
   163
  Gnome::Canvas::Item * active_item, * target_item;
alpar@1643
   164
  Node active_node;
alpar@1643
   165
  Edge active_edge;
alpar@1643
   166
  Edge forming_edge;
hegyi@1579
   167
hegyi@1579
   168
  std::string nodemap_to_edit, edgemap_to_edit;
ladanyi@1442
   169
ladanyi@1442
   170
  static const int zoom_step = 5;
hegyi@1499
   171
hegyi@1512
   172
  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
ladanyi@1606
   173
  MapWin & mapwin;
hegyi@1512
   174
ladanyi@1648
   175
  ///pointer to the parent window
hegyi@1614
   176
  Gtk::Window * parentwin;
hegyi@1614
   177
ladanyi@1442
   178
};
ladanyi@1442
   179
ladanyi@1442
   180
#endif //GRAPH_DISPLAYER_CANVAS_H