gui/graph_displayer_canvas-edge.cc
author hegyi
Fri, 22 Jul 2005 11:04:27 +0000
changeset 1581 9bb83c7f479b
parent 1579 ed7da82bbecf
child 1589 9192e1b26d32
permissions -rwxr-xr-x
There were bugs, created yesterday, and there is still one. (I hope only one :) )
hegyi@1510
     1
#include <graph_displayer_canvas.h>
hegyi@1510
     2
#include <broken_edge.h>
hegyi@1510
     3
#include <math.h>
hegyi@1510
     4
hegyi@1510
     5
hegyi@1512
     6
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
hegyi@1510
     7
{
hegyi@1525
     8
  Graph::EdgeMap<double> * actual_map;
hegyi@1525
     9
  if(mapname=="Default")
hegyi@1525
    10
    {
hegyi@1525
    11
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
hegyi@1525
    12
    }
hegyi@1525
    13
  else
hegyi@1525
    14
    {
hegyi@1525
    15
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@1525
    16
    }
hegyi@1525
    17
hegyi@1512
    18
  if(edge==INVALID)
hegyi@1510
    19
    {
hegyi@1512
    20
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1512
    21
	{
hegyi@1525
    22
	  int w=(int)(*actual_map)[i];
hegyi@1512
    23
	  if(w>=0)
hegyi@1512
    24
	    {
hegyi@1512
    25
	      edgesmap[i]->property_width_pixels().set_value(w);
hegyi@1512
    26
	    }
hegyi@1512
    27
	}
hegyi@1512
    28
    }
hegyi@1512
    29
  else
hegyi@1512
    30
    {
hegyi@1525
    31
      int w=(int)(*actual_map)[edge];
hegyi@1510
    32
      if(w>=0)
hegyi@1510
    33
	{
hegyi@1512
    34
	  edgesmap[edge]->property_width_pixels().set_value(w);
hegyi@1510
    35
	}
hegyi@1510
    36
    }
hegyi@1510
    37
  return 0;
hegyi@1510
    38
};
hegyi@1510
    39
hegyi@1512
    40
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
hegyi@1510
    41
{  
hegyi@1510
    42
hegyi@1510
    43
  //function maps the range of the maximum and
hegyi@1510
    44
  //the minimum of the nodemap to the range of
hegyi@1510
    45
  //green in RGB
hegyi@1525
    46
  Graph::EdgeMap<double> * actual_map;
hegyi@1525
    47
  if(mapname=="Default")
hegyi@1525
    48
    {
hegyi@1525
    49
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
hegyi@1525
    50
    }
hegyi@1525
    51
  else
hegyi@1525
    52
    {
hegyi@1525
    53
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@1525
    54
    }
hegyi@1525
    55
hegyi@1525
    56
  double max, min;
hegyi@1525
    57
hegyi@1525
    58
  if(mapname!="Default")
hegyi@1525
    59
    {
hegyi@1525
    60
      max=mapstorage.maxOfEdgeMap(mapname);
hegyi@1525
    61
      min=mapstorage.minOfEdgeMap(mapname);
hegyi@1525
    62
    }
hegyi@1525
    63
  else
hegyi@1525
    64
    {
hegyi@1525
    65
      max=edge_property_defaults[E_COLOR];
hegyi@1525
    66
      min=edge_property_defaults[E_COLOR];
hegyi@1525
    67
    }
hegyi@1525
    68
hegyi@1512
    69
  if(edge==INVALID)
hegyi@1512
    70
    {
hegyi@1512
    71
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1512
    72
	{
hegyi@1525
    73
	  double w=(*actual_map)[i];
hegyi@1525
    74
hegyi@1512
    75
	  Gdk::Color color;
hegyi@1512
    76
	  if(max!=min)
hegyi@1512
    77
	    {
hegyi@1512
    78
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1512
    79
	    }
hegyi@1512
    80
	  else
hegyi@1512
    81
	    {
hegyi@1512
    82
	      color.set_rgb_p (0, 100, 0);
hegyi@1512
    83
	    }
hegyi@1512
    84
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@1512
    85
	}
hegyi@1512
    86
    }
hegyi@1512
    87
  else
hegyi@1510
    88
    {
hegyi@1512
    89
      Gdk::Color color;
hegyi@1525
    90
hegyi@1525
    91
      double w=(*actual_map)[edge];
hegyi@1525
    92
hegyi@1512
    93
      if(max!=min)
hegyi@1512
    94
	{
hegyi@1512
    95
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1512
    96
	}
hegyi@1512
    97
      else
hegyi@1512
    98
	{
hegyi@1512
    99
	  color.set_rgb_p (0, 100, 0);
hegyi@1512
   100
	}
hegyi@1512
   101
hegyi@1512
   102
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@1510
   103
    }
hegyi@1510
   104
  return 0;
hegyi@1510
   105
};
hegyi@1510
   106
hegyi@1512
   107
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
hegyi@1510
   108
{
hegyi@1510
   109
hegyi@1510
   110
  //the number in the map will be written on the edge
hegyi@1510
   111
  //EXCEPT when the name of the map is Text, because
hegyi@1510
   112
  //in that case empty string will be written, because
hegyi@1510
   113
  //that is the deleter map
hegyi@1510
   114
hegyi@1512
   115
  if(edge==INVALID)
hegyi@1510
   116
    {
hegyi@1512
   117
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1510
   118
	{
hegyi@1525
   119
	  if(mapname!="Default")
hegyi@1512
   120
	    {
hegyi@1579
   121
	      edgemap_to_edit=mapname;
hegyi@1512
   122
	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@1512
   123
	      int length=1;
hegyi@1512
   124
	      //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   125
	      if(number>=1)
hegyi@1512
   126
		{
hegyi@1512
   127
		  length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   128
		}
hegyi@1512
   129
	      int maxpos=(int)(pow(10,length-1));
hegyi@1512
   130
	      int strl=length+1+RANGE;
hegyi@1512
   131
	      char * str=new char[strl];
hegyi@1512
   132
	      str[length]='.';
hegyi@1512
   133
	      str[strl]='\0';
hegyi@1512
   134
      
hegyi@1512
   135
	      for(int j=0;j<strl;j++)
hegyi@1512
   136
		{
hegyi@1512
   137
		  if(j!=length)
hegyi@1512
   138
		    {
hegyi@1581
   139
		      if((number-(int)number)>ALMOST_ONE)
hegyi@1581
   140
			{
hegyi@1581
   141
			  number=round(number);
hegyi@1581
   142
			}
hegyi@1512
   143
		      int digit=(int)(number/maxpos);
hegyi@1512
   144
		      str[j]=(digit+'0');
hegyi@1512
   145
		      number-=digit*maxpos;
hegyi@1512
   146
		      number*=10;
hegyi@1512
   147
		    }
hegyi@1512
   148
		}
hegyi@1512
   149
      
hegyi@1512
   150
	      edgetextmap[i]->property_text().set_value(str);
hegyi@1512
   151
	    }
hegyi@1512
   152
	  else
hegyi@1512
   153
	    {
hegyi@1579
   154
	      edgemap_to_edit="";
hegyi@1512
   155
	      edgetextmap[i]->property_text().set_value("");
hegyi@1512
   156
	    }
hegyi@1512
   157
	}
hegyi@1512
   158
hegyi@1512
   159
    }
hegyi@1512
   160
  else
hegyi@1512
   161
    {
hegyi@1525
   162
      if(mapname!="Default")
hegyi@1512
   163
	{
hegyi@1512
   164
	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
hegyi@1510
   165
	  int length=1;
hegyi@1510
   166
	  //if number is smaller than one, length would be negative, or invalid
hegyi@1510
   167
	  if(number>=1)
hegyi@1510
   168
	    {
hegyi@1510
   169
	      length=(int)(floor(log(number)/log(10)))+1;
hegyi@1510
   170
	    }
hegyi@1510
   171
	  int maxpos=(int)(pow(10,length-1));
hegyi@1510
   172
	  int strl=length+1+RANGE;
hegyi@1510
   173
	  char * str=new char[strl];
hegyi@1510
   174
	  str[length]='.';
hegyi@1510
   175
	  str[strl]='\0';
hegyi@1510
   176
      
hegyi@1510
   177
	  for(int j=0;j<strl;j++)
hegyi@1510
   178
	    {
hegyi@1510
   179
	      if(j!=length)
hegyi@1510
   180
		{
hegyi@1581
   181
		  if((number-(int)number)>ALMOST_ONE)
hegyi@1581
   182
		    {
hegyi@1581
   183
		      number=round(number);
hegyi@1581
   184
		    }
hegyi@1510
   185
		  int digit=(int)(number/maxpos);
hegyi@1510
   186
		  str[j]=(digit+'0');
hegyi@1510
   187
		  number-=digit*maxpos;
hegyi@1510
   188
		  number*=10;
hegyi@1510
   189
		}
hegyi@1510
   190
	    }
hegyi@1510
   191
      
hegyi@1512
   192
	  edgetextmap[edge]->property_text().set_value(str);
hegyi@1510
   193
	}
hegyi@1510
   194
      else
hegyi@1510
   195
	{
hegyi@1512
   196
	  edgetextmap[edge]->property_text().set_value("");
hegyi@1510
   197
	}
hegyi@1512
   198
	  
hegyi@1510
   199
    }
hegyi@1512
   200
hegyi@1510
   201
  return 0;
hegyi@1512
   202
hegyi@1510
   203
};