[Lemon-commits] [lemon_svn] hegyi: r2454 - hugo/trunk/gui

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


Author: hegyi
Date: Thu Jan  5 17:54:34 2006
New Revision: 2454

Modified:
   hugo/trunk/gui/algobox.cc
   hugo/trunk/gui/algobox.h
   hugo/trunk/gui/algowin.cc
   hugo/trunk/gui/algowin.h
   hugo/trunk/gui/graph_displayer_canvas-event.cc
   hugo/trunk/gui/kruskalbox.cc
   hugo/trunk/gui/kruskalbox.h
   hugo/trunk/gui/new_map_win.cc

Log:
Kruskal algorithm can be run from GUI from now on.

Modified: hugo/trunk/gui/algobox.cc
==============================================================================
--- hugo/trunk/gui/algobox.cc	(original)
+++ hugo/trunk/gui/algobox.cc	Thu Jan  5 17:54:34 2006
@@ -59,9 +59,9 @@
   emit_tab_change();
 }
 
-void AlgoBox::update_maplist( void * ms)
+void AlgoBox::update_maplist(MapStorage * ms)
 {
-  mapstorage=(MapStorage *)ms;
+  mapstorage=ms;
   std::vector<std::string> nml;
   std::vector<std::string> eml;
   if(mapstorage!=NULL)
@@ -69,7 +69,7 @@
       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->getNodeMapList();
+      eml=mapstorage->getEdgeMapList();
     }
   for(int i=0;i<(int)nodemapcbts.size();i++)
     {

Modified: hugo/trunk/gui/algobox.h
==============================================================================
--- hugo/trunk/gui/algobox.h	(original)
+++ hugo/trunk/gui/algobox.h	Thu Jan  5 17:54:34 2006
@@ -33,7 +33,7 @@
   void emit_tab_change();
 
   void update_tablist( std::vector< std::string > tl );
-  void update_maplist( void * );
+  void update_maplist( MapStorage * );
 
   void nodemaplist_changed(std::string);
   void edgemaplist_changed(std::string);

Modified: hugo/trunk/gui/algowin.cc
==============================================================================
--- hugo/trunk/gui/algowin.cc	(original)
+++ hugo/trunk/gui/algowin.cc	Thu Jan  5 17:54:34 2006
@@ -71,7 +71,7 @@
   ab->update_tablist(tabnames);
 }
 
-void AlgoWin::update_maplist(void * mapstorage)
+void AlgoWin::update_maplist(MapStorage * mapstorage)
 {
   ab->update_maplist(mapstorage);
 }

Modified: hugo/trunk/gui/algowin.h
==============================================================================
--- hugo/trunk/gui/algowin.h	(original)
+++ hugo/trunk/gui/algowin.h	Thu Jan  5 17:54:34 2006
@@ -6,10 +6,13 @@
 class AlgoWin;
 
 #include <all_include.h>
+//#include <mapstorage.h>
 #include <algobox.h>
 #include <libgnomecanvasmm.h>
 #include <libgnomecanvasmm/polygon.h>
 
+class MapStorage;
+
 enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs;
 
 class AlgoWin : public Gtk::Window
@@ -34,7 +37,7 @@
   AlgoWin(int, std::vector<std::string>);
 
   void update_tablist(std::vector<std::string> tabnames);
-  void update_maplist( void *);
+  void update_maplist(MapStorage *);
 
   void on_hide();
 };

Modified: hugo/trunk/gui/graph_displayer_canvas-event.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-event.cc	(original)
+++ hugo/trunk/gui/graph_displayer_canvas-event.cc	Thu Jan  5 17:54:34 2006
@@ -850,49 +850,4 @@
 	  std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
 	}
     }
-
 }
-
-int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
-{
-  //create the new map
-  Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mytab.mapstorage).graph, default_value);
-
-  //if addition was not successful addEdgeMap returns one.
-  //cause can be that there is already a map named like the new one
-  if((mytab.mapstorage).addEdgeMap(mapname,emptr, default_value))
-    {
-      return 1;
-    }
-
-
-  //add it to the list of the displayable maps
-  mytab.registerNewEdgeMap(mapname);
-
-  //display it
-  changeEdgeText(mapname);
-
-  return 0;
-}
-
-int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
-{
-  //create the new map
-  Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mytab.mapstorage).graph,default_value);
-
-  //if addition was not successful addNodeMap returns one.
-  //cause can be that there is already a map named like the new one
-  if((mytab.mapstorage).addNodeMap(mapname,emptr, default_value))
-    {
-      return 1;
-    }
-
-  //add it to the list of the displayable maps
-  mytab.registerNewNodeMap(mapname);
-
-  //display it
-  changeNodeText(mapname);
-
-  return 0;
-}
-

Modified: hugo/trunk/gui/kruskalbox.cc
==============================================================================
--- hugo/trunk/gui/kruskalbox.cc	(original)
+++ hugo/trunk/gui/kruskalbox.cc	Thu Jan  5 17:54:34 2006
@@ -1,5 +1,7 @@
 #include <kruskalbox.h>
 
+enum {INPUT, OUTPUT, MAP_NUM};
+
 KruskalBox::KruskalBox(std::vector<std::string> t):AlgoBox()
 {
   init(t);
@@ -7,22 +9,56 @@
     
 void KruskalBox::run()
 {
-  
-  std::cout << "Kruskal inditasa, de meg nincsen keszen." << std::endl;
+  Graph g=mapstorage->graph;
+  Graph::EdgeMap<double> * inputmap=((mapstorage->edgemap_storage)[(edgemapcbts[INPUT])->get_active_text()]);
+  Graph::EdgeMap<bool> outputmap(g);
+  double res=kruskal(g, *inputmap, outputmap);
+
+  for (EdgeIt i(g); i!=INVALID; ++i)
+  {
+    if(outputmap[i])
+      {
+	(*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=1;
+      }
+    else
+      {
+	(*((mapstorage->edgemap_storage)[(edgemapcbts[OUTPUT])->get_active_text()]))[i]=0;
+      }
+  }
+
+  std::ostringstream o;
+  o << "Result: " << res;
+  resultlabel.set_text(o.str());
+
+  mapstorage->changeActiveMap(true, E_COLOR, (edgemapcbts[OUTPUT])->get_active_text());
+  mapstorage->changeActiveMap(true, E_TEXT, (edgemapcbts[INPUT])->get_active_text());
 }
     
 void KruskalBox::build_box()
 {
-  edgemapcbts.resize(1);
-  Gtk::HBox * hbox=new Gtk::HBox();
+  edgemapcbts.resize(MAP_NUM);
+  Gtk::HBox * hbox;
 
-  std::ostringstream o;
-  o << "Edgecosts: ";
-  label=new Gtk::Label(o.str());
+  hbox=new Gtk::HBox();
+
+  label=new Gtk::Label("Edgecosts: ");
 
   edgemapcbts[0]=new Gtk::ComboBoxText();
 
   hbox->pack_start(*label);
-  hbox->pack_start(*(edgemapcbts[0]));
+  hbox->pack_start(*(edgemapcbts[INPUT]));
   pack_start(*hbox);
+
+  hbox=new Gtk::HBox();
+
+  label=new Gtk::Label("Edges of tree here: ");
+
+  edgemapcbts[1]=new Gtk::ComboBoxText();
+
+  hbox->pack_start(*label);
+  hbox->pack_start(*(edgemapcbts[OUTPUT]));
+  pack_start(*hbox);
+
+  resultlabel.set_text("Result: algorithm is not run yet.");
+  pack_start(resultlabel);
 }

Modified: hugo/trunk/gui/kruskalbox.h
==============================================================================
--- hugo/trunk/gui/kruskalbox.h	(original)
+++ hugo/trunk/gui/kruskalbox.h	Thu Jan  5 17:54:34 2006
@@ -13,6 +13,8 @@
 
 class KruskalBox : public AlgoBox
 {
+  Gtk::Label resultlabel;
+
 public:
   KruskalBox(std::vector<std::string> t);
     

Modified: hugo/trunk/gui/new_map_win.cc
==============================================================================
--- hugo/trunk/gui/new_map_win.cc	(original)
+++ hugo/trunk/gui/new_map_win.cc	Thu Jan  5 17:54:34 2006
@@ -120,6 +120,7 @@
 				  def_val_ch[j]=ch2var[ polishform[i] ][j];
 				}
 			      polishstack.push(atof(def_val_ch));
+			      delete def_val_ch;
 			    }
 			  operation=false;
 			  break;
@@ -164,6 +165,8 @@
 
 	      //display it
 	      //gdc.changeEdgeText(mapname);
+
+	      //delete emptr;
 	    }
 	  else //!edge.get_active()
 	    {
@@ -204,6 +207,7 @@
 				  def_val_ch[j]=ch2var[ polishform[i] ][j];
 				}
 			      polishstack.push(atof(def_val_ch));
+			      delete def_val_ch;
 			    }
 			  operation=false;
 			  break;
@@ -248,6 +252,8 @@
 
 	      //display it
 	      //gdc.changeNodeText(mapname);
+
+	      //delete emptr;
 	    }
 	  if(!abortion)
 	    {



More information about the Lemon-commits mailing list