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

Lemon SVN svn at lemon.cs.elte.hu
Wed Oct 24 08:25:28 CEST 2007


Author: ladanyi
Date: Wed Oct 24 08:25:26 2007
New Revision: 3342

Modified:
   glemon/branches/akos/file_chooser_extra_widget.cc
   glemon/branches/akos/graph_displayer_canvas-node.cc
   glemon/branches/akos/gui_writer.cc
   glemon/branches/akos/io_helper.h
   glemon/branches/akos/mapstorage.cc
   glemon/branches/akos/mapstorage.h
   glemon/branches/akos/save_details_dialog.cc
   glemon/branches/akos/save_details_widget.cc
   glemon/branches/akos/save_details_widget.h

Log:
Saving works now.

Modified: glemon/branches/akos/file_chooser_extra_widget.cc
==============================================================================
--- glemon/branches/akos/file_chooser_extra_widget.cc	(original)
+++ glemon/branches/akos/file_chooser_extra_widget.cc	Wed Oct 24 08:25:26 2007
@@ -23,8 +23,6 @@
   Gtk::Expander("_Details", true),
   SaveDetails(ms)
 {
-  std::cout << "FileChooserExtraWidget()" << std::endl;
-
   add(SaveDetails);
 
   show_all_children();
@@ -32,5 +30,4 @@
 
 FileChooserExtraWidget::~FileChooserExtraWidget()
 {
-  std::cout << "~FileChooserExtraWidget()" << std::endl;
 }

Modified: glemon/branches/akos/graph_displayer_canvas-node.cc
==============================================================================
--- glemon/branches/akos/graph_displayer_canvas-node.cc	(original)
+++ glemon/branches/akos/graph_displayer_canvas-node.cc	Wed Oct 24 08:25:26 2007
@@ -297,22 +297,15 @@
       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
 	{
 	  nodemap_to_edit=mapname;
-	  double number=mytab.mapstorage.get(mapname, i);
 
-	  std::ostringstream ostr;
-	  ostr << number;
-	      
-	  nodetextmap[i]->property_text().set_value(ostr.str());
+	  nodetextmap[i]->property_text().set_value(
+              static_cast<std::string>(mytab.mapstorage.get(mapname, i)));
 	}
     }
   else
     {
-      double number=mytab.mapstorage.get(mapname, node);
-
-      std::ostringstream ostr;
-      ostr << number;
-	      
-      nodetextmap[node]->property_text().set_value(ostr.str());
+      nodetextmap[node]->property_text().set_value(
+          static_cast<std::string>(mytab.mapstorage.get(mapname, node)));
     }
   return 0;
 };

Modified: glemon/branches/akos/gui_writer.cc
==============================================================================
--- glemon/branches/akos/gui_writer.cc	(original)
+++ glemon/branches/akos/gui_writer.cc	Wed Oct 24 08:25:26 2007
@@ -34,7 +34,6 @@
 
   XmlIo x(os);
 
-
   vector<string> all_node_map_names = mapstorage->getNodeMapList();
   vector<string> node_map_names; // name of the maps need to be saved
 
@@ -210,6 +209,8 @@
   { x("redesign-iteration", iteration); }
 }
 
-GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms)
+GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) :
+  Parent(writer),
+  mapstorage(ms)
 {
 }

Modified: glemon/branches/akos/io_helper.h
==============================================================================
--- glemon/branches/akos/io_helper.h	(original)
+++ glemon/branches/akos/io_helper.h	Wed Oct 24 08:25:26 2007
@@ -49,8 +49,7 @@
   {
     for (EdgeIt e(v.graph); e != INVALID; ++e)
     {
-      //{ XmlIo::LineTag t(x,"from"); x(v.label[v.graph.source(e)]); }
-      //{ XmlIo::ContTag t(x,"to"); x(v.label[v.graph.target(e)]); }
+      { XmlIo::LineTag t(x,"from"); x(v.label[e]); }
       { XmlIo::ContTag t(x,"value"); x(v.map[e]); }
     }
   }

Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc	(original)
+++ glemon/branches/akos/mapstorage.cc	Wed Oct 24 08:25:26 2007
@@ -34,8 +34,11 @@
 const double p_d=40000;
 
 MapStorage::MapStorage() :
+  gui_sect_save_dest(LGF_FILE),
   modified(false),
   file_name(""),
+  max_node_label(0),
+  max_edge_label(0),
   iterations(i_d),
   attraction(a_d),
   propulsation(p_d),
@@ -91,8 +94,6 @@
   }
 
   nodemaps[name]->default_value = def_val;
-  nodemaps[name]->writeable = true;
-  nodemaps[name]->save_dest = GUI_SECT;
 
   signal_node_map.emit(name);
 }
@@ -118,8 +119,6 @@
   }
 
   edgemaps[name]->default_value = def_val;
-  edgemaps[name]->writeable = true;
-  edgemaps[name]->save_dest = GUI_SECT;
 
   signal_edge_map.emit(name);
 }
@@ -164,7 +163,7 @@
 {
   if (type == ALL)
   {
-    std::vector<std::string> ret(edgemaps.size());
+    std::vector<std::string> ret;
     for (EdgeMapStore::const_iterator it = edgemaps.begin();
         it != edgemaps.end(); ++it)
     {
@@ -193,13 +192,33 @@
 
 std::vector<std::string> MapStorage::getNodeMapList(MapType type)
 {
-  std::vector<std::string> ret(nodemaps.size());
-  for (NodeMapStore::const_iterator it = nodemaps.begin();
-      it != nodemaps.end(); ++it)
+  if (type == ALL)
+  {
+    std::vector<std::string> ret;
+    for (NodeMapStore::const_iterator it = nodemaps.begin();
+        it != nodemaps.end(); ++it)
+    {
+      ret.push_back(it->first);
+    }
+    return ret;
+  }
+  else
   {
-    ret.push_back(it->first);
+    std::vector<std::string> ret;
+    for (NodeMapStore::const_iterator it = nodemaps.begin();
+        it != nodemaps.end(); ++it)
+    {
+      NodeMapData* data = getNodeMapData(it->first);
+      MapValue::Type t = data->type();
+      if ((t == MapValue::INTEGER && (type & INT)) ||
+          (t == MapValue::SCALAR && (type & SCAL)) ||
+          (t == MapValue::STRING && (type & STR)))
+      {
+        ret.push_back(it->first);
+      }
+    }
+    return ret;
   }
-  return ret;
 }
 
 sigc::signal<void, bool, int> MapStorage::signal_prop_ch()
@@ -501,34 +520,75 @@
   std::cout << "Time elapsed: " << timer << std::endl;
 
   */
+
+  // set max_node_label
+  // set max_edge_label
+
   return 0;
 }
 
 //TODO
 void MapStorage::writeToFile(const std::string &filename)
 {
-  /*
-  GraphWriter<Graph> gwriter(filename, graph);
-
-  for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
-      nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
+  // relabel nodes and edges
+  int i = 0;
+  for (NodeIt n(graph); n != INVALID; ++n)
   {
-    gwriter.writeNodeMap(it->first, *(it->second));
+    node_label[n] = i++;
   }
-  for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
-      edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
+  max_node_label = i-1;
+  i = 0;
+  for (EdgeIt e(graph); e != INVALID; ++e)
   {
-    if ((it->first != "arrow_pos_x") &&
-        (it->first != "arrow_pos_y"))
+    edge_label[e] = i++;
+  }
+  max_edge_label = i-1;
+
+  // write .lgf file
+  {
+    GraphWriter<Graph> gwriter(filename, graph);
+
+    std::list<MapValueNodeMap> MapValueNodeMaps;
+    std::list<MapValueEdgeMap> MapValueEdgeMaps;
+
+    for (NodeMapStore::const_iterator it = nodemaps.begin();
+        it != nodemaps.end(); ++it)
     {
-      gwriter.writeEdgeMap(it->first, *(it->second));
+      if (it->second->save_dest == NESET_SECT)
+      {
+        MapValueNodeMaps.push_back(MapValueNodeMap(it->first, this));
+        gwriter.writeNodeMap(it->first, MapValueNodeMaps.back());
+      }
+    }
+
+    for (EdgeMapStore::const_iterator it = edgemaps.begin();
+        it != edgemaps.end(); ++it)
+    {
+      if (it->second->save_dest == NESET_SECT)
+      {
+        MapValueEdgeMaps.push_back(MapValueEdgeMap(it->first, this));
+        gwriter.writeEdgeMap(it->first, MapValueEdgeMaps.back());
+      }
     }
-  }
 
-  GuiWriter gui_writer(gwriter, this);
+    if (gui_sect_save_dest == LGF_FILE)
+    {
+      GuiWriter gui_writer(gwriter, this);
+      gwriter.run();
+    }
+    else
+    {
+      gwriter.run();
+    }
+  }
 
-  gwriter.run();
-  */
+  // write .lgf file
+  if (gui_sect_save_dest == CONF_FILE)
+  {
+    LemonWriter lwriter(filename + ".conf");
+    GuiWriter gui_writer(lwriter, this);
+    lwriter.run();
+  }
 }
 
 //TODO
@@ -923,21 +983,35 @@
   using std::endl;
 
   cout << "Node maps:" << endl;
-  for (NodeMapStore::const_iterator it = nodemaps.begin(); it != nodemaps.end(); ++it)
+  for (NodeMapStore::const_iterator it = nodemaps.begin();
+      it != nodemaps.end(); ++it)
   {
     cout << it->first << " ";
     switch (it->second->type())
     {
       case MapValue::INTEGER:
-        cout << "INTEGER" << endl;
+        cout << "INTEGER";
         break;
       case MapValue::SCALAR:
-        cout << "SCALAR" << endl;
+        cout << "SCALAR";
         break;
       case MapValue::STRING:
-        cout << "STRING" << endl;
+        cout << "STRING";
         break;
     }
+    switch (it->second->save_dest)
+    {
+      case GUI_SECT:
+        cout << " GUI section";
+        break;
+      case NESET_SECT:
+        cout << " Nodeset or Edgeset section";
+        break;
+      case DONT_SAVE:
+        cout << " Don't save";
+        break;
+    }
+    cout << endl;
     for (Graph::NodeIt n(graph); n != INVALID; ++n)
     {
       cout << it->second->get(n) << " ";
@@ -952,15 +1026,28 @@
     switch (it->second->type())
     {
       case MapValue::INTEGER:
-        cout << "INTEGER" << endl;
+        cout << "INTEGER";
         break;
       case MapValue::SCALAR:
-        cout << "SCALAR" << endl;
+        cout << "SCALAR";
         break;
       case MapValue::STRING:
-        cout << "STRING" << endl;
+        cout << "STRING";
+        break;
+    }
+    switch (it->second->save_dest)
+    {
+      case GUI_SECT:
+        cout << " GUI section";
+        break;
+      case NESET_SECT:
+        cout << " Nodeset or Edgeset section";
+        break;
+      case DONT_SAVE:
+        cout << " Don't save";
         break;
     }
+    cout << endl;
     for (Graph::EdgeIt e(graph); e != INVALID; ++e)
     {
       cout << it->second->get(e) << " ";

Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h	(original)
+++ glemon/branches/akos/mapstorage.h	Wed Oct 24 08:25:26 2007
@@ -76,6 +76,8 @@
     virtual MapValue get(Edge e) = 0;
     virtual void set(Edge e, MapValue v) = 0;
     EdgeMapData(MapValue def_val) :
+      save_dest(GUI_SECT),
+      writeable(true),
       default_value(def_val)
     {}
   };
@@ -124,6 +126,8 @@
     virtual MapValue get(Node e) = 0;
     virtual void set(Node e, MapValue v) = 0;
     NodeMapData(MapValue def_val) :
+      save_dest(GUI_SECT),
+      writeable(true),
       default_value(def_val)
     {}
   };

Modified: glemon/branches/akos/save_details_dialog.cc
==============================================================================
--- glemon/branches/akos/save_details_dialog.cc	(original)
+++ glemon/branches/akos/save_details_dialog.cc	Wed Oct 24 08:25:26 2007
@@ -5,6 +5,8 @@
   Gtk::Dialog("Save Details", true),
   SaveDetails(ms)
 {
+  set_size_request(300, -1);
+
   Gtk::VBox* pVBox = get_vbox();
   pVBox->pack_start(SaveDetails, Gtk::PACK_SHRINK);
 

Modified: glemon/branches/akos/save_details_widget.cc
==============================================================================
--- glemon/branches/akos/save_details_widget.cc	(original)
+++ glemon/branches/akos/save_details_widget.cc	Wed Oct 24 08:25:26 2007
@@ -8,8 +8,6 @@
   rbLgfFile(".lgf file", true),
   rbConfFile("separate .conf file", true)
 {
-  std::cout << "SaveDetailsWidget::SaveDetailsWidget()" << std::endl;
-
   Gtk::RadioButtonGroup group = rbLgfFile.get_group();
   rbConfFile.set_group(group);
 
@@ -34,11 +32,6 @@
   box.pack_start(rbLgfFile, Gtk::PACK_SHRINK);
   box.pack_start(rbConfFile, Gtk::PACK_SHRINK);
 
-  rbLgfFile.signal_group_changed().connect(
-      sigc::mem_fun(*this, &SaveDetailsWidget::onRbToggled));
-  rbConfFile.signal_group_changed().connect(
-      sigc::mem_fun(*this, &SaveDetailsWidget::onRbToggled));
-
   pack_start(lblMapsSave, Gtk::PACK_SHRINK);
   pack_start(nbMaps, Gtk::PACK_EXPAND_WIDGET);
 
@@ -49,7 +42,6 @@
   swEdgeMaps.add(twEdgeMaps);
 
   refNodeMapStore = Gtk::ListStore::create(NodeMapColumns);
-  //refMapStore->signal_row_changed().connect(sigc::mem_fun(*this, &Phy sicalProperties::onChannelChanged));
 
   std::vector<std::string> node_maps = pMapStorage->getNodeMapList();
   for (std::vector<std::string>::const_iterator it = node_maps.begin();
@@ -57,8 +49,21 @@
   {
     Gtk::TreeModel::Row row = *(refNodeMapStore->append());
     row[NodeMapColumns.colName] = *it;
-    row[NodeMapColumns.colSaveToMainSect] = true;
-    row[NodeMapColumns.colSaveToGuiSect] = false;
+    switch (pMapStorage->getNodeMapSaveDest(*it))
+    {
+      case MapStorage::GUI_SECT:
+        row[NodeMapColumns.colSaveToMainSect] = false;
+        row[NodeMapColumns.colSaveToGuiSect] = true;
+        break;
+      case MapStorage::NESET_SECT:
+        row[NodeMapColumns.colSaveToMainSect] = true;
+        row[NodeMapColumns.colSaveToGuiSect] = false;
+        break;
+      case MapStorage::DONT_SAVE:
+        row[NodeMapColumns.colSaveToMainSect] = false;
+        row[NodeMapColumns.colSaveToGuiSect] = false;
+        break;
+    }
   }
 
   twNodeMaps.set_model(refNodeMapStore);
@@ -67,26 +72,11 @@
       NodeMapColumns.colSaveToMainSect);
   twNodeMaps.append_column_editable("GUI section",
       NodeMapColumns.colSaveToGuiSect);
-  /*
-  {
-    Gtk::TreeView::Column* pViewColumn =
-      Gtk::manage(
-        new Gtk::TreeView::Column("Value type", NodeMapColumns.colValue));
-    twMap.append_column(*pViewColumn);
-  }
-  {
-    Gtk::TreeView::Column* pViewColumn =
-      Gtk::manage(
-        new Gtk::TreeView::Column("Map type", NodeMapColumns.colType));
-    twMap.append_column(*pViewColumn);
-  }
-  */
 
   swNodeMaps.set_size_request(250, 200);
   swNodeMaps.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
 
   refEdgeMapStore = Gtk::ListStore::create(EdgeMapColumns);
-  //refMapStore->signal_row_changed().connect(sigc::mem_fun(*this, &Phy sicalProperties::onChannelChanged));
 
   std::vector<std::string> edge_maps = pMapStorage->getEdgeMapList();
   for (std::vector<std::string>::const_iterator it = edge_maps.begin();
@@ -94,8 +84,21 @@
   {
     Gtk::TreeModel::Row row = *(refEdgeMapStore->append());
     row[EdgeMapColumns.colName] = *it;
-    row[EdgeMapColumns.colSaveToMainSect] = true;
-    row[EdgeMapColumns.colSaveToGuiSect] = false;
+    switch (pMapStorage->getEdgeMapSaveDest(*it))
+    {
+      case MapStorage::GUI_SECT:
+        row[EdgeMapColumns.colSaveToMainSect] = false;
+        row[EdgeMapColumns.colSaveToGuiSect] = true;
+        break;
+      case MapStorage::NESET_SECT:
+        row[EdgeMapColumns.colSaveToMainSect] = true;
+        row[EdgeMapColumns.colSaveToGuiSect] = false;
+        break;
+      case MapStorage::DONT_SAVE:
+        row[EdgeMapColumns.colSaveToMainSect] = false;
+        row[EdgeMapColumns.colSaveToGuiSect] = false;
+        break;
+    }
   }
 
   twEdgeMaps.set_model(refEdgeMapStore);
@@ -104,33 +107,99 @@
       EdgeMapColumns.colSaveToMainSect);
   twEdgeMaps.append_column_editable("GUI section",
       EdgeMapColumns.colSaveToGuiSect);
-  /*
-  {
-    Gtk::TreeView::Column* pViewColumn =
-      Gtk::manage(
-        new Gtk::TreeView::Column("Value type", EdgeMapColumns.colValue));
-    twMap.append_column(*pViewColumn);
-  }
-  {
-    Gtk::TreeView::Column* pViewColumn =
-      Gtk::manage(
-        new Gtk::TreeView::Column("Map type", EdgeMapColumns.colType));
-    twMap.append_column(*pViewColumn);
-  }
-  */
 
   swEdgeMaps.set_size_request(250, 200);
   swEdgeMaps.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
 
+  refNodeMapStore->signal_row_changed().connect(
+      sigc::mem_fun(*this, &SaveDetailsWidget::onNodeMapRowChanged));
+  refEdgeMapStore->signal_row_changed().connect(
+      sigc::mem_fun(*this, &SaveDetailsWidget::onEdgeMapRowChanged));
+
+  rbLgfFile.signal_toggled().connect(
+      sigc::mem_fun(*this, &SaveDetailsWidget::onRbToggled));
+  rbConfFile.signal_toggled().connect(
+      sigc::mem_fun(*this, &SaveDetailsWidget::onRbToggled));
+
   show_all_children();
 }
 
 void SaveDetailsWidget::onRbToggled()
 {
   if (rbLgfFile.get_active())
+  {
     pMapStorage->setGUIDataSaveLocation(MapStorage::LGF_FILE);
+  }
   else if (rbConfFile.get_active())
+  {
     pMapStorage->setGUIDataSaveLocation(MapStorage::CONF_FILE);
+  }
+}
+
+void SaveDetailsWidget::onEdgeMapRowChanged(const Gtk::TreeModel::Path& path,
+    const Gtk::TreeModel::iterator& iter)
+{
+  Gtk::TreeModel::Row row = *iter;
+  Glib::ustring map_name = row[EdgeMapColumns.colName];
+  if (row[EdgeMapColumns.colSaveToMainSect] &&
+      row[EdgeMapColumns.colSaveToGuiSect])
+  {
+    if (pMapStorage->getEdgeMapSaveDest(map_name) == MapStorage::NESET_SECT)
+    {
+      pMapStorage->setEdgeMapSaveDest(map_name, MapStorage::GUI_SECT);
+      row[EdgeMapColumns.colSaveToMainSect] = false;
+    }
+    else
+    {
+      pMapStorage->setEdgeMapSaveDest(map_name, MapStorage::NESET_SECT);
+      row[EdgeMapColumns.colSaveToGuiSect] = false;
+    }
+  }
+  else if (row[EdgeMapColumns.colSaveToMainSect])
+  {
+    pMapStorage->setEdgeMapSaveDest(map_name, MapStorage::NESET_SECT);
+  }
+  else if (row[EdgeMapColumns.colSaveToGuiSect])
+  {
+    pMapStorage->setEdgeMapSaveDest(map_name, MapStorage::GUI_SECT);
+  }
+  else
+  {
+    pMapStorage->setEdgeMapSaveDest(map_name, MapStorage::DONT_SAVE);
+  }
+}
+
+void SaveDetailsWidget::onNodeMapRowChanged(const Gtk::TreeModel::Path& path,
+    const Gtk::TreeModel::iterator& iter)
+{
+  Gtk::TreeModel::Row row = *iter;
+  Glib::ustring map_name = row[NodeMapColumns.colName];
+  if (row[NodeMapColumns.colSaveToMainSect] &&
+      row[NodeMapColumns.colSaveToGuiSect])
+  {
+    if (pMapStorage->getNodeMapSaveDest(map_name) == MapStorage::NESET_SECT)
+    {
+      pMapStorage->setNodeMapSaveDest(map_name, MapStorage::GUI_SECT);
+      row[NodeMapColumns.colSaveToMainSect] = false;
+    }
+    else
+    {
+      pMapStorage->setNodeMapSaveDest(map_name, MapStorage::NESET_SECT);
+      row[NodeMapColumns.colSaveToGuiSect] = false;
+    }
+  }
+  else if (row[NodeMapColumns.colSaveToMainSect])
+  {
+    pMapStorage->setNodeMapSaveDest(map_name, MapStorage::NESET_SECT);
+  }
+  else if (row[NodeMapColumns.colSaveToGuiSect])
+  {
+    pMapStorage->setNodeMapSaveDest(map_name, MapStorage::GUI_SECT);
+  }
+  else
+  {
+    pMapStorage->setNodeMapSaveDest(map_name, MapStorage::DONT_SAVE);
+  }
 }
 
 SaveDetailsWidget::~SaveDetailsWidget()

Modified: glemon/branches/akos/save_details_widget.h
==============================================================================
--- glemon/branches/akos/save_details_widget.h	(original)
+++ glemon/branches/akos/save_details_widget.h	Wed Oct 24 08:25:26 2007
@@ -44,6 +44,10 @@
     Glib::RefPtr<Gtk::ListStore> refEdgeMapStore;
     MapStorage* pMapStorage;
     void onRbToggled();
+    void onEdgeMapRowChanged(const Gtk::TreeModel::Path& path,
+        const Gtk::TreeModel::iterator& iter);
+    void onNodeMapRowChanged(const Gtk::TreeModel::Path& path,
+        const Gtk::TreeModel::iterator& iter);
   public:
     SaveDetailsWidget(MapStorage* ms);
     ~SaveDetailsWidget();



More information about the Lemon-commits mailing list