gui/new_map_win.cc
author hegyi
Wed, 27 Jul 2005 11:35:13 +0000
changeset 1597 15b51d278bf0
parent 1593 a8a007f1c01c
child 1737 dc821d2668c1
permissions -rw-r--r--
No maps with the same name can be added.
hegyi@1593
     1
#include <new_map_win.h>
hegyi@1593
     2
hegyi@1593
     3
bool NewMapWin::closeIfEscapeIsPressed(GdkEventKey* e)
hegyi@1593
     4
{
hegyi@1593
     5
  if(e->keyval==GDK_Escape)
hegyi@1593
     6
  {
hegyi@1593
     7
    hide();
hegyi@1593
     8
  }
hegyi@1593
     9
  return true;
hegyi@1593
    10
}
hegyi@1593
    11
hegyi@1593
    12
NewMapWin::NewMapWin(const std::string& title, GraphDisplayerCanvas & grdispc):gdc(grdispc),node("Create NodeMap"),edge("Create EdgeMap")
hegyi@1593
    13
{
hegyi@1593
    14
  set_title(title);
hegyi@1593
    15
  set_default_size(200, 50);
hegyi@1593
    16
hegyi@1593
    17
  signal_key_press_event().connect(sigc::mem_fun(*this, &NewMapWin::closeIfEscapeIsPressed));
hegyi@1593
    18
hegyi@1593
    19
hegyi@1593
    20
  //entries
hegyi@1593
    21
  table=new Gtk::Table(3, 2, false);
hegyi@1593
    22
hegyi@1593
    23
  label=new Gtk::Label;
hegyi@1593
    24
  label->set_text("Name of new map:");
hegyi@1593
    25
  name.set_text("");
hegyi@1593
    26
hegyi@1593
    27
  (*table).attach(*label,0,1,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1593
    28
  (*table).attach(name,1,2,0,1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1593
    29
hegyi@1593
    30
  label=new Gtk::Label;
hegyi@1593
    31
  label->set_text("Default value in the map:");
hegyi@1593
    32
  default_value.set_text("0");
hegyi@1593
    33
hegyi@1593
    34
  (*table).attach(*label,0,1,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1593
    35
  (*table).attach(default_value,1,2,1,2,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1593
    36
hegyi@1593
    37
  //node vs. edge map selector
hegyi@1593
    38
  Gtk::RadioButton::Group group = node.get_group();
hegyi@1593
    39
  edge.set_group(group);
hegyi@1593
    40
hegyi@1593
    41
  (*table).attach(node,0,1,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1593
    42
  (*table).attach(edge,1,2,2,3,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@1593
    43
hegyi@1593
    44
  vbox.pack_start(*table);
hegyi@1593
    45
hegyi@1593
    46
  //OK button
hegyi@1593
    47
  button=new Gtk::Button("OK");
hegyi@1593
    48
hegyi@1593
    49
  button->signal_clicked().connect
hegyi@1593
    50
    (
hegyi@1593
    51
     sigc::mem_fun(*this, &NewMapWin::buttonPressed)
hegyi@1593
    52
    );
hegyi@1593
    53
hegyi@1593
    54
hegyi@1593
    55
  vbox.pack_start(*button);
hegyi@1593
    56
hegyi@1593
    57
  add(vbox);
hegyi@1593
    58
hegyi@1593
    59
  show_all_children();
hegyi@1593
    60
hegyi@1593
    61
}
hegyi@1593
    62
hegyi@1593
    63
void NewMapWin::buttonPressed()
hegyi@1593
    64
{
hegyi@1593
    65
  bool valid_double=true;
hegyi@1593
    66
  int point_num=0;
hegyi@1593
    67
hegyi@1593
    68
  std::string def_val_str=default_value.get_text();
hegyi@1593
    69
  char * def_val_ch=new char [def_val_str.length()];
hegyi@1593
    70
  for(int i=0;i<(int)(def_val_str.length());i++)
hegyi@1593
    71
    {
hegyi@1593
    72
      if(((def_val_str[i]<'0')||(def_val_str[i]>'9'))&&(def_val_str[i]!='.'))
hegyi@1593
    73
	{
hegyi@1593
    74
	  valid_double=false;
hegyi@1593
    75
	}
hegyi@1593
    76
      else
hegyi@1593
    77
	{
hegyi@1593
    78
	  if(def_val_str[i]=='.')
hegyi@1593
    79
	    {
hegyi@1593
    80
	      point_num++;
hegyi@1593
    81
	    }
hegyi@1593
    82
	}
hegyi@1593
    83
      def_val_ch[i]=def_val_str[i];
hegyi@1593
    84
    }
hegyi@1593
    85
  
hegyi@1593
    86
  double def_val=atof(def_val_ch);
hegyi@1593
    87
hegyi@1593
    88
  std::string mapname=name.get_text();
hegyi@1593
    89
hegyi@1593
    90
  if((point_num<=1)&&(valid_double)&&(!mapname.empty()))
hegyi@1593
    91
    {
hegyi@1597
    92
      int abortion=0;
hegyi@1593
    93
      if(edge.get_active())
hegyi@1593
    94
	{
hegyi@1597
    95
	  abortion=gdc.addNewEdgeMap(def_val,mapname);
hegyi@1593
    96
	}
hegyi@1593
    97
      else
hegyi@1593
    98
	{
hegyi@1597
    99
	  abortion=gdc.addNewNodeMap(def_val,mapname);
hegyi@1593
   100
	}
hegyi@1597
   101
      if(!abortion)
hegyi@1597
   102
	{
hegyi@1597
   103
	  name.set_text("");
hegyi@1597
   104
	  default_value.set_text("0");
hegyi@1597
   105
	  hide();
hegyi@1597
   106
	}
hegyi@1593
   107
    }
hegyi@1593
   108
}
hegyi@1593
   109