- in Properties Tool fixed the dimensions calculations (length, width, area) to work for multi-geo objects
This commit is contained in:
parent
60512f09a7
commit
707a22c7a3
|
@ -19,6 +19,7 @@ CAD program, and create G-Code for Isolation routing.
|
|||
- 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
|
||||
- in Properties Tool fixed the dimensions calculations (length, width, area) to work for multi-geo objects
|
||||
|
||||
1.09.2019
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ if '_' not in builtins.__dict__:
|
|||
class Properties(FlatCAMTool):
|
||||
toolName = _("Properties")
|
||||
|
||||
area_finished = pyqtSignal(float, object)
|
||||
calculations_finished = pyqtSignal(float, float, float, float, object)
|
||||
|
||||
def __init__(self, app):
|
||||
FlatCAMTool.__init__(self, app)
|
||||
|
@ -65,7 +65,7 @@ class Properties(FlatCAMTool):
|
|||
self.vlay.addWidget(self.treeWidget)
|
||||
self.vlay.setStretch(0, 0)
|
||||
|
||||
self.area_finished.connect(self.show_area_chull)
|
||||
self.calculations_finished.connect(self.show_area_chull)
|
||||
|
||||
def run(self, toggle=True):
|
||||
self.app.report_usage("ToolProperties()")
|
||||
|
@ -149,36 +149,65 @@ class Properties(FlatCAMTool):
|
|||
|
||||
self.addChild(obj_name, [obj.options['name']])
|
||||
|
||||
def job_thread(obj):
|
||||
proc = self.app.proc_container.new(_("Calculating dimensions ... Please wait."))
|
||||
|
||||
length = 0.0
|
||||
width = 0.0
|
||||
area = 0.0
|
||||
|
||||
geo = obj.solid_geometry
|
||||
if geo:
|
||||
# calculate physical dimensions
|
||||
try:
|
||||
xmin, ymin, xmax, ymax = obj.bounds()
|
||||
|
||||
length = abs(xmax - xmin)
|
||||
width = abs(ymax - ymin)
|
||||
except Exception as e:
|
||||
log.debug("PropertiesTool.addItems() --> %s" % str(e))
|
||||
return
|
||||
|
||||
# calculate box area
|
||||
if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower() == 'mm':
|
||||
area = (length * width) / 100
|
||||
else:
|
||||
area = length * width
|
||||
else:
|
||||
xmin = []
|
||||
ymin = []
|
||||
xmax = []
|
||||
ymax = []
|
||||
|
||||
for tool in obj.tools:
|
||||
try:
|
||||
x0, y0, x1, y1 = cascaded_union(obj.tools[tool]['solid_geometry']).bounds
|
||||
xmin.append(x0)
|
||||
ymin.append(y0)
|
||||
xmax.append(x1)
|
||||
ymax.append(y1)
|
||||
except Exception as ee:
|
||||
log.debug("PropertiesTool.addItems() --> %s" % str(ee))
|
||||
|
||||
try:
|
||||
xmin = min(xmin)
|
||||
ymin = min(ymin)
|
||||
xmax = max(xmax)
|
||||
ymax = max(ymax)
|
||||
|
||||
length = abs(xmax - xmin)
|
||||
width = abs(ymax - ymin)
|
||||
|
||||
self.addChild(dims, ['%s:' % _('Length'), '%.4f %s' % (
|
||||
length, self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())], True)
|
||||
self.addChild(dims, ['%s:' % _('Width'), '%.4f %s' % (
|
||||
width, self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())], True)
|
||||
|
||||
# calculate and add box area
|
||||
# calculate box area
|
||||
if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower() == 'mm':
|
||||
area = (length * width) / 100
|
||||
self.addChild(dims, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'cm2')], True)
|
||||
else:
|
||||
area = length * width
|
||||
self.addChild(dims, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'in2')], True)
|
||||
except Exception as e:
|
||||
log.debug("Properties.addItems() --> %s" % str(e))
|
||||
|
||||
area_chull = 0.0
|
||||
if not isinstance(obj, FlatCAMCNCjob):
|
||||
|
||||
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
|
||||
|
@ -202,9 +231,12 @@ class Properties(FlatCAMTool):
|
|||
area_chull = None
|
||||
log.debug("Properties.addItems() --> %s" % str(e))
|
||||
|
||||
self.area_finished.emit(area_chull, dims)
|
||||
if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower() == 'mm':
|
||||
area_chull = area_chull / 100
|
||||
|
||||
self.app.worker_task.emit({'fcn': job_thread, 'params': []})
|
||||
self.calculations_finished.emit(area, length, width, area_chull, dims)
|
||||
|
||||
self.app.worker_task.emit({'fcn': job_thread, 'params': [obj]})
|
||||
|
||||
self.addChild(units,
|
||||
['FlatCAM units:',
|
||||
|
@ -310,11 +342,21 @@ class Properties(FlatCAMTool):
|
|||
if column1 is not None:
|
||||
item.setText(1, str(title[1]))
|
||||
|
||||
def show_area_chull(self, area, location):
|
||||
def show_area_chull(self, area, length, width, chull_area, location):
|
||||
|
||||
# add dimensions
|
||||
self.addChild(location, ['%s:' % _('Length'), '%.4f %s' % (
|
||||
length, self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())], True)
|
||||
self.addChild(location, ['%s:' % _('Width'), '%.4f %s' % (
|
||||
width, self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().lower())], True)
|
||||
|
||||
# add box area
|
||||
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)
|
||||
self.addChild(location, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'cm2')], True)
|
||||
self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (chull_area, 'cm2')], True)
|
||||
|
||||
else:
|
||||
area_chull = area
|
||||
self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (area_chull, 'in2')], True)
|
||||
self.addChild(location, ['%s:' % _('Box Area'), '%.4f %s' % (area, 'in2')], True)
|
||||
self.addChild(location, ['%s:' % _('Convex_Hull Area'), '%.4f %s' % (chull_area, 'in2')], True)
|
||||
|
||||
# end of file
|
||||
|
|
Loading…
Reference in New Issue