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