#!@WISH@ -f # $Id: qfp-ui.in,v 1.1.1.1 2003/02/20 00:23:32 danmc Exp $ # # User Interface that generates custom QFP and SOIC packages for pcb-1.6.3 # Invoked from a line like # esyscmd(qfp-ui $1 $2 $3) # within an m4 macro triggered by pcb-1.6.3 # depends on having the Right [TM] m4 macro PKG_QFP in qfp.inc # Copyright 1999 Larry Doolittle # # SOIC support added Jan 2000 Larry Doolittle # Use nX==0 for that mode. # # Parts library added Feb 2000 Larry Doolittle # That feature is still rough, but it is useful, and you get the idea # # Refinement of library file usage Mar 2000 Larry Doolittle # Peeks at the X resource Pcb.libraryPath, uses that for a search path # for qfp.dat. Appends .:$HOME to that path, and writes any updates # (via the "Save" button) to $HOME/qfp.dat only. # # Wish list: # have someone else test it enough to know what needs fixing # proper support for changing pin 1 location # more choices of outline (at least inboard vs. outboard) # more packages in default qfp.dat, double checked and tested global description boardname partnum set description [ lindex $argv 0 ] set boardname [ lindex $argv 1 ] set partnum [ lindex $argv 2 ] # scaling and centering for canvas; # I use max_pix=380 for big screens, and trim it down to 266 for # use on my 640x480 laptop. # I've never seen any QFP exceed 36 mm, so max_mm=38 should be safe. set max_mm 38 set max_pix 266 global s c set s [ expr $max_pix/$max_mm*.0254 ] set c [ expr 0.5*$max_pix ] # fixme ... maybe put in a search path? Get from environment? set libwritedir "$env(HOME)" global libpath set libpath ".:$libwritedir" global libwritefile set libwritefile "$libwritedir/qfp.dat" # default values of the actual parameters that describe the QFP global istart nX nY pitch pwidth plength lX lY set istart 1 set nX 32 set nY 32 set pitch 8000 set pwidth 10 set plength 50 set lX 1290 set lY 1290 # Define the native units for each dimension # dm is "decimicrons" :-) allows exact conversion from microns or mils foreach v {pwidth plength lX lY} { global ${v}_native set ${v}_native mil } global pitch_native set pitch_native dm set factor(inch) 254000 set factor(mm) 10000 set factor(mil) 254 set factor(dm) 1 proc m4define { name val } { puts "define(`$name', $val)" } proc spit_output { } { global description boardname partnum global pkgname istart nX nY pitch pwidth plength lX lY m4define PITCH $pitch m4define PAD_LENGTH $plength m4define PAD_WIDTH $pwidth m4define ISTART $istart m4define XPADS $nX m4define YPADS $nY m4define X_LENGTH $lX m4define Y_LENGTH $lY puts "PKG_GEN_QFP($description, $boardname, $partnum)" exit } proc state_encode { } { global description boardname partnum global pkgname istart nX nY pitch pwidth plength lX lY return "$pitch $plength $pwidth $istart $nX $nY $lX $lY $partnum $description" } proc state_decode { s } { global description boardname partnum global pkgname istart nX nY pitch pwidth plength lX lY regexp {([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+) ([^ ]+) (.*)} $s dummy\ pitch plength pwidth istart nX nY lX lY partnum description } proc woohoo { x y } { global library catch { .p.txt tag delete mine } set loc [ .p.txt index "@$x,$y" ] regexp {([0-9]*)\.} $loc dummy l # puts "woo-hoo $x $y $loc $l" regexp {([^ ]+)} [ .p.txt get $l.0 "$l.0 lineend" ] dummy k if { [ catch { state_decode $library($k) } ] } return .p.txt tag add mine $l.0 "$l.0 lineend" .p.txt tag configure mine -background red push_state_to_screen draw_outline } proc libfiles_read { } { global libpath home if { [ catch { set fd [ open "| appres Pcb" ] } ] } return while { [ gets $fd line ] != -1 } { regexp {([a-zA-Z.]+):[ ] *([^ ]*)} $line dummy res_name res_value if { $res_name == "Pcb.libraryPath" } { set libpath "$res_value:$libpath" } } close $fd foreach f [ split $libpath ":" ] { libfile_read "$f/qfp.dat" } } proc libfile_read { filename } { global library if { [ catch { set fd [ open $filename ] } ] } return while { [ gets $fd line ] != -1 } { regexp {[0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ ([^ ]+) .*} $line dummy pn set library($pn) $line } close $fd } proc load_library { } { global library libline if { [ catch { toplevel .p } ] } return wm title .p "qfp-ui-library" frame .p.b button .p.b.dismiss -text "Dismiss" -command "destroy .p" pack .p.b.dismiss -side left pack .p.b -side bottom text .p.txt -width 40 -height 15 -font fixed \ -yscrollcommand ".p.sbar set" scrollbar .p.sbar -command ".p.txt yview" pack .p.txt -side left -fill both -expand 1 pack .p.sbar -side right -fill y catch { unset libline } libfiles_read set keys [ lsort [ array names library ] ] foreach d $keys { regexp {[0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ [0-9]+ ([^ ]+) (.*)} $library($d) dummy pn desc paint_lib_entry $pn $desc } .p.txt configure -state disabled bind .p.txt