COIN-OR::LEMON - Graph Library

source: glemon-0.x/new_map_win.cc @ 42:f1b70894b953

gui
Last change on this file since 42:f1b70894b953 was 42:f1b70894b953, checked in by Hegyi Péter, 19 years ago

EdgeMap? and NodeMap? creation is done, at last. Bach 4ever.

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      if(edge.get_active())
93        {
94          gdc.addNewEdgeMap(def_val,mapname);
95        }
96      else
97        {
98          gdc.addNewNodeMap(def_val,mapname);
99        }
100      name.set_text("");
101      default_value.set_text("0");
102      hide();
103    }
104}
105
Note: See TracBrowser for help on using the repository browser.