[Lemon-commits] ladanyi: r3361 - glemon/branches/akos

Lemon SVN svn at lemon.cs.elte.hu
Wed Nov 7 16:39:01 CET 2007


Author: ladanyi
Date: Wed Nov  7 16:39:00 2007
New Revision: 3361

Modified:
   glemon/branches/akos/file_import_dialog.cc
   glemon/branches/akos/file_import_dialog.h
   glemon/branches/akos/mapstorage.cc
   glemon/branches/akos/mapstorage.h

Log:
Importing node and arrow coordinates works now.

Modified: glemon/branches/akos/file_import_dialog.cc
==============================================================================
--- glemon/branches/akos/file_import_dialog.cc	(original)
+++ glemon/branches/akos/file_import_dialog.cc	Wed Nov  7 16:39:00 2007
@@ -359,18 +359,27 @@
     cbNodeCoordOneMap.get_parent()->set_sensitive(true);
     cbNodeCoordTwoMaps1.get_parent()->set_sensitive(false);
     cbNodeCoordTwoMaps2.get_parent()->set_sensitive(false);
+
+    p_data->node_coord_load_from = ImportData::ONE_MAP;
+    p_data->node_coord_one_map_name = cbNodeCoordOneMap.get_active_text();
   }
   else if (rbNodeCoordTwoMaps.get_active())
   {
     cbNodeCoordOneMap.get_parent()->set_sensitive(false);
     cbNodeCoordTwoMaps1.get_parent()->set_sensitive(true);
     cbNodeCoordTwoMaps2.get_parent()->set_sensitive(true);
+
+    p_data->node_coord_load_from = ImportData::TWO_MAPS;
+    p_data->node_coord_two_maps_1_name = cbNodeCoordTwoMaps1.get_active_text();
+    p_data->node_coord_two_maps_2_name = cbNodeCoordTwoMaps2.get_active_text();
   }
   else if (rbNodeCoordNone.get_active())
   {
     cbNodeCoordOneMap.get_parent()->set_sensitive(false);
     cbNodeCoordTwoMaps1.get_parent()->set_sensitive(false);
     cbNodeCoordTwoMaps2.get_parent()->set_sensitive(false);
+
+    p_data->node_coord_load_from = ImportData::DONT_READ;
   }
 }
 
@@ -381,18 +390,29 @@
     cbArrowCoordOneMap.get_parent()->set_sensitive(true);
     cbArrowCoordTwoMaps1.get_parent()->set_sensitive(false);
     cbArrowCoordTwoMaps2.get_parent()->set_sensitive(false);
+
+    p_data->arrow_coord_load_from = ImportData::ONE_MAP;
+    p_data->arrow_coord_one_map_name = cbArrowCoordOneMap.get_active_text();
   }
   else if (rbArrowCoordTwoMaps.get_active())
   {
     cbArrowCoordOneMap.get_parent()->set_sensitive(false);
     cbArrowCoordTwoMaps1.get_parent()->set_sensitive(true);
     cbArrowCoordTwoMaps2.get_parent()->set_sensitive(true);
+
+    p_data->arrow_coord_load_from = ImportData::TWO_MAPS;
+    p_data->arrow_coord_two_maps_1_name =
+      cbArrowCoordTwoMaps1.get_active_text();
+    p_data->arrow_coord_two_maps_2_name =
+      cbArrowCoordTwoMaps2.get_active_text();
   }
   else if (rbArrowCoordNone.get_active())
   {
     cbArrowCoordOneMap.get_parent()->set_sensitive(false);
     cbArrowCoordTwoMaps1.get_parent()->set_sensitive(false);
     cbArrowCoordTwoMaps2.get_parent()->set_sensitive(false);
+
+    p_data->arrow_coord_load_from = ImportData::DONT_READ;
   }
 }
 

Modified: glemon/branches/akos/file_import_dialog.h
==============================================================================
--- glemon/branches/akos/file_import_dialog.h	(original)
+++ glemon/branches/akos/file_import_dialog.h	Wed Nov  7 16:39:00 2007
@@ -1,7 +1,6 @@
 #ifndef FILE_IMPORT_DIALOG
 #define FILE_IMPORT_DIALOG
 
-#include <libglademm/xml.h>
 #include <gtkmm/dialog.h>
 #include <gtkmm/radiobutton.h>
 #include <gtkmm/comboboxtext.h>
@@ -28,13 +27,16 @@
             const std::vector<std::string>& vec,
             const std::string& str);
 
-        std::string node_coord_map_x;
-        std::string node_coord_map_y;
-        std::string arrow_coord_map_x;
-        std::string arrow_coord_map_y;
-
-        bool node_coord_load_from_file;
-        bool arrow_coord_load_from_file;
+        std::string node_coord_one_map_name;
+        std::string node_coord_two_maps_1_name;
+        std::string node_coord_two_maps_2_name;
+        std::string arrow_coord_one_map_name;
+        std::string arrow_coord_two_maps_1_name;
+        std::string arrow_coord_two_maps_2_name;
+
+        enum ReadOpts { ONE_MAP, TWO_MAPS, DONT_READ };
+        ReadOpts node_coord_load_from;
+        ReadOpts arrow_coord_load_from;
 
         bool isXYNodeMap(const std::string& name);
         bool isXYEdgeMap(const std::string& name);

Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc	(original)
+++ glemon/branches/akos/mapstorage.cc	Wed Nov  7 16:39:00 2007
@@ -234,13 +234,6 @@
   bool gui_data_in_conf = g_file_test((filename + ".conf").c_str(),
       (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR));
 
-  /*
-  if (gui_data_in_conf)
-    std::cerr << filename << ".conf file exists" << std::endl;
-  else
-    std::cerr << filename << ".conf file not found" << std::endl;
-  */
-
   // check whether the .lgf file contains a gui section
   bool gui_data_in_lgf = false;
   {
@@ -265,13 +258,6 @@
     }
   }
 
-  /*
-  if (gui_data_in_lgf)
-    std::cerr << "found gui section in " << filename << std::endl;
-  else
-    std::cerr << "no gui section in " << filename << std::endl;
-  */
-
   bool gui_data_found = gui_data_in_lgf || gui_data_in_conf;
 
   // ask for user input if both exist
@@ -308,7 +294,6 @@
       // read the gui section from the .lgf file
       try
       {
-        //std::cerr << "reading gui section form file " << filename << std::endl;
         LemonReader lreader(filename);
         GuiReader gui_reader(lreader, this, gui_data);
         lreader.run();
@@ -316,7 +301,6 @@
       }
       catch (Exception& error)
       {
-        //std::cerr << "reading gui section from file " << filename << "failed" << std::endl;
         clear();
         return 1;
       }
@@ -326,7 +310,6 @@
       // read the gui section from the .conf file
       try
       {
-        //std::cerr << "reading " << filename << ".conf file" << std::endl;
         LemonReader lreader(filename + ".conf");
         GuiReader gui_reader(lreader, this, gui_data);
         lreader.run();
@@ -334,7 +317,6 @@
       }
       catch (Exception& error)
       {
-        //std::cerr << "reading " << filename << ".conf file failed" << std::endl;
         clear();
         return 1;
       }
@@ -343,130 +325,57 @@
     // read the graph and maps form the .lgf file
     try
     {
-      //std::cerr << "reading the graph and maps form " << filename << " file" << std::endl;
-      GraphReader<Graph> greader(filename, graph);
-
-      // read the label maps
-      greader.readNodeMap("label", node_label);
-      greader.readEdgeMap("label", edge_label);
-
-      // read the node maps
-      for (vector<string>::const_iterator
-          it = gui_data.main_node_map_names.begin();
-          it != gui_data.main_node_map_names.end(); ++it)
-      {
-        switch (gui_data.node_map_types[*it])
-        {
-          case MapValue::NUMERIC:
-            {
-              createNodeMap(*it, MapValue::NUMERIC, double());
-              greader.readNodeMap(*it, getNumericNodeMap(*it));
-              break;
-            }
-          case MapValue::STRING:
-            {
-              createNodeMap(*it, MapValue::STRING, string());
-              greader.readNodeMap(*it, getStringNodeMap(*it));
-              break;
-            }
-        }
-        getNodeMapData(*it)->save_dest = NESET_SECT;
-      }
-
-      // read the edge maps
-      for (vector<string>::const_iterator
-          it = gui_data.main_edge_map_names.begin();
-          it != gui_data.main_edge_map_names.end(); ++it)
-      {
-        switch (gui_data.edge_map_types[*it])
-        {
-          case MapValue::NUMERIC:
-            {
-              createEdgeMap(*it, MapValue::NUMERIC, double());
-              greader.readEdgeMap(*it, getNumericEdgeMap(*it));
-              break;
-            }
-          case MapValue::STRING:
-            {
-              createEdgeMap(*it, MapValue::STRING, string());
-              greader.readEdgeMap(*it, getStringEdgeMap(*it));
-              break;
-            }
-        }
-        getEdgeMapData(*it)->save_dest = NESET_SECT;
-      }
+      std::string node_coord_xmap_name, node_coord_ymap_name;
+      std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
 
-      // read the node coordinate maps
       if (gui_data.node_coords_save_dest ==
           MapStorage::SpecMapSaveOpts::NESET_SECT)
       {
         switch (gui_data.node_coords_save_map_num)
         {
           case SpecMapSaveOpts::ONE_MAP:
-            greader.readNodeMap(gui_data.node_coords_one_map_name + ":x",
-                node_coords_x);
-            greader.readNodeMap(gui_data.node_coords_one_map_name + ":y",
-                node_coords_y);
-            node_coords_save_dest =
-              gui_data.node_coords_save_dest;
-            node_coords_save_map_num =
-              gui_data.node_coords_save_map_num;
-            node_coords_one_map_name =
-              gui_data.node_coords_one_map_name;
+            node_coord_xmap_name = gui_data.node_coords_one_map_name + ":x";
+            node_coord_ymap_name = gui_data.node_coords_one_map_name + ":y";
+            node_coords_one_map_name = gui_data.node_coords_one_map_name;
             break;
           case SpecMapSaveOpts::TWO_MAPS:
-            greader.readNodeMap(gui_data.node_coords_two_maps_1_name,
-                node_coords_x);
-            greader.readNodeMap(gui_data.node_coords_two_maps_2_name,
-                node_coords_y);
-            node_coords_save_dest =
-              gui_data.node_coords_save_dest;
-            node_coords_save_map_num =
-              gui_data.node_coords_save_map_num;
-            node_coords_two_maps_1_name =
-              gui_data.node_coords_two_maps_1_name;
-            node_coords_two_maps_2_name =
-              gui_data.node_coords_two_maps_2_name;
+            node_coord_xmap_name = gui_data.node_coords_two_maps_1_name;
+            node_coord_ymap_name = gui_data.node_coords_two_maps_2_name;
+            node_coords_two_maps_1_name = gui_data.node_coords_two_maps_1_name;
+            node_coords_two_maps_2_name = gui_data.node_coords_two_maps_2_name;
             break;
         }
+        node_coords_save_dest = gui_data.node_coords_save_dest;
+        node_coords_save_map_num = gui_data.node_coords_save_map_num;
       }
 
-      // read the arrow coordinate maps
       if (gui_data.arrow_coords_save_dest ==
           MapStorage::SpecMapSaveOpts::NESET_SECT)
       {
         switch (gui_data.arrow_coords_save_map_num)
         {
           case SpecMapSaveOpts::ONE_MAP:
-            greader.readEdgeMap(gui_data.arrow_coords_one_map_name + ":x",
-                arrow_coords_x);
-            greader.readEdgeMap(gui_data.arrow_coords_one_map_name + ":y",
-                arrow_coords_y);
-            arrow_coords_save_dest =
-              gui_data.arrow_coords_save_dest;
-            arrow_coords_save_map_num =
-              gui_data.arrow_coords_save_map_num;
-            arrow_coords_one_map_name =
-              gui_data.arrow_coords_one_map_name;
+            arrow_coord_xmap_name = gui_data.arrow_coords_one_map_name + ":x";
+            arrow_coord_ymap_name = gui_data.arrow_coords_one_map_name + ":y";
+            arrow_coords_one_map_name = gui_data.arrow_coords_one_map_name;
             break;
           case SpecMapSaveOpts::TWO_MAPS:
-            greader.readEdgeMap(gui_data.arrow_coords_two_maps_1_name,
-                arrow_coords_x);
-            greader.readEdgeMap(gui_data.arrow_coords_two_maps_2_name,
-                arrow_coords_y);
-            arrow_coords_save_dest =
-              gui_data.arrow_coords_save_dest;
-            arrow_coords_save_map_num =
-              gui_data.arrow_coords_save_map_num;
+            arrow_coord_xmap_name = gui_data.arrow_coords_two_maps_1_name;
+            arrow_coord_ymap_name = gui_data.arrow_coords_two_maps_2_name;
             arrow_coords_two_maps_1_name =
               gui_data.arrow_coords_two_maps_1_name;
             arrow_coords_two_maps_2_name =
               gui_data.arrow_coords_two_maps_2_name;
             break;
         }
+        arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
+        arrow_coords_save_map_num = gui_data.arrow_coords_save_map_num;
       }
-
-      greader.run();
+      readLGF(filename,
+          gui_data.main_node_map_names, gui_data.main_edge_map_names,
+          gui_data.node_map_types, gui_data.edge_map_types,
+          node_coord_xmap_name, node_coord_ymap_name,
+          arrow_coord_xmap_name, arrow_coord_ymap_name);
     }
     catch (Exception& error)
     {
@@ -600,225 +509,129 @@
 
       FileImportDialog::ImportData data(nodeMapNames, edgeMapNames);
       FileImportDialog fidialog(&data);
-      fidialog.run();
-    }
-  }
-
-
-
-/*
-  bool read_x = false;
-  bool read_y = false;
-  bool read_edge_id = false;
-
-  try {
-    LemonReader lreader(filename);
-    ContentReader content(lreader);
-    lreader.run();
+      int response = fidialog.run();
+      if (response == Gtk::RESPONSE_OK)
+      {
+        try
+        {
+          std::string node_coord_xmap_name, node_coord_ymap_name;
+          std::string arrow_coord_xmap_name, arrow_coord_ymap_name;
+          bool gen_node_coords = false;
+          bool gen_arrow_coords = false;
 
-    if (content.nodeSetNum() < 1)
-    {
-      Gtk::MessageDialog mdialog("No nodeset found in file.");
-      mdialog.run();
-      clear();
-      return 1;
-    }
+          switch (data.node_coord_load_from)
+          {
+            case FileImportDialog::ImportData::ONE_MAP:
+              node_coord_xmap_name = data.node_coord_one_map_name + ":x";
+              node_coord_ymap_name = data.node_coord_one_map_name + ":y";
+              node_coords_one_map_name = data.node_coord_one_map_name;
 
-    if (content.edgeSetNum() < 1)
-    {
-      Gtk::MessageDialog mdialog("No edgeset found in file.");
-      mdialog.run();
-      clear();
-      return 1;
-    }
+              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
+              node_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
+              break;
+            case FileImportDialog::ImportData::TWO_MAPS:
+              node_coord_xmap_name = data.node_coord_two_maps_1_name;
+              node_coord_ymap_name = data.node_coord_two_maps_2_name;
+              node_coords_two_maps_1_name = data.node_coord_two_maps_1_name;
+              node_coords_two_maps_2_name = data.node_coord_two_maps_2_name;
 
-    const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
-    const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
+              node_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
+              node_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
+              break;
+            case FileImportDialog::ImportData::DONT_READ:
+              node_coord_xmap_name = "";
+              node_coord_ymap_name = "";
 
-    GraphReader<Graph> greader(filename, graph);
-    for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
-        it != nodeMapNames.end(); ++it)
-    {
-      if (*it == "coordinates_x")
-      {
-        read_x = true;
-        greader.readNodeMap(*it, node_x_coord);
-        //std::cerr << "read X nodemap" << std::endl;
-      }
-      else if (*it == "coordinates_y")
-      {
-        read_y = true;
-        greader.readNodeMap(*it, node_y_coord);
-        //std::cerr << "read Y nodemap" << std::endl;
-      }
-      else if (*it == "label")
-      {
-        greader.readNodeMap(*it, node_label);
-        //std::cerr << "read id nodemap" << std::endl;
-      }
-      else
-      {
-        nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
-        greader.readNodeMap(*it, *nodemap_storage[*it]);
-        //std::cerr << "read " << *it << " nodemap" << std::endl;
-      }
-    }
-    for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
-        it != edgeMapNames.end(); ++it)
-    {
-      if (*it == "label")
-      {
-        //std::cerr << "read id edgemap" << std::endl;
-        read_edge_id = true;
-        greader.readEdgeMap(*it, edge_label);
-      }
-      else
-      {
-        edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
-        //std::cerr << "read " << *it << " edgemap" << std::endl;
-        greader.readEdgeMap(*it, *edgemap_storage[*it]);
-      }
-    }
-    if ((gui_data_in_lgf && !gui_data_in_conf) ||
-        (gui_data_in_lgf && gui_data_in_conf && use_gui_data_in_lgf))
-    {
-      std::cerr << "reading gui section" << std::endl;
-      GuiReader gui_reader(greader, this);
-    }
-    greader.run();
+              node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
+              gen_node_coords = true;
+              break;
+          }
 
-    if ((!gui_data_in_lgf && gui_data_in_conf) ||
-        (gui_data_in_lgf && gui_data_in_conf && !use_gui_data_in_lgf))
-    {
-      std::cerr << "reading .conf file" << std::endl;
-      LemonReader lreader(filename + ".conf");
-      GuiReader gui_reader(lreader, this);
-      lreader.run();
-    }
+          switch (data.arrow_coord_load_from)
+          {
+            case FileImportDialog::ImportData::ONE_MAP:
+              arrow_coord_xmap_name = data.arrow_coord_one_map_name + ":x";
+              arrow_coord_ymap_name = data.arrow_coord_one_map_name + ":y";
+              arrow_coords_one_map_name = data.arrow_coord_one_map_name;
 
-  } catch (Exception& error) {
-    Gtk::MessageDialog mdialog(error.what());
-    mdialog.run();
-    clear();
-    return 1;
-  }
+              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
+              arrow_coords_save_map_num = SpecMapSaveOpts::ONE_MAP;
+              break;
+            case FileImportDialog::ImportData::TWO_MAPS:
+              arrow_coord_xmap_name = data.arrow_coord_two_maps_1_name;
+              arrow_coord_ymap_name = data.arrow_coord_two_maps_2_name;
+              arrow_coords_two_maps_1_name = data.arrow_coord_two_maps_1_name;
+              arrow_coords_two_maps_2_name = data.arrow_coord_two_maps_2_name;
 
-  if (!read_edge_id)
-  {
-    int i = 1;
-    for (EdgeIt e(graph); e != INVALID; ++e)
-    {
-      edge_label[e] = i++;
-    }
-    max_edge_label = i--;
-  }
-  else
-  {
-    EdgeIt e(graph);
-    int max_edge_label = edge_label[e];
-    for (++e; e != INVALID; ++e)
-    {
-      if (edge_label[e] > max_edge_label)
-      {
-        max_edge_label = edge_label[e];
-      }
-    }
-  }
+              arrow_coords_save_dest = SpecMapSaveOpts::NESET_SECT;
+              arrow_coords_save_map_num = SpecMapSaveOpts::TWO_MAPS;
+              break;
+            case FileImportDialog::ImportData::DONT_READ:
+              arrow_coord_xmap_name = "";
+              arrow_coord_ymap_name = "";
 
-  {
-    NodeIt n(graph);
-    int max_node_label = node_label[n];
-    for (++n; n != INVALID; ++n)
-    {
-      if (node_label[n] > max_node_label)
-      {
-        max_node_label = node_label[n];
-      }
-    }
-  }
+              arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
+              gen_arrow_coords = true;
+              break;
+          }
 
-  if (!read_x || !read_y)
-  {
-    int node_num = 0;
-    for (NodeIt n(graph); n != INVALID; ++n)
-    {
-      node_num++;
-    }
-    const double pi = 3.142;
-    double step = 2 * pi / (double) node_num;
-    int i = 0;
-    for (NodeIt n(graph); n != INVALID; ++n)
-    {
-      setNodeCoords(n, XY(250.0 * std::cos(i * step), 250.0 * std::sin(i * step)));
-      i++;
-    }
-  }
+          // TODO
+          // read edge and node maps
+          readLGF(filename,
+              std::vector<std::string>(), std::vector<std::string>(),
+              std::map<std::string, MapValue::Type>(),
+              std::map<std::string, MapValue::Type>(),
+              node_coord_xmap_name, node_coord_ymap_name,
+              arrow_coord_xmap_name, arrow_coord_ymap_name);
 
-  if (!arrow_pos_read_ok)
-  {
-    arrow_pos_read_ok = false;
-    for (EdgeIt e(graph); e != INVALID; ++e)
-    {
-      if (graph.source(e) == graph.target(e))
-      {
-        setArrowCoords(e, getNodeCoords(graph.source(e)) + XY(0.0, 80.0));
+          if (gen_node_coords)
+          {
+            // generate node coordinates
+            int node_num = 0;
+            for (NodeIt n(graph); n != INVALID; ++n) { node_num++; }
+            const double pi = 3.142;
+            double step = 2 * pi / (double) node_num;
+            int i = 0;
+            for (NodeIt n(graph); n != INVALID; ++n)
+            {
+              setNodeCoords(n,
+                  XY(250.0 * std::cos(i * step),
+                    250.0 * std::sin(i * step)));
+              i++;
+            }
+          }
+          if (gen_arrow_coords)
+          {
+            // generate arrow coordinates
+            for (EdgeIt e(graph); e != INVALID; ++e)
+            {
+              if (graph.source(e) == graph.target(e))
+              {
+                setArrowCoords(e,
+                    getNodeCoords(graph.source(e)) + XY(0.0, 80.0));
+              }
+              else
+              {
+                setArrowCoords(e,
+                    (getNodeCoords(graph.source(e)) +
+                     getNodeCoords(graph.target(e))) / 2.0);
+              }
+            }
+          }
+        }
+        catch (Exception& error)
+        {
+          clear();
+          return 1;
+        }
       }
       else
       {
-        setArrowCoords(e,
-            (getNodeCoords(graph.source(e)) +
-             getNodeCoords(graph.target(e))) / 2.0);
-      }
-    }
-  }
-
-  // fill in the default values for the maps
-  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
-      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
-  {
-    if ((it->first != "label") &&
-        (it->first != "coordiantes_x") &&
-        (it->first != "coordinates_y"))
-    {
-      nodemap_default[it->first] = 0.0;
-    }
-    else if (it->first == "label")
-    {
-      NodeIt n(graph);
-      double max = (*nodemap_storage["label"])[n];
-      for (; n != INVALID; ++n)
-      {
-        if ((*nodemap_storage["label"])[n] > max)
-          max = (*nodemap_storage["label"])[n];
-      }
-      nodemap_default["label"] = max + 1.0;
-    }
-  }
-  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
-      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
-  {
-    if (it->first != "label")
-    {
-      edgemap_default[it->first] = 0.0;
-    }
-    else
-    {
-      double max = std::numeric_limits<double>::min();
-      for (EdgeIt e(graph); e != INVALID; ++e)
-      {
-        if ((*edgemap_storage["label"])[e] > max)
-          max = (*edgemap_storage["label"])[e];
+        clear();
+        return 1;
       }
-      if (max > std::numeric_limits<double>::min())
-        edgemap_default["label"] = max + 1.0;
-      else
-        edgemap_default["label"] = 1.0;
     }
   }
-  */
-
-  //std::cerr << "reading finished" << std::endl;
-
 
   // set max_node_label
   {
@@ -1528,3 +1341,85 @@
 {
   arrow_coords_two_maps_2_name = name;
 }
+
+void MapStorage::readLGF(
+    const std::string& filename,
+    const std::vector<std::string>& node_map_names,
+    const std::vector<std::string>& edge_map_names,
+    const std::map<std::string, MapValue::Type>& node_map_types,
+    const std::map<std::string, MapValue::Type>& edge_map_types,
+    const std::string& node_coord_xmap_name,
+    const std::string& node_coord_ymap_name,
+    const std::string& arrow_coord_xmap_name,
+    const std::string& arrow_coord_ymap_name)
+{
+  using std::vector;
+  using std::map;
+  using std::string;
+
+  GraphReader<Graph> greader(filename, graph);
+
+  // read the label maps
+  greader.readNodeMap("label", node_label);
+  greader.readEdgeMap("label", edge_label);
+
+  // read the node maps
+  for (vector<string>::const_iterator
+      it = node_map_names.begin();
+      it != node_map_names.end(); ++it)
+  {
+    switch (node_map_types.find(*it)->second)
+    {
+      case MapValue::NUMERIC:
+        {
+          createNodeMap(*it, MapValue::NUMERIC, double());
+          greader.readNodeMap(*it, getNumericNodeMap(*it));
+          break;
+        }
+      case MapValue::STRING:
+        {
+          createNodeMap(*it, MapValue::STRING, string());
+          greader.readNodeMap(*it, getStringNodeMap(*it));
+          break;
+        }
+    }
+    getNodeMapData(*it)->save_dest = NESET_SECT;
+  }
+
+  // read the edge maps
+  for (vector<string>::const_iterator
+      it = edge_map_names.begin();
+      it != edge_map_names.end(); ++it)
+  {
+    switch (edge_map_types.find(*it)->second)
+    {
+      case MapValue::NUMERIC:
+        {
+          createEdgeMap(*it, MapValue::NUMERIC, double());
+          greader.readEdgeMap(*it, getNumericEdgeMap(*it));
+          break;
+        }
+      case MapValue::STRING:
+        {
+          createEdgeMap(*it, MapValue::STRING, string());
+          greader.readEdgeMap(*it, getStringEdgeMap(*it));
+          break;
+        }
+    }
+    getEdgeMapData(*it)->save_dest = NESET_SECT;
+  }
+
+  // read the node coordinate maps
+  if (node_coord_xmap_name != "")
+    greader.readNodeMap(node_coord_xmap_name, node_coords_x);
+  if (node_coord_ymap_name != "")
+    greader.readNodeMap(node_coord_ymap_name, node_coords_y);
+
+  // read the arrow coordinate maps
+  if (arrow_coord_xmap_name != "")
+    greader.readEdgeMap(arrow_coord_xmap_name, arrow_coords_x);
+  if (arrow_coord_ymap_name != "")
+    greader.readEdgeMap(arrow_coord_ymap_name, arrow_coords_y);
+
+  greader.run();
+}

Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h	(original)
+++ glemon/branches/akos/mapstorage.h	Wed Nov  7 16:39:00 2007
@@ -508,6 +508,16 @@
 private:
   EdgeMapData* getEdgeMapData(std::string name) const;
   NodeMapData* getNodeMapData(std::string name) const;
+  void readLGF(
+      const std::string& filename,
+      const std::vector<std::string>& node_map_names,
+      const std::vector<std::string>& edge_map_names,
+      const std::map<std::string, MapValue::Type>& node_map_types,
+      const std::map<std::string, MapValue::Type>& edge_map_types,
+      const std::string& node_coord_xmap_name,
+      const std::string& node_coord_ymap_name,
+      const std::string& arrow_coord_xmap_name,
+      const std::string& arrow_coord_ymap_name);
 };
 
 #endif //MAPSTORAGE_H



More information about the Lemon-commits mailing list