1 | /* -*- C++ -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2006 |
---|
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
8 | * |
---|
9 | * Permission to use, modify and distribute this software is granted |
---|
10 | * provided that this copyright notice appears in all copies. For |
---|
11 | * precise terms see the accompanying LICENSE file. |
---|
12 | * |
---|
13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
14 | * express or implied, and with no claim as to its suitability for any |
---|
15 | * purpose. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | #include <map_win.h> |
---|
20 | #include <nbtab.h> |
---|
21 | #include <mapselector.h> |
---|
22 | #include <set> |
---|
23 | |
---|
24 | bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e) |
---|
25 | { |
---|
26 | if(e->keyval==GDK_Escape) |
---|
27 | { |
---|
28 | mytab.closeMapWin(); |
---|
29 | // hide(); |
---|
30 | } |
---|
31 | return true; |
---|
32 | } |
---|
33 | |
---|
34 | MapWin::MapWin(const std::string& title, |
---|
35 | std::vector<std::string> n_eml, |
---|
36 | std::vector<std::string> s_eml, |
---|
37 | std::vector<std::string> n_nml, |
---|
38 | std::vector<std::string> s_nml, |
---|
39 | NoteBookTab & mw):mytab(mw) |
---|
40 | { |
---|
41 | set_title(title); |
---|
42 | set_default_size(200, 50); |
---|
43 | |
---|
44 | set_resizable(false); |
---|
45 | |
---|
46 | signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed)); |
---|
47 | |
---|
48 | mytab.signal_title_ch().connect(sigc::mem_fun(*this, &MapWin::set_title)); |
---|
49 | |
---|
50 | e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM]; |
---|
51 | |
---|
52 | table=new Gtk::Table(EDGE_PROPERTY_NUM, 1, false); |
---|
53 | |
---|
54 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
55 | { |
---|
56 | switch (i) |
---|
57 | { |
---|
58 | case E_WIDTH: |
---|
59 | e_combo_array[i]=new MapSelector(n_eml, s_eml, |
---|
60 | mytab.getActiveArcMap(i), arc_property_strings[i], |
---|
61 | true, true, NUM); |
---|
62 | break; |
---|
63 | case E_COLOR: |
---|
64 | e_combo_array[i]=new MapSelector(n_eml, s_eml, |
---|
65 | mytab.getActiveArcMap(i), arc_property_strings[i], |
---|
66 | true, true, NUM); |
---|
67 | break; |
---|
68 | case E_TEXT: |
---|
69 | e_combo_array[i]=new MapSelector(n_eml, s_eml, |
---|
70 | mytab.getActiveArcMap(i), arc_property_strings[i], |
---|
71 | true, true, ALL); |
---|
72 | break; |
---|
73 | } |
---|
74 | |
---|
75 | (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
---|
76 | |
---|
77 | e_combo_array[i]->signal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::arcMapChanged), i)); |
---|
78 | e_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded)); |
---|
79 | } |
---|
80 | |
---|
81 | vbox.pack_start(*(new Gtk::Label("Arc properties"))); |
---|
82 | |
---|
83 | vbox.pack_start(*table); |
---|
84 | |
---|
85 | vbox.pack_start(*(new Gtk::HSeparator)); |
---|
86 | |
---|
87 | n_combo_array=new MapSelector * [NODE_PROPERTY_NUM]; |
---|
88 | |
---|
89 | table=new Gtk::Table(NODE_PROPERTY_NUM, 1, false); |
---|
90 | |
---|
91 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
92 | { |
---|
93 | switch (i) |
---|
94 | { |
---|
95 | case N_RADIUS: |
---|
96 | n_combo_array[i]=new MapSelector(n_nml, s_nml, |
---|
97 | mytab.getActiveNodeMap(i), node_property_strings[i], |
---|
98 | false, true, NUM); |
---|
99 | break; |
---|
100 | case N_COLOR: |
---|
101 | n_combo_array[i]=new MapSelector(n_nml, s_nml, |
---|
102 | mytab.getActiveNodeMap(i), node_property_strings[i], |
---|
103 | false, true, NUM); |
---|
104 | break; |
---|
105 | case N_TEXT: |
---|
106 | n_combo_array[i]=new MapSelector(n_nml, s_nml, |
---|
107 | mytab.getActiveNodeMap(i), node_property_strings[i], |
---|
108 | false, true, ALL); |
---|
109 | break; |
---|
110 | } |
---|
111 | |
---|
112 | (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
---|
113 | |
---|
114 | n_combo_array[i]->signal_cbt_ch().connect(sigc::bind(sigc::mem_fun(*this, &MapWin::nodeMapChanged), i)); |
---|
115 | n_combo_array[i]->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MapWin::newMapWinNeeded)); |
---|
116 | } |
---|
117 | |
---|
118 | add(vbox); |
---|
119 | |
---|
120 | vbox.pack_start(*(new Gtk::Label("Node properties"))); |
---|
121 | |
---|
122 | vbox.pack_start(*table); |
---|
123 | |
---|
124 | update(n_eml, s_eml, n_nml, s_nml); |
---|
125 | |
---|
126 | show_all_children(); |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | void MapWin::nodeMapChanged(std::string mapname, int prop) |
---|
131 | { |
---|
132 | mytab.propertyChange(false, prop, mapname); |
---|
133 | } |
---|
134 | |
---|
135 | void MapWin::arcMapChanged(std::string mapname, int prop) |
---|
136 | { |
---|
137 | mytab.propertyChange(true, prop, mapname); |
---|
138 | } |
---|
139 | |
---|
140 | void MapWin::newMapWinNeeded(bool itisarc) |
---|
141 | { |
---|
142 | mytab.popupNewMapWin(itisarc); |
---|
143 | } |
---|
144 | |
---|
145 | void MapWin::update( |
---|
146 | std::vector<std::string> n_eml, |
---|
147 | std::vector<std::string> s_eml, |
---|
148 | std::vector<std::string> n_nml, |
---|
149 | std::vector<std::string> s_nml) |
---|
150 | { |
---|
151 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
152 | { |
---|
153 | e_combo_array[i]->update_list(n_eml, s_eml); |
---|
154 | } |
---|
155 | |
---|
156 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
157 | { |
---|
158 | n_combo_array[i]->update_list(n_nml, s_nml); |
---|
159 | } |
---|
160 | |
---|
161 | mytab.active_maps_needed(); |
---|
162 | } |
---|
163 | |
---|
164 | void MapWin::registerNewArcMap(std::string newmapname, MapValue::Type type) |
---|
165 | { |
---|
166 | for(int i=0;i<EDGE_PROPERTY_NUM;i++) |
---|
167 | { |
---|
168 | //filling in combo box with choices |
---|
169 | e_combo_array[i]->append_text((Glib::ustring)newmapname, type); |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | void MapWin::registerNewNodeMap(std::string newmapname, MapValue::Type type) |
---|
174 | { |
---|
175 | for(int i=0;i<NODE_PROPERTY_NUM;i++) |
---|
176 | { |
---|
177 | //filling in combo box with choices |
---|
178 | n_combo_array[i]->append_text((Glib::ustring)newmapname, type); |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | bool MapWin::on_delete_event(GdkEventAny * event) |
---|
183 | { |
---|
184 | event=event; |
---|
185 | mytab.closeMapWin(); |
---|
186 | return true; |
---|
187 | } |
---|
188 | |
---|
189 | void MapWin::changeEntry(bool isitarc, int prop, std::string mapname) |
---|
190 | { |
---|
191 | if(isitarc) |
---|
192 | { |
---|
193 | e_combo_array[prop]->set_active_text(mapname); |
---|
194 | } |
---|
195 | else |
---|
196 | { |
---|
197 | n_combo_array[prop]->set_active_text(mapname); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | void MapWin::set_title(std::string tabname) |
---|
202 | { |
---|
203 | Gtk::Window::set_title("Map Setup - "+tabname); |
---|
204 | } |
---|