#!/usr/bin/perl -w

#############################################################################
# Walls - walls that can be inserted into an empty cell.
#
# Copyright (C) 1999-2000 by Tels. All rights reserved.
#############################################################################

package CoW::Architecture::Frame;
use vars qw($VERSION);
$VERSION = 1.00;    # Current version of this package
require  5.005;     # requires this Perl version or later

use base CoW::Thing;
use strict;
use vars qw($AUTOLOAD);

use CoW::Angle;
use CoW::Coord;
use CoW::Brush;
use CoW::Dromed::Constants qw(SOLID AIR CUBE);

#############################################################################
# private, initialize self 

sub _init
  {
  my $self = shift;
  my $args = shift;

  $self->SUPER::_init($args);
  $self->SUPER::_default( {
   x => new CoW::Coord (rel => '_parent::x', val => 0),
   y => new CoW::Coord (rel => '_parent::y', val => 0),
   z => new CoW::Coord (rel => '_parent::z', val => 0),
   l => 1,
   w => new CoW::Coord (rel => '_parent::w', val => 1),
   h => new CoW::Coord (rel => '_parent::h', val => 1),
   rx => new CoW::Angle (rel => '_parent::rx', val => 0),
   ry => new CoW::Angle (rel => '_parent::ry', val => 0),
   rz => new CoW::Angle (rel => '_parent::rz', val => 0),
   thick => 1,
   hor_bars => 0,
   ver_bars => 0,
   } );
  return $self->_construct();
  }

#############################################################################
# public

sub thick
  {
  my $self = shift;
   
  if (defined $_[0])
    {
    $self->{thick} = shift;
    $self->_construct();
    }
  return $self->{thick};
  }

sub hor_bars
  {
  my $self = shift;
   
  if (defined $_[0])
    {
    $self->{hor_bars} = shift;
    $self->_construct();
    }
  return $self->{hor_bars};
  }

sub ver_bars
  {
  my $self = shift;
   
  if (defined $_[0])
    {
    $self->{ver_bars} = shift;
    $self->_construct();
    }
  return $self->{ver_bars};
  }

sub _construct
  {
  # from thick, hor_bars and ver_bars construct yourself
  my $self = shift;

  # first scrap anything we possible already got
  $self->empty();

  my @insert;
  # this automatically is as big as we are
  push @insert, new CoW::Brush (shape => CUBE, kind => SOLID ); 
  # as heigh as we are, but spaced thick*2 in w and l
  push @insert, new CoW::Brush (shape => CUBE, kind => AIR,
    sw => $self->{thick}*2,
    sl => $self->{thick}*2,
    );
  # now the bars
  for (my $i = 0; $i < $self->{hor_bars}; $i++)
    {
    push @insert, new CoW::Brush (shape => CUBE, kind => SOLID,
      sw => $self->{thick}*2,
      h => $self->{thick},
      );
    }
  for (my $i = 0; $i < $self->{ver_bars}; $i++)
    {
    push @insert, new CoW::Brush (shape => CUBE, kind => SOLID,
      sh => $self->{thick}*2,
      w => $self->{thick},
      );
    }
  # now insert them all
  $self->insert(@insert); 
  return $self;
  }

1; 

__END__

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

=pod

=head1 NAME

Frame -- a simple frame, optional with cross, facing North.

=head1 SYNOPSIS

	use CoW::Architecture::Frame;

	$frame = new CoW::Architexture::Frame ( 
	   l => 1, thick => 1,	# thickness of bars
	   hor_bars => 1,	# how many bars horizontal
 	   ver_bars => 0,	# how many vertical
	  );
	print $frame->as_string();

=head1 REQUIRES

perl5.005, Exporter, L<Bunch|Bunch>, L<Thing|Thing>, L<Coord|Coord>,
L<Angle|Angle>

=head1 EXPORTS

Exports nothing.

=head1 DESCRIPTION

This module creates a frame with C<thick> as the thickness of the frame.
The frame will stand and face north, per default. But you can rotate it
if needed.
The two parameters C<hor_bars> and C<ver_bars> control how many
bars will be created horizontal and vertical. Both default to 0.

The description horizontal/vertical actually only fits for the unrotated
frame, but always means the same set of bars.

See also L<Thing|Thing>.

=head1 FIELDS

The following additional fields are possible upon creation:

=over 2

=item thick

Thickness of bars around the inner space and horizontal/vertical bars.
Defaults to 1.

=item hor_bars, ver_bars

Number of bars horizontal/vertical. Default to 0.

=back

=head1 METHODS

=over 2

=item thick

This sets/gets the frame-thickness. 

=item hor_bars

This sets/gets the number of horizontal bars.

=item ver_bars

This sets/gets the number of vertical bars.

=item _construct

If you change one of the fields C<thick>, C<hor_bars> or C<ver_bars> directly,
call C<_construct()> so that the frame can reconstruct itself.

=back

=head1 BUGS

None known yet.

=head1 AUTHOR

Tels http://bloodgate.com in late 2000.

=cut

