# HG changeset patch # User hegyi # Date 1136397955 0 # Node ID 853dd852abc7c1515d7657b1b4efe63928953cc4 # Parent 9e78d14fd0ba16be35e298e18ba1f0d1c50fac2d Communication with algorithm window is developed. diff -r 9e78d14fd0ba -r 853dd852abc7 Makefile.am --- a/Makefile.am Wed Jan 04 13:31:59 2006 +0000 +++ b/Makefile.am Wed Jan 04 18:05:55 2006 +0000 @@ -7,6 +7,10 @@ glemon_SOURCES = \ all_include.h \ + algobox.cc \ + algobox.h \ + algowin.cc \ + algowin.h \ gdc-broken_edge.cc \ graph_displayer_canvas.cc \ graph_displayer_canvas.h \ @@ -15,6 +19,8 @@ graph_displayer_canvas-node.cc \ graph_displayer_canvas-zoom.cc \ graph-displayer.cc \ + kruskalbox.cc \ + kruskalbox.h \ main_win.cc \ main_win.h \ mapstorage.cc \ diff -r 9e78d14fd0ba -r 853dd852abc7 algobox.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/algobox.cc Wed Jan 04 18:05:55 2006 +0000 @@ -0,0 +1,140 @@ +#include + +enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes; +enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges; + +AlgoBox::AlgoBox(std::vector tabnames, std::vector nodemapnames, std::vector edgemapnames) +{ + init(tabnames, nodemapnames, edgemapnames); +} + +void AlgoBox::init(std::vector tabnames, std::vector nodemapnames, std::vector edgemapnames) +{ + set_spacing(5); + + update_tablist(tabnames); + + //if active tab is changed, the map names in cbt/s have to be updated + tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change)); + + pack_start(tabcbt); + + build_box(); + + update_maplist(nodemapnames, edgemapnames); + + show_all_children(); +}; + +void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt) +{ + std::string actname=cbt.get_active_text(); + int prev_act=-1; + + cbt.clear(); + int actptr=0; + + std::vector< std::string >::iterator emsi=stringlist.begin(); + for(;emsi!=stringlist.end();emsi++) + { + if(actname==*emsi) + { + prev_act=actptr; + } + + cbt.append_text(*emsi); + actptr++; + } + + if(prev_act!=-1) + { + cbt.set_active(prev_act); + } + else if(actptr>0) //so there is item in the list + { + cbt.set_active(0); + } +} + +void AlgoBox::update_tablist( std::vector< std::string > tl ) +{ + update_cbt(tl, tabcbt); + emit_tab_change(); +} + +void AlgoBox::update_maplist( std::vector< std::string > nml, std::vector< std::string > eml ) +{ + for(int i=0;i<(int)nodemapcbts.size();i++) + { + update_cbt(nml, *(nodemapcbts[i])); + } + for(int i=0;i<(int)edgemapcbts.size();i++) + { + update_cbt(eml, *(edgemapcbts[i])); + } +} + +void AlgoBox::run() +{ + std::cout << "Start algorithm." << std::endl; +} + +void AlgoBox::build_box() +{ + pack_start(*(new Gtk::HSeparator())); + + label=new Gtk::Label("Specific part for each algorithm."); + + pack_start(*label); + pack_start(*(new Gtk::HSeparator())); + + label=new Gtk::Label("Maps in chosen tab:"); + + pack_start(*label); + + nodemapcbts.resize(NODE_INPUT_NUM); + for(int i=0;i<(int)nodemapcbts.size();i++) + { + Gtk::HBox * hbox=new Gtk::HBox(); + + std::ostringstream o; + o << "NodeInput " << i+1 << ":"; + label=new Gtk::Label(o.str()); + + nodemapcbts[i]=new Gtk::ComboBoxText(); + + hbox->pack_start(*label); + hbox->pack_start(*(nodemapcbts[i])); + pack_start(*hbox); + } + + pack_start(*(new Gtk::HSeparator())); + + edgemapcbts.resize(EDGE_INPUT_NUM); + for(int i=0;i<(int)edgemapcbts.size();i++) + { + Gtk::HBox * hbox=new Gtk::HBox(); + + std::ostringstream o; + o << "EdgeInput " << i+1 << ":"; + label=new Gtk::Label(o.str()); + + edgemapcbts[i]=new Gtk::ComboBoxText(); + + hbox->pack_start(*label); + hbox->pack_start(*(edgemapcbts[i])); + pack_start(*hbox); + } + + pack_start(*(new Gtk::HSeparator())); +} + +sigc::signal AlgoBox::signal_maplist_needed() +{ + return signal_maplist_need; +} + +void AlgoBox::emit_tab_change() +{ + signal_maplist_need.emit(tabcbt.get_active_text()); +} diff -r 9e78d14fd0ba -r 853dd852abc7 algobox.h --- a/algobox.h Wed Jan 04 13:31:59 2006 +0000 +++ b/algobox.h Wed Jan 04 18:05:55 2006 +0000 @@ -11,52 +11,31 @@ class AlgoBox : public Gtk::VBox { + sigc::signal signal_maplist_need; + Gtk::ComboBoxText tabcbt; + +protected: Gtk::Label * label; - Gtk::ComboBoxText cbt; + std::vector nodemapcbts; + std::vector edgemapcbts; - public: - AlgoBox(std::vector tabnames) - { - update_tablist(tabnames); +public: + AlgoBox(){}; + AlgoBox(std::vector, std::vector, std::vector); - label=new Gtk::Label("Haliho"); - - pack_start(*label); - pack_start(cbt); + virtual void init(std::vector, std::vector, std::vector); - show_all_children(); - }; + sigc::signal signal_maplist_needed(); + void emit_tab_change(); - void update_tablist( std::vector< std::string > tl ) - { - std::string actname=cbt.get_active_text(); - int prev_act=-1; + void update_tablist( std::vector< std::string > tl ); + void update_maplist( std::vector< std::string >, std::vector< std::string >); - cbt.clear(); - int actptr=0; - - std::vector< std::string >::iterator emsi=tl.begin(); - for(;emsi!=tl.end();emsi++) - { - if(actname==*emsi) - { - prev_act=actptr; - } - - cbt.append_text(*emsi); - actptr++; - } - - if(prev_act!=-1) - { - cbt.set_active(prev_act); - } - else if(actptr>0) //so there is item in the list - { - cbt.set_active(0); - } - } - + void update_cbt( std::vector< std::string > tl, Gtk::ComboBoxText &); + + virtual void run(); + + virtual void build_box(); }; #endif //ALGOBOX_H diff -r 9e78d14fd0ba -r 853dd852abc7 algowin.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/algowin.cc Wed Jan 04 18:05:55 2006 +0000 @@ -0,0 +1,88 @@ +#include +#include + +sigc::signal AlgoWin::signal_closing() +{ + return signal_closed; +} + +sigc::signal AlgoWin::signal_maplist_needed() +{ + return signal_maplist_need; +} + +bool AlgoWin::closeIfEscapeIsPressed(GdkEventKey* e) +{ + if(e->keyval==GDK_Escape) + { + on_hide(); + } + return true; +} + +AlgoWin::AlgoWin(int algoid, std::vector tabnames, std::vector nodemapnames,std::vector edgemapnames) +{ + signal_key_press_event().connect(sigc::mem_fun(*this, &AlgoWin::closeIfEscapeIsPressed)); + + Gtk::VBox * vbox=new Gtk::VBox(); + vbox->set_spacing(5); + + Gtk::Label * label=new Gtk::Label("Select graph:"); + + switch(algoid) + { + case 0: + ab=new AlgoBox(tabnames, nodemapnames, edgemapnames); + set_title("Algo Win Demo"); + break; + case 1: + ab=new KruskalBox(tabnames, nodemapnames, edgemapnames); + set_title("Kruskal Algorithm"); + break; + default: + break; + } + ab->signal_maplist_needed().connect(sigc::mem_fun(*this, &AlgoWin::emit_tab_change)); + + runbutton=new Gtk::Button("Run"); + runbutton->signal_released().connect(sigc::mem_fun(*ab,&AlgoBox::run)); + runbutton->signal_activate().connect(sigc::mem_fun(*ab,&AlgoBox::run)); + + closebutton=new Gtk::Button("Close"); + closebutton->signal_released().connect(sigc::mem_fun(*this,&AlgoWin::on_hide)); + closebutton->signal_activate().connect(sigc::mem_fun(*this,&AlgoWin::on_hide)); + + Gtk::HBox * hbox=new Gtk::HBox(); + + hbox->pack_start(*runbutton); + hbox->pack_start(*closebutton); + + vbox->pack_start(*label); + vbox->pack_start(*ab); + vbox->pack_start(*hbox); + + add(*vbox); + + show_all_children(); +}; + +void AlgoWin::update_tablist(std::vector tabnames) +{ + ab->update_tablist(tabnames); +} + +void AlgoWin::update_maplist(std::vector nodemapnames, std::vector edgemapnames) +{ + ab->update_maplist(nodemapnames, edgemapnames); +} + +void AlgoWin::on_hide() +{ + signal_closed.emit(this); + Gtk::Window::on_hide(); +} + +void AlgoWin::emit_tab_change(std::string newtab) +{ + signal_maplist_need.emit(this, newtab); +} diff -r 9e78d14fd0ba -r 853dd852abc7 algowin.h --- a/algowin.h Wed Jan 04 13:31:59 2006 +0000 +++ b/algowin.h Wed Jan 04 18:05:55 2006 +0000 @@ -10,44 +10,32 @@ #include #include -enum {GENERAL, ALGO_NUM}; // algorithm IDs; +enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs; -class AlgoWin : public Gtk::Dialog +class AlgoWin : public Gtk::Window { private: AlgoBox * ab; + Gtk::Button * runbutton; + Gtk::Button * closebutton; protected: sigc::signal signal_closed; + sigc::signal signal_maplist_need; public: - sigc::signal signal_closing() - { - return signal_closed; - } + bool closeIfEscapeIsPressed(GdkEventKey* e); - AlgoWin(int algoid, std::vector tabnames) - { - Gtk::VBox * vbox=get_vbox(); - - ab=new AlgoBox(tabnames); - - vbox->pack_start(*ab); - - add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); - - show_all_children(); - }; + sigc::signal signal_closing(); + sigc::signal signal_maplist_needed(); - void update_tablist(std::vector tabnames) - { - ab->update_tablist(tabnames); - } + void emit_tab_change(std::string); - void on_hide() - { - signal_closed.emit(this); - Gtk::Dialog::on_hide(); - } + AlgoWin(int, std::vector, std::vector, std::vector); + + void update_tablist(std::vector tabnames); + void update_maplist(std::vector, std::vector); + + void on_hide(); }; #endif //ALGOWIN_H diff -r 9e78d14fd0ba -r 853dd852abc7 kruskalbox.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kruskalbox.cc Wed Jan 04 18:05:55 2006 +0000 @@ -0,0 +1,27 @@ +#include + +KruskalBox::KruskalBox(std::vector t, std::vector nm, std::vector em):AlgoBox() +{ + init(t, nm, em); +} + +void KruskalBox::run() +{ + std::cout << "Kruskal inditasa, de meg nincsen keszen." << std::endl; +} + +void KruskalBox::build_box() +{ + edgemapcbts.resize(1); + Gtk::HBox * hbox=new Gtk::HBox(); + + std::ostringstream o; + o << "Edgecosts: "; + label=new Gtk::Label(o.str()); + + edgemapcbts[0]=new Gtk::ComboBoxText(); + + hbox->pack_start(*label); + hbox->pack_start(*(edgemapcbts[0])); + pack_start(*hbox); +} diff -r 9e78d14fd0ba -r 853dd852abc7 kruskalbox.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/kruskalbox.h Wed Jan 04 18:05:55 2006 +0000 @@ -0,0 +1,23 @@ +// -*- C++ -*- // + +#ifndef KRUSKALBOX_H +#define KRUSKALBOX_H + +class KruskalBox; + +#include +#include +#include +#include +#include + +class KruskalBox : public AlgoBox +{ +public: + KruskalBox(std::vector t, std::vector nm, std::vector em); + + void run(); + + void build_box(); +}; +#endif //KRUSKALBOX_H diff -r 9e78d14fd0ba -r 853dd852abc7 main_win.cc --- a/main_win.cc Wed Jan 04 13:31:59 2006 +0000 +++ b/main_win.cc Wed Jan 04 18:05:55 2006 +0000 @@ -104,6 +104,8 @@ ag->add( Gtk::Action::create("AlgoMenu", "_Algorithms") ); ag->add( Gtk::Action::create("AlgoGeneral", "_General"), sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) ); + ag->add( Gtk::Action::create("AlgoKruskal", "_Kruskal"), + sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) ); Gtk::RadioAction::Group tool_group; ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), "Move"), @@ -153,6 +155,7 @@ " " " " " " + " " " " " " " " @@ -224,7 +227,7 @@ } set_title(tabnames[active_tab] + " - " + prog_name); notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]); - updateAlgoWins(); + updateAlgoWinTabs(); } void MainWin::readFile(const std::string & filename) @@ -246,7 +249,7 @@ notebook.append_page((Gtk::Widget&)(*(tabs[active_tab]))); notebook.set_current_page(size); set_tabtitle("unsaved file"); - updateAlgoWins(); + updateAlgoWinTabs(); } void MainWin::closeTab() @@ -306,7 +309,7 @@ active_tab=-1; } - updateAlgoWins(); + updateAlgoWinTabs(); } } @@ -404,18 +407,28 @@ void MainWin::createAlgoWin(int algoid) { - AlgoWin * aw=new AlgoWin(algoid, tabnames); + AlgoWin * aw=new AlgoWin(algoid, tabnames, tabs[0]->mapstorage.getNodeMapList(),tabs[0]->mapstorage.getEdgeMapList()); aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin)); + aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps)); aws.insert(aw); aw->show(); } +void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname) +{ + int i=0; + for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++) + { + } + awp->update_maplist(tabs[i]->mapstorage.getNodeMapList(),tabs[i]->mapstorage.getEdgeMapList()); +} + void MainWin::deRegisterAlgoWin(AlgoWin * awp) { aws.erase(awp); } -void MainWin::updateAlgoWins() +void MainWin::updateAlgoWinTabs() { std::set< AlgoWin* >::iterator awsi=aws.begin(); for(;awsi!=aws.end();awsi++) diff -r 9e78d14fd0ba -r 853dd852abc7 main_win.h --- a/main_win.h Wed Jan 04 13:31:59 2006 +0000 +++ b/main_win.h Wed Jan 04 18:05:55 2006 +0000 @@ -73,7 +73,8 @@ virtual void createAlgoWin(int); virtual void deRegisterAlgoWin(AlgoWin *); - virtual void updateAlgoWins(); + virtual void updateAlgoWinTabs(); + virtual void updateAlgoWinMaps(AlgoWin *, std::string); virtual void changeEditorialTool(int);