Skip to content

Commit 3a418b0

Browse files
tywtyw2002yaqwsx
authored andcommitted
feat: plugin able to show/hidden selected item only.
1 parent 44e6e22 commit 3a418b0

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

kikit/actionPlugins/hideReferences.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, state, parent=None, board=None, action=None, updateState=None
1818
self.actionCallback = action
1919
self.updateStatusCallback = updateState
2020
self.text = ""
21+
self.selectedItemOnly = False
2122

2223
self.Bind(wx.EVT_CLOSE, self.OnCancel, id=self.GetId())
2324
self.Bind(wx.EVT_SIZE, self.OnSize)
@@ -41,6 +42,16 @@ def __init__(self, state, parent=None, board=None, action=None, updateState=None
4142
self.Bind(wx.EVT_TEXT, self.OnPatternChange, id=self.pattern.GetId())
4243
self.item_grid.Add(self.pattern, 0, wx.EXPAND)
4344

45+
label = wx.StaticText(panel, label="Only Selected items:",
46+
size=wx.Size(200, -1),
47+
style=wx.ALIGN_RIGHT)
48+
label.Wrap(200)
49+
self.item_grid.Add(label, 1, wx.ALIGN_CENTRE_VERTICAL)
50+
self.selected_only = wx.CheckBox(panel, style=wx.CHK_2STATE)
51+
self.Bind(wx.EVT_CHECKBOX, self.OnselectedItemOnlyChange)
52+
self.selected_only.SetValue(self.selectedItemOnly)
53+
self.item_grid.Add(self.selected_only, 0, wx.EXPAND)
54+
4455
label = wx.StaticText(panel, label="What to do:",
4556
size=wx.Size(200, -1),
4657
style=wx.ALIGN_RIGHT)
@@ -191,12 +202,19 @@ def GetPattern(self):
191202
def GetActiveLayers(self):
192203
return set(self.layers.GetCheckedItems())
193204

205+
def GetSelectedItemOnly(self):
206+
return self.selectedItemOnly
207+
194208
def ModifyReferences(self):
195209
return self.scope.GetSelection() in [0, 2]
196210

197211
def ModifyValues(self):
198212
return self.scope.GetSelection() in [1, 2]
199213

214+
def OnselectedItemOnlyChange(self, event):
215+
self.selectedItemOnly = not self.selectedItemOnly
216+
self.OnPatternChange(None)
217+
200218
def OnPatternChange(self, event):
201219
try:
202220
regex = re.compile(self.pattern.GetValue())
@@ -206,6 +224,9 @@ def OnPatternChange(self, event):
206224
else:
207225
refs = []
208226
for footprint in self.board.GetFootprints():
227+
if self.selectedItemOnly and not footprint.IsSelected():
228+
continue
229+
209230
if regex.match(footprint.GetReference()):
210231
refs.append(footprint.GetReference())
211232
if len(refs) > 0:
@@ -238,10 +259,12 @@ def action(self, dialog):
238259
try:
239260
if dialog.ModifyReferences():
240261
modify.references(dialog.board, dialog.GetShowLabels(),
241-
dialog.GetPattern(), dialog.GetActiveLayers())
262+
dialog.GetPattern(), dialog.GetActiveLayers(),
263+
dialog.GetSelectedItemOnly())
242264
if dialog.ModifyValues():
243265
modify.values(dialog.board, dialog.GetShowLabels(),
244-
dialog.GetPattern(), dialog.GetActiveLayers())
266+
dialog.GetPattern(), dialog.GetActiveLayers(),
267+
dialog.GetSelectedItemOnly())
245268
pcbnew.Refresh()
246269
except Exception as e:
247270
self.error(f"Cannot perform: {e}")

kikit/modify.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import re
55

66
def references(board: pcbnew.BOARD, show: bool, pattern: str,
7-
allowedLayers: Set[Layer] = set(Layer.all())) -> None:
7+
allowedLayers: Set[Layer] = set(Layer.all()),
8+
isSelectedItemOnly: bool = False) -> None:
89
"""
910
Show or hide references in a footprint.
1011
"""
1112
for footprint in board.GetFootprints():
13+
if isSelectedItemOnly and not footprint.IsSelected():
14+
continue
1215
if re.match(pattern, footprint.GetReference()) and footprint.Reference().GetLayer() in allowedLayers:
1316
footprint.Reference().SetVisible(show)
1417
for x in footprint.GraphicalItems():
@@ -19,11 +22,14 @@ def references(board: pcbnew.BOARD, show: bool, pattern: str,
1922

2023

2124
def values(board: pcbnew.BOARD, show: bool, pattern: str,
22-
allowedLayers: Set[Layer] = set(Layer.all())) -> None:
25+
allowedLayers: Set[Layer] = set(Layer.all()),
26+
isSelectedItemOnly: bool = False) -> None:
2327
"""
2428
Show or hide values in a footprint.
2529
"""
2630
for footprint in board.GetFootprints():
31+
if isSelectedItemOnly and not footprint.IsSelected():
32+
continue
2733
if re.match(pattern, footprint.GetReference()) and footprint.Value().GetLayer() in allowedLayers:
2834
footprint.Value().SetVisible(show)
2935
for x in footprint.GraphicalItems():

0 commit comments

Comments
 (0)