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