alpar@174: /* -*- C++ -*- alpar@174: * alpar@174: * This file is a part of LEMON, a generic C++ optimization library alpar@174: * alpar@174: * Copyright (C) 2003-2006 alpar@174: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@174: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@174: * alpar@174: * Permission to use, modify and distribute this software is granted alpar@174: * provided that this copyright notice appears in all copies. For alpar@174: * precise terms see the accompanying LICENSE file. alpar@174: * alpar@174: * This software is provided "AS IS" with no warranty of any kind, alpar@174: * express or implied, and with no claim as to its suitability for any alpar@174: * purpose. alpar@174: * alpar@174: */ alpar@174: ladanyi@53: #include "graph_displayer_canvas.h" alpar@59: #include hegyi@27: hegyi@167: const int minimum_edge_width=0; hegyi@27: hegyi@81: int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) hegyi@81: { hegyi@81: double min, max; hegyi@81: hegyi@81: min=edge_property_defaults[E_WIDTH]; hegyi@81: max=edge_property_defaults[E_WIDTH]; hegyi@96: Graph::EdgeMap actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]); hegyi@81: hegyi@81: if(edge==INVALID) hegyi@81: { hegyi@96: for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@81: { ladanyi@91: double v=fabs(actual_map[i]); hegyi@81: int w; hegyi@81: if(min==max) hegyi@81: { hegyi@81: w=(int)(edge_property_defaults[E_WIDTH]); hegyi@81: } hegyi@81: else hegyi@81: { hegyi@81: w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); hegyi@81: } hegyi@157: if(zoomtrack) hegyi@157: { hegyi@157: double actual_ppu=get_pixels_per_unit(); hegyi@157: w=(int)(w/actual_ppu*fixed_zoom_factor); hegyi@157: } ladanyi@147: edgesmap[i]->setLineWidth(w); hegyi@81: } hegyi@81: } hegyi@81: else hegyi@81: { ladanyi@91: int w=(int)actual_map[edge]; hegyi@81: if(w>=0) hegyi@81: { ladanyi@147: edgesmap[edge]->setLineWidth(w); hegyi@81: } hegyi@81: } hegyi@81: return 0; hegyi@81: } hegyi@81: hegyi@81: alpar@62: int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge) hegyi@27: { hegyi@31: Graph::EdgeMap * actual_map; hegyi@48: double min, max; hegyi@48: hegyi@96: min=(mytab.mapstorage).minOfEdgeMap(mapname); hegyi@96: max=(mytab.mapstorage).maxOfEdgeMap(mapname); hegyi@96: actual_map=((mytab.mapstorage).edgemap_storage)[mapname]; hegyi@31: hegyi@28: if(edge==INVALID) hegyi@27: { hegyi@96: for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@28: { hegyi@178: double v=(*actual_map)[i]; hegyi@48: int w; hegyi@157: if(autoscale) hegyi@28: { hegyi@157: if(min==max) hegyi@157: { hegyi@157: w=(int)(edge_property_defaults[E_WIDTH]); hegyi@157: } hegyi@157: else hegyi@157: { hegyi@157: w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width)); hegyi@157: } hegyi@28: } hegyi@48: else hegyi@48: { hegyi@157: w=(int)(v*edge_width); hegyi@157: } hegyi@178: if(w<0) hegyi@157: { hegyi@178: edgesmap[i]->hide(); hegyi@157: } hegyi@178: else hegyi@157: { hegyi@178: edgesmap[i]->show(); hegyi@178: if(wsetLineWidth(w); hegyi@48: } hegyi@28: } hegyi@28: } hegyi@28: else hegyi@28: { hegyi@31: int w=(int)(*actual_map)[edge]; hegyi@27: if(w>=0) hegyi@27: { ladanyi@147: edgesmap[edge]->setLineWidth(w); hegyi@27: } hegyi@27: } hegyi@27: return 0; hegyi@27: }; hegyi@27: alpar@62: int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge) hegyi@27: { hegyi@27: hegyi@27: //function maps the range of the maximum and hegyi@27: //the minimum of the nodemap to the range of hegyi@27: //green in RGB hegyi@31: Graph::EdgeMap * actual_map; hegyi@96: actual_map=((mytab.mapstorage).edgemap_storage)[mapname]; hegyi@81: hegyi@81: double max, min; hegyi@81: hegyi@96: max=(mytab.mapstorage).maxOfEdgeMap(mapname); hegyi@96: min=(mytab.mapstorage).minOfEdgeMap(mapname); hegyi@81: hegyi@81: if(edge==INVALID) hegyi@31: { hegyi@96: for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@81: { hegyi@81: double w=(*actual_map)[i]; hegyi@81: hegyi@81: Gdk::Color color; hegyi@81: if(max!=min) hegyi@81: { hegyi@81: color.set_rgb_p (0, 100*(w-min)/(max-min), 0); hegyi@81: } hegyi@81: else hegyi@81: { hegyi@81: color.set_rgb_p (0, 100, 0); hegyi@81: } ladanyi@147: edgesmap[i]->setFillColor(color); hegyi@81: } hegyi@31: } hegyi@31: else hegyi@31: { hegyi@81: Gdk::Color color; hegyi@81: hegyi@81: double w=(*actual_map)[edge]; hegyi@81: hegyi@81: if(max!=min) hegyi@81: { hegyi@81: color.set_rgb_p (0, 100*(w-min)/(max-min), 0); hegyi@81: } hegyi@81: else hegyi@81: { hegyi@81: color.set_rgb_p (0, 100, 0); hegyi@81: } hegyi@81: ladanyi@147: edgesmap[edge]->setFillColor(color); hegyi@31: } hegyi@81: return 0; hegyi@81: }; hegyi@81: hegyi@81: int GraphDisplayerCanvas::resetEdgeColor (Edge edge) hegyi@81: { hegyi@81: hegyi@81: //function maps the range of the maximum and hegyi@81: //the minimum of the nodemap to the range of hegyi@81: //green in RGB hegyi@96: Graph::EdgeMap actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]); hegyi@31: hegyi@31: double max, min; hegyi@31: hegyi@81: max=edge_property_defaults[E_COLOR]; hegyi@81: min=edge_property_defaults[E_COLOR]; hegyi@31: hegyi@28: if(edge==INVALID) hegyi@28: { hegyi@96: for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@28: { ladanyi@91: double w=actual_map[i]; hegyi@31: hegyi@28: Gdk::Color color; hegyi@28: if(max!=min) hegyi@28: { hegyi@28: color.set_rgb_p (0, 100*(w-min)/(max-min), 0); hegyi@28: } hegyi@28: else hegyi@28: { hegyi@28: color.set_rgb_p (0, 100, 0); hegyi@28: } ladanyi@147: edgesmap[i]->setFillColor(color); hegyi@28: } hegyi@28: } hegyi@28: else hegyi@27: { hegyi@28: Gdk::Color color; hegyi@31: ladanyi@91: double w=actual_map[edge]; hegyi@31: hegyi@28: if(max!=min) hegyi@28: { hegyi@28: color.set_rgb_p (0, 100*(w-min)/(max-min), 0); hegyi@28: } hegyi@28: else hegyi@28: { hegyi@28: color.set_rgb_p (0, 100, 0); hegyi@28: } hegyi@28: ladanyi@147: edgesmap[edge]->setFillColor(color); hegyi@27: } hegyi@27: return 0; hegyi@27: }; hegyi@27: alpar@62: int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge) hegyi@27: { hegyi@27: //the number in the map will be written on the edge hegyi@40: //EXCEPT when the name of the map is Default, because hegyi@27: //in that case empty string will be written, because hegyi@27: //that is the deleter map ladanyi@63: hegyi@28: if(edge==INVALID) hegyi@27: { hegyi@96: for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@27: { hegyi@81: edgemap_to_edit=mapname; hegyi@96: double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i]; hegyi@81: hegyi@81: std::ostringstream ostr; hegyi@81: ostr << number; hegyi@81: hegyi@81: edgetextmap[i]->property_text().set_value(ostr.str()); hegyi@28: } hegyi@28: hegyi@28: } hegyi@28: else hegyi@28: { hegyi@96: double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge]; hegyi@45: hegyi@45: std::ostringstream ostr; hegyi@45: ostr << number; hegyi@45: hegyi@45: edgetextmap[edge]->property_text().set_value(ostr.str()); hegyi@27: } hegyi@28: hegyi@27: return 0; hegyi@28: hegyi@27: }; hegyi@81: hegyi@81: int GraphDisplayerCanvas::resetEdgeText (Edge edge) hegyi@81: { hegyi@81: //the number in the map will be written on the edge hegyi@81: //EXCEPT when the name of the map is Default, because hegyi@81: //in that case empty string will be written, because hegyi@81: //that is the deleter map hegyi@81: hegyi@81: if(edge==INVALID) hegyi@81: { hegyi@96: for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@81: { hegyi@81: edgemap_to_edit=""; hegyi@81: edgetextmap[i]->property_text().set_value(""); hegyi@81: } hegyi@81: hegyi@81: } hegyi@81: else hegyi@81: { hegyi@81: edgetextmap[edge]->property_text().set_value(""); hegyi@81: } hegyi@81: hegyi@81: return 0; hegyi@81: hegyi@81: };