File graph_displayer is split in functional parts.
authorhegyi
Fri, 24 Jun 2005 07:58:18 +0000
changeset 1510cde847387b5a
parent 1509 f9113440b667
child 1511 d6b95a59da26
File graph_displayer is split in functional parts.
gui/Makefile.am
gui/graph_displayer_canvas-edge.cc
gui/graph_displayer_canvas-event.cc
gui/graph_displayer_canvas-zoom.cc
gui/graph_displayer_canvas.cc
     1.1 --- a/gui/Makefile.am	Thu Jun 23 17:56:24 2005 +0000
     1.2 +++ b/gui/Makefile.am	Fri Jun 24 07:58:18 2005 +0000
     1.3 @@ -6,6 +6,9 @@
     1.4  gd_SOURCES = \
     1.5  	all_include.h \
     1.6  	graph_displayer_canvas.cc \
     1.7 +	graph_displayer_canvas-edge.cc \
     1.8 +	graph_displayer_canvas-event.cc \
     1.9 +	graph_displayer_canvas-zoom.cc \
    1.10  	graph_displayer_canvas.h \
    1.11  	graph-displayer.cc \
    1.12  	main_win.cc \
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gui/graph_displayer_canvas-edge.cc	Fri Jun 24 07:58:18 2005 +0000
     2.3 @@ -0,0 +1,93 @@
     2.4 +#include <graph_displayer_canvas.h>
     2.5 +#include <broken_edge.h>
     2.6 +#include <math.h>
     2.7 +
     2.8 +
     2.9 +int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
    2.10 +{
    2.11 +  for (EdgeIt i(g); i!=INVALID; ++i)
    2.12 +    {
    2.13 +      int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
    2.14 +      if(w>=0)
    2.15 +	{
    2.16 +	  edgesmap[i]->property_width_pixels().set_value(w);
    2.17 +	}
    2.18 +    }
    2.19 +  return 0;
    2.20 +};
    2.21 +
    2.22 +int GraphDisplayerCanvas::changeColor (std::string mapname)
    2.23 +{  
    2.24 +
    2.25 +  //function maps the range of the maximum and
    2.26 +  //the minimum of the nodemap to the range of
    2.27 +  //green in RGB
    2.28 +
    2.29 +  for (EdgeIt i(g); i!=INVALID; ++i)
    2.30 +  {
    2.31 +    double w=(*(mapstorage.edgemap_storage)[mapname])[i];
    2.32 +    double max=mapstorage.maxOfEdgeMap(mapname);
    2.33 +    double min=mapstorage.minOfEdgeMap(mapname);
    2.34 +      
    2.35 +    //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    2.36 +    Gdk::Color color;
    2.37 +    if(max!=min)
    2.38 +    {
    2.39 +      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    2.40 +    }
    2.41 +    else
    2.42 +    {
    2.43 +      color.set_rgb_p (0, 100, 0);
    2.44 +    }
    2.45 +
    2.46 +    edgesmap[i]->property_fill_color_gdk().set_value(color);
    2.47 +  }
    2.48 +  return 0;
    2.49 +};
    2.50 +
    2.51 +int GraphDisplayerCanvas::changeText (std::string mapname)
    2.52 +{
    2.53 +
    2.54 +  //the number in the map will be written on the edge
    2.55 +  //EXCEPT when the name of the map is Text, because
    2.56 +  //in that case empty string will be written, because
    2.57 +  //that is the deleter map
    2.58 +  //\todo isn't it a bit woodcutter?
    2.59 +
    2.60 +  for (EdgeIt i(g); i!=INVALID; ++i)
    2.61 +    {
    2.62 +      if(mapname!="Text")
    2.63 +	{
    2.64 +	  double number=(*(mapstorage.edgemap_storage)[mapname])[i];
    2.65 +	  int length=1;
    2.66 +	  //if number is smaller than one, length would be negative, or invalid
    2.67 +	  if(number>=1)
    2.68 +	    {
    2.69 +	      length=(int)(floor(log(number)/log(10)))+1;
    2.70 +	    }
    2.71 +	  int maxpos=(int)(pow(10,length-1));
    2.72 +	  int strl=length+1+RANGE;
    2.73 +	  char * str=new char[strl];
    2.74 +	  str[length]='.';
    2.75 +	  str[strl]='\0';
    2.76 +      
    2.77 +	  for(int j=0;j<strl;j++)
    2.78 +	    {
    2.79 +	      if(j!=length)
    2.80 +		{
    2.81 +		  int digit=(int)(number/maxpos);
    2.82 +		  str[j]=(digit+'0');
    2.83 +		  number-=digit*maxpos;
    2.84 +		  number*=10;
    2.85 +		}
    2.86 +	    }
    2.87 +      
    2.88 +	  edgetextmap[i]->property_text().set_value(str);
    2.89 +	}
    2.90 +      else
    2.91 +	{
    2.92 +	  edgetextmap[i]->property_text().set_value("");
    2.93 +	}
    2.94 +    }
    2.95 +  return 0;
    2.96 +};
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gui/graph_displayer_canvas-event.cc	Fri Jun 24 07:58:18 2005 +0000
     3.3 @@ -0,0 +1,492 @@
     3.4 +#include <graph_displayer_canvas.h>
     3.5 +#include <broken_edge.h>
     3.6 +#include <math.h>
     3.7 +
     3.8 +
     3.9 +bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
    3.10 +{
    3.11 +  Gnome::Canvas::CanvasAA::on_expose_event(event);
    3.12 +  //usleep(10000);
    3.13 +  //rezoom();
    3.14 +  return true;
    3.15 +}
    3.16 +
    3.17 +void GraphDisplayerCanvas::changeEditorialTool(int newtool)
    3.18 +{
    3.19 +  actual_handler.disconnect();
    3.20 +
    3.21 +  if(actual_tool==CREATE_EDGE)
    3.22 +    {
    3.23 +	GdkEvent * generated=new GdkEvent();
    3.24 +	generated->type=GDK_BUTTON_RELEASE;
    3.25 +	generated->button.button=3;
    3.26 +	create_edge_event_handler(generated);      
    3.27 +    }
    3.28 +
    3.29 +  actual_tool=newtool;
    3.30 +
    3.31 +  switch(newtool)
    3.32 +    {
    3.33 +    case MOVE:
    3.34 +      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
    3.35 +      break;
    3.36 +
    3.37 +      //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group
    3.38 +    case CREATE_NODE:
    3.39 +      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
    3.40 +      break;
    3.41 +
    3.42 +    case CREATE_EDGE:
    3.43 +      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
    3.44 +      break;
    3.45 +
    3.46 +    case ERASER:
    3.47 +      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraser_event_handler), false);
    3.48 +      break;
    3.49 +
    3.50 +    default:
    3.51 +      break;
    3.52 +    }
    3.53 +}
    3.54 +
    3.55 +int GraphDisplayerCanvas::get_actual_tool()
    3.56 +{
    3.57 +  return actual_tool;
    3.58 +}
    3.59 +
    3.60 +bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
    3.61 +{
    3.62 +  switch(e->type)
    3.63 +  {
    3.64 +    case GDK_BUTTON_PRESS:
    3.65 +      //we mark the location of the event to be able to calculate parameters of dragging
    3.66 +      clicked_x=e->button.x;
    3.67 +      clicked_y=e->button.y;
    3.68 +      active_item=(get_item_at(e->button.x, e->button.y));
    3.69 +      active_node=INVALID;
    3.70 +      for (NodeIt i(g); i!=INVALID; ++i)
    3.71 +	{
    3.72 +	  if(nodesmap[i]==active_item)
    3.73 +	    {
    3.74 +	      active_node=i;
    3.75 +	    }
    3.76 +	}
    3.77 +      switch(e->button.button)
    3.78 +	{
    3.79 +	case 3:      
    3.80 +	  isbutton=3;
    3.81 +	  break;
    3.82 +	default:
    3.83 +	  isbutton=1;
    3.84 +	  break;
    3.85 +	}
    3.86 +      break;
    3.87 +    case GDK_BUTTON_RELEASE:
    3.88 +      isbutton=0;
    3.89 +      active_item=NULL;
    3.90 +      active_node=INVALID;
    3.91 +      updateScrollRegion();
    3.92 +      break;
    3.93 +    case GDK_MOTION_NOTIFY:
    3.94 +      //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
    3.95 +      if(active_node!=INVALID)
    3.96 +      {
    3.97 +	//new coordinates will be the old values,
    3.98 +	//because the item will be moved to the
    3.99 +	//new coordinate therefore the new movement
   3.100 +	//has to be calculated from here
   3.101 +
   3.102 +        double dx=e->motion.x-clicked_x;
   3.103 +        double dy=e->motion.y-clicked_y;
   3.104 +
   3.105 +        active_item->move(dx, dy);
   3.106 +
   3.107 +        clicked_x=e->motion.x;
   3.108 +        clicked_y=e->motion.y;
   3.109 +
   3.110 +	//all the edges connected to the moved point has to be redrawn
   3.111 +        EdgeIt ei;
   3.112 +
   3.113 +        g.firstOut(ei,active_node);
   3.114 +
   3.115 +        for(;ei!=INVALID;g.nextOut(ei))
   3.116 +        {
   3.117 +            Gnome::Canvas::Points coos;
   3.118 +            double x1, x2, y1, y2;
   3.119 +
   3.120 +            nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
   3.121 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.122 +
   3.123 +            nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
   3.124 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.125 +
   3.126 +	    if(isbutton==3)
   3.127 +	      {
   3.128 +		edgesmap[ei]->set_points(coos);
   3.129 +	      }
   3.130 +	    else
   3.131 +	      {
   3.132 +		edgesmap[ei]->set_points(coos,true);
   3.133 +	      }
   3.134 +
   3.135 +	    xy<double> text_pos=edgesmap[ei]->get_arrow_pos();
   3.136 +	    text_pos+=(xy<double>(10,10));
   3.137 +	    edgetextmap[ei]->property_x().set_value(text_pos.x);
   3.138 +	    edgetextmap[ei]->property_y().set_value(text_pos.y);
   3.139 +        }
   3.140 +
   3.141 +        g.firstIn(ei,active_node);
   3.142 +        for(;ei!=INVALID;g.nextIn(ei))
   3.143 +        {
   3.144 +            Gnome::Canvas::Points coos;
   3.145 +            double x1, x2, y1, y2;
   3.146 +
   3.147 +            nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
   3.148 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.149 +
   3.150 +            nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
   3.151 +            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.152 +
   3.153 +	    if(isbutton==3)
   3.154 +	      {
   3.155 +		edgesmap[ei]->set_points(coos);
   3.156 +	      }
   3.157 +	    else
   3.158 +	      {
   3.159 +		edgesmap[ei]->set_points(coos,true);
   3.160 +	      }
   3.161 +
   3.162 +	    xy<double> text_pos=edgesmap[ei]->get_arrow_pos();
   3.163 +	    text_pos+=(xy<double>(10,10));
   3.164 +	    edgetextmap[ei]->property_x().set_value(text_pos.x);
   3.165 +	    edgetextmap[ei]->property_y().set_value(text_pos.y);
   3.166 +        }
   3.167 +      }
   3.168 +    default: break;
   3.169 +  }
   3.170 +
   3.171 +  return true;
   3.172 +}
   3.173 +
   3.174 +bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
   3.175 +{
   3.176 +  switch(e->type)
   3.177 +    {
   3.178 +
   3.179 +      //draw the new node in red at the clicked place
   3.180 +    case GDK_BUTTON_PRESS:
   3.181 +      isbutton=1;
   3.182 +
   3.183 +      active_node=NodeIt(g,g.addNode());
   3.184 +
   3.185 +      //initiating values corresponding to new node in maps
   3.186 +      
   3.187 +
   3.188 +      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   3.189 +
   3.190 +      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
   3.191 +      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
   3.192 +      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
   3.193 +      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
   3.194 +      (nodesmap[active_node])->show();
   3.195 +      break;
   3.196 +
   3.197 +      //move the new node
   3.198 +    case GDK_MOTION_NOTIFY:
   3.199 +      {
   3.200 +	double world_motion_x, world_motion_y;
   3.201 +	GdkEvent * generated=new GdkEvent();
   3.202 +	window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
   3.203 +	generated->motion.x=world_motion_x;
   3.204 +	generated->motion.y=world_motion_y;
   3.205 +	generated->type=GDK_MOTION_NOTIFY;
   3.206 +	move_event_handler(generated);      
   3.207 +	break;
   3.208 +      }
   3.209 +
   3.210 +      //finalize the new node
   3.211 +    case GDK_BUTTON_RELEASE:
   3.212 +      isbutton=0;
   3.213 +      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   3.214 +      active_item=NULL;
   3.215 +      active_node=INVALID;
   3.216 +      updateScrollRegion();
   3.217 +      break;
   3.218 +    default:
   3.219 +      break;
   3.220 +    }
   3.221 +  return false;
   3.222 +}
   3.223 +
   3.224 +bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
   3.225 +{
   3.226 +  switch(e->type)
   3.227 +    {
   3.228 +    case GDK_BUTTON_PRESS:
   3.229 +      //in edge creation right button has special meaning
   3.230 +      if(e->button.button!=3)
   3.231 +	{
   3.232 +	  //there is not yet selected node
   3.233 +	  if(active_node==INVALID)
   3.234 +	    {
   3.235 +	      //we mark the location of the event to be able to calculate parameters of dragging
   3.236 +	      clicked_x=e->button.x;
   3.237 +	      clicked_y=e->button.y;
   3.238 +	      active_item=(get_item_at(e->button.x, e->button.y));
   3.239 +	      active_node=INVALID;
   3.240 +	      for (NodeIt i(g); i!=INVALID; ++i)
   3.241 +		{
   3.242 +		  if(nodesmap[i]==active_item)
   3.243 +		    {
   3.244 +		      active_node=i;
   3.245 +		    }
   3.246 +		}
   3.247 +	      //the clicked item is really a node
   3.248 +	      if(active_node!=INVALID)
   3.249 +		{
   3.250 +		  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
   3.251 +		  isbutton=1;
   3.252 +		}
   3.253 +	      //clicked item was not a node. It could be e.g. edge.
   3.254 +	      else
   3.255 +		{
   3.256 +		  active_item=NULL;
   3.257 +		}
   3.258 +	    }
   3.259 +	  //we only have to do sg. if the mouse button
   3.260 +	  // is pressed already once AND the click was
   3.261 +	  // on a node that was found in the set of 
   3.262 +	  //nodes, and now we only search for the second 
   3.263 +	  //node
   3.264 +	  else
   3.265 +	    {
   3.266 +	      target_item=(get_item_at(e->button.x, e->button.y));
   3.267 +	      Graph::NodeIt target_node=INVALID;
   3.268 +	      for (NodeIt i(g); i!=INVALID; ++i)
   3.269 +		{
   3.270 +		  if(nodesmap[i]==target_item)
   3.271 +		    {
   3.272 +		      target_node=i;
   3.273 +		    }
   3.274 +		}
   3.275 +	      //the clicked item is a node, the edge can be drawn
   3.276 +	      if(target_node!=INVALID)
   3.277 +		{
   3.278 +		  *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
   3.279 +
   3.280 +		  //creating new edge
   3.281 +		  active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
   3.282 +
   3.283 +		  //initiating values corresponding to new edge in maps
   3.284 +		  mapstorage.init_maps_for_edge(active_edge);
   3.285 +	  
   3.286 +		  //calculating coordinates of new edge
   3.287 +		  Gnome::Canvas::Points coos;
   3.288 +		  double x1, x2, y1, y2;
   3.289 +	  
   3.290 +		  active_item->get_bounds(x1, y1, x2, y2);
   3.291 +		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.292 +
   3.293 +		  target_item->get_bounds(x1, y1, x2, y2);
   3.294 +		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   3.295 +
   3.296 +		  //drawing new edge
   3.297 +		  edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
   3.298 +		  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
   3.299 +		  edgesmap[active_edge]->property_width_pixels().set_value(10);
   3.300 +
   3.301 +		  //redraw nodes to blank terminations of the new edge
   3.302 +		  target_item->raise_to_top();
   3.303 +		  active_item->raise_to_top();
   3.304 +
   3.305 +		  //initializing edge-text as well, to empty string
   3.306 +		  xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos();
   3.307 +		  text_pos+=(xy<double>(10,10));
   3.308 +
   3.309 +		  edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
   3.310 +		  edgetextmap[active_edge]->property_fill_color().set_value("black");
   3.311 +		}
   3.312 +	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
   3.313 +	      else
   3.314 +		{
   3.315 +		  target_item=NULL;
   3.316 +		}
   3.317 +	    }
   3.318 +	}
   3.319 +      break;
   3.320 +    case GDK_BUTTON_RELEASE:
   3.321 +      isbutton=0;
   3.322 +      //we clear settings in two cases
   3.323 +      //1: the edge is ready (target_item has valid value)
   3.324 +      //2: the edge creation is cancelled with right button
   3.325 +      if((target_item)||(e->button.button==3))
   3.326 +	{
   3.327 +	  if(active_item)
   3.328 +	    {
   3.329 +	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   3.330 +	      active_item=NULL;
   3.331 +	    }
   3.332 +	  if(target_item)
   3.333 +	    {
   3.334 +	      *target_item << Gnome::Canvas::Properties::fill_color("blue");
   3.335 +	      target_item=NULL;
   3.336 +	    }
   3.337 +	  active_node=INVALID;
   3.338 +	  active_edge=INVALID;
   3.339 +	}
   3.340 +      break;
   3.341 +    default:
   3.342 +      break;
   3.343 +    }
   3.344 +  return false;
   3.345 +}
   3.346 +
   3.347 +bool GraphDisplayerCanvas::eraser_event_handler(GdkEvent* e)
   3.348 +{
   3.349 +  switch(e->type)
   3.350 +    {
   3.351 +    case GDK_BUTTON_PRESS:
   3.352 +      active_item=(get_item_at(e->button.x, e->button.y));
   3.353 +      active_node=INVALID;
   3.354 +      active_edge=INVALID;
   3.355 +      for (NodeIt i(g); i!=INVALID; ++i)
   3.356 +	{
   3.357 +	  if(nodesmap[i]==active_item)
   3.358 +	    {
   3.359 +	      active_node=i;
   3.360 +	    }
   3.361 +	}
   3.362 +      if(active_node==INVALID)
   3.363 +	{
   3.364 +	  for (EdgeIt i(g); i!=INVALID; ++i)
   3.365 +	    {
   3.366 +	      if(edgesmap[i]==active_item)
   3.367 +		{
   3.368 +		  active_edge=i;
   3.369 +		}
   3.370 +	    }
   3.371 +	}
   3.372 +    *active_item << Gnome::Canvas::Properties::fill_color("red");
   3.373 +      break;
   3.374 +
   3.375 +    case GDK_BUTTON_RELEASE:
   3.376 +      if(active_item==(get_item_at(e->button.x, e->button.y)))
   3.377 +	{
   3.378 +	  if(active_node!=INVALID)
   3.379 +	    {
   3.380 +
   3.381 +	      //collecting edges to delete
   3.382 +	      EdgeIt e;
   3.383 +	      std::set<Graph::Edge> edges_to_delete;
   3.384 +
   3.385 +	      g.firstOut(e,active_node);
   3.386 +	      for(;e!=INVALID;g.nextOut(e))
   3.387 +		{
   3.388 +		      edges_to_delete.insert(e);
   3.389 +		}
   3.390 +
   3.391 +	      g.firstIn(e,active_node);
   3.392 +	      for(;e!=INVALID;g.nextIn(e))
   3.393 +		{
   3.394 +		      edges_to_delete.insert(e);
   3.395 +		}
   3.396 +
   3.397 +	      //deleting collected edges
   3.398 +	      for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
   3.399 +		{
   3.400 +		  delete_item(*edge_set_it);
   3.401 +		}
   3.402 +	      delete_item(active_node);
   3.403 +	    }
   3.404 +	  //a simple edge was chosen
   3.405 +	  else
   3.406 +	    {
   3.407 +	      delete_item(active_edge);
   3.408 +	    }
   3.409 +
   3.410 +	  
   3.411 +	}
   3.412 +      //pointer was moved, deletion is cancelled
   3.413 +      else
   3.414 +	{
   3.415 +	  if(active_node!=INVALID)
   3.416 +	    {
   3.417 +	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   3.418 +	    }
   3.419 +	  else
   3.420 +	    {
   3.421 +	      *active_item << Gnome::Canvas::Properties::fill_color("green");
   3.422 +	    }
   3.423 +	}
   3.424 +      //reseting datas
   3.425 +      active_item=NULL;
   3.426 +      active_edge=INVALID;
   3.427 +      active_node=INVALID;
   3.428 +      break;
   3.429 +
   3.430 +    case GDK_MOTION_NOTIFY:
   3.431 +      break;
   3.432 +
   3.433 +    default:
   3.434 +      break;
   3.435 +    }
   3.436 +  return true;
   3.437 +}
   3.438 +
   3.439 +void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete)
   3.440 +{
   3.441 +  delete(nodesmap[node_to_delete]);
   3.442 +  g.erase(node_to_delete);
   3.443 +}
   3.444 +
   3.445 +void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete)
   3.446 +{
   3.447 +  delete(edgesmap[edge_to_delete]);
   3.448 +  g.erase(edge_to_delete);
   3.449 +}
   3.450 +
   3.451 +void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete)
   3.452 +{
   3.453 +  delete(edgesmap[edge_to_delete]);
   3.454 +  g.erase(edge_to_delete);
   3.455 +}
   3.456 +
   3.457 +void GraphDisplayerCanvas::text_reposition(xy<double> new_place)
   3.458 +{
   3.459 +  new_place+=(xy<double>(10,10));
   3.460 +  edgetextmap[active_edge]->property_x().set_value(new_place.x);
   3.461 +  edgetextmap[active_edge]->property_y().set_value(new_place.y);
   3.462 +}
   3.463 +
   3.464 +void GraphDisplayerCanvas::toggle_edge_activity(BrokenEdge* active_bre, bool on)
   3.465 +{
   3.466 +  if(on)
   3.467 +    {
   3.468 +      if(active_edge!=INVALID)
   3.469 +	{
   3.470 +	  std::cout << "ERROR!!!! Valid edge found!" << std::endl;
   3.471 +	}
   3.472 +      else
   3.473 +	{
   3.474 +	  for (EdgeIt i(g); i!=INVALID; ++i)
   3.475 +	    {
   3.476 +	      if(edgesmap[i]==active_bre)
   3.477 +		{
   3.478 +		  active_edge=i;
   3.479 +		}
   3.480 +	    }
   3.481 +	}
   3.482 +    }
   3.483 +  else
   3.484 +    {
   3.485 +      if(active_edge!=INVALID)
   3.486 +	{
   3.487 +	  active_edge=INVALID;
   3.488 +	}
   3.489 +      else
   3.490 +	{
   3.491 +	  std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
   3.492 +	}
   3.493 +    }
   3.494 +
   3.495 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/gui/graph_displayer_canvas-zoom.cc	Fri Jun 24 07:58:18 2005 +0000
     4.3 @@ -0,0 +1,49 @@
     4.4 +#include <graph_displayer_canvas.h>
     4.5 +#include <broken_edge.h>
     4.6 +#include <math.h>
     4.7 +
     4.8 +void GraphDisplayerCanvas::zoomIn()
     4.9 +{
    4.10 +  set_pixels_per_unit(
    4.11 +      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
    4.12 +}
    4.13 +
    4.14 +void GraphDisplayerCanvas::zoomOut()
    4.15 +{
    4.16 +  set_pixels_per_unit(
    4.17 +      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
    4.18 +}
    4.19 +
    4.20 +void GraphDisplayerCanvas::zoomFit()
    4.21 +{
    4.22 +  // get the height and width of the canvas
    4.23 +  Gtk::Allocation a = get_allocation();
    4.24 +  int aw = a.get_width();
    4.25 +  int ah = a.get_height();
    4.26 +  // add some space
    4.27 +  aw -= 5; if (aw < 0) aw = 0;
    4.28 +  ah -= 5; if (ah < 0) ah = 0;
    4.29 +
    4.30 +  // get the bounding box of the graph
    4.31 +  double wx1, wy1, wx2, wy2;
    4.32 +  Gnome::Canvas::Item* pCanvasItem = root();
    4.33 +  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
    4.34 +
    4.35 +  // fit the graph to the window
    4.36 +  double ppu1 = (double) aw / fabs(wx2 - wx1);
    4.37 +  double ppu2 = (double) ah / fabs(wy2 - wy1);
    4.38 +  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
    4.39 +}
    4.40 +
    4.41 +void GraphDisplayerCanvas::zoom100()
    4.42 +{
    4.43 +  set_pixels_per_unit(1.0);
    4.44 +}
    4.45 +
    4.46 +void GraphDisplayerCanvas::updateScrollRegion()
    4.47 +{
    4.48 +  double wx1, wy1, wx2, wy2;
    4.49 +  Gnome::Canvas::Item* pCanvasItem = root();
    4.50 +  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
    4.51 +  set_scroll_region(wx1, wy1, wx2, wy2);
    4.52 +}
     5.1 --- a/gui/graph_displayer_canvas.cc	Thu Jun 23 17:56:24 2005 +0000
     5.2 +++ b/gui/graph_displayer_canvas.cc	Fri Jun 24 07:58:18 2005 +0000
     5.3 @@ -91,706 +91,3 @@
     5.4    writer.writeNodeMap("coordinates_y", yc);
     5.5    writer.run();
     5.6  }
     5.7 -
     5.8 -int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
     5.9 -{
    5.10 -  for (EdgeIt i(g); i!=INVALID; ++i)
    5.11 -    {
    5.12 -      int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
    5.13 -      if(w>=0)
    5.14 -	{
    5.15 -	  edgesmap[i]->property_width_pixels().set_value(w);
    5.16 -	}
    5.17 -    }
    5.18 -  return 0;
    5.19 -};
    5.20 -
    5.21 -int GraphDisplayerCanvas::changeColor (std::string mapname)
    5.22 -{  
    5.23 -
    5.24 -  //function maps the range of the maximum and
    5.25 -  //the minimum of the nodemap to the range of
    5.26 -  //green in RGB
    5.27 -
    5.28 -  for (EdgeIt i(g); i!=INVALID; ++i)
    5.29 -  {
    5.30 -    double w=(*(mapstorage.edgemap_storage)[mapname])[i];
    5.31 -    double max=mapstorage.maxOfEdgeMap(mapname);
    5.32 -    double min=mapstorage.minOfEdgeMap(mapname);
    5.33 -      
    5.34 -    //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    5.35 -    Gdk::Color color;
    5.36 -    if(max!=min)
    5.37 -    {
    5.38 -      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    5.39 -    }
    5.40 -    else
    5.41 -    {
    5.42 -      color.set_rgb_p (0, 100, 0);
    5.43 -    }
    5.44 -
    5.45 -    edgesmap[i]->property_fill_color_gdk().set_value(color);
    5.46 -  }
    5.47 -  return 0;
    5.48 -};
    5.49 -
    5.50 -int GraphDisplayerCanvas::changeText (std::string mapname)
    5.51 -{
    5.52 -
    5.53 -  //the number in the map will be written on the edge
    5.54 -  //EXCEPT when the name of the map is Text, because
    5.55 -  //in that case empty string will be written, because
    5.56 -  //that is the deleter map
    5.57 -  //\todo isn't it a bit woodcutter?
    5.58 -
    5.59 -  for (EdgeIt i(g); i!=INVALID; ++i)
    5.60 -    {
    5.61 -      if(mapname!="Text")
    5.62 -	{
    5.63 -	  double number=(*(mapstorage.edgemap_storage)[mapname])[i];
    5.64 -	  int length=1;
    5.65 -	  //if number is smaller than one, length would be negative, or invalid
    5.66 -	  if(number>=1)
    5.67 -	    {
    5.68 -	      length=(int)(floor(log(number)/log(10)))+1;
    5.69 -	    }
    5.70 -	  int maxpos=(int)(pow(10,length-1));
    5.71 -	  int strl=length+1+RANGE;
    5.72 -	  char * str=new char[strl];
    5.73 -	  str[length]='.';
    5.74 -	  str[strl]='\0';
    5.75 -      
    5.76 -	  for(int j=0;j<strl;j++)
    5.77 -	    {
    5.78 -	      if(j!=length)
    5.79 -		{
    5.80 -		  int digit=(int)(number/maxpos);
    5.81 -		  str[j]=(digit+'0');
    5.82 -		  number-=digit*maxpos;
    5.83 -		  number*=10;
    5.84 -		}
    5.85 -	    }
    5.86 -      
    5.87 -	  edgetextmap[i]->property_text().set_value(str);
    5.88 -	}
    5.89 -      else
    5.90 -	{
    5.91 -	  edgetextmap[i]->property_text().set_value("");
    5.92 -	}
    5.93 -    }
    5.94 -  return 0;
    5.95 -};
    5.96 -
    5.97 -//Deprecated
    5.98 -bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
    5.99 -{
   5.100 -  switch(e->type)
   5.101 -  {
   5.102 -    case GDK_BUTTON_PRESS:
   5.103 -      //we mark the location of the event to be able to calculate parameters of dragging
   5.104 -      clicked_x=e->button.x;
   5.105 -      clicked_y=e->button.y;
   5.106 -      active_item=(get_item_at(e->button.x, e->button.y));
   5.107 -      isbutton=1;
   5.108 -      break;
   5.109 -    case GDK_BUTTON_RELEASE:
   5.110 -      isbutton=0;
   5.111 -      active_item=NULL;
   5.112 -      updateScrollRegion();
   5.113 -      break;
   5.114 -    case GDK_MOTION_NOTIFY:
   5.115 -      //we only have to do sg. if the mouse button is pressed
   5.116 -      if(isbutton)
   5.117 -      {
   5.118 -	//new coordinates will be the old values,
   5.119 -	//because the item will be moved to the
   5.120 -	//new coordinate therefore the new movement
   5.121 -	//has to be calculated from here
   5.122 -
   5.123 -        double dx=e->motion.x-clicked_x;
   5.124 -        double dy=e->motion.y-clicked_y;
   5.125 -        active_item->move(dx, dy);
   5.126 -        clicked_x=e->motion.x;
   5.127 -        clicked_y=e->motion.y;
   5.128 -
   5.129 -	//all the edges connected to the moved point has to be redrawn
   5.130 -
   5.131 -        EdgeIt e;
   5.132 -        g.firstOut(e,n);
   5.133 -        for(;e!=INVALID;g.nextOut(e))
   5.134 -        {
   5.135 -            Gnome::Canvas::Points coos;
   5.136 -            double x1, x2, y1, y2;
   5.137 -
   5.138 -            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
   5.139 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.140 -
   5.141 -            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
   5.142 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.143 -
   5.144 -            edgesmap[e]->property_points().set_value(coos);
   5.145 -
   5.146 -	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
   5.147 -
   5.148 -	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
   5.149 -	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
   5.150 -        }
   5.151 -
   5.152 -        g.firstIn(e,n);
   5.153 -        for(;e!=INVALID;g.nextIn(e))
   5.154 -        {
   5.155 -            Gnome::Canvas::Points coos;
   5.156 -            double x1, x2, y1, y2;
   5.157 -
   5.158 -            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
   5.159 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.160 -
   5.161 -            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
   5.162 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.163 -
   5.164 -            edgesmap[e]->property_points().set_value(coos);
   5.165 -
   5.166 -	    edgesmap[e]->get_bounds(x1, y1, x2, y2);
   5.167 -
   5.168 -	    edgetextmap[e]->property_x().set_value((x1+x2)/2);
   5.169 -	    edgetextmap[e]->property_y().set_value((y1+y2)/2);
   5.170 -        }
   5.171 -      }
   5.172 -    default: break;
   5.173 -  }
   5.174 -  return true;
   5.175 -}
   5.176 -
   5.177 -bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
   5.178 -{
   5.179 -  Gnome::Canvas::CanvasAA::on_expose_event(event);
   5.180 -  //usleep(10000);
   5.181 -  //rezoom();
   5.182 -  return true;
   5.183 -}
   5.184 -
   5.185 -void GraphDisplayerCanvas::zoomIn()
   5.186 -{
   5.187 -  set_pixels_per_unit(
   5.188 -      (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
   5.189 -}
   5.190 -
   5.191 -void GraphDisplayerCanvas::zoomOut()
   5.192 -{
   5.193 -  set_pixels_per_unit(
   5.194 -      (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
   5.195 -}
   5.196 -
   5.197 -void GraphDisplayerCanvas::zoomFit()
   5.198 -{
   5.199 -  // get the height and width of the canvas
   5.200 -  Gtk::Allocation a = get_allocation();
   5.201 -  int aw = a.get_width();
   5.202 -  int ah = a.get_height();
   5.203 -  // add some space
   5.204 -  aw -= 5; if (aw < 0) aw = 0;
   5.205 -  ah -= 5; if (ah < 0) ah = 0;
   5.206 -
   5.207 -  // get the bounding box of the graph
   5.208 -  double wx1, wy1, wx2, wy2;
   5.209 -  Gnome::Canvas::Item* pCanvasItem = root();
   5.210 -  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   5.211 -
   5.212 -  // fit the graph to the window
   5.213 -  double ppu1 = (double) aw / fabs(wx2 - wx1);
   5.214 -  double ppu2 = (double) ah / fabs(wy2 - wy1);
   5.215 -  set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
   5.216 -}
   5.217 -
   5.218 -void GraphDisplayerCanvas::zoom100()
   5.219 -{
   5.220 -  set_pixels_per_unit(1.0);
   5.221 -}
   5.222 -
   5.223 -void GraphDisplayerCanvas::updateScrollRegion()
   5.224 -{
   5.225 -  double wx1, wy1, wx2, wy2;
   5.226 -  Gnome::Canvas::Item* pCanvasItem = root();
   5.227 -  pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
   5.228 -  set_scroll_region(wx1, wy1, wx2, wy2);
   5.229 -}
   5.230 -
   5.231 -void GraphDisplayerCanvas::changeEditorialTool(int newtool)
   5.232 -{
   5.233 -  actual_handler.disconnect();
   5.234 -
   5.235 -  if(actual_tool==CREATE_EDGE)
   5.236 -    {
   5.237 -	GdkEvent * generated=new GdkEvent();
   5.238 -	generated->type=GDK_BUTTON_RELEASE;
   5.239 -	generated->button.button=3;
   5.240 -	create_edge_event_handler(generated);      
   5.241 -    }
   5.242 -
   5.243 -  actual_tool=newtool;
   5.244 -
   5.245 -  switch(newtool)
   5.246 -    {
   5.247 -    case MOVE:
   5.248 -      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
   5.249 -      break;
   5.250 -
   5.251 -      //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group
   5.252 -    case CREATE_NODE:
   5.253 -      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
   5.254 -      break;
   5.255 -
   5.256 -    case CREATE_EDGE:
   5.257 -      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
   5.258 -      break;
   5.259 -
   5.260 -    case ERASER:
   5.261 -      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraser_event_handler), false);
   5.262 -      break;
   5.263 -
   5.264 -    default:
   5.265 -      break;
   5.266 -    }
   5.267 -}
   5.268 -
   5.269 -int GraphDisplayerCanvas::get_actual_tool()
   5.270 -{
   5.271 -  return actual_tool;
   5.272 -}
   5.273 -
   5.274 -bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
   5.275 -{
   5.276 -  switch(e->type)
   5.277 -  {
   5.278 -    case GDK_BUTTON_PRESS:
   5.279 -      //we mark the location of the event to be able to calculate parameters of dragging
   5.280 -      clicked_x=e->button.x;
   5.281 -      clicked_y=e->button.y;
   5.282 -      active_item=(get_item_at(e->button.x, e->button.y));
   5.283 -      active_node=INVALID;
   5.284 -      for (NodeIt i(g); i!=INVALID; ++i)
   5.285 -	{
   5.286 -	  if(nodesmap[i]==active_item)
   5.287 -	    {
   5.288 -	      active_node=i;
   5.289 -	    }
   5.290 -	}
   5.291 -      switch(e->button.button)
   5.292 -	{
   5.293 -	case 3:      
   5.294 -	  isbutton=3;
   5.295 -	  break;
   5.296 -	default:
   5.297 -	  isbutton=1;
   5.298 -	  break;
   5.299 -	}
   5.300 -      break;
   5.301 -    case GDK_BUTTON_RELEASE:
   5.302 -      isbutton=0;
   5.303 -      active_item=NULL;
   5.304 -      active_node=INVALID;
   5.305 -      updateScrollRegion();
   5.306 -      break;
   5.307 -    case GDK_MOTION_NOTIFY:
   5.308 -      //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
   5.309 -      if(active_node!=INVALID)
   5.310 -      {
   5.311 -	//new coordinates will be the old values,
   5.312 -	//because the item will be moved to the
   5.313 -	//new coordinate therefore the new movement
   5.314 -	//has to be calculated from here
   5.315 -
   5.316 -        double dx=e->motion.x-clicked_x;
   5.317 -        double dy=e->motion.y-clicked_y;
   5.318 -
   5.319 -        active_item->move(dx, dy);
   5.320 -
   5.321 -        clicked_x=e->motion.x;
   5.322 -        clicked_y=e->motion.y;
   5.323 -
   5.324 -	//all the edges connected to the moved point has to be redrawn
   5.325 -        EdgeIt ei;
   5.326 -
   5.327 -        g.firstOut(ei,active_node);
   5.328 -
   5.329 -        for(;ei!=INVALID;g.nextOut(ei))
   5.330 -        {
   5.331 -            Gnome::Canvas::Points coos;
   5.332 -            double x1, x2, y1, y2;
   5.333 -
   5.334 -            nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
   5.335 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.336 -
   5.337 -            nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
   5.338 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.339 -
   5.340 -	    if(isbutton==3)
   5.341 -	      {
   5.342 -		edgesmap[ei]->set_points(coos);
   5.343 -	      }
   5.344 -	    else
   5.345 -	      {
   5.346 -		edgesmap[ei]->set_points(coos,true);
   5.347 -	      }
   5.348 -
   5.349 -	    xy<double> text_pos=edgesmap[ei]->get_arrow_pos();
   5.350 -	    text_pos+=(xy<double>(10,10));
   5.351 -	    edgetextmap[ei]->property_x().set_value(text_pos.x);
   5.352 -	    edgetextmap[ei]->property_y().set_value(text_pos.y);
   5.353 -        }
   5.354 -
   5.355 -        g.firstIn(ei,active_node);
   5.356 -        for(;ei!=INVALID;g.nextIn(ei))
   5.357 -        {
   5.358 -            Gnome::Canvas::Points coos;
   5.359 -            double x1, x2, y1, y2;
   5.360 -
   5.361 -            nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
   5.362 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.363 -
   5.364 -            nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
   5.365 -            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.366 -
   5.367 -	    if(isbutton==3)
   5.368 -	      {
   5.369 -		edgesmap[ei]->set_points(coos);
   5.370 -	      }
   5.371 -	    else
   5.372 -	      {
   5.373 -		edgesmap[ei]->set_points(coos,true);
   5.374 -	      }
   5.375 -
   5.376 -	    xy<double> text_pos=edgesmap[ei]->get_arrow_pos();
   5.377 -	    text_pos+=(xy<double>(10,10));
   5.378 -	    edgetextmap[ei]->property_x().set_value(text_pos.x);
   5.379 -	    edgetextmap[ei]->property_y().set_value(text_pos.y);
   5.380 -        }
   5.381 -      }
   5.382 -    default: break;
   5.383 -  }
   5.384 -
   5.385 -  return true;
   5.386 -}
   5.387 -
   5.388 -bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
   5.389 -{
   5.390 -  switch(e->type)
   5.391 -    {
   5.392 -
   5.393 -      //draw the new node in red at the clicked place
   5.394 -    case GDK_BUTTON_PRESS:
   5.395 -      isbutton=1;
   5.396 -
   5.397 -      active_node=NodeIt(g,g.addNode());
   5.398 -
   5.399 -      //initiating values corresponding to new node in maps
   5.400 -      
   5.401 -
   5.402 -      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
   5.403 -
   5.404 -      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
   5.405 -      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
   5.406 -      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
   5.407 -      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
   5.408 -      (nodesmap[active_node])->show();
   5.409 -      break;
   5.410 -
   5.411 -      //move the new node
   5.412 -    case GDK_MOTION_NOTIFY:
   5.413 -      {
   5.414 -	double world_motion_x, world_motion_y;
   5.415 -	GdkEvent * generated=new GdkEvent();
   5.416 -	window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
   5.417 -	generated->motion.x=world_motion_x;
   5.418 -	generated->motion.y=world_motion_y;
   5.419 -	generated->type=GDK_MOTION_NOTIFY;
   5.420 -	move_event_handler(generated);      
   5.421 -	break;
   5.422 -      }
   5.423 -
   5.424 -      //finalize the new node
   5.425 -    case GDK_BUTTON_RELEASE:
   5.426 -      isbutton=0;
   5.427 -      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   5.428 -      active_item=NULL;
   5.429 -      active_node=INVALID;
   5.430 -      updateScrollRegion();
   5.431 -      break;
   5.432 -    default:
   5.433 -      break;
   5.434 -    }
   5.435 -  return false;
   5.436 -}
   5.437 -
   5.438 -bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
   5.439 -{
   5.440 -  switch(e->type)
   5.441 -    {
   5.442 -    case GDK_BUTTON_PRESS:
   5.443 -      //in edge creation right button has special meaning
   5.444 -      if(e->button.button!=3)
   5.445 -	{
   5.446 -	  //there is not yet selected node
   5.447 -	  if(active_node==INVALID)
   5.448 -	    {
   5.449 -	      //we mark the location of the event to be able to calculate parameters of dragging
   5.450 -	      clicked_x=e->button.x;
   5.451 -	      clicked_y=e->button.y;
   5.452 -	      active_item=(get_item_at(e->button.x, e->button.y));
   5.453 -	      active_node=INVALID;
   5.454 -	      for (NodeIt i(g); i!=INVALID; ++i)
   5.455 -		{
   5.456 -		  if(nodesmap[i]==active_item)
   5.457 -		    {
   5.458 -		      active_node=i;
   5.459 -		    }
   5.460 -		}
   5.461 -	      //the clicked item is really a node
   5.462 -	      if(active_node!=INVALID)
   5.463 -		{
   5.464 -		  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
   5.465 -		  isbutton=1;
   5.466 -		}
   5.467 -	      //clicked item was not a node. It could be e.g. edge.
   5.468 -	      else
   5.469 -		{
   5.470 -		  active_item=NULL;
   5.471 -		}
   5.472 -	    }
   5.473 -	  //we only have to do sg. if the mouse button
   5.474 -	  // is pressed already once AND the click was
   5.475 -	  // on a node that was found in the set of 
   5.476 -	  //nodes, and now we only search for the second 
   5.477 -	  //node
   5.478 -	  else
   5.479 -	    {
   5.480 -	      target_item=(get_item_at(e->button.x, e->button.y));
   5.481 -	      Graph::NodeIt target_node=INVALID;
   5.482 -	      for (NodeIt i(g); i!=INVALID; ++i)
   5.483 -		{
   5.484 -		  if(nodesmap[i]==target_item)
   5.485 -		    {
   5.486 -		      target_node=i;
   5.487 -		    }
   5.488 -		}
   5.489 -	      //the clicked item is a node, the edge can be drawn
   5.490 -	      if(target_node!=INVALID)
   5.491 -		{
   5.492 -		  *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
   5.493 -
   5.494 -		  //creating new edge
   5.495 -		  active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
   5.496 -
   5.497 -		  //initiating values corresponding to new edge in maps
   5.498 -		  mapstorage.init_maps_for_edge(active_edge);
   5.499 -	  
   5.500 -		  //calculating coordinates of new edge
   5.501 -		  Gnome::Canvas::Points coos;
   5.502 -		  double x1, x2, y1, y2;
   5.503 -	  
   5.504 -		  active_item->get_bounds(x1, y1, x2, y2);
   5.505 -		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.506 -
   5.507 -		  target_item->get_bounds(x1, y1, x2, y2);
   5.508 -		  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
   5.509 -
   5.510 -		  //drawing new edge
   5.511 -		  edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
   5.512 -		  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
   5.513 -		  edgesmap[active_edge]->property_width_pixels().set_value(10);
   5.514 -
   5.515 -		  //redraw nodes to blank terminations of the new edge
   5.516 -		  target_item->raise_to_top();
   5.517 -		  active_item->raise_to_top();
   5.518 -
   5.519 -		  //initializing edge-text as well, to empty string
   5.520 -		  xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos();
   5.521 -		  text_pos+=(xy<double>(10,10));
   5.522 -
   5.523 -		  edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
   5.524 -		  edgetextmap[active_edge]->property_fill_color().set_value("black");
   5.525 -		}
   5.526 -	      //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
   5.527 -	      else
   5.528 -		{
   5.529 -		  target_item=NULL;
   5.530 -		}
   5.531 -	    }
   5.532 -	}
   5.533 -      break;
   5.534 -    case GDK_BUTTON_RELEASE:
   5.535 -      isbutton=0;
   5.536 -      //we clear settings in two cases
   5.537 -      //1: the edge is ready (target_item has valid value)
   5.538 -      //2: the edge creation is cancelled with right button
   5.539 -      if((target_item)||(e->button.button==3))
   5.540 -	{
   5.541 -	  if(active_item)
   5.542 -	    {
   5.543 -	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   5.544 -	      active_item=NULL;
   5.545 -	    }
   5.546 -	  if(target_item)
   5.547 -	    {
   5.548 -	      *target_item << Gnome::Canvas::Properties::fill_color("blue");
   5.549 -	      target_item=NULL;
   5.550 -	    }
   5.551 -	  active_node=INVALID;
   5.552 -	  active_edge=INVALID;
   5.553 -	}
   5.554 -      break;
   5.555 -    default:
   5.556 -      break;
   5.557 -    }
   5.558 -  return false;
   5.559 -}
   5.560 -
   5.561 -bool GraphDisplayerCanvas::eraser_event_handler(GdkEvent* e)
   5.562 -{
   5.563 -  switch(e->type)
   5.564 -    {
   5.565 -    case GDK_BUTTON_PRESS:
   5.566 -      active_item=(get_item_at(e->button.x, e->button.y));
   5.567 -      active_node=INVALID;
   5.568 -      active_edge=INVALID;
   5.569 -      for (NodeIt i(g); i!=INVALID; ++i)
   5.570 -	{
   5.571 -	  if(nodesmap[i]==active_item)
   5.572 -	    {
   5.573 -	      active_node=i;
   5.574 -	    }
   5.575 -	}
   5.576 -      if(active_node==INVALID)
   5.577 -	{
   5.578 -	  for (EdgeIt i(g); i!=INVALID; ++i)
   5.579 -	    {
   5.580 -	      if(edgesmap[i]==active_item)
   5.581 -		{
   5.582 -		  active_edge=i;
   5.583 -		}
   5.584 -	    }
   5.585 -	}
   5.586 -    *active_item << Gnome::Canvas::Properties::fill_color("red");
   5.587 -      break;
   5.588 -
   5.589 -    case GDK_BUTTON_RELEASE:
   5.590 -      if(active_item==(get_item_at(e->button.x, e->button.y)))
   5.591 -	{
   5.592 -	  if(active_node!=INVALID)
   5.593 -	    {
   5.594 -
   5.595 -	      //collecting edges to delete
   5.596 -	      EdgeIt e;
   5.597 -	      std::set<Graph::Edge> edges_to_delete;
   5.598 -
   5.599 -	      g.firstOut(e,active_node);
   5.600 -	      for(;e!=INVALID;g.nextOut(e))
   5.601 -		{
   5.602 -		      edges_to_delete.insert(e);
   5.603 -		}
   5.604 -
   5.605 -	      g.firstIn(e,active_node);
   5.606 -	      for(;e!=INVALID;g.nextIn(e))
   5.607 -		{
   5.608 -		      edges_to_delete.insert(e);
   5.609 -		}
   5.610 -
   5.611 -	      //deleting collected edges
   5.612 -	      for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
   5.613 -		{
   5.614 -		  delete_item(*edge_set_it);
   5.615 -		}
   5.616 -	      delete_item(active_node);
   5.617 -	    }
   5.618 -	  //a simple edge was chosen
   5.619 -	  else
   5.620 -	    {
   5.621 -	      delete_item(active_edge);
   5.622 -	    }
   5.623 -
   5.624 -	  
   5.625 -	}
   5.626 -      //pointer was moved, deletion is cancelled
   5.627 -      else
   5.628 -	{
   5.629 -	  if(active_node!=INVALID)
   5.630 -	    {
   5.631 -	      *active_item << Gnome::Canvas::Properties::fill_color("blue");
   5.632 -	    }
   5.633 -	  else
   5.634 -	    {
   5.635 -	      *active_item << Gnome::Canvas::Properties::fill_color("green");
   5.636 -	    }
   5.637 -	}
   5.638 -      //reseting datas
   5.639 -      active_item=NULL;
   5.640 -      active_edge=INVALID;
   5.641 -      active_node=INVALID;
   5.642 -      break;
   5.643 -
   5.644 -    case GDK_MOTION_NOTIFY:
   5.645 -      break;
   5.646 -
   5.647 -    default:
   5.648 -      break;
   5.649 -    }
   5.650 -  return true;
   5.651 -}
   5.652 -
   5.653 -void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete)
   5.654 -{
   5.655 -  delete(nodesmap[node_to_delete]);
   5.656 -  g.erase(node_to_delete);
   5.657 -}
   5.658 -
   5.659 -void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete)
   5.660 -{
   5.661 -  delete(edgesmap[edge_to_delete]);
   5.662 -  g.erase(edge_to_delete);
   5.663 -}
   5.664 -
   5.665 -void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete)
   5.666 -{
   5.667 -  delete(edgesmap[edge_to_delete]);
   5.668 -  g.erase(edge_to_delete);
   5.669 -}
   5.670 -
   5.671 -void GraphDisplayerCanvas::text_reposition(xy<double> new_place)
   5.672 -{
   5.673 -  new_place+=(xy<double>(10,10));
   5.674 -  edgetextmap[active_edge]->property_x().set_value(new_place.x);
   5.675 -  edgetextmap[active_edge]->property_y().set_value(new_place.y);
   5.676 -}
   5.677 -
   5.678 -void GraphDisplayerCanvas::toggle_edge_activity(BrokenEdge* active_bre, bool on)
   5.679 -{
   5.680 -  if(on)
   5.681 -    {
   5.682 -      if(active_edge!=INVALID)
   5.683 -	{
   5.684 -	  std::cout << "ERROR!!!! Valid edge found!" << std::endl;
   5.685 -	}
   5.686 -      else
   5.687 -	{
   5.688 -	  for (EdgeIt i(g); i!=INVALID; ++i)
   5.689 -	    {
   5.690 -	      if(edgesmap[i]==active_bre)
   5.691 -		{
   5.692 -		  active_edge=i;
   5.693 -		}
   5.694 -	    }
   5.695 -	}
   5.696 -    }
   5.697 -  else
   5.698 -    {
   5.699 -      if(active_edge!=INVALID)
   5.700 -	{
   5.701 -	  active_edge=INVALID;
   5.702 -	}
   5.703 -      else
   5.704 -	{
   5.705 -	  std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
   5.706 -	}
   5.707 -    }
   5.708 -
   5.709 -}