hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all copies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: const int minimum_node_radius=5; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: double min, max; hegyi@1: hegyi@1: { hegyi@1: NodeIt n(ms.digraph); hegyi@1: min = max = ms.get(mapname, n); hegyi@1: for (; n != INVALID; ++n) hegyi@1: { hegyi@1: if (static_cast(ms.get(mapname, n)) > max) hegyi@1: max = ms.get(mapname, n); hegyi@1: if (static_cast(ms.get(mapname, n)) < min) hegyi@1: min = ms.get(mapname, n); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: if(node==INVALID) hegyi@1: { hegyi@1: for (NodeIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: double v=fabs(ms.get(mapname,i)); hegyi@1: int w; hegyi@1: if(autoscale) hegyi@1: { hegyi@1: if(min==max) hegyi@1: { hegyi@1: w=(int)(node_property_defaults[N_RADIUS]); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius)); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: w=(int)(v*radius_size); hegyi@1: } hegyi@1: hegyi@1: if(w=0) hegyi@1: { hegyi@1: double x1, y1, x2, y2; hegyi@1: x1=nodesmap[i]->property_x1().get_value(); hegyi@1: x2=nodesmap[i]->property_x2().get_value(); hegyi@1: y1=nodesmap[i]->property_y1().get_value(); hegyi@1: y2=nodesmap[i]->property_y2().get_value(); hegyi@1: nodesmap[i]->property_x1().set_value((x1+x2)/2-w); hegyi@1: nodesmap[i]->property_x2().set_value((x1+x2)/2+w); hegyi@1: nodesmap[i]->property_y1().set_value((y1+y2)/2-w); hegyi@1: nodesmap[i]->property_y2().set_value((y1+y2)/2+w); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: //I think only new nodes use this case hegyi@1: //that has no own value, only the default one hegyi@1: //int w=(int)(*actual_map)[node]; hegyi@1: int w=(int)(node_property_defaults[N_RADIUS]); hegyi@1: if(w>=0) hegyi@1: { hegyi@1: double x1, y1, x2, y2; hegyi@1: x1=nodesmap[node]->property_x1().get_value(); hegyi@1: x2=nodesmap[node]->property_x2().get_value(); hegyi@1: y1=nodesmap[node]->property_y1().get_value(); hegyi@1: y2=nodesmap[node]->property_y2().get_value(); hegyi@1: nodesmap[node]->property_x1().set_value((x1+x2)/2-w); hegyi@1: nodesmap[node]->property_x2().set_value((x1+x2)/2+w); hegyi@1: nodesmap[node]->property_y1().set_value((y1+y2)/2-w); hegyi@1: nodesmap[node]->property_y2().set_value((y1+y2)/2+w); hegyi@1: } hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::resetNodeRadius (Node node) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: double min, max; hegyi@1: min=node_property_defaults[N_RADIUS]; hegyi@1: max=node_property_defaults[N_RADIUS]; hegyi@1: Digraph::NodeMap actual_map(ms.digraph,node_property_defaults[N_RADIUS]); hegyi@1: hegyi@1: if(node==INVALID) hegyi@1: { hegyi@1: for (NodeIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: double v=fabs(actual_map[i]); hegyi@1: int w; hegyi@1: if(min==max) hegyi@1: { hegyi@1: w=(int)(node_property_defaults[N_RADIUS]); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); hegyi@1: } hegyi@1: if(zoomtrack) hegyi@1: { hegyi@1: double actual_ppu=get_pixels_per_unit(); hegyi@1: w=(int)(w/actual_ppu*fixed_zoom_factor); hegyi@1: } hegyi@1: if(w>=0) hegyi@1: { hegyi@1: double x1, y1, x2, y2; hegyi@1: x1=nodesmap[i]->property_x1().get_value(); hegyi@1: x2=nodesmap[i]->property_x2().get_value(); hegyi@1: y1=nodesmap[i]->property_y1().get_value(); hegyi@1: y2=nodesmap[i]->property_y2().get_value(); hegyi@1: nodesmap[i]->property_x1().set_value((x1+x2)/2-w); hegyi@1: nodesmap[i]->property_x2().set_value((x1+x2)/2+w); hegyi@1: nodesmap[i]->property_y1().set_value((y1+y2)/2-w); hegyi@1: nodesmap[i]->property_y2().set_value((y1+y2)/2+w); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: //I think only new nodes use this case hegyi@1: // int w=(int)actual_map[node]; hegyi@1: int w=(int)(node_property_defaults[N_RADIUS]); hegyi@1: if(w>=0) hegyi@1: { hegyi@1: double x1, y1, x2, y2; hegyi@1: x1=nodesmap[node]->property_x1().get_value(); hegyi@1: x2=nodesmap[node]->property_x2().get_value(); hegyi@1: y1=nodesmap[node]->property_y1().get_value(); hegyi@1: y2=nodesmap[node]->property_y2().get_value(); hegyi@1: nodesmap[node]->property_x1().set_value((x1+x2)/2-w); hegyi@1: nodesmap[node]->property_x2().set_value((x1+x2)/2+w); hegyi@1: nodesmap[node]->property_y1().set_value((y1+y2)/2-w); hegyi@1: nodesmap[node]->property_y2().set_value((y1+y2)/2+w); hegyi@1: } hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: //function maps the range of the maximum and hegyi@1: //the minimum of the nodemap to the range of hegyi@1: //green in RGB hegyi@1: hegyi@1: double max, min; hegyi@1: hegyi@1: { hegyi@1: NodeIt n(ms.digraph); hegyi@1: min = max = ms.get(mapname, n); hegyi@1: for (; n != INVALID; ++n) hegyi@1: { hegyi@1: if (static_cast(ms.get(mapname, n)) > max) hegyi@1: max = ms.get(mapname, n); hegyi@1: if (static_cast(ms.get(mapname, n)) < min) hegyi@1: min = ms.get(mapname, n); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: if(node==INVALID) hegyi@1: { hegyi@1: hegyi@1: for (NodeIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: Gdk::Color color; hegyi@1: hegyi@1: double w=ms.get(mapname, i); hegyi@1: hegyi@1: if(max!=min) hegyi@1: { hegyi@1: color=rainbowColorCounter(min, max, w); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: color.set_rgb_p (0, 0, 1); hegyi@1: } hegyi@1: hegyi@1: nodesmap[i]->property_fill_color_gdk().set_value(color); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: Gdk::Color color; hegyi@1: hegyi@1: double w=ms.get(mapname, node); hegyi@1: hegyi@1: if(max!=min) hegyi@1: { hegyi@1: color=rainbowColorCounter(min, max, w); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: color.set_rgb_p (0, 0, 1); hegyi@1: } hegyi@1: hegyi@1: nodesmap[node]->property_fill_color_gdk().set_value(color); hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::resetNodeColor (Node node) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: //function maps the range of the maximum and hegyi@1: //the minimum of the nodemap to the range of hegyi@1: //green in RGB hegyi@1: hegyi@1: Digraph::NodeMap actual_map(ms.digraph,node_property_defaults[N_COLOR]); hegyi@1: hegyi@1: double max, min; hegyi@1: hegyi@1: max=node_property_defaults[N_COLOR]; hegyi@1: min=node_property_defaults[N_COLOR]; hegyi@1: hegyi@1: if(node==INVALID) hegyi@1: { hegyi@1: hegyi@1: for (NodeIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: Gdk::Color color; hegyi@1: hegyi@1: double w=actual_map[i]; hegyi@1: hegyi@1: if(max!=min) hegyi@1: { hegyi@1: color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: color.set_rgb_p (0, 0, 100); hegyi@1: } hegyi@1: hegyi@1: nodesmap[i]->property_fill_color_gdk().set_value(color); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: Gdk::Color color; hegyi@1: hegyi@1: double w=actual_map[node]; hegyi@1: hegyi@1: if(max!=min) hegyi@1: { hegyi@1: color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: color.set_rgb_p (0, 0, 100); hegyi@1: } hegyi@1: hegyi@1: nodesmap[node]->property_fill_color_gdk().set_value(color); hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::changeNodeText (std::string mapname, Node node) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: //the number in the map will be written on the node hegyi@1: //EXCEPT when the name of the map is Text, because hegyi@1: //in that case empty string will be written, because hegyi@1: //that is the deleter map hegyi@1: hegyi@1: if(node==INVALID) hegyi@1: { hegyi@1: for (NodeIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: nodemap_to_edit=mapname; hegyi@1: hegyi@1: nodetextmap[i]->property_text().set_value( hegyi@1: static_cast(ms.get(mapname, i))); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: nodetextmap[node]->property_text().set_value( hegyi@1: static_cast(ms.get(mapname, node))); hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::resetNodeText (Node node) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: //the number in the map will be written on the node hegyi@1: //EXCEPT when the name of the map is Text, because hegyi@1: //in that case empty string will be written, because hegyi@1: //that is the deleter map hegyi@1: hegyi@1: if(node==INVALID) hegyi@1: { hegyi@1: for (NodeIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: nodemap_to_edit=""; hegyi@1: nodetextmap[i]->property_text().set_value(""); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: nodetextmap[node]->property_text().set_value(""); hegyi@1: } hegyi@1: return 0; hegyi@1: };