Make CSV parts list that can be used to generate assembly labels v0.1
authorKeith Packard <keithp@keithp.com>
Thu, 23 Aug 2012 07:16:35 +0000 (00:16 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 23 Aug 2012 07:16:35 +0000 (00:16 -0700)
These labels get stuck inside the muffin tins during assembly

Signed-off-by: Keith Packard <keithp@keithp.com>
Makefile
gnet-partslist-csv.scm [new file with mode: 0644]

index 857cb97dbc340366faefccb0a4939ddc45e60ea9..483c422987a090b934e6c0b6243f49abe3a2b75a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,10 +12,13 @@ partslist:  $(PROJECT).sch Makefile
        tail -n+2 $(PROJECT)-bom.unsorted | sort >> partslist
 #      rm -f $(PROJECT)-bom.unsorted
 
-partslist.csv: $(PROJECT).sch Makefile
+partslist.tab: $(PROJECT).sch Makefile
        gnetlist -l gnet-partslist-keithp.scm -g partslist-keithp -o $(PROJECT)-list.unsorted $(PROJECT).sch
        nickle ./retab < $(PROJECT)-list.unsorted > $@
 
+partslist.csv: $(PROJECT).sch Makefile gnet-partslist-csv.scm
+       gnetlist -l gnet-partslist-csv.scm -g partslist-csv -o $@ $(PROJECT).sch
+
 partslist.dk:  $(PROJECT).sch Makefile
        gnetlist -m ./gnet-partslist-bom.scm -g partslist-bom -o $@ $(PROJECT).sch
 
diff --git a/gnet-partslist-csv.scm b/gnet-partslist-csv.scm
new file mode 100644 (file)
index 0000000..0f735f7
--- /dev/null
@@ -0,0 +1,86 @@
+; Copyright (C) 2001-2010 MIYAMOTO Takanori
+; gnet-partslist-csv.scm
+; 
+; This program is free software; you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation; either version 2 of the License, or
+; (at your option) any later version.
+; 
+; This program is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+; GNU General Public License for more details.
+; 
+; You should have received a copy of the GNU General Public License
+; along with this program; if not, write to the Free Software
+; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+; The /'s may not work on win32
+(load (string-append gedadata "/scheme/gnet-partslist-common.scm"))
+
+(define partslist-csv:write-top-header
+  (lambda (port)
+    (display "device, value, footprint, vendor, vendor_part_number, quantity, refdes\n" port)))
+
+(define (partslist-csv:write-partslist ls port)
+  (if (null? ls)
+      '()
+      (begin (write-one-row (cdar ls) ", " ", " port)
+            (write-one-row (caar ls) " " "\n" port)
+            (partslist-csv:write-partslist (cdr ls) port))))
+
+(define (count-same-parts ls)
+  (if (null? ls)
+      (append ls)
+      (let* ((parts-table-no-uref (let ((result '()))
+                                   (for-each (lambda (l) (set! result (cons (cdr l) result))) (reverse ls))
+                                   (append result)))
+            (first-ls (car parts-table-no-uref))
+            (match-length (length (member first-ls (reverse parts-table-no-uref))))
+            (rest-ls (list-tail ls match-length))
+            (match-ls (list-tail (reverse ls) (- (length ls) match-length)))
+            (uref-ls (let ((result '()))
+                       (for-each (lambda (l) (set! result (cons (car l) result))) match-ls)
+                       (append result))))
+       (cons (cons uref-ls (append first-ls  (list match-length))) (count-same-parts rest-ls)))))
+
+(define get-vendor
+   (lambda (package)
+      (gnetlist:get-package-attribute package "vendor")))
+
+(define get-vendor-part-number
+   (lambda (package)
+      (gnetlist:get-package-attribute package "vendor_part_number")))
+
+(define get-footprint
+   (lambda (package)
+      (gnetlist:get-package-attribute package "footprint")))
+
+(define get-loadstatus
+  (lambda (package)
+    (gnetlist:get-package-attribute package "loadstatus")))
+
+(define (get-parts-table-csv packages)
+  (if (null? packages)
+      '()
+      (let ((package (car packages)))
+       (if (string=? (get-device package) "include")
+           (get-parts-table-csv (cdr packages))
+           (if (string=? (get-loadstatus package) "smt")
+               (cons (list package
+                           (get-device package)
+                           (get-value package)
+                           (get-footprint package)
+                           (get-vendor package)
+                           (get-vendor-part-number package)) ;; sdb change
+                     (get-parts-table-csv (cdr packages)))
+               (get-parts-table-csv (cdr packages)))))))
+
+(define partslist-csv
+  (lambda (output-filename)
+    (let ((port (open-output-file output-filename))
+         (parts-table (marge-sort-with-multikey (get-parts-table-csv packages) '(1 2 3 0))))
+      (set! parts-table (count-same-parts parts-table))
+      (partslist-csv:write-top-header port)
+      (partslist-csv:write-partslist parts-table port)
+      (close-output-port port))))