Added support for filters and variants to pdf_print_sch
This commit is contained in:
parent
05f14e2049
commit
0216fc93c7
|
|
@ -1534,10 +1534,12 @@ class Schematic(object):
|
|||
lib_no = os.path.join(dest_dir, 'n.lib')
|
||||
self.gen_lib(lib_yes)
|
||||
self.gen_lib(lib_no, cross=True)
|
||||
self.save(os.path.basename(self.fname), dest_dir)
|
||||
fname = os.path.basename(self.fname)
|
||||
self.save(fname, dest_dir)
|
||||
# SymLibTable to use y/n
|
||||
with open(os.path.join(dest_dir, 'sym-lib-table'), 'wt') as f:
|
||||
f.write('(sym_lib_table\n')
|
||||
f.write(' (lib (name y)(type Legacy)(uri ${KIPRJMOD}/y.lib)(options "")(descr ""))\n')
|
||||
f.write(' (lib (name n)(type Legacy)(uri ${KIPRJMOD}/n.lib)(options "")(descr ""))\n')
|
||||
f.write(')\n')
|
||||
return fname
|
||||
|
|
|
|||
|
|
@ -4,11 +4,15 @@
|
|||
# License: GPL-3.0
|
||||
# Project: KiBot (formerly KiPlot)
|
||||
import os
|
||||
from tempfile import mkdtemp
|
||||
from shutil import rmtree
|
||||
from .gs import (GS)
|
||||
from .kiplot import check_eeschema_do, exec_with_retry
|
||||
from .misc import (CMD_EESCHEMA_DO, PDF_SCH_PRINT)
|
||||
from .optionable import BaseOptions
|
||||
from .optionable import BaseOptions, Optionable
|
||||
from .registrable import RegOutput
|
||||
from .macros import macros, document, output_class # noqa: F401
|
||||
from .fil_base import BaseFilter
|
||||
from . import log
|
||||
|
||||
logger = log.get_logger(__name__)
|
||||
|
|
@ -19,11 +23,38 @@ class PDF_Sch_PrintOptions(BaseOptions):
|
|||
with document:
|
||||
self.output = GS.def_global_output
|
||||
""" filename for the output PDF (%i=schematic %x=pdf) """
|
||||
self.variant = ''
|
||||
""" Board variant(s), used to determine which components are crossed. """
|
||||
self.dnf_filter = Optionable
|
||||
""" [string|list(string)=''] Name of the filter to mark components as not fitted.
|
||||
A short-cut to use for simple cases where a variant is an overkill """
|
||||
super().__init__()
|
||||
|
||||
def config(self):
|
||||
super().config()
|
||||
self.variant = RegOutput.check_variant(self.variant)
|
||||
self.dnf_filter = BaseFilter.solve_filter(self.dnf_filter, 'dnf_filter')
|
||||
|
||||
def run(self, output_dir, board):
|
||||
check_eeschema_do()
|
||||
cmd = [CMD_EESCHEMA_DO, 'export', '--all_pages', '--file_format', 'pdf', GS.sch_file, output_dir]
|
||||
if self.variant or self.dnf_filter:
|
||||
# Get the components list from the schematic
|
||||
comps = GS.sch.get_components()
|
||||
# Apply the filter
|
||||
if self.dnf_filter:
|
||||
for c in comps:
|
||||
c.fitted = self.dnf_filter.filter(c)
|
||||
# Apply the variant
|
||||
if self.variant:
|
||||
self.variant.filter(comps)
|
||||
# Save it to a temporal dir
|
||||
sch_dir = mkdtemp(prefix='tmp-kibot-pdf_sch_print-')
|
||||
fname = GS.sch.save_variant(sch_dir)
|
||||
sch_file = os.path.join(sch_dir, fname)
|
||||
else:
|
||||
sch_dir = None
|
||||
sch_file = GS.sch_file
|
||||
cmd = [CMD_EESCHEMA_DO, 'export', '--all_pages', '--file_format', 'pdf', sch_file, output_dir]
|
||||
if GS.debug_enabled:
|
||||
cmd.insert(1, '-vv')
|
||||
cmd.insert(1, '-r')
|
||||
|
|
@ -38,6 +69,10 @@ class PDF_Sch_PrintOptions(BaseOptions):
|
|||
new = self.expand_filename_sch(output_dir, self.output, id, ext)
|
||||
logger.debug('Moving '+cur+' -> '+new)
|
||||
os.rename(cur, new)
|
||||
# Remove the temporal dir if needed
|
||||
if sch_dir:
|
||||
logger.debug('Removing temporal variant dir `{}`'.format(sch_dir))
|
||||
rmtree(sch_dir)
|
||||
|
||||
|
||||
@output_class
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
# License: GPL-3.0
|
||||
# Project: KiBot (formerly KiPlot)
|
||||
from .optionable import Optionable
|
||||
from .error import KiPlotConfigurationError
|
||||
|
||||
|
||||
class Registrable(object):
|
||||
|
|
@ -72,6 +73,14 @@ class RegOutput(Optionable, Registrable):
|
|||
def add_filter(obj):
|
||||
RegOutput._def_filters[obj.name] = obj
|
||||
|
||||
@staticmethod
|
||||
def check_variant(variant):
|
||||
if variant:
|
||||
if not RegOutput.is_variant(variant):
|
||||
raise KiPlotConfigurationError("Unknown variant name `{}`".format(variant))
|
||||
return RegOutput.get_variant(variant)
|
||||
return None
|
||||
|
||||
|
||||
class RegVariant(Optionable, Registrable):
|
||||
""" An optionable that is also registrable.
|
||||
|
|
|
|||
Loading…
Reference in New Issue