COIN-OR::LEMON - Graph Library

Changeset 201:879e47e5b731 in glemon-0.x


Ignore:
Timestamp:
01/02/08 22:03:09 (16 years ago)
Author:
Akos Ladanyi
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
Message:

Merge branches/akos to trunk.

Files:
12 added
31 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r193 r201  
    4848        dijkstrabox.h \
    4949        dijkstrabox.cc \
     50        file_import_dialog.h \
     51        file_import_dialog.cc \
     52        map_value.h \
     53        map_value.cc \
     54        map_value_map.h \
     55        map_value_map.cc \
     56        save_details_widget.h \
     57        save_details_widget.cc \
     58        save_details_dialog.h \
     59        save_details_dialog.cc \
     60        io_helper.h \
     61        io_helper.cc \
    5062        background_chooser_dialog.h \
    5163        background_chooser_dialog.cc \
  • algobox.cc

    r194 r201  
    8383{
    8484  mapstorage=ms;
    85   std::vector<std::string> nml;
    86   std::vector<std::string> eml;
     85  std::vector<std::string> n_nml;
     86  std::vector<std::string> s_nml;
     87  std::vector<std::string> n_eml;
     88  std::vector<std::string> s_eml;
    8789  if(mapstorage!=NULL)
    8890    {
    8991      mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
    9092      mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
    91       nml=mapstorage->getNodeMapList();
    92       eml=mapstorage->getEdgeMapList();
     93      n_nml=mapstorage->getNodeMapList(NUM);
     94      s_nml=mapstorage->getNodeMapList(STR);
     95      n_eml=mapstorage->getEdgeMapList(NUM);
     96      s_eml=mapstorage->getEdgeMapList(STR);
    9397    }
    9498  for(int i=0;i<(int)nodemapcbts.size();i++)
    9599    {
    96       (nodemapcbts[i])->update_list(nml);
     100      (nodemapcbts[i])->update_list(n_nml, s_nml);
    97101      //update_cbt(nml, *(nodemapcbts[i]));
    98102    }
    99103  for(int i=0;i<(int)edgemapcbts.size();i++)
    100104    {
    101       (edgemapcbts[i])->update_list(eml);
     105      (edgemapcbts[i])->update_list(n_eml, s_eml);
    102106      //update_cbt(eml, *(edgemapcbts[i]));
    103107    }
     
    105109}
    106110
    107 void AlgoBox::nodemaplist_changed(std::string newmap)
     111void AlgoBox::nodemaplist_changed(std::string newmap, MapValue::Type type)
    108112{
    109113  for(int i=0;i<(int)nodemapcbts.size();i++)
    110114    {
    111       (nodemapcbts[i])->append_text(newmap);
    112     }
    113 }
    114 
    115 void AlgoBox::edgemaplist_changed(std::string newmap)
     115      (nodemapcbts[i])->append_text(newmap, type);
     116    }
     117}
     118
     119void AlgoBox::edgemaplist_changed(std::string newmap, MapValue::Type type)
    116120{
    117121  for(int i=0;i<(int)edgemapcbts.size();i++)
    118122    {
    119       (edgemapcbts[i])->append_text(newmap);
     123      (edgemapcbts[i])->append_text(newmap, type);
    120124    }
    121125}
     
    161165}
    162166
    163 void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
     167void AlgoBox::addMapSelector(std::string inputname, bool itisedge, MapType type)
    164168{
    165169  std::vector<std::string> empty_vector;
    166170
    167   MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
     171  MapSelector * msp=new MapSelector(empty_vector,empty_vector,"",inputname,itisedge, false, type);
    168172
    169173  if(itisedge)
  • algobox.h

    r194 r201  
    2626#include <libgnomecanvasmm.h>
    2727#include <libgnomecanvasmm/polygon.h>
     28#include "map_value.h"
    2829
    2930///Ancestor class of algorithm graphical interface classes.
     
    139140  ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s
    140141  ///in \ref nodemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text)
    141   void nodemaplist_changed(std::string);
     142  void nodemaplist_changed(std::string, MapValue::Type);
    142143
    143144  ///Interface, through which \ref AlgoBox can be notified about edgemap addition.
     
    146147  ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s
    147148  ///in \ref edgemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text)
    148   void edgemaplist_changed(std::string);
     149  void edgemaplist_changed(std::string, MapValue::Type);
    149150
    150151  ///Aid function to provide data for a given entry.
     
    184185  ///\param label label to show in \ref MapSelector
    185186  ///\param itisedge whether edge or nodemaps stored in \ref MapSelector
    186   void addMapSelector(std::string label, bool itisedge);
     187  void addMapSelector(std::string label, bool itisedge, MapType type = ALL);
    187188};
    188189#endif //ALGOBOX_H
  • all_include.h

    r191 r201  
    6666const std::string prog_name = "LEMON Graph Editor";
    6767
     68enum MapType
     69{
     70  NUM  = 1 << 0,
     71  STR  = 1 << 1,
     72  ALL  = (1 << 0) | (1 << 1)
     73};
     74
    6875#endif // ALL_INCLUDE_H
  • configure.ac

    r183 r201  
    2727PKG_CHECK_MODULES([GTK], [libgnomecanvasmm-2.6 >= 2.6.0 gtkmm-2.4 >= 2.6])
    2828
    29 AC_ARG_WITH([lemon-prefix],
    30 AS_HELP_STRING([--with-lemon-prefix@<:@=PREFIX@:>@], [search for LEMON under PREFIX]), [], [with_lemon_prefix=no])
    31 if test x"$with_lemon_prefix" != x"no"; then
    32   export PKG_CONFIG_PATH="$with_lemon_prefix/lib/pkgconfig/:$PKG_CONFIG_PATH"
     29AC_ARG_WITH([lemon],
     30AS_HELP_STRING([--with-lemon@<:@=PREFIX@:>@], [search for LEMON under PREFIX]), [], [with_lemon=no])
     31if test x"$with_lemon" != x"no"; then
     32  export PKG_CONFIG_PATH="$with_lemon/lib/pkgconfig/:$PKG_CONFIG_PATH"
    3333fi
    3434
    35 PKG_CHECK_MODULES([LEMON_0_5], [lemon >= 0.5],
    36   [lemon_0_5_found=yes], [
    37     AC_MSG_RESULT([no])
    38     lemon_0_5_found=no])
    39 PKG_CHECK_MODULES([LEMON_SVNHEAD], [lemon = svnhead],
    40   [lemon_svn_head_found=yes], [
    41     AC_MSG_RESULT([no])
    42     lemon_svn_head_found=no])
    43 if test x"$lemon_0_5_found" = x"no" -a x"$lemon_svn_head_found" = x"no"; then
    44   AC_MSG_ERROR([LEMON not found.])
    45 else
    46   if test x"$lemon_svn_head_found" = x"yes"; then
    47     LEMON_CFLAGS="$LEMON_SVNHEAD_CFLAGS"
    48     LEMON_LIBS="$LEMON_SVNHEAD_LIBS"
    49   else
    50     LEMON_CFLAGS="$LEMON_0_5_CFLAGS"
    51     LEMON_LIBS="$LEMON_0_5_LIBS"
    52   fi
    53   AC_SUBST(LEMON_CFLAGS)
    54   AC_SUBST(LEMON_LIBS)
    55 fi
     35PKG_CHECK_MODULES([LEMON], [lemon >= 0.6.90])
    5636
    5737dnl Checks for header files.
  • dijkstrabox.cc

    r194 r201  
    5151   
    5252void DijkstraBox::run()
     53{
     54  if(
     55      tabcbt.get_active_text()!="" &&
     56      (edgemapcbts[INPUT])->get_active_text()!="" &&
     57      (edgemapcbts[OUTPUT])->get_active_text()!="" &&
     58      source.get_active_text()!="" &&
     59      target.get_active_text()!=""
     60    )
     61  {
     62    const Graph &g=mapstorage->graph;
     63    Node from, to;
     64
     65    get_from_to(from, to, (Graph&)g);
     66
     67    std::ostringstream o;
     68
     69    if(!(from==to))
     70    {
     71      std::string inputmapName = edgemapcbts[INPUT]->get_active_text();
     72      std::string outputmapName = edgemapcbts[OUTPUT]->get_active_text();
     73
     74      MapStorage::NumericEdgeMap& inputmap = mapstorage->getNumericEdgeMap(inputmapName);
     75      MapStorage::NumericEdgeMap& outputmap = mapstorage->getNumericEdgeMap(outputmapName);
     76
     77      //zero out output map
     78      for (EdgeIt i(g); i!=INVALID; ++i)
     79      {
     80        outputmap[i]=0;
     81      }
     82
     83      Dijkstra<Graph, MapStorage::NumericEdgeMap > dijkstra(g, inputmap);
     84      dijkstra.run(from, to);
     85
     86      if(dijkstra.reached(to))
     87      {
     88        Node n=to;
     89        int length=0;
     90        while (n!=INVALID && n!=from)
     91        {
     92          Edge e=dijkstra.predEdge(n);
     93          outputmap[e]=1;
     94          n=dijkstra.predNode(n);
     95          length++;
     96        }
     97        o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
     98      }
     99      else
     100      {
     101        o << "Result: failed to find shortest path between ";
     102        o << source.get_active_text() << " and " << target.get_active_text();
     103      }
     104      resultlabel.set_text(o.str());
     105
     106      mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
     107      //   mapstorage->changeActiveMap(true, E_COLOR,
     108      //                              (edgemapcbts[OUTPUT])->get_active_text());
     109      //   mapstorage->changeActiveMap(true, E_TEXT,
     110      //                              (edgemapcbts[INPUT])->get_active_text());
     111    }
     112  }
     113}
     114
     115void SuurballeBox::run()
    53116{
    54117  if(
     
    69132      if(!(from==to))
    70133        {
    71           Graph::EdgeMap<double> * inputmap=
    72             (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
    73           Graph::EdgeMap<double> * outputmap=
    74             (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
     134          MapStorage::NumericEdgeMap& inputmap=
     135            mapstorage->getNumericEdgeMap(edgemapcbts[INPUT]->get_active_text());
     136          MapStorage::NumericEdgeMap& outputmap=
     137            mapstorage->getNumericEdgeMap(edgemapcbts[OUTPUT]->get_active_text());
    75138
    76139          //zero out output map
    77140          for (EdgeIt i(g); i!=INVALID; ++i)
    78141            {
    79               (*outputmap)[i]=0;
     142              outputmap[i]=0;
    80143            }
    81144         
    82           Dijkstra<Graph, Graph::EdgeMap<double> > dijkstra(g, *inputmap);
    83           dijkstra.run(from, to);
    84          
    85           if(dijkstra.reached(to))
    86             {
    87               Node n=to;
    88               int length=0;
    89               while (n!=INVALID && n!=from)
    90                 {
    91                   Edge e=dijkstra.predEdge(n);
    92                   (*outputmap)[e]=1;
    93                   n=dijkstra.predNode(n);
    94                   length++;
    95                 }
    96               o << "Result: " << length << " long path, with cost " << dijkstra.dist(to);
    97             }
    98           else
    99             {
    100               o << "Result: failed to find shortest path between ";
    101               o << source.get_active_text() << " and " << target.get_active_text();
    102             }
    103           resultlabel.set_text(o.str());
    104          
    105           mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
    106           //   mapstorage->changeActiveMap(true, E_COLOR,
    107           //                          (edgemapcbts[OUTPUT])->get_active_text());
    108           //   mapstorage->changeActiveMap(true, E_TEXT,
    109           //                          (edgemapcbts[INPUT])->get_active_text());
    110         }
    111     }
    112 }
    113 
    114 void SuurballeBox::run()
    115 {
    116   if(
    117      tabcbt.get_active_text()!="" &&
    118      (edgemapcbts[INPUT])->get_active_text()!="" &&
    119      (edgemapcbts[OUTPUT])->get_active_text()!="" &&
    120      source.get_active_text()!="" &&
    121      target.get_active_text()!=""
    122      )
    123     {
    124       const Graph &g=mapstorage->graph;
    125       Node from, to;
    126 
    127       get_from_to(from, to, (Graph&)g);
    128 
    129       std::ostringstream o;
    130 
    131       if(!(from==to))
    132         {
    133           Graph::EdgeMap<double> * inputmap=
    134             (mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()];
    135           Graph::EdgeMap<double> * outputmap=
    136             (mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()];
    137 
    138           //zero out output map
    139           for (EdgeIt i(g); i!=INVALID; ++i)
    140             {
    141               (*outputmap)[i]=0;
    142             }
    143          
    144           Suurballe<Graph, Graph::EdgeMap<double> > sb((Graph&)g, *inputmap, from, to);
     145          Suurballe<Graph, MapStorage::NumericEdgeMap > sb((Graph&)g, inputmap, from, to);
    145146         
    146147          int found=sb.run(num_set->get_value_as_int());
     
    153154                  for(int k=0;k<path.length();k++)
    154155                    {
    155                       (*outputmap)[path.nth(k)]=j+1;
     156                      outputmap[path.nth(k)]=j+1;
    156157                    }
    157158                }
     
    181182  signal_upon_maplist_updated().connect(sigc::mem_fun(*this, &DijkstraBox::maplists_updated));
    182183
    183   addMapSelector("Cost map: ", true);
    184   addMapSelector("Edges of path here: ", true);
     184  addMapSelector("Cost map: ", true, NUM);
     185  addMapSelector("Edges of path here: ", true, NUM);
    185186
    186187  Gtk::Label * source_label=new Gtk::Label("Source: ");
     
    213214        {
    214215          std::ostringstream text;
    215           text << (*((mapstorage->nodemap_storage)["label"]))[i];
     216          text << mapstorage->getLabel(i);
    216217          source.prepend_text(text.str());
    217218          target.prepend_text(text.str());
     
    226227    {
    227228      std::ostringstream text;
    228       text << (*((mapstorage->nodemap_storage)["label"]))[i];
     229      text << mapstorage->getLabel(i);
    229230      if(!(text.str().compare(source.get_active_text())))
    230231        {
  • eps_win.cc

    r198 r201  
    3232}
    3333
    34 EpsWin::EpsWin(const std::string& title, std::vector<std::string> nml):Gtk::Dialog(title, true, true)
     34EpsWin::EpsWin(const std::string& title, std::vector<std::string> n_nml, std::vector<std::string> s_nml):Gtk::Dialog(title, true, true)
    3535{
    3636  set_default_size(200, 50);
     
    5858    }
    5959
    60   mapselector=new MapSelector(nml, "", "Nodeshapes", false);
     60  mapselector=new MapSelector(n_nml, s_nml, "", "Nodeshapes", false, true, NUM);
    6161  mapselector->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &EpsWin::newMapWinNeeded));
    6262
     
    105105}
    106106
    107 void EpsWin::registerNewNodeMap(std::string newmapname)
     107void EpsWin::registerNewNodeMap(std::string newmapname, MapValue::Type type)
    108108{
    109     mapselector->append_text((Glib::ustring)newmapname);
     109    mapselector->append_text((Glib::ustring)newmapname, type);
    110110}
  • eps_win.h

    r198 r201  
    2525#include <libgnomecanvasmm.h>
    2626#include <libgnomecanvasmm/polygon.h>
     27#include "map_value.h"
    2728
    2829///Graph visualization setup window.
     
    6263  ///\param nml nodemap list
    6364  ///\param mw the owner \ref NoteBookTab (\ref mytab)
    64   EpsWin(const std::string& title, std::vector<std::string>);
     65  EpsWin(const std::string& title, std::vector<std::string>, std::vector<std::string>);
    6566
    6667  ///Deregistrates \ref EpsWin in its \ref NoteBookTab (\ref mytab)
     
    103104  ///\param new_name
    104105  ///name of new map
    105   void registerNewNodeMap(std::string new_name);
     106  void registerNewNodeMap(std::string new_name, MapValue::Type type);
    106107};
    107108
  • gdc-broken_edge.cc

    r194 r201  
    3737{
    3838  MapStorage& ms = *canvas.mytab.mapstorage;
    39   XY center(ms.arrow_pos[edge]);
     39  XY center(ms.getArrowCoords(edge));
    4040  XY unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
    4141
     
    9090
    9191  //calculating coordinates of the direction indicator arrow
    92   XY head(ms.coords[ms.graph.target(edge)]);
    93   XY center(ms.arrow_pos[edge]);
     92  XY head(ms.getNodeCoords(ms.graph.target(edge)));
     93  XY center(ms.getArrowCoords(edge));
    9494
    9595  XY unit_vector_in_dir(head-center);
     
    108108  Node source = ms.graph.source(edge);
    109109  Node target = ms.graph.target(edge);
    110   points.push_back(Gnome::Art::Point(ms.coords[source].x,
    111         ms.coords[source].y));
    112   points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x,
    113         ms.arrow_pos[edge].y));
    114   points.push_back(Gnome::Art::Point(ms.coords[target].x,
    115         ms.coords[target].y));
     110  points.push_back(Gnome::Art::Point(ms.getNodeCoords(source).x,
     111        ms.getNodeCoords(source).y));
     112  points.push_back(Gnome::Art::Point(ms.getArrowCoords(edge).x,
     113        ms.getArrowCoords(edge).y));
     114  points.push_back(Gnome::Art::Point(ms.getNodeCoords(target).x,
     115        ms.getNodeCoords(target).y));
    116116  line.property_points().set_value(points);
    117117}
     
    153153        Gnome::Canvas::Points points_new;
    154154
    155         canvas.mytab.mapstorage->arrow_pos.set(edge, canvas.mytab.mapstorage->arrow_pos[edge] + XY(dx, dy));
     155        canvas.mytab.mapstorage->setArrowCoords(edge, canvas.mytab.mapstorage->getArrowCoords(edge) + XY(dx, dy));
    156156
    157157        draw();
    158         canvas.textReposition(canvas.mytab.mapstorage->arrow_pos[edge]);
     158        canvas.textReposition(canvas.mytab.mapstorage->getArrowCoords(edge));
    159159
    160160        clicked_x=e->motion.x;
     
    200200
    201201  Node node = ms.graph.source(edge);
    202   XY center = (ms.coords[node] + ms.arrow_pos[edge]) / 2.0;
    203 
    204   XY unit_vector_in_dir(rot90(center - ms.arrow_pos[edge]));
     202  XY center = (ms.getNodeCoords(node) + ms.getArrowCoords(edge)) / 2.0;
     203
     204  XY unit_vector_in_dir(rot90(center - ms.getArrowCoords(edge)));
    205205  double length = sqrt(unit_vector_in_dir.normSquare());
    206206  unit_vector_in_dir /= length;
     
    209209
    210210  double radius =
    211     sqrt((ms.arrow_pos[edge] - ms.coords[node]).normSquare()) / 2.0;
     211    sqrt((ms.getArrowCoords(edge) - ms.getNodeCoords(node)).normSquare()) / 2.0;
    212212
    213213  XY p1 = center + XY(-radius,  radius);
     
    250250      if(isbutton)
    251251      {
    252         canvas.mytab.mapstorage->arrow_pos.set(edge, XY(e->motion.x, e->motion.y));
     252        canvas.mytab.mapstorage->setArrowCoords(edge, XY(e->motion.x, e->motion.y));
    253253
    254254        draw();
    255         canvas.textReposition(canvas.mytab.mapstorage->arrow_pos[edge]);
     255        canvas.textReposition(canvas.mytab.mapstorage->getArrowCoords(edge));
    256256      }
    257257    default: break;
  • graph-displayer.cc

    r194 r201  
    9696//     }
    9797  if(argc>=2)
     98  {
     99    for(int i=1;i<argc;i++)
    98100    {
    99       for(int i=1;i<argc;i++)
    100         {
    101           if(Glib::file_test(argv[i], Glib::FILE_TEST_IS_REGULAR))
    102             {
    103               mytab.readFile(argv[i]);
    104             }
    105         }
     101      if(Glib::file_test(argv[i], Glib::FILE_TEST_IS_REGULAR))
     102      {
     103        mytab.readFile(argv[i]);
     104      }
    106105    }
     106  }
    107107  else
    108108    {
  • graph_displayer_canvas-edge.cc

    r194 r201  
    2626int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
    2727{
     28  MapStorage& ms = *mytab.mapstorage;
    2829  double min, max;
    2930
    3031  min=edge_property_defaults[E_WIDTH];
    3132  max=edge_property_defaults[E_WIDTH];
    32   Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_WIDTH]);
    33  
    34   if(edge==INVALID)
    35     {
    36       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    37         {
    38           double v=fabs(actual_map[i]);
    39           int w;
    40           if(min==max)
    41             {
    42               w=(int)(edge_property_defaults[E_WIDTH]);
    43             }
    44           else
    45             {
    46               w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
    47             }
    48           if(zoomtrack)
    49             {
    50               double actual_ppu=get_pixels_per_unit();
    51               w=(int)(w/actual_ppu*fixed_zoom_factor);
    52             }
    53           edgesmap[i]->setLineWidth(w);
    54         }
    55     }
    56   else
    57     {
    58       int w=(int)actual_map[edge];
    59       if(w>=0)
    60         {
    61           edgesmap[edge]->setLineWidth(w);
    62         }
    63     }
     33  Graph::EdgeMap<double> actual_map(ms.graph,edge_property_defaults[E_WIDTH]);
     34
     35  if(edge==INVALID)
     36  {
     37    for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     38    {
     39      double v=fabs(actual_map[i]);
     40      int w;
     41      if(min==max)
     42      {
     43        w=(int)(edge_property_defaults[E_WIDTH]);
     44      }
     45      else
     46      {
     47        w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
     48      }
     49      if(zoomtrack)
     50      {
     51        double actual_ppu=get_pixels_per_unit();
     52        w=(int)(w/actual_ppu*fixed_zoom_factor);
     53      }
     54      edgesmap[i]->setLineWidth(w);
     55    }
     56  }
     57  else
     58  {
     59    int w=(int)actual_map[edge];
     60    if(w>=0)
     61    {
     62      edgesmap[edge]->setLineWidth(w);
     63    }
     64  }
    6465  return 0;
    6566}
     
    6869int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
    6970{
    70   Graph::EdgeMap<double> * actual_map;
     71  MapStorage& ms = *mytab.mapstorage;
    7172  double min, max;
    7273
    73   min=(mytab.mapstorage)->minOfEdgeMap(mapname);
    74   max=(mytab.mapstorage)->maxOfEdgeMap(mapname);
    75   actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];
    76 
    77   if(edge==INVALID)
    78     {
    79       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    80         {
    81           double v=(*actual_map)[i];
    82           int w;
    83           if(autoscale)
    84             {
    85               if(min==max)
    86                 {
    87                   w=(int)(edge_property_defaults[E_WIDTH]);
    88                 }
    89               else
    90                 {
    91                   w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
    92                 }
    93             }
    94           else
    95             {
    96               w=(int)(v*edge_width);
    97             }
    98           if(w<0)
    99             {
    100               edgesmap[i]->hide();
    101             }
    102           else
    103             {
    104               edgesmap[i]->show();
    105               if(w<minimum_edge_width)
    106                 {
    107                   w=minimum_edge_width;
    108                 }
    109               if(zoomtrack)
    110                 {
    111                   double actual_ppu=get_pixels_per_unit();
    112                   w=(int)(w/actual_ppu*fixed_zoom_factor);
    113                 }
    114               edgesmap[i]->setLineWidth(w);
    115             }
    116         }
    117     }
    118   else
    119     {
    120       int w=(int)(*actual_map)[edge];
    121       if(w>=0)
    122         {
    123           edgesmap[edge]->setLineWidth(w);
    124         }
    125     }
     74  {
     75    EdgeIt e(ms.graph);
     76    min = max = ms.get(mapname, e);
     77    for (; e != INVALID; ++e)
     78    {
     79      if (static_cast<double>(ms.get(mapname, e)) > max)
     80        max = ms.get(mapname, e);
     81      if (static_cast<double>(ms.get(mapname, e)) < min)
     82        min = ms.get(mapname, e);
     83    }
     84  }
     85
     86  if(edge==INVALID)
     87  {
     88    for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     89    {
     90      double v=ms.get(mapname, i);
     91      int w;
     92      if(autoscale)
     93      {
     94        if(min==max)
     95        {
     96          w=(int)(edge_property_defaults[E_WIDTH]);
     97        }
     98        else
     99        {
     100          w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
     101        }
     102      }
     103      else
     104      {
     105        w=(int)(v*edge_width);
     106      }
     107      if(w<0)
     108      {
     109        edgesmap[i]->hide();
     110      }
     111      else
     112      {
     113        edgesmap[i]->show();
     114        if(w<minimum_edge_width)
     115        {
     116          w=minimum_edge_width;
     117        }
     118        if(zoomtrack)
     119        {
     120          double actual_ppu=get_pixels_per_unit();
     121          w=(int)(w/actual_ppu*fixed_zoom_factor);
     122        }
     123        edgesmap[i]->setLineWidth(w);
     124      }
     125    }
     126  }
     127  else
     128  {
     129    int w=(int)ms.get(mapname, edge);
     130    if(w>=0)
     131    {
     132      edgesmap[edge]->setLineWidth(w);
     133    }
     134  }
    126135  return 0;
    127136};
     
    129138int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
    130139
     140  MapStorage& ms = *mytab.mapstorage;
    131141
    132142  //function maps the range of the maximum and
    133143  //the minimum of the nodemap to the range of
    134144  //green in RGB
    135   Graph::EdgeMap<double> * actual_map;
    136   actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];
    137145
    138146  double max, min;
    139147
    140   max=(mytab.mapstorage)->maxOfEdgeMap(mapname);
    141   min=(mytab.mapstorage)->minOfEdgeMap(mapname);
    142 
    143   if(edge==INVALID)
    144     {
    145       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     148  {
     149    EdgeIt e(ms.graph);
     150    min = max = ms.get(mapname, e);
     151    for (; e != INVALID; ++e)
     152    {
     153      if (static_cast<double>(ms.get(mapname, e)) > max)
     154        max = ms.get(mapname, e);
     155      if (static_cast<double>(ms.get(mapname, e)) < min)
     156        min = ms.get(mapname, e);
     157    }
     158  }
     159
     160  if(edge==INVALID)
     161    {
     162      for (EdgeIt i(ms.graph); i!=INVALID; ++i)
    146163        {
    147           double w=(*actual_map)[i];
     164          double w=ms.get(mapname, i);
    148165
    149166          Gdk::Color color;
     
    163180      Gdk::Color color;
    164181
    165       double w=(*actual_map)[edge];
     182      double w=ms.get(mapname, edge);
    166183
    167184      if(max!=min)
     
    181198int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
    182199
     200  MapStorage& ms = *mytab.mapstorage;
    183201
    184202  //function maps the range of the maximum and
    185203  //the minimum of the nodemap to the range of
    186204  //green in RGB
    187   Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_COLOR]);
     205  Graph::EdgeMap<double> actual_map(ms.graph,edge_property_defaults[E_COLOR]);
    188206
    189207  double max, min;
     
    193211
    194212  if(edge==INVALID)
    195     {
    196       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    197         {
    198           double w=actual_map[i];
    199 
    200           Gdk::Color color;
    201           if(max!=min)
    202             {
    203               color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    204             }
    205           else
    206             {
    207               color.set_rgb_p (0, 100, 0);
    208             }
    209           edgesmap[i]->setFillColor(color);
    210         }
    211     }
    212   else
    213     {
     213  {
     214    for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     215    {
     216      double w=actual_map[i];
     217
    214218      Gdk::Color color;
    215 
    216       double w=actual_map[edge];
    217 
    218219      if(max!=min)
    219         {
    220           color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    221         }
    222       else
    223         {
    224           color.set_rgb_p (0, 100, 0);
    225         }
    226 
    227       edgesmap[edge]->setFillColor(color);
    228     }
     220      {
     221        color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
     222      }
     223      else
     224      {
     225        color.set_rgb_p (0, 100, 0);
     226      }
     227      edgesmap[i]->setFillColor(color);
     228    }
     229  }
     230  else
     231  {
     232    Gdk::Color color;
     233
     234    double w=actual_map[edge];
     235
     236    if(max!=min)
     237    {
     238      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
     239    }
     240    else
     241    {
     242      color.set_rgb_p (0, 100, 0);
     243    }
     244
     245    edgesmap[edge]->setFillColor(color);
     246  }
    229247  return 0;
    230248};
     
    232250int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
    233251{
     252  MapStorage& ms = *mytab.mapstorage;
     253
    234254  //the number in the map will be written on the edge
    235255  //EXCEPT when the name of the map is Default, because
    236256  //in that case empty string will be written, because
    237257  //that is the deleter map
    238  
    239   if(edge==INVALID)
    240     {
    241       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    242         {
    243           edgemap_to_edit=mapname;
    244           double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[i];
    245          
    246           std::ostringstream ostr;
    247           ostr << number;
    248          
    249           edgetextmap[i]->property_text().set_value(ostr.str());
    250         }
    251 
    252     }
    253   else
    254     {
    255           double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[edge];
    256 
    257           std::ostringstream ostr;
    258           ostr << number;
    259          
    260           edgetextmap[edge]->property_text().set_value(ostr.str());
    261     }
    262 
    263   return 0;
    264 
     258
     259  if(edge==INVALID)
     260  {
     261    for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     262    {
     263      edgemap_to_edit=mapname;
     264
     265      edgetextmap[i]->property_text().set_value(
     266          static_cast<std::string>(ms.get(mapname, i)));
     267    }
     268
     269  }
     270  else
     271  {
     272    edgetextmap[edge]->property_text().set_value(
     273        static_cast<std::string>(ms.get(mapname, edge)));
     274  }
     275
     276  return 0;
    265277};
    266278
    267279int GraphDisplayerCanvas::resetEdgeText (Edge edge)
    268280{
     281  MapStorage& ms = *mytab.mapstorage;
     282
    269283  //the number in the map will be written on the edge
    270284  //EXCEPT when the name of the map is Default, because
    271285  //in that case empty string will be written, because
    272286  //that is the deleter map
    273  
    274   if(edge==INVALID)
    275     {
    276       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    277         {
    278           edgemap_to_edit="";
    279           edgetextmap[i]->property_text().set_value("");
    280         }
    281 
    282     }
    283   else
    284     {
    285       edgetextmap[edge]->property_text().set_value("");
    286     }
    287 
    288   return 0;
    289 
    290 };
     287
     288  if(edge==INVALID)
     289  {
     290    for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     291    {
     292      edgemap_to_edit="";
     293      edgetextmap[i]->property_text().set_value("");
     294    }
     295  }
     296  else
     297  {
     298    edgetextmap[edge]->property_text().set_value("");
     299  }
     300
     301  return 0;
     302};
  • graph_displayer_canvas-event.cc

    r200 r201  
    3434{
    3535  if(actual_tool!=newtool)
    36     {
    37 
    38       actual_handler.disconnect();
    39 
    40       switch(actual_tool)
    41         {
    42         case CREATE_EDGE:
    43           {
    44             GdkEvent * generated=new GdkEvent();
    45             generated->type=GDK_BUTTON_RELEASE;
    46             generated->button.button=3;
    47             createEdgeEventHandler(generated);     
    48             break;
    49           }
    50         case MAP_EDIT:
    51           {
    52             break;
    53           }
    54         default:
    55           break;
    56         }
    57 
    58       active_item=NULL;
    59       target_item=NULL;
    60       active_edge=INVALID;     
    61       active_node=INVALID;     
    62 
    63 
    64       actual_tool=newtool;
    65  
    66       switch(newtool)
    67         {
    68         case MOVE:
    69           actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    70           break;
    71 
    72         case CREATE_NODE:
    73           actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
    74           break;
    75 
    76         case CREATE_EDGE:
    77           actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
    78           break;
    79 
    80         case ERASER:
    81           actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
    82           break;
    83 
    84         case MAP_EDIT:
    85           grab_focus();
    86           actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
    87           break;
    88 
    89         default:
    90           break;
    91         }
    92     }
     36  {
     37
     38    actual_handler.disconnect();
     39
     40    switch(actual_tool)
     41    {
     42      case CREATE_EDGE:
     43        {
     44          GdkEvent * generated=new GdkEvent();
     45          generated->type=GDK_BUTTON_RELEASE;
     46          generated->button.button=3;
     47          createEdgeEventHandler(generated);     
     48          break;
     49        }
     50      case MAP_EDIT:
     51        {
     52          break;
     53        }
     54      default:
     55        break;
     56    }
     57
     58    active_item=NULL;
     59    target_item=NULL;
     60    active_edge=INVALID;       
     61    active_node=INVALID;       
     62
     63
     64    actual_tool=newtool;
     65
     66    switch(newtool)
     67    {
     68      case MOVE:
     69        actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
     70        break;
     71
     72      case CREATE_NODE:
     73        actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
     74        break;
     75
     76      case CREATE_EDGE:
     77        actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
     78        break;
     79
     80      case ERASER:
     81        actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
     82        break;
     83
     84      case MAP_EDIT:
     85        grab_focus();
     86        actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false);
     87        break;
     88
     89      default:
     90        break;
     91    }
     92  }
    9393}
    9494
     
    139139bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
    140140{
     141  MapStorage& ms = *mytab.mapstorage;
     142
    141143  static Gnome::Canvas::Text *coord_text = 0;
    142144  switch(e->type)
    143     {
     145  {
    144146    case GDK_BUTTON_PRESS:
    145147      //we mark the location of the event to be able to calculate parameters of dragging
    146148      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    147      
     149
    148150      active_item=(get_item_at(clicked_x, clicked_y));
    149151      active_node=INVALID;
    150       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    151         {
    152           if(nodesmap[i]==active_item)
    153             {
    154               active_node=i;
    155             }
    156         }
     152      for (NodeIt i(ms.graph); i!=INVALID; ++i)
     153      {
     154        if(nodesmap[i]==active_item)
     155        {
     156          active_node=i;
     157        }
     158      }
    157159      isbutton=e->button.button;
    158160      break;
    159161    case GDK_BUTTON_RELEASE:
    160162      if (coord_text)
    161         {
    162           delete coord_text;
    163           coord_text = 0;
    164         }
     163      {
     164        delete coord_text;
     165        coord_text = 0;
     166      }
    165167      isbutton=0;
    166168      active_item=NULL;
     
    170172      //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
    171173      if(active_node!=INVALID)
    172         {
    173           (mytab.mapstorage)->modified = true;
    174          
    175           //new coordinates will be the old values,
    176           //because the item will be moved to the
    177           //new coordinate therefore the new movement
    178           //has to be calculated from here
    179          
    180           double new_x, new_y;
    181          
    182           window_to_world (e->motion.x, e->motion.y, new_x, new_y);
    183          
    184           double dx=new_x-clicked_x;
    185           double dy=new_y-clicked_y;
    186          
    187           moveNode(dx, dy);
    188 
    189           clicked_x=new_x;
    190           clicked_y=new_y;
    191 
    192           // reposition the coordinates text
    193           std::ostringstream ostr;
    194           ostr << "(" <<
    195             (mytab.mapstorage)->coords[active_node].x << ", " <<
    196             (mytab.mapstorage)->coords[active_node].y << ")";
    197           double radius =
    198             (nodesmap[active_node]->property_x2().get_value() -
    199              nodesmap[active_node]->property_x1().get_value()) / 2.0;
    200           if (coord_text)
    201             {
    202               coord_text->property_text().set_value(ostr.str());
    203               coord_text->property_x().set_value((mytab.mapstorage)->coords[active_node].x +
    204                                                 radius);
    205               coord_text->property_y().set_value((mytab.mapstorage)->coords[active_node].y -
    206                                                 radius);
    207             }
    208           else
    209             {
    210               coord_text = new Gnome::Canvas::Text(
    211                                                    displayed_graph,
    212                                                    (mytab.mapstorage)->coords[active_node].x + radius,
    213                                                    (mytab.mapstorage)->coords[active_node].y - radius,
    214                                                    ostr.str());
    215               coord_text->property_fill_color().set_value("black");
    216               coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
    217             }
    218 
    219 
    220         }
     174      {
     175        ms.setModified();
     176
     177        //new coordinates will be the old values,
     178        //because the item will be moved to the
     179        //new coordinate therefore the new movement
     180        //has to be calculated from here
     181
     182        double new_x, new_y;
     183
     184        window_to_world (e->motion.x, e->motion.y, new_x, new_y);
     185
     186        double dx=new_x-clicked_x;
     187        double dy=new_y-clicked_y;
     188
     189        moveNode(dx, dy);
     190
     191        clicked_x=new_x;
     192        clicked_y=new_y;
     193
     194        // reposition the coordinates text
     195        std::ostringstream ostr;
     196        ostr << "(" <<
     197          ms.getNodeCoords(active_node).x << ", " <<
     198          ms.getNodeCoords(active_node).y << ")";
     199        double radius =
     200          (nodesmap[active_node]->property_x2().get_value() -
     201           nodesmap[active_node]->property_x1().get_value()) / 2.0;
     202        if (coord_text)
     203        {
     204          coord_text->property_text().set_value(ostr.str());
     205          coord_text->property_x().set_value(
     206              ms.getNodeCoords(active_node).x + radius);
     207          coord_text->property_y().set_value(
     208              ms.getNodeCoords(active_node).y - radius);
     209        }
     210        else
     211        {
     212          coord_text = new Gnome::Canvas::Text(
     213              displayed_graph,
     214              ms.getNodeCoords(active_node).x + radius,
     215              ms.getNodeCoords(active_node).y - radius,
     216              ostr.str());
     217          coord_text->property_fill_color().set_value("black");
     218          coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
     219        }
     220
     221
     222      }
    221223    default: break;
    222     }
    223 
    224 return false;
     224  }
     225
     226  return false;
    225227}
    226228
     
    228230{
    229231  switch(move_code)
    230     {
     232  {
    231233    case 1:
    232234      return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
     
    237239    case 3:
    238240      {
    239         //////////////////////////////////////////////////////////////////////////////////////////////////////
    240         /////////// keeps shape-with scalar multiplication - version 2.
    241         //////////////////////////////////////////////////////////////////////////////////////////////////////
    242 
    243         //old vector from one to the other node - a
    244         XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
    245         //new vector from one to the other node - b
    246         XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
    247 
    248         double absa=sqrt(a_v.normSquare());
    249         double absb=sqrt(b_v.normSquare());
    250 
    251         if ((absa == 0.0) || (absb == 0.0))
    252           {
    253             return old_arrow_pos;
    254           }
    255         else
    256           {
    257             //old vector from one node to the breakpoint - c
    258             XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
    259 
    260             //unit vector with the same direction to a_v
    261             XY a_v_u(a_v.x/absa,a_v.y/absa);
    262 
    263             //normal vector of unit vector with the same direction to a_v
    264             XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
    265 
    266             //unit vector with the same direction to b_v
    267             XY b_v_u(b_v.x/absb,b_v.y/absb);
    268 
    269             //normal vector of unit vector with the same direction to b_v
    270             XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
    271 
    272             //vector c in a_v_u and a_v_u_n co-ordinate system
    273             XY c_a(c_v*a_v_u,c_v*a_v_u_n);
    274 
    275             //new vector from one node to the breakpoint - d - we have to calculate this one
    276             XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
    277 
    278             return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
    279           }
    280         break;
     241        //////////////////////////////////////////////////////////////////////////////////////////////////////
     242        /////////// keeps shape-with scalar multiplication - version 2.
     243        //////////////////////////////////////////////////////////////////////////////////////////////////////
     244
     245        //old vector from one to the other node - a
     246        XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
     247        //new vector from one to the other node - b
     248        XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
     249
     250        double absa=sqrt(a_v.normSquare());
     251        double absb=sqrt(b_v.normSquare());
     252
     253        if ((absa == 0.0) || (absb == 0.0))
     254        {
     255          return old_arrow_pos;
     256        }
     257        else
     258        {
     259          //old vector from one node to the breakpoint - c
     260          XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
     261
     262          //unit vector with the same direction to a_v
     263          XY a_v_u(a_v.x/absa,a_v.y/absa);
     264
     265          //normal vector of unit vector with the same direction to a_v
     266          XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
     267
     268          //unit vector with the same direction to b_v
     269          XY b_v_u(b_v.x/absb,b_v.y/absb);
     270
     271          //normal vector of unit vector with the same direction to b_v
     272          XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
     273
     274          //vector c in a_v_u and a_v_u_n co-ordinate system
     275          XY c_a(c_v*a_v_u,c_v*a_v_u_n);
     276
     277          //new vector from one node to the breakpoint - d - we have to calculate this one
     278          XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
     279
     280          return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
     281        }
     282        break;
    281283      }
    282284    default:
    283285      break;
    284     }
     286  }
    285287}
    286288
     
    288290bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
    289291{
     292  MapStorage& ms = *mytab.mapstorage;
     293
    290294  switch(e->type)
    291295  {
     
    302306
    303307    case GDK_BUTTON_RELEASE:
    304       (mytab.mapstorage)->modified = true;
     308      ms.setModified();
    305309
    306310      is_drawn=true;
     
    308312      isbutton=1;
    309313
    310       active_node=(mytab.mapstorage)->graph.addNode();
    311 
    312       //initiating values corresponding to new node in maps
    313 
    314314      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    315315
    316       // update coordinates
    317       (mytab.mapstorage)->coords.set(active_node, XY(clicked_x, clicked_y));
    318 
    319       // update all other maps
    320       for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    321           (mytab.mapstorage)->nodemap_storage.begin(); it !=
    322           (mytab.mapstorage)->nodemap_storage.end(); ++it)
    323       {
    324         if ((it->first != "coordinates_x") &&
    325             (it->first != "coordinates_y"))
    326         {
    327           (*(it->second))[active_node] =
    328             (mytab.mapstorage)->nodemap_default[it->first];
    329         }
    330       }
    331       // increment the id map's default value
    332       (mytab.mapstorage)->nodemap_default["label"] += 1.0;
     316      active_node = ms.addNode(XY(clicked_x, clicked_y));
    333317
    334318      nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
     
    349333      nodetextmap[active_node]->raise_to_top();
    350334
    351 //       mapwin.updateNode(active_node);
     335      //       mapwin.updateNode(active_node);
    352336      propertyUpdate(active_node);
    353337
     
    365349bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
    366350{
     351  MapStorage& ms = *mytab.mapstorage;
     352
    367353  switch(e->type)
    368354  {
     
    380366          active_item=(get_item_at(clicked_x, clicked_y));
    381367          active_node=INVALID;
    382           for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     368          for (NodeIt i(ms.graph); i!=INVALID; ++i)
    383369          {
    384370            if(nodesmap[i]==active_item)
     
    409395          target_item=(get_item_at(clicked_x, clicked_y));
    410396          Node target_node=INVALID;
    411           for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     397          for (NodeIt i(ms.graph); i!=INVALID; ++i)
    412398          {
    413399            if(nodesmap[i]==target_item)
     
    419405          if(target_node!=INVALID)
    420406          {
    421             (mytab.mapstorage)->modified = true;
     407            ms.setModified();
    422408
    423409            *(nodesmap[target_node]) <<
    424410              Gnome::Canvas::Properties::fill_color("red");
    425411
    426             //creating new edge
    427             active_edge=(mytab.mapstorage)->graph.addEdge(active_node,
    428                 target_node);
    429 
    430             // update maps
    431             for (std::map<std::string,
    432                 Graph::EdgeMap<double>*>::const_iterator it =
    433                 (mytab.mapstorage)->edgemap_storage.begin(); it !=
    434                 (mytab.mapstorage)->edgemap_storage.end(); ++it)
    435             {
    436               (*(it->second))[active_edge] =
    437                 (mytab.mapstorage)->edgemap_default[it->first];
    438             }
    439             // increment the id map's default value
    440             (mytab.mapstorage)->edgemap_default["label"] += 1.0;
     412            active_edge = ms.addEdge(active_node, target_node);
    441413
    442414            if(target_node!=active_node)               
    443415            {
    444               // set the coordinates of the arrow on the new edge
    445               MapStorage& ms = *mytab.mapstorage;
    446               ms.arrow_pos.set(active_edge,
    447                   (ms.coords[ms.graph.source(active_edge)] +
    448                    ms.coords[ms.graph.target(active_edge)])/ 2.0);
    449 
    450               //drawing new edge
    451               edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
    452                   *this);
     416              edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, *this);
    453417            }
    454418            else
    455419            {
    456               // set the coordinates of the arrow on the new edge
    457               MapStorage& ms = *mytab.mapstorage;
    458               ms.arrow_pos.set(active_edge,
    459                   (ms.coords[ms.graph.source(active_edge)] +
    460                    XY(0.0, 80.0)));
    461 
    462               //drawing new edge
    463               edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge,
    464                   *this);
     420              edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, *this);
    465421            }
    466422
    467423            //initializing edge-text as well, to empty string
    468             XY text_pos=mytab.mapstorage->arrow_pos[active_edge];
     424            XY text_pos=ms.getArrowCoords(active_edge);
    469425            text_pos+=(XY(10,10));
    470426
     
    495451        if(active_item)
    496452        {
    497           propertyUpdate(active_node,N_COLOR);
     453          propertyUpdate(active_node,N_COLOR);
    498454          active_item=NULL;
    499455        }
    500456        if(target_item)
    501457        {
    502           propertyUpdate((mytab.mapstorage)->graph.target(active_edge),N_COLOR);
     458          propertyUpdate(ms.graph.target(active_edge),N_COLOR);
    503459          target_item=NULL;
    504460        }
     
    515471bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
    516472{
     473  MapStorage& ms = *mytab.mapstorage;
     474
    517475  switch(e->type)
    518     {
     476  {
    519477    case GDK_BUTTON_PRESS:
    520478      //finding the clicked items
     
    524482      active_edge=INVALID;
    525483      //was it a node?
    526       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    527         {
    528           if(nodesmap[i]==active_item)
    529             {
    530               active_node=i;
    531             }
    532         }
     484      for (NodeIt i(ms.graph); i!=INVALID; ++i)
     485      {
     486        if(nodesmap[i]==active_item)
     487        {
     488          active_node=i;
     489        }
     490      }
    533491      //or was it an edge?
    534492      if(active_node==INVALID)
    535         {
    536           for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    537             {
    538               if(edgesmap[i]->getLine()==active_item)
    539                 {
    540                   active_edge=i;
    541                 }
    542             }
    543         }
     493      {
     494        for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     495        {
     496          if(edgesmap[i]->getLine()==active_item)
     497          {
     498            active_edge=i;
     499          }
     500        }
     501      }
    544502
    545503      // return if the clicked object is neither an edge nor a node
    546504      if (active_edge == INVALID) return false;
    547      
     505
    548506      //recolor activated item
    549507      if(active_item)
    550         {
    551           *active_item << Gnome::Canvas::Properties::fill_color("red");
    552         }
     508      {
     509        *active_item << Gnome::Canvas::Properties::fill_color("red");
     510      }
    553511      break;
    554512
     
    556514      window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    557515      if(active_item)
    558         {
    559           //the cursor was not moved since pressing it
    560           if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
    561             {
    562               //a node was found
    563               if(active_node!=INVALID)
    564                 {
    565                   (mytab.mapstorage)->modified = true;
    566 
    567                   std::set<Graph::Edge> edges_to_delete;
    568 
    569                   for(OutEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e)
    570                     {
    571                       edges_to_delete.insert(e);
    572                     }
    573                  
    574                   for(InEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e)
    575                     {
    576                       edges_to_delete.insert(e);
    577                     }
    578                  
    579                   //deleting collected edges
    580                   for(std::set<Graph::Edge>::iterator
    581                         edge_set_it=edges_to_delete.begin();
    582                       edge_set_it!=edges_to_delete.end();
    583                       ++edge_set_it)
    584                     {
    585                       deleteItem(*edge_set_it);
    586                     }
    587                   deleteItem(active_node);
    588                 }
    589               //a simple edge was chosen
    590               else if (active_edge != INVALID)
    591                 {
    592                   deleteItem(active_edge);
    593                 }
    594             }
    595           //pointer was moved, deletion is cancelled
    596           else
    597             {
    598               if(active_node!=INVALID)
    599                 {
    600                   *active_item << Gnome::Canvas::Properties::fill_color("blue");
    601                 }
    602               else if (active_edge != INVALID)
    603                 {
    604                   *active_item << Gnome::Canvas::Properties::fill_color("green");
    605                 }
    606             }
    607         }
     516      {
     517        //the cursor was not moved since pressing it
     518        if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
     519        {
     520          //a node was found
     521          if(active_node!=INVALID)
     522          {
     523            ms.setModified();
     524
     525            std::set<Graph::Edge> edges_to_delete;
     526
     527            for(OutEdgeIt e(ms.graph,active_node);e!=INVALID;++e)
     528            {
     529              edges_to_delete.insert(e);
     530            }
     531
     532            for(InEdgeIt e(ms.graph,active_node);e!=INVALID;++e)
     533            {
     534              edges_to_delete.insert(e);
     535            }
     536
     537            //deleting collected edges
     538            for(std::set<Graph::Edge>::iterator
     539                edge_set_it=edges_to_delete.begin();
     540                edge_set_it!=edges_to_delete.end();
     541                ++edge_set_it)
     542            {
     543              deleteItem(*edge_set_it);
     544            }
     545            deleteItem(active_node);
     546          }
     547          //a simple edge was chosen
     548          else if (active_edge != INVALID)
     549          {
     550            deleteItem(active_edge);
     551          }
     552        }
     553        //pointer was moved, deletion is cancelled
     554        else
     555        {
     556          if(active_node!=INVALID)
     557          {
     558            *active_item << Gnome::Canvas::Properties::fill_color("blue");
     559          }
     560          else if (active_edge != INVALID)
     561          {
     562            *active_item << Gnome::Canvas::Properties::fill_color("green");
     563          }
     564        }
     565      }
    608566      //reseting datas
    609567      active_item=NULL;
     
    617575    default:
    618576      break;
    619     }
     577  }
    620578  return false;
    621579}
     
    623581bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e)
    624582{
     583  MapStorage& ms = *mytab.mapstorage;
     584
    625585  if(actual_tool==MAP_EDIT)
    626     {
    627       switch(e->type)
    628         {
    629         case GDK_BUTTON_PRESS:
    630           {
    631             //for determine, whether it was an edge
    632             Edge clicked_edge=INVALID;
    633             //for determine, whether it was a node
    634             Node clicked_node=INVALID;
    635 
    636             window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
    637             active_item=(get_item_at(clicked_x, clicked_y));
    638 
    639             //find the activated item between text of nodes
    640             for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    641               {
    642                 //at the same time only one can be active
    643                 if(nodetextmap[i]==active_item)
    644                   {
    645                     clicked_node=i;
    646                   }
    647               }
    648 
    649             //if there was not, search for it between nodes
    650             if(clicked_node==INVALID)
    651               {
    652                 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    653                   {
    654                     //at the same time only one can be active
    655                     if(nodesmap[i]==active_item)
    656                       {
    657                         clicked_node=i;
    658                       }
    659                   }
    660               }
    661 
    662             if(clicked_node==INVALID)
    663               {
    664                 //find the activated item between texts
    665                 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    666                   {
    667                     //at the same time only one can be active
    668                     if(edgetextmap[i]==active_item)
    669                       {
    670                         clicked_edge=i;
    671                       }
    672                   }
    673 
    674                 //if it was not between texts, search for it between edges
    675                 if(clicked_edge==INVALID)
    676                   {
    677                     for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    678                       {
    679                         //at the same time only one can be active
    680                         if((edgesmap[i]->getLine())==active_item)
    681                           {
    682                             clicked_edge=i;
    683                           }
    684                       }
    685                   }
    686               }
    687 
    688             //if it was really a node...
    689             if(clicked_node!=INVALID)
    690               {
    691                 // the id map is not editable
    692                 if (nodemap_to_edit == "label") return 0;
    693 
    694                 //and there is activated map
    695                 if(nodetextmap[clicked_node]->property_text().get_value()!="")
    696                   {
    697                     //activate the general variable for it
    698                     active_node=clicked_node;
    699 
    700                     //create a dialog
    701                     Gtk::Dialog dialog("Edit value", true);
    702                     dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    703                     dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
    704                     Gtk::VBox* vbox = dialog.get_vbox();
    705                     Gtk::SpinButton spin(0.0, 4);
    706                     spin.set_increments(1.0, 10.0);
    707                     spin.set_range(-1000000.0, 1000000.0);
    708                     spin.set_numeric(true);
    709                     spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str()));
    710                     vbox->add(spin);
    711                     spin.show();
    712                     switch (dialog.run())
    713                       {
    714                       case Gtk::RESPONSE_NONE:
    715                       case Gtk::RESPONSE_CANCEL:
    716                         break;
    717                       case Gtk::RESPONSE_ACCEPT:
    718                         double new_value = spin.get_value();
    719                         (*(mytab.mapstorage)->nodemap_storage[nodemap_to_edit])[active_node] =
    720                           new_value;
    721                         std::ostringstream ostr;
    722                         ostr << new_value;
    723                         nodetextmap[active_node]->property_text().set_value(ostr.str());
    724                         //mapwin.updateNode(active_node);
    725                         //mapwin.updateNode(Node(INVALID));
    726                         propertyUpdate(Node(INVALID));
    727                       }
    728                   }
    729               }
    730             else
    731               //if it was really an edge...
    732               if(clicked_edge!=INVALID)
    733                 {
    734                   // the id map is not editable
    735                   if (edgemap_to_edit == "label") return 0;
    736 
    737                   //and there is activated map
    738                   if(edgetextmap[clicked_edge]->property_text().get_value()!="")
    739                     {
    740                       //activate the general variable for it
    741                       active_edge=clicked_edge;
    742 
    743                       //create a dialog
    744                       Gtk::Dialog dialog("Edit value", true);
    745                       dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    746                       dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
    747                       Gtk::VBox* vbox = dialog.get_vbox();
    748                       Gtk::SpinButton spin(0.0, 4);
    749                       spin.set_increments(1.0, 10.0);
    750                       spin.set_range(-1000000.0, 1000000.0);
    751                       spin.set_numeric(true);
    752                       spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str()));
    753                       vbox->add(spin);
    754                       spin.show();
    755                       switch (dialog.run())
    756                         {
    757                         case Gtk::RESPONSE_NONE:
    758                         case Gtk::RESPONSE_CANCEL:
    759                           break;
    760                         case Gtk::RESPONSE_ACCEPT:
    761                           double new_value = spin.get_value();
    762                           (*(mytab.mapstorage)->edgemap_storage[edgemap_to_edit])[active_edge] =
    763                             new_value;
    764                           std::ostringstream ostr;
    765                           ostr << new_value;
    766                           edgetextmap[active_edge]->property_text().set_value(
    767                                                                               ostr.str());
    768                           //mapwin.updateEdge(active_edge);
    769                           //                   mapwin.updateEdge(Edge(INVALID));
    770                           propertyUpdate(Edge(INVALID));
    771                         }
    772                     }
    773                 }
    774             break;
    775           }
    776         default:
    777           break;
    778         }
    779     }
     586  {
     587    switch(e->type)
     588    {
     589      case GDK_BUTTON_PRESS:
     590        {
     591          //for determine, whether it was an edge
     592          Edge clicked_edge=INVALID;
     593          //for determine, whether it was a node
     594          Node clicked_node=INVALID;
     595
     596          window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
     597          active_item=(get_item_at(clicked_x, clicked_y));
     598
     599          //find the activated item between text of nodes
     600          for (NodeIt i(ms.graph); i!=INVALID; ++i)
     601          {
     602            //at the same time only one can be active
     603            if(nodetextmap[i]==active_item)
     604            {
     605              clicked_node=i;
     606            }
     607          }
     608
     609          //if there was not, search for it between nodes
     610          if(clicked_node==INVALID)
     611          {
     612            for (NodeIt i(ms.graph); i!=INVALID; ++i)
     613            {
     614              //at the same time only one can be active
     615              if(nodesmap[i]==active_item)
     616              {
     617                clicked_node=i;
     618              }
     619            }
     620          }
     621
     622          if(clicked_node==INVALID)
     623          {
     624            //find the activated item between texts
     625            for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     626            {
     627              //at the same time only one can be active
     628              if(edgetextmap[i]==active_item)
     629              {
     630                clicked_edge=i;
     631              }
     632            }
     633
     634            //if it was not between texts, search for it between edges
     635            if(clicked_edge==INVALID)
     636            {
     637              for (EdgeIt i(ms.graph); i!=INVALID; ++i)
     638              {
     639                //at the same time only one can be active
     640                if((edgesmap[i]->getLine())==active_item)
     641                {
     642                  clicked_edge=i;
     643                }
     644              }
     645            }
     646          }
     647
     648          //if it was really a node...
     649          if(clicked_node!=INVALID)
     650          {
     651            // the id map is not editable
     652            if (nodemap_to_edit == "label") return 0;
     653
     654            //and there is activated map
     655            if(nodetextmap[clicked_node]->property_text().get_value()!="")
     656            {
     657              //activate the general variable for it
     658              active_node=clicked_node;
     659
     660              //create a dialog
     661              Gtk::Dialog dialog("Edit value", true);
     662              dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     663              dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
     664              Gtk::VBox* vbox = dialog.get_vbox();
     665
     666              /*
     667              Gtk::SpinButton spin(0.0, 4);
     668              spin.set_increments(1.0, 10.0);
     669              spin.set_range(-1000000.0, 1000000.0);
     670              spin.set_numeric(true);
     671              spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str()));
     672              vbox->add(spin);
     673              spin.show();
     674              */
     675              Gtk::Entry entry;
     676              entry.set_text(nodetextmap[active_node]->property_text().get_value());
     677              vbox->add(entry);
     678              entry.show();
     679
     680              switch (dialog.run())
     681              {
     682                case Gtk::RESPONSE_NONE:
     683                case Gtk::RESPONSE_CANCEL:
     684                  break;
     685                case Gtk::RESPONSE_ACCEPT:
     686                  switch (ms.getNodeMapElementType(nodemap_to_edit))
     687                  {
     688                    case MapValue::NUMERIC:
     689                      ms.set(nodemap_to_edit, active_node,
     690                          atof(entry.get_text().c_str()));
     691                      break;
     692                    case MapValue::STRING:
     693                      ms.set(nodemap_to_edit, active_node,
     694                          static_cast<std::string>(entry.get_text()));
     695                      break;
     696                  }
     697                  nodetextmap[active_node]->property_text().set_value(
     698                      static_cast<std::string>(ms.get(nodemap_to_edit, active_node)));
     699
     700                  //mapwin.updateNode(active_node);
     701                  //mapwin.updateNode(Node(INVALID));
     702                  propertyUpdate(Node(INVALID));
     703              }
     704            }
     705          }
     706          else
     707            //if it was really an edge...
     708            if(clicked_edge!=INVALID)
     709            {
     710              // the id map is not editable
     711              if (edgemap_to_edit == "label") return 0;
     712
     713              //and there is activated map
     714              if(edgetextmap[clicked_edge]->property_text().get_value()!="")
     715              {
     716                //activate the general variable for it
     717                active_edge=clicked_edge;
     718
     719                //create a dialog
     720                Gtk::Dialog dialog("Edit value", true);
     721                dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
     722                dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
     723                Gtk::VBox* vbox = dialog.get_vbox();
     724
     725                /*
     726                Gtk::SpinButton spin(0.0, 4);
     727                spin.set_increments(1.0, 10.0);
     728                spin.set_range(-1000000.0, 1000000.0);
     729                spin.set_numeric(true);
     730                spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str()));
     731                vbox->add(spin);
     732                spin.show();
     733                */
     734                Gtk::Entry entry;
     735                entry.set_text(edgetextmap[active_edge]->property_text().get_value());
     736                vbox->add(entry);
     737                entry.show();
     738
     739                std::cout << edgemap_to_edit << std::endl;
     740                switch (dialog.run())
     741                {
     742                  case Gtk::RESPONSE_NONE:
     743                  case Gtk::RESPONSE_CANCEL:
     744                    break;
     745                  case Gtk::RESPONSE_ACCEPT:
     746                    switch (ms.getEdgeMapElementType(edgemap_to_edit))
     747                    {
     748                      case MapValue::NUMERIC:
     749                        ms.set(edgemap_to_edit, active_edge,
     750                            atof(entry.get_text().c_str()));
     751                        break;
     752                      case MapValue::STRING:
     753                        ms.set(edgemap_to_edit, active_edge,
     754                            static_cast<std::string>(entry.get_text()));
     755                        break;
     756                    }
     757                    edgetextmap[active_edge]->property_text().set_value(
     758                        static_cast<std::string>(ms.get(edgemap_to_edit, active_edge)));
     759
     760                    //mapwin.updateEdge(active_edge);
     761                    //                   mapwin.updateEdge(Edge(INVALID));
     762                    propertyUpdate(Edge(INVALID));
     763                }
     764              }
     765            }
     766          break;
     767        }
     768      default:
     769        break;
     770    }
     771  }
    780772  return false; 
    781773}
     
    785777  delete(nodetextmap[node_to_delete]);
    786778  delete(nodesmap[node_to_delete]);
    787   (mytab.mapstorage)->graph.erase(node_to_delete);
     779  mytab.mapstorage->graph.erase(node_to_delete);
    788780}
    789781
     
    792784  delete(edgetextmap[edge_to_delete]);
    793785  delete(edgesmap[edge_to_delete]);
    794   (mytab.mapstorage)->graph.erase(edge_to_delete);
     786  mytab.mapstorage->graph.erase(edge_to_delete);
    795787}
    796788
     
    812804    else
    813805    {
    814       for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     806      for (EdgeIt i(mytab.mapstorage->graph); i!=INVALID; ++i)
    815807      {
    816808        if(edgesmap[i]==active_bre)
     
    822814  }
    823815  else
    824     {
    825       if(forming_edge!=INVALID)
    826         {
    827           forming_edge=INVALID;
    828         }
    829       else
    830         {
    831           std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
    832         }
    833     }
     816  {
     817    if(forming_edge!=INVALID)
     818    {
     819      forming_edge=INVALID;
     820    }
     821    else
     822    {
     823      std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
     824    }
     825  }
    834826}
    835827
    836828void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node)
    837829{
     830  MapStorage& ms = *mytab.mapstorage;
     831
    838832  Gnome::Canvas::Item * moved_item=item;
    839833  Node moved_node=node;
    840834
    841835  if(item==NULL && node==INVALID)
    842     {
    843       moved_item=active_item;
    844       moved_node=active_node;
    845     }
     836  {
     837    moved_item=active_item;
     838    moved_node=active_node;
     839  }
    846840  else
    847     {
    848       isbutton=1;
    849     }
     841  {
     842    isbutton=1;
     843  }
    850844
    851845  //repositioning node and its text
     
    854848
    855849  // the new coordinates of the centre of the node
    856   double coord_x = dx + (mytab.mapstorage)->coords[moved_node].x;
    857   double coord_y = dy + (mytab.mapstorage)->coords[moved_node].y;
     850  double coord_x = dx + ms.getNodeCoords(moved_node).x;
     851  double coord_y = dy + ms.getNodeCoords(moved_node).y;
    858852
    859853  // write back the new coordinates to the coords map
    860   (mytab.mapstorage)->coords.set(moved_node, XY(coord_x, coord_y));
     854  ms.setNodeCoords(moved_node, XY(coord_x, coord_y));
    861855
    862856  //all the edges connected to the moved point has to be redrawn
    863   for(OutEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei)
    864     {
     857  for(OutEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei)
     858  {
     859    XY arrow_pos;
     860
     861    if (ms.graph.source(ei) == ms.graph.target(ei))
     862    {
     863      arrow_pos = ms.getArrowCoords(ei) + XY(dx, dy);
     864    }
     865    else
     866    {
     867      XY moved_node_1(coord_x - dx, coord_y - dy);
     868      XY moved_node_2(coord_x, coord_y);
     869      Node target = ms.graph.target(ei);
     870      XY fix_node = ms.getNodeCoords(target);
     871      XY old_arrow_pos(ms.getArrowCoords(ei));
     872
     873      arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
     874    }
     875
     876    ms.setArrowCoords(ei, arrow_pos);
     877    edgesmap[ei]->draw();
     878
     879    //reposition of edgetext
     880    XY text_pos=ms.getArrowCoords(ei);
     881    text_pos+=(XY(10,10));
     882    edgetextmap[ei]->property_x().set_value(text_pos.x);
     883    edgetextmap[ei]->property_y().set_value(text_pos.y);
     884  }
     885
     886  for(InEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei)
     887  {
     888    if (ms.graph.source(ei) != ms.graph.target(ei))
     889    {
     890      XY moved_node_1(coord_x - dx, coord_y - dy);
     891      XY moved_node_2(coord_x, coord_y);
     892      Node source = ms.graph.source(ei);
     893      XY fix_node = ms.getNodeCoords(source);
     894      XY old_arrow_pos(ms.getArrowCoords(ei));
     895
    865896      XY arrow_pos;
    866 
    867       if (mytab.mapstorage->graph.source(ei) == mytab.mapstorage->graph.target(ei))
    868         {
    869           arrow_pos = mytab.mapstorage->arrow_pos[ei] + XY(dx, dy);
    870         }
    871       else
    872         {
    873           XY moved_node_1(coord_x - dx, coord_y - dy);
    874           XY moved_node_2(coord_x, coord_y);
    875           Node target = mytab.mapstorage->graph.target(ei);
    876           XY fix_node(mytab.mapstorage->coords[target].x,
    877                       mytab.mapstorage->coords[target].y);
    878           XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]);
    879 
    880           arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
    881         }
    882 
    883       mytab.mapstorage->arrow_pos.set(ei, arrow_pos);
     897      arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
     898
     899      ms.setArrowCoords(ei, arrow_pos);
    884900      edgesmap[ei]->draw();
    885901
    886902      //reposition of edgetext
    887       XY text_pos=mytab.mapstorage->arrow_pos[ei];
     903      XY text_pos=ms.getArrowCoords(ei);
    888904      text_pos+=(XY(10,10));
    889905      edgetextmap[ei]->property_x().set_value(text_pos.x);
    890906      edgetextmap[ei]->property_y().set_value(text_pos.y);
    891907    }
    892 
    893   for(InEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei)
    894     {
    895       if (mytab.mapstorage->graph.source(ei) != mytab.mapstorage->graph.target(ei))
    896         {
    897           XY moved_node_1(coord_x - dx, coord_y - dy);
    898           XY moved_node_2(coord_x, coord_y);
    899           Node source = mytab.mapstorage->graph.source(ei);
    900           XY fix_node(mytab.mapstorage->coords[source].x,
    901                       mytab.mapstorage->coords[source].y);
    902           XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]);
    903 
    904           XY arrow_pos;
    905           arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
    906 
    907           mytab.mapstorage->arrow_pos.set(ei, arrow_pos);
    908           edgesmap[ei]->draw();
    909 
    910           //reposition of edgetext
    911           XY text_pos=mytab.mapstorage->arrow_pos[ei];
    912           text_pos+=(XY(10,10));
    913           edgetextmap[ei]->property_x().set_value(text_pos.x);
    914           edgetextmap[ei]->property_y().set_value(text_pos.y);
    915         }
    916     }
     908  }
    917909}
    918910
     
    929921  //the actual value belongs to
    930922  for (int i=0;i<=5;i++)
    931     {
    932       if(((double)i/6<pos)&&(pos<=(double(i+1)/6)))
    933         {
    934           phase=i;
    935         }
    936     }
     923  {
     924    if(((double)i/6<pos)&&(pos<=(double(i+1)/6)))
     925    {
     926      phase=i;
     927    }
     928  }
    937929  if(phase<6)
    938     {
    939       //within its 1/6 long phase the relativ position
    940       //determines the power of the color changed in
    941       //that phase
    942       //we normalize that to one, to be able to give percentage
    943       //value for the function
    944       double rel_pos=(pos-(phase/6.0))*6.0;
    945 
    946       switch(phase)
    947         {
    948         case 0:
    949           color.set_rgb_p (1, 0, 1-rel_pos);
    950           break;
    951         case 1:
    952           color.set_rgb_p (1, rel_pos, 0);
    953           break;
    954         case 2:
    955           color.set_rgb_p (1-rel_pos, 1, 0);
    956           break;
    957         case 3:
    958           color.set_rgb_p (0, 1, rel_pos);
    959           break;
    960         case 4:
    961           color.set_rgb_p (0, 1-rel_pos, 1);
    962           break;
    963         case 5:
    964           color.set_rgb_p ((rel_pos/3.0), 0, 1);
    965           break;
    966         default:
    967           std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
    968         }
    969     }
     930  {
     931    //within its 1/6 long phase the relativ position
     932    //determines the power of the color changed in
     933    //that phase
     934    //we normalize that to one, to be able to give percentage
     935    //value for the function
     936    double rel_pos=(pos-(phase/6.0))*6.0;
     937
     938    switch(phase)
     939    {
     940      case 0:
     941        color.set_rgb_p (1, 0, 1-rel_pos);
     942        break;
     943      case 1:
     944        color.set_rgb_p (1, rel_pos, 0);
     945        break;
     946      case 2:
     947        color.set_rgb_p (1-rel_pos, 1, 0);
     948        break;
     949      case 3:
     950        color.set_rgb_p (0, 1, rel_pos);
     951        break;
     952      case 4:
     953        color.set_rgb_p (0, 1-rel_pos, 1);
     954        break;
     955      case 5:
     956        color.set_rgb_p ((rel_pos/3.0), 0, 1);
     957        break;
     958      default:
     959        std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
     960    }
     961  }
    970962  else
    971     {
    972       std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
    973     }
     963  {
     964    std::cout << "Wrong phase: " << phase << " " << pos << std::endl;
     965  }
    974966  return color;
    975967}
  • graph_displayer_canvas-node.cc

    r194 r201  
    2626int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
    2727{
    28   Graph::NodeMap<double> * actual_map;
     28  MapStorage& ms = *mytab.mapstorage;
     29
    2930  double min, max;
    30   min=(mytab.mapstorage)->minOfNodeMap(mapname);
    31   max=(mytab.mapstorage)->maxOfNodeMap(mapname);
    32   actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
    33 
    34   if(node==INVALID)
    35     {
    36       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    37         {
    38           double v=fabs((*actual_map)[i]);
     31
     32  {
     33    NodeIt n(ms.graph);
     34    min = max = ms.get(mapname, n);
     35    for (; n != INVALID; ++n)
     36    {
     37      if (static_cast<double>(ms.get(mapname, n)) > max)
     38        max = ms.get(mapname, n);
     39      if (static_cast<double>(ms.get(mapname, n)) < min)
     40        min = ms.get(mapname, n);
     41    }
     42  }
     43
     44  if(node==INVALID)
     45    {
     46      for (NodeIt i(ms.graph); i!=INVALID; ++i)
     47        {
     48          double v=fabs(ms.get(mapname,i));
    3949          int w;
    4050          if(autoscale)
     
    103113int GraphDisplayerCanvas::resetNodeRadius (Node node)
    104114{
     115  MapStorage& ms = *mytab.mapstorage;
     116
    105117  double min, max;
    106118  min=node_property_defaults[N_RADIUS];
    107119  max=node_property_defaults[N_RADIUS];
    108   Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_RADIUS]);
     120  Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_RADIUS]);
    109121 
    110122  if(node==INVALID)
    111123    {
    112       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     124      for (NodeIt i(ms.graph); i!=INVALID; ++i)
    113125        {
    114126          double v=fabs(actual_map[i]);
     
    164176int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
    165177
     178  MapStorage& ms = *mytab.mapstorage;
    166179
    167180  //function maps the range of the maximum and
     
    169182  //green in RGB
    170183
    171   Graph::NodeMap<double> * actual_map;
    172   actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
    173 
    174184  double max, min;
    175185
    176   max=(mytab.mapstorage)->maxOfNodeMap(mapname);
    177   min=(mytab.mapstorage)->minOfNodeMap(mapname);
    178 
    179   if(node==INVALID)
    180     {
    181 
    182       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     186  {
     187    NodeIt n(ms.graph);
     188    min = max = ms.get(mapname, n);
     189    for (; n != INVALID; ++n)
     190    {
     191      if (static_cast<double>(ms.get(mapname, n)) > max)
     192        max = ms.get(mapname, n);
     193      if (static_cast<double>(ms.get(mapname, n)) < min)
     194        min = ms.get(mapname, n);
     195    }
     196  }
     197
     198  if(node==INVALID)
     199    {
     200
     201      for (NodeIt i(ms.graph); i!=INVALID; ++i)
    183202        {
    184203          Gdk::Color color;
    185204
    186           double w=(*actual_map)[i];
     205          double w=ms.get(mapname, i);
    187206
    188207          if(max!=min)
     
    202221      Gdk::Color color;
    203222
    204       double w=(*actual_map)[node];
     223      double w=ms.get(mapname, node);
    205224
    206225      if(max!=min)
     
    220239int GraphDisplayerCanvas::resetNodeColor (Node node)
    221240
     241  MapStorage& ms = *mytab.mapstorage;
    222242
    223243  //function maps the range of the maximum and
     
    225245  //green in RGB
    226246
    227   Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_COLOR]);
     247  Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_COLOR]);
    228248
    229249  double max, min;
     
    235255    {
    236256
    237       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     257      for (NodeIt i(ms.graph); i!=INVALID; ++i)
    238258        {
    239259          Gdk::Color color;
     
    275295int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
    276296{
     297  MapStorage& ms = *mytab.mapstorage;
    277298
    278299  //the number in the map will be written on the node
     
    281302  //that is the deleter map
    282303
    283   Graph::NodeMap<double> * actual_map=NULL;
    284   actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
    285 
    286   if(node==INVALID)
    287     {
    288       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     304  if(node==INVALID)
     305    {
     306      for (NodeIt i(ms.graph); i!=INVALID; ++i)
    289307        {
    290308          nodemap_to_edit=mapname;
    291           double number=(*actual_map)[i];
    292 
    293           std::ostringstream ostr;
    294           ostr << number;
    295              
    296           nodetextmap[i]->property_text().set_value(ostr.str());
    297         }
    298     }
    299   else
    300     {
    301       double number=(*actual_map)[node];
    302 
    303       std::ostringstream ostr;
    304       ostr << number;
    305              
    306       nodetextmap[node]->property_text().set_value(ostr.str());
     309
     310          nodetextmap[i]->property_text().set_value(
     311              static_cast<std::string>(ms.get(mapname, i)));
     312        }
     313    }
     314  else
     315    {
     316      nodetextmap[node]->property_text().set_value(
     317          static_cast<std::string>(ms.get(mapname, node)));
    307318    }
    308319  return 0;
     
    311322int GraphDisplayerCanvas::resetNodeText (Node node)
    312323{
     324  MapStorage& ms = *mytab.mapstorage;
    313325
    314326  //the number in the map will be written on the node
     
    319331  if(node==INVALID)
    320332    {
    321       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     333      for (NodeIt i(ms.graph); i!=INVALID; ++i)
    322334        {
    323335          nodemap_to_edit="";
  • graph_displayer_canvas.cc

    r194 r201  
    118118
    119119  if(is_drawn)
    120     {
    121       if(mapname!="")
    122         {
    123           if( ( ((mytab.mapstorage)->nodemap_storage).find(mapname) != ((mytab.mapstorage)->nodemap_storage).end() ) )
    124             {
    125               switch(prop)
    126                 {
    127                 case N_RADIUS:
    128                   changeNodeRadius(mapname, node);
    129                   break;
    130                 case N_COLOR:
    131                   changeNodeColor(mapname, node);
    132                   break;
    133                 case N_TEXT:
    134                   changeNodeText(mapname, node);
    135                   break;
    136                 default:
    137                   std::cerr<<"Error\n";
    138                 }
    139             }
    140         }
    141       else //mapname==""
    142         {
    143           Node node=INVALID;   
    144           switch(prop)
    145             {
    146             case N_RADIUS:
    147               resetNodeRadius(node);
    148               break;
    149             case N_COLOR:
    150               resetNodeColor(node);
    151               break;
    152             case N_TEXT:
    153               resetNodeText(node);
    154               break;
    155             default:
    156               std::cerr<<"Error\n";
    157             }
    158         }
    159     }
     120  {
     121    if(mapname!="")
     122    {
     123      std::vector<std::string> nodemaps = mytab.mapstorage->getNodeMapList();
     124      bool found = false;
     125      for (std::vector<std::string>::const_iterator it = nodemaps.begin();
     126          it != nodemaps.end(); ++it)
     127      {
     128        if (*it == mapname)
     129        {
     130          found = true;
     131          break;
     132        }
     133      }
     134      if (found)
     135      {
     136        switch(prop)
     137        {
     138          case N_RADIUS:
     139            changeNodeRadius(mapname, node);
     140            break;
     141          case N_COLOR:
     142            changeNodeColor(mapname, node);
     143            break;
     144          case N_TEXT:
     145            changeNodeText(mapname, node);
     146            break;
     147          default:
     148            std::cerr<<"Error\n";
     149        }
     150      }
     151    }
     152    else //mapname==""
     153    {
     154      Node node=INVALID;
     155      switch(prop)
     156      {
     157        case N_RADIUS:
     158          resetNodeRadius(node);
     159          break;
     160        case N_COLOR:
     161          resetNodeColor(node);
     162          break;
     163        case N_TEXT:
     164          resetNodeText(node);
     165          break;
     166        default:
     167          std::cerr<<"Error\n";
     168      }
     169    }
     170  }
    160171}
    161172
     
    165176
    166177  if(is_drawn)
    167     {
    168       if(mapname!="")
    169         {
    170           if( ( ((mytab.mapstorage)->edgemap_storage).find(mapname) != ((mytab.mapstorage)->edgemap_storage).end() ) )
    171             {
    172               switch(prop)
    173                 {
    174                 case E_WIDTH:
    175                   changeEdgeWidth(mapname, edge);
    176                   break;
    177                 case E_COLOR:
    178                   changeEdgeColor(mapname, edge);
    179                   break;
    180                 case E_TEXT:
    181                   changeEdgeText(mapname, edge);
    182                   break;
    183                 default:
    184                   std::cerr<<"Error\n";
    185                 }
    186             }
    187         }
    188       else //mapname==""
    189         {
    190           switch(prop)
    191             {
    192             case E_WIDTH:
    193               resetEdgeWidth(edge);
    194               break;
    195             case E_COLOR:
    196               resetEdgeColor(edge);
    197               break;
    198             case E_TEXT:
    199               resetEdgeText(edge);
    200               break;
    201             default:
    202               std::cerr<<"Error\n";
    203             }
    204         }
    205     }
     178  {
     179    if(mapname!="")
     180    {
     181      std::vector<std::string> edgemaps = mytab.mapstorage->getEdgeMapList();
     182      bool found = false;
     183      for (std::vector<std::string>::const_iterator it = edgemaps.begin();
     184          it != edgemaps.end(); ++it)
     185      {
     186        if (*it == mapname)
     187        {
     188          found = true;
     189          break;
     190        }
     191      }
     192      if (found)
     193      {
     194        switch(prop)
     195        {
     196          case E_WIDTH:
     197            changeEdgeWidth(mapname, edge);
     198            break;
     199          case E_COLOR:
     200            changeEdgeColor(mapname, edge);
     201            break;
     202          case E_TEXT:
     203            changeEdgeText(mapname, edge);
     204            break;
     205          default:
     206            std::cerr<<"Error\n";
     207        }
     208      }
     209    }
     210    else //mapname==""
     211    {
     212      switch(prop)
     213      {
     214        case E_WIDTH:
     215          resetEdgeWidth(edge);
     216          break;
     217        case E_COLOR:
     218          resetEdgeColor(edge);
     219          break;
     220        case E_TEXT:
     221          resetEdgeText(edge);
     222          break;
     223        default:
     224          std::cerr<<"Error\n";
     225      }
     226    }
     227  }
    206228}
    207229
     
    222244    //initializing edge-text as well, to empty string
    223245
    224     XY text_pos=mytab.mapstorage->arrow_pos[i];
     246    XY text_pos=mytab.mapstorage->getArrowCoords(i);
    225247    text_pos+=(XY(10,10));
    226248
     
    239261    nodesmap[i]=new Gnome::Canvas::Ellipse(
    240262        displayed_graph,
    241         (mytab.mapstorage)->coords[i].x-20,
    242         (mytab.mapstorage)->coords[i].y-20,
    243         (mytab.mapstorage)->coords[i].x+20,
    244         (mytab.mapstorage)->coords[i].y+20);
     263        mytab.mapstorage->getNodeCoords(i).x-20,
     264        mytab.mapstorage->getNodeCoords(i).y-20,
     265        mytab.mapstorage->getNodeCoords(i).x+20,
     266        mytab.mapstorage->getNodeCoords(i).y+20);
    245267    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
    246268    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
     
    250272
    251273    XY text_pos(
    252         ((mytab.mapstorage)->coords[i].x+node_property_defaults[N_RADIUS]+5),
    253         ((mytab.mapstorage)->coords[i].y+node_property_defaults[N_RADIUS]+5));
     274        (mytab.mapstorage->getNodeCoords(i).x+node_property_defaults[N_RADIUS]+5),
     275        (mytab.mapstorage->getNodeCoords(i).y+node_property_defaults[N_RADIUS]+5));
    254276
    255277    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
     
    326348void GraphDisplayerCanvas::reDesignGraph()
    327349{
    328   NodeIt firstnode((mytab.mapstorage)->graph);
     350  MapStorage& ms = *mytab.mapstorage;
     351  NodeIt firstnode(ms.graph);
    329352  //is it not an empty graph?
    330353  if(firstnode!=INVALID)
     
    336359      if(!was_redesigned)
    337360        {
    338           NodeIt i((mytab.mapstorage)->graph);
     361          NodeIt i(ms.graph);
    339362
    340363          dim2::Point<double> init(init_vector_length*rnd(),
     
    348371      int iterations;
    349372
    350       (mytab.mapstorage)->get_design_data(attraction, propulsation, iterations);
     373      ms.get_design_data(attraction, propulsation, iterations);
    351374
    352375      //iteration counter
    353376      for(int l=0;l<iterations;l++)
    354377        {
    355           Graph::NodeMap<double> x(mytab.mapstorage->graph);
    356           Graph::NodeMap<double> y(mytab.mapstorage->graph);
     378          Graph::NodeMap<double> x(ms.graph);
     379          Graph::NodeMap<double> y(ms.graph);
    357380          XYMap<Graph::NodeMap<double> > actual_forces;
    358381          actual_forces.setXMap(x);
     
    360383
    361384          //count actual force for each nodes
    362           for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
     385          for (NodeIt i(ms.graph); i!=INVALID; ++i)
    363386            {
    364387              //propulsation of nodes
    365               for (NodeIt j((mytab.mapstorage)->graph); j!=INVALID; ++j)
     388              for (NodeIt j(ms.graph); j!=INVALID; ++j)
    366389                {
    367390                  if(i!=j)
    368391                    {
    369392                      lemon::dim2::Point<double> delta =
    370                         ((mytab.mapstorage)->coords[i]-
    371                          (mytab.mapstorage)->coords[j]);
     393                        (ms.getNodeCoords(i)-
     394                         ms.getNodeCoords(j));
    372395
    373396                      const double length_sqr=std::max(delta.normSquare(),min_dist);
     
    383406                    }
    384407                }
    385               //attraction of nodes, to which actual node is bound
    386               for(OutEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)
     408            //attraction of nodes, to which actual node is bound
     409            for(OutEdgeIt ei(ms.graph,i);ei!=INVALID;++ei)
     410              {
     411                lemon::dim2::Point<double> delta =
     412                  (ms.getNodeCoords(i)-
     413                   ms.getNodeCoords(ms.graph.target(ei)));
     414
     415                //calculating attraction strength
     416                //greater distance means greater strength
     417                delta*=attraction;
     418
     419                actual_forces.set(i,actual_forces[i]-delta);
     420              }
     421                    for(InEdgeIt ei(ms.graph,i);ei!=INVALID;++ei)
     422              {
     423                lemon::dim2::Point<double> delta =
     424                  (ms.getNodeCoords(i)-
     425                   ms.getNodeCoords(ms.graph.source(ei)));
     426
     427                //calculating attraction strength
     428                //greater distance means greater strength
     429                delta*=attraction;
     430
     431                actual_forces.set(i,actual_forces[i]-delta);
     432              }
     433            }
     434          for (NodeIt i(ms.graph); i!=INVALID; ++i)
     435            {
     436              if((ms.getNodeCoords(i).x)+actual_forces[i].x>max_coord)
    387437                {
    388                   lemon::dim2::Point<double> delta =
    389                     ((mytab.mapstorage)->coords[i]-
    390                      (mytab.mapstorage)->coords[mytab.mapstorage->
    391                                                graph.target(ei)]);
    392                
    393                   //calculating attraction strength
    394                   //greater distance means greater strength
    395                   delta*=attraction;
    396                
    397                   actual_forces.set(i,actual_forces[i]-delta);
     438                  actual_forces[i].x=max_coord-(ms.getNodeCoords(i).x);
     439                  std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl;
    398440                }
    399               for(InEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)
     441              else if((ms.getNodeCoords(i).x)+actual_forces[i].x<(0-max_coord))
    400442                {
    401                   lemon::dim2::Point<double> delta =
    402                     ((mytab.mapstorage)->coords[i]-
    403                      (mytab.mapstorage)->coords[mytab.mapstorage->
    404                                                graph.source(ei)]);
    405                
    406                   //calculating attraction strength
    407                   //greater distance means greater strength
    408                   delta*=attraction;
    409                
    410                   actual_forces.set(i,actual_forces[i]-delta);
     443                  actual_forces[i].x=0-max_coord-(ms.getNodeCoords(i).x);
     444                  std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl;
    411445                }
    412             }
    413           for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    414             {
    415               if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x>max_coord)
     446              if((ms.getNodeCoords(i).y)+actual_forces[i].y>max_coord)
    416447                {
    417                   actual_forces[i].x=max_coord-((mytab.mapstorage)->coords[i].x);
    418                   std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;
     448                  actual_forces[i].y=max_coord-(ms.getNodeCoords(i).y);
     449                  std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl;
    419450                }
    420               else if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x<(0-max_coord))
     451              else if((ms.getNodeCoords(i).y)+actual_forces[i].y<(0-max_coord))
    421452                {
    422                   actual_forces[i].x=0-max_coord-((mytab.mapstorage)->coords[i].x);
    423                   std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;
    424                 }
    425               if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y>max_coord)
    426                 {
    427                   actual_forces[i].y=max_coord-((mytab.mapstorage)->coords[i].y);
    428                   std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl;
    429                 }
    430               else if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y<(0-max_coord))
    431                 {
    432                   actual_forces[i].y=0-max_coord-((mytab.mapstorage)->coords[i].y);
    433                   std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl;
     453                  actual_forces[i].y=0-max_coord-(ms.getNodeCoords(i).y);
     454                  std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl;
    434455                }
    435456              moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
  • gui_reader.cc

    r194 r201  
    2121
    2222#include <xml.h>
     23#include "io_helper.h"
    2324#include <lemon/dim2.h>
    2425#include <vector>
     
    3435void GuiReader::read(std::istream& is)
    3536{
     37  using std::vector;
     38  using std::string;
     39  using std::pair;
     40  using std::make_pair;
     41  using std::string;
     42  using std::map;
     43
    3644  XmlIo x(is);
    37   std::map<int, XY > m;
    38   x("arrow_pos", m);
    3945
    40   if ((int)m.size() == countEdges(mapstorage->graph))
     46  { x("main_node_map_names", gui_data.main_node_map_names); }
     47  { x("gui_node_map_names", gui_data.gui_node_map_names); }
     48
     49  { x("node_map_types", gui_data.node_map_types); }
     50
     51  { x("main_edge_map_names", gui_data.main_edge_map_names); }
     52  { x("gui_edge_map_names", gui_data.gui_edge_map_names); }
     53
     54  { x("edge_map_types", gui_data.edge_map_types); }
     55
     56  for (vector<string>::const_iterator it = gui_data.gui_node_map_names.begin();
     57      it != gui_data.gui_node_map_names.end(); ++it)
     58  {
     59    MapValue::Type type = gui_data.node_map_types[*it];
     60    switch (type)
    4161    {
    42       for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
    43         {
    44           int edgeid = (int)(*mapstorage->edgemap_storage["label"])[e];
    45           mapstorage->arrow_pos.set(e, m[edgeid]);
    46         }
    47       mapstorage->ArrowPosReadOK();
     62      case MapValue::NUMERIC:
     63        {
     64          map<int, double>* p_map_data =
     65            new map<int, double>;
     66          gui_data.numeric_node_maps[*it] = p_map_data;
     67          { x(*it, *p_map_data); }
     68        }
     69        break;
     70      case MapValue::STRING:
     71        {
     72          map<int, string>* p_map_data =
     73            new map<int, string>;
     74          gui_data.string_node_maps[*it] = p_map_data;
     75          { x(*it, *p_map_data); }
     76        }
     77        break;
    4878    }
    49  
     79  }
     80
     81  for (vector<string>::const_iterator it = gui_data.gui_edge_map_names.begin();
     82      it != gui_data.gui_edge_map_names.end(); ++it)
     83  {
     84    MapValue::Type type = gui_data.edge_map_types[*it];
     85    switch (type)
     86    {
     87      case MapValue::NUMERIC:
     88        {
     89          map<int, double>* p_map_data =
     90            new map<int, double>;
     91          gui_data.numeric_edge_maps[*it] = p_map_data;
     92          { x(*it, *p_map_data); }
     93        }
     94        break;
     95      case MapValue::STRING:
     96        {
     97          map<int, string>* p_map_data =
     98            new map<int, string>;
     99          gui_data.string_edge_maps[*it] = p_map_data;
     100          { x(*it, *p_map_data); }
     101        }
     102        break;
     103    }
     104  }
     105
     106  {
     107    std::string node_coords_save_dest;
     108    { x("node_coords_save_dest", node_coords_save_dest); }
     109    if (node_coords_save_dest == "gui_sect")
     110    {
     111      // read the node coorinates
     112      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
     113      { x("node_coord_map", gui_data.node_coord_map); }
     114    }
     115    else if (node_coords_save_dest == "nodeset_sect_1_map")
     116    {
     117      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
     118      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
     119      { x("map_name", gui_data.node_coords_one_map_name); }
     120    }
     121    else if (node_coords_save_dest == "nodeset_sect_2_maps")
     122    {
     123      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
     124      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
     125      { x("map1_name", gui_data.node_coords_two_maps_1_name); }
     126      { x("map2_name", gui_data.node_coords_two_maps_2_name); }
     127    }
     128  }
     129
     130  {
     131    std::string arrow_coords_save_dest;
     132    { x("arrow_coords_save_dest", arrow_coords_save_dest); }
     133    if (arrow_coords_save_dest == "gui_sect")
     134    {
     135      // read the arrow coorinates
     136      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
     137      { x("arrow_coord_map", gui_data.arrow_coord_map); }
     138    }
     139    else if (arrow_coords_save_dest == "edgeset_sect_1_map")
     140    {
     141      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
     142      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
     143      { x("map_name", gui_data.arrow_coords_one_map_name); }
     144    }
     145    else if (arrow_coords_save_dest == "edgeset_sect_2_maps")
     146    {
     147      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
     148      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
     149      { x("map1_name", gui_data.arrow_coords_two_maps_1_name); }
     150      { x("map2_name", gui_data.arrow_coords_two_maps_2_name); }
     151    }
     152  }
     153
     154
     155
    50156  std::map<int, std::string> nm;
    51157  x("active_nodemaps", nm);
    52158
    53159  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    54     {
    55       mapstorage->changeActiveMap(false, i, nm[i]);
    56     }
     160  {
     161    mapstorage->changeActiveMap(false, i, nm[i]);
     162  }
    57163
    58164  std::map<int, std::string> em;
    59165  x("active_edgemaps", em);
    60166  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    61     {
    62       mapstorage->changeActiveMap(true, i, em[i]);
    63     }
     167  {
     168    mapstorage->changeActiveMap(true, i, em[i]);
     169  }
    64170
    65171  double attraction;
     
    78184}
    79185
    80 GuiReader::GuiReader(LemonReader& reader, MapStorage* ms) : Parent(reader), mapstorage(ms)
     186GuiReader::GuiReader(LemonReader& reader, MapStorage* _mapstorage,
     187    MapStorage::GUISectData& _gui_data) :
     188  Parent(reader),
     189  mapstorage(_mapstorage),
     190  gui_data(_gui_data)
    81191{
    82192}
  • gui_reader.h

    r194 r201  
    2121#include <lemon/lemon_reader.h>
    2222
    23 class MapStorage;
     23#include "mapstorage.h"
    2424
    2525using lemon::LemonReader;
     
    2929  private:
    3030    MapStorage* mapstorage;
     31    MapStorage::GUISectData& gui_data;
    3132  protected:
    3233    virtual bool header(const std::string&);
     
    3435  public:
    3536    typedef LemonReader::SectionReader Parent;
    36     GuiReader(LemonReader&, MapStorage*);
     37    GuiReader(LemonReader&, MapStorage*, MapStorage::GUISectData&);
    3738};
    3839
  • gui_writer.cc

    r194 r201  
    1717 */
    1818
    19 #include <xml.h>
     19#include "gui_writer.h"
     20#include "io_helper.h"
     21#include "mapstorage.h"
     22#include "xml.h"
    2023#include <lemon/dim2.h>
    2124#include <vector>
     
    3134void GuiWriter::write(std::ostream& os)
    3235{
     36  using std::vector;
     37  using std::string;
     38  using std::map;
     39  using std::string;
     40
    3341  XmlIo x(os);
    34   std::map<int, XY > m;
    35   for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
    36   {
    37     int edgeid = (int)(*(mapstorage->edgemap_storage["label"]))[e];
    38     m[edgeid] = mapstorage->arrow_pos[e];
    39   }
    40   x("arrow_pos", m);
     42
     43  vector<string> all_node_map_names = mapstorage->getNodeMapList();
     44  // name of the maps saved to the nodeset section
     45  vector<string> main_node_map_names;
     46  // name of the maps saved to the gui section
     47  vector<string> gui_node_map_names;
     48
     49  for (vector<string>::const_iterator it = all_node_map_names.begin();
     50      it != all_node_map_names.end(); ++it)
     51  {
     52    if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::NESET_SECT)
     53      main_node_map_names.push_back(*it);
     54    else if (mapstorage->getNodeMapSaveDest(*it) == MapStorage::GUI_SECT)
     55      gui_node_map_names.push_back(*it);
     56  }
     57
     58  { x("main_node_map_names", main_node_map_names); }
     59  { x("gui_node_map_names", gui_node_map_names); }
     60
     61  map<string, MapValue::Type> node_map_types;
     62  for (vector<string>::const_iterator it = main_node_map_names.begin();
     63      it != main_node_map_names.end(); ++it)
     64  {
     65    node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
     66  }
     67  for (vector<string>::const_iterator it = gui_node_map_names.begin();
     68      it != gui_node_map_names.end(); ++it)
     69  {
     70    node_map_types[*it] = mapstorage->getNodeMapElementType(*it);
     71  }
     72
     73  { x("node_map_types", node_map_types); }
     74
     75
     76  vector<string> all_edge_map_names = mapstorage->getEdgeMapList();
     77  // name of the maps saved to the edgeset section
     78  vector<string> main_edge_map_names;
     79  // name of the maps saved to the gui section
     80  vector<string> gui_edge_map_names;
     81
     82  for (vector<string>::const_iterator it = all_edge_map_names.begin();
     83      it != all_edge_map_names.end(); ++it)
     84  {
     85    if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::NESET_SECT)
     86      main_edge_map_names.push_back(*it);
     87    if (mapstorage->getEdgeMapSaveDest(*it) == MapStorage::GUI_SECT)
     88      gui_edge_map_names.push_back(*it);
     89  }
     90
     91  { x("main_edge_map_names", main_edge_map_names); }
     92  { x("gui_edge_map_names", gui_edge_map_names); }
     93
     94  map<string, MapValue::Type> edge_map_types;
     95  for (vector<string>::const_iterator it = main_edge_map_names.begin();
     96      it != main_edge_map_names.end(); ++it)
     97  {
     98    edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it);
     99  }
     100  for (vector<string>::const_iterator it = gui_edge_map_names.begin();
     101      it != gui_edge_map_names.end(); ++it)
     102  {
     103    edge_map_types[*it] = mapstorage->getEdgeMapElementType(*it);
     104  }
     105
     106  { x("edge_map_types", edge_map_types); }
     107
     108  // write the gui node maps
     109  for (vector<string>::const_iterator it = gui_node_map_names.begin();
     110      it != gui_node_map_names.end(); ++it)
     111  {
     112    MapValue::Type type = mapstorage->getNodeMapElementType(*it);
     113    const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap();
     114    switch (type)
     115    {
     116      case MapValue::NUMERIC:
     117        {
     118          std::map<int, double> map_data;
     119          MapStorage::NumericNodeMap& map =
     120            mapstorage->getNumericNodeMap(*it);
     121          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
     122          {
     123            map_data[labels[n]] = map[n];
     124          }
     125          { x(*it, map_data); }
     126        }
     127        break;
     128      case MapValue::STRING:
     129        {
     130          std::map<int, std::string> map_data;
     131          MapStorage::StringNodeMap& map =
     132            mapstorage->getStringNodeMap(*it);
     133          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
     134          {
     135            map_data[labels[n]] = map[n];
     136          }
     137          { x(*it, map_data); }
     138        }
     139        break;
     140    }
     141  }
     142
     143  // write the gui edge maps
     144  for (vector<string>::const_iterator it = gui_edge_map_names.begin();
     145      it != gui_edge_map_names.end(); ++it)
     146  {
     147    MapValue::Type type = mapstorage->getEdgeMapElementType(*it);
     148    const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap();
     149    switch (type)
     150    {
     151      case MapValue::NUMERIC:
     152        {
     153          std::map<int, double> map_data;
     154          MapStorage::NumericEdgeMap& map =
     155            mapstorage->getNumericEdgeMap(*it);
     156          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
     157          {
     158            map_data[labels[e]] = map[e];
     159          }
     160          { x(*it, map_data); }
     161        }
     162        break;
     163      case MapValue::STRING:
     164        {
     165          std::map<int, std::string> map_data;
     166          MapStorage::StringEdgeMap& map =
     167            mapstorage->getStringEdgeMap(*it);
     168          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
     169          {
     170            map_data[labels[e]] = map[e];
     171          }
     172          { x(*it, map_data); }
     173        }
     174        break;
     175    }
     176  }
     177
     178  {
     179    switch (mapstorage->getNodeCoordsSaveDest())
     180    {
     181      case MapStorage::SpecMapSaveOpts::GUI_SECT:
     182        { x("node_coords_save_dest", string("gui_sect")); }
     183        // write the node coorinates
     184        {
     185          const MapStorage::NodeLabelMap& labels =
     186            mapstorage->getNodeLabelMap();
     187          std::map<int, XY> node_coord_map;
     188          MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
     189          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
     190          {
     191            node_coord_map[labels[n]] = map[n];
     192          }
     193          { x("node_coord_map", node_coord_map); }
     194        }
     195        break;
     196      case MapStorage::SpecMapSaveOpts::NESET_SECT:
     197        switch (mapstorage->getNodeCoordsSaveMapNum())
     198        {
     199          case MapStorage::SpecMapSaveOpts::ONE_MAP:
     200            { x("node_coords_save_dest", string("nodeset_sect_1_map")); }
     201            { x("map_name", mapstorage->getNodeCoordsOneMapName()); }
     202            break;
     203          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
     204            { x("node_coords_save_dest", string("nodeset_sect_2_maps")); }
     205            { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); }
     206            { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); }
     207            break;
     208        }
     209        break;
     210    }
     211  }
     212
     213  {
     214    switch (mapstorage->getArrowCoordsSaveDest())
     215    {
     216      case MapStorage::SpecMapSaveOpts::GUI_SECT:
     217        { x("arrow_coords_save_dest", string("gui_sect")); }
     218        // write the arrow coorinates
     219        {
     220          const MapStorage::EdgeLabelMap& labels =
     221            mapstorage->getEdgeLabelMap();
     222          std::map<int, XY> arrow_coord_map;
     223          MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
     224          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
     225          {
     226            arrow_coord_map[labels[e]] = map[e];
     227          }
     228          { x("arrow_coord_map", arrow_coord_map); }
     229        }
     230        break;
     231      case MapStorage::SpecMapSaveOpts::NESET_SECT:
     232        switch (mapstorage->getArrowCoordsSaveMapNum())
     233        {
     234          case MapStorage::SpecMapSaveOpts::ONE_MAP:
     235            { x("arrow_coords_save_dest", string("edgeset_sect_1_map")); }
     236            { x("map_name", mapstorage->getArrowCoordsOneMapName()); }
     237            break;
     238          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
     239            { x("arrow_coords_save_dest", string("edgeset_sect_2_maps")); }
     240            { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); }
     241            { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); }
     242            break;
     243        }
     244        break;
     245    }
     246  }
     247
    41248
    42249  std::map<int, std::string> nm;
     
    45252      nm[i]=mapstorage->active_nodemaps[i];
    46253    }
    47   x("active_nodemaps", nm);
     254  { x("active_nodemaps", nm); }
    48255
    49256  std::map<int, std::string> em;
     
    52259      em[i]=mapstorage->active_edgemaps[i];
    53260    }
    54   x("active_edgemaps", em);
     261  { x("active_edgemaps", em); }
    55262
    56263  double attraction;
     
    60267  mapstorage->get_design_data(attraction, propulsation, iteration);
    61268
    62   x("redesign-attraction", attraction);
    63   x("redesign-propulsation", propulsation);
    64   x("redesign-iteration", iteration);
     269  { x("redesign-attraction", attraction); }
     270  { x("redesign-propulsation", propulsation); }
     271  { x("redesign-iteration", iteration); }
    65272}
    66273
    67 GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms)
     274GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) :
     275  Parent(writer),
     276  mapstorage(ms)
    68277{
    69278}
  • kruskalbox.cc

    r194 r201  
    3434{
    3535  if(
    36      tabcbt.get_active_text()!="" &&
    37      (edgemapcbts[INPUT])->get_active_text()!="" &&
    38      (edgemapcbts[OUTPUT])->get_active_text()!=""
    39      )
     36      tabcbt.get_active_text()!="" &&
     37      (edgemapcbts[INPUT])->get_active_text()!="" &&
     38      (edgemapcbts[OUTPUT])->get_active_text()!=""
     39    )
     40  {
     41
     42    const Graph &g=mapstorage->getGraph();
     43    std::string input_map_name = edgemapcbts[INPUT]->get_active_text();
     44    Graph::EdgeMap<bool> outputmap(g);
     45    const MapStorage::NumericEdgeMap& inputmap=
     46      mapstorage->getNumericEdgeMap(input_map_name);
     47    double res=kruskal(g, inputmap, outputmap);
     48
     49    for (EdgeIt i(g); i!=INVALID; ++i)
    4050    {
     51      if(outputmap[i])
     52      {
     53        mapstorage->set(edgemapcbts[OUTPUT]->get_active_text(), i, 1.0);
     54      }
     55      else
     56      {
     57        mapstorage->set(edgemapcbts[OUTPUT]->get_active_text(), i, 0.0);
     58      }
     59    }
    4160
    42       const Graph &g=mapstorage->graph;
    43       Graph::EdgeMap<double> * inputmap=
    44         ((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
    45       Graph::EdgeMap<bool> outputmap(g);
    46       double res=kruskal(g, *inputmap, outputmap);
     61    std::ostringstream o;
     62    o << "Result: " << res;
     63    resultlabel.set_text(o.str());
    4764
    48       for (EdgeIt i(g); i!=INVALID; ++i)
    49         {
    50           if(outputmap[i])
    51             {
    52               (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
    53                                                get_active_text()]))[i]=1;
    54             }
    55           else
    56             {
    57               (*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->
    58                                                get_active_text()]))[i]=0;
    59             }
    60         }
     65    mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
     66    //   mapstorage->changeActiveMap(true, E_COLOR,
     67    //                        (edgemapcbts[OUTPUT])->get_active_text());
     68    //   mapstorage->changeActiveMap(true, E_TEXT,
     69    //                        (edgemapcbts[INPUT])->get_active_text());
    6170
    62       std::ostringstream o;
    63       o << "Result: " << res;
    64       resultlabel.set_text(o.str());
    65 
    66       mapstorage->mapChanged(true, (edgemapcbts[OUTPUT])->get_active_text());
    67       //   mapstorage->changeActiveMap(true, E_COLOR,
    68       //                              (edgemapcbts[OUTPUT])->get_active_text());
    69       //   mapstorage->changeActiveMap(true, E_TEXT,
    70       //                              (edgemapcbts[INPUT])->get_active_text());
    71  
    72     }
     71  }
    7372}
    7473   
     
    7776  std::vector<std::string> empty_vector;
    7877
    79   addMapSelector("Edgecosts: ", true);
    80   addMapSelector("Edges of tree here: ", true);
     78  addMapSelector("Edgecosts: ", true, NUM);
     79  addMapSelector("Edges of tree here: ", true, NUM);
    8180
    8281  resultlabel.set_text("Result: algorithm is not run yet.");
  • main_win.cc

    r194 r201  
    2121#endif
    2222
    23 #include <main_win.h>
    24 #include <guipixbufs.h>
    25 #include <background_chooser_dialog.h>
     23#include "main_win.h"
     24#include "guipixbufs.h"
     25#include "save_details_dialog.h"
     26#include "background_chooser_dialog.h"
    2627
    2728#include <mapstorage.h>
     
    115116  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
    116117      sigc::mem_fun(*this, &MainWin::saveFileAs));
     118  ag->add( Gtk::Action::create("SaveDetails", _("Save _Details...")),
     119           sigc::mem_fun(*this, &MainWin::createSaveDetailsDialog));
    117120  ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
    118121      sigc::mem_fun(*this, &MainWin::closeTab));
     
    161164      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
    162165
    163   ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
     166  ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap"), "New map"),
    164167      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
    165168
     
    167170      sigc::mem_fun ( *this , &MainWin::reDesignGraph ) );
    168171
    169   ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps")),
     172  ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps"), "Export to EPS"),
    170173      sigc::mem_fun ( *this , &MainWin::exportToEPS ) );
    171174
     
    186189      "      <menuitem action='FileSave'/>"
    187190      "      <menuitem action='FileSaveAs'/>"
     191      "      <menuitem action='SaveDetails'/>"
    188192      "      <menuitem action='Close'/>"
    189193      "      <menuitem action='Quit'/>"
     
    371375  if(active_tab!=-1)
    372376    {
    373       if (tabs[active_tab]->mapstorage->modified)
     377      if (tabs[active_tab]->mapstorage->getModified())
    374378        {
    375379          Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
     
    629633}
    630634
     635void MainWin::createSaveDetailsDialog()
     636{
     637  SaveDetailsDialog dialog(tabs[active_tab]->mapstorage);
     638  dialog.run();
     639}
     640
    631641void MainWin::exportToEPS()
    632642{
  • main_win.h

    r194 r201  
    261261  virtual void reDesignGraph();
    262262
     263  /// Pops up a SaveDetailsDialog.
     264  void createSaveDetailsDialog();
     265
    263266  virtual void exportToEPS();
    264267
  • map_win.cc

    r194 r201  
    3232}
    3333
    34 MapWin::MapWin(const std::string& title, std::vector<std::string> eml, std::vector<std::string> nml, NoteBookTab & mw):mytab(mw)
     34MapWin::MapWin(const std::string& title,
     35    std::vector<std::string> n_eml,
     36    std::vector<std::string> s_eml,
     37    std::vector<std::string> n_nml,
     38    std::vector<std::string> s_nml,
     39    NoteBookTab & mw):mytab(mw)
    3540{
    3641  set_title(title);
     
    4954  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    5055  {
    51     e_combo_array[i]=new MapSelector(eml, mytab.getActiveEdgeMap(i), edge_property_strings[i], true);
     56    switch (i)
     57    {
     58      case E_WIDTH:
     59        e_combo_array[i]=new MapSelector(n_eml, s_eml,
     60            mytab.getActiveEdgeMap(i), edge_property_strings[i],
     61            true, true, NUM);
     62        break;
     63      case E_COLOR:
     64        e_combo_array[i]=new MapSelector(n_eml, s_eml,
     65            mytab.getActiveEdgeMap(i), edge_property_strings[i],
     66            true, true, NUM);
     67        break;
     68      case E_TEXT:
     69        e_combo_array[i]=new MapSelector(n_eml, s_eml,
     70            mytab.getActiveEdgeMap(i), edge_property_strings[i],
     71            true, true, ALL);
     72        break;
     73    }
    5274
    5375    (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     
    6991  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    7092  {
    71     n_combo_array[i]=new MapSelector(nml, mytab.getActiveNodeMap(i), node_property_strings[i], false);
     93    switch (i)
     94    {
     95      case N_RADIUS:
     96        n_combo_array[i]=new MapSelector(n_nml, s_nml,
     97            mytab.getActiveNodeMap(i), node_property_strings[i],
     98            false, true, NUM);
     99        break;
     100      case N_COLOR:
     101        n_combo_array[i]=new MapSelector(n_nml, s_nml,
     102            mytab.getActiveNodeMap(i), node_property_strings[i],
     103            false, true, NUM);
     104        break;
     105      case N_TEXT:
     106        n_combo_array[i]=new MapSelector(n_nml, s_nml,
     107            mytab.getActiveNodeMap(i), node_property_strings[i],
     108            false, true, ALL);
     109        break;
     110    }
    72111
    73112    (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
     
    83122  vbox.pack_start(*table);
    84123
     124  update(n_eml, s_eml, n_nml, s_nml);
     125
    85126  show_all_children();
    86127
     
    102143}
    103144
    104 void MapWin::update(std::vector<std::string> eml, std::vector<std::string> nml)
     145void MapWin::update(
     146    std::vector<std::string> n_eml,
     147    std::vector<std::string> s_eml,
     148    std::vector<std::string> n_nml,
     149    std::vector<std::string> s_nml)
    105150{
    106151  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    107152  {
    108     e_combo_array[i]->update_list(eml);
     153    e_combo_array[i]->update_list(n_eml, s_eml);
    109154  }
    110155
    111156  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    112157  {
    113     n_combo_array[i]->update_list(nml);
     158    n_combo_array[i]->update_list(n_nml, s_nml);
    114159  }
    115160
     
    117162}
    118163
    119 void MapWin::registerNewEdgeMap(std::string newmapname)
     164void MapWin::registerNewEdgeMap(std::string newmapname, MapValue::Type type)
    120165{
    121166  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    122167  {
    123168    //filling in combo box with choices
    124     e_combo_array[i]->append_text((Glib::ustring)newmapname);
    125   }
    126 }
    127 
    128 void MapWin::registerNewNodeMap(std::string newmapname)
     169    e_combo_array[i]->append_text((Glib::ustring)newmapname, type);
     170  }
     171}
     172
     173void MapWin::registerNewNodeMap(std::string newmapname, MapValue::Type type)
    129174{
    130175  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    131176  {
    132177    //filling in combo box with choices
    133     n_combo_array[i]->append_text((Glib::ustring)newmapname);
     178    n_combo_array[i]->append_text((Glib::ustring)newmapname, type);
    134179  }
    135180}
  • map_win.h

    r194 r201  
    2626#include <libgnomecanvasmm.h>
    2727#include <libgnomecanvasmm/polygon.h>
     28#include "map_value.h"
    2829
    2930///Graph visualization setup window.
     
    6566  ///binds the needed signal to the correct place.
    6667  ///\param title title of window
    67   ///\param eml edgemap list
    68   ///\param nml nodemap list
    6968  ///\param mw the owner \ref NoteBookTab (\ref mytab)
    70   MapWin(const std::string& title, std::vector<std::string> eml, std::vector<std::string> nml, NoteBookTab & mw);
     69  MapWin(const std::string& title,
     70      std::vector<std::string> n_eml,
     71      std::vector<std::string> s_eml,
     72      std::vector<std::string> n_nml,
     73      std::vector<std::string> s_nml,
     74      NoteBookTab & mw);
    7175
    7276  ///Deregistrates \ref MapWin in its \ref NoteBookTab (\ref mytab)
     
    107111  ///\param new_name
    108112  ///name of new map
    109   void registerNewEdgeMap(std::string new_name);
     113  void registerNewEdgeMap(std::string new_name, MapValue::Type type);
    110114
    111115  ///This function inserts name of the new nodemap in the name list in \ref MapSelector s
     
    113117  ///\param new_name
    114118  ///name of new map
    115   void registerNewNodeMap(std::string new_name);
     119  void registerNewNodeMap(std::string new_name, MapValue::Type type);
    116120
    117121  ///Close window if Esc key pressed.
     
    125129  ///has to call this function or not from the \ref NoteBookTab::mapwinexists
    126130  ///variable.
    127   ///\param eml edge map list
    128   ///\param nml node map list
    129   void update(std::vector<std::string> eml, std::vector<std::string> nml);
     131  void update(
     132    std::vector<std::string> n_eml,
     133    std::vector<std::string> s_eml,
     134    std::vector<std::string> n_nml,
     135    std::vector<std::string> s_nml);
    130136
    131137  void changeEntry(bool, int, std::string);
  • mapselector.cc

    r194 r201  
    1919#include <mapselector.h>
    2020
    21 MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false)
     21MapSelector::MapSelector(std::vector<std::string> n_ml,
     22    std::vector<std::string> s_ml, std::string act,
     23    std::string labeltext, bool edge, bool d, MapType type) :
     24  def(d),
     25  itisedge(edge),
     26  set_new_map(false),
     27  label(labeltext),
     28  map_type(type),
     29  newbut(Gtk::Stock::NEW)
    2230{
    23   update_list(ml);
     31  update_list(n_ml, s_ml);
    2432
    2533  if(act=="")
    26     {
    27       cbt.set_active(0);
    28       default_state=true;
    29     }
     34  {
     35    cbt.set_active(0);
     36    default_state=true;
     37  }
    3038  else
    31     {
    32       cbt.set_active_text((Glib::ustring)act);
    33       default_state=false;
    34     }
     39  {
     40    cbt.set_active_text((Glib::ustring)act);
     41    default_state=false;
     42  }
    3543
    3644  //binding signal to the actual entry
     
    3947     sigc::mem_fun((*this), &MapSelector::comboChanged),
    4048     false
    41      );
    42  
    43   label=new Gtk::Label(labeltext);
     49    );
    4450
    45   label->set_width_chars(longest_property_string_length);
     51  label.set_width_chars(longest_property_string_length);
    4652
    47   defbut=NULL;
    4853  if(def)
    49     {
    50       defbut=new Gtk::Button();
    51       defbut->set_label("Reset");
    52      
    53       defbut->signal_pressed().connect
    54         (
    55          sigc::mem_fun(*this, &MapSelector::reset)
    56          );
    57     }
     54  {
     55    defbut.set_label("Reset");
     56    defbut.signal_pressed().connect
     57      (
     58       sigc::mem_fun(*this, &MapSelector::reset)
     59      );
     60  }
    5861
    59   newbut=new Gtk::Button(Gtk::Stock::NEW);
    6062
    61   newbut->signal_pressed().connect
     63  newbut.signal_pressed().connect
    6264    (
    6365     sigc::mem_fun(*this, &MapSelector::new_but_pressed)
    64      );
     66    );
    6567
    66   add(*label);
     68  add(label);
    6769
    6870  add(cbt);
    6971
    7072  if(def)
    71     {
    72       add(*defbut);
    73     }
     73  {
     74    add(defbut);
     75  }
    7476
    75   add(*newbut);
     77  add(newbut);
    7678}
    7779
     
    8284}
    8385
    84 void MapSelector::update_list( std::vector< std::string > ml )
     86void MapSelector::update_list(std::vector<std::string> n_ml,
     87    std::vector<std::string> s_ml)
    8588{
    8689  int prev_act=cbt.get_active_row_number();
    8790  cbt.clear();
    8891  cbt_content.clear();
    89   std::vector< std::string >::iterator emsi=ml.begin();
    90   for(;emsi!=ml.end();emsi++)
     92
     93  if (map_type & NUM)
     94  {
     95    std::vector< std::string >::iterator emsi=n_ml.begin();
     96    for(;emsi!=n_ml.end();emsi++)
    9197    {
    9298      cbt.append_text(*emsi);
    9399      cbt_content.push_back(*emsi);
    94100    }
     101  }
     102  if (map_type & STR)
     103  {
     104    std::vector< std::string >::iterator emsi=s_ml.begin();
     105    for(;emsi!=s_ml.end();emsi++)
     106    {
     107      cbt.append_text(*emsi);
     108      cbt_content.push_back(*emsi);
     109    }
     110  }
    95111  if(def)
    96112    {
     
    148164}
    149165
    150 void MapSelector::append_text(Glib::ustring text)
     166void MapSelector::append_text(Glib::ustring text, MapValue::Type type)
    151167{
    152   cbt.append_text(text);
    153   cbt_content.push_back(text);
     168  if (type & map_type)
     169  {
     170    cbt.append_text(text);
     171    cbt_content.push_back(text);
    154172
    155   if(set_new_map)
     173    if(set_new_map)
    156174    {
    157175      set_active_text(text);
    158176      set_new_map=false;
    159177    }
     178  }
    160179}
    161180
  • mapselector.h

    r194 r201  
    2323#include <libgnomecanvasmm.h>
    2424#include <libgnomecanvasmm/polygon.h>
     25#include "map_value.h"
    2526
    2627///A widget by which node and edgemaps can be selected, deselected and created.
     
    8182  ///By pressing it
    8283  ///\ref NewMapWin wilol pop-up
    83   Gtk::Button * newbut;
     84  Gtk::Button newbut;
    8485
    8586  ///Reset button.
     
    8990  ///
    9091  ///It is visible only if \ref def is true.
    91   Gtk::Button * defbut;
    92 
    93   ///Container in which GUI elements are packed.
    94   Gtk::HBox hbox;
     92  Gtk::Button defbut;
    9593
    9694  ///Shows purpose of \ref MapSelector piece.
    97   Gtk::Label * label;
     95  Gtk::Label label;
     96
     97  /// Which types of maps (integer, string, ...) to display.
     98  MapType map_type;
    9899
    99100 public:
     
    102103
    103104  ///Creates the layout and binds signal to the correct place.
    104   ///\param optionlist list of names to place in \ref cbt
     105  ///\param mapstorage Pointer to the \ref MapStorage to get the map list from.
    105106  ///\param act preselected option
    106107  ///\param purpose text of label indicating purpose of \ref MapStorage
    107108  ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames.
    108109  ///\param def do we need 'Default' option. See \ref def.
    109   MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true);
     110  ///\param type Specifies which types of maps to display.
     111  MapSelector(std::vector<std::string> n_ml,
     112      std::vector<std::string> s_ml, std::string act, std::string labeltext,
     113      bool edge, bool d = true, MapType type = ALL);
    110114
    111115  ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt)
     
    120124  ///into account that the previously selected option
    121125  ///has to be set back after the operation.
    122   void update_list( std::vector<std::string> );
     126  void update_list(std::vector<std::string> n_ml,
     127      std::vector<std::string> s_ml);
    123128
    124129  ///Handles changement in \ref cbt.
     
    169174  ///this function  will set \ref cbt to the new option.
    170175  ///\param new_option new option to append
    171   void append_text(Glib::ustring new_option);
     176  void append_text(Glib::ustring new_option, MapValue::Type);
    172177};
    173178#endif //MAPSELECTOR_H
  • mapstorage.cc

    r199 r201  
    88 *
    99 * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
     10 * provided that this copyright notice appears in all cop       ies. For
    1111 * precise terms see the accompanying LICENSE file.
    1212 *
     
    1717 */
    1818
     19#include "i18n.h"
    1920#include <limits>
    2021#include <cmath>
     22#include <iostream>
     23#include <fstream>
     24#include <string>
     25#include <algorithm>
    2126#include <gtkmm.h>
    22 
     27#include "file_import_dialog.h"
    2328#include <mapstorage.h>
    2429#include <gui_writer.h>
     
    3035const double p_d=40000;
    3136
    32 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false), iterations(i_d), attraction(a_d), propulsation(p_d), background_set(false)
    33 {
    34   nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
    35   coords.setXMap(*nodemap_storage["coordinates_x"]);
    36   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    37   coords.setYMap(*nodemap_storage["coordinates_y"]);
    38 
    39   edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
    40   arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
    41   edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
    42   arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    43 
    44   nodemap_storage["label"] = new Graph::NodeMap<double>(graph);
    45   edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
    46 
    47   nodemap_default["label"] = 1.0;
    48   edgemap_default["label"] = 1.0;
     37MapStorage::MapStorage() :
     38  gui_sect_save_dest(LGF_FILE),
     39  node_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
     40  arrow_coords_save_dest(SpecMapSaveOpts::GUI_SECT),
     41  modified(false),
     42  file_name(""),
     43  max_node_label(0),
     44  max_edge_label(0),
     45  node_coords_one_map_name("coord"),
     46  node_coords_two_maps_1_name("coord_x"),
     47  node_coords_two_maps_2_name("coord_y"),
     48  arrow_coords_one_map_name("arrow"),
     49  arrow_coords_two_maps_1_name("arrow_x"),
     50  arrow_coords_two_maps_2_name("arrow_y"),
     51  iterations(i_d),
     52  attraction(a_d),
     53  propulsation(p_d),
     54  node_coords_x(graph),
     55  node_coords_y(graph),
     56  arrow_coords_x(graph),
     57  arrow_coords_y(graph),
     58  node_label(graph),
     59  edge_label(graph),
     60  background_set(false)
     61{
     62  node_coords.setXMap(node_coords_x);
     63  node_coords.setYMap(node_coords_y);
     64  arrow_coords.setXMap(arrow_coords_x);
     65  arrow_coords.setYMap(arrow_coords_y);
    4966
    5067  active_nodemaps.resize(NODE_PROPERTY_NUM);
     
    6380MapStorage::~MapStorage()
    6481{
    65   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    66       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    67   {
    68     delete it->second;
    69   }
    70   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    71       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    72   {
    73     delete it->second;
    74   }
    75 }
    76 
    77 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
    78 {
    79   if( nodemap_storage.find(name) == nodemap_storage.end() )
    80     {
    81       nodemap_storage[name]=nodemap;
    82       // set the maps default value
    83       nodemap_default[name] = default_value;
    84 
    85       //announce changement in maps
    86       signal_node_map.emit(name);
    87       return 0;
    88     }
    89   return 1;
     82  clear();
     83}
     84
     85void MapStorage::createNodeMap(const std::string& name, MapValue::Type type,
     86    MapValue def_val)
     87{
     88  NodeMapStore::const_iterator it = nodemaps.find(name);
     89  if (it != nodemaps.end())
     90    throw Error("Node map " + name + " already exists.");
     91
     92  switch (type)
     93  {
     94    case MapValue::NUMERIC:
     95      nodemaps[name] = new NumericNodeMapData(graph, def_val);
     96      break;
     97    case MapValue::STRING:
     98      nodemaps[name] = new StringNodeMapData(graph, def_val);
     99      break;
     100  }
     101
     102  nodemaps[name]->default_value = def_val;
     103
     104  signal_node_map.emit(name, type);
     105}
     106
     107void MapStorage::createEdgeMap(const std::string& name, MapValue::Type type,
     108    MapValue def_val)
     109{
     110  EdgeMapStore::const_iterator it = edgemaps.find(name);
     111  if (it != edgemaps.end())
     112    throw Error("Edge map " + name + " already exists.");
     113
     114  switch (type)
     115  {
     116    case MapValue::NUMERIC:
     117      edgemaps[name] = new NumericEdgeMapData(graph, def_val);
     118      break;
     119    case MapValue::STRING:
     120      edgemaps[name] = new StringEdgeMapData(graph, def_val);
     121      break;
     122  }
     123
     124  edgemaps[name]->default_value = def_val;
     125
     126  signal_edge_map.emit(name, type);
    90127}
    91128
     
    116153}
    117154
    118 
    119155std::string MapStorage::getActiveEdgeMap(int prop)
    120156{
     
    127163}
    128164
    129 std::vector<std::string> MapStorage::getEdgeMapList()
    130 {
    131   std::vector<std::string> eml;
    132   eml.resize(edgemap_storage.size());
    133   int i=0;
    134   std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=beginOfEdgeMaps();
    135   for(;emsi!=endOfEdgeMaps();emsi++)
    136     {
    137       eml[i]=(emsi->first);
    138       i++;
    139     }
    140   return eml;
    141 }
    142 
    143 std::vector<std::string> MapStorage::getNodeMapList()
    144 {
    145   std::vector<std::string> nml;
    146   nml.resize(nodemap_storage.size());
    147   int i=0;
    148   std::map< std::string,Graph::NodeMap<double> * >::iterator nmsi=beginOfNodeMaps();
    149   for(;nmsi!=endOfNodeMaps();nmsi++)
    150     {
    151       nml[i]=(nmsi->first);
    152       i++;
    153     }
    154   return nml;
     165std::vector<std::string> MapStorage::getEdgeMapList(MapType type)
     166{
     167  if (type == ALL)
     168  {
     169    std::vector<std::string> ret;
     170    for (EdgeMapStore::const_iterator it = edgemaps.begin();
     171        it != edgemaps.end(); ++it)
     172    {
     173      ret.push_back(it->first);
     174    }
     175    return ret;
     176  }
     177  else
     178  {
     179    std::vector<std::string> ret;
     180    for (EdgeMapStore::const_iterator it = edgemaps.begin();
     181        it != edgemaps.end(); ++it)
     182    {
     183      EdgeMapData* data = getEdgeMapData(it->first);
     184      MapValue::Type t = data->type();
     185      if ((t == MapValue::NUMERIC && (type & NUM)) ||
     186          (t == MapValue::STRING && (type & STR)))
     187      {
     188        ret.push_back(it->first);
     189      }
     190    }
     191    return ret;
     192  }
     193}
     194
     195std::vector<std::string> MapStorage::getNodeMapList(MapType type)
     196{
     197  if (type == ALL)
     198  {
     199    std::vector<std::string> ret;
     200    for (NodeMapStore::const_iterator it = nodemaps.begin();
     201        it != nodemaps.end(); ++it)
     202    {
     203      ret.push_back(it->first);
     204    }
     205    return ret;
     206  }
     207  else
     208  {
     209    std::vector<std::string> ret;
     210    for (NodeMapStore::const_iterator it = nodemaps.begin();
     211        it != nodemaps.end(); ++it)
     212    {
     213      NodeMapData* data = getNodeMapData(it->first);
     214      MapValue::Type t = data->type();
     215      if ((t == MapValue::NUMERIC && (type & NUM)) ||
     216          (t == MapValue::STRING && (type & STR)))
     217      {
     218        ret.push_back(it->first);
     219      }
     220    }
     221    return ret;
     222  }
    155223}
    156224
     
    160228}
    161229
    162 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value)
    163 {
    164   if( edgemap_storage.find(name) == edgemap_storage.end() )
    165     {
    166       edgemap_storage[name]=edgemap;
    167       // set the maps default value
    168       edgemap_default[name] = default_value;
    169 
    170       //announce changement in maps
    171       signal_edge_map.emit(name);
    172       return 0;
    173     }
    174   return 1;
    175 }
    176 
    177 double MapStorage::maxOfNodeMap(const std::string & name)
    178 {
    179   double max=0;
    180   for (NodeIt j(graph); j!=INVALID; ++j)
    181   {
    182     if( (*nodemap_storage[name])[j]>max )
    183     {
    184       max=(*nodemap_storage[name])[j];
    185     }
    186   }
    187   return max;
    188 }
    189 
    190 double MapStorage::maxOfEdgeMap(const std::string & name)
    191 {
    192   double max=0;
    193   for (EdgeIt j(graph); j!=INVALID; ++j)
    194   {
    195     if( (*edgemap_storage[name])[j]>max )
    196     {
    197       max=(*edgemap_storage[name])[j];
    198     }
    199   }
    200   return max;
    201 }
    202 
    203 double MapStorage::minOfNodeMap(const std::string & name)
    204 {
    205   NodeIt j(graph);
    206   double min;
    207   if(j!=INVALID)
    208     {
    209       min=(*nodemap_storage[name])[j];
    210     }
     230int MapStorage::readFromFile(const std::string &filename)
     231{
     232  using std::vector;
     233  using std::map;
     234  using std::string;
     235
     236  // check whether the .conf file exists
     237  bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(),
     238      (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
     239
     240  // check whether the .lgf file contains a gui section
     241  bool gui_data_in_lgf = false;
     242  {
     243    std::ifstream ifs(filename.c_str());
     244    std::string line;
     245    while (getline(ifs, line))
     246    {
     247      int pos = line.find("@gui");
     248      if (pos != std::string::npos)
     249      {
     250        bool only_whitespace_before = true;
     251        for (int i = 0; i < pos; ++i)
     252        {
     253          if (!std::isspace(line[i]))
     254          {
     255            only_whitespace_before = false;
     256            break;
     257          }
     258        }
     259        if (only_whitespace_before) gui_data_in_lgf = true;
     260      }
     261    }
     262  }
     263
     264  bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
     265
     266  // ask for user input if both exist
     267  bool use_gui_data_in_lgf = false;
     268  if (gui_data_in_conf && gui_data_in_lgf)
     269  {
     270    Gtk::MessageDialog mdialog(_("<b>Found both ") + filename +
     271        _(".conf and a gui section in ") + filename + _(".</b>"), true,
     272        Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_NONE);
     273          mdialog.add_button(_("Use the ._conf file"), 1);
     274          mdialog.add_button(_("Use the _gui section"), 2);
     275    switch (mdialog.run())
     276    {
     277      case 1:
     278        use_gui_data_in_lgf = false;
     279        break;
     280      case 2:
     281        use_gui_data_in_lgf = true;
     282        break;
     283      case Gtk::RESPONSE_NONE:
     284        return 1;
     285    }
     286  }
    211287  else
    212     {
    213       min=0;
    214     }
    215   for (; j!=INVALID; ++j)
    216   {
    217     if( (*nodemap_storage[name])[j]<min )
    218     {
    219       min=(*nodemap_storage[name])[j];
    220     }
    221   }
    222   return min;
    223 }
    224 
    225 double MapStorage::minOfEdgeMap(const std::string & name)
    226 {
    227   EdgeIt j(graph);
    228   double min;
    229   if(j!=INVALID)
    230     {
    231       min=(*edgemap_storage[name])[j];
    232     }
    233   else
    234     {
    235       min=0;
    236     }
    237   for (EdgeIt j(graph); j!=INVALID; ++j)
    238   {
    239     if( (*edgemap_storage[name])[j]<min )
    240     {
    241       min=(*edgemap_storage[name])[j];
    242     }
    243   }
    244   return min;
    245 }
    246 
    247 int MapStorage::readFromFile(const std::string &filename)
    248 {
    249   bool read_x = false;
    250   bool read_y = false;
    251   bool read_edge_id = false;
    252 
    253   try {
    254     LemonReader lreader(filename);
    255     ContentReader content(lreader);
    256     lreader.run();
    257 
    258     if (content.nodeSetNum() < 1)
    259     {
    260       Gtk::MessageDialog mdialog("No nodeset found in file.");
    261       mdialog.run();
     288  {
     289    use_gui_data_in_lgf = gui_data_in_lgf;
     290  }
     291
     292  if (gui_data_found)
     293  {
     294    GUISectData gui_data;
     295    if (use_gui_data_in_lgf)
     296    {
     297      // read the gui section from the .lgf file
     298      try
     299      {
     300        LemonReader lreader(filename);
     301        GuiReader gui_reader(lreader, this, gui_data);
     302        lreader.run();
     303        gui_sect_save_dest = LGF_FILE;
     304      }
     305      catch (Exception& error)
     306      {
     307        clear();
     308        return 1;
     309      }
     310    }
     311    else
     312    {
     313      // read the gui section from the .conf file
     314      try
     315      {
     316        LemonReader lreader(filename + ".conf");
     317        GuiReader gui_reader(lreader, this, gui_data);
     318        lreader.run();
     319        gui_sect_save_dest = CONF_FILE;
     320      }
     321      catch (Exception& error)
     322      {
     323        clear();
     324        return 1;
     325      }
     326    }
     327
     328    // read the graph and maps form the .lgf file
     329    try
     330    {
     331      std::string node_coord_xmap_name, node_coord_ymap_name;
     332      std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
     333
     334      if (gui_data.node_coords_save_dest ==
     335          MapStorage::SpecMapSaveOpts::NESET_SECT)
     336      {
     337        switch (gui_data.node_coords_save_map_num)
     338        {
     339          case SpecMapSaveOpts::ONE_MAP:
     340            node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x";
     341            node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y";
     342            node_coords_one_map_name = gui_data.node_coords_one_map_name;
     343            break;
     344          case SpecMapSaveOpts::TWO_MAPS:
     345            node_coord_xmap_name = gui_data.node_coords_two_maps_1_name;
     346            node_coord_ymap_name = gui_data.node_coords_two_maps_2_name;
     347            node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name;
     348            node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name;
     349            break;
     350        }
     351        node_coords_save_dest = gui_data.node_coords_save_dest;
     352        node_coords_save_map_num = gui_data.node_coords_save_map_num;
     353      }
     354
     355      if (gui_data.arrow_coords_save_dest ==
     356          MapStorage::SpecMapSaveOpts::NESET_SECT)
     357      {
     358        switch (gui_data.arrow_coords_save_map_num)
     359        {
     360          case SpecMapSaveOpts::ONE_MAP:
     361            arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x";
     362            arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y";
     363            arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name;
     364            break;
     365          case SpecMapSaveOpts::TWO_MAPS:
     366            arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name;
     367            arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name;
     368            arrow_coords_two_maps_1_name =
     369              gui_data.arrow_coords_two_maps_1_name;
     370            arrow_coords_two_maps_2_name =
     371              gui_data.arrow_coords_two_maps_2_name;
     372            break;
     373        }
     374        arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
     375        arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num;
     376      }
     377      readLGF(filename, true,
     378          gui_data.main_node_map_names, gui_data.main_edge_map_names,
     379          gui_data.node_map_types, gui_data.edge_map_types,
     380          node_coord_xmap_name, node_coord_ymap_name,
     381          arrow_coord_xmap_name, arrow_coord_ymap_name);
     382    }
     383    catch (Exception& error)
     384    {
    262385      clear();
    263386      return 1;
    264387    }
    265388
    266     if (content.edgeSetNum() < 1)
    267     {
    268       Gtk::MessageDialog mdialog("No edgeset found in file.");
    269       mdialog.run();
    270       clear();
    271       return 1;
    272     }
    273 
    274     const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
    275     const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
    276 
    277     GraphReader<Graph> greader(filename, graph);
    278     for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
    279         it != nodeMapNames.end(); ++it)
    280     {
    281       if (*it == "coordinates_x")
    282       {
    283         read_x = true;
    284         //std::cout << "read X nodemap" << std::endl;
    285       }
    286       else if (*it == "coordinates_y")
    287       {
    288         read_y = true;
    289         //std::cout << "read Y nodemap" << std::endl;
    290       }
    291       else if (*it == "label")
    292       {
    293         //std::cout << "read id nodemap" << std::endl;
     389    // add the maps from the gui section
     390    for (vector<string>::const_iterator
     391        it = gui_data.gui_node_map_names.begin();
     392        it != gui_data.gui_node_map_names.end(); ++it)
     393    {
     394      string map_name = *it;
     395      switch (gui_data.node_map_types[map_name])
     396      {
     397        case MapValue::NUMERIC:
     398          {
     399            createNodeMap(map_name, MapValue::NUMERIC, double());
     400            NumericNodeMap& dmap = getNumericNodeMap(map_name);
     401            map<int, double>& smap = *gui_data.numeric_node_maps[map_name];
     402            for (NodeIt n(graph); n != INVALID; ++n)
     403            {
     404              dmap[n] = smap[node_label[n]];
     405            }
     406            break;
     407          }
     408        case MapValue::STRING:
     409          {
     410            createNodeMap(map_name, MapValue::STRING, string());
     411            StringNodeMap& dmap = getStringNodeMap(map_name);
     412            map<int, string>& smap = *gui_data.string_node_maps[map_name];
     413            for (NodeIt n(graph); n != INVALID; ++n)
     414            {
     415              dmap[n] = smap[node_label[n]];
     416            }
     417            break;
     418          }
     419      }
     420      getNodeMapData(map_name)->save_dest = GUI_SECT;
     421    }
     422    for (vector<string>::const_iterator
     423        it = gui_data.gui_edge_map_names.begin();
     424        it != gui_data.gui_edge_map_names.end(); ++it)
     425    {
     426      string map_name = *it;
     427      switch (gui_data.edge_map_types[map_name])
     428      {
     429        case MapValue::NUMERIC:
     430          {
     431            createEdgeMap(map_name, MapValue::NUMERIC, double());
     432            NumericEdgeMap& dmap = getNumericEdgeMap(map_name);
     433            map<int, double>& smap = *gui_data.numeric_edge_maps[map_name];
     434            for (EdgeIt e(graph); e != INVALID; ++e)
     435            {
     436              dmap[e] = smap[edge_label[e]];
     437            }
     438            break;
     439          }
     440        case MapValue::STRING:
     441          {
     442            createEdgeMap(map_name, MapValue::STRING, string());
     443            StringEdgeMap& dmap = getStringEdgeMap(map_name);
     444            map<int, string>& smap = *gui_data.string_edge_maps[map_name];
     445            for (EdgeIt e(graph); e != INVALID; ++e)
     446            {
     447              dmap[e] = smap[edge_label[e]];
     448            }
     449            break;
     450          }
     451      }
     452      getEdgeMapData(map_name)->save_dest = GUI_SECT;
     453    }
     454
     455    // restore the node coordinate maps
     456    if (gui_data.node_coords_save_dest ==
     457        MapStorage::SpecMapSaveOpts::GUI_SECT)
     458    {
     459      for (NodeIt n(graph); n != INVALID; ++n)
     460      {
     461        node_coords.set(n, gui_data.node_coord_map[node_label[n]]);
     462      }
     463      node_coords_save_dest = gui_data.node_coords_save_dest;
     464    }
     465    // restore the arrow coordinate maps
     466    if (gui_data.arrow_coords_save_dest ==
     467        MapStorage::SpecMapSaveOpts::GUI_SECT)
     468    {
     469      for (EdgeIt e(graph); e != INVALID; ++e)
     470      {
     471        arrow_coords.set(e, gui_data.arrow_coord_map[edge_label[e]]);
     472      }
     473      arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
     474    }
     475  }
     476  else
     477  {
     478    // there is no gui section neither in the .lgf file nor in the .conf file
     479    {
     480      LemonReader lreader(filename);
     481      ContentReader content(lreader);
     482      try
     483      {
     484        lreader.run();
     485      }
     486      catch (Exception& error)
     487      {
     488        Gtk::MessageDialog mdialog(error.what());
     489        mdialog.run();
     490        clear();
     491        return 1;
     492      }
     493
     494      if (content.nodeSetNum() < 1)
     495      {
     496        Gtk::MessageDialog mdialog("No nodeset found in file.");
     497        mdialog.run();
     498        clear();
     499        return 1;
     500      }
     501
     502      if (content.edgeSetNum() < 1)
     503      {
     504        Gtk::MessageDialog mdialog("No edgeset found in file.");
     505        mdialog.run();
     506        clear();
     507        return 1;
     508      }
     509
     510      std::vector<std::string> nodeMapNames = content.nodeSetMaps(0);
     511      std::vector<std::string> edgeMapNames = content.edgeSetMaps(0);
     512     
     513      bool read_edge_label = true;
     514      if (std::find(edgeMapNames.begin(), edgeMapNames.end(), "label") ==
     515          edgeMapNames.end())
     516      {
     517        read_edge_label = false;
     518      }
     519
     520      nodeMapNames.erase(
     521          std::remove(nodeMapNames.begin(), nodeMapNames.end(), "label"),
     522          nodeMapNames.end());
     523
     524      edgeMapNames.erase(
     525          std::remove(edgeMapNames.begin(), edgeMapNames.end(), "label"),
     526          edgeMapNames.end());
     527
     528      FileImportDialog::ImportData data(nodeMapNames, edgeMapNames);
     529      FileImportDialog fidialog(&data);
     530      int response = fidialog.run();
     531      if (response == Gtk::RESPONSE_OK)
     532      {
     533        try
     534        {
     535          std::string node_coord_xmap_name, node_coord_ymap_name;
     536          std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
     537          bool gen_node_coords = false;
     538          bool gen_arrow_coords = false;
     539
     540          switch (data.node_coord_load_from)
     541          {
     542            case FileImportDialog::ImportData::ONE_MAP:
     543              node_coord_xmap_name = data.node_coord_one_map_name + ":x";
     544              node_coord_ymap_name = data.node_coord_one_map_name + ":y";
     545              node_coords_one_map_name = data.node_coord_one_map_name;
     546
     547              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     548              node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
     549              break;
     550            case FileImportDialog::ImportData::TWO_MAPS:
     551              node_coord_xmap_name = data.node_coord_two_maps_1_name;
     552              node_coord_ymap_name = data.node_coord_two_maps_2_name;
     553              node_coords_two_maps_1_name = data.node_coord_two_maps_1_name;
     554              node_coords_two_maps_2_name = data.node_coord_two_maps_2_name;
     555
     556              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     557              node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
     558              break;
     559            case FileImportDialog::ImportData::DONT_READ:
     560              node_coord_xmap_name = "";
     561              node_coord_ymap_name = "";
     562
     563              node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     564              gen_node_coords = true;
     565              break;
     566          }
     567
     568          switch (data.arrow_coord_load_from)
     569          {
     570            case FileImportDialog::ImportData::ONE_MAP:
     571              arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x";
     572              arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y";
     573              arrow_coords_one_map_name = data.arrow_coord_one_map_name;
     574
     575              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     576              arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
     577              break;
     578            case FileImportDialog::ImportData::TWO_MAPS:
     579              arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name;
     580              arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name;
     581              arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name;
     582              arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name;
     583
     584              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
     585              arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
     586              break;
     587            case FileImportDialog::ImportData::DONT_READ:
     588              arrow_coord_xmap_name = "";
     589              arrow_coord_ymap_name = "";
     590
     591              arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     592              gen_arrow_coords = true;
     593              break;
     594          }
     595
     596          // read edge and node maps
     597          std::vector<std::string> node_map_names;
     598          std::vector<std::string> edge_map_names;
     599          std::map<std::string, MapValue::Type> node_map_types;
     600          std::map<std::string, MapValue::Type> edge_map_types;
     601          for (std::vector<std::string>::const_iterator it =
     602              data.numeric_node_map_names.begin();
     603              it != data.numeric_node_map_names.end(); ++it)
     604          {
     605            node_map_names.push_back(*it);
     606            node_map_types[*it] = MapValue::NUMERIC;
     607          }
     608          for (std::vector<std::string>::const_iterator it =
     609              data.string_node_map_names.begin();
     610              it != data.string_node_map_names.end(); ++it)
     611          {
     612            node_map_names.push_back(*it);
     613            node_map_types[*it] = MapValue::STRING;
     614          }
     615          for (std::vector<std::string>::const_iterator it =
     616              data.numeric_edge_map_names.begin();
     617              it != data.numeric_edge_map_names.end(); ++it)
     618          {
     619            edge_map_names.push_back(*it);
     620            edge_map_types[*it] = MapValue::NUMERIC;
     621          }
     622          for (std::vector<std::string>::const_iterator it =
     623              data.string_edge_map_names.begin();
     624              it != data.string_edge_map_names.end(); ++it)
     625          {
     626            edge_map_names.push_back(*it);
     627            edge_map_types[*it] = MapValue::STRING;
     628          }
     629
     630          readLGF(filename, read_edge_label,
     631              node_map_names, edge_map_names,
     632              node_map_types, edge_map_types,
     633              node_coord_xmap_name, node_coord_ymap_name,
     634              arrow_coord_xmap_name, arrow_coord_ymap_name);
     635
     636          // generate edge labels
     637          if (!read_edge_label)
     638          {
     639            int l = 0;
     640            for (EdgeIt e(graph); e != INVALID; ++e)
     641            {
     642              edge_label[e] = l++;
     643            }
     644          }
     645
     646          if (gen_node_coords)
     647          {
     648            // generate node coordinates
     649            int node_num = 0;
     650            for (NodeIt n(graph); n != INVALID; ++n) { node_num++; }
     651            const double pi = 3.142;
     652            double step = 2 * pi / (double) node_num;
     653            int i = 0;
     654            for (NodeIt n(graph); n != INVALID; ++n)
     655            {
     656              setNodeCoords(n,
     657                  XY(250.0 * std::cos(i * step),
     658                    250.0 * std::sin(i * step)));
     659              i++;
     660            }
     661          }
     662          if (gen_arrow_coords)
     663          {
     664            // generate arrow coordinates
     665            for (EdgeIt e(graph); e != INVALID; ++e)
     666            {
     667              if (graph.source(e) == graph.target(e))
     668              {
     669                setArrowCoords(e,
     670                    getNodeCoords(graph.source(e)) + XY(0.0, 80.0));
     671              }
     672              else
     673              {
     674                setArrowCoords(e,
     675                    (getNodeCoords(graph.source(e)) +
     676                     getNodeCoords(graph.target(e))) / 2.0);
     677              }
     678            }
     679          }
     680        }
     681        catch (Exception& error)
     682        {
     683          clear();
     684          return 1;
     685        }
    294686      }
    295687      else
    296688      {
    297         nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
    298         //std::cout << "read " << *it << " nodemap" << std::endl;
    299       }
    300       greader.readNodeMap(*it, *nodemap_storage[*it]);
    301     }
    302     for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
    303         it != edgeMapNames.end(); ++it)
    304     {
    305       if (*it == "label")
    306       {
    307         //std::cout << "read id edgemap" << std::endl;
    308         read_edge_id = true;
    309       }
    310       else
    311       {
    312         edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
    313         //std::cout << "read " << *it << " edgemap" << std::endl;
    314       }
    315       greader.readEdgeMap(*it, *edgemap_storage[*it]);
    316     }
    317     GuiReader gui_reader(greader, this);
    318     greader.run();
    319   } catch (Exception& error) {
    320     Gtk::MessageDialog mdialog(error.what());
    321     mdialog.run();
    322     clear();
    323     return 1;
    324   }
    325 
    326   if (!read_edge_id)
    327   {
    328     edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
    329     int i = 1;
     689        clear();
     690        return 1;
     691      }
     692    }
     693  }
     694
     695  // set max_node_label
     696  {
     697    max_node_label = std::numeric_limits<int>::min();
     698    for (NodeIt n(graph); n != INVALID; ++n)
     699    {
     700      if (node_label[n] > max_node_label)
     701      {
     702        max_node_label = node_label[n];
     703      }
     704    }
     705  }
     706  // set max_edge_label
     707  {
     708    max_edge_label = std::numeric_limits<int>::min();
    330709    for (EdgeIt e(graph); e != INVALID; ++e)
    331710    {
    332       (*edgemap_storage["label"])[e] = i++;
    333     }
    334   }
    335 
    336   if (!read_x || !read_y)
    337   {
    338     int node_num = 0;
    339     for (NodeIt n(graph); n != INVALID; ++n)
    340     {
    341       node_num++;
    342     }
    343     const double pi = 3.142;
    344     double step = 2 * pi / (double) node_num;
    345     int i = 0;
    346     for (NodeIt n(graph); n != INVALID; ++n)
    347     {
    348       nodemap_storage["coordinates_x"]->set(n, 250.0 * std::cos(i * step));
    349       nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
    350       i++;
    351     }
    352   }
    353 
    354   if (!arrow_pos_read_ok)
    355   {
    356     arrow_pos_read_ok = false;
    357     for (EdgeIt e(graph); e != INVALID; ++e)
    358     {
    359       if (graph.source(e) == graph.target(e))
    360       {
    361         arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0));
    362       }
    363       else
    364       {
    365         arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
    366       }
    367     }
    368   }
    369 
    370   // fill in the default values for the maps
    371   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    372       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    373   {
    374     if ((it->first != "label") &&
    375         (it->first != "coordiantes_x") &&
    376         (it->first != "coordinates_y"))
    377     {
    378       nodemap_default[it->first] = 0.0;
    379     }
    380     else if (it->first == "label")
    381     {
    382       NodeIt n(graph);
    383       double max = (*nodemap_storage["label"])[n];
    384       for (; n != INVALID; ++n)
    385       {
    386         if ((*nodemap_storage["label"])[n] > max)
    387           max = (*nodemap_storage["label"])[n];
    388       }
    389       nodemap_default["label"] = max + 1.0;
    390     }
    391   }
    392   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    393       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    394   {
    395     if (it->first != "label")
    396     {
    397       edgemap_default[it->first] = 0.0;
     711      if (edge_label[e] > max_edge_label)
     712      {
     713        max_edge_label = edge_label[e];
     714      }
     715    }
     716  }
     717
     718  return 0;
     719}
     720
     721void MapStorage::writeToFile(const std::string &filename)
     722{
     723  // relabel nodes and edges
     724  int i = 0;
     725  for (NodeIt n(graph); n != INVALID; ++n)
     726  {
     727    node_label[n] = i++;
     728  }
     729  max_node_label = i-1;
     730  i = 0;
     731  for (EdgeIt e(graph); e != INVALID; ++e)
     732  {
     733    edge_label[e] = i++;
     734  }
     735  max_edge_label = i-1;
     736
     737  // write .lgf file
     738  {
     739    GraphWriter<Graph> gwriter(filename, graph);
     740
     741    gwriter.writeNodeMap("label", node_label);
     742    gwriter.writeEdgeMap("label", edge_label);
     743
     744    // write node maps
     745    for (NodeMapStore::const_iterator it = nodemaps.begin();
     746        it != nodemaps.end(); ++it)
     747    {
     748      if (it->second->save_dest == NESET_SECT)
     749      {
     750        switch (it->second->type())
     751        {
     752          case MapValue::NUMERIC:
     753            gwriter.writeNodeMap(it->first, getNumericNodeMap(it->first));
     754            break;
     755          case MapValue::STRING:
     756            gwriter.writeNodeMap(it->first, getStringNodeMap(it->first));
     757            break;
     758        }
     759      }
     760    }
     761
     762    // write edge maps
     763    for (EdgeMapStore::const_iterator it = edgemaps.begin();
     764        it != edgemaps.end(); ++it)
     765    {
     766      if (it->second->save_dest == NESET_SECT)
     767      {
     768        switch (it->second->type())
     769        {
     770          case MapValue::NUMERIC:
     771            gwriter.writeEdgeMap(it->first, getNumericEdgeMap(it->first));
     772            break;
     773          case MapValue::STRING:
     774            gwriter.writeEdgeMap(it->first, getStringEdgeMap(it->first));
     775            break;
     776        }
     777      }
     778    }
     779
     780    // write node coordinates
     781    switch (getNodeCoordsSaveDest())
     782    {
     783      case MapStorage::SpecMapSaveOpts::GUI_SECT:
     784        break;
     785      case MapStorage::SpecMapSaveOpts::NESET_SECT:
     786        switch (getNodeCoordsSaveMapNum())
     787        {
     788          case MapStorage::SpecMapSaveOpts::ONE_MAP:
     789            gwriter.writeNodeMap(node_coords_one_map_name + ":x",
     790                node_coords_x);
     791            gwriter.writeNodeMap(node_coords_one_map_name + ":y",
     792                node_coords_y);
     793            break;
     794          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
     795            gwriter.writeNodeMap(node_coords_two_maps_1_name,
     796                node_coords_x);
     797            gwriter.writeNodeMap(node_coords_two_maps_2_name,
     798                node_coords_y);
     799            break;
     800        }
     801        break;
     802    }
     803
     804    // write arrow coordinates
     805    switch (getArrowCoordsSaveDest())
     806    {
     807      case MapStorage::SpecMapSaveOpts::GUI_SECT:
     808        break;
     809      case MapStorage::SpecMapSaveOpts::NESET_SECT:
     810        switch (getArrowCoordsSaveMapNum())
     811        {
     812          case MapStorage::SpecMapSaveOpts::ONE_MAP:
     813            gwriter.writeEdgeMap(arrow_coords_one_map_name + ":x",
     814                arrow_coords_x);
     815            gwriter.writeEdgeMap(arrow_coords_one_map_name + ":y",
     816                arrow_coords_y);
     817            break;
     818          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
     819            gwriter.writeEdgeMap(arrow_coords_two_maps_1_name,
     820                arrow_coords_x);
     821            gwriter.writeEdgeMap(arrow_coords_two_maps_2_name,
     822                arrow_coords_y);
     823            break;
     824        }
     825        break;
     826    }
     827
     828    if (gui_sect_save_dest == LGF_FILE)
     829    {
     830      GuiWriter gui_writer(gwriter, this);
     831      gwriter.run();
    398832    }
    399833    else
    400834    {
    401       double max = std::numeric_limits<double>::min();
    402       for (EdgeIt e(graph); e != INVALID; ++e)
    403       {
    404         if ((*edgemap_storage["label"])[e] > max)
    405           max = (*edgemap_storage["label"])[e];
    406       }
    407       if (max > std::numeric_limits<double>::min())
    408         edgemap_default["label"] = max + 1.0;
    409       else
    410         edgemap_default["label"] = 1.0;
    411     }
    412   }
    413 
    414   return 0;
    415 }
    416 
    417 void MapStorage::writeToFile(const std::string &filename)
    418 {
    419   GraphWriter<Graph> gwriter(filename, graph);
    420 
    421   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    422       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    423   {
    424     gwriter.writeNodeMap(it->first, *(it->second));
    425   }
    426   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    427       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    428   {
    429     if ((it->first != "arrow_pos_x") &&
    430         (it->first != "arrow_pos_y"))
    431     {
    432       gwriter.writeEdgeMap(it->first, *(it->second));
    433     }
    434   }
    435 
    436   GuiWriter gui_writer(gwriter, this);
    437 
    438   gwriter.run();
     835      gwriter.run();
     836    }
     837  }
     838
     839  // write .conf file
     840  if (gui_sect_save_dest == CONF_FILE)
     841  {
     842    LemonWriter lwriter(filename + ".conf");
     843    GuiWriter gui_writer(lwriter, this);
     844    lwriter.run();
     845  }
    439846}
    440847
    441848void MapStorage::clear()
    442849{
    443   for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
    444       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    445   {
    446     if ((it->first != "coordinates_x") &&
    447         (it->first != "coordinates_y") &&
    448         (it->first != "label"))
    449     {
    450       delete it->second;
    451       nodemap_storage.erase(it);
    452     }
    453   }
    454   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
    455       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    456   {
    457     if ((it->first != "label") &&
    458         (it->first != "arrow_pos_x") &&
    459         (it->first != "arrow_pos_y"))
    460     {
    461       delete it->second;
    462       edgemap_storage.erase(it);
    463     }
    464   }
    465   for (std::map<std::string, double>::iterator it =
    466       nodemap_default.begin(); it != nodemap_default.end(); ++it)
    467   {
    468     if (it->first != "label")
    469       nodemap_default.erase(it);
    470   }
    471   for (std::map<std::string, double>::iterator it =
    472       edgemap_default.begin(); it != edgemap_default.end(); ++it)
    473   {
    474     if (it->first != "label")
    475       edgemap_default.erase(it);
     850  for (NodeMapStore::iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
     851  {
     852    delete it->second;
     853    nodemaps.erase(it);
     854  }
     855  for (EdgeMapStore::iterator it = edgemaps.begin(); it != edgemaps.end(); ++it)
     856  {
     857    delete it->second;
     858    edgemaps.erase(it);
    476859  }
    477860  graph.clear();
    478861  file_name = "";
    479862  modified = false;
    480 
    481   arrow_pos_read_ok = false;
    482  
     863  max_node_label = 0;
     864  max_edge_label = 0;
     865  background_set = false;
     866
     867  gui_sect_save_dest = LGF_FILE;
     868  node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     869  arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
     870  node_coords_one_map_name = "coord";
     871  node_coords_two_maps_1_name = "coord_x";
     872  node_coords_two_maps_2_name = "coord_y";
     873  arrow_coords_one_map_name = "arrow";
     874  arrow_coords_two_maps_1_name = "arrow_x";
     875  arrow_coords_two_maps_2_name = "arrow_y";
     876
    483877  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    484878    {
     
    500894}
    501895
    502 void MapStorage::ArrowPosReadOK()
    503 {
    504   arrow_pos_read_ok = true;
    505 }
    506 
    507896void MapStorage::mapChanged(bool itisedge, std::string mapname)
    508897{
    509898  if(itisedge)
    510     {
    511       for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    512         {
    513           if(active_edgemaps[i]==mapname)
    514             {
    515               signal_prop.emit(itisedge, i);
    516             }
    517         }
    518     }
     899  {
     900    for(int i=0;i<EDGE_PROPERTY_NUM;i++)
     901    {
     902      if(active_edgemaps[i]==mapname)
     903      {
     904        signal_prop.emit(itisedge, i);
     905      }
     906    }
     907  }
    519908  else
    520     {
    521       for(int i=0;i<NODE_PROPERTY_NUM;i++)
    522         {
    523           if(active_nodemaps[i]==mapname)
    524             {
    525               signal_prop.emit(itisedge, i);
    526             }
    527         }
    528     }
     909  {
     910    for(int i=0;i<NODE_PROPERTY_NUM;i++)
     911    {
     912      if(active_nodemaps[i]==mapname)
     913      {
     914        signal_prop.emit(itisedge, i);
     915      }
     916    }
     917  }
    529918}
    530919
     
    554943{
    555944  signal_design_win.emit(attraction, propulsation, iterations);
     945}
     946
     947XY MapStorage::getNodeCoords(Node n) const
     948{
     949  return node_coords[n];
     950}
     951
     952void MapStorage::setNodeCoords(Node n, XY c)
     953{
     954  node_coords.set(n, c);
     955}
     956
     957XY MapStorage::getArrowCoords(Edge e) const
     958{
     959  return arrow_coords[e];
     960}
     961
     962void MapStorage::setArrowCoords(Edge e, XY c)
     963{
     964  arrow_coords.set(e, c);
     965}
     966
     967MapValue MapStorage::get(const std::string& name, Node node) const
     968{
     969  NodeMapData* data = getNodeMapData(name);
     970  return data->get(node);
     971}
     972
     973void MapStorage::set(const std::string& name, Node node, MapValue val)
     974{
     975  NodeMapData* data = getNodeMapData(name);
     976  data->set(node, val);
     977}
     978
     979MapValue MapStorage::get(const std::string& name, Edge edge) const
     980{
     981  EdgeMapData* data = getEdgeMapData(name);
     982  return data->get(edge);
     983}
     984
     985void MapStorage::set(const std::string& name, Edge edge, MapValue val)
     986{
     987  EdgeMapData* data = getEdgeMapData(name);
     988  data->set(edge, val);
     989}
     990
     991const std::string& MapStorage::getFileName() const
     992{
     993  return file_name;
     994}
     995
     996void MapStorage::setFileName(const std::string& fn)
     997{
     998  file_name = fn;
     999}
     1000
     1001bool MapStorage::getModified() const
     1002{
     1003  return modified;
     1004}
     1005
     1006void MapStorage::setModified(bool m)
     1007{
     1008  modified = m;
     1009}
     1010
     1011Node MapStorage::addNode(XY coords)
     1012{
     1013  Node node = graph.addNode();
     1014
     1015  setNodeCoords(node, coords);
     1016
     1017  max_node_label++;
     1018
     1019  node_label[node] = max_node_label;
     1020
     1021  std::vector<std::string> node_maps = getNodeMapList();
     1022  for (std::vector<std::string>::const_iterator it = node_maps.begin();
     1023      it != node_maps.end(); ++it)
     1024  {
     1025    NodeMapData* data = getNodeMapData(*it);
     1026    set(*it, node, data->default_value);
     1027  }
     1028
     1029  return node;
     1030}
     1031
     1032Edge MapStorage::addEdge(Node from, Node to)
     1033{
     1034  Edge edge = graph.addEdge(from, to);
     1035
     1036  if (from == to)
     1037  {
     1038    setArrowCoords(edge, getNodeCoords(from) + XY(0.0, 80.0));
     1039  }
     1040  else
     1041  {
     1042    setArrowCoords(edge, (getNodeCoords(from) + getNodeCoords(to)) / 2.0);
     1043  }
     1044
     1045  max_edge_label++;
     1046
     1047  edge_label[edge] = max_edge_label;
     1048
     1049  std::vector<std::string> edge_maps = getEdgeMapList();
     1050  for (std::vector<std::string>::const_iterator it = edge_maps.begin();
     1051      it != edge_maps.end(); ++it)
     1052  {
     1053    EdgeMapData* data = getEdgeMapData(*it);
     1054    set(*it, edge, data->default_value);
     1055  }
     1056  return edge;
     1057}
     1058
     1059MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
     1060{
     1061  NodeMapData* data = getNodeMapData(name);
     1062  if (data->type() != MapValue::NUMERIC)
     1063    throw Error("Numeric node map " + name + " does not exists.");
     1064  return static_cast<NumericNodeMapData*>(data)->map;
     1065}
     1066
     1067MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
     1068{
     1069  NodeMapData* data = getNodeMapData(name);
     1070  if (data->type() != MapValue::STRING)
     1071    throw Error("String node map " + name + " does not exists.");
     1072  return static_cast<StringNodeMapData*>(data)->map;
     1073}
     1074
     1075MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name)
     1076{
     1077  EdgeMapData* data = getEdgeMapData(name);
     1078  if (data->type() != MapValue::NUMERIC)
     1079    throw Error("Numeric edge map " + name + " does not exists.");
     1080  return static_cast<NumericEdgeMapData*>(data)->map;
     1081}
     1082
     1083MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
     1084{
     1085  EdgeMapData* data = getEdgeMapData(name);
     1086  if (data->type() != MapValue::STRING)
     1087    throw Error("String edge map " + name + " does not exists.");
     1088  return static_cast<StringEdgeMapData*>(data)->map;
     1089}
     1090
     1091MapValueEdgeMap MapStorage::getEdgeMap(const std::string& name)
     1092{
     1093  return MapValueEdgeMap(name, this);
     1094}
     1095
     1096MapValueNodeMap MapStorage::getNodeMap(const std::string& name)
     1097{
     1098  return MapValueNodeMap(name, this);
     1099}
     1100
     1101int MapStorage::getLabel(Node n) const
     1102{
     1103  return node_label[n];
     1104}
     1105
     1106int MapStorage::getLabel(Edge e) const
     1107{
     1108  return edge_label[e];
     1109}
     1110
     1111MapStorage::GuiSectSaveDest MapStorage::getGUIDataSaveLocation()
     1112{
     1113  return gui_sect_save_dest;
     1114}
     1115
     1116void MapStorage::setGUIDataSaveLocation(MapStorage::GuiSectSaveDest dest)
     1117{
     1118  gui_sect_save_dest = dest;
     1119}
     1120
     1121MapStorage::MapSaveDest MapStorage::getNodeMapSaveDest(std::string name) const
     1122{
     1123  NodeMapData *data = getNodeMapData(name);
     1124  return data->save_dest;
     1125}
     1126
     1127MapStorage::MapSaveDest MapStorage::getEdgeMapSaveDest(std::string name) const
     1128{
     1129  EdgeMapData *data = getEdgeMapData(name);
     1130  return data->save_dest;
     1131}
     1132
     1133void MapStorage::setNodeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
     1134{
     1135  NodeMapData *data = getNodeMapData(name);
     1136  data->save_dest = dest;
     1137}
     1138
     1139void MapStorage::setEdgeMapSaveDest(std::string name, MapStorage::MapSaveDest dest)
     1140{
     1141  EdgeMapData *data = getEdgeMapData(name);
     1142  data->save_dest = dest;
     1143}
     1144
     1145MapStorage::EdgeMapData* MapStorage::getEdgeMapData(std::string name) const
     1146{
     1147  EdgeMapStore::const_iterator it = edgemaps.find(name);
     1148  if (it != edgemaps.end())
     1149    return it->second;
     1150  else
     1151    throw Error("Edge map " + name + " does not exists.");
     1152}
     1153
     1154MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
     1155{
     1156  NodeMapStore::const_iterator it = nodemaps.find(name);
     1157  if (it != nodemaps.end())
     1158    return it->second;
     1159  else
     1160    throw Error("Node map " + name + " does not exists.");
     1161}
     1162
     1163MapValue::Type MapStorage::getNodeMapElementType(std::string name) const
     1164{
     1165  NodeMapData *data = getNodeMapData(name);
     1166  return data->type();
     1167}
     1168
     1169MapValue::Type MapStorage::getEdgeMapElementType(std::string name) const
     1170{
     1171  EdgeMapData *data = getEdgeMapData(name);
     1172  return data->type();
     1173}
     1174
     1175const MapStorage::NodeLabelMap& MapStorage::getNodeLabelMap()
     1176{
     1177  return node_label;
     1178}
     1179
     1180const MapStorage::EdgeLabelMap& MapStorage::getEdgeLabelMap()
     1181{
     1182  return edge_label;
     1183}
     1184
     1185const Graph& MapStorage::getGraph()
     1186{
     1187  return graph;
     1188}
     1189
     1190bool MapStorage::nodeMapExists(std::string name)
     1191{
     1192  NodeMapStore::const_iterator it = nodemaps.find(name);
     1193  if (it == nodemaps.end())
     1194    return false;
     1195  else
     1196    return true;
     1197}
     1198
     1199bool MapStorage::edgeMapExists(std::string name)
     1200{
     1201  EdgeMapStore::const_iterator it = edgemaps.find(name);
     1202  if (it == edgemaps.end())
     1203    return false;
     1204  else
     1205    return true;
     1206}
     1207
     1208std::vector<std::string> MapStorage::getEdgeMaps(MapType type)
     1209{
     1210  std::vector<std::string> maps;
     1211  for (EdgeMapStore::const_iterator it = edgemaps.begin(); it != edgemaps.end(); ++it)
     1212  {
     1213    if (it->second->type() & type)
     1214    {
     1215      maps.push_back(it->first);
     1216    }
     1217  }
     1218  return maps;
     1219}
     1220
     1221std::vector<std::string> MapStorage::getNodeMaps(MapType type)
     1222{
     1223  std::vector<std::string> maps;
     1224  for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
     1225  {
     1226    if (it->second->type() & type)
     1227    {
     1228      maps.push_back(it->first);
     1229    }
     1230  }
     1231  return maps;
     1232}
     1233
     1234MapStorage::NodeCoordMap& MapStorage::getNodeCoordMap()
     1235{
     1236  return node_coords;
     1237}
     1238
     1239MapStorage::ArrowCoordMap& MapStorage::getArrowCoordMap()
     1240{
     1241  return arrow_coords;
     1242}
     1243
     1244MapStorage::SpecMapSaveOpts::Dest MapStorage::getNodeCoordsSaveDest()
     1245{
     1246  return node_coords_save_dest;
     1247}
     1248
     1249MapStorage::SpecMapSaveOpts::Dest MapStorage::getArrowCoordsSaveDest()
     1250{
     1251  return arrow_coords_save_dest;
     1252}
     1253
     1254void MapStorage::setNodeCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
     1255{
     1256  node_coords_save_dest = dest;
     1257}
     1258
     1259void MapStorage::setArrowCoordsSaveDest(MapStorage::SpecMapSaveOpts::Dest dest)
     1260{
     1261  arrow_coords_save_dest = dest;
     1262}
     1263
     1264MapStorage::SpecMapSaveOpts::MapNum MapStorage::getNodeCoordsSaveMapNum()
     1265{
     1266  return node_coords_save_map_num;
     1267}
     1268
     1269MapStorage::SpecMapSaveOpts::MapNum MapStorage::getArrowCoordsSaveMapNum()
     1270{
     1271  return arrow_coords_save_map_num;
     1272}
     1273
     1274void MapStorage::setNodeCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
     1275{
     1276  node_coords_save_map_num = num;
     1277}
     1278
     1279void MapStorage::setArrowCoordsSaveMapNum(MapStorage::SpecMapSaveOpts::MapNum num)
     1280{
     1281  arrow_coords_save_map_num = num;
     1282}
     1283
     1284const std::string& MapStorage::getNodeCoordsOneMapName()
     1285{
     1286  return node_coords_one_map_name;
     1287}
     1288const std::string& MapStorage::getNodeCoordsTwoMaps1Name()
     1289{
     1290  return node_coords_two_maps_1_name;
     1291}
     1292const std::string& MapStorage::getNodeCoordsTwoMaps2Name()
     1293{
     1294  return node_coords_two_maps_2_name;
     1295}
     1296
     1297void MapStorage::setNodeCoordsOneMapName(const std::string& name)
     1298{
     1299  node_coords_one_map_name = name;
     1300}
     1301void MapStorage::setNodeCoordsTwoMaps1Name(const std::string& name)
     1302{
     1303  node_coords_two_maps_1_name = name;
     1304}
     1305void MapStorage::setNodeCoordsTwoMaps2Name(const std::string& name)
     1306{
     1307  node_coords_two_maps_2_name = name;
     1308}
     1309
     1310const std::string& MapStorage::getArrowCoordsOneMapName()
     1311{
     1312  return arrow_coords_one_map_name;
     1313}
     1314const std::string& MapStorage::getArrowCoordsTwoMaps1Name()
     1315{
     1316  return arrow_coords_two_maps_1_name;
     1317}
     1318const std::string& MapStorage::getArrowCoordsTwoMaps2Name()
     1319{
     1320  return arrow_coords_two_maps_2_name;
     1321}
     1322
     1323void MapStorage::setArrowCoordsOneMapName(const std::string& name)
     1324{
     1325  arrow_coords_one_map_name = name;
     1326}
     1327void MapStorage::setArrowCoordsTwoMaps1Name(const std::string& name)
     1328{
     1329  arrow_coords_two_maps_1_name = name;
     1330}
     1331void MapStorage::setArrowCoordsTwoMaps2Name(const std::string& name)
     1332{
     1333  arrow_coords_two_maps_2_name = name;
     1334}
     1335
     1336void MapStorage::readLGF(
     1337    const std::string& filename,
     1338    bool read_edge_label,
     1339    const std::vector<std::string>& node_map_names,
     1340    const std::vector<std::string>& edge_map_names,
     1341    const std::map<std::string, MapValue::Type>& node_map_types,
     1342    const std::map<std::string, MapValue::Type>& edge_map_types,
     1343    const std::string& node_coord_xmap_name,
     1344    const std::string& node_coord_ymap_name,
     1345    const std::string& arrow_coord_xmap_name,
     1346    const std::string& arrow_coord_ymap_name)
     1347{
     1348  using std::vector;
     1349  using std::map;
     1350  using std::string;
     1351
     1352  GraphReader<Graph> greader(filename, graph);
     1353
     1354  // read the label maps
     1355  greader.readNodeMap("label", node_label);
     1356  if (read_edge_label)
     1357    greader.readEdgeMap("label", edge_label);
     1358
     1359  // read the node maps
     1360  for (vector<string>::const_iterator
     1361      it = node_map_names.begin();
     1362      it != node_map_names.end(); ++it)
     1363  {
     1364    switch (node_map_types.find(*it)->second)
     1365    {
     1366      case MapValue::NUMERIC:
     1367        {
     1368          createNodeMap(*it, MapValue::NUMERIC, double());
     1369          greader.readNodeMap(*it, getNumericNodeMap(*it));
     1370          break;
     1371        }
     1372      case MapValue::STRING:
     1373        {
     1374          createNodeMap(*it, MapValue::STRING, string());
     1375          greader.readNodeMap(*it, getStringNodeMap(*it));
     1376          break;
     1377        }
     1378    }
     1379    getNodeMapData(*it)->save_dest = NESET_SECT;
     1380  }
     1381
     1382  // read the edge maps
     1383  for (vector<string>::const_iterator
     1384      it = edge_map_names.begin();
     1385      it != edge_map_names.end(); ++it)
     1386  {
     1387    switch (edge_map_types.find(*it)->second)
     1388    {
     1389      case MapValue::NUMERIC:
     1390        {
     1391          createEdgeMap(*it, MapValue::NUMERIC, double());
     1392          greader.readEdgeMap(*it, getNumericEdgeMap(*it));
     1393          break;
     1394        }
     1395      case MapValue::STRING:
     1396        {
     1397          createEdgeMap(*it, MapValue::STRING, string());
     1398          greader.readEdgeMap(*it, getStringEdgeMap(*it));
     1399          break;
     1400        }
     1401    }
     1402    getEdgeMapData(*it)->save_dest = NESET_SECT;
     1403  }
     1404
     1405  // read the node coordinate maps
     1406  if (node_coord_xmap_name != "")
     1407    greader.readNodeMap(node_coord_xmap_name, node_coords_x);
     1408  if (node_coord_ymap_name != "")
     1409    greader.readNodeMap(node_coord_ymap_name, node_coords_y);
     1410
     1411  // read the arrow coordinate maps
     1412  if (arrow_coord_xmap_name != "")
     1413    greader.readEdgeMap(arrow_coord_xmap_name, arrow_coords_x);
     1414  if (arrow_coord_ymap_name != "")
     1415    greader.readEdgeMap(arrow_coord_ymap_name, arrow_coords_y);
     1416
     1417  greader.run();
    5561418}
    5571419
     
    6111473      if(active_nodemaps[N_RADIUS]!="")
    6121474        {
    613           _nodeSizes=*(nodemap_storage[active_nodemaps[N_RADIUS]]);
     1475          _nodeSizes=getNumericNodeMap(active_nodemaps[N_RADIUS]);
    6141476        }
    6151477      if(active_nodemaps[N_COLOR]!="")
     
    6171479          for(NodeIt ni(graph);ni!=INVALID;++ni)
    6181480            {
    619               _nodeColors[ni]=(int)((*(nodemap_storage[active_nodemaps[N_COLOR]]))[ni]);
     1481              _nodeColors[ni]=(int)get(active_nodemaps[N_COLOR], ni);
    6201482            }
    6211483        }
     
    6251487            {
    6261488              std::ostringstream o;
    627               o << ((*(nodemap_storage[active_nodemaps[N_TEXT]]))[ni]);
     1489              o << get(active_nodemaps[N_TEXT], ni);
    6281490              _nodeTextMap[ni]=o.str();       
    6291491            }
     
    6341496      if(active_edgemaps[E_WIDTH]!="")
    6351497        {
    636           _edgeWidths=*(edgemap_storage[active_edgemaps[E_WIDTH]]);
     1498          _edgeWidths=getNumericEdgeMap(active_edgemaps[E_WIDTH]);
    6371499        }
    6381500      if(active_edgemaps[E_COLOR]!="")
     
    6401502          for(EdgeIt ei(graph);ei!=INVALID;++ei)
    6411503            {
    642               _edgeColors[ei]=(int)((*(edgemap_storage[active_edgemaps[E_COLOR]]))[ei]);
     1504              _edgeColors[ei]=(int)get(active_edgemaps[E_COLOR], ei);
    6431505            }
    6441506        }
     
    6461508  if(shapemap!="Default values")
    6471509    {
    648       if((minOfNodeMap(shapemap)>=0)&&(maxOfNodeMap(shapemap)<=4))
     1510      double min = std::numeric_limits<double>::max();
     1511      double max = std::numeric_limits<double>::min();
     1512      for (NodeIt n(graph); n != INVALID; ++n)
     1513      {
     1514        double v = static_cast<double>(get(shapemap, n));
     1515        if (v < min) min = v;
     1516        if (v > max) max = v;
     1517      }
     1518      if((min>=0)&&(max<=4))
    6491519        {
    650           _shapes=*(nodemap_storage[shapemap]);
     1520          NumericNodeMap& map = static_cast<NumericNodeMapData*>(getNodeMapData(shapemap))->map;
     1521          for (NodeIt n(graph); n != INVALID; ++n)
     1522          {
     1523            _shapes[n] = static_cast<int>(map[n]);
     1524          }
    6511525        }
    6521526    }
     
    6601534    absoluteNodeSizes().absoluteEdgeWidths().
    6611535    nodeScale(2).nodeSizes(_nodeSizes).
    662     coords(coords).
     1536    coords(node_coords).
    6631537    nodeShapes(_shapes).
    6641538    nodeColors(composeMap(paletteW,_nodeColors)).
  • mapstorage.h

    r198 r201  
    2020#define MAPSTORAGE_H
    2121
    22 #include <all_include.h>
    23 #include <xymap.h>
     22class Mapstorage;
     23
     24#include <vector>
     25#include <map>
     26#include <string>
     27#include "all_include.h"
     28#include "xymap.h"
    2429#include <libgnomecanvasmm.h>
     30#include "map_value.h"
     31#include "map_value_map.h"
    2532
    2633///class MapStorage handles NodeMaps and EdgeMaps.
     
    4249  double background_scaling;
    4350public:
     51  class Error : public std::exception
     52  {
     53    private:
     54      std::string message;
     55    public:
     56      Error(const std::string& msg) : message(msg) {}
     57      virtual const char* what() const throw()
     58      {
     59        return message.c_str();
     60      }
     61      ~Error() throw() {}
     62  };
     63
    4464  void setBackground(const std::string& file_name);
    4565  const std::string& getBackgroundFilename();
     
    4767  double getBackgroundScaling();
    4868  void setBackgroundScaling(double scaling);
     69
     70  enum MapSaveDest { GUI_SECT, NESET_SECT, DONT_SAVE };
     71  enum GuiSectSaveDest { LGF_FILE, CONF_FILE };
     72  struct SpecMapSaveOpts
     73  {
     74    enum Dest { GUI_SECT, NESET_SECT };
     75    enum MapNum { ONE_MAP, TWO_MAPS };
     76  };
     77
     78  typedef Graph::NodeMap<double> NumericNodeMap;
     79  typedef Graph::NodeMap<std::string> StringNodeMap;
     80  typedef Graph::EdgeMap<double> NumericEdgeMap;
     81  typedef Graph::EdgeMap<std::string> StringEdgeMap;
     82  typedef Graph::NodeMap<int> NodeLabelMap;
     83  typedef Graph::EdgeMap<int> EdgeLabelMap;
     84  typedef XYMap<Graph::NodeMap<double> > NodeCoordMap;
     85  typedef XYMap<Graph::EdgeMap<double> > ArrowCoordMap;
     86
     87  struct EdgeMapData
     88  {
     89    /// where to save the map
     90    MapSaveDest save_dest;
     91    /// read-only or read-write
     92    bool writeable;
     93    /// default value
     94    MapValue default_value;
     95    virtual MapValue::Type type() = 0;
     96    virtual MapValue get(Edge e) = 0;
     97    virtual void set(Edge e, MapValue v) = 0;
     98    EdgeMapData(MapValue def_val) :
     99      save_dest(GUI_SECT),
     100      writeable(true),
     101      default_value(def_val)
     102    {}
     103  };
     104
     105  struct NumericEdgeMapData : public EdgeMapData
     106  {
     107    NumericEdgeMap map;
     108    MapValue::Type type() { return MapValue::NUMERIC; }
     109    MapValue get(Edge e) { return MapValue(map[e]); }
     110    void set(Edge e, MapValue v) { map.set(e, static_cast<double>(v)); }
     111    NumericEdgeMapData(Graph& g, double def_val) :
     112      EdgeMapData(MapValue(def_val)),
     113      map(g, def_val)
     114    {}
     115  };
     116
     117  struct StringEdgeMapData : public EdgeMapData
     118  {
     119    StringEdgeMap map;
     120    MapValue::Type type() { return MapValue::STRING; }
     121    MapValue get(Edge e) { return MapValue(map[e]); }
     122    void set(Edge e, MapValue v) { map.set(e, static_cast<std::string>(v)); }
     123    StringEdgeMapData(Graph& g, std::string def_val) :
     124      EdgeMapData(MapValue(def_val)),
     125      map(g, def_val)
     126    {}
     127  };
     128
     129  struct NodeMapData
     130  {
     131    /// where to save the map
     132    MapSaveDest save_dest;
     133    /// read-only or read-write
     134    bool writeable;
     135    /// default value
     136    MapValue default_value;
     137    virtual MapValue::Type type() = 0;
     138    virtual MapValue get(Node e) = 0;
     139    virtual void set(Node e, MapValue v) = 0;
     140    NodeMapData(MapValue def_val) :
     141      save_dest(GUI_SECT),
     142      writeable(true),
     143      default_value(def_val)
     144    {}
     145  };
     146
     147  struct NumericNodeMapData : public NodeMapData
     148  {
     149    NumericNodeMap map;
     150    MapValue::Type type() { return MapValue::NUMERIC; }
     151    MapValue get(Node e) { return MapValue(map[e]); }
     152    void set(Node e, MapValue v) { map.set(e, static_cast<double>(v)); }
     153    NumericNodeMapData(Graph& g, double def_val) :
     154      NodeMapData(MapValue(def_val)),
     155      map(g, def_val)
     156    {}
     157  };
     158
     159  struct StringNodeMapData : public NodeMapData
     160  {
     161    StringNodeMap map;
     162    MapValue::Type type() { return MapValue::STRING; }
     163    MapValue get(Node e) { return MapValue(map[e]); }
     164    void set(Node e, MapValue v) { map.set(e, static_cast<std::string>(v)); }
     165    StringNodeMapData(Graph& g, std::string def_val) :
     166      NodeMapData(MapValue(def_val)),
     167      map(g, def_val)
     168    {}
     169  };
     170
     171  typedef std::map<std::string, NodeMapData*> NodeMapStore;
     172  typedef std::map<std::string, EdgeMapData*> EdgeMapStore;
     173
     174  struct GUISectData
     175  {
     176    std::vector<std::string> main_node_map_names;
     177    std::vector<std::string> main_edge_map_names;
     178
     179    std::vector<std::string> gui_node_map_names;
     180    std::vector<std::string> gui_edge_map_names;
     181
     182    std::map<std::string, MapValue::Type> node_map_types;
     183    std::map<std::string, MapValue::Type> edge_map_types;
     184
     185    std::map<std::string, std::map<int, double>* > numeric_node_maps;
     186    std::map<std::string, std::map<int, std::string>* > string_node_maps;
     187
     188    std::map<std::string, std::map<int, double>* > numeric_edge_maps;
     189    std::map<std::string, std::map<int, std::string>* > string_edge_maps;
     190
     191    std::map<int, XY> node_coord_map;
     192    std::map<int, XY> arrow_coord_map;
     193
     194    SpecMapSaveOpts::Dest node_coords_save_dest;
     195    SpecMapSaveOpts::MapNum node_coords_save_map_num;
     196    std::string node_coords_one_map_name;
     197    std::string node_coords_two_maps_1_name;
     198    std::string node_coords_two_maps_2_name;
     199
     200    SpecMapSaveOpts::Dest arrow_coords_save_dest;
     201    SpecMapSaveOpts::MapNum arrow_coords_save_map_num;
     202    std::string arrow_coords_one_map_name;
     203    std::string arrow_coords_two_maps_1_name;
     204    std::string arrow_coords_two_maps_2_name;
     205
     206    ~GUISectData()
     207    {
     208      using std::map;
     209      using std::vector;
     210      using std::pair;
     211      using std::string;
     212
     213      for (map<string, map<int, double>* >::iterator it =
     214          numeric_node_maps.begin(); it != numeric_node_maps.end(); ++it)
     215      {
     216        delete it->second;
     217      }
     218      for (map<string, map<int, string>* >::iterator it =
     219          string_node_maps.begin(); it != string_node_maps.end(); ++it)
     220      {
     221        delete it->second;
     222      }
     223      for (map<string, map<int, double>* >::iterator it =
     224          numeric_edge_maps.begin(); it != numeric_edge_maps.end(); ++it)
     225      {
     226        delete it->second;
     227      }
     228      for (map<string, map<int, string>* >::iterator it =
     229          string_edge_maps.begin(); it != string_edge_maps.end(); ++it)
     230      {
     231        delete it->second;
     232      }
     233    }
     234  };
     235public:
    49236  ///The graph for which the datas are stored.
    50237  Graph graph;
     238  const Graph& getGraph();
     239
     240private:
     241  GuiSectSaveDest gui_sect_save_dest;
     242
     243  SpecMapSaveOpts::Dest node_coords_save_dest;
     244  SpecMapSaveOpts::MapNum node_coords_save_map_num;
     245  SpecMapSaveOpts::Dest arrow_coords_save_dest;
     246  SpecMapSaveOpts::MapNum arrow_coords_save_map_num;
     247
     248  NodeMapStore nodemaps;
     249  EdgeMapStore edgemaps;
     250
     251  NodeLabelMap node_label;
     252  EdgeLabelMap edge_label;
     253
    51254  /// the coordinates of the nodes
    52   XYMap<Graph::NodeMap<double> > coords;
     255  NodeCoordMap node_coords;
     256  Graph::NodeMap<double> node_coords_x;
     257  Graph::NodeMap<double> node_coords_y;
     258
    53259  /// the coordinates of the arrows on the edges
    54   XYMap<Graph::EdgeMap<double> > arrow_pos;
     260  ArrowCoordMap arrow_coords;
     261  Graph::EdgeMap<double> arrow_coords_x;
     262  Graph::EdgeMap<double> arrow_coords_y;
    55263
    56264  ///The content of the object has changed, update is needed.
     
    60268  std::string file_name;
    61269
    62   ///Stores double type NodeMaps
    63   std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
    64 
    65   ///Stores double type EdgeMaps
    66   std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
    67 
     270  // the largest node label
     271  int max_node_label;
     272
     273  // the largest edge label
     274  int max_edge_label;
     275
     276  std::string node_coords_one_map_name;
     277  std::string node_coords_two_maps_1_name;
     278  std::string node_coords_two_maps_2_name;
     279
     280  std::string arrow_coords_one_map_name;
     281  std::string arrow_coords_two_maps_1_name;
     282  std::string arrow_coords_two_maps_2_name;
     283
     284public:
    68285  ///Stores the default values for the different visualization node attributes
    69286  std::vector<Graph::NodeMap<double> > default_nodemaps;
     
    77294  /// Stores the active maps for the different visualization edge attributes
    78295  std::vector< std::string > active_edgemaps;
    79 
    80   /// Default values for the maps
    81   std::map< std::string, double > nodemap_default;
    82 
    83   /// Default values for the maps
    84   std::map< std::string, double > edgemap_default;
    85 
    86   bool arrow_pos_read_ok;
    87296
    88297protected:
     
    99308  /// std::string is the
    100309  ///name of the new map
    101   sigc::signal<void, std::string> signal_node_map;
     310  sigc::signal<void, std::string, MapValue::Type> signal_node_map;
    102311
    103312  /// Signal emitted in the case of edgemap addition
     
    105314  /// std::string is the
    106315  ///name of the new map
    107   sigc::signal<void, std::string> signal_edge_map;
     316  sigc::signal<void, std::string, MapValue::Type> signal_edge_map;
    108317
    109318  /// Signal emitted, when entry in \ref MapWin should be changed.
     
    165374
    166375  /// Returns the names of the edgemaps stored here.
    167   std::vector<std::string> getEdgeMapList();
     376  std::vector<std::string> getEdgeMapList(MapType type = ALL);
    168377
    169378  /// Returns the names of the nodemaps stored here.
    170   std::vector<std::string> getNodeMapList();
     379  std::vector<std::string> getNodeMapList(MapType type = ALL);
    171380
    172381  ///returns \ref signal_prop to be able to connect functions to it
     
    174383
    175384  ///returns \ref signal_node_map to be able to connect functions to it
    176   sigc::signal<void, std::string> signal_node_map_ch(){return signal_node_map;};
     385  sigc::signal<void, std::string, MapValue::Type> signal_node_map_ch(){return signal_node_map;};
    177386
    178387  ///returns \ref signal_edge_map to be able to connect functions to it
    179   sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
     388  sigc::signal<void, std::string, MapValue::Type> signal_edge_map_ch(){return signal_edge_map;};
    180389
    181390  ///returns \ref signal_map_win to be able to connect functions to it
     
    185394  sigc::signal<void, double, double, int> signal_design_win_ch(){return signal_design_win;};
    186395
     396  void createNodeMap(const std::string& name, MapValue::Type type,
     397    MapValue def_val);
     398  void createEdgeMap(const std::string& name, MapValue::Type type,
     399    MapValue def_val);
     400
    187401  ///returns \ref signal_background to be able to connect functions to it
    188402  sigc::signal<void> signal_background_ch(){return signal_background;};
     
    190404
    191405  ///Adds given map to storage.
    192 
    193   ///A name and the map itself has to be provided.
    194   ///\param mapname is the name of map
    195   ///\param nodemap is the pointer of the given nodemap
    196   ///\param def the default value of the map. If not given, it will be 0.
    197   ///If new edge is added to graph the value of it in the map will be this.
    198   ///\todo map should be given by reference!
    199   ///\todo why is default value stored?
    200   int addNodeMap(const std::string & mapname,Graph::NodeMap<double> * nodemap, double def=0.0);
    201 
    202   ///Adds given map to storage. A name and the map itself has to be provided.
    203 
    204   ///A name and the map itself has to be provided.
    205   ///\param mapname is the name of map
    206   ///\param edgemap is the pointer of the given edgemap
    207   ///\param def the default value of the map. If not given, it will be 0.
    208   ///If new edge is added to graph the value of it in the map will be this.
    209   ///\todo map should be given by reference!
    210   int addEdgeMap(const std::string & mapname,Graph::EdgeMap<double> * edgemap, double def=0.0);
    211 
    212   ///Returns how much nodemaps is stored in \ref MapStorage
    213   int numOfNodeMaps() {return nodemap_storage.size();};
    214 
    215   ///Returns how much edgemaps is stored in \ref MapStorage
    216   int numOfEdgeMaps() {return edgemap_storage.size();};
    217 
    218   ///Returns the maximum value of the given NodeMap.
    219 
    220   ///NodeMap has to be given by its name.
    221   ///\param name the name of map of which maximum is searched
    222   double maxOfNodeMap(const std::string & name);
    223 
    224   ///Returns the maximum value of the given EdgeMap.
    225 
    226   ///EdgeMap has to be given by its name.
    227   ///\param name the name of map of which maximum is searched
    228   double maxOfEdgeMap(const std::string & name);
    229 
    230   ///Returns the minimum value of the given NodeMap.
    231 
    232   ///NodeMap has to be given by its name.
    233   ///\param name the name of map of which minimum is searched
    234   double minOfNodeMap(const std::string & name);
    235 
    236   ///Returns the minimum value of the given EdgeMap.
    237 
    238   ///EdgeMap has to be given by its name.
    239   ///\param name the name of map of which minimum is searched
    240   double minOfEdgeMap(const std::string & name);
    241 
    242   ///Returns iterator pointing to the first NodeMap in storage.
    243 
    244   ///To be able to iterate through each maps this function
    245   ///returns an iterator pointing to the first nodemap in
    246   ///the storage.
    247   std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
    248 
    249   ///Returns iterator pointing to the first EdgeMap in storage.
    250 
    251   ///To be able to iterate through each maps this function
    252   ///returns an iterator pointing to the first edgemap in
    253   ///the storage.
    254   std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
    255 
    256   ///Returns iterator pointing after the last NodeMap in storage.
    257 
    258   ///To be able to iterate through each maps this function
    259   ///returns an iterator pointing to the last nodemap in the storage.
    260   std::map< std::string,Graph::NodeMap<double> * >::iterator endOfNodeMaps(){return nodemap_storage.end();};
    261 
    262   ///Returns iterator pointing after the last EdgeMap in storage.
    263 
    264   ///To be able to iterate through each maps this function
    265   ///returns an iterator pointing to the last edgemap in the storage.
    266   std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();};
    267406
    268407  ///Emits \ref signal_prop if mapvalues have changed, and MapStorage gets to know it.
     
    286425  void clear();
    287426
    288   void ArrowPosReadOK();
    289 
    290427  void get_design_data(double &, double &, int &);
    291428  void set_attraction(double);
     
    295432  void redesign_data_changed();
    296433
     434  XY getNodeCoords(Node n) const;
     435  void setNodeCoords(Node n, XY c);
     436  XY getArrowCoords(Edge e) const;
     437  void setArrowCoords(Edge e, XY c);
     438
     439  MapValue get(const std::string& name, Node node) const;
     440  void set(const std::string& name, Node node, MapValue val);
     441  MapValue get(const std::string& name, Edge edge) const;
     442  void set(const std::string& name, Edge edge, MapValue val);
     443
     444  const std::string& getFileName() const;
     445  void setFileName(const std::string& fn);
     446
     447  bool getModified() const;
     448  void setModified(bool m = true);
     449
     450  Node addNode(XY);
     451  Edge addEdge(Node, Node);
     452
     453  NumericNodeMap& getNumericNodeMap(const std::string& name);
     454  StringNodeMap& getStringNodeMap(const std::string& name);
     455  NumericEdgeMap& getNumericEdgeMap(const std::string& name);
     456  StringEdgeMap& getStringEdgeMap(const std::string& name);
     457
     458  MapValueEdgeMap getEdgeMap(const std::string& name);
     459  MapValueNodeMap getNodeMap(const std::string& name);
     460
     461  int getLabel(Node) const;
     462  int getLabel(Edge) const;
     463
     464  GuiSectSaveDest getGUIDataSaveLocation();
     465  void setGUIDataSaveLocation(GuiSectSaveDest dest);
     466
     467  MapSaveDest getNodeMapSaveDest(std::string name) const;
     468  MapSaveDest getEdgeMapSaveDest(std::string name) const;
     469  void setNodeMapSaveDest(std::string name, MapSaveDest dest);
     470  void setEdgeMapSaveDest(std::string name, MapSaveDest dest);
     471
     472  SpecMapSaveOpts::Dest getNodeCoordsSaveDest();
     473  SpecMapSaveOpts::Dest getArrowCoordsSaveDest();
     474  void setNodeCoordsSaveDest(SpecMapSaveOpts::Dest dest);
     475  void setArrowCoordsSaveDest(SpecMapSaveOpts::Dest dest);
     476
     477  SpecMapSaveOpts::MapNum getNodeCoordsSaveMapNum();
     478  SpecMapSaveOpts::MapNum getArrowCoordsSaveMapNum();
     479  void setNodeCoordsSaveMapNum(SpecMapSaveOpts::MapNum num);
     480  void setArrowCoordsSaveMapNum(SpecMapSaveOpts::MapNum num);
     481
     482  MapValue::Type getNodeMapElementType(std::string name) const;
     483  MapValue::Type getEdgeMapElementType(std::string name) const;
     484
     485  const NodeLabelMap& getNodeLabelMap();
     486  const EdgeLabelMap& getEdgeLabelMap();
     487
     488  bool nodeMapExists(std::string name);
     489  bool edgeMapExists(std::string name);
     490
     491  std::vector<std::string> getEdgeMaps(MapType type = ALL);
     492  std::vector<std::string> getNodeMaps(MapType type = ALL);
     493
     494  NodeCoordMap& getNodeCoordMap();
     495  ArrowCoordMap& getArrowCoordMap();
     496
     497  const std::string& getNodeCoordsOneMapName();
     498  const std::string& getNodeCoordsTwoMaps1Name();
     499  const std::string& getNodeCoordsTwoMaps2Name();
     500  void setNodeCoordsOneMapName(const std::string& name);
     501  void setNodeCoordsTwoMaps1Name(const std::string& name);
     502  void setNodeCoordsTwoMaps2Name(const std::string& name);
     503
     504  const std::string& getArrowCoordsOneMapName();
     505  const std::string& getArrowCoordsTwoMaps1Name();
     506  const std::string& getArrowCoordsTwoMaps2Name();
     507  void setArrowCoordsOneMapName(const std::string& name);
     508  void setArrowCoordsTwoMaps1Name(const std::string& name);
     509  void setArrowCoordsTwoMaps2Name(const std::string& name);
     510
     511private:
     512  EdgeMapData* getEdgeMapData(std::string name) const;
     513  NodeMapData* getNodeMapData(std::string name) const;
     514  void readLGF(
     515      const std::string& filename,
     516      bool read_edge_label,
     517      const std::vector<std::string>& node_map_names,
     518      const std::vector<std::string>& edge_map_names,
     519      const std::map<std::string, MapValue::Type>& node_map_types,
     520      const std::map<std::string, MapValue::Type>& edge_map_types,
     521      const std::string& node_coord_xmap_name,
     522      const std::string& node_coord_ymap_name,
     523      const std::string& arrow_coord_xmap_name,
     524      const std::string& arrow_coord_ymap_name);
     525
     526public:
    297527  void exportGraphToEPS(std::vector<bool>, std::string, std::string);
    298528};
  • nbtab.cc

    r198 r201  
    3131
    3232  Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
     33  pScrolledWindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
    3334  gd_canvas=new GraphDisplayerCanvas(*this);
    3435  pScrolledWindow->add(*gd_canvas);
     
    4748{
    4849  mapstorage->readFromFile(file);
    49   mapstorage->file_name = file;
    50   mapstorage->modified = false;
     50  mapstorage->setFileName(file);
     51  mapstorage->setModified(false);
    5152  gd_canvas->drawGraph();
    5253  if(mapwinexists)
    5354    {
    54       mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
     55      mapwin->update(
     56          mapstorage->getEdgeMapList(NUM),
     57          mapstorage->getEdgeMapList(STR),
     58          mapstorage->getNodeMapList(NUM),
     59          mapstorage->getNodeMapList(STR));
    5560    }
    5661  title_changed(Glib::filename_display_basename(file));
     
    5964void NoteBookTab::newFile()
    6065{
    61   if (mapstorage->modified)
     66  if (mapstorage->getModified())
    6267  {
    6368    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
     
    8186  if(mapwinexists)
    8287    {
    83       mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
     88      mapwin->update(
     89          mapstorage->getEdgeMapList(NUM),
     90          mapstorage->getEdgeMapList(STR),
     91          mapstorage->getNodeMapList(NUM),
     92          mapstorage->getNodeMapList(STR));
    8493    }
    8594  title_changed("unsaved file");
     
    8897void NoteBookTab::openFile()
    8998{
    90   if (mapstorage->modified)
     99  if (mapstorage->getModified())
    91100  {
    92101    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
     
    116125    if (!mapstorage->readFromFile(filename))
    117126    {
    118       mapstorage->file_name = filename;
    119       mapstorage->modified = false;
     127      mapstorage->setFileName(filename);
     128      mapstorage->setModified(false);
    120129      gd_canvas->drawGraph();
    121130      if(mapwinexists)
    122131        {
    123           mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
     132          mapwin->update(
     133              mapstorage->getEdgeMapList(NUM),
     134              mapstorage->getEdgeMapList(STR),
     135              mapstorage->getNodeMapList(NUM),
     136              mapstorage->getNodeMapList(STR));
    124137        }
    125138      title_changed(Glib::filename_display_basename(filename));
     
    130143void NoteBookTab::saveFile()
    131144{
    132   if (mapstorage->file_name == "") {
     145  if (mapstorage->getFileName() == "") {
    133146    saveFileAs();
    134147  }
    135148  else
    136149  {
    137     mapstorage->writeToFile(mapstorage->file_name);
    138     mapstorage->modified = false;
    139     title_changed(Glib::filename_display_basename(mapstorage->file_name));
     150    mapstorage->writeToFile(mapstorage->getFileName());
     151    mapstorage->setModified(false);
     152    title_changed(Glib::filename_display_basename(mapstorage->getFileName()));
    140153  }
    141154}
     
    149162  {
    150163    Glib::ustring filename = fcdialog.get_filename();
    151     mapstorage->file_name = filename;
     164    mapstorage->setFileName(filename);
    152165    mapstorage->writeToFile(filename);
    153     mapstorage->modified = false;
     166    mapstorage->setModified(false);
    154167    title_changed(Glib::filename_display_basename(filename));
    155168  }
     
    158171void NoteBookTab::close()
    159172{
    160   if (mapstorage->modified)
     173  if (mapstorage->getModified())
    161174  {
    162175    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
     
    180193  if(mapwinexists)
    181194    {
    182       mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
     195      mapwin->update(
     196          mapstorage->getEdgeMapList(NUM),
     197          mapstorage->getEdgeMapList(STR),
     198          mapstorage->getNodeMapList(NUM),
     199          mapstorage->getNodeMapList(STR));
    183200    }
    184201  title_changed("unsaved file");
     
    210227}
    211228
    212 void NoteBookTab::registerNewEdgeMap(std::string mapname)
    213 {
    214   if(mapwinexists)
    215     {
    216       mapwin->registerNewEdgeMap(mapname);
    217     }
    218 }
    219 
    220 void NoteBookTab::registerNewNodeMap(std::string mapname)
    221 {
    222   if(mapwinexists)
    223     {
    224       mapwin->registerNewNodeMap(mapname);
     229void NoteBookTab::registerNewEdgeMap(std::string mapname, MapValue::Type type)
     230{
     231  if(mapwinexists)
     232    {
     233      mapwin->registerNewEdgeMap(mapname, type);
     234    }
     235}
     236
     237void NoteBookTab::registerNewNodeMap(std::string mapname, MapValue::Type type)
     238{
     239  if(mapwinexists)
     240    {
     241      mapwin->registerNewNodeMap(mapname, type);
    225242    }
    226243  if(epswinexists)
    227244    {
    228       epswin->registerNewNodeMap(mapname);
     245      epswin->registerNewNodeMap(mapname, type);
    229246    }
    230247}
     
    234251  if(!mapwinexists)
    235252    {
    236       mapwin=new MapWin("Map Setup - "+name, mapstorage->getEdgeMapList(), mapstorage->getNodeMapList(), *this);
     253      mapwin=new MapWin("Map Setup - "+name,
     254          mapstorage->getEdgeMapList(NUM),
     255          mapstorage->getEdgeMapList(STR),
     256          mapstorage->getNodeMapList(NUM),
     257          mapstorage->getNodeMapList(STR),
     258          *this);
    237259      mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
    238260      mapwin->show();
     
    245267  if(!epswinexists)
    246268    {
    247       epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList());
     269      epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList(NUM), mapstorage->getNodeMapList(STR));
    248270      epswin->show();
    249271      epswinexists=true;
     
    264286      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
    265287
    266       designwin->signal_attraction().connect(sigc::mem_fun(mapstorage, &MapStorage::set_attraction));
    267       designwin->signal_propulsation().connect(sigc::mem_fun(mapstorage, &MapStorage::set_propulsation));
    268       designwin->signal_iteration().connect(sigc::mem_fun(mapstorage, &MapStorage::set_iteration));
     288      designwin->signal_attraction().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_attraction));
     289      designwin->signal_propulsation().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_propulsation));
     290      designwin->signal_iteration().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_iteration));
    269291      designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::reDesignGraph));
    270292
  • nbtab.h

    r198 r201  
    2828#include <libgnomecanvasmm.h>
    2929#include <libgnomecanvasmm/polygon.h>
     30#include "map_value.h"
    3031
    3132///One tab in the Notebook that is placed in the main window (\ref MainWin).
     
    173174  ///This call-forwarder function is needed, because \ref Mapstorage does not know \ref MapWin
    174175  ///\param mapname name of new map
    175   void registerNewEdgeMap(std::string mapname);
     176  void registerNewEdgeMap(std::string mapname, MapValue::Type type);
    176177
    177178  ///Registers recently created nodemap in \ref MapWin.
     
    182183  ///This call-forwarder function is needed, because \ref Mapstorage does not know \ref MapWin
    183184  ///\param mapname name of new map
    184   void registerNewNodeMap(std::string mapname);
     185  void registerNewNodeMap(std::string mapname, MapValue::Type type);
    185186
    186187  ///Pops up and registrates the \ref MapWin of \ref NoteBookTab.
  • new_map_win.cc

    r194 r201  
    3030}
    3131
    32 NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap")
     32NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode, MapType type):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap"),map_type(type)
    3333{
    3434  set_default_size(200, 50);
     
    3939
    4040  //entries
    41   table=new Gtk::Table(3, 2, false);
     41  table=new Gtk::Table(5, 2, false);
    4242
    4343  label=new Gtk::Label;
     
    4848  (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    4949
     50  lblType.set_label("Element type:");
     51  if (map_type & NUM)
     52    cbType.append_text("Numeric");
     53  if (map_type & STR)
     54    cbType.append_text("String");
     55  cbType.set_active(0);
     56
     57  (*table).attach(lblType,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
     58  (*table).attach(cbType, 1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
     59
    5060  label=new Gtk::Label;
    5161  label->set_text("Default value in the map:");
    5262  default_value.set_text("0");
    5363
    54   (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    55   (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
     64  (*table).attach(*label,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
     65  (*table).attach(default_value,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    5666
    5767  //node vs. edge map selector
    5868  Gtk::RadioButton::Group group = node.get_group();
    5969  edge.set_group(group);
    60  
     70
    6171  if(edgenode)
    62     {
    63       (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    64       (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    65     }
     72  {
     73    (*table).attach(node,0,1,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
     74    (*table).attach(edge,1,2,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
     75  }
    6676  else
    67     {
    68       if(itisedge)
    69         {
    70           edge.set_active();
    71         }
    72       else
    73         {
    74           node.set_active();
    75         }
    76     }
     77  {
     78    if(itisedge)
     79    {
     80      edge.set_active();
     81    }
     82    else
     83    {
     84      node.set_active();
     85    }
     86  }
     87
     88  (*table).attach(lblErrorMsg,0,2,4,5,Gtk::SHRINK,Gtk::SHRINK,10,3);
    7789
    7890  vbox->pack_start(*table);
     
    8597}
    8698
     99void NewMapWin::setErrorMsg(const Glib::ustring& msg)
     100{
     101  lblErrorMsg.set_markup("<i><small>" + msg + "</small></i>");
     102}
     103
     104std::vector<double>* NewMapWin::evaluate_expr(const std::string polishform, bool itisedge)
     105{
     106  MapStorage& ms = *mytab.mapstorage;
     107
     108  std::vector<double>* ret = new std::vector<double>;
     109  std::stack<double> polishstack;
     110
     111  if (itisedge)
     112  {
     113    for(EdgeIt k(ms.graph); k!=INVALID; ++k)
     114    {
     115      for(int i=0;i<(int)polishform.size();i++)
     116      {
     117        double op1=0, op2=0;
     118        bool operation=true;
     119        switch(polishform[i])
     120        {
     121          case '+':
     122          case '-':
     123          case '/':
     124          case '*':
     125            op1=polishstack.top();
     126            polishstack.pop();
     127            op2=polishstack.top();
     128            polishstack.pop();
     129            break;
     130          default:
     131            //substitute variable
     132            std::vector<std::string> maps = ms.getEdgeMapList(NUM);
     133            bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
     134            if(itisvar)
     135            {
     136              polishstack.push(ms.get(ch2var[ polishform[i] ], k));
     137            }
     138            else
     139            {
     140              polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
     141            }
     142            operation=false;
     143            break;
     144        }
     145        if(operation)
     146        {
     147          double res;
     148          switch(polishform[i])
     149          {
     150            case '+':
     151              res=op1+op2;
     152              break;
     153            case '-':
     154              res=op2-op1;
     155              break;
     156            case '/':
     157              res=op2/op1;
     158              break;
     159            case '*':
     160              res=op1*op2;
     161              break;
     162            default:
     163              std::cout << "How could we get here?" << std::endl;
     164              break;
     165          }
     166          polishstack.push(res);
     167        }
     168      }//foreach letter in polishform
     169      ret->push_back(polishstack.top());
     170    }//foreach edge
     171  }
     172  else
     173  {
     174    for(NodeIt k(ms.graph); k!=INVALID; ++k)
     175    {
     176      for(int i=0;i<(int)polishform.size();i++)
     177      {
     178        double op1=0, op2=0;
     179        bool operation=true;
     180        switch(polishform[i])
     181        {
     182          case '+':
     183          case '-':
     184          case '/':
     185          case '*':
     186            op1=polishstack.top();
     187            polishstack.pop();
     188            op2=polishstack.top();
     189            polishstack.pop();
     190            break;
     191          default:
     192            //substitute variable
     193            std::vector<std::string> maps = ms.getNodeMapList(NUM);
     194            bool itisvar=(std::find(maps.begin(), maps.end(), ch2var[ polishform[i] ]) != maps.end());
     195            if(itisvar)
     196            {
     197              polishstack.push(ms.get(ch2var[ polishform[i] ], k));
     198            }
     199            else
     200            {
     201              polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
     202            }
     203            operation=false;
     204            break;
     205        }
     206        if(operation)
     207        {
     208          double res;
     209          switch(polishform[i])
     210          {
     211            case '+':
     212              res=op1+op2;
     213              break;
     214            case '-':
     215              res=op2-op1;
     216              break;
     217            case '/':
     218              res=op2/op1;
     219              break;
     220            case '*':
     221              res=op1*op2;
     222              break;
     223            default:
     224              std::cout << "How could we get here?" << std::endl;
     225              break;
     226          }
     227          polishstack.push(res);
     228        }
     229      }//foreach letter in polishform
     230      ret->push_back(polishstack.top());
     231    }//foreach edge
     232  }
     233  return ret;
     234}
     235
    87236void NewMapWin::on_response(int response_id)
    88237{
     238  MapStorage& ms = *mytab.mapstorage;
     239
    89240  if(response_id==Gtk::RESPONSE_OK)
    90     {
    91       double def_val=0;
    92 
    93       //get and formulate text
    94       std::string def_val_str=default_value.get_text();
    95 
    96       bool only_nums=true;
    97       for(int i=0;i<(int)def_val_str.size() && only_nums;i++)
    98         {
    99           if( def_val_str[i]<'0' || def_val_str[i]>'9' )
    100             {
    101               only_nums=false;
    102             }
    103         }
    104       std::string polishform;
    105 
    106       if(only_nums)
    107         {
    108           def_val=atof(def_val_str.c_str());
    109         }
     241  {
     242    std::string map_name = name.get_text();
     243    std::string def_val = default_value.get_text();
     244
     245    if (map_name.empty())
     246    {
     247      setErrorMsg("No map name given.");
     248      return;
     249    }
     250
     251    // check whether the map already exists
     252    if (edge.get_active())
     253    {
     254      if (ms.edgeMapExists(map_name))
     255      {
     256        setErrorMsg("Map '" + map_name + "' already exists.");
     257        return;
     258      }
     259    }
     260    else
     261    {
     262      if (ms.nodeMapExists(map_name))
     263      {
     264        setErrorMsg("Map '" + map_name + "' already exists.");
     265        return;
     266      }
     267    }
     268
     269    Glib::ustring text = cbType.get_active_text();
     270    if (text == "Numeric")
     271    {
     272      double d;
     273      char *endptr;
     274      d = strtod(def_val.c_str(), &endptr);
     275      if (def_val.c_str() + def_val.length() == endptr)
     276      {
     277        // the full string was a number
     278        if (edge.get_active())
     279          ms.createEdgeMap(map_name, MapValue::NUMERIC,
     280              MapValue(d));
     281        else
     282          ms.createNodeMap(map_name, MapValue::NUMERIC,
     283              MapValue(d));
     284      }
    110285      else
    111         {
    112           polishform=string2Polishform(def_val_str,edge.get_active());
    113         }
    114 
    115       //get name of text
    116       std::string mapname=name.get_text();
    117      
    118       if(!mapname.empty()&&(!polishform.empty()||only_nums))
    119         {
    120           int abortion=0;
    121           if(edge.get_active())
    122             {
    123               //create the new map
    124               Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mytab.mapstorage->graph, def_val);
    125              
    126               if(!only_nums)
    127                 {
    128                   std::stack<double> polishstack;
    129                  
    130                   for(EdgeIt k(mytab.mapstorage->graph); k!=INVALID; ++k)
    131                     {
    132                       for(int i=0;i<(int)polishform.size();i++)
    133                         {
    134                           double op1=0, op2=0;
    135                           bool operation=true;
    136                           switch(polishform[i])
    137                             {
    138                             case '+':
    139                             case '-':
    140                             case '/':
    141                             case '*':
    142                               op1=polishstack.top();
    143                               polishstack.pop();
    144                               op2=polishstack.top();
    145                               polishstack.pop();
    146                               break;
    147                             default:
    148                               //substitute variable
    149                               std::map< std::string,Graph::EdgeMap<double> * > ems=mytab.mapstorage->edgemap_storage;
    150                               bool itisvar=(ems.find(ch2var[ polishform[i] ])!=ems.end());
    151                               if(itisvar)
    152                                 {
    153                                   polishstack.push( (*(mytab.mapstorage->edgemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    154                                 }
    155                               else
    156                                 {
    157                                   polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    158                                 }
    159                               operation=false;
    160                               break;
    161                             }
    162                           if(operation)
    163                             {
    164                               double res;
    165                               switch(polishform[i])
    166                                 {
    167                                 case '+':
    168                                   res=op1+op2;
    169                                   break;
    170                                 case '-':
    171                                   res=op2-op1;
    172                                   break;
    173                                 case '/':
    174                                   res=op2/op1;
    175                                   break;
    176                                 case '*':
    177                                   res=op1*op2;
    178                                   break;
    179                                 default:
    180                                   std::cout << "How could we get here?" << std::endl;
    181                                   break;
    182                                 }
    183                               polishstack.push(res);
    184                             }
    185                         }//foreach letter in polishform
    186                       (*emptr)[k]=polishstack.top();
    187                     }//foreach edge
    188                 }//!only_nums
    189 
    190               //if addition was not successful addEdgeMap returns one.
    191               //cause can be that there is already a map named like the new one
    192               if(mytab.mapstorage->addEdgeMap(mapname, emptr, def_val))
    193                 {
    194                   abortion=1;
    195                 }
    196 
    197               //add it to the list of the displayable maps
    198               //furthermore it is done by signals
    199               //mytab.registerNewEdgeMap(mapname);
    200 
    201               //display it
    202               //gdc.changeEdgeText(mapname);
    203             }
    204           else //!edge.get_active()
    205             {
    206               //create the new map
    207               Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mytab.mapstorage->graph, def_val);
    208 
    209               if(!only_nums)
    210                 {
    211                   std::stack<double> polishstack;
    212  
    213                   for(NodeIt k(mytab.mapstorage->graph); k!=INVALID; ++k)
    214                     {
    215                       for(int i=0;i<(int)polishform.size();i++)
    216                         {
    217                           double op1=0, op2=0;
    218                           bool operation=true;
    219                           switch(polishform[i])
    220                             {
    221                             case '+':
    222                             case '-':
    223                             case '/':
    224                             case '*':
    225                               op1=polishstack.top();
    226                               polishstack.pop();
    227                               op2=polishstack.top();
    228                               polishstack.pop();
    229                               break;
    230                             default:
    231                               std::map< std::string,Graph::NodeMap<double> * > nms=mytab.mapstorage->nodemap_storage;
    232                               bool itisvar=(nms.find(ch2var[ polishform[i] ])!=nms.end());
    233                               if(itisvar)
    234                                 {
    235                                   polishstack.push( (*(mytab.mapstorage->nodemap_storage[ ch2var[ polishform[i] ] ]))[k]);
    236                                 }
    237                               else
    238                                 {
    239                                   polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
    240                                 }
    241                               operation=false;
    242                               break;
    243                             }
    244                           if(operation)
    245                             {
    246                               double res;
    247                               switch(polishform[i])
    248                                 {
    249                                 case '+':
    250                                   res=op1+op2;
    251                                   break;
    252                                 case '-':
    253                                   res=op2-op1;
    254                                   break;
    255                                 case '/':
    256                                   res=op2/op1;
    257                                   break;
    258                                 case '*':
    259                                   res=op1*op2;
    260                                   break;
    261                                 default:
    262                                   std::cout << "How could we get here?" << std::endl;
    263                                   break;
    264                                 }
    265                               polishstack.push(res);
    266                             }
    267                         }
    268                       (*emptr)[k]=polishstack.top();
    269                     }
    270                 }
    271               //if addition was not successful addNodeMap returns one.
    272               //cause can be that there is already a map named like the new one
    273               if(mytab.mapstorage->addNodeMap(mapname,emptr, def_val))
    274                 {
    275                   abortion=1;
    276                 }
    277 
    278               //add it to the list of the displayable maps
    279               //furthermore it is done by signals
    280               //mytab.registerNewNodeMap(mapname);
    281 
    282               //display it
    283               //gdc.changeNodeText(mapname);
    284             }
    285           if(!abortion)
    286             {
    287               name.set_text("");
    288               default_value.set_text("0");
    289               edge.show();
    290               node.show();
    291               hide();
    292             }
    293         }
    294     }
     286      {
     287        // let't try to evaluate the string as an arithmetic expression
     288        std::string polishform =
     289          string2Polishform(def_val, edge.get_active());
     290        if (polishform.empty())
     291          return;
     292        std::vector<double>* values =
     293          evaluate_expr(polishform, edge.get_active());
     294        if (edge.get_active())
     295        {
     296          ms.createEdgeMap(map_name, MapValue::NUMERIC,
     297              MapValue(0.0));
     298          std::vector<double>::const_iterator vit = values->begin();
     299          for (EdgeIt it(ms.graph); it != INVALID; ++it)
     300          {
     301            ms.set(map_name, it, MapValue(*vit));
     302            ++vit;
     303          }
     304        }
     305        else
     306        {
     307          ms.createNodeMap(map_name, MapValue::NUMERIC,
     308              MapValue(0.0));
     309          std::vector<double>::const_iterator vit = values->begin();
     310          for (NodeIt it(ms.graph); it != INVALID; ++it)
     311          {
     312            ms.set(map_name, it, MapValue(*vit));
     313            ++vit;
     314          }
     315        }
     316        delete values;
     317      }
     318    }
     319    else if (text == "String")
     320    {
     321      if (edge.get_active())
     322        ms.createEdgeMap(map_name, MapValue::STRING,
     323            MapValue(def_val));
     324      else
     325        ms.createNodeMap(map_name, MapValue::STRING,
     326            MapValue(def_val));
     327    }
     328
     329    name.set_text("");
     330    default_value.set_text("0");
     331    edge.show();
     332    node.show();
     333    hide();
     334  }
    295335}
    296336
     
    309349
    310350  for(int i=0;(valid_entry&&(i<(int)rawcommand.size()));i++)
    311     {
    312       switch(rawcommand[i])
    313         {
    314         case '+':
    315         case '-':
    316         case '*':
    317         case '/':
    318         case ')':
    319         case '(':
    320           if(!variable.empty())
    321             {
    322               valid_entry=validVariable(variable, itisedge);
    323               ch2var[index]=variable;
    324               command+=index;
    325               index++;
    326               variable.erase(0,variable.size());         
    327             }
    328           command+=rawcommand[i];
    329           break;
    330         default:
    331           variable+=rawcommand[i];
    332           break;
    333         }
    334     }
     351  {
     352    switch(rawcommand[i])
     353    {
     354      case '+':
     355      case '-':
     356      case '*':
     357      case '/':
     358      case ')':
     359      case '(':
     360        if(!variable.empty())
     361        {
     362          valid_entry=validVariable(variable, itisedge);
     363          ch2var[index]=variable;
     364          command+=index;
     365          index++;
     366          variable.erase(0,variable.size());     
     367        }
     368        command+=rawcommand[i];
     369        break;
     370      default:
     371        variable+=rawcommand[i];
     372        break;
     373    }
     374  }
    335375
    336376  if(!variable.empty()&&valid_entry)
    337     {
    338       valid_entry=validVariable(variable, itisedge);
    339       ch2var[index]=variable;
    340       command+=index;
    341       index++;
    342       variable.erase(0,variable.size());         
    343     }
     377  {
     378    valid_entry=validVariable(variable, itisedge);
     379    ch2var[index]=variable;
     380    command+=index;
     381    index++;
     382    variable.erase(0,variable.size());   
     383  }
    344384
    345385  if(valid_entry)
    346     {
    347       unsigned int pr=10000;
    348       bool prevmult=false;
    349       unsigned int prev_change=pr;
    350       unsigned int prev_br=pr;
    351       int counter=0;
    352       std::string comm_nobr="";
    353       std::vector<unsigned int> p;
    354       p.resize(counter+1);
    355      
    356       //limits
    357       //6 brackets embedded
    358       //100 operation in a row from the same priority
    359      
    360       for(int i=0;i<(int)command.size();i++)
    361         {
    362           bool put_in_string=true;
    363           switch(command[i])
    364             {
    365             case '(':
    366               pr=prev_br+10000;
    367               prev_br=pr;
    368               prevmult=false;
    369               put_in_string=false;
    370               break;
    371             case ')':
    372               pr=prev_br-10000;
    373               prev_br=pr;
    374               prevmult=false;
    375               put_in_string=false;
    376               break;
    377             case '+':
    378             case '-':
    379               if(prevmult)
    380                 {
    381                   pr=prev_change;
    382                 }
    383               p[counter]=pr;
    384               pr-=100;
    385 
    386               prevmult=false;
    387               break;
    388             case '/':
    389             case '*':
    390               if(!prevmult)
    391                 {
    392                   prev_change=pr;
    393                   pr+=200;
    394                   pr-=1;
    395                 }
    396               p[counter]=pr;
    397               pr-=1;
    398               prevmult=true;
    399               break;
    400             default:
    401               p[counter]=65000;
    402               break;
    403             }
    404           if(put_in_string)
    405             {
    406               counter++;
    407               p.resize(counter+1);
    408               comm_nobr=comm_nobr+command[i];
    409             }
    410         }
    411 
    412       tree_node * root=weightedString2Tree(comm_nobr, p, 0);
    413 
    414       std::string polishform=postOrder(root);
    415 
    416       deleteTree(root);
    417 
    418       return polishform;
    419     }
     386  {
     387    unsigned int pr=10000;
     388    bool prevmult=false;
     389    unsigned int prev_change=pr;
     390    unsigned int prev_br=pr;
     391    int counter=0;
     392    std::string comm_nobr="";
     393    std::vector<unsigned int> p;
     394    p.resize(counter+1);
     395
     396    //limits
     397    //6 brackets embedded
     398    //100 operation in a row from the same priority
     399
     400    for(int i=0;i<(int)command.size();i++)
     401    {
     402      bool put_in_string=true;
     403      switch(command[i])
     404      {
     405        case '(':
     406          pr=prev_br+10000;
     407          prev_br=pr;
     408          prevmult=false;
     409          put_in_string=false;
     410          break;
     411        case ')':
     412          pr=prev_br-10000;
     413          prev_br=pr;
     414          prevmult=false;
     415          put_in_string=false;
     416          break;
     417        case '+':
     418        case '-':
     419          if(prevmult)
     420          {
     421            pr=prev_change;
     422          }
     423          p[counter]=pr;
     424          pr-=100;
     425
     426          prevmult=false;
     427          break;
     428        case '/':
     429        case '*':
     430          if(!prevmult)
     431          {
     432            prev_change=pr;
     433            pr+=200;
     434            pr-=1;
     435          }
     436          p[counter]=pr;
     437          pr-=1;
     438          prevmult=true;
     439          break;
     440        default:
     441          p[counter]=65000;
     442          break;
     443      }
     444      if(put_in_string)
     445      {
     446        counter++;
     447        p.resize(counter+1);
     448        comm_nobr=comm_nobr+command[i];
     449      }
     450    }
     451
     452    tree_node * root=weightedString2Tree(comm_nobr, p, 0);
     453
     454    std::string polishform=postOrder(root);
     455
     456    deleteTree(root);
     457
     458    return polishform;
     459  }
    420460  return "";
    421461}
     
    424464{
    425465  if(node->left_child!=NULL)
    426     {
    427       deleteTree(node->left_child);
    428     }
     466  {
     467    deleteTree(node->left_child);
     468  }
    429469  if(node->right_child!=NULL)
    430     {
    431       deleteTree(node->right_child);
    432     }
     470  {
     471    deleteTree(node->right_child);
     472  }
    433473  delete node;
    434474}
     
    439479  int minplace=0;
    440480  for(int i=0;i<(int)to_tree.size();i++)
    441     {
    442       if(min>p[offset+i])
    443         {
    444           min=p[offset+i];
    445           minplace=i;
    446         }
    447     }
     481  {
     482    if(min>p[offset+i])
     483    {
     484      min=p[offset+i];
     485      minplace=i;
     486    }
     487  }
    448488  tree_node * act_node=new tree_node;
    449489  act_node->ch=to_tree[minplace];
    450490  if(to_tree.size()>=3)
    451     {
    452       act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
    453       act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
    454     }
     491  {
     492    act_node->left_child=weightedString2Tree(to_tree.substr(0,minplace), p, offset);
     493    act_node->right_child=weightedString2Tree(to_tree.substr(minplace+1,to_tree.size()-minplace-1), p, offset+minplace+1);
     494  }
    455495  else
    456     {
    457       act_node->left_child=NULL;
    458       act_node->right_child=NULL;
    459     }
     496  {
     497    act_node->left_child=NULL;
     498    act_node->right_child=NULL;
     499  }
    460500  return act_node;
    461501}
     
    465505  std::string subtree_to_string;
    466506  if(subtree->left_child)
    467     {
    468       subtree_to_string=postOrder(subtree->left_child);
    469     }
     507  {
     508    subtree_to_string=postOrder(subtree->left_child);
     509  }
    470510  if(subtree->right_child)
    471     {
    472       subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
    473     }
     511  {
     512    subtree_to_string=subtree_to_string+postOrder(subtree->right_child);
     513  }
    474514  subtree_to_string=subtree_to_string+subtree->ch;
    475515  return subtree_to_string;
     
    478518bool NewMapWin::validVariable(std::string variable, bool itisedge)
    479519{
     520  MapStorage& ms = *mytab.mapstorage;
     521
    480522  bool cancel;
    481523  //is it mapname?
    482524  if(itisedge)
    483     {
    484       cancel=(mytab.mapstorage->edgemap_storage.find(variable)==mytab.mapstorage->edgemap_storage.end());
    485     }
     525  {
     526    std::vector<std::string> edge_maps =
     527      ms.getEdgeMapList(NUM);
     528    cancel=(std::find(edge_maps.begin(), edge_maps.end(), variable)==edge_maps.end());
     529  }
    486530  else
    487     {
    488       cancel=(mytab.mapstorage->nodemap_storage.find(variable)==mytab.mapstorage->nodemap_storage.end());
    489     }
     531  {
     532    std::vector<std::string> node_maps =
     533      ms.getNodeMapList(NUM);
     534    cancel=(std::find(node_maps.begin(), node_maps.end(), variable)==node_maps.end());
     535  }
    490536  //maybe it is number
    491537  int point_num=0;
    492538  if(cancel)
    493     {
    494       cancel=false;
    495       for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
    496         {
    497           if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
    498             {
    499               cancel=true;
    500             }
    501           else
    502             {
    503               if(variable[j]=='.')
    504                 {
    505                   point_num++;
    506                   if(point_num>1)
    507                     {
    508                       cancel=true;
    509                     }
    510                 }
    511             }
    512         }
    513     }
     539  {
     540    cancel=false;
     541    for(int j=0;(!cancel)&&(j<(int)variable.size());j++)
     542    {
     543      if(((variable[j]<'0')||(variable[j]>'9'))&&(variable[j]!='.'))
     544      {
     545        cancel=true;
     546      }
     547      else
     548      {
     549        if(variable[j]=='.')
     550        {
     551          point_num++;
     552          if(point_num>1)
     553          {
     554            cancel=true;
     555          }
     556        }
     557      }
     558    }
     559  }
    514560  if(cancel)
    515     {
    516       return false;
    517     }
     561  {
     562    return false;
     563  }
    518564  return true;
    519565}
  • new_map_win.h

    r194 r201  
    3636  NoteBookTab & mytab;
    3737
     38  MapType map_type;
     39  Gtk::Label lblType;
     40  Gtk::ComboBoxText cbType;
     41
     42  Gtk::Label lblErrorMsg;
     43  void setErrorMsg(const Glib::ustring& msg);
     44
     45  std::vector<double>* evaluate_expr(const std::string polishform, bool itisedge);
     46
    3847public:
    3948
     
    6069  ///It creates the widgets shown in
    6170  ///NewMapWin.
    62   NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true);
     71  NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true, MapType type = ALL);
    6372
    6473  ///Callback function for OK button. It creates the map.
  • xml.h

    r174 r201  
    1616 *
    1717 */
     18
     19#ifndef GLEMON_XML_H
     20#define GLEMON_XML_H
    1821
    1922#include <iostream>
     
    443446}
    444447
     448#endif
Note: See TracChangeset for help on using the changeset viewer.