#!btred -Te DrawTree
# -*- cperl -*-

sub DrawTree {
  my $top = shift || $this;
  my $only_attrs = undef;
  if (@_) {
    my %a;
    @a{ @_ } = ();
    $only_attrs=\%a;
  }
  my $node = $top;
  my $older;
  my $l;
  return unless $top;
  print "(";
  my @attrs = Attributes($top,1);
  print join ",",map { "$_->[0]='$_->[1]'" }
    grep { $_->[1] ne q{} } 
      map { [$_,$top->get_member($_)] }
	$only_attrs ? 
	  (grep { exists $only_attrs->{$_} } @attrs) : @attrs;
  print ")\n";

  $node=$top->firstson;
  while ($node) {
    $l='';
    $older=$node->parent;
    while ($older and $older!=$top) {
      if ($older->rbrother) {
	$l='| '.$l;
      } else {
	$l='  '.$l;
      }
      $older=$older->parent();
    }
    $l=" ".$l;
    print $l,"| \n";
    if ($node->rbrother) {
      $l.="+-[ ";
    } else {
      $l.="`-[ ";
    }
    print $l;
    my @attrs = Attributes($node,1);
    print join ",",map { "$_->[0]='$_->[1]'" }
      grep { $_->[1] ne q{} } 
      map { [$_,$node->get_member($_)] }
      $only_attrs ? 
      (grep { exists $only_attrs->{$_} } @attrs) : @attrs;
    print "]\n";
    $node=$node->following($top);
  }
}
