algobox.cc
author hegyi
Fri, 13 Oct 2006 13:53:10 +0000
changeset 162 aaa517c9dc23
parent 116 2bd795bb9984
child 174 95872af46fc4
permissions -rw-r--r--
Dijkstra in GUI.
     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   signal_maplist_updated.emit();
    85 }
    86 
    87 void AlgoBox::nodemaplist_changed(std::string newmap)
    88 {
    89   for(int i=0;i<(int)nodemapcbts.size();i++)
    90     {
    91       (nodemapcbts[i])->append_text(newmap);
    92     }
    93 }
    94 
    95 void AlgoBox::edgemaplist_changed(std::string newmap)
    96 {
    97   for(int i=0;i<(int)edgemapcbts.size();i++)
    98     {
    99       (edgemapcbts[i])->append_text(newmap);
   100     }
   101 }
   102 
   103 void AlgoBox::run()
   104 {
   105   std::cout << "Start algorithm." << std::endl;
   106 }
   107 
   108 void AlgoBox::build_box()
   109 {
   110   pack_start(*(new Gtk::HSeparator()));
   111 
   112   Gtk::Label * label=new Gtk::Label("Specific part for each algorithm.");
   113       
   114   pack_start(*label);
   115   pack_start(*(new Gtk::HSeparator()));
   116 
   117   label=new Gtk::Label("Maps in chosen tab:");
   118       
   119   pack_start(*label);
   120 
   121   for(int i=0;i<NODE_INPUT_NUM;i++)
   122     {
   123       std::ostringstream o;
   124       o << "NodeInput " << i+1 << ":";
   125 
   126       addMapSelector(o.str(), false);
   127     }
   128 
   129   pack_start(*(new Gtk::HSeparator()));
   130 
   131   for(int i=0;i<EDGE_INPUT_NUM;i++)
   132     {
   133 
   134       std::ostringstream o;
   135       o << "EdgeInput " << i+1 << ":";
   136 
   137       addMapSelector(o.str(), true);
   138     }
   139 
   140   pack_start(*(new Gtk::HSeparator()));
   141 }
   142 
   143 void AlgoBox::addMapSelector(std::string inputname, bool itisedge)
   144 {
   145   std::vector<std::string> empty_vector;
   146 
   147   MapSelector * msp=new MapSelector(empty_vector,"",inputname,itisedge, false);
   148 
   149   if(itisedge)
   150     {
   151       edgemapcbts.resize(edgemapcbts.size()+1);
   152       edgemapcbts[edgemapcbts.size()-1]=msp;
   153     }
   154   else
   155     {
   156       nodemapcbts.resize(nodemapcbts.size()+1);
   157       nodemapcbts[nodemapcbts.size()-1]=msp;
   158     }
   159 
   160   msp->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &AlgoBox::emit_new_map_signal));
   161 
   162   pack_start(*msp);
   163 }
   164 
   165 sigc::signal<void, std::string> AlgoBox::signal_maplist_needed()
   166 {
   167   return signal_maplist_need;
   168 }
   169 
   170 void AlgoBox::emit_tab_change()
   171 {
   172   std::string active_tab=tabcbt.get_active_text();
   173   if(active_tab!="")
   174     {
   175       signal_maplist_need.emit(active_tab);
   176     }
   177   else
   178     {
   179       std::vector<std::string> empty_vector;
   180       update_maplist(NULL);
   181     }
   182 }
   183 
   184 void AlgoBox::emit_new_map_signal(bool itisedge)
   185 {
   186   signal_newmapwin_need.emit(tabcbt.get_active_text(), itisedge);
   187 }