COIN-OR::LEMON - Graph Library

source: glemon-0.x/new_map_win.cc @ 46:121452cc4096

gui
Last change on this file since 46:121452cc4096 was 46:121452cc4096, checked in by Hegyi Péter, 15 years ago

No maps with the same name can be added.

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