COIN-OR::LEMON - Graph Library

Changeset 12:1db7a6dd17f8 in glemon-0.x


Ignore:
Timestamp:
06/13/05 21:49:33 (14 years ago)
Author:
Hegyi Péter
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@1958
Message:

Known bugs are eliminated from gui, and new ones are created by changing tool selectors to special radiobuttons, and by adding edgecreation-canceller function (right-click on any group element).

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • edit_win.cc

    r10 r12  
    1515  set_title(title);
    1616  set_default_size(200, 50);
    17 
     17  set_keep_above(true);
    1818  signal_key_press_event().connect(sigc::mem_fun(*this, &EditWin::close_if_escape_is_pressed));
    1919 
     20  //buttons array
     21  buttons=new (Gtk::RadioButton *) [TOOL_NUM];
     22  for(int i=0;i<TOOL_NUM;i++)
     23    {
     24      buttons[i]=NULL;
     25    }
     26
     27  Gtk::RadioButton::Group group;//=buttons[MOVE]->get_group();
     28
    2029  //New node button
    21   button=new Gtk::Button("New Node");
    22   button->signal_clicked().connect
     30  buttons[CREATE_NODE]=new Gtk::RadioButton("New Node");
     31  buttons[CREATE_NODE]->set_mode(false);
     32  buttons[CREATE_NODE]->set_group(group);
     33  buttons[CREATE_NODE]->signal_clicked().connect
    2334    (
    2435     sigc::bind
     
    2839      )
    2940     );
    30   table.attach(*button,0,1,0,1);
     41  table.attach(*buttons[CREATE_NODE],0,1,0,1);
    3142
    3243  //New edge button
    33   button=new Gtk::Button("New Edge");
    34   button->signal_clicked().connect
     44  buttons[CREATE_EDGE]=new Gtk::RadioButton("New Edge");
     45  buttons[CREATE_EDGE]->set_mode(false);
     46  buttons[CREATE_EDGE]->set_group(group);
     47  buttons[CREATE_EDGE]->signal_clicked().connect
    3548    (
    3649     sigc::bind
     
    4053      )
    4154     );
    42   table.attach(*button,1,2,0,1);
     55  table.attach(*buttons[CREATE_EDGE],1,2,0,1);
    4356   
    4457  //Move button
    45   button=new Gtk::Button("Move");
    46   button->signal_clicked().connect
     58  buttons[MOVE]=new Gtk::RadioButton("Move");
     59  buttons[MOVE]->set_mode(false);
     60  buttons[MOVE]->set_group(group);
     61  buttons[MOVE]->signal_clicked().connect
    4762    (
    4863     sigc::bind
     
    5267      )
    5368     );
    54   table.attach(*button,0,1,1,2);
    55    
     69  table.attach(*buttons[MOVE],0,1,1,2);
     70     
    5671  add(table);
    5772
  • edit_win.h

    r10 r12  
    1616protected:
    1717  ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
    18   ///It has to be known for this class, because
    19   ///when a map assigned to a certain attribute
    20   ///a function of the \ref GraphDisplayerCanvas will be called.
     18  ///It has to be known for this class, because the appropriate
     19  //callback function for each tool is implemented in that class
    2120  GraphDisplayerCanvas & gdc;
    2221
     22  ///Table that holds the tools.
    2323  Gtk::Table table;
    2424 
    25   Gtk::Label * label;
    26   Gtk::Button * button;
     25  ///these buttons are RadioButtons with classic look
     26  Gtk::RadioButton ** buttons;
    2727
    2828public:
  • graph_displayer_canvas.cc

    r11 r12  
    66 
    77  actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
     8
     9  active_node=INVALID;
     10  active_edge=INVALID;
    811
    912  //set_center_scroll_region(true);
     
    311314      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
    312315      break;
     316
     317      //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group
    313318    case CREATE_NODE:
    314319      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
    315320      break;
     321
    316322    case CREATE_EDGE:
    317323      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
     
    344350      isbutton=false;
    345351      active_item=NULL;
     352      active_node=INVALID;
    346353      updateScrollRegion();
    347354      break;
    348355    case GDK_MOTION_NOTIFY:
    349       //we only have to do sg. if the mouse button is pressed
    350       if(isbutton)
     356      //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
     357      if(active_node!=INVALID)
    351358      {
    352359        //new coordinates will be the old values,
     
    417424  switch(e->type)
    418425    {
     426
     427      //draw the new node in red at the clicked place
    419428    case GDK_BUTTON_PRESS:
    420429      isbutton=true;
     
    430439      (nodesmap[active_node])->show();
    431440      break;
     441
     442      //move the new node
    432443    case GDK_MOTION_NOTIFY:
    433444      {
     
    441452        break;
    442453      }
     454
     455      //finalize the new node
    443456    case GDK_BUTTON_RELEASE:
    444457      isbutton=false;
    445458      *active_item << Gnome::Canvas::Properties::fill_color("blue");
    446459      active_item=NULL;
     460      active_node=INVALID;
    447461      updateScrollRegion();
    448462      break;
     
    458472    {
    459473    case GDK_BUTTON_PRESS:
    460       if(!active_item)
     474      //in edge creatino right button has special meaning
     475      if(e->button.button!=3)
    461476        {
    462           //we mark the location of the event to be able to calculate parameters of dragging
    463           clicked_x=e->button.x;
    464           clicked_y=e->button.y;
    465           active_item=(get_item_at(e->button.x, e->button.y));
    466           active_node=INVALID;
    467           for (NodeIt i(g); i!=INVALID; ++i)
     477          //there is not yet selected node
     478          if(active_node==INVALID)
    468479            {
    469               if(nodesmap[i]==active_item)
     480              //we mark the location of the event to be able to calculate parameters of dragging
     481              clicked_x=e->button.x;
     482              clicked_y=e->button.y;
     483              active_item=(get_item_at(e->button.x, e->button.y));
     484              active_node=INVALID;
     485              for (NodeIt i(g); i!=INVALID; ++i)
    470486                {
    471                   active_node=i;
     487                  if(nodesmap[i]==active_item)
     488                    {
     489                      active_node=i;
     490                    }
     491                }
     492              //the clicked item is really a node
     493              if(active_node!=INVALID)
     494                {
     495                  *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
     496                  isbutton=true;
     497                }
     498              //clicked item was not a node. It could be e.g. edge.
     499              else
     500                {
     501                  active_item=NULL;
    472502                }
    473503            }
    474           *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
    475           isbutton=true;
    476         }
    477       else
    478         {
    479           target_item=(get_item_at(e->button.x, e->button.y));
    480           Graph::NodeIt target_node=INVALID;
    481           for (NodeIt i(g); i!=INVALID; ++i)
     504          //we only have to do sg. if the mouse button
     505          // is pressed already once AND the click was
     506          // on a node that was found in the set of
     507          //nodes, and now we only search for the second
     508          //node
     509          else
    482510            {
    483               if(nodesmap[i]==target_item)
     511              target_item=(get_item_at(e->button.x, e->button.y));
     512              Graph::NodeIt target_node=INVALID;
     513              for (NodeIt i(g); i!=INVALID; ++i)
    484514                {
    485                   target_node=i;
     515                  if(nodesmap[i]==target_item)
     516                    {
     517                      target_node=i;
     518                    }
     519                }
     520              //the clicked item is a node, the edge can be drawn
     521              if(target_node!=INVALID)
     522                {
     523                  *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
     524
     525                  //creating new edge
     526                  active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
     527         
     528                  //calculating coordinates of new edge
     529                  Gnome::Canvas::Points coos;
     530                  double x1, x2, y1, y2;
     531         
     532                  active_item->get_bounds(x1, y1, x2, y2);
     533                  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     534
     535                  target_item->get_bounds(x1, y1, x2, y2);
     536                  coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     537
     538                  //drawing new edge
     539                  edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);
     540                  *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
     541                  edgesmap[active_edge]->property_width_pixels().set_value(10);
     542
     543                  //redraw nodes to blank terminations of the new edge
     544                  target_item->raise_to_top();
     545                  active_item->raise_to_top();
     546
     547                  //initializing edge-text as well, to empty string
     548                  edgesmap[active_edge]->get_bounds(x1, y1, x2, y2);
     549                  edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
     550                  edgetextmap[active_edge]->property_fill_color().set_value("black");
     551                }
     552              //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
     553              else
     554                {
     555                  target_item=NULL;
    486556                }
    487557            }
    488           *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
    489 
    490           //creating new edge
    491           //      Graph::Edge new_edge=g.addEdge(active_node, target_node);
    492           active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
    493          
    494           //calculating coordinates of new edge
    495           Gnome::Canvas::Points coos;
    496           double x1, x2, y1, y2;
    497          
    498           active_item->get_bounds(x1, y1, x2, y2);
    499           coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    500 
    501           target_item->get_bounds(x1, y1, x2, y2);
    502           coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    503 
    504           //drawing new edge
    505           edgesmap[active_edge]=new Gnome::Canvas::Line(displayed_graph, coos);
    506           *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
    507           edgesmap[active_edge]->property_width_pixels().set_value(10);
    508 
    509           //redraw nodes to blank terminations of the new edge
    510           target_item->raise_to_top();
    511           active_item->raise_to_top();
    512 
    513           //initializing edge-text as well, to empty string
    514           edgesmap[active_edge]->get_bounds(x1, y1, x2, y2);
    515           edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
    516           edgetextmap[active_edge]->property_fill_color().set_value("black");
    517558        }
    518559      break;
    519560    case GDK_BUTTON_RELEASE:
    520561      isbutton=false;
    521       if(target_item)
     562      //we clear settings in two cases
     563      //1: the edge is ready (target_item has valid value)
     564      //2: the edge creation is cancelled with right button
     565      if((target_item)||(e->button.button==3))
    522566        {
    523           *active_item << Gnome::Canvas::Properties::fill_color("blue");
    524           *target_item << Gnome::Canvas::Properties::fill_color("blue");
    525           active_item=NULL;
    526           target_item=NULL;
     567          if(active_item)
     568            {
     569              *active_item << Gnome::Canvas::Properties::fill_color("blue");
     570              active_item=NULL;
     571            }
     572          if(target_item)
     573            {
     574              *target_item << Gnome::Canvas::Properties::fill_color("blue");
     575              target_item=NULL;
     576            }
     577          active_node=INVALID;
     578          active_edge=INVALID;
    527579        }
    528580      break;
Note: See TracChangeset for help on using the changeset viewer.