Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds "LCSC Part" as an LCSC property; a "Description" column is shown to the user. #505

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,12 @@ def get_part_details(self, lcsc: list) -> dict:
con.row_factory = dict_factory
cur = con.cursor()
results = []
query = '''SELECT "LCSC Part" AS lcsc, "Stock" AS stock, "Library Type" AS type FROM parts WHERE parts MATCH ?'''
query = '''SELECT "LCSC Part" AS lcsc, "Stock" AS stock, "Library Type" AS type, "Description" FROM parts WHERE parts MATCH ?'''

# Use parameter binding to prevent SQL injection and handle the query more efficiently
for number in lcsc:
# Each number needs to be wrapped in double quotes for exact match in FTS5
match_query = f'"LCSC Part:{number}"'
match_query = f'"lcsc:{number}"'
cur.execute(query, (match_query,))
results.extend(cur.fetchall())
if results:
Expand Down
16 changes: 13 additions & 3 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def __init__(self, parent, kicad_provider=KicadProvider()):
"bom-pos.png",
self.scale_factor,
),
"Toggle exclud from BOM and POS attribute",
"Toggle exclude from BOM and POS attribute",
)

self.toggle_bom_button = self.right_toolbar.AddTool(
Expand Down Expand Up @@ -382,7 +382,7 @@ def __init__(self, parent, kicad_provider=KicadProvider()):
self.footprint = self.footprint_list.AppendTextColumn(
"Footprint",
mode=wx.dataview.DATAVIEW_CELL_INERT,
width=int(self.scale_factor * 300),
width=int(self.scale_factor * 150),
align=wx.ALIGN_CENTER,
flags=wx.dataview.DATAVIEW_COL_RESIZABLE,
)
Expand Down Expand Up @@ -435,6 +435,13 @@ def __init__(self, parent, kicad_provider=KicadProvider()):
align=wx.ALIGN_CENTER,
flags=wx.dataview.DATAVIEW_COL_RESIZABLE,
)
self.description = self.footprint_list.AppendTextColumn(
"Description",
mode=wx.dataview.DATAVIEW_CELL_INERT,
width=int(self.scale_factor * 300),
align=wx.ALIGN_LEFT,
flags=wx.dataview.DATAVIEW_COL_RESIZABLE,
)
self.footprint_list.AppendTextColumn(
"",
mode=wx.dataview.DATAVIEW_CELL_INERT,
Expand Down Expand Up @@ -607,6 +614,7 @@ def populate_footprint_list(self, *_):
part["rotation"] = ""
part["type"] = ""
part["side"] = ""
part["description"] = ""
parts.append(part)
details = self.library.get_part_details(numbers)
corrections = self.library.get_all_correction_data()
Expand All @@ -615,7 +623,8 @@ def populate_footprint_list(self, *_):
if details:
part["type"] = details["type"]
part["stock"] = details["stock"]
# First check if the part name mathes
part["description"] = details["description"]
# First check if the part name matches
for regex, correction in corrections:
if re.search(regex, str(part["reference"])):
part["rotation"] = str(correction)
Expand All @@ -639,6 +648,7 @@ def populate_footprint_list(self, *_):
part["exclude_from_pos"],
part["rotation"],
part["side"],
part["description"],
"",
]
)
Expand Down
7 changes: 4 additions & 3 deletions schematicexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def _update_schematic8(self, path):
lastLcsc = ""
newLcsc = ""
lastRef = ""
property_name = self.parent.settings.get("schematic", {}).get("property_name", "LCSC")

lines = []
newlines = []
Expand All @@ -224,7 +225,7 @@ def _update_schematic8(self, path):
key = m.group(1)
# self.logger.info("key %s", key)
# found a LCSC property, so update it if needed
if key in {"LCSC", "LCSC_PN", "JLC_PN"}:
if key in {"LCSC", "LCSC_PN", "LCSC Part", "JLC_PN"}:
value = m.group(2)
lastLcsc = value
if newLcsc not in (lastLcsc, ""):
Expand Down Expand Up @@ -254,7 +255,7 @@ def _update_schematic8(self, path):
if m3 and partSection:
if lastLcsc == "" and newLcsc != "" and lastLoc != "":
self.logger.info("added %s to %s", newLcsc, lastRef)
newTxt = f'\t\t(property "LCSC" "{newLcsc}"\n\t\t\t(at {lastLoc} 0)'
newTxt = f'\t\t(property "{property_name}" "{newLcsc}"\n\t\t\t(at {lastLoc} 0)'
newlines.append(newTxt)
newlines.append(
"\t\t\t(effects\n\t\t\t\t(font\n\t\t\t\t\t(size 1.27 1.27)\n\t\t\t\t)\n\t\t\t\t(hide yes)"
Expand All @@ -273,4 +274,4 @@ def _update_schematic8(self, path):
with open(path, "w", encoding="utf-8") as f:
for line in newlines:
f.write(line + "\n")
self.logger.info("Added LCSC's to %s (maybe?)", path)
self.logger.info("Added \"%s\"'s to %s (maybe?)", property_name, path)
26 changes: 26 additions & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,24 @@ def __init__(self, parent):
lcsc_bom_cpl_sizer.Add(self.lcsc_bom_cpl_image, 10, wx.ALL | wx.EXPAND, 5)
lcsc_bom_cpl_sizer.Add(self.lcsc_bom_cpl_setting, 100, wx.ALL | wx.EXPAND, 5)

##### Property name used when updating schematics #####
self.property_name_setting = wx.ComboBox(
self,
size=wx.DefaultSize,
choices=["LCSC", "LCSC_PN", "LCSC Part", "JLC_PN"],
value="LCSC",
name="schematic_property_name",
)
self.property_name_setting.SetToolTip(
wx.ToolTip("The property name that will be used when updating schematics")
)
self.property_name_setting.Bind(wx.EVT_COMBOBOX, self.update_settings)
self.property_name_label = wx.StaticText(self, label="Property name:")

property_name_sizer = wx.BoxSizer()
property_name_sizer.Add(self.property_name_label, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5)
property_name_sizer.Add(self.property_name_setting, 0, wx.ALL | wx.EXPAND, 5)

# ---------------------------------------------------------------------
# ---------------------- Main Layout Sizer ----------------------------
# ---------------------------------------------------------------------
Expand All @@ -243,6 +261,7 @@ def __init__(self, parent):
layout.Add(plot_references_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(lcsc_priority_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(lcsc_bom_cpl_sizer, 0, wx.ALL | wx.EXPAND, 5)
layout.Add(property_name_sizer, 0, wx.ALL | wx.EXPAND, 5)
self.SetSizer(layout)
self.Layout()
self.Centre(wx.BOTH)
Expand Down Expand Up @@ -355,6 +374,10 @@ def update_lcsc_bom_cpl(self, add):
loadBitmapScaled("no_bom.png", self.parent.scale_factor, static=True)
)

def update_property_name(self, name):
"""Update settings dialog according to the settings."""
self.property_name_setting.SetValue(name)

def load_settings(self):
"""Load settings and set checkboxes accordingly."""
self.update_tented_vias(
Expand All @@ -375,6 +398,9 @@ def load_settings(self):
self.update_lcsc_bom_cpl(
self.parent.settings.get("gerber", {}).get("lcsc_bom_cpl", True)
)
self.update_property_name(
self.parent.settings.get("schematic", {}).get("property_name", "LCSC")
)

def update_settings(self, event):
"""Update and persist a setting that was changed."""
Expand Down