[Lemon-commits] [lemon_svn] hegyi: r3017 - glemon/trunk

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 21:51:52 CET 2006


Author: hegyi
Date: Wed Oct 25 15:21:24 2006
New Revision: 3017

Modified:
   glemon/trunk/design_win.cc
   glemon/trunk/design_win.h
   glemon/trunk/graph_displayer_canvas.cc
   glemon/trunk/graph_displayer_canvas.h
   glemon/trunk/gui_reader.cc
   glemon/trunk/gui_writer.cc
   glemon/trunk/map_win.cc
   glemon/trunk/map_win.h
   glemon/trunk/mapselector.cc
   glemon/trunk/mapselector.h
   glemon/trunk/mapstorage.cc
   glemon/trunk/mapstorage.h
   glemon/trunk/nbtab.cc
   glemon/trunk/nbtab.h

Log:
Currently visualized map can be saved and loaded from file.

Modified: glemon/trunk/design_win.cc
==============================================================================
--- glemon/trunk/design_win.cc	(original)
+++ glemon/trunk/design_win.cc	Wed Oct 25 15:21:24 2006
@@ -9,10 +9,12 @@
   return true;
 }
 
-DesignWin::DesignWin(const std::string& title, double attraction_v, double propulsation_v, int iterations_v)
+DesignWin::DesignWin(const std::string& title, double attraction_v, double propulsation_v, int iterations_v, NoteBookTab & mw):mytab(mw)
 {
   set_title(title);
 
+  mytab.signal_title_ch().connect(sigc::mem_fun(*this, &DesignWin::set_title));
+
   signal_key_press_event().connect(sigc::mem_fun(*this, &DesignWin::closeIfEscapeIsPressed));
 
   Gtk::VBox * vbox=new Gtk::VBox();
@@ -64,3 +66,8 @@
 {
   signal_iteration_ch.emit((int)iteration->get_value());
 }
+
+void DesignWin::set_title(std::string tabname)
+{
+  Gtk::Window::set_title("Design Setup - "+tabname);
+}

Modified: glemon/trunk/design_win.h
==============================================================================
--- glemon/trunk/design_win.h	(original)
+++ glemon/trunk/design_win.h	Wed Oct 25 15:21:24 2006
@@ -3,13 +3,19 @@
 #ifndef DESWIN_H
 #define DESWIN_H
 
+class DesignWin;
+
 #include <all_include.h>
+#include <nbtab.h>
 #include <libgnomecanvasmm.h>
 #include <libgnomecanvasmm/polygon.h>
 
 class DesignWin : public Gtk::Window
 {
 private:
+  ///\ref NoteBookTab to that the \ref MapWin belongs to.
+  NoteBookTab & mytab;
+
   Gtk::SpinButton * attraction;
   Gtk::SpinButton * propulsation;
   Gtk::SpinButton * iteration;
@@ -33,11 +39,13 @@
   ///Constructor
 
   ///It builds the window.
-  DesignWin(const std::string&, double, double, int);
+  DesignWin(const std::string&, double, double, int, NoteBookTab & mw);
 
   sigc::signal<void, double> signal_attraction(){return signal_attraction_ch;};
   sigc::signal<void, double> signal_propulsation(){return signal_propulsation_ch;};
   sigc::signal<void, int> signal_iteration(){return signal_iteration_ch;};
   sigc::signal<void> close_run(){return close_run_pr;};
+
+  void set_title(std::string);
 };
 #endif //DESWIN_H

Modified: glemon/trunk/graph_displayer_canvas.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas.cc	(original)
+++ glemon/trunk/graph_displayer_canvas.cc	Wed Oct 25 15:21:24 2006
@@ -7,7 +7,7 @@
   nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
   isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
   edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
-  iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), mytab(mainw)
+  iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), is_drawn(false), mytab(mainw)
 {
   //base event handler is move tool
   actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
@@ -63,94 +63,95 @@
 
 void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
 {
-  //dummy=dummy;
-
   std::string mapname=mytab.getActiveNodeMap(prop);
 
-  if(mapname!="")
+  if(is_drawn)
     {
-      if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
+      if(mapname!="")
 	{
+	  if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
+	    {
+	      switch(prop)
+		{
+		case N_RADIUS:
+		  changeNodeRadius(mapname, node);
+		  break;
+		case N_COLOR:
+		  changeNodeColor(mapname, node);
+		  break;
+		case N_TEXT:
+		  changeNodeText(mapname, node);
+		  break;
+		default:
+		  std::cerr<<"Error\n";
+		}
+	    }
+	}
+      else //mapname==""
+	{
+	  Node node=INVALID;	
 	  switch(prop)
 	    {
 	    case N_RADIUS:
-	      changeNodeRadius(mapname, node);
+	      resetNodeRadius(node);
 	      break;
 	    case N_COLOR:
-	      changeNodeColor(mapname, node);
+	      resetNodeColor(node);
 	      break;
 	    case N_TEXT:
-	      changeNodeText(mapname, node);
+	      resetNodeText(node);
 	      break;
 	    default:
 	      std::cerr<<"Error\n";
 	    }
 	}
     }
-  else //mapname==""
-    {
-      Node node=INVALID;	
-      switch(prop)
-	{
-	case N_RADIUS:
-	  resetNodeRadius(node);
-	  break;
-	case N_COLOR:
-	  resetNodeColor(node);
-	  break;
-	case N_TEXT:
-	  resetNodeText(node);
-	  break;
-	default:
-	  std::cerr<<"Error\n";
-	}
-    }
-
 }
 
 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
 {
-  //dummy=dummy;
-
   std::string mapname=mytab.getActiveEdgeMap(prop);
 
-  if(mapname!="")
+  if(is_drawn)
     {
-      if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
+      if(mapname!="")
+	{
+	  if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
+	    {
+	      switch(prop)
+		{
+		case E_WIDTH:
+		  changeEdgeWidth(mapname, edge);
+		  break;
+		case E_COLOR:
+		  changeEdgeColor(mapname, edge);
+		  break;
+		case E_TEXT:
+		  changeEdgeText(mapname, edge);
+		  break;
+		default:
+		  std::cerr<<"Error\n";
+		}
+	    }
+	}
+      else //mapname==""
 	{
 	  switch(prop)
 	    {
 	    case E_WIDTH:
-	      changeEdgeWidth(mapname, edge);
+	      resetEdgeWidth(edge);
 	      break;
 	    case E_COLOR:
-	      changeEdgeColor(mapname, edge);
+	      resetEdgeColor(edge);
 	      break;
 	    case E_TEXT:
-	      changeEdgeText(mapname, edge);
+	      resetEdgeText(edge);
 	      break;
 	    default:
 	      std::cerr<<"Error\n";
 	    }
 	}
     }
-  else //mapname==""
-    {
-      switch(prop)
-	{
-	case E_WIDTH:
-	  resetEdgeWidth(edge);
-	  break;
-	case E_COLOR:
-	  resetEdgeColor(edge);
-	  break;
-	case E_TEXT:
-	  resetEdgeText(edge);
-	  break;
-	default:
-	  std::cerr<<"Error\n";
-	}
-    }
 }
 
 void GraphDisplayerCanvas::drawGraph()
@@ -207,6 +208,21 @@
     nodetextmap[i]->raise_to_top();
   }
 
+  is_drawn=true;
+
+  //upon drawing graph
+  //properties have to
+  //be set in as well
+  for(int i=0;i<NODE_PROPERTY_NUM;i++)
+    {
+      propertyUpdate(Node(INVALID), i);
+    }
+
+  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+    {
+      propertyUpdate(Edge(INVALID), i);
+    }
+
   updateScrollRegion();
 }
 
@@ -227,6 +243,8 @@
     delete edgesmap[e];
     delete edgetextmap[e];
   }
+
+  is_drawn=false;
 }
 
 void GraphDisplayerCanvas::setView(bool autoscale_p, bool zoomtrack_p, double width_p, double radius_p)

Modified: glemon/trunk/graph_displayer_canvas.h
==============================================================================
--- glemon/trunk/graph_displayer_canvas.h	(original)
+++ glemon/trunk/graph_displayer_canvas.h	Wed Oct 25 15:21:24 2006
@@ -325,6 +325,9 @@
   void set_propulsation(double);
   void set_iteration(int);
 
+  ///Show whether the graph is already drawn.
+  bool is_drawn;
+
 private:
   ///Deletes the given element.
   void deleteItem(Node);

Modified: glemon/trunk/gui_reader.cc
==============================================================================
--- glemon/trunk/gui_reader.cc	(original)
+++ glemon/trunk/gui_reader.cc	Wed Oct 25 15:21:24 2006
@@ -26,6 +26,21 @@
     mapstorage->arrow_pos.set(e, m[edgeid]);
   }
   mapstorage->ArrowPosReadOK();
+
+  std::map<int, std::string> nm;
+  x("active_nodemaps", nm);
+
+  for(int i=0;i<NODE_PROPERTY_NUM;i++)
+    {
+      mapstorage->changeActiveMap(false, i, nm[i]);
+    }
+
+  std::map<int, std::string> em;
+  x("active_edgemaps", em);
+  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+    {
+      mapstorage->changeActiveMap(true, i, em[i]);
+    }
 }
 
 GuiReader::GuiReader(LemonReader& reader, MapStorage* ms) : Parent(reader), mapstorage(ms)

Modified: glemon/trunk/gui_writer.cc
==============================================================================
--- glemon/trunk/gui_writer.cc	(original)
+++ glemon/trunk/gui_writer.cc	Wed Oct 25 15:21:24 2006
@@ -19,6 +19,20 @@
     m[edgeid] = mapstorage->arrow_pos[e];
   }
   x("arrow_pos", m);
+
+  std::map<int, std::string> nm;
+  for(int i=0;i<NODE_PROPERTY_NUM;i++)
+    {
+      nm[i]=mapstorage->active_nodemaps[i];
+    }
+  x("active_nodemaps", nm);
+
+  std::map<int, std::string> em;
+  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+    {
+      em[i]=mapstorage->active_edgemaps[i];
+    }
+  x("active_edgemaps", em);
 }
 
 GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms)

Modified: glemon/trunk/map_win.cc
==============================================================================
--- glemon/trunk/map_win.cc	(original)
+++ glemon/trunk/map_win.cc	Wed Oct 25 15:21:24 2006
@@ -20,6 +20,8 @@
 
   signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
 
+  mytab.signal_title_ch().connect(sigc::mem_fun(*this, &MapWin::set_title));
+
   e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM];
 
   table=new Gtk::Table(EDGE_PROPERTY_NUM, 1, false);
@@ -90,6 +92,8 @@
   {
     n_combo_array[i]->update_list(nml);
   }
+
+  mytab.active_maps_needed();
 }
 
 void MapWin::registerNewEdgeMap(std::string newmapname)
@@ -116,3 +120,20 @@
   mytab.closeMapWin();
   return true;
 }
+
+void MapWin::changeEntry(bool isitedge, int prop, std::string mapname)
+{
+  if(isitedge)
+    {
+      e_combo_array[prop]->set_active_text(mapname);
+    }
+  else
+    {
+      n_combo_array[prop]->set_active_text(mapname);
+    }
+}
+
+void MapWin::set_title(std::string tabname)
+{
+  Gtk::Window::set_title("Map Setup - "+tabname);
+}

Modified: glemon/trunk/map_win.h
==============================================================================
--- glemon/trunk/map_win.h	(original)
+++ glemon/trunk/map_win.h	Wed Oct 25 15:21:24 2006
@@ -112,6 +112,10 @@
   ///\param eml edge map list
   ///\param nml node map list
   void update(std::vector<std::string> eml, std::vector<std::string> nml);
+
+  void changeEntry(bool, int, std::string);
+
+  void set_title(std::string);
 };
 
 #endif //MAP_WIN_H

Modified: glemon/trunk/mapselector.cc
==============================================================================
--- glemon/trunk/mapselector.cc	(original)
+++ glemon/trunk/mapselector.cc	Wed Oct 25 15:21:24 2006
@@ -67,14 +67,17 @@
 {
   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);
     }
   if(def)
     {
       cbt.prepend_text("Default values");
+      cbt_content.push_back("Default values");
     }
   if(prev_act!=-1)
     {
@@ -116,12 +119,21 @@
 
 void MapSelector::set_active_text(Glib::ustring text)
 {
-  cbt.set_active_text(text);
+  if(text.compare(""))
+    {
+      cbt.set_active_text(text);
+    }
+  else
+    { 
+      cbt.set_active_text("Default values");
+    }
 }
 
 void MapSelector::append_text(Glib::ustring text)
 {
   cbt.append_text(text);
+  cbt_content.push_back(text);
+
   if(set_new_map)
     {
       set_active_text(text);

Modified: glemon/trunk/mapselector.h
==============================================================================
--- glemon/trunk/mapselector.h	(original)
+++ glemon/trunk/mapselector.h	Wed Oct 25 15:21:24 2006
@@ -61,6 +61,8 @@
   ///Names in it are selectable.
   Gtk::ComboBoxText cbt;
 
+  std::vector<std::string> cbt_content;
+
   ///New button.
 
   ///By pressing it

Modified: glemon/trunk/mapstorage.cc
==============================================================================
--- glemon/trunk/mapstorage.cc	(original)
+++ glemon/trunk/mapstorage.cc	Wed Oct 25 15:21:24 2006
@@ -52,7 +52,6 @@
 
 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value)
 {
-  std::cout << default_value << std::endl;
   if( nodemap_storage.find(name) == nodemap_storage.end() )
     {
       nodemap_storage[name]=nodemap;
@@ -79,6 +78,20 @@
   signal_prop.emit(itisedge, prop);
 }
 
+void MapStorage::broadcastActiveMaps()
+{
+  for(int i=0;i<NODE_PROPERTY_NUM;i++)
+    {
+      signal_map_win.emit(false, i, active_nodemaps[i]);
+    }
+  
+  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+    {
+      signal_map_win.emit(true, i, active_edgemaps[i]);
+    }
+}
+
+
 std::string MapStorage::getActiveEdgeMap(int prop)
 {
   return active_edgemaps[prop];
@@ -440,6 +453,20 @@
   graph.clear();
   file_name = "";
   modified = false;
+
+  arrow_pos_read_ok = false;
+  
+  for(int i=0;i<NODE_PROPERTY_NUM;i++)
+    {
+      changeActiveMap(false, i, "");
+      signal_map_win.emit(false, i, "");
+    }
+  
+  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+    {
+      changeActiveMap(true, i, "");
+      signal_map_win.emit(true, i, "");
+    }
 }
 
 void MapStorage::ArrowPosReadOK()

Modified: glemon/trunk/mapstorage.h
==============================================================================
--- glemon/trunk/mapstorage.h	(original)
+++ glemon/trunk/mapstorage.h	Wed Oct 25 15:21:24 2006
@@ -85,6 +85,9 @@
   ///name of the new map
   sigc::signal<void, std::string> signal_edge_map;
 
+  /// Signal emitted, when entry in \ref MapWin should be changed.
+  sigc::signal<void, bool, int, std::string> signal_map_win;
+
 public:
   ///Constructor of MapStorage.
 
@@ -109,6 +112,9 @@
   ///\param mapname the visible map
   void changeActiveMap(bool itisedge , int prop , std::string mapname);
 
+  ///Emits signals that let change the active maps in \ref MapWin.
+  void broadcastActiveMaps();
+
   /// Returns the active edgemap shown by a visualization property.
 
   /// \param prop is the property
@@ -136,6 +142,9 @@
   ///returns \ref signal_edge_map to be able to connect functions to it
   sigc::signal<void, std::string> signal_edge_map_ch(){return signal_edge_map;};
 
+  ///returns \ref signal_map_win to be able to connect functions to it
+  sigc::signal<void, bool, int, std::string> signal_map_win_ch(){return signal_map_win;};
+
   ///Adds given map to storage.
 
   ///A name and the map itself has to be provided.

Modified: glemon/trunk/nbtab.cc
==============================================================================
--- glemon/trunk/nbtab.cc	(original)
+++ glemon/trunk/nbtab.cc	Wed Oct 25 15:21:24 2006
@@ -202,6 +202,7 @@
   if(!mapwinexists)
     {
       mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
+      mapst2mapwin=mapstorage.signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
       mapwin->show();
       mapwinexists=true;
     }
@@ -214,7 +215,7 @@
       double attraction, propulsation;
       int iterations;
       gd_canvas->get_design_data(attraction, propulsation, iterations);
-      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
+      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations, *this);
 
       designwin->signal_attraction().connect(sigc::mem_fun(*this, &NoteBookTab::attraction_ch));
       designwin->signal_propulsation().connect(sigc::mem_fun(*this, &NoteBookTab::propulsation_ch));
@@ -230,6 +231,7 @@
 
 void NoteBookTab::closeMapWin()
 {
+  mapst2mapwin.disconnect();
   mapwinexists=false;
   delete mapwin;
 }
@@ -278,3 +280,7 @@
   gd_canvas->set_iteration(v);
 }
 
+void NoteBookTab::active_maps_needed()
+{
+  mapstorage.broadcastActiveMaps();
+}

Modified: glemon/trunk/nbtab.h
==============================================================================
--- glemon/trunk/nbtab.h	(original)
+++ glemon/trunk/nbtab.h	Wed Oct 25 15:21:24 2006
@@ -183,13 +183,27 @@
   ///Gets node representation settings
   void getView(bool &, bool &, double&, double&);
 
+  ///Let the graph redesign, based on gravity and edge elasticity.
   void reDesignGraph();
 
+  ///Indicates that attraction factor is changed
   void attraction_ch(double);
 
+  ///Indicates that propulsation factor is changed
   void propulsation_ch(double);
 
+  ///Indicates that iteration number of redesign is changed
   void iteration_ch(int);
+
+  ///\ref MapWin calls this function when it updates the maplist in comboboxes.
+  void active_maps_needed();
+
+private:
+  ///Signal connection from \ref MapStorage to \ref MapWin
+
+  ///If \ref MapWin is closed this connection has to be disconnected,
+  ///therefore we have to store it.
+  sigc::connection mapst2mapwin;
 };
 
 #endif //NBTAB_H



More information about the Lemon-commits mailing list