mapstorage.cc
branchgui
changeset 134 82e19031c319
parent 128 3a4b6b31afb3
child 135 84996003b01c
equal deleted inserted replaced
23:04933d0a5ffa 24:5cd85492e57d
    15   edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
    15   edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
    16   arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
    16   arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
    17   edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
    17   edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
    18   arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    18   arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
    19 
    19 
    20   nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
    20   nodemap_storage["label"] = new Graph::NodeMap<double>(graph);
    21   edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
    21   edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
    22 
    22 
    23   nodemap_default["id"] = 1.0;
    23   nodemap_default["label"] = 1.0;
    24   edgemap_default["id"] = 1.0;
    24   edgemap_default["label"] = 1.0;
    25 
    25 
    26   active_nodemaps.resize(NODE_PROPERTY_NUM);
    26   active_nodemaps.resize(NODE_PROPERTY_NUM);
    27   for(int i=0;i<NODE_PROPERTY_NUM;i++)
    27   for(int i=0;i<NODE_PROPERTY_NUM;i++)
    28     {
    28     {
    29       active_nodemaps[i]="";
    29       active_nodemaps[i]="";
   249       else if (*it == "coordinates_y")
   249       else if (*it == "coordinates_y")
   250       {
   250       {
   251         read_y = true;
   251         read_y = true;
   252         //std::cout << "read Y nodemap" << std::endl;
   252         //std::cout << "read Y nodemap" << std::endl;
   253       }
   253       }
   254       else if (*it == "id")
   254       else if (*it == "label")
   255       {
   255       {
   256         //std::cout << "read id nodemap" << std::endl;
   256         //std::cout << "read id nodemap" << std::endl;
   257       }
   257       }
   258       else
   258       else
   259       {
   259       {
   263       greader.readNodeMap(*it, *nodemap_storage[*it]);
   263       greader.readNodeMap(*it, *nodemap_storage[*it]);
   264     }
   264     }
   265     for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
   265     for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
   266         it != edgeMapNames.end(); ++it)
   266         it != edgeMapNames.end(); ++it)
   267     {
   267     {
   268       if (*it == "id")
   268       if (*it == "label")
   269       {
   269       {
   270         //std::cout << "read id edgemap" << std::endl;
   270         //std::cout << "read id edgemap" << std::endl;
   271       }
   271       }
   272       else
   272       else
   273       {
   273       {
   285     return 1;
   285     return 1;
   286   }
   286   }
   287 
   287 
   288   if (!read_edge_id)
   288   if (!read_edge_id)
   289   {
   289   {
   290     edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
   290     edgemap_storage["label"] = new Graph::EdgeMap<double>(graph);
   291     int i = 1;
   291     int i = 1;
   292     for (EdgeIt e(graph); e != INVALID; ++e)
   292     for (EdgeIt e(graph); e != INVALID; ++e)
   293     {
   293     {
   294       (*edgemap_storage["id"])[e] = i++;
   294       (*edgemap_storage["label"])[e] = i++;
   295     }
   295     }
   296   }
   296   }
   297 
   297 
   298   if (!read_x || !read_y)
   298   if (!read_x || !read_y)
   299   {
   299   {
   324 
   324 
   325   // fill in the default values for the maps
   325   // fill in the default values for the maps
   326   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   326   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
   327       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   327       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   328   {
   328   {
   329     if ((it->first != "id") &&
   329     if ((it->first != "label") &&
   330         (it->first != "coordiantes_x") &&
   330         (it->first != "coordiantes_x") &&
   331         (it->first != "coordinates_y"))
   331         (it->first != "coordinates_y"))
   332     {
   332     {
   333       nodemap_default[it->first] = 0.0;
   333       nodemap_default[it->first] = 0.0;
   334     }
   334     }
   335     else if (it->first == "id")
   335     else if (it->first == "label")
   336     {
   336     {
   337       NodeIt n(graph);
   337       NodeIt n(graph);
   338       double max = (*nodemap_storage["id"])[n];
   338       double max = (*nodemap_storage["label"])[n];
   339       for (; n != INVALID; ++n)
   339       for (; n != INVALID; ++n)
   340       {
   340       {
   341         if ((*nodemap_storage["id"])[n] > max)
   341         if ((*nodemap_storage["label"])[n] > max)
   342           max = (*nodemap_storage["id"])[n];
   342           max = (*nodemap_storage["label"])[n];
   343       }
   343       }
   344       nodemap_default["id"] = max + 1.0;
   344       nodemap_default["label"] = max + 1.0;
   345     }
   345     }
   346   }
   346   }
   347   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
   347   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
   348       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   348       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   349   {
   349   {
   350     if (it->first != "id")
   350     if (it->first != "label")
   351     {
   351     {
   352       edgemap_default[it->first] = 0.0;
   352       edgemap_default[it->first] = 0.0;
   353     }
   353     }
   354     else
   354     else
   355     {
   355     {
   356       double max = std::numeric_limits<double>::min();
   356       double max = std::numeric_limits<double>::min();
   357       for (EdgeIt e(graph); e != INVALID; ++e)
   357       for (EdgeIt e(graph); e != INVALID; ++e)
   358       {
   358       {
   359         if ((*edgemap_storage["id"])[e] > max)
   359         if ((*edgemap_storage["label"])[e] > max)
   360           max = (*edgemap_storage["id"])[e];
   360           max = (*edgemap_storage["label"])[e];
   361       }
   361       }
   362       if (max > std::numeric_limits<double>::min())
   362       if (max > std::numeric_limits<double>::min())
   363         edgemap_default["id"] = max + 1.0;
   363         edgemap_default["label"] = max + 1.0;
   364       else
   364       else
   365         edgemap_default["id"] = 1.0;
   365         edgemap_default["label"] = 1.0;
   366     }
   366     }
   367   }
   367   }
   368 
   368 
   369   return 0;
   369   return 0;
   370 }
   370 }
   398   for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
   398   for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
   399       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   399       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   400   {
   400   {
   401     if ((it->first != "coordinates_x") &&
   401     if ((it->first != "coordinates_x") &&
   402         (it->first != "coordinates_y") &&
   402         (it->first != "coordinates_y") &&
   403         (it->first != "id"))
   403         (it->first != "label"))
   404     {
   404     {
   405       delete it->second;
   405       delete it->second;
   406       nodemap_storage.erase(it);
   406       nodemap_storage.erase(it);
   407     }
   407     }
   408   }
   408   }
   409   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
   409   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
   410       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   410       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   411   {
   411   {
   412     if ((it->first != "id") &&
   412     if ((it->first != "label") &&
   413         (it->first != "arrow_pos_x") &&
   413         (it->first != "arrow_pos_x") &&
   414         (it->first != "arrow_pos_y"))
   414         (it->first != "arrow_pos_y"))
   415     {
   415     {
   416       delete it->second;
   416       delete it->second;
   417       edgemap_storage.erase(it);
   417       edgemap_storage.erase(it);
   418     }
   418     }
   419   }
   419   }
   420   for (std::map<std::string, double>::iterator it =
   420   for (std::map<std::string, double>::iterator it =
   421       nodemap_default.begin(); it != nodemap_default.end(); ++it)
   421       nodemap_default.begin(); it != nodemap_default.end(); ++it)
   422   {
   422   {
   423     if (it->first != "id")
   423     if (it->first != "label")
   424       nodemap_default.erase(it);
   424       nodemap_default.erase(it);
   425   }
   425   }
   426   for (std::map<std::string, double>::iterator it =
   426   for (std::map<std::string, double>::iterator it =
   427       edgemap_default.begin(); it != edgemap_default.end(); ++it)
   427       edgemap_default.begin(); it != edgemap_default.end(); ++it)
   428   {
   428   {
   429     if (it->first != "id")
   429     if (it->first != "label")
   430       edgemap_default.erase(it);
   430       edgemap_default.erase(it);
   431   }
   431   }
   432   graph.clear();
   432   graph.clear();
   433   file_name = "";
   433   file_name = "";
   434   modified = false;
   434   modified = false;