graph_displayer_canvas-edge.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@27
    23
hegyi@167
    24
const int minimum_edge_width=0;
hegyi@27
    25
hegyi@81
    26
int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
hegyi@81
    27
{
hegyi@81
    28
  double min, max;
hegyi@81
    29
hegyi@81
    30
  min=edge_property_defaults[E_WIDTH];
hegyi@81
    31
  max=edge_property_defaults[E_WIDTH];
hegyi@194
    32
  Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_WIDTH]);
hegyi@81
    33
  
hegyi@81
    34
  if(edge==INVALID)
hegyi@81
    35
    {
hegyi@194
    36
      for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@81
    37
	{
ladanyi@91
    38
	  double v=fabs(actual_map[i]);
hegyi@81
    39
	  int w;
hegyi@81
    40
	  if(min==max)
hegyi@81
    41
	    {
hegyi@81
    42
	      w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@81
    43
	    }
hegyi@81
    44
	  else
hegyi@81
    45
	    {
hegyi@81
    46
	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
hegyi@81
    47
	    }
hegyi@157
    48
	  if(zoomtrack)
hegyi@157
    49
	    {
hegyi@157
    50
	      double actual_ppu=get_pixels_per_unit();
hegyi@157
    51
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@157
    52
	    }
ladanyi@147
    53
	  edgesmap[i]->setLineWidth(w);
hegyi@81
    54
	}
hegyi@81
    55
    }
hegyi@81
    56
  else
hegyi@81
    57
    {
ladanyi@91
    58
      int w=(int)actual_map[edge];
hegyi@81
    59
      if(w>=0)
hegyi@81
    60
	{
ladanyi@147
    61
	  edgesmap[edge]->setLineWidth(w);
hegyi@81
    62
	}
hegyi@81
    63
    }
hegyi@81
    64
  return 0;
hegyi@81
    65
}
hegyi@81
    66
hegyi@81
    67
alpar@62
    68
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
hegyi@27
    69
{
hegyi@31
    70
  Graph::EdgeMap<double> * actual_map;
hegyi@48
    71
  double min, max;
hegyi@48
    72
hegyi@194
    73
  min=(mytab.mapstorage)->minOfEdgeMap(mapname);
hegyi@194
    74
  max=(mytab.mapstorage)->maxOfEdgeMap(mapname);
hegyi@194
    75
  actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];
hegyi@31
    76
hegyi@28
    77
  if(edge==INVALID)
hegyi@27
    78
    {
hegyi@194
    79
      for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@28
    80
	{
hegyi@178
    81
	  double v=(*actual_map)[i];
hegyi@48
    82
	  int w;
hegyi@157
    83
	  if(autoscale)
hegyi@28
    84
	    {
hegyi@157
    85
	      if(min==max)
hegyi@157
    86
		{
hegyi@157
    87
		  w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@157
    88
		}
hegyi@157
    89
	      else
hegyi@157
    90
		{
hegyi@157
    91
		  w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
hegyi@157
    92
		}
hegyi@28
    93
	    }
hegyi@48
    94
	  else
hegyi@48
    95
	    {
hegyi@157
    96
	      w=(int)(v*edge_width);
hegyi@157
    97
	    }
hegyi@178
    98
	  if(w<0)
hegyi@157
    99
	    {
hegyi@178
   100
	      edgesmap[i]->hide();
hegyi@157
   101
	    }
hegyi@178
   102
	  else
hegyi@157
   103
	    {
hegyi@178
   104
	      edgesmap[i]->show();
hegyi@178
   105
	      if(w<minimum_edge_width)
hegyi@178
   106
		{
hegyi@178
   107
		  w=minimum_edge_width;
hegyi@178
   108
		}
hegyi@178
   109
	      if(zoomtrack)
hegyi@178
   110
		{
hegyi@178
   111
		  double actual_ppu=get_pixels_per_unit();
hegyi@178
   112
		  w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@178
   113
		}
hegyi@178
   114
	      edgesmap[i]->setLineWidth(w);
hegyi@48
   115
	    }
hegyi@28
   116
	}
hegyi@28
   117
    }
hegyi@28
   118
  else
hegyi@28
   119
    {
hegyi@31
   120
      int w=(int)(*actual_map)[edge];
hegyi@27
   121
      if(w>=0)
hegyi@27
   122
	{
ladanyi@147
   123
	  edgesmap[edge]->setLineWidth(w);
hegyi@27
   124
	}
hegyi@27
   125
    }
hegyi@27
   126
  return 0;
hegyi@27
   127
};
hegyi@27
   128
alpar@62
   129
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
hegyi@27
   130
{  
hegyi@27
   131
hegyi@27
   132
  //function maps the range of the maximum and
hegyi@27
   133
  //the minimum of the nodemap to the range of
hegyi@27
   134
  //green in RGB
hegyi@31
   135
  Graph::EdgeMap<double> * actual_map;
hegyi@194
   136
  actual_map=((mytab.mapstorage)->edgemap_storage)[mapname];
hegyi@81
   137
hegyi@81
   138
  double max, min;
hegyi@81
   139
hegyi@194
   140
  max=(mytab.mapstorage)->maxOfEdgeMap(mapname);
hegyi@194
   141
  min=(mytab.mapstorage)->minOfEdgeMap(mapname);
hegyi@81
   142
hegyi@81
   143
  if(edge==INVALID)
hegyi@31
   144
    {
hegyi@194
   145
      for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@81
   146
	{
hegyi@81
   147
	  double w=(*actual_map)[i];
hegyi@81
   148
hegyi@81
   149
	  Gdk::Color color;
hegyi@81
   150
	  if(max!=min)
hegyi@81
   151
	    {
hegyi@179
   152
	      color=rainbowColorCounter(min, max, w);
hegyi@81
   153
	    }
hegyi@81
   154
	  else
hegyi@81
   155
	    {
hegyi@179
   156
	      color.set_rgb_p (0, 1, 0);
hegyi@81
   157
	    }
ladanyi@147
   158
	  edgesmap[i]->setFillColor(color);
hegyi@81
   159
	}
hegyi@31
   160
    }
hegyi@31
   161
  else
hegyi@31
   162
    {
hegyi@81
   163
      Gdk::Color color;
hegyi@81
   164
hegyi@81
   165
      double w=(*actual_map)[edge];
hegyi@81
   166
hegyi@81
   167
      if(max!=min)
hegyi@81
   168
	{
hegyi@179
   169
	  color=rainbowColorCounter(min, max, w);
hegyi@81
   170
	}
hegyi@81
   171
      else
hegyi@81
   172
	{
hegyi@179
   173
	  color.set_rgb_p (0, 1, 0);
hegyi@81
   174
	}
hegyi@81
   175
ladanyi@147
   176
      edgesmap[edge]->setFillColor(color);
hegyi@31
   177
    }
hegyi@81
   178
  return 0;
hegyi@81
   179
};
hegyi@81
   180
hegyi@81
   181
int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
hegyi@81
   182
{  
hegyi@81
   183
hegyi@81
   184
  //function maps the range of the maximum and
hegyi@81
   185
  //the minimum of the nodemap to the range of
hegyi@81
   186
  //green in RGB
hegyi@194
   187
  Graph::EdgeMap<double> actual_map((mytab.mapstorage)->graph,edge_property_defaults[E_COLOR]);
hegyi@31
   188
hegyi@31
   189
  double max, min;
hegyi@31
   190
hegyi@81
   191
  max=edge_property_defaults[E_COLOR];
hegyi@81
   192
  min=edge_property_defaults[E_COLOR];
hegyi@31
   193
hegyi@28
   194
  if(edge==INVALID)
hegyi@28
   195
    {
hegyi@194
   196
      for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@28
   197
	{
ladanyi@91
   198
	  double w=actual_map[i];
hegyi@31
   199
hegyi@28
   200
	  Gdk::Color color;
hegyi@28
   201
	  if(max!=min)
hegyi@28
   202
	    {
hegyi@28
   203
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
   204
	    }
hegyi@28
   205
	  else
hegyi@28
   206
	    {
hegyi@28
   207
	      color.set_rgb_p (0, 100, 0);
hegyi@28
   208
	    }
ladanyi@147
   209
	  edgesmap[i]->setFillColor(color);
hegyi@28
   210
	}
hegyi@28
   211
    }
hegyi@28
   212
  else
hegyi@27
   213
    {
hegyi@28
   214
      Gdk::Color color;
hegyi@31
   215
ladanyi@91
   216
      double w=actual_map[edge];
hegyi@31
   217
hegyi@28
   218
      if(max!=min)
hegyi@28
   219
	{
hegyi@28
   220
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
   221
	}
hegyi@28
   222
      else
hegyi@28
   223
	{
hegyi@28
   224
	  color.set_rgb_p (0, 100, 0);
hegyi@28
   225
	}
hegyi@28
   226
ladanyi@147
   227
      edgesmap[edge]->setFillColor(color);
hegyi@27
   228
    }
hegyi@27
   229
  return 0;
hegyi@27
   230
};
hegyi@27
   231
alpar@62
   232
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
hegyi@27
   233
{
hegyi@27
   234
  //the number in the map will be written on the edge
hegyi@40
   235
  //EXCEPT when the name of the map is Default, because
hegyi@27
   236
  //in that case empty string will be written, because
hegyi@27
   237
  //that is the deleter map
ladanyi@63
   238
  
hegyi@28
   239
  if(edge==INVALID)
hegyi@27
   240
    {
hegyi@194
   241
      for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@27
   242
	{
hegyi@81
   243
	  edgemap_to_edit=mapname;
hegyi@194
   244
	  double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[i];
hegyi@81
   245
	  
hegyi@81
   246
	  std::ostringstream ostr;
hegyi@81
   247
	  ostr << number;
hegyi@81
   248
	  
hegyi@81
   249
	  edgetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   250
	}
hegyi@28
   251
hegyi@28
   252
    }
hegyi@28
   253
  else
hegyi@28
   254
    {
hegyi@194
   255
	  double number=(*((mytab.mapstorage)->edgemap_storage)[mapname])[edge];
hegyi@45
   256
hegyi@45
   257
	  std::ostringstream ostr;
hegyi@45
   258
	  ostr << number;
hegyi@45
   259
	  
hegyi@45
   260
	  edgetextmap[edge]->property_text().set_value(ostr.str());
hegyi@27
   261
    }
hegyi@28
   262
hegyi@27
   263
  return 0;
hegyi@28
   264
hegyi@27
   265
};
hegyi@81
   266
hegyi@81
   267
int GraphDisplayerCanvas::resetEdgeText (Edge edge)
hegyi@81
   268
{
hegyi@81
   269
  //the number in the map will be written on the edge
hegyi@81
   270
  //EXCEPT when the name of the map is Default, because
hegyi@81
   271
  //in that case empty string will be written, because
hegyi@81
   272
  //that is the deleter map
hegyi@81
   273
  
hegyi@81
   274
  if(edge==INVALID)
hegyi@81
   275
    {
hegyi@194
   276
      for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
hegyi@81
   277
	{
hegyi@81
   278
	  edgemap_to_edit="";
hegyi@81
   279
	  edgetextmap[i]->property_text().set_value("");
hegyi@81
   280
	}
hegyi@81
   281
hegyi@81
   282
    }
hegyi@81
   283
  else
hegyi@81
   284
    {
hegyi@81
   285
      edgetextmap[edge]->property_text().set_value("");
hegyi@81
   286
    }
hegyi@81
   287
hegyi@81
   288
  return 0;
hegyi@81
   289
hegyi@81
   290
};