graph_displayer_canvas-node.cc
author hegyi
Wed, 27 Jul 2005 11:19:35 +0000
branchgui
changeset 45 199f433eb7cd
parent 36 7a8c41aa3c29
child 48 b8ec84524fa2
permissions -rwxr-xr-x
Sorry for the previous commit, it was not ready yet, but that damned up arrow... So in this new revision string-double and double-string conversion is corrected to a more C++ way.
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@36
   138
  Graph::NodeMap<double> * actual_map=NULL;
hegyi@35
   139
  if(mapname!="Default")
hegyi@31
   140
    {
hegyi@31
   141
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@31
   142
    }
hegyi@28
   143
hegyi@28
   144
  if(node==INVALID)
hegyi@28
   145
    {
hegyi@28
   146
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@28
   147
	{
hegyi@31
   148
	  if(mapname!="Default")
hegyi@28
   149
	    {
hegyi@35
   150
	      nodemap_to_edit=mapname;
hegyi@31
   151
	      double number=(*actual_map)[i];
hegyi@45
   152
hegyi@45
   153
	      std::ostringstream ostr;
hegyi@45
   154
	      ostr << number;
hegyi@45
   155
	      
hegyi@45
   156
      	      nodetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   157
	    }
hegyi@28
   158
	  else
hegyi@28
   159
	    {
hegyi@35
   160
	      nodemap_to_edit="";
hegyi@28
   161
	      nodetextmap[i]->property_text().set_value("");
hegyi@28
   162
	    }
hegyi@28
   163
	}
hegyi@28
   164
    }
hegyi@28
   165
  else
hegyi@28
   166
    {
hegyi@31
   167
      if(mapname!="Default")
hegyi@28
   168
	{
hegyi@31
   169
	  double number=(*actual_map)[node];
hegyi@45
   170
hegyi@45
   171
	  std::ostringstream ostr;
hegyi@45
   172
	  ostr << number;
hegyi@45
   173
	      
hegyi@45
   174
	  nodetextmap[node]->property_text().set_value(ostr.str());
hegyi@28
   175
	}
hegyi@28
   176
      else
hegyi@28
   177
	{
hegyi@28
   178
	  nodetextmap[node]->property_text().set_value("");
hegyi@28
   179
	}
hegyi@28
   180
    }
hegyi@28
   181
  return 0;
hegyi@28
   182
};