[174] | 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 | |
---|
[194] | 19 | #include <graph_displayer_canvas.h> |
---|
| 20 | #include <mapstorage.h> |
---|
| 21 | #include <nbtab.h> |
---|
[59] | 22 | #include <cmath> |
---|
[28] | 23 | |
---|
[157] | 24 | const int minimum_node_radius=5; |
---|
[28] | 25 | |
---|
[62] | 26 | int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node) |
---|
[28] | 27 | { |
---|
[31] | 28 | Graph::NodeMap<double> * actual_map; |
---|
[48] | 29 | double min, max; |
---|
[194] | 30 | min=(mytab.mapstorage)->minOfNodeMap(mapname); |
---|
| 31 | max=(mytab.mapstorage)->maxOfNodeMap(mapname); |
---|
| 32 | actual_map=((mytab.mapstorage)->nodemap_storage)[mapname]; |
---|
[81] | 33 | |
---|
| 34 | if(node==INVALID) |
---|
[31] | 35 | { |
---|
[194] | 36 | for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[81] | 37 | { |
---|
| 38 | double v=fabs((*actual_map)[i]); |
---|
| 39 | int w; |
---|
[154] | 40 | if(autoscale) |
---|
[81] | 41 | { |
---|
[154] | 42 | if(min==max) |
---|
| 43 | { |
---|
| 44 | w=(int)(node_property_defaults[N_RADIUS]); |
---|
| 45 | } |
---|
| 46 | else |
---|
| 47 | { |
---|
[157] | 48 | w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius)); |
---|
[154] | 49 | } |
---|
[81] | 50 | } |
---|
| 51 | else |
---|
| 52 | { |
---|
[157] | 53 | w=(int)(v*radius_size); |
---|
[81] | 54 | } |
---|
[155] | 55 | |
---|
[157] | 56 | if(w<minimum_node_radius) |
---|
[155] | 57 | { |
---|
[157] | 58 | w=minimum_node_radius; |
---|
[155] | 59 | } |
---|
| 60 | |
---|
[156] | 61 | if(zoomtrack) |
---|
| 62 | { |
---|
| 63 | double actual_ppu=get_pixels_per_unit(); |
---|
| 64 | w=(int)(w/actual_ppu*fixed_zoom_factor); |
---|
| 65 | } |
---|
| 66 | |
---|
[81] | 67 | if(w>=0) |
---|
| 68 | { |
---|
| 69 | double x1, y1, x2, y2; |
---|
| 70 | x1=nodesmap[i]->property_x1().get_value(); |
---|
| 71 | x2=nodesmap[i]->property_x2().get_value(); |
---|
| 72 | y1=nodesmap[i]->property_y1().get_value(); |
---|
| 73 | y2=nodesmap[i]->property_y2().get_value(); |
---|
| 74 | nodesmap[i]->property_x1().set_value((x1+x2)/2-w); |
---|
| 75 | nodesmap[i]->property_x2().set_value((x1+x2)/2+w); |
---|
| 76 | nodesmap[i]->property_y1().set_value((y1+y2)/2-w); |
---|
| 77 | nodesmap[i]->property_y2().set_value((y1+y2)/2+w); |
---|
| 78 | } |
---|
| 79 | } |
---|
[31] | 80 | } |
---|
| 81 | else |
---|
| 82 | { |
---|
[81] | 83 | //I think only new nodes use this case |
---|
[154] | 84 | //that has no own value, only the default one |
---|
| 85 | //int w=(int)(*actual_map)[node]; |
---|
[81] | 86 | int w=(int)(node_property_defaults[N_RADIUS]); |
---|
| 87 | if(w>=0) |
---|
| 88 | { |
---|
| 89 | double x1, y1, x2, y2; |
---|
| 90 | x1=nodesmap[node]->property_x1().get_value(); |
---|
| 91 | x2=nodesmap[node]->property_x2().get_value(); |
---|
| 92 | y1=nodesmap[node]->property_y1().get_value(); |
---|
| 93 | y2=nodesmap[node]->property_y2().get_value(); |
---|
| 94 | nodesmap[node]->property_x1().set_value((x1+x2)/2-w); |
---|
| 95 | nodesmap[node]->property_x2().set_value((x1+x2)/2+w); |
---|
| 96 | nodesmap[node]->property_y1().set_value((y1+y2)/2-w); |
---|
| 97 | nodesmap[node]->property_y2().set_value((y1+y2)/2+w); |
---|
| 98 | } |
---|
[31] | 99 | } |
---|
[81] | 100 | return 0; |
---|
| 101 | }; |
---|
[31] | 102 | |
---|
[81] | 103 | int GraphDisplayerCanvas::resetNodeRadius (Node node) |
---|
| 104 | { |
---|
| 105 | double min, max; |
---|
| 106 | min=node_property_defaults[N_RADIUS]; |
---|
| 107 | max=node_property_defaults[N_RADIUS]; |
---|
[194] | 108 | Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_RADIUS]); |
---|
[81] | 109 | |
---|
[28] | 110 | if(node==INVALID) |
---|
| 111 | { |
---|
[194] | 112 | for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[28] | 113 | { |
---|
[91] | 114 | double v=fabs(actual_map[i]); |
---|
[48] | 115 | int w; |
---|
| 116 | if(min==max) |
---|
| 117 | { |
---|
| 118 | w=(int)(node_property_defaults[N_RADIUS]); |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | { |
---|
| 122 | w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); |
---|
| 123 | } |
---|
[156] | 124 | if(zoomtrack) |
---|
| 125 | { |
---|
| 126 | double actual_ppu=get_pixels_per_unit(); |
---|
| 127 | w=(int)(w/actual_ppu*fixed_zoom_factor); |
---|
| 128 | } |
---|
[28] | 129 | if(w>=0) |
---|
| 130 | { |
---|
| 131 | double x1, y1, x2, y2; |
---|
[31] | 132 | x1=nodesmap[i]->property_x1().get_value(); |
---|
| 133 | x2=nodesmap[i]->property_x2().get_value(); |
---|
| 134 | y1=nodesmap[i]->property_y1().get_value(); |
---|
| 135 | y2=nodesmap[i]->property_y2().get_value(); |
---|
[28] | 136 | nodesmap[i]->property_x1().set_value((x1+x2)/2-w); |
---|
| 137 | nodesmap[i]->property_x2().set_value((x1+x2)/2+w); |
---|
| 138 | nodesmap[i]->property_y1().set_value((y1+y2)/2-w); |
---|
| 139 | nodesmap[i]->property_y2().set_value((y1+y2)/2+w); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | else |
---|
| 144 | { |
---|
[31] | 145 | //I think only new nodes use this case |
---|
[91] | 146 | // int w=(int)actual_map[node]; |
---|
[31] | 147 | int w=(int)(node_property_defaults[N_RADIUS]); |
---|
[28] | 148 | if(w>=0) |
---|
| 149 | { |
---|
| 150 | double x1, y1, x2, y2; |
---|
[31] | 151 | x1=nodesmap[node]->property_x1().get_value(); |
---|
| 152 | x2=nodesmap[node]->property_x2().get_value(); |
---|
| 153 | y1=nodesmap[node]->property_y1().get_value(); |
---|
| 154 | y2=nodesmap[node]->property_y2().get_value(); |
---|
[28] | 155 | nodesmap[node]->property_x1().set_value((x1+x2)/2-w); |
---|
| 156 | nodesmap[node]->property_x2().set_value((x1+x2)/2+w); |
---|
| 157 | nodesmap[node]->property_y1().set_value((y1+y2)/2-w); |
---|
| 158 | nodesmap[node]->property_y2().set_value((y1+y2)/2+w); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | return 0; |
---|
| 162 | }; |
---|
| 163 | |
---|
[62] | 164 | int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node) |
---|
[28] | 165 | { |
---|
| 166 | |
---|
| 167 | //function maps the range of the maximum and |
---|
| 168 | //the minimum of the nodemap to the range of |
---|
| 169 | //green in RGB |
---|
| 170 | |
---|
[31] | 171 | Graph::NodeMap<double> * actual_map; |
---|
[194] | 172 | actual_map=((mytab.mapstorage)->nodemap_storage)[mapname]; |
---|
[81] | 173 | |
---|
| 174 | double max, min; |
---|
| 175 | |
---|
[194] | 176 | max=(mytab.mapstorage)->maxOfNodeMap(mapname); |
---|
| 177 | min=(mytab.mapstorage)->minOfNodeMap(mapname); |
---|
[81] | 178 | |
---|
| 179 | if(node==INVALID) |
---|
[31] | 180 | { |
---|
[81] | 181 | |
---|
[194] | 182 | for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[81] | 183 | { |
---|
| 184 | Gdk::Color color; |
---|
| 185 | |
---|
| 186 | double w=(*actual_map)[i]; |
---|
| 187 | |
---|
| 188 | if(max!=min) |
---|
| 189 | { |
---|
[179] | 190 | color=rainbowColorCounter(min, max, w); |
---|
[81] | 191 | } |
---|
| 192 | else |
---|
| 193 | { |
---|
[179] | 194 | color.set_rgb_p (0, 0, 1); |
---|
[81] | 195 | } |
---|
| 196 | |
---|
| 197 | nodesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 198 | } |
---|
[31] | 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
[81] | 202 | Gdk::Color color; |
---|
| 203 | |
---|
| 204 | double w=(*actual_map)[node]; |
---|
| 205 | |
---|
| 206 | if(max!=min) |
---|
| 207 | { |
---|
[179] | 208 | color=rainbowColorCounter(min, max, w); |
---|
[81] | 209 | } |
---|
| 210 | else |
---|
| 211 | { |
---|
[179] | 212 | color.set_rgb_p (0, 0, 1); |
---|
[81] | 213 | } |
---|
| 214 | |
---|
| 215 | nodesmap[node]->property_fill_color_gdk().set_value(color); |
---|
[31] | 216 | } |
---|
[81] | 217 | return 0; |
---|
| 218 | }; |
---|
| 219 | |
---|
| 220 | int GraphDisplayerCanvas::resetNodeColor (Node node) |
---|
| 221 | { |
---|
| 222 | |
---|
| 223 | //function maps the range of the maximum and |
---|
| 224 | //the minimum of the nodemap to the range of |
---|
| 225 | //green in RGB |
---|
| 226 | |
---|
[194] | 227 | Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_COLOR]); |
---|
[31] | 228 | |
---|
| 229 | double max, min; |
---|
| 230 | |
---|
[81] | 231 | max=node_property_defaults[N_COLOR]; |
---|
| 232 | min=node_property_defaults[N_COLOR]; |
---|
[31] | 233 | |
---|
[28] | 234 | if(node==INVALID) |
---|
| 235 | { |
---|
| 236 | |
---|
[194] | 237 | for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[28] | 238 | { |
---|
| 239 | Gdk::Color color; |
---|
[31] | 240 | |
---|
[91] | 241 | double w=actual_map[i]; |
---|
[31] | 242 | |
---|
[28] | 243 | if(max!=min) |
---|
| 244 | { |
---|
| 245 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 246 | } |
---|
| 247 | else |
---|
| 248 | { |
---|
| 249 | color.set_rgb_p (0, 0, 100); |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | nodesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 253 | } |
---|
| 254 | } |
---|
| 255 | else |
---|
| 256 | { |
---|
| 257 | Gdk::Color color; |
---|
[31] | 258 | |
---|
[91] | 259 | double w=actual_map[node]; |
---|
[31] | 260 | |
---|
[28] | 261 | if(max!=min) |
---|
| 262 | { |
---|
| 263 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 264 | } |
---|
| 265 | else |
---|
| 266 | { |
---|
| 267 | color.set_rgb_p (0, 0, 100); |
---|
| 268 | } |
---|
| 269 | |
---|
| 270 | nodesmap[node]->property_fill_color_gdk().set_value(color); |
---|
| 271 | } |
---|
| 272 | return 0; |
---|
| 273 | }; |
---|
| 274 | |
---|
[62] | 275 | int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node) |
---|
[28] | 276 | { |
---|
| 277 | |
---|
| 278 | //the number in the map will be written on the node |
---|
| 279 | //EXCEPT when the name of the map is Text, because |
---|
| 280 | //in that case empty string will be written, because |
---|
| 281 | //that is the deleter map |
---|
[31] | 282 | |
---|
[36] | 283 | Graph::NodeMap<double> * actual_map=NULL; |
---|
[194] | 284 | actual_map=((mytab.mapstorage)->nodemap_storage)[mapname]; |
---|
[28] | 285 | |
---|
| 286 | if(node==INVALID) |
---|
| 287 | { |
---|
[194] | 288 | for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[28] | 289 | { |
---|
[81] | 290 | nodemap_to_edit=mapname; |
---|
| 291 | double number=(*actual_map)[i]; |
---|
[45] | 292 | |
---|
[81] | 293 | std::ostringstream ostr; |
---|
| 294 | ostr << number; |
---|
[45] | 295 | |
---|
[81] | 296 | nodetextmap[i]->property_text().set_value(ostr.str()); |
---|
[28] | 297 | } |
---|
| 298 | } |
---|
| 299 | else |
---|
| 300 | { |
---|
[81] | 301 | double number=(*actual_map)[node]; |
---|
[45] | 302 | |
---|
[81] | 303 | std::ostringstream ostr; |
---|
| 304 | ostr << number; |
---|
[45] | 305 | |
---|
[81] | 306 | nodetextmap[node]->property_text().set_value(ostr.str()); |
---|
[28] | 307 | } |
---|
| 308 | return 0; |
---|
| 309 | }; |
---|
[81] | 310 | |
---|
| 311 | int GraphDisplayerCanvas::resetNodeText (Node node) |
---|
| 312 | { |
---|
| 313 | |
---|
| 314 | //the number in the map will be written on the node |
---|
| 315 | //EXCEPT when the name of the map is Text, because |
---|
| 316 | //in that case empty string will be written, because |
---|
| 317 | //that is the deleter map |
---|
| 318 | |
---|
| 319 | if(node==INVALID) |
---|
| 320 | { |
---|
[194] | 321 | for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[81] | 322 | { |
---|
| 323 | nodemap_to_edit=""; |
---|
| 324 | nodetextmap[i]->property_text().set_value(""); |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | else |
---|
| 328 | { |
---|
| 329 | nodetextmap[node]->property_text().set_value(""); |
---|
| 330 | } |
---|
| 331 | return 0; |
---|
| 332 | }; |
---|