Skip to content

Commit

Permalink
Added design files for EDU-CIAA-INTEL
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo committed Apr 17, 2015
1 parent 51943c7 commit 9be8495
Show file tree
Hide file tree
Showing 69 changed files with 748,321 additions and 0 deletions.
93 changes: 93 additions & 0 deletions PCB/EDU-INTEL/bom_scripts/bom2csv.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!--XSL style sheet to convert EESCHEMA XML Partlist Format to CSV BOM Format
Copyright (C) 2013, Stefan Helmert.
GPL v2.
Functionality:
Generation of csv table with table head of all existing field names
and correct assigned cell entries
How to use this is explained in eeschema.pdf chapter 14. You enter a command line into the
netlist exporter using a new (custom) tab in the netlist export dialog. The command is
similar to
on Windows:
xsltproc -o "%O.csv" "C:\Program Files (x86)\KiCad\bin\plugins\bom2csv.xsl" "%I"
on Linux:
xsltproc -o "%O.csv" /usr/local/lib/kicad/plugins/bom2csv.xsl "%I"
Instead of "%O.csv" you can alternatively use "%O" if you will supply your own file extension when
prompted in the UI. The double quotes are there to account for the possibility of space(s)
in the filename.
-->

<!--
@package
Generate a Tab delimited list (csv file type).
One component per line
Fields are
Ref,Value, Footprint, Datasheet, Field5, Field4, price
-->

<!DOCTYPE xsl:stylesheet [
<!ENTITY nl "&#xd;&#xa;"> <!--new line CR, LF, or LF, your choice -->
]>


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>

<!-- for table head and empty table fields-->
<xsl:key name="headentr" match="field" use="@name"/>

<!-- main part -->
<xsl:template match="/export">
<xsl:text>Reference, Value, Footprint, Datasheet</xsl:text>

<!-- find all existing table head entries and list each one once -->
<xsl:for-each select="components/comp/fields/field[generate-id(.) = generate-id(key('headentr',@name)[1])]">
<xsl:text>, </xsl:text>
<xsl:value-of select="@name"/>
</xsl:for-each>
<xsl:text>&nl;</xsl:text>

<!-- all table entries -->
<xsl:apply-templates select="components/comp"/>
</xsl:template>

<!-- the table entries -->
<xsl:template match="components/comp">
<xsl:value-of select="@ref"/><xsl:text>,</xsl:text>
<xsl:value-of select="value"/><xsl:text>,</xsl:text>
<xsl:value-of select="footprint"/><xsl:text>,</xsl:text>
<xsl:value-of select="datasheet"/>
<xsl:apply-templates select="fields"/>
<xsl:text>&nl;</xsl:text>
</xsl:template>

<!-- table entries with dynamic table head -->
<xsl:template match="fields">

<!-- remember current fields section -->
<xsl:variable name="fieldvar" select="field"/>

<!-- for all existing head entries -->
<xsl:for-each select="/export/components/comp/fields/field[generate-id(.) = generate-id(key('headentr',@name)[1])]">
<xsl:variable name="allnames" select="@name"/>
<xsl:text>,</xsl:text>

<!-- for all field entries in the remembered fields section -->
<xsl:for-each select="$fieldvar">

<!-- only if this field entry exists in this fields section -->
<xsl:if test="@name=$allnames">
<!-- content of the field -->
<xsl:value-of select="."/>
</xsl:if>
<!--
If it does not exist, use an empty cell in output for this row.
Every non-blank entry is assigned to its proper column.
-->
</xsl:for-each>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
134 changes: 134 additions & 0 deletions PCB/EDU-INTEL/bom_scripts/bom_csv_grouped_by_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#
# Example python script to generate a BOM from a KiCad generic netlist
#
# Example: Sorted and Grouped CSV BOM
#

from __future__ import print_function

# Import the KiCad python helper module and the csv formatter
import kicad_netlist_reader
import csv
import sys


if len(sys.argv) != 3:
print("Usage ", __file__, "<generic_netlist.xml> <output.csv>", file=sys.stderr)
sys.exit(1)


# Generate an instance of a generic netlist, and load the netlist tree from
# the command line option. If the file doesn't exist, execution will stop
net = kicad_netlist_reader.netlist(sys.argv[1])

# Open a file to write to, if the file cannot be opened output to stdout
# instead
try:
f = open(sys.argv[2], 'w')
except IOError:
e = "Can't open output file for writing: " + sys.argv[2]
print( __file__, ":", e, sys.stderr )
f = sys.stdout

# subset the components to those wanted in the BOM, controlled
# by <configure> block in kicad_netlist_reader.py
components = net.getInterestingComponents()

compfields = net.gatherComponentFieldUnion(components)
partfields = net.gatherLibPartFieldUnion()

# remove Reference, Value, Datasheet, and Footprint, they will come from 'columns' below
partfields -= set( ['Reference', 'Value', 'Datasheet', 'Footprint'] )

columnset = compfields | partfields # union

# prepend an initial 'hard coded' list and put the enchillada into list 'columns'
columns = ['Item', 'Qty', 'Reference(s)', 'Value', 'LibPart', 'Footprint', 'Datasheet'] + sorted(list(columnset))

# Create a new csv writer object to use as the output formatter
out = csv.writer( f, lineterminator='\n', delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL )

# override csv.writer's writerow() to support utf8 encoding:
def writerow( acsvwriter, columns ):
utf8row = []
for col in columns:
utf8row.append( str(col).encode('utf8') )
acsvwriter.writerow( utf8row )

# Output a set of rows as a header providing general information
writerow( out, ['Source:', net.getSource()] )
writerow( out, ['Date:', net.getDate()] )
writerow( out, ['Tool:', net.getTool()] )
writerow( out, ['Component Count:', len(components)] )
writerow( out, [] )
writerow( out, ['Individual Components:'] )
writerow( out, [] ) # blank line
writerow( out, columns )

# Output all the interesting components individually first:
row = []
for c in components:
del row[:]
row.append('') # item is blank in individual table
row.append('') # Qty is always 1, why print it
row.append( c.getRef() ) # Reference
row.append( c.getValue() ) # Value
row.append( c.getLibName() + ":" + c.getPartName() ) # LibPart
#row.append( c.getDescription() )
row.append( c.getFootprint() )
row.append( c.getDatasheet() )

# from column 7 upwards, use the fieldnames to grab the data
for field in columns[7:]:
row.append( c.getField( field ) );

writerow( out, row )


writerow( out, [] ) # blank line
writerow( out, [] ) # blank line
writerow( out, [] ) # blank line

writerow( out, ['Collated Components:'] )
writerow( out, [] ) # blank line
writerow( out, columns ) # reuse same columns



# Get all of the components in groups of matching parts + values
# (see kicad_netlist_reader.py)
grouped = net.groupComponents(components)


# Output component information organized by group, aka as collated:
item = 0
for group in grouped:
del row[:]
refs = ""

# Add the reference of every component in the group and keep a reference
# to the component so that the other data can be filled in once per group
for component in group:
if len(refs) > 0:
refs += ", "
refs += component.getRef()
c = component

# Fill in the component groups common data
# columns = ['Item', 'Qty', 'Reference(s)', 'Value', 'LibPart', 'Footprint', 'Datasheet'] + sorted(list(columnset))
item += 1
row.append( item )
row.append( len(group) )
row.append( refs );
row.append( c.getValue() )
row.append( c.getLibName() + ":" + c.getPartName() )
row.append( net.getGroupFootprint(group) )
row.append( net.getGroupDatasheet(group) )

# from column 7 upwards, use the fieldnames to grab the data
for field in columns[7:]:
row.append( net.getGroupField(group, field) );

writerow( out, row )

f.close()
45 changes: 45 additions & 0 deletions PCB/EDU-INTEL/bom_scripts/bom_cvs.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="ISO-8859-1"?>

<!--XSL style sheet that takes EESCHEMA's Generic Netlist Format as input and
outputs a simple BOM in CSV format. Feel free to enhance this and submit
patches.
How to use:
Eeschema.pdf: chapter 14
-->
<!--
@package
Generate a comma separated value BOM list (csv file type).
Components are sorted by value
One component per line
Fields are
Quantity, 'Part name', Description, lib
-->

<!DOCTYPE xsl:stylesheet [
<!ENTITY nl "&#xd;&#xa;"> <!--new line CR, LF -->
]>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>

<!-- for each component -->
<xsl:template match="libpart">

<!-- -->
<xsl:value-of select="count(//comp/libsource/@part[@part])"/><xsl:text>,"</xsl:text>
<xsl:value-of select="@part"/><xsl:text>","</xsl:text>
<xsl:value-of select="description"/><xsl:text>","</xsl:text>
<xsl:value-of select="@lib"/>

<xsl:text>"&nl;</xsl:text>
</xsl:template>


<xsl:template match="/export">
<xsl:text>Qty,partname,description,lib&nl;</xsl:text>
<xsl:apply-templates select="libparts/libpart"/>
</xsl:template>


</xsl:stylesheet>
Loading

0 comments on commit 9be8495

Please sign in to comment.