graph_displayer_canvas-node.cc
author ladanyi
Wed, 02 Jan 2008 21:03:09 +0000
changeset 201 879e47e5b731
parent 194 6b2b718420eb
permissions -rwxr-xr-x
Merge branches/akos to trunk.
alpar@174
     1
/* -*- C++ -*-
alpar@174
     2
 *
alpar@174
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@174
     4
 *
alpar@174
     5
 * Copyright (C) 2003-2006
alpar@174
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@174
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@174
     8
 *
alpar@174
     9
 * Permission to use, modify and distribute this software is granted
alpar@174
    10
 * provided that this copyright notice appears in all copies. For
alpar@174
    11
 * precise terms see the accompanying LICENSE file.
alpar@174
    12
 *
alpar@174
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@174
    14
 * express or implied, and with no claim as to its suitability for any
alpar@174
    15
 * purpose.
alpar@174
    16
 *
alpar@174
    17
 */
alpar@174
    18
hegyi@194
    19
#include <graph_displayer_canvas.h>
hegyi@194
    20
#include <mapstorage.h>
hegyi@194
    21
#include <nbtab.h>
alpar@59
    22
#include <cmath>
hegyi@28
    23
hegyi@157
    24
const int minimum_node_radius=5;
hegyi@28
    25
alpar@62
    26
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
hegyi@28
    27
{
ladanyi@201
    28
  MapStorage& ms = *mytab.mapstorage;
ladanyi@201
    29
hegyi@48
    30
  double min, max;
ladanyi@201
    31
ladanyi@201
    32
  {
ladanyi@201
    33
    NodeIt n(ms.graph);
ladanyi@201
    34
    min = max = ms.get(mapname, n);
ladanyi@201
    35
    for (; n != INVALID; ++n)
ladanyi@201
    36
    {
ladanyi@201
    37
      if (static_cast<double>(ms.get(mapname, n)) > max)
ladanyi@201
    38
        max = ms.get(mapname, n);
ladanyi@201
    39
      if (static_cast<double>(ms.get(mapname, n)) < min)
ladanyi@201
    40
        min = ms.get(mapname, n);
ladanyi@201
    41
    }
ladanyi@201
    42
  }
hegyi@81
    43
hegyi@81
    44
  if(node==INVALID)
hegyi@31
    45
    {
ladanyi@201
    46
      for (NodeIt i(ms.graph); i!=INVALID; ++i)
hegyi@81
    47
	{
ladanyi@201
    48
	  double v=fabs(ms.get(mapname,i));
hegyi@81
    49
	  int w;
hegyi@154
    50
	  if(autoscale)
hegyi@81
    51
	    {
hegyi@154
    52
	      if(min==max)
hegyi@154
    53
		{
hegyi@154
    54
		  w=(int)(node_property_defaults[N_RADIUS]);
hegyi@154
    55
		}
hegyi@154
    56
	      else
hegyi@154
    57
		{
hegyi@157
    58
		  w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
hegyi@154
    59
		}
hegyi@81
    60
	    }
hegyi@81
    61
	  else
hegyi@81
    62
	    {
hegyi@157
    63
	      w=(int)(v*radius_size);
hegyi@81
    64
	    }
hegyi@155
    65
hegyi@157
    66
	  if(w<minimum_node_radius)
hegyi@155
    67
	    {
hegyi@157
    68
	      w=minimum_node_radius;
hegyi@155
    69
	    }
hegyi@155
    70
hegyi@156
    71
	  if(zoomtrack)
hegyi@156
    72
	    {
hegyi@156
    73
	      double actual_ppu=get_pixels_per_unit();
hegyi@156
    74
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@156
    75
	    }
hegyi@156
    76
hegyi@81
    77
	  if(w>=0)
hegyi@81
    78
	    {
hegyi@81
    79
	      double x1, y1, x2, y2;
hegyi@81
    80
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@81
    81
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@81
    82
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@81
    83
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@81
    84
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    85
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    86
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    87
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    88
	    }
hegyi@81
    89
	}
hegyi@31
    90
    }
hegyi@31
    91
  else
hegyi@31
    92
    {
hegyi@81
    93
      //I think only new nodes use this case
hegyi@154
    94
      //that has no own value, only the default one
hegyi@154
    95
      //int w=(int)(*actual_map)[node];
hegyi@81
    96
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@81
    97
      if(w>=0)
hegyi@81
    98
	{
hegyi@81
    99
	  double x1, y1, x2, y2;
hegyi@81
   100
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@81
   101
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@81
   102
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@81
   103
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@81
   104
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
   105
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
   106
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
   107
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
   108
	}
hegyi@31
   109
    }
hegyi@81
   110
  return 0;
hegyi@81
   111
};
hegyi@31
   112
hegyi@81
   113
int GraphDisplayerCanvas::resetNodeRadius (Node node)
hegyi@81
   114
{
ladanyi@201
   115
  MapStorage& ms = *mytab.mapstorage;
ladanyi@201
   116
hegyi@81
   117
  double min, max;
hegyi@81
   118
  min=node_property_defaults[N_RADIUS];
hegyi@81
   119
  max=node_property_defaults[N_RADIUS];
ladanyi@201
   120
  Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_RADIUS]);
hegyi@81
   121
  
hegyi@28
   122
  if(node==INVALID)
hegyi@28
   123
    {
ladanyi@201
   124
      for (NodeIt i(ms.graph); i!=INVALID; ++i)
hegyi@28
   125
	{
ladanyi@91
   126
	  double v=fabs(actual_map[i]);
hegyi@48
   127
	  int w;
hegyi@48
   128
	  if(min==max)
hegyi@48
   129
	    {
hegyi@48
   130
	      w=(int)(node_property_defaults[N_RADIUS]);
hegyi@48
   131
	    }
hegyi@48
   132
	  else
hegyi@48
   133
	    {
hegyi@48
   134
	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
hegyi@48
   135
	    }
hegyi@156
   136
	  if(zoomtrack)
hegyi@156
   137
	    {
hegyi@156
   138
	      double actual_ppu=get_pixels_per_unit();
hegyi@156
   139
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@156
   140
	    }
hegyi@28
   141
	  if(w>=0)
hegyi@28
   142
	    {
hegyi@28
   143
	      double x1, y1, x2, y2;
hegyi@31
   144
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@31
   145
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@31
   146
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@31
   147
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@28
   148
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   149
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   150
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   151
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   152
	    }
hegyi@28
   153
	}
hegyi@28
   154
    }
hegyi@28
   155
  else
hegyi@28
   156
    {
hegyi@31
   157
      //I think only new nodes use this case
ladanyi@91
   158
//       int w=(int)actual_map[node];
hegyi@31
   159
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@28
   160
      if(w>=0)
hegyi@28
   161
	{
hegyi@28
   162
	  double x1, y1, x2, y2;
hegyi@31
   163
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@31
   164
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@31
   165
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@31
   166
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@28
   167
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   168
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   169
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   170
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   171
	}
hegyi@28
   172
    }
hegyi@28
   173
  return 0;
hegyi@28
   174
};
hegyi@28
   175
alpar@62
   176
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
hegyi@28
   177
{  
ladanyi@201
   178
  MapStorage& ms = *mytab.mapstorage;
hegyi@28
   179
hegyi@28
   180
  //function maps the range of the maximum and
hegyi@28
   181
  //the minimum of the nodemap to the range of
hegyi@28
   182
  //green in RGB
hegyi@28
   183
hegyi@81
   184
  double max, min;
hegyi@81
   185
ladanyi@201
   186
  {
ladanyi@201
   187
    NodeIt n(ms.graph);
ladanyi@201
   188
    min = max = ms.get(mapname, n);
ladanyi@201
   189
    for (; n != INVALID; ++n)
ladanyi@201
   190
    {
ladanyi@201
   191
      if (static_cast<double>(ms.get(mapname, n)) > max)
ladanyi@201
   192
        max = ms.get(mapname, n);
ladanyi@201
   193
      if (static_cast<double>(ms.get(mapname, n)) < min)
ladanyi@201
   194
        min = ms.get(mapname, n);
ladanyi@201
   195
    }
ladanyi@201
   196
  }
hegyi@81
   197
hegyi@81
   198
  if(node==INVALID)
hegyi@31
   199
    {
hegyi@81
   200
ladanyi@201
   201
      for (NodeIt i(ms.graph); i!=INVALID; ++i)
hegyi@81
   202
	{
hegyi@81
   203
	  Gdk::Color color;
hegyi@81
   204
ladanyi@201
   205
	  double w=ms.get(mapname, i);
hegyi@81
   206
hegyi@81
   207
	  if(max!=min)
hegyi@81
   208
	    {
hegyi@179
   209
	      color=rainbowColorCounter(min, max, w);
hegyi@81
   210
	    }
hegyi@81
   211
	  else
hegyi@81
   212
	    {
hegyi@179
   213
	      color.set_rgb_p (0, 0, 1);
hegyi@81
   214
	    }
hegyi@81
   215
hegyi@81
   216
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@81
   217
	}
hegyi@31
   218
    }
hegyi@31
   219
  else
hegyi@31
   220
    {
hegyi@81
   221
      Gdk::Color color;
hegyi@81
   222
ladanyi@201
   223
      double w=ms.get(mapname, node);
hegyi@81
   224
hegyi@81
   225
      if(max!=min)
hegyi@81
   226
	{
hegyi@179
   227
	  color=rainbowColorCounter(min, max, w);
hegyi@81
   228
	}
hegyi@81
   229
      else
hegyi@81
   230
	{
hegyi@179
   231
	  color.set_rgb_p (0, 0, 1);
hegyi@81
   232
	}
hegyi@81
   233
hegyi@81
   234
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@31
   235
    }
hegyi@81
   236
  return 0;
hegyi@81
   237
};
hegyi@81
   238
hegyi@81
   239
int GraphDisplayerCanvas::resetNodeColor (Node node)
hegyi@81
   240
{  
ladanyi@201
   241
  MapStorage& ms = *mytab.mapstorage;
hegyi@81
   242
hegyi@81
   243
  //function maps the range of the maximum and
hegyi@81
   244
  //the minimum of the nodemap to the range of
hegyi@81
   245
  //green in RGB
hegyi@81
   246
ladanyi@201
   247
  Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_COLOR]);
hegyi@31
   248
hegyi@31
   249
  double max, min;
hegyi@31
   250
hegyi@81
   251
  max=node_property_defaults[N_COLOR];
hegyi@81
   252
  min=node_property_defaults[N_COLOR];
hegyi@31
   253
hegyi@28
   254
  if(node==INVALID)
hegyi@28
   255
    {
hegyi@28
   256
ladanyi@201
   257
      for (NodeIt i(ms.graph); i!=INVALID; ++i)
hegyi@28
   258
	{
hegyi@28
   259
	  Gdk::Color color;
hegyi@31
   260
ladanyi@91
   261
	  double w=actual_map[i];
hegyi@31
   262
hegyi@28
   263
	  if(max!=min)
hegyi@28
   264
	    {
hegyi@28
   265
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   266
	    }
hegyi@28
   267
	  else
hegyi@28
   268
	    {
hegyi@28
   269
	      color.set_rgb_p (0, 0, 100);
hegyi@28
   270
	    }
hegyi@28
   271
hegyi@28
   272
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
   273
	}
hegyi@28
   274
    }
hegyi@28
   275
  else
hegyi@28
   276
    {
hegyi@28
   277
      Gdk::Color color;
hegyi@31
   278
ladanyi@91
   279
      double w=actual_map[node];
hegyi@31
   280
hegyi@28
   281
      if(max!=min)
hegyi@28
   282
	{
hegyi@28
   283
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   284
	}
hegyi@28
   285
      else
hegyi@28
   286
	{
hegyi@28
   287
	  color.set_rgb_p (0, 0, 100);
hegyi@28
   288
	}
hegyi@28
   289
hegyi@28
   290
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@28
   291
    }
hegyi@28
   292
  return 0;
hegyi@28
   293
};
hegyi@28
   294
alpar@62
   295
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
hegyi@28
   296
{
ladanyi@201
   297
  MapStorage& ms = *mytab.mapstorage;
hegyi@81
   298
hegyi@81
   299
  //the number in the map will be written on the node
hegyi@81
   300
  //EXCEPT when the name of the map is Text, because
hegyi@81
   301
  //in that case empty string will be written, because
hegyi@81
   302
  //that is the deleter map
hegyi@81
   303
hegyi@81
   304
  if(node==INVALID)
hegyi@81
   305
    {
ladanyi@201
   306
      for (NodeIt i(ms.graph); i!=INVALID; ++i)
ladanyi@201
   307
	{
ladanyi@201
   308
	  nodemap_to_edit=mapname;
ladanyi@201
   309
ladanyi@201
   310
	  nodetextmap[i]->property_text().set_value(
ladanyi@201
   311
              static_cast<std::string>(ms.get(mapname, i)));
ladanyi@201
   312
	}
ladanyi@201
   313
    }
ladanyi@201
   314
  else
ladanyi@201
   315
    {
ladanyi@201
   316
      nodetextmap[node]->property_text().set_value(
ladanyi@201
   317
          static_cast<std::string>(ms.get(mapname, node)));
ladanyi@201
   318
    }
ladanyi@201
   319
  return 0;
ladanyi@201
   320
};
ladanyi@201
   321
ladanyi@201
   322
int GraphDisplayerCanvas::resetNodeText (Node node)
ladanyi@201
   323
{
ladanyi@201
   324
  MapStorage& ms = *mytab.mapstorage;
ladanyi@201
   325
ladanyi@201
   326
  //the number in the map will be written on the node
ladanyi@201
   327
  //EXCEPT when the name of the map is Text, because
ladanyi@201
   328
  //in that case empty string will be written, because
ladanyi@201
   329
  //that is the deleter map
ladanyi@201
   330
ladanyi@201
   331
  if(node==INVALID)
ladanyi@201
   332
    {
ladanyi@201
   333
      for (NodeIt i(ms.graph); i!=INVALID; ++i)
hegyi@81
   334
	{
hegyi@81
   335
	  nodemap_to_edit="";
hegyi@81
   336
	  nodetextmap[i]->property_text().set_value("");
hegyi@81
   337
	}
hegyi@81
   338
    }
hegyi@81
   339
  else
hegyi@81
   340
    {
hegyi@81
   341
      nodetextmap[node]->property_text().set_value("");
hegyi@81
   342
    }
hegyi@81
   343
  return 0;
hegyi@81
   344
};