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