gui/graph_displayer_canvas-node.cc
author hegyi
Thu, 21 Jul 2005 19:28:29 +0000
changeset 1579 ed7da82bbecf
parent 1525 6d94de269ab1
child 1581 9bb83c7f479b
permissions -rwxr-xr-x
Edge and nodemap edition is done.
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@1579
   139
  if(mapname!="Default")
hegyi@1525
   140
    {
hegyi@1525
   141
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@1525
   142
    }
hegyi@1512
   143
hegyi@1512
   144
  if(node==INVALID)
hegyi@1512
   145
    {
hegyi@1512
   146
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@1512
   147
	{
hegyi@1525
   148
	  if(mapname!="Default")
hegyi@1512
   149
	    {
hegyi@1579
   150
	      nodemap_to_edit=mapname;
hegyi@1525
   151
	      double number=(*actual_map)[i];
hegyi@1512
   152
	      int length=1;
hegyi@1512
   153
	      //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   154
	      if(number>=1)
hegyi@1512
   155
		{
hegyi@1512
   156
		  length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   157
		}
hegyi@1512
   158
	      int maxpos=(int)(pow(10,length-1));
hegyi@1512
   159
	      int strl=length+1+RANGE;
hegyi@1512
   160
	      char * str=new char[strl];
hegyi@1512
   161
	      str[length]='.';
hegyi@1512
   162
	      str[strl]='\0';
hegyi@1512
   163
      
hegyi@1512
   164
	      for(int j=0;j<strl;j++)
hegyi@1512
   165
		{
hegyi@1512
   166
		  if(j!=length)
hegyi@1512
   167
		    {
hegyi@1579
   168
 		      int digit=(int)round(number/maxpos);
hegyi@1512
   169
		      str[j]=(digit+'0');
hegyi@1512
   170
		      number-=digit*maxpos;
hegyi@1512
   171
		      number*=10;
hegyi@1512
   172
		    }
hegyi@1512
   173
		}
hegyi@1512
   174
      
hegyi@1512
   175
	      nodetextmap[i]->property_text().set_value(str);
hegyi@1512
   176
	    }
hegyi@1512
   177
	  else
hegyi@1512
   178
	    {
hegyi@1579
   179
	      nodemap_to_edit="";
hegyi@1512
   180
	      nodetextmap[i]->property_text().set_value("");
hegyi@1512
   181
	    }
hegyi@1512
   182
	}
hegyi@1512
   183
    }
hegyi@1512
   184
  else
hegyi@1512
   185
    {
hegyi@1525
   186
      if(mapname!="Default")
hegyi@1512
   187
	{
hegyi@1525
   188
	  double number=(*actual_map)[node];
hegyi@1512
   189
	  int length=1;
hegyi@1512
   190
	  //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   191
	  if(number>=1)
hegyi@1512
   192
	    {
hegyi@1512
   193
	      length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   194
	    }
hegyi@1512
   195
	  int maxpos=(int)(pow(10,length-1));
hegyi@1512
   196
	  int strl=length+1+RANGE;
hegyi@1512
   197
	  char * str=new char[strl];
hegyi@1512
   198
	  str[length]='.';
hegyi@1512
   199
	  str[strl]='\0';
hegyi@1512
   200
      
hegyi@1512
   201
	  for(int j=0;j<strl;j++)
hegyi@1512
   202
	    {
hegyi@1512
   203
	      if(j!=length)
hegyi@1512
   204
		{
hegyi@1512
   205
		  int digit=(int)(number/maxpos);
hegyi@1512
   206
		  str[j]=(digit+'0');
hegyi@1512
   207
		  number-=digit*maxpos;
hegyi@1512
   208
		  number*=10;
hegyi@1512
   209
		}
hegyi@1512
   210
	    }
hegyi@1512
   211
      
hegyi@1512
   212
	  nodetextmap[node]->property_text().set_value(str);
hegyi@1512
   213
	}
hegyi@1512
   214
      else
hegyi@1512
   215
	{
hegyi@1512
   216
	  nodetextmap[node]->property_text().set_value("");
hegyi@1512
   217
	}
hegyi@1512
   218
    }
hegyi@1512
   219
  return 0;
hegyi@1512
   220
};