COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
06/29/05 21:44:30 (15 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2011
Message:

Uh, long comment arrives... Zoom update does not happen after editorial steps. Nodes initial color is light blue, if there is any item under them. Strange node-text relations disappeared. Initial values of new items are given now in a more common way. The wood-cutter way of handling default values of properties is now changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas-event.cc

    r1524 r1525  
    2929    {
    3030    case MOVE:
    31       actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    32       break;
    33 
    34       //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group
     31      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
     32      break;
     33
    3534    case CREATE_NODE:
    3635      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
     
    3837
    3938    case CREATE_EDGE:
    40       actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
     39      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
    4140      break;
    4241
    4342    case ERASER:
    44       actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
     43      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
    4544      break;
    4645
     
    6160    case GDK_BUTTON_PRESS:
    6261      //we mark the location of the event to be able to calculate parameters of dragging
    63       clicked_x=e->button.x;
    64       clicked_y=e->button.y;
    65       active_item=(get_item_at(e->button.x, e->button.y));
     62      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     63
     64      active_item=(get_item_at(clicked_x, clicked_y));
    6665      active_node=INVALID;
    6766      for (NodeIt i(g); i!=INVALID; ++i)
     
    8685      active_item=NULL;
    8786      active_node=INVALID;
    88       updateScrollRegion();
    8987      break;
    9088    case GDK_MOTION_NOTIFY:
     
    9795        //has to be calculated from here
    9896
    99         double dx=e->motion.x-clicked_x;
    100         double dy=e->motion.y-clicked_y;
     97        double new_x, new_y;
     98
     99        window_to_world (e->motion.x, e->motion.y, new_x, new_y);
     100
     101        double dx=new_x-clicked_x;
     102        double dy=new_y-clicked_y;
    101103
    102104        //repositioning node and its text
     
    104106        nodetextmap[active_node]->move(dx, dy);
    105107
    106         clicked_x=e->motion.x;
    107         clicked_y=e->motion.y;
     108        clicked_x=new_x;
     109        clicked_y=new_y;
    108110
    109111        //all the edges connected to the moved point has to be redrawn
     
    169171  }
    170172
    171   return true;
     173  return false;
    172174}
    173175
     
    178180
    179181      //draw the new node in red at the clicked place
     182    case GDK_2BUTTON_PRESS:
     183      std::cout << "double click" << std::endl;
     184      break;
    180185    case GDK_BUTTON_PRESS:
    181186      isbutton=1;
     
    184189
    185190      //initiating values corresponding to new node in maps
    186      
    187191
    188192      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     193
     194      target_item=NULL;
     195      target_item=get_item_at(clicked_x, clicked_y);
    189196
    190197      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
     
    206213        double world_motion_x, world_motion_y;
    207214        GdkEvent * generated=new GdkEvent();
    208         window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
    209         generated->motion.x=world_motion_x;
    210         generated->motion.y=world_motion_y;
     215        generated->motion.x=e->motion.x;
     216        generated->motion.y=e->motion.y;
    211217        generated->type=GDK_MOTION_NOTIFY;
    212218        moveEventHandler(generated);     
     
    217223    case GDK_BUTTON_RELEASE:
    218224      isbutton=0;
    219       *active_item << Gnome::Canvas::Properties::fill_color("blue");
     225      if(!target_item)
     226        {
     227          //Its appropriate color is given by update.
     228          //*active_item << Gnome::Canvas::Properties::fill_color("blue");
     229        }
     230      else
     231        {
     232          //In this case the given color has to be overwritten, because the noe covers an other item.
     233          *active_item << Gnome::Canvas::Properties::fill_color("lightblue");
     234        }
     235      target_item=NULL;
    220236      active_item=NULL;
    221237      active_node=INVALID;
    222       updateScrollRegion();
    223238      break;
    224239    default:
     
    240255            {
    241256              //we mark the location of the event to be able to calculate parameters of dragging
    242               clicked_x=e->button.x;
    243               clicked_y=e->button.y;
    244               active_item=(get_item_at(e->button.x, e->button.y));
     257
     258              window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     259
     260              active_item=(get_item_at(clicked_x, clicked_y));
    245261              active_node=INVALID;
    246262              for (NodeIt i(g); i!=INVALID; ++i)
     
    270286          else
    271287            {
    272               target_item=(get_item_at(e->button.x, e->button.y));
     288              window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     289              target_item=(get_item_at(clicked_x, clicked_y));
    273290              Graph::NodeIt target_node=INVALID;
    274291              for (NodeIt i(g); i!=INVALID; ++i)
     
    367384    {
    368385    case GDK_BUTTON_PRESS:
    369       active_item=(get_item_at(e->button.x, e->button.y));
     386      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     387      active_item=(get_item_at(clicked_x, clicked_y));
    370388      active_node=INVALID;
    371389      active_edge=INVALID;
     
    387405            }
    388406        }
    389     *active_item << Gnome::Canvas::Properties::fill_color("red");
     407      if(active_item)
     408        {
     409          *active_item << Gnome::Canvas::Properties::fill_color("red");
     410        }
    390411      break;
    391412
    392413    case GDK_BUTTON_RELEASE:
    393       if(active_item==(get_item_at(e->button.x, e->button.y)))
    394         {
    395           if(active_node!=INVALID)
    396             {
    397 
    398               //collecting edges to delete
    399               EdgeIt e;
    400               std::set<Graph::Edge> edges_to_delete;
    401 
    402               g.firstOut(e,active_node);
    403               for(;e!=INVALID;g.nextOut(e))
    404                 {
     414      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     415      if(active_item)
     416        {
     417          if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
     418            {
     419              if(active_node!=INVALID)
     420                {
     421
     422                  //collecting edges to delete
     423                  EdgeIt e;
     424                  std::set<Graph::Edge> edges_to_delete;
     425
     426                  g.firstOut(e,active_node);
     427                  for(;e!=INVALID;g.nextOut(e))
     428                    {
    405429                      edges_to_delete.insert(e);
    406                 }
    407 
    408               g.firstIn(e,active_node);
    409               for(;e!=INVALID;g.nextIn(e))
    410                 {
     430                    }
     431
     432                  g.firstIn(e,active_node);
     433                  for(;e!=INVALID;g.nextIn(e))
     434                    {
    411435                      edges_to_delete.insert(e);
    412                 }
    413 
    414               //deleting collected edges
    415               for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
    416                 {
    417                   deleteItem(*edge_set_it);
    418                 }
    419               deleteItem(active_node);
    420             }
    421           //a simple edge was chosen
     436                    }
     437
     438                  //deleting collected edges
     439                  for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
     440                    {
     441                      deleteItem(*edge_set_it);
     442                    }
     443                  deleteItem(active_node);
     444                }
     445              //a simple edge was chosen
     446              else
     447                {
     448                  deleteItem(active_edge);
     449                }
     450            }
     451          //pointer was moved, deletion is cancelled
    422452          else
    423453            {
    424               deleteItem(active_edge);
    425             }
    426 
    427          
    428         }
    429       //pointer was moved, deletion is cancelled
    430       else
    431         {
    432           if(active_node!=INVALID)
    433             {
    434               *active_item << Gnome::Canvas::Properties::fill_color("blue");
    435             }
    436           else
    437             {
    438               *active_item << Gnome::Canvas::Properties::fill_color("green");
     454              if(active_node!=INVALID)
     455                {
     456                  *active_item << Gnome::Canvas::Properties::fill_color("blue");
     457                }
     458              else
     459                {
     460                  *active_item << Gnome::Canvas::Properties::fill_color("green");
     461                }
    439462            }
    440463        }
     
    451474      break;
    452475    }
    453   return true;
     476  return false;
    454477}
    455478
Note: See TracChangeset for help on using the changeset viewer.