- fixed an issue in Gerber Editor where the multiprocessing pool was reported as closed and an ValueError exception was raised in a certain scneraio

This commit is contained in:
Marius Stanciu
2020-02-19 16:57:36 +02:00
parent f8f337526d
commit 6a24c8e204
2 changed files with 112 additions and 78 deletions

View File

@@ -12,6 +12,7 @@ CAD program, and create G-Code for Isolation routing.
19.02.2020 19.02.2020
- fixed some issues in the Geometry Editor; the jump sigmal disconnect was failing for repeated Editor tool operation - fixed some issues in the Geometry Editor; the jump sigmal disconnect was failing for repeated Editor tool operation
- fixed an issue in Gerber Editor where the multiprocessing pool was reported as closed and an ValueError exception was raised in a certain scneraio
17.02.2020 17.02.2020

View File

@@ -3045,6 +3045,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
# A QTimer # A QTimer
self.plot_thread = None self.plot_thread = None
# a QThread for the edit process
self.thread = QtCore.QThread()
# store the status of the editor so the Delete at object level will not work until the edit is finished # store the status of the editor so the Delete at object level will not work until the edit is finished
self.editor_active = False self.editor_active = False
@@ -3106,6 +3109,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
def pool_recreated(self, pool): def pool_recreated(self, pool):
self.shapes.pool = pool self.shapes.pool = pool
self.tool_shape.pool = pool self.tool_shape.pool = pool
self.pool = pool
def set_ui(self): def set_ui(self):
# updated units # updated units
@@ -3927,6 +3931,18 @@ class FlatCAMGrbEditor(QtCore.QObject):
# # and add the first aperture to have something to play with # # and add the first aperture to have something to play with
# self.on_aperture_add('10') # self.on_aperture_add('10')
# self.app.worker_task.emit({'fcn': worker_job, 'params': [self]})
class Execute_Edit(QtCore.QObject):
start = QtCore.pyqtSignal(str)
def __init__(self, app):
super(Execute_Edit, self).__init__()
self.app = app
self.start.connect(self.run)
@staticmethod
def worker_job(app_obj): def worker_job(app_obj):
with app_obj.app.proc_container.new('%s ...' % _("Loading Gerber into Editor")): with app_obj.app.proc_container.new('%s ...' % _("Loading Gerber into Editor")):
# ############################################################# ## # ############################################################# ##
@@ -3934,7 +3950,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
# ############################################################# ## # ############################################################# ##
# list of clear geos that are to be applied to the entire file # list of clear geos that are to be applied to the entire file
global_clear_geo = [] global_clear_geo = list()
# create one big geometry made out of all 'negative' (clear) polygons # create one big geometry made out of all 'negative' (clear) polygons
for apid in app_obj.gerber_obj.apertures: for apid in app_obj.gerber_obj.apertures:
@@ -3945,6 +3961,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
global_clear_geo.append(elem['clear']) global_clear_geo.append(elem['clear'])
log.warning("Found %d clear polygons." % len(global_clear_geo)) log.warning("Found %d clear polygons." % len(global_clear_geo))
if global_clear_geo:
global_clear_geo = MultiPolygon(global_clear_geo) global_clear_geo = MultiPolygon(global_clear_geo)
if isinstance(global_clear_geo, Polygon): if isinstance(global_clear_geo, Polygon):
global_clear_geo = list(global_clear_geo) global_clear_geo = list(global_clear_geo)
@@ -3952,7 +3969,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
# we subtract the big "negative" (clear) geometry from each solid polygon but only the part of # we subtract the big "negative" (clear) geometry from each solid polygon but only the part of
# clear geometry that fits inside the solid. otherwise we may loose the solid # clear geometry that fits inside the solid. otherwise we may loose the solid
for apid in app_obj.gerber_obj.apertures: for apid in app_obj.gerber_obj.apertures:
temp_solid_geometry = [] temp_solid_geometry = list()
if 'geometry' in app_obj.gerber_obj.apertures[apid]: if 'geometry' in app_obj.gerber_obj.apertures[apid]:
# for elem in self.gerber_obj.apertures[apid]['geometry']: # for elem in self.gerber_obj.apertures[apid]['geometry']:
# if 'solid' in elem: # if 'solid' in elem:
@@ -3985,11 +4002,13 @@ class FlatCAMGrbEditor(QtCore.QObject):
new_elem = dict() new_elem = dict()
if 'solid' in elem: if 'solid' in elem:
solid_geo = elem['solid'] solid_geo = elem['solid']
if not global_clear_geo or global_clear_geo.is_empty:
pass
else:
for clear_geo in global_clear_geo: for clear_geo in global_clear_geo:
# Make sure that the clear_geo is within the solid_geo otherwise we loose # Make sure that the clear_geo is within the solid_geo otherwise we loose
# the solid_geometry. We want for clear_geometry just to cut into solid_geometry # the solid_geometry. We want for clear_geometry just to cut into
# not to delete it # solid_geometry not to delete it
if clear_geo.within(solid_geo): if clear_geo.within(solid_geo):
solid_geo = solid_geo.difference(clear_geo) solid_geo = solid_geo.difference(clear_geo)
@@ -4003,9 +4022,16 @@ class FlatCAMGrbEditor(QtCore.QObject):
app_obj.gerber_obj.apertures[apid]['geometry'] = deepcopy(temp_solid_geometry) app_obj.gerber_obj.apertures[apid]['geometry'] = deepcopy(temp_solid_geometry)
log.warning("Polygon difference done for %d apertures." % len(app_obj.gerber_obj.apertures)) log.warning("Polygon difference done for %d apertures." % len(app_obj.gerber_obj.apertures))
try:
# Loading the Geometry into Editor Storage # Loading the Geometry into Editor Storage
for ap_id, ap_dict in app_obj.gerber_obj.apertures.items(): for ap_id, ap_dict in app_obj.gerber_obj.apertures.items():
app_obj.results.append(app_obj.pool.apply_async(app_obj.add_apertures, args=(ap_id, ap_dict))) app_obj.results.append(
app_obj.pool.apply_async(app_obj.add_apertures, args=(ap_id, ap_dict))
)
except Exception as e:
log.debug(
"FlatCAMGrbEditor.edit_fcgerber.worker_job() Adding processes to pool --> %s" % str(e))
traceback.print_exc()
output = list() output = list()
for p in app_obj.results: for p in app_obj.results:
@@ -4016,7 +4042,14 @@ class FlatCAMGrbEditor(QtCore.QObject):
app_obj.mp_finished.emit(output) app_obj.mp_finished.emit(output)
self.app.worker_task.emit({'fcn': worker_job, 'params': [self]}) def run(self):
self.worker_job(self.app)
self.thread.start(QtCore.QThread.NormalPriority)
executable_edit = Execute_Edit(app=self)
executable_edit.moveToThread(self.thread)
executable_edit.start.emit("Started")
@staticmethod @staticmethod
def add_apertures(aperture_id, aperture_dict): def add_apertures(aperture_id, aperture_dict):