gui/algobox.cc
author hegyi
Fri, 06 Jan 2006 16:07:08 +0000
changeset 1884 9c061834b33b
parent 1879 01d41844ef46
child 1886 8b225c2935e7
permissions -rw-r--r--
In algorithm window maps can be selected and reated through MapSelector widget.
     1 #include <algobox.h>
     2 
     3 enum {N_DEMO1, N_DEMO2, NODE_INPUT_NUM}; // input IDs for nodes;
     4 enum {E_DEMO1, EDGE_INPUT_NUM}; // input IDs for edges;
     5 
     6 AlgoBox::AlgoBox(std::vector<std::string> tabnames)
     7 {
     8   init(tabnames);
     9 }
    10 
    11 void AlgoBox::init(std::vector<std::string> tabnames)
    12 {
    13   set_spacing(5);
    14 
    15   update_tablist(tabnames);
    16 
    17   //if active tab is changed, the map names in cbt/s have to be updated
    18   tabcbt.signal_changed().connect(sigc::mem_fun(*this, &AlgoBox::emit_tab_change));
    19 
    20   pack_start(tabcbt);
    21   build_box();
    22 
    23   show_all_children();
    24 };
    25 
    26 void AlgoBox::update_cbt(std::vector< std::string > stringlist, Gtk::ComboBoxText & cbt)
    27 {
    28   std::string actname=cbt.get_active_text();
    29   int prev_act=-1;
    30 
    31   cbt.clear();
    32   int actptr=0;
    33 
    34   std::vector< std::string >::iterator emsi=stringlist.begin();
    35   for(;emsi!=stringlist.end();emsi++)
    36     {
    37       if(actname==*emsi)
    38 	{
    39 	  prev_act=actptr;
    40 	}
    41 
    42       cbt.append_text(*emsi);
    43       actptr++;
    44     }
    45 
    46   if(prev_act!=-1)
    47     {
    48       cbt.set_active(prev_act);
    49     }
    50   else if(actptr>0) //so there is item in the list
    51     {
    52       //cbt.set_active(0);
    53     }
    54 }
    55 
    56 void AlgoBox::update_tablist( std::vector< std::string > tl )
    57 {
    58   update_cbt(tl, tabcbt);
    59   emit_tab_change();
    60 }
    61 
    62 void AlgoBox::update_maplist(MapStorage * ms)
    63 {
    64   mapstorage=ms;
    65   std::vector<std::string> nml;
    66   std::vector<std::string> eml;
    67   if(mapstorage!=NULL)
    68     {
    69       mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::nodemaplist_changed));
    70       mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &AlgoBox::edgemaplist_changed));
    71       nml=mapstorage->getNodeMapList();
    72       eml=mapstorage->getEdgeMapList();
    73     }
    74   for(int i=0;i<(int)nodemapcbts.size();i++)
    75     {
    76       (nodemapcbts[i])->update_list(nml);
    77       //update_cbt(nml, *(nodemapcbts[i]));
    78     }
    79   for(int i=0;i<(int)edgemapcbts.size();i++)
    80     {
    81       (edgemapcbts[i])->update_list(eml);
    82       //update_cbt(eml, *(edgemapcbts[i]));
    83     }
    84 }
    85 
    86 void AlgoBox::nodemaplist_changed(std::string newmap)
    87 {
    88   for(int i=0;i<(int)nodemapcbts.size();i++)
    89     {
    90       (nodemapcbts[i])->append_text(newmap);
    91     }
    92 }
    93 
    94 void AlgoBox::edgemaplist_changed(std::string newmap)
    95 {
    96   for(int i=0;i<(int)edgemapcbts.size();i++)
    97     {
    98       (edgemapcbts[i])->append_text(newmap);
    99     }
   100 }
   101 
   102 void AlgoBox::run()
   103 {
   104   std::cout << "Start algorithm." << std::endl;
   105 }
   106 
   107 void AlgoBox::build_box()
   108 {
   109   pack_start(*(new Gtk::HSeparator()));
   110 
   111   Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
   112       
   113   pack_start(*label);
   114   pack_start(*(new Gtk::HSeparator()));
   115 
   116   label=new Gtk::Label("Maps in chosen tab:");
   117       
   118   pack_start(*label);
   119 
   120   nodemapcbts.resize(NODE_INPUT_NUM);
   121   for(int i=0;i<(int)nodemapcbts.size();i++)
   122     {
   123       std::vector<std::string> empty_vector;
   124 
   125       std::ostringstream o;
   126       o << "NodeInput " << i+1 << ":";
   127 
   128       nodemapcbts[i]=new MapSelector(empty_vector,"",o.str(),false, false);
   129       nodemapcbts[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
   130 
   131       pack_start(*(nodemapcbts[i]));
   132     }
   133 
   134   pack_start(*(new Gtk::HSeparator()));
   135 
   136   edgemapcbts.resize(EDGE_INPUT_NUM);
   137   for(int i=0;i<(int)edgemapcbts.size();i++)
   138     {
   139       std::vector<std::string> empty_vector;
   140 
   141       std::ostringstream o;
   142       o << "EdgeInput " << i+1 << ":";
   143 
   144       edgemapcbts[i]=new MapSelector(empty_vector,"",o.str(),true, false);
   145       edgemapcbts[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
   146 
   147       pack_start(*(edgemapcbts[i]));
   148     }
   149 
   150   pack_start(*(new Gtk::HSeparator()));
   151 }
   152 
   153 sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
   154 {
   155   return signal_maplist_need;
   156 }
   157 
   158 void AlgoBox::emit_tab_change()
   159 {
   160   std::string active_tab=tabcbt.get_active_text();
   161   if(active_tab!="")
   162     {
   163       signal_maplist_need.emit(active_tab);
   164     }
   165   else
   166     {
   167       std::vector<std::string> empty_vector;
   168       update_maplist(NULL);
   169     }
   170 }
   171 
   172 void AlgoBox::emit_new_map_signal(bool itisedge)
   173 {
   174   signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
   175 }