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_arc_width=0; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::resetArcWidth (Arc arc) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: double min, max; hegyi@1: hegyi@1: min=arc_property_defaults[E_WIDTH]; hegyi@1: max=arc_property_defaults[E_WIDTH]; hegyi@1: Digraph::ArcMap actual_map(ms.digraph,arc_property_defaults[E_WIDTH]); hegyi@1: hegyi@1: if(arc==INVALID) hegyi@1: { hegyi@1: for (ArcIt 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)(arc_property_defaults[E_WIDTH]); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH)); 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: arcsmap[i]->setLineWidth(w); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: int w=(int)actual_map[arc]; hegyi@1: if(w>=0) hegyi@1: { hegyi@1: arcsmap[arc]->setLineWidth(w); hegyi@1: } hegyi@1: } hegyi@1: return 0; hegyi@1: } hegyi@1: hegyi@1: hegyi@1: int DigraphDisplayerCanvas::changeArcWidth (std::string mapname, Arc arc) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: double min, max; hegyi@1: hegyi@1: { hegyi@1: ArcIt e(ms.digraph); hegyi@1: min = max = ms.get(mapname, e); hegyi@1: for (; e != INVALID; ++e) hegyi@1: { hegyi@1: if (static_cast(ms.get(mapname, e)) > max) hegyi@1: max = ms.get(mapname, e); hegyi@1: if (static_cast(ms.get(mapname, e)) < min) hegyi@1: min = ms.get(mapname, e); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: if(arc==INVALID) hegyi@1: { hegyi@1: for (ArcIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: double v=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)(arc_property_defaults[E_WIDTH]); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: w=(int)(minimum_arc_width+(v-min)/(max-min)*(arc_width-minimum_arc_width)); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: w=(int)(v*arc_width); hegyi@1: } hegyi@1: if(w<0) hegyi@1: { hegyi@1: arcsmap[i]->hide(); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: arcsmap[i]->show(); hegyi@1: if(wsetLineWidth(w); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: int w=(int)ms.get(mapname, arc); hegyi@1: if(w>=0) hegyi@1: { hegyi@1: arcsmap[arc]->setLineWidth(w); hegyi@1: } hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::changeArcColor (std::string mapname, Arc arc) 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: ArcIt e(ms.digraph); hegyi@1: min = max = ms.get(mapname, e); hegyi@1: for (; e != INVALID; ++e) hegyi@1: { hegyi@1: if (static_cast(ms.get(mapname, e)) > max) hegyi@1: max = ms.get(mapname, e); hegyi@1: if (static_cast(ms.get(mapname, e)) < min) hegyi@1: min = ms.get(mapname, e); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: if(arc==INVALID) hegyi@1: { hegyi@1: for (ArcIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: double w=ms.get(mapname, i); hegyi@1: hegyi@1: Gdk::Color color; 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, 1, 0); hegyi@1: } hegyi@1: arcsmap[i]->setFillColor(color); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: Gdk::Color color; hegyi@1: hegyi@1: double w=ms.get(mapname, arc); 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, 1, 0); hegyi@1: } hegyi@1: hegyi@1: arcsmap[arc]->setFillColor(color); hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::resetArcColor (Arc arc) 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: Digraph::ArcMap actual_map(ms.digraph,arc_property_defaults[E_COLOR]); hegyi@1: hegyi@1: double max, min; hegyi@1: hegyi@1: max=arc_property_defaults[E_COLOR]; hegyi@1: min=arc_property_defaults[E_COLOR]; hegyi@1: hegyi@1: if(arc==INVALID) hegyi@1: { hegyi@1: for (ArcIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: double w=actual_map[i]; hegyi@1: hegyi@1: Gdk::Color color; hegyi@1: if(max!=min) hegyi@1: { hegyi@1: color.set_rgb_p (0, 100*(w-min)/(max-min), 0); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: color.set_rgb_p (0, 100, 0); hegyi@1: } hegyi@1: arcsmap[i]->setFillColor(color); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: Gdk::Color color; hegyi@1: hegyi@1: double w=actual_map[arc]; hegyi@1: hegyi@1: if(max!=min) hegyi@1: { hegyi@1: color.set_rgb_p (0, 100*(w-min)/(max-min), 0); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: color.set_rgb_p (0, 100, 0); hegyi@1: } hegyi@1: hegyi@1: arcsmap[arc]->setFillColor(color); hegyi@1: } hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::changeArcText (std::string mapname, Arc arc) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: //the number in the map will be written on the arc hegyi@1: //EXCEPT when the name of the map is Default, because hegyi@1: //in that case empty string will be written, because hegyi@1: //that is the deleter map hegyi@1: hegyi@1: if(arc==INVALID) hegyi@1: { hegyi@1: for (ArcIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: arcmap_to_edit=mapname; hegyi@1: hegyi@1: arctextmap[i]->property_text().set_value( hegyi@1: static_cast(ms.get(mapname, i))); hegyi@1: } hegyi@1: hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: arctextmap[arc]->property_text().set_value( hegyi@1: static_cast(ms.get(mapname, arc))); hegyi@1: } hegyi@1: hegyi@1: return 0; hegyi@1: }; hegyi@1: hegyi@1: int DigraphDisplayerCanvas::resetArcText (Arc arc) hegyi@1: { hegyi@1: MapStorage& ms = *mytab.mapstorage; hegyi@1: hegyi@1: //the number in the map will be written on the arc hegyi@1: //EXCEPT when the name of the map is Default, because hegyi@1: //in that case empty string will be written, because hegyi@1: //that is the deleter map hegyi@1: hegyi@1: if(arc==INVALID) hegyi@1: { hegyi@1: for (ArcIt i(ms.digraph); i!=INVALID; ++i) hegyi@1: { hegyi@1: arcmap_to_edit=""; hegyi@1: arctextmap[i]->property_text().set_value(""); hegyi@1: } hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: arctextmap[arc]->property_text().set_value(""); hegyi@1: } hegyi@1: hegyi@1: return 0; hegyi@1: };