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