mapstorage.cc
branchgui
changeset 66 4ca5a537ef07
parent 63 59768817442a
child 67 052cfd7832b1
equal deleted inserted replaced
12:6e2c361a75bc 13:14ad866888fd
     9   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
     9   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
    10   coords.setYMap(*nodemap_storage["coordinates_y"]);
    10   coords.setYMap(*nodemap_storage["coordinates_y"]);
    11 
    11 
    12   nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
    12   nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
    13   edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
    13   edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
       
    14 
       
    15   nodemap_default["id"] = 1.0;
       
    16   edgemap_default["id"] = 1.0;
    14 }
    17 }
    15 
    18 
    16 MapStorage::~MapStorage()
    19 MapStorage::~MapStorage()
    17 {
    20 {
    18   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
    21   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   123 
   126 
   124 int MapStorage::readFromFile(const std::string &filename)
   127 int MapStorage::readFromFile(const std::string &filename)
   125 {
   128 {
   126   bool read_x = false;
   129   bool read_x = false;
   127   bool read_y = false;
   130   bool read_y = false;
       
   131   bool read_edge_id = false;
   128 
   132 
   129   try {
   133   try {
   130     LemonReader lreader(filename);
   134     LemonReader lreader(filename);
   131     ContentReader content(lreader);
   135     ContentReader content(lreader);
   132     lreader.run();
   136     lreader.run();
   180     mdialog.run();
   184     mdialog.run();
   181     clear();
   185     clear();
   182     return 1;
   186     return 1;
   183   }
   187   }
   184 
   188 
       
   189   if (!read_edge_id)
       
   190   {
       
   191     edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
       
   192     int i = 1;
       
   193     for (EdgeIt e(graph); e != INVALID; ++e)
       
   194     {
       
   195       (*edgemap_storage["id"])[e] = i++;
       
   196     }
       
   197   }
       
   198 
   185   if (!read_x || !read_y)
   199   if (!read_x || !read_y)
   186   {
   200   {
   187     int node_num = 0;
   201     int node_num = 0;
   188     for (NodeIt n(graph); n != INVALID; ++n)
   202     for (NodeIt n(graph); n != INVALID; ++n)
   189     {
   203     {
   208         (it->first != "coordiantes_x") &&
   222         (it->first != "coordiantes_x") &&
   209         (it->first != "coordinates_y"))
   223         (it->first != "coordinates_y"))
   210     {
   224     {
   211       nodemap_default[it->first] = 0.0;
   225       nodemap_default[it->first] = 0.0;
   212     }
   226     }
       
   227     else if (it->first == "id")
       
   228     {
       
   229       NodeIt n(graph);
       
   230       double max = (*nodemap_storage["id"])[n];
       
   231       for (; n != INVALID; ++n)
       
   232       {
       
   233         if ((*nodemap_storage["id"])[n] > max)
       
   234           max = (*nodemap_storage["id"])[n];
       
   235       }
       
   236       nodemap_default["id"] = max + 1.0;
       
   237     }
   213   }
   238   }
   214   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
   239   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
   215       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   240       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   216   {
   241   {
   217     if (it->first != "id")
   242     if (it->first != "id")
   218     {
   243     {
   219       edgemap_default[it->first] = 0.0;
   244       edgemap_default[it->first] = 0.0;
       
   245     }
       
   246     else
       
   247     {
       
   248       EdgeIt e(graph);
       
   249       double max = (*edgemap_storage["id"])[e];
       
   250       for (; e != INVALID; ++e)
       
   251       {
       
   252         if ((*edgemap_storage["id"])[e] > max)
       
   253           max = (*edgemap_storage["id"])[e];
       
   254       }
       
   255       edgemap_default["id"] = max + 1.0;
   220     }
   256     }
   221   }
   257   }
   222 
   258 
   223   return 0;
   259   return 0;
   224 }
   260 }
   265     }
   301     }
   266   }
   302   }
   267   for (std::map<std::string, double>::iterator it =
   303   for (std::map<std::string, double>::iterator it =
   268       nodemap_default.begin(); it != nodemap_default.end(); ++it)
   304       nodemap_default.begin(); it != nodemap_default.end(); ++it)
   269   {
   305   {
   270     nodemap_default.erase(it);
   306     if (it->first != "id")
       
   307       nodemap_default.erase(it);
   271   }
   308   }
   272   for (std::map<std::string, double>::iterator it =
   309   for (std::map<std::string, double>::iterator it =
   273       edgemap_default.begin(); it != edgemap_default.end(); ++it)
   310       edgemap_default.begin(); it != edgemap_default.end(); ++it)
   274   {
   311   {
   275     edgemap_default.erase(it);
   312     if (it->first != "id")
       
   313       edgemap_default.erase(it);
   276   }
   314   }
   277   graph.clear();
   315   graph.clear();
   278   file_name = "";
   316   file_name = "";
   279   modified = false;
   317   modified = false;
   280 }
   318 }