COIN-OR::LEMON - Graph Library

Changeset 1468:d0ccb2fdeeff in lemon-0.x


Ignore:
Timestamp:
06/10/05 13:58:03 (19 years ago)
Author:
Hegyi Péter
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1948
Message:

Hopefully, node creation works well, after a small structural consideration.

Location:
gui
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • gui/Makefile.am

    r1435 r1468  
    1414        mapstorage.h \
    1515        map_win.cc \
    16         map_win.h
     16        map_win.h \
     17        edit_win.cc \
     18        edit_win.h
    1719
    1820gd_CXXFLAGS = $(GTK_CFLAGS)
  • gui/all_include.h

    r1442 r1468  
    1717#include <lemon/xy.h>
    1818
    19 enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
     19enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties;
     20enum {MOVE, CREATE_NODE, CREATE_EDGE, TOOL_NUM}; // tools;
    2021#define RANGE 3
    2122#define WIN_WIDTH 900
  • gui/graph_displayer_canvas.cc

    r1444 r1468  
    44GraphDisplayerCanvas::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)
    55{
     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");
     9 
     10  actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
     11
    612  //set_center_scroll_region(true);
    713
     
    4955    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    5056    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
    51     (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
    52   }
    53 
    54 /*
    55   //setting zoom to be able to see the whole graph on the canvas
    56 
    57   double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
    58   double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
    59 
    60   set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
    61   std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
    62   std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
    63   std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
    64 */
     57    //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
     58  }
     59
    6560  updateScrollRegion();
    6661}
     
    309304  set_scroll_region(wx1, wy1, wx2, wy2);
    310305}
     306
     307void GraphDisplayerCanvas::changeEditorialTool(int newtool)
     308{
     309  actual_handler.disconnect();
     310
     311  switch(newtool)
     312    {
     313    case MOVE:
     314      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
     315      break;
     316    case CREATE_NODE:
     317      actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
     318      break;
     319    case CREATE_EDGE:
     320      actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
     321      break;
     322    default:
     323      break;
     324    }
     325}
     326
     327bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
     328{
     329  switch(e->type)
     330  {
     331    case GDK_BUTTON_PRESS:
     332      //we mark the location of the event to be able to calculate parameters of dragging
     333      clicked_x=e->button.x;
     334      clicked_y=e->button.y;
     335      active_item=(get_item_at(e->button.x, e->button.y));
     336      active_node=INVALID;
     337      for (NodeIt i(g); i!=INVALID; ++i)
     338        {
     339          if(nodesmap[i]==active_item)
     340            {
     341              active_node=i;
     342            }
     343        }
     344      isbutton=true;
     345      break;
     346    case GDK_BUTTON_RELEASE:
     347      isbutton=false;
     348      active_item=NULL;
     349      updateScrollRegion();
     350      break;
     351    case GDK_MOTION_NOTIFY:
     352      //we only have to do sg. if the mouse button is pressed
     353      if(isbutton)
     354      {
     355        //new coordinates will be the old values,
     356        //because the item will be moved to the
     357        //new coordinate therefore the new movement
     358        //has to be calculated from here
     359
     360        double dx=e->motion.x-clicked_x;
     361        double dy=e->motion.y-clicked_y;
     362
     363        active_item->move(dx, dy);
     364
     365        clicked_x=e->motion.x;
     366        clicked_y=e->motion.y;
     367
     368        //all the edges connected to the moved point has to be redrawn
     369
     370        EdgeIt e;
     371
     372        g.firstOut(e,active_node);
     373
     374        for(;e!=INVALID;g.nextOut(e))
     375        {
     376            Gnome::Canvas::Points coos;
     377            double x1, x2, y1, y2;
     378
     379            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
     380            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     381
     382            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
     383            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     384
     385            edgesmap[e]->property_points().set_value(coos);
     386
     387            edgesmap[e]->get_bounds(x1, y1, x2, y2);
     388
     389            edgetextmap[e]->property_x().set_value((x1+x2)/2);
     390            edgetextmap[e]->property_y().set_value((y1+y2)/2);
     391        }
     392
     393        g.firstIn(e,active_node);
     394        for(;e!=INVALID;g.nextIn(e))
     395        {
     396            Gnome::Canvas::Points coos;
     397            double x1, x2, y1, y2;
     398
     399            nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
     400            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     401
     402            nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
     403            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
     404
     405            edgesmap[e]->property_points().set_value(coos);
     406
     407            edgesmap[e]->get_bounds(x1, y1, x2, y2);
     408
     409            edgetextmap[e]->property_x().set_value((x1+x2)/2);
     410            edgetextmap[e]->property_y().set_value((y1+y2)/2);
     411        }
     412      }
     413    default: break;
     414  }
     415
     416  return true;
     417}
     418
     419bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
     420{
     421  switch(e->type)
     422    {
     423    case GDK_BUTTON_PRESS:
     424      isbutton=true;
     425
     426      active_node=NodeIt(g,g.addNode());
     427
     428      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     429
     430      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
     431      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
     432      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
     433      *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
     434      (nodesmap[active_node])->show();
     435      break;
     436    case GDK_MOTION_NOTIFY:
     437      {
     438        double world_motion_x, world_motion_y;
     439        GdkEvent * generated=new GdkEvent();
     440        window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
     441        generated->motion.x=world_motion_x;
     442        generated->motion.y=world_motion_y;
     443        generated->type=GDK_MOTION_NOTIFY;
     444        move_event_handler(generated);     
     445        break;
     446      }
     447    case GDK_BUTTON_RELEASE:
     448      isbutton=false;
     449      *active_item << Gnome::Canvas::Properties::fill_color("blue");
     450      active_item=NULL;
     451      updateScrollRegion();
     452      break;
     453    default:
     454      break;
     455    }
     456  return false;
     457}
     458
     459bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
     460{
     461  e=e;
     462  return false;
     463}
     464
  • gui/graph_displayer_canvas.h

    r1442 r1468  
    4141  void updateScrollRegion();
    4242
     43  ///This function changes the tool in the graph-editor's hand
     44  void changeEditorialTool(int);
     45
    4346protected:
    4447
     
    5255  ///of the canvas
    5356  bool event_handler(GdkEvent* e, Node n);
     57
     58  ///actual event handler
     59  ///
     60  ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
     61  sigc::connection actual_handler;
     62
     63  ///event handler for the case when move-tool is active
     64  bool move_event_handler(GdkEvent*);
     65  ///event handler for the case when create_node-tool is active
     66  bool create_node_event_handler(GdkEvent*);
     67  ///event handler for the case when create_edge-tool is active
     68  bool create_edge_event_handler(GdkEvent*);
    5469
    5570  ///The graph, on which we work
     
    8398  ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
    8499  Gnome::Canvas::Item * active_item;
     100  Graph::NodeIt active_node;
    85101
    86102  static const int zoom_step = 5;
  • gui/main_win.cc

    r1442 r1468  
    22
    33MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
    4     MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
     4    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms)
    55{
    66  set_title (title);
     
    3535  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
    3636      sigc::mem_fun(*this, &MainWin::showMaps));
     37  ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"),
     38      sigc::mem_fun(*this, &MainWin::showEditorials));
    3739
    3840  uim=Gtk::UIManager::create();
     
    6163      "    <menu action='ShowMenu'>"
    6264      "      <menuitem action='ShowMaps'/>"
     65      "      <menuitem action='ShowEditorials'/>"
    6366      "    </menu>"
    6467      "  </menubar>"
     
    108111}
    109112
     113void MainWin::showEditorials()
     114{
     115  editwin.show();
     116}
     117
    110118void MainWin::quit()
    111119{
  • gui/main_win.h

    r1442 r1468  
    77#include <mapstorage.h>
    88#include <map_win.h>
     9#include <edit_win.h>
    910#include <libgnomecanvasmm.h>
    1011#include <libgnomecanvasmm/polygon.h>
     
    2627  MapWin mapwin;
    2728
     29  ///Window of editorial tools. Its type is \ref EditWin
     30  EditWin editwin;
     31
    2832  ///The graph will be drawn on this \ref GraphDisplayerCanvas
    2933  GraphDisplayerCanvas gd_canvas;
     
    4044  ///This function makes map-setup window popped up.
    4145  virtual void showMaps();
     46  ///This function makes editorial window popped up.
     47  virtual void showEditorials();
    4248  ///Callback for 'FileNew' action.
    4349  virtual void newFile();
Note: See TracChangeset for help on using the changeset viewer.