- added the Gerber code as source for the panelized object in Panelize Tool

- whenever a Gerber file is deleted, the mark_shapes objects are deleted also
This commit is contained in:
Marius Stanciu 2019-09-11 04:54:30 +03:00 committed by Marius
parent a348bc8738
commit 91cad9c57d
5 changed files with 52 additions and 24 deletions

View File

@ -5734,7 +5734,8 @@ class App(QtCore.QObject):
for el in obj_active.mark_shapes:
obj_active.mark_shapes[el].clear(update=True)
obj_active.mark_shapes[el].enabled = False
obj_active.mark_shapes[el] = None
# obj_active.mark_shapes[el] = None
del el
elif isinstance(obj_active, FlatCAMCNCjob):
try:
obj_active.annotation.clear(update=True)
@ -8557,12 +8558,14 @@ class App(QtCore.QObject):
_('Could not export Excellon file.'))
return
def export_gerber(self, obj_name, filename, use_thread=True):
def export_gerber(self, obj_name, filename, local_use=None, use_thread=True):
"""
Exports a Gerber Object to an Gerber file.
:param obj_name: the name of the FlatCAM object to be saved as Gerber
:param filename: Path to the Gerber file to save to.
:param local_use: if the Gerber code is to be saved to a file (None) or used within FlatCAM.
When not None, the value will be the actual Gerber object for which to create the Gerber code
:param use_thread: if to be run in a separate thread
:return:
"""
@ -8573,11 +8576,14 @@ class App(QtCore.QObject):
self.log.debug("export_gerber()")
try:
obj = self.collection.get_by_name(str(obj_name))
except:
# TODO: The return behavior has not been established... should raise exception?
return "Could not retrieve object: %s" % obj_name
if local_use is None:
try:
obj = self.collection.get_by_name(str(obj_name))
except:
# TODO: The return behavior has not been established... should raise exception?
return "Could not retrieve object: %s" % obj_name
else:
obj = local_use
# updated units
gunits = self.defaults["gerber_exp_units"]
@ -8649,26 +8655,28 @@ class App(QtCore.QObject):
exported_gerber += gerber_code
exported_gerber += footer
try:
with open(filename, 'w') as fp:
fp.write(exported_gerber)
except PermissionError:
self.inform.emit('[WARNING] %s' %
_("Permission denied, saving not possible.\n"
"Most likely another app is holding the file open and not accessible."))
return 'fail'
if local_use is None:
try:
with open(filename, 'w') as fp:
fp.write(exported_gerber)
except PermissionError:
self.inform.emit('[WARNING] %s' %
_("Permission denied, saving not possible.\n"
"Most likely another app is holding the file open and not accessible."))
return 'fail'
if self.defaults["global_open_style"] is False:
self.file_opened.emit("Gerber", filename)
self.file_saved.emit("Gerber", filename)
self.inform.emit('[success] %s: %s' %
(_("Gerber file exported to"), filename))
if self.defaults["global_open_style"] is False:
self.file_opened.emit("Gerber", filename)
self.file_saved.emit("Gerber", filename)
self.inform.emit('[success] %s: %s' %
(_("Gerber file exported to"), filename))
else:
return exported_gerber
except Exception as e:
log.debug("App.export_gerber.make_gerber() --> %s" % str(e))
return 'fail'
if use_thread is True:
with self.proc_container.new(_("Exporting Gerber")) as proc:
def job_thread_grb(app_obj):
@ -8684,7 +8692,9 @@ class App(QtCore.QObject):
if ret == 'fail':
self.inform.emit('[ERROR_NOTCL] %s' %
_('Could not export Gerber file.'))
return
return 'fail'
if local_use is not None:
return ret
def export_dxf(self, obj_name, filename, use_thread=True):
"""

View File

@ -1519,7 +1519,12 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
def export_gerber(self, whole, fract, g_zeros='L', factor=1):
"""
Creates a Gerber file content to be exported to a file.
:param whole: how many digits in the whole part of coordinates
:param fract: how many decimals in coordinates
:param g_zeros: type of the zero suppression used: LZ or TZ; string
:param factor: factor to be applied onto the Gerber coordinates
:return: Gerber_code
"""
log.debug("FlatCAMGerber.export_gerber() --> Generating the Gerber code from the selected Gerber file")
@ -1670,7 +1675,6 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
for geo_elem in self.apertures[apid]['geometry']:
if 'follow' in geo_elem:
geo = geo_elem['follow']
print(geo)
if not geo.is_empty:
if isinstance(geo, Point):
if g_zeros == 'T':

View File

@ -9,6 +9,11 @@ CAD program, and create G-Code for Isolation routing.
=================================================
11.09.2019
- added the Gerber code as source for the panelized object in Panelize Tool
- whenever a Gerber file is deleted, the mark_shapes objects are deleted also
10.09.2019
- made isolation threaded

View File

@ -3395,6 +3395,7 @@ class Gerber (Geometry):
log.warning("Union done.")
if current_polarity == 'D':
self.app.inform.emit('%s' % _("Gerber processing. Applying Gerber polarity."))
try:
self.solid_geometry = self.solid_geometry.union(new_poly)
except Exception as e:

View File

@ -487,7 +487,7 @@ class Panelize(FlatCAMTool):
def panelize_2():
if panel_obj is not None:
self.app.inform.emit(_("Generating panel ... Please wait."))
self.app.inform.emit(_("Generating panel ... "))
self.app.progress.emit(0)
@ -771,6 +771,12 @@ class Panelize(FlatCAMTool):
currentx += lenghtx
currenty += lenghty
if panel_type == 'gerber':
self.app.inform.emit('%s %s' %
(_("Generating panel ..."), _("Adding the Gerber code.")))
obj_fin.source_file = self.app.export_gerber(obj_name=self.outname, filename=None,
local_use=obj_fin, use_thread=False)
# app_obj.log.debug("Found %s geometries. Creating a panel geometry cascaded union ..." %
# len(obj_fin.solid_geometry))
@ -778,6 +784,8 @@ class Panelize(FlatCAMTool):
# app_obj.log.debug("Finished creating a cascaded union for the panel.")
self.app.proc_container.update_view_text('')
self.app.inform.emit('%s %s: %d' %
(_("Generating panel ..."), _("Spawning copies"), (int(rows * columns))))
if isinstance(panel_obj, FlatCAMExcellon):
self.app.progress.emit(50)
self.app.new_object("excellon", self.outname, job_init_excellon, plot=True, autoselected=True)