- in Properties Tool made threaded the calculation of convex_hull area and to work for multi-geo objects

- in NCC tool the type of tool that is used is transferred to the Geometry object
- in NCC tool the type of isolation done with the tools selected as isolation tools can now be selected and it has also an Edit -> Preferences entry
This commit is contained in:
Marius Stanciu
2019-09-02 21:39:46 +03:00
committed by Marius
parent c3505b434a
commit 60512f09a7
5 changed files with 165 additions and 47 deletions

View File

@@ -140,6 +140,23 @@ class NonCopperClear(FlatCAMTool, Gerber):
"If it's not successful then the non-copper clearing will fail, too.\n"
"- Clear -> the regular non-copper clearing."))
# Milling Type Radio Button
self.milling_type_label = QtWidgets.QLabel('%s:' % _('Milling Type'))
self.milling_type_label.setToolTip(
_("Milling type when the selected tool is of type: 'iso_op':\n"
"- climb / best for precision milling and to reduce tool usage\n"
"- conventional / useful when there is no backlash compensation")
)
self.milling_type_radio = RadioSet([{'label': _('Climb'), 'value': 'cl'},
{'label': _('Conv.'), 'value': 'cv'}])
self.milling_type_radio.setToolTip(
_("Milling type when the selected tool is of type: 'iso_op':\n"
"- climb / best for precision milling and to reduce tool usage\n"
"- conventional / useful when there is no backlash compensation")
)
# Tool order
self.ncc_order_label = QtWidgets.QLabel('<b>%s:</b>' % _('Tool order'))
self.ncc_order_label.setToolTip(_("This set the way that the tools in the tools table are used.\n"
"'No' --> means that the used order is the one in the tool table\n"
@@ -159,9 +176,14 @@ class NonCopperClear(FlatCAMTool, Gerber):
"in reverse and disable this control."))
form = QtWidgets.QFormLayout()
self.tools_box.addLayout(form)
form.addRow(QtWidgets.QLabel(''), QtWidgets.QLabel(''))
form.addRow(self.milling_type_label, self.milling_type_radio)
form.addRow(self.ncc_order_label, self.ncc_order_radio)
self.milling_type_label.hide()
self.milling_type_radio.hide()
# ### Add a new Tool ####
self.addtool_entry_lbl = QtWidgets.QLabel('<b>%s:</b>' % _('Tool Dia'))
self.addtool_entry_lbl.setToolTip(
@@ -397,6 +419,8 @@ class NonCopperClear(FlatCAMTool, Gerber):
# store here solid_geometry when there are tool with isolation job
self.solid_geometry = []
self.tool_type_item_options = []
self.addtool_btn.clicked.connect(self.on_tool_add)
self.addtool_entry.returnPressed.connect(self.on_tool_add)
self.deltool_btn.clicked.connect(self.on_tool_delete)
@@ -463,6 +487,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.ncc_contour_cb.set_value(self.app.defaults["tools_ncccontour"])
self.ncc_rest_cb.set_value(self.app.defaults["tools_nccrest"])
self.reference_radio.set_value(self.app.defaults["tools_nccref"])
self.milling_type_radio.set_value(self.app.defaults["tools_nccmilling_type"])
# init the working variables
self.default_data.clear()
@@ -524,7 +549,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
'offset_value': 0.0,
'type': 'Iso',
'tool_type': 'V',
'operation': 'clear',
'operation': 'clear_op',
'data': dict(self.default_data),
'solid_geometry': []
}
@@ -594,9 +619,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
tool_uid_item = QtWidgets.QTableWidgetItem(str(int(tooluid_key)))
operation_type = QtWidgets.QComboBox()
operation_type.addItem('iso')
operation_type.addItem('iso_op')
operation_type.setStyleSheet('background-color: rgb(255,255,255)')
operation_type.addItem('clear')
operation_type.addItem('clear_op')
operation_type.setStyleSheet('background-color: rgb(255,255,255)')
op_idx = operation_type.findText(tooluid_value['operation'])
operation_type.setCurrentIndex(op_idx)
@@ -642,6 +667,10 @@ class NonCopperClear(FlatCAMTool, Gerber):
def ui_connect(self):
self.tools_table.itemChanged.connect(self.on_tool_edit)
for row in range(self.tools_table.rowCount()):
for col in [2, 4]:
self.tools_table.cellWidget(row, col).currentIndexChanged.connect(self.on_tooltable_cellwidget_change)
def ui_disconnect(self):
try:
# if connected, disconnect the signal from the slot on item_changed as it creates issues
@@ -649,6 +678,13 @@ class NonCopperClear(FlatCAMTool, Gerber):
except (TypeError, AttributeError):
pass
for row in range(self.tools_table.rowCount()):
for col in [2, 4]:
try:
self.ui.geo_tools_table.cellWidget(row, col).currentIndexChanged.disconnect()
except (TypeError, AttributeError):
pass
def on_combo_box_type(self):
obj_type = self.box_combo_type.currentIndex()
self.box_combo.setRootModelIndex(self.app.collection.index(obj_type, 0, QtCore.QModelIndex()))
@@ -687,6 +723,40 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.ncc_order_label.setDisabled(False)
self.ncc_order_radio.setDisabled(False)
def on_tooltable_cellwidget_change(self):
cw = self.sender()
cw_index = self.tools_table.indexAt(cw.pos())
cw_row = cw_index.row()
cw_col = cw_index.column()
current_uid = int(self.tools_table.item(cw_row, 3).text())
hide_iso_type = True
for row in range(self.tools_table.rowCount()):
if self.tools_table.cellWidget(row, 4).currentText() == 'iso_op':
hide_iso_type = False
break
if hide_iso_type is False:
self.milling_type_label.show()
self.milling_type_radio.show()
else:
self.milling_type_label.hide()
self.milling_type_radio.hide()
# if the sender is in the column with index 2 then we update the tool_type key
if cw_col == 2:
tt = cw.currentText()
if tt == 'V':
typ = 'Iso'
else:
typ = "Rough"
self.ncc_tools[current_uid].update({
'type': typ,
'tool_type': tt,
})
def on_tool_add(self, dia=None, muted=None):
self.ui_disconnect()
@@ -748,7 +818,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
'offset_value': 0.0,
'type': 'Iso',
'tool_type': 'V',
'operation': 'clear',
'operation': 'clear_op',
'data': dict(self.default_data),
'solid_geometry': []
}
@@ -759,6 +829,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
def on_tool_edit(self):
self.ui_disconnect()
old_tool_dia = ''
tool_dias = []
for k, v in self.ncc_tools.items():
for tool_v in v.keys():
@@ -901,7 +972,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
"use a number."))
continue
if self.tools_table.cellWidget(x.row(), 4).currentText() == 'iso':
if self.tools_table.cellWidget(x.row(), 4).currentText() == 'iso_op':
iso_dia_list.append(tooldia)
else:
ncc_dia_list.append(tooldia)
@@ -1167,7 +1238,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
sorted_tools = ncctooldia
else:
for row in range(self.tools_table.rowCount()):
if self.tools_table.cellWidget(row, 1).currentText() == 'clear':
if self.tools_table.cellWidget(row, 1).currentText() == 'clear_op':
sorted_tools.append(float(self.tools_table.item(row, 1).text()))
# ##############################################################################################################
@@ -1287,7 +1358,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.solid_geometry = ncc_obj.solid_geometry
# if milling type is climb then the move is counter-clockwise around features
milling_type = 'cl'
milling_type = self.milling_type_radio.get_value()
for tool_iso in isotooldia:
new_geometry = []
@@ -1503,7 +1574,7 @@ class NonCopperClear(FlatCAMTool, Gerber):
self.solid_geometry = ncc_obj.solid_geometry
# if milling type is climb then the move is counter-clockwise around features
milling_type = 'cl'
milling_type = self.milling_type_radio.get_value()
for tool_iso in isotooldia:
new_geometry = []

View File

@@ -21,9 +21,10 @@ if '_' not in builtins.__dict__:
class Properties(FlatCAMTool):
toolName = _("Properties")
area_finished = pyqtSignal(float, object)
def __init__(self, app):
FlatCAMTool.__init__(self, app)
@@ -64,6 +65,8 @@ class Properties(FlatCAMTool):
self.vlay.addWidget(self.treeWidget)
self.vlay.setStretch(0, 0)
self.area_finished.connect(self.show_area_chull)
def run(self, toggle=True):
self.app.report_usage("ToolProperties()")
@@ -170,25 +173,38 @@ class Properties(FlatCAMTool):
self.addChild(dims, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'in2')], True)
if not isinstance(obj, FlatCAMCNCjob):
# calculate and add convex hull area
geo = obj.solid_geometry
if isinstance(geo, MultiPolygon):
env_obj = geo.convex_hull
elif (isinstance(geo, MultiPolygon) and len(geo) == 1) or \
(isinstance(geo, list) and len(geo) == 1) and isinstance(geo[0], Polygon):
env_obj = cascaded_union(obj.solid_geometry)
env_obj = env_obj.convex_hull
else:
env_obj = cascaded_union(obj.solid_geometry)
env_obj = env_obj.convex_hull
area_chull = env_obj.area
if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower() == 'mm':
area_chull = area_chull / 100
self.addChild(dims, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (area_chull, 'cm2')], True)
else:
area_chull = area_chull
self.addChild(dims, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (area_chull, 'in2')], True)
def job_thread():
proc = self.app.proc_container.new(_("Calculating area ... Please wait."))
# calculate and add convex hull area
geo = obj.solid_geometry
if geo:
if isinstance(geo, MultiPolygon):
env_obj = geo.convex_hull
elif (isinstance(geo, MultiPolygon) and len(geo) == 1) or \
(isinstance(geo, list) and len(geo) == 1) and isinstance(geo[0], Polygon):
env_obj = cascaded_union(obj.solid_geometry)
env_obj = env_obj.convex_hull
else:
env_obj = cascaded_union(obj.solid_geometry)
env_obj = env_obj.convex_hull
area_chull = env_obj.area
else:
try:
area_chull = []
for tool in obj.tools:
area_el = cascaded_union(obj.tools[tool]['solid_geometry']).convex_hull
area_chull.append(area_el.area)
area_chull = max(area_chull)
except Exception as e:
area_chull = None
log.debug("Properties.addItems() --> %s" % str(e))
self.area_finished.emit(area_chull, dims)
self.app.worker_task.emit({'fcn': job_thread, 'params': []})
self.addChild(units,
['FlatCAM units:',
@@ -294,4 +310,11 @@ class Properties(FlatCAMTool):
if column1 is not None:
item.setText(1, str(title[1]))
def show_area_chull(self, area, location):
if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower() == 'mm':
area_chull = area / 100
self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (area_chull, 'cm2')], True)
else:
area_chull = area
self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (area_chull, 'in2')], True)
# end of file