=pod

=head1 NAME

CAD::Drawing::IO::DWGI - Perl bindings to the OpenDWG toolkit

=head1 WARNING

This module is intended to serve as a backend to CAD::Drawing and is not
guaranteed to remain interface stable.  Do not use this module directly
unless you have a need for higher-speed access than that which is
provided by CAD::Drawing (which also provides loads of other features.)

Just 

  use CAD::Drawing 

=head1 AUTHOR

  Eric L. Wilhelm
  ewilhelm AT sbcglobal DOT net
  http://pages.sbcglobal.net/mycroft

=head1 COPYRIGHT

This module is copyright 2003 by Eric L. Wilhelm and A. Zahner Co.  

This is module is free software as described under the terms below.
Permission to use, modify and distribute this module shall be governed
by these terms (the module code is distributed and licensed
independently from the OpenDWG consortium's code.)  All notices and
disclaimers must remain intact with any copies of this software.

=head1 LICENSE

This module is distributed under the same terms as Perl.  See the Perl
source package for details.

=head1 REQUIREMENTS

You must obtain and install the OpenDWG libraries from the OpenDWG
consortium in order to use this module.  By using this module, you have
the responsibility to adhere to both the licensing of this module and
the licensing of the OpenDWG consortium.

=head1 SYNOPSIS

  use CAD::Drawing::IO::DWGI;
  $dwg = CAD::Drawing::IO::DWGI->new();
  $dwg->loadfile("file.dwg");
  $dwg->getentinit();
  while(my($layer, $color, $type) = $dwg->getent()) {
    my $type = $dwg->entype($type);
    if($type eq "lines") {
      $line = $dwg->getLine();
      }
    }
  
  $dxf = CAD::Drawing::IO::DWGI->new();
  $dxf->newfile(1);
  $dxf->getentinit();
  $dxf->writeCircle({"pt"=>[$x, $y], "rad" => 1.125, "color" => 9});
  $dxf->savefile("check.dxf", 1);

=head1 SPEED

Wow!  This is fast!  I had originally implemented this with a
function-call based wrapper which had the drawback that the layerhandle
had to be found for every object which was being saved.  See the
writeLayer() and setLayer() functions below for details of the improved
methods.  Also note that while the speed is amazing from this level,
very little speed is lost by moving up a level to using CAD::Drawing
(please do this.)

=head1 Accuracy

The dxf file accuracy is set internally at 14 digits after the decimal
place.  Providing an interface to set this would take a bit of coding
in C, so you are more than welcome to submit a patch.

=head1 Changes

  0.08 First public release
  0.09 Fixed error reading image size


=head1 Constructor

=head2 new

Creates a new blessed reference which gives access to the following
object methods.

  $d = CAD::Drawing::IO::DWGI->new();

=head1 File Actions

=head2 loadfile

Loads a file from disk into the toolkit data structure.

  $d->loadfile("filename.dxf|dwg");

=head2 newfile

Creates an empty data structure and initializes some default values.

  $d->newfile($version);

=head2 savefile

Writes the data to disk.

  $d->savefile($name, $type);

=head1 Layer Actions

=head2 listlayers

Returns a list of layers in the loaded object.

  @layers = $d->listlayers();

=head2 writeLayer

Add a new layer to the database and set it as the current layer.  A
newfile() starts with layer "0" as the default.

=head2 setLayer

Set layer as the default.  Layer must have been previously created with
writeLayer().

=head1 Typed Entity Functions

=head2 getCircle

Reads a circle from the current entity.  NOTE that all getThing methods
must be part of a getent() loop.

$circle = $d->getCircle();
print "point:  ", join(",", @{$circle->{pt}}), "\n";
print "rad:    $circle->{rad}\n";

=head2 writeCircle

Writes a circle to the object structure.

$d->writeCircle({"pt"=>[$x,$y,$z], "rad"=>$rad, "color"=>$color});

=head2 getArc

Reads an arc from the current entity.

$arc = $d->getArc();
print "point:  ", join(",", @{$arc->{pt}}), "\n";
print "rad:    $arc->{rad}\n";
print "radian angles: ", join(",", @{$arc->{angs}}), "\n";

=head2 writeArc

Writes an arc to the object structure.

%ArcOpts = ( 
		"pt" => [$x,$y,$z],
		"rad" => $rad,
		"angs" => [$start, $end],
		"color" => $color,
		);
$d->writeArc(\%ArcOpts);

=head2 getLine

Reads a line from the current entity.

$line = $d->getLine();
print "endpoints:  ", 
	join("\n", 
			map({join(",", @{$_})}
				@{$line->{pts}}
			   )
		), "\n";

=head2 writeLine

Writes a line to the object structure.

%LineOpts = (
		"pts" => [ [$x1,$y1,$z1], [$x2,$y2,$z2] ],
		"color" => $color,
		);
$d->writeLine(\%LineOpts);

=head2 getText

$text = $d->getText();
print "point:  ", join(",", @{$text->{pt}}), "\n";
print "string: ", $text->{string}, "\n";
print "height: ", $text->{height}, "\n";

=head2 writeText

%TextOpts = (
		"pt" => [$x, $y, $z],
		"string" => $string,
		"height" => $height,
		"color" => $color,
		);
$d->writeText(\%TextOpts);

=head2 getPoint

$point = $d->getPoint();
print "point:  ", join(",", @{$point->{pt}}), "\n";

=head2 writePoint

%PointOpts = (
		"pt" => [$x, $y, $z],
		"color" => $color,
		);
$d->writePoint(\%PointOpts);

=head2 getLWPline

$pline = $d->getLWPline();
print "points:\n\t", 
	join("\n\t", 
			map({join(",", @{$_})}
				@{$pline->{pts}}
			   )
		), "\n";
	$pline->{closed} && print "closed\n";

=head2 writeLWPline

@pts = (
		[0,1],
		[5,-2.25],
		[7,9],
		[4,6],
		[-2,7.375],
	   );
%PlineOpts = (
		"pts" => \@pts,
		"closed" => 1,
		"color" => 255,
		);
$d->writeLWPline(\%PlineOpts);

=head1 Entity List handling

=head2 getentinit

Initializes the entity list.  Call this before adding anything to a
newfile() or before calling getent() after loadfile()

=head2 getent

Returns the next entity.  This is paired with getentinit() and the two
act as a pair much like Perl's open() and $line = <FILEHANDLE> setup.

=head1 Utilities

=head2 get_extrusion

Returns the extrusion vector of the current entity as an array
reference.

=head2 set_extrusion

Sets the extrusion direction of the current entity.  Not intended to be
used from Perl (each write<entity> function calls this itself if the
value of $optsextrusion is set.)

=head2 entype

Return a text string for the entity type code.

  $type = $d->entype($type);
  if($type eq "plines") {
    $pline = $d->getLWPline();
    }

=head2 DESTROY

This function is called under the hood by perl when variables created by
new() go out of scope.  You should never call this from your code, but
you can undef() your object and it will get called.


