Skip to content

Commit

Permalink
added support for datasheet fields
Browse files Browse the repository at this point in the history
  • Loading branch information
HashDefineElectronics committed Sep 9, 2017
1 parent 7abdd1f commit f16c62a
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Doc/shortcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ These are the list of short code that are used in the template files.
<!--ROW_PART_QTY--> inserts the number of parts grouped together
<!--ROW_PART_VALUE--> inserts the part value
<!--ROW_PART_FOOTPRINT--> inserts the part footprint.
<!--ROW_PART_DATASHEET--> inserts the part datasheet.
<!--ROW_PART_FIELDS--> inserts the generator parts fields
<!--ROW_CLASS_ODD_EVEN_TAG--> returns RowEvenTag on even rows or RowOddTag for odds rows.
<!--HEADER_CLASS_REF_TAG--> insert the tag for the part reference. HeadRefTag
<!--HEADER_CLASS_QTY_TAG--> insert the tag for the part qty. HeadQtyTag
<!--HEADER_CLASS_VALUE_TAG--> insert the tag for the part value. HeadValueTag
<!--HEADER_CLASS_FOOTPRINT_TAG--> insert the tag for the part footprint. HeadFootprintTag
<!--HEADER_CLASS_DATASHEET_TAG--> insert the tag for the part datasheet. HeadDatasheetTag


### for fields.conf:
Expand Down
1 change: 1 addition & 0 deletions Example/example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<components>
<comp ref="C1">
<value>C1210C106K5RACTU</value>
<datasheet>C1210C106K5RACTU.pdf</datasheet>
<footprint>Capacitors:CAP_1210</footprint>
<fields>
<field name="Description">10uF, 50V, 1210, MLCC, X7R 10%</field>
Expand Down
2 changes: 1 addition & 1 deletion KiCad_BOM_Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Ronald Sousa http://hashdefineelectronics.com/kicad-bom-wizard/
*
* @version 0.0.10
* @version 0.0.11
*
* @fileoverview This KiCad plugin can be used to create custom BOM files based on easy
* configurable templates files. The plugin is writing in JavaScript and has been
Expand Down
17 changes: 15 additions & 2 deletions Lib/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function SearchUniquePartIndex (source, searchTerm, listOfGroups) {
// reset the filed test flag. this will ensure that we check the next part that might have all the matching fields
var FieldsTestResult = true
// part value matches
if (searchTerm.Value === source[Index].Value && searchTerm.Footprint === source[Index].Footprint) {
if (searchTerm.Value === source[Index].Value && searchTerm.Footprint === source[Index].Footprint && searchTerm.Datasheet === source[Index].Datasheet) {
for (var FieldIndex = 0; FieldIndex < listOfGroups.length; FieldIndex++) {
// If either one is true
if (listOfGroups[ FieldIndex ] in searchTerm.Fields || listOfGroups[ FieldIndex ] in source[Index].Fields) {
Expand Down Expand Up @@ -116,6 +116,7 @@ function ExtractAndSortComponents (config) {

// Get the list of groups we are going to use
Components.inputData.export.components[0].comp.forEach(function (Part) {

if (Part.fields) {
Part.fields.forEach(function (value) {
value.field.forEach(function (value) {
Expand Down Expand Up @@ -147,7 +148,14 @@ function ExtractAndSortComponents (config) {
FootprintValue = Part.footprint[0]
}

var TempPart = {Value: Part.value[0], Count: 1, Ref: [], Fields: TempFieldHolder, Footprint: FootprintValue, RefPrefix: Part.$.ref.replace(/[0-9]/g, '')}
var DatasheetValue = ''

// get the component footprint if its not been defined or left empty
if (typeof Part.datasheet !== 'undefined' && typeof Part.datasheet[0] !== 'undefined') {
DatasheetValue = Part.datasheet[0]
}

var TempPart = {Value: Part.value[0], Count: 1, Ref: [], Fields: TempFieldHolder, Datasheet: DatasheetValue, Footprint: FootprintValue, RefPrefix: Part.$.ref.replace(/[0-9]/g, '')}

PartIndex = SearchUniquePartIndex(Components.UniquePartList, TempPart, Components.sortMeta.fields)

Expand Down Expand Up @@ -235,6 +243,11 @@ function ApplaySort(config) {
CompareA = partA.Footprint
CompareB = partB.Footprint
break
case 'datasheet':
IsNumber = false
CompareA = partA.Datasheet
CompareB = partB.Datasheet
break
default:
return 0 // leave unsorted
}
Expand Down
2 changes: 1 addition & 1 deletion Lib/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var Config = {
landscape: false,
marginsType : 0
},
sort : {by: 'ref', ascending: true} // possible ref, qty, value, value_num, footprint
sort : {by: 'ref', ascending: true} // possible ref, qty, value, value_num, footprint, datasheet
}

/**
Expand Down
7 changes: 7 additions & 0 deletions Lib/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function GenerateTable (component, template) {
} else if (ListOfheaders[HeaderIndex].indexOf('FOOTPRINT-->') !== -1) {
HeaderTemp += template.header.replace(/<!--HEADER_ROW-->/g, 'Footprint')
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_FOOTPRINT_TAG-->/g, 'HeadFootprintTag')
} else if (ListOfheaders[HeaderIndex].indexOf('DATASHEET-->') !== -1) {
HeaderTemp += template.header.replace(/<!--HEADER_ROW-->/g, 'Datasheet')
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_DATASHEET_TAG-->/g, 'HeadDatasheetTag')
} else if (ListOfheaders[HeaderIndex].indexOf('FIELDS-->') !== -1) {
// this will help us place the fileds header
HeaderTemp += '<!--FIELDS_HEADER_PLACEHOLDER-->'
Expand All @@ -77,6 +80,7 @@ function GenerateTable (component, template) {
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_QTY_TAG-->/g, '')
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_VALUE_TAG-->/g, '')
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_FOOTPRINT_TAG-->/g, '')
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_DATASHEET_TAG-->/g, '')
HeaderTemp = HeaderTemp.replace(/<!--HEADER_CLASS_FIELDS-->/g, '')
}
}
Expand All @@ -89,6 +93,7 @@ function GenerateTable (component, template) {
TempFieldHeader = TempFieldHeader.replace(/<!--HEADER_CLASS_QTY_TAG-->/g, '')
TempFieldHeader = TempFieldHeader.replace(/<!--HEADER_CLASS_VALUE_TAG-->/g, '')
TempFieldHeader = TempFieldHeader.replace(/<!--HEADER_CLASS_FOOTPRINT_TAG-->/g, '')
TempFieldHeader = TempFieldHeader.replace(/<!--HEADER_CLASS_DATASHEET_TAG-->/g, '')
TempFieldHeader = TempFieldHeader.replace(/<!--HEADER_CLASS_FIELDS-->/g, 'HeadField_' + component.sortMeta.fields[ FieldIndex ].replace(' ','_'))
}

Expand Down Expand Up @@ -124,11 +129,13 @@ function GenerateTable (component, template) {
TempRow = TempRow.replace(/<!--ROW_PART_QTY-->/g, component.GroupedList[GroupdName][Item].Count)
TempRow = TempRow.replace(/<!--ROW_PART_VALUE-->/g, component.GroupedList[GroupdName][Item].Value)
TempRow = TempRow.replace(/<!--ROW_PART_FOOTPRINT-->/g, component.GroupedList[GroupdName][Item].Footprint)
TempRow = TempRow.replace(/<!--ROW_PART_DATASHEET-->/g, component.GroupedList[GroupdName][Item].Datasheet)

TempRow = TempRow.replace(/<!--HEADER_CLASS_REF_TAG-->/g, 'HeadRefTag')
TempRow = TempRow.replace(/<!--HEADER_CLASS_QTY_TAG-->/g, 'HeadQtyTag')
TempRow = TempRow.replace(/<!--HEADER_CLASS_VALUE_TAG-->/g, 'HeadValueTag')
TempRow = TempRow.replace(/<!--HEADER_CLASS_FOOTPRINT_TAG-->/g, 'HeadFootprintTag')
TempRow = TempRow.replace(/<!--HEADER_CLASS_DATASHEET_TAG-->/g, 'HeadDatasheetTag')

var FieldsTemp = ''

Expand Down
2 changes: 1 addition & 1 deletion Template/CSV/row.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!--ROW_PART_REF-->,<!--ROW_PART_QTY-->,<!--ROW_PART_VALUE-->,<!--ROW_PART_FOOTPRINT--><!--ROW_PART_FIELDS-->
<!--ROW_PART_REF-->,<!--ROW_PART_QTY-->,<!--ROW_PART_VALUE-->,<!--ROW_PART_FOOTPRINT-->,<!--ROW_PART_DATASHEET--><!--ROW_PART_FIELDS-->
2 changes: 1 addition & 1 deletion Template/HTML/headers.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class='Head <!--HEADER_CLASS_REF_TAG--><!--HEADER_CLASS_QTY_TAG--><!--HEADER_CLASS_VALUE_TAG--><!--HEADER_CLASS_FOOTPRINT_TAG-->'><!--HEADER_ROW--></div>
<div class='Head <!--HEADER_CLASS_REF_TAG--><!--HEADER_CLASS_QTY_TAG--><!--HEADER_CLASS_VALUE_TAG--><!--HEADER_CLASS_FOOTPRINT_TAG--><!--HEADER_CLASS_DATASHEET_TAG-->'><!--HEADER_ROW--></div>
1 change: 1 addition & 0 deletions Template/HTML/row.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<div class="column <!--HEADER_CLASS_QTY_TAG-->"><!--ROW_PART_QTY--></div>
<div class="column <!--HEADER_CLASS_VALUE_TAG-->"><!--ROW_PART_VALUE--></div>
<div class="column <!--HEADER_CLASS_FOOTPRINT_TAG-->"><!--ROW_PART_FOOTPRINT--></div>
<div class="column <!--HEADER_CLASS_DATASHEET_TAG-->"><!--ROW_PART_DATASHEET--></div>
<!--ROW_PART_FIELDS-->
</div>
2 changes: 1 addition & 1 deletion Template/HTML_PDF/headers.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<th class='Head <!--HEADER_CLASS_REF_TAG--><!--HEADER_CLASS_QTY_TAG--><!--HEADER_CLASS_VALUE_TAG--><!--HEADER_CLASS_FOOTPRINT_TAG--><!--HEADER_CLASS_FIELDS-->'><!--HEADER_ROW--></th>
<th class='Head <!--HEADER_CLASS_REF_TAG--><!--HEADER_CLASS_QTY_TAG--><!--HEADER_CLASS_VALUE_TAG--><!--HEADER_CLASS_FOOTPRINT_TAG--><!--HEADER_CLASS_DATASHEET_TAG--><!--HEADER_CLASS_FIELDS-->'><!--HEADER_ROW--></th>
1 change: 1 addition & 0 deletions Template/HTML_PDF/row.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<td class="<!--HEADER_CLASS_QTY_TAG-->"><!--ROW_PART_QTY--></td>
<td class="<!--HEADER_CLASS_VALUE_TAG-->"><!--ROW_PART_VALUE--></td>
<td class="<!--HEADER_CLASS_FOOTPRINT_TAG-->"><!--ROW_PART_FOOTPRINT--></td>
<td class="<!--HEADER_CLASS_DATASHEET_TAG-->"><!--ROW_PART_DATASHEET--></td>
<!--ROW_PART_FIELDS-->
</tr>

0 comments on commit f16c62a

Please sign in to comment.