gui/graph_displayer_canvas-event.cc
author alpar
Tue, 16 Aug 2005 20:17:43 +0000
changeset 1633 4bc163d55528
parent 1614 350c1d8bb7cc
child 1643 9285f3777553
permissions -rwxr-xr-x
Move simann.h to trunk/lemon
ladanyi@1606
     1
#include "graph_displayer_canvas.h"
ladanyi@1606
     2
#include "broken_edge.h"
alpar@1632
     3
#include <cmath>
hegyi@1510
     4
hegyi@1510
     5
hegyi@1510
     6
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
hegyi@1510
     7
{
hegyi@1510
     8
  Gnome::Canvas::CanvasAA::on_expose_event(event);
hegyi@1510
     9
  //usleep(10000);
hegyi@1510
    10
  //rezoom();
hegyi@1510
    11
  return true;
hegyi@1510
    12
}
hegyi@1510
    13
hegyi@1510
    14
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
hegyi@1510
    15
{
hegyi@1562
    16
  if(actual_tool!=newtool)
hegyi@1562
    17
    {
hegyi@1510
    18
hegyi@1562
    19
      actual_handler.disconnect();
hegyi@1510
    20
hegyi@1562
    21
      switch(actual_tool)
hegyi@1562
    22
	{
hegyi@1562
    23
	case CREATE_EDGE:
hegyi@1562
    24
	  {
hegyi@1562
    25
	    GdkEvent * generated=new GdkEvent();
hegyi@1562
    26
	    generated->type=GDK_BUTTON_RELEASE;
hegyi@1562
    27
	    generated->button.button=3;
hegyi@1562
    28
	    createEdgeEventHandler(generated);      
hegyi@1562
    29
	    break;
hegyi@1562
    30
	  }
hegyi@1562
    31
	case EDGE_MAP_EDIT:
hegyi@1579
    32
	  //has to do the same thing as in the case of NODE_MAP_EDIT
hegyi@1579
    33
	case NODE_MAP_EDIT:
hegyi@1579
    34
	  {
hegyi@1579
    35
	    GdkEvent * generated=new GdkEvent();
hegyi@1579
    36
	    generated->type=GDK_KEY_PRESS;
hegyi@1579
    37
	    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
hegyi@1579
    38
	    entryWidgetChangeHandler(generated);
hegyi@1579
    39
	    entrywidget.hide();
hegyi@1579
    40
	    break;
hegyi@1579
    41
	  }
hegyi@1562
    42
	default:
hegyi@1562
    43
	  break;
hegyi@1562
    44
	}
hegyi@1510
    45
hegyi@1562
    46
      active_item=NULL; 
hegyi@1562
    47
      target_item=NULL; 
hegyi@1562
    48
      active_edge=INVALID;	
hegyi@1562
    49
      active_node=INVALID;	
hegyi@1551
    50
hegyi@1510
    51
hegyi@1562
    52
      actual_tool=newtool;
hegyi@1562
    53
  
hegyi@1562
    54
      switch(newtool)
hegyi@1562
    55
	{
hegyi@1562
    56
	case MOVE:
hegyi@1562
    57
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
hegyi@1562
    58
	  break;
hegyi@1510
    59
hegyi@1562
    60
	case CREATE_NODE:
hegyi@1562
    61
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
hegyi@1562
    62
	  break;
hegyi@1510
    63
hegyi@1562
    64
	case CREATE_EDGE:
hegyi@1562
    65
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
hegyi@1562
    66
	  break;
hegyi@1510
    67
hegyi@1562
    68
	case ERASER:
hegyi@1562
    69
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
hegyi@1562
    70
	  break;
hegyi@1550
    71
hegyi@1562
    72
	case EDGE_MAP_EDIT:
hegyi@1562
    73
	  grab_focus();
hegyi@1562
    74
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
hegyi@1562
    75
	  break;
hegyi@1550
    76
hegyi@1562
    77
	case NODE_MAP_EDIT:
hegyi@1562
    78
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
hegyi@1562
    79
	  break;
hegyi@1562
    80
hegyi@1562
    81
	default:
hegyi@1562
    82
	  break;
hegyi@1562
    83
	}
hegyi@1510
    84
    }
hegyi@1510
    85
}
hegyi@1510
    86
hegyi@1524
    87
int GraphDisplayerCanvas::getActualTool()
hegyi@1510
    88
{
hegyi@1510
    89
  return actual_tool;
hegyi@1510
    90
}
hegyi@1510
    91
hegyi@1524
    92
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
hegyi@1510
    93
{
hegyi@1510
    94
  switch(e->type)
hegyi@1510
    95
  {
hegyi@1510
    96
    case GDK_BUTTON_PRESS:
hegyi@1510
    97
      //we mark the location of the event to be able to calculate parameters of dragging
hegyi@1525
    98
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1525
    99
hegyi@1525
   100
      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@1510
   101
      active_node=INVALID;
ladanyi@1606
   102
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   103
	{
hegyi@1510
   104
	  if(nodesmap[i]==active_item)
hegyi@1510
   105
	    {
hegyi@1510
   106
	      active_node=i;
hegyi@1510
   107
	    }
hegyi@1510
   108
	}
hegyi@1510
   109
      switch(e->button.button)
hegyi@1510
   110
	{
hegyi@1510
   111
	case 3:      
hegyi@1510
   112
	  isbutton=3;
hegyi@1510
   113
	  break;
hegyi@1510
   114
	default:
hegyi@1510
   115
	  isbutton=1;
hegyi@1510
   116
	  break;
hegyi@1510
   117
	}
hegyi@1510
   118
      break;
hegyi@1510
   119
    case GDK_BUTTON_RELEASE:
hegyi@1510
   120
      isbutton=0;
hegyi@1510
   121
      active_item=NULL;
hegyi@1510
   122
      active_node=INVALID;
hegyi@1510
   123
      break;
hegyi@1510
   124
    case GDK_MOTION_NOTIFY:
hegyi@1510
   125
      //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
hegyi@1510
   126
      if(active_node!=INVALID)
hegyi@1510
   127
      {
ladanyi@1606
   128
        mapstorage.modified = true;
ladanyi@1606
   129
        mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
hegyi@1510
   130
	//new coordinates will be the old values,
hegyi@1510
   131
	//because the item will be moved to the
hegyi@1510
   132
	//new coordinate therefore the new movement
hegyi@1510
   133
	//has to be calculated from here
hegyi@1510
   134
hegyi@1525
   135
	double new_x, new_y;
hegyi@1525
   136
hegyi@1525
   137
	window_to_world (e->motion.x, e->motion.y, new_x, new_y);
hegyi@1525
   138
hegyi@1525
   139
        double dx=new_x-clicked_x;
hegyi@1525
   140
        double dy=new_y-clicked_y;
hegyi@1510
   141
hegyi@1512
   142
	//repositioning node and its text
hegyi@1510
   143
        active_item->move(dx, dy);
hegyi@1512
   144
	nodetextmap[active_node]->move(dx, dy);
hegyi@1510
   145
hegyi@1525
   146
        clicked_x=new_x;
hegyi@1525
   147
        clicked_y=new_y;
hegyi@1510
   148
hegyi@1510
   149
	//all the edges connected to the moved point has to be redrawn
hegyi@1510
   150
        EdgeIt ei;
hegyi@1510
   151
ladanyi@1606
   152
        mapstorage.graph.firstOut(ei,active_node);
hegyi@1510
   153
ladanyi@1606
   154
        for(;ei!=INVALID;mapstorage.graph.nextOut(ei))
hegyi@1510
   155
        {
hegyi@1510
   156
            Gnome::Canvas::Points coos;
hegyi@1510
   157
            double x1, x2, y1, y2;
hegyi@1510
   158
ladanyi@1606
   159
            nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@1510
   160
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@1510
   161
ladanyi@1606
   162
            nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@1510
   163
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@1510
   164
hegyi@1510
   165
	    if(isbutton==3)
hegyi@1510
   166
	      {
hegyi@1524
   167
		edgesmap[ei]->setPoints(coos);
hegyi@1510
   168
	      }
hegyi@1510
   169
	    else
hegyi@1510
   170
	      {
hegyi@1524
   171
		edgesmap[ei]->setPoints(coos,true);
hegyi@1510
   172
	      }
hegyi@1510
   173
hegyi@1512
   174
	    //reposition of edgetext
hegyi@1524
   175
	    xy<double> text_pos=edgesmap[ei]->getArrowPos();
hegyi@1510
   176
	    text_pos+=(xy<double>(10,10));
hegyi@1510
   177
	    edgetextmap[ei]->property_x().set_value(text_pos.x);
hegyi@1510
   178
	    edgetextmap[ei]->property_y().set_value(text_pos.y);
hegyi@1510
   179
        }
hegyi@1510
   180
ladanyi@1606
   181
        mapstorage.graph.firstIn(ei,active_node);
ladanyi@1606
   182
        for(;ei!=INVALID;mapstorage.graph.nextIn(ei))
hegyi@1510
   183
        {
hegyi@1510
   184
            Gnome::Canvas::Points coos;
hegyi@1510
   185
            double x1, x2, y1, y2;
hegyi@1510
   186
ladanyi@1606
   187
            nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@1510
   188
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@1510
   189
ladanyi@1606
   190
            nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@1510
   191
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@1510
   192
hegyi@1510
   193
	    if(isbutton==3)
hegyi@1510
   194
	      {
hegyi@1524
   195
		edgesmap[ei]->setPoints(coos);
hegyi@1510
   196
	      }
hegyi@1510
   197
	    else
hegyi@1510
   198
	      {
hegyi@1524
   199
		edgesmap[ei]->setPoints(coos,true);
hegyi@1510
   200
	      }
hegyi@1510
   201
hegyi@1524
   202
	    xy<double> text_pos=edgesmap[ei]->getArrowPos();
hegyi@1510
   203
	    text_pos+=(xy<double>(10,10));
hegyi@1510
   204
	    edgetextmap[ei]->property_x().set_value(text_pos.x);
hegyi@1510
   205
	    edgetextmap[ei]->property_y().set_value(text_pos.y);
hegyi@1510
   206
        }
hegyi@1510
   207
      }
hegyi@1510
   208
    default: break;
hegyi@1510
   209
  }
hegyi@1510
   210
hegyi@1525
   211
  return false;
hegyi@1510
   212
}
hegyi@1510
   213
hegyi@1524
   214
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
hegyi@1510
   215
{
hegyi@1510
   216
  switch(e->type)
hegyi@1510
   217
    {
hegyi@1510
   218
hegyi@1510
   219
      //draw the new node in red at the clicked place
hegyi@1525
   220
    case GDK_2BUTTON_PRESS:
hegyi@1599
   221
      //std::cout << "double click" << std::endl;
hegyi@1525
   222
      break;
hegyi@1510
   223
    case GDK_BUTTON_PRESS:
ladanyi@1606
   224
      mapstorage.modified = true;
ladanyi@1606
   225
hegyi@1510
   226
      isbutton=1;
hegyi@1510
   227
ladanyi@1606
   228
      active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode());
hegyi@1510
   229
hegyi@1510
   230
      //initiating values corresponding to new node in maps
hegyi@1510
   231
hegyi@1510
   232
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1510
   233
ladanyi@1606
   234
      mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
ladanyi@1606
   235
      (*mapstorage.nodemap_storage["id"])[active_node] =
ladanyi@1606
   236
        mapstorage.graph.id(active_node);
ladanyi@1606
   237
ladanyi@1606
   238
      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
ladanyi@1606
   239
        clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
hegyi@1510
   240
      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
hegyi@1510
   241
      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@1510
   242
      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@1510
   243
      (nodesmap[active_node])->show();
hegyi@1512
   244
ladanyi@1606
   245
      nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
ladanyi@1606
   246
        clicked_x+node_property_defaults[N_RADIUS]+5,
ladanyi@1606
   247
        clicked_y+node_property_defaults[N_RADIUS]+5, "");
hegyi@1512
   248
      nodetextmap[active_node]->property_fill_color().set_value("darkblue");
hegyi@1512
   249
ladanyi@1606
   250
      mapwin.updateNode(active_node);
hegyi@1512
   251
hegyi@1510
   252
      break;
hegyi@1510
   253
hegyi@1510
   254
      //move the new node
hegyi@1510
   255
    case GDK_MOTION_NOTIFY:
hegyi@1510
   256
      {
hegyi@1510
   257
	GdkEvent * generated=new GdkEvent();
hegyi@1525
   258
	generated->motion.x=e->motion.x;
hegyi@1525
   259
	generated->motion.y=e->motion.y;
hegyi@1510
   260
	generated->type=GDK_MOTION_NOTIFY;
hegyi@1524
   261
	moveEventHandler(generated);      
hegyi@1510
   262
	break;
hegyi@1510
   263
      }
hegyi@1510
   264
hegyi@1510
   265
      //finalize the new node
hegyi@1510
   266
    case GDK_BUTTON_RELEASE:
hegyi@1579
   267
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1579
   268
hegyi@1579
   269
      active_item->lower_to_bottom();
hegyi@1579
   270
hegyi@1579
   271
      target_item=NULL;
hegyi@1579
   272
      target_item=get_item_at(clicked_x, clicked_y);
hegyi@1579
   273
hegyi@1579
   274
      active_item->raise_to_top();
hegyi@1579
   275
hegyi@1510
   276
      isbutton=0;
hegyi@1579
   277
      if(target_item==active_item)
hegyi@1525
   278
	{
hegyi@1525
   279
	  //Its appropriate color is given by update.
hegyi@1579
   280
	  *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@1525
   281
	}
hegyi@1525
   282
      else
hegyi@1525
   283
	{
hegyi@1525
   284
	  //In this case the given color has to be overwritten, because the noe covers an other item.
hegyi@1525
   285
	  *active_item << Gnome::Canvas::Properties::fill_color("lightblue");
hegyi@1525
   286
	}
hegyi@1525
   287
      target_item=NULL;
hegyi@1510
   288
      active_item=NULL;
hegyi@1510
   289
      active_node=INVALID;
hegyi@1510
   290
      break;
hegyi@1510
   291
    default:
hegyi@1510
   292
      break;
hegyi@1510
   293
    }
hegyi@1510
   294
  return false;
hegyi@1510
   295
}
hegyi@1510
   296
hegyi@1524
   297
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
hegyi@1510
   298
{
hegyi@1510
   299
  switch(e->type)
hegyi@1510
   300
    {
hegyi@1510
   301
    case GDK_BUTTON_PRESS:
hegyi@1510
   302
      //in edge creation right button has special meaning
hegyi@1510
   303
      if(e->button.button!=3)
hegyi@1510
   304
	{
hegyi@1510
   305
	  //there is not yet selected node
hegyi@1510
   306
	  if(active_node==INVALID)
hegyi@1510
   307
	    {
hegyi@1510
   308
	      //we mark the location of the event to be able to calculate parameters of dragging
hegyi@1525
   309
hegyi@1525
   310
	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1525
   311
hegyi@1525
   312
	      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@1510
   313
	      active_node=INVALID;
ladanyi@1606
   314
	      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   315
		{
hegyi@1510
   316
		  if(nodesmap[i]==active_item)
hegyi@1510
   317
		    {
hegyi@1510
   318
		      active_node=i;
hegyi@1510
   319
		    }
hegyi@1510
   320
		}
hegyi@1510
   321
	      //the clicked item is really a node
hegyi@1510
   322
	      if(active_node!=INVALID)
hegyi@1510
   323
		{
hegyi@1510
   324
		  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@1510
   325
		  isbutton=1;
hegyi@1510
   326
		}
hegyi@1510
   327
	      //clicked item was not a node. It could be e.g. edge.
hegyi@1510
   328
	      else
hegyi@1510
   329
		{
hegyi@1510
   330
		  active_item=NULL;
hegyi@1510
   331
		}
hegyi@1510
   332
	    }
hegyi@1510
   333
	  //we only have to do sg. if the mouse button
hegyi@1510
   334
	  // is pressed already once AND the click was
hegyi@1510
   335
	  // on a node that was found in the set of 
hegyi@1510
   336
	  //nodes, and now we only search for the second 
hegyi@1510
   337
	  //node
hegyi@1510
   338
	  else
hegyi@1510
   339
	    {
hegyi@1525
   340
	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1525
   341
	      target_item=(get_item_at(clicked_x, clicked_y));
hegyi@1510
   342
	      Graph::NodeIt target_node=INVALID;
ladanyi@1606
   343
	      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   344
		{
hegyi@1510
   345
		  if(nodesmap[i]==target_item)
hegyi@1510
   346
		    {
hegyi@1510
   347
		      target_node=i;
hegyi@1510
   348
		    }
hegyi@1510
   349
		}
hegyi@1510
   350
	      //the clicked item is a node, the edge can be drawn
hegyi@1510
   351
	      if(target_node!=INVALID)
hegyi@1510
   352
		{
hegyi@1512
   353
		  if(target_node!=active_node)		
hegyi@1512
   354
		    {
ladanyi@1606
   355
          mapstorage.modified = true;
ladanyi@1606
   356
hegyi@1512
   357
		      *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@1510
   358
hegyi@1512
   359
		      //creating new edge
ladanyi@1606
   360
		      active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node));
hegyi@1510
   361
hegyi@1512
   362
		      //initiating values corresponding to new edge in maps
hegyi@1524
   363
		      mapstorage.initMapsForEdge(active_edge);
ladanyi@1606
   364
                      (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge);
hegyi@1510
   365
	  
hegyi@1512
   366
		      //calculating coordinates of new edge
hegyi@1512
   367
		      Gnome::Canvas::Points coos;
hegyi@1512
   368
		      double x1, x2, y1, y2;
hegyi@1510
   369
	  
hegyi@1512
   370
		      active_item->get_bounds(x1, y1, x2, y2);
hegyi@1512
   371
		      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@1510
   372
hegyi@1512
   373
		      target_item->get_bounds(x1, y1, x2, y2);
hegyi@1512
   374
		      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@1510
   375
hegyi@1512
   376
		      //drawing new edge
hegyi@1512
   377
		      edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
hegyi@1512
   378
		      *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
hegyi@1512
   379
		      edgesmap[active_edge]->property_width_pixels().set_value(10);
hegyi@1510
   380
hegyi@1512
   381
		      //redraw nodes to blank terminations of the new edge
hegyi@1512
   382
		      target_item->raise_to_top();
hegyi@1512
   383
		      active_item->raise_to_top();
hegyi@1510
   384
hegyi@1512
   385
		      //initializing edge-text as well, to empty string
hegyi@1524
   386
		      xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
hegyi@1512
   387
		      text_pos+=(xy<double>(10,10));
hegyi@1510
   388
hegyi@1512
   389
		      edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
hegyi@1512
   390
		      edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
hegyi@1512
   391
hegyi@1512
   392
		      //updating its properties
ladanyi@1606
   393
		      mapwin.updateEdge(active_edge);
hegyi@1512
   394
		    }
hegyi@1512
   395
		  else
hegyi@1512
   396
		    {
hegyi@1512
   397
		      target_node=INVALID;
hegyi@1599
   398
		      std::cerr << "Loop edge is not yet implemented!" << std::endl;
hegyi@1512
   399
		    }
hegyi@1510
   400
		}
hegyi@1510
   401
	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
hegyi@1510
   402
	      else
hegyi@1510
   403
		{
hegyi@1510
   404
		  target_item=NULL;
hegyi@1510
   405
		}
hegyi@1510
   406
	    }
hegyi@1510
   407
	}
hegyi@1510
   408
      break;
hegyi@1510
   409
    case GDK_BUTTON_RELEASE:
hegyi@1510
   410
      isbutton=0;
hegyi@1510
   411
      //we clear settings in two cases
hegyi@1510
   412
      //1: the edge is ready (target_item has valid value)
hegyi@1510
   413
      //2: the edge creation is cancelled with right button
hegyi@1510
   414
      if((target_item)||(e->button.button==3))
hegyi@1510
   415
	{
hegyi@1510
   416
	  if(active_item)
hegyi@1510
   417
	    {
hegyi@1510
   418
	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@1510
   419
	      active_item=NULL;
hegyi@1510
   420
	    }
hegyi@1510
   421
	  if(target_item)
hegyi@1510
   422
	    {
hegyi@1510
   423
	      *target_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@1510
   424
	      target_item=NULL;
hegyi@1510
   425
	    }
hegyi@1510
   426
	  active_node=INVALID;
hegyi@1510
   427
	  active_edge=INVALID;
hegyi@1510
   428
	}
hegyi@1510
   429
      break;
hegyi@1510
   430
    default:
hegyi@1510
   431
      break;
hegyi@1510
   432
    }
hegyi@1510
   433
  return false;
hegyi@1510
   434
}
hegyi@1510
   435
hegyi@1524
   436
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
hegyi@1510
   437
{
hegyi@1510
   438
  switch(e->type)
hegyi@1510
   439
    {
hegyi@1510
   440
    case GDK_BUTTON_PRESS:
hegyi@1594
   441
      //finding the clicked items
hegyi@1525
   442
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1525
   443
      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@1510
   444
      active_node=INVALID;
hegyi@1510
   445
      active_edge=INVALID;
hegyi@1594
   446
      //was it a node?
ladanyi@1606
   447
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   448
	{
hegyi@1510
   449
	  if(nodesmap[i]==active_item)
hegyi@1510
   450
	    {
hegyi@1510
   451
	      active_node=i;
hegyi@1510
   452
	    }
hegyi@1510
   453
	}
hegyi@1594
   454
      //or was it an edge?
hegyi@1510
   455
      if(active_node==INVALID)
hegyi@1510
   456
	{
ladanyi@1606
   457
	  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   458
	    {
hegyi@1510
   459
	      if(edgesmap[i]==active_item)
hegyi@1510
   460
		{
hegyi@1510
   461
		  active_edge=i;
hegyi@1510
   462
		}
hegyi@1510
   463
	    }
hegyi@1510
   464
	}
hegyi@1594
   465
hegyi@1594
   466
      //recolor activated item
hegyi@1525
   467
      if(active_item)
hegyi@1525
   468
	{
hegyi@1525
   469
	  *active_item << Gnome::Canvas::Properties::fill_color("red");
hegyi@1525
   470
	}
hegyi@1510
   471
      break;
hegyi@1510
   472
hegyi@1510
   473
    case GDK_BUTTON_RELEASE:
hegyi@1525
   474
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1525
   475
      if(active_item)
hegyi@1510
   476
	{
hegyi@1594
   477
	  //the cursor was not moved since pressing it
hegyi@1525
   478
	  if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
hegyi@1510
   479
	    {
hegyi@1594
   480
	      //a node was found
hegyi@1525
   481
	      if(active_node!=INVALID)
hegyi@1525
   482
		{
ladanyi@1606
   483
                  mapstorage.modified = true;
hegyi@1510
   484
hegyi@1525
   485
		  //collecting edges to delete
hegyi@1525
   486
		  EdgeIt e;
hegyi@1525
   487
		  std::set<Graph::Edge> edges_to_delete;
hegyi@1510
   488
ladanyi@1606
   489
		  mapstorage.graph.firstOut(e,active_node);
ladanyi@1606
   490
		  for(;e!=INVALID;mapstorage.graph.nextOut(e))
hegyi@1525
   491
		    {
hegyi@1525
   492
		      edges_to_delete.insert(e);
hegyi@1525
   493
		    }
hegyi@1525
   494
ladanyi@1606
   495
		  mapstorage.graph.firstIn(e,active_node);
ladanyi@1606
   496
		  for(;e!=INVALID;mapstorage.graph.nextIn(e))
hegyi@1525
   497
		    {
hegyi@1525
   498
		      edges_to_delete.insert(e);
hegyi@1525
   499
		    }
hegyi@1525
   500
hegyi@1525
   501
		  //deleting collected edges
hegyi@1525
   502
		  for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
hegyi@1525
   503
		    {
hegyi@1525
   504
		      deleteItem(*edge_set_it);
hegyi@1525
   505
		    }
hegyi@1525
   506
		  deleteItem(active_node);
hegyi@1525
   507
		}
hegyi@1525
   508
	      //a simple edge was chosen
hegyi@1525
   509
	      else
hegyi@1510
   510
		{
hegyi@1525
   511
		  deleteItem(active_edge);
hegyi@1510
   512
		}
hegyi@1510
   513
	    }
hegyi@1525
   514
	  //pointer was moved, deletion is cancelled
hegyi@1510
   515
	  else
hegyi@1510
   516
	    {
hegyi@1525
   517
	      if(active_node!=INVALID)
hegyi@1525
   518
		{
hegyi@1525
   519
		  *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@1525
   520
		}
hegyi@1525
   521
	      else
hegyi@1525
   522
		{
hegyi@1525
   523
		  *active_item << Gnome::Canvas::Properties::fill_color("green");
hegyi@1525
   524
		}
hegyi@1510
   525
	    }
hegyi@1510
   526
	}
hegyi@1510
   527
      //reseting datas
hegyi@1510
   528
      active_item=NULL;
hegyi@1510
   529
      active_edge=INVALID;
hegyi@1510
   530
      active_node=INVALID;
hegyi@1510
   531
      break;
hegyi@1510
   532
hegyi@1510
   533
    case GDK_MOTION_NOTIFY:
hegyi@1510
   534
      break;
hegyi@1510
   535
hegyi@1510
   536
    default:
hegyi@1510
   537
      break;
hegyi@1510
   538
    }
hegyi@1525
   539
  return false;
hegyi@1510
   540
}
hegyi@1510
   541
hegyi@1550
   542
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
hegyi@1550
   543
{
hegyi@1599
   544
  if(actual_tool==EDGE_MAP_EDIT)
hegyi@1550
   545
    {
hegyi@1599
   546
      switch(e->type)
hegyi@1599
   547
	{
hegyi@1599
   548
	case GDK_KEY_PRESS:
hegyi@1599
   549
	  //for Escape or Enter hide the displayed widget
hegyi@1599
   550
	  {
hegyi@1599
   551
	    nodeMapEditEventHandler(e);
hegyi@1599
   552
	    break;
hegyi@1599
   553
	  }
hegyi@1599
   554
	case GDK_BUTTON_PRESS:
hegyi@1599
   555
	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
hegyi@1599
   556
	  {
hegyi@1599
   557
	    //for determine, whether it was an edge
hegyi@1599
   558
	    Graph::EdgeIt clicked_edge=INVALID;
hegyi@1594
   559
hegyi@1599
   560
	    //find the activated item between texts
hegyi@1599
   561
	    active_item=(get_item_at(e->button.x, e->button.y));
ladanyi@1606
   562
	    for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1562
   563
	      {
hegyi@1599
   564
		if(edgetextmap[i]==active_item)
hegyi@1599
   565
		  {
hegyi@1599
   566
		    clicked_edge=i;
hegyi@1599
   567
		  }
hegyi@1562
   568
	      }
hegyi@1599
   569
hegyi@1599
   570
	    //if it was not between texts, search for it between edges
hegyi@1599
   571
	    if(clicked_edge==INVALID)
hegyi@1562
   572
	      {
hegyi@1599
   573
		window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1599
   574
		active_item=(get_item_at(clicked_x, clicked_y));
hegyi@1599
   575
ladanyi@1606
   576
		for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1599
   577
		  {
hegyi@1599
   578
		    //at the same time only one can be active
hegyi@1599
   579
		    if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
hegyi@1599
   580
		      {
hegyi@1599
   581
			clicked_edge=i;
hegyi@1599
   582
		      }
hegyi@1599
   583
		  }
hegyi@1599
   584
	      }
hegyi@1599
   585
	    //if it was really an edge...
hegyi@1599
   586
	    if(clicked_edge!=INVALID)
hegyi@1599
   587
	      {
hegyi@1599
   588
		//If there is already edited edge, it has to be saved first
hegyi@1599
   589
		if(entrywidget.is_visible())
hegyi@1599
   590
		  {
hegyi@1599
   591
		    GdkEvent * generated=new GdkEvent();
hegyi@1599
   592
		    generated->type=GDK_KEY_PRESS;
hegyi@1599
   593
		    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
hegyi@1599
   594
		    entryWidgetChangeHandler(generated);
hegyi@1599
   595
		  }
hegyi@1599
   596
		//If the previous value could be saved, we can go further, otherwise not
hegyi@1599
   597
		if(!entrywidget.is_visible())
hegyi@1599
   598
		  {
hegyi@1599
   599
		    //and there is activated map
hegyi@1599
   600
		    if(edgetextmap[clicked_edge]->property_text().get_value()!="")
hegyi@1599
   601
		      {
hegyi@1599
   602
			//activate the general variable for it
hegyi@1599
   603
			active_edge=clicked_edge;
hegyi@1599
   604
			//delete visible widget if there is
hegyi@1599
   605
			if(canvasentrywidget)
hegyi@1599
   606
			  {
hegyi@1599
   607
			    delete(canvasentrywidget);
hegyi@1599
   608
			  }
hegyi@1599
   609
hegyi@1599
   610
			//initialize the entry
hegyi@1599
   611
			entrywidget.show();
hegyi@1599
   612
hegyi@1599
   613
			//fill in the correct value
hegyi@1599
   614
			entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
hegyi@1599
   615
hegyi@1599
   616
			//replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
hegyi@1599
   617
			xy<double> entry_coos;
hegyi@1599
   618
			entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
hegyi@1599
   619
			entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
hegyi@1599
   620
			entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
hegyi@1599
   621
			entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
hegyi@1599
   622
			canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
hegyi@1599
   623
			canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
hegyi@1599
   624
			canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
hegyi@1614
   625
hegyi@1614
   626
			//setting the focus to newly created widget
hegyi@1614
   627
			parentwin->set_focus(entrywidget);
hegyi@1614
   628
			parentwin->activate_focus();
hegyi@1599
   629
		      }
hegyi@1599
   630
		  }
hegyi@1599
   631
	      }
hegyi@1599
   632
	    //if it was not an edge...
hegyi@1599
   633
	    else
hegyi@1599
   634
	      {
hegyi@1599
   635
		//In this case the click did not happen on an edge
hegyi@1599
   636
		//if there is visible entry we save the value in it
hegyi@1599
   637
		//we pretend like an Enter was presse din the Entry widget
hegyi@1594
   638
		GdkEvent * generated=new GdkEvent();
hegyi@1594
   639
		generated->type=GDK_KEY_PRESS;
hegyi@1594
   640
		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
hegyi@1594
   641
		entryWidgetChangeHandler(generated);
hegyi@1594
   642
	      }
hegyi@1599
   643
	    break;
hegyi@1562
   644
	  }
hegyi@1599
   645
	default:
hegyi@1599
   646
	  break;
hegyi@1599
   647
	}
hegyi@1550
   648
    }
hegyi@1550
   649
  return false;  
hegyi@1550
   650
}
hegyi@1550
   651
hegyi@1550
   652
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
hegyi@1550
   653
{
hegyi@1599
   654
  if(actual_tool==NODE_MAP_EDIT)
hegyi@1579
   655
    {
hegyi@1599
   656
      switch(e->type)
hegyi@1599
   657
	{
hegyi@1599
   658
	case GDK_KEY_PRESS:
hegyi@1599
   659
	  //for Escape or Enter hide the displayed widget
hegyi@1579
   660
	  {
hegyi@1599
   661
	    switch(((GdkEventKey*)e)->keyval)
hegyi@1599
   662
	      {
hegyi@1599
   663
	      case GDK_Escape:
hegyi@1599
   664
		entrywidget.hide();
hegyi@1599
   665
		break;
hegyi@1599
   666
	      case GDK_Return:
hegyi@1599
   667
	      case GDK_KP_Enter:
hegyi@1599
   668
		entrywidget.hide();
hegyi@1599
   669
		break;
hegyi@1599
   670
	      default:
hegyi@1599
   671
		break;
hegyi@1599
   672
	      }
hegyi@1599
   673
  
hegyi@1579
   674
	    break;
hegyi@1579
   675
	  }
hegyi@1599
   676
	case GDK_BUTTON_PRESS:
hegyi@1599
   677
	  //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
hegyi@1599
   678
	  {
hegyi@1599
   679
	    //for determine, whether it was a node
hegyi@1599
   680
	    Graph::NodeIt clicked_node=INVALID;
hegyi@1594
   681
hegyi@1599
   682
	    //find the activated item between texts
hegyi@1599
   683
	    active_item=(get_item_at(e->button.x, e->button.y));
ladanyi@1606
   684
	    for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1579
   685
	      {
hegyi@1599
   686
		//at the same time only one can be active
hegyi@1599
   687
		if(nodetextmap[i]==active_item)
hegyi@1599
   688
		  {
hegyi@1599
   689
		    clicked_node=i;
hegyi@1599
   690
		  }
hegyi@1579
   691
	      }
hegyi@1594
   692
hegyi@1599
   693
	    //if there was not, search for it between nodes
hegyi@1599
   694
	    if(clicked_node==INVALID)
hegyi@1579
   695
	      {
hegyi@1599
   696
		window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@1599
   697
		active_item=(get_item_at(clicked_x, clicked_y));
hegyi@1599
   698
ladanyi@1606
   699
		for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1599
   700
		  {
hegyi@1599
   701
		    //at the same time only one can be active
hegyi@1599
   702
		    if(nodesmap[i]==active_item)
hegyi@1599
   703
		      {
hegyi@1599
   704
			clicked_node=i;
hegyi@1599
   705
		      }
hegyi@1599
   706
		  }
hegyi@1599
   707
	      }
hegyi@1599
   708
	    //if it was really an edge...
hegyi@1599
   709
	    if(clicked_node!=INVALID)
hegyi@1599
   710
	      {
hegyi@1599
   711
		//If there is already edited edge, it has to be saved first
hegyi@1599
   712
		if(entrywidget.is_visible())
hegyi@1599
   713
		  {
hegyi@1599
   714
		    GdkEvent * generated=new GdkEvent();
hegyi@1599
   715
		    generated->type=GDK_KEY_PRESS;
hegyi@1599
   716
		    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
hegyi@1599
   717
		    entryWidgetChangeHandler(generated);
hegyi@1599
   718
		  }
hegyi@1599
   719
		//If the previous value could be saved, we can go further, otherwise not
hegyi@1599
   720
		if(!entrywidget.is_visible())
hegyi@1599
   721
		  {
hegyi@1599
   722
		    //and there is activated map
hegyi@1599
   723
		    if(nodetextmap[clicked_node]->property_text().get_value()!="")
hegyi@1599
   724
		      {
hegyi@1599
   725
			//activate the general variable for it
hegyi@1599
   726
			active_node=clicked_node;
hegyi@1599
   727
			//delete visible widget if there is
hegyi@1599
   728
			if(canvasentrywidget)
hegyi@1599
   729
			  {
hegyi@1599
   730
			    delete(canvasentrywidget);
hegyi@1599
   731
			  }
hegyi@1599
   732
hegyi@1599
   733
			//initialize the entry
hegyi@1599
   734
			entrywidget.show();
hegyi@1599
   735
hegyi@1599
   736
			//fill in the correct value
hegyi@1599
   737
			entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
hegyi@1599
   738
hegyi@1599
   739
			//replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
hegyi@1599
   740
			xy<double> entry_coos;
hegyi@1599
   741
			entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
hegyi@1599
   742
			entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
hegyi@1599
   743
			entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
hegyi@1599
   744
			entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
hegyi@1599
   745
			canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
hegyi@1599
   746
			canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
hegyi@1599
   747
			canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
hegyi@1599
   748
		      }
hegyi@1599
   749
		  }
hegyi@1599
   750
	      }
hegyi@1599
   751
	    //if it was not an edge...
hegyi@1599
   752
	    else
hegyi@1599
   753
	      {
hegyi@1599
   754
		//In this case the click did not happen on an edge
hegyi@1599
   755
		//if there is visible entry we save the value in it
hegyi@1599
   756
		//we pretend like an Enter was presse din the Entry widget
hegyi@1579
   757
		GdkEvent * generated=new GdkEvent();
hegyi@1579
   758
		generated->type=GDK_KEY_PRESS;
hegyi@1579
   759
		((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
hegyi@1579
   760
		entryWidgetChangeHandler(generated);
hegyi@1579
   761
	      }
hegyi@1599
   762
	    break;
hegyi@1579
   763
	  }
hegyi@1599
   764
	default:
hegyi@1599
   765
	  break;
hegyi@1599
   766
	}
hegyi@1579
   767
    }
hegyi@1579
   768
  return false;  
hegyi@1550
   769
}
hegyi@1550
   770
hegyi@1562
   771
bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
hegyi@1562
   772
{
hegyi@1579
   773
  if(entrywidget.is_visible())
hegyi@1579
   774
    {
hegyi@1579
   775
      if(e->type==GDK_KEY_PRESS)
hegyi@1579
   776
	{
hegyi@1579
   777
	  switch(((GdkEventKey*)e)->keyval)
hegyi@1579
   778
	    {
hegyi@1579
   779
	    case GDK_Escape:
hegyi@1579
   780
	      entrywidget.hide();
hegyi@1579
   781
	      break;
hegyi@1579
   782
	    case GDK_KP_Enter:
hegyi@1579
   783
	    case GDK_Return:
hegyi@1579
   784
	      {
hegyi@1594
   785
		//these variables check whether the text in the entry is valid
hegyi@1592
   786
		bool valid_double=true;
hegyi@1592
   787
		int point_num=0;
hegyi@1594
   788
hegyi@1594
   789
		//getting the value from the entry and converting it to double
hegyi@1592
   790
		Glib::ustring mapvalue_str = entrywidget.get_text();
hegyi@1579
   791
hegyi@1592
   792
		char * mapvalue_ch=new char [mapvalue_str.length()];
hegyi@1592
   793
		for(int i=0;i<(int)(mapvalue_str.length());i++)
hegyi@1579
   794
		  {
hegyi@1592
   795
		    if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
hegyi@1579
   796
		      {
hegyi@1592
   797
			valid_double=false;
hegyi@1579
   798
		      }
hegyi@1579
   799
		    else
hegyi@1579
   800
		      {
hegyi@1592
   801
			if(mapvalue_str[i]=='.')
hegyi@1592
   802
			  {
hegyi@1592
   803
			    point_num++;
hegyi@1592
   804
			  }
hegyi@1579
   805
		      }
hegyi@1592
   806
		    mapvalue_ch[i]=mapvalue_str[i];
hegyi@1579
   807
		  }
hegyi@1596
   808
  	      
hegyi@1594
   809
		//if the text in the entry was correct
hegyi@1592
   810
		if((point_num<=1)&&(valid_double))
hegyi@1579
   811
		  {
hegyi@1596
   812
		    double mapvalue_d=atof(mapvalue_ch);
hegyi@1596
   813
hegyi@1596
   814
		    //reconvert the double to string for the correct format
hegyi@1596
   815
		    std::ostringstream ostr;
hegyi@1596
   816
		    ostr << mapvalue_d;
hegyi@1596
   817
hegyi@1594
   818
		    //save the value to the correct place
hegyi@1579
   819
		    switch(actual_tool)
hegyi@1579
   820
		      {
hegyi@1579
   821
		      case EDGE_MAP_EDIT:
hegyi@1596
   822
			edgetextmap[active_edge]->property_text().set_value(ostr.str());
hegyi@1592
   823
			(*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
ladanyi@1606
   824
			mapwin.updateEdge(active_edge);
hegyi@1579
   825
			break;
hegyi@1579
   826
		      case NODE_MAP_EDIT:
hegyi@1596
   827
			nodetextmap[active_node]->property_text().set_value(ostr.str());
hegyi@1592
   828
			(*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
ladanyi@1606
   829
			mapwin.updateNode(active_node);
hegyi@1579
   830
			break;
hegyi@1579
   831
		      default:
hegyi@1579
   832
			break;
hegyi@1579
   833
		      }
hegyi@1579
   834
		    entrywidget.hide();
hegyi@1579
   835
		  }
hegyi@1594
   836
		//the text in the entry was not correct for a double
hegyi@1579
   837
		else
hegyi@1579
   838
		  {
hegyi@1599
   839
		    std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
hegyi@1579
   840
		  }
hegyi@1579
   841
hegyi@1579
   842
		break;
hegyi@1579
   843
	      }
hegyi@1579
   844
	    default:
hegyi@1579
   845
	      break;
hegyi@1579
   846
	    }
hegyi@1579
   847
	}
hegyi@1579
   848
    }
hegyi@1562
   849
  return false;
hegyi@1562
   850
}
hegyi@1562
   851
hegyi@1524
   852
void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
hegyi@1510
   853
{
hegyi@1512
   854
  delete(nodetextmap[node_to_delete]);
hegyi@1510
   855
  delete(nodesmap[node_to_delete]);
ladanyi@1606
   856
  mapstorage.graph.erase(node_to_delete);
hegyi@1510
   857
}
hegyi@1510
   858
hegyi@1524
   859
void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
hegyi@1510
   860
{
hegyi@1512
   861
  delete(edgetextmap[edge_to_delete]);
hegyi@1510
   862
  delete(edgesmap[edge_to_delete]);
ladanyi@1606
   863
  mapstorage.graph.erase(edge_to_delete);
hegyi@1510
   864
}
hegyi@1510
   865
hegyi@1524
   866
void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
hegyi@1510
   867
{
hegyi@1512
   868
  delete(edgetextmap[edge_to_delete]);
hegyi@1510
   869
  delete(edgesmap[edge_to_delete]);
ladanyi@1606
   870
  mapstorage.graph.erase(edge_to_delete);
hegyi@1510
   871
}
hegyi@1510
   872
hegyi@1524
   873
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
hegyi@1510
   874
{
hegyi@1510
   875
  new_place+=(xy<double>(10,10));
hegyi@1579
   876
  edgetextmap[forming_edge]->property_x().set_value(new_place.x);
hegyi@1579
   877
  edgetextmap[forming_edge]->property_y().set_value(new_place.y);
hegyi@1510
   878
}
hegyi@1510
   879
hegyi@1524
   880
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
hegyi@1510
   881
{
hegyi@1510
   882
  if(on)
hegyi@1510
   883
    {
hegyi@1579
   884
      if(forming_edge!=INVALID)
hegyi@1510
   885
	{
hegyi@1599
   886
	  std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
hegyi@1510
   887
	}
hegyi@1510
   888
      else
hegyi@1510
   889
	{
ladanyi@1606
   890
	  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   891
	    {
hegyi@1510
   892
	      if(edgesmap[i]==active_bre)
hegyi@1510
   893
		{
hegyi@1579
   894
		  forming_edge=i;
hegyi@1510
   895
		}
hegyi@1510
   896
	    }
hegyi@1510
   897
	}
hegyi@1510
   898
    }
hegyi@1510
   899
  else
hegyi@1510
   900
    {
hegyi@1579
   901
      if(forming_edge!=INVALID)
hegyi@1510
   902
	{
hegyi@1579
   903
	  forming_edge=INVALID;
hegyi@1510
   904
	}
hegyi@1510
   905
      else
hegyi@1510
   906
	{
hegyi@1599
   907
	  std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
hegyi@1510
   908
	}
hegyi@1510
   909
    }
hegyi@1510
   910
hegyi@1510
   911
}
hegyi@1550
   912
hegyi@1597
   913
int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
hegyi@1585
   914
{
hegyi@1594
   915
  //create the new map
ladanyi@1606
   916
  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
hegyi@1597
   917
hegyi@1597
   918
  //if addition was not successful addEdgeMap returns one.
hegyi@1597
   919
  //cause can be that there is already a map named like the new one
hegyi@1597
   920
  if(mapstorage.addEdgeMap(mapname,emptr))
hegyi@1597
   921
    {
hegyi@1597
   922
      return 1;
hegyi@1597
   923
    }
hegyi@1597
   924
hegyi@1594
   925
hegyi@1594
   926
  //add it to the list of the displayable maps
ladanyi@1606
   927
  mapwin.registerNewEdgeMap(mapname);
hegyi@1594
   928
hegyi@1594
   929
  //display it
hegyi@1592
   930
  changeEdgeText(mapname);
hegyi@1597
   931
hegyi@1597
   932
  return 0;
hegyi@1585
   933
}
hegyi@1585
   934
hegyi@1597
   935
int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
hegyi@1585
   936
{
hegyi@1594
   937
  //create the new map
ladanyi@1606
   938
  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
hegyi@1597
   939
hegyi@1597
   940
  //if addition was not successful addNodeMap returns one.
hegyi@1597
   941
  //cause can be that there is already a map named like the new one
hegyi@1597
   942
  if(mapstorage.addNodeMap(mapname,emptr))
hegyi@1597
   943
    {
hegyi@1597
   944
      return 1;
hegyi@1597
   945
    }
hegyi@1594
   946
hegyi@1594
   947
  //add it to the list of the displayable maps
ladanyi@1606
   948
  mapwin.registerNewNodeMap(mapname);
hegyi@1594
   949
hegyi@1594
   950
  //display it
hegyi@1592
   951
  changeNodeText(mapname);
hegyi@1597
   952
hegyi@1597
   953
  return 0;
hegyi@1585
   954
}
hegyi@1585
   955