COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/new_map_win.cc @ 1768:1e2e0238e7c8

Last change on this file since 1768:1e2e0238e7c8 was 1737:dc821d2668c1, checked in by Hegyi Péter, 19 years ago

Newly created map is realized by the property givening by common sense.

File size: 2.5 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::showByPreChoose(bool itisedge)
64{
65  if(itisedge)
66    {
67      edge.set_active();
68    }
69  else
70    {
71      node.set_active();
72    }
73  node.hide();
74  edge.hide();
75  show();
76}
77
78void NewMapWin::buttonPressed()
79{
80  bool valid_double=true;
81  int point_num=0;
82
83  std::string def_val_str=default_value.get_text();
84  char * def_val_ch=new char [def_val_str.length()];
85  for(int i=0;i<(int)(def_val_str.length());i++)
86    {
87      if(((def_val_str[i]<'0')||(def_val_str[i]>'9'))&&(def_val_str[i]!='.'))
88        {
89          valid_double=false;
90        }
91      else
92        {
93          if(def_val_str[i]=='.')
94            {
95              point_num++;
96            }
97        }
98      def_val_ch[i]=def_val_str[i];
99    }
100 
101  double def_val=atof(def_val_ch);
102
103  std::string mapname=name.get_text();
104
105  if((point_num<=1)&&(valid_double)&&(!mapname.empty()))
106    {
107      int abortion=0;
108      if(edge.get_active())
109        {
110          abortion=gdc.addNewEdgeMap(def_val,mapname);
111        }
112      else
113        {
114          abortion=gdc.addNewNodeMap(def_val,mapname);
115        }
116      if(!abortion)
117        {
118          name.set_text("");
119          default_value.set_text("0");
120          edge.show();
121          node.show();
122          hide();
123        }
124    }
125}
126
Note: See TracBrowser for help on using the repository browser.