499
flatcamTools/ToolAlignObjects.py
Normal file
499
flatcamTools/ToolAlignObjects.py
Normal file
@@ -0,0 +1,499 @@
|
||||
# ##########################################################
|
||||
# FlatCAM: 2D Post-processing for Manufacturing #
|
||||
# File Author: Marius Adrian Stanciu (c) #
|
||||
# Date: 1/13/2020 #
|
||||
# MIT Licence #
|
||||
# ##########################################################
|
||||
|
||||
from PyQt5 import QtWidgets, QtGui, QtCore
|
||||
from FlatCAMTool import FlatCAMTool
|
||||
|
||||
from flatcamGUI.GUIElements import FCComboBox, RadioSet
|
||||
|
||||
import math
|
||||
|
||||
from shapely.geometry import Point
|
||||
from shapely.affinity import translate
|
||||
|
||||
import gettext
|
||||
import FlatCAMTranslation as fcTranslate
|
||||
import builtins
|
||||
import logging
|
||||
|
||||
fcTranslate.apply_language('strings')
|
||||
if '_' not in builtins.__dict__:
|
||||
_ = gettext.gettext
|
||||
|
||||
log = logging.getLogger('base')
|
||||
|
||||
|
||||
class AlignObjects(FlatCAMTool):
|
||||
|
||||
toolName = _("Align Objects")
|
||||
|
||||
def __init__(self, app):
|
||||
FlatCAMTool.__init__(self, app)
|
||||
|
||||
self.app = app
|
||||
self.decimals = app.decimals
|
||||
|
||||
self.canvas = self.app.plotcanvas
|
||||
|
||||
# ## Title
|
||||
title_label = QtWidgets.QLabel("%s" % self.toolName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
# Form Layout
|
||||
grid0 = QtWidgets.QGridLayout()
|
||||
grid0.setColumnStretch(0, 0)
|
||||
grid0.setColumnStretch(1, 1)
|
||||
self.layout.addLayout(grid0)
|
||||
|
||||
self.aligned_label = QtWidgets.QLabel('<b>%s</b>' % _("Selection of the WORKING object"))
|
||||
grid0.addWidget(self.aligned_label, 0, 0, 1, 2)
|
||||
|
||||
# Type of object to be aligned
|
||||
self.type_obj_combo = FCComboBox()
|
||||
self.type_obj_combo.addItem("Gerber")
|
||||
self.type_obj_combo.addItem("Excellon")
|
||||
|
||||
self.type_obj_combo.setItemIcon(0, QtGui.QIcon(self.app.resource_location + "/flatcam_icon16.png"))
|
||||
self.type_obj_combo.setItemIcon(1, QtGui.QIcon(self.app.resource_location + "/drill16.png"))
|
||||
|
||||
self.type_obj_combo_label = QtWidgets.QLabel('%s:' % _("Object Type"))
|
||||
self.type_obj_combo_label.setToolTip(
|
||||
_("Specify the type of object to be aligned.\n"
|
||||
"It can be of type: Gerber or Excellon.\n"
|
||||
"The selection here decide the type of objects that will be\n"
|
||||
"in the Object combobox.")
|
||||
)
|
||||
grid0.addWidget(self.type_obj_combo_label, 2, 0)
|
||||
grid0.addWidget(self.type_obj_combo, 2, 1)
|
||||
|
||||
# Object to be aligned
|
||||
self.object_combo = FCComboBox()
|
||||
self.object_combo.setModel(self.app.collection)
|
||||
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.object_combo.setCurrentIndex(1)
|
||||
|
||||
self.object_label = QtWidgets.QLabel('%s:' % _("Object"))
|
||||
self.object_label.setToolTip(
|
||||
_("Object to be aligned.")
|
||||
)
|
||||
|
||||
grid0.addWidget(self.object_label, 3, 0)
|
||||
grid0.addWidget(self.object_combo, 3, 1)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid0.addWidget(separator_line, 4, 0, 1, 2)
|
||||
|
||||
self.aligned_label = QtWidgets.QLabel('<b>%s</b>' % _("Selection of the TARGET object"))
|
||||
self.aligned_label.setToolTip(
|
||||
_("Object to which the other objects will be aligned to (moved to).")
|
||||
)
|
||||
grid0.addWidget(self.aligned_label, 6, 0, 1, 2)
|
||||
|
||||
# Type of object to be aligned to = aligner
|
||||
self.type_aligner_obj_combo = FCComboBox()
|
||||
self.type_aligner_obj_combo.addItem("Gerber")
|
||||
self.type_aligner_obj_combo.addItem("Excellon")
|
||||
|
||||
self.type_aligner_obj_combo.setItemIcon(0, QtGui.QIcon(self.app.resource_location + "/flatcam_icon16.png"))
|
||||
self.type_aligner_obj_combo.setItemIcon(1, QtGui.QIcon(self.app.resource_location + "/drill16.png"))
|
||||
|
||||
self.type_aligner_obj_combo_label = QtWidgets.QLabel('%s:' % _("Object Type"))
|
||||
self.type_aligner_obj_combo_label.setToolTip(
|
||||
_("Specify the type of object to be aligned to.\n"
|
||||
"It can be of type: Gerber or Excellon.\n"
|
||||
"The selection here decide the type of objects that will be\n"
|
||||
"in the Object combobox.")
|
||||
)
|
||||
grid0.addWidget(self.type_aligner_obj_combo_label, 7, 0)
|
||||
grid0.addWidget(self.type_aligner_obj_combo, 7, 1)
|
||||
|
||||
# Object to be aligned to = aligner
|
||||
self.aligner_object_combo = FCComboBox()
|
||||
self.aligner_object_combo.setModel(self.app.collection)
|
||||
self.aligner_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.aligner_object_combo.setCurrentIndex(1)
|
||||
|
||||
self.aligner_object_label = QtWidgets.QLabel('%s:' % _("Object"))
|
||||
self.aligner_object_label.setToolTip(
|
||||
_("Object to be aligned to. Aligner.")
|
||||
)
|
||||
|
||||
grid0.addWidget(self.aligner_object_label, 8, 0)
|
||||
grid0.addWidget(self.aligner_object_combo, 8, 1)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid0.addWidget(separator_line, 9, 0, 1, 2)
|
||||
|
||||
# Alignment Type
|
||||
self.a_type_lbl = QtWidgets.QLabel('<b>%s:</b>' % _("Alignment Type"))
|
||||
self.a_type_lbl.setToolTip(
|
||||
_("The type of alignment can be:\n"
|
||||
"- Single Point -> it require a single point of sync, the action will be a translation\n"
|
||||
"- Dual Point -> it require two points of sync, the action will be translation followed by rotation")
|
||||
)
|
||||
self.a_type_radio = RadioSet(
|
||||
[
|
||||
{'label': _('Single Point'), 'value': 'sp'},
|
||||
{'label': _('Dual Point'), 'value': 'dp'}
|
||||
],
|
||||
orientation='horizontal',
|
||||
stretch=False
|
||||
)
|
||||
|
||||
grid0.addWidget(self.a_type_lbl, 10, 0, 1, 2)
|
||||
grid0.addWidget(self.a_type_radio, 11, 0, 1, 2)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid0.addWidget(separator_line, 12, 0, 1, 2)
|
||||
|
||||
# Buttons
|
||||
self.align_object_button = QtWidgets.QPushButton(_("Align Object"))
|
||||
self.align_object_button.setToolTip(
|
||||
_("Align the specified object to the aligner object.\n"
|
||||
"If only one point is used then it assumes translation.\n"
|
||||
"If tho points are used it assume translation and rotation.")
|
||||
)
|
||||
self.align_object_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(self.align_object_button)
|
||||
|
||||
self.layout.addStretch()
|
||||
|
||||
# ## Reset Tool
|
||||
self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
|
||||
self.reset_button.setToolTip(
|
||||
_("Will reset the tool parameters.")
|
||||
)
|
||||
self.reset_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(self.reset_button)
|
||||
|
||||
# Signals
|
||||
self.align_object_button.clicked.connect(self.on_align)
|
||||
self.type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
|
||||
self.type_aligner_obj_combo.currentIndexChanged.connect(self.on_type_aligner_index_changed)
|
||||
self.reset_button.clicked.connect(self.set_tool_ui)
|
||||
|
||||
self.mr = None
|
||||
|
||||
# if the mouse events are connected to a local method set this True
|
||||
self.local_connected = False
|
||||
|
||||
# store the status of the grid
|
||||
self.grid_status_memory = None
|
||||
|
||||
self.aligned_obj = None
|
||||
self.aligner_obj = None
|
||||
|
||||
# this is one of the objects: self.aligned_obj or self.aligner_obj
|
||||
self.target_obj = None
|
||||
|
||||
# here store the alignment points
|
||||
self.clicked_points = list()
|
||||
|
||||
self.align_type = None
|
||||
|
||||
# old colors of objects involved in the alignment
|
||||
self.aligner_old_fill_color = None
|
||||
self.aligner_old_line_color = None
|
||||
self.aligned_old_fill_color = None
|
||||
self.aligned_old_line_color = None
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.report_usage("ToolAlignObjects()")
|
||||
|
||||
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])
|
||||
|
||||
FlatCAMTool.run(self)
|
||||
self.set_tool_ui()
|
||||
|
||||
self.app.ui.notebook.setTabText(2, _("Align Tool"))
|
||||
|
||||
def install(self, icon=None, separator=None, **kwargs):
|
||||
FlatCAMTool.install(self, icon, separator, shortcut='ALT+A', **kwargs)
|
||||
|
||||
def set_tool_ui(self):
|
||||
self.reset_fields()
|
||||
|
||||
self.clicked_points = list()
|
||||
self.target_obj = None
|
||||
self.aligned_obj = None
|
||||
self.aligner_obj = None
|
||||
|
||||
self.aligner_old_fill_color = None
|
||||
self.aligner_old_line_color = None
|
||||
self.aligned_old_fill_color = None
|
||||
self.aligned_old_line_color = None
|
||||
|
||||
self.a_type_radio.set_value(self.app.defaults["tools_align_objects_align_type"])
|
||||
|
||||
if self.local_connected is True:
|
||||
self.disconnect_cal_events()
|
||||
|
||||
def on_type_obj_index_changed(self):
|
||||
obj_type = self.type_obj_combo.currentIndex()
|
||||
self.object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
|
||||
self.object_combo.setCurrentIndex(0)
|
||||
|
||||
def on_type_aligner_index_changed(self):
|
||||
obj_type = self.type_aligner_obj_combo.currentIndex()
|
||||
self.aligner_object_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
|
||||
self.aligner_object_combo.setCurrentIndex(0)
|
||||
|
||||
def on_align(self):
|
||||
self.app.delete_selection_shape()
|
||||
|
||||
obj_sel_index = self.object_combo.currentIndex()
|
||||
obj_model_index = self.app.collection.index(obj_sel_index, 0, self.object_combo.rootModelIndex())
|
||||
try:
|
||||
self.aligned_obj = obj_model_index.internalPointer().obj
|
||||
except AttributeError:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no aligned FlatCAM object selected..."))
|
||||
return
|
||||
|
||||
aligner_obj_sel_index = self.aligner_object_combo.currentIndex()
|
||||
aligner_obj_model_index = self.app.collection.index(
|
||||
aligner_obj_sel_index, 0, self.aligner_object_combo.rootModelIndex())
|
||||
|
||||
try:
|
||||
self.aligner_obj = aligner_obj_model_index.internalPointer().obj
|
||||
except AttributeError:
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("There is no aligner FlatCAM object selected..."))
|
||||
return
|
||||
|
||||
self.align_type = self.a_type_radio.get_value()
|
||||
|
||||
# disengage the grid snapping since it will be hard to find the drills or pads on grid
|
||||
if self.app.ui.grid_snap_btn.isChecked():
|
||||
self.grid_status_memory = True
|
||||
self.app.ui.grid_snap_btn.trigger()
|
||||
else:
|
||||
self.grid_status_memory = False
|
||||
|
||||
self.mr = self.canvas.graph_event_connect('mouse_release', self.on_mouse_click_release)
|
||||
|
||||
if self.app.is_legacy is False:
|
||||
self.canvas.graph_event_disconnect('mouse_release', self.app.on_mouse_click_release_over_plot)
|
||||
else:
|
||||
self.canvas.graph_event_disconnect(self.app.mr)
|
||||
|
||||
self.local_connected = True
|
||||
|
||||
self.aligner_old_fill_color = self.aligner_obj.fill_color
|
||||
self.aligner_old_line_color = self.aligner_obj.outline_color
|
||||
self.aligned_old_fill_color = self.aligned_obj.fill_color
|
||||
self.aligned_old_line_color = self.aligned_obj.outline_color
|
||||
|
||||
self.app.inform.emit('%s: %s' % (_("First Point"), _("Click on the START point.")))
|
||||
self.target_obj = self.aligned_obj
|
||||
self.set_color()
|
||||
|
||||
def on_mouse_click_release(self, event):
|
||||
if self.app.is_legacy is False:
|
||||
event_pos = event.pos
|
||||
right_button = 2
|
||||
self.app.event_is_dragging = self.app.event_is_dragging
|
||||
else:
|
||||
event_pos = (event.xdata, event.ydata)
|
||||
right_button = 3
|
||||
self.app.event_is_dragging = self.app.ui.popMenu.mouse_is_panning
|
||||
|
||||
pos_canvas = self.canvas.translate_coords(event_pos)
|
||||
|
||||
if event.button == 1:
|
||||
click_pt = Point([pos_canvas[0], pos_canvas[1]])
|
||||
|
||||
if self.app.selection_type is not None:
|
||||
# delete previous selection shape
|
||||
self.app.delete_selection_shape()
|
||||
self.app.selection_type = None
|
||||
else:
|
||||
if self.target_obj.kind.lower() == 'excellon':
|
||||
for tool, tool_dict in self.target_obj.tools.items():
|
||||
for geo in tool_dict['solid_geometry']:
|
||||
if click_pt.within(geo):
|
||||
center_pt = geo.centroid
|
||||
self.clicked_points.append(
|
||||
[
|
||||
float('%.*f' % (self.decimals, center_pt.x)),
|
||||
float('%.*f' % (self.decimals, center_pt.y))
|
||||
]
|
||||
)
|
||||
self.check_points()
|
||||
elif self.target_obj.kind.lower() == 'gerber':
|
||||
for apid, apid_val in self.target_obj.apertures.items():
|
||||
for geo_el in apid_val['geometry']:
|
||||
if 'solid' in geo_el:
|
||||
if click_pt.within(geo_el['solid']):
|
||||
if isinstance(geo_el['follow'], Point):
|
||||
center_pt = geo_el['solid'].centroid
|
||||
self.clicked_points.append(
|
||||
[
|
||||
float('%.*f' % (self.decimals, center_pt.x)),
|
||||
float('%.*f' % (self.decimals, center_pt.y))
|
||||
]
|
||||
)
|
||||
self.check_points()
|
||||
|
||||
elif event.button == right_button and self.app.event_is_dragging is False:
|
||||
self.reset_color()
|
||||
self.clicked_points = list()
|
||||
self.disconnect_cal_events()
|
||||
self.app.inform.emit('[WARNING_NOTCL] %s' % _("Cancelled by user request."))
|
||||
|
||||
def check_points(self):
|
||||
if len(self.clicked_points) == 1:
|
||||
self.app.inform.emit('%s: %s. %s' % (
|
||||
_("First Point"), _("Click on the DESTINATION point."), _(" Or right click to cancel.")))
|
||||
self.target_obj = self.aligner_obj
|
||||
self.reset_color()
|
||||
self.set_color()
|
||||
|
||||
if len(self.clicked_points) == 2:
|
||||
if self.align_type == 'sp':
|
||||
self.align_translate()
|
||||
self.app.inform.emit('[success] %s' % _("Done."))
|
||||
self.app.plot_all()
|
||||
|
||||
self.disconnect_cal_events()
|
||||
return
|
||||
else:
|
||||
self.app.inform.emit('%s: %s. %s' % (
|
||||
_("Second Point"), _("Click on the START point."), _(" Or right click to cancel.")))
|
||||
self.target_obj = self.aligned_obj
|
||||
self.reset_color()
|
||||
self.set_color()
|
||||
|
||||
if len(self.clicked_points) == 3:
|
||||
self.app.inform.emit('%s: %s. %s' % (
|
||||
_("Second Point"), _("Click on the DESTINATION point."), _(" Or right click to cancel.")))
|
||||
self.target_obj = self.aligner_obj
|
||||
self.reset_color()
|
||||
self.set_color()
|
||||
|
||||
if len(self.clicked_points) == 4:
|
||||
self.align_translate()
|
||||
self.align_rotate()
|
||||
self.app.inform.emit('[success] %s' % _("Done."))
|
||||
|
||||
self.disconnect_cal_events()
|
||||
self.app.plot_all()
|
||||
|
||||
def align_translate(self):
|
||||
dx = self.clicked_points[1][0] - self.clicked_points[0][0]
|
||||
dy = self.clicked_points[1][1] - self.clicked_points[0][1]
|
||||
|
||||
self.aligned_obj.offset((dx, dy))
|
||||
|
||||
# Update the object bounding box options
|
||||
a, b, c, d = self.aligned_obj.bounds()
|
||||
self.aligned_obj.options['xmin'] = a
|
||||
self.aligned_obj.options['ymin'] = b
|
||||
self.aligned_obj.options['xmax'] = c
|
||||
self.aligned_obj.options['ymax'] = d
|
||||
|
||||
def align_rotate(self):
|
||||
dx = self.clicked_points[1][0] - self.clicked_points[0][0]
|
||||
dy = self.clicked_points[1][1] - self.clicked_points[0][1]
|
||||
|
||||
test_rotation_pt = translate(Point(self.clicked_points[2]), xoff=dx, yoff=dy)
|
||||
new_start = (test_rotation_pt.x, test_rotation_pt.y)
|
||||
new_dest = self.clicked_points[3]
|
||||
|
||||
origin_pt = self.clicked_points[1]
|
||||
|
||||
dxd = new_dest[0] - origin_pt[0]
|
||||
dyd = new_dest[1] - origin_pt[1]
|
||||
|
||||
dxs = new_start[0] - origin_pt[0]
|
||||
dys = new_start[1] - origin_pt[1]
|
||||
|
||||
rotation_not_needed = (abs(new_start[0] - new_dest[0]) <= (10 ** -self.decimals)) or \
|
||||
(abs(new_start[1] - new_dest[1]) <= (10 ** -self.decimals))
|
||||
if rotation_not_needed is False:
|
||||
# calculate rotation angle
|
||||
angle_dest = math.degrees(math.atan(dyd / dxd))
|
||||
angle_start = math.degrees(math.atan(dys / dxs))
|
||||
angle = angle_dest - angle_start
|
||||
self.aligned_obj.rotate(angle=angle, point=origin_pt)
|
||||
|
||||
def disconnect_cal_events(self):
|
||||
# restore the Grid snapping if it was active before
|
||||
if self.grid_status_memory is True:
|
||||
self.app.ui.grid_snap_btn.trigger()
|
||||
|
||||
self.app.mr = self.canvas.graph_event_connect('mouse_release', self.app.on_mouse_click_release_over_plot)
|
||||
|
||||
if self.app.is_legacy is False:
|
||||
self.canvas.graph_event_disconnect('mouse_release', self.on_mouse_click_release)
|
||||
else:
|
||||
self.canvas.graph_event_disconnect(self.mr)
|
||||
|
||||
self.local_connected = False
|
||||
|
||||
self.aligner_old_fill_color = None
|
||||
self.aligner_old_line_color = None
|
||||
self.aligned_old_fill_color = None
|
||||
self.aligned_old_line_color = None
|
||||
|
||||
def set_color(self):
|
||||
new_color = "#15678abf"
|
||||
new_line_color = new_color
|
||||
self.target_obj.shapes.redraw(
|
||||
update_colors=(new_color, new_line_color)
|
||||
)
|
||||
|
||||
def reset_color(self):
|
||||
self.aligned_obj.shapes.redraw(
|
||||
update_colors=(self.aligned_old_fill_color, self.aligned_old_line_color)
|
||||
)
|
||||
|
||||
self.aligner_obj.shapes.redraw(
|
||||
update_colors=(self.aligner_old_fill_color, self.aligner_old_line_color)
|
||||
)
|
||||
|
||||
def reset_fields(self):
|
||||
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.aligner_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
@@ -533,16 +533,17 @@ class DblSidedTool(FlatCAMTool):
|
||||
"Add them and retry."))
|
||||
return
|
||||
|
||||
drills = []
|
||||
drills = list()
|
||||
|
||||
for hole in holes:
|
||||
point = Point(hole)
|
||||
point_mirror = affinity.scale(point, xscale, yscale, origin=(px, py))
|
||||
drills.append({"point": point, "tool": "1"})
|
||||
drills.append({"point": point_mirror, "tool": "1"})
|
||||
if 'solid_geometry' not in tools:
|
||||
tools["1"]['solid_geometry'] = []
|
||||
if 'solid_geometry' not in tools["1"]:
|
||||
tools["1"]['solid_geometry'] = list()
|
||||
else:
|
||||
tools["1"]['solid_geometry'].append(point)
|
||||
tools["1"]['solid_geometry'].append(point_mirror)
|
||||
|
||||
def obj_init(obj_inst, app_inst):
|
||||
|
||||
@@ -361,11 +361,12 @@ class Distance(FlatCAMTool):
|
||||
self.distance_x_entry.set_value('%.*f' % (self.decimals, abs(dx)))
|
||||
self.distance_y_entry.set_value('%.*f' % (self.decimals, abs(dy)))
|
||||
|
||||
try:
|
||||
angle = math.degrees(math.atan(dy / dx))
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception as e:
|
||||
pass
|
||||
if dx != 0.0:
|
||||
try:
|
||||
angle = math.degrees(math.atan(dy / dx))
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
self.total_distance_entry.set_value('%.*f' % (self.decimals, abs(d)))
|
||||
self.app.ui.rel_position_label.setText(
|
||||
@@ -424,11 +425,13 @@ class Distance(FlatCAMTool):
|
||||
if len(self.points) == 1:
|
||||
self.utility_geometry(pos=pos)
|
||||
# and display the temporary angle
|
||||
try:
|
||||
angle = math.degrees(math.atan(dy / dx))
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception as e:
|
||||
pass
|
||||
if dx != 0.0:
|
||||
try:
|
||||
angle = math.degrees(math.atan(dy / dx))
|
||||
self.angle_entry.set_value('%.*f' % (self.decimals, angle))
|
||||
except Exception as e:
|
||||
log.debug("Distance.on_mouse_move_meas() -> update utility geometry -> %s" % str(e))
|
||||
pass
|
||||
|
||||
except Exception as e:
|
||||
log.debug("Distance.on_mouse_move_meas() --> %s" % str(e))
|
||||
|
||||
697
flatcamTools/ToolExtractDrills.py
Normal file
697
flatcamTools/ToolExtractDrills.py
Normal file
@@ -0,0 +1,697 @@
|
||||
# ##########################################################
|
||||
# FlatCAM: 2D Post-processing for Manufacturing #
|
||||
# File Author: Marius Adrian Stanciu (c) #
|
||||
# Date: 1/10/2020 #
|
||||
# MIT Licence #
|
||||
# ##########################################################
|
||||
|
||||
from PyQt5 import QtWidgets, QtCore
|
||||
|
||||
from FlatCAMTool import FlatCAMTool
|
||||
from flatcamGUI.GUIElements import RadioSet, FCDoubleSpinner, FCCheckBox
|
||||
|
||||
from shapely.geometry import Point
|
||||
|
||||
import logging
|
||||
import gettext
|
||||
import FlatCAMTranslation as fcTranslate
|
||||
import builtins
|
||||
|
||||
fcTranslate.apply_language('strings')
|
||||
if '_' not in builtins.__dict__:
|
||||
_ = gettext.gettext
|
||||
|
||||
log = logging.getLogger('base')
|
||||
|
||||
|
||||
class ToolExtractDrills(FlatCAMTool):
|
||||
|
||||
toolName = _("Extract Drills")
|
||||
|
||||
def __init__(self, app):
|
||||
FlatCAMTool.__init__(self, app)
|
||||
self.decimals = self.app.decimals
|
||||
|
||||
# ## Title
|
||||
title_label = QtWidgets.QLabel("%s" % self.toolName)
|
||||
title_label.setStyleSheet("""
|
||||
QLabel
|
||||
{
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(title_label)
|
||||
|
||||
self.empty_lb = QtWidgets.QLabel("")
|
||||
self.layout.addWidget(self.empty_lb)
|
||||
|
||||
# ## Grid Layout
|
||||
grid_lay = QtWidgets.QGridLayout()
|
||||
self.layout.addLayout(grid_lay)
|
||||
grid_lay.setColumnStretch(0, 1)
|
||||
grid_lay.setColumnStretch(1, 0)
|
||||
|
||||
# ## Gerber Object
|
||||
self.gerber_object_combo = QtWidgets.QComboBox()
|
||||
self.gerber_object_combo.setModel(self.app.collection)
|
||||
self.gerber_object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
||||
self.gerber_object_combo.setCurrentIndex(1)
|
||||
|
||||
self.grb_label = QtWidgets.QLabel("<b>%s:</b>" % _("GERBER"))
|
||||
self.grb_label.setToolTip('%s.' % _("Gerber from which to extract drill holes"))
|
||||
|
||||
# grid_lay.addRow("Bottom Layer:", self.object_combo)
|
||||
grid_lay.addWidget(self.grb_label, 0, 0, 1, 2)
|
||||
grid_lay.addWidget(self.gerber_object_combo, 1, 0, 1, 2)
|
||||
|
||||
self.padt_label = QtWidgets.QLabel("<b>%s</b>" % _("Processed Pads Type"))
|
||||
self.padt_label.setToolTip(
|
||||
_("The type of pads shape to be processed.\n"
|
||||
"If the PCB has many SMD pads with rectangular pads,\n"
|
||||
"disable the Rectangular aperture.")
|
||||
)
|
||||
|
||||
grid_lay.addWidget(self.padt_label, 2, 0, 1, 2)
|
||||
|
||||
# Circular Aperture Selection
|
||||
self.circular_cb = FCCheckBox('%s' % _("Circular"))
|
||||
self.circular_cb.setToolTip(
|
||||
_("Create drills from circular pads.")
|
||||
)
|
||||
|
||||
grid_lay.addWidget(self.circular_cb, 3, 0, 1, 2)
|
||||
|
||||
# Oblong Aperture Selection
|
||||
self.oblong_cb = FCCheckBox('%s' % _("Oblong"))
|
||||
self.oblong_cb.setToolTip(
|
||||
_("Create drills from oblong pads.")
|
||||
)
|
||||
|
||||
grid_lay.addWidget(self.oblong_cb, 4, 0, 1, 2)
|
||||
|
||||
# Square Aperture Selection
|
||||
self.square_cb = FCCheckBox('%s' % _("Square"))
|
||||
self.square_cb.setToolTip(
|
||||
_("Create drills from square pads.")
|
||||
)
|
||||
|
||||
grid_lay.addWidget(self.square_cb, 5, 0, 1, 2)
|
||||
|
||||
# Rectangular Aperture Selection
|
||||
self.rectangular_cb = FCCheckBox('%s' % _("Rectangular"))
|
||||
self.rectangular_cb.setToolTip(
|
||||
_("Create drills from rectangular pads.")
|
||||
)
|
||||
|
||||
grid_lay.addWidget(self.rectangular_cb, 6, 0, 1, 2)
|
||||
|
||||
# Others type of Apertures Selection
|
||||
self.other_cb = FCCheckBox('%s' % _("Others"))
|
||||
self.other_cb.setToolTip(
|
||||
_("Create drills from other types of pad shape.")
|
||||
)
|
||||
|
||||
grid_lay.addWidget(self.other_cb, 7, 0, 1, 2)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid_lay.addWidget(separator_line, 8, 0, 1, 2)
|
||||
|
||||
# ## Grid Layout
|
||||
grid1 = QtWidgets.QGridLayout()
|
||||
self.layout.addLayout(grid1)
|
||||
grid1.setColumnStretch(0, 0)
|
||||
grid1.setColumnStretch(1, 1)
|
||||
|
||||
self.method_label = QtWidgets.QLabel('<b>%s</b>' % _("Method"))
|
||||
grid1.addWidget(self.method_label, 2, 0, 1, 2)
|
||||
|
||||
# ## Axis
|
||||
self.hole_size_radio = RadioSet(
|
||||
[
|
||||
{'label': _("Fixed Diameter"), 'value': 'fixed'},
|
||||
{'label': _("Fixed Annular Ring"), 'value': 'ring'},
|
||||
{'label': _("Proportional"), 'value': 'prop'}
|
||||
],
|
||||
orientation='vertical',
|
||||
stretch=False)
|
||||
|
||||
self.hole_size_label = QtWidgets.QLabel('%s:' % _("Hole Size"))
|
||||
self.hole_size_label.setToolTip(
|
||||
_("The selected method of extracting the drills. Can be:\n"
|
||||
"- Fixed Diameter -> all holes will have a set size\n"
|
||||
"- Fixed Annular Ring -> all holes will have a set annular ring\n"
|
||||
"- Proportional -> each hole size will be a fraction of the pad size"))
|
||||
|
||||
grid1.addWidget(self.hole_size_label, 3, 0)
|
||||
grid1.addWidget(self.hole_size_radio, 3, 1)
|
||||
|
||||
# grid_lay1.addWidget(QtWidgets.QLabel(''))
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid1.addWidget(separator_line, 5, 0, 1, 2)
|
||||
|
||||
# Annular Ring
|
||||
self.fixed_label = QtWidgets.QLabel('<b>%s</b>' % _("Fixed Diameter"))
|
||||
grid1.addWidget(self.fixed_label, 6, 0, 1, 2)
|
||||
|
||||
# Diameter value
|
||||
self.dia_entry = FCDoubleSpinner()
|
||||
self.dia_entry.set_precision(self.decimals)
|
||||
self.dia_entry.set_range(0.0000, 9999.9999)
|
||||
|
||||
self.dia_label = QtWidgets.QLabel('%s:' % _("Value"))
|
||||
self.dia_label.setToolTip(
|
||||
_("Fixed hole diameter.")
|
||||
)
|
||||
|
||||
grid1.addWidget(self.dia_label, 8, 0)
|
||||
grid1.addWidget(self.dia_entry, 8, 1)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid1.addWidget(separator_line, 9, 0, 1, 2)
|
||||
|
||||
self.ring_frame = QtWidgets.QFrame()
|
||||
self.ring_frame.setContentsMargins(0, 0, 0, 0)
|
||||
self.layout.addWidget(self.ring_frame)
|
||||
|
||||
self.ring_box = QtWidgets.QVBoxLayout()
|
||||
self.ring_box.setContentsMargins(0, 0, 0, 0)
|
||||
self.ring_frame.setLayout(self.ring_box)
|
||||
|
||||
# ## Grid Layout
|
||||
grid2 = QtWidgets.QGridLayout()
|
||||
grid2.setColumnStretch(0, 0)
|
||||
grid2.setColumnStretch(1, 1)
|
||||
self.ring_box.addLayout(grid2)
|
||||
|
||||
# Annular Ring value
|
||||
self.ring_label = QtWidgets.QLabel('<b>%s</b>' % _("Fixed Annular Ring"))
|
||||
self.ring_label.setToolTip(
|
||||
_("The size of annular ring.\n"
|
||||
"The copper sliver between the drill hole exterior\n"
|
||||
"and the margin of the copper pad.")
|
||||
)
|
||||
grid2.addWidget(self.ring_label, 0, 0, 1, 2)
|
||||
|
||||
# Circular Annular Ring Value
|
||||
self.circular_ring_label = QtWidgets.QLabel('%s:' % _("Circular"))
|
||||
self.circular_ring_label.setToolTip(
|
||||
_("The size of annular ring for circular pads.")
|
||||
)
|
||||
|
||||
self.circular_ring_entry = FCDoubleSpinner()
|
||||
self.circular_ring_entry.set_precision(self.decimals)
|
||||
self.circular_ring_entry.set_range(0.0000, 9999.9999)
|
||||
|
||||
grid2.addWidget(self.circular_ring_label, 1, 0)
|
||||
grid2.addWidget(self.circular_ring_entry, 1, 1)
|
||||
|
||||
# Oblong Annular Ring Value
|
||||
self.oblong_ring_label = QtWidgets.QLabel('%s:' % _("Oblong"))
|
||||
self.oblong_ring_label.setToolTip(
|
||||
_("The size of annular ring for oblong pads.")
|
||||
)
|
||||
|
||||
self.oblong_ring_entry = FCDoubleSpinner()
|
||||
self.oblong_ring_entry.set_precision(self.decimals)
|
||||
self.oblong_ring_entry.set_range(0.0000, 9999.9999)
|
||||
|
||||
grid2.addWidget(self.oblong_ring_label, 2, 0)
|
||||
grid2.addWidget(self.oblong_ring_entry, 2, 1)
|
||||
|
||||
# Square Annular Ring Value
|
||||
self.square_ring_label = QtWidgets.QLabel('%s:' % _("Square"))
|
||||
self.square_ring_label.setToolTip(
|
||||
_("The size of annular ring for square pads.")
|
||||
)
|
||||
|
||||
self.square_ring_entry = FCDoubleSpinner()
|
||||
self.square_ring_entry.set_precision(self.decimals)
|
||||
self.square_ring_entry.set_range(0.0000, 9999.9999)
|
||||
|
||||
grid2.addWidget(self.square_ring_label, 3, 0)
|
||||
grid2.addWidget(self.square_ring_entry, 3, 1)
|
||||
|
||||
# Rectangular Annular Ring Value
|
||||
self.rectangular_ring_label = QtWidgets.QLabel('%s:' % _("Rectangular"))
|
||||
self.rectangular_ring_label.setToolTip(
|
||||
_("The size of annular ring for rectangular pads.")
|
||||
)
|
||||
|
||||
self.rectangular_ring_entry = FCDoubleSpinner()
|
||||
self.rectangular_ring_entry.set_precision(self.decimals)
|
||||
self.rectangular_ring_entry.set_range(0.0000, 9999.9999)
|
||||
|
||||
grid2.addWidget(self.rectangular_ring_label, 4, 0)
|
||||
grid2.addWidget(self.rectangular_ring_entry, 4, 1)
|
||||
|
||||
# Others Annular Ring Value
|
||||
self.other_ring_label = QtWidgets.QLabel('%s:' % _("Others"))
|
||||
self.other_ring_label.setToolTip(
|
||||
_("The size of annular ring for other pads.")
|
||||
)
|
||||
|
||||
self.other_ring_entry = FCDoubleSpinner()
|
||||
self.other_ring_entry.set_precision(self.decimals)
|
||||
self.other_ring_entry.set_range(0.0000, 9999.9999)
|
||||
|
||||
grid2.addWidget(self.other_ring_label, 5, 0)
|
||||
grid2.addWidget(self.other_ring_entry, 5, 1)
|
||||
|
||||
grid3 = QtWidgets.QGridLayout()
|
||||
self.layout.addLayout(grid3)
|
||||
grid3.setColumnStretch(0, 0)
|
||||
grid3.setColumnStretch(1, 1)
|
||||
|
||||
separator_line = QtWidgets.QFrame()
|
||||
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
||||
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
||||
grid3.addWidget(separator_line, 1, 0, 1, 2)
|
||||
|
||||
# Annular Ring value
|
||||
self.prop_label = QtWidgets.QLabel('<b>%s</b>' % _("Proportional Diameter"))
|
||||
grid3.addWidget(self.prop_label, 2, 0, 1, 2)
|
||||
|
||||
# Diameter value
|
||||
self.factor_entry = FCDoubleSpinner(suffix='%')
|
||||
self.factor_entry.set_precision(self.decimals)
|
||||
self.factor_entry.set_range(0.0000, 100.0000)
|
||||
self.factor_entry.setSingleStep(0.1)
|
||||
|
||||
self.factor_label = QtWidgets.QLabel('%s:' % _("Value"))
|
||||
self.factor_label.setToolTip(
|
||||
_("Proportional Diameter.\n"
|
||||
"The drill diameter will be a fraction of the pad size.")
|
||||
)
|
||||
|
||||
grid3.addWidget(self.factor_label, 3, 0)
|
||||
grid3.addWidget(self.factor_entry, 3, 1)
|
||||
|
||||
# Extract drills from Gerber apertures flashes (pads)
|
||||
self.e_drills_button = QtWidgets.QPushButton(_("Extract Drills"))
|
||||
self.e_drills_button.setToolTip(
|
||||
_("Extract drills from a given Gerber file.")
|
||||
)
|
||||
self.e_drills_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(self.e_drills_button)
|
||||
|
||||
self.layout.addStretch()
|
||||
|
||||
# ## Reset Tool
|
||||
self.reset_button = QtWidgets.QPushButton(_("Reset Tool"))
|
||||
self.reset_button.setToolTip(
|
||||
_("Will reset the tool parameters.")
|
||||
)
|
||||
self.reset_button.setStyleSheet("""
|
||||
QPushButton
|
||||
{
|
||||
font-weight: bold;
|
||||
}
|
||||
""")
|
||||
self.layout.addWidget(self.reset_button)
|
||||
|
||||
self.circular_ring_entry.setEnabled(False)
|
||||
self.oblong_ring_entry.setEnabled(False)
|
||||
self.square_ring_entry.setEnabled(False)
|
||||
self.rectangular_ring_entry.setEnabled(False)
|
||||
self.other_ring_entry.setEnabled(False)
|
||||
|
||||
self.dia_entry.setDisabled(True)
|
||||
self.dia_label.setDisabled(True)
|
||||
self.factor_label.setDisabled(True)
|
||||
self.factor_entry.setDisabled(True)
|
||||
|
||||
self.ring_frame.setDisabled(True)
|
||||
|
||||
# ## 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):
|
||||
FlatCAMTool.install(self, icon, separator, shortcut='ALT+I', **kwargs)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.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])
|
||||
|
||||
FlatCAMTool.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 = list()
|
||||
tools = dict()
|
||||
|
||||
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": {"C": drill_dia}}
|
||||
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):
|
||||
drills.append({"point": geo_el['follow'], "tool": "1"})
|
||||
if 'solid_geometry' not in tools["1"]:
|
||||
tools["1"]['solid_geometry'] = list()
|
||||
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["C"])) - 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 = str(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] = {"C": dia}
|
||||
|
||||
drills.append({"point": geo_el['follow'], "tool": tool_in_drills})
|
||||
|
||||
if 'solid_geometry' not in tools[tool_in_drills]:
|
||||
tools[tool_in_drills]['solid_geometry'] = list()
|
||||
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.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["C"])) - 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 = str(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] = {"C": dia}
|
||||
|
||||
drills.append({"point": geo_el['follow'], "tool": tool_in_drills})
|
||||
|
||||
if 'solid_geometry' not in tools[tool_in_drills]:
|
||||
tools[tool_in_drills]['solid_geometry'] = list()
|
||||
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.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)
|
||||
@@ -752,7 +752,7 @@ class Film(FlatCAMTool):
|
||||
skew_factor_x=skew_factor_x, skew_factor_y=skew_factor_y,
|
||||
skew_reference=skew_reference,
|
||||
mirror=mirror,
|
||||
pagesize=pagesize, orientation=orientation, color=color, opacity=1.0,
|
||||
pagesize_val=pagesize, orientation_val=orientation, color_val=color, opacity_val=1.0,
|
||||
ftype=ftype
|
||||
)
|
||||
|
||||
@@ -1080,23 +1080,28 @@ class Film(FlatCAMTool):
|
||||
skew_factor_x=None, skew_factor_y=None, skew_reference='center',
|
||||
mirror=None, orientation_val='p', pagesize_val='A4', color_val='black', opacity_val=1.0,
|
||||
use_thread=True, ftype='svg'):
|
||||
|
||||
"""
|
||||
Exports a Geometry Object to an SVG file in positive black.
|
||||
|
||||
:param obj_name: the name of the FlatCAM object to be saved as SVG
|
||||
:param box_name: the name of the FlatCAM object to be used as delimitation of the content to be saved
|
||||
:param filename: Path to the SVG file to save to.
|
||||
:param obj_name: the name of the FlatCAM object to be saved
|
||||
:param box_name: the name of the FlatCAM object to be used as delimitation of the content to be saved
|
||||
:param filename: Path to the file to save to.
|
||||
:param scale_stroke_factor: factor by which to change/scale the thickness of the features
|
||||
:param scale_factor_x: factor to scale the svg geometry on the X axis
|
||||
:param scale_factor_y: factor to scale the svg geometry on the Y axis
|
||||
:param skew_factor_x: factor to skew the svg geometry on the X axis
|
||||
:param skew_factor_y: factor to skew the svg geometry on the Y axis
|
||||
:param skew_reference: reference to use for skew. Can be 'bottomleft', 'bottomright', 'topleft', 'topright' and
|
||||
those are the 4 points of the bounding box of the geometry to be skewed.
|
||||
:param mirror: can be 'x' or 'y' or 'both'. Axis on which to mirror the svg geometry
|
||||
:param scale_factor_x: factor to scale the geometry on the X axis
|
||||
:param scale_factor_y: factor to scale the geometry on the Y axis
|
||||
:param skew_factor_x: factor to skew the geometry on the X axis
|
||||
:param skew_factor_y: factor to skew the geometry on the Y axis
|
||||
:param skew_reference: reference to use for skew. Can be 'bottomleft', 'bottomright', 'topleft',
|
||||
'topright' and those are the 4 points of the bounding box of the geometry to be skewed.
|
||||
:param mirror: can be 'x' or 'y' or 'both'. Axis on which to mirror the svg geometry
|
||||
:param orientation_val:
|
||||
:param pagesize_val:
|
||||
:param color_val:
|
||||
:param opacity_val:
|
||||
:param use_thread: if to be run in a separate thread; boolean
|
||||
:param ftype: the type of file for saving the film: 'svg', 'png' or 'pdf'
|
||||
|
||||
:param use_thread: if to be run in a separate thread; boolean
|
||||
:param ftype: the type of file for saving the film: 'svg', 'png' or 'pdf'
|
||||
:return:
|
||||
"""
|
||||
self.app.report_usage("export_positive()")
|
||||
|
||||
@@ -651,7 +651,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# ############################ SGINALS ########################################
|
||||
# ############################ SIGNALS ########################################
|
||||
# #############################################################################
|
||||
self.addtool_btn.clicked.connect(self.on_tool_add)
|
||||
self.addtool_entry.returnPressed.connect(self.on_tool_add)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import sys
|
||||
|
||||
|
||||
from flatcamTools.ToolCalculators import ToolCalculator
|
||||
from flatcamTools.ToolCalibration import ToolCalibration
|
||||
from flatcamTools.ToolCutOut import CutOut
|
||||
|
||||
from flatcamTools.ToolDblSided import DblSidedTool
|
||||
from flatcamTools.ToolExtractDrills import ToolExtractDrills
|
||||
from flatcamTools.ToolAlignObjects import AlignObjects
|
||||
|
||||
from flatcamTools.ToolFilm import Film
|
||||
|
||||
@@ -17,10 +18,10 @@ from flatcamTools.ToolDistanceMin import DistanceMin
|
||||
from flatcamTools.ToolMove import ToolMove
|
||||
|
||||
from flatcamTools.ToolNonCopperClear import NonCopperClear
|
||||
from flatcamTools.ToolPaint import ToolPaint
|
||||
|
||||
from flatcamTools.ToolOptimal import ToolOptimal
|
||||
|
||||
from flatcamTools.ToolPaint import ToolPaint
|
||||
from flatcamTools.ToolPanelize import Panelize
|
||||
from flatcamTools.ToolPcbWizard import PcbWizard
|
||||
from flatcamTools.ToolPDF import ToolPDF
|
||||
|
||||
Reference in New Issue
Block a user