1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/graph_displayer_canvas-edge.cc Mon Jul 07 08:10:39 2008 -0500
1.3 @@ -0,0 +1,302 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include <graph_displayer_canvas.h>
1.23 +#include <mapstorage.h>
1.24 +#include <nbtab.h>
1.25 +#include <cmath>
1.26 +
1.27 +const int minimum_arc_width=0;
1.28 +
1.29 +int DigraphDisplayerCanvas::resetArcWidth (Arc arc)
1.30 +{
1.31 + MapStorage& ms = *mytab.mapstorage;
1.32 + double min, max;
1.33 +
1.34 + min=arc_property_defaults[E_WIDTH];
1.35 + max=arc_property_defaults[E_WIDTH];
1.36 + Digraph::ArcMap<double> actual_map(ms.digraph,arc_property_defaults[E_WIDTH]);
1.37 +
1.38 + if(arc==INVALID)
1.39 + {
1.40 + for (ArcIt i(ms.digraph); i!=INVALID; ++i)
1.41 + {
1.42 + double v=fabs(actual_map[i]);
1.43 + int w;
1.44 + if(min==max)
1.45 + {
1.46 + w=(int)(arc_property_defaults[E_WIDTH]);
1.47 + }
1.48 + else
1.49 + {
1.50 + w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
1.51 + }
1.52 + if(zoomtrack)
1.53 + {
1.54 + double actual_ppu=get_pixels_per_unit();
1.55 + w=(int)(w/actual_ppu*fixed_zoom_factor);
1.56 + }
1.57 + arcsmap[i]->setLineWidth(w);
1.58 + }
1.59 + }
1.60 + else
1.61 + {
1.62 + int w=(int)actual_map[arc];
1.63 + if(w>=0)
1.64 + {
1.65 + arcsmap[arc]->setLineWidth(w);
1.66 + }
1.67 + }
1.68 + return 0;
1.69 +}
1.70 +
1.71 +
1.72 +int DigraphDisplayerCanvas::changeArcWidth (std::string mapname, Arc arc)
1.73 +{
1.74 + MapStorage& ms = *mytab.mapstorage;
1.75 + double min, max;
1.76 +
1.77 + {
1.78 + ArcIt e(ms.digraph);
1.79 + min = max = ms.get(mapname, e);
1.80 + for (; e != INVALID; ++e)
1.81 + {
1.82 + if (static_cast<double>(ms.get(mapname, e)) > max)
1.83 + max = ms.get(mapname, e);
1.84 + if (static_cast<double>(ms.get(mapname, e)) < min)
1.85 + min = ms.get(mapname, e);
1.86 + }
1.87 + }
1.88 +
1.89 + if(arc==INVALID)
1.90 + {
1.91 + for (ArcIt i(ms.digraph); i!=INVALID; ++i)
1.92 + {
1.93 + double v=ms.get(mapname, i);
1.94 + int w;
1.95 + if(autoscale)
1.96 + {
1.97 + if(min==max)
1.98 + {
1.99 + w=(int)(arc_property_defaults[E_WIDTH]);
1.100 + }
1.101 + else
1.102 + {
1.103 + w=(int)(minimum_arc_width+(v-min)/(max-min)*(arc_width-minimum_arc_width));
1.104 + }
1.105 + }
1.106 + else
1.107 + {
1.108 + w=(int)(v*arc_width);
1.109 + }
1.110 + if(w<0)
1.111 + {
1.112 + arcsmap[i]->hide();
1.113 + }
1.114 + else
1.115 + {
1.116 + arcsmap[i]->show();
1.117 + if(w<minimum_arc_width)
1.118 + {
1.119 + w=minimum_arc_width;
1.120 + }
1.121 + if(zoomtrack)
1.122 + {
1.123 + double actual_ppu=get_pixels_per_unit();
1.124 + w=(int)(w/actual_ppu*fixed_zoom_factor);
1.125 + }
1.126 + arcsmap[i]->setLineWidth(w);
1.127 + }
1.128 + }
1.129 + }
1.130 + else
1.131 + {
1.132 + int w=(int)ms.get(mapname, arc);
1.133 + if(w>=0)
1.134 + {
1.135 + arcsmap[arc]->setLineWidth(w);
1.136 + }
1.137 + }
1.138 + return 0;
1.139 +};
1.140 +
1.141 +int DigraphDisplayerCanvas::changeArcColor (std::string mapname, Arc arc)
1.142 +{
1.143 + MapStorage& ms = *mytab.mapstorage;
1.144 +
1.145 + //function maps the range of the maximum and
1.146 + //the minimum of the nodemap to the range of
1.147 + //green in RGB
1.148 +
1.149 + double max, min;
1.150 +
1.151 + {
1.152 + ArcIt e(ms.digraph);
1.153 + min = max = ms.get(mapname, e);
1.154 + for (; e != INVALID; ++e)
1.155 + {
1.156 + if (static_cast<double>(ms.get(mapname, e)) > max)
1.157 + max = ms.get(mapname, e);
1.158 + if (static_cast<double>(ms.get(mapname, e)) < min)
1.159 + min = ms.get(mapname, e);
1.160 + }
1.161 + }
1.162 +
1.163 + if(arc==INVALID)
1.164 + {
1.165 + for (ArcIt i(ms.digraph); i!=INVALID; ++i)
1.166 + {
1.167 + double w=ms.get(mapname, i);
1.168 +
1.169 + Gdk::Color color;
1.170 + if(max!=min)
1.171 + {
1.172 + color=rainbowColorCounter(min, max, w);
1.173 + }
1.174 + else
1.175 + {
1.176 + color.set_rgb_p (0, 1, 0);
1.177 + }
1.178 + arcsmap[i]->setFillColor(color);
1.179 + }
1.180 + }
1.181 + else
1.182 + {
1.183 + Gdk::Color color;
1.184 +
1.185 + double w=ms.get(mapname, arc);
1.186 +
1.187 + if(max!=min)
1.188 + {
1.189 + color=rainbowColorCounter(min, max, w);
1.190 + }
1.191 + else
1.192 + {
1.193 + color.set_rgb_p (0, 1, 0);
1.194 + }
1.195 +
1.196 + arcsmap[arc]->setFillColor(color);
1.197 + }
1.198 + return 0;
1.199 +};
1.200 +
1.201 +int DigraphDisplayerCanvas::resetArcColor (Arc arc)
1.202 +{
1.203 + MapStorage& ms = *mytab.mapstorage;
1.204 +
1.205 + //function maps the range of the maximum and
1.206 + //the minimum of the nodemap to the range of
1.207 + //green in RGB
1.208 + Digraph::ArcMap<double> actual_map(ms.digraph,arc_property_defaults[E_COLOR]);
1.209 +
1.210 + double max, min;
1.211 +
1.212 + max=arc_property_defaults[E_COLOR];
1.213 + min=arc_property_defaults[E_COLOR];
1.214 +
1.215 + if(arc==INVALID)
1.216 + {
1.217 + for (ArcIt i(ms.digraph); i!=INVALID; ++i)
1.218 + {
1.219 + double w=actual_map[i];
1.220 +
1.221 + Gdk::Color color;
1.222 + if(max!=min)
1.223 + {
1.224 + color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
1.225 + }
1.226 + else
1.227 + {
1.228 + color.set_rgb_p (0, 100, 0);
1.229 + }
1.230 + arcsmap[i]->setFillColor(color);
1.231 + }
1.232 + }
1.233 + else
1.234 + {
1.235 + Gdk::Color color;
1.236 +
1.237 + double w=actual_map[arc];
1.238 +
1.239 + if(max!=min)
1.240 + {
1.241 + color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
1.242 + }
1.243 + else
1.244 + {
1.245 + color.set_rgb_p (0, 100, 0);
1.246 + }
1.247 +
1.248 + arcsmap[arc]->setFillColor(color);
1.249 + }
1.250 + return 0;
1.251 +};
1.252 +
1.253 +int DigraphDisplayerCanvas::changeArcText (std::string mapname, Arc arc)
1.254 +{
1.255 + MapStorage& ms = *mytab.mapstorage;
1.256 +
1.257 + //the number in the map will be written on the arc
1.258 + //EXCEPT when the name of the map is Default, because
1.259 + //in that case empty string will be written, because
1.260 + //that is the deleter map
1.261 +
1.262 + if(arc==INVALID)
1.263 + {
1.264 + for (ArcIt i(ms.digraph); i!=INVALID; ++i)
1.265 + {
1.266 + arcmap_to_edit=mapname;
1.267 +
1.268 + arctextmap[i]->property_text().set_value(
1.269 + static_cast<std::string>(ms.get(mapname, i)));
1.270 + }
1.271 +
1.272 + }
1.273 + else
1.274 + {
1.275 + arctextmap[arc]->property_text().set_value(
1.276 + static_cast<std::string>(ms.get(mapname, arc)));
1.277 + }
1.278 +
1.279 + return 0;
1.280 +};
1.281 +
1.282 +int DigraphDisplayerCanvas::resetArcText (Arc arc)
1.283 +{
1.284 + MapStorage& ms = *mytab.mapstorage;
1.285 +
1.286 + //the number in the map will be written on the arc
1.287 + //EXCEPT when the name of the map is Default, because
1.288 + //in that case empty string will be written, because
1.289 + //that is the deleter map
1.290 +
1.291 + if(arc==INVALID)
1.292 + {
1.293 + for (ArcIt i(ms.digraph); i!=INVALID; ++i)
1.294 + {
1.295 + arcmap_to_edit="";
1.296 + arctextmap[i]->property_text().set_value("");
1.297 + }
1.298 + }
1.299 + else
1.300 + {
1.301 + arctextmap[arc]->property_text().set_value("");
1.302 + }
1.303 +
1.304 + return 0;
1.305 +};