graph_displayer_canvas-edge.cc
author hegyi
Wed, 29 Jun 2005 19:44:30 +0000
branchgui
changeset 31 66e85f44a66f
parent 28 fa28f1071bd6
child 35 79bffdf6aea2
permissions -rwxr-xr-x
Uh, long comment arrives... Zoom update does not happen after editorial steps. Nodes initial color is light blue, if there is any item under them. Strange node-text relations disappeared. Initial values of new items are given now in a more common way. The wood-cutter way of handling default values of properties is now changed.
hegyi@27
     1
#include <graph_displayer_canvas.h>
hegyi@27
     2
#include <broken_edge.h>
hegyi@27
     3
#include <math.h>
hegyi@27
     4
hegyi@27
     5
hegyi@28
     6
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
hegyi@27
     7
{
hegyi@31
     8
  Graph::EdgeMap<double> * actual_map;
hegyi@31
     9
  if(mapname=="Default")
hegyi@31
    10
    {
hegyi@31
    11
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
hegyi@31
    12
    }
hegyi@31
    13
  else
hegyi@31
    14
    {
hegyi@31
    15
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@31
    16
    }
hegyi@31
    17
hegyi@28
    18
  if(edge==INVALID)
hegyi@27
    19
    {
hegyi@28
    20
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@28
    21
	{
hegyi@31
    22
	  int w=(int)(*actual_map)[i];
hegyi@28
    23
	  if(w>=0)
hegyi@28
    24
	    {
hegyi@28
    25
	      edgesmap[i]->property_width_pixels().set_value(w);
hegyi@28
    26
	    }
hegyi@28
    27
	}
hegyi@28
    28
    }
hegyi@28
    29
  else
hegyi@28
    30
    {
hegyi@31
    31
      int w=(int)(*actual_map)[edge];
hegyi@27
    32
      if(w>=0)
hegyi@27
    33
	{
hegyi@28
    34
	  edgesmap[edge]->property_width_pixels().set_value(w);
hegyi@27
    35
	}
hegyi@27
    36
    }
hegyi@27
    37
  return 0;
hegyi@27
    38
};
hegyi@27
    39
hegyi@28
    40
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
hegyi@27
    41
{  
hegyi@27
    42
hegyi@27
    43
  //function maps the range of the maximum and
hegyi@27
    44
  //the minimum of the nodemap to the range of
hegyi@27
    45
  //green in RGB
hegyi@31
    46
  Graph::EdgeMap<double> * actual_map;
hegyi@31
    47
  if(mapname=="Default")
hegyi@31
    48
    {
hegyi@31
    49
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
hegyi@31
    50
    }
hegyi@31
    51
  else
hegyi@31
    52
    {
hegyi@31
    53
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@31
    54
    }
hegyi@31
    55
hegyi@31
    56
  double max, min;
hegyi@31
    57
hegyi@31
    58
  if(mapname!="Default")
hegyi@31
    59
    {
hegyi@31
    60
      max=mapstorage.maxOfEdgeMap(mapname);
hegyi@31
    61
      min=mapstorage.minOfEdgeMap(mapname);
hegyi@31
    62
    }
hegyi@31
    63
  else
hegyi@31
    64
    {
hegyi@31
    65
      max=edge_property_defaults[E_COLOR];
hegyi@31
    66
      min=edge_property_defaults[E_COLOR];
hegyi@31
    67
    }
hegyi@31
    68
hegyi@28
    69
  if(edge==INVALID)
hegyi@28
    70
    {
hegyi@28
    71
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@28
    72
	{
hegyi@31
    73
	  double w=(*actual_map)[i];
hegyi@31
    74
hegyi@28
    75
	  Gdk::Color color;
hegyi@28
    76
	  if(max!=min)
hegyi@28
    77
	    {
hegyi@28
    78
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
    79
	    }
hegyi@28
    80
	  else
hegyi@28
    81
	    {
hegyi@28
    82
	      color.set_rgb_p (0, 100, 0);
hegyi@28
    83
	    }
hegyi@28
    84
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
    85
	}
hegyi@28
    86
    }
hegyi@28
    87
  else
hegyi@27
    88
    {
hegyi@28
    89
      Gdk::Color color;
hegyi@31
    90
hegyi@31
    91
      double w=(*actual_map)[edge];
hegyi@31
    92
hegyi@28
    93
      if(max!=min)
hegyi@28
    94
	{
hegyi@28
    95
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
    96
	}
hegyi@28
    97
      else
hegyi@28
    98
	{
hegyi@28
    99
	  color.set_rgb_p (0, 100, 0);
hegyi@28
   100
	}
hegyi@28
   101
hegyi@28
   102
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@27
   103
    }
hegyi@27
   104
  return 0;
hegyi@27
   105
};
hegyi@27
   106
hegyi@28
   107
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
hegyi@27
   108
{
hegyi@27
   109
hegyi@27
   110
  //the number in the map will be written on the edge
hegyi@27
   111
  //EXCEPT when the name of the map is Text, because
hegyi@27
   112
  //in that case empty string will be written, because
hegyi@27
   113
  //that is the deleter map
hegyi@27
   114
hegyi@28
   115
  if(edge==INVALID)
hegyi@27
   116
    {
hegyi@28
   117
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@27
   118
	{
hegyi@31
   119
	  if(mapname!="Default")
hegyi@28
   120
	    {
hegyi@28
   121
	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@28
   122
	      int length=1;
hegyi@28
   123
	      //if number is smaller than one, length would be negative, or invalid
hegyi@28
   124
	      if(number>=1)
hegyi@28
   125
		{
hegyi@28
   126
		  length=(int)(floor(log(number)/log(10)))+1;
hegyi@28
   127
		}
hegyi@28
   128
	      int maxpos=(int)(pow(10,length-1));
hegyi@28
   129
	      int strl=length+1+RANGE;
hegyi@28
   130
	      char * str=new char[strl];
hegyi@28
   131
	      str[length]='.';
hegyi@28
   132
	      str[strl]='\0';
hegyi@28
   133
      
hegyi@28
   134
	      for(int j=0;j<strl;j++)
hegyi@28
   135
		{
hegyi@28
   136
		  if(j!=length)
hegyi@28
   137
		    {
hegyi@28
   138
		      int digit=(int)(number/maxpos);
hegyi@28
   139
		      str[j]=(digit+'0');
hegyi@28
   140
		      number-=digit*maxpos;
hegyi@28
   141
		      number*=10;
hegyi@28
   142
		    }
hegyi@28
   143
		}
hegyi@28
   144
      
hegyi@28
   145
	      edgetextmap[i]->property_text().set_value(str);
hegyi@28
   146
	    }
hegyi@28
   147
	  else
hegyi@28
   148
	    {
hegyi@28
   149
	      edgetextmap[i]->property_text().set_value("");
hegyi@28
   150
	    }
hegyi@28
   151
	}
hegyi@28
   152
hegyi@28
   153
    }
hegyi@28
   154
  else
hegyi@28
   155
    {
hegyi@31
   156
      if(mapname!="Default")
hegyi@28
   157
	{
hegyi@28
   158
	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
hegyi@27
   159
	  int length=1;
hegyi@27
   160
	  //if number is smaller than one, length would be negative, or invalid
hegyi@27
   161
	  if(number>=1)
hegyi@27
   162
	    {
hegyi@27
   163
	      length=(int)(floor(log(number)/log(10)))+1;
hegyi@27
   164
	    }
hegyi@27
   165
	  int maxpos=(int)(pow(10,length-1));
hegyi@27
   166
	  int strl=length+1+RANGE;
hegyi@27
   167
	  char * str=new char[strl];
hegyi@27
   168
	  str[length]='.';
hegyi@27
   169
	  str[strl]='\0';
hegyi@27
   170
      
hegyi@27
   171
	  for(int j=0;j<strl;j++)
hegyi@27
   172
	    {
hegyi@27
   173
	      if(j!=length)
hegyi@27
   174
		{
hegyi@27
   175
		  int digit=(int)(number/maxpos);
hegyi@27
   176
		  str[j]=(digit+'0');
hegyi@27
   177
		  number-=digit*maxpos;
hegyi@27
   178
		  number*=10;
hegyi@27
   179
		}
hegyi@27
   180
	    }
hegyi@27
   181
      
hegyi@28
   182
	  edgetextmap[edge]->property_text().set_value(str);
hegyi@27
   183
	}
hegyi@27
   184
      else
hegyi@27
   185
	{
hegyi@28
   186
	  edgetextmap[edge]->property_text().set_value("");
hegyi@27
   187
	}
hegyi@28
   188
	  
hegyi@27
   189
    }
hegyi@28
   190
hegyi@27
   191
  return 0;
hegyi@28
   192
hegyi@27
   193
};