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