graph_displayer_canvas-node.cc
author hegyi
Mon, 21 Nov 2005 12:07:05 +0000
branchgui
changeset 89 4042761b21e3
parent 81 5ad61c33487c
child 91 55cf06f14981
permissions -rwxr-xr-x
Reorganizing.
ladanyi@53
     1
#include "graph_displayer_canvas.h"
alpar@59
     2
#include <cmath>
hegyi@28
     3
hegyi@28
     4
alpar@62
     5
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
hegyi@28
     6
{
hegyi@31
     7
  Graph::NodeMap<double> * actual_map;
hegyi@48
     8
  double min, max;
hegyi@81
     9
  min=mapstorage.minOfNodeMap(mapname);
hegyi@81
    10
  max=mapstorage.maxOfNodeMap(mapname);
hegyi@81
    11
  actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@81
    12
hegyi@81
    13
  if(node==INVALID)
hegyi@31
    14
    {
hegyi@81
    15
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@81
    16
	{
hegyi@81
    17
	  double v=fabs((*actual_map)[i]);
hegyi@81
    18
	  int w;
hegyi@81
    19
	  if(min==max)
hegyi@81
    20
	    {
hegyi@81
    21
	      w=(int)(node_property_defaults[N_RADIUS]);
hegyi@81
    22
	    }
hegyi@81
    23
	  else
hegyi@81
    24
	    {
hegyi@81
    25
	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
hegyi@81
    26
	    }
hegyi@81
    27
	  if(w>=0)
hegyi@81
    28
	    {
hegyi@81
    29
	      double x1, y1, x2, y2;
hegyi@81
    30
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@81
    31
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@81
    32
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@81
    33
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@81
    34
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    35
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    36
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    37
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    38
	    }
hegyi@81
    39
	}
hegyi@31
    40
    }
hegyi@31
    41
  else
hegyi@31
    42
    {
hegyi@81
    43
      //I think only new nodes use this case
hegyi@81
    44
//       int w=(int)(*actual_map)[node];
hegyi@81
    45
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@81
    46
      if(w>=0)
hegyi@81
    47
	{
hegyi@81
    48
	  double x1, y1, x2, y2;
hegyi@81
    49
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@81
    50
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@81
    51
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@81
    52
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@81
    53
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    54
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    55
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    56
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    57
	}
hegyi@31
    58
    }
hegyi@81
    59
  return 0;
hegyi@81
    60
};
hegyi@31
    61
hegyi@81
    62
int GraphDisplayerCanvas::resetNodeRadius (Node node)
hegyi@81
    63
{
hegyi@81
    64
  Graph::NodeMap<double> * actual_map;
hegyi@81
    65
  double min, max;
hegyi@81
    66
  min=node_property_defaults[N_RADIUS];
hegyi@81
    67
  max=node_property_defaults[N_RADIUS];
hegyi@81
    68
  actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
hegyi@81
    69
  
hegyi@28
    70
  if(node==INVALID)
hegyi@28
    71
    {
ladanyi@53
    72
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@28
    73
	{
hegyi@55
    74
	  double v=fabs((*actual_map)[i]);
hegyi@48
    75
	  int w;
hegyi@48
    76
	  if(min==max)
hegyi@48
    77
	    {
hegyi@48
    78
	      w=(int)(node_property_defaults[N_RADIUS]);
hegyi@48
    79
	    }
hegyi@48
    80
	  else
hegyi@48
    81
	    {
hegyi@48
    82
	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
hegyi@48
    83
	    }
hegyi@28
    84
	  if(w>=0)
hegyi@28
    85
	    {
hegyi@28
    86
	      double x1, y1, x2, y2;
hegyi@31
    87
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@31
    88
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@31
    89
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@31
    90
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@28
    91
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
    92
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
    93
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
    94
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
    95
	    }
hegyi@28
    96
	}
hegyi@28
    97
    }
hegyi@28
    98
  else
hegyi@28
    99
    {
hegyi@31
   100
      //I think only new nodes use this case
hegyi@31
   101
//       int w=(int)(*actual_map)[node];
hegyi@31
   102
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@28
   103
      if(w>=0)
hegyi@28
   104
	{
hegyi@28
   105
	  double x1, y1, x2, y2;
hegyi@31
   106
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@31
   107
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@31
   108
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@31
   109
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@28
   110
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   111
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   112
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   113
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   114
	}
hegyi@28
   115
    }
hegyi@28
   116
  return 0;
hegyi@28
   117
};
hegyi@28
   118
alpar@62
   119
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
hegyi@28
   120
{  
hegyi@28
   121
hegyi@28
   122
  //function maps the range of the maximum and
hegyi@28
   123
  //the minimum of the nodemap to the range of
hegyi@28
   124
  //green in RGB
hegyi@28
   125
hegyi@31
   126
  Graph::NodeMap<double> * actual_map;
hegyi@81
   127
  actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@81
   128
hegyi@81
   129
  double max, min;
hegyi@81
   130
hegyi@81
   131
  max=mapstorage.maxOfNodeMap(mapname);
hegyi@81
   132
  min=mapstorage.minOfNodeMap(mapname);
hegyi@81
   133
hegyi@81
   134
  if(node==INVALID)
hegyi@31
   135
    {
hegyi@81
   136
hegyi@81
   137
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@81
   138
	{
hegyi@81
   139
	  Gdk::Color color;
hegyi@81
   140
hegyi@81
   141
	  double w=(*actual_map)[i];
hegyi@81
   142
hegyi@81
   143
	  if(max!=min)
hegyi@81
   144
	    {
hegyi@81
   145
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@81
   146
	    }
hegyi@81
   147
	  else
hegyi@81
   148
	    {
hegyi@81
   149
	      color.set_rgb_p (0, 0, 100);
hegyi@81
   150
	    }
hegyi@81
   151
hegyi@81
   152
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@81
   153
	}
hegyi@31
   154
    }
hegyi@31
   155
  else
hegyi@31
   156
    {
hegyi@81
   157
      Gdk::Color color;
hegyi@81
   158
hegyi@81
   159
      double w=(*actual_map)[node];
hegyi@81
   160
hegyi@81
   161
      if(max!=min)
hegyi@81
   162
	{
hegyi@81
   163
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@81
   164
	}
hegyi@81
   165
      else
hegyi@81
   166
	{
hegyi@81
   167
	  color.set_rgb_p (0, 0, 100);
hegyi@81
   168
	}
hegyi@81
   169
hegyi@81
   170
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@31
   171
    }
hegyi@81
   172
  return 0;
hegyi@81
   173
};
hegyi@81
   174
hegyi@81
   175
int GraphDisplayerCanvas::resetNodeColor (Node node)
hegyi@81
   176
{  
hegyi@81
   177
hegyi@81
   178
  //function maps the range of the maximum and
hegyi@81
   179
  //the minimum of the nodemap to the range of
hegyi@81
   180
  //green in RGB
hegyi@81
   181
hegyi@81
   182
  Graph::NodeMap<double> * actual_map;
hegyi@81
   183
  actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
hegyi@31
   184
hegyi@31
   185
  double max, min;
hegyi@31
   186
hegyi@81
   187
  max=node_property_defaults[N_COLOR];
hegyi@81
   188
  min=node_property_defaults[N_COLOR];
hegyi@31
   189
hegyi@28
   190
  if(node==INVALID)
hegyi@28
   191
    {
hegyi@28
   192
ladanyi@53
   193
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@28
   194
	{
hegyi@28
   195
	  Gdk::Color color;
hegyi@31
   196
hegyi@31
   197
	  double w=(*actual_map)[i];
hegyi@31
   198
hegyi@28
   199
	  if(max!=min)
hegyi@28
   200
	    {
hegyi@28
   201
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   202
	    }
hegyi@28
   203
	  else
hegyi@28
   204
	    {
hegyi@28
   205
	      color.set_rgb_p (0, 0, 100);
hegyi@28
   206
	    }
hegyi@28
   207
hegyi@28
   208
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
   209
	}
hegyi@28
   210
    }
hegyi@28
   211
  else
hegyi@28
   212
    {
hegyi@28
   213
      Gdk::Color color;
hegyi@31
   214
hegyi@31
   215
      double w=(*actual_map)[node];
hegyi@31
   216
hegyi@28
   217
      if(max!=min)
hegyi@28
   218
	{
hegyi@28
   219
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   220
	}
hegyi@28
   221
      else
hegyi@28
   222
	{
hegyi@28
   223
	  color.set_rgb_p (0, 0, 100);
hegyi@28
   224
	}
hegyi@28
   225
hegyi@28
   226
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@28
   227
    }
hegyi@28
   228
  return 0;
hegyi@28
   229
};
hegyi@28
   230
alpar@62
   231
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
hegyi@28
   232
{
hegyi@28
   233
hegyi@28
   234
  //the number in the map will be written on the node
hegyi@28
   235
  //EXCEPT when the name of the map is Text, because
hegyi@28
   236
  //in that case empty string will be written, because
hegyi@28
   237
  //that is the deleter map
hegyi@31
   238
hegyi@36
   239
  Graph::NodeMap<double> * actual_map=NULL;
hegyi@81
   240
  actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@28
   241
hegyi@28
   242
  if(node==INVALID)
hegyi@28
   243
    {
ladanyi@53
   244
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@28
   245
	{
hegyi@81
   246
	  nodemap_to_edit=mapname;
hegyi@81
   247
	  double number=(*actual_map)[i];
hegyi@45
   248
hegyi@81
   249
	  std::ostringstream ostr;
hegyi@81
   250
	  ostr << number;
hegyi@45
   251
	      
hegyi@81
   252
	  nodetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   253
	}
hegyi@28
   254
    }
hegyi@28
   255
  else
hegyi@28
   256
    {
hegyi@81
   257
      double number=(*actual_map)[node];
hegyi@45
   258
hegyi@81
   259
      std::ostringstream ostr;
hegyi@81
   260
      ostr << number;
hegyi@45
   261
	      
hegyi@81
   262
      nodetextmap[node]->property_text().set_value(ostr.str());
hegyi@28
   263
    }
hegyi@28
   264
  return 0;
hegyi@28
   265
};
hegyi@81
   266
hegyi@81
   267
int GraphDisplayerCanvas::resetNodeText (Node node)
hegyi@81
   268
{
hegyi@81
   269
hegyi@81
   270
  //the number in the map will be written on the node
hegyi@81
   271
  //EXCEPT when the name of the map is Text, because
hegyi@81
   272
  //in that case empty string will be written, because
hegyi@81
   273
  //that is the deleter map
hegyi@81
   274
hegyi@81
   275
  if(node==INVALID)
hegyi@81
   276
    {
hegyi@81
   277
      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@81
   278
	{
hegyi@81
   279
	  nodemap_to_edit="";
hegyi@81
   280
	  nodetextmap[i]->property_text().set_value("");
hegyi@81
   281
	}
hegyi@81
   282
    }
hegyi@81
   283
  else
hegyi@81
   284
    {
hegyi@81
   285
      nodetextmap[node]->property_text().set_value("");
hegyi@81
   286
    }
hegyi@81
   287
  return 0;
hegyi@81
   288
};