Skip to content

Commit

Permalink
Merge pull request #85 from INTI-CMNB/generate_dnf
Browse files Browse the repository at this point in the history
Added 'html_generate_dnf' to add a separated section for DNF components
  • Loading branch information
SchrodingersGat authored Mar 13, 2020
2 parents d395f50 + 2aaa317 commit 8802e17
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions bomlib/html_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,50 @@ def WriteHTML(filename, groups, net, headings, prefs):
html.write("</table>\n")
html.write("<br><br>\n")

if prefs.generateDNF:
html.write("<h2>Optional components (DNF=Do Not Fit)</h2>\n")

# DNF component groups
html.write('<table border="1">\n')

# Row titles:
html.write("<tr>\n")
if prefs.numberRows:
html.write("\t<th></th>\n")
for i, h in enumerate(headings):
# Cell background color
bg = bgColor(h)
html.write('\t<th align="center"{bg}>{h}</th>\n'.format(h=h, bg=' bgcolor="{c}"'.format(c=bg) if bg else ''))
html.write("</tr>\n")

rowCount = 0

for i, group in enumerate(groups):

if not(prefs.ignoreDNF and not group.isFitted()):
continue

row = group.getRow(headings)
rowCount += 1
html.write("<tr>\n")

if prefs.numberRows:
html.write('\t<td align="center">{n}</td>\n'.format(n=rowCount))

for n, r in enumerate(row):

if len(r) == 0:
bg = BG_EMPTY
else:
bg = bgColor(headings[n])

html.write('\t<td align="center"{bg}>{val}</td>\n'.format(bg=' bgcolor={c}'.format(c=bg) if bg else '', val=link(r)))

html.write("</tr>\n")

html.write("</table>\n")
html.write("<br><br>\n")

html.write("</body></html>")

return True
4 changes: 4 additions & 0 deletions bomlib/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BomPref:
OPT_ALT_WRAP = "alt_wrap"
OPT_MERGE_BLANK = "merge_blank_fields"
OPT_IGNORE_DNF = "ignore_dnf"
OPT_GENERATE_DNF = "html_generate_dnf"
OPT_BACKUP = "make_backup"
OPT_OUTPUT_FILE_NAME = "output_file_name"
OPT_VARIANT_FILE_NAME_FORMAT = "variant_file_name_format"
Expand All @@ -52,6 +53,7 @@ def __init__(self):
self.useAlt = False # Use alternate reference representation
self.altWrap = None # Wrap to n items when using alt representation
self.ignoreDNF = True # Ignore rows for do-not-fit parts
self.generateDNF = True # Generate a list of do-not-fit parts
self.numberRows = True # Add row-numbers to BoM output
self.groupConnectors = True # Group connectors and ignore component value
self.useRegex = True # Test various columns with regex
Expand Down Expand Up @@ -134,6 +136,7 @@ def Read(self, file, verbose=False):
# Read general options
if self.SECTION_GENERAL in cf.sections():
self.ignoreDNF = self.checkOption(cf, self.OPT_IGNORE_DNF, default=True)
self.generateDNF = self.checkOption(cf, self.OPT_GENERATE_DNF, default=True)
self.useAlt = self.checkOption(cf, self.OPT_USE_ALT, default=False)
self.altWrap = self.checkInt(cf, self.OPT_ALT_WRAP, default=None)
self.numberRows = self.checkOption(cf, self.OPT_NUMBER_ROWS, default=True)
Expand Down Expand Up @@ -209,6 +212,7 @@ def Write(self, file):
cf.add_section(self.SECTION_GENERAL)
cf.set(self.SECTION_GENERAL, "; General BoM options here")
self.addOption(cf, self.OPT_IGNORE_DNF, self.ignoreDNF, comment="If '{opt}' option is set to 1, rows that are not to be fitted on the PCB will not be written to the BoM file".format(opt=self.OPT_IGNORE_DNF))
self.addOption(cf, self.OPT_GENERATE_DNF, self.generateDNF, comment="If '{opt}' option is set to 1, also generate a list of components not fitted on the PCB (HTML only)".format(opt=self.OPT_GENERATE_DNF))
self.addOption(cf, self.OPT_USE_ALT, self.useAlt, comment="If '{opt}' option is set to 1, grouped references will be printed in the alternate compressed style eg: R1-R7,R18".format(opt=self.OPT_USE_ALT))
self.addOption(cf, self.OPT_ALT_WRAP, self.altWrap, comment="If '{opt}' option is set to and integer N, the references field will wrap after N entries are printed".format(opt=self.OPT_ALT_WRAP))
self.addOption(cf, self.OPT_NUMBER_ROWS, self.numberRows, comment="If '{opt}' option is set to 1, each row in the BoM will be prepended with an incrementing row number".format(opt=self.OPT_NUMBER_ROWS))
Expand Down

0 comments on commit 8802e17

Please sign in to comment.