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