COIN-OR::LEMON - Graph Library

Changeset 53:e73d7540bd24 in glemon-0.x


Ignore:
Timestamp:
07/29/05 14:01:37 (14 years ago)
Author:
Akos Ladanyi
Branch:
gui
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@2111
Message:

added support for saving files

Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r52 r53  
    2626        broken_edge.h \
    2727        new_map_win.cc \
    28         new_map_win.h
     28        new_map_win.h \
     29        xymap.h
    2930
    3031gd_CXXFLAGS = $(GTK_CFLAGS)
  • broken_edge.cc

    r51 r53  
    1 #include <broken_edge.h>
     1#include "broken_edge.h"
    22#include <math.h>
    33
  • broken_edge.h

    r30 r53  
    66class BrokenEdge;
    77
    8 #include <all_include.h>
     8#include "all_include.h"
    99#include <libgnomecanvasmm.h>
    1010#include <libgnomecanvasmm/polygon.h>
    11 #include <graph_displayer_canvas.h>
     11#include "graph_displayer_canvas.h"
    1212#include <lemon/xy.h>
    1313
  • graph-displayer.cc

    r28 r53  
    1 #include <all_include.h>
    2 #include <mapstorage.h>
    3 #include <main_win.h>
     1#include "all_include.h"
     2#include "mapstorage.h"
     3#include "main_win.h"
    44#include <libgnomecanvasmm.h>
    55#include <libgnomecanvasmm/polygon.h>
     
    3838  node_property_defaults[N_TEXT]=0;
    3939
    40   if(argc<2)
    41   {
    42       std::cerr << "USAGE: gd <input filename.lgf>" << std::endl;
    43       return 0;
    44   }
    45 
    46   Coordinates coosvector;
    47 
    48   Graph g;
    49 
    50   CoordinatesMap cm(g);
    51   Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);
    52   Graph::NodeMap<double> nodedata (g);
    53 
    54   //we create one object to read x coordinates
    55   //and one to read y coordinate of nodes and write them to cm NodeMap.
    56   XMap <CoordinatesMap> xreader (cm);
    57   YMap <CoordinatesMap> yreader (cm);
    58 
    59   //reading in graph and its maps
    60 
    61   std::ifstream is(argv[1]);
    62 
    63   GraphReader<Graph> reader(is, g);
    64   reader.readNodeMap("coordinates_x", xreader);
    65   reader.readNodeMap("coordinates_y", yreader);
    66   reader.readNodeMap("data", nodedata);
    67   reader.readEdgeMap("cap", cap);
    68   reader.readEdgeMap("map1", map1);
    69   reader.readEdgeMap("map2", map2);
    70   reader.readEdgeMap("map3", map3);
    71   reader.readEdgeMap("map4", map4);
    72   reader.run();
    73 
    74   //initializing MapStorage with the read data
    75 
    76   MapStorage ms(g);
    77   ms.addNodeMap("data",&nodedata);
    78   ms.addEdgeMap("cap",&cap);
    79   ms.addEdgeMap("map1",&map1);
    80   ms.addEdgeMap("map2",&map2);
    81   ms.addEdgeMap("map3",&map3);
    82   ms.addEdgeMap("map4",&map4);
    83 
    8440  //initializing GUI
    8541
     
    8743  Gtk::Main app(argc, argv);
    8844
    89   MainWin mainwin("Displayed Graph", g, cm, ms);
     45  MainWin mainwin("Displayed Graph");
    9046  app.run(mainwin);
    9147
  • graph_displayer_canvas-edge.cc

    r48 r53  
    1 #include <graph_displayer_canvas.h>
    2 #include <broken_edge.h>
     1#include "graph_displayer_canvas.h"
     2#include "broken_edge.h"
    33#include <math.h>
    44
     
    1313      min=edge_property_defaults[E_WIDTH];
    1414      max=edge_property_defaults[E_WIDTH];
    15       actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
     15      actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
    1616    }
    1717  else
     
    2424  if(edge==INVALID)
    2525    {
    26       for (EdgeIt i(g); i!=INVALID; ++i)
     26      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    2727        {
    2828          double v=abs((*actual_map)[i]);
     
    5959  if(mapname=="Default")
    6060    {
    61       actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
     61      actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
    6262    }
    6363  else
     
    8181  if(edge==INVALID)
    8282    {
    83       for (EdgeIt i(g); i!=INVALID; ++i)
     83      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    8484        {
    8585          double w=(*actual_map)[i];
     
    126126  if(edge==INVALID)
    127127    {
    128       for (EdgeIt i(g); i!=INVALID; ++i)
     128      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    129129        {
    130130          if(mapname!="Default")
  • graph_displayer_canvas-event.cc

    r48 r53  
    1 #include <graph_displayer_canvas.h>
    2 #include <broken_edge.h>
     1#include "graph_displayer_canvas.h"
     2#include "broken_edge.h"
    33#include <math.h>
    44
     
    100100      active_item=(get_item_at(clicked_x, clicked_y));
    101101      active_node=INVALID;
    102       for (NodeIt i(g); i!=INVALID; ++i)
     102      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    103103        {
    104104          if(nodesmap[i]==active_item)
     
    126126      if(active_node!=INVALID)
    127127      {
     128        mapstorage.modified = true;
     129        mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
    128130        //new coordinates will be the old values,
    129131        //because the item will be moved to the
     
    148150        EdgeIt ei;
    149151
    150         g.firstOut(ei,active_node);
    151 
    152         for(;ei!=INVALID;g.nextOut(ei))
     152        mapstorage.graph.firstOut(ei,active_node);
     153
     154        for(;ei!=INVALID;mapstorage.graph.nextOut(ei))
    153155        {
    154156            Gnome::Canvas::Points coos;
    155157            double x1, x2, y1, y2;
    156158
    157             nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
     159            nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    158160            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    159161
    160             nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
     162            nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    161163            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    162164
     
    177179        }
    178180
    179         g.firstIn(ei,active_node);
    180         for(;ei!=INVALID;g.nextIn(ei))
     181        mapstorage.graph.firstIn(ei,active_node);
     182        for(;ei!=INVALID;mapstorage.graph.nextIn(ei))
    181183        {
    182184            Gnome::Canvas::Points coos;
    183185            double x1, x2, y1, y2;
    184186
    185             nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
     187            nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
    186188            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    187189
    188             nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
     190            nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
    189191            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
    190192
     
    220222      break;
    221223    case GDK_BUTTON_PRESS:
     224      mapstorage.modified = true;
     225
    222226      isbutton=1;
    223227
    224       active_node=NodeIt(g,g.addNode());
     228      active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode());
    225229
    226230      //initiating values corresponding to new node in maps
     
    228232      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    229233
    230       nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
     234      mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
     235      (*mapstorage.nodemap_storage["id"])[active_node] =
     236        mapstorage.graph.id(active_node);
     237
     238      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
     239        clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
    231240      active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
    232241      *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
     
    234243      (nodesmap[active_node])->show();
    235244
    236       nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, "");
     245      nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
     246        clicked_x+node_property_defaults[N_RADIUS]+5,
     247        clicked_y+node_property_defaults[N_RADIUS]+5, "");
    237248      nodetextmap[active_node]->property_fill_color().set_value("darkblue");
    238249
    239       mapwin->updateNode(active_node);
     250      mapwin.updateNode(active_node);
    240251
    241252      break;
     
    301312              active_item=(get_item_at(clicked_x, clicked_y));
    302313              active_node=INVALID;
    303               for (NodeIt i(g); i!=INVALID; ++i)
     314              for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    304315                {
    305316                  if(nodesmap[i]==active_item)
     
    330341              target_item=(get_item_at(clicked_x, clicked_y));
    331342              Graph::NodeIt target_node=INVALID;
    332               for (NodeIt i(g); i!=INVALID; ++i)
     343              for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    333344                {
    334345                  if(nodesmap[i]==target_item)
     
    342353                  if(target_node!=active_node)         
    343354                    {
     355          mapstorage.modified = true;
     356
    344357                      *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
    345358
    346359                      //creating new edge
    347                       active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
     360                      active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node));
    348361
    349362                      //initiating values corresponding to new edge in maps
    350363                      mapstorage.initMapsForEdge(active_edge);
     364                      (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge);
    351365         
    352366                      //calculating coordinates of new edge
     
    377391
    378392                      //updating its properties
    379                       mapwin->updateEdge(active_edge);
     393                      mapwin.updateEdge(active_edge);
    380394                    }
    381395                  else
     
    430444      active_node=INVALID;
    431445      active_edge=INVALID;
    432 
    433446      //was it a node?
    434       for (NodeIt i(g); i!=INVALID; ++i)
     447      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    435448        {
    436449          if(nodesmap[i]==active_item)
     
    442455      if(active_node==INVALID)
    443456        {
    444           for (EdgeIt i(g); i!=INVALID; ++i)
     457          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    445458            {
    446459              if(edgesmap[i]==active_item)
     
    468481              if(active_node!=INVALID)
    469482                {
     483                  mapstorage.modified = true;
    470484
    471485                  //collecting edges to delete
     
    473487                  std::set<Graph::Edge> edges_to_delete;
    474488
    475                   g.firstOut(e,active_node);
    476                   for(;e!=INVALID;g.nextOut(e))
     489                  mapstorage.graph.firstOut(e,active_node);
     490                  for(;e!=INVALID;mapstorage.graph.nextOut(e))
    477491                    {
    478492                      edges_to_delete.insert(e);
    479493                    }
    480494
    481                   g.firstIn(e,active_node);
    482                   for(;e!=INVALID;g.nextIn(e))
     495                  mapstorage.graph.firstIn(e,active_node);
     496                  for(;e!=INVALID;mapstorage.graph.nextIn(e))
    483497                    {
    484498                      edges_to_delete.insert(e);
     
    546560            //find the activated item between texts
    547561            active_item=(get_item_at(e->button.x, e->button.y));
    548             for (EdgeIt i(g); i!=INVALID; ++i)
     562            for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    549563              {
    550564                if(edgetextmap[i]==active_item)
     
    560574                active_item=(get_item_at(clicked_x, clicked_y));
    561575
    562                 for (EdgeIt i(g); i!=INVALID; ++i)
     576                for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    563577                  {
    564578                    //at the same time only one can be active
     
    664678            //find the activated item between texts
    665679            active_item=(get_item_at(e->button.x, e->button.y));
    666             for (NodeIt i(g); i!=INVALID; ++i)
     680            for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    667681              {
    668682                //at the same time only one can be active
     
    679693                active_item=(get_item_at(clicked_x, clicked_y));
    680694
    681                 for (NodeIt i(g); i!=INVALID; ++i)
     695                for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    682696                  {
    683697                    //at the same time only one can be active
     
    804818                        edgetextmap[active_edge]->property_text().set_value(ostr.str());
    805819                        (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
    806                         mapwin->updateEdge(active_edge);
     820                        mapwin.updateEdge(active_edge);
    807821                        break;
    808822                      case NODE_MAP_EDIT:
    809823                        nodetextmap[active_node]->property_text().set_value(ostr.str());
    810824                        (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
    811                         mapwin->updateNode(active_node);
     825                        mapwin.updateNode(active_node);
    812826                        break;
    813827                      default:
     
    836850  delete(nodetextmap[node_to_delete]);
    837851  delete(nodesmap[node_to_delete]);
    838   g.erase(node_to_delete);
     852  mapstorage.graph.erase(node_to_delete);
    839853}
    840854
     
    843857  delete(edgetextmap[edge_to_delete]);
    844858  delete(edgesmap[edge_to_delete]);
    845   g.erase(edge_to_delete);
     859  mapstorage.graph.erase(edge_to_delete);
    846860}
    847861
     
    850864  delete(edgetextmap[edge_to_delete]);
    851865  delete(edgesmap[edge_to_delete]);
    852   g.erase(edge_to_delete);
     866  mapstorage.graph.erase(edge_to_delete);
    853867}
    854868
     
    870884      else
    871885        {
    872           for (EdgeIt i(g); i!=INVALID; ++i)
     886          for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    873887            {
    874888              if(edgesmap[i]==active_bre)
     
    896910{
    897911  //create the new map
    898   Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
     912  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
    899913
    900914  //if addition was not successful addEdgeMap returns one.
     
    907921
    908922  //add it to the list of the displayable maps
    909   mapwin->registerNewEdgeMap(mapname);
     923  mapwin.registerNewEdgeMap(mapname);
    910924
    911925  //display it
     
    918932{
    919933  //create the new map
    920   Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
     934  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
    921935
    922936  //if addition was not successful addNodeMap returns one.
     
    928942
    929943  //add it to the list of the displayable maps
    930   mapwin->registerNewNodeMap(mapname);
     944  mapwin.registerNewNodeMap(mapname);
    931945
    932946  //display it
  • graph_displayer_canvas-node.cc

    r48 r53  
    1 #include <graph_displayer_canvas.h>
    2 #include <broken_edge.h>
     1#include "graph_displayer_canvas.h"
     2#include "broken_edge.h"
    33#include <math.h>
    44
     
    1212      min=node_property_defaults[N_RADIUS];
    1313      max=node_property_defaults[N_RADIUS];
    14       actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
     14      actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
    1515    }
    1616  else
     
    2323  if(node==INVALID)
    2424    {
    25       for (NodeIt i(g); i!=INVALID; ++i)
     25      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    2626        {
    2727          double v=abs((*actual_map)[i]);
     
    8080  if(mapname=="Default")
    8181    {
    82       actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
     82      actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
    8383    }
    8484  else
     
    104104    {
    105105
    106       for (NodeIt i(g); i!=INVALID; ++i)
     106      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    107107        {
    108108          Gdk::Color color;
     
    158158  if(node==INVALID)
    159159    {
    160       for (NodeIt i(g); i!=INVALID; ++i)
     160      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    161161        {
    162162          if(mapname!="Default")
  • graph_displayer_canvas-zoom.cc

    r27 r53  
    1 #include <graph_displayer_canvas.h>
    2 #include <broken_edge.h>
     1#include "graph_displayer_canvas.h"
     2#include "broken_edge.h"
    33#include <math.h>
    44
  • graph_displayer_canvas.cc

    r48 r53  
    1 #include <graph_displayer_canvas.h>
    2 #include <broken_edge.h>
     1#include "graph_displayer_canvas.h"
     2#include "broken_edge.h"
    33#include <math.h>
    44
    5 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),nodemap_to_edit(""),edgemap_to_edit(""),mapwin(mw)
     5GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) :
     6  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
     7  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
     8  canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
     9  target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
    610{
    7  
    8   //Initializing values.
    9   active_node=INVALID;
    10   active_edge=INVALID;
    11   forming_edge=INVALID;
     11  //base event handler is move tool
     12  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
     13  actual_tool=MOVE;
    1214
    1315  //setting event handler for the editor widget
    1416  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
    1517
    16   //base event handler is move tool
    17   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    18   actual_tool=MOVE;
     18  active_node=INVALID;
     19  active_edge=INVALID;
     20  forming_edge=INVALID;
     21}
    1922
    20   //set_center_scroll_region(true);
     23GraphDisplayerCanvas::~GraphDisplayerCanvas()
     24{
     25  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
     26  {
     27    delete nodesmap[n];
     28    delete nodetextmap[n];
     29  }
    2130
     31  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
     32  {
     33    delete edgesmap[e];
     34    delete edgetextmap[e];
     35  }
     36
     37  if(canvasentrywidget)
     38  {
     39    delete(canvasentrywidget);
     40  }
     41}
     42
     43void GraphDisplayerCanvas::drawGraph()
     44{
    2245  //first edges are drawn, to hide joining with nodes later
    2346
    24   for (EdgeIt i(g); i!=INVALID; ++i)
     47  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    2548  {
    2649
    27     //drawing green lines, coordinates are from cm
     50    //drawing green lines, coordinates are from mapstorage.coords
    2851
    2952    Gnome::Canvas::Points coos;
    30     coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
    31     coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
     53    coos.push_back(Gnome::Art::Point(
     54          mapstorage.coords[mapstorage.graph.source(i)].x,
     55          mapstorage.coords[mapstorage.graph.source(i)].y));
     56    coos.push_back(Gnome::Art::Point(
     57          mapstorage.coords[mapstorage.graph.target(i)].x,
     58          mapstorage.coords[mapstorage.graph.target(i)].y));
    3259   
    3360    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
     
    4774  //afterwards nodes come to be drawn
    4875
    49   NodeIt i(g);
    50   int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
    51 
    52   for (; i!=INVALID; ++i)
     76  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    5377  {
    54     //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
    55 
    56     if(cm[i].x>maxx)maxx=(int)cm[i].x;
    57     if(cm[i].y>maxy)maxy=(int)cm[i].y;
    58     if(cm[i].x<minx)minx=(int)cm[i].x;
    59     if(cm[i].y<miny)miny=(int)cm[i].y;
    60 
    6178    //drawing bule nodes, with black line around them
    6279
    63     nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
     80    nodesmap[i]=new Gnome::Canvas::Ellipse(
     81        displayed_graph,
     82        mapstorage.coords[i].x-20,
     83        mapstorage.coords[i].y-20,
     84        mapstorage.coords[i].x+20,
     85        mapstorage.coords[i].y+20);
    6486    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    6587    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
     
    6789    //initializing edge-text as well, to empty string
    6890
    69     xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
     91    xy<double> text_pos(
     92        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
     93        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
    7094
    71     nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
     95    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
     96        text_pos.x, text_pos.y, "");
    7297    nodetextmap[i]->property_fill_color().set_value("darkblue");
    7398    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
     
    77102}
    78103
    79 GraphDisplayerCanvas::~GraphDisplayerCanvas()
     104void GraphDisplayerCanvas::clear()
    80105{
    81   if(canvasentrywidget)
    82     {
    83       delete(canvasentrywidget);
    84     }
     106  active_node=INVALID;
     107  active_edge=INVALID;
     108  forming_edge=INVALID;
    85109
    86   //writing out the end state of the graph
    87   //\todo all the maps has to be write out!
    88 
    89   Graph::NodeMap <int> id(g);
    90   Graph::NodeMap <double> xc(g);
    91   Graph::NodeMap <double> yc(g);
    92  
    93   int j=1;
    94  
    95   for (NodeIt i(g); i!=INVALID; ++i)
     110  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
    96111  {
    97     double x1,y1,x2,y2;
    98     nodesmap[i]->get_bounds(x1, y1, x2, y2);
    99    
    100     id[i]=j++;
    101     xc[i]=(x1+x2)/2;
    102     yc[i]=(y1+y2)/2;
     112    delete nodesmap[n];
     113    delete nodetextmap[n];
    103114  }
    104115
    105   GraphWriter<Graph> writer(std::cout,g);
    106  
    107   writer.writeNodeMap("id", id);
    108   writer.writeNodeMap("coordinates_x", xc);
    109   writer.writeNodeMap("coordinates_y", yc);
    110   writer.run();
     116  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
     117  {
     118    delete edgesmap[e];
     119    delete edgetextmap[e];
     120  }
    111121}
  • graph_displayer_canvas.h

    r46 r53  
    66class GraphDisplayerCanvas;
    77
    8 #include <all_include.h>
    9 #include <map_win.h>
    10 #include <mapstorage.h>
    11 #include <broken_edge.h>
     8#include "all_include.h"
     9#include "mapstorage.h"
     10#include "broken_edge.h"
     11#include "map_win.h"
    1212#include <libgnomecanvasmm.h>
    1313#include <libgnomecanvasmm/polygon.h>
     
    1919
    2020public:
    21   GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &, MapWin *);
     21  GraphDisplayerCanvas(MapStorage &, MapWin &);
    2222  virtual ~GraphDisplayerCanvas();
    2323
     
    110110  int getActualTool();
    111111
     112  void drawGraph();
     113  void clear();
     114
    112115  ///creates a new Nodemap
    113116  int addNewNodeMap(double,std::string);
     
    124127
    125128private:
    126 
    127   ///The graph, on which we work
    128   Graph & g;
    129129
    130130  ///Map of nodes of graph
     
    176176
    177177  ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
    178   MapWin * mapwin;
     178  MapWin & mapwin;
    179179
    180180};
  • main_win.cc

    r50 r53  
    1 #include <main_win.h>
    2 
    3 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
    4     MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),newmapwin("Creating new map",gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
     1#include "main_win.h"
     2
     3MainWin::MainWin(const std::string& title) :
     4  mapwin("Map Setup", mapstorage, gd_canvas),
     5  newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin)
    56{
    67
     
    2021  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
    2122      sigc::mem_fun(*this, &MainWin::saveFileAs));
    22   ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
     23  ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
     24      sigc::mem_fun(*this, &MainWin::close));
     25  ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
    2326      sigc::mem_fun(*this, &MainWin::hide));
    2427
     
    3740      sigc::mem_fun(this->mapwin, &MapWin::show));
    3841
    39   ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO),
     42  Gtk::RadioAction::Group tool_group;
     43  ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
     44      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
     45  ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
    4046      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
    41   ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE),
     47  ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
    4248      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
    43   ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE),
     49  ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
    4450      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
    45   ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),
    46       sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
    4751  ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
    4852      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
     
    6771      "      <menuitem action='FileSave'/>"
    6872      "      <menuitem action='FileSaveAs'/>"
    69       "      <menuitem action='FileQuit'/>"
     73      "      <menuitem action='Close'/>"
     74      "      <menuitem action='Quit'/>"
    7075      "    </menu>"
    7176      "    <menu action='ViewMenu'>"
     
    8388      "    <toolitem action='FileOpen' />"
    8489      "    <toolitem action='FileSave' />"
     90      "    <toolitem action='Close' />"
    8591      "    <separator />"
    8692      "    <toolitem action='ViewZoomIn' />"
     
    8995      "    <toolitem action='ViewZoom100' />"
    9096      "    <separator />"
     97      "    <toolitem action='MoveItem' />"
    9198      "    <toolitem action='CreateNode' />"
    9299      "    <toolitem action='CreateEdge' />"
    93100      "    <toolitem action='EraseItem' />"
    94       "    <toolitem action='MoveItem' />"
    95101      "    <toolitem action='EditEdgeMap' />"
    96102      "    <toolitem action='EditNodeMap' />"
     
    131137void MainWin::newFile()
    132138{
    133   std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
     139  if (mapstorage.modified)
     140  {
     141    Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
     142        Gtk::BUTTONS_NONE);
     143    mdialog.set_message("<b>Save changes before closing?</b>", true);
     144    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
     145    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     146    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
     147    switch (mdialog.run())
     148    {
     149      case Gtk::RESPONSE_CANCEL:
     150        return;
     151      case Gtk::RESPONSE_REJECT:
     152        break;
     153      case Gtk::RESPONSE_ACCEPT:
     154        saveFile();
     155        break;
     156    }
     157  }
     158  gd_canvas.clear();
     159  mapstorage.clear();
     160  mapwin.update();
    134161}
    135162
    136163void MainWin::openFile()
    137164{
    138   std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
     165  if (mapstorage.modified)
     166  {
     167    Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
     168        Gtk::BUTTONS_NONE);
     169    mdialog.set_message("<b>Save changes before closing?</b>", true);
     170    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
     171    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     172    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
     173    switch (mdialog.run())
     174    {
     175      case Gtk::RESPONSE_CANCEL:
     176        return;
     177      case Gtk::RESPONSE_REJECT:
     178        break;
     179      case Gtk::RESPONSE_ACCEPT:
     180        saveFile();
     181        break;
     182    }
     183  }
     184  gd_canvas.clear();
     185  mapstorage.clear();
     186  Gtk::FileChooserDialog fcdialog("Open File");
     187  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     188  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
     189  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
     190  {
     191    Glib::ustring filename = fcdialog.get_filename();
     192    mapstorage.readFromFile(filename);
     193    mapstorage.file_name = filename;
     194    mapstorage.modified = false;
     195    gd_canvas.drawGraph();
     196    mapwin.update();
     197  }
    139198}
    140199
    141200void MainWin::saveFile()
    142201{
    143   std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
     202  if (mapstorage.file_name == "") {
     203    saveFileAs();
     204  }
     205  else
     206  {
     207    mapstorage.writeToFile(mapstorage.file_name);
     208    mapstorage.modified = false;
     209  }
    144210}
    145211
    146212void MainWin::saveFileAs()
    147213{
    148   std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
    149 }
     214  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
     215  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     216  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
     217  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
     218  {
     219    Glib::ustring filename = fcdialog.get_filename();
     220    mapstorage.file_name = filename;
     221    mapstorage.writeToFile(filename);
     222    mapstorage.modified = false;
     223  }
     224}
     225
     226void MainWin::close()
     227{
     228  if (mapstorage.modified)
     229  {
     230    Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
     231        Gtk::BUTTONS_NONE);
     232    mdialog.set_message("<b>Save changes before closing?</b>", true);
     233    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
     234    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     235    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
     236    switch (mdialog.run())
     237    {
     238      case Gtk::RESPONSE_CANCEL:
     239        return;
     240      case Gtk::RESPONSE_REJECT:
     241        break;
     242      case Gtk::RESPONSE_ACCEPT:
     243        saveFile();
     244        break;
     245    }
     246  }
     247  gd_canvas.clear();
     248  mapstorage.clear();
     249  mapwin.update();
     250}
  • main_win.h

    r50 r53  
    44#define MAIN_WIN_H
    55
    6 #include <all_include.h>
    7 #include <mapstorage.h>
    8 #include <map_win.h>
    9 #include <new_map_win.h>
     6#include "all_include.h"
     7#include "mapstorage.h"
     8#include "map_win.h"
     9#include "new_map_win.h"
     10#include "edit_win.h"
     11#include "graph_displayer_canvas.h"
    1012#include <libgnomecanvasmm.h>
    1113#include <libgnomecanvasmm/polygon.h>
     
    1820  ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
    1921  ///\param title is the title of the window
    20   ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
    21   ///\param cm stores the coordinates of the nodes of the graph
    22   ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
    23   MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
     22  MainWin(const std::string& title);
     23
     24  MapStorage mapstorage;
    2425
    2526protected:
     
    5354  ///Callback for 'FileSaveAs' action.
    5455  virtual void saveFileAs();
     56  ///Callback for 'Close' action.
     57  virtual void close();
    5558};
    5659
  • map_win.cc

    r48 r53  
    1 #include <map_win.h>
     1#include "map_win.h"
    22#include <set>
    33
     
    119119  show_all_children();
    120120
     121}
     122
     123void MapWin::update()
     124{
     125  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     126  {
     127    //filling in combo box with choices
     128    std::list<Glib::ustring> listStrings;
     129
     130    listStrings.push_back("Default");
     131
     132    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
     133    for(;emsi!=ms.endOfEdgeMaps();emsi++)
     134    {
     135      listStrings.push_back(emsi->first);
     136    }
     137
     138    e_combo_array[i].set_popdown_strings(listStrings);
     139  }
     140  for(int i=0;i<NODE_PROPERTY_NUM;i++)
     141  {
     142    //filling in combo box with choices
     143    std::list<Glib::ustring> listStrings;
     144
     145    listStrings.push_back("Default");
     146
     147    std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
     148
     149    for(;emsi!=ms.endOfNodeMaps();emsi++)
     150    {
     151      listStrings.push_back(emsi->first);
     152    }
     153
     154    n_combo_array[i].set_popdown_strings(listStrings);
     155  }
    121156}
    122157
  • map_win.h

    r38 r53  
    66class MapWin;
    77
    8 #include <all_include.h>
    9 #include <mapstorage.h>
    10 #include <graph_displayer_canvas.h>
     8#include "all_include.h"
     9#include "graph_displayer_canvas.h"
     10#include "mapstorage.h"
    1111#include <libgnomecanvasmm.h>
    1212#include <libgnomecanvasmm/polygon.h>
     
    6464  virtual bool closeIfEscapeIsPressed(GdkEventKey*);
    6565
     66  void update();
    6667};
    6768
  • mapstorage.cc

    r46 r53  
    1 #include <mapstorage.h>
    2 
    3 MapStorage::MapStorage(Graph & graph):g(graph)
    4 {
    5 };
     1#include "mapstorage.h"
     2
     3MapStorage::MapStorage() : modified(false), file_name("")
     4{
     5  nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
     6  coords.setXMap(*nodemap_storage["coordinates_x"]);
     7  nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
     8  coords.setYMap(*nodemap_storage["coordinates_y"]);
     9
     10  nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
     11  edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
     12}
     13
     14MapStorage::~MapStorage()
     15{
     16  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
     17      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
     18  {
     19    delete it->second;
     20  }
     21  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
     22      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
     23  {
     24    delete it->second;
     25  }
     26}
    627
    728int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
     
    2849{
    2950  double max=0;
    30   for (NodeIt j(g); j!=INVALID; ++j)
     51  for (NodeIt j(graph); j!=INVALID; ++j)
    3152  {
    3253    if( (*nodemap_storage[name])[j]>max )
     
    4162{
    4263  double max=0;
    43   for (EdgeIt j(g); j!=INVALID; ++j)
     64  for (EdgeIt j(graph); j!=INVALID; ++j)
    4465  {
    4566    if( (*edgemap_storage[name])[j]>max )
     
    5374double MapStorage::minOfNodeMap(const std::string & name)
    5475{
    55   NodeIt j(g);
     76  NodeIt j(graph);
    5677  double min=(*nodemap_storage[name])[j];
    5778  for (; j!=INVALID; ++j)
     
    6788double MapStorage::minOfEdgeMap(const std::string & name)
    6889{
    69   EdgeIt j(g);
     90  EdgeIt j(graph);
    7091  double min=(*edgemap_storage[name])[j];
    71   for (EdgeIt j(g); j!=INVALID; ++j)
     92  for (EdgeIt j(graph); j!=INVALID; ++j)
    7293  {
    7394    if( (*edgemap_storage[name])[j]<min )
     
    87108    }
    88109}
     110
     111void MapStorage::readFromFile(const std::string &filename)
     112{
     113  bool read_x = false;
     114  bool read_y = false;
     115
     116  try {
     117    LemonReader lreader(filename);
     118    ContentReader content(lreader);
     119    lreader.run();
     120
     121    const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
     122    const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
     123
     124    GraphReader<Graph> greader(filename, graph);
     125    for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
     126        it != nodeMapNames.end(); ++it)
     127    {
     128      if (*it == "coordinates_x")
     129      {
     130        read_x = true;
     131        //std::cout << "read X nodemap" << std::endl;
     132      }
     133      else if (*it == "coordinates_y")
     134      {
     135        read_y = true;
     136        //std::cout << "read Y nodemap" << std::endl;
     137      }
     138      else if (*it == "id")
     139      {
     140        //std::cout << "read id nodemap" << std::endl;
     141      }
     142      else
     143      {
     144        nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
     145        //std::cout << "read " << *it << " nodemap" << std::endl;
     146      }
     147      greader.readNodeMap(*it, *nodemap_storage[*it]);
     148    }
     149    for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
     150        it != edgeMapNames.end(); ++it)
     151    {
     152      if (*it == "id")
     153      {
     154        //std::cout << "read id edgemap" << std::endl;
     155      }
     156      else
     157      {
     158        edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
     159        //std::cout << "read " << *it << " edgemap" << std::endl;
     160      }
     161      greader.readEdgeMap(*it, *edgemap_storage[*it]);
     162    }
     163    greader.run();
     164  } catch (DataFormatError& error) {
     165    /*
     166    Gtk::MessageDialog mdialog("Read Error");
     167    mdialog.set_message(error.what());
     168    mdialog.run();
     169    */
     170    // reset graph and mapstorage ?
     171    return;
     172  }
     173
     174  if (!read_x || !read_y)
     175  {
     176    int node_num = 0;
     177    for (NodeIt n(graph); n != INVALID; ++n)
     178    {
     179      node_num++;
     180    }
     181    const double pi = 3.142;
     182    double step = 2 * pi / (double) node_num;
     183    int i = 0;
     184    for (NodeIt n(graph); n != INVALID; ++n)
     185    {
     186      nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step));
     187      nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step));
     188      i++;
     189    }
     190  }
     191}
     192
     193void MapStorage::writeToFile(const std::string &filename)
     194{
     195  GraphWriter<Graph> gwriter(filename, graph);
     196
     197  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
     198      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
     199  {
     200    gwriter.writeNodeMap(it->first, *(it->second));
     201    //std::cout << "wrote " << it->first << " nodemap" << std::endl;
     202  }
     203  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
     204      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
     205  {
     206    gwriter.writeEdgeMap(it->first, *(it->second));
     207    //std::cout << "wrote " << it->first << " edgemap" << std::endl;
     208  }
     209  gwriter.run();
     210}
     211
     212void MapStorage::clear()
     213{
     214  for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
     215      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
     216  {
     217    if ((it->first != "coordinates_x") &&
     218        (it->first != "coordinates_y") &&
     219        (it->first != "id"))
     220    {
     221      delete it->second;
     222      nodemap_storage.erase(it);
     223    }
     224  }
     225  for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
     226      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
     227  {
     228    if (it->first != "id")
     229    {
     230      delete it->second;
     231      edgemap_storage.erase(it);
     232    }
     233  }
     234  graph.clear();
     235  file_name = "";
     236  modified = false;
     237}
  • mapstorage.h

    r31 r53  
    44#define MAPSTORAGE_H
    55
    6 #include <all_include.h>
     6#include "all_include.h"
     7#include "xymap.h"
    78
    89///Class MapStorage is responsible for storing
     
    1920public:
    2021
    21   Graph &g;
     22  Graph graph;
     23  XYMap<Graph::NodeMap<double> > coords;
     24
     25  bool modified;
     26  std::string file_name;
    2227
    2328  ///Stores double type NodeMaps
     
    4045  ///
    4146  ///\param graph is the graph for which the maps are stored in this object.
    42   MapStorage(Graph &);
     47  MapStorage();
     48
     49  ~MapStorage();
    4350
    4451  ///Adds given map to storage. A name and the map itself has to be provided.
     
    93100  ///This function sets a default base value for the newly created node
    94101  void initMapsForEdge(Graph::Edge);
     102
     103  void readFromFile(const std::string &);
     104  void writeToFile(const std::string &);
     105
     106  void clear();
    95107};
    96108
Note: See TracChangeset for help on using the changeset viewer.