- Gerber Editor: fixed units conversion for obj.apertures keys that require it

This commit is contained in:
Marius Stanciu 2019-05-15 03:56:31 +03:00
parent c70309e802
commit 78939fdc84
4 changed files with 41 additions and 14 deletions

View File

@ -1428,6 +1428,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
yform=y_formatted)
# gerber_code += "D02*\n"
if 'clear' in geo_elem:
gerber_code += '%LPC*%\n'
@ -1461,7 +1462,8 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
else:
x_formatted, y_formatted = lz_format(coord[0], coord[1], factor)
gerber_code += "X{xform}Y{yform}D01*\n".format(xform=x_formatted,
yform=y_formatted)
yform=y_formatted)
# gerber_code += "D02*\n"
gerber_code += '%LPD*%\n'
except Exception as e:

View File

@ -15,6 +15,7 @@ CAD program, and create G-Code for Isolation routing.
- moved the self.apertures[aperture]['geometry'] processing for clear_geometry (geometry made with Gerber LPC command) in Gerber Editor
- Gerber Editor: fixed the Poligonize Tool to work with new geometric structure and took care of a special case
- Gerber Export is fixed to work with the new Gerber object data structure and it now works also for Gerber objects edited in Gerber Editor
- Gerber Editor: fixed units conversion for obj.apertures keys that require it
12.05.2019

View File

@ -1936,6 +1936,9 @@ class Gerber (Geometry):
}
'''
# store the file units here:
self.gerber_units = 'IN'
# aperture storage
self.apertures = {}
@ -2173,7 +2176,7 @@ class Gerber (Geometry):
path = []
# store the file units here:
gerber_units = 'IN'
self.gerber_units = 'IN'
# this is for temporary storage of solid geometry until it is added to poly_buffer
geo_s = None
@ -2323,8 +2326,8 @@ class Gerber (Geometry):
# Example: %MOIN*%
match = self.mode_re.search(gline)
if match:
gerber_units = match.group(1)
log.debug("Gerber units found = %s" % gerber_units)
self.gerber_units = match.group(1)
log.debug("Gerber units found = %s" % self.gerber_units)
# Changed for issue #80
self.convert_units(match.group(1))
continue
@ -2344,8 +2347,8 @@ class Gerber (Geometry):
"D-no zero suppression)" % self.gerber_zeros)
log.debug("Gerber format found. Coordinates type = %s (Absolute or Relative)" % absolute)
gerber_units = match.group(1)
log.debug("Gerber units found = %s" % gerber_units)
self.gerber_units = match.group(1)
log.debug("Gerber units found = %s" % self.gerber_units)
# Changed for issue #80
self.convert_units(match.group(5))
continue
@ -2370,8 +2373,8 @@ class Gerber (Geometry):
"D-no zerosuppressionn)" % self.gerber_zeros)
log.debug("Gerber format found. Coordinates type = %s (Absolute or Relative)" % absolute)
gerber_units = match.group(1)
log.debug("Gerber units found = %s" % gerber_units)
self.gerber_units = match.group(1)
log.debug("Gerber units found = %s" % self.gerber_units)
# Changed for issue #80
self.convert_units(match.group(5))
continue
@ -3123,7 +3126,7 @@ class Gerber (Geometry):
# TODO: make sure to keep track of units changes because right now it seems to happen in a weird way
# find out the conversion factor used to convert inside the self.apertures keys: size, width, height
file_units = gerber_units if gerber_units else 'IN'
file_units = self.gerber_units if self.gerber_units else 'IN'
app_units = self.app.defaults['units']
conversion_factor = 25.4 if file_units == 'IN' else (1/25.4) if file_units != app_units else 1
@ -3136,9 +3139,6 @@ class Gerber (Geometry):
# this treats the case when we are storing geometry as solids
log.warning("Joining %d polygons." % len(poly_buffer))
for td in self.apertures:
print(td, self.apertures[td])
if len(poly_buffer) == 0:
log.error("Object is not Gerber file or empty. Aborting Object creation.")
return 'fail'

View File

@ -2603,6 +2603,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
# 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.conversion_factor = 1
self.set_ui()
def pool_recreated(self, pool):
@ -2712,8 +2714,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
try:
if self.storage_dict[ap_code]['size'] is not None:
ap_size_item = QtWidgets.QTableWidgetItem('%.4f' %
float(self.storage_dict[ap_code]['size']))
ap_size_item = QtWidgets.QTableWidgetItem('%.4f' % float(
self.storage_dict[ap_code]['size']))
else:
ap_size_item = QtWidgets.QTableWidgetItem('')
except KeyError:
@ -3266,6 +3268,11 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.gerber_obj = orig_grb_obj
self.gerber_obj_options = orig_grb_obj.options
file_units = self.gerber_obj.gerber_units if self.gerber_obj.gerber_units else 'IN'
app_units = self.app.defaults['units']
self.conversion_factor = 25.4 if file_units == 'IN' else (1 / 25.4) if file_units != app_units else 1
# Hide original geometry
orig_grb_obj.visible = False
@ -3280,6 +3287,23 @@ class FlatCAMGrbEditor(QtCore.QObject):
except Exception as e:
log.debug("FlatCAMGrbEditor.edit_fcgerber() --> %s" % str(e))
# apply the conversion factor on the obj.apertures
conv_apertures = deepcopy(self.gerber_obj.apertures)
for apid in self.gerber_obj.apertures:
for key in self.gerber_obj.apertures[apid]:
if key == 'width':
conv_apertures[apid]['width'] = self.gerber_obj.apertures[apid]['width'] * self.conversion_factor
elif key == 'height':
conv_apertures[apid]['height'] = self.gerber_obj.apertures[apid]['height'] * self.conversion_factor
elif key == 'diam':
conv_apertures[apid]['diam'] = self.gerber_obj.apertures[apid]['diam'] * self.conversion_factor
elif key == 'size':
conv_apertures[apid]['size'] = self.gerber_obj.apertures[apid]['size'] * self.conversion_factor
else:
conv_apertures[apid][key] = self.gerber_obj.apertures[apid][key]
self.gerber_obj.apertures = conv_apertures
# ###############################################################
# APPLY CLEAR_GEOMETRY on the SOLID_GEOMETRY
# ###############################################################