Version 0 of dxf

Updated 2003-09-10 11:26:49

Here is a script from Tcad 2.0b

    # Program: dxf (an autocad's dxf to tk's canvas converter)
    # Author:  Tuan T. Doan
# Date
4/20/93
    # =========================================================================
    # Copyright 1993 Tuan T. Doan
    #
    # Permission to use, copy, modify, and distribute this software and its
    # documentation for any purpose and without fee is hereby granted,
    # provided that the above copyright notice appear in all copies.  Tuan
    # Doan make no representations about the suitability of this software
    # for any purpose.  It is provided "as is" without express or implied
    # warranty.  If you do use any part of the software, I would like to
    # know about it.  Please send me mail at [email protected]
    #
    # DXF format is copyrighted by Autodesk, Inc.
    # =========================================================================

    set auto_path ". $auto_path"

    set gvar(unit) p
    set gvar(scale) 1.0

    proc _gettuple {fd} {
        #  read in two lines; first line = groupcode, second line = groupvalue
        global gvar
        set gvar(groupcode)  [string trim [gets $fd]]
        set gvar(groupvalue) [string trim [gets $fd]]
        #  puts stdout "$gvar(groupcode) $gvar(groupvalue) - " nonewline
    }

    proc _circle {fd} {
        #  we already read: 0,CIRCLE  ; continue to read in circle info until see 0
        #  interested in: 10=xcenter, 20=ycenter, 40=radius
        global gvar
        while {! [eof $fd]} {
            _gettuple $fd
            case $gvar(groupcode) in {
                {0}   {return "[expr $x-$r]$gvar(unit) [expr $y-$r]$gvar(unit) [expr $x+$r]$gvar(unit) [expr $y+$r]$gvar(unit) -outline black"}
                {10}  {set x $gvar(groupvalue)}
                {20}  {set y [expr {-1 * $gvar(groupvalue)}]}
                {40}  {set r $gvar(groupvalue)}
                {62}  {set gvar(color) $gvar(groupvalue)}
            }
        }
    }

    proc _line {fd} {
        #  we already read: 0,LINE  ; continue to read in line info until see 0
        #  interested in: 10=xpoint1, 20=ypoint1, 11=xpoint2, 21=ypoint2
        global gvar
        while {! [eof $fd]} {
            _gettuple $fd
            case $gvar(groupcode) in {
                {0}   {return "${x1}$gvar(unit) ${y1}$gvar(unit) ${x2}$gvar(unit) ${y2}$gvar(unit) -fill black"}
                {10}  {set x1 $gvar(groupvalue)}
                {20}  {set y1 [expr {-1 * $gvar(groupvalue)}]}
                {11}  {set x2 $gvar(groupvalue)}
                {21}  {set y2 [expr {-1 * $gvar(groupvalue)}]}
                {62}  {set gvar(color) $gvar(groupvalue)}
            }
        }
    }

    proc _triangle {fd} {
        #  we already read: 0,3DFACE ; continue to read in surface info until see 0
        #  interested in: 10=xpoint1, 20=ypoint1, 11=xpoint2, 21=ypoint2
        #                 12=xpoint3, 22=ypoint3, 13=xpoint3, 23=ypoint3
        #  if last point 3 is same as point 4, we want only points 1-3
        global gvar
        set x1 ""; set x2 ""; set x3 ""; set x4 ""
        set y1 ""; set y2 ""; set y3 ""; set y4 ""
        while {! [eof $fd]} {
            _gettuple $fd
            case $gvar(groupcode) in {
                {0}   {if {$x3==$x4 && $y3==$y4} {
                        puts stdout "3dtri"
                        #               return "polygon ${x1}$gvar(unit) ${y1}$gvar(unit) ${x2}$gvar(unit) ${y2}$gvar(unit) ${x3}$gvar(unit) ${y3}$gvar(unit) -fill white"
                        return "line ${x1}$gvar(unit) ${y1}$gvar(unit) ${x2}$gvar(unit) ${y2}$gvar(unit) ${x3}$gvar(unit) ${y3}$gvar(unit) -fill black"
                    } else {
                        puts stdout "3dpoly"
                        #               return "polygon ${x1}$gvar(unit) ${y1}$gvar(unit) ${x2}$gvar(unit) ${y2}$gvar(unit) ${x3}$gvar(unit) ${y3}$gvar(unit) ${x4}$gvar(unit) ${y4}$gvar(unit) -fill white"
                        return "line ${x1}$gvar(unit) ${y1}$gvar(unit) ${x2}$gva