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

Added rotation by reference #477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion fabrication.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def fix_rotation(self, footprint):
if footprint.GetLayer() != 0:
# bottom angles need to be mirrored on Y-axis
rotation = (180 - rotation) % 360
# First check if the value aka part name matches
# First check if the reference matches
for regex, correction in self.corrections:
if re.search(regex, str(footprint.GetReference())):
return self.rotate(footprint, rotation, correction)
# Then check if the value aka part name matches
for regex, correction in self.corrections:
if re.search(regex, str(footprint.GetValue())):
return self.rotate(footprint, rotation, correction)
Expand Down
23 changes: 20 additions & 3 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
ID_HIDE_POS = 14
ID_SAVE_MAPPINGS = 15
ID_EXPORT_TO_SCHEMATIC = 16
ID_CONTEXT_MENU_ADD_ROT_BY_REFERENCE = wx.NewIdRef()
ID_CONTEXT_MENU_ADD_ROT_BY_PACKAGE = wx.NewIdRef()
ID_CONTEXT_MENU_ADD_ROT_BY_NAME = wx.NewIdRef()

Expand Down Expand Up @@ -616,11 +617,17 @@ def populate_footprint_list(self, *_):
if detail:
part[4] = detail[0][2]
part[5] = detail[0][1]
# First check if the part name mathes
# First check if the part reference mathes
for regex, correction in corrections:
if re.search(regex, str(part[1])):
if re.search(regex, str(part[0])):
part[8] = str(correction)
break
# If there was no match for the part reference, check if the part name mathes
if part[8] == "":
for regex, correction in corrections:
if re.search(regex, str(part[1])):
part[8] = str(correction)
break
# If there was no match for the part name, check if the package matches
if part[8] == "":
for regex, correction in corrections:
Expand Down Expand Up @@ -982,7 +989,11 @@ def add_part_rot(self, e):
row = self.footprint_list.ItemToRow(item)
if row == -1:
return
if e.GetId() == ID_CONTEXT_MENU_ADD_ROT_BY_PACKAGE:
if e.GetId() == ID_CONTEXT_MENU_ADD_ROT_BY_REFERENCE:
package = self.footprint_list.GetTextValue(row, 0)
if package != "":
RotationManagerDialog(self, f"\\b{re.escape(package)}\\b").ShowModal()
elif e.GetId() == ID_CONTEXT_MENU_ADD_ROT_BY_PACKAGE:
package = self.footprint_list.GetTextValue(row, 2)
if package != "":
RotationManagerDialog(self, "^" + re.escape(package)).ShowModal()
Expand Down Expand Up @@ -1068,6 +1079,12 @@ def OnRightDown(self, *_):
conMenu.Append(paste_lcsc)
conMenu.Bind(wx.EVT_MENU, self.paste_part_lcsc, paste_lcsc)

rotation_by_reference = wx.MenuItem(
conMenu, ID_CONTEXT_MENU_ADD_ROT_BY_REFERENCE, "Add Rotation by reference"
)
conMenu.Append(rotation_by_reference)
conMenu.Bind(wx.EVT_MENU, self.add_part_rot, rotation_by_reference)

rotation_by_package = wx.MenuItem(
conMenu, ID_CONTEXT_MENU_ADD_ROT_BY_PACKAGE, "Add Rotation by package"
)
Expand Down