[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> |
---|
[27] | 23 | |
---|
[167] | 24 | const int minimum_edge_width=0; |
---|
[27] | 25 | |
---|
[81] | 26 | int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) |
---|
| 27 | { |
---|
| 28 | double min, max; |
---|
| 29 | |
---|
| 30 | min=edge_property_defaults[E_WIDTH]; |
---|
| 31 | max=edge_property_defaults[E_WIDTH]; |
---|
[194] | 32 | Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_WIDTH]); |
---|
[81] | 33 | |
---|
| 34 | if(edge==INVALID) |
---|
| 35 | { |
---|
[194] | 36 | for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[81] | 37 | { |
---|
[91] | 38 | double v=fabs(actual_map[i]); |
---|
[81] | 39 | int w; |
---|
| 40 | if(min==max) |
---|
| 41 | { |
---|
| 42 | w=(int)(edge_property_defaults[E_WIDTH]); |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); |
---|
| 47 | } |
---|
[157] | 48 | if(zoomtrack) |
---|
| 49 | { |
---|
| 50 | double actual_ppu=get_pixels_per_unit(); |
---|
| 51 | w=(int)(w/actual_ppu*fixed_zoom_factor); |
---|
| 52 | } |
---|
[147] | 53 | edgesmap[i]->setLineWidth(w); |
---|
[81] | 54 | } |
---|
| 55 | } |
---|
| 56 | else |
---|
| 57 | { |
---|
[91] | 58 | int w=(int)actual_map[edge]; |
---|
[81] | 59 | if(w>=0) |
---|
| 60 | { |
---|
[147] | 61 | edgesmap[edge]->setLineWidth(w); |
---|
[81] | 62 | } |
---|
| 63 | } |
---|
| 64 | return 0; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | |
---|
[62] | 68 | int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge) |
---|
[27] | 69 | { |
---|
[31] | 70 | Graph::EdgeMap<double> * actual_map; |
---|
[48] | 71 | double min, max; |
---|
| 72 | |
---|
[194] | 73 | min=(mytab.mapstorage)->minOfEdgeMap(mapname); |
---|
| 74 | max=(mytab.mapstorage)->maxOfEdgeMap(mapname); |
---|
| 75 | actual_map=((mytab.mapstorage)->edgemap_storage)[mapname]; |
---|
[31] | 76 | |
---|
[28] | 77 | if(edge==INVALID) |
---|
[27] | 78 | { |
---|
[194] | 79 | for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[28] | 80 | { |
---|
[178] | 81 | double v=(*actual_map)[i]; |
---|
[48] | 82 | int w; |
---|
[157] | 83 | if(autoscale) |
---|
[28] | 84 | { |
---|
[157] | 85 | if(min==max) |
---|
| 86 | { |
---|
| 87 | w=(int)(edge_property_defaults[E_WIDTH]); |
---|
| 88 | } |
---|
| 89 | else |
---|
| 90 | { |
---|
| 91 | w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width)); |
---|
| 92 | } |
---|
[28] | 93 | } |
---|
[48] | 94 | else |
---|
| 95 | { |
---|
[157] | 96 | w=(int)(v*edge_width); |
---|
| 97 | } |
---|
[178] | 98 | if(w<0) |
---|
[157] | 99 | { |
---|
[178] | 100 | edgesmap[i]->hide(); |
---|
[157] | 101 | } |
---|
[178] | 102 | else |
---|
[157] | 103 | { |
---|
[178] | 104 | edgesmap[i]->show(); |
---|
| 105 | if(w<minimum_edge_width) |
---|
| 106 | { |
---|
| 107 | w=minimum_edge_width; |
---|
| 108 | } |
---|
| 109 | if(zoomtrack) |
---|
| 110 | { |
---|
| 111 | double actual_ppu=get_pixels_per_unit(); |
---|
| 112 | w=(int)(w/actual_ppu*fixed_zoom_factor); |
---|
| 113 | } |
---|
| 114 | edgesmap[i]->setLineWidth(w); |
---|
[48] | 115 | } |
---|
[28] | 116 | } |
---|
| 117 | } |
---|
| 118 | else |
---|
| 119 | { |
---|
[31] | 120 | int w=(int)(*actual_map)[edge]; |
---|
[27] | 121 | if(w>=0) |
---|
| 122 | { |
---|
[147] | 123 | edgesmap[edge]->setLineWidth(w); |
---|
[27] | 124 | } |
---|
| 125 | } |
---|
| 126 | return 0; |
---|
| 127 | }; |
---|
| 128 | |
---|
[62] | 129 | int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge) |
---|
[27] | 130 | { |
---|
| 131 | |
---|
| 132 | //function maps the range of the maximum and |
---|
| 133 | //the minimum of the nodemap to the range of |
---|
| 134 | //green in RGB |
---|
[31] | 135 | Graph::EdgeMap<double> * actual_map; |
---|
[194] | 136 | actual_map=((mytab.mapstorage)->edgemap_storage)[mapname]; |
---|
[81] | 137 | |
---|
| 138 | double max, min; |
---|
| 139 | |
---|
[194] | 140 | max=(mytab.mapstorage)->maxOfEdgeMap(mapname); |
---|
| 141 | min=(mytab.mapstorage)->minOfEdgeMap(mapname); |
---|
[81] | 142 | |
---|
| 143 | if(edge==INVALID) |
---|
[31] | 144 | { |
---|
[194] | 145 | for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[81] | 146 | { |
---|
| 147 | double w=(*actual_map)[i]; |
---|
| 148 | |
---|
| 149 | Gdk::Color color; |
---|
| 150 | if(max!=min) |
---|
| 151 | { |
---|
[179] | 152 | color=rainbowColorCounter(min, max, w); |
---|
[81] | 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
[179] | 156 | color.set_rgb_p (0, 1, 0); |
---|
[81] | 157 | } |
---|
[147] | 158 | edgesmap[i]->setFillColor(color); |
---|
[81] | 159 | } |
---|
[31] | 160 | } |
---|
| 161 | else |
---|
| 162 | { |
---|
[81] | 163 | Gdk::Color color; |
---|
| 164 | |
---|
| 165 | double w=(*actual_map)[edge]; |
---|
| 166 | |
---|
| 167 | if(max!=min) |
---|
| 168 | { |
---|
[179] | 169 | color=rainbowColorCounter(min, max, w); |
---|
[81] | 170 | } |
---|
| 171 | else |
---|
| 172 | { |
---|
[179] | 173 | color.set_rgb_p (0, 1, 0); |
---|
[81] | 174 | } |
---|
| 175 | |
---|
[147] | 176 | edgesmap[edge]->setFillColor(color); |
---|
[31] | 177 | } |
---|
[81] | 178 | return 0; |
---|
| 179 | }; |
---|
| 180 | |
---|
| 181 | int GraphDisplayerCanvas::resetEdgeColor (Edge edge) |
---|
| 182 | { |
---|
| 183 | |
---|
| 184 | //function maps the range of the maximum and |
---|
| 185 | //the minimum of the nodemap to the range of |
---|
| 186 | //green in RGB |
---|
[194] | 187 | Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_COLOR]); |
---|
[31] | 188 | |
---|
| 189 | double max, min; |
---|
| 190 | |
---|
[81] | 191 | max=edge_property_defaults[E_COLOR]; |
---|
| 192 | min=edge_property_defaults[E_COLOR]; |
---|
[31] | 193 | |
---|
[28] | 194 | if(edge==INVALID) |
---|
| 195 | { |
---|
[194] | 196 | for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[28] | 197 | { |
---|
[91] | 198 | double w=actual_map[i]; |
---|
[31] | 199 | |
---|
[28] | 200 | Gdk::Color color; |
---|
| 201 | if(max!=min) |
---|
| 202 | { |
---|
| 203 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 204 | } |
---|
| 205 | else |
---|
| 206 | { |
---|
| 207 | color.set_rgb_p (0, 100, 0); |
---|
| 208 | } |
---|
[147] | 209 | edgesmap[i]->setFillColor(color); |
---|
[28] | 210 | } |
---|
| 211 | } |
---|
| 212 | else |
---|
[27] | 213 | { |
---|
[28] | 214 | Gdk::Color color; |
---|
[31] | 215 | |
---|
[91] | 216 | double w=actual_map[edge]; |
---|
[31] | 217 | |
---|
[28] | 218 | if(max!=min) |
---|
| 219 | { |
---|
| 220 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | color.set_rgb_p (0, 100, 0); |
---|
| 225 | } |
---|
| 226 | |
---|
[147] | 227 | edgesmap[edge]->setFillColor(color); |
---|
[27] | 228 | } |
---|
| 229 | return 0; |
---|
| 230 | }; |
---|
| 231 | |
---|
[62] | 232 | int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge) |
---|
[27] | 233 | { |
---|
| 234 | //the number in the map will be written on the edge |
---|
[40] | 235 | //EXCEPT when the name of the map is Default, because |
---|
[27] | 236 | //in that case empty string will be written, because |
---|
| 237 | //that is the deleter map |
---|
[63] | 238 | |
---|
[28] | 239 | if(edge==INVALID) |
---|
[27] | 240 | { |
---|
[194] | 241 | for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[27] | 242 | { |
---|
[81] | 243 | edgemap_to_edit=mapname; |
---|
[194] | 244 | double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[i]; |
---|
[81] | 245 | |
---|
| 246 | std::ostringstream ostr; |
---|
| 247 | ostr << number; |
---|
| 248 | |
---|
| 249 | edgetextmap[i]->property_text().set_value(ostr.str()); |
---|
[28] | 250 | } |
---|
| 251 | |
---|
| 252 | } |
---|
| 253 | else |
---|
| 254 | { |
---|
[194] | 255 | double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[edge]; |
---|
[45] | 256 | |
---|
| 257 | std::ostringstream ostr; |
---|
| 258 | ostr << number; |
---|
| 259 | |
---|
| 260 | edgetextmap[edge]->property_text().set_value(ostr.str()); |
---|
[27] | 261 | } |
---|
[28] | 262 | |
---|
[27] | 263 | return 0; |
---|
[28] | 264 | |
---|
[27] | 265 | }; |
---|
[81] | 266 | |
---|
| 267 | int GraphDisplayerCanvas::resetEdgeText (Edge edge) |
---|
| 268 | { |
---|
| 269 | //the number in the map will be written on the edge |
---|
| 270 | //EXCEPT when the name of the map is Default, because |
---|
| 271 | //in that case empty string will be written, because |
---|
| 272 | //that is the deleter map |
---|
| 273 | |
---|
| 274 | if(edge==INVALID) |
---|
| 275 | { |
---|
[194] | 276 | for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
---|
[81] | 277 | { |
---|
| 278 | edgemap_to_edit=""; |
---|
| 279 | edgetextmap[i]->property_text().set_value(""); |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | } |
---|
| 283 | else |
---|
| 284 | { |
---|
| 285 | edgetextmap[edge]->property_text().set_value(""); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | return 0; |
---|
| 289 | |
---|
| 290 | }; |
---|