- optimized FlatCAMObj.add_properties_items() method
This commit is contained in:
@@ -26,6 +26,7 @@ CHANGELOG for FlatCAM beta
|
|||||||
- compacted the UI for the 2Sided Tool
|
- compacted the UI for the 2Sided Tool
|
||||||
- added a button in Excellon UI that will hide/show the milling section
|
- added a button in Excellon UI that will hide/show the milling section
|
||||||
- optimized a bit the UI for Gerber/Excellon/Geometry objects
|
- optimized a bit the UI for Gerber/Excellon/Geometry objects
|
||||||
|
- optimized FlatCAMObj.add_properties_items() method
|
||||||
|
|
||||||
20.10.2020
|
20.10.2020
|
||||||
|
|
||||||
|
|||||||
@@ -1763,6 +1763,22 @@ class GeometryObjectUI(ObjectUI):
|
|||||||
)
|
)
|
||||||
self.grid4.addWidget(self.tools_label, 28, 0, 1, 2)
|
self.grid4.addWidget(self.tools_label, 28, 0, 1, 2)
|
||||||
|
|
||||||
|
# Milling Tool - will create GCode for slot holes
|
||||||
|
self.milling_button = QtWidgets.QPushButton(_('Milling Tool'))
|
||||||
|
self.milling_button.setIcon(QtGui.QIcon(self.app.resource_location + '/milling_tool32.png'))
|
||||||
|
self.milling_button.setToolTip(
|
||||||
|
_("Generate a CNCJob by milling a Geometry.")
|
||||||
|
)
|
||||||
|
self.milling_button.setStyleSheet("""
|
||||||
|
QPushButton
|
||||||
|
{
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
self.grid4.addWidget(self.milling_button, 30, 0, 1, 2)
|
||||||
|
# FIXME: until the Milling Tool is ready, this get disabled
|
||||||
|
self.milling_button.setDisabled(True)
|
||||||
|
|
||||||
# Paint Button
|
# Paint Button
|
||||||
self.paint_tool_button = QtWidgets.QPushButton(_('Paint Tool'))
|
self.paint_tool_button = QtWidgets.QPushButton(_('Paint Tool'))
|
||||||
self.paint_tool_button.setIcon(QtGui.QIcon(self.app.resource_location + '/paint20_1.png'))
|
self.paint_tool_button.setIcon(QtGui.QIcon(self.app.resource_location + '/paint20_1.png'))
|
||||||
@@ -1774,13 +1790,13 @@ class GeometryObjectUI(ObjectUI):
|
|||||||
"to click on the desired polygon."
|
"to click on the desired polygon."
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.paint_tool_button.setStyleSheet("""
|
# self.paint_tool_button.setStyleSheet("""
|
||||||
QPushButton
|
# QPushButton
|
||||||
{
|
# {
|
||||||
font-weight: bold;
|
# font-weight: bold;
|
||||||
}
|
# }
|
||||||
""")
|
# """)
|
||||||
self.grid4.addWidget(self.paint_tool_button, 30, 0, 1, 2)
|
self.grid4.addWidget(self.paint_tool_button, 32, 0, 1, 2)
|
||||||
|
|
||||||
# NCC Tool
|
# NCC Tool
|
||||||
self.generate_ncc_button = QtWidgets.QPushButton(_('NCC Tool'))
|
self.generate_ncc_button = QtWidgets.QPushButton(_('NCC Tool'))
|
||||||
@@ -1795,7 +1811,7 @@ class GeometryObjectUI(ObjectUI):
|
|||||||
# font-weight: bold;
|
# font-weight: bold;
|
||||||
# }
|
# }
|
||||||
# """)
|
# """)
|
||||||
self.grid4.addWidget(self.generate_ncc_button, 32, 0, 1, 2)
|
self.grid4.addWidget(self.generate_ncc_button, 34, 0, 1, 2)
|
||||||
|
|
||||||
|
|
||||||
class CNCObjectUI(ObjectUI):
|
class CNCObjectUI(ObjectUI):
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
length = abs(xmax - xmin)
|
length = abs(xmax - xmin)
|
||||||
width = abs(ymax - ymin)
|
width = abs(ymax - ymin)
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
log.debug("FlatCAMObj.addItems() -> calculate dimensions --> %s" % str(ee))
|
log.debug("FlatCAMObj.add_properties_items() -> calculate dimensions --> %s" % str(ee))
|
||||||
|
|
||||||
# calculate box area
|
# calculate box area
|
||||||
if self.app.defaults['units'].lower() == 'mm':
|
if self.app.defaults['units'].lower() == 'mm':
|
||||||
@@ -531,7 +531,7 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
else:
|
else:
|
||||||
area = length * width
|
area = length * width
|
||||||
|
|
||||||
if obj_prop.kind.lower() == 'gerber':
|
if obj_prop.kind.lower() == 'gerber' and geo:
|
||||||
# calculate copper area
|
# calculate copper area
|
||||||
try:
|
try:
|
||||||
for geo_el in geo:
|
for geo_el in geo:
|
||||||
@@ -554,7 +554,7 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
xmax.append(x1)
|
xmax.append(x1)
|
||||||
ymax.append(y1)
|
ymax.append(y1)
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
log.debug("FlatCAMObj.addItems() --> %s" % str(ee))
|
log.debug("FlatCAMObj.add_properties_items() cncjob --> %s" % str(ee))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for tool_k in obj_prop.cnc_tools:
|
for tool_k in obj_prop.cnc_tools:
|
||||||
@@ -564,19 +564,24 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
xmax.append(x1)
|
xmax.append(x1)
|
||||||
ymax.append(y1)
|
ymax.append(y1)
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
log.debug("FlatCAMObj.addItems() --> %s" % str(ee))
|
log.debug("FlatCAMObj.add_properties_items() cncjob --> %s" % str(ee))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
for tool_k in obj_prop.tools:
|
if obj_prop.tools:
|
||||||
x0, y0, x1, y1 = unary_union(obj_prop.tools[tool_k]['solid_geometry']).bounds
|
for tool_k in obj_prop.tools:
|
||||||
xmin.append(x0)
|
t_geo = obj_prop.tools[tool_k]['solid_geometry']
|
||||||
ymin.append(y0)
|
try:
|
||||||
xmax.append(x1)
|
x0, y0, x1, y1 = unary_union(t_geo).bounds
|
||||||
ymax.append(y1)
|
except Exception:
|
||||||
|
continue
|
||||||
|
xmin.append(x0)
|
||||||
|
ymin.append(y0)
|
||||||
|
xmax.append(x1)
|
||||||
|
ymax.append(y1)
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
log.debug("FlatCAMObj.addItems() --> %s" % str(ee))
|
log.debug("FlatCAMObj.add_properties_items() not cncjob tools --> %s" % str(ee))
|
||||||
|
|
||||||
try:
|
if xmin and ymin and xmax and ymax:
|
||||||
xmin = min(xmin)
|
xmin = min(xmin)
|
||||||
ymin = min(ymin)
|
ymin = min(ymin)
|
||||||
xmax = max(xmax)
|
xmax = max(xmax)
|
||||||
@@ -591,24 +596,20 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
else:
|
else:
|
||||||
area = length * width
|
area = length * width
|
||||||
|
|
||||||
if obj_prop.kind.lower() == 'gerber':
|
if obj_prop.kind.lower() == 'gerber' and obj_prop.tools:
|
||||||
# calculate copper area
|
# calculate copper area
|
||||||
|
|
||||||
# create a complete solid_geometry from the tools
|
# create a complete solid_geometry from the tools
|
||||||
geo_tools = []
|
geo_tools = []
|
||||||
for tool_k in obj_prop.tools:
|
for tool_k in obj_prop.tools:
|
||||||
if 'solid_geometry' in obj_prop.tools[tool_k]:
|
if 'solid_geometry' in obj_prop.tools[tool_k]:
|
||||||
for geo_el in obj_prop.tools[tool_k]['solid_geometry']:
|
for geo_el in obj_prop.tools[tool_k]['solid_geometry']:
|
||||||
geo_tools.append(geo_el)
|
geo_tools.append(geo_el)
|
||||||
|
|
||||||
try:
|
for geo_el in geo_tools:
|
||||||
for geo_el in geo_tools:
|
copper_area += geo_el.area
|
||||||
copper_area += geo_el.area
|
# in cm2
|
||||||
except TypeError:
|
copper_area /= 100
|
||||||
copper_area += geo_tools.area
|
|
||||||
copper_area /= 100
|
|
||||||
except Exception as err:
|
|
||||||
log.debug("FlatCAMObj.addItems() --> %s" % str(err))
|
|
||||||
|
|
||||||
area_chull = 0.0
|
area_chull = 0.0
|
||||||
if obj_prop.kind.lower() != 'cncjob':
|
if obj_prop.kind.lower() != 'cncjob':
|
||||||
@@ -630,14 +631,16 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
area_chull = 0
|
area_chull = 0
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
area_chull = []
|
area_chull = None
|
||||||
for tool_k in obj_prop.tools:
|
if obj_prop.tools:
|
||||||
area_el = unary_union(obj_prop.tools[tool_k]['solid_geometry']).convex_hull
|
area_chull_list = []
|
||||||
area_chull.append(area_el.area)
|
for tool_k in obj_prop.tools:
|
||||||
area_chull = max(area_chull)
|
area_el = unary_union(obj_prop.tools[tool_k]['solid_geometry']).convex_hull
|
||||||
|
area_chull_list.append(area_el.area)
|
||||||
|
area_chull = max(area_chull_list)
|
||||||
except Exception as er:
|
except Exception as er:
|
||||||
area_chull = None
|
area_chull = None
|
||||||
log.debug("FlatCAMObj.addItems() --> %s" % str(er))
|
log.debug("FlatCAMObj.add_properties_items() area chull--> %s" % str(er))
|
||||||
|
|
||||||
if self.app.defaults['units'].lower() == 'mm' and area_chull:
|
if self.app.defaults['units'].lower() == 'mm' and area_chull:
|
||||||
area_chull = area_chull / 100
|
area_chull = area_chull / 100
|
||||||
@@ -656,7 +659,7 @@ class FlatCAMObj(QtCore.QObject):
|
|||||||
self.treeWidget.addChild(options, [str(option), str(obj.options[option])], True)
|
self.treeWidget.addChild(options, [str(option), str(obj.options[option])], True)
|
||||||
|
|
||||||
# Items that depend on the object type
|
# Items that depend on the object type
|
||||||
if obj.kind.lower() == 'gerber':
|
if obj.kind.lower() == 'gerber' and obj.apertures:
|
||||||
temp_ap = {}
|
temp_ap = {}
|
||||||
for ap in obj.apertures:
|
for ap in obj.apertures:
|
||||||
temp_ap.clear()
|
temp_ap.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user