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

Lemon SVN svn at lemon.cs.elte.hu
Mon Apr 16 10:21:16 CEST 2007


Author: ladanyi
Date: Mon Apr 16 10:21:14 2007
New Revision: 3254

Modified:
   glemon/branches/akos/algobox.cc
   glemon/branches/akos/all_include.h
   glemon/branches/akos/map_win.cc
   glemon/branches/akos/mapselector.cc
   glemon/branches/akos/mapselector.h
   glemon/branches/akos/mapstorage.cc
   glemon/branches/akos/mapstorage.h
   glemon/branches/akos/new_map_win.cc
   glemon/branches/akos/new_map_win.h

Log:
- MapSelector and NewMapWin changes to handle multiple map types.


Modified: glemon/branches/akos/algobox.cc
==============================================================================
--- glemon/branches/akos/algobox.cc	(original)
+++ glemon/branches/akos/algobox.cc	Mon Apr 16 10:21:14 2007
@@ -80,23 +80,19 @@
 void AlgoBox::update_maplist(MapStorage * ms)
 {
   mapstorage=ms;
-  std::vector<std::string> nml;
-  std::vector<std::string> eml;
   if(mapstorage!=NULL)
     {
       mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
       mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
-      nml=mapstorage->getNodeMapList();
-      eml=mapstorage->getEdgeMapList();
     }
   for(int i=0;i<(int)nodemapcbts.size();i++)
     {
-      (nodemapcbts[i])->update_list(nml);
+      (nodemapcbts[i])->update_list(ms);
       //update_cbt(nml, *(nodemapcbts[i]));
     }
   for(int i=0;i<(int)edgemapcbts.size();i++)
     {
-      (edgemapcbts[i])->update_list(eml);
+      (edgemapcbts[i])->update_list(ms);
       //update_cbt(eml, *(edgemapcbts[i]));
     }
   signal_maplist_updated.emit();

Modified: glemon/branches/akos/all_include.h
==============================================================================
--- glemon/branches/akos/all_include.h	(original)
+++ glemon/branches/akos/all_include.h	Mon Apr 16 10:21:14 2007
@@ -64,4 +64,12 @@
 
 const std::string prog_name = "LEMON Graph Editor";
 
+enum MapType
+{
+  INT  = 1 << 0,
+  SCAL = 1 << 1,
+  STR  = 1 << 2,
+  ALL  = (1 << 0) | (1 << 1) | (1 << 2)
+};
+
 #endif // ALL_INCLUDE_H

Modified: glemon/branches/akos/map_win.cc
==============================================================================
--- glemon/branches/akos/map_win.cc	(original)
+++ glemon/branches/akos/map_win.cc	Mon Apr 16 10:21:14 2007
@@ -103,12 +103,12 @@
 {
   for(int i=0;i<EDGE_PROPERTY_NUM;i++)
   {
-    e_combo_array[i]->update_list(eml);
+    e_combo_array[i]->update_list(&mytab.mapstorage);
   }
 
   for(int i=0;i<NODE_PROPERTY_NUM;i++)
   {
-    n_combo_array[i]->update_list(nml);
+    n_combo_array[i]->update_list(&mytab.mapstorage);
   }
 
   mytab.active_maps_needed();

Modified: glemon/branches/akos/mapselector.cc
==============================================================================
--- glemon/branches/akos/mapselector.cc	(original)
+++ glemon/branches/akos/mapselector.cc	Mon Apr 16 10:21:14 2007
@@ -18,7 +18,7 @@
 
 #include "mapselector.h"
 
-MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false)
+MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, MapType type, bool d):def(d),itisedge(edge),set_new_map(false), map_type(type)
 {
   update_list(ml);
 
@@ -81,17 +81,26 @@
   signal_newmapwin.emit(itisedge);
 }
 
-void MapSelector::update_list( std::vector< std::string > ml )
+void MapSelector::update_list( MapStorage* ms )
 {
+  using std::string;
+  using std::vector;
   int prev_act=cbt.get_active_row_number();
   cbt.clear();
   cbt_content.clear();
-  std::vector< std::string >::iterator emsi=ml.begin();
-  for(;emsi!=ml.end();emsi++)
-    {
-      cbt.append_text(*emsi);
-      cbt_content.push_back(*emsi);
-    }
+
+  vector<string> v;
+  if (itisedge)
+    v = ms->getEdgeMapList(map_type);
+  else
+    v = ms->getNodeMapList(map_type);
+
+  for (vector<string>::const_iterator it = v.begin(); it != v.end(); ++v)
+  {
+    cbt.append_text(*it);
+    cbt_content.push_back(*it);
+  }
+
   if(def)
     {
       cbt.prepend_text("Default values");

Modified: glemon/branches/akos/mapselector.h
==============================================================================
--- glemon/branches/akos/mapselector.h	(original)
+++ glemon/branches/akos/mapselector.h	Mon Apr 16 10:21:14 2007
@@ -99,6 +99,9 @@
   ///Shows purpose of \ref MapSelector piece.
   Gtk::Label * label;
 
+  /// Which types of maps (integer, string, ...) to display.
+  MapType map_type;
+
  public:
 
   ///Constructor of \ref MapSelector
@@ -109,7 +112,7 @@
   ///\param purpose text of label indicating purpose of \ref MapStorage
   ///\param itisedge do \ref MapSelector contains edgemap names or nodemapnames.
   ///\param def do we need 'Default' option. See \ref def.
-  MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true);
+  MapSelector(std::vector<std::string> optionlist, std::string act, std::string purpose, bool itisedge, bool def=true, MapType type = ALL);
 
   ///Returns signal emitted if the user has changed the selection. (\ref signal_cbt)
   sigc::signal<void, std::string> signal_cbt_ch();
@@ -122,7 +125,7 @@
   ///Fills in \ref cbt with names, taking
   ///into account that the previously selected option
   ///has to be set back after the operation.
-  void update_list( std::vector<std::string> );
+  void update_list( MapStorage* );
 
   ///Handles changement in \ref cbt.
 

Modified: glemon/branches/akos/mapstorage.cc
==============================================================================
--- glemon/branches/akos/mapstorage.cc	(original)
+++ glemon/branches/akos/mapstorage.cc	Mon Apr 16 10:21:14 2007
@@ -169,15 +169,35 @@
   return active_nodemaps[prop];
 }
 
-std::vector<std::string> MapStorage::getEdgeMapList()
+std::vector<std::string> MapStorage::getEdgeMapList(MapType type = ALL)
 {
-  std::vector<std::string> ret(edgemaps.size());
-  for (EdgeMapStore::const_iterator it = edgemaps.begin();
-      it != edgemaps.end(); ++it)
+  it (type == ALL)
   {
-    ret.push_back(it->first);
+    std::vector<std::string> ret(edgemaps.size());
+    for (EdgeMapStore::const_iterator it = edgemaps.begin();
+        it != edgemaps.end(); ++it)
+    {
+      ret.push_back(it->first);
+    }
+    return ret;
+  }
+  else
+  {
+    std::vector<std::string> ret;
+    for (EdgeMapStore::const_iterator it = edgemaps.begin();
+        it != edgemaps.end(); ++it)
+    {
+      EdgeMapData* data = getEdgeMapData(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;
 }
 
 std::vector<std::string> MapStorage::getNodeMapList()
@@ -789,11 +809,6 @@
   return static_cast<StringEdgeMapData*>(data)->map;
 }
 
-const Graph::EdgeMap<double>& MapStorage::getEdgeMap(const std::string& name)
-{
-  return *edgemap_storage[name];
-}
-
 int MapStorage::getLabel(Node n) const
 {
   return node_label[n];
@@ -882,3 +897,21 @@
 {
   return graph;
 }
+
+bool MapStorage::nodeMapExists(std::string name)
+{
+  NodeMapStore::const_iterator it = nodemaps.find(name);
+  if (it == nodemaps.end())
+    return false;
+  else
+    return true;
+}
+
+bool MapStorage::edgeMapExists(std::string name)
+{
+  EdgeMapStore::const_iterator it = edgemaps.find(name);
+  if (it == edgemaps.end())
+    return false;
+  else
+    return true;
+}

Modified: glemon/branches/akos/mapstorage.h
==============================================================================
--- glemon/branches/akos/mapstorage.h	(original)
+++ glemon/branches/akos/mapstorage.h	Mon Apr 16 10:21:14 2007
@@ -388,6 +388,9 @@
   const NodeLabelMap& getNodeLabelMap();
   const EdgeLabelMap& getEdgeLabelMap();
 
+  bool nodeMapExists(std::string name);
+  bool edgeMapExists(std::string name);
+
 private:
   EdgeMapData* getEdgeMapData(std::string name) const;
   NodeMapData* getNodeMapData(std::string name) const;

Modified: glemon/branches/akos/new_map_win.cc
==============================================================================
--- glemon/branches/akos/new_map_win.cc	(original)
+++ glemon/branches/akos/new_map_win.cc	Mon Apr 16 10:21:14 2007
@@ -27,7 +27,7 @@
   return true;
 }
 
-NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap")
+NewMapWin::NewMapWin(const std::string& title, NoteBookTab & mw, bool itisedge, bool edgenode, MapType type):Gtk::Dialog(title, true, true),mytab(mw),node("Create NodeMap"),edge("Create EdgeMap"),map_type(type)
 {
   set_default_size(200, 50);
 
@@ -36,7 +36,7 @@
   Gtk::VBox * vbox=get_vbox();
 
   //entries
-  table=new Gtk::Table(3, 2, false);
+  table=new Gtk::Table(5, 2, false);
 
   label=new Gtk::Label;
   label->set_text("Name of new map:");
@@ -45,12 +45,23 @@
   (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
   (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
 
+  lblType.set_label("Element type:");
+  if (map_type & INT)
+    cbType.append_text("integer");
+  else if (map_type & SCAL)
+    cbType.append_text("scalar");
+  else if (map_type & STR)
+    cbType.append_text("string");
+
+  (*table).attach(lblType,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
+  (*table).attach(cbType, 1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
+
   label=new Gtk::Label;
   label->set_text("Default value in the map:");
   default_value.set_text("0");
 
-  (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
-  (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
+  (*table).attach(*label,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
+  (*table).attach(default_value,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
 
   //node vs. edge map selector
   Gtk::RadioButton::Group group = node.get_group();
@@ -58,8 +69,8 @@
 
   if(edgenode)
   {
-    (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
-    (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
+    (*table).attach(node,0,1,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
+    (*table).attach(edge,1,2,3,4,Gtk::SHRINK,Gtk::SHRINK,10,3);
   }
   else
   {
@@ -73,6 +84,8 @@
     }
   }
 
+  (*table).attach(lblErrorMsg,0,2,4,5,Gtk::SHRINK,Gtk::SHRINK,10,3);
+
   vbox->pack_start(*table);
 
   //OK button
@@ -82,6 +95,146 @@
 
 }
 
+void NewMapWin::setErrorMsg(const Glib::ustring& msg)
+{
+  lblErrorMsg.set_markup("<i><small>" + msg + "</i></small>");
+}
+
+std::vector<double>* NewMapWin::evaluate_expr(const std::string polishform)
+{
+  std::vector<double>* ret = new std::vector<double>;
+  std::stack<double> polishstack;
+
+  for(EdgeIt k(mytab.mapstorage.graph); k!=INVALID; ++k)
+  {
+    for(int i=0;i<(int)polishform.size();i++)
+    {
+      double op1=0, op2=0;
+      bool operation=true;
+      switch(polishform[i])
+      {
+        case '+':
+        case '-':
+        case '/':
+        case '*':
+          op1=polishstack.top();
+          polishstack.pop();
+          op2=polishstack.top();
+          polishstack.pop();
+          break;
+        default:
+          //substitute variable
+          std::vector<std::string> ems = mytab.mapstorage.getEdgeMapList(map_type);
+          bool itisvar=(std::find(ems.begin(), ems.end(), ch2var[ polishform[i] ]) != ems.end());
+          if(itisvar)
+          {
+            polishstack.push(mytab.mapstorage.get(ch2var[ polishform[i] ], k));
+          }
+          else
+          {
+            polishstack.push(atof(ch2var[ polishform[i] ].c_str()));
+          }
+          operation=false;
+          break;
+      }
+      if(operation)
+      {
+        double res;
+        switch(polishform[i])
+        {
+          case '+':
+            res=op1+op2;
+            break;
+          case '-':
+            res=op2-op1;
+            break;
+          case '/':
+            res=op2/op1;
+            break;
+          case '*':
+            res=op1*op2;
+            break;
+          default:
+            std::cout << "How could we get here?" << std::endl;
+            break;
+        }
+        polishstack.push(res);
+      }
+    }//foreach letter in polishform
+    ret->push_back(polishstack.top());
+  }//foreach edge
+  return ret;
+}
+
+void NewMapWin::on_response(int response_id)
+{
+  if(response_id==Gtk::RESPONSE_OK)
+  {
+    std::string map_name = name.get_text();
+    std::string def_val = default_value.get_text();
+
+    if (map_name.empty())
+    {
+      setErrorMsg("No map name given.");
+      return;
+    }
+
+    if (edge.get_active())
+    {
+      if (mytab.mapstorage.edgeMapExists(map_name))
+      {
+        setErrorMsg("Map '" + map_name "' already exists.");
+        return;
+      }
+    }
+    else
+    {
+      if (mytab.mapstorage.nodeMapExists(map_name))
+      {
+        setErrorMsg("Map '" + map_name "' already exists.");
+        return;
+      }
+    }
+
+    Glib::ustring text cbType.get_active_text();
+    if (text == "integer")
+    {
+    }
+    else if (text == "scalar")
+    {
+      double d;
+      char *endptr;
+      d = strtod(def_val.c_str(), &endptr);
+      if (s.c_str() + s.length() == endptr)
+      {
+        // the full string was a number
+        if (edge.get_active())
+          mytab.mapstorage.createEdgeMap(map_name, MapValue::SCALAR,
+              MapValue(d));
+        else
+          mytab.mapstorage.createNodeMap(map_name, MapValue::SCALAR,
+              MapValue(d));
+      }
+      else
+      {
+        // let't try to evaluate the string as an arithmetic expression
+        std::vector<double>* values;
+        values = evaluate_expr(string2Polishform(def_val, edge.get_active()));
+        // TODO
+      }
+    }
+    else if (text == "string")
+    {
+      if (edge.get_active())
+        mytab.mapstorage.createEdgeMap(map_name, MapValue::STRING,
+            MapValue(def_val));
+      else
+        mytab.mapstorage.createNodeMap(map_name, MapValue::STRING,
+            MapValue(def_val));
+    }
+  }
+}
+
 void NewMapWin::on_response(int response_id)
 {
   if(response_id==Gtk::RESPONSE_OK)

Modified: glemon/branches/akos/new_map_win.h
==============================================================================
--- glemon/branches/akos/new_map_win.h	(original)
+++ glemon/branches/akos/new_map_win.h	Mon Apr 16 10:21:14 2007
@@ -36,6 +36,15 @@
   ///The \ref NoteBookTab in which the new map has to be placed.
   NoteBookTab & mytab;
 
+  MapType map_type;
+  Gtk::Label lblType;
+  Gtk::ComboBoxText cbType;
+
+  Gtk::Label lblErrorMsg;
+  void setErrorMsg(const Glib::ustring& msg);
+
+  std::vector<double>* evaluate_expr(const std::string polishform);
+
 public:
 
   ///Struct to be able to evaluate expressions.
@@ -60,7 +69,7 @@
 
   ///It creates the widgets shown in
   ///NewMapWin.
-  NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true);
+  NewMapWin(const std::string& title, NoteBookTab &, bool itisedge=true, bool edgenode=true, MapType type = ALL);
 
   ///Callback function for OK button. It creates the map.
   



More information about the Lemon-commits mailing list