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