graph_displayer_canvas-edge.cc
author hegyi
Thu, 05 Jan 2006 12:30:09 +0000
branchgui
changeset 108 bf355fd6563e
parent 94 adfdc2f70548
child 147 10ef59f6633c
permissions -rwxr-xr-x
Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
ladanyi@53
     1
#include "graph_displayer_canvas.h"
alpar@59
     2
#include <cmath>
hegyi@27
     3
hegyi@27
     4
hegyi@81
     5
int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
hegyi@81
     6
{
hegyi@81
     7
  double min, max;
hegyi@81
     8
hegyi@81
     9
  min=edge_property_defaults[E_WIDTH];
hegyi@81
    10
  max=edge_property_defaults[E_WIDTH];
hegyi@96
    11
  Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]);
hegyi@81
    12
  
hegyi@81
    13
  if(edge==INVALID)
hegyi@81
    14
    {
hegyi@96
    15
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@81
    16
	{
ladanyi@91
    17
	  double v=fabs(actual_map[i]);
hegyi@81
    18
	  int w;
hegyi@81
    19
	  if(min==max)
hegyi@81
    20
	    {
hegyi@81
    21
	      w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@81
    22
	    }
hegyi@81
    23
	  else
hegyi@81
    24
	    {
hegyi@81
    25
	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
hegyi@81
    26
	    }
hegyi@81
    27
	  edgesmap[i]->property_width_units().set_value(w);
hegyi@81
    28
	}
hegyi@81
    29
    }
hegyi@81
    30
  else
hegyi@81
    31
    {
ladanyi@91
    32
      int w=(int)actual_map[edge];
hegyi@81
    33
      if(w>=0)
hegyi@81
    34
	{
hegyi@81
    35
	  edgesmap[edge]->property_width_units().set_value(w);
hegyi@81
    36
	}
hegyi@81
    37
    }
hegyi@81
    38
  return 0;
hegyi@81
    39
}
hegyi@81
    40
hegyi@81
    41
alpar@62
    42
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
hegyi@27
    43
{
hegyi@31
    44
  Graph::EdgeMap<double> * actual_map;
hegyi@48
    45
  double min, max;
hegyi@48
    46
hegyi@96
    47
  min=(mytab.mapstorage).minOfEdgeMap(mapname);
hegyi@96
    48
  max=(mytab.mapstorage).maxOfEdgeMap(mapname);
hegyi@96
    49
  actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
hegyi@31
    50
hegyi@28
    51
  if(edge==INVALID)
hegyi@27
    52
    {
hegyi@96
    53
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@28
    54
	{
hegyi@55
    55
	  double v=fabs((*actual_map)[i]);
hegyi@48
    56
	  int w;
hegyi@48
    57
	  if(min==max)
hegyi@28
    58
	    {
hegyi@48
    59
	      w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@28
    60
	    }
hegyi@48
    61
	  else
hegyi@48
    62
	    {
hegyi@48
    63
	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
hegyi@48
    64
	    }
hegyi@48
    65
	  edgesmap[i]->property_width_units().set_value(w);
hegyi@28
    66
	}
hegyi@28
    67
    }
hegyi@28
    68
  else
hegyi@28
    69
    {
hegyi@31
    70
      int w=(int)(*actual_map)[edge];
hegyi@27
    71
      if(w>=0)
hegyi@27
    72
	{
hegyi@47
    73
	  edgesmap[edge]->property_width_units().set_value(w);
hegyi@27
    74
	}
hegyi@27
    75
    }
hegyi@27
    76
  return 0;
hegyi@27
    77
};
hegyi@27
    78
alpar@62
    79
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
hegyi@27
    80
{  
hegyi@27
    81
hegyi@27
    82
  //function maps the range of the maximum and
hegyi@27
    83
  //the minimum of the nodemap to the range of
hegyi@27
    84
  //green in RGB
hegyi@31
    85
  Graph::EdgeMap<double> * actual_map;
hegyi@96
    86
  actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
hegyi@81
    87
hegyi@81
    88
  double max, min;
hegyi@81
    89
hegyi@96
    90
  max=(mytab.mapstorage).maxOfEdgeMap(mapname);
hegyi@96
    91
  min=(mytab.mapstorage).minOfEdgeMap(mapname);
hegyi@81
    92
hegyi@81
    93
  if(edge==INVALID)
hegyi@31
    94
    {
hegyi@96
    95
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@81
    96
	{
hegyi@81
    97
	  double w=(*actual_map)[i];
hegyi@81
    98
hegyi@81
    99
	  Gdk::Color color;
hegyi@81
   100
	  if(max!=min)
hegyi@81
   101
	    {
hegyi@81
   102
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@81
   103
	    }
hegyi@81
   104
	  else
hegyi@81
   105
	    {
hegyi@81
   106
	      color.set_rgb_p (0, 100, 0);
hegyi@81
   107
	    }
hegyi@81
   108
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@81
   109
	}
hegyi@31
   110
    }
hegyi@31
   111
  else
hegyi@31
   112
    {
hegyi@81
   113
      Gdk::Color color;
hegyi@81
   114
hegyi@81
   115
      double w=(*actual_map)[edge];
hegyi@81
   116
hegyi@81
   117
      if(max!=min)
hegyi@81
   118
	{
hegyi@81
   119
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@81
   120
	}
hegyi@81
   121
      else
hegyi@81
   122
	{
hegyi@81
   123
	  color.set_rgb_p (0, 100, 0);
hegyi@81
   124
	}
hegyi@81
   125
hegyi@81
   126
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@31
   127
    }
hegyi@81
   128
  return 0;
hegyi@81
   129
};
hegyi@81
   130
hegyi@81
   131
int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
hegyi@81
   132
{  
hegyi@81
   133
hegyi@81
   134
  //function maps the range of the maximum and
hegyi@81
   135
  //the minimum of the nodemap to the range of
hegyi@81
   136
  //green in RGB
hegyi@96
   137
  Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
hegyi@31
   138
hegyi@31
   139
  double max, min;
hegyi@31
   140
hegyi@81
   141
  max=edge_property_defaults[E_COLOR];
hegyi@81
   142
  min=edge_property_defaults[E_COLOR];
hegyi@31
   143
hegyi@28
   144
  if(edge==INVALID)
hegyi@28
   145
    {
hegyi@96
   146
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@28
   147
	{
ladanyi@91
   148
	  double w=actual_map[i];
hegyi@31
   149
hegyi@28
   150
	  Gdk::Color color;
hegyi@28
   151
	  if(max!=min)
hegyi@28
   152
	    {
hegyi@28
   153
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
   154
	    }
hegyi@28
   155
	  else
hegyi@28
   156
	    {
hegyi@28
   157
	      color.set_rgb_p (0, 100, 0);
hegyi@28
   158
	    }
hegyi@28
   159
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
   160
	}
hegyi@28
   161
    }
hegyi@28
   162
  else
hegyi@27
   163
    {
hegyi@28
   164
      Gdk::Color color;
hegyi@31
   165
ladanyi@91
   166
      double w=actual_map[edge];
hegyi@31
   167
hegyi@28
   168
      if(max!=min)
hegyi@28
   169
	{
hegyi@28
   170
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
   171
	}
hegyi@28
   172
      else
hegyi@28
   173
	{
hegyi@28
   174
	  color.set_rgb_p (0, 100, 0);
hegyi@28
   175
	}
hegyi@28
   176
hegyi@28
   177
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@27
   178
    }
hegyi@27
   179
  return 0;
hegyi@27
   180
};
hegyi@27
   181
alpar@62
   182
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
hegyi@27
   183
{
hegyi@27
   184
  //the number in the map will be written on the edge
hegyi@40
   185
  //EXCEPT when the name of the map is Default, because
hegyi@27
   186
  //in that case empty string will be written, because
hegyi@27
   187
  //that is the deleter map
ladanyi@63
   188
  
hegyi@28
   189
  if(edge==INVALID)
hegyi@27
   190
    {
hegyi@96
   191
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@27
   192
	{
hegyi@81
   193
	  edgemap_to_edit=mapname;
hegyi@96
   194
	  double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
hegyi@81
   195
	  
hegyi@81
   196
	  std::ostringstream ostr;
hegyi@81
   197
	  ostr << number;
hegyi@81
   198
	  
hegyi@81
   199
	  edgetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   200
	}
hegyi@28
   201
hegyi@28
   202
    }
hegyi@28
   203
  else
hegyi@28
   204
    {
hegyi@96
   205
	  double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
hegyi@45
   206
hegyi@45
   207
	  std::ostringstream ostr;
hegyi@45
   208
	  ostr << number;
hegyi@45
   209
	  
hegyi@45
   210
	  edgetextmap[edge]->property_text().set_value(ostr.str());
hegyi@27
   211
    }
hegyi@28
   212
hegyi@27
   213
  return 0;
hegyi@28
   214
hegyi@27
   215
};
hegyi@81
   216
hegyi@81
   217
int GraphDisplayerCanvas::resetEdgeText (Edge edge)
hegyi@81
   218
{
hegyi@81
   219
  //the number in the map will be written on the edge
hegyi@81
   220
  //EXCEPT when the name of the map is Default, because
hegyi@81
   221
  //in that case empty string will be written, because
hegyi@81
   222
  //that is the deleter map
hegyi@81
   223
  
hegyi@81
   224
  if(edge==INVALID)
hegyi@81
   225
    {
hegyi@96
   226
      for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@81
   227
	{
hegyi@81
   228
	  edgemap_to_edit="";
hegyi@81
   229
	  edgetextmap[i]->property_text().set_value("");
hegyi@81
   230
	}
hegyi@81
   231
hegyi@81
   232
    }
hegyi@81
   233
  else
hegyi@81
   234
    {
hegyi@81
   235
      edgetextmap[edge]->property_text().set_value("");
hegyi@81
   236
    }
hegyi@81
   237
hegyi@81
   238
  return 0;
hegyi@81
   239
hegyi@81
   240
};