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