COIN-OR::LEMON - Graph Library

Changeset 1474:75c6d2eb187a in lemon-0.x


Ignore:
Timestamp:
06/13/05 12:30:08 (14 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1954
Message:

Edge creation is available.

Location:
gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gui/graph_displayer_canvas.cc

    r1468 r1474  
    22#include <math.h>
    33
    4 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
    5 {
    6   Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
    7   *origo << Gnome::Canvas::Properties::fill_color("black");
    8   *origo << Gnome::Canvas::Properties::outline_color("black");
     4GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL),target_item(NULL)
     5{
    96 
    10   actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
     7  actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
    118
    129  //set_center_scroll_region(true);
     
    367364
    368365        //all the edges connected to the moved point has to be redrawn
    369 
    370366        EdgeIt e;
    371367
     
    459455bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
    460456{
    461   e=e;
     457  switch(e->type)
     458    {
     459    case GDK_BUTTON_PRESS:
     460      if(!active_item)
     461        {
     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)
     468            {
     469              if(nodesmap[i]==active_item)
     470                {
     471                  active_node=i;
     472                }
     473            }
     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)
     482            {
     483              if(nodesmap[i]==target_item)
     484                {
     485                  target_node=i;
     486                }
     487            }
     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");
     517        }
     518      break;
     519    case GDK_BUTTON_RELEASE:
     520      isbutton=false;
     521      if(target_item)
     522        {
     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;
     527        }
     528      break;
     529    default:
     530      break;
     531    }
    462532  return false;
    463533}
  • gui/graph_displayer_canvas.h

    r1468 r1474  
    9797  ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
    9898  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
    99   Gnome::Canvas::Item * active_item;
     99  Gnome::Canvas::Item * active_item, * target_item;
    100100  Graph::NodeIt active_node;
     101  Graph::EdgeIt active_edge;
    101102
    102103  static const int zoom_step = 5;
Note: See TracChangeset for help on using the changeset viewer.