diff -r 4708b716d2f4 -r a8a007f1c01c gui/new_map_win.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/new_map_win.cc Tue Jul 26 21:20:01 2005 +0000 @@ -0,0 +1,105 @@ +#include + +bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e) +{ + if(e->keyval==GDK_Escape) + { + hide(); + } + return true; +} + +NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap") +{ + set_title(title); + set_default_size(200, 50); + + signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed)); + + + //entries + table=new Gtk::Table(3, 2, false); + + label=new Gtk::Label; + label->set_text("Name of new map:"); + name.set_text(""); + + (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3); + (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3); + + label=new Gtk::Label; + label->set_text("Default value in the map:"); + default_value.set_text("0"); + + (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3); + (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3); + + //node vs. edge map selector + Gtk::RadioButton::Group group = node.get_group(); + edge.set_group(group); + + (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); + (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3); + + vbox.pack_start(*table); + + //OK button + button=new Gtk::Button("OK"); + + button->signal_clicked().connect + ( + sigc::mem_fun(*this, &NewMapWin::buttonPressed) + ); + + + vbox.pack_start(*button); + + add(vbox); + + show_all_children(); + +} + +void NewMapWin::buttonPressed() +{ + bool valid_double=true; + int point_num=0; + + std::string def_val_str=default_value.get_text(); + char * def_val_ch=new char [def_val_str.length()]; + for(int i=0;i<(int)(def_val_str.length());i++) + { + if(((def_val_str[i]<'0')||(def_val_str[i]>'9'))&&(def_val_str[i]!='.')) + { + valid_double=false; + } + else + { + if(def_val_str[i]=='.') + { + point_num++; + } + } + def_val_ch[i]=def_val_str[i]; + } + + double def_val=atof(def_val_ch); + + std::string mapname=name.get_text(); + + if((point_num<=1)&&(valid_double)&&(!mapname.empty())) + { + if(edge.get_active()) + { + gdc.addNewEdgeMap(def_val,mapname); + } + else + { + gdc.addNewNodeMap(def_val,mapname); + } + name.set_text(""); + default_value.set_text("0"); + hide(); + } +} +