COIN-OR::LEMON - Graph Library

Changeset 48:b8ec84524fa2 in glemon-0.x


Ignore:
Timestamp:
07/28/05 17:54:00 (19 years ago)
Author:
Hegyi Péter
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2104
Message:

cout->cerr, node radius and edge width is now scaled, maps are editable by clicking on texts.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r41 r48  
    1919        map_win.cc \
    2020        map_win.h \
    21         edit_win.cc \
    22         edit_win.h \
    2321        broken_edge.cc \
    2422        broken_edge.h \
  • all_include.h

    r37 r48  
    2323#define WIN_WIDTH 900
    2424#define WIN_HEIGHT 600
    25 #define ALMOST_ONE 0.9999999999
     25#define MIN_EDGE_WIDTH 2
     26#define MAX_EDGE_WIDTH 40
     27#define MIN_NODE_RADIUS 2
     28#define MAX_NODE_RADIUS 80
    2629
    2730#ifndef MAIN_PART
  • graph_displayer_canvas-edge.cc

    r47 r48  
    77{
    88  Graph::EdgeMap<double> * actual_map;
     9  double min, max;
     10
    911  if(mapname=="Default")
    1012    {
     13      min=edge_property_defaults[E_WIDTH];
     14      max=edge_property_defaults[E_WIDTH];
    1115      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
    1216    }
    1317  else
    1418    {
     19      min=mapstorage.minOfEdgeMap(mapname);
     20      max=mapstorage.maxOfEdgeMap(mapname);
    1521      actual_map=(mapstorage.edgemap_storage)[mapname];
    1622    }
     
    2026      for (EdgeIt i(g); i!=INVALID; ++i)
    2127        {
    22           int w=(int)(*actual_map)[i];
    23           if(w>=0)
     28          double v=abs((*actual_map)[i]);
     29          int w;
     30          if(min==max)
    2431            {
    25               edgesmap[i]->property_width_units().set_value(w);
     32              w=(int)(edge_property_defaults[E_WIDTH]);
    2633            }
     34          else
     35            {
     36              w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
     37            }
     38          edgesmap[i]->property_width_units().set_value(w);
    2739        }
    2840    }
  • graph_displayer_canvas-event.cc

    r47 r48  
    217217      //draw the new node in red at the clicked place
    218218    case GDK_2BUTTON_PRESS:
    219       std::cout << "double click" << std::endl;
     219      //std::cout << "double click" << std::endl;
    220220      break;
    221221    case GDK_BUTTON_PRESS:
     
    382382                    {
    383383                      target_node=INVALID;
    384                       std::cout << "Loop edge is not yet implemented!" << std::endl;
     384                      std::cerr << "Loop edge is not yet implemented!" << std::endl;
    385385                    }
    386386                }
     
    528528bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
    529529{
    530   switch(e->type)
    531     {
    532     case GDK_KEY_PRESS:
    533       //for Escape or Enter hide the displayed widget
    534       {
    535         nodeMapEditEventHandler(e);
    536         break;
    537       }
    538     case GDK_BUTTON_PRESS:
    539       //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    540       {
    541         //find the activated item
    542         window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    543         active_item=(get_item_at(clicked_x, clicked_y));
    544 
    545         //determine, whether it was an edge
    546         Graph::EdgeIt clicked_edge=INVALID;
    547         for (EdgeIt i(g); i!=INVALID; ++i)
     530  if(actual_tool==EDGE_MAP_EDIT)
     531    {
     532      switch(e->type)
     533        {
     534        case GDK_KEY_PRESS:
     535          //for Escape or Enter hide the displayed widget
    548536          {
    549             if(edgesmap[i]==active_item)
    550               {
    551                 clicked_edge=i;
    552               }
     537            nodeMapEditEventHandler(e);
     538            break;
    553539          }
    554         //if it was really an edge...
    555         if(clicked_edge!=INVALID)
     540        case GDK_BUTTON_PRESS:
     541          //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    556542          {
    557             //If there is already edited edge, it has to be saved first
    558             if(entrywidget.is_visible())
    559               {
     543            //for determine, whether it was an edge
     544            Graph::EdgeIt clicked_edge=INVALID;
     545
     546            //find the activated item between texts
     547            active_item=(get_item_at(e->button.x, e->button.y));
     548            for (EdgeIt i(g); i!=INVALID; ++i)
     549              {
     550                if(edgetextmap[i]==active_item)
     551                  {
     552                    clicked_edge=i;
     553                  }
     554              }
     555
     556            //if it was not between texts, search for it between edges
     557            if(clicked_edge==INVALID)
     558              {
     559                window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     560                active_item=(get_item_at(clicked_x, clicked_y));
     561
     562                for (EdgeIt i(g); i!=INVALID; ++i)
     563                  {
     564                    //at the same time only one can be active
     565                    if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
     566                      {
     567                        clicked_edge=i;
     568                      }
     569                  }
     570              }
     571            //if it was really an edge...
     572            if(clicked_edge!=INVALID)
     573              {
     574                //If there is already edited edge, it has to be saved first
     575                if(entrywidget.is_visible())
     576                  {
     577                    GdkEvent * generated=new GdkEvent();
     578                    generated->type=GDK_KEY_PRESS;
     579                    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
     580                    entryWidgetChangeHandler(generated);
     581                  }
     582                //If the previous value could be saved, we can go further, otherwise not
     583                if(!entrywidget.is_visible())
     584                  {
     585                    //and there is activated map
     586                    if(edgetextmap[clicked_edge]->property_text().get_value()!="")
     587                      {
     588                        //activate the general variable for it
     589                        active_edge=clicked_edge;
     590                        //delete visible widget if there is
     591                        if(canvasentrywidget)
     592                          {
     593                            delete(canvasentrywidget);
     594                          }
     595
     596                        //initialize the entry
     597                        entrywidget.show();
     598
     599                        //fill in the correct value
     600                        entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
     601
     602                        //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
     603                        xy<double> entry_coos;
     604                        entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
     605                        entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
     606                        entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
     607                        entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
     608                        canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
     609                        canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
     610                        canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
     611                      }
     612                  }
     613              }
     614            //if it was not an edge...
     615            else
     616              {
     617                //In this case the click did not happen on an edge
     618                //if there is visible entry we save the value in it
     619                //we pretend like an Enter was presse din the Entry widget
    560620                GdkEvent * generated=new GdkEvent();
    561621                generated->type=GDK_KEY_PRESS;
     
    563623                entryWidgetChangeHandler(generated);
    564624              }
    565             //If the previous value could be saved, we can go further, otherwise not
    566             if(!entrywidget.is_visible())
    567               {
    568                 //and there is activated map
    569                 if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    570                   {
    571                     //activate the general variable for it
    572                     active_edge=clicked_edge;
    573                     //delete visible widget if there is
    574                     if(canvasentrywidget)
    575                       {
    576                         delete(canvasentrywidget);
    577                       }
    578 
    579                     //initialize the entry
    580                     entrywidget.show();
    581 
    582                     //fill in the correct value
    583                     entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
    584 
    585                     //replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
    586                     xy<double> entry_coos;
    587                     entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
    588                     entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
    589                     entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
    590                     entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
    591                     canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
    592                     canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
    593                     canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
    594                   }
    595               }
    596           }
    597         //if it was not an edge...
    598         else
    599           {
    600             //In this case the click did not happen on an edge
    601             //if there is visible entry we save the value in it
    602             //we pretend like an Enter was presse din the Entry widget
    603             GdkEvent * generated=new GdkEvent();
    604             generated->type=GDK_KEY_PRESS;
    605             ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    606             entryWidgetChangeHandler(generated);
    607           }
    608         break;
    609       }
    610     default:
    611       break;
    612     }
    613   return false; 
    614 }
    615 
    616 bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
    617 {
    618   switch(e->type)
    619     {
    620     case GDK_KEY_PRESS:
    621       //for Escape or Enter hide the displayed widget
    622       {
    623         switch(((GdkEventKey*)e)->keyval)
    624           {
    625           case GDK_Escape:
    626             entrywidget.hide();
    627             break;
    628           case GDK_Return:
    629           case GDK_KP_Enter:
    630             entrywidget.hide();
    631             break;
    632           default:
    633625            break;
    634626          }
     627        default:
     628          break;
     629        }
     630    }
     631  return false; 
     632}
     633
     634bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
     635{
     636  if(actual_tool==NODE_MAP_EDIT)
     637    {
     638      switch(e->type)
     639        {
     640        case GDK_KEY_PRESS:
     641          //for Escape or Enter hide the displayed widget
     642          {
     643            switch(((GdkEventKey*)e)->keyval)
     644              {
     645              case GDK_Escape:
     646                entrywidget.hide();
     647                break;
     648              case GDK_Return:
     649              case GDK_KP_Enter:
     650                entrywidget.hide();
     651                break;
     652              default:
     653                break;
     654              }
    635655 
    636         break;
    637       }
    638     case GDK_BUTTON_PRESS:
    639       //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    640       {
    641         //find the activated item
    642         window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    643         active_item=(get_item_at(clicked_x, clicked_y));
    644 
    645         //determine, whether it was a node
    646         Graph::NodeIt clicked_node=INVALID;
    647         for (NodeIt i(g); i!=INVALID; ++i)
     656            break;
     657          }
     658        case GDK_BUTTON_PRESS:
     659          //If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
    648660          {
    649             if(nodesmap[i]==active_item)
    650               {
    651                 clicked_node=i;
    652               }
    653           }
    654 
    655         //if it was really an edge...
    656         if(clicked_node!=INVALID)
    657           {
    658             //If there is already edited edge, it has to be saved first
    659             if(entrywidget.is_visible())
    660               {
     661            //for determine, whether it was a node
     662            Graph::NodeIt clicked_node=INVALID;
     663
     664            //find the activated item between texts
     665            active_item=(get_item_at(e->button.x, e->button.y));
     666            for (NodeIt i(g); i!=INVALID; ++i)
     667              {
     668                //at the same time only one can be active
     669                if(nodetextmap[i]==active_item)
     670                  {
     671                    clicked_node=i;
     672                  }
     673              }
     674
     675            //if there was not, search for it between nodes
     676            if(clicked_node==INVALID)
     677              {
     678                window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     679                active_item=(get_item_at(clicked_x, clicked_y));
     680
     681                for (NodeIt i(g); i!=INVALID; ++i)
     682                  {
     683                    //at the same time only one can be active
     684                    if(nodesmap[i]==active_item)
     685                      {
     686                        clicked_node=i;
     687                      }
     688                  }
     689              }
     690            //if it was really an edge...
     691            if(clicked_node!=INVALID)
     692              {
     693                //If there is already edited edge, it has to be saved first
     694                if(entrywidget.is_visible())
     695                  {
     696                    GdkEvent * generated=new GdkEvent();
     697                    generated->type=GDK_KEY_PRESS;
     698                    ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
     699                    entryWidgetChangeHandler(generated);
     700                  }
     701                //If the previous value could be saved, we can go further, otherwise not
     702                if(!entrywidget.is_visible())
     703                  {
     704                    //and there is activated map
     705                    if(nodetextmap[clicked_node]->property_text().get_value()!="")
     706                      {
     707                        //activate the general variable for it
     708                        active_node=clicked_node;
     709                        //delete visible widget if there is
     710                        if(canvasentrywidget)
     711                          {
     712                            delete(canvasentrywidget);
     713                          }
     714
     715                        //initialize the entry
     716                        entrywidget.show();
     717
     718                        //fill in the correct value
     719                        entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
     720
     721                        //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
     722                        xy<double> entry_coos;
     723                        entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
     724                        entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
     725                        entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
     726                        entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
     727                        canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
     728                        canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
     729                        canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
     730                      }
     731                  }
     732              }
     733            //if it was not an edge...
     734            else
     735              {
     736                //In this case the click did not happen on an edge
     737                //if there is visible entry we save the value in it
     738                //we pretend like an Enter was presse din the Entry widget
    661739                GdkEvent * generated=new GdkEvent();
    662740                generated->type=GDK_KEY_PRESS;
     
    664742                entryWidgetChangeHandler(generated);
    665743              }
    666             //If the previous value could be saved, we can go further, otherwise not
    667             if(!entrywidget.is_visible())
    668               {
    669                 //and there is activated map
    670                 if(nodetextmap[clicked_node]->property_text().get_value()!="")
    671                   {
    672                     //activate the general variable for it
    673                     active_node=clicked_node;
    674                     //delete visible widget if there is
    675                     if(canvasentrywidget)
    676                       {
    677                         delete(canvasentrywidget);
    678                       }
    679 
    680                     //initialize the entry
    681                     entrywidget.show();
    682 
    683                     //fill in the correct value
    684                     entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
    685 
    686                     //replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
    687                     xy<double> entry_coos;
    688                     entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
    689                     entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
    690                     entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
    691                     entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
    692                     canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
    693                     canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*1.5);
    694                     canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
    695                   }
    696               }
     744            break;
    697745          }
    698         //if it was not an edge...
    699         else
    700           {
    701             //In this case the click did not happen on an edge
    702             //if there is visible entry we save the value in it
    703             //we pretend like an Enter was presse din the Entry widget
    704             GdkEvent * generated=new GdkEvent();
    705             generated->type=GDK_KEY_PRESS;
    706             ((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
    707             entryWidgetChangeHandler(generated);
    708           }
    709         break;
    710       }
    711     default:
    712       break;
     746        default:
     747          break;
     748        }
    713749    }
    714750  return false; 
     
    783819                else
    784820                  {
    785                     std::cout << "ERROR: only handling of double values is implemented yet!" << std::endl;
     821                    std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
    786822                  }
    787823
     
    830866      if(forming_edge!=INVALID)
    831867        {
    832           std::cout << "ERROR!!!! Valid edge found!" << std::endl;
     868          std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
    833869        }
    834870      else
     
    851887      else
    852888        {
    853           std::cout << "ERROR!!!! Invalid edge found!" << std::endl;
     889          std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
    854890        }
    855891    }
  • graph_displayer_canvas-node.cc

    r45 r48  
    77{
    88  Graph::NodeMap<double> * actual_map;
     9  double min, max;
    910  if(mapname=="Default")
    1011    {
     12      min=node_property_defaults[N_RADIUS];
     13      max=node_property_defaults[N_RADIUS];
    1114      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
    1215    }
    1316  else
    1417    {
     18      min=mapstorage.minOfNodeMap(mapname);
     19      max=mapstorage.maxOfNodeMap(mapname);
    1520      actual_map=(mapstorage.nodemap_storage)[mapname];
    1621    }
     
    2025      for (NodeIt i(g); i!=INVALID; ++i)
    2126        {
    22           int w=(int)(*actual_map)[i];
     27          double v=abs((*actual_map)[i]);
     28          int w;
     29          if(min==max)
     30            {
     31              w=(int)(node_property_defaults[N_RADIUS]);
     32            }
     33          else
     34            {
     35              w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
     36            }
    2337          if(w>=0)
    2438            {
  • graph_displayer_canvas.cc

    r47 r48  
    4242    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    4343    edgetextmap[i]->property_fill_color().set_value("darkgreen");
     44    edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
    4445  }
    4546
     
    7071    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    7172    nodetextmap[i]->property_fill_color().set_value("darkblue");
     73    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
    7274  }
    7375
  • map_win.cc

    r43 r48  
    145145            break;
    146146          default:
    147             std::cout<<"Error\n";
     147            std::cerr<<"Error\n";
    148148        }
    149149      }
     
    176176            break;
    177177          default:
    178             std::cout<<"Error\n";
     178            std::cerr<<"Error\n";
    179179        }
    180180      }
     
    208208                      break;
    209209                    default:
    210                       std::cout<<"Error\n";
     210                      std::cerr<<"Error\n";
    211211                    }
    212212                }
     
    243243                      break;
    244244                    default:
    245                       std::cout<<"Error\n";
     245                      std::cerr<<"Error\n";
    246246                    }
    247247                }
Note: See TracChangeset for help on using the changeset viewer.