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