Skip to content

Commit f93f294

Browse files
committed
adding coverage outline
1 parent 14d1837 commit f93f294

1 file changed

Lines changed: 81 additions & 43 deletions

File tree

src/plugin.py

Lines changed: 81 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import wx.aui
77
from wx.lib import buttons
88
import pcbnew
9+
import dataclasses
910

1011
path_ = Path(__file__).parent.absolute()
1112
sys.path.append(str(path_))
@@ -24,7 +25,7 @@
2425

2526
_board = None
2627
_frame_size = (800, 600)
27-
_min_frame_size = (300, 200)
28+
_frame_size_min = (300, 200)
2829

2930
def set_board(board):
3031
"""
@@ -40,22 +41,27 @@ def get_board():
4041
"""
4142
return _board
4243

44+
@dataclasses.dataclass
4345
class Meta:
4446
"""
4547
Information about package
4648
"""
47-
toolname = "kicadtestpoints"
48-
title = "Test Point Report"
49-
body = ("Choose test points by setting the desired pads 'Fabrication Property' to \
50-
'Test Point Pad'. The output default is in the JigsApp test point report style.\
51-
Coordinates are Cartesian with x increasing to the right and y increasing upwards.\
52-
For correct agreement with generated gerbers and the component placement, ensure the origin used is consistent.")
53-
about_text = "This plugin generates TheJigsApp style test points reports. Test more, worry less."
54-
short_description = "TheJigsApp KiCAD Test Point Report"
55-
frame_title = "TheJigsApp KiCAD Test Point Report"
56-
website = "https://www.thejigsapp.com"
57-
gitlink = "https://github.com/snhobbs/kicad-testpoints-pcm"
58-
version = __version__
49+
toolname : str = "kicadtestpoints"
50+
title : str = "Test Point Report"
51+
body : str = ("Choose test points by setting the desired pads 'Fabrication Property' to \
52+
'Test Point Pad'. The output default is in the JigsApp test point report style. \
53+
Coordinates are Cartesian with x increasing to the right and y increasing upwards. \
54+
For correct agreement with generated gerbers and the component placement, ensure the \
55+
origin used is consistent.")
56+
about_text : str = "This plugin generates TheJigsApp style test points reports. Test more, worry less."
57+
short_description : str = "TheJigsApp KiCAD Test Point Report"
58+
frame_title : str = "TheJigsApp KiCAD Test Point Report"
59+
website : str = "https://www.thejigsapp.com"
60+
gitlink : str = "https://github.com/snhobbs/kicad-testpoints-pcm"
61+
version : str = __version__
62+
category : str = "Read PCB"
63+
icon_dir : Path = Path(__file__).parent
64+
icon_base_file_name : str = "icon.png"
5965

6066

6167
def setattr_keywords(obj, name, value):
@@ -89,14 +95,13 @@ def __init__(self, parent):
8995
)
9096
self.file_output_selector.SetPath(default_file_path.as_posix())
9197

92-
# Lorem Ipsum text
9398
lorem_text = wx.StaticText(self, label=Meta.body)
9499

95100
# Buttons
96101
self.submit_button = buttons.GenButton(self, label="Submit")
97102
self.cancel_button = buttons.GenButton(self, label="Cancel")
98-
self.submit_button.SetBackgroundColour(wx.Colour(150, 225, 150))
99-
self.cancel_button.SetBackgroundColour(wx.Colour(225, 150, 150))
103+
self.submit_button.SetBackgroundColour(wx.Colour(100, 225, 100))
104+
self.cancel_button.SetBackgroundColour(wx.Colour(225, 100, 100))
100105
self.submit_button.Bind(wx.EVT_BUTTON, self.on_submit)
101106
self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel)
102107

@@ -105,15 +110,14 @@ def __init__(self, parent):
105110
button_sizer.Add(self.submit_button, 0, wx.ALL | wx.EXPAND, 5)
106111
button_sizer.Add(self.cancel_button, 0, wx.ALL, 5)
107112

108-
# Origin selectiondd
113+
# Origin selection
109114
self.use_aux_origin_cb = wx.CheckBox(self, label="Use drill/place file origin")
110115
self.use_aux_origin_cb.SetValue(True)
111116
self.settings.use_aux_origin = self.use_aux_origin_cb.GetValue()
112117

113118
self.Bind(wx.EVT_CHECKBOX, self.on_checkbox_toggle)
114119

115120
# Sizer for layout
116-
# sizer = wx.BoxSizer(wx.HORIZONTAL)
117121
sizer = wx.BoxSizer(wx.VERTICAL)
118122
sizer.Add(self.use_aux_origin_cb, 0, wx.ALL, 10)
119123

@@ -130,26 +134,39 @@ def on_checkbox_toggle(self, event):
130134

131135
def on_submit(self, _):
132136
file_path = Path(self.file_output_selector.GetPath())
133-
if file_path:
134-
print("Submitting...")
135-
print("File Path:", file_path)
136-
137-
board = get_board()
138-
pads = get_pads_by_property(board)
139-
data = build_test_point_report(board, pads=pads, settings=self.settings)
140-
if not data:
141-
wx.MessageBox(
142-
"No test point pads found, have you set any?",
143-
"Error",
144-
wx.OK | wx.ICON_ERROR,
145-
)
146-
else:
147-
write_csv(data, filename=file_path)
148-
self.GetTopLevelParent().EndModal(wx.ID_OK)
149-
else:
137+
if not file_path:
150138
wx.MessageBox(
151139
"Please select a file output path.", "Error", wx.OK | wx.ICON_ERROR
152140
)
141+
return
142+
143+
print("Submitting...")
144+
print("File Path:", file_path)
145+
146+
board = get_board()
147+
pads = get_pads_by_property(board)
148+
data = build_test_point_report(board, pads=pads, settings=self.settings)
149+
if not data:
150+
wx.MessageBox(
151+
"No test point pads found, have you set any?",
152+
"Error",
153+
wx.OK | wx.ICON_ERROR,
154+
)
155+
return
156+
157+
nets = set(board.GetNetsByName())
158+
tp_nets = set([pt["net"] for pt in data])
159+
160+
write_csv(data, filename=file_path)
161+
162+
wx.MessageBox(
163+
"Coverage: %d / %d nets\n\nSaved to: %s"%(len(tp_nets), len(nets), file_path),
164+
"Success",
165+
wx.OK,
166+
)
167+
168+
self.GetTopLevelParent().EndModal(wx.ID_OK)
169+
return
153170

154171
def on_cancel(self, _):
155172
print("Canceling...")
@@ -184,7 +201,7 @@ def __init__(self, parent):
184201
from wx.lib.agw.hyperlink import HyperLinkCtrl
185202
link_sizer = wx.BoxSizer(wx.HORIZONTAL)
186203

187-
pre_link_text = wx.StaticText(self, label="Brought to you by: ")
204+
pre_link_text = wx.StaticText(self, label="Brought to you by TheJigsApp: ")
188205
pre_link_text.SetFont(font)
189206
link_sizer.Add(pre_link_text, 0, wx.EXPAND, 0)
190207

@@ -211,11 +228,15 @@ def __init__(self, parent):
211228

212229

213230
class MyDialog(wx.Dialog):
231+
"""
232+
Top level GUI view
233+
"""
214234
def __init__(self, parent, title):
215235
super().__init__(
216236
parent, title=title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER
217237
)
218238

239+
# Sizer for layout
219240
sizer = wx.BoxSizer(wx.HORIZONTAL)
220241

221242
# Create a notebook with two tabs
@@ -226,11 +247,11 @@ def __init__(self, parent, title):
226247
notebook.AddPage(tab_panel, "Main")
227248
notebook.AddPage(about_panel, "About")
228249

229-
# Sizer for layout
230250
sizer.Add(notebook, 1, wx.EXPAND | wx.ALL, 10)
251+
231252
self.SetSizer(sizer)
253+
self.SetMinSize(_frame_size_min)
232254
self.SetSize(_frame_size)
233-
self.SetMinSize(_min_frame_size)
234255

235256
def on_close(self, event):
236257
self.EndModal(wx.ID_CANCEL)
@@ -248,25 +269,42 @@ def fit_to_screen(self):
248269
self.SetSize(wx.Size(screen_width, screen_height))
249270

250271

272+
def get_gui_frame(name: str = "PcbFrame"):
273+
pcb_frame = None
274+
275+
try:
276+
pcb_frame = [
277+
x for x in wx.GetTopLevelWindows() if x.GetName() == name
278+
][0]
279+
except IndexError:
280+
pass
281+
return pcb_frame
282+
283+
251284
class Plugin(pcbnew.ActionPlugin):
252285
def __init__(self):
253286
super().__init__()
254287

255288
_log.debug("Loading kicad_testpoints")
256289

257-
self.logger = None
290+
self.logger = _log
258291
self.config_file = None
259292

260293
self.name = Meta.title
261-
self.category = "Read PCB"
294+
self.category = Meta.category
262295
self.pcbnew_icon_support = hasattr(self, "show_toolbar_button")
263296
self.show_toolbar_button = True
264-
icon_dir = os.path.dirname(__file__)
265-
self.icon_file_name = os.path.join(icon_dir, "icon.png")
266297
self.description = Meta.body
267298

299+
icon_file_path = Meta.icon_dir / Meta.icon_base_file_name
300+
# assert icon_file_path.exists()
301+
self.icon_file_name = str(icon_file_path)
302+
303+
def defaults(self):
304+
pass
305+
268306
def Run(self):
269-
dlg = MyDialog(None, title=Meta.title)
307+
dlg = MyDialog(get_gui_frame(name="PcbFrame"), title=Meta.title)
270308
try:
271309
dlg.ShowModal()
272310

0 commit comments

Comments
 (0)