mapstorage.cc
branchgui
changeset 98 f60f89147531
parent 94 adfdc2f70548
child 101 7234b7fabd05
     1.1 --- a/mapstorage.cc	Thu Dec 08 14:16:08 2005 +0000
     1.2 +++ b/mapstorage.cc	Sat Dec 17 20:55:41 2005 +0000
     1.3 @@ -1,16 +1,23 @@
     1.4  #include "mapstorage.h"
     1.5 +#include "gui_writer.h"
     1.6 +#include "gui_reader.h"
     1.7  #include <gtkmm.h>
     1.8  #include <cmath>
     1.9  
    1.10  #include <cmath>
    1.11  
    1.12 -MapStorage::MapStorage() : modified(false), file_name("")
    1.13 +MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false)
    1.14  {
    1.15    nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
    1.16    coords.setXMap(*nodemap_storage["coordinates_x"]);
    1.17    nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    1.18    coords.setYMap(*nodemap_storage["coordinates_y"]);
    1.19  
    1.20 +  edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
    1.21 +  arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
    1.22 +  edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
    1.23 +  arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    1.24 +
    1.25    nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
    1.26    edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
    1.27  
    1.28 @@ -247,6 +254,7 @@
    1.29        }
    1.30        greader.readEdgeMap(*it, *edgemap_storage[*it]);
    1.31      }
    1.32 +    GuiReader gui_reader(greader, this);
    1.33      greader.run();
    1.34    } catch (DataFormatError& error) {
    1.35      Gtk::MessageDialog mdialog(error.what());
    1.36 @@ -283,6 +291,15 @@
    1.37      }
    1.38    }
    1.39  
    1.40 +  if (!arrow_pos_read_ok)
    1.41 +  {
    1.42 +    arrow_pos_read_ok = false;
    1.43 +    for (EdgeIt e(graph); e != INVALID; ++e)
    1.44 +    {
    1.45 +      arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
    1.46 +    }
    1.47 +  }
    1.48 +
    1.49    // fill in the default values for the maps
    1.50    for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    1.51        nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    1.52 @@ -338,14 +355,19 @@
    1.53        nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
    1.54    {
    1.55      gwriter.writeNodeMap(it->first, *(it->second));
    1.56 -    //std::cout << "wrote " << it->first << " nodemap" << std::endl;
    1.57    }
    1.58    for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
    1.59        edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    1.60    {
    1.61 -    gwriter.writeEdgeMap(it->first, *(it->second));
    1.62 -    //std::cout << "wrote " << it->first << " edgemap" << std::endl;
    1.63 +    if ((it->first != "arrow_pos_x") &&
    1.64 +        (it->first != "arrow_pos_y"))
    1.65 +    {
    1.66 +      gwriter.writeEdgeMap(it->first, *(it->second));
    1.67 +    }
    1.68    }
    1.69 +
    1.70 +  GuiWriter gui_writer(gwriter, this);
    1.71 +
    1.72    gwriter.run();
    1.73  }
    1.74  
    1.75 @@ -365,7 +387,9 @@
    1.76    for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
    1.77        edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
    1.78    {
    1.79 -    if (it->first != "id")
    1.80 +    if ((it->first != "id") &&
    1.81 +        (it->first != "arrow_pos_x") &&
    1.82 +        (it->first != "arrow_pos_y"))
    1.83      {
    1.84        delete it->second;
    1.85        edgemap_storage.erase(it);
    1.86 @@ -387,3 +411,8 @@
    1.87    file_name = "";
    1.88    modified = false;
    1.89  }
    1.90 +
    1.91 +void MapStorage::ArrowPosReadOK()
    1.92 +{
    1.93 +  arrow_pos_read_ok = true;
    1.94 +}