Communication with algorithm window is developed.
1.1 --- a/Makefile.am Wed Jan 04 13:31:59 2006 +0000
1.2 +++ b/Makefile.am Wed Jan 04 18:05:55 2006 +0000
1.3 @@ -7,6 +7,10 @@
1.4
1.5 glemon_SOURCES = \
1.6 all_include.h \
1.7 + algobox.cc \
1.8 + algobox.h \
1.9 + algowin.cc \
1.10 + algowin.h \
1.11 gdc-broken_edge.cc \
1.12 graph_displayer_canvas.cc \
1.13 graph_displayer_canvas.h \
1.14 @@ -15,6 +19,8 @@
1.15 graph_displayer_canvas-node.cc \
1.16 graph_displayer_canvas-zoom.cc \
1.17 graph-displayer.cc \
1.18 + kruskalbox.cc \
1.19 + kruskalbox.h \
1.20 main_win.cc \
1.21 main_win.h \
1.22 mapstorage.cc \
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/algobox.cc Wed Jan 04 18:05:55 2006 +0000
2.3 @@ -0,0 +1,140 @@
2.4 +#include <algobox.h>
2.5 +
2.6 +enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
2.7 +enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
2.8 +
2.9 +AlgoBox::AlgoBox(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
2.10 +{
2.11 + init(tabnames, nodemapnames, edgemapnames);
2.12 +}
2.13 +
2.14 +void AlgoBox::init(std::vector<std::string> tabnames, std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
2.15 +{
2.16 + set_spacing(5);
2.17 +
2.18 + update_tablist(tabnames);
2.19 +
2.20 + //if active tab is changed, the map names in cbt/s have to be updated
2.21 + tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
2.22 +
2.23 + pack_start(tabcbt);
2.24 +
2.25 + build_box();
2.26 +
2.27 + update_maplist(nodemapnames, edgemapnames);
2.28 +
2.29 + show_all_children();
2.30 +};
2.31 +
2.32 +void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
2.33 +{
2.34 + std::string actname=cbt.get_active_text();
2.35 + int prev_act=-1;
2.36 +
2.37 + cbt.clear();
2.38 + int actptr=0;
2.39 +
2.40 + std::vector< std::string >::iterator emsi=stringlist.begin();
2.41 + for(;emsi!=stringlist.end();emsi++)
2.42 + {
2.43 + if(actname==*emsi)
2.44 + {
2.45 + prev_act=actptr;
2.46 + }
2.47 +
2.48 + cbt.append_text(*emsi);
2.49 + actptr++;
2.50 + }
2.51 +
2.52 + if(prev_act!=-1)
2.53 + {
2.54 + cbt.set_active(prev_act);
2.55 + }
2.56 + else if(actptr>0) //so there is item in the list
2.57 + {
2.58 + cbt.set_active(0);
2.59 + }
2.60 +}
2.61 +
2.62 +void AlgoBox::update_tablist( std::vector< std::string > tl )
2.63 +{
2.64 + update_cbt(tl, tabcbt);
2.65 + emit_tab_change();
2.66 +}
2.67 +
2.68 +void AlgoBox::update_maplist( std::vector< std::string > nml, std::vector< std::string > eml )
2.69 +{
2.70 + for(int i=0;i<(int)nodemapcbts.size();i++)
2.71 + {
2.72 + update_cbt(nml, *(nodemapcbts[i]));
2.73 + }
2.74 + for(int i=0;i<(int)edgemapcbts.size();i++)
2.75 + {
2.76 + update_cbt(eml, *(edgemapcbts[i]));
2.77 + }
2.78 +}
2.79 +
2.80 +void AlgoBox::run()
2.81 +{
2.82 + std::cout << "Start algorithm." << std::endl;
2.83 +}
2.84 +
2.85 +void AlgoBox::build_box()
2.86 +{
2.87 + pack_start(*(new Gtk::HSeparator()));
2.88 +
2.89 + label=new Gtk::Label("Specific part for each algorithm.");
2.90 +
2.91 + pack_start(*label);
2.92 + pack_start(*(new Gtk::HSeparator()));
2.93 +
2.94 + label=new Gtk::Label("Maps in chosen tab:");
2.95 +
2.96 + pack_start(*label);
2.97 +
2.98 + nodemapcbts.resize(NODE_INPUT_NUM);
2.99 + for(int i=0;i<(int)nodemapcbts.size();i++)
2.100 + {
2.101 + Gtk::HBox * hbox=new Gtk::HBox();
2.102 +
2.103 + std::ostringstream o;
2.104 + o << "NodeInput " << i+1 << ":";
2.105 + label=new Gtk::Label(o.str());
2.106 +
2.107 + nodemapcbts[i]=new Gtk::ComboBoxText();
2.108 +
2.109 + hbox->pack_start(*label);
2.110 + hbox->pack_start(*(nodemapcbts[i]));
2.111 + pack_start(*hbox);
2.112 + }
2.113 +
2.114 + pack_start(*(new Gtk::HSeparator()));
2.115 +
2.116 + edgemapcbts.resize(EDGE_INPUT_NUM);
2.117 + for(int i=0;i<(int)edgemapcbts.size();i++)
2.118 + {
2.119 + Gtk::HBox * hbox=new Gtk::HBox();
2.120 +
2.121 + std::ostringstream o;
2.122 + o << "EdgeInput " << i+1 << ":";
2.123 + label=new Gtk::Label(o.str());
2.124 +
2.125 + edgemapcbts[i]=new Gtk::ComboBoxText();
2.126 +
2.127 + hbox->pack_start(*label);
2.128 + hbox->pack_start(*(edgemapcbts[i]));
2.129 + pack_start(*hbox);
2.130 + }
2.131 +
2.132 + pack_start(*(new Gtk::HSeparator()));
2.133 +}
2.134 +
2.135 +sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
2.136 +{
2.137 + return signal_maplist_need;
2.138 +}
2.139 +
2.140 +void AlgoBox::emit_tab_change()
2.141 +{
2.142 + signal_maplist_need.emit(tabcbt.get_active_text());
2.143 +}
3.1 --- a/algobox.h Wed Jan 04 13:31:59 2006 +0000
3.2 +++ b/algobox.h Wed Jan 04 18:05:55 2006 +0000
3.3 @@ -11,52 +11,31 @@
3.4
3.5 class AlgoBox : public Gtk::VBox
3.6 {
3.7 + sigc::signal<void, std::string> signal_maplist_need;
3.8
3.9 + Gtk::ComboBoxText tabcbt;
3.10 +
3.11 +protected:
3.12 Gtk::Label * label;
3.13 - Gtk::ComboBoxText cbt;
3.14 + std::vector<Gtk::ComboBoxText *> nodemapcbts;
3.15 + std::vector<Gtk::ComboBoxText *> edgemapcbts;
3.16
3.17 - public:
3.18 - AlgoBox(std::vector<std::string> tabnames)
3.19 - {
3.20 - update_tablist(tabnames);
3.21 +public:
3.22 + AlgoBox(){};
3.23 + AlgoBox(std::vector<std::string>, std::vector<std::string>, std::vector<std::string>);
3.24
3.25 - label=new Gtk::Label("Haliho");
3.26 -
3.27 - pack_start(*label);
3.28 - pack_start(cbt);
3.29 + virtual void init(std::vector<std::string>, std::vector<std::string>, std::vector<std::string>);
3.30
3.31 - show_all_children();
3.32 - };
3.33 + sigc::signal<void, std::string> signal_maplist_needed();
3.34 + void emit_tab_change();
3.35
3.36 - void update_tablist( std::vector< std::string > tl )
3.37 - {
3.38 - std::string actname=cbt.get_active_text();
3.39 - int prev_act=-1;
3.40 + void update_tablist( std::vector< std::string > tl );
3.41 + void update_maplist( std::vector< std::string >, std::vector< std::string >);
3.42
3.43 - cbt.clear();
3.44 - int actptr=0;
3.45 -
3.46 - std::vector< std::string >::iterator emsi=tl.begin();
3.47 - for(;emsi!=tl.end();emsi++)
3.48 - {
3.49 - if(actname==*emsi)
3.50 - {
3.51 - prev_act=actptr;
3.52 - }
3.53 -
3.54 - cbt.append_text(*emsi);
3.55 - actptr++;
3.56 - }
3.57 -
3.58 - if(prev_act!=-1)
3.59 - {
3.60 - cbt.set_active(prev_act);
3.61 - }
3.62 - else if(actptr>0) //so there is item in the list
3.63 - {
3.64 - cbt.set_active(0);
3.65 - }
3.66 - }
3.67 -
3.68 + void update_cbt( std::vector< std::string > tl, Gtk::ComboBoxText &);
3.69 +
3.70 + virtual void run();
3.71 +
3.72 + virtual void build_box();
3.73 };
3.74 #endif //ALGOBOX_H
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/algowin.cc Wed Jan 04 18:05:55 2006 +0000
4.3 @@ -0,0 +1,88 @@
4.4 +#include <algowin.h>
4.5 +#include <kruskalbox.h>
4.6 +
4.7 +sigc::signal<void, AlgoWin *> AlgoWin::signal_closing()
4.8 +{
4.9 + return signal_closed;
4.10 +}
4.11 +
4.12 +sigc::signal<void, AlgoWin *, std::string> AlgoWin::signal_maplist_needed()
4.13 +{
4.14 + return signal_maplist_need;
4.15 +}
4.16 +
4.17 +bool AlgoWin::closeIfEscapeIsPressed(GdkEventKey* e)
4.18 +{
4.19 + if(e->keyval==GDK_Escape)
4.20 + {
4.21 + on_hide();
4.22 + }
4.23 + return true;
4.24 +}
4.25 +
4.26 +AlgoWin::AlgoWin(int algoid, std::vector<std::string> tabnames, std::vector<std::string> nodemapnames,std::vector<std::string> edgemapnames)
4.27 +{
4.28 + signal_key_press_event().connect(sigc::mem_fun(*this, &AlgoWin::closeIfEscapeIsPressed));
4.29 +
4.30 + Gtk::VBox * vbox=new Gtk::VBox();
4.31 + vbox->set_spacing(5);
4.32 +
4.33 + Gtk::Label * label=new Gtk::Label("Select graph:");
4.34 +
4.35 + switch(algoid)
4.36 + {
4.37 + case 0:
4.38 + ab=new AlgoBox(tabnames, nodemapnames, edgemapnames);
4.39 + set_title("Algo Win Demo");
4.40 + break;
4.41 + case 1:
4.42 + ab=new KruskalBox(tabnames, nodemapnames, edgemapnames);
4.43 + set_title("Kruskal Algorithm");
4.44 + break;
4.45 + default:
4.46 + break;
4.47 + }
4.48 + ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change));
4.49 +
4.50 + runbutton=new Gtk::Button("Run");
4.51 + runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run));
4.52 + runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run));
4.53 +
4.54 + closebutton=new Gtk::Button("Close");
4.55 + closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
4.56 + closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide));
4.57 +
4.58 + Gtk::HBox * hbox=new Gtk::HBox();
4.59 +
4.60 + hbox->pack_start(*runbutton);
4.61 + hbox->pack_start(*closebutton);
4.62 +
4.63 + vbox->pack_start(*label);
4.64 + vbox->pack_start(*ab);
4.65 + vbox->pack_start(*hbox);
4.66 +
4.67 + add(*vbox);
4.68 +
4.69 + show_all_children();
4.70 +};
4.71 +
4.72 +void AlgoWin::update_tablist(std::vector<std::string> tabnames)
4.73 +{
4.74 + ab->update_tablist(tabnames);
4.75 +}
4.76 +
4.77 +void AlgoWin::update_maplist(std::vector<std::string> nodemapnames, std::vector<std::string> edgemapnames)
4.78 +{
4.79 + ab->update_maplist(nodemapnames, edgemapnames);
4.80 +}
4.81 +
4.82 +void AlgoWin::on_hide()
4.83 +{
4.84 + signal_closed.emit(this);
4.85 + Gtk::Window::on_hide();
4.86 +}
4.87 +
4.88 +void AlgoWin::emit_tab_change(std::string newtab)
4.89 +{
4.90 + signal_maplist_need.emit(this, newtab);
4.91 +}
5.1 --- a/algowin.h Wed Jan 04 13:31:59 2006 +0000
5.2 +++ b/algowin.h Wed Jan 04 18:05:55 2006 +0000
5.3 @@ -10,44 +10,32 @@
5.4 #include <libgnomecanvasmm.h>
5.5 #include <libgnomecanvasmm/polygon.h>
5.6
5.7 -enum {GENERAL, ALGO_NUM}; // algorithm IDs;
5.8 +enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs;
5.9
5.10 -class AlgoWin : public Gtk::Dialog
5.11 +class AlgoWin : public Gtk::Window
5.12 {
5.13 private:
5.14 AlgoBox * ab;
5.15 + Gtk::Button * runbutton;
5.16 + Gtk::Button * closebutton;
5.17
5.18 protected:
5.19 sigc::signal<void, AlgoWin *> signal_closed;
5.20 + sigc::signal<void, AlgoWin *, std::string> signal_maplist_need;
5.21
5.22 public:
5.23 - sigc::signal<void, AlgoWin *> signal_closing()
5.24 - {
5.25 - return signal_closed;
5.26 - }
5.27 + bool closeIfEscapeIsPressed(GdkEventKey* e);
5.28
5.29 - AlgoWin(int algoid, std::vector<std::string> tabnames)
5.30 - {
5.31 - Gtk::VBox * vbox=get_vbox();
5.32 -
5.33 - ab=new AlgoBox(tabnames);
5.34 -
5.35 - vbox->pack_start(*ab);
5.36 -
5.37 - add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK);
5.38 -
5.39 - show_all_children();
5.40 - };
5.41 + sigc::signal<void, AlgoWin *> signal_closing();
5.42 + sigc::signal<void, AlgoWin *, std::string> signal_maplist_needed();
5.43
5.44 - void update_tablist(std::vector<std::string> tabnames)
5.45 - {
5.46 - ab->update_tablist(tabnames);
5.47 - }
5.48 + void emit_tab_change(std::string);
5.49
5.50 - void on_hide()
5.51 - {
5.52 - signal_closed.emit(this);
5.53 - Gtk::Dialog::on_hide();
5.54 - }
5.55 + AlgoWin(int, std::vector<std::string>, std::vector<std::string>, std::vector<std::string>);
5.56 +
5.57 + void update_tablist(std::vector<std::string> tabnames);
5.58 + void update_maplist(std::vector<std::string>, std::vector<std::string>);
5.59 +
5.60 + void on_hide();
5.61 };
5.62 #endif //ALGOWIN_H
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/kruskalbox.cc Wed Jan 04 18:05:55 2006 +0000
6.3 @@ -0,0 +1,27 @@
6.4 +#include <kruskalbox.h>
6.5 +
6.6 +KruskalBox::KruskalBox(std::vector<std::string> t, std::vector<std::string> nm, std::vector<std::string> em):AlgoBox()
6.7 +{
6.8 + init(t, nm, em);
6.9 +}
6.10 +
6.11 +void KruskalBox::run()
6.12 +{
6.13 + std::cout << "Kruskal inditasa, de meg nincsen keszen." << std::endl;
6.14 +}
6.15 +
6.16 +void KruskalBox::build_box()
6.17 +{
6.18 + edgemapcbts.resize(1);
6.19 + Gtk::HBox * hbox=new Gtk::HBox();
6.20 +
6.21 + std::ostringstream o;
6.22 + o << "Edgecosts: ";
6.23 + label=new Gtk::Label(o.str());
6.24 +
6.25 + edgemapcbts[0]=new Gtk::ComboBoxText();
6.26 +
6.27 + hbox->pack_start(*label);
6.28 + hbox->pack_start(*(edgemapcbts[0]));
6.29 + pack_start(*hbox);
6.30 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/kruskalbox.h Wed Jan 04 18:05:55 2006 +0000
7.3 @@ -0,0 +1,23 @@
7.4 +// -*- C++ -*- //
7.5 +
7.6 +#ifndef KRUSKALBOX_H
7.7 +#define KRUSKALBOX_H
7.8 +
7.9 +class KruskalBox;
7.10 +
7.11 +#include <all_include.h>
7.12 +#include <algobox.h>
7.13 +#include <lemon/kruskal.h>
7.14 +#include <libgnomecanvasmm.h>
7.15 +#include <libgnomecanvasmm/polygon.h>
7.16 +
7.17 +class KruskalBox : public AlgoBox
7.18 +{
7.19 +public:
7.20 + KruskalBox(std::vector<std::string> t, std::vector<std::string> nm, std::vector<std::string> em);
7.21 +
7.22 + void run();
7.23 +
7.24 + void build_box();
7.25 +};
7.26 +#endif //KRUSKALBOX_H
8.1 --- a/main_win.cc Wed Jan 04 13:31:59 2006 +0000
8.2 +++ b/main_win.cc Wed Jan 04 18:05:55 2006 +0000
8.3 @@ -104,6 +104,8 @@
8.4 ag->add( Gtk::Action::create("AlgoMenu", "_Algorithms") );
8.5 ag->add( Gtk::Action::create("AlgoGeneral", "_General"),
8.6 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
8.7 + ag->add( Gtk::Action::create("AlgoKruskal", "_Kruskal"),
8.8 + sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
8.9
8.10 Gtk::RadioAction::Group tool_group;
8.11 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"),
8.12 @@ -153,6 +155,7 @@
8.13 " </menu>"
8.14 " <menu action='AlgoMenu'>"
8.15 " <menuitem action='AlgoGeneral'/>"
8.16 + " <menuitem action='AlgoKruskal'/>"
8.17 " </menu>"
8.18 " </menubar>"
8.19 " <toolbar name='ToolBar'>"
8.20 @@ -224,7 +227,7 @@
8.21 }
8.22 set_title(tabnames[active_tab] + " - " + prog_name);
8.23 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
8.24 - updateAlgoWins();
8.25 + updateAlgoWinTabs();
8.26 }
8.27
8.28 void MainWin::readFile(const std::string & filename)
8.29 @@ -246,7 +249,7 @@
8.30 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
8.31 notebook.set_current_page(size);
8.32 set_tabtitle("unsaved file");
8.33 - updateAlgoWins();
8.34 + updateAlgoWinTabs();
8.35 }
8.36
8.37 void MainWin::closeTab()
8.38 @@ -306,7 +309,7 @@
8.39 active_tab=-1;
8.40 }
8.41
8.42 - updateAlgoWins();
8.43 + updateAlgoWinTabs();
8.44 }
8.45 }
8.46
8.47 @@ -404,18 +407,28 @@
8.48
8.49 void MainWin::createAlgoWin(int algoid)
8.50 {
8.51 - AlgoWin * aw=new AlgoWin(algoid, tabnames);
8.52 + AlgoWin * aw=new AlgoWin(algoid, tabnames, tabs[0]->mapstorage.getNodeMapList(),tabs[0]->mapstorage.getEdgeMapList());
8.53 aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
8.54 + aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
8.55 aws.insert(aw);
8.56 aw->show();
8.57 }
8.58
8.59 +void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
8.60 +{
8.61 + int i=0;
8.62 + for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
8.63 + {
8.64 + }
8.65 + awp->update_maplist(tabs[i]->mapstorage.getNodeMapList(),tabs[i]->mapstorage.getEdgeMapList());
8.66 +}
8.67 +
8.68 void MainWin::deRegisterAlgoWin(AlgoWin * awp)
8.69 {
8.70 aws.erase(awp);
8.71 }
8.72
8.73 -void MainWin::updateAlgoWins()
8.74 +void MainWin::updateAlgoWinTabs()
8.75 {
8.76 std::set< AlgoWin* >::iterator awsi=aws.begin();
8.77 for(;awsi!=aws.end();awsi++)
9.1 --- a/main_win.h Wed Jan 04 13:31:59 2006 +0000
9.2 +++ b/main_win.h Wed Jan 04 18:05:55 2006 +0000
9.3 @@ -73,7 +73,8 @@
9.4
9.5 virtual void createAlgoWin(int);
9.6 virtual void deRegisterAlgoWin(AlgoWin *);
9.7 - virtual void updateAlgoWins();
9.8 + virtual void updateAlgoWinTabs();
9.9 + virtual void updateAlgoWinMaps(AlgoWin *, std::string);
9.10
9.11 virtual void changeEditorialTool(int);
9.12