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