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