[28] | 1 | #include <graph_displayer_canvas.h> |
---|
| 2 | #include <broken_edge.h> |
---|
| 3 | #include <math.h> |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node) |
---|
| 7 | { |
---|
[31] | 8 | Graph::NodeMap<double> * actual_map; |
---|
| 9 | if(mapname=="Default") |
---|
| 10 | { |
---|
| 11 | actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]); |
---|
| 12 | } |
---|
| 13 | else |
---|
| 14 | { |
---|
| 15 | actual_map=(mapstorage.nodemap_storage)[mapname]; |
---|
| 16 | } |
---|
| 17 | |
---|
[28] | 18 | if(node==INVALID) |
---|
| 19 | { |
---|
| 20 | for (NodeIt i(g); i!=INVALID; ++i) |
---|
| 21 | { |
---|
[31] | 22 | int w=(int)(*actual_map)[i]; |
---|
[28] | 23 | if(w>=0) |
---|
| 24 | { |
---|
| 25 | double x1, y1, x2, y2; |
---|
[31] | 26 | x1=nodesmap[i]->property_x1().get_value(); |
---|
| 27 | x2=nodesmap[i]->property_x2().get_value(); |
---|
| 28 | y1=nodesmap[i]->property_y1().get_value(); |
---|
| 29 | y2=nodesmap[i]->property_y2().get_value(); |
---|
[28] | 30 | nodesmap[i]->property_x1().set_value((x1+x2)/2-w); |
---|
| 31 | nodesmap[i]->property_x2().set_value((x1+x2)/2+w); |
---|
| 32 | nodesmap[i]->property_y1().set_value((y1+y2)/2-w); |
---|
| 33 | nodesmap[i]->property_y2().set_value((y1+y2)/2+w); |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | else |
---|
| 38 | { |
---|
[31] | 39 | //I think only new nodes use this case |
---|
| 40 | // int w=(int)(*actual_map)[node]; |
---|
| 41 | int w=(int)(node_property_defaults[N_RADIUS]); |
---|
[28] | 42 | if(w>=0) |
---|
| 43 | { |
---|
| 44 | double x1, y1, x2, y2; |
---|
[31] | 45 | x1=nodesmap[node]->property_x1().get_value(); |
---|
| 46 | x2=nodesmap[node]->property_x2().get_value(); |
---|
| 47 | y1=nodesmap[node]->property_y1().get_value(); |
---|
| 48 | y2=nodesmap[node]->property_y2().get_value(); |
---|
[28] | 49 | nodesmap[node]->property_x1().set_value((x1+x2)/2-w); |
---|
| 50 | nodesmap[node]->property_x2().set_value((x1+x2)/2+w); |
---|
| 51 | nodesmap[node]->property_y1().set_value((y1+y2)/2-w); |
---|
| 52 | nodesmap[node]->property_y2().set_value((y1+y2)/2+w); |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | return 0; |
---|
| 56 | }; |
---|
| 57 | |
---|
| 58 | int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node) |
---|
| 59 | { |
---|
| 60 | |
---|
| 61 | //function maps the range of the maximum and |
---|
| 62 | //the minimum of the nodemap to the range of |
---|
| 63 | //green in RGB |
---|
| 64 | |
---|
[31] | 65 | Graph::NodeMap<double> * actual_map; |
---|
| 66 | if(mapname=="Default") |
---|
| 67 | { |
---|
| 68 | actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]); |
---|
| 69 | } |
---|
| 70 | else |
---|
| 71 | { |
---|
| 72 | actual_map=(mapstorage.nodemap_storage)[mapname]; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | double max, min; |
---|
| 76 | |
---|
| 77 | if(mapname!="Default") |
---|
| 78 | { |
---|
| 79 | max=mapstorage.maxOfNodeMap(mapname); |
---|
| 80 | min=mapstorage.minOfNodeMap(mapname); |
---|
| 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
| 84 | max=node_property_defaults[N_COLOR]; |
---|
| 85 | min=node_property_defaults[N_COLOR]; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
[28] | 89 | if(node==INVALID) |
---|
| 90 | { |
---|
| 91 | |
---|
| 92 | for (NodeIt i(g); i!=INVALID; ++i) |
---|
| 93 | { |
---|
| 94 | Gdk::Color color; |
---|
[31] | 95 | |
---|
| 96 | double w=(*actual_map)[i]; |
---|
| 97 | |
---|
[28] | 98 | if(max!=min) |
---|
| 99 | { |
---|
| 100 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 101 | } |
---|
| 102 | else |
---|
| 103 | { |
---|
| 104 | color.set_rgb_p (0, 0, 100); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | nodesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 108 | } |
---|
| 109 | } |
---|
| 110 | else |
---|
| 111 | { |
---|
| 112 | Gdk::Color color; |
---|
[31] | 113 | |
---|
| 114 | double w=(*actual_map)[node]; |
---|
| 115 | |
---|
[28] | 116 | if(max!=min) |
---|
| 117 | { |
---|
| 118 | color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); |
---|
| 119 | } |
---|
| 120 | else |
---|
| 121 | { |
---|
| 122 | color.set_rgb_p (0, 0, 100); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | nodesmap[node]->property_fill_color_gdk().set_value(color); |
---|
| 126 | } |
---|
| 127 | return 0; |
---|
| 128 | }; |
---|
| 129 | |
---|
| 130 | int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node) |
---|
| 131 | { |
---|
| 132 | |
---|
| 133 | //the number in the map will be written on the node |
---|
| 134 | //EXCEPT when the name of the map is Text, because |
---|
| 135 | //in that case empty string will be written, because |
---|
| 136 | //that is the deleter map |
---|
[31] | 137 | |
---|
[36] | 138 | Graph::NodeMap<double> * actual_map=NULL; |
---|
[35] | 139 | if(mapname!="Default") |
---|
[31] | 140 | { |
---|
| 141 | actual_map=(mapstorage.nodemap_storage)[mapname]; |
---|
| 142 | } |
---|
[28] | 143 | |
---|
| 144 | if(node==INVALID) |
---|
| 145 | { |
---|
| 146 | for (NodeIt i(g); i!=INVALID; ++i) |
---|
| 147 | { |
---|
[31] | 148 | if(mapname!="Default") |
---|
[28] | 149 | { |
---|
[35] | 150 | nodemap_to_edit=mapname; |
---|
[31] | 151 | double number=(*actual_map)[i]; |
---|
[45] | 152 | |
---|
| 153 | std::ostringstream ostr; |
---|
| 154 | ostr << number; |
---|
| 155 | |
---|
| 156 | nodetextmap[i]->property_text().set_value(ostr.str()); |
---|
[28] | 157 | } |
---|
| 158 | else |
---|
| 159 | { |
---|
[35] | 160 | nodemap_to_edit=""; |
---|
[28] | 161 | nodetextmap[i]->property_text().set_value(""); |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | } |
---|
| 165 | else |
---|
| 166 | { |
---|
[31] | 167 | if(mapname!="Default") |
---|
[28] | 168 | { |
---|
[31] | 169 | double number=(*actual_map)[node]; |
---|
[45] | 170 | |
---|
| 171 | std::ostringstream ostr; |
---|
| 172 | ostr << number; |
---|
| 173 | |
---|
| 174 | nodetextmap[node]->property_text().set_value(ostr.str()); |
---|
[28] | 175 | } |
---|
| 176 | else |
---|
| 177 | { |
---|
| 178 | nodetextmap[node]->property_text().set_value(""); |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | return 0; |
---|
| 182 | }; |
---|