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

Lemon SVN svn at lemon.cs.elte.hu
Sat Nov 3 12:26:35 CET 2007


Author: ladanyi
Date: Sat Nov  3 12:26:30 2007
New Revision: 3355

Modified:
   glemon/branches/akos/gui_reader.cc
   glemon/branches/akos/gui_writer.cc
   glemon/branches/akos/mapstorage.cc
   glemon/branches/akos/mapstorage.h

Log:
Configurable node and arrow coordinate map save destination.

Modified: glemon/branches/akos/gui_reader.cc
==============================================================================
--- glemon/branches/akos/gui_reader.cc	(original)
+++ glemon/branches/akos/gui_reader.cc	Sat Nov  3 12:26:30 2007
@@ -102,10 +102,53 @@
     }
   }
 
-  // read the node coorinates
-  { x("node_coord_map", gui_data.node_coord_map); }
-  // read the arrow coorinates
-  { x("arrow_coord_map", gui_data.arrow_coord_map); }
+  {
+    std::string node_coords_save_dest;
+    { x("node_coords_save_dest", node_coords_save_dest); }
+    if (node_coords_save_dest == "gui_sect")
+    {
+      // read the node coorinates
+      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
+      { x("node_coord_map", gui_data.node_coord_map); }
+    }
+    else if (node_coords_save_dest == "nodeset_sect_1_map")
+    {
+      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
+      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
+      { x("map_name", gui_data.node_coords_one_map_name); }
+    }
+    else if (node_coords_save_dest == "nodeset_sect_2_maps")
+    {
+      gui_data.node_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
+      gui_data.node_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
+      { x("map1_name", gui_data.node_coords_two_maps_1_name); }
+      { x("map2_name", gui_data.node_coords_two_maps_2_name); }
+    }
+  }
+
+  {
+    std::string arrow_coords_save_dest;
+    { x("arrow_coords_save_dest", arrow_coords_save_dest); }
+    if (arrow_coords_save_dest == "gui_sect")
+    {
+      // read the arrow coorinates
+      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::GUI_SECT;
+      { x("arrow_coord_map", gui_data.arrow_coord_map); }
+    }
+    else if (arrow_coords_save_dest == "edgeset_sect_1_map")
+    {
+      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
+      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::ONE_MAP;
+      { x("map_name", gui_data.arrow_coords_one_map_name); }
+    }
+    else if (arrow_coords_save_dest == "edgeset_sect_2_maps")
+    {
+      gui_data.arrow_coords_save_dest = MapStorage::SpecMapSaveOpts::NESET_SECT;
+      gui_data.arrow_coords_save_map_num = MapStorage::SpecMapSaveOpts::TWO_MAPS;
+      { x("map1_name", gui_data.arrow_coords_two_maps_1_name); }
+      { x("map2_name", gui_data.arrow_coords_two_maps_2_name); }
+    }
+  }
 
 
 

Modified: glemon/branches/akos/gui_writer.cc
==============================================================================
--- glemon/branches/akos/gui_writer.cc	(original)
+++ glemon/branches/akos/gui_writer.cc	Sat Nov  3 12:26:30 2007
@@ -171,31 +171,77 @@
     }
   }
 
-  // write the node coorinates
   {
-    const MapStorage::NodeLabelMap& labels = mapstorage->getNodeLabelMap();
-    std::map<int, XY> node_coord_map;
-    MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
-    for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
+    switch (mapstorage->getNodeCoordsSaveDest())
     {
-      node_coord_map[labels[n]] = map[n];
+      case MapStorage::SpecMapSaveOpts::GUI_SECT:
+        { x("node_coords_save_dest", string("gui_sect")); }
+        // write the node coorinates
+        {
+          const MapStorage::NodeLabelMap& labels =
+            mapstorage->getNodeLabelMap();
+          std::map<int, XY> node_coord_map;
+          MapStorage::NodeCoordMap& map = mapstorage->getNodeCoordMap();
+          for (NodeIt n(mapstorage->getGraph()); n != INVALID; ++n)
+          {
+            node_coord_map[labels[n]] = map[n];
+          }
+          { x("node_coord_map", node_coord_map); }
+        }
+        break;
+      case MapStorage::SpecMapSaveOpts::NESET_SECT:
+        switch (mapstorage->getNodeCoordsSaveMapNum())
+        {
+          case MapStorage::SpecMapSaveOpts::ONE_MAP:
+            { x("node_coords_save_dest", string("nodeset_sect_1_map")); }
+            { x("map_name", mapstorage->getNodeCoordsOneMapName()); }
+            break;
+          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
+            { x("node_coords_save_dest", string("nodeset_sect_2_maps")); }
+            { x("map1_name", mapstorage->getNodeCoordsTwoMaps1Name()); }
+            { x("map2_name", mapstorage->getNodeCoordsTwoMaps2Name()); }
+            break;
+        }
+        break;
     }
-    { x("node_coord_map", node_coord_map); }
   }
-  // write the arrow coorinates
+
   {
-    const MapStorage::EdgeLabelMap& labels = mapstorage->getEdgeLabelMap();
-    std::map<int, XY> arrow_coord_map;
-    MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
-    for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
+    switch (mapstorage->getArrowCoordsSaveDest())
     {
-      arrow_coord_map[labels[e]] = map[e];
+      case MapStorage::SpecMapSaveOpts::GUI_SECT:
+        { x("arrow_coords_save_dest", string("gui_sect")); }
+        // write the arrow coorinates
+        {
+          const MapStorage::EdgeLabelMap& labels =
+            mapstorage->getEdgeLabelMap();
+          std::map<int, XY> arrow_coord_map;
+          MapStorage::ArrowCoordMap& map = mapstorage->getArrowCoordMap();
+          for (EdgeIt e(mapstorage->getGraph()); e != INVALID; ++e)
+          {
+            arrow_coord_map[labels[e]] = map[e];
+          }
+          { x("arrow_coord_map", arrow_coord_map); }
+        }
+        break;
+      case MapStorage::SpecMapSaveOpts::NESET_SECT:
+        switch (mapstorage->getArrowCoordsSaveMapNum())
+        {
+          case MapStorage::SpecMapSaveOpts::ONE_MAP:
+            { x("arrow_coords_save_dest", string("edgeset_sect_1_map")); }
+            { x("map_name", mapstorage->getArrowCoordsOneMapName()); }
+            break;
+          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
+            { x("arrow_coords_save_dest", string("edgeset_sect_2_maps")); }
+            { x("map1_name", mapstorage->getArrowCoordsTwoMaps1Name()); }
+            { x("map2_name", mapstorage->getArrowCoordsTwoMaps2Name()); }
+            break;
+        }
+        break;
     }
-    { x("arrow_coord_map", arrow_coord_map); }
   }
 
 
-
   std::map<int, std::string> nm;
   for(int i=0;i<NODE_PROPERTY_NUM;i++)
     {

Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc	(original)
+++ glemon/branches/akos/mapstorage.cc	Sat Nov  3 12:26:30 2007
@@ -49,11 +49,18 @@
   iterations(i_d),
   attraction(a_d),
   propulsation(p_d),
-  node_coords(graph),
-  arrow_coords(graph),
+  node_coords_x(graph),
+  node_coords_y(graph),
+  arrow_coords_x(graph),
+  arrow_coords_y(graph),
   node_label(graph),
   edge_label(graph)
 {
+  node_coords.setXMap(node_coords_x);
+  node_coords.setYMap(node_coords_y);
+  arrow_coords.setXMap(arrow_coords_x);
+  arrow_coords.setYMap(arrow_coords_y);
+
   active_nodemaps.resize(NODE_PROPERTY_NUM);
   for(int i=0;i<NODE_PROPERTY_NUM;i++)
     {
@@ -77,7 +84,7 @@
 {
   NodeMapStore::const_iterator it = nodemaps.find(name);
   if (it != nodemaps.end())
-    throw MapAlreadyExists();
+    throw MapAlreadyExists(name);
 
   switch (type)
   {
@@ -99,7 +106,7 @@
 {
   EdgeMapStore::const_iterator it = edgemaps.find(name);
   if (it != edgemaps.end())
-    throw MapAlreadyExists();
+    throw MapAlreadyExists(name);
 
   switch (type)
   {
@@ -344,9 +351,11 @@
         << " 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)
@@ -369,6 +378,7 @@
         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)
@@ -391,6 +401,76 @@
         getEdgeMapData(*it)->save_dest = NESET_SECT;
       }
 
+      // 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;
+            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;
+            break;
+        }
+      }
+
+      // 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;
+            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_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;
+        }
+      }
+
       greader.run();
     }
     catch (Exception& error)
@@ -416,6 +496,7 @@
             {
               dmap[n] = smap[node_label[n]];
             }
+            break;
           }
         case MapValue::STRING:
           {
@@ -426,6 +507,7 @@
             {
               dmap[n] = smap[node_label[n]];
             }
+            break;
           }
       }
       getNodeMapData(map_name)->save_dest = GUI_SECT;
@@ -446,6 +528,7 @@
             {
               dmap[e] = smap[edge_label[e]];
             }
+            break;
           }
         case MapValue::STRING:
           {
@@ -456,19 +539,31 @@
             {
               dmap[e] = smap[edge_label[e]];
             }
+            break;
           }
       }
       getEdgeMapData(map_name)->save_dest = GUI_SECT;
     }
 
-    // restore the node and arrow coordinate maps
-    for (NodeIt n(graph); n != INVALID; ++n)
+    // restore the node coordinate maps
+    if (gui_data.node_coords_save_dest ==
+        MapStorage::SpecMapSaveOpts::GUI_SECT)
     {
-      node_coords[n] = gui_data.node_coord_map[node_label[n]];
+      for (NodeIt n(graph); n != INVALID; ++n)
+      {
+        node_coords.set(n, gui_data.node_coord_map[node_label[n]]);
+      }
+      node_coords_save_dest = gui_data.node_coords_save_dest;
     }
-    for (EdgeIt e(graph); e != INVALID; ++e)
+    // restore the arrow coordinate maps
+    if (gui_data.arrow_coords_save_dest ==
+        MapStorage::SpecMapSaveOpts::GUI_SECT)
     {
-      arrow_coords[e] = gui_data.arrow_coord_map[edge_label[e]];
+      for (EdgeIt e(graph); e != INVALID; ++e)
+      {
+        arrow_coords.set(e, gui_data.arrow_coord_map[edge_label[e]]);
+      }
+      arrow_coords_save_dest = gui_data.arrow_coords_save_dest;
     }
   }
   else
@@ -742,6 +837,7 @@
     gwriter.writeNodeMap("label", node_label);
     gwriter.writeEdgeMap("label", edge_label);
 
+    // write node maps
     for (NodeMapStore::const_iterator it = nodemaps.begin();
         it != nodemaps.end(); ++it)
     {
@@ -759,6 +855,7 @@
       }
     }
 
+    // write edge maps
     for (EdgeMapStore::const_iterator it = edgemaps.begin();
         it != edgemaps.end(); ++it)
     {
@@ -776,6 +873,54 @@
       }
     }
 
+    // write node coordinates
+    switch (getNodeCoordsSaveDest())
+    {
+      case MapStorage::SpecMapSaveOpts::GUI_SECT:
+        break;
+      case MapStorage::SpecMapSaveOpts::NESET_SECT:
+        switch (getNodeCoordsSaveMapNum())
+        {
+          case MapStorage::SpecMapSaveOpts::ONE_MAP:
+            gwriter.writeNodeMap(node_coords_one_map_name + ":x",
+                node_coords_x);
+            gwriter.writeNodeMap(node_coords_one_map_name + ":y",
+                node_coords_y);
+            break;
+          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
+            gwriter.writeNodeMap(node_coords_two_maps_1_name,
+                node_coords_x);
+            gwriter.writeNodeMap(node_coords_two_maps_2_name,
+                node_coords_y);
+            break;
+        }
+        break;
+    }
+
+    // write arrow coordinates
+    switch (getArrowCoordsSaveDest())
+    {
+      case MapStorage::SpecMapSaveOpts::GUI_SECT:
+        break;
+      case MapStorage::SpecMapSaveOpts::NESET_SECT:
+        switch (getArrowCoordsSaveMapNum())
+        {
+          case MapStorage::SpecMapSaveOpts::ONE_MAP:
+            gwriter.writeEdgeMap(arrow_coords_one_map_name + ":x",
+                arrow_coords_x);
+            gwriter.writeEdgeMap(arrow_coords_one_map_name + ":y",
+                arrow_coords_y);
+            break;
+          case MapStorage::SpecMapSaveOpts::TWO_MAPS:
+            gwriter.writeEdgeMap(arrow_coords_two_maps_1_name,
+                arrow_coords_x);
+            gwriter.writeEdgeMap(arrow_coords_two_maps_2_name,
+                arrow_coords_y);
+            break;
+        }
+        break;
+    }
+
     if (gui_sect_save_dest == LGF_FILE)
     {
       GuiWriter gui_writer(gwriter, this);
@@ -811,10 +956,19 @@
   graph.clear();
   file_name = "";
   modified = false;
-  gui_sect_save_dest = LGF_FILE;
   max_node_label = 0;
   max_edge_label = 0;
 
+  gui_sect_save_dest = LGF_FILE;
+  node_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
+  arrow_coords_save_dest = SpecMapSaveOpts::GUI_SECT;
+  node_coords_one_map_name = "coord";
+  node_coords_two_maps_1_name = "coord_x";
+  node_coords_two_maps_2_name = "coord_y";
+  arrow_coords_one_map_name = "arrow";
+  arrow_coords_two_maps_1_name = "arrow_x";
+  arrow_coords_two_maps_2_name = "arrow_y";
+
   for(int i=0;i<NODE_PROPERTY_NUM;i++)
     {
       changeActiveMap(false, i, "");
@@ -1000,28 +1154,28 @@
 MapStorage::NumericNodeMap& MapStorage::getNumericNodeMap(const std::string& name)
 {
   NodeMapData* data = getNodeMapData(name);
-  if (data->type() != MapValue::NUMERIC) throw NonexistentMap();
+  if (data->type() != MapValue::NUMERIC) throw NonexistentMap(name);
   return static_cast<NumericNodeMapData*>(data)->map;
 }
 
 MapStorage::StringNodeMap& MapStorage::getStringNodeMap(const std::string& name)
 {
   NodeMapData* data = getNodeMapData(name);
-  if (data->type() != MapValue::STRING) throw NonexistentMap();
+  if (data->type() != MapValue::STRING) throw NonexistentMap(name);
   return static_cast<StringNodeMapData*>(data)->map;
 }
 
 MapStorage::NumericEdgeMap& MapStorage::getNumericEdgeMap(const std::string& name)
 {
   EdgeMapData* data = getEdgeMapData(name);
-  if (data->type() != MapValue::NUMERIC) throw NonexistentMap();
+  if (data->type() != MapValue::NUMERIC) throw NonexistentMap(name);
   return static_cast<NumericEdgeMapData*>(data)->map;
 }
 
 MapStorage::StringEdgeMap& MapStorage::getStringEdgeMap(const std::string& name)
 {
   EdgeMapData* data = getEdgeMapData(name);
-  if (data->type() != MapValue::STRING) throw NonexistentMap();
+  if (data->type() != MapValue::STRING) throw NonexistentMap(name);
   return static_cast<StringEdgeMapData*>(data)->map;
 }
 
@@ -1085,7 +1239,7 @@
   if (it != edgemaps.end())
     return it->second;
   else
-    throw NonexistentMap();
+    throw NonexistentMap(name);
 }
 
 MapStorage::NodeMapData* MapStorage::getNodeMapData(std::string name) const
@@ -1094,7 +1248,7 @@
   if (it != nodemaps.end())
     return it->second;
   else
-    throw NonexistentMap();
+    throw NonexistentMap(name);
 }
 
 MapValue::Type MapStorage::getNodeMapElementType(std::string name) const

Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h	(original)
+++ glemon/branches/akos/mapstorage.h	Sat Nov  3 12:26:30 2007
@@ -46,18 +46,30 @@
 public:
   class NonexistentMap : public std::exception
   {
-    virtual const char* what() const throw()
-    {
-      return "Map does not exist.";
-    }
+    private:
+      std::string message;
+    public:
+      NonexistentMap(const std::string& name) :
+        message("Map '" + name + "' does not exist.") {}
+      virtual const char* what() const throw()
+      {
+        return message.c_str();
+      }
+      ~NonexistentMap() throw() {}
   };
 
   class MapAlreadyExists : public std::exception
   {
-    virtual const char* what() const throw()
-    {
-      return "This map already exists.";
-    }
+    private:
+      std::string message;
+    public:
+      MapAlreadyExists(const std::string& name) :
+        message("Map '" + name + "' already exists.") {}
+      virtual const char* what() const throw()
+      {
+        return message.c_str();
+      }
+      ~MapAlreadyExists() throw() {}
   };
 
   enum MapSaveDest { GUI_SECT, NESET_SECT, DONT_SAVE };
@@ -74,8 +86,8 @@
   typedef Graph::EdgeMap<std::string> StringEdgeMap;
   typedef Graph::NodeMap<int> NodeLabelMap;
   typedef Graph::EdgeMap<int> EdgeLabelMap;
-  typedef Graph::NodeMap<XY> NodeCoordMap;
-  typedef Graph::EdgeMap<XY> ArrowCoordMap;
+  typedef XYMap<Graph::NodeMap<double> > NodeCoordMap;
+  typedef XYMap<Graph::EdgeMap<double> > ArrowCoordMap;
 
   struct EdgeMapData
   {
@@ -184,6 +196,18 @@
     std::map<int, XY> node_coord_map;
     std::map<int, XY> arrow_coord_map;
 
+    SpecMapSaveOpts::Dest node_coords_save_dest;
+    SpecMapSaveOpts::MapNum node_coords_save_map_num;
+    std::string node_coords_one_map_name;
+    std::string node_coords_two_maps_1_name;
+    std::string node_coords_two_maps_2_name;
+
+    SpecMapSaveOpts::Dest arrow_coords_save_dest;
+    SpecMapSaveOpts::MapNum arrow_coords_save_map_num;
+    std::string arrow_coords_one_map_name;
+    std::string arrow_coords_two_maps_1_name;
+    std::string arrow_coords_two_maps_2_name;
+
     ~GUISectData()
     {
       using std::map;
@@ -234,9 +258,13 @@
 
   /// the coordinates of the nodes
   NodeCoordMap node_coords;
+  Graph::NodeMap<double> node_coords_x;
+  Graph::NodeMap<double> node_coords_y;
 
   /// the coordinates of the arrows on the edges
   ArrowCoordMap arrow_coords;
+  Graph::EdgeMap<double> arrow_coords_x;
+  Graph::EdgeMap<double> arrow_coords_y;
 
   ///The content of the object has changed, update is needed.
   bool modified;



More information about the Lemon-commits mailing list