#  Copyright (c) 1997-2004
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-----------------------------------------------------------------------------
#  $Project: polymake $$Id: geomview.rules,v 1.5 2004/10/26 19:00:52 gawrilow Exp $


CONFIGURE : common::

package Geomview::Viewer;

sub line_colors {
   my ($Graph)=@_;
   my ($appearance, @params, @color);
   if (defined (my $get_style=$Graph->EdgeStyle)) {
      if (!is_code($get_style)) {
	 if ($get_style =~ $Visual::thickness_re) {
	    $appearance="linewidth $1";
	 }
      }
   }
   if (defined (my $get_color=$Graph->EdgeColor)) {
      if (is_code($get_color)) {
	 my @colors;
	 for (my $edge=$Graph->edges; $edge; ++$edge) {
	    push @colors, RGB2float( (@color=Visual::parse_color($get_color->($edge))) ? @color[2..4] : $Visual::Color::graph );
	 }
	 @params=( lineColors => \@colors );
      } elsif (@color=Visual::parse_color($get_color)) {
	 $appearance.=" material { edgecolor " . RGB2float(@color[2..4]) . " }";
      }
   }
   push @params, ( appearance => $appearance ) if $appearance;
   return @params;
}

global_method geomview.graph: draw(Visual::Graph, @) {
   my ($self, $Graph)=@_;
   my $nodes=$Graph->get_number_nodes;
   my @lines;
   for (my $edge=$Graph->edges; $edge; ++$edge) {
      push @lines, [ $edge->incident_nodes ];
   }
   my $geom=new Geomview::SKEL( name => $Graph->Name,
				points => $Graph->Coord,
				dim => Modules::common::dim($Graph->Coord),
				lines => \@lines,
				line_colors($Graph),
			      );
   $self->append($geom);
}


# Local Variables:
# mode: perl
# c-basic-offset:3
# End:
