Implemented the 'Sheetpath' column.

This commit is contained in:
Salvador E. Tropea 2020-07-28 20:05:50 -03:00
parent d8ff6c92aa
commit 9d3645fa41
4 changed files with 17 additions and 8 deletions

View File

@ -252,6 +252,7 @@ class ComponentGroup(object):
self.fields[ColumnList.COL_DATASHEET_L] = comp.datasheet
self.fields[ColumnList.COL_FP_L] = comp.footprint
self.fields[ColumnList.COL_FP_LIB_L] = comp.footprint_lib
self.fields[ColumnList.COL_SHEETPATH_L] = comp.sheet_path_h
# self.fields[ColumnList.COL_DESCRIPTION_L] = self.components[0].getDescription() TODO
def get_row(self, columns):

View File

@ -26,6 +26,8 @@ class ColumnList:
COL_PART_LIB_L = COL_PART_LIB.lower()
COL_DATASHEET = 'Datasheet'
COL_DATASHEET_L = COL_DATASHEET.lower()
COL_SHEETPATH = 'Sheetpath'
COL_SHEETPATH_L = COL_SHEETPATH.lower()
# Default columns for groups
COL_GRP_QUANTITY = 'Quantity Per PCB'
@ -52,7 +54,8 @@ class ColumnList:
COL_FP_LIB,
COL_GRP_QUANTITY,
COL_GRP_BUILD_QUANTITY,
COL_DATASHEET
COL_DATASHEET,
COL_SHEETPATH
]
# Default columns
@ -65,6 +68,7 @@ class ColumnList:
COL_PART_LIB_L: 1,
COL_DESCRIPTION_L: 1,
COL_DATASHEET_L: 1,
COL_SHEETPATH_L: 1,
COL_FP_L: 1,
COL_FP_LIB_L: 1
}

View File

@ -170,7 +170,7 @@ class SchematicComponent(object):
return '{} ({} {})'.format(self.ref, self.name, self.value)
@staticmethod
def load(f, sheet_path):
def load(f, sheet_path, sheet_path_h):
# L lib:name reference
line = _get_line(f)
if line[0] != 'L':
@ -249,6 +249,9 @@ class SchematicComponent(object):
if not m:
raise SchFileError('Malformed component reference', comp.ref, _sch_line_number)
comp.ref_prefix, comp.ref_suffix = m.groups()
# Location in the project
comp.sheet_path = sheet_path
comp.sheet_path_h = sheet_path_h
if GS.debug_level > 1:
logger.debug("- Loaded component {}".format(comp))
return comp
@ -406,12 +409,13 @@ class SchematicSheet(object):
self.sheet = None
self.id = ''
def load_sheet(self, parent, sheet_path):
def load_sheet(self, parent, sheet_path, sheet_path_h):
assert self.name
self.sheet = Schematic()
parent_dir = os.path.dirname(parent)
sheet_path += '/'+self.id
self.sheet.load(os.path.join(parent_dir, self.file), sheet_path)
sheet_path_h += '/'+(self.name if self.name else 'Unknown')
self.sheet.load(os.path.join(parent_dir, self.file), sheet_path, sheet_path_h)
return self.sheet
@staticmethod
@ -496,7 +500,7 @@ class Schematic(object):
raise SchFileError('Wrong entry in title block', line, _sch_line_number)
self.title_block[m.group(1)] = m.group(2)
def load(self, fname, sheet_path=''):
def load(self, fname, sheet_path='', sheet_path_h=''):
""" Load a v5.x KiCad Schematic.
The caller must be sure the file exists. """
logger.debug("Loading sheet from "+fname)
@ -532,7 +536,7 @@ class Schematic(object):
self.sheets = []
while not line.startswith('$EndSCHEMATC'):
if line.startswith('$Comp'):
obj = SchematicComponent.load(f, sheet_path)
obj = SchematicComponent.load(f, sheet_path, sheet_path_h)
self.components.append(obj)
elif line.startswith('NoConn'):
obj = SchematicConnection.parse(False, line[7:])
@ -559,7 +563,7 @@ class Schematic(object):
# Load sub-sheets
self.sub_sheets = []
for sch in self.sheets:
self.sub_sheets.append(sch.load_sheet(fname, sheet_path))
self.sub_sheets.append(sch.load_sheet(fname, sheet_path, sheet_path_h))
def get_files(self):
""" A list of the names for all the sheets, including this one. """

View File

@ -201,7 +201,7 @@ class BoMOptions(BaseOptions):
if isinstance(self.columns, type):
self.columns = None
# Ignore the library part and footprint
self.ignore = [ColumnList.COL_PART_LIB_L, ColumnList.COL_FP_LIB_L]
self.ignore = [ColumnList.COL_PART_LIB_L, ColumnList.COL_FP_LIB_L, ColumnList.COL_SHEETPATH_L]
else:
# This is tricky
# Lower case available columns