2019-10-13 15:13:39 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# File Author: Marius Adrian Stanciu (c) #
|
|
|
|
# Date: 3/10/2019 #
|
|
|
|
# MIT Licence #
|
2019-10-13 15:13:39 +00:00
|
|
|
# ##########################################################
|
2019-03-10 13:22:16 +00:00
|
|
|
|
2019-10-15 23:28:18 +00:00
|
|
|
from PyQt5 import QtWidgets, QtGui, QtCore
|
2020-05-18 16:09:37 +00:00
|
|
|
from AppTool import AppTool
|
2019-10-15 23:28:18 +00:00
|
|
|
|
2020-05-18 13:02:41 +00:00
|
|
|
from AppGUI.GUIElements import FCSpinner, FCDoubleSpinner, RadioSet, FCCheckBox, OptionalInputSection, FCComboBox
|
2020-05-18 16:09:37 +00:00
|
|
|
from camlib import grace
|
|
|
|
|
2019-10-15 23:28:18 +00:00
|
|
|
from copy import deepcopy
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
import shapely.affinity as affinity
|
2020-05-02 12:56:30 +00:00
|
|
|
from shapely.ops import unary_union
|
|
|
|
from shapely.geometry import LineString
|
2019-03-07 16:04:11 +00:00
|
|
|
|
2019-03-07 23:32:18 +00:00
|
|
|
import gettext
|
2020-05-18 13:02:41 +00:00
|
|
|
import AppTranslation as fcTranslate
|
2019-05-06 23:08:17 +00:00
|
|
|
import builtins
|
2019-10-15 23:28:18 +00:00
|
|
|
import logging
|
2019-03-10 15:12:58 +00:00
|
|
|
|
2019-03-13 23:09:06 +00:00
|
|
|
fcTranslate.apply_language('strings')
|
2019-03-10 15:12:58 +00:00
|
|
|
if '_' not in builtins.__dict__:
|
|
|
|
_ = gettext.gettext
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-10-15 23:28:18 +00:00
|
|
|
log = logging.getLogger('base')
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-05-18 13:11:02 +00:00
|
|
|
class Panelize(AppTool):
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-03-10 12:34:13 +00:00
|
|
|
toolName = _("Panelize PCB")
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def __init__(self, app):
|
2019-12-05 13:18:54 +00:00
|
|
|
self.decimals = app.decimals
|
|
|
|
|
2020-05-18 13:11:02 +00:00
|
|
|
AppTool.__init__(self, app)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-30 18:05:12 +00:00
|
|
|
# ## Title
|
2019-02-18 01:45:34 +00:00
|
|
|
title_label = QtWidgets.QLabel("%s" % self.toolName)
|
|
|
|
title_label.setStyleSheet("""
|
|
|
|
QLabel
|
|
|
|
{
|
|
|
|
font-size: 16px;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
""")
|
2019-01-03 19:25:08 +00:00
|
|
|
self.layout.addWidget(title_label)
|
|
|
|
|
2020-01-30 03:14:05 +00:00
|
|
|
self.object_label = QtWidgets.QLabel('<b>%s:</b>' % _("Source Object"))
|
|
|
|
self.object_label.setToolTip(
|
|
|
|
_("Specify the type of object to be panelized\n"
|
|
|
|
"It can be of type: Gerber, Excellon or Geometry.\n"
|
|
|
|
"The selection here decide the type of objects that will be\n"
|
|
|
|
"in the Object combobox.")
|
|
|
|
)
|
|
|
|
|
|
|
|
self.layout.addWidget(self.object_label)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Form Layout
|
2019-05-07 10:55:20 +00:00
|
|
|
form_layout_0 = QtWidgets.QFormLayout()
|
|
|
|
self.layout.addLayout(form_layout_0)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Type of object to be panelized
|
2020-03-02 04:17:18 +00:00
|
|
|
self.type_obj_combo = FCComboBox()
|
2019-01-03 19:25:08 +00:00
|
|
|
self.type_obj_combo.addItem("Gerber")
|
|
|
|
self.type_obj_combo.addItem("Excellon")
|
|
|
|
self.type_obj_combo.addItem("Geometry")
|
|
|
|
|
2019-12-15 14:28:36 +00:00
|
|
|
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.setItemIcon(2, QtGui.QIcon(self.app.resource_location + "/geometry16.png"))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-01-30 03:14:05 +00:00
|
|
|
self.type_object_label = QtWidgets.QLabel('%s:' % _("Object Type"))
|
|
|
|
|
|
|
|
form_layout_0.addRow(self.type_object_label, self.type_obj_combo)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Object to be panelized
|
2020-03-02 04:17:18 +00:00
|
|
|
self.object_combo = FCComboBox()
|
2019-01-03 19:25:08 +00:00
|
|
|
self.object_combo.setModel(self.app.collection)
|
|
|
|
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
2020-03-03 22:27:51 +00:00
|
|
|
self.object_combo.is_last = True
|
2019-02-04 18:49:37 +00:00
|
|
|
|
2020-01-30 03:14:05 +00:00
|
|
|
self.object_combo.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Object to be panelized. This means that it will\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"be duplicated in an array of rows and columns.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
2020-01-30 03:14:05 +00:00
|
|
|
form_layout_0.addRow(self.object_combo)
|
2019-05-07 10:55:20 +00:00
|
|
|
|
|
|
|
# Form Layout
|
|
|
|
form_layout = QtWidgets.QFormLayout()
|
|
|
|
self.layout.addLayout(form_layout)
|
|
|
|
|
|
|
|
# Type of box Panel object
|
2019-07-17 11:11:10 +00:00
|
|
|
self.reference_radio = RadioSet([{'label': _('Object'), 'value': 'object'},
|
|
|
|
{'label': _('Bounding Box'), 'value': 'bbox'}])
|
2019-08-18 11:17:46 +00:00
|
|
|
self.box_label = QtWidgets.QLabel("<b>%s:</b>" % _("Penelization Reference"))
|
2019-05-07 10:55:20 +00:00
|
|
|
self.box_label.setToolTip(
|
|
|
|
_("Choose the reference for panelization:\n"
|
|
|
|
"- Object = the bounding box of a different object\n"
|
|
|
|
"- Bounding Box = the bounding box of the object to be panelized\n"
|
|
|
|
"\n"
|
|
|
|
"The reference is useful when doing panelization for more than one\n"
|
|
|
|
"object. The spacings (really offsets) will be applied in reference\n"
|
|
|
|
"to this reference object therefore maintaining the panelized\n"
|
|
|
|
"objects in sync.")
|
|
|
|
)
|
|
|
|
form_layout.addRow(self.box_label)
|
|
|
|
form_layout.addRow(self.reference_radio)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Type of Box Object to be used as an envelope for panelization
|
2020-03-02 04:17:18 +00:00
|
|
|
self.type_box_combo = FCComboBox()
|
2020-03-03 22:27:51 +00:00
|
|
|
self.type_box_combo.addItems([_("Gerber"), _("Geometry")])
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
# we get rid of item1 ("Excellon") as it is not suitable for use as a "box" for panelizing
|
2020-03-02 04:17:18 +00:00
|
|
|
# self.type_box_combo.view().setRowHidden(1, True)
|
2019-12-15 14:28:36 +00:00
|
|
|
self.type_box_combo.setItemIcon(0, QtGui.QIcon(self.app.resource_location + "/flatcam_icon16.png"))
|
2020-03-02 04:17:18 +00:00
|
|
|
self.type_box_combo.setItemIcon(1, QtGui.QIcon(self.app.resource_location + "/geometry16.png"))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.type_box_combo_label = QtWidgets.QLabel('%s:' % _("Box Type"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.type_box_combo_label.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Specify the type of object to be used as an container for\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"panelization. It can be: Gerber or Geometry type.\n"
|
|
|
|
"The selection here decide the type of objects that will be\n"
|
|
|
|
"in the Box Object combobox.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.type_box_combo_label, self.type_box_combo)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Box
|
2020-03-02 04:17:18 +00:00
|
|
|
self.box_combo = FCComboBox()
|
2019-01-03 19:25:08 +00:00
|
|
|
self.box_combo.setModel(self.app.collection)
|
|
|
|
self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
2020-03-03 22:27:51 +00:00
|
|
|
self.box_combo.is_last = True
|
2019-02-04 18:49:37 +00:00
|
|
|
|
2020-01-30 03:14:05 +00:00
|
|
|
self.box_combo.setToolTip(
|
2020-05-01 14:10:42 +00:00
|
|
|
_("The actual object that is used as container for the\n "
|
2019-05-06 23:08:17 +00:00
|
|
|
"selected object that is to be panelized.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
2020-01-30 03:14:05 +00:00
|
|
|
form_layout.addRow(self.box_combo)
|
2020-05-18 03:48:30 +00:00
|
|
|
|
|
|
|
separator_line = QtWidgets.QFrame()
|
|
|
|
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
|
|
|
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
|
|
form_layout.addRow(separator_line)
|
2019-05-07 10:55:20 +00:00
|
|
|
|
2019-08-18 11:17:46 +00:00
|
|
|
panel_data_label = QtWidgets.QLabel("<b>%s:</b>" % _("Panel Data"))
|
2019-05-07 10:55:20 +00:00
|
|
|
panel_data_label.setToolTip(
|
|
|
|
_("This informations will shape the resulting panel.\n"
|
|
|
|
"The number of rows and columns will set how many\n"
|
|
|
|
"duplicates of the original geometry will be generated.\n"
|
|
|
|
"\n"
|
|
|
|
"The spacings will set the distance between any two\n"
|
|
|
|
"elements of the panel array.")
|
|
|
|
)
|
|
|
|
form_layout.addRow(panel_data_label)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Spacing Columns
|
2020-02-17 02:43:01 +00:00
|
|
|
self.spacing_columns = FCDoubleSpinner(callback=self.confirmation_message)
|
2019-10-09 21:30:07 +00:00
|
|
|
self.spacing_columns.set_range(0, 9999)
|
|
|
|
self.spacing_columns.set_precision(4)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.spacing_columns_label = QtWidgets.QLabel('%s:' % _("Spacing cols"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.spacing_columns_label.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Spacing between columns of the desired panel.\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"In current units.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.spacing_columns_label, self.spacing_columns)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Spacing Rows
|
2020-02-17 02:43:01 +00:00
|
|
|
self.spacing_rows = FCDoubleSpinner(callback=self.confirmation_message)
|
2019-10-09 21:30:07 +00:00
|
|
|
self.spacing_rows.set_range(0, 9999)
|
|
|
|
self.spacing_rows.set_precision(4)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.spacing_rows_label = QtWidgets.QLabel('%s:' % _("Spacing rows"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.spacing_rows_label.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Spacing between rows of the desired panel.\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"In current units.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.spacing_rows_label, self.spacing_rows)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Columns
|
2020-02-17 02:56:57 +00:00
|
|
|
self.columns = FCSpinner(callback=self.confirmation_message_int)
|
2019-10-09 21:30:07 +00:00
|
|
|
self.columns.set_range(0, 9999)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.columns_label = QtWidgets.QLabel('%s:' % _("Columns"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.columns_label.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Number of columns of the desired panel")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.columns_label, self.columns)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Rows
|
2020-02-17 02:56:57 +00:00
|
|
|
self.rows = FCSpinner(callback=self.confirmation_message_int)
|
2019-10-09 21:30:07 +00:00
|
|
|
self.rows.set_range(0, 9999)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.rows_label = QtWidgets.QLabel('%s:' % _("Rows"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.rows_label.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Number of rows of the desired panel")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.rows_label, self.rows)
|
2020-05-18 03:48:30 +00:00
|
|
|
|
|
|
|
separator_line = QtWidgets.QFrame()
|
|
|
|
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
|
|
|
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
|
|
form_layout.addRow(separator_line)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Type of resulting Panel object
|
2019-07-17 11:11:10 +00:00
|
|
|
self.panel_type_radio = RadioSet([{'label': _('Gerber'), 'value': 'gerber'},
|
|
|
|
{'label': _('Geo'), 'value': 'geometry'}])
|
2019-08-18 11:17:46 +00:00
|
|
|
self.panel_type_label = QtWidgets.QLabel("<b>%s:</b>" % _("Panel Type"))
|
2019-02-18 21:50:33 +00:00
|
|
|
self.panel_type_label.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Choose the type of object for the panel object:\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"- Geometry\n"
|
|
|
|
"- Gerber")
|
2019-02-18 21:50:33 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.panel_type_label)
|
|
|
|
form_layout.addRow(self.panel_type_radio)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Constrains
|
2019-08-19 14:24:56 +00:00
|
|
|
self.constrain_cb = FCCheckBox('%s:' % _("Constrain panel within"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.constrain_cb.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Area define by DX and DY within to constrain the panel.\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"DX and DY values are in current units.\n"
|
|
|
|
"Regardless of how many columns and rows are desired,\n"
|
|
|
|
"the final panel will have as many columns and rows as\n"
|
|
|
|
"they fit completely within selected area.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.constrain_cb)
|
|
|
|
|
2020-02-17 02:43:01 +00:00
|
|
|
self.x_width_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
2019-10-09 21:30:07 +00:00
|
|
|
self.x_width_entry.set_precision(4)
|
|
|
|
self.x_width_entry.set_range(0, 9999)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.x_width_lbl = QtWidgets.QLabel('%s:' % _("Width (DX)"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.x_width_lbl.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("The width (DX) within which the panel must fit.\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"In current units.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.x_width_lbl, self.x_width_entry)
|
|
|
|
|
2020-02-17 02:43:01 +00:00
|
|
|
self.y_height_entry = FCDoubleSpinner(callback=self.confirmation_message)
|
2019-10-09 21:30:07 +00:00
|
|
|
self.y_height_entry.set_range(0, 9999)
|
|
|
|
self.y_height_entry.set_precision(4)
|
|
|
|
|
2019-08-19 14:24:56 +00:00
|
|
|
self.y_height_lbl = QtWidgets.QLabel('%s:' % _("Height (DY)"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.y_height_lbl.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("The height (DY)within which the panel must fit.\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"In current units.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
|
|
|
form_layout.addRow(self.y_height_lbl, self.y_height_entry)
|
|
|
|
|
|
|
|
self.constrain_sel = OptionalInputSection(
|
|
|
|
self.constrain_cb, [self.x_width_lbl, self.x_width_entry, self.y_height_lbl, self.y_height_entry])
|
|
|
|
|
2020-05-18 03:48:30 +00:00
|
|
|
separator_line = QtWidgets.QFrame()
|
|
|
|
separator_line.setFrameShape(QtWidgets.QFrame.HLine)
|
|
|
|
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
|
|
|
|
form_layout.addRow(separator_line)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Buttons
|
2019-03-10 12:34:13 +00:00
|
|
|
self.panelize_object_button = QtWidgets.QPushButton(_("Panelize Object"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.panelize_object_button.setToolTip(
|
2019-03-10 12:34:13 +00:00
|
|
|
_("Panelize the specified object around the specified box.\n"
|
2019-05-06 23:08:17 +00:00
|
|
|
"In other words it creates multiple copies of the source object,\n"
|
|
|
|
"arranged in a 2D array of rows and columns.")
|
2019-01-03 19:25:08 +00:00
|
|
|
)
|
2019-12-04 22:06:25 +00:00
|
|
|
self.panelize_object_button.setStyleSheet("""
|
|
|
|
QPushButton
|
|
|
|
{
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
""")
|
|
|
|
self.layout.addWidget(self.panelize_object_button)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.layout.addStretch()
|
|
|
|
|
2019-12-04 22:06:25 +00:00
|
|
|
# ## 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)
|
|
|
|
|
2019-05-06 23:08:17 +00:00
|
|
|
# Signals
|
2019-05-07 10:55:20 +00:00
|
|
|
self.reference_radio.activated_custom.connect(self.on_reference_radio_changed)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.panelize_object_button.clicked.connect(self.on_panelize)
|
|
|
|
self.type_obj_combo.currentIndexChanged.connect(self.on_type_obj_index_changed)
|
|
|
|
self.type_box_combo.currentIndexChanged.connect(self.on_type_box_index_changed)
|
2019-12-04 22:06:25 +00:00
|
|
|
self.reset_button.clicked.connect(self.set_tool_ui)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
# list to hold the temporary objects
|
|
|
|
self.objs = []
|
|
|
|
|
|
|
|
# final name for the panel object
|
|
|
|
self.outname = ""
|
|
|
|
|
|
|
|
# flag to signal the constrain was activated
|
|
|
|
self.constrain_flag = False
|
|
|
|
|
2019-03-10 15:12:58 +00:00
|
|
|
def run(self, toggle=True):
|
2020-04-29 01:46:52 +00:00
|
|
|
self.app.defaults.report_usage("ToolPanelize()")
|
2019-02-03 21:08:09 +00:00
|
|
|
|
2019-03-11 20:58:27 +00:00
|
|
|
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:
|
2019-03-11 21:04:38 +00:00
|
|
|
try:
|
|
|
|
if self.app.ui.tool_scroll_area.widget().objectName() == self.toolName:
|
2019-08-23 16:30:33 +00:00
|
|
|
# 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])
|
2019-03-11 21:04:38 +00:00
|
|
|
except AttributeError:
|
|
|
|
pass
|
2019-03-13 23:09:06 +00:00
|
|
|
else:
|
|
|
|
if self.app.ui.splitter.sizes()[0] == 0:
|
|
|
|
self.app.ui.splitter.setSizes([1, 1])
|
2019-03-11 20:58:27 +00:00
|
|
|
|
2020-05-18 13:11:02 +00:00
|
|
|
AppTool.run(self)
|
2019-02-27 15:32:52 +00:00
|
|
|
self.set_tool_ui()
|
2019-02-12 02:00:11 +00:00
|
|
|
|
2019-07-17 11:11:10 +00:00
|
|
|
self.app.ui.notebook.setTabText(2, _("Panel. Tool"))
|
2019-02-02 16:26:01 +00:00
|
|
|
|
|
|
|
def install(self, icon=None, separator=None, **kwargs):
|
2020-05-18 13:11:02 +00:00
|
|
|
AppTool.install(self, icon, separator, shortcut='Alt+Z', **kwargs)
|
2019-02-02 16:26:01 +00:00
|
|
|
|
|
|
|
def set_tool_ui(self):
|
|
|
|
self.reset_fields()
|
|
|
|
|
2019-05-07 10:55:20 +00:00
|
|
|
self.reference_radio.set_value('bbox')
|
|
|
|
|
2019-02-04 14:29:12 +00:00
|
|
|
sp_c = self.app.defaults["tools_panelize_spacing_columns"] if \
|
|
|
|
self.app.defaults["tools_panelize_spacing_columns"] else 0.0
|
|
|
|
self.spacing_columns.set_value(float(sp_c))
|
2019-02-02 16:26:01 +00:00
|
|
|
|
2019-02-04 14:29:12 +00:00
|
|
|
sp_r = self.app.defaults["tools_panelize_spacing_rows"] if \
|
|
|
|
self.app.defaults["tools_panelize_spacing_rows"] else 0.0
|
|
|
|
self.spacing_rows.set_value(float(sp_r))
|
2019-02-02 16:26:01 +00:00
|
|
|
|
2019-02-04 14:29:12 +00:00
|
|
|
rr = self.app.defaults["tools_panelize_rows"] if \
|
|
|
|
self.app.defaults["tools_panelize_rows"] else 0.0
|
|
|
|
self.rows.set_value(int(rr))
|
|
|
|
|
|
|
|
cc = self.app.defaults["tools_panelize_columns"] if \
|
|
|
|
self.app.defaults["tools_panelize_columns"] else 0.0
|
|
|
|
self.columns.set_value(int(cc))
|
|
|
|
|
|
|
|
c_cb = self.app.defaults["tools_panelize_constrain"] if \
|
|
|
|
self.app.defaults["tools_panelize_constrain"] else False
|
|
|
|
self.constrain_cb.set_value(c_cb)
|
|
|
|
|
|
|
|
x_w = self.app.defaults["tools_panelize_constrainx"] if \
|
|
|
|
self.app.defaults["tools_panelize_constrainx"] else 0.0
|
|
|
|
self.x_width_entry.set_value(float(x_w))
|
|
|
|
|
|
|
|
y_w = self.app.defaults["tools_panelize_constrainy"] if \
|
|
|
|
self.app.defaults["tools_panelize_constrainy"] else 0.0
|
|
|
|
self.y_height_entry.set_value(float(y_w))
|
2019-02-02 16:26:01 +00:00
|
|
|
|
2019-02-18 21:47:59 +00:00
|
|
|
panel_type = self.app.defaults["tools_panelize_panel_type"] if \
|
|
|
|
self.app.defaults["tools_panelize_panel_type"] else 'gerber'
|
|
|
|
self.panel_type_radio.set_value(panel_type)
|
|
|
|
|
2020-03-03 22:27:51 +00:00
|
|
|
# run once the following so the obj_type attribute is updated in the FCComboBoxes
|
|
|
|
# such that the last loaded object is populated in the combo boxes
|
|
|
|
self.on_type_obj_index_changed()
|
|
|
|
self.on_type_box_index_changed()
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
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)
|
2020-03-03 22:27:51 +00:00
|
|
|
self.object_combo.obj_type = {
|
|
|
|
_("Gerber"): "Gerber", _("Excellon"): "Excellon", _("Geometry"): "Geometry"
|
|
|
|
}[self.type_obj_combo.get_value()]
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-07 10:55:20 +00:00
|
|
|
# hide the panel type for Excellons, the panel can be only of type Geometry
|
|
|
|
if self.type_obj_combo.currentText() != 'Excellon':
|
|
|
|
self.panel_type_label.setDisabled(False)
|
|
|
|
self.panel_type_radio.setDisabled(False)
|
|
|
|
else:
|
|
|
|
self.panel_type_label.setDisabled(True)
|
|
|
|
self.panel_type_radio.setDisabled(True)
|
|
|
|
self.panel_type_radio.set_value('geometry')
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
def on_type_box_index_changed(self):
|
|
|
|
obj_type = self.type_box_combo.currentIndex()
|
|
|
|
self.box_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
|
|
|
|
self.box_combo.setCurrentIndex(0)
|
2020-03-03 22:27:51 +00:00
|
|
|
self.box_combo.obj_type = {
|
|
|
|
_("Gerber"): "Gerber", _("Geometry"): "Geometry"
|
|
|
|
}[self.type_box_combo.get_value()]
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-05-07 10:55:20 +00:00
|
|
|
def on_reference_radio_changed(self, current_val):
|
|
|
|
if current_val == 'object':
|
|
|
|
self.type_box_combo.setDisabled(False)
|
|
|
|
self.type_box_combo_label.setDisabled(False)
|
|
|
|
self.box_combo.setDisabled(False)
|
|
|
|
else:
|
|
|
|
self.type_box_combo.setDisabled(True)
|
|
|
|
self.type_box_combo_label.setDisabled(True)
|
|
|
|
self.box_combo.setDisabled(True)
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
def on_panelize(self):
|
|
|
|
name = self.object_combo.currentText()
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
# Get source object to be panelized.
|
2019-01-03 19:25:08 +00:00
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
panel_source_obj = self.app.collection.get_by_name(str(name))
|
2019-07-28 23:36:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
log.debug("Panelize.on_panelize() --> %s" % str(e))
|
2020-05-02 12:56:30 +00:00
|
|
|
self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), name))
|
2019-01-03 19:25:08 +00:00
|
|
|
return "Could not retrieve object: %s" % name
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj is None:
|
2019-09-06 18:02:08 +00:00
|
|
|
self.app.inform.emit('[ERROR_NOTCL] %s: %s' %
|
2020-05-02 12:56:30 +00:00
|
|
|
(_("Object not found"), panel_source_obj))
|
|
|
|
return "Object not found: %s" % panel_source_obj
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
boxname = self.box_combo.currentText()
|
|
|
|
|
|
|
|
try:
|
|
|
|
box = self.app.collection.get_by_name(boxname)
|
2019-07-28 23:36:29 +00:00
|
|
|
except Exception as e:
|
|
|
|
log.debug("Panelize.on_panelize() --> %s" % str(e))
|
2020-05-02 12:56:30 +00:00
|
|
|
self.app.inform.emit('[ERROR_NOTCL] %s: %s' % (_("Could not retrieve object"), boxname))
|
2019-01-03 19:25:08 +00:00
|
|
|
return "Could not retrieve object: %s" % boxname
|
|
|
|
|
|
|
|
if box is None:
|
2020-05-31 00:14:33 +00:00
|
|
|
self.app.inform.emit('[WARNING_NOTCL] %s: %s' % (_("No object Box. Using instead"), panel_source_obj))
|
2019-05-07 10:55:20 +00:00
|
|
|
self.reference_radio.set_value('bbox')
|
|
|
|
|
|
|
|
if self.reference_radio.get_value() == 'bbox':
|
2020-05-02 12:56:30 +00:00
|
|
|
box = panel_source_obj
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
self.outname = name + '_panelized'
|
|
|
|
|
2019-10-05 14:08:51 +00:00
|
|
|
spacing_columns = float(self.spacing_columns.get_value())
|
2019-01-03 19:25:08 +00:00
|
|
|
spacing_columns = spacing_columns if spacing_columns is not None else 0
|
|
|
|
|
2019-10-05 14:08:51 +00:00
|
|
|
spacing_rows = float(self.spacing_rows.get_value())
|
2019-01-03 19:25:08 +00:00
|
|
|
spacing_rows = spacing_rows if spacing_rows is not None else 0
|
|
|
|
|
2019-10-05 14:08:51 +00:00
|
|
|
rows = int(self.rows.get_value())
|
2019-01-03 19:25:08 +00:00
|
|
|
rows = rows if rows is not None else 1
|
|
|
|
|
2019-10-05 14:08:51 +00:00
|
|
|
columns = int(self.columns.get_value())
|
2019-01-03 19:25:08 +00:00
|
|
|
columns = columns if columns is not None else 1
|
|
|
|
|
2019-10-05 14:08:51 +00:00
|
|
|
constrain_dx = float(self.x_width_entry.get_value())
|
|
|
|
constrain_dy = float(self.y_height_entry.get_value())
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-02-18 21:47:59 +00:00
|
|
|
panel_type = str(self.panel_type_radio.get_value())
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
if 0 in {columns, rows}:
|
2019-09-06 18:02:08 +00:00
|
|
|
self.app.inform.emit('[ERROR_NOTCL] %s' %
|
|
|
|
_("Columns or Rows are zero value. Change them to a positive integer."))
|
2019-01-03 19:25:08 +00:00
|
|
|
return "Columns or Rows are zero value. Change them to a positive integer."
|
|
|
|
|
|
|
|
xmin, ymin, xmax, ymax = box.bounds()
|
|
|
|
lenghtx = xmax - xmin + spacing_columns
|
|
|
|
lenghty = ymax - ymin + spacing_rows
|
|
|
|
|
|
|
|
# check if constrain within an area is desired
|
|
|
|
if self.constrain_cb.isChecked():
|
|
|
|
panel_lengthx = ((xmax - xmin) * columns) + (spacing_columns * (columns - 1))
|
|
|
|
panel_lengthy = ((ymax - ymin) * rows) + (spacing_rows * (rows - 1))
|
|
|
|
|
|
|
|
# adjust the number of columns and/or rows so the panel will fit within the panel constraint area
|
|
|
|
if (panel_lengthx > constrain_dx) or (panel_lengthy > constrain_dy):
|
|
|
|
self.constrain_flag = True
|
|
|
|
|
|
|
|
while panel_lengthx > constrain_dx:
|
|
|
|
columns -= 1
|
|
|
|
panel_lengthx = ((xmax - xmin) * columns) + (spacing_columns * (columns - 1))
|
|
|
|
while panel_lengthy > constrain_dy:
|
|
|
|
rows -= 1
|
|
|
|
panel_lengthy = ((ymax - ymin) * rows) + (spacing_rows * (rows - 1))
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.kind == 'excellon' or panel_source_obj.kind == 'geometry':
|
2019-10-15 23:28:18 +00:00
|
|
|
# make a copy of the panelized Excellon or Geometry tools
|
2020-02-29 22:52:24 +00:00
|
|
|
copied_tools = {}
|
2020-05-02 12:56:30 +00:00
|
|
|
for tt, tt_val in list(panel_source_obj.tools.items()):
|
2019-10-15 23:28:18 +00:00
|
|
|
copied_tools[tt] = deepcopy(tt_val)
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.kind == 'gerber':
|
2019-10-15 23:28:18 +00:00
|
|
|
# make a copy of the panelized Gerber apertures
|
2020-02-29 22:52:24 +00:00
|
|
|
copied_apertures = {}
|
2020-05-02 12:56:30 +00:00
|
|
|
for tt, tt_val in list(panel_source_obj.apertures.items()):
|
2019-10-15 23:28:18 +00:00
|
|
|
copied_apertures[tt] = deepcopy(tt_val)
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
def panelize_worker():
|
|
|
|
if panel_source_obj is not None:
|
2019-09-11 01:54:30 +00:00
|
|
|
self.app.inform.emit(_("Generating panel ... "))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-01-25 13:16:36 +00:00
|
|
|
def job_init_excellon(obj_fin, app_obj):
|
2019-01-03 19:25:08 +00:00
|
|
|
currenty = 0.0
|
2019-10-15 23:28:18 +00:00
|
|
|
obj_fin.tools = copied_tools
|
2019-01-25 13:16:36 +00:00
|
|
|
obj_fin.drills = []
|
|
|
|
obj_fin.slots = []
|
|
|
|
obj_fin.solid_geometry = []
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
for option in panel_source_obj.options:
|
2020-04-01 15:45:20 +00:00
|
|
|
if option != 'name':
|
2019-01-25 13:27:46 +00:00
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
obj_fin.options[option] = panel_source_obj.options[option]
|
2019-07-28 23:36:29 +00:00
|
|
|
except KeyError:
|
|
|
|
log.warning("Failed to copy option. %s" % str(option))
|
2019-01-25 13:27:46 +00:00
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len_drills = len(panel_source_obj.drills) if panel_source_obj.drills else 0
|
|
|
|
geo_len_slots = len(panel_source_obj.slots) if panel_source_obj.slots else 0
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
element = 0
|
2019-01-03 19:25:08 +00:00
|
|
|
for row in range(rows):
|
|
|
|
currentx = 0.0
|
|
|
|
for col in range(columns):
|
2019-09-10 12:08:42 +00:00
|
|
|
element += 1
|
|
|
|
old_disp_number = 0
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.drills:
|
2019-09-10 12:08:42 +00:00
|
|
|
drill_nr = 0
|
2020-05-02 12:56:30 +00:00
|
|
|
for tool_dict in panel_source_obj.drills:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
2019-01-25 13:16:36 +00:00
|
|
|
point_offseted = affinity.translate(tool_dict['point'], currentx, currenty)
|
|
|
|
obj_fin.drills.append(
|
|
|
|
{
|
|
|
|
"point": point_offseted,
|
|
|
|
"tool": tool_dict['tool']
|
|
|
|
}
|
|
|
|
)
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
drill_nr += 1
|
|
|
|
disp_number = int(np.interp(drill_nr, [0, geo_len_drills], [0, 100]))
|
|
|
|
|
2019-10-15 23:28:18 +00:00
|
|
|
if old_disp_number < disp_number <= 100:
|
2019-09-10 12:08:42 +00:00
|
|
|
self.app.proc_container.update_view_text(' %s: %d D:%d%%' %
|
|
|
|
(_("Copy"),
|
|
|
|
int(element),
|
|
|
|
disp_number))
|
|
|
|
old_disp_number = disp_number
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.slots:
|
2019-09-10 12:08:42 +00:00
|
|
|
slot_nr = 0
|
2020-05-02 12:56:30 +00:00
|
|
|
for tool_dict in panel_source_obj.slots:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
2019-01-25 13:16:36 +00:00
|
|
|
start_offseted = affinity.translate(tool_dict['start'], currentx, currenty)
|
|
|
|
stop_offseted = affinity.translate(tool_dict['stop'], currentx, currenty)
|
|
|
|
obj_fin.slots.append(
|
|
|
|
{
|
|
|
|
"start": start_offseted,
|
|
|
|
"stop": stop_offseted,
|
|
|
|
"tool": tool_dict['tool']
|
|
|
|
}
|
|
|
|
)
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
slot_nr += 1
|
|
|
|
disp_number = int(np.interp(slot_nr, [0, geo_len_slots], [0, 100]))
|
|
|
|
|
2019-10-15 23:28:18 +00:00
|
|
|
if old_disp_number < disp_number <= 100:
|
2019-09-10 12:08:42 +00:00
|
|
|
self.app.proc_container.update_view_text(' %s: %d S:%d%%' %
|
|
|
|
(_("Copy"),
|
|
|
|
int(element),
|
|
|
|
disp_number))
|
|
|
|
old_disp_number = disp_number
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
currentx += lenghtx
|
|
|
|
currenty += lenghty
|
|
|
|
|
2019-01-25 13:16:36 +00:00
|
|
|
obj_fin.create_geometry()
|
2020-05-02 12:56:30 +00:00
|
|
|
obj_fin.zeros = panel_source_obj.zeros
|
|
|
|
obj_fin.units = panel_source_obj.units
|
2019-09-10 12:08:42 +00:00
|
|
|
self.app.proc_container.update_view_text('')
|
2019-01-25 13:16:36 +00:00
|
|
|
|
|
|
|
def job_init_geometry(obj_fin, app_obj):
|
|
|
|
currentx = 0.0
|
|
|
|
currenty = 0.0
|
|
|
|
|
|
|
|
def translate_recursion(geom):
|
|
|
|
if type(geom) == list:
|
2020-02-29 22:52:24 +00:00
|
|
|
geoms = []
|
2019-01-25 13:16:36 +00:00
|
|
|
for local_geom in geom:
|
2019-05-06 23:08:17 +00:00
|
|
|
res_geo = translate_recursion(local_geom)
|
|
|
|
try:
|
2019-07-28 23:36:29 +00:00
|
|
|
geoms += res_geo
|
2019-05-06 23:08:17 +00:00
|
|
|
except TypeError:
|
|
|
|
geoms.append(res_geo)
|
2019-01-25 13:16:36 +00:00
|
|
|
return geoms
|
|
|
|
else:
|
|
|
|
return affinity.translate(geom, xoff=currentx, yoff=currenty)
|
|
|
|
|
|
|
|
obj_fin.solid_geometry = []
|
|
|
|
|
2019-09-10 12:08:42 +00:00
|
|
|
# create the initial structure on which to create the panel
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.kind == 'geometry':
|
|
|
|
obj_fin.multigeo = panel_source_obj.multigeo
|
2019-10-15 23:28:18 +00:00
|
|
|
obj_fin.tools = copied_tools
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.multigeo is True:
|
|
|
|
for tool in panel_source_obj.tools:
|
2019-01-25 13:16:36 +00:00
|
|
|
obj_fin.tools[tool]['solid_geometry'][:] = []
|
2020-05-02 12:56:30 +00:00
|
|
|
elif panel_source_obj.kind == 'gerber':
|
2019-10-15 23:28:18 +00:00
|
|
|
obj_fin.apertures = copied_apertures
|
2019-05-06 23:08:17 +00:00
|
|
|
for ap in obj_fin.apertures:
|
2020-02-29 22:52:24 +00:00
|
|
|
obj_fin.apertures[ap]['geometry'] = []
|
2019-05-06 23:08:17 +00:00
|
|
|
|
2019-09-10 12:08:42 +00:00
|
|
|
# find the number of polygons in the source solid_geometry
|
|
|
|
geo_len = 0
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.kind == 'geometry':
|
|
|
|
if panel_source_obj.multigeo is True:
|
|
|
|
for tool in panel_source_obj.tools:
|
2019-09-10 12:08:42 +00:00
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len += len(panel_source_obj.tools[tool]['solid_geometry'])
|
2019-09-10 12:08:42 +00:00
|
|
|
except TypeError:
|
2019-12-26 01:15:17 +00:00
|
|
|
geo_len += 1
|
2019-09-10 12:08:42 +00:00
|
|
|
else:
|
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len = len(panel_source_obj.solid_geometry)
|
2019-09-10 12:08:42 +00:00
|
|
|
except TypeError:
|
|
|
|
geo_len = 1
|
2020-05-02 12:56:30 +00:00
|
|
|
elif panel_source_obj.kind == 'gerber':
|
|
|
|
for ap in panel_source_obj.apertures:
|
|
|
|
if 'geometry' in panel_source_obj.apertures[ap]:
|
2019-12-26 01:15:17 +00:00
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len += len(panel_source_obj.apertures[ap]['geometry'])
|
2019-12-26 01:15:17 +00:00
|
|
|
except TypeError:
|
|
|
|
geo_len += 1
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
element = 0
|
2019-01-03 19:25:08 +00:00
|
|
|
for row in range(rows):
|
2019-01-25 13:16:36 +00:00
|
|
|
currentx = 0.0
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
for col in range(columns):
|
2019-09-10 12:08:42 +00:00
|
|
|
element += 1
|
|
|
|
old_disp_number = 0
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
# Will panelize a Geometry Object
|
|
|
|
if panel_source_obj.kind == 'geometry':
|
|
|
|
if panel_source_obj.multigeo is True:
|
|
|
|
for tool in panel_source_obj.tools:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
# calculate the number of polygons
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len = len(panel_source_obj.tools[tool]['solid_geometry'])
|
2019-09-10 12:08:42 +00:00
|
|
|
pol_nr = 0
|
2020-05-02 12:56:30 +00:00
|
|
|
for geo_el in panel_source_obj.tools[tool]['solid_geometry']:
|
2019-09-10 12:08:42 +00:00
|
|
|
trans_geo = translate_recursion(geo_el)
|
|
|
|
obj_fin.tools[tool]['solid_geometry'].append(trans_geo)
|
|
|
|
|
|
|
|
pol_nr += 1
|
|
|
|
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
|
2019-09-10 13:05:54 +00:00
|
|
|
if old_disp_number < disp_number <= 100:
|
2019-09-10 12:08:42 +00:00
|
|
|
self.app.proc_container.update_view_text(' %s: %d %d%%' %
|
|
|
|
(_("Copy"),
|
|
|
|
int(element),
|
|
|
|
disp_number))
|
|
|
|
old_disp_number = disp_number
|
2019-01-25 13:16:36 +00:00
|
|
|
else:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
# calculate the number of polygons
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len = len(panel_source_obj.solid_geometry)
|
2019-09-10 12:08:42 +00:00
|
|
|
except TypeError:
|
|
|
|
geo_len = 1
|
|
|
|
pol_nr = 0
|
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
for geo_el in panel_source_obj.solid_geometry:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
trans_geo = translate_recursion(geo_el)
|
|
|
|
obj_fin.solid_geometry.append(trans_geo)
|
|
|
|
|
|
|
|
pol_nr += 1
|
|
|
|
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
|
|
|
|
|
2019-09-10 13:05:54 +00:00
|
|
|
if old_disp_number < disp_number <= 100:
|
2019-09-10 12:08:42 +00:00
|
|
|
self.app.proc_container.update_view_text(' %s: %d %d%%' %
|
|
|
|
(_("Copy"),
|
|
|
|
int(element),
|
|
|
|
disp_number))
|
|
|
|
old_disp_number = disp_number
|
2020-05-02 12:56:30 +00:00
|
|
|
|
2019-09-10 12:08:42 +00:00
|
|
|
except TypeError:
|
2020-05-02 12:56:30 +00:00
|
|
|
trans_geo = translate_recursion(panel_source_obj.solid_geometry)
|
2019-09-10 12:08:42 +00:00
|
|
|
obj_fin.solid_geometry.append(trans_geo)
|
2020-05-02 12:56:30 +00:00
|
|
|
# Will panelize a Gerber Object
|
2019-01-25 13:16:36 +00:00
|
|
|
else:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
for geo_el in panel_source_obj.solid_geometry:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
|
|
|
trans_geo = translate_recursion(geo_el)
|
|
|
|
obj_fin.solid_geometry.append(trans_geo)
|
|
|
|
except TypeError:
|
2020-05-02 12:56:30 +00:00
|
|
|
trans_geo = translate_recursion(panel_source_obj.solid_geometry)
|
2019-09-10 12:08:42 +00:00
|
|
|
obj_fin.solid_geometry.append(trans_geo)
|
2019-05-06 23:08:17 +00:00
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
for apid in panel_source_obj.apertures:
|
2019-09-10 12:08:42 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2020-05-02 12:56:30 +00:00
|
|
|
if 'geometry' in panel_source_obj.apertures[apid]:
|
2019-12-26 01:15:17 +00:00
|
|
|
try:
|
|
|
|
# calculate the number of polygons
|
2020-05-02 12:56:30 +00:00
|
|
|
geo_len = len(panel_source_obj.apertures[apid]['geometry'])
|
2019-12-26 01:15:17 +00:00
|
|
|
except TypeError:
|
|
|
|
geo_len = 1
|
|
|
|
pol_nr = 0
|
2020-05-02 12:56:30 +00:00
|
|
|
for el in panel_source_obj.apertures[apid]['geometry']:
|
2019-12-26 01:15:17 +00:00
|
|
|
if self.app.abort_flag:
|
|
|
|
# graceful abort requested by the user
|
2020-04-27 07:03:22 +00:00
|
|
|
raise grace
|
2019-09-10 12:08:42 +00:00
|
|
|
|
2020-02-29 22:52:24 +00:00
|
|
|
new_el = {}
|
2019-12-26 01:15:17 +00:00
|
|
|
if 'solid' in el:
|
|
|
|
geo_aper = translate_recursion(el['solid'])
|
|
|
|
new_el['solid'] = geo_aper
|
2019-05-06 23:08:17 +00:00
|
|
|
|
2019-12-26 01:15:17 +00:00
|
|
|
if 'clear' in el:
|
|
|
|
geo_aper = translate_recursion(el['clear'])
|
|
|
|
new_el['clear'] = geo_aper
|
2019-05-06 23:08:17 +00:00
|
|
|
|
2019-12-26 01:15:17 +00:00
|
|
|
if 'follow' in el:
|
|
|
|
geo_aper = translate_recursion(el['follow'])
|
|
|
|
new_el['follow'] = geo_aper
|
2019-09-10 00:20:14 +00:00
|
|
|
|
2019-12-26 01:15:17 +00:00
|
|
|
obj_fin.apertures[apid]['geometry'].append(deepcopy(new_el))
|
2019-01-25 13:16:36 +00:00
|
|
|
|
2019-12-26 01:15:17 +00:00
|
|
|
pol_nr += 1
|
|
|
|
disp_number = int(np.interp(pol_nr, [0, geo_len], [0, 100]))
|
2019-09-10 12:08:42 +00:00
|
|
|
|
2019-12-26 01:15:17 +00:00
|
|
|
if old_disp_number < disp_number <= 100:
|
|
|
|
self.app.proc_container.update_view_text(' %s: %d %d%%' %
|
|
|
|
(_("Copy"),
|
|
|
|
int(element),
|
|
|
|
disp_number))
|
|
|
|
old_disp_number = disp_number
|
2019-09-10 12:08:42 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
currentx += lenghtx
|
|
|
|
currenty += lenghty
|
|
|
|
|
2020-05-02 12:56:30 +00:00
|
|
|
print("before", obj_fin.tools)
|
|
|
|
if panel_source_obj.kind == 'geometry' and panel_source_obj.multigeo is True:
|
|
|
|
# I'm going to do this only here as a fix for panelizing cutouts
|
|
|
|
# I'm going to separate linestrings out of the solid geometry from other
|
|
|
|
# possible type of elements and apply unary_union on them to fuse them
|
|
|
|
for tool in obj_fin.tools:
|
|
|
|
lines = []
|
|
|
|
other_geo = []
|
|
|
|
for geo in obj_fin.tools[tool]['solid_geometry']:
|
|
|
|
if isinstance(geo, LineString):
|
|
|
|
lines.append(geo)
|
|
|
|
else:
|
|
|
|
other_geo.append(geo)
|
|
|
|
fused_lines = list(unary_union(lines))
|
|
|
|
obj_fin.tools[tool]['solid_geometry'] = fused_lines + other_geo
|
|
|
|
print("after", obj_fin.tools)
|
|
|
|
|
2019-09-11 01:54:30 +00:00
|
|
|
if panel_type == 'gerber':
|
2019-12-26 01:15:17 +00:00
|
|
|
self.app.inform.emit('%s' % _("Generating panel ... Adding the Gerber code."))
|
2019-09-11 01:54:30 +00:00
|
|
|
obj_fin.source_file = self.app.export_gerber(obj_name=self.outname, filename=None,
|
|
|
|
local_use=obj_fin, use_thread=False)
|
|
|
|
|
2019-09-10 00:20:14 +00:00
|
|
|
# obj_fin.solid_geometry = cascaded_union(obj_fin.solid_geometry)
|
2019-09-10 12:08:42 +00:00
|
|
|
# app_obj.log.debug("Finished creating a cascaded union for the panel.")
|
|
|
|
self.app.proc_container.update_view_text('')
|
2019-05-06 23:08:17 +00:00
|
|
|
|
2019-12-26 01:15:17 +00:00
|
|
|
self.app.inform.emit('%s: %d' % (_("Generating panel... Spawning copies"), (int(rows * columns))))
|
2020-05-02 12:56:30 +00:00
|
|
|
if panel_source_obj.kind == 'excellon':
|
2020-05-18 14:31:02 +00:00
|
|
|
self.app.app_obj.new_object("excellon", self.outname, job_init_excellon, plot=True, autoselected=True)
|
2019-01-03 19:25:08 +00:00
|
|
|
else:
|
2020-05-18 14:31:02 +00:00
|
|
|
self.app.app_obj.new_object(panel_type, self.outname, job_init_geometry, plot=True, autoselected=True)
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
if self.constrain_flag is False:
|
2019-09-06 18:02:08 +00:00
|
|
|
self.app.inform.emit('[success] %s' % _("Panel done..."))
|
2019-01-03 19:25:08 +00:00
|
|
|
else:
|
|
|
|
self.constrain_flag = False
|
2019-09-06 18:02:08 +00:00
|
|
|
self.app.inform.emit(_("{text} Too big for the constrain area. "
|
2019-05-06 23:08:17 +00:00
|
|
|
"Final panel has {col} columns and {row} rows").format(
|
2019-09-06 18:02:08 +00:00
|
|
|
text='[WARNING] ', col=columns, row=rows))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
2019-09-10 12:08:42 +00:00
|
|
|
proc = self.app.proc_container.new(_("Working..."))
|
2019-01-25 13:16:36 +00:00
|
|
|
|
|
|
|
def job_thread(app_obj):
|
|
|
|
try:
|
2020-05-02 12:56:30 +00:00
|
|
|
panelize_worker()
|
2019-09-06 18:02:08 +00:00
|
|
|
self.app.inform.emit('[success] %s' % _("Panel created successfully."))
|
2019-07-28 23:36:29 +00:00
|
|
|
except Exception as ee:
|
2019-01-25 13:16:36 +00:00
|
|
|
proc.done()
|
2019-07-28 23:36:29 +00:00
|
|
|
log.debug(str(ee))
|
2019-01-25 16:57:44 +00:00
|
|
|
return
|
2019-01-25 13:16:36 +00:00
|
|
|
proc.done()
|
|
|
|
|
|
|
|
self.app.collection.promise(self.outname)
|
|
|
|
self.app.worker_task.emit({'fcn': job_thread, 'params': [self.app]})
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def reset_fields(self):
|
|
|
|
self.object_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|
|
|
|
self.box_combo.setRootModelIndex(self.app.collection.index(0, 0, QtCore.QModelIndex()))
|