[PythonCAD] I/O filters via text streams

Eric Wilhelm ewilhelm at sbcglobal.net
Thu Feb 12 13:53:28 EST 2004

> The following was supposedly scribed by
> Art Haas
> on Thursday 12 February 2004 12:20 pm:

>Aside from the lack of writing either a DWG or DXF file, a problem with
>the current DWG reader is that it won't work if the DWG info is coming
>in through a pipe, as the reader does all sorts of seek()ing through the
>file when reading the objects found in the object map. One can read a DWG
>file from in a serial manner, but that isn't how the code does it at
> present.

I don't think that is really a problem.  Some formats are more suited to being 
parsed into a library as a whole (would that be the wholistic method?)

Where pipes come in is the ability to connect libraries from dissimilar 
languages.  I think it's fine if one end of the pipe has to read everything 
before it can start emitting to the other end (and also fine if the far end 
has to receive everything before saving / dumping.)

The central part of the idea that I have is that CAD::Drawing would have a 
stream implementation available for its objects so that a middle-ground 
in-memory data-structure is not necessary.  The worst case would be two 
wholistic formats connected together, but its much better to store the data 
in two places rather than three.  The best case would be two streamable 
formats connected together, where each time an entity is read from the input 
stream, it is immediately added to the output stream.

CAD::Drawing currently implements multiple format support by having each 
backend use a load and save function.  The load function calls add<thing> 
methods and the save function calls get<thing> methods.  Currently, these 
methods build into an in-memory data structure, so to go from dwg to dxf, you 
load the whole dwg via the library (in C structs, etc), go through it adding 
each entity to a format-agnostic data structure, and then go through that 
data structure, adding each entity to a dxf object before saving the file.

The thought is to have the add<thing> methods be connectable directly to the 
output format.  So, rather than having 4000 entities in the middle-ground 
memory between formats, you would have 1 entity in memory at a time which 
gets passed directly to the save function.

A counterintuitive sansevieria trifasciata was once literalized guiltily.
                                        --Product of Artificial Intelligence

More information about the PythonCAD mailing list