2019-05-30 18:05:12 +00:00
|
|
|
# ########################################################## ##
|
2019-03-10 13:22:16 +00:00
|
|
|
# FlatCAM: 2D Post-processing for Manufacturing #
|
|
|
|
# http://flatcam.org #
|
|
|
|
# File Author: Marius Adrian Stanciu (c) #
|
|
|
|
# Date: 3/10/2019 #
|
|
|
|
# MIT Licence #
|
2019-05-30 18:05:12 +00:00
|
|
|
# ########################################################## ##
|
2019-03-10 13:22:16 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
from PyQt5 import QtGui, QtCore, QtWidgets
|
|
|
|
from PyQt5.QtCore import Qt
|
|
|
|
from FlatCAMTool import FlatCAMTool
|
|
|
|
from FlatCAMObj import *
|
2019-03-07 16:04:11 +00:00
|
|
|
|
2019-03-07 23:32:18 +00:00
|
|
|
import gettext
|
|
|
|
import FlatCAMTranslation as fcTranslate
|
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
|
|
|
import builtins
|
|
|
|
if '_' not in builtins.__dict__:
|
|
|
|
_ = gettext.gettext
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Properties(FlatCAMTool):
|
|
|
|
|
2019-03-10 12:34:13 +00:00
|
|
|
toolName = _("Properties")
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def __init__(self, app):
|
|
|
|
FlatCAMTool.__init__(self, app)
|
|
|
|
|
|
|
|
self.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Ignored)
|
|
|
|
|
|
|
|
# this way I can hide/show the frame
|
|
|
|
self.properties_frame = QtWidgets.QFrame()
|
|
|
|
self.properties_frame.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.layout.addWidget(self.properties_frame)
|
|
|
|
self.properties_box = QtWidgets.QVBoxLayout()
|
|
|
|
self.properties_box.setContentsMargins(0, 0, 0, 0)
|
|
|
|
self.properties_frame.setLayout(self.properties_box)
|
|
|
|
|
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.properties_box.addWidget(title_label)
|
|
|
|
|
|
|
|
# self.layout.setMargin(0) # PyQt4
|
|
|
|
self.properties_box.setContentsMargins(0, 0, 0, 0) # PyQt5
|
|
|
|
|
|
|
|
self.vlay = QtWidgets.QVBoxLayout()
|
|
|
|
|
|
|
|
self.properties_box.addLayout(self.vlay)
|
|
|
|
|
|
|
|
self.treeWidget = QtWidgets.QTreeWidget()
|
|
|
|
self.treeWidget.setColumnCount(2)
|
|
|
|
self.treeWidget.setHeaderHidden(True)
|
|
|
|
self.treeWidget.header().setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
|
|
|
|
self.treeWidget.setSizePolicy(QtWidgets.QSizePolicy.Ignored, QtWidgets.QSizePolicy.Expanding)
|
|
|
|
|
|
|
|
self.vlay.addWidget(self.treeWidget)
|
|
|
|
self.vlay.setStretch(0,0)
|
|
|
|
|
2019-03-10 15:12:58 +00:00
|
|
|
def run(self, toggle=True):
|
2019-02-03 21:08:09 +00:00
|
|
|
self.app.report_usage("ToolProperties()")
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
if self.app.tool_tab_locked is True:
|
|
|
|
return
|
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:
|
|
|
|
self.app.ui.splitter.setSizes([0, 1])
|
|
|
|
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
|
|
|
|
|
|
|
FlatCAMTool.run(self)
|
2019-02-02 16:26:01 +00:00
|
|
|
self.set_tool_ui()
|
2019-02-12 02:00:11 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
self.properties()
|
|
|
|
|
2019-01-27 01:32:09 +00:00
|
|
|
def install(self, icon=None, separator=None, **kwargs):
|
|
|
|
FlatCAMTool.install(self, icon, separator, shortcut='P', **kwargs)
|
|
|
|
|
2019-02-02 16:26:01 +00:00
|
|
|
def set_tool_ui(self):
|
|
|
|
# this reset the TreeWidget
|
|
|
|
self.treeWidget.clear()
|
|
|
|
self.properties_frame.show()
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
def properties(self):
|
|
|
|
obj_list = self.app.collection.get_selected()
|
|
|
|
if not obj_list:
|
2019-03-10 12:34:13 +00:00
|
|
|
self.app.inform.emit(_("[ERROR_NOTCL] Properties Tool was not displayed. No object selected."))
|
|
|
|
self.app.ui.notebook.setTabText(2, _("Tools"))
|
2019-01-03 19:25:08 +00:00
|
|
|
self.properties_frame.hide()
|
|
|
|
self.app.ui.notebook.setCurrentWidget(self.app.ui.project_tab)
|
|
|
|
return
|
|
|
|
for obj in obj_list:
|
|
|
|
self.addItems(obj)
|
2019-03-10 12:34:13 +00:00
|
|
|
self.app.inform.emit(_("[success] Object Properties are displayed."))
|
|
|
|
self.app.ui.notebook.setTabText(2, _("Properties Tool"))
|
2019-01-03 19:25:08 +00:00
|
|
|
|
|
|
|
def addItems(self, obj):
|
|
|
|
parent = self.treeWidget.invisibleRootItem()
|
|
|
|
|
|
|
|
font = QtGui.QFont()
|
|
|
|
font.setBold(True)
|
|
|
|
obj_type = self.addParent(parent, 'TYPE', expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
obj_name = self.addParent(parent, 'NAME', expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
dims = self.addParent(parent, 'Dimensions', expanded=True, color=QtGui.QColor("#000000"), font=font)
|
2019-02-23 14:02:45 +00:00
|
|
|
units = self.addParent(parent, 'Units', expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
options = self.addParent(parent, 'Options', color=QtGui.QColor("#000000"), font=font)
|
2019-02-23 14:02:45 +00:00
|
|
|
if obj.kind.lower() == 'gerber':
|
|
|
|
apertures = self.addParent(parent, 'Apertures', expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
else:
|
|
|
|
tools = self.addParent(parent, 'Tools', expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
separator = self.addParent(parent, '')
|
|
|
|
|
2019-02-23 14:02:45 +00:00
|
|
|
self.addChild(obj_type, ['Object Type:', ('%s' % (obj.kind.capitalize()))], True)
|
|
|
|
try:
|
|
|
|
self.addChild(obj_type, ['Geo Type:', ('%s' % ({False: "Single-Geo", True: "Multi-Geo"}[obj.multigeo]))], True)
|
|
|
|
except Exception as e:
|
|
|
|
pass
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
self.addChild(obj_name, [obj.options['name']])
|
|
|
|
|
|
|
|
# calculate physical dimensions
|
2019-02-23 14:02:45 +00:00
|
|
|
try:
|
|
|
|
xmin, ymin, xmax, ymax = obj.bounds()
|
|
|
|
except Exception as e:
|
|
|
|
log.debug("PropertiesTool.addItems() --> %s" % str(e))
|
|
|
|
return
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
length = abs(xmax - xmin)
|
|
|
|
width = abs(ymax - ymin)
|
|
|
|
|
|
|
|
self.addChild(dims, ['Length:', '%.4f %s' % (
|
2019-03-04 01:47:19 +00:00
|
|
|
length, self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())], True)
|
2019-01-03 19:25:08 +00:00
|
|
|
self.addChild(dims, ['Width:', '%.4f %s' % (
|
2019-03-04 01:47:19 +00:00
|
|
|
width, self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())], True)
|
|
|
|
if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower() == 'mm':
|
2019-01-03 19:25:08 +00:00
|
|
|
area = (length * width) / 100
|
|
|
|
self.addChild(dims, ['Box Area:', '%.4f %s' % (area, 'cm2')], True)
|
|
|
|
else:
|
|
|
|
area = length * width
|
|
|
|
self.addChild(dims, ['Box Area:', '%.4f %s' % (area, 'in2')], True)
|
|
|
|
|
2019-02-23 14:02:45 +00:00
|
|
|
self.addChild(units,
|
|
|
|
['FlatCAM units:',
|
|
|
|
{
|
|
|
|
'in': 'Inch',
|
|
|
|
'mm': 'Metric'
|
|
|
|
}
|
2019-03-04 01:47:19 +00:00
|
|
|
[str(self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())]], True)
|
2019-02-23 14:02:45 +00:00
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
for option in obj.options:
|
|
|
|
if option is 'name':
|
|
|
|
continue
|
|
|
|
self.addChild(options, [str(option), str(obj.options[option])], True)
|
|
|
|
|
2019-02-23 14:02:45 +00:00
|
|
|
if obj.kind.lower() == 'gerber':
|
2019-03-11 01:31:33 +00:00
|
|
|
temp_ap = {}
|
2019-02-23 14:02:45 +00:00
|
|
|
for ap in obj.apertures:
|
2019-03-11 01:31:33 +00:00
|
|
|
temp_ap.clear()
|
|
|
|
temp_ap = deepcopy(obj.apertures[ap])
|
2019-05-17 21:17:37 +00:00
|
|
|
temp_ap.pop('geometry', None)
|
|
|
|
if obj.apertures[ap]['geometry']:
|
|
|
|
solid_nr = 0
|
|
|
|
follow_nr = 0
|
|
|
|
clear_nr = 0
|
|
|
|
|
|
|
|
for el in obj.apertures[ap]['geometry']:
|
|
|
|
if 'solid' in el:
|
|
|
|
solid_nr += 1
|
|
|
|
if 'follow' in el:
|
|
|
|
follow_nr += 1
|
|
|
|
if 'clear' in el:
|
|
|
|
clear_nr += 1
|
|
|
|
temp_ap['Solid_Geo'] = '%s Polygons' % str(solid_nr)
|
2019-05-18 15:22:02 +00:00
|
|
|
temp_ap['Follow_Geo'] = '%s LineStrings' % str(follow_nr)
|
2019-05-17 21:17:37 +00:00
|
|
|
temp_ap['Clear_Geo'] = '%s Polygons' % str(clear_nr)
|
|
|
|
|
|
|
|
apid = self.addParent(apertures, str(ap), expanded=False, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
for key in temp_ap:
|
|
|
|
self.addChild(apid, [str(key), str(temp_ap[key])], True)
|
|
|
|
|
2019-02-23 14:02:45 +00:00
|
|
|
elif obj.kind.lower() == 'excellon':
|
|
|
|
for tool, value in obj.tools.items():
|
|
|
|
self.addChild(tools, [str(tool), str(value['C'])], True)
|
|
|
|
elif obj.kind.lower() == 'geometry':
|
|
|
|
for tool, value in obj.tools.items():
|
|
|
|
geo_tool = self.addParent(tools, str(tool), expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
for k, v in value.items():
|
|
|
|
if k == 'solid_geometry':
|
|
|
|
printed_value = 'Present' if v else 'None'
|
|
|
|
self.addChild(geo_tool, [str(k), printed_value], True)
|
|
|
|
elif k == 'data':
|
2019-03-03 14:35:15 +00:00
|
|
|
tool_data = self.addParent(geo_tool, str(k).capitalize(),
|
2019-02-23 14:02:45 +00:00
|
|
|
color=QtGui.QColor("#000000"), font=font)
|
|
|
|
for data_k, data_v in v.items():
|
|
|
|
self.addChild(tool_data, [str(data_k), str(data_v)], True)
|
|
|
|
else:
|
|
|
|
self.addChild(geo_tool, [str(k), str(v)], True)
|
|
|
|
elif obj.kind.lower() == 'cncjob':
|
|
|
|
for tool, value in obj.cnc_tools.items():
|
|
|
|
geo_tool = self.addParent(tools, str(tool), expanded=True, color=QtGui.QColor("#000000"), font=font)
|
|
|
|
for k, v in value.items():
|
|
|
|
if k == 'solid_geometry':
|
|
|
|
printed_value = 'Present' if v else 'None'
|
|
|
|
self.addChild(geo_tool, [str(k), printed_value], True)
|
|
|
|
elif k == 'gcode':
|
|
|
|
printed_value = 'Present' if v != '' else 'None'
|
|
|
|
self.addChild(geo_tool, [str(k), printed_value], True)
|
|
|
|
elif k == 'gcode_parsed':
|
|
|
|
printed_value = 'Present' if v else 'None'
|
|
|
|
self.addChild(geo_tool, [str(k), printed_value], True)
|
|
|
|
elif k == 'data':
|
|
|
|
tool_data = self.addParent(geo_tool, str(k).capitalize(),
|
|
|
|
color=QtGui.QColor("#000000"), font=font)
|
|
|
|
for data_k, data_v in v.items():
|
|
|
|
self.addChild(tool_data, [str(data_k), str(data_v)], True)
|
|
|
|
else:
|
|
|
|
self.addChild(geo_tool, [str(k), str(v)], True)
|
|
|
|
|
2019-01-03 19:25:08 +00:00
|
|
|
self.addChild(separator, [''])
|
|
|
|
|
|
|
|
def addParent(self, parent, title, expanded=False, color=None, font=None):
|
|
|
|
item = QtWidgets.QTreeWidgetItem(parent, [title])
|
|
|
|
item.setChildIndicatorPolicy(QtWidgets.QTreeWidgetItem.ShowIndicator)
|
|
|
|
item.setExpanded(expanded)
|
|
|
|
if color is not None:
|
|
|
|
# item.setTextColor(0, color) # PyQt4
|
|
|
|
item.setForeground(0, QtGui.QBrush(color))
|
|
|
|
if font is not None:
|
|
|
|
item.setFont(0, font)
|
|
|
|
return item
|
|
|
|
|
|
|
|
def addChild(self, parent, title, column1=None):
|
|
|
|
item = QtWidgets.QTreeWidgetItem(parent)
|
|
|
|
item.setText(0, str(title[0]))
|
|
|
|
if column1 is not None:
|
|
|
|
item.setText(1, str(title[1]))
|
|
|
|
|
|
|
|
# end of file
|