/* -*- 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_edge_width=0; int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) { double min, max; min=edge_property_defaults[E_WIDTH]; max=edge_property_defaults[E_WIDTH]; Graph::EdgeMap actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]); if(edge==INVALID) { for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { double v=fabs(actual_map[i]); int w; if(min==max) { w=(int)(edge_property_defaults[E_WIDTH]); } else { w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); } if(zoomtrack) { double actual_ppu=get_pixels_per_unit(); w=(int)(w/actual_ppu*fixed_zoom_factor); } edgesmap[i]->setLineWidth(w); } } else { int w=(int)actual_map[edge]; if(w>=0) { edgesmap[edge]->setLineWidth(w); } } return 0; } int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge) { Graph::EdgeMap * actual_map; double min, max; min=(mytab.mapstorage).minOfEdgeMap(mapname); max=(mytab.mapstorage).maxOfEdgeMap(mapname); actual_map=((mytab.mapstorage).edgemap_storage)[mapname]; if(edge==INVALID) { for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { double v=(*actual_map)[i]; int w; if(autoscale) { if(min==max) { w=(int)(edge_property_defaults[E_WIDTH]); } else { w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width)); } } else { w=(int)(v*edge_width); } if(w<0) { edgesmap[i]->hide(); } else { edgesmap[i]->show(); if(wsetLineWidth(w); } } } else { int w=(int)(*actual_map)[edge]; if(w>=0) { edgesmap[edge]->setLineWidth(w); } } return 0; }; int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge) { //function maps the range of the maximum and //the minimum of the nodemap to the range of //green in RGB Graph::EdgeMap * actual_map; actual_map=((mytab.mapstorage).edgemap_storage)[mapname]; double max, min; max=(mytab.mapstorage).maxOfEdgeMap(mapname); min=(mytab.mapstorage).minOfEdgeMap(mapname); if(edge==INVALID) { for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { double w=(*actual_map)[i]; Gdk::Color color; if(max!=min) { color=rainbowColorCounter(min, max, w); } else { color.set_rgb_p (0, 1, 0); } edgesmap[i]->setFillColor(color); } } else { Gdk::Color color; double w=(*actual_map)[edge]; if(max!=min) { color=rainbowColorCounter(min, max, w); } else { color.set_rgb_p (0, 1, 0); } edgesmap[edge]->setFillColor(color); } return 0; }; int GraphDisplayerCanvas::resetEdgeColor (Edge edge) { //function maps the range of the maximum and //the minimum of the nodemap to the range of //green in RGB Graph::EdgeMap actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]); double max, min; max=edge_property_defaults[E_COLOR]; min=edge_property_defaults[E_COLOR]; if(edge==INVALID) { for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { double w=actual_map[i]; Gdk::Color color; if(max!=min) { color.set_rgb_p (0, 100*(w-min)/(max-min), 0); } else { color.set_rgb_p (0, 100, 0); } edgesmap[i]->setFillColor(color); } } else { Gdk::Color color; double w=actual_map[edge]; if(max!=min) { color.set_rgb_p (0, 100*(w-min)/(max-min), 0); } else { color.set_rgb_p (0, 100, 0); } edgesmap[edge]->setFillColor(color); } return 0; }; int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge) { //the number in the map will be written on the edge //EXCEPT when the name of the map is Default, because //in that case empty string will be written, because //that is the deleter map if(edge==INVALID) { for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { edgemap_to_edit=mapname; double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i]; std::ostringstream ostr; ostr << number; edgetextmap[i]->property_text().set_value(ostr.str()); } } else { double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge]; std::ostringstream ostr; ostr << number; edgetextmap[edge]->property_text().set_value(ostr.str()); } return 0; }; int GraphDisplayerCanvas::resetEdgeText (Edge edge) { //the number in the map will be written on the edge //EXCEPT when the name of the map is Default, because //in that case empty string will be written, because //that is the deleter map if(edge==INVALID) { for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { edgemap_to_edit=""; edgetextmap[i]->property_text().set_value(""); } } else { edgetextmap[edge]->property_text().set_value(""); } return 0; };