graph_displayer_canvas-node.cc
author hegyi
Wed, 28 Feb 2007 18:20:28 +0000
changeset 194 6b2b718420eb
parent 179 1f436ea3ef4f
child 201 879e47e5b731
permissions -rwxr-xr-x
Header reorganising
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
{
hegyi@31
    28
  Graph::NodeMap<double> * actual_map;
hegyi@48
    29
  double min, max;
hegyi@194
    30
  min=(mytab.mapstorage)->minOfNodeMap(mapname);
hegyi@194
    31
  max=(mytab.mapstorage)->maxOfNodeMap(mapname);
hegyi@194
    32
  actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
hegyi@81
    33
hegyi@81
    34
  if(node==INVALID)
hegyi@31
    35
    {
hegyi@194
    36
      for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@81
    37
	{
hegyi@81
    38
	  double v=fabs((*actual_map)[i]);
hegyi@81
    39
	  int w;
hegyi@154
    40
	  if(autoscale)
hegyi@81
    41
	    {
hegyi@154
    42
	      if(min==max)
hegyi@154
    43
		{
hegyi@154
    44
		  w=(int)(node_property_defaults[N_RADIUS]);
hegyi@154
    45
		}
hegyi@154
    46
	      else
hegyi@154
    47
		{
hegyi@157
    48
		  w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
hegyi@154
    49
		}
hegyi@81
    50
	    }
hegyi@81
    51
	  else
hegyi@81
    52
	    {
hegyi@157
    53
	      w=(int)(v*radius_size);
hegyi@81
    54
	    }
hegyi@155
    55
hegyi@157
    56
	  if(w<minimum_node_radius)
hegyi@155
    57
	    {
hegyi@157
    58
	      w=minimum_node_radius;
hegyi@155
    59
	    }
hegyi@155
    60
hegyi@156
    61
	  if(zoomtrack)
hegyi@156
    62
	    {
hegyi@156
    63
	      double actual_ppu=get_pixels_per_unit();
hegyi@156
    64
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@156
    65
	    }
hegyi@156
    66
hegyi@81
    67
	  if(w>=0)
hegyi@81
    68
	    {
hegyi@81
    69
	      double x1, y1, x2, y2;
hegyi@81
    70
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@81
    71
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@81
    72
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@81
    73
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@81
    74
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    75
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    76
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    77
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    78
	    }
hegyi@81
    79
	}
hegyi@31
    80
    }
hegyi@31
    81
  else
hegyi@31
    82
    {
hegyi@81
    83
      //I think only new nodes use this case
hegyi@154
    84
      //that has no own value, only the default one
hegyi@154
    85
      //int w=(int)(*actual_map)[node];
hegyi@81
    86
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@81
    87
      if(w>=0)
hegyi@81
    88
	{
hegyi@81
    89
	  double x1, y1, x2, y2;
hegyi@81
    90
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@81
    91
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@81
    92
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@81
    93
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@81
    94
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    95
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    96
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    97
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    98
	}
hegyi@31
    99
    }
hegyi@81
   100
  return 0;
hegyi@81
   101
};
hegyi@31
   102
hegyi@81
   103
int GraphDisplayerCanvas::resetNodeRadius (Node node)
hegyi@81
   104
{
hegyi@81
   105
  double min, max;
hegyi@81
   106
  min=node_property_defaults[N_RADIUS];
hegyi@81
   107
  max=node_property_defaults[N_RADIUS];
hegyi@194
   108
  Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_RADIUS]);
hegyi@81
   109
  
hegyi@28
   110
  if(node==INVALID)
hegyi@28
   111
    {
hegyi@194
   112
      for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@28
   113
	{
ladanyi@91
   114
	  double v=fabs(actual_map[i]);
hegyi@48
   115
	  int w;
hegyi@48
   116
	  if(min==max)
hegyi@48
   117
	    {
hegyi@48
   118
	      w=(int)(node_property_defaults[N_RADIUS]);
hegyi@48
   119
	    }
hegyi@48
   120
	  else
hegyi@48
   121
	    {
hegyi@48
   122
	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
hegyi@48
   123
	    }
hegyi@156
   124
	  if(zoomtrack)
hegyi@156
   125
	    {
hegyi@156
   126
	      double actual_ppu=get_pixels_per_unit();
hegyi@156
   127
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@156
   128
	    }
hegyi@28
   129
	  if(w>=0)
hegyi@28
   130
	    {
hegyi@28
   131
	      double x1, y1, x2, y2;
hegyi@31
   132
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@31
   133
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@31
   134
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@31
   135
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@28
   136
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   137
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   138
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   139
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   140
	    }
hegyi@28
   141
	}
hegyi@28
   142
    }
hegyi@28
   143
  else
hegyi@28
   144
    {
hegyi@31
   145
      //I think only new nodes use this case
ladanyi@91
   146
//       int w=(int)actual_map[node];
hegyi@31
   147
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@28
   148
      if(w>=0)
hegyi@28
   149
	{
hegyi@28
   150
	  double x1, y1, x2, y2;
hegyi@31
   151
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@31
   152
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@31
   153
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@31
   154
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@28
   155
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   156
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   157
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   158
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   159
	}
hegyi@28
   160
    }
hegyi@28
   161
  return 0;
hegyi@28
   162
};
hegyi@28
   163
alpar@62
   164
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
hegyi@28
   165
{  
hegyi@28
   166
hegyi@28
   167
  //function maps the range of the maximum and
hegyi@28
   168
  //the minimum of the nodemap to the range of
hegyi@28
   169
  //green in RGB
hegyi@28
   170
hegyi@31
   171
  Graph::NodeMap<double> * actual_map;
hegyi@194
   172
  actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
hegyi@81
   173
hegyi@81
   174
  double max, min;
hegyi@81
   175
hegyi@194
   176
  max=(mytab.mapstorage)->maxOfNodeMap(mapname);
hegyi@194
   177
  min=(mytab.mapstorage)->minOfNodeMap(mapname);
hegyi@81
   178
hegyi@81
   179
  if(node==INVALID)
hegyi@31
   180
    {
hegyi@81
   181
hegyi@194
   182
      for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@81
   183
	{
hegyi@81
   184
	  Gdk::Color color;
hegyi@81
   185
hegyi@81
   186
	  double w=(*actual_map)[i];
hegyi@81
   187
hegyi@81
   188
	  if(max!=min)
hegyi@81
   189
	    {
hegyi@179
   190
	      color=rainbowColorCounter(min, max, w);
hegyi@81
   191
	    }
hegyi@81
   192
	  else
hegyi@81
   193
	    {
hegyi@179
   194
	      color.set_rgb_p (0, 0, 1);
hegyi@81
   195
	    }
hegyi@81
   196
hegyi@81
   197
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@81
   198
	}
hegyi@31
   199
    }
hegyi@31
   200
  else
hegyi@31
   201
    {
hegyi@81
   202
      Gdk::Color color;
hegyi@81
   203
hegyi@81
   204
      double w=(*actual_map)[node];
hegyi@81
   205
hegyi@81
   206
      if(max!=min)
hegyi@81
   207
	{
hegyi@179
   208
	  color=rainbowColorCounter(min, max, w);
hegyi@81
   209
	}
hegyi@81
   210
      else
hegyi@81
   211
	{
hegyi@179
   212
	  color.set_rgb_p (0, 0, 1);
hegyi@81
   213
	}
hegyi@81
   214
hegyi@81
   215
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@31
   216
    }
hegyi@81
   217
  return 0;
hegyi@81
   218
};
hegyi@81
   219
hegyi@81
   220
int GraphDisplayerCanvas::resetNodeColor (Node node)
hegyi@81
   221
{  
hegyi@81
   222
hegyi@81
   223
  //function maps the range of the maximum and
hegyi@81
   224
  //the minimum of the nodemap to the range of
hegyi@81
   225
  //green in RGB
hegyi@81
   226
hegyi@194
   227
  Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_COLOR]);
hegyi@31
   228
hegyi@31
   229
  double max, min;
hegyi@31
   230
hegyi@81
   231
  max=node_property_defaults[N_COLOR];
hegyi@81
   232
  min=node_property_defaults[N_COLOR];
hegyi@31
   233
hegyi@28
   234
  if(node==INVALID)
hegyi@28
   235
    {
hegyi@28
   236
hegyi@194
   237
      for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@28
   238
	{
hegyi@28
   239
	  Gdk::Color color;
hegyi@31
   240
ladanyi@91
   241
	  double w=actual_map[i];
hegyi@31
   242
hegyi@28
   243
	  if(max!=min)
hegyi@28
   244
	    {
hegyi@28
   245
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   246
	    }
hegyi@28
   247
	  else
hegyi@28
   248
	    {
hegyi@28
   249
	      color.set_rgb_p (0, 0, 100);
hegyi@28
   250
	    }
hegyi@28
   251
hegyi@28
   252
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
   253
	}
hegyi@28
   254
    }
hegyi@28
   255
  else
hegyi@28
   256
    {
hegyi@28
   257
      Gdk::Color color;
hegyi@31
   258
ladanyi@91
   259
      double w=actual_map[node];
hegyi@31
   260
hegyi@28
   261
      if(max!=min)
hegyi@28
   262
	{
hegyi@28
   263
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   264
	}
hegyi@28
   265
      else
hegyi@28
   266
	{
hegyi@28
   267
	  color.set_rgb_p (0, 0, 100);
hegyi@28
   268
	}
hegyi@28
   269
hegyi@28
   270
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@28
   271
    }
hegyi@28
   272
  return 0;
hegyi@28
   273
};
hegyi@28
   274
alpar@62
   275
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
hegyi@28
   276
{
hegyi@28
   277
hegyi@28
   278
  //the number in the map will be written on the node
hegyi@28
   279
  //EXCEPT when the name of the map is Text, because
hegyi@28
   280
  //in that case empty string will be written, because
hegyi@28
   281
  //that is the deleter map
hegyi@31
   282
hegyi@36
   283
  Graph::NodeMap<double> * actual_map=NULL;
hegyi@194
   284
  actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
hegyi@28
   285
hegyi@28
   286
  if(node==INVALID)
hegyi@28
   287
    {
hegyi@194
   288
      for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@28
   289
	{
hegyi@81
   290
	  nodemap_to_edit=mapname;
hegyi@81
   291
	  double number=(*actual_map)[i];
hegyi@45
   292
hegyi@81
   293
	  std::ostringstream ostr;
hegyi@81
   294
	  ostr << number;
hegyi@45
   295
	      
hegyi@81
   296
	  nodetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   297
	}
hegyi@28
   298
    }
hegyi@28
   299
  else
hegyi@28
   300
    {
hegyi@81
   301
      double number=(*actual_map)[node];
hegyi@45
   302
hegyi@81
   303
      std::ostringstream ostr;
hegyi@81
   304
      ostr << number;
hegyi@45
   305
	      
hegyi@81
   306
      nodetextmap[node]->property_text().set_value(ostr.str());
hegyi@28
   307
    }
hegyi@28
   308
  return 0;
hegyi@28
   309
};
hegyi@81
   310
hegyi@81
   311
int GraphDisplayerCanvas::resetNodeText (Node node)
hegyi@81
   312
{
hegyi@81
   313
hegyi@81
   314
  //the number in the map will be written on the node
hegyi@81
   315
  //EXCEPT when the name of the map is Text, because
hegyi@81
   316
  //in that case empty string will be written, because
hegyi@81
   317
  //that is the deleter map
hegyi@81
   318
hegyi@81
   319
  if(node==INVALID)
hegyi@81
   320
    {
hegyi@194
   321
      for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@81
   322
	{
hegyi@81
   323
	  nodemap_to_edit="";
hegyi@81
   324
	  nodetextmap[i]->property_text().set_value("");
hegyi@81
   325
	}
hegyi@81
   326
    }
hegyi@81
   327
  else
hegyi@81
   328
    {
hegyi@81
   329
      nodetextmap[node]->property_text().set_value("");
hegyi@81
   330
    }
hegyi@81
   331
  return 0;
hegyi@81
   332
};