COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-event.cc @ 79:e6619f95c97e

gui
Last change on this file since 79:e6619f95c97e was 72:ebde44fded74, checked in by Akos Ladanyi, 19 years ago

placement of the coordinates caption now takes into account the node radius

  • Property exe set to *
File size: 24.0 KB
RevLine 
[53]1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
[59]3#include <cmath>
[27]4
5
6bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
7{
8  Gnome::Canvas::CanvasAA::on_expose_event(event);
9  //usleep(10000);
10  //rezoom();
11  return true;
12}
13
14void GraphDisplayerCanvas::changeEditorialTool(int newtool)
15{
[34]16  if(actual_tool!=newtool)
17    {
[27]18
[34]19      actual_handler.disconnect();
[27]20
[34]21      switch(actual_tool)
22        {
23        case CREATE_EDGE:
24          {
25            GdkEvent * generated=new GdkEvent();
26            generated->type=GDK_BUTTON_RELEASE;
27            generated->button.button=3;
28            createEdgeEventHandler(generated);     
29            break;
30          }
31        case EDGE_MAP_EDIT:
[35]32          //has to do the same thing as in the case of NODE_MAP_EDIT
33        case NODE_MAP_EDIT:
34          {
35            break;
36          }
[34]37        default:
38          break;
39        }
[27]40
[34]41      active_item=NULL;
42      target_item=NULL;
43      active_edge=INVALID;     
44      active_node=INVALID;     
[33]45
[27]46
[34]47      actual_tool=newtool;
48 
49      switch(newtool)
50        {
51        case MOVE:
52          actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
53          break;
[27]54
[34]55        case CREATE_NODE:
56          actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
57          break;
[27]58
[34]59        case CREATE_EDGE:
60          actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
61          break;
[27]62
[34]63        case ERASER:
64          actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
65          break;
[32]66
[34]67        case EDGE_MAP_EDIT:
68          grab_focus();
69          actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
70          break;
[32]71
[34]72        case NODE_MAP_EDIT:
73          actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
74          break;
75
76        default:
77          break;
78        }
[27]79    }
80}
81
[30]82int GraphDisplayerCanvas::getActualTool()
[27]83{
84  return actual_tool;
85}
86
[30]87bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
[27]88{
[70]89  static Gnome::Canvas::Text *coord_text = 0;
[27]90  switch(e->type)
91  {
92    case GDK_BUTTON_PRESS:
93      //we mark the location of the event to be able to calculate parameters of dragging
[31]94      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
95
96      active_item=(get_item_at(clicked_x, clicked_y));
[27]97      active_node=INVALID;
[53]98      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
[27]99        {
100          if(nodesmap[i]==active_item)
101            {
102              active_node=i;
103            }
104        }
105      switch(e->button.button)
106        {
107        case 3:     
108          isbutton=3;
109          break;
110        default:
111          isbutton=1;
112          break;
113        }
114      break;
115    case GDK_BUTTON_RELEASE:
[70]116      if (coord_text)
117      {
118        delete coord_text;
119        coord_text = 0;
120      }
[27]121      isbutton=0;
122      active_item=NULL;
123      active_node=INVALID;
124      break;
125    case GDK_MOTION_NOTIFY:
126      //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
127      if(active_node!=INVALID)
128      {
[53]129        mapstorage.modified = true;
[70]130
[27]131        //new coordinates will be the old values,
132        //because the item will be moved to the
133        //new coordinate therefore the new movement
134        //has to be calculated from here
135
[31]136        double new_x, new_y;
137
138        window_to_world (e->motion.x, e->motion.y, new_x, new_y);
139
140        double dx=new_x-clicked_x;
141        double dy=new_y-clicked_y;
[27]142
[28]143        //repositioning node and its text
[27]144        active_item->move(dx, dy);
[28]145        nodetextmap[active_node]->move(dx, dy);
[27]146
[70]147        // the new coordinates of the centre of the node
148        double coord_x = new_x - (clicked_x - mapstorage.coords[active_node].x);
149        double coord_y = new_y - (clicked_y - mapstorage.coords[active_node].y);
150
[31]151        clicked_x=new_x;
152        clicked_y=new_y;
[27]153
[70]154        // write back the new coordinates to the coords map
155        mapstorage.coords.set(active_node, xy<double>(coord_x, coord_y));
[27]156
[70]157        // reposition the coordinates text
158        std::ostringstream ostr;
159        ostr << "(" <<
160          mapstorage.coords[active_node].x << ", " <<
161          mapstorage.coords[active_node].y << ")";
[72]162        double radius =
163          (nodesmap[active_node]->property_x2().get_value() -
164          nodesmap[active_node]->property_x1().get_value()) / 2.0;
[70]165        if (coord_text)
166        {
167          coord_text->property_text().set_value(ostr.str());
168          coord_text->property_x().set_value(mapstorage.coords[active_node].x +
[72]169              radius);
170          coord_text->property_y().set_value(mapstorage.coords[active_node].y -
171              radius);
[70]172        }
173        else
174        {
175          coord_text = new Gnome::Canvas::Text(
176              displayed_graph,
[72]177              mapstorage.coords[active_node].x + radius,
178              mapstorage.coords[active_node].y - radius,
[70]179              ostr.str());
180          coord_text->property_fill_color().set_value("black");
[72]181          coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
[70]182        }
183
184        //all the edges connected to the moved point has to be redrawn
[69]185        for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
[27]186        {
187            Gnome::Canvas::Points coos;
188            double x1, x2, y1, y2;
189
[53]190            nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
[27]191            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
192
[53]193            nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
[27]194            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
195
196            if(isbutton==3)
197              {
[30]198                edgesmap[ei]->setPoints(coos);
[27]199              }
200            else
201              {
[30]202                edgesmap[ei]->setPoints(coos,true);
[27]203              }
204
[28]205            //reposition of edgetext
[30]206            xy<double> text_pos=edgesmap[ei]->getArrowPos();
[27]207            text_pos+=(xy<double>(10,10));
208            edgetextmap[ei]->property_x().set_value(text_pos.x);
209            edgetextmap[ei]->property_y().set_value(text_pos.y);
210        }
211
[69]212        for(InEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
[27]213        {
214            Gnome::Canvas::Points coos;
215            double x1, x2, y1, y2;
216
[53]217            nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
[27]218            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
219
[53]220            nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
[27]221            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
222
223            if(isbutton==3)
224              {
[30]225                edgesmap[ei]->setPoints(coos);
[27]226              }
227            else
228              {
[30]229                edgesmap[ei]->setPoints(coos,true);
[27]230              }
231
[30]232            xy<double> text_pos=edgesmap[ei]->getArrowPos();
[27]233            text_pos+=(xy<double>(10,10));
234            edgetextmap[ei]->property_x().set_value(text_pos.x);
235            edgetextmap[ei]->property_y().set_value(text_pos.y);
236        }
237      }
238    default: break;
239  }
240
[31]241  return false;
[27]242}
243
[30]244bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
[27]245{
246  switch(e->type)
[63]247  {
248    //move the new node
249    case GDK_MOTION_NOTIFY:
250      {
251        GdkEvent * generated=new GdkEvent();
252        generated->motion.x=e->motion.x;
253        generated->motion.y=e->motion.y;
254        generated->type=GDK_MOTION_NOTIFY;
255        moveEventHandler(generated);     
256        break;
257      }
[27]258
[63]259    case GDK_BUTTON_RELEASE:
[53]260      mapstorage.modified = true;
261
[27]262      isbutton=1;
263
[62]264      active_node=mapstorage.graph.addNode();
[27]265
266      //initiating values corresponding to new node in maps
267
268      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
269
[63]270      // update coordinates
[53]271      mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
[63]272
273      // update all other maps
274      for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
275          mapstorage.nodemap_storage.begin(); it !=
276          mapstorage.nodemap_storage.end(); ++it)
277      {
[64]278        if ((it->first != "coordinates_x") &&
279            (it->first != "coordinates_y"))
[63]280        {
281          (*(it->second))[active_node] =
282            mapstorage.nodemap_default[it->first];
283        }
284      }
[64]285      // increment the id map's default value
286      mapstorage.nodemap_default["id"] += 1.0;
[63]287
[53]288      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
[63]289          clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
[27]290      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
[63]291      *(nodesmap[active_node]) <<
292        Gnome::Canvas::Properties::fill_color("blue");
293      *(nodesmap[active_node]) <<
294        Gnome::Canvas::Properties::outline_color("black");
295      active_item->raise_to_top();
296
[27]297      (nodesmap[active_node])->show();
[28]298
[53]299      nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
[63]300          clicked_x+node_property_defaults[N_RADIUS]+5,
301          clicked_y+node_property_defaults[N_RADIUS]+5, "");
[28]302      nodetextmap[active_node]->property_fill_color().set_value("darkblue");
[63]303      nodetextmap[active_node]->raise_to_top();
[28]304
[53]305      mapwin.updateNode(active_node);
[28]306
[27]307      isbutton=0;
[31]308      target_item=NULL;
[27]309      active_item=NULL;
310      active_node=INVALID;
[63]311
[27]312      break;
313    default:
314      break;
[63]315  }
[27]316  return false;
317}
318
[30]319bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
[27]320{
321  switch(e->type)
[63]322  {
[27]323    case GDK_BUTTON_PRESS:
324      //in edge creation right button has special meaning
325      if(e->button.button!=3)
[63]326      {
327        //there is not yet selected node
328        if(active_node==INVALID)
329        {
330          //we mark the location of the event to be able to calculate parameters of dragging
[31]331
[63]332          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
[31]333
[63]334          active_item=(get_item_at(clicked_x, clicked_y));
335          active_node=INVALID;
336          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
337          {
338            if(nodesmap[i]==active_item)
339            {
340              active_node=i;
341            }
342          }
343          //the clicked item is really a node
344          if(active_node!=INVALID)
345          {
346            *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
347            isbutton=1;
348          }
349          //clicked item was not a node. It could be e.g. edge.
350          else
351          {
352            active_item=NULL;
353          }
354        }
355        //we only have to do sg. if the mouse button
356        // is pressed already once AND the click was
357        // on a node that was found in the set of
358        //nodes, and now we only search for the second
359        //node
360        else
361        {
362          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
363          target_item=(get_item_at(clicked_x, clicked_y));
364          Node target_node=INVALID;
365          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
366          {
367            if(nodesmap[i]==target_item)
368            {
369              target_node=i;
370            }
371          }
372          //the clicked item is a node, the edge can be drawn
373          if(target_node!=INVALID)
374          {
375            if(target_node!=active_node)               
376            {
377              mapstorage.modified = true;
[53]378
[63]379              *(nodesmap[target_node]) <<
380                Gnome::Canvas::Properties::fill_color("red");
[27]381
[63]382              //creating new edge
383              active_edge=mapstorage.graph.addEdge(active_node,
384                  target_node);
[27]385
[64]386              // update maps
[63]387              for (std::map<std::string,
388                  Graph::EdgeMap<double>*>::const_iterator it =
389                  mapstorage.edgemap_storage.begin(); it !=
390                  mapstorage.edgemap_storage.end(); ++it)
391              {
[64]392                (*(it->second))[active_edge] =
393                  mapstorage.edgemap_default[it->first];
[63]394              }
[64]395              // increment the id map's default value
396              mapstorage.edgemap_default["id"] += 1.0;
[27]397
[63]398              //calculating coordinates of new edge
399              Gnome::Canvas::Points coos;
400              double x1, x2, y1, y2;
[27]401
[63]402              active_item->get_bounds(x1, y1, x2, y2);
403              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
[27]404
[63]405              target_item->get_bounds(x1, y1, x2, y2);
406              coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
[27]407
[63]408              //drawing new edge
409              edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
410                  *this);
411              *(edgesmap[active_edge]) <<
412                Gnome::Canvas::Properties::fill_color("green");
413              edgesmap[active_edge]->property_width_pixels().set_value(10);
[27]414
[63]415              edgesmap[active_edge]->lower_to_bottom();
[28]416
[63]417              //initializing edge-text as well, to empty string
418              xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
419              text_pos+=(xy<double>(10,10));
420
421              edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
422                  text_pos.x, text_pos.y, "");
423              edgetextmap[active_edge]->property_fill_color().set_value(
424                  "darkgreen");
425              edgetextmap[active_edge]->raise_to_top();
426
427              //updating its properties
428              mapwin.updateEdge(active_edge);
429            }
430            else
431            {
432              target_node=INVALID;
433              std::cerr << "Loop edge is not yet implemented!" << std::endl;
434            }
435          }
436          //clicked item was not a node. it could be an e.g. edge. we do not
437          //deal with it furthermore.
438          else
439          {
440            target_item=NULL;
441          }
442        }
443      }
[27]444      break;
445    case GDK_BUTTON_RELEASE:
446      isbutton=0;
447      //we clear settings in two cases
448      //1: the edge is ready (target_item has valid value)
449      //2: the edge creation is cancelled with right button
450      if((target_item)||(e->button.button==3))
[63]451      {
452        if(active_item)
453        {
454          *active_item << Gnome::Canvas::Properties::fill_color("blue");
455          active_item=NULL;
456        }
457        if(target_item)
458        {
459          *target_item << Gnome::Canvas::Properties::fill_color("blue");
460          target_item=NULL;
461        }
462        active_node=INVALID;
463        active_edge=INVALID;
464      }
[27]465      break;
466    default:
467      break;
[63]468  }
[27]469  return false;
470}
471
[30]472bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
[27]473{
474  switch(e->type)
475    {
476    case GDK_BUTTON_PRESS:
[43]477      //finding the clicked items
[31]478      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
479      active_item=(get_item_at(clicked_x, clicked_y));
[27]480      active_node=INVALID;
481      active_edge=INVALID;
[43]482      //was it a node?
[53]483      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
[27]484        {
485          if(nodesmap[i]==active_item)
486            {
487              active_node=i;
488            }
489        }
[43]490      //or was it an edge?
[27]491      if(active_node==INVALID)
492        {
[53]493          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[27]494            {
495              if(edgesmap[i]==active_item)
496                {
497                  active_edge=i;
498                }
499            }
500        }
[43]501
502      //recolor activated item
[31]503      if(active_item)
504        {
505          *active_item << Gnome::Canvas::Properties::fill_color("red");
506        }
[27]507      break;
508
509    case GDK_BUTTON_RELEASE:
[31]510      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
511      if(active_item)
[27]512        {
[43]513          //the cursor was not moved since pressing it
[31]514          if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
[27]515            {
[43]516              //a node was found
[31]517              if(active_node!=INVALID)
518                {
[53]519                  mapstorage.modified = true;
[27]520
[31]521                  std::set<Graph::Edge> edges_to_delete;
[27]522
[69]523                  for(OutEdgeIt e(mapstorage.graph,active_node);e!=INVALID;++e)
[31]524                    {
525                      edges_to_delete.insert(e);
526                    }
[69]527                 
528                  for(InEdgeIt e(mapstorage.graph,active_node);e!=INVALID;++e)
[31]529                    {
530                      edges_to_delete.insert(e);
531                    }
[69]532                 
[31]533                  //deleting collected edges
[69]534                  for(std::set<Graph::Edge>::iterator
535                        edge_set_it=edges_to_delete.begin();
536                      edge_set_it!=edges_to_delete.end();
537                      ++edge_set_it)
[31]538                    {
539                      deleteItem(*edge_set_it);
540                    }
541                  deleteItem(active_node);
542                }
543              //a simple edge was chosen
544              else
[27]545                {
[31]546                  deleteItem(active_edge);
[27]547                }
548            }
[31]549          //pointer was moved, deletion is cancelled
[27]550          else
551            {
[31]552              if(active_node!=INVALID)
553                {
554                  *active_item << Gnome::Canvas::Properties::fill_color("blue");
555                }
556              else
557                {
558                  *active_item << Gnome::Canvas::Properties::fill_color("green");
559                }
[27]560            }
561        }
562      //reseting datas
563      active_item=NULL;
564      active_edge=INVALID;
565      active_node=INVALID;
566      break;
567
568    case GDK_MOTION_NOTIFY:
569      break;
570
571    default:
572      break;
573    }
[31]574  return false;
[27]575}
576
[32]577bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
578{
[48]579  if(actual_tool==EDGE_MAP_EDIT)
[66]580  {
581    switch(e->type)
[32]582    {
[66]583      case GDK_BUTTON_PRESS:
584        {
585          //for determine, whether it was an edge
586          Edge clicked_edge=INVALID;
[43]587
[66]588          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
589          active_item=(get_item_at(clicked_x, clicked_y));
[48]590
[66]591          //find the activated item between texts
592          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
593          {
594            //at the same time only one can be active
595            if(edgetextmap[i]==active_item)
596            {
597              clicked_edge=i;
598            }
599          }
[65]600
[66]601          //if it was not between texts, search for it between edges
602          if(clicked_edge==INVALID)
603          {
604            for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
605            {
606              //at the same time only one can be active
607              if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
608              {
609                clicked_edge=i;
610              }
611            }
612          }
613 
614          //if it was really an edge...
615          if(clicked_edge!=INVALID)
616          {
617            // the id map is not editable
618            if (edgemap_to_edit == "id") return 0;
[48]619
[66]620            //and there is activated map
621            if(edgetextmap[clicked_edge]->property_text().get_value()!="")
622            {
623              //activate the general variable for it
624              active_edge=clicked_edge;
[48]625
[66]626              //create a dialog
627              Gtk::Dialog dialog("Edit value", *parentwin, true);
628              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
629              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
630              Gtk::VBox* vbox = dialog.get_vbox();
631              Gtk::Adjustment adj(
632                  (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge],
633                  -1000000.0,
634                  1000000.0,
635                  1.0, 5.0, 0.0);
636              //TODO: find out why doesn't it work with
637              //numeric_limits<double>::min/max
638              Gtk::SpinButton spin(adj);
639              spin.set_numeric(true);
640              spin.set_digits(4);
641              vbox->add(spin);
642              spin.show();
643              switch (dialog.run())
644              {
645                case Gtk::RESPONSE_NONE:
646                case Gtk::RESPONSE_CANCEL:
647                  break;
648                case Gtk::RESPONSE_ACCEPT:
649                  double new_value = spin.get_value();
650                  (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] =
651                    new_value;
652                  std::ostringstream ostr;
653                  ostr << new_value;
654                  edgetextmap[active_edge]->property_text().set_value(
655                      ostr.str());
656                  //mapwin.updateEdge(active_edge);
657                  mapwin.updateEdge(Edge(INVALID));
658              }
659            }
660          }
661          break;
662        }
663      default:
664        break;
[32]665    }
[66]666  }
[32]667  return false; 
668}
669
670bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
671{
[48]672  if(actual_tool==NODE_MAP_EDIT)
[66]673  {
674    switch(e->type)
[35]675    {
[66]676      case GDK_BUTTON_PRESS:
677        {
678          //for determine, whether it was a node
679          Node clicked_node=INVALID;
[43]680
[66]681          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
682          active_item=(get_item_at(clicked_x, clicked_y));
[43]683
[66]684          //find the activated item between texts
685          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
686          {
687            //at the same time only one can be active
688            if(nodetextmap[i]==active_item)
689            {
690              clicked_node=i;
691            }
692          }
[48]693
[66]694          //if there was not, search for it between nodes
695          if(clicked_node==INVALID)
696          {
697            for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
698            {
699              //at the same time only one can be active
700              if(nodesmap[i]==active_item)
701              {
702                clicked_node=i;
703              }
704            }
705          }
[48]706
[66]707          //if it was really a node...
708          if(clicked_node!=INVALID)
709          {
710            // the id map is not editable
711            if (nodemap_to_edit == "id") return 0;
[48]712
[66]713            //and there is activated map
714            if(nodetextmap[clicked_node]->property_text().get_value()!="")
715            {
716              //activate the general variable for it
717              active_node=clicked_node;
[48]718
[66]719              //create a dialog
720              Gtk::Dialog dialog("Edit value", *parentwin, true);
721              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
722              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
723              Gtk::VBox* vbox = dialog.get_vbox();
724              Gtk::Adjustment adj(
725                  (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node],
726                  -1000000.0,
727                  1000000.0,
728                  1.0, 5.0, 0.0);
729              //TODO: find out why doesn't it work with
730              //numeric_limits<double>::min/max
731              Gtk::SpinButton spin(adj);
732              spin.set_numeric(true);
733              spin.set_digits(4);
734              vbox->add(spin);
735              spin.show();
736              switch (dialog.run())
737              {
738                case Gtk::RESPONSE_NONE:
739                case Gtk::RESPONSE_CANCEL:
740                  break;
741                case Gtk::RESPONSE_ACCEPT:
742                  double new_value = spin.get_value();
743                  (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] =
744                    new_value;
745                  std::ostringstream ostr;
746                  ostr << new_value;
747                  nodetextmap[active_node]->property_text().set_value(
748                      ostr.str());
749                  //mapwin.updateNode(active_node);
750                  mapwin.updateNode(Node(INVALID));
751              }
752            }
753          }
754          break;
755        }
756      default:
757        break;
[35]758    }
[66]759  }
[35]760  return false; 
[32]761}
762
[62]763void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
[27]764{
[28]765  delete(nodetextmap[node_to_delete]);
[27]766  delete(nodesmap[node_to_delete]);
[53]767  mapstorage.graph.erase(node_to_delete);
[27]768}
769
[62]770void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
[27]771{
[28]772  delete(edgetextmap[edge_to_delete]);
[27]773  delete(edgesmap[edge_to_delete]);
[53]774  mapstorage.graph.erase(edge_to_delete);
[27]775}
776
[30]777void GraphDisplayerCanvas::textReposition(xy<double> new_place)
[27]778{
779  new_place+=(xy<double>(10,10));
[35]780  edgetextmap[forming_edge]->property_x().set_value(new_place.x);
781  edgetextmap[forming_edge]->property_y().set_value(new_place.y);
[27]782}
783
[30]784void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
[27]785{
786  if(on)
787    {
[35]788      if(forming_edge!=INVALID)
[27]789        {
[48]790          std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
[27]791        }
792      else
793        {
[53]794          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[27]795            {
796              if(edgesmap[i]==active_bre)
797                {
[35]798                  forming_edge=i;
[27]799                }
800            }
801        }
802    }
803  else
804    {
[35]805      if(forming_edge!=INVALID)
[27]806        {
[35]807          forming_edge=INVALID;
[27]808        }
809      else
810        {
[48]811          std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
[27]812        }
813    }
814
815}
[32]816
[46]817int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
[37]818{
[43]819  //create the new map
[53]820  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
[46]821
822  //if addition was not successful addEdgeMap returns one.
823  //cause can be that there is already a map named like the new one
[63]824  if(mapstorage.addEdgeMap(mapname,emptr, default_value))
[46]825    {
826      return 1;
827    }
828
[43]829
830  //add it to the list of the displayable maps
[53]831  mapwin.registerNewEdgeMap(mapname);
[43]832
833  //display it
[41]834  changeEdgeText(mapname);
[46]835
836  return 0;
[37]837}
838
[46]839int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
[37]840{
[43]841  //create the new map
[53]842  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
[46]843
844  //if addition was not successful addNodeMap returns one.
845  //cause can be that there is already a map named like the new one
[63]846  if(mapstorage.addNodeMap(mapname,emptr, default_value))
[46]847    {
848      return 1;
849    }
[43]850
851  //add it to the list of the displayable maps
[53]852  mapwin.registerNewNodeMap(mapname);
[43]853
854  //display it
[41]855  changeNodeText(mapname);
[46]856
857  return 0;
[37]858}
859
Note: See TracBrowser for help on using the repository browser.