|
1 #include "file_import_dialog.h" |
|
2 #include <gtkmm/dialog.h> |
|
3 #include <gtkmm/stock.h> |
|
4 #include <gtkmm/notebook.h> |
|
5 #include <gtkmm/messagedialog.h> |
|
6 #include <gtkmm/frame.h> |
|
7 #include <iostream> |
|
8 |
|
9 FileImportDialog::FileImportDialog(ImportData* d) : |
|
10 p_data(d) |
|
11 { |
|
12 add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
|
13 add_button(Gtk::Stock::OK, Gtk::RESPONSE_OK); |
|
14 |
|
15 Gtk::VBox* pVBox = get_vbox(); |
|
16 |
|
17 Gtk::Notebook* nb = Gtk::manage(new Gtk::Notebook); |
|
18 pVBox->pack_start(*nb, Gtk::PACK_EXPAND_WIDGET); |
|
19 |
|
20 Gtk::VBox* vbNodeMaps = Gtk::manage(new Gtk::VBox(false, 18)); |
|
21 vbNodeMaps->set_border_width(12); |
|
22 |
|
23 Gtk::VBox* vbEdgeMaps = Gtk::manage(new Gtk::VBox(false, 18)); |
|
24 vbEdgeMaps->set_border_width(12); |
|
25 |
|
26 Gtk::VBox* vbSpecMaps = Gtk::manage(new Gtk::VBox(false, 18)); |
|
27 vbSpecMaps->set_border_width(12); |
|
28 |
|
29 nb->append_page(*vbSpecMaps, "Special Maps"); |
|
30 nb->append_page(*vbNodeMaps, "Node Maps"); |
|
31 nb->append_page(*vbEdgeMaps, "Edge Maps"); |
|
32 |
|
33 // child widgets of vbSpecMaps |
|
34 { |
|
35 Gtk::VBox* box1 = Gtk::manage(new Gtk::VBox(false, 6)); |
|
36 vbSpecMaps->pack_start(*box1, Gtk::PACK_SHRINK); |
|
37 |
|
38 { |
|
39 Gtk::Label* label1 = |
|
40 Gtk::manage(new Gtk::Label("<b>Node Coordinates</b>")); |
|
41 label1->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); |
|
42 label1->set_use_markup(); |
|
43 box1->pack_start(*label1); |
|
44 |
|
45 Gtk::HBox* box2 = Gtk::manage(new Gtk::HBox); |
|
46 box1->pack_start(*box2); |
|
47 |
|
48 Gtk::Label* fill1 = Gtk::manage(new Gtk::Label(" ")); |
|
49 box2->pack_start(*fill1, Gtk::PACK_SHRINK); |
|
50 |
|
51 Gtk::VBox* box3 = Gtk::manage(new Gtk::VBox); |
|
52 box2->pack_start(*box3); |
|
53 |
|
54 Gtk::VBox* box13 = Gtk::manage(new Gtk::VBox); |
|
55 box3->pack_start(*box13); |
|
56 |
|
57 rbNodeCoordNone.set_label("None"); |
|
58 Gtk::RadioButtonGroup group = rbNodeCoordNone.get_group(); |
|
59 box13->pack_start(rbNodeCoordNone); |
|
60 |
|
61 Gtk::VBox* box4 = Gtk::manage(new Gtk::VBox); |
|
62 box3->pack_start(*box4); |
|
63 |
|
64 rbNodeCoordOneMap.set_label("One Map"); |
|
65 rbNodeCoordOneMap.set_group(group); |
|
66 box4->pack_start(rbNodeCoordOneMap); |
|
67 |
|
68 Gtk::HBox* box5 = Gtk::manage(new Gtk::HBox); |
|
69 box4->pack_start(*box5); |
|
70 |
|
71 Gtk::Label* fill2 = Gtk::manage(new Gtk::Label(" ")); |
|
72 box5->pack_start(*fill2, Gtk::PACK_SHRINK); |
|
73 |
|
74 Gtk::VBox* box6 = Gtk::manage(new Gtk::VBox); |
|
75 box5->pack_start(*box6); |
|
76 |
|
77 Gtk::HBox* box7 = Gtk::manage(new Gtk::HBox); |
|
78 box6->pack_start(*box7); |
|
79 |
|
80 Gtk::Label* label2 = Gtk::manage(new Gtk::Label("(X, Y)")); |
|
81 box7->pack_start(*label2, Gtk::PACK_SHRINK, 4); |
|
82 |
|
83 box7->pack_start(cbNodeCoordOneMap, Gtk::PACK_EXPAND_WIDGET); |
|
84 |
|
85 |
|
86 Gtk::VBox* box8 = Gtk::manage(new Gtk::VBox); |
|
87 box3->pack_start(*box8); |
|
88 |
|
89 rbNodeCoordTwoMaps.set_label("Two Maps"); |
|
90 rbNodeCoordTwoMaps.set_group(group); |
|
91 box8->pack_start(rbNodeCoordTwoMaps); |
|
92 |
|
93 Gtk::HBox* box9 = Gtk::manage(new Gtk::HBox); |
|
94 box8->pack_start(*box9); |
|
95 |
|
96 Gtk::Label* fill3 = Gtk::manage(new Gtk::Label(" ")); |
|
97 box9->pack_start(*fill3, Gtk::PACK_SHRINK); |
|
98 |
|
99 Gtk::VBox* box10 = Gtk::manage(new Gtk::VBox); |
|
100 box9->pack_start(*box10); |
|
101 |
|
102 Gtk::HBox* box11 = Gtk::manage(new Gtk::HBox); |
|
103 box10->pack_start(*box11); |
|
104 |
|
105 Gtk::Label* label3 = Gtk::manage(new Gtk::Label("X")); |
|
106 box11->pack_start(*label3, Gtk::PACK_SHRINK, 4); |
|
107 |
|
108 box11->pack_start(cbNodeCoordTwoMaps1, Gtk::PACK_EXPAND_WIDGET); |
|
109 |
|
110 Gtk::HBox* box12 = Gtk::manage(new Gtk::HBox); |
|
111 box10->pack_start(*box12); |
|
112 |
|
113 Gtk::Label* label4 = Gtk::manage(new Gtk::Label("Y")); |
|
114 box12->pack_start(*label4, Gtk::PACK_SHRINK, 4); |
|
115 |
|
116 box12->pack_start(cbNodeCoordTwoMaps2, Gtk::PACK_EXPAND_WIDGET); |
|
117 |
|
118 cbNodeCoordOneMap.signal_changed().connect( |
|
119 sigc::mem_fun(*this, &FileImportDialog::onNodeCoordOneMapChanged)); |
|
120 cbNodeCoordTwoMaps1.signal_changed().connect( |
|
121 sigc::mem_fun(*this, &FileImportDialog::onNodeCoordTwoMaps1Changed)); |
|
122 cbNodeCoordTwoMaps2.signal_changed().connect( |
|
123 sigc::mem_fun(*this, &FileImportDialog::onNodeCoordTwoMaps2Changed)); |
|
124 } |
|
125 |
|
126 { |
|
127 Gtk::Label* label1 = |
|
128 Gtk::manage(new Gtk::Label("<b>Arrow Coordinates</b>")); |
|
129 label1->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); |
|
130 label1->set_use_markup(); |
|
131 box1->pack_start(*label1); |
|
132 |
|
133 Gtk::HBox* box2 = Gtk::manage(new Gtk::HBox); |
|
134 box1->pack_start(*box2); |
|
135 |
|
136 Gtk::Label* fill1 = Gtk::manage(new Gtk::Label(" ")); |
|
137 box2->pack_start(*fill1, Gtk::PACK_SHRINK); |
|
138 |
|
139 Gtk::VBox* box3 = Gtk::manage(new Gtk::VBox); |
|
140 box2->pack_start(*box3); |
|
141 |
|
142 Gtk::VBox* box13 = Gtk::manage(new Gtk::VBox); |
|
143 box3->pack_start(*box13); |
|
144 |
|
145 rbArrowCoordNone.set_label("None"); |
|
146 Gtk::RadioButtonGroup group = rbArrowCoordNone.get_group(); |
|
147 box13->pack_start(rbArrowCoordNone); |
|
148 |
|
149 Gtk::VBox* box4 = Gtk::manage(new Gtk::VBox); |
|
150 box3->pack_start(*box4); |
|
151 |
|
152 rbArrowCoordOneMap.set_label("One Map"); |
|
153 rbArrowCoordOneMap.set_group(group); |
|
154 box4->pack_start(rbArrowCoordOneMap); |
|
155 |
|
156 Gtk::HBox* box5 = Gtk::manage(new Gtk::HBox); |
|
157 box4->pack_start(*box5); |
|
158 |
|
159 Gtk::Label* fill2 = Gtk::manage(new Gtk::Label(" ")); |
|
160 box5->pack_start(*fill2, Gtk::PACK_SHRINK); |
|
161 |
|
162 Gtk::VBox* box6 = Gtk::manage(new Gtk::VBox); |
|
163 box5->pack_start(*box6); |
|
164 |
|
165 Gtk::HBox* box7 = Gtk::manage(new Gtk::HBox); |
|
166 box6->pack_start(*box7); |
|
167 |
|
168 Gtk::Label* label2 = Gtk::manage(new Gtk::Label("(X, Y)")); |
|
169 box7->pack_start(*label2, Gtk::PACK_SHRINK, 4); |
|
170 |
|
171 box7->pack_start(cbArrowCoordOneMap, Gtk::PACK_EXPAND_WIDGET); |
|
172 |
|
173 |
|
174 Gtk::VBox* box8 = Gtk::manage(new Gtk::VBox); |
|
175 box3->pack_start(*box8); |
|
176 |
|
177 rbArrowCoordTwoMaps.set_label("Two Maps"); |
|
178 rbArrowCoordTwoMaps.set_group(group); |
|
179 box8->pack_start(rbArrowCoordTwoMaps); |
|
180 |
|
181 Gtk::HBox* box9 = Gtk::manage(new Gtk::HBox); |
|
182 box8->pack_start(*box9); |
|
183 |
|
184 Gtk::Label* fill3 = Gtk::manage(new Gtk::Label(" ")); |
|
185 box9->pack_start(*fill3, Gtk::PACK_SHRINK); |
|
186 |
|
187 Gtk::VBox* box10 = Gtk::manage(new Gtk::VBox); |
|
188 box9->pack_start(*box10); |
|
189 |
|
190 Gtk::HBox* box11 = Gtk::manage(new Gtk::HBox); |
|
191 box10->pack_start(*box11); |
|
192 |
|
193 Gtk::Label* label3 = Gtk::manage(new Gtk::Label("X")); |
|
194 box11->pack_start(*label3, Gtk::PACK_SHRINK, 4); |
|
195 |
|
196 box11->pack_start(cbArrowCoordTwoMaps1, Gtk::PACK_EXPAND_WIDGET); |
|
197 |
|
198 Gtk::HBox* box12 = Gtk::manage(new Gtk::HBox); |
|
199 box10->pack_start(*box12); |
|
200 |
|
201 Gtk::Label* label4 = Gtk::manage(new Gtk::Label("Y")); |
|
202 box12->pack_start(*label4, Gtk::PACK_SHRINK, 4); |
|
203 |
|
204 box12->pack_start(cbArrowCoordTwoMaps2, Gtk::PACK_EXPAND_WIDGET); |
|
205 |
|
206 cbArrowCoordOneMap.signal_changed().connect( |
|
207 sigc::mem_fun(*this, &FileImportDialog::onArrowCoordOneMapChanged)); |
|
208 cbArrowCoordTwoMaps1.signal_changed().connect( |
|
209 sigc::mem_fun(*this, &FileImportDialog::onArrowCoordTwoMaps1Changed)); |
|
210 cbArrowCoordTwoMaps2.signal_changed().connect( |
|
211 sigc::mem_fun(*this, &FileImportDialog::onArrowCoordTwoMaps2Changed)); |
|
212 } |
|
213 } |
|
214 |
|
215 // child widgets of vbNodeMaps |
|
216 { |
|
217 Gtk::VBox* box1 = Gtk::manage(new Gtk::VBox(false, 6)); |
|
218 vbNodeMaps->pack_start(*box1, Gtk::PACK_SHRINK); |
|
219 |
|
220 Gtk::Label* label1 = |
|
221 Gtk::manage(new Gtk::Label("<b>Element type</b>")); |
|
222 label1->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); |
|
223 label1->set_use_markup(); |
|
224 box1->pack_start(*label1, Gtk::PACK_SHRINK); |
|
225 |
|
226 Gtk::HBox* box2 = Gtk::manage(new Gtk::HBox); |
|
227 box1->pack_start(*box2, Gtk::PACK_SHRINK); |
|
228 |
|
229 Gtk::Label* fill1 = Gtk::manage(new Gtk::Label(" ")); |
|
230 box2->pack_start(*fill1, Gtk::PACK_SHRINK); |
|
231 |
|
232 Gtk::Frame* frame = Gtk::manage(new Gtk::Frame); |
|
233 box2->pack_start(*frame, Gtk::PACK_EXPAND_WIDGET); |
|
234 |
|
235 Gtk::ScrolledWindow* swNodeMaps = Gtk::manage(new Gtk::ScrolledWindow); |
|
236 frame->add(*swNodeMaps); |
|
237 |
|
238 swNodeMaps->add(twNodeMaps); |
|
239 |
|
240 refNodeMapStore = Gtk::ListStore::create(NodeMapColumns); |
|
241 |
|
242 for (std::vector<std::string>::const_iterator it = |
|
243 p_data->node_map_names.begin(); it != p_data->node_map_names.end(); |
|
244 ++it) |
|
245 { |
|
246 node_tree_view_records.push_back( |
|
247 tree_view_record(*it, false, false, true)); |
|
248 } |
|
249 |
|
250 twNodeMaps.set_model(refNodeMapStore); |
|
251 twNodeMaps.append_column("Name", NodeMapColumns.colName); |
|
252 { |
|
253 int col = twNodeMaps.append_column_editable("Numeric", |
|
254 NodeMapColumns.colReadAsNumeric); |
|
255 Gtk::CellRendererToggle* pRenderer = |
|
256 static_cast<Gtk::CellRendererToggle*>( |
|
257 twNodeMaps.get_column_cell_renderer(col-1)); |
|
258 pRenderer->signal_toggled().connect( |
|
259 sigc::mem_fun(*this, &FileImportDialog::onNodeMapNumericToggled)); |
|
260 } |
|
261 { |
|
262 int col = twNodeMaps.append_column_editable("String", |
|
263 NodeMapColumns.colReadAsString); |
|
264 Gtk::CellRendererToggle* pRenderer = |
|
265 static_cast<Gtk::CellRendererToggle*>( |
|
266 twNodeMaps.get_column_cell_renderer(col-1)); |
|
267 pRenderer->signal_toggled().connect( |
|
268 sigc::mem_fun(*this, &FileImportDialog::onNodeMapStringToggled)); |
|
269 } |
|
270 |
|
271 swNodeMaps->set_size_request(-1, 200); |
|
272 swNodeMaps->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
|
273 } |
|
274 |
|
275 // child widgets of vbEdgeMaps |
|
276 { |
|
277 Gtk::VBox* box1 = Gtk::manage(new Gtk::VBox(false, 6)); |
|
278 vbEdgeMaps->pack_start(*box1, Gtk::PACK_SHRINK); |
|
279 |
|
280 Gtk::Label* label1 = |
|
281 Gtk::manage(new Gtk::Label("<b>Element type</b>")); |
|
282 label1->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); |
|
283 label1->set_use_markup(); |
|
284 box1->pack_start(*label1, Gtk::PACK_SHRINK); |
|
285 |
|
286 Gtk::HBox* box2 = Gtk::manage(new Gtk::HBox); |
|
287 box1->pack_start(*box2, Gtk::PACK_SHRINK); |
|
288 |
|
289 Gtk::Label* fill1 = Gtk::manage(new Gtk::Label(" ")); |
|
290 box2->pack_start(*fill1, Gtk::PACK_SHRINK); |
|
291 |
|
292 Gtk::Frame* frame = Gtk::manage(new Gtk::Frame); |
|
293 box2->pack_start(*frame, Gtk::PACK_EXPAND_WIDGET); |
|
294 |
|
295 Gtk::ScrolledWindow* swEdgeMaps = Gtk::manage(new Gtk::ScrolledWindow); |
|
296 frame->add(*swEdgeMaps); |
|
297 |
|
298 swEdgeMaps->add(twEdgeMaps); |
|
299 |
|
300 refEdgeMapStore = Gtk::ListStore::create(EdgeMapColumns); |
|
301 |
|
302 for (std::vector<std::string>::const_iterator it = |
|
303 p_data->edge_map_names.begin(); it != p_data->edge_map_names.end(); |
|
304 ++it) |
|
305 { |
|
306 edge_tree_view_records.push_back( |
|
307 tree_view_record(*it, false, false, true)); |
|
308 } |
|
309 |
|
310 twEdgeMaps.set_model(refEdgeMapStore); |
|
311 twEdgeMaps.append_column("Name", EdgeMapColumns.colName); |
|
312 { |
|
313 int col = twEdgeMaps.append_column_editable("Numeric", |
|
314 EdgeMapColumns.colReadAsNumeric); |
|
315 Gtk::CellRendererToggle* pRenderer = |
|
316 static_cast<Gtk::CellRendererToggle*>( |
|
317 twEdgeMaps.get_column_cell_renderer(col-1)); |
|
318 pRenderer->signal_toggled().connect( |
|
319 sigc::mem_fun(*this, &FileImportDialog::onEdgeMapNumericToggled)); |
|
320 } |
|
321 { |
|
322 int col = twEdgeMaps.append_column_editable("String", |
|
323 EdgeMapColumns.colReadAsString); |
|
324 Gtk::CellRendererToggle* pRenderer = |
|
325 static_cast<Gtk::CellRendererToggle*>( |
|
326 twEdgeMaps.get_column_cell_renderer(col-1)); |
|
327 pRenderer->signal_toggled().connect( |
|
328 sigc::mem_fun(*this, &FileImportDialog::onEdgeMapStringToggled)); |
|
329 } |
|
330 |
|
331 swEdgeMaps->set_size_request(-1, 200); |
|
332 swEdgeMaps->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); |
|
333 } |
|
334 |
|
335 // fill in the ComboBoxes |
|
336 typedef std::vector<std::string> StrVec; |
|
337 for (StrVec::const_iterator it = p_data->node_map_names.begin(); |
|
338 it != p_data->node_map_names.end(); ++it) |
|
339 { |
|
340 cbNodeCoordTwoMaps1.append_text(*it); |
|
341 cbNodeCoordTwoMaps2.append_text(*it); |
|
342 } |
|
343 for (StrVec::const_iterator it = p_data->edge_map_names.begin(); |
|
344 it != p_data->edge_map_names.end(); ++it) |
|
345 { |
|
346 cbArrowCoordTwoMaps1.append_text(*it); |
|
347 cbArrowCoordTwoMaps2.append_text(*it); |
|
348 } |
|
349 for (StrVec::const_iterator it = p_data->xy_node_map_names.begin(); |
|
350 it != p_data->xy_node_map_names.end(); ++it) |
|
351 { |
|
352 cbNodeCoordOneMap.append_text(*it); |
|
353 } |
|
354 for (StrVec::const_iterator it = p_data->xy_edge_map_names.begin(); |
|
355 it != p_data->xy_edge_map_names.end(); ++it) |
|
356 { |
|
357 cbArrowCoordOneMap.append_text(*it); |
|
358 } |
|
359 |
|
360 if (p_data->isXYNodeMap("coord")) |
|
361 { |
|
362 cbNodeCoordOneMap.set_active_text("coord"); |
|
363 } |
|
364 else if (p_data->isXYNodeMap("coords")) |
|
365 { |
|
366 cbNodeCoordOneMap.set_active_text("coords"); |
|
367 } |
|
368 else if (p_data->isNodeMap("coord_x") && |
|
369 p_data->isNodeMap("coord_y")) |
|
370 { |
|
371 cbNodeCoordTwoMaps1.set_active_text("coord_x"); |
|
372 cbNodeCoordTwoMaps2.set_active_text("coord_y"); |
|
373 } |
|
374 else if (p_data->isNodeMap("coords_x") && |
|
375 p_data->isNodeMap("coords_y")) |
|
376 { |
|
377 cbNodeCoordTwoMaps1.set_active_text("coords_x"); |
|
378 cbNodeCoordTwoMaps2.set_active_text("coords_y"); |
|
379 } |
|
380 else if (p_data->isNodeMap("x") && |
|
381 p_data->isNodeMap("y")) |
|
382 { |
|
383 cbNodeCoordTwoMaps1.set_active_text("x"); |
|
384 cbNodeCoordTwoMaps2.set_active_text("y"); |
|
385 } |
|
386 |
|
387 if (p_data->isXYEdgeMap("arrow")) |
|
388 { |
|
389 cbArrowCoordOneMap.set_active_text("arrow"); |
|
390 } |
|
391 else if (p_data->isXYEdgeMap("arrows")) |
|
392 { |
|
393 cbArrowCoordOneMap.set_active_text("arrows"); |
|
394 } |
|
395 else if (p_data->isXYEdgeMap("midpoint")) |
|
396 { |
|
397 cbArrowCoordOneMap.set_active_text("midpoint"); |
|
398 } |
|
399 else if (p_data->isXYEdgeMap("midpoints")) |
|
400 { |
|
401 cbArrowCoordOneMap.set_active_text("midpoints"); |
|
402 } |
|
403 else if (p_data->isXYEdgeMap("mid")) |
|
404 { |
|
405 cbArrowCoordOneMap.set_active_text("mid"); |
|
406 } |
|
407 else if (p_data->isXYEdgeMap("mids")) |
|
408 { |
|
409 cbArrowCoordOneMap.set_active_text("mids"); |
|
410 } |
|
411 else if (p_data->isEdgeMap("arrow_x") && |
|
412 p_data->isEdgeMap("arrow_y")) |
|
413 { |
|
414 cbArrowCoordTwoMaps1.set_active_text("arrow_x"); |
|
415 cbArrowCoordTwoMaps2.set_active_text("arrow_y"); |
|
416 } |
|
417 else if (p_data->isEdgeMap("arrows_x") && |
|
418 p_data->isEdgeMap("arrows_y")) |
|
419 { |
|
420 cbArrowCoordTwoMaps1.set_active_text("arrows_x"); |
|
421 cbArrowCoordTwoMaps2.set_active_text("arrows_y"); |
|
422 } |
|
423 else if (p_data->isEdgeMap("midpoint_x") && |
|
424 p_data->isEdgeMap("midpoint_y")) |
|
425 { |
|
426 cbArrowCoordTwoMaps1.set_active_text("midpoint_x"); |
|
427 cbArrowCoordTwoMaps2.set_active_text("midpoint_y"); |
|
428 } |
|
429 else if (p_data->isEdgeMap("midpoints_x") && |
|
430 p_data->isEdgeMap("midpoints_y")) |
|
431 { |
|
432 cbArrowCoordTwoMaps1.set_active_text("midpoints_x"); |
|
433 cbArrowCoordTwoMaps2.set_active_text("midpoints_y"); |
|
434 } |
|
435 else if (p_data->isEdgeMap("mid_x") && |
|
436 p_data->isEdgeMap("mid_y")) |
|
437 { |
|
438 cbArrowCoordTwoMaps1.set_active_text("mid_x"); |
|
439 cbArrowCoordTwoMaps2.set_active_text("mid_y"); |
|
440 } |
|
441 else if (p_data->isEdgeMap("mids_x") && |
|
442 p_data->isEdgeMap("mids_y")) |
|
443 { |
|
444 cbArrowCoordTwoMaps1.set_active_text("mids_x"); |
|
445 cbArrowCoordTwoMaps2.set_active_text("mids_y"); |
|
446 } |
|
447 |
|
448 { |
|
449 if (cbNodeCoordOneMap.get_active_text() != "") |
|
450 rbNodeCoordOneMap.set_active(); |
|
451 else if (cbNodeCoordTwoMaps1.get_active_text() != "") |
|
452 rbNodeCoordTwoMaps.set_active(); |
|
453 else |
|
454 rbNodeCoordNone.set_active(); |
|
455 |
|
456 if (cbArrowCoordOneMap.get_active_text() != "") |
|
457 rbArrowCoordOneMap.set_active(); |
|
458 else if (cbArrowCoordTwoMaps1.get_active_text() != "") |
|
459 rbArrowCoordTwoMaps.set_active(); |
|
460 else |
|
461 rbArrowCoordNone.set_active(); |
|
462 |
|
463 onNodeCoordMapNumToggled(); |
|
464 onArrowCoordMapNumToggled(); |
|
465 |
|
466 rbNodeCoordOneMap.signal_toggled().connect( |
|
467 sigc::mem_fun(*this, &FileImportDialog::onNodeCoordMapNumToggled)); |
|
468 rbNodeCoordTwoMaps.signal_toggled().connect( |
|
469 sigc::mem_fun(*this, &FileImportDialog::onNodeCoordMapNumToggled)); |
|
470 rbArrowCoordOneMap.signal_toggled().connect( |
|
471 sigc::mem_fun(*this, &FileImportDialog::onArrowCoordMapNumToggled)); |
|
472 rbArrowCoordTwoMaps.signal_toggled().connect( |
|
473 sigc::mem_fun(*this, &FileImportDialog::onArrowCoordMapNumToggled)); |
|
474 } |
|
475 |
|
476 signal_response().connect( |
|
477 sigc::mem_fun(*this, &FileImportDialog::onResponse)); |
|
478 |
|
479 update_node_tree_view(); |
|
480 update_edge_tree_view(); |
|
481 |
|
482 show_all_children(); |
|
483 } |
|
484 |
|
485 void FileImportDialog::onNodeCoordMapNumToggled() |
|
486 { |
|
487 if (rbNodeCoordOneMap.get_active()) |
|
488 { |
|
489 cbNodeCoordOneMap.get_parent()->set_sensitive(true); |
|
490 cbNodeCoordTwoMaps1.get_parent()->set_sensitive(false); |
|
491 cbNodeCoordTwoMaps2.get_parent()->set_sensitive(false); |
|
492 |
|
493 p_data->node_coord_load_from = ImportData::ONE_MAP; |
|
494 } |
|
495 else if (rbNodeCoordTwoMaps.get_active()) |
|
496 { |
|
497 cbNodeCoordOneMap.get_parent()->set_sensitive(false); |
|
498 cbNodeCoordTwoMaps1.get_parent()->set_sensitive(true); |
|
499 cbNodeCoordTwoMaps2.get_parent()->set_sensitive(true); |
|
500 |
|
501 p_data->node_coord_load_from = ImportData::TWO_MAPS; |
|
502 } |
|
503 else if (rbNodeCoordNone.get_active()) |
|
504 { |
|
505 cbNodeCoordOneMap.get_parent()->set_sensitive(false); |
|
506 cbNodeCoordTwoMaps1.get_parent()->set_sensitive(false); |
|
507 cbNodeCoordTwoMaps2.get_parent()->set_sensitive(false); |
|
508 |
|
509 p_data->node_coord_load_from = ImportData::DONT_READ; |
|
510 } |
|
511 update_node_tree_view(); |
|
512 } |
|
513 |
|
514 void FileImportDialog::onArrowCoordMapNumToggled() |
|
515 { |
|
516 if (rbArrowCoordOneMap.get_active()) |
|
517 { |
|
518 cbArrowCoordOneMap.get_parent()->set_sensitive(true); |
|
519 cbArrowCoordTwoMaps1.get_parent()->set_sensitive(false); |
|
520 cbArrowCoordTwoMaps2.get_parent()->set_sensitive(false); |
|
521 |
|
522 p_data->arrow_coord_load_from = ImportData::ONE_MAP; |
|
523 } |
|
524 else if (rbArrowCoordTwoMaps.get_active()) |
|
525 { |
|
526 cbArrowCoordOneMap.get_parent()->set_sensitive(false); |
|
527 cbArrowCoordTwoMaps1.get_parent()->set_sensitive(true); |
|
528 cbArrowCoordTwoMaps2.get_parent()->set_sensitive(true); |
|
529 |
|
530 p_data->arrow_coord_load_from = ImportData::TWO_MAPS; |
|
531 } |
|
532 else if (rbArrowCoordNone.get_active()) |
|
533 { |
|
534 cbArrowCoordOneMap.get_parent()->set_sensitive(false); |
|
535 cbArrowCoordTwoMaps1.get_parent()->set_sensitive(false); |
|
536 cbArrowCoordTwoMaps2.get_parent()->set_sensitive(false); |
|
537 |
|
538 p_data->arrow_coord_load_from = ImportData::DONT_READ; |
|
539 } |
|
540 update_edge_tree_view(); |
|
541 } |
|
542 |
|
543 FileImportDialog::~FileImportDialog() |
|
544 { |
|
545 } |
|
546 |
|
547 void FileImportDialog::onResponse(int id) |
|
548 { |
|
549 if (id == Gtk::RESPONSE_OK) |
|
550 { |
|
551 if ((rbNodeCoordOneMap.get_active() && |
|
552 cbNodeCoordOneMap.get_active_text() == "") || |
|
553 (rbNodeCoordTwoMaps.get_active() && |
|
554 (cbNodeCoordTwoMaps1.get_active_text() == "" || |
|
555 cbNodeCoordTwoMaps2.get_active_text() == ""))) |
|
556 { |
|
557 Gtk::MessageDialog mdialog("No node map selected.", |
|
558 false, Gtk::MESSAGE_ERROR); |
|
559 mdialog.run(); |
|
560 return; |
|
561 } |
|
562 else if (rbNodeCoordTwoMaps.get_active() && |
|
563 cbNodeCoordTwoMaps1.get_active_text() == |
|
564 cbNodeCoordTwoMaps2.get_active_text()) |
|
565 { |
|
566 Gtk::MessageDialog mdialog( |
|
567 "Same node map selected for both coordinates.", |
|
568 false, Gtk::MESSAGE_ERROR); |
|
569 mdialog.run(); |
|
570 return; |
|
571 } |
|
572 if ((rbArrowCoordOneMap.get_active() && |
|
573 cbArrowCoordOneMap.get_active_text() == "") || |
|
574 (rbArrowCoordTwoMaps.get_active() && |
|
575 (cbArrowCoordTwoMaps1.get_active_text() == "" || |
|
576 cbArrowCoordTwoMaps2.get_active_text() == ""))) |
|
577 { |
|
578 Gtk::MessageDialog mdialog("No edge map selected.", |
|
579 false, Gtk::MESSAGE_ERROR); |
|
580 mdialog.run(); |
|
581 return; |
|
582 } |
|
583 else if (rbArrowCoordTwoMaps.get_active() && |
|
584 cbArrowCoordTwoMaps1.get_active_text() == |
|
585 cbArrowCoordTwoMaps2.get_active_text()) |
|
586 { |
|
587 Gtk::MessageDialog mdialog( |
|
588 "Same edge map selected for both coordinates.", |
|
589 false, Gtk::MESSAGE_ERROR); |
|
590 mdialog.run(); |
|
591 return; |
|
592 } |
|
593 |
|
594 for (std::vector<tree_view_record>::const_iterator it = |
|
595 node_tree_view_records.begin(); it != node_tree_view_records.end(); |
|
596 ++it) |
|
597 { |
|
598 if (it->visible) |
|
599 { |
|
600 if (it->numeric) |
|
601 p_data->numeric_node_map_names.push_back(it->name); |
|
602 if (it->string) |
|
603 p_data->string_node_map_names.push_back(it->name); |
|
604 } |
|
605 } |
|
606 |
|
607 for (std::vector<tree_view_record>::const_iterator it = |
|
608 edge_tree_view_records.begin(); it != edge_tree_view_records.end(); |
|
609 ++it) |
|
610 { |
|
611 if (it->visible) |
|
612 { |
|
613 if (it->numeric) |
|
614 p_data->numeric_edge_map_names.push_back(it->name); |
|
615 if (it->string) |
|
616 p_data->string_edge_map_names.push_back(it->name); |
|
617 } |
|
618 } |
|
619 } |
|
620 } |
|
621 |
|
622 FileImportDialog::ImportData::ImportData( |
|
623 const std::vector<std::string>& _node_map_names, |
|
624 const std::vector<std::string>& _edge_map_names) : |
|
625 node_map_names(_node_map_names), |
|
626 edge_map_names(_edge_map_names) |
|
627 { |
|
628 typedef std::vector<std::string> StrVec; |
|
629 { |
|
630 StrVec xMaps; |
|
631 StrVec yMaps; |
|
632 // collect map names ending with ":x" and ":y" |
|
633 for (StrVec::const_iterator it = node_map_names.begin(); |
|
634 it != node_map_names.end(); ++it) |
|
635 { |
|
636 if ((it->length() >= 3) && |
|
637 (it->substr(it->length()-2, it->length()) == ":x")) |
|
638 { |
|
639 xMaps.push_back(it->substr(0, it->length()-2)); |
|
640 } |
|
641 if ((it->length() >= 3) && |
|
642 (it->substr(it->length()-2, it->length()) == ":y")) |
|
643 { |
|
644 yMaps.push_back(it->substr(0, it->length()-2)); |
|
645 } |
|
646 } |
|
647 |
|
648 for (StrVec::const_iterator it1 = xMaps.begin(); |
|
649 it1 != xMaps.end(); ++it1) |
|
650 { |
|
651 for (StrVec::const_iterator it2 = yMaps.begin(); |
|
652 it2 != yMaps.end(); ++it2) |
|
653 { |
|
654 if (*it1 == *it2) xy_node_map_names.push_back(*it1); |
|
655 } |
|
656 } |
|
657 } |
|
658 { |
|
659 StrVec xMaps; |
|
660 StrVec yMaps; |
|
661 // collect map names ending with ":x" and ":y" |
|
662 for (StrVec::const_iterator it = edge_map_names.begin(); |
|
663 it != edge_map_names.end(); ++it) |
|
664 { |
|
665 if ((it->length() >= 3) && |
|
666 (it->substr(it->length()-2, it->length()) == ":x")) |
|
667 { |
|
668 xMaps.push_back(it->substr(0, it->length()-2)); |
|
669 } |
|
670 if ((it->length() >= 3) && |
|
671 (it->substr(it->length()-2, it->length()) == ":y")) |
|
672 { |
|
673 yMaps.push_back(it->substr(0, it->length()-2)); |
|
674 } |
|
675 } |
|
676 |
|
677 for (StrVec::const_iterator it1 = xMaps.begin(); |
|
678 it1 != xMaps.end(); ++it1) |
|
679 { |
|
680 for (StrVec::const_iterator it2 = yMaps.begin(); |
|
681 it2 != yMaps.end(); ++it2) |
|
682 { |
|
683 if (*it1 == *it2) xy_edge_map_names.push_back(*it1); |
|
684 } |
|
685 } |
|
686 } |
|
687 } |
|
688 |
|
689 FileImportDialog::ImportData::~ImportData() |
|
690 { |
|
691 } |
|
692 |
|
693 bool FileImportDialog::ImportData::isXYNodeMap(const std::string& name) |
|
694 { |
|
695 if (isNodeMap(name + ":x") && isNodeMap(name + ":y")) return true; |
|
696 return false; |
|
697 } |
|
698 |
|
699 bool FileImportDialog::ImportData::isXYEdgeMap(const std::string& name) |
|
700 { |
|
701 if (isEdgeMap(name + ":x") && isEdgeMap(name + ":y")) return true; |
|
702 return false; |
|
703 } |
|
704 |
|
705 bool FileImportDialog::ImportData::isNodeMap(const std::string& name) |
|
706 { |
|
707 if (contains(node_map_names, name)) return true; |
|
708 return false; |
|
709 } |
|
710 |
|
711 bool FileImportDialog::ImportData::isEdgeMap(const std::string& name) |
|
712 { |
|
713 if (contains(edge_map_names, name)) return true; |
|
714 return false; |
|
715 } |
|
716 |
|
717 bool FileImportDialog::ImportData::contains(const std::vector<std::string>& vec, |
|
718 const std::string& str) |
|
719 { |
|
720 for (std::vector<std::string>::const_iterator it = vec.begin(); |
|
721 it != vec.end(); ++it) |
|
722 { |
|
723 if (*it == str) return true; |
|
724 } |
|
725 return false; |
|
726 } |
|
727 |
|
728 void FileImportDialog::onNodeCoordOneMapChanged() |
|
729 { |
|
730 p_data->node_coord_one_map_name = cbNodeCoordOneMap.get_active_text(); |
|
731 update_node_tree_view(); |
|
732 } |
|
733 |
|
734 void FileImportDialog::onNodeCoordTwoMaps1Changed() |
|
735 { |
|
736 p_data->node_coord_two_maps_1_name = cbNodeCoordTwoMaps1.get_active_text(); |
|
737 update_node_tree_view(); |
|
738 } |
|
739 |
|
740 void FileImportDialog::onNodeCoordTwoMaps2Changed() |
|
741 { |
|
742 p_data->node_coord_two_maps_2_name = cbNodeCoordTwoMaps2.get_active_text(); |
|
743 update_node_tree_view(); |
|
744 } |
|
745 |
|
746 void FileImportDialog::onArrowCoordOneMapChanged() |
|
747 { |
|
748 p_data->arrow_coord_one_map_name = cbArrowCoordOneMap.get_active_text(); |
|
749 update_edge_tree_view(); |
|
750 } |
|
751 |
|
752 void FileImportDialog::onArrowCoordTwoMaps1Changed() |
|
753 { |
|
754 p_data->arrow_coord_two_maps_1_name = cbArrowCoordTwoMaps1.get_active_text(); |
|
755 update_edge_tree_view(); |
|
756 } |
|
757 |
|
758 void FileImportDialog::onArrowCoordTwoMaps2Changed() |
|
759 { |
|
760 p_data->arrow_coord_two_maps_2_name = cbArrowCoordTwoMaps2.get_active_text(); |
|
761 update_edge_tree_view(); |
|
762 } |
|
763 |
|
764 void FileImportDialog::onNodeMapNumericToggled(const Glib::ustring& path) |
|
765 { |
|
766 Gtk::TreeModel::iterator iter = refNodeMapStore->get_iter( |
|
767 Gtk::TreeModel::Path(path)); |
|
768 Gtk::TreeModel::Row row = *iter; |
|
769 std::vector<tree_view_record>::iterator it; |
|
770 for (it = node_tree_view_records.begin(); |
|
771 it != node_tree_view_records.end(); ++it) |
|
772 { |
|
773 if (it->name == row[NodeMapColumns.colName]) break; |
|
774 } |
|
775 if (row[NodeMapColumns.colReadAsNumeric]) |
|
776 { |
|
777 row[NodeMapColumns.colReadAsString] = false; |
|
778 it->string = false; |
|
779 it->numeric = true; |
|
780 } |
|
781 } |
|
782 |
|
783 void FileImportDialog::onNodeMapStringToggled(const Glib::ustring& path) |
|
784 { |
|
785 Gtk::TreeModel::iterator iter = refNodeMapStore->get_iter( |
|
786 Gtk::TreeModel::Path(path)); |
|
787 Gtk::TreeModel::Row row = *iter; |
|
788 std::vector<tree_view_record>::iterator it; |
|
789 for (it = node_tree_view_records.begin(); |
|
790 it != node_tree_view_records.end(); ++it) |
|
791 { |
|
792 if (it->name == row[NodeMapColumns.colName]) break; |
|
793 } |
|
794 if (row[NodeMapColumns.colReadAsString]) |
|
795 { |
|
796 row[NodeMapColumns.colReadAsNumeric] = false; |
|
797 it->string = true; |
|
798 it->numeric = false; |
|
799 } |
|
800 } |
|
801 |
|
802 void FileImportDialog::update_node_tree_view() |
|
803 { |
|
804 for (std::vector<tree_view_record>::iterator it = |
|
805 node_tree_view_records.begin(); it != node_tree_view_records.end(); ++it) |
|
806 { |
|
807 it->visible = true; |
|
808 } |
|
809 switch (p_data->node_coord_load_from) |
|
810 { |
|
811 case ImportData::ONE_MAP: |
|
812 for (std::vector<tree_view_record>::iterator it = |
|
813 node_tree_view_records.begin(); it != |
|
814 node_tree_view_records.end(); ++it) |
|
815 { |
|
816 if (it->name == p_data->node_coord_one_map_name) |
|
817 it->visible = false; |
|
818 } |
|
819 break; |
|
820 case ImportData::TWO_MAPS: |
|
821 for (std::vector<tree_view_record>::iterator it = |
|
822 node_tree_view_records.begin(); it != |
|
823 node_tree_view_records.end(); ++it) |
|
824 { |
|
825 if ((it->name == p_data->node_coord_two_maps_1_name) || |
|
826 (it->name == p_data->node_coord_two_maps_2_name)) |
|
827 it->visible = false; |
|
828 } |
|
829 break; |
|
830 case ImportData::DONT_READ: |
|
831 break; |
|
832 } |
|
833 refNodeMapStore->clear(); |
|
834 for (std::vector<tree_view_record>::iterator it = |
|
835 node_tree_view_records.begin(); it != node_tree_view_records.end(); ++it) |
|
836 { |
|
837 if (it->visible) |
|
838 { |
|
839 Gtk::TreeModel::Row row = *(refNodeMapStore->append()); |
|
840 row[NodeMapColumns.colName] = it->name; |
|
841 row[NodeMapColumns.colReadAsNumeric] = it->numeric; |
|
842 row[NodeMapColumns.colReadAsString] = it->string; |
|
843 } |
|
844 } |
|
845 } |
|
846 |
|
847 void FileImportDialog::onEdgeMapNumericToggled(const Glib::ustring& path) |
|
848 { |
|
849 Gtk::TreeModel::iterator iter = refEdgeMapStore->get_iter( |
|
850 Gtk::TreeModel::Path(path)); |
|
851 Gtk::TreeModel::Row row = *iter; |
|
852 std::vector<tree_view_record>::iterator it; |
|
853 for (it = edge_tree_view_records.begin(); |
|
854 it != edge_tree_view_records.end(); ++it) |
|
855 { |
|
856 if (it->name == row[EdgeMapColumns.colName]) break; |
|
857 } |
|
858 if (row[EdgeMapColumns.colReadAsNumeric]) |
|
859 { |
|
860 row[EdgeMapColumns.colReadAsString] = false; |
|
861 it->string = false; |
|
862 it->numeric = true; |
|
863 } |
|
864 } |
|
865 |
|
866 void FileImportDialog::onEdgeMapStringToggled(const Glib::ustring& path) |
|
867 { |
|
868 Gtk::TreeModel::iterator iter = refEdgeMapStore->get_iter( |
|
869 Gtk::TreeModel::Path(path)); |
|
870 Gtk::TreeModel::Row row = *iter; |
|
871 std::vector<tree_view_record>::iterator it; |
|
872 for (it = edge_tree_view_records.begin(); |
|
873 it != edge_tree_view_records.end(); ++it) |
|
874 { |
|
875 if (it->name == row[EdgeMapColumns.colName]) break; |
|
876 } |
|
877 if (row[EdgeMapColumns.colReadAsString]) |
|
878 { |
|
879 row[EdgeMapColumns.colReadAsNumeric] = false; |
|
880 it->string = true; |
|
881 it->numeric = false; |
|
882 } |
|
883 } |
|
884 |
|
885 void FileImportDialog::update_edge_tree_view() |
|
886 { |
|
887 for (std::vector<tree_view_record>::iterator it = |
|
888 edge_tree_view_records.begin(); it != edge_tree_view_records.end(); ++it) |
|
889 { |
|
890 it->visible = true; |
|
891 } |
|
892 switch (p_data->arrow_coord_load_from) |
|
893 { |
|
894 case ImportData::ONE_MAP: |
|
895 for (std::vector<tree_view_record>::iterator it = |
|
896 edge_tree_view_records.begin(); it != |
|
897 edge_tree_view_records.end(); ++it) |
|
898 { |
|
899 if (it->name == p_data->arrow_coord_one_map_name) |
|
900 it->visible = false; |
|
901 } |
|
902 break; |
|
903 case ImportData::TWO_MAPS: |
|
904 for (std::vector<tree_view_record>::iterator it = |
|
905 edge_tree_view_records.begin(); it != |
|
906 edge_tree_view_records.end(); ++it) |
|
907 { |
|
908 if ((it->name == p_data->arrow_coord_two_maps_1_name) || |
|
909 (it->name == p_data->arrow_coord_two_maps_2_name)) |
|
910 it->visible = false; |
|
911 } |
|
912 break; |
|
913 case ImportData::DONT_READ: |
|
914 break; |
|
915 } |
|
916 refEdgeMapStore->clear(); |
|
917 for (std::vector<tree_view_record>::iterator it = |
|
918 edge_tree_view_records.begin(); it != edge_tree_view_records.end(); ++it) |
|
919 { |
|
920 if (it->visible) |
|
921 { |
|
922 Gtk::TreeModel::Row row = *(refEdgeMapStore->append()); |
|
923 row[EdgeMapColumns.colName] = it->name; |
|
924 row[EdgeMapColumns.colReadAsNumeric] = it->numeric; |
|
925 row[EdgeMapColumns.colReadAsString] = it->string; |
|
926 } |
|
927 } |
|
928 } |