########################################################################
#  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
#  of the License, or (at your option) any later version.
#  
#  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.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor,
#  Boston, MA  02110-1301, USA.
#  
#  ---
#  Copyright (C) 2011-2015, Simon Hampe <simon.hampe@googlemail.com>
#
#  Contains functions to visualize the domain of a RationalFunction or
#  a Morphism.
#
########################################################################

package Visual::Cycle;

#Visualization options for RationalFunction/Morphism->BB_VISUAL
options %Visual::Cycle::FunctionDecorations=(
	%Visual::Cycle::BoundingDecorations,

	# String, if set to "show", the function labels indicatingt the affine linear representation of each function
	# on each cone are computed
	FunctionLabels => enum("hidden", "show"),
);

object RationalFunction {

# @category Visualization 
# Visualizes the domain of the function. Works exactly as BB_VISUAL of WeightedComplex, but has additional option
# @options
# @option String FunctionLabels If set to "show", textual function representations are diplayed on cones. False by default
	user_method BB_VISUAL(%Visual::Cycle::FunctionDecorations, {CutOff => $Visual::Color::cutoff}) : DOMAIN, VERTEX_VALUES, LINEALITY_VALUES {

		my ($this,$decor,$cutoff_decor)=@_;

		my $showFunctionLabels = 0;
		if(defined($$decor{"FunctionLabels"})) {
			if($$decor{"FunctionLabels"} eq "show") {
				$showFunctionLabels = 1;
			}
		}
		delete($$decor{"FunctionLabels"});

		my $domain = $this->DOMAIN;

		my @labels = ();
		if($showFunctionLabels == 1) {
			my $ray_values = $this->VERTEX_VALUES;
			my $lin_values = $this->LINEALITY_VALUES;

			my ($M,$L);
			if($ray_values->dim() > 0) {
				$M = new Matrix<Rational>($ray_values);
				$M = transpose($M);
			}
			else {
				$M = new Matrix<Rational>(0,1);
			}
			if($lin_values->dim() > 0) {
				$L = new Matrix<Rational>($lin_values);
				$L = transpose($L);
			}
			else {
				$L = new Matrix<Rational>(0,1);
			}

			@labels = computeFunctionLabels($domain,$M,$L,0);
			$$decor{"ConeLabels"} = new Array<String>(\@labels);
		}


		$domain->BB_VISUAL($decor,$cutoff_decor);
	}
}; #END object RationalFunction


object Morphism {
  
# @category Visualization 
# Visualizes the domain of the morphism. Works exactly as BB_VISUAL of WeightedComplex, but has additional option
# @options
# @option String FunctionLabels If set to "show", textual function representations are diplayed on cones. False by default
user_method BB_VISUAL(%Visual::Cycle::FunctionDecorations, {CutOff => $Visual::Color::cutoff}) : DOMAIN, VERTEX_VALUES, LINEALITY_VALUES {
    
    my ($this,$decor,$cutoff_decor)= @_;
    
    my $showFunctionLabels = 0;
    if(defined($$decor{"FunctionLabels"})) {
      if($$decor{"FunctionLabels"} eq "show") {
	$showFunctionLabels = 1;
      }
    }
    delete($$decor{"FunctionLabels"});
  
    my $domain = $this->DOMAIN;
   
    my @labels = ();
    if($showFunctionLabels == 1) {
      my $M = $this->VERTEX_VALUES;
      my $L = $this->LINEALITY_VALUES;
      
      @labels = computeFunctionLabels($domain,$M,$L,1);
      $$decor{"ConeLabels"} = new Array<String>(\@labels);
    }
    
    
    $domain->BB_VISUAL($decor,$cutoff_decor);
}
}
