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