graph_displayer_canvas-event.cc
author hegyi
Tue, 27 Feb 2007 17:23:55 +0000
changeset 192 9d7489e8921e
parent 179 1f436ea3ef4f
child 194 6b2b718420eb
child 204 8fec6a6472fe
permissions -rwxr-xr-x
Forgot the meat.
alpar@174
     1
/* -*- C++ -*-
alpar@174
     2
 *
alpar@174
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@174
     4
 *
alpar@174
     5
 * Copyright (C) 2003-2006
alpar@174
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@174
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@174
     8
 *
alpar@174
     9
 * Permission to use, modify and distribute this software is granted
alpar@174
    10
 * provided that this copyright notice appears in all copies. For
alpar@174
    11
 * precise terms see the accompanying LICENSE file.
alpar@174
    12
 *
alpar@174
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@174
    14
 * express or implied, and with no claim as to its suitability for any
alpar@174
    15
 * purpose.
alpar@174
    16
 *
alpar@174
    17
 */
alpar@174
    18
ladanyi@53
    19
#include "graph_displayer_canvas.h"
alpar@59
    20
#include <cmath>
hegyi@27
    21
hegyi@27
    22
hegyi@27
    23
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
hegyi@27
    24
{
hegyi@27
    25
  Gnome::Canvas::CanvasAA::on_expose_event(event);
hegyi@27
    26
  //usleep(10000);
hegyi@27
    27
  //rezoom();
hegyi@27
    28
  return true;
hegyi@27
    29
}
hegyi@27
    30
hegyi@27
    31
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
hegyi@27
    32
{
hegyi@34
    33
  if(actual_tool!=newtool)
hegyi@34
    34
    {
hegyi@27
    35
hegyi@34
    36
      actual_handler.disconnect();
hegyi@27
    37
hegyi@34
    38
      switch(actual_tool)
hegyi@34
    39
	{
hegyi@34
    40
	case CREATE_EDGE:
hegyi@34
    41
	  {
hegyi@34
    42
	    GdkEvent * generated=new GdkEvent();
hegyi@34
    43
	    generated->type=GDK_BUTTON_RELEASE;
hegyi@34
    44
	    generated->button.button=3;
hegyi@34
    45
	    createEdgeEventHandler(generated);      
hegyi@34
    46
	    break;
hegyi@34
    47
	  }
hegyi@149
    48
	case MAP_EDIT:
hegyi@35
    49
	  {
hegyi@35
    50
	    break;
hegyi@35
    51
	  }
hegyi@34
    52
	default:
hegyi@34
    53
	  break;
hegyi@34
    54
	}
hegyi@27
    55
hegyi@34
    56
      active_item=NULL; 
hegyi@34
    57
      target_item=NULL; 
hegyi@34
    58
      active_edge=INVALID;	
hegyi@34
    59
      active_node=INVALID;	
hegyi@33
    60
hegyi@27
    61
hegyi@34
    62
      actual_tool=newtool;
hegyi@34
    63
  
hegyi@34
    64
      switch(newtool)
hegyi@34
    65
	{
hegyi@34
    66
	case MOVE:
hegyi@34
    67
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
hegyi@34
    68
	  break;
hegyi@27
    69
hegyi@34
    70
	case CREATE_NODE:
hegyi@34
    71
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
hegyi@34
    72
	  break;
hegyi@27
    73
hegyi@34
    74
	case CREATE_EDGE:
hegyi@34
    75
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
hegyi@34
    76
	  break;
hegyi@27
    77
hegyi@34
    78
	case ERASER:
hegyi@34
    79
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
hegyi@34
    80
	  break;
hegyi@32
    81
hegyi@149
    82
	case MAP_EDIT:
hegyi@34
    83
	  grab_focus();
hegyi@149
    84
	  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
hegyi@34
    85
	  break;
hegyi@34
    86
hegyi@34
    87
	default:
hegyi@34
    88
	  break;
hegyi@34
    89
	}
hegyi@27
    90
    }
hegyi@27
    91
}
hegyi@27
    92
hegyi@30
    93
int GraphDisplayerCanvas::getActualTool()
hegyi@27
    94
{
hegyi@27
    95
  return actual_tool;
hegyi@27
    96
}
hegyi@27
    97
hegyi@187
    98
bool GraphDisplayerCanvas::scrollEventHandler(GdkEvent* e)
hegyi@187
    99
{
hegyi@187
   100
  bool handled=false;
hegyi@187
   101
  if(e->type==GDK_SCROLL)
hegyi@187
   102
    {
hegyi@187
   103
hegyi@187
   104
      //pointer shows this win point before zoom
hegyi@187
   105
      XY win_coord(((GdkEventScroll*)e)->x, ((GdkEventScroll*)e)->y);
hegyi@187
   106
hegyi@187
   107
      //the original scroll settings
hegyi@187
   108
      int scroll_offset_x, scroll_offset_y;
hegyi@187
   109
      get_scroll_offsets(scroll_offset_x, scroll_offset_y);
hegyi@187
   110
hegyi@187
   111
      //pointer shows this canvas point before zoom
hegyi@187
   112
      XY canvas_coord;
hegyi@187
   113
      window_to_world(win_coord.x, win_coord.y, canvas_coord.x, canvas_coord.y);
hegyi@187
   114
hegyi@187
   115
      if(((GdkEventScroll*)e)->direction) //IN
hegyi@187
   116
	{
hegyi@187
   117
	  zoomIn();
hegyi@187
   118
	}
hegyi@187
   119
      else
hegyi@187
   120
	{
hegyi@187
   121
	  zoomOut();
hegyi@187
   122
	}
hegyi@187
   123
hegyi@187
   124
      //pointer shows this window point after zoom
hegyi@187
   125
      XY post_win_coord;
hegyi@187
   126
      world_to_window(canvas_coord.x, canvas_coord.y, post_win_coord.x, post_win_coord.y);
hegyi@187
   127
hegyi@187
   128
      //we have to add the difference between new and old window point to original scroll offset
hegyi@187
   129
      scroll_to(scroll_offset_x+(int)(post_win_coord.x-win_coord.x),scroll_offset_y+(int)(post_win_coord.y-win_coord.y));
hegyi@187
   130
      
hegyi@187
   131
      //no other eventhandler is needed
hegyi@187
   132
      handled=true;
hegyi@187
   133
    }
hegyi@187
   134
  return handled;
hegyi@187
   135
}
hegyi@187
   136
hegyi@30
   137
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
hegyi@27
   138
{
ladanyi@70
   139
  static Gnome::Canvas::Text *coord_text = 0;
hegyi@27
   140
  switch(e->type)
hegyi@160
   141
    {
hegyi@27
   142
    case GDK_BUTTON_PRESS:
hegyi@27
   143
      //we mark the location of the event to be able to calculate parameters of dragging
hegyi@31
   144
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@160
   145
      
hegyi@31
   146
      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@27
   147
      active_node=INVALID;
hegyi@96
   148
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@27
   149
	{
hegyi@27
   150
	  if(nodesmap[i]==active_item)
hegyi@27
   151
	    {
hegyi@27
   152
	      active_node=i;
hegyi@27
   153
	    }
hegyi@27
   154
	}
hegyi@148
   155
      isbutton=e->button.button;
hegyi@27
   156
      break;
hegyi@27
   157
    case GDK_BUTTON_RELEASE:
ladanyi@70
   158
      if (coord_text)
hegyi@160
   159
	{
hegyi@160
   160
	  delete coord_text;
hegyi@160
   161
	  coord_text = 0;
hegyi@160
   162
	}
hegyi@27
   163
      isbutton=0;
hegyi@27
   164
      active_item=NULL;
hegyi@27
   165
      active_node=INVALID;
hegyi@27
   166
      break;
hegyi@27
   167
    case GDK_MOTION_NOTIFY:
hegyi@27
   168
      //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
   169
      if(active_node!=INVALID)
hegyi@160
   170
	{
hegyi@160
   171
	  (mytab.mapstorage).modified = true;
hegyi@160
   172
	  
hegyi@160
   173
	  //new coordinates will be the old values,
hegyi@160
   174
	  //because the item will be moved to the
hegyi@160
   175
	  //new coordinate therefore the new movement
hegyi@160
   176
	  //has to be calculated from here
hegyi@160
   177
	  
hegyi@160
   178
	  double new_x, new_y;
hegyi@160
   179
	  
hegyi@160
   180
	  window_to_world (e->motion.x, e->motion.y, new_x, new_y);
hegyi@160
   181
	  
hegyi@160
   182
	  double dx=new_x-clicked_x;
hegyi@160
   183
	  double dy=new_y-clicked_y;
hegyi@160
   184
	  
hegyi@160
   185
	  moveNode(dx, dy);
ladanyi@70
   186
hegyi@160
   187
	  clicked_x=new_x;
hegyi@160
   188
	  clicked_y=new_y;
hegyi@27
   189
hegyi@160
   190
	  // reposition the coordinates text
hegyi@160
   191
	  std::ostringstream ostr;
hegyi@160
   192
	  ostr << "(" <<
hegyi@160
   193
	    (mytab.mapstorage).coords[active_node].x << ", " <<
hegyi@160
   194
	    (mytab.mapstorage).coords[active_node].y << ")";
hegyi@160
   195
	  double radius =
hegyi@160
   196
	    (nodesmap[active_node]->property_x2().get_value() -
hegyi@160
   197
	     nodesmap[active_node]->property_x1().get_value()) / 2.0;
hegyi@160
   198
	  if (coord_text)
hegyi@160
   199
	    {
hegyi@160
   200
	      coord_text->property_text().set_value(ostr.str());
hegyi@160
   201
	      coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x +
hegyi@160
   202
						 radius);
hegyi@160
   203
	      coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y -
hegyi@160
   204
						 radius);
hegyi@160
   205
	    }
hegyi@160
   206
	  else
hegyi@160
   207
	    {
hegyi@160
   208
	      coord_text = new Gnome::Canvas::Text(
hegyi@160
   209
						   displayed_graph,
hegyi@160
   210
						   (mytab.mapstorage).coords[active_node].x + radius,
hegyi@160
   211
						   (mytab.mapstorage).coords[active_node].y - radius,
hegyi@160
   212
						   ostr.str());
hegyi@160
   213
	      coord_text->property_fill_color().set_value("black");
hegyi@160
   214
	      coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
hegyi@160
   215
	    }
hegyi@31
   216
hegyi@31
   217
hegyi@160
   218
	}
hegyi@160
   219
    default: break;
hegyi@160
   220
    }
hegyi@27
   221
hegyi@160
   222
return false;
hegyi@27
   223
}
hegyi@27
   224
hegyi@148
   225
XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code)
ladanyi@98
   226
{
hegyi@148
   227
  switch(move_code)
hegyi@148
   228
    {
hegyi@148
   229
    case 1:
hegyi@148
   230
      return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
hegyi@148
   231
      break;
hegyi@148
   232
    case 2:
hegyi@148
   233
      return old_arrow_pos;
hegyi@148
   234
      break;
hegyi@148
   235
    case 3:
hegyi@148
   236
      {
hegyi@148
   237
	//////////////////////////////////////////////////////////////////////////////////////////////////////
hegyi@148
   238
	/////////// keeps shape-with scalar multiplication - version 2.
hegyi@148
   239
	//////////////////////////////////////////////////////////////////////////////////////////////////////
ladanyi@98
   240
hegyi@148
   241
	//old vector from one to the other node - a
hegyi@150
   242
	XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
hegyi@148
   243
	//new vector from one to the other node - b
hegyi@150
   244
	XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
ladanyi@98
   245
hegyi@148
   246
	double absa=sqrt(a_v.normSquare());
hegyi@148
   247
	double absb=sqrt(b_v.normSquare());
ladanyi@98
   248
hegyi@148
   249
	if ((absa == 0.0) || (absb == 0.0))
hegyi@148
   250
	  {
hegyi@148
   251
	    return old_arrow_pos;
hegyi@148
   252
	  }
hegyi@148
   253
	else
hegyi@148
   254
	  {
hegyi@148
   255
	    //old vector from one node to the breakpoint - c
hegyi@150
   256
	    XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
hegyi@148
   257
hegyi@148
   258
	    //unit vector with the same direction to a_v
hegyi@150
   259
	    XY a_v_u(a_v.x/absa,a_v.y/absa);
hegyi@148
   260
hegyi@148
   261
	    //normal vector of unit vector with the same direction to a_v
hegyi@150
   262
	    XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
hegyi@148
   263
hegyi@148
   264
	    //unit vector with the same direction to b_v
hegyi@150
   265
	    XY b_v_u(b_v.x/absb,b_v.y/absb);
hegyi@148
   266
hegyi@148
   267
	    //normal vector of unit vector with the same direction to b_v
hegyi@150
   268
	    XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
hegyi@148
   269
hegyi@148
   270
	    //vector c in a_v_u and a_v_u_n co-ordinate system
hegyi@150
   271
	    XY c_a(c_v*a_v_u,c_v*a_v_u_n);
hegyi@148
   272
hegyi@148
   273
	    //new vector from one node to the breakpoint - d - we have to calculate this one
hegyi@150
   274
	    XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
hegyi@148
   275
hegyi@148
   276
	    return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
hegyi@148
   277
	  }
hegyi@148
   278
	break;
hegyi@148
   279
      }
hegyi@148
   280
    default:
hegyi@148
   281
      break;
ladanyi@98
   282
    }
hegyi@148
   283
}
ladanyi@98
   284
ladanyi@98
   285
hegyi@30
   286
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
hegyi@27
   287
{
hegyi@27
   288
  switch(e->type)
ladanyi@63
   289
  {
ladanyi@63
   290
    //move the new node
ladanyi@63
   291
    case GDK_MOTION_NOTIFY:
ladanyi@63
   292
      {
ladanyi@63
   293
        GdkEvent * generated=new GdkEvent();
ladanyi@63
   294
        generated->motion.x=e->motion.x;
ladanyi@63
   295
        generated->motion.y=e->motion.y;
ladanyi@63
   296
        generated->type=GDK_MOTION_NOTIFY;
ladanyi@63
   297
        moveEventHandler(generated);      
ladanyi@63
   298
        break;
ladanyi@63
   299
      }
hegyi@27
   300
ladanyi@63
   301
    case GDK_BUTTON_RELEASE:
hegyi@96
   302
      (mytab.mapstorage).modified = true;
ladanyi@53
   303
hegyi@178
   304
      is_drawn=true;
hegyi@178
   305
hegyi@27
   306
      isbutton=1;
hegyi@27
   307
hegyi@96
   308
      active_node=(mytab.mapstorage).graph.addNode();
hegyi@27
   309
hegyi@27
   310
      //initiating values corresponding to new node in maps
hegyi@27
   311
hegyi@27
   312
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@27
   313
ladanyi@63
   314
      // update coordinates
hegyi@150
   315
      (mytab.mapstorage).coords.set(active_node, XY(clicked_x, clicked_y));
ladanyi@63
   316
ladanyi@63
   317
      // update all other maps
ladanyi@63
   318
      for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
hegyi@96
   319
          (mytab.mapstorage).nodemap_storage.begin(); it !=
hegyi@96
   320
          (mytab.mapstorage).nodemap_storage.end(); ++it)
ladanyi@63
   321
      {
ladanyi@64
   322
        if ((it->first != "coordinates_x") &&
ladanyi@64
   323
            (it->first != "coordinates_y"))
ladanyi@63
   324
        {
ladanyi@63
   325
          (*(it->second))[active_node] =
hegyi@96
   326
            (mytab.mapstorage).nodemap_default[it->first];
ladanyi@63
   327
        }
ladanyi@63
   328
      }
ladanyi@64
   329
      // increment the id map's default value
ladanyi@134
   330
      (mytab.mapstorage).nodemap_default["label"] += 1.0;
ladanyi@63
   331
ladanyi@53
   332
      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
ladanyi@63
   333
          clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
hegyi@27
   334
      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
ladanyi@63
   335
      *(nodesmap[active_node]) <<
ladanyi@63
   336
        Gnome::Canvas::Properties::fill_color("blue");
ladanyi@63
   337
      *(nodesmap[active_node]) <<
ladanyi@63
   338
        Gnome::Canvas::Properties::outline_color("black");
ladanyi@63
   339
      active_item->raise_to_top();
ladanyi@63
   340
hegyi@27
   341
      (nodesmap[active_node])->show();
hegyi@28
   342
ladanyi@53
   343
      nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
ladanyi@63
   344
          clicked_x+node_property_defaults[N_RADIUS]+5,
ladanyi@63
   345
          clicked_y+node_property_defaults[N_RADIUS]+5, "");
hegyi@28
   346
      nodetextmap[active_node]->property_fill_color().set_value("darkblue");
ladanyi@63
   347
      nodetextmap[active_node]->raise_to_top();
hegyi@28
   348
hegyi@94
   349
//       mapwin.updateNode(active_node);
hegyi@94
   350
      propertyUpdate(active_node);
hegyi@28
   351
hegyi@27
   352
      isbutton=0;
hegyi@31
   353
      target_item=NULL;
hegyi@27
   354
      active_item=NULL;
hegyi@27
   355
      active_node=INVALID;
hegyi@27
   356
      break;
hegyi@27
   357
    default:
hegyi@27
   358
      break;
ladanyi@63
   359
  }
hegyi@27
   360
  return false;
hegyi@27
   361
}
hegyi@27
   362
hegyi@30
   363
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
hegyi@27
   364
{
hegyi@27
   365
  switch(e->type)
ladanyi@63
   366
  {
hegyi@27
   367
    case GDK_BUTTON_PRESS:
hegyi@27
   368
      //in edge creation right button has special meaning
hegyi@27
   369
      if(e->button.button!=3)
ladanyi@63
   370
      {
ladanyi@63
   371
        //there is not yet selected node
ladanyi@63
   372
        if(active_node==INVALID)
ladanyi@63
   373
        {
ladanyi@63
   374
          //we mark the location of the event to be able to calculate parameters of dragging
hegyi@31
   375
ladanyi@63
   376
          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   377
ladanyi@63
   378
          active_item=(get_item_at(clicked_x, clicked_y));
ladanyi@63
   379
          active_node=INVALID;
hegyi@96
   380
          for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
ladanyi@63
   381
          {
ladanyi@63
   382
            if(nodesmap[i]==active_item)
ladanyi@63
   383
            {
ladanyi@63
   384
              active_node=i;
ladanyi@63
   385
            }
ladanyi@63
   386
          }
ladanyi@63
   387
          //the clicked item is really a node
ladanyi@63
   388
          if(active_node!=INVALID)
ladanyi@63
   389
          {
ladanyi@63
   390
            *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
ladanyi@63
   391
            isbutton=1;
ladanyi@63
   392
          }
ladanyi@63
   393
          //clicked item was not a node. It could be e.g. edge.
ladanyi@63
   394
          else
ladanyi@63
   395
          {
ladanyi@63
   396
            active_item=NULL;
ladanyi@63
   397
          }
ladanyi@63
   398
        }
ladanyi@63
   399
        //we only have to do sg. if the mouse button
ladanyi@63
   400
        // is pressed already once AND the click was
ladanyi@63
   401
        // on a node that was found in the set of 
ladanyi@63
   402
        //nodes, and now we only search for the second 
ladanyi@63
   403
        //node
ladanyi@63
   404
        else
ladanyi@63
   405
        {
ladanyi@63
   406
          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
ladanyi@63
   407
          target_item=(get_item_at(clicked_x, clicked_y));
ladanyi@63
   408
          Node target_node=INVALID;
hegyi@96
   409
          for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
ladanyi@63
   410
          {
ladanyi@63
   411
            if(nodesmap[i]==target_item)
ladanyi@63
   412
            {
ladanyi@63
   413
              target_node=i;
ladanyi@63
   414
            }
ladanyi@63
   415
          }
ladanyi@63
   416
          //the clicked item is a node, the edge can be drawn
ladanyi@63
   417
          if(target_node!=INVALID)
ladanyi@63
   418
          {
ladanyi@151
   419
            (mytab.mapstorage).modified = true;
ladanyi@151
   420
ladanyi@151
   421
            *(nodesmap[target_node]) <<
ladanyi@151
   422
              Gnome::Canvas::Properties::fill_color("red");
ladanyi@151
   423
ladanyi@151
   424
            //creating new edge
ladanyi@151
   425
            active_edge=(mytab.mapstorage).graph.addEdge(active_node,
ladanyi@151
   426
                target_node);
ladanyi@151
   427
ladanyi@151
   428
            // update maps
ladanyi@151
   429
            for (std::map<std::string,
ladanyi@151
   430
                Graph::EdgeMap<double>*>::const_iterator it =
ladanyi@151
   431
                (mytab.mapstorage).edgemap_storage.begin(); it !=
ladanyi@151
   432
                (mytab.mapstorage).edgemap_storage.end(); ++it)
ladanyi@151
   433
            {
ladanyi@151
   434
              (*(it->second))[active_edge] =
ladanyi@151
   435
                (mytab.mapstorage).edgemap_default[it->first];
ladanyi@151
   436
            }
ladanyi@151
   437
            // increment the id map's default value
ladanyi@151
   438
            (mytab.mapstorage).edgemap_default["label"] += 1.0;
ladanyi@151
   439
ladanyi@63
   440
            if(target_node!=active_node)		
ladanyi@63
   441
            {
ladanyi@113
   442
              // set the coordinates of the arrow on the new edge
ladanyi@113
   443
              MapStorage& ms = mytab.mapstorage;
ladanyi@113
   444
              ms.arrow_pos.set(active_edge,
ladanyi@113
   445
                  (ms.coords[ms.graph.source(active_edge)] +
ladanyi@113
   446
                   ms.coords[ms.graph.target(active_edge)])/ 2.0);
ladanyi@113
   447
ladanyi@63
   448
              //drawing new edge
ladanyi@98
   449
              edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
ladanyi@63
   450
                  *this);
ladanyi@63
   451
            }
ladanyi@63
   452
            else
ladanyi@63
   453
            {
ladanyi@151
   454
              // set the coordinates of the arrow on the new edge
ladanyi@151
   455
              MapStorage& ms = mytab.mapstorage;
ladanyi@151
   456
              ms.arrow_pos.set(active_edge,
ladanyi@151
   457
                  (ms.coords[ms.graph.source(active_edge)] +
ladanyi@151
   458
                   XY(0.0, 80.0)));
ladanyi@151
   459
ladanyi@151
   460
              //drawing new edge
ladanyi@151
   461
              edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge,
ladanyi@151
   462
                  *this);
ladanyi@63
   463
            }
ladanyi@151
   464
ladanyi@151
   465
            //initializing edge-text as well, to empty string
ladanyi@151
   466
            XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
ladanyi@151
   467
            text_pos+=(XY(10,10));
ladanyi@151
   468
ladanyi@151
   469
            edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
ladanyi@151
   470
                text_pos.x, text_pos.y, "");
ladanyi@151
   471
            edgetextmap[active_edge]->property_fill_color().set_value(
ladanyi@151
   472
                "darkgreen");
ladanyi@151
   473
            edgetextmap[active_edge]->raise_to_top();
ladanyi@151
   474
ladanyi@151
   475
            propertyUpdate(active_edge);
ladanyi@63
   476
          }
ladanyi@63
   477
          //clicked item was not a node. it could be an e.g. edge. we do not
ladanyi@63
   478
          //deal with it furthermore.
ladanyi@63
   479
          else
ladanyi@63
   480
          {
ladanyi@63
   481
            target_item=NULL;
ladanyi@63
   482
          }
ladanyi@63
   483
        }
ladanyi@63
   484
      }
hegyi@27
   485
      break;
hegyi@27
   486
    case GDK_BUTTON_RELEASE:
hegyi@27
   487
      isbutton=0;
hegyi@27
   488
      //we clear settings in two cases
hegyi@27
   489
      //1: the edge is ready (target_item has valid value)
hegyi@27
   490
      //2: the edge creation is cancelled with right button
hegyi@27
   491
      if((target_item)||(e->button.button==3))
ladanyi@63
   492
      {
ladanyi@63
   493
        if(active_item)
ladanyi@63
   494
        {
hegyi@179
   495
	  propertyUpdate(active_node,N_COLOR);
ladanyi@63
   496
          active_item=NULL;
ladanyi@63
   497
        }
ladanyi@63
   498
        if(target_item)
ladanyi@63
   499
        {
hegyi@179
   500
	  propertyUpdate((mytab.mapstorage).graph.target(active_edge),N_COLOR);
ladanyi@63
   501
          target_item=NULL;
ladanyi@63
   502
        }
ladanyi@63
   503
        active_node=INVALID;
ladanyi@63
   504
        active_edge=INVALID;
ladanyi@63
   505
      }
hegyi@27
   506
      break;
hegyi@27
   507
    default:
hegyi@27
   508
      break;
ladanyi@63
   509
  }
hegyi@27
   510
  return false;
hegyi@27
   511
}
hegyi@27
   512
hegyi@30
   513
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
hegyi@27
   514
{
hegyi@27
   515
  switch(e->type)
hegyi@27
   516
    {
hegyi@27
   517
    case GDK_BUTTON_PRESS:
hegyi@43
   518
      //finding the clicked items
hegyi@31
   519
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   520
      active_item=(get_item_at(clicked_x, clicked_y));
hegyi@27
   521
      active_node=INVALID;
hegyi@27
   522
      active_edge=INVALID;
hegyi@43
   523
      //was it a node?
hegyi@96
   524
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@27
   525
	{
hegyi@27
   526
	  if(nodesmap[i]==active_item)
hegyi@27
   527
	    {
hegyi@27
   528
	      active_node=i;
hegyi@27
   529
	    }
hegyi@27
   530
	}
hegyi@43
   531
      //or was it an edge?
hegyi@27
   532
      if(active_node==INVALID)
hegyi@27
   533
	{
hegyi@96
   534
	  for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@27
   535
	    {
ladanyi@153
   536
	      if(edgesmap[i]->getLine()==active_item)
hegyi@27
   537
		{
hegyi@27
   538
		  active_edge=i;
hegyi@27
   539
		}
hegyi@27
   540
	    }
hegyi@27
   541
	}
hegyi@43
   542
ladanyi@129
   543
      // return if the clicked object is neither an edge nor a node
ladanyi@129
   544
      if (active_edge == INVALID) return false;
ladanyi@129
   545
      
hegyi@43
   546
      //recolor activated item
hegyi@31
   547
      if(active_item)
hegyi@31
   548
	{
hegyi@31
   549
	  *active_item << Gnome::Canvas::Properties::fill_color("red");
hegyi@31
   550
	}
hegyi@27
   551
      break;
hegyi@27
   552
hegyi@27
   553
    case GDK_BUTTON_RELEASE:
hegyi@31
   554
      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@31
   555
      if(active_item)
hegyi@27
   556
	{
hegyi@43
   557
	  //the cursor was not moved since pressing it
hegyi@31
   558
	  if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
hegyi@27
   559
	    {
hegyi@43
   560
	      //a node was found
hegyi@31
   561
	      if(active_node!=INVALID)
hegyi@31
   562
		{
hegyi@96
   563
                  (mytab.mapstorage).modified = true;
hegyi@27
   564
hegyi@31
   565
		  std::set<Graph::Edge> edges_to_delete;
hegyi@27
   566
hegyi@96
   567
		  for(OutEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e)
hegyi@31
   568
		    {
hegyi@31
   569
		      edges_to_delete.insert(e);
hegyi@31
   570
		    }
alpar@69
   571
		  
hegyi@96
   572
		  for(InEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e)
hegyi@31
   573
		    {
hegyi@31
   574
		      edges_to_delete.insert(e);
hegyi@31
   575
		    }
alpar@69
   576
		  
hegyi@31
   577
		  //deleting collected edges
alpar@69
   578
		  for(std::set<Graph::Edge>::iterator
alpar@69
   579
			edge_set_it=edges_to_delete.begin();
alpar@69
   580
		      edge_set_it!=edges_to_delete.end();
alpar@69
   581
		      ++edge_set_it)
hegyi@31
   582
		    {
hegyi@31
   583
		      deleteItem(*edge_set_it);
hegyi@31
   584
		    }
hegyi@31
   585
		  deleteItem(active_node);
hegyi@31
   586
		}
hegyi@31
   587
	      //a simple edge was chosen
ladanyi@129
   588
	      else if (active_edge != INVALID)
hegyi@27
   589
		{
hegyi@31
   590
		  deleteItem(active_edge);
hegyi@27
   591
		}
hegyi@27
   592
	    }
hegyi@31
   593
	  //pointer was moved, deletion is cancelled
hegyi@27
   594
	  else
hegyi@27
   595
	    {
hegyi@31
   596
	      if(active_node!=INVALID)
hegyi@31
   597
		{
hegyi@31
   598
		  *active_item << Gnome::Canvas::Properties::fill_color("blue");
hegyi@31
   599
		}
ladanyi@129
   600
	      else if (active_edge != INVALID)
hegyi@31
   601
		{
hegyi@31
   602
		  *active_item << Gnome::Canvas::Properties::fill_color("green");
hegyi@31
   603
		}
hegyi@27
   604
	    }
hegyi@27
   605
	}
hegyi@27
   606
      //reseting datas
hegyi@27
   607
      active_item=NULL;
hegyi@27
   608
      active_edge=INVALID;
hegyi@27
   609
      active_node=INVALID;
hegyi@27
   610
      break;
hegyi@27
   611
hegyi@27
   612
    case GDK_MOTION_NOTIFY:
hegyi@27
   613
      break;
hegyi@27
   614
hegyi@27
   615
    default:
hegyi@27
   616
      break;
hegyi@27
   617
    }
hegyi@31
   618
  return false;
hegyi@27
   619
}
hegyi@27
   620
hegyi@149
   621
bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e)
hegyi@32
   622
{
hegyi@149
   623
  if(actual_tool==MAP_EDIT)
hegyi@32
   624
    {
hegyi@149
   625
      switch(e->type)
hegyi@149
   626
	{
hegyi@149
   627
	case GDK_BUTTON_PRESS:
hegyi@149
   628
	  {
hegyi@149
   629
	    //for determine, whether it was an edge
hegyi@149
   630
	    Edge clicked_edge=INVALID;
hegyi@149
   631
	    //for determine, whether it was a node
hegyi@149
   632
	    Node clicked_node=INVALID;
hegyi@43
   633
hegyi@149
   634
	    window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
hegyi@149
   635
	    active_item=(get_item_at(clicked_x, clicked_y));
hegyi@48
   636
hegyi@149
   637
	    //find the activated item between text of nodes
hegyi@149
   638
	    for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@149
   639
	      {
hegyi@149
   640
		//at the same time only one can be active
hegyi@149
   641
		if(nodetextmap[i]==active_item)
hegyi@149
   642
		  {
hegyi@149
   643
		    clicked_node=i;
hegyi@149
   644
		  }
hegyi@149
   645
	      }
ladanyi@65
   646
hegyi@149
   647
	    //if there was not, search for it between nodes
hegyi@149
   648
	    if(clicked_node==INVALID)
hegyi@149
   649
	      {
hegyi@149
   650
		for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@149
   651
		  {
hegyi@149
   652
		    //at the same time only one can be active
hegyi@149
   653
		    if(nodesmap[i]==active_item)
hegyi@149
   654
		      {
hegyi@149
   655
			clicked_node=i;
hegyi@149
   656
		      }
hegyi@149
   657
		  }
hegyi@149
   658
	      }
hegyi@48
   659
hegyi@149
   660
	    if(clicked_node==INVALID)
hegyi@149
   661
	      {
hegyi@149
   662
		//find the activated item between texts
hegyi@149
   663
		for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@149
   664
		  {
hegyi@149
   665
		    //at the same time only one can be active
hegyi@149
   666
		    if(edgetextmap[i]==active_item)
hegyi@149
   667
		      {
hegyi@149
   668
			clicked_edge=i;
hegyi@149
   669
		      }
hegyi@149
   670
		  }
hegyi@48
   671
hegyi@149
   672
		//if it was not between texts, search for it between edges
hegyi@149
   673
		if(clicked_edge==INVALID)
hegyi@149
   674
		  {
hegyi@149
   675
		    for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@149
   676
		      {
hegyi@149
   677
			//at the same time only one can be active
hegyi@149
   678
			if((edgesmap[i]->getLine())==active_item)
hegyi@149
   679
			  {
hegyi@149
   680
			    clicked_edge=i;
hegyi@149
   681
			  }
hegyi@149
   682
		      }
hegyi@149
   683
		  }
hegyi@149
   684
	      }
hegyi@149
   685
hegyi@149
   686
	    //if it was really a node...
hegyi@149
   687
	    if(clicked_node!=INVALID)
hegyi@149
   688
	      {
hegyi@149
   689
		// the id map is not editable
hegyi@149
   690
		if (nodemap_to_edit == "label") return 0;
hegyi@149
   691
hegyi@149
   692
		//and there is activated map
hegyi@149
   693
		if(nodetextmap[clicked_node]->property_text().get_value()!="")
hegyi@149
   694
		  {
hegyi@149
   695
		    //activate the general variable for it
hegyi@149
   696
		    active_node=clicked_node;
hegyi@149
   697
hegyi@149
   698
		    //create a dialog
hegyi@149
   699
		    Gtk::Dialog dialog("Edit value", true);
hegyi@149
   700
		    dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@149
   701
		    dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
hegyi@149
   702
		    Gtk::VBox* vbox = dialog.get_vbox();
hegyi@149
   703
		    Gtk::SpinButton spin(0.0, 4);
hegyi@149
   704
		    spin.set_increments(1.0, 10.0);
hegyi@149
   705
		    spin.set_range(-1000000.0, 1000000.0);
hegyi@149
   706
		    spin.set_numeric(true);
hegyi@149
   707
		    spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str()));
hegyi@149
   708
		    vbox->add(spin);
hegyi@149
   709
		    spin.show();
hegyi@149
   710
		    switch (dialog.run())
hegyi@149
   711
		      {
hegyi@149
   712
		      case Gtk::RESPONSE_NONE:
hegyi@149
   713
		      case Gtk::RESPONSE_CANCEL:
hegyi@149
   714
			break;
hegyi@149
   715
		      case Gtk::RESPONSE_ACCEPT:
hegyi@149
   716
			double new_value = spin.get_value();
hegyi@149
   717
			(*(mytab.mapstorage).nodemap_storage[nodemap_to_edit])[active_node] =
hegyi@149
   718
			  new_value;
hegyi@149
   719
			std::ostringstream ostr;
hegyi@149
   720
			ostr << new_value;
hegyi@149
   721
			nodetextmap[active_node]->property_text().set_value(ostr.str());
hegyi@149
   722
			//mapwin.updateNode(active_node);
hegyi@149
   723
			//mapwin.updateNode(Node(INVALID));
hegyi@149
   724
			propertyUpdate(Node(INVALID));
hegyi@149
   725
		      }
hegyi@149
   726
		  }
hegyi@149
   727
	      }
hegyi@149
   728
	    else
hegyi@149
   729
	      //if it was really an edge...
hegyi@149
   730
	      if(clicked_edge!=INVALID)
hegyi@149
   731
		{
hegyi@149
   732
		  // the id map is not editable
hegyi@149
   733
		  if (edgemap_to_edit == "label") return 0;
hegyi@149
   734
hegyi@149
   735
		  //and there is activated map
hegyi@149
   736
		  if(edgetextmap[clicked_edge]->property_text().get_value()!="")
hegyi@149
   737
		    {
hegyi@149
   738
		      //activate the general variable for it
hegyi@149
   739
		      active_edge=clicked_edge;
hegyi@149
   740
hegyi@149
   741
		      //create a dialog
hegyi@149
   742
		      Gtk::Dialog dialog("Edit value", true);
hegyi@149
   743
		      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@149
   744
		      dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
hegyi@149
   745
		      Gtk::VBox* vbox = dialog.get_vbox();
hegyi@149
   746
		      Gtk::SpinButton spin(0.0, 4);
hegyi@149
   747
		      spin.set_increments(1.0, 10.0);
hegyi@149
   748
		      spin.set_range(-1000000.0, 1000000.0);
hegyi@149
   749
		      spin.set_numeric(true);
hegyi@149
   750
		      spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str()));
hegyi@149
   751
		      vbox->add(spin);
hegyi@149
   752
		      spin.show();
hegyi@149
   753
		      switch (dialog.run())
hegyi@149
   754
			{
hegyi@149
   755
			case Gtk::RESPONSE_NONE:
hegyi@149
   756
			case Gtk::RESPONSE_CANCEL:
hegyi@149
   757
			  break;
hegyi@149
   758
			case Gtk::RESPONSE_ACCEPT:
hegyi@149
   759
			  double new_value = spin.get_value();
hegyi@149
   760
			  (*(mytab.mapstorage).edgemap_storage[edgemap_to_edit])[active_edge] =
hegyi@149
   761
			    new_value;
hegyi@149
   762
			  std::ostringstream ostr;
hegyi@149
   763
			  ostr << new_value;
hegyi@149
   764
			  edgetextmap[active_edge]->property_text().set_value(
hegyi@149
   765
									      ostr.str());
hegyi@149
   766
			  //mapwin.updateEdge(active_edge);
hegyi@149
   767
			  //                   mapwin.updateEdge(Edge(INVALID));
hegyi@149
   768
			  propertyUpdate(Edge(INVALID));
hegyi@149
   769
			}
hegyi@149
   770
		    }
hegyi@149
   771
		}
hegyi@149
   772
	    break;
hegyi@149
   773
	  }
hegyi@149
   774
	default:
hegyi@149
   775
	  break;
hegyi@149
   776
	}
hegyi@32
   777
    }
hegyi@35
   778
  return false;  
hegyi@32
   779
}
hegyi@32
   780
alpar@62
   781
void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
hegyi@27
   782
{
hegyi@28
   783
  delete(nodetextmap[node_to_delete]);
hegyi@27
   784
  delete(nodesmap[node_to_delete]);
hegyi@96
   785
  (mytab.mapstorage).graph.erase(node_to_delete);
hegyi@27
   786
}
hegyi@27
   787
alpar@62
   788
void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
hegyi@27
   789
{
hegyi@28
   790
  delete(edgetextmap[edge_to_delete]);
hegyi@27
   791
  delete(edgesmap[edge_to_delete]);
hegyi@96
   792
  (mytab.mapstorage).graph.erase(edge_to_delete);
hegyi@27
   793
}
hegyi@27
   794
hegyi@150
   795
void GraphDisplayerCanvas::textReposition(XY new_place)
hegyi@27
   796
{
hegyi@150
   797
  new_place+=(XY(10,10));
hegyi@35
   798
  edgetextmap[forming_edge]->property_x().set_value(new_place.x);
hegyi@35
   799
  edgetextmap[forming_edge]->property_y().set_value(new_place.y);
hegyi@27
   800
}
hegyi@27
   801
ladanyi@147
   802
void GraphDisplayerCanvas::toggleEdgeActivity(EdgeBase* active_bre, bool on)
hegyi@27
   803
{
hegyi@27
   804
  if(on)
ladanyi@147
   805
  {
ladanyi@147
   806
    if(forming_edge!=INVALID)
hegyi@27
   807
    {
ladanyi@147
   808
      std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
hegyi@27
   809
    }
ladanyi@147
   810
    else
ladanyi@147
   811
    {
ladanyi@147
   812
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
ladanyi@147
   813
      {
ladanyi@147
   814
        if(edgesmap[i]==active_bre)
ladanyi@147
   815
        {
ladanyi@147
   816
          forming_edge=i;
ladanyi@147
   817
        }
ladanyi@147
   818
      }
ladanyi@147
   819
    }
ladanyi@147
   820
  }
hegyi@27
   821
  else
hegyi@27
   822
    {
hegyi@160
   823
      if(forming_edge!=INVALID)
hegyi@160
   824
	{
hegyi@160
   825
	  forming_edge=INVALID;
hegyi@160
   826
	}
hegyi@160
   827
      else
hegyi@160
   828
	{
hegyi@160
   829
	  std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
hegyi@160
   830
	}
hegyi@27
   831
    }
hegyi@160
   832
}
hegyi@160
   833
hegyi@160
   834
void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node)
hegyi@160
   835
{
hegyi@160
   836
  Gnome::Canvas::Item * moved_item=item;
hegyi@160
   837
  Node moved_node=node;
hegyi@160
   838
hegyi@160
   839
  if(item==NULL && node==INVALID)
ladanyi@147
   840
    {
hegyi@160
   841
      moved_item=active_item;
hegyi@160
   842
      moved_node=active_node;
ladanyi@147
   843
    }
hegyi@160
   844
  else
hegyi@160
   845
    {
hegyi@160
   846
      isbutton=1;
hegyi@160
   847
    }
hegyi@160
   848
hegyi@160
   849
  //repositioning node and its text
hegyi@160
   850
  moved_item->move(dx, dy);
hegyi@160
   851
  nodetextmap[moved_node]->move(dx, dy);
hegyi@160
   852
hegyi@160
   853
  // the new coordinates of the centre of the node 
hegyi@160
   854
  double coord_x = dx + (mytab.mapstorage).coords[moved_node].x;
hegyi@160
   855
  double coord_y = dy + (mytab.mapstorage).coords[moved_node].y;
hegyi@160
   856
hegyi@160
   857
  // write back the new coordinates to the coords map
hegyi@160
   858
  (mytab.mapstorage).coords.set(moved_node, XY(coord_x, coord_y));
hegyi@160
   859
hegyi@160
   860
  //all the edges connected to the moved point has to be redrawn
hegyi@160
   861
  for(OutEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei)
hegyi@160
   862
    {
hegyi@160
   863
      XY arrow_pos;
hegyi@160
   864
hegyi@160
   865
      if (mytab.mapstorage.graph.source(ei) == mytab.mapstorage.graph.target(ei))
hegyi@160
   866
	{
hegyi@160
   867
	  arrow_pos = mytab.mapstorage.arrow_pos[ei] + XY(dx, dy);
hegyi@160
   868
	}
hegyi@160
   869
      else
hegyi@160
   870
	{
hegyi@160
   871
	  XY moved_node_1(coord_x - dx, coord_y - dy);
hegyi@160
   872
	  XY moved_node_2(coord_x, coord_y);
hegyi@160
   873
	  Node target = mytab.mapstorage.graph.target(ei);
hegyi@160
   874
	  XY fix_node(mytab.mapstorage.coords[target].x,
hegyi@160
   875
		      mytab.mapstorage.coords[target].y);
hegyi@160
   876
	  XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
hegyi@160
   877
hegyi@160
   878
	  arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
hegyi@160
   879
	}
hegyi@160
   880
hegyi@160
   881
      mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
hegyi@160
   882
      edgesmap[ei]->draw();
hegyi@160
   883
hegyi@160
   884
      //reposition of edgetext
hegyi@160
   885
      XY text_pos=mytab.mapstorage.arrow_pos[ei];
hegyi@160
   886
      text_pos+=(XY(10,10));
hegyi@160
   887
      edgetextmap[ei]->property_x().set_value(text_pos.x);
hegyi@160
   888
      edgetextmap[ei]->property_y().set_value(text_pos.y);
hegyi@160
   889
    }
hegyi@160
   890
hegyi@160
   891
  for(InEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei)
hegyi@160
   892
    {
hegyi@160
   893
      if (mytab.mapstorage.graph.source(ei) != mytab.mapstorage.graph.target(ei))
hegyi@160
   894
	{
hegyi@160
   895
	  XY moved_node_1(coord_x - dx, coord_y - dy);
hegyi@160
   896
	  XY moved_node_2(coord_x, coord_y);
hegyi@160
   897
	  Node source = mytab.mapstorage.graph.source(ei);
hegyi@160
   898
	  XY fix_node(mytab.mapstorage.coords[source].x,
hegyi@160
   899
		      mytab.mapstorage.coords[source].y);
hegyi@160
   900
	  XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
hegyi@160
   901
hegyi@160
   902
	  XY arrow_pos;
hegyi@160
   903
	  arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
hegyi@160
   904
hegyi@160
   905
	  mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
hegyi@160
   906
	  edgesmap[ei]->draw();
hegyi@160
   907
hegyi@160
   908
	  //reposition of edgetext
hegyi@160
   909
	  XY text_pos=mytab.mapstorage.arrow_pos[ei];
hegyi@160
   910
	  text_pos+=(XY(10,10));
hegyi@160
   911
	  edgetextmap[ei]->property_x().set_value(text_pos.x);
hegyi@160
   912
	  edgetextmap[ei]->property_y().set_value(text_pos.y);
hegyi@160
   913
	}
hegyi@160
   914
    }
hegyi@27
   915
}
hegyi@179
   916
hegyi@179
   917
Gdk::Color GraphDisplayerCanvas::rainbowColorCounter(double min, double max, double w)
hegyi@179
   918
{
hegyi@179
   919
  Gdk::Color color;
hegyi@179
   920
hegyi@179
   921
  double pos=(w-min)/(max-min);
hegyi@179
   922
  int phase=0;
hegyi@179
   923
hegyi@179
   924
  //rainbow transitions contain 6 phase
hegyi@179
   925
  //in each phase only one color is changed
hegyi@179
   926
  //first we determine the phase, in which
hegyi@179
   927
  //the actual value belongs to
hegyi@179
   928
  for (int i=0;i<=5;i++)
hegyi@179
   929
    {
hegyi@179
   930
      if(((double)i/6<pos)&&(pos<=(double(i+1)/6)))
hegyi@179
   931
	{
hegyi@179
   932
	  phase=i;
hegyi@179
   933
	}
hegyi@179
   934
    }
hegyi@179
   935
  if(phase<6)
hegyi@179
   936
    {
hegyi@179
   937
      //within its 1/6 long phase the relativ position
hegyi@179
   938
      //determines the power of the color changed in
hegyi@179
   939
      //that phase
hegyi@179
   940
      //we normalize that to one, to be able to give percentage
hegyi@179
   941
      //value for the function
hegyi@179
   942
      double rel_pos=(pos-(phase/6))*6;
hegyi@179
   943
hegyi@179
   944
      switch(phase)
hegyi@179
   945
	{
hegyi@179
   946
	case 0:
hegyi@179
   947
	  color.set_rgb_p (1, 0, 1-rel_pos);
hegyi@179
   948
	  break;
hegyi@179
   949
	case 1:
hegyi@179
   950
	  color.set_rgb_p (1, rel_pos, 0);
hegyi@179
   951
	  break;
hegyi@179
   952
	case 2:
hegyi@179
   953
	  color.set_rgb_p (1-rel_pos, 1, 0);
hegyi@179
   954
	  break;
hegyi@179
   955
	case 3:
hegyi@179
   956
	  color.set_rgb_p (0, 1, rel_pos);
hegyi@179
   957
	  break;
hegyi@179
   958
	case 4:
hegyi@179
   959
	  color.set_rgb_p (0, 1-rel_pos, 1);
hegyi@179
   960
	  break;
hegyi@179
   961
	case 5:
hegyi@179
   962
	  color.set_rgb_p ((rel_pos/3), 0, 1);
hegyi@179
   963
	  break;
hegyi@179
   964
	default:
hegyi@179
   965
	  std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
hegyi@179
   966
	}
hegyi@179
   967
    }
hegyi@179
   968
  else
hegyi@179
   969
    {
hegyi@179
   970
      std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
hegyi@179
   971
    }
hegyi@179
   972
  return color;
hegyi@179
   973
}