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