1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/graph_displayer_canvas-node.cc Mon Jul 07 08:10:39 2008 -0500
1.3 @@ -0,0 +1,344 @@
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_node_radius=5;
1.28 +
1.29 +int DigraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
1.30 +{
1.31 + MapStorage& ms = *mytab.mapstorage;
1.32 +
1.33 + double min, max;
1.34 +
1.35 + {
1.36 + NodeIt n(ms.digraph);
1.37 + min = max = ms.get(mapname, n);
1.38 + for (; n != INVALID; ++n)
1.39 + {
1.40 + if (static_cast<double>(ms.get(mapname, n)) > max)
1.41 + max = ms.get(mapname, n);
1.42 + if (static_cast<double>(ms.get(mapname, n)) < min)
1.43 + min = ms.get(mapname, n);
1.44 + }
1.45 + }
1.46 +
1.47 + if(node==INVALID)
1.48 + {
1.49 + for (NodeIt i(ms.digraph); i!=INVALID; ++i)
1.50 + {
1.51 + double v=fabs(ms.get(mapname,i));
1.52 + int w;
1.53 + if(autoscale)
1.54 + {
1.55 + if(min==max)
1.56 + {
1.57 + w=(int)(node_property_defaults[N_RADIUS]);
1.58 + }
1.59 + else
1.60 + {
1.61 + w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
1.62 + }
1.63 + }
1.64 + else
1.65 + {
1.66 + w=(int)(v*radius_size);
1.67 + }
1.68 +
1.69 + if(w<minimum_node_radius)
1.70 + {
1.71 + w=minimum_node_radius;
1.72 + }
1.73 +
1.74 + if(zoomtrack)
1.75 + {
1.76 + double actual_ppu=get_pixels_per_unit();
1.77 + w=(int)(w/actual_ppu*fixed_zoom_factor);
1.78 + }
1.79 +
1.80 + if(w>=0)
1.81 + {
1.82 + double x1, y1, x2, y2;
1.83 + x1=nodesmap[i]->property_x1().get_value();
1.84 + x2=nodesmap[i]->property_x2().get_value();
1.85 + y1=nodesmap[i]->property_y1().get_value();
1.86 + y2=nodesmap[i]->property_y2().get_value();
1.87 + nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
1.88 + nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
1.89 + nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
1.90 + nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
1.91 + }
1.92 + }
1.93 + }
1.94 + else
1.95 + {
1.96 + //I think only new nodes use this case
1.97 + //that has no own value, only the default one
1.98 + //int w=(int)(*actual_map)[node];
1.99 + int w=(int)(node_property_defaults[N_RADIUS]);
1.100 + if(w>=0)
1.101 + {
1.102 + double x1, y1, x2, y2;
1.103 + x1=nodesmap[node]->property_x1().get_value();
1.104 + x2=nodesmap[node]->property_x2().get_value();
1.105 + y1=nodesmap[node]->property_y1().get_value();
1.106 + y2=nodesmap[node]->property_y2().get_value();
1.107 + nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
1.108 + nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
1.109 + nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
1.110 + nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
1.111 + }
1.112 + }
1.113 + return 0;
1.114 +};
1.115 +
1.116 +int DigraphDisplayerCanvas::resetNodeRadius (Node node)
1.117 +{
1.118 + MapStorage& ms = *mytab.mapstorage;
1.119 +
1.120 + double min, max;
1.121 + min=node_property_defaults[N_RADIUS];
1.122 + max=node_property_defaults[N_RADIUS];
1.123 + Digraph::NodeMap<double> actual_map(ms.digraph,node_property_defaults[N_RADIUS]);
1.124 +
1.125 + if(node==INVALID)
1.126 + {
1.127 + for (NodeIt i(ms.digraph); i!=INVALID; ++i)
1.128 + {
1.129 + double v=fabs(actual_map[i]);
1.130 + int w;
1.131 + if(min==max)
1.132 + {
1.133 + w=(int)(node_property_defaults[N_RADIUS]);
1.134 + }
1.135 + else
1.136 + {
1.137 + w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
1.138 + }
1.139 + if(zoomtrack)
1.140 + {
1.141 + double actual_ppu=get_pixels_per_unit();
1.142 + w=(int)(w/actual_ppu*fixed_zoom_factor);
1.143 + }
1.144 + if(w>=0)
1.145 + {
1.146 + double x1, y1, x2, y2;
1.147 + x1=nodesmap[i]->property_x1().get_value();
1.148 + x2=nodesmap[i]->property_x2().get_value();
1.149 + y1=nodesmap[i]->property_y1().get_value();
1.150 + y2=nodesmap[i]->property_y2().get_value();
1.151 + nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
1.152 + nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
1.153 + nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
1.154 + nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
1.155 + }
1.156 + }
1.157 + }
1.158 + else
1.159 + {
1.160 + //I think only new nodes use this case
1.161 +// int w=(int)actual_map[node];
1.162 + int w=(int)(node_property_defaults[N_RADIUS]);
1.163 + if(w>=0)
1.164 + {
1.165 + double x1, y1, x2, y2;
1.166 + x1=nodesmap[node]->property_x1().get_value();
1.167 + x2=nodesmap[node]->property_x2().get_value();
1.168 + y1=nodesmap[node]->property_y1().get_value();
1.169 + y2=nodesmap[node]->property_y2().get_value();
1.170 + nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
1.171 + nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
1.172 + nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
1.173 + nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
1.174 + }
1.175 + }
1.176 + return 0;
1.177 +};
1.178 +
1.179 +int DigraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
1.180 +{
1.181 + MapStorage& ms = *mytab.mapstorage;
1.182 +
1.183 + //function maps the range of the maximum and
1.184 + //the minimum of the nodemap to the range of
1.185 + //green in RGB
1.186 +
1.187 + double max, min;
1.188 +
1.189 + {
1.190 + NodeIt n(ms.digraph);
1.191 + min = max = ms.get(mapname, n);
1.192 + for (; n != INVALID; ++n)
1.193 + {
1.194 + if (static_cast<double>(ms.get(mapname, n)) > max)
1.195 + max = ms.get(mapname, n);
1.196 + if (static_cast<double>(ms.get(mapname, n)) < min)
1.197 + min = ms.get(mapname, n);
1.198 + }
1.199 + }
1.200 +
1.201 + if(node==INVALID)
1.202 + {
1.203 +
1.204 + for (NodeIt i(ms.digraph); i!=INVALID; ++i)
1.205 + {
1.206 + Gdk::Color color;
1.207 +
1.208 + double w=ms.get(mapname, i);
1.209 +
1.210 + if(max!=min)
1.211 + {
1.212 + color=rainbowColorCounter(min, max, w);
1.213 + }
1.214 + else
1.215 + {
1.216 + color.set_rgb_p (0, 0, 1);
1.217 + }
1.218 +
1.219 + nodesmap[i]->property_fill_color_gdk().set_value(color);
1.220 + }
1.221 + }
1.222 + else
1.223 + {
1.224 + Gdk::Color color;
1.225 +
1.226 + double w=ms.get(mapname, node);
1.227 +
1.228 + if(max!=min)
1.229 + {
1.230 + color=rainbowColorCounter(min, max, w);
1.231 + }
1.232 + else
1.233 + {
1.234 + color.set_rgb_p (0, 0, 1);
1.235 + }
1.236 +
1.237 + nodesmap[node]->property_fill_color_gdk().set_value(color);
1.238 + }
1.239 + return 0;
1.240 +};
1.241 +
1.242 +int DigraphDisplayerCanvas::resetNodeColor (Node node)
1.243 +{
1.244 + MapStorage& ms = *mytab.mapstorage;
1.245 +
1.246 + //function maps the range of the maximum and
1.247 + //the minimum of the nodemap to the range of
1.248 + //green in RGB
1.249 +
1.250 + Digraph::NodeMap<double> actual_map(ms.digraph,node_property_defaults[N_COLOR]);
1.251 +
1.252 + double max, min;
1.253 +
1.254 + max=node_property_defaults[N_COLOR];
1.255 + min=node_property_defaults[N_COLOR];
1.256 +
1.257 + if(node==INVALID)
1.258 + {
1.259 +
1.260 + for (NodeIt i(ms.digraph); i!=INVALID; ++i)
1.261 + {
1.262 + Gdk::Color color;
1.263 +
1.264 + double w=actual_map[i];
1.265 +
1.266 + if(max!=min)
1.267 + {
1.268 + color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
1.269 + }
1.270 + else
1.271 + {
1.272 + color.set_rgb_p (0, 0, 100);
1.273 + }
1.274 +
1.275 + nodesmap[i]->property_fill_color_gdk().set_value(color);
1.276 + }
1.277 + }
1.278 + else
1.279 + {
1.280 + Gdk::Color color;
1.281 +
1.282 + double w=actual_map[node];
1.283 +
1.284 + if(max!=min)
1.285 + {
1.286 + color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
1.287 + }
1.288 + else
1.289 + {
1.290 + color.set_rgb_p (0, 0, 100);
1.291 + }
1.292 +
1.293 + nodesmap[node]->property_fill_color_gdk().set_value(color);
1.294 + }
1.295 + return 0;
1.296 +};
1.297 +
1.298 +int DigraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
1.299 +{
1.300 + MapStorage& ms = *mytab.mapstorage;
1.301 +
1.302 + //the number in the map will be written on the node
1.303 + //EXCEPT when the name of the map is Text, because
1.304 + //in that case empty string will be written, because
1.305 + //that is the deleter map
1.306 +
1.307 + if(node==INVALID)
1.308 + {
1.309 + for (NodeIt i(ms.digraph); i!=INVALID; ++i)
1.310 + {
1.311 + nodemap_to_edit=mapname;
1.312 +
1.313 + nodetextmap[i]->property_text().set_value(
1.314 + static_cast<std::string>(ms.get(mapname, i)));
1.315 + }
1.316 + }
1.317 + else
1.318 + {
1.319 + nodetextmap[node]->property_text().set_value(
1.320 + static_cast<std::string>(ms.get(mapname, node)));
1.321 + }
1.322 + return 0;
1.323 +};
1.324 +
1.325 +int DigraphDisplayerCanvas::resetNodeText (Node node)
1.326 +{
1.327 + MapStorage& ms = *mytab.mapstorage;
1.328 +
1.329 + //the number in the map will be written on the node
1.330 + //EXCEPT when the name of the map is Text, because
1.331 + //in that case empty string will be written, because
1.332 + //that is the deleter map
1.333 +
1.334 + if(node==INVALID)
1.335 + {
1.336 + for (NodeIt i(ms.digraph); i!=INVALID; ++i)
1.337 + {
1.338 + nodemap_to_edit="";
1.339 + nodetextmap[i]->property_text().set_value("");
1.340 + }
1.341 + }
1.342 + else
1.343 + {
1.344 + nodetextmap[node]->property_text().set_value("");
1.345 + }
1.346 + return 0;
1.347 +};