COIN-OR::LEMON - Graph Library

Changeset 66:4ca5a537ef07 in glemon-0.x


Ignore:
Timestamp:
08/26/05 09:35:23 (19 years ago)
Author:
Akos Ladanyi
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2161
Message:
  • use Gtk::Dialog to set the new values of edge and node maps
  • update all edges/nodes when editing a map so that edge widths and node sizes change properly
  • coordinate maps are no longer selectable in the maps window
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • graph_displayer_canvas-event.cc

    r65 r66  
    3333        case NODE_MAP_EDIT:
    3434          {
    35             GdkEvent * generated=new GdkEvent();
    36             generated->type=GDK_KEY_PRESS;
    37             ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    38             entryWidgetChangeHandler(generated);
    39             entrywidget.hide();
    4035            break;
    4136          }
     
    549544{
    550545  if(actual_tool==EDGE_MAP_EDIT)
     546  {
     547    switch(e->type)
    551548    {
    552       switch(e->type)
    553         {
    554         case GDK_KEY_PRESS:
    555           //for Escape or Enter hide the displayed widget
    556           {
    557             nodeMapEditEventHandler(e);
    558             break;
    559           }
    560         case GDK_BUTTON_PRESS:
    561           //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    562           {
    563             //for determine, whether it was an edge
    564             Edge clicked_edge=INVALID;
    565 
    566             //find the activated item between texts
    567             window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    568             active_item=(get_item_at(clicked_x, clicked_y));
    569             for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    570               {
    571                 if(edgetextmap[i]==active_item)
    572                   {
    573                     clicked_edge=i;
    574                   }
    575               }
    576 
    577             //if it was not between texts, search for it between edges
    578             if(clicked_edge==INVALID)
    579               {
    580                 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    581                   {
    582                     //at the same time only one can be active
    583                     if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
    584                       {
    585                         clicked_edge=i;
    586                       }
    587                   }
    588               }
    589             //if it was really an edge...
    590             if(clicked_edge!=INVALID)
    591               {
    592                 // the id map is not editable
    593                 if (edgemap_to_edit == "id") return 0;
    594 
    595                 //If there is already edited edge, it has to be saved first
    596                 if(entrywidget.is_visible())
    597                   {
    598                     GdkEvent * generated=new GdkEvent();
    599                     generated->type=GDK_KEY_PRESS;
    600                     ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    601                     entryWidgetChangeHandler(generated);
    602                   }
    603                 //If the previous value could be saved, we can go further, otherwise not
    604                 if(!entrywidget.is_visible())
    605                   {
    606                     //and there is activated map
    607                     if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    608                       {
    609                         //activate the general variable for it
    610                         active_edge=clicked_edge;
    611                         //delete visible widget if there is
    612                         if(canvasentrywidget)
    613                           {
    614                             delete(canvasentrywidget);
    615                           }
    616 
    617                         //initialize the entry
    618                         entrywidget.show();
    619 
    620                         //fill in the correct value
    621                         entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
    622 
    623                         //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
    624                         xy<double> entry_coos;
    625                         entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
    626                         entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
    627                         entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
    628                         entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
    629                         canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
    630                         canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
    631                         canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
    632 
    633                         //setting the focus to newly created widget
    634                         parentwin->set_focus(entrywidget);
    635                         parentwin->activate_focus();
    636                       }
    637                   }
    638               }
    639             //if it was not an edge...
    640             else
    641               {
    642                 //In this case the click did not happen on an edge
    643                 //if there is visible entry we save the value in it
    644                 //we pretend like an Enter was presse din the Entry widget
    645                 GdkEvent * generated=new GdkEvent();
    646                 generated->type=GDK_KEY_PRESS;
    647                 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    648                 entryWidgetChangeHandler(generated);
    649               }
    650             break;
    651           }
    652         default:
    653           break;
    654         }
     549      case GDK_BUTTON_PRESS:
     550        {
     551          //for determine, whether it was an edge
     552          Edge clicked_edge=INVALID;
     553
     554          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     555          active_item=(get_item_at(clicked_x, clicked_y));
     556
     557          //find the activated item between texts
     558          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     559          {
     560            //at the same time only one can be active
     561            if(edgetextmap[i]==active_item)
     562            {
     563              clicked_edge=i;
     564            }
     565          }
     566
     567          //if it was not between texts, search for it between edges
     568          if(clicked_edge==INVALID)
     569          {
     570            for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
     571            {
     572              //at the same time only one can be active
     573              if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
     574              {
     575                clicked_edge=i;
     576              }
     577            }
     578          }
     579 
     580          //if it was really an edge...
     581          if(clicked_edge!=INVALID)
     582          {
     583            // the id map is not editable
     584            if (edgemap_to_edit == "id") return 0;
     585
     586            //and there is activated map
     587            if(edgetextmap[clicked_edge]->property_text().get_value()!="")
     588            {
     589              //activate the general variable for it
     590              active_edge=clicked_edge;
     591
     592              //create a dialog
     593              Gtk::Dialog dialog("Edit value", *parentwin, true);
     594              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     595              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
     596              Gtk::VBox* vbox = dialog.get_vbox();
     597              Gtk::Adjustment adj(
     598                  (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge],
     599                  -1000000.0,
     600                  1000000.0,
     601                  1.0, 5.0, 0.0);
     602              //TODO: find out why doesn't it work with
     603              //numeric_limits<double>::min/max
     604              Gtk::SpinButton spin(adj);
     605              spin.set_numeric(true);
     606              spin.set_digits(4);
     607              vbox->add(spin);
     608              spin.show();
     609              switch (dialog.run())
     610              {
     611                case Gtk::RESPONSE_NONE:
     612                case Gtk::RESPONSE_CANCEL:
     613                  break;
     614                case Gtk::RESPONSE_ACCEPT:
     615                  double new_value = spin.get_value();
     616                  (*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] =
     617                    new_value;
     618                  std::ostringstream ostr;
     619                  ostr << new_value;
     620                  edgetextmap[active_edge]->property_text().set_value(
     621                      ostr.str());
     622                  //mapwin.updateEdge(active_edge);
     623                  mapwin.updateEdge(Edge(INVALID));
     624              }
     625            }
     626          }
     627          break;
     628        }
     629      default:
     630        break;
    655631    }
     632  }
    656633  return false; 
    657634}
     
    660637{
    661638  if(actual_tool==NODE_MAP_EDIT)
     639  {
     640    switch(e->type)
    662641    {
    663       switch(e->type)
    664         {
    665         case GDK_KEY_PRESS:
    666           //for Escape or Enter hide the displayed widget
    667           {
    668             switch(((GdkEventKey*)e)->keyval)
    669               {
    670               case GDK_Escape:
    671                 entrywidget.hide();
    672                 break;
    673               case GDK_Return:
    674               case GDK_KP_Enter:
    675                 entrywidget.hide();
    676                 break;
    677               default:
    678                 break;
    679               }
    680  
    681             break;
    682           }
    683         case GDK_BUTTON_PRESS:
    684           //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    685           {
    686             //for determine, whether it was a node
    687             Node clicked_node=INVALID;
    688 
    689             //find the activated item between texts
    690             active_item=(get_item_at(e->button.x, e->button.y));
    691             for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    692               {
    693                 //at the same time only one can be active
    694                 if(nodetextmap[i]==active_item)
    695                   {
    696                     clicked_node=i;
    697                   }
    698               }
    699 
    700             //if there was not, search for it between nodes
    701             if(clicked_node==INVALID)
    702               {
    703                 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    704                 active_item=(get_item_at(clicked_x, clicked_y));
    705 
    706                 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    707                   {
    708                     //at the same time only one can be active
    709                     if(nodesmap[i]==active_item)
    710                       {
    711                         clicked_node=i;
    712                       }
    713                   }
    714               }
    715             //if it was really an edge...
    716             if(clicked_node!=INVALID)
    717               {
    718                 // the id map is not editable
    719                 if (nodemap_to_edit == "id") return 0;
    720                 //If there is already edited edge, it has to be saved first
    721                 if(entrywidget.is_visible())
    722                   {
    723                     GdkEvent * generated=new GdkEvent();
    724                     generated->type=GDK_KEY_PRESS;
    725                     ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    726                     entryWidgetChangeHandler(generated);
    727                   }
    728                 //If the previous value could be saved, we can go further, otherwise not
    729                 if(!entrywidget.is_visible())
    730                   {
    731                     //and there is activated map
    732                     if(nodetextmap[clicked_node]->property_text().get_value()!="")
    733                       {
    734                         //activate the general variable for it
    735                         active_node=clicked_node;
    736                         //delete visible widget if there is
    737                         if(canvasentrywidget)
    738                           {
    739                             delete(canvasentrywidget);
    740                           }
    741 
    742                         //initialize the entry
    743                         entrywidget.show();
    744 
    745                         //fill in the correct value
    746                         entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
    747 
    748                         //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
    749                         xy<double> entry_coos;
    750                         entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
    751                         entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
    752                         entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
    753                         entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
    754                         canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
    755                         canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
    756                         canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
    757                       }
    758                   }
    759               }
    760             //if it was not an edge...
    761             else
    762               {
    763                 //In this case the click did not happen on an edge
    764                 //if there is visible entry we save the value in it
    765                 //we pretend like an Enter was presse din the Entry widget
    766                 GdkEvent * generated=new GdkEvent();
    767                 generated->type=GDK_KEY_PRESS;
    768                 ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    769                 entryWidgetChangeHandler(generated);
    770               }
    771             break;
    772           }
    773         default:
    774           break;
    775         }
     642      case GDK_BUTTON_PRESS:
     643        {
     644          //for determine, whether it was a node
     645          Node clicked_node=INVALID;
     646
     647          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     648          active_item=(get_item_at(clicked_x, clicked_y));
     649
     650          //find the activated item between texts
     651          for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     652          {
     653            //at the same time only one can be active
     654            if(nodetextmap[i]==active_item)
     655            {
     656              clicked_node=i;
     657            }
     658          }
     659
     660          //if there was not, search for it between nodes
     661          if(clicked_node==INVALID)
     662          {
     663            for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
     664            {
     665              //at the same time only one can be active
     666              if(nodesmap[i]==active_item)
     667              {
     668                clicked_node=i;
     669              }
     670            }
     671          }
     672
     673          //if it was really a node...
     674          if(clicked_node!=INVALID)
     675          {
     676            // the id map is not editable
     677            if (nodemap_to_edit == "id") return 0;
     678
     679            //and there is activated map
     680            if(nodetextmap[clicked_node]->property_text().get_value()!="")
     681            {
     682              //activate the general variable for it
     683              active_node=clicked_node;
     684
     685              //create a dialog
     686              Gtk::Dialog dialog("Edit value", *parentwin, true);
     687              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     688              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
     689              Gtk::VBox* vbox = dialog.get_vbox();
     690              Gtk::Adjustment adj(
     691                  (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node],
     692                  -1000000.0,
     693                  1000000.0,
     694                  1.0, 5.0, 0.0);
     695              //TODO: find out why doesn't it work with
     696              //numeric_limits<double>::min/max
     697              Gtk::SpinButton spin(adj);
     698              spin.set_numeric(true);
     699              spin.set_digits(4);
     700              vbox->add(spin);
     701              spin.show();
     702              switch (dialog.run())
     703              {
     704                case Gtk::RESPONSE_NONE:
     705                case Gtk::RESPONSE_CANCEL:
     706                  break;
     707                case Gtk::RESPONSE_ACCEPT:
     708                  double new_value = spin.get_value();
     709                  (*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] =
     710                    new_value;
     711                  std::ostringstream ostr;
     712                  ostr << new_value;
     713                  nodetextmap[active_node]->property_text().set_value(
     714                      ostr.str());
     715                  //mapwin.updateNode(active_node);
     716                  mapwin.updateNode(Node(INVALID));
     717              }
     718            }
     719          }
     720          break;
     721        }
     722      default:
     723        break;
    776724    }
     725  }
    777726  return false; 
    778 }
    779 
    780 bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
    781 {
    782   if(entrywidget.is_visible())
    783     {
    784       if(e->type==GDK_KEY_PRESS)
    785         {
    786           switch(((GdkEventKey*)e)->keyval)
    787             {
    788             case GDK_Escape:
    789               entrywidget.hide();
    790               break;
    791             case GDK_KP_Enter:
    792             case GDK_Return:
    793               {
    794                 //these variables check whether the text in the entry is valid
    795                 bool valid_double=true;
    796                 int point_num=0;
    797 
    798                 //getting the value from the entry and converting it to double
    799                 Glib::ustring mapvalue_str = entrywidget.get_text();
    800 
    801                 char * mapvalue_ch=new char [mapvalue_str.length()];
    802                 for(int i=0;i<(int)(mapvalue_str.length());i++)
    803                   {
    804                     if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
    805                       {
    806                         valid_double=false;
    807                       }
    808                     else
    809                       {
    810                         if(mapvalue_str[i]=='.')
    811                           {
    812                             point_num++;
    813                           }
    814                       }
    815                     mapvalue_ch[i]=mapvalue_str[i];
    816                   }
    817              
    818                 //if the text in the entry was correct
    819                 if((point_num<=1)&&(valid_double))
    820                   {
    821                     double mapvalue_d=atof(mapvalue_ch);
    822 
    823                     //reconvert the double to string for the correct format
    824                     std::ostringstream ostr;
    825                     ostr << mapvalue_d;
    826 
    827                     //save the value to the correct place
    828                     switch(actual_tool)
    829                       {
    830                       case EDGE_MAP_EDIT:
    831                         edgetextmap[active_edge]->property_text().set_value(ostr.str());
    832                         (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
    833                         mapwin.updateEdge(active_edge);
    834                         break;
    835                       case NODE_MAP_EDIT:
    836                         nodetextmap[active_node]->property_text().set_value(ostr.str());
    837                         (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
    838                         mapwin.updateNode(active_node);
    839                         break;
    840                       default:
    841                         break;
    842                       }
    843                     entrywidget.hide();
    844                   }
    845                 //the text in the entry was not correct for a double
    846                 else
    847                   {
    848                     std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
    849                   }
    850 
    851                 break;
    852               }
    853             default:
    854               break;
    855             }
    856         }
    857     }
    858   return false;
    859727}
    860728
  • graph_displayer_canvas.cc

    r63 r66  
    55GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
    66  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
    7   nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
    8   canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
    9   target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
     7  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms),
     8  isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
     9  edgemap_to_edit(""), mapwin(mw)
    1010{
    1111  parentwin=mainwin;
     
    1414  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    1515  actual_tool=MOVE;
    16 
    17   //setting event handler for the editor widget
    18   entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
    1916
    2017  active_node=INVALID;
     
    3532    delete edgesmap[e];
    3633    delete edgetextmap[e];
    37   }
    38 
    39   if(canvasentrywidget)
    40   {
    41     delete(canvasentrywidget);
    4234  }
    4335}
  • graph_displayer_canvas.h

    r62 r66  
    9191  bool nodeMapEditEventHandler(GdkEvent*);
    9292
    93   ///event handler for the case when the entry widget is changed
    94   bool entryWidgetChangeHandler(GdkEvent*);
    95 
    9693public:
    9794  ///Moves the text to new place
     
    141138  Gnome::Canvas::Group displayed_graph;
    142139
    143   ///Map editor entry
    144   Gtk::Entry entrywidget;
    145 
    146   ///GnomeCanvas holder for entry
    147   Gnome::Canvas::Widget * canvasentrywidget;
    148 
    149140  ///Here we store the maps that can be displayed through properties.
    150141  MapStorage & mapstorage;
     
    176167  MapWin & mapwin;
    177168
    178   ///We need to store the parent window to be able to set the focus on a given widget
    179   ///We will use this variable to activate the set focus on entry widget in the case of editing map values.
     169  ///pointer to the parent window
    180170  Gtk::Window * parentwin;
    181171
  • map_win.cc

    r62 r66  
    8282    for(;emsi!=ms.endOfNodeMaps();emsi++)
    8383    {
    84       listStrings.push_back(emsi->first);
     84      if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
     85      {
     86        listStrings.push_back(emsi->first);
     87      }
    8588    }
    8689
     
    149152    for(;emsi!=ms.endOfNodeMaps();emsi++)
    150153    {
    151       listStrings.push_back(emsi->first);
     154      if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
     155      {
     156        listStrings.push_back(emsi->first);
     157      }
    152158    }
    153159
Note: See TracChangeset for help on using the changeset viewer.