graph_displayer_canvas-event.cc
author hegyi
Wed, 29 Jun 2005 19:44:30 +0000
branchgui
changeset 31 66e85f44a66f
parent 30 f70bbee5350a
child 32 1f45545f124c
permissions -rwxr-xr-x
Uh, long comment arrives... Zoom update does not happen after editorial steps. Nodes initial color is light blue, if there is any item under them. Strange node-text relations disappeared. Initial values of new items are given now in a more common way. The wood-cutter way of handling default values of properties is now changed.
hegyi@27
     1
#include <graph_displayer_canvas.h>
hegyi@27
     2
#include <broken_edge.h>
hegyi@27
     3
#include <math.h>
hegyi@27
     4
hegyi@27
     5
hegyi@27
     6
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
hegyi@27
     7
{
hegyi@27
     8
  Gnome::Canvas::CanvasAA::on_expose_event(event);
hegyi@27
     9
  //usleep(10000);
hegyi@27
    10
  //rezoom();
hegyi@27
    11
  return true;
hegyi@27
    12
}
hegyi@27
    13
hegyi@27
    14
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
hegyi@27
    15
{
hegyi@27
    16
  actual_handler.disconnect();
hegyi@27
    17
hegyi@27
    18
  if(actual_tool==CREATE_EDGE)
hegyi@27
    19
    {
hegyi@27
    20
	GdkEvent * generated=new GdkEvent();
hegyi@27
    21
	generated->type=GDK_BUTTON_RELEASE;
hegyi@27
    22
	generated->button.button=3;
hegyi@30
    23
	createEdgeEventHandler(generated);      
hegyi@27
    24
    }
hegyi@27
    25
hegyi@27
    26
  actual_tool=newtool;
hegyi@27
    27
hegyi@27
    28
  switch(newtool)
hegyi@27
    29
    {
hegyi@27
    30
    case MOVE:
hegyi@31
    31
      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
hegyi@27
    32
      break;
hegyi@27
    33
hegyi@27
    34
    case CREATE_NODE:
hegyi@30
    35
      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
hegyi@27
    36
      break;
hegyi@27
    37
hegyi@27
    38
    case CREATE_EDGE:
hegyi@31
    39
      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
hegyi@27
    40
      break;
hegyi@27
    41
hegyi@27
    42
    case ERASER:
hegyi@31
    43
      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
hegyi@27
    44
      break;
hegyi@27
    45
hegyi@27
    46
    default:
hegyi@27
    47
      break;
hegyi@27
    48
    }
hegyi@27
    49
}
hegyi@27
    50
hegyi@30
    51
int GraphDisplayerCanvas::getActualTool()
hegyi@27
    52
{
hegyi@27
    53
  return actual_tool;
hegyi@27
    54
}
hegyi@27
    55
hegyi@30
    56
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
hegyi@27
    57
{
hegyi@27
    58
  switch(e->type)
hegyi@27
    59
  {
hegyi@27
    60
    case GDK_BUTTON_PRESS:
hegyi@27
    61
      //we mark the location of the event to be able to calculate parameters of dragging
hegyi@31
    62
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
    63
hegyi@31
    64
      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@27
    65
      active_node=INVALID;
hegyi@27
    66
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@27
    67
	{
hegyi@27
    68
	  if(nodesmap[i]==active_item)
hegyi@27
    69
	    {
hegyi@27
    70
	      active_node=i;
hegyi@27
    71
	    }
hegyi@27
    72
	}
hegyi@27
    73
      switch(e->button.button)
hegyi@27
    74
	{
hegyi@27
    75
	case 3:      
hegyi@27
    76
	  isbutton=3;
hegyi@27
    77
	  break;
hegyi@27
    78
	default:
hegyi@27
    79
	  isbutton=1;
hegyi@27
    80
	  break;
hegyi@27
    81
	}
hegyi@27
    82
      break;
hegyi@27
    83
    case GDK_BUTTON_RELEASE:
hegyi@27
    84
      isbutton=0;
hegyi@27
    85
      active_item=NULL;
hegyi@27
    86
      active_node=INVALID;
hegyi@27
    87
      break;
hegyi@27
    88
    case GDK_MOTION_NOTIFY:
hegyi@27
    89
      //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@27
    90
      if(active_node!=INVALID)
hegyi@27
    91
      {
hegyi@27
    92
	//new coordinates will be the old values,
hegyi@27
    93
	//because the item will be moved to the
hegyi@27
    94
	//new coordinate therefore the new movement
hegyi@27
    95
	//has to be calculated from here
hegyi@27
    96
hegyi@31
    97
	double new_x, new_y;
hegyi@31
    98
hegyi@31
    99
	window_to_world (e->motion.x, e->motion.y, new_x, new_y);
hegyi@31
   100
hegyi@31
   101
        double dx=new_x-clicked_x;
hegyi@31
   102
        double dy=new_y-clicked_y;
hegyi@27
   103
hegyi@28
   104
	//repositioning node and its text
hegyi@27
   105
        active_item->move(dx, dy);
hegyi@28
   106
	nodetextmap[active_node]->move(dx, dy);
hegyi@27
   107
hegyi@31
   108
        clicked_x=new_x;
hegyi@31
   109
        clicked_y=new_y;
hegyi@27
   110
hegyi@27
   111
	//all the edges connected to the moved point has to be redrawn
hegyi@27
   112
        EdgeIt ei;
hegyi@27
   113
hegyi@27
   114
        g.firstOut(ei,active_node);
hegyi@27
   115
hegyi@27
   116
        for(;ei!=INVALID;g.nextOut(ei))
hegyi@27
   117
        {
hegyi@27
   118
            Gnome::Canvas::Points coos;
hegyi@27
   119
            double x1, x2, y1, y2;
hegyi@27
   120
hegyi@27
   121
            nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@27
   122
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@27
   123
hegyi@27
   124
            nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@27
   125
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@27
   126
hegyi@27
   127
	    if(isbutton==3)
hegyi@27
   128
	      {
hegyi@30
   129
		edgesmap[ei]->setPoints(coos);
hegyi@27
   130
	      }
hegyi@27
   131
	    else
hegyi@27
   132
	      {
hegyi@30
   133
		edgesmap[ei]->setPoints(coos,true);
hegyi@27
   134
	      }
hegyi@27
   135
hegyi@28
   136
	    //reposition of edgetext
hegyi@30
   137
	    xy<double> text_pos=edgesmap[ei]->getArrowPos();
hegyi@27
   138
	    text_pos+=(xy<double>(10,10));
hegyi@27
   139
	    edgetextmap[ei]->property_x().set_value(text_pos.x);
hegyi@27
   140
	    edgetextmap[ei]->property_y().set_value(text_pos.y);
hegyi@27
   141
        }
hegyi@27
   142
hegyi@27
   143
        g.firstIn(ei,active_node);
hegyi@27
   144
        for(;ei!=INVALID;g.nextIn(ei))
hegyi@27
   145
        {
hegyi@27
   146
            Gnome::Canvas::Points coos;
hegyi@27
   147
            double x1, x2, y1, y2;
hegyi@27
   148
hegyi@27
   149
            nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@27
   150
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@27
   151
hegyi@27
   152
            nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
hegyi@27
   153
            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@27
   154
hegyi@27
   155
	    if(isbutton==3)
hegyi@27
   156
	      {
hegyi@30
   157
		edgesmap[ei]->setPoints(coos);
hegyi@27
   158
	      }
hegyi@27
   159
	    else
hegyi@27
   160
	      {
hegyi@30
   161
		edgesmap[ei]->setPoints(coos,true);
hegyi@27
   162
	      }
hegyi@27
   163
hegyi@30
   164
	    xy<double> text_pos=edgesmap[ei]->getArrowPos();
hegyi@27
   165
	    text_pos+=(xy<double>(10,10));
hegyi@27
   166
	    edgetextmap[ei]->property_x().set_value(text_pos.x);
hegyi@27
   167
	    edgetextmap[ei]->property_y().set_value(text_pos.y);
hegyi@27
   168
        }
hegyi@27
   169
      }
hegyi@27
   170
    default: break;
hegyi@27
   171
  }
hegyi@27
   172
hegyi@31
   173
  return false;
hegyi@27
   174
}
hegyi@27
   175
hegyi@30
   176
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
hegyi@27
   177
{
hegyi@27
   178
  switch(e->type)
hegyi@27
   179
    {
hegyi@27
   180
hegyi@27
   181
      //draw the new node in red at the clicked place
hegyi@31
   182
    case GDK_2BUTTON_PRESS:
hegyi@31
   183
      std::cout << "double click" << std::endl;
hegyi@31
   184
      break;
hegyi@27
   185
    case GDK_BUTTON_PRESS:
hegyi@27
   186
      isbutton=1;
hegyi@27
   187
hegyi@27
   188
      active_node=NodeIt(g,g.addNode());
hegyi@27
   189
hegyi@27
   190
      //initiating values corresponding to new node in maps
hegyi@27
   191
hegyi@27
   192
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@27
   193
hegyi@31
   194
      target_item=NULL;
hegyi@31
   195
      target_item=get_item_at(clicked_x, clicked_y);
hegyi@31
   196
hegyi@27
   197
      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
hegyi@27
   198
      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
hegyi@27
   199
      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@27
   200
      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
hegyi@27
   201
      (nodesmap[active_node])->show();
hegyi@28
   202
hegyi@28
   203
      nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, "");
hegyi@28
   204
      nodetextmap[active_node]->property_fill_color().set_value("darkblue");
hegyi@28
   205
hegyi@30
   206
      mapwin->updateNode(active_node);
hegyi@28
   207
hegyi@27
   208
      break;
hegyi@27
   209
hegyi@27
   210
      //move the new node
hegyi@27
   211
    case GDK_MOTION_NOTIFY:
hegyi@27
   212
      {
hegyi@27
   213
	double world_motion_x, world_motion_y;
hegyi@27
   214
	GdkEvent * generated=new GdkEvent();
hegyi@31
   215
	generated->motion.x=e->motion.x;
hegyi@31
   216
	generated->motion.y=e->motion.y;
hegyi@27
   217
	generated->type=GDK_MOTION_NOTIFY;
hegyi@30
   218
	moveEventHandler(generated);      
hegyi@27
   219
	break;
hegyi@27
   220
      }
hegyi@27
   221
hegyi@27
   222
      //finalize the new node
hegyi@27
   223
    case GDK_BUTTON_RELEASE:
hegyi@27
   224
      isbutton=0;
hegyi@31
   225
      if(!target_item)
hegyi@31
   226
	{
hegyi@31
   227
	  //Its appropriate color is given by update.
hegyi@31
   228
	  //*active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@31
   229
	}
hegyi@31
   230
      else
hegyi@31
   231
	{
hegyi@31
   232
	  //In this case the given color has to be overwritten, because the noe covers an other item.
hegyi@31
   233
	  *active_item << Gnome::Canvas::Properties::fill_color("lightblue");
hegyi@31
   234
	}
hegyi@31
   235
      target_item=NULL;
hegyi@27
   236
      active_item=NULL;
hegyi@27
   237
      active_node=INVALID;
hegyi@27
   238
      break;
hegyi@27
   239
    default:
hegyi@27
   240
      break;
hegyi@27
   241
    }
hegyi@27
   242
  return false;
hegyi@27
   243
}
hegyi@27
   244
hegyi@30
   245
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
hegyi@27
   246
{
hegyi@27
   247
  switch(e->type)
hegyi@27
   248
    {
hegyi@27
   249
    case GDK_BUTTON_PRESS:
hegyi@27
   250
      //in edge creation right button has special meaning
hegyi@27
   251
      if(e->button.button!=3)
hegyi@27
   252
	{
hegyi@27
   253
	  //there is not yet selected node
hegyi@27
   254
	  if(active_node==INVALID)
hegyi@27
   255
	    {
hegyi@27
   256
	      //we mark the location of the event to be able to calculate parameters of dragging
hegyi@31
   257
hegyi@31
   258
	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   259
hegyi@31
   260
	      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@27
   261
	      active_node=INVALID;
hegyi@27
   262
	      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@27
   263
		{
hegyi@27
   264
		  if(nodesmap[i]==active_item)
hegyi@27
   265
		    {
hegyi@27
   266
		      active_node=i;
hegyi@27
   267
		    }
hegyi@27
   268
		}
hegyi@27
   269
	      //the clicked item is really a node
hegyi@27
   270
	      if(active_node!=INVALID)
hegyi@27
   271
		{
hegyi@27
   272
		  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@27
   273
		  isbutton=1;
hegyi@27
   274
		}
hegyi@27
   275
	      //clicked item was not a node. It could be e.g. edge.
hegyi@27
   276
	      else
hegyi@27
   277
		{
hegyi@27
   278
		  active_item=NULL;
hegyi@27
   279
		}
hegyi@27
   280
	    }
hegyi@27
   281
	  //we only have to do sg. if the mouse button
hegyi@27
   282
	  // is pressed already once AND the click was
hegyi@27
   283
	  // on a node that was found in the set of 
hegyi@27
   284
	  //nodes, and now we only search for the second 
hegyi@27
   285
	  //node
hegyi@27
   286
	  else
hegyi@27
   287
	    {
hegyi@31
   288
	      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   289
	      target_item=(get_item_at(clicked_x, clicked_y));
hegyi@27
   290
	      Graph::NodeIt target_node=INVALID;
hegyi@27
   291
	      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@27
   292
		{
hegyi@27
   293
		  if(nodesmap[i]==target_item)
hegyi@27
   294
		    {
hegyi@27
   295
		      target_node=i;
hegyi@27
   296
		    }
hegyi@27
   297
		}
hegyi@27
   298
	      //the clicked item is a node, the edge can be drawn
hegyi@27
   299
	      if(target_node!=INVALID)
hegyi@27
   300
		{
hegyi@28
   301
		  if(target_node!=active_node)		
hegyi@28
   302
		    {
hegyi@28
   303
		      *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
hegyi@27
   304
hegyi@28
   305
		      //creating new edge
hegyi@28
   306
		      active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
hegyi@27
   307
hegyi@28
   308
		      //initiating values corresponding to new edge in maps
hegyi@30
   309
		      mapstorage.initMapsForEdge(active_edge);
hegyi@27
   310
	  
hegyi@28
   311
		      //calculating coordinates of new edge
hegyi@28
   312
		      Gnome::Canvas::Points coos;
hegyi@28
   313
		      double x1, x2, y1, y2;
hegyi@27
   314
	  
hegyi@28
   315
		      active_item->get_bounds(x1, y1, x2, y2);
hegyi@28
   316
		      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@27
   317
hegyi@28
   318
		      target_item->get_bounds(x1, y1, x2, y2);
hegyi@28
   319
		      coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
hegyi@27
   320
hegyi@28
   321
		      //drawing new edge
hegyi@28
   322
		      edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
hegyi@28
   323
		      *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
hegyi@28
   324
		      edgesmap[active_edge]->property_width_pixels().set_value(10);
hegyi@27
   325
hegyi@28
   326
		      //redraw nodes to blank terminations of the new edge
hegyi@28
   327
		      target_item->raise_to_top();
hegyi@28
   328
		      active_item->raise_to_top();
hegyi@27
   329
hegyi@28
   330
		      //initializing edge-text as well, to empty string
hegyi@30
   331
		      xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
hegyi@28
   332
		      text_pos+=(xy<double>(10,10));
hegyi@27
   333
hegyi@28
   334
		      edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
hegyi@28
   335
		      edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
hegyi@28
   336
hegyi@28
   337
		      //updating its properties
hegyi@30
   338
		      mapwin->updateEdge(active_edge);
hegyi@28
   339
		    }
hegyi@28
   340
		  else
hegyi@28
   341
		    {
hegyi@28
   342
		      target_node=INVALID;
hegyi@28
   343
		      std::cout << "Loop edge is not yet implemented!" << std::endl;
hegyi@28
   344
		    }
hegyi@27
   345
		}
hegyi@27
   346
	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
hegyi@27
   347
	      else
hegyi@27
   348
		{
hegyi@27
   349
		  target_item=NULL;
hegyi@27
   350
		}
hegyi@27
   351
	    }
hegyi@27
   352
	}
hegyi@27
   353
      break;
hegyi@27
   354
    case GDK_BUTTON_RELEASE:
hegyi@27
   355
      isbutton=0;
hegyi@27
   356
      //we clear settings in two cases
hegyi@27
   357
      //1: the edge is ready (target_item has valid value)
hegyi@27
   358
      //2: the edge creation is cancelled with right button
hegyi@27
   359
      if((target_item)||(e->button.button==3))
hegyi@27
   360
	{
hegyi@27
   361
	  if(active_item)
hegyi@27
   362
	    {
hegyi@27
   363
	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@27
   364
	      active_item=NULL;
hegyi@27
   365
	    }
hegyi@27
   366
	  if(target_item)
hegyi@27
   367
	    {
hegyi@27
   368
	      *target_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@27
   369
	      target_item=NULL;
hegyi@27
   370
	    }
hegyi@27
   371
	  active_node=INVALID;
hegyi@27
   372
	  active_edge=INVALID;
hegyi@27
   373
	}
hegyi@27
   374
      break;
hegyi@27
   375
    default:
hegyi@27
   376
      break;
hegyi@27
   377
    }
hegyi@27
   378
  return false;
hegyi@27
   379
}
hegyi@27
   380
hegyi@30
   381
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
hegyi@27
   382
{
hegyi@27
   383
  switch(e->type)
hegyi@27
   384
    {
hegyi@27
   385
    case GDK_BUTTON_PRESS:
hegyi@31
   386
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   387
      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@27
   388
      active_node=INVALID;
hegyi@27
   389
      active_edge=INVALID;
hegyi@27
   390
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@27
   391
	{
hegyi@27
   392
	  if(nodesmap[i]==active_item)
hegyi@27
   393
	    {
hegyi@27
   394
	      active_node=i;
hegyi@27
   395
	    }
hegyi@27
   396
	}
hegyi@27
   397
      if(active_node==INVALID)
hegyi@27
   398
	{
hegyi@27
   399
	  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@27
   400
	    {
hegyi@27
   401
	      if(edgesmap[i]==active_item)
hegyi@27
   402
		{
hegyi@27
   403
		  active_edge=i;
hegyi@27
   404
		}
hegyi@27
   405
	    }
hegyi@27
   406
	}
hegyi@31
   407
      if(active_item)
hegyi@31
   408
	{
hegyi@31
   409
	  *active_item << Gnome::Canvas::Properties::fill_color("red");
hegyi@31
   410
	}
hegyi@27
   411
      break;
hegyi@27
   412
hegyi@27
   413
    case GDK_BUTTON_RELEASE:
hegyi@31
   414
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   415
      if(active_item)
hegyi@27
   416
	{
hegyi@31
   417
	  if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
hegyi@27
   418
	    {
hegyi@31
   419
	      if(active_node!=INVALID)
hegyi@31
   420
		{
hegyi@27
   421
hegyi@31
   422
		  //collecting edges to delete
hegyi@31
   423
		  EdgeIt e;
hegyi@31
   424
		  std::set<Graph::Edge> edges_to_delete;
hegyi@27
   425
hegyi@31
   426
		  g.firstOut(e,active_node);
hegyi@31
   427
		  for(;e!=INVALID;g.nextOut(e))
hegyi@31
   428
		    {
hegyi@31
   429
		      edges_to_delete.insert(e);
hegyi@31
   430
		    }
hegyi@31
   431
hegyi@31
   432
		  g.firstIn(e,active_node);
hegyi@31
   433
		  for(;e!=INVALID;g.nextIn(e))
hegyi@31
   434
		    {
hegyi@31
   435
		      edges_to_delete.insert(e);
hegyi@31
   436
		    }
hegyi@31
   437
hegyi@31
   438
		  //deleting collected edges
hegyi@31
   439
		  for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
hegyi@31
   440
		    {
hegyi@31
   441
		      deleteItem(*edge_set_it);
hegyi@31
   442
		    }
hegyi@31
   443
		  deleteItem(active_node);
hegyi@31
   444
		}
hegyi@31
   445
	      //a simple edge was chosen
hegyi@31
   446
	      else
hegyi@27
   447
		{
hegyi@31
   448
		  deleteItem(active_edge);
hegyi@27
   449
		}
hegyi@27
   450
	    }
hegyi@31
   451
	  //pointer was moved, deletion is cancelled
hegyi@27
   452
	  else
hegyi@27
   453
	    {
hegyi@31
   454
	      if(active_node!=INVALID)
hegyi@31
   455
		{
hegyi@31
   456
		  *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@31
   457
		}
hegyi@31
   458
	      else
hegyi@31
   459
		{
hegyi@31
   460
		  *active_item << Gnome::Canvas::Properties::fill_color("green");
hegyi@31
   461
		}
hegyi@27
   462
	    }
hegyi@27
   463
	}
hegyi@27
   464
      //reseting datas
hegyi@27
   465
      active_item=NULL;
hegyi@27
   466
      active_edge=INVALID;
hegyi@27
   467
      active_node=INVALID;
hegyi@27
   468
      break;
hegyi@27
   469
hegyi@27
   470
    case GDK_MOTION_NOTIFY:
hegyi@27
   471
      break;
hegyi@27
   472
hegyi@27
   473
    default:
hegyi@27
   474
      break;
hegyi@27
   475
    }
hegyi@31
   476
  return false;
hegyi@27
   477
}
hegyi@27
   478
hegyi@30
   479
void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete)
hegyi@27
   480
{
hegyi@28
   481
  delete(nodetextmap[node_to_delete]);
hegyi@27
   482
  delete(nodesmap[node_to_delete]);
hegyi@27
   483
  g.erase(node_to_delete);
hegyi@27
   484
}
hegyi@27
   485
hegyi@30
   486
void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
hegyi@27
   487
{
hegyi@28
   488
  delete(edgetextmap[edge_to_delete]);
hegyi@27
   489
  delete(edgesmap[edge_to_delete]);
hegyi@27
   490
  g.erase(edge_to_delete);
hegyi@27
   491
}
hegyi@27
   492
hegyi@30
   493
void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
hegyi@27
   494
{
hegyi@28
   495
  delete(edgetextmap[edge_to_delete]);
hegyi@27
   496
  delete(edgesmap[edge_to_delete]);
hegyi@27
   497
  g.erase(edge_to_delete);
hegyi@27
   498
}
hegyi@27
   499
hegyi@30
   500
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
hegyi@27
   501
{
hegyi@27
   502
  new_place+=(xy<double>(10,10));
hegyi@27
   503
  edgetextmap[active_edge]->property_x().set_value(new_place.x);
hegyi@27
   504
  edgetextmap[active_edge]->property_y().set_value(new_place.y);
hegyi@27
   505
}
hegyi@27
   506
hegyi@30
   507
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
hegyi@27
   508
{
hegyi@27
   509
  if(on)
hegyi@27
   510
    {
hegyi@27
   511
      if(active_edge!=INVALID)
hegyi@27
   512
	{
hegyi@27
   513
	  std::cout << "ERROR!!!! Valid edge found!" << std::endl;
hegyi@27
   514
	}
hegyi@27
   515
      else
hegyi@27
   516
	{
hegyi@27
   517
	  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@27
   518
	    {
hegyi@27
   519
	      if(edgesmap[i]==active_bre)
hegyi@27
   520
		{
hegyi@27
   521
		  active_edge=i;
hegyi@27
   522
		}
hegyi@27
   523
	    }
hegyi@27
   524
	}
hegyi@27
   525
    }
hegyi@27
   526
  else
hegyi@27
   527
    {
hegyi@27
   528
      if(active_edge!=INVALID)
hegyi@27
   529
	{
hegyi@27
   530
	  active_edge=INVALID;
hegyi@27
   531
	}
hegyi@27
   532
      else
hegyi@27
   533
	{
hegyi@27
   534
	  std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
hegyi@27
   535
	}
hegyi@27
   536
    }
hegyi@27
   537
hegyi@27
   538
}