gui/graph_displayer_canvas-node.cc
author hegyi
Tue, 12 Jul 2005 18:21:49 +0000
changeset 1550 4dcbb4ab1d7a
parent 1512 e54392395480
child 1579 ed7da82bbecf
permissions -rwxr-xr-x
Editors are based.
hegyi@1512
     1
#include <graph_displayer_canvas.h>
hegyi@1512
     2
#include <broken_edge.h>
hegyi@1512
     3
#include <math.h>
hegyi@1512
     4
hegyi@1512
     5
hegyi@1512
     6
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
hegyi@1512
     7
{
hegyi@1525
     8
  Graph::NodeMap<double> * actual_map;
hegyi@1525
     9
  if(mapname=="Default")
hegyi@1525
    10
    {
hegyi@1525
    11
      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
hegyi@1525
    12
    }
hegyi@1525
    13
  else
hegyi@1525
    14
    {
hegyi@1525
    15
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@1525
    16
    }
hegyi@1525
    17
hegyi@1512
    18
  if(node==INVALID)
hegyi@1512
    19
    {
hegyi@1512
    20
      for (NodeIt 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
	      double x1, y1, x2, y2;
hegyi@1525
    26
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@1525
    27
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@1525
    28
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@1525
    29
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@1512
    30
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@1512
    31
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@1512
    32
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@1512
    33
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@1512
    34
	    }
hegyi@1512
    35
	}
hegyi@1512
    36
    }
hegyi@1512
    37
  else
hegyi@1512
    38
    {
hegyi@1525
    39
      //I think only new nodes use this case
hegyi@1525
    40
//       int w=(int)(*actual_map)[node];
hegyi@1525
    41
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@1512
    42
      if(w>=0)
hegyi@1512
    43
	{
hegyi@1512
    44
	  double x1, y1, x2, y2;
hegyi@1525
    45
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@1525
    46
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@1525
    47
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@1525
    48
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@1512
    49
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@1512
    50
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@1512
    51
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@1512
    52
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@1512
    53
	}
hegyi@1512
    54
    }
hegyi@1512
    55
  return 0;
hegyi@1512
    56
};
hegyi@1512
    57
hegyi@1512
    58
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
hegyi@1512
    59
{  
hegyi@1512
    60
hegyi@1512
    61
  //function maps the range of the maximum and
hegyi@1512
    62
  //the minimum of the nodemap to the range of
hegyi@1512
    63
  //green in RGB
hegyi@1512
    64
hegyi@1525
    65
  Graph::NodeMap<double> * actual_map;
hegyi@1525
    66
  if(mapname=="Default")
hegyi@1525
    67
    {
hegyi@1525
    68
      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
hegyi@1525
    69
    }
hegyi@1525
    70
  else
hegyi@1525
    71
    {
hegyi@1525
    72
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@1525
    73
    }
hegyi@1525
    74
hegyi@1525
    75
  double max, min;
hegyi@1525
    76
hegyi@1525
    77
  if(mapname!="Default")
hegyi@1525
    78
    {
hegyi@1525
    79
      max=mapstorage.maxOfNodeMap(mapname);
hegyi@1525
    80
      min=mapstorage.minOfNodeMap(mapname);
hegyi@1525
    81
    }
hegyi@1525
    82
  else
hegyi@1525
    83
    {
hegyi@1525
    84
      max=node_property_defaults[N_COLOR];
hegyi@1525
    85
      min=node_property_defaults[N_COLOR];
hegyi@1525
    86
    }
hegyi@1525
    87
hegyi@1525
    88
hegyi@1512
    89
  if(node==INVALID)
hegyi@1512
    90
    {
hegyi@1512
    91
hegyi@1512
    92
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@1512
    93
	{
hegyi@1512
    94
	  Gdk::Color color;
hegyi@1525
    95
hegyi@1525
    96
	  double w=(*actual_map)[i];
hegyi@1525
    97
hegyi@1512
    98
	  if(max!=min)
hegyi@1512
    99
	    {
hegyi@1512
   100
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@1512
   101
	    }
hegyi@1512
   102
	  else
hegyi@1512
   103
	    {
hegyi@1512
   104
	      color.set_rgb_p (0, 0, 100);
hegyi@1512
   105
	    }
hegyi@1512
   106
hegyi@1512
   107
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@1512
   108
	}
hegyi@1512
   109
    }
hegyi@1512
   110
  else
hegyi@1512
   111
    {
hegyi@1512
   112
      Gdk::Color color;
hegyi@1525
   113
hegyi@1525
   114
      double w=(*actual_map)[node];
hegyi@1525
   115
hegyi@1512
   116
      if(max!=min)
hegyi@1512
   117
	{
hegyi@1512
   118
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@1512
   119
	}
hegyi@1512
   120
      else
hegyi@1512
   121
	{
hegyi@1512
   122
	  color.set_rgb_p (0, 0, 100);
hegyi@1512
   123
	}
hegyi@1512
   124
hegyi@1512
   125
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@1512
   126
    }
hegyi@1512
   127
  return 0;
hegyi@1512
   128
};
hegyi@1512
   129
hegyi@1512
   130
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
hegyi@1512
   131
{
hegyi@1512
   132
hegyi@1512
   133
  //the number in the map will be written on the node
hegyi@1512
   134
  //EXCEPT when the name of the map is Text, because
hegyi@1512
   135
  //in that case empty string will be written, because
hegyi@1512
   136
  //that is the deleter map
hegyi@1525
   137
hegyi@1525
   138
  Graph::NodeMap<double> * actual_map;
hegyi@1525
   139
  if(mapname=="Default")
hegyi@1525
   140
    {
hegyi@1525
   141
      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
hegyi@1525
   142
    }
hegyi@1525
   143
  else
hegyi@1525
   144
    {
hegyi@1525
   145
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@1525
   146
    }
hegyi@1512
   147
hegyi@1512
   148
  if(node==INVALID)
hegyi@1512
   149
    {
hegyi@1512
   150
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@1512
   151
	{
hegyi@1525
   152
	  if(mapname!="Default")
hegyi@1512
   153
	    {
hegyi@1525
   154
	      double number=(*actual_map)[i];
hegyi@1512
   155
	      int length=1;
hegyi@1512
   156
	      //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   157
	      if(number>=1)
hegyi@1512
   158
		{
hegyi@1512
   159
		  length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   160
		}
hegyi@1512
   161
	      int maxpos=(int)(pow(10,length-1));
hegyi@1512
   162
	      int strl=length+1+RANGE;
hegyi@1512
   163
	      char * str=new char[strl];
hegyi@1512
   164
	      str[length]='.';
hegyi@1512
   165
	      str[strl]='\0';
hegyi@1512
   166
      
hegyi@1512
   167
	      for(int j=0;j<strl;j++)
hegyi@1512
   168
		{
hegyi@1512
   169
		  if(j!=length)
hegyi@1512
   170
		    {
hegyi@1512
   171
		      int digit=(int)(number/maxpos);
hegyi@1512
   172
		      str[j]=(digit+'0');
hegyi@1512
   173
		      number-=digit*maxpos;
hegyi@1512
   174
		      number*=10;
hegyi@1512
   175
		    }
hegyi@1512
   176
		}
hegyi@1512
   177
      
hegyi@1512
   178
	      nodetextmap[i]->property_text().set_value(str);
hegyi@1512
   179
	    }
hegyi@1512
   180
	  else
hegyi@1512
   181
	    {
hegyi@1512
   182
	      nodetextmap[i]->property_text().set_value("");
hegyi@1512
   183
	    }
hegyi@1512
   184
	}
hegyi@1512
   185
    }
hegyi@1512
   186
  else
hegyi@1512
   187
    {
hegyi@1525
   188
      if(mapname!="Default")
hegyi@1512
   189
	{
hegyi@1525
   190
	  double number=(*actual_map)[node];
hegyi@1512
   191
	  int length=1;
hegyi@1512
   192
	  //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   193
	  if(number>=1)
hegyi@1512
   194
	    {
hegyi@1512
   195
	      length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   196
	    }
hegyi@1512
   197
	  int maxpos=(int)(pow(10,length-1));
hegyi@1512
   198
	  int strl=length+1+RANGE;
hegyi@1512
   199
	  char * str=new char[strl];
hegyi@1512
   200
	  str[length]='.';
hegyi@1512
   201
	  str[strl]='\0';
hegyi@1512
   202
      
hegyi@1512
   203
	  for(int j=0;j<strl;j++)
hegyi@1512
   204
	    {
hegyi@1512
   205
	      if(j!=length)
hegyi@1512
   206
		{
hegyi@1512
   207
		  int digit=(int)(number/maxpos);
hegyi@1512
   208
		  str[j]=(digit+'0');
hegyi@1512
   209
		  number-=digit*maxpos;
hegyi@1512
   210
		  number*=10;
hegyi@1512
   211
		}
hegyi@1512
   212
	    }
hegyi@1512
   213
      
hegyi@1512
   214
	  nodetextmap[node]->property_text().set_value(str);
hegyi@1512
   215
	}
hegyi@1512
   216
      else
hegyi@1512
   217
	{
hegyi@1512
   218
	  nodetextmap[node]->property_text().set_value("");
hegyi@1512
   219
	}
hegyi@1512
   220
    }
hegyi@1512
   221
  return 0;
hegyi@1512
   222
};