graph_displayer_canvas-edge.cc
author hegyi
Thu, 28 Jul 2005 14:31:32 +0000
branchgui
changeset 47 9a0e6e92d06c
parent 45 199f433eb7cd
child 48 b8ec84524fa2
permissions -rwxr-xr-x
Redundant functions from main_win disappeared, entry is now bigger, properties refresh upon edition, edgewidth is zoomable.
hegyi@27
     1
#include <graph_displayer_canvas.h>
hegyi@27
     2
#include <broken_edge.h>
hegyi@27
     3
#include <math.h>
hegyi@27
     4
hegyi@27
     5
hegyi@28
     6
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
hegyi@27
     7
{
hegyi@31
     8
  Graph::EdgeMap<double> * actual_map;
hegyi@31
     9
  if(mapname=="Default")
hegyi@31
    10
    {
hegyi@31
    11
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
hegyi@31
    12
    }
hegyi@31
    13
  else
hegyi@31
    14
    {
hegyi@31
    15
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@31
    16
    }
hegyi@31
    17
hegyi@28
    18
  if(edge==INVALID)
hegyi@27
    19
    {
hegyi@28
    20
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@28
    21
	{
hegyi@31
    22
	  int w=(int)(*actual_map)[i];
hegyi@28
    23
	  if(w>=0)
hegyi@28
    24
	    {
hegyi@47
    25
	      edgesmap[i]->property_width_units().set_value(w);
hegyi@28
    26
	    }
hegyi@28
    27
	}
hegyi@28
    28
    }
hegyi@28
    29
  else
hegyi@28
    30
    {
hegyi@31
    31
      int w=(int)(*actual_map)[edge];
hegyi@27
    32
      if(w>=0)
hegyi@27
    33
	{
hegyi@47
    34
	  edgesmap[edge]->property_width_units().set_value(w);
hegyi@27
    35
	}
hegyi@27
    36
    }
hegyi@27
    37
  return 0;
hegyi@27
    38
};
hegyi@27
    39
hegyi@28
    40
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
hegyi@27
    41
{  
hegyi@27
    42
hegyi@27
    43
  //function maps the range of the maximum and
hegyi@27
    44
  //the minimum of the nodemap to the range of
hegyi@27
    45
  //green in RGB
hegyi@31
    46
  Graph::EdgeMap<double> * actual_map;
hegyi@31
    47
  if(mapname=="Default")
hegyi@31
    48
    {
hegyi@31
    49
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
hegyi@31
    50
    }
hegyi@31
    51
  else
hegyi@31
    52
    {
hegyi@31
    53
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@31
    54
    }
hegyi@31
    55
hegyi@31
    56
  double max, min;
hegyi@31
    57
hegyi@31
    58
  if(mapname!="Default")
hegyi@31
    59
    {
hegyi@31
    60
      max=mapstorage.maxOfEdgeMap(mapname);
hegyi@31
    61
      min=mapstorage.minOfEdgeMap(mapname);
hegyi@31
    62
    }
hegyi@31
    63
  else
hegyi@31
    64
    {
hegyi@31
    65
      max=edge_property_defaults[E_COLOR];
hegyi@31
    66
      min=edge_property_defaults[E_COLOR];
hegyi@31
    67
    }
hegyi@31
    68
hegyi@28
    69
  if(edge==INVALID)
hegyi@28
    70
    {
hegyi@28
    71
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@28
    72
	{
hegyi@31
    73
	  double w=(*actual_map)[i];
hegyi@31
    74
hegyi@28
    75
	  Gdk::Color color;
hegyi@28
    76
	  if(max!=min)
hegyi@28
    77
	    {
hegyi@28
    78
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
    79
	    }
hegyi@28
    80
	  else
hegyi@28
    81
	    {
hegyi@28
    82
	      color.set_rgb_p (0, 100, 0);
hegyi@28
    83
	    }
hegyi@28
    84
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
    85
	}
hegyi@28
    86
    }
hegyi@28
    87
  else
hegyi@27
    88
    {
hegyi@28
    89
      Gdk::Color color;
hegyi@31
    90
hegyi@31
    91
      double w=(*actual_map)[edge];
hegyi@31
    92
hegyi@28
    93
      if(max!=min)
hegyi@28
    94
	{
hegyi@28
    95
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
    96
	}
hegyi@28
    97
      else
hegyi@28
    98
	{
hegyi@28
    99
	  color.set_rgb_p (0, 100, 0);
hegyi@28
   100
	}
hegyi@28
   101
hegyi@28
   102
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@27
   103
    }
hegyi@27
   104
  return 0;
hegyi@27
   105
};
hegyi@27
   106
hegyi@28
   107
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
hegyi@27
   108
{
hegyi@27
   109
  //the number in the map will be written on the edge
hegyi@40
   110
  //EXCEPT when the name of the map is Default, because
hegyi@27
   111
  //in that case empty string will be written, because
hegyi@27
   112
  //that is the deleter map
hegyi@27
   113
hegyi@28
   114
  if(edge==INVALID)
hegyi@27
   115
    {
hegyi@28
   116
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@27
   117
	{
hegyi@31
   118
	  if(mapname!="Default")
hegyi@28
   119
	    {
hegyi@35
   120
	      edgemap_to_edit=mapname;
hegyi@28
   121
	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@44
   122
hegyi@44
   123
	      std::ostringstream ostr;
hegyi@44
   124
	      ostr << number;
hegyi@45
   125
	      
hegyi@44
   126
      	      edgetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   127
	    }
hegyi@28
   128
	  else
hegyi@28
   129
	    {
hegyi@35
   130
	      edgemap_to_edit="";
hegyi@28
   131
	      edgetextmap[i]->property_text().set_value("");
hegyi@28
   132
	    }
hegyi@28
   133
	}
hegyi@28
   134
hegyi@28
   135
    }
hegyi@28
   136
  else
hegyi@28
   137
    {
hegyi@31
   138
      if(mapname!="Default")
hegyi@28
   139
	{
hegyi@28
   140
	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
hegyi@45
   141
hegyi@45
   142
	  std::ostringstream ostr;
hegyi@45
   143
	  ostr << number;
hegyi@45
   144
	  
hegyi@45
   145
	  edgetextmap[edge]->property_text().set_value(ostr.str());
hegyi@27
   146
	}
hegyi@27
   147
      else
hegyi@27
   148
	{
hegyi@28
   149
	  edgetextmap[edge]->property_text().set_value("");
hegyi@27
   150
	}
hegyi@28
   151
	  
hegyi@27
   152
    }
hegyi@28
   153
hegyi@27
   154
  return 0;
hegyi@28
   155
hegyi@27
   156
};