- Tool Punch Gerber - updated the UI
- Tool Panelize - updated the UI - Tool Extract Drills - updated the UI - Tool QRcode - updated the UI - Tool SolderPaste - updated the UI - Tool DblSided - updated the UI
This commit is contained in:
@@ -26,21 +26,413 @@ log = logging.getLogger('base')
|
||||
|
||||
class ToolExtractDrills(AppTool):
|
||||
|
||||
toolName = _("Extract Drills")
|
||||
|
||||
def __init__(self, app):
|
||||
AppTool.__init__(self, app)
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = ExtractDrillsUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
# ## Signals
|
||||
self.ui.hole_size_radio.activated_custom.connect(self.on_hole_size_toggle)
|
||||
self.ui.e_drills_button.clicked.connect(self.on_extract_drills_click)
|
||||
self.ui.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
self.ui.circular_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.ui.circular_ring_entry.setDisabled(False) if state else self.ui.circular_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.ui.oblong_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.ui.oblong_ring_entry.setDisabled(False) if state else self.ui.oblong_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.ui.square_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.ui.square_ring_entry.setDisabled(False) if state else self.ui.square_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.ui.rectangular_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.ui.rectangular_ring_entry.setDisabled(False) if state else
|
||||
self.ui.rectangular_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.ui.other_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.ui.other_ring_entry.setDisabled(False) if state else self.ui.other_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+I', **kwargs)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("Extract Drills()")
|
||||
|
||||
if toggle:
|
||||
# if the splitter is hidden, display it, else hide it but only if the current widget is the same
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
else:
|
||||
try:
|
||||
if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
|
||||
# if tab is populated with the tool but it does not have the focus, focus on it
|
||||
if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
|
||||
# focus on Tool Tab
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
|
||||
else:
|
||||
self.app.ui.splitter.setSizes([0, 1])
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
|
||||
AppTool.run(self)
|
||||
self.set_tool_ui()
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Extract Drills Tool"))
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.reset_fields()
|
||||
|
||||
self.ui.hole_size_radio.set_value(self.app.defaults["tools_edrills_hole_type"])
|
||||
|
||||
self.ui.dia_entry.set_value(float(self.app.defaults["tools_edrills_hole_fixed_dia"]))
|
||||
|
||||
self.ui.circular_ring_entry.set_value(float(self.app.defaults["tools_edrills_circular_ring"]))
|
||||
self.ui.oblong_ring_entry.set_value(float(self.app.defaults["tools_edrills_oblong_ring"]))
|
||||
self.ui.square_ring_entry.set_value(float(self.app.defaults["tools_edrills_square_ring"]))
|
||||
self.ui.rectangular_ring_entry.set_value(float(self.app.defaults["tools_edrills_rectangular_ring"]))
|
||||
self.ui.other_ring_entry.set_value(float(self.app.defaults["tools_edrills_others_ring"]))
|
||||
|
||||
self.ui.circular_cb.set_value(self.app.defaults["tools_edrills_circular"])
|
||||
self.ui.oblong_cb.set_value(self.app.defaults["tools_edrills_oblong"])
|
||||
self.ui.square_cb.set_value(self.app.defaults["tools_edrills_square"])
|
||||
self.ui.rectangular_cb.set_value(self.app.defaults["tools_edrills_rectangular"])
|
||||
self.ui.other_cb.set_value(self.app.defaults["tools_edrills_others"])
|
||||
|
||||
self.ui.factor_entry.set_value(float(self.app.defaults["tools_edrills_hole_prop_factor"]))
|
||||
|
||||
def on_extract_drills_click(self):
|
||||
|
||||
drill_dia = self.ui.dia_entry.get_value()
|
||||
circ_r_val = self.ui.circular_ring_entry.get_value()
|
||||
oblong_r_val = self.ui.oblong_ring_entry.get_value()
|
||||
square_r_val = self.ui.square_ring_entry.get_value()
|
||||
rect_r_val = self.ui.rectangular_ring_entry.get_value()
|
||||
other_r_val = self.ui.other_ring_entry.get_value()
|
||||
|
||||
prop_factor = self.ui.factor_entry.get_value() / 100.0
|
||||
|
||||
drills = []
|
||||
tools = {}
|
||||
|
||||
selection_index = self.ui.gerber_object_combo.currentIndex()
|
||||
model_index = self.app.collection.index(selection_index, 0, self.ui.gerber_object_combo.rootModelIndex())
|
||||
|
||||
try:
|
||||
fcobj = model_index.internalPointer().obj
|
||||
except Exception:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
|
||||
return
|
||||
|
||||
outname = fcobj.options['name'].rpartition('.')[0]
|
||||
|
||||
mode = self.ui.hole_size_radio.get_value()
|
||||
|
||||
if mode == 'fixed':
|
||||
tools = {
|
||||
1: {
|
||||
"tooldia": drill_dia,
|
||||
"drills": [],
|
||||
"slots": []
|
||||
}
|
||||
}
|
||||
for apid, apid_value in fcobj.apertures.items():
|
||||
ap_type = apid_value['type']
|
||||
|
||||
if ap_type == 'C':
|
||||
if self.ui.circular_cb.get_value() is False:
|
||||
continue
|
||||
elif ap_type == 'O':
|
||||
if self.ui.oblong_cb.get_value() is False:
|
||||
continue
|
||||
elif ap_type == 'R':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
|
||||
# if the height == width (float numbers so the reason for the following)
|
||||
if round(width, self.decimals) == round(height, self.decimals):
|
||||
if self.ui.square_cb.get_value() is False:
|
||||
continue
|
||||
else:
|
||||
if self.ui.rectangular_cb.get_value() is False:
|
||||
continue
|
||||
else:
|
||||
if self.ui.other_cb.get_value() is False:
|
||||
continue
|
||||
|
||||
for geo_el in apid_value['geometry']:
|
||||
if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
|
||||
tools[1]["drills"].append(geo_el['follow'])
|
||||
if 'solid_geometry' not in tools[1]:
|
||||
tools[1]['solid_geometry'] = []
|
||||
else:
|
||||
tools[1]['solid_geometry'].append(geo_el['follow'])
|
||||
|
||||
if 'solid_geometry' not in tools[1] or not tools[1]['solid_geometry']:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("No drills extracted. Try different parameters."))
|
||||
return
|
||||
elif mode == 'ring':
|
||||
drills_found = set()
|
||||
for apid, apid_value in fcobj.apertures.items():
|
||||
ap_type = apid_value['type']
|
||||
|
||||
dia = None
|
||||
if ap_type == 'C':
|
||||
if self.ui.circular_cb.get_value():
|
||||
dia = float(apid_value['size']) - (2 * circ_r_val)
|
||||
elif ap_type == 'O':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
if self.ui.oblong_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) - (2 * oblong_r_val)
|
||||
else:
|
||||
dia = float(apid_value['width']) - (2 * oblong_r_val)
|
||||
elif ap_type == 'R':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
|
||||
# if the height == width (float numbers so the reason for the following)
|
||||
if abs(float('%.*f' % (self.decimals, width)) - float('%.*f' % (self.decimals, height))) < \
|
||||
(10 ** -self.decimals):
|
||||
if self.ui.square_cb.get_value():
|
||||
dia = float(apid_value['height']) - (2 * square_r_val)
|
||||
else:
|
||||
if self.ui.rectangular_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) - (2 * rect_r_val)
|
||||
else:
|
||||
dia = float(apid_value['width']) - (2 * rect_r_val)
|
||||
else:
|
||||
if self.ui.other_cb.get_value():
|
||||
try:
|
||||
dia = float(apid_value['size']) - (2 * other_r_val)
|
||||
except KeyError:
|
||||
if ap_type == 'AM':
|
||||
pol = apid_value['geometry'][0]['solid']
|
||||
x0, y0, x1, y1 = pol.bounds
|
||||
dx = x1 - x0
|
||||
dy = y1 - y0
|
||||
if dx <= dy:
|
||||
dia = dx - (2 * other_r_val)
|
||||
else:
|
||||
dia = dy - (2 * other_r_val)
|
||||
|
||||
# if dia is None then none of the above applied so we skip the following
|
||||
if dia is None:
|
||||
continue
|
||||
|
||||
tool_in_drills = False
|
||||
for tool, tool_val in tools.items():
|
||||
if abs(float('%.*f' % (
|
||||
self.decimals,
|
||||
tool_val["tooldia"])) - float('%.*f' % (self.decimals, dia))) < (10 ** -self.decimals):
|
||||
tool_in_drills = tool
|
||||
|
||||
if tool_in_drills is False:
|
||||
if tools:
|
||||
new_tool = max([int(t) for t in tools]) + 1
|
||||
tool_in_drills = new_tool
|
||||
else:
|
||||
tool_in_drills = 1
|
||||
|
||||
for geo_el in apid_value['geometry']:
|
||||
if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
|
||||
if tool_in_drills not in tools:
|
||||
tools[tool_in_drills] = {
|
||||
"tooldia": dia,
|
||||
"drills": [],
|
||||
"slots": []
|
||||
}
|
||||
|
||||
tools[tool_in_drills]['drills'].append(geo_el['follow'])
|
||||
|
||||
if 'solid_geometry' not in tools[tool_in_drills]:
|
||||
tools[tool_in_drills]['solid_geometry'] = []
|
||||
else:
|
||||
tools[tool_in_drills]['solid_geometry'].append(geo_el['follow'])
|
||||
|
||||
if tool_in_drills in tools:
|
||||
if 'solid_geometry' not in tools[tool_in_drills] or not tools[tool_in_drills]['solid_geometry']:
|
||||
drills_found.add(False)
|
||||
else:
|
||||
drills_found.add(True)
|
||||
|
||||
if True not in drills_found:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("No drills extracted. Try different parameters."))
|
||||
return
|
||||
else:
|
||||
drills_found = set()
|
||||
for apid, apid_value in fcobj.apertures.items():
|
||||
ap_type = apid_value['type']
|
||||
|
||||
dia = None
|
||||
if ap_type == 'C':
|
||||
if self.ui.circular_cb.get_value():
|
||||
dia = float(apid_value['size']) * prop_factor
|
||||
elif ap_type == 'O':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
if self.ui.oblong_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) * prop_factor
|
||||
else:
|
||||
dia = float(apid_value['width']) * prop_factor
|
||||
elif ap_type == 'R':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
|
||||
# if the height == width (float numbers so the reason for the following)
|
||||
if abs(float('%.*f' % (self.decimals, width)) - float('%.*f' % (self.decimals, height))) < \
|
||||
(10 ** -self.decimals):
|
||||
if self.ui.square_cb.get_value():
|
||||
dia = float(apid_value['height']) * prop_factor
|
||||
else:
|
||||
if self.ui.rectangular_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) * prop_factor
|
||||
else:
|
||||
dia = float(apid_value['width']) * prop_factor
|
||||
else:
|
||||
if self.ui.other_cb.get_value():
|
||||
try:
|
||||
dia = float(apid_value['size']) * prop_factor
|
||||
except KeyError:
|
||||
if ap_type == 'AM':
|
||||
pol = apid_value['geometry'][0]['solid']
|
||||
x0, y0, x1, y1 = pol.bounds
|
||||
dx = x1 - x0
|
||||
dy = y1 - y0
|
||||
if dx <= dy:
|
||||
dia = dx * prop_factor
|
||||
else:
|
||||
dia = dy * prop_factor
|
||||
|
||||
# if dia is None then none of the above applied so we skip the following
|
||||
if dia is None:
|
||||
continue
|
||||
|
||||
tool_in_drills = False
|
||||
for tool, tool_val in tools.items():
|
||||
if abs(float('%.*f' % (
|
||||
self.decimals,
|
||||
tool_val["tooldia"])) - float('%.*f' % (self.decimals, dia))) < (10 ** -self.decimals):
|
||||
tool_in_drills = tool
|
||||
|
||||
if tool_in_drills is False:
|
||||
if tools:
|
||||
new_tool = max([int(t) for t in tools]) + 1
|
||||
tool_in_drills = new_tool
|
||||
else:
|
||||
tool_in_drills = 1
|
||||
|
||||
for geo_el in apid_value['geometry']:
|
||||
if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
|
||||
if tool_in_drills not in tools:
|
||||
tools[tool_in_drills] = {
|
||||
"tooldia": dia,
|
||||
"drills": [],
|
||||
"slots": []
|
||||
}
|
||||
|
||||
tools[tool_in_drills]['drills'].append(geo_el['follow'])
|
||||
|
||||
if 'solid_geometry' not in tools[tool_in_drills]:
|
||||
tools[tool_in_drills]['solid_geometry'] = []
|
||||
else:
|
||||
tools[tool_in_drills]['solid_geometry'].append(geo_el['follow'])
|
||||
|
||||
if tool_in_drills in tools:
|
||||
if 'solid_geometry' not in tools[tool_in_drills] or not tools[tool_in_drills]['solid_geometry']:
|
||||
drills_found.add(False)
|
||||
else:
|
||||
drills_found.add(True)
|
||||
|
||||
if True not in drills_found:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("No drills extracted. Try different parameters."))
|
||||
return
|
||||
|
||||
def obj_init(obj_inst, app_inst):
|
||||
obj_inst.tools = tools
|
||||
obj_inst.drills = drills
|
||||
obj_inst.create_geometry()
|
||||
obj_inst.source_file = self.app.export_excellon(obj_name=outname, local_use=obj_inst, filename=None,
|
||||
use_thread=False)
|
||||
|
||||
self.app.app_obj.new_object("excellon", outname, obj_init)
|
||||
|
||||
def on_hole_size_toggle(self, val):
|
||||
if val == "fixed":
|
||||
self.ui.fixed_label.setDisabled(False)
|
||||
self.ui.dia_entry.setDisabled(False)
|
||||
self.ui.dia_label.setDisabled(False)
|
||||
|
||||
self.ui.ring_frame.setDisabled(True)
|
||||
|
||||
self.ui.prop_label.setDisabled(True)
|
||||
self.ui.factor_label.setDisabled(True)
|
||||
self.ui.factor_entry.setDisabled(True)
|
||||
elif val == "ring":
|
||||
self.ui.fixed_label.setDisabled(True)
|
||||
self.ui.dia_entry.setDisabled(True)
|
||||
self.ui.dia_label.setDisabled(True)
|
||||
|
||||
self.ui.ring_frame.setDisabled(False)
|
||||
|
||||
self.ui.prop_label.setDisabled(True)
|
||||
self.ui.factor_label.setDisabled(True)
|
||||
self.ui.factor_entry.setDisabled(True)
|
||||
elif val == "prop":
|
||||
self.ui.fixed_label.setDisabled(True)
|
||||
self.ui.dia_entry.setDisabled(True)
|
||||
self.ui.dia_label.setDisabled(True)
|
||||
|
||||
self.ui.ring_frame.setDisabled(True)
|
||||
|
||||
self.ui.prop_label.setDisabled(False)
|
||||
self.ui.factor_label.setDisabled(False)
|
||||
self.ui.factor_entry.setDisabled(False)
|
||||
|
||||
def reset_fields(self):
|
||||
self.ui.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.ui.gerber_object_combo.setCurrentIndex(0)
|
||||
|
||||
|
||||
class ExtractDrillsUI:
|
||||
|
||||
toolName = _("Extract Drills")
|
||||
|
||||
def __init__(self, layout, app):
|
||||
self.app = app
|
||||
self.decimals = self.app.decimals
|
||||
self.layout = layout
|
||||
|
||||
# ## Title
|
||||
title_label = QtWidgets.QLabel("%s" % self.toolName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
self.layout.addWidget(QtWidgets.QLabel(""))
|
||||
@@ -297,11 +689,11 @@ class ToolExtractDrills(AppTool):
|
||||
_("Extract drills from a given Gerber file.")
|
||||
)
|
||||
self.e_drills_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(self.e_drills_button)
|
||||
|
||||
self.layout.addStretch()
|
||||
@@ -312,11 +704,11 @@ class ToolExtractDrills(AppTool):
|
||||
_("Will reset the tool parameters.")
|
||||
)
|
||||
self.reset_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(self.reset_button)
|
||||
|
||||
self.circular_ring_entry.setEnabled(False)
|
||||
@@ -331,380 +723,22 @@ class ToolExtractDrills(AppTool):
|
||||
self.factor_entry.setDisabled(True)
|
||||
|
||||
self.ring_frame.setDisabled(True)
|
||||
# #################################### FINSIHED GUI ###########################
|
||||
# #############################################################################
|
||||
|
||||
# ## Signals
|
||||
self.hole_size_radio.activated_custom.connect(self.on_hole_size_toggle)
|
||||
self.e_drills_button.clicked.connect(self.on_extract_drills_click)
|
||||
self.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
self.circular_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.circular_ring_entry.setDisabled(False) if state else self.circular_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.oblong_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.oblong_ring_entry.setDisabled(False) if state else self.oblong_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.square_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.square_ring_entry.setDisabled(False) if state else self.square_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.rectangular_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.rectangular_ring_entry.setDisabled(False) if state else self.rectangular_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
self.other_cb.stateChanged.connect(
|
||||
lambda state:
|
||||
self.other_ring_entry.setDisabled(False) if state else self.other_ring_entry.setDisabled(True)
|
||||
)
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+I', **kwargs)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("Extract Drills()")
|
||||
|
||||
if toggle:
|
||||
# if the splitter is hidden, display it, else hide it but only if the current widget is the same
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
else:
|
||||
try:
|
||||
if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
|
||||
# if tab is populated with the tool but it does not have the focus, focus on it
|
||||
if not self.app.ui.notebook.currentWidget() is self.app.ui.tool_tab:
|
||||
# focus on Tool Tab
|
||||
self.app.ui.notebook.setCurrentWidget(self.app.ui.tool_tab)
|
||||
else:
|
||||
self.app.ui.splitter.setSizes([0, 1])
|
||||
except AttributeError:
|
||||
pass
|
||||
def confirmation_message(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%.*f, %.*f]' % (_("Edited value is out of range"),
|
||||
self.decimals,
|
||||
minval,
|
||||
self.decimals,
|
||||
maxval), False)
|
||||
else:
|
||||
if self.app.ui.splitter.sizes()[0] == 0:
|
||||
self.app.ui.splitter.setSizes([1, 1])
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
AppTool.run(self)
|
||||
self.set_tool_ui()
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Extract Drills Tool"))
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.reset_fields()
|
||||
|
||||
self.hole_size_radio.set_value(self.app.defaults["tools_edrills_hole_type"])
|
||||
|
||||
self.dia_entry.set_value(float(self.app.defaults["tools_edrills_hole_fixed_dia"]))
|
||||
|
||||
self.circular_ring_entry.set_value(float(self.app.defaults["tools_edrills_circular_ring"]))
|
||||
self.oblong_ring_entry.set_value(float(self.app.defaults["tools_edrills_oblong_ring"]))
|
||||
self.square_ring_entry.set_value(float(self.app.defaults["tools_edrills_square_ring"]))
|
||||
self.rectangular_ring_entry.set_value(float(self.app.defaults["tools_edrills_rectangular_ring"]))
|
||||
self.other_ring_entry.set_value(float(self.app.defaults["tools_edrills_others_ring"]))
|
||||
|
||||
self.circular_cb.set_value(self.app.defaults["tools_edrills_circular"])
|
||||
self.oblong_cb.set_value(self.app.defaults["tools_edrills_oblong"])
|
||||
self.square_cb.set_value(self.app.defaults["tools_edrills_square"])
|
||||
self.rectangular_cb.set_value(self.app.defaults["tools_edrills_rectangular"])
|
||||
self.other_cb.set_value(self.app.defaults["tools_edrills_others"])
|
||||
|
||||
self.factor_entry.set_value(float(self.app.defaults["tools_edrills_hole_prop_factor"]))
|
||||
|
||||
def on_extract_drills_click(self):
|
||||
|
||||
drill_dia = self.dia_entry.get_value()
|
||||
circ_r_val = self.circular_ring_entry.get_value()
|
||||
oblong_r_val = self.oblong_ring_entry.get_value()
|
||||
square_r_val = self.square_ring_entry.get_value()
|
||||
rect_r_val = self.rectangular_ring_entry.get_value()
|
||||
other_r_val = self.other_ring_entry.get_value()
|
||||
|
||||
prop_factor = self.factor_entry.get_value() / 100.0
|
||||
|
||||
drills = []
|
||||
tools = {}
|
||||
|
||||
selection_index = self.gerber_object_combo.currentIndex()
|
||||
model_index = self.app.collection.index(selection_index, 0, self.gerber_object_combo.rootModelIndex())
|
||||
|
||||
try:
|
||||
fcobj = model_index.internalPointer().obj
|
||||
except Exception:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
|
||||
return
|
||||
|
||||
outname = fcobj.options['name'].rpartition('.')[0]
|
||||
|
||||
mode = self.hole_size_radio.get_value()
|
||||
|
||||
if mode == 'fixed':
|
||||
tools = {
|
||||
1: {
|
||||
"tooldia": drill_dia,
|
||||
"drills": [],
|
||||
"slots": []
|
||||
}
|
||||
}
|
||||
for apid, apid_value in fcobj.apertures.items():
|
||||
ap_type = apid_value['type']
|
||||
|
||||
if ap_type == 'C':
|
||||
if self.circular_cb.get_value() is False:
|
||||
continue
|
||||
elif ap_type == 'O':
|
||||
if self.oblong_cb.get_value() is False:
|
||||
continue
|
||||
elif ap_type == 'R':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
|
||||
# if the height == width (float numbers so the reason for the following)
|
||||
if round(width, self.decimals) == round(height, self.decimals):
|
||||
if self.square_cb.get_value() is False:
|
||||
continue
|
||||
else:
|
||||
if self.rectangular_cb.get_value() is False:
|
||||
continue
|
||||
else:
|
||||
if self.other_cb.get_value() is False:
|
||||
continue
|
||||
|
||||
for geo_el in apid_value['geometry']:
|
||||
if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
|
||||
tools[1]["drills"].append(geo_el['follow'])
|
||||
if 'solid_geometry' not in tools[1]:
|
||||
tools[1]['solid_geometry'] = []
|
||||
else:
|
||||
tools[1]['solid_geometry'].append(geo_el['follow'])
|
||||
|
||||
if 'solid_geometry' not in tools[1] or not tools[1]['solid_geometry']:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("No drills extracted. Try different parameters."))
|
||||
return
|
||||
elif mode == 'ring':
|
||||
drills_found = set()
|
||||
for apid, apid_value in fcobj.apertures.items():
|
||||
ap_type = apid_value['type']
|
||||
|
||||
dia = None
|
||||
if ap_type == 'C':
|
||||
if self.circular_cb.get_value():
|
||||
dia = float(apid_value['size']) - (2 * circ_r_val)
|
||||
elif ap_type == 'O':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
if self.oblong_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) - (2 * oblong_r_val)
|
||||
else:
|
||||
dia = float(apid_value['width']) - (2 * oblong_r_val)
|
||||
elif ap_type == 'R':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
|
||||
# if the height == width (float numbers so the reason for the following)
|
||||
if abs(float('%.*f' % (self.decimals, width)) - float('%.*f' % (self.decimals, height))) < \
|
||||
(10 ** -self.decimals):
|
||||
if self.square_cb.get_value():
|
||||
dia = float(apid_value['height']) - (2 * square_r_val)
|
||||
else:
|
||||
if self.rectangular_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) - (2 * rect_r_val)
|
||||
else:
|
||||
dia = float(apid_value['width']) - (2 * rect_r_val)
|
||||
else:
|
||||
if self.other_cb.get_value():
|
||||
try:
|
||||
dia = float(apid_value['size']) - (2 * other_r_val)
|
||||
except KeyError:
|
||||
if ap_type == 'AM':
|
||||
pol = apid_value['geometry'][0]['solid']
|
||||
x0, y0, x1, y1 = pol.bounds
|
||||
dx = x1 - x0
|
||||
dy = y1 - y0
|
||||
if dx <= dy:
|
||||
dia = dx - (2 * other_r_val)
|
||||
else:
|
||||
dia = dy - (2 * other_r_val)
|
||||
|
||||
# if dia is None then none of the above applied so we skip the following
|
||||
if dia is None:
|
||||
continue
|
||||
|
||||
tool_in_drills = False
|
||||
for tool, tool_val in tools.items():
|
||||
if abs(float('%.*f' % (
|
||||
self.decimals,
|
||||
tool_val["tooldia"])) - float('%.*f' % (self.decimals, dia))) < (10 ** -self.decimals):
|
||||
tool_in_drills = tool
|
||||
|
||||
if tool_in_drills is False:
|
||||
if tools:
|
||||
new_tool = max([int(t) for t in tools]) + 1
|
||||
tool_in_drills = new_tool
|
||||
else:
|
||||
tool_in_drills = 1
|
||||
|
||||
for geo_el in apid_value['geometry']:
|
||||
if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
|
||||
if tool_in_drills not in tools:
|
||||
tools[tool_in_drills] = {
|
||||
"tooldia": dia,
|
||||
"drills": [],
|
||||
"slots": []
|
||||
}
|
||||
|
||||
tools[tool_in_drills]['drills'].append(geo_el['follow'])
|
||||
|
||||
if 'solid_geometry' not in tools[tool_in_drills]:
|
||||
tools[tool_in_drills]['solid_geometry'] = []
|
||||
else:
|
||||
tools[tool_in_drills]['solid_geometry'].append(geo_el['follow'])
|
||||
|
||||
if tool_in_drills in tools:
|
||||
if 'solid_geometry' not in tools[tool_in_drills] or not tools[tool_in_drills]['solid_geometry']:
|
||||
drills_found.add(False)
|
||||
else:
|
||||
drills_found.add(True)
|
||||
|
||||
if True not in drills_found:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("No drills extracted. Try different parameters."))
|
||||
return
|
||||
def confirmation_message_int(self, accepted, minval, maxval):
|
||||
if accepted is False:
|
||||
self.app.inform[str, bool].emit('[WARNING_NOTCL] %s: [%d, %d]' %
|
||||
(_("Edited value is out of range"), minval, maxval), False)
|
||||
else:
|
||||
drills_found = set()
|
||||
for apid, apid_value in fcobj.apertures.items():
|
||||
ap_type = apid_value['type']
|
||||
|
||||
dia = None
|
||||
if ap_type == 'C':
|
||||
if self.circular_cb.get_value():
|
||||
dia = float(apid_value['size']) * prop_factor
|
||||
elif ap_type == 'O':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
if self.oblong_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) * prop_factor
|
||||
else:
|
||||
dia = float(apid_value['width']) * prop_factor
|
||||
elif ap_type == 'R':
|
||||
width = float(apid_value['width'])
|
||||
height = float(apid_value['height'])
|
||||
|
||||
# if the height == width (float numbers so the reason for the following)
|
||||
if abs(float('%.*f' % (self.decimals, width)) - float('%.*f' % (self.decimals, height))) < \
|
||||
(10 ** -self.decimals):
|
||||
if self.square_cb.get_value():
|
||||
dia = float(apid_value['height']) * prop_factor
|
||||
else:
|
||||
if self.rectangular_cb.get_value():
|
||||
if width > height:
|
||||
dia = float(apid_value['height']) * prop_factor
|
||||
else:
|
||||
dia = float(apid_value['width']) * prop_factor
|
||||
else:
|
||||
if self.other_cb.get_value():
|
||||
try:
|
||||
dia = float(apid_value['size']) * prop_factor
|
||||
except KeyError:
|
||||
if ap_type == 'AM':
|
||||
pol = apid_value['geometry'][0]['solid']
|
||||
x0, y0, x1, y1 = pol.bounds
|
||||
dx = x1 - x0
|
||||
dy = y1 - y0
|
||||
if dx <= dy:
|
||||
dia = dx * prop_factor
|
||||
else:
|
||||
dia = dy * prop_factor
|
||||
|
||||
# if dia is None then none of the above applied so we skip the following
|
||||
if dia is None:
|
||||
continue
|
||||
|
||||
tool_in_drills = False
|
||||
for tool, tool_val in tools.items():
|
||||
if abs(float('%.*f' % (
|
||||
self.decimals,
|
||||
tool_val["tooldia"])) - float('%.*f' % (self.decimals, dia))) < (10 ** -self.decimals):
|
||||
tool_in_drills = tool
|
||||
|
||||
if tool_in_drills is False:
|
||||
if tools:
|
||||
new_tool = max([int(t) for t in tools]) + 1
|
||||
tool_in_drills = new_tool
|
||||
else:
|
||||
tool_in_drills = 1
|
||||
|
||||
for geo_el in apid_value['geometry']:
|
||||
if 'follow' in geo_el and isinstance(geo_el['follow'], Point):
|
||||
if tool_in_drills not in tools:
|
||||
tools[tool_in_drills] = {
|
||||
"tooldia": dia,
|
||||
"drills": [],
|
||||
"slots": []
|
||||
}
|
||||
|
||||
tools[tool_in_drills]['drills'].append(geo_el['follow'])
|
||||
|
||||
if 'solid_geometry' not in tools[tool_in_drills]:
|
||||
tools[tool_in_drills]['solid_geometry'] = []
|
||||
else:
|
||||
tools[tool_in_drills]['solid_geometry'].append(geo_el['follow'])
|
||||
|
||||
if tool_in_drills in tools:
|
||||
if 'solid_geometry' not in tools[tool_in_drills] or not tools[tool_in_drills]['solid_geometry']:
|
||||
drills_found.add(False)
|
||||
else:
|
||||
drills_found.add(True)
|
||||
|
||||
if True not in drills_found:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("No drills extracted. Try different parameters."))
|
||||
return
|
||||
|
||||
def obj_init(obj_inst, app_inst):
|
||||
obj_inst.tools = tools
|
||||
obj_inst.drills = drills
|
||||
obj_inst.create_geometry()
|
||||
obj_inst.source_file = self.app.export_excellon(obj_name=outname, local_use=obj_inst, filename=None,
|
||||
use_thread=False)
|
||||
|
||||
self.app.app_obj.new_object("excellon", outname, obj_init)
|
||||
|
||||
def on_hole_size_toggle(self, val):
|
||||
if val == "fixed":
|
||||
self.fixed_label.setDisabled(False)
|
||||
self.dia_entry.setDisabled(False)
|
||||
self.dia_label.setDisabled(False)
|
||||
|
||||
self.ring_frame.setDisabled(True)
|
||||
|
||||
self.prop_label.setDisabled(True)
|
||||
self.factor_label.setDisabled(True)
|
||||
self.factor_entry.setDisabled(True)
|
||||
elif val == "ring":
|
||||
self.fixed_label.setDisabled(True)
|
||||
self.dia_entry.setDisabled(True)
|
||||
self.dia_label.setDisabled(True)
|
||||
|
||||
self.ring_frame.setDisabled(False)
|
||||
|
||||
self.prop_label.setDisabled(True)
|
||||
self.factor_label.setDisabled(True)
|
||||
self.factor_entry.setDisabled(True)
|
||||
elif val == "prop":
|
||||
self.fixed_label.setDisabled(True)
|
||||
self.dia_entry.setDisabled(True)
|
||||
self.dia_label.setDisabled(True)
|
||||
|
||||
self.ring_frame.setDisabled(True)
|
||||
|
||||
self.prop_label.setDisabled(False)
|
||||
self.factor_label.setDisabled(False)
|
||||
self.factor_entry.setDisabled(False)
|
||||
|
||||
def reset_fields(self):
|
||||
self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.gerber_object_combo.setCurrentIndex(0)
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
Reference in New Issue
Block a user