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