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