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