gui/new_map_win.cc
changeset 1593 a8a007f1c01c
child 1597 15b51d278bf0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui/new_map_win.cc	Tue Jul 26 21:20:01 2005 +0000
     1.3 @@ -0,0 +1,105 @@
     1.4 +#include <new_map_win.h>
     1.5 +
     1.6 +bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
     1.7 +{
     1.8 +  if(e->keyval==GDK_Escape)
     1.9 +  {
    1.10 +    hide();
    1.11 +  }
    1.12 +  return true;
    1.13 +}
    1.14 +
    1.15 +NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
    1.16 +{
    1.17 +  set_title(title);
    1.18 +  set_default_size(200, 50);
    1.19 +
    1.20 +  signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
    1.21 +
    1.22 +
    1.23 +  //entries
    1.24 +  table=new Gtk::Table(3, 2, false);
    1.25 +
    1.26 +  label=new Gtk::Label;
    1.27 +  label->set_text("Name of new map:");
    1.28 +  name.set_text("");
    1.29 +
    1.30 +  (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.31 +  (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.32 +
    1.33 +  label=new Gtk::Label;
    1.34 +  label->set_text("Default value in the map:");
    1.35 +  default_value.set_text("0");
    1.36 +
    1.37 +  (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.38 +  (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.39 +
    1.40 +  //node vs. edge map selector
    1.41 +  Gtk::RadioButton::Group group = node.get_group();
    1.42 +  edge.set_group(group);
    1.43 +
    1.44 +  (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.45 +  (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
    1.46 +
    1.47 +  vbox.pack_start(*table);
    1.48 +
    1.49 +  //OK button
    1.50 +  button=new Gtk::Button("OK");
    1.51 +
    1.52 +  button->signal_clicked().connect
    1.53 +    (
    1.54 +     sigc::mem_fun(*this, &NewMapWin::buttonPressed)
    1.55 +    );
    1.56 +
    1.57 +
    1.58 +  vbox.pack_start(*button);
    1.59 +
    1.60 +  add(vbox);
    1.61 +
    1.62 +  show_all_children();
    1.63 +
    1.64 +}
    1.65 +
    1.66 +void NewMapWin::buttonPressed()
    1.67 +{
    1.68 +  bool valid_double=true;
    1.69 +  int point_num=0;
    1.70 +
    1.71 +  std::string def_val_str=default_value.get_text();
    1.72 +  char * def_val_ch=new char [def_val_str.length()];
    1.73 +  for(int i=0;i<(int)(def_val_str.length());i++)
    1.74 +    {
    1.75 +      if(((def_val_str[i]<'0')||(def_val_str[i]>'9'))&&(def_val_str[i]!='.'))
    1.76 +	{
    1.77 +	  valid_double=false;
    1.78 +	}
    1.79 +      else
    1.80 +	{
    1.81 +	  if(def_val_str[i]=='.')
    1.82 +	    {
    1.83 +	      point_num++;
    1.84 +	    }
    1.85 +	}
    1.86 +      def_val_ch[i]=def_val_str[i];
    1.87 +    }
    1.88 +  
    1.89 +  double def_val=atof(def_val_ch);
    1.90 +
    1.91 +  std::string mapname=name.get_text();
    1.92 +
    1.93 +  if((point_num<=1)&&(valid_double)&&(!mapname.empty()))
    1.94 +    {
    1.95 +      if(edge.get_active())
    1.96 +	{
    1.97 +	  gdc.addNewEdgeMap(def_val,mapname);
    1.98 +	}
    1.99 +      else
   1.100 +	{
   1.101 +	  gdc.addNewNodeMap(def_val,mapname);
   1.102 +	}
   1.103 +      name.set_text("");
   1.104 +      default_value.set_text("0");
   1.105 +      hide();
   1.106 +    }
   1.107 +}
   1.108 +