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