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