hegyi@1731
|
1 |
#include "mapselector.h"
|
hegyi@1731
|
2 |
|
hegyi@1733
|
3 |
MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, NewMapWin & newmapw, int identifier, bool edge):gdc(grdispc),ms(mapst),nmw(newmapw),id(identifier),itisedge(edge),default_state(true),node_to_update(INVALID),edge_to_update(INVALID)
|
hegyi@1731
|
4 |
{
|
hegyi@1731
|
5 |
update_list();
|
hegyi@1731
|
6 |
|
hegyi@1731
|
7 |
cbt.set_active(0);
|
hegyi@1731
|
8 |
|
hegyi@1731
|
9 |
//binding signal to the actual entry
|
hegyi@1731
|
10 |
cbt.signal_changed().connect
|
hegyi@1731
|
11 |
(
|
hegyi@1731
|
12 |
sigc::mem_fun((*this), &MapSelector::comboChanged),
|
hegyi@1731
|
13 |
false
|
hegyi@1731
|
14 |
);
|
hegyi@1731
|
15 |
|
hegyi@1731
|
16 |
if(itisedge)
|
hegyi@1731
|
17 |
{
|
hegyi@1731
|
18 |
label=new Gtk::Label(edge_property_strings[id]);
|
hegyi@1731
|
19 |
}
|
hegyi@1731
|
20 |
else
|
hegyi@1731
|
21 |
{
|
hegyi@1731
|
22 |
label=new Gtk::Label(node_property_strings[id]);
|
hegyi@1731
|
23 |
}
|
hegyi@1731
|
24 |
|
hegyi@1731
|
25 |
label->set_width_chars(longest_property_string_length);
|
hegyi@1731
|
26 |
|
hegyi@1731
|
27 |
defbut=new Gtk::Button();
|
hegyi@1731
|
28 |
defbut->set_label("Reset");
|
hegyi@1731
|
29 |
|
hegyi@1731
|
30 |
defbut->signal_pressed().connect
|
hegyi@1731
|
31 |
(
|
hegyi@1731
|
32 |
sigc::mem_fun(*this, &MapSelector::reset)
|
hegyi@1731
|
33 |
);
|
hegyi@1731
|
34 |
|
hegyi@1731
|
35 |
newbut=new Gtk::Button(Gtk::Stock::NEW);
|
hegyi@1731
|
36 |
|
hegyi@1733
|
37 |
newbut->signal_pressed().connect
|
hegyi@1733
|
38 |
(
|
hegyi@1733
|
39 |
sigc::mem_fun(nmw, &NewMapWin::show)
|
hegyi@1733
|
40 |
);
|
hegyi@1733
|
41 |
|
hegyi@1731
|
42 |
add(*label);
|
hegyi@1731
|
43 |
|
hegyi@1731
|
44 |
add(cbt);
|
hegyi@1731
|
45 |
|
hegyi@1731
|
46 |
add(*defbut);
|
hegyi@1731
|
47 |
add(*newbut);
|
hegyi@1731
|
48 |
}
|
hegyi@1731
|
49 |
|
hegyi@1731
|
50 |
void MapSelector::update_list()
|
hegyi@1731
|
51 |
{
|
hegyi@1731
|
52 |
cbt.clear();
|
hegyi@1731
|
53 |
if(itisedge)
|
hegyi@1731
|
54 |
{
|
hegyi@1731
|
55 |
std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
|
hegyi@1731
|
56 |
for(;emsi!=ms.endOfEdgeMaps();emsi++)
|
hegyi@1731
|
57 |
{
|
hegyi@1731
|
58 |
cbt.append_text(emsi->first);
|
hegyi@1731
|
59 |
}
|
hegyi@1731
|
60 |
}
|
hegyi@1731
|
61 |
else
|
hegyi@1731
|
62 |
{
|
hegyi@1731
|
63 |
std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
|
hegyi@1731
|
64 |
for(;emsi!=ms.endOfNodeMaps();emsi++)
|
hegyi@1731
|
65 |
{
|
hegyi@1731
|
66 |
cbt.append_text(emsi->first);
|
hegyi@1731
|
67 |
}
|
hegyi@1731
|
68 |
}
|
hegyi@1731
|
69 |
cbt.prepend_text("Default values");
|
hegyi@1731
|
70 |
}
|
hegyi@1731
|
71 |
|
hegyi@1731
|
72 |
void MapSelector::comboChanged()
|
hegyi@1731
|
73 |
{
|
hegyi@1731
|
74 |
if(cbt.get_active_row_number()!=0)
|
hegyi@1731
|
75 |
{
|
hegyi@1731
|
76 |
default_state=false;
|
hegyi@1731
|
77 |
Glib::ustring mapname = cbt.get_active_text();
|
hegyi@1731
|
78 |
if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
|
hegyi@1731
|
79 |
{
|
hegyi@1731
|
80 |
if(itisedge)
|
hegyi@1731
|
81 |
{
|
hegyi@1731
|
82 |
if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) )
|
hegyi@1731
|
83 |
{
|
hegyi@1731
|
84 |
Edge edge=edge_to_update;
|
hegyi@1731
|
85 |
switch(id)
|
hegyi@1731
|
86 |
{
|
hegyi@1731
|
87 |
case E_WIDTH:
|
hegyi@1731
|
88 |
gdc.changeEdgeWidth(mapname, edge);
|
hegyi@1731
|
89 |
break;
|
hegyi@1731
|
90 |
case E_COLOR:
|
hegyi@1731
|
91 |
gdc.changeEdgeColor(mapname, edge);
|
hegyi@1731
|
92 |
break;
|
hegyi@1731
|
93 |
case E_TEXT:
|
hegyi@1731
|
94 |
gdc.changeEdgeText(mapname, edge);
|
hegyi@1731
|
95 |
break;
|
hegyi@1731
|
96 |
default:
|
hegyi@1731
|
97 |
std::cerr<<"Error\n";
|
hegyi@1731
|
98 |
}
|
hegyi@1731
|
99 |
}
|
hegyi@1731
|
100 |
}
|
hegyi@1731
|
101 |
else
|
hegyi@1731
|
102 |
{
|
hegyi@1731
|
103 |
if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) )
|
hegyi@1731
|
104 |
{
|
hegyi@1731
|
105 |
Node node=node_to_update;
|
hegyi@1731
|
106 |
switch(id)
|
hegyi@1731
|
107 |
{
|
hegyi@1731
|
108 |
case N_RADIUS:
|
hegyi@1731
|
109 |
gdc.changeNodeRadius(mapname, node);
|
hegyi@1731
|
110 |
break;
|
hegyi@1731
|
111 |
case N_COLOR:
|
hegyi@1731
|
112 |
gdc.changeNodeColor(mapname, node);
|
hegyi@1731
|
113 |
break;
|
hegyi@1731
|
114 |
case N_TEXT:
|
hegyi@1731
|
115 |
gdc.changeNodeText(mapname, node);
|
hegyi@1731
|
116 |
break;
|
hegyi@1731
|
117 |
default:
|
hegyi@1731
|
118 |
std::cerr<<"Error\n";
|
hegyi@1731
|
119 |
}
|
hegyi@1731
|
120 |
}
|
hegyi@1731
|
121 |
}
|
hegyi@1731
|
122 |
}
|
hegyi@1731
|
123 |
}
|
hegyi@1731
|
124 |
else if((!default_state)&&(cbt.get_active_row_number()==0))
|
hegyi@1731
|
125 |
{
|
hegyi@1731
|
126 |
reset();
|
hegyi@1731
|
127 |
}
|
hegyi@1731
|
128 |
}
|
hegyi@1731
|
129 |
|
hegyi@1731
|
130 |
void MapSelector::reset()
|
hegyi@1731
|
131 |
{
|
hegyi@1731
|
132 |
default_state=true;
|
hegyi@1731
|
133 |
cbt.set_active(0);
|
hegyi@1731
|
134 |
|
hegyi@1731
|
135 |
if(itisedge)
|
hegyi@1731
|
136 |
{
|
hegyi@1731
|
137 |
Edge edge=edge_to_update;
|
hegyi@1731
|
138 |
switch(id)
|
hegyi@1731
|
139 |
{
|
hegyi@1731
|
140 |
case E_WIDTH:
|
hegyi@1731
|
141 |
gdc.resetEdgeWidth(edge);
|
hegyi@1731
|
142 |
break;
|
hegyi@1731
|
143 |
case E_COLOR:
|
hegyi@1731
|
144 |
gdc.resetEdgeColor(edge);
|
hegyi@1731
|
145 |
break;
|
hegyi@1731
|
146 |
case E_TEXT:
|
hegyi@1731
|
147 |
gdc.resetEdgeText(edge);
|
hegyi@1731
|
148 |
break;
|
hegyi@1731
|
149 |
default:
|
hegyi@1731
|
150 |
std::cerr<<"Error\n";
|
hegyi@1731
|
151 |
}
|
hegyi@1731
|
152 |
}
|
hegyi@1731
|
153 |
else
|
hegyi@1731
|
154 |
{
|
hegyi@1731
|
155 |
Node node=node_to_update;
|
hegyi@1731
|
156 |
switch(id)
|
hegyi@1731
|
157 |
{
|
hegyi@1731
|
158 |
case N_RADIUS:
|
hegyi@1731
|
159 |
gdc.resetNodeRadius(node);
|
hegyi@1731
|
160 |
break;
|
hegyi@1731
|
161 |
case N_COLOR:
|
hegyi@1731
|
162 |
gdc.resetNodeColor(node);
|
hegyi@1731
|
163 |
break;
|
hegyi@1731
|
164 |
case N_TEXT:
|
hegyi@1731
|
165 |
gdc.resetNodeText(node);
|
hegyi@1731
|
166 |
break;
|
hegyi@1731
|
167 |
default:
|
hegyi@1731
|
168 |
std::cerr<<"Error\n";
|
hegyi@1731
|
169 |
}
|
hegyi@1731
|
170 |
}
|
hegyi@1731
|
171 |
}
|
hegyi@1731
|
172 |
|
hegyi@1731
|
173 |
void MapSelector::update(Node node)
|
hegyi@1731
|
174 |
{
|
hegyi@1731
|
175 |
node_to_update=node;
|
hegyi@1731
|
176 |
if(default_state)
|
hegyi@1731
|
177 |
{
|
hegyi@1731
|
178 |
reset();
|
hegyi@1731
|
179 |
}
|
hegyi@1731
|
180 |
else
|
hegyi@1731
|
181 |
{
|
hegyi@1731
|
182 |
comboChanged();
|
hegyi@1731
|
183 |
}
|
hegyi@1731
|
184 |
node_to_update=INVALID;
|
hegyi@1731
|
185 |
}
|
hegyi@1731
|
186 |
|
hegyi@1731
|
187 |
void MapSelector::update(Edge edge)
|
hegyi@1731
|
188 |
{
|
hegyi@1731
|
189 |
edge_to_update=edge;
|
hegyi@1731
|
190 |
if(default_state)
|
hegyi@1731
|
191 |
{
|
hegyi@1731
|
192 |
reset();
|
hegyi@1731
|
193 |
}
|
hegyi@1731
|
194 |
else
|
hegyi@1731
|
195 |
{
|
hegyi@1731
|
196 |
comboChanged();
|
hegyi@1731
|
197 |
}
|
hegyi@1731
|
198 |
edge_to_update=INVALID;
|
hegyi@1731
|
199 |
}
|
hegyi@1731
|
200 |
|
hegyi@1731
|
201 |
Glib::ustring MapSelector::get_active_text()
|
hegyi@1731
|
202 |
{
|
hegyi@1731
|
203 |
return cbt.get_active_text();
|
hegyi@1731
|
204 |
}
|
hegyi@1731
|
205 |
|
hegyi@1731
|
206 |
void MapSelector::set_active_text(Glib::ustring text)
|
hegyi@1731
|
207 |
{
|
hegyi@1731
|
208 |
cbt.set_active_text(text);
|
hegyi@1731
|
209 |
}
|
hegyi@1731
|
210 |
|
hegyi@1731
|
211 |
void MapSelector::append_text(Glib::ustring text)
|
hegyi@1731
|
212 |
{
|
hegyi@1731
|
213 |
cbt.append_text(text);
|
hegyi@1731
|
214 |
}
|