#  Copyright (c) 1997-2006
#  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: BackgroundViewer.pm 7161 2006-03-07 17:50:53Z gawrilow $

use Poly::BackgroundProcess;
use Poly::Tempfile;

package Poly::BackgroundViewer;

use Struct (
   [ '$graphics' => 'undef' ],
   [ '$tempfile' => 'new Poly::Tempfile' ],
);

sub run {
   my ($self, $synchronous)=@_;
   $self->graphics->print_it;
   my $command=$self->command;
   dbg_print( "running '$command'" ) if $Switches::d;
   $synchronous
   ? system($command)
   : new BackgroundProcess(to_destroy => $self->tempfile, $command);
   undef $self->tempfile;
}

# execution in background
sub proceed {
   run(shift);
   ()	# empty return
}

# old style synchronous execution 
sub launch {
   run(shift,1);
}

###########################################################################################
#
#  Viewer not capable to show multiple pages in one process

package Poly::SimpleViewer;

use Struct [ '@ISA' => 'Poly::BackgroundViewer' ];

sub new_instance {
   my $self=shift;
   if ($self->graphics) {
      run($self);
      $self->tempfile=new Poly::Tempfile;
   }
}

1


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