#  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: visual.rules,v 1.8 2004/11/24 18:05:00 gawrilow Exp $


# category: Visualization
# args: [ "title" ], VisualObject, ...
#
# Create a drawing with given @a VisualObject's.  Optional @a title will replace
# the default one taken from the first object.
#
# The visualization program is chosen based on the types of the given objects,
# as well as on the user preferences.
#
# Multiple visual objects of the same kind may be passed together packed into
# anonymous arrays; this will essentially accelerate the chosing procedure.
#
# No matter how many visual objects are passed, they all will be stuffed
# on the same page (window, etc.)  If it is not what you want, call this function
# several times giving it smaller sets of objects.
#
# Note that for the most visualization packages the real work will be delayed
# until the end of the user interaction cycle.  In interactive shell mode,
# it is after the whole user input line is executed, in script mode it occurs just before
# the script termination.  This allows to bundle several drawings to multi-page documents
# (or multi-window presentations), as far as supported by the visualization package.
#
# However, when called in non-void context, this function simply returns the first @a VisualObject,
# with the rest objects attached to it.
#
# All single-object drawing methods (like @c VISUAL, @c VISUAL_GRAPH, @c SCHLEGEL, etc.)
# always return their results via @c visualize.  This way you can use them for both
# immediate drawing (by calling them in void context) and composing more complex pictures,
# e.g. <code>visualize(VISUAL, VISUAL_DUAL)</code>

user_function visualize {
   my $title=!ref($_[0]) && shift;
   if (defined(wantarray)) {
      my $first=shift;
      if (ref($first) eq "ARRAY") {
	 my $rest=$first;
	 $first=shift @$rest;
	 unshift @{$first->attached}, @$rest;
      }
      $first->Name=$title if length($title);
      if (@_) {
	 &Visual::plain_attached;
	 push @{$first->attached}, @_;
      }
      $first;
   } else {
      Visual::show($title, @_);
   }
}

###############################################################################
#
#  some common colors
#
package Visual::Color;

# topic: customize/Visual::Color
# All colors defined here are RGB values in integer representation (0..255)
# You may use symbolic names defined in the file $RGBtxt as well.

custom $RGBtxt_path="";

CONFIGURE {
   foreach my $dir (qw( /usr/X11 /usr/X11R6 /usr/local/X11 /usr/local/X11R6 /usr/openwin )) {
      if (-f (my $f="$dir/lib/X11/rgb.txt")) {
	 $RGBtxt_path=$f; last;
      }
   }
   warn_print("file rgb.txt not found - no symbolic color names will be allowed") unless $RGBtxt_path;
   1;  # go on compiling anyway
}

# facets in famous polymake-green
custom $facets="119 236 158";

# black
custom $edges="0 0 0";

# red
custom $vertices="255 0 0";

# background color
custom $background="255 247 208";

package default;

###############################################################################

require Visual;
require VisualPolygon;

function RGB2float {	# (R, G, B) or [ R, G, B ] or "R G B" in int representation => "R G B" in floating-point representation
   no integer;
   sprintf "%8.6f %8.6f %8.6f", map { $_/255 } (ref($_[0]) ? @{$_[0]} : @_==3 ? @_ : $_[0]=~/\d+/g)
}

function RGB2hex {	# (R, G, B) or [ R, G, B ] or "R G B" in int representation => "#RRGGBB" in X Windows-style hex representation
   sprintf "#%02X%02X%02X", (ref($_[0]) ? @{$_[0]} : @_==3 ? @_ : $_[0]=~/\d+/g);
}

function flatten_indices(Visual::Embedding) { () }


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