- for Tools: Calculators, Calibration, Copper Thieving, Corners, Fiducials - moved the Tool UI in its own class
This commit is contained in:
parent
0d15130b40
commit
c3b99c3e33
|
@ -14,6 +14,7 @@ CHANGELOG for FlatCAM beta
|
|||
- in CNCJob UI Autolevelling - adding manual probe points now show some geometry (circles) for the added points until the adding is finished
|
||||
- 2Sided Tool - finished the feature that allows picking an Excellon drill hole center as a Point mirror reference
|
||||
- Tool Align Objects - moved the Tool Ui into its own class
|
||||
- for Tools: Calculators, Calibration, Copper Thieving, Corners, Fiducials - moved the Tool UI in its own class
|
||||
|
||||
24.08.2020
|
||||
|
||||
|
|
|
@ -21,17 +21,143 @@ if '_' not in builtins.__dict__:
|
|||
|
||||
class ToolCalculator(AppTool):
|
||||
|
||||
toolName = _("Calculators")
|
||||
v_shapeName = _("V-Shape Tool Calculator")
|
||||
unitsName = _("Units Calculator")
|
||||
eplateName = _("ElectroPlating Calculator")
|
||||
|
||||
def __init__(self, app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
self.app = app
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = CalcUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
self.units = ''
|
||||
|
||||
# ## Signals
|
||||
self.ui.cutDepth_entry.valueChanged.connect(self.on_calculate_tool_dia)
|
||||
self.ui.cutDepth_entry.returnPressed.connect(self.on_calculate_tool_dia)
|
||||
self.ui.tipDia_entry.returnPressed.connect(self.on_calculate_tool_dia)
|
||||
self.ui.tipAngle_entry.returnPressed.connect(self.on_calculate_tool_dia)
|
||||
self.ui.calculate_vshape_button.clicked.connect(self.on_calculate_tool_dia)
|
||||
|
||||
self.ui.mm_entry.editingFinished.connect(self.on_calculate_inch_units)
|
||||
self.ui.inch_entry.editingFinished.connect(self.on_calculate_mm_units)
|
||||
|
||||
self.ui.calculate_plate_button.clicked.connect(self.on_calculate_eplate)
|
||||
self.ui.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("ToolCalculators()")
|
||||
|
||||
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, _("Calc. Tool"))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+C', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.units = self.app.defaults['units'].upper()
|
||||
|
||||
# ## Initialize form
|
||||
self.ui.mm_entry.set_value('%.*f' % (self.decimals, 0))
|
||||
self.ui.inch_entry.set_value('%.*f' % (self.decimals, 0))
|
||||
|
||||
length = self.app.defaults["tools_calc_electro_length"]
|
||||
width = self.app.defaults["tools_calc_electro_width"]
|
||||
density = self.app.defaults["tools_calc_electro_cdensity"]
|
||||
growth = self.app.defaults["tools_calc_electro_growth"]
|
||||
self.ui.pcblength_entry.set_value(length)
|
||||
self.ui.pcbwidth_entry.set_value(width)
|
||||
self.ui.cdensity_entry.set_value(density)
|
||||
self.ui.growth_entry.set_value(growth)
|
||||
self.ui.cvalue_entry.set_value(0.00)
|
||||
self.ui.time_entry.set_value(0.0)
|
||||
|
||||
tip_dia = self.app.defaults["tools_calc_vshape_tip_dia"]
|
||||
tip_angle = self.app.defaults["tools_calc_vshape_tip_angle"]
|
||||
cut_z = self.app.defaults["tools_calc_vshape_cut_z"]
|
||||
|
||||
self.ui.tipDia_entry.set_value(tip_dia)
|
||||
self.ui.tipAngle_entry.set_value(tip_angle)
|
||||
self.ui.cutDepth_entry.set_value(cut_z)
|
||||
self.ui.effectiveToolDia_entry.set_value('0.0000')
|
||||
|
||||
def on_calculate_tool_dia(self):
|
||||
# Calculation:
|
||||
# Manufacturer gives total angle of the the tip but we need only half of it
|
||||
# tangent(half_tip_angle) = opposite side / adjacent = part_of _real_dia / depth_of_cut
|
||||
# effective_diameter = tip_diameter + part_of_real_dia_left_side + part_of_real_dia_right_side
|
||||
# tool is symmetrical therefore: part_of_real_dia_left_side = part_of_real_dia_right_side
|
||||
# effective_diameter = tip_diameter + (2 * part_of_real_dia_left_side)
|
||||
# effective diameter = tip_diameter + (2 * depth_of_cut * tangent(half_tip_angle))
|
||||
|
||||
tip_diameter = float(self.ui.tipDia_entry.get_value())
|
||||
|
||||
half_tip_angle = float(self.ui.tipAngle_entry.get_value()) / 2.0
|
||||
|
||||
cut_depth = float(self.ui.cutDepth_entry.get_value())
|
||||
cut_depth = -cut_depth if cut_depth < 0 else cut_depth
|
||||
|
||||
tool_diameter = tip_diameter + (2 * cut_depth * math.tan(math.radians(half_tip_angle)))
|
||||
self.ui.effectiveToolDia_entry.set_value("%.*f" % (self.decimals, tool_diameter))
|
||||
|
||||
def on_calculate_inch_units(self):
|
||||
mm_val = float(self.mm_entry.get_value())
|
||||
self.ui.inch_entry.set_value('%.*f' % (self.decimals, (mm_val / 25.4)))
|
||||
|
||||
def on_calculate_mm_units(self):
|
||||
inch_val = float(self.inch_entry.get_value())
|
||||
self.ui.mm_entry.set_value('%.*f' % (self.decimals, (inch_val * 25.4)))
|
||||
|
||||
def on_calculate_eplate(self):
|
||||
length = float(self.ui.pcblength_entry.get_value())
|
||||
width = float(self.ui.pcbwidth_entry.get_value())
|
||||
density = float(self.ui.cdensity_entry.get_value())
|
||||
copper = float(self.ui.growth_entry.get_value())
|
||||
|
||||
calculated_current = (length * width * density) * 0.0021527820833419
|
||||
calculated_time = copper * 2.142857142857143 * float(20 / density)
|
||||
|
||||
self.ui.cvalue_entry.set_value('%.2f' % calculated_current)
|
||||
self.ui.time_entry.set_value('%.1f' % calculated_time)
|
||||
|
||||
|
||||
class CalcUI:
|
||||
|
||||
toolName = _("Calculators")
|
||||
v_shapeName = _("V-Shape Tool Calculator")
|
||||
unitsName = _("Units Calculator")
|
||||
eplateName = _("ElectroPlating Calculator")
|
||||
|
||||
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("""
|
||||
|
@ -256,116 +382,22 @@ class ToolCalculator(AppTool):
|
|||
""")
|
||||
self.layout.addWidget(self.reset_button)
|
||||
|
||||
self.units = ''
|
||||
# #################################### FINSIHED GUI ###########################
|
||||
# #############################################################################
|
||||
|
||||
# ## Signals
|
||||
self.cutDepth_entry.valueChanged.connect(self.on_calculate_tool_dia)
|
||||
self.cutDepth_entry.returnPressed.connect(self.on_calculate_tool_dia)
|
||||
self.tipDia_entry.returnPressed.connect(self.on_calculate_tool_dia)
|
||||
self.tipAngle_entry.returnPressed.connect(self.on_calculate_tool_dia)
|
||||
self.calculate_vshape_button.clicked.connect(self.on_calculate_tool_dia)
|
||||
|
||||
self.mm_entry.editingFinished.connect(self.on_calculate_inch_units)
|
||||
self.inch_entry.editingFinished.connect(self.on_calculate_mm_units)
|
||||
|
||||
self.calculate_plate_button.clicked.connect(self.on_calculate_eplate)
|
||||
self.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("ToolCalculators()")
|
||||
|
||||
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])
|
||||
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:
|
||||
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)
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
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:
|
||||
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, _("Calc. Tool"))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+C', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.units = self.app.defaults['units'].upper()
|
||||
|
||||
# ## Initialize form
|
||||
self.mm_entry.set_value('%.*f' % (self.decimals, 0))
|
||||
self.inch_entry.set_value('%.*f' % (self.decimals, 0))
|
||||
|
||||
length = self.app.defaults["tools_calc_electro_length"]
|
||||
width = self.app.defaults["tools_calc_electro_width"]
|
||||
density = self.app.defaults["tools_calc_electro_cdensity"]
|
||||
growth = self.app.defaults["tools_calc_electro_growth"]
|
||||
self.pcblength_entry.set_value(length)
|
||||
self.pcbwidth_entry.set_value(width)
|
||||
self.cdensity_entry.set_value(density)
|
||||
self.growth_entry.set_value(growth)
|
||||
self.cvalue_entry.set_value(0.00)
|
||||
self.time_entry.set_value(0.0)
|
||||
|
||||
tip_dia = self.app.defaults["tools_calc_vshape_tip_dia"]
|
||||
tip_angle = self.app.defaults["tools_calc_vshape_tip_angle"]
|
||||
cut_z = self.app.defaults["tools_calc_vshape_cut_z"]
|
||||
|
||||
self.tipDia_entry.set_value(tip_dia)
|
||||
self.tipAngle_entry.set_value(tip_angle)
|
||||
self.cutDepth_entry.set_value(cut_z)
|
||||
self.effectiveToolDia_entry.set_value('0.0000')
|
||||
|
||||
def on_calculate_tool_dia(self):
|
||||
# Calculation:
|
||||
# Manufacturer gives total angle of the the tip but we need only half of it
|
||||
# tangent(half_tip_angle) = opposite side / adjacent = part_of _real_dia / depth_of_cut
|
||||
# effective_diameter = tip_diameter + part_of_real_dia_left_side + part_of_real_dia_right_side
|
||||
# tool is symmetrical therefore: part_of_real_dia_left_side = part_of_real_dia_right_side
|
||||
# effective_diameter = tip_diameter + (2 * part_of_real_dia_left_side)
|
||||
# effective diameter = tip_diameter + (2 * depth_of_cut * tangent(half_tip_angle))
|
||||
|
||||
tip_diameter = float(self.tipDia_entry.get_value())
|
||||
|
||||
half_tip_angle = float(self.tipAngle_entry.get_value()) / 2.0
|
||||
|
||||
cut_depth = float(self.cutDepth_entry.get_value())
|
||||
cut_depth = -cut_depth if cut_depth < 0 else cut_depth
|
||||
|
||||
tool_diameter = tip_diameter + (2 * cut_depth * math.tan(math.radians(half_tip_angle)))
|
||||
self.effectiveToolDia_entry.set_value("%.*f" % (self.decimals, tool_diameter))
|
||||
|
||||
def on_calculate_inch_units(self):
|
||||
mm_val = float(self.mm_entry.get_value())
|
||||
self.inch_entry.set_value('%.*f' % (self.decimals, (mm_val / 25.4)))
|
||||
|
||||
def on_calculate_mm_units(self):
|
||||
inch_val = float(self.inch_entry.get_value())
|
||||
self.mm_entry.set_value('%.*f' % (self.decimals, (inch_val * 25.4)))
|
||||
|
||||
def on_calculate_eplate(self):
|
||||
length = float(self.pcblength_entry.get_value())
|
||||
width = float(self.pcbwidth_entry.get_value())
|
||||
density = float(self.cdensity_entry.get_value())
|
||||
copper = float(self.growth_entry.get_value())
|
||||
|
||||
calculated_current = (length * width * density) * 0.0021527820833419
|
||||
calculated_time = copper * 2.142857142857143 * float(20 / density)
|
||||
|
||||
self.cvalue_entry.set_value('%.2f' % calculated_current)
|
||||
self.time_entry.set_value('%.1f' % calculated_time)
|
||||
|
||||
# end of file
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -28,8 +28,6 @@ log = logging.getLogger('base')
|
|||
|
||||
class ToolCorners(AppTool):
|
||||
|
||||
toolName = _("Corner Markers Tool")
|
||||
|
||||
def __init__(self, app):
|
||||
AppTool.__init__(self, app)
|
||||
|
||||
|
@ -39,6 +37,270 @@ class ToolCorners(AppTool):
|
|||
self.decimals = self.app.decimals
|
||||
self.units = ''
|
||||
|
||||
# #############################################################################
|
||||
# ######################### Tool GUI ##########################################
|
||||
# #############################################################################
|
||||
self.ui = CornersUI(layout=self.layout, app=self.app)
|
||||
self.toolName = self.ui.toolName
|
||||
|
||||
# Objects involved in Copper thieving
|
||||
self.grb_object = None
|
||||
|
||||
# store the flattened geometry here:
|
||||
self.flat_geometry = []
|
||||
|
||||
# Tool properties
|
||||
self.fid_dia = None
|
||||
|
||||
self.grb_steps_per_circle = self.app.defaults["gerber_circle_steps"]
|
||||
|
||||
# SIGNALS
|
||||
self.ui.add_marker_button.clicked.connect(self.add_markers)
|
||||
self.ui.toggle_all_cb.toggled.connect(self.on_toggle_all)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("ToolCorners()")
|
||||
|
||||
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, _("Corners Tool"))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+M', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.units = self.app.defaults['units']
|
||||
self.ui.thick_entry.set_value(self.app.defaults["tools_corners_thickness"])
|
||||
self.ui.l_entry.set_value(float(self.app.defaults["tools_corners_length"]))
|
||||
self.ui.margin_entry.set_value(float(self.app.defaults["tools_corners_margin"]))
|
||||
self.ui.toggle_all_cb.set_value(False)
|
||||
|
||||
def on_toggle_all(self, val):
|
||||
self.ui.bl_cb.set_value(val)
|
||||
self.ui.br_cb.set_value(val)
|
||||
self.ui.tl_cb.set_value(val)
|
||||
self.ui.tr_cb.set_value(val)
|
||||
|
||||
def add_markers(self):
|
||||
self.app.call_source = "corners_tool"
|
||||
tl_state = self.ui.tl_cb.get_value()
|
||||
tr_state = self.ui.tr_cb.get_value()
|
||||
bl_state = self.ui.bl_cb.get_value()
|
||||
br_state = self.ui.br_cb.get_value()
|
||||
|
||||
# get the Gerber object on which the corner marker will be inserted
|
||||
selection_index = self.ui.object_combo.currentIndex()
|
||||
model_index = self.app.collection.index(selection_index, 0, self.ui.object_combo.rootModelIndex())
|
||||
|
||||
try:
|
||||
self.grb_object = model_index.internalPointer().obj
|
||||
except Exception as e:
|
||||
log.debug("ToolCorners.add_markers() --> %s" % str(e))
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
|
||||
return
|
||||
|
||||
xmin, ymin, xmax, ymax = self.grb_object.bounds()
|
||||
points = {}
|
||||
if tl_state:
|
||||
points['tl'] = (xmin, ymax)
|
||||
if tr_state:
|
||||
points['tr'] = (xmax, ymax)
|
||||
if bl_state:
|
||||
points['bl'] = (xmin, ymin)
|
||||
if br_state:
|
||||
points['br'] = (xmax, ymin)
|
||||
|
||||
self.add_corners_geo(points, g_obj=self.grb_object)
|
||||
|
||||
self.grb_object.source_file = self.app.export_gerber(obj_name=self.grb_object.options['name'],
|
||||
filename=None,
|
||||
local_use=self.grb_object, use_thread=False)
|
||||
self.on_exit()
|
||||
|
||||
def add_corners_geo(self, points_storage, g_obj):
|
||||
"""
|
||||
Add geometry to the solid_geometry of the copper Gerber object
|
||||
|
||||
:param points_storage: a dictionary holding the points where to add corners
|
||||
:param g_obj: the Gerber object where to add the geometry
|
||||
:return: None
|
||||
"""
|
||||
|
||||
line_thickness = self.ui.thick_entry.get_value()
|
||||
line_length = self.ui.l_entry.get_value()
|
||||
margin = self.ui.margin_entry.get_value()
|
||||
|
||||
geo_list = []
|
||||
|
||||
if not points_storage:
|
||||
self.app.inform.emit("[ERROR_NOTCL] %s." % _("Please select at least a location"))
|
||||
return
|
||||
|
||||
for key in points_storage:
|
||||
if key == 'tl':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] - margin - line_thickness / 2.0
|
||||
y = pt[1] + margin + line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x + line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y - line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
if key == 'tr':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] + margin + line_thickness / 2.0
|
||||
y = pt[1] + margin + line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x - line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y - line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
if key == 'bl':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] - margin - line_thickness / 2.0
|
||||
y = pt[1] - margin - line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x + line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y + line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
if key == 'br':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] + margin + line_thickness / 2.0
|
||||
y = pt[1] - margin - line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x - line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y + line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
|
||||
aperture_found = None
|
||||
for ap_id, ap_val in g_obj.apertures.items():
|
||||
if ap_val['type'] == 'C' and ap_val['size'] == line_thickness:
|
||||
aperture_found = ap_id
|
||||
break
|
||||
|
||||
geo_buff_list = []
|
||||
if aperture_found:
|
||||
for geo in geo_list:
|
||||
geo_buff = geo.buffer(line_thickness / 2.0, resolution=self.grb_steps_per_circle, join_style=2)
|
||||
geo_buff_list.append(geo_buff)
|
||||
|
||||
dict_el = {}
|
||||
dict_el['follow'] = geo
|
||||
dict_el['solid'] = geo_buff
|
||||
g_obj.apertures[aperture_found]['geometry'].append(deepcopy(dict_el))
|
||||
else:
|
||||
ap_keys = list(g_obj.apertures.keys())
|
||||
if ap_keys:
|
||||
new_apid = str(int(max(ap_keys)) + 1)
|
||||
else:
|
||||
new_apid = '10'
|
||||
|
||||
g_obj.apertures[new_apid] = {}
|
||||
g_obj.apertures[new_apid]['type'] = 'C'
|
||||
g_obj.apertures[new_apid]['size'] = line_thickness
|
||||
g_obj.apertures[new_apid]['geometry'] = []
|
||||
|
||||
for geo in geo_list:
|
||||
geo_buff = geo.buffer(line_thickness / 2.0, resolution=self.grb_steps_per_circle, join_style=3)
|
||||
geo_buff_list.append(geo_buff)
|
||||
|
||||
dict_el = {}
|
||||
dict_el['follow'] = geo
|
||||
dict_el['solid'] = geo_buff
|
||||
g_obj.apertures[new_apid]['geometry'].append(deepcopy(dict_el))
|
||||
|
||||
s_list = []
|
||||
if g_obj.solid_geometry:
|
||||
try:
|
||||
for poly in g_obj.solid_geometry:
|
||||
s_list.append(poly)
|
||||
except TypeError:
|
||||
s_list.append(g_obj.solid_geometry)
|
||||
|
||||
geo_buff_list = MultiPolygon(geo_buff_list)
|
||||
geo_buff_list = geo_buff_list.buffer(0)
|
||||
for poly in geo_buff_list:
|
||||
s_list.append(poly)
|
||||
g_obj.solid_geometry = MultiPolygon(s_list)
|
||||
|
||||
def replot(self, obj, run_thread=True):
|
||||
def worker_task():
|
||||
with self.app.proc_container.new('%s...' % _("Plotting")):
|
||||
obj.plot()
|
||||
|
||||
if run_thread:
|
||||
self.app.worker_task.emit({'fcn': worker_task, 'params': []})
|
||||
else:
|
||||
worker_task()
|
||||
|
||||
def on_exit(self):
|
||||
# plot the object
|
||||
try:
|
||||
self.replot(obj=self.grb_object)
|
||||
except (AttributeError, TypeError):
|
||||
return
|
||||
|
||||
# update the bounding box values
|
||||
try:
|
||||
a, b, c, d = self.grb_object.bounds()
|
||||
self.grb_object.options['xmin'] = a
|
||||
self.grb_object.options['ymin'] = b
|
||||
self.grb_object.options['xmax'] = c
|
||||
self.grb_object.options['ymax'] = d
|
||||
except Exception as e:
|
||||
log.debug("ToolCorners.on_exit() copper_obj bounds error --> %s" % str(e))
|
||||
|
||||
# reset the variables
|
||||
self.grb_object = None
|
||||
|
||||
self.app.call_source = "app"
|
||||
self.app.inform.emit('[success] %s' % _("Corners Tool exit."))
|
||||
|
||||
|
||||
class CornersUI:
|
||||
|
||||
toolName = _("Corner Markers Tool")
|
||||
|
||||
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("""
|
||||
|
@ -49,7 +311,7 @@ class ToolCorners(AppTool):
|
|||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
self.layout.addWidget(QtWidgets.QLabel(''))
|
||||
self.layout.addWidget(QtWidgets.QLabel(""))
|
||||
|
||||
# Gerber object #
|
||||
self.object_label = QtWidgets.QLabel('<b>%s:</b>' % _("GERBER"))
|
||||
|
@ -192,250 +454,22 @@ class ToolCorners(AppTool):
|
|||
""")
|
||||
self.layout.addWidget(self.reset_button)
|
||||
|
||||
# Objects involved in Copper thieving
|
||||
self.grb_object = None
|
||||
# #################################### FINSIHED GUI ###########################
|
||||
# #############################################################################
|
||||
|
||||
# store the flattened geometry here:
|
||||
self.flat_geometry = []
|
||||
|
||||
# Tool properties
|
||||
self.fid_dia = None
|
||||
|
||||
self.grb_steps_per_circle = self.app.defaults["gerber_circle_steps"]
|
||||
|
||||
# SIGNALS
|
||||
self.add_marker_button.clicked.connect(self.add_markers)
|
||||
self.toggle_all_cb.toggled.connect(self.on_toggle_all)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.defaults.report_usage("ToolCorners()")
|
||||
|
||||
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])
|
||||
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:
|
||||
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)
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
||||
|
||||
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:
|
||||
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, _("Corners Tool"))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
AppTool.install(self, icon, separator, shortcut='Alt+M', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.units = self.app.defaults['units']
|
||||
self.thick_entry.set_value(self.app.defaults["tools_corners_thickness"])
|
||||
self.l_entry.set_value(float(self.app.defaults["tools_corners_length"]))
|
||||
self.margin_entry.set_value(float(self.app.defaults["tools_corners_margin"]))
|
||||
self.toggle_all_cb.set_value(False)
|
||||
|
||||
def on_toggle_all(self, val):
|
||||
self.bl_cb.set_value(val)
|
||||
self.br_cb.set_value(val)
|
||||
self.tl_cb.set_value(val)
|
||||
self.tr_cb.set_value(val)
|
||||
|
||||
def add_markers(self):
|
||||
self.app.call_source = "corners_tool"
|
||||
tl_state = self.tl_cb.get_value()
|
||||
tr_state = self.tr_cb.get_value()
|
||||
bl_state = self.bl_cb.get_value()
|
||||
br_state = self.br_cb.get_value()
|
||||
|
||||
# get the Gerber object on which the corner marker will be inserted
|
||||
selection_index = self.object_combo.currentIndex()
|
||||
model_index = self.app.collection.index(selection_index, 0, self.object_combo.rootModelIndex())
|
||||
|
||||
try:
|
||||
self.grb_object = model_index.internalPointer().obj
|
||||
except Exception as e:
|
||||
log.debug("ToolCorners.add_markers() --> %s" % str(e))
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no Gerber object loaded ..."))
|
||||
return
|
||||
|
||||
xmin, ymin, xmax, ymax = self.grb_object.bounds()
|
||||
points = {}
|
||||
if tl_state:
|
||||
points['tl'] = (xmin, ymax)
|
||||
if tr_state:
|
||||
points['tr'] = (xmax, ymax)
|
||||
if bl_state:
|
||||
points['bl'] = (xmin, ymin)
|
||||
if br_state:
|
||||
points['br'] = (xmax, ymin)
|
||||
|
||||
self.add_corners_geo(points, g_obj=self.grb_object)
|
||||
|
||||
self.grb_object.source_file = self.app.export_gerber(obj_name=self.grb_object.options['name'],
|
||||
filename=None,
|
||||
local_use=self.grb_object, use_thread=False)
|
||||
self.on_exit()
|
||||
|
||||
def add_corners_geo(self, points_storage, g_obj):
|
||||
"""
|
||||
Add geometry to the solid_geometry of the copper Gerber object
|
||||
|
||||
:param points_storage: a dictionary holding the points where to add corners
|
||||
:param g_obj: the Gerber object where to add the geometry
|
||||
:return: None
|
||||
"""
|
||||
|
||||
line_thickness = self.thick_entry.get_value()
|
||||
line_length = self.l_entry.get_value()
|
||||
margin = self.margin_entry.get_value()
|
||||
|
||||
geo_list = []
|
||||
|
||||
if not points_storage:
|
||||
self.app.inform.emit("[ERROR_NOTCL] %s." % _("Please select at least a location"))
|
||||
return
|
||||
|
||||
for key in points_storage:
|
||||
if key == 'tl':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] - margin - line_thickness / 2.0
|
||||
y = pt[1] + margin + line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x + line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y - line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
if key == 'tr':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] + margin + line_thickness / 2.0
|
||||
y = pt[1] + margin + line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x - line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y - line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
if key == 'bl':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] - margin - line_thickness / 2.0
|
||||
y = pt[1] - margin - line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x + line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y + line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
if key == 'br':
|
||||
pt = points_storage[key]
|
||||
x = pt[0] + margin + line_thickness / 2.0
|
||||
y = pt[1] - margin - line_thickness / 2.0
|
||||
line_geo_hor = LineString([
|
||||
(x, y), (x - line_length, y)
|
||||
])
|
||||
line_geo_vert = LineString([
|
||||
(x, y), (x, y + line_length)
|
||||
])
|
||||
geo_list.append(line_geo_hor)
|
||||
geo_list.append(line_geo_vert)
|
||||
|
||||
aperture_found = None
|
||||
for ap_id, ap_val in g_obj.apertures.items():
|
||||
if ap_val['type'] == 'C' and ap_val['size'] == line_thickness:
|
||||
aperture_found = ap_id
|
||||
break
|
||||
|
||||
geo_buff_list = []
|
||||
if aperture_found:
|
||||
for geo in geo_list:
|
||||
geo_buff = geo.buffer(line_thickness / 2.0, resolution=self.grb_steps_per_circle, join_style=2)
|
||||
geo_buff_list.append(geo_buff)
|
||||
|
||||
dict_el = {}
|
||||
dict_el['follow'] = geo
|
||||
dict_el['solid'] = geo_buff
|
||||
g_obj.apertures[aperture_found]['geometry'].append(deepcopy(dict_el))
|
||||
else:
|
||||
ap_keys = list(g_obj.apertures.keys())
|
||||
if ap_keys:
|
||||
new_apid = str(int(max(ap_keys)) + 1)
|
||||
else:
|
||||
new_apid = '10'
|
||||
|
||||
g_obj.apertures[new_apid] = {}
|
||||
g_obj.apertures[new_apid]['type'] = 'C'
|
||||
g_obj.apertures[new_apid]['size'] = line_thickness
|
||||
g_obj.apertures[new_apid]['geometry'] = []
|
||||
|
||||
for geo in geo_list:
|
||||
geo_buff = geo.buffer(line_thickness / 2.0, resolution=self.grb_steps_per_circle, join_style=3)
|
||||
geo_buff_list.append(geo_buff)
|
||||
|
||||
dict_el = {}
|
||||
dict_el['follow'] = geo
|
||||
dict_el['solid'] = geo_buff
|
||||
g_obj.apertures[new_apid]['geometry'].append(deepcopy(dict_el))
|
||||
|
||||
s_list = []
|
||||
if g_obj.solid_geometry:
|
||||
try:
|
||||
for poly in g_obj.solid_geometry:
|
||||
s_list.append(poly)
|
||||
except TypeError:
|
||||
s_list.append(g_obj.solid_geometry)
|
||||
|
||||
geo_buff_list = MultiPolygon(geo_buff_list)
|
||||
geo_buff_list = geo_buff_list.buffer(0)
|
||||
for poly in geo_buff_list:
|
||||
s_list.append(poly)
|
||||
g_obj.solid_geometry = MultiPolygon(s_list)
|
||||
|
||||
def replot(self, obj, run_thread=True):
|
||||
def worker_task():
|
||||
with self.app.proc_container.new('%s...' % _("Plotting")):
|
||||
obj.plot()
|
||||
|
||||
if run_thread:
|
||||
self.app.worker_task.emit({'fcn': worker_task, 'params': []})
|
||||
else:
|
||||
worker_task()
|
||||
|
||||
def on_exit(self):
|
||||
# plot the object
|
||||
try:
|
||||
self.replot(obj=self.grb_object)
|
||||
except (AttributeError, TypeError):
|
||||
return
|
||||
|
||||
# update the bounding box values
|
||||
try:
|
||||
a, b, c, d = self.grb_object.bounds()
|
||||
self.grb_object.options['xmin'] = a
|
||||
self.grb_object.options['ymin'] = b
|
||||
self.grb_object.options['xmax'] = c
|
||||
self.grb_object.options['ymax'] = d
|
||||
except Exception as e:
|
||||
log.debug("ToolCorners.on_exit() copper_obj bounds error --> %s" % str(e))
|
||||
|
||||
# reset the variables
|
||||
self.grb_object = None
|
||||
|
||||
self.app.call_source = "app"
|
||||
self.app.inform.emit('[success] %s' % _("Corners Tool exit."))
|
||||
self.app.inform[str, bool].emit('[success] %s' % _("Edited value is within limits."), False)
|
|
@ -509,7 +509,6 @@ class DsidedUI:
|
|||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
self.layout.addWidget(QtWidgets.QLabel(""))
|
||||
|
||||
# ## Grid Layout
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue