mapstorage.cc
branchgui
changeset 98 f60f89147531
parent 94 adfdc2f70548
child 101 7234b7fabd05
equal deleted inserted replaced
17:54ae3e5d6544 18:57c760125f80
     1 #include "mapstorage.h"
     1 #include "mapstorage.h"
       
     2 #include "gui_writer.h"
       
     3 #include "gui_reader.h"
     2 #include <gtkmm.h>
     4 #include <gtkmm.h>
     3 #include <cmath>
     5 #include <cmath>
     4 
     6 
     5 #include <cmath>
     7 #include <cmath>
     6 
     8 
     7 MapStorage::MapStorage() : modified(false), file_name("")
     9 MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false)
     8 {
    10 {
     9   nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
    11   nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
    10   coords.setXMap(*nodemap_storage["coordinates_x"]);
    12   coords.setXMap(*nodemap_storage["coordinates_x"]);
    11   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    13   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    12   coords.setYMap(*nodemap_storage["coordinates_y"]);
    14   coords.setYMap(*nodemap_storage["coordinates_y"]);
       
    15 
       
    16   edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
       
    17   arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
       
    18   edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
       
    19   arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    13 
    20 
    14   nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
    21   nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
    15   edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
    22   edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
    16 
    23 
    17   nodemap_default["id"] = 1.0;
    24   nodemap_default["id"] = 1.0;
   245         edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
   252         edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
   246         //std::cout << "read " << *it << " edgemap" << std::endl;
   253         //std::cout << "read " << *it << " edgemap" << std::endl;
   247       }
   254       }
   248       greader.readEdgeMap(*it, *edgemap_storage[*it]);
   255       greader.readEdgeMap(*it, *edgemap_storage[*it]);
   249     }
   256     }
       
   257     GuiReader gui_reader(greader, this);
   250     greader.run();
   258     greader.run();
   251   } catch (DataFormatError& error) {
   259   } catch (DataFormatError& error) {
   252     Gtk::MessageDialog mdialog(error.what());
   260     Gtk::MessageDialog mdialog(error.what());
   253     mdialog.run();
   261     mdialog.run();
   254     clear();
   262     clear();
   281       nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
   289       nodemap_storage["coordinates_y"]->set(n, 250.0 * std::sin(i * step));
   282       i++;
   290       i++;
   283     }
   291     }
   284   }
   292   }
   285 
   293 
       
   294   if (!arrow_pos_read_ok)
       
   295   {
       
   296     arrow_pos_read_ok = false;
       
   297     for (EdgeIt e(graph); e != INVALID; ++e)
       
   298     {
       
   299       arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
       
   300     }
       
   301   }
       
   302 
   286   // fill in the default values for the maps
   303   // fill in the default values for the maps
   287   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   304   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   288       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   305       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   289   {
   306   {
   290     if ((it->first != "id") &&
   307     if ((it->first != "id") &&
   336 
   353 
   337   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   354   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   338       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   355       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   339   {
   356   {
   340     gwriter.writeNodeMap(it->first, *(it->second));
   357     gwriter.writeNodeMap(it->first, *(it->second));
   341     //std::cout << "wrote " << it->first << " nodemap" << std::endl;
       
   342   }
   358   }
   343   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
   359   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
   344       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   360       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   345   {
   361   {
   346     gwriter.writeEdgeMap(it->first, *(it->second));
   362     if ((it->first != "arrow_pos_x") &&
   347     //std::cout << "wrote " << it->first << " edgemap" << std::endl;
   363         (it->first != "arrow_pos_y"))
   348   }
   364     {
       
   365       gwriter.writeEdgeMap(it->first, *(it->second));
       
   366     }
       
   367   }
       
   368 
       
   369   GuiWriter gui_writer(gwriter, this);
       
   370 
   349   gwriter.run();
   371   gwriter.run();
   350 }
   372 }
   351 
   373 
   352 void MapStorage::clear()
   374 void MapStorage::clear()
   353 {
   375 {
   363     }
   385     }
   364   }
   386   }
   365   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
   387   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
   366       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   388       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   367   {
   389   {
   368     if (it->first != "id")
   390     if ((it->first != "id") &&
       
   391         (it->first != "arrow_pos_x") &&
       
   392         (it->first != "arrow_pos_y"))
   369     {
   393     {
   370       delete it->second;
   394       delete it->second;
   371       edgemap_storage.erase(it);
   395       edgemap_storage.erase(it);
   372     }
   396     }
   373   }
   397   }
   385   }
   409   }
   386   graph.clear();
   410   graph.clear();
   387   file_name = "";
   411   file_name = "";
   388   modified = false;
   412   modified = false;
   389 }
   413 }
       
   414 
       
   415 void MapStorage::ArrowPosReadOK()
       
   416 {
       
   417   arrow_pos_read_ok = true;
       
   418 }