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