- the application now uses only the default values from the app.options dict, the app.defaults dict holds the definitive default values

- fixed some outstanding issues from the PyQt6 port
- PEP8 fixes
- minor fixes
- updated the saving of Preferences to update the self.options too: the `Apply` action will update the self.options but the `Save` action will save the updated preferences to the file on disk
This commit is contained in:
Marius Stanciu
2022-02-18 23:06:58 +02:00
committed by Marius
parent 14d9ea5470
commit 65d8dcc0b2
92 changed files with 1881 additions and 1882 deletions

View File

@@ -82,7 +82,7 @@ class Gerber(Geometry):
# How to approximate a circle with lines.
if steps_per_circle is None:
self.steps_per_circle = int(self.app.defaults["gerber_circle_steps"])
self.steps_per_circle = int(self.app.options["gerber_circle_steps"])
else:
self.steps_per_circle = steps_per_circle
self.decimals = self.app.decimals
@@ -97,7 +97,7 @@ class Gerber(Geometry):
self.frac_digits = 4
"""Number of fraction digits in Gerber numbers. Used during parsing."""
self.gerber_zeros = self.app.defaults['gerber_def_zeros']
self.gerber_zeros = self.app.options['gerber_def_zeros']
"""Zeros in Gerber numbers. If 'L' then remove leading zeros, if 'T' remove trailing zeros. Used during parsing.
"""
@@ -121,7 +121,7 @@ class Gerber(Geometry):
'''
# store the file units here:
self.units = self.app.defaults['gerber_def_units']
self.units = self.app.options['gerber_def_units']
# aperture storage
self.tools = {}
@@ -231,7 +231,7 @@ class Gerber(Geometry):
# in a Gerber file (normal or obsolete ones)
self.conversion_done = False
self.use_buffer_for_union = self.app.defaults["gerber_use_buffer_for_union"]
self.use_buffer_for_union = self.app.options["gerber_use_buffer_for_union"]
# Attributes to be included in serialization
# Always append to it because it carries contents
@@ -441,7 +441,7 @@ class Gerber(Geometry):
line_num = 0
gline = ""
s_tol = float(self.app.defaults["gerber_simp_tolerance"])
s_tol = float(self.app.options["gerber_simp_tolerance"])
self.app.inform.emit('%s %d %s.' % (_("Gerber processing. Parsing"), len(glines), _("Lines").lower()))
try:
@@ -510,7 +510,7 @@ class Gerber(Geometry):
geo_dict['follow'] = geo_f
geo_s = LineString(path).buffer(width / 1.999, int(self.steps_per_circle))
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
if not geo_s.is_empty and geo_s.is_valid:
poly_buffer.append(geo_s)
@@ -579,7 +579,7 @@ class Gerber(Geometry):
self.app.log.debug("Gerber units found = %s" % self.units)
# Changed for issue #80
# self.convert_units(match.group(1))
s_tol = float(self.app.defaults["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
s_tol = float(self.app.options["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
self.conversion_done = True
continue
@@ -601,7 +601,7 @@ class Gerber(Geometry):
self.app.log.debug("Gerber format found. Coordinates type = %s (Absolute or Relative)" % absolute)
self.units = match.group(5)
s_tol = float(self.app.defaults["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
s_tol = float(self.app.options["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
self.app.log.debug("Gerber units found = %s" % self.units)
# Changed for issue #80
@@ -634,7 +634,7 @@ class Gerber(Geometry):
self.units = match.group(1)
s_tol = float(
self.app.defaults["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
self.app.options["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
self.app.log.debug("Gerber units found = %s" % self.units)
# Changed for issue #80
@@ -649,7 +649,7 @@ class Gerber(Geometry):
if match:
obs_gerber_units = {'0': 'IN', '1': 'MM'}[match.group(1)]
self.units = obs_gerber_units
s_tol = float(self.app.defaults["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
s_tol = float(self.app.options["gerber_simp_tolerance"]) / 25.4 if self.units == 'IN' else s_tol
self.app.log.warning("Gerber obsolete units found = %s" % obs_gerber_units)
# Changed for issue #80
@@ -731,7 +731,7 @@ class Gerber(Geometry):
geo_dict['follow'] = Point([current_x, current_y])
if not flash.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
flash = flash.simplify(s_tol)
poly_buffer.append(flash)
@@ -791,7 +791,7 @@ class Gerber(Geometry):
# --- Buffered ----
width = self.tools[last_path_aperture]["size"]
geo_s = LineString(path).buffer(width / 1.999, int(self.steps_per_circle))
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
if not geo_s.is_empty:
poly_buffer.append(geo_s)
@@ -848,7 +848,7 @@ class Gerber(Geometry):
for pol in geo_s:
if not pol.is_empty:
# is it possible that simplification creates an Empty Geometry ?????
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
pol = pol.simplify(s_tol)
poly_buffer.append(pol)
@@ -862,7 +862,7 @@ class Gerber(Geometry):
except TypeError:
if not geo_s.is_empty:
# is it possible that simplification creates an Empty Geometry ?????
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -911,7 +911,7 @@ class Gerber(Geometry):
geo_dict['follow'] = geo_f
if geo_s:
if not geo_s.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
if not geo_s.is_valid:
@@ -967,7 +967,7 @@ class Gerber(Geometry):
try:
for pol in region_s:
# is it possible that simplification creates an Empty Geometry ?????
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
pol = pol.simplify(s_tol)
pol_f = pol.exterior
@@ -986,7 +986,7 @@ class Gerber(Geometry):
self.tools[0]['geometry'].append(geo_dict)
except TypeError:
# is it possible that simplification creates an Empty Geometry ?????
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
region_s = region_s.simplify(s_tol)
region_f = region_s.exterior
@@ -1005,7 +1005,7 @@ class Gerber(Geometry):
self.tools[0]['geometry'].append(geo_dict)
else:
# is it possible that simplification creates an Empty Geometry ?????
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
region_s = region_s.simplify(s_tol)
region_f = region_s.exterior
@@ -1104,7 +1104,7 @@ class Gerber(Geometry):
self.steps_per_circle
)
if not flash.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
flash = flash.simplify(s_tol)
poly_buffer.append(flash)
@@ -1140,7 +1140,7 @@ class Gerber(Geometry):
geo_dict['follow'] = geo_f
geo_s = shply_box(minx, miny, maxx, maxy)
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -1237,7 +1237,7 @@ class Gerber(Geometry):
try:
if self.tools[last_path_aperture]["type"] != 'R':
if not geo_s.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -1248,7 +1248,7 @@ class Gerber(Geometry):
geo_dict['solid'] = geo_s
except Exception as e:
self.app.log.error("camlib.Gerber.parse_lines() --> %s" % str(e))
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -1305,7 +1305,7 @@ class Gerber(Geometry):
if not geo_s.is_empty:
try:
if self.tools[last_path_aperture]["type"] != 'R':
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -1315,7 +1315,7 @@ class Gerber(Geometry):
else:
geo_dict['solid'] = geo_s
except Exception:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -1350,7 +1350,7 @@ class Gerber(Geometry):
)
if not flash.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
flash = flash.simplify(s_tol)
poly_buffer.append(flash)
@@ -1463,7 +1463,7 @@ class Gerber(Geometry):
# this treats the case when we are storing geometry as solids
buffered = LineString(path).buffer(width / 1.999, int(self.steps_per_circle))
if not buffered.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
buffered = buffered.simplify(s_tol)
poly_buffer.append(buffered)
@@ -1616,7 +1616,7 @@ class Gerber(Geometry):
width = self.tools[last_path_aperture]["size"]
geo_s = LineString(path).buffer(width / 1.999, int(self.steps_per_circle))
if not geo_s.is_empty:
if self.app.defaults['gerber_simplification']:
if self.app.options['gerber_simplification']:
geo_s = geo_s.simplify(s_tol)
poly_buffer.append(geo_s)
@@ -1667,7 +1667,7 @@ class Gerber(Geometry):
self.app.log.debug("Union by buffer...")
new_poly = MultiPolygon(poly_buffer)
if self.app.defaults["gerber_buffering"] == 'full':
if self.app.options["gerber_buffering"] == 'full':
new_poly = new_poly.buffer(0.00000001)
new_poly = new_poly.buffer(-0.00000001)
self.app.log.warning("Union(buffer) done.")
@@ -1703,7 +1703,7 @@ class Gerber(Geometry):
# FIX for issue #347 - Sprint Layout generate Gerber files when the copper pour is enabled
# it use a filled bounding box polygon to which add clear polygons (negative) to isolate the copper
# features
if self.app.defaults['gerber_extra_buffering']:
if self.app.options['gerber_extra_buffering']:
candidate_geo = []
if isinstance(self.solid_geometry, MultiPolygon):
geo_to_buff = self.solid_geometry.geoms
@@ -1722,7 +1722,7 @@ class Gerber(Geometry):
# flatten the solid geometry
self.solid_geometry = flatten_shapely_geometry(self.solid_geometry)
if self.app.defaults['gerber_clean_apertures']:
if self.app.options['gerber_clean_apertures']:
# clean the Gerber file of apertures with no geometry
for apid, apvalue in list(self.tools.items()):
if 'geometry' not in apvalue:
@@ -1952,7 +1952,7 @@ class Gerber(Geometry):
h = svgparselength(svg_root.get('height'))[0] # TODO: No units support yet
units = self.app.app_units if units is None else units
res = self.app.defaults['gerber_circle_steps']
res = self.app.options['gerber_circle_steps']
factor = svgparse_viewbox(svg_root)
geos = getsvggeo(svg_root, 'gerber', units=units, res=res, factor=factor, app=self.app)

View File

@@ -41,7 +41,7 @@ class HPGL2:
self.app = app
# How to approximate a circle with lines.
self.steps_per_circle = int(self.app.defaults["geometry_circle_steps"])
self.steps_per_circle = int(self.app.options["geometry_circle_steps"])
self.decimals = self.app.decimals
# store the file units here
@@ -53,67 +53,67 @@ class HPGL2:
self.default_data = {}
self.default_data.update({
"name": '_ncc',
"plot": self.app.defaults["geometry_plot"],
"cutz": self.app.defaults["geometry_cutz"],
"vtipdia": self.app.defaults["tools_mill_vtipdia"],
"vtipangle": self.app.defaults["tools_mill_vtipangle"],
"travelz": self.app.defaults["geometry_travelz"],
"feedrate": self.app.defaults["geometry_feedrate"],
"feedrate_z": self.app.defaults["geometry_feedrate_z"],
"feedrate_rapid": self.app.defaults["geometry_feedrate_rapid"],
"dwell": self.app.defaults["geometry_dwell"],
"dwelltime": self.app.defaults["geometry_dwelltime"],
"multidepth": self.app.defaults["geometry_multidepth"],
"ppname_g": self.app.defaults["geometry_ppname_g"],
"depthperpass": self.app.defaults["geometry_depthperpass"],
"extracut": self.app.defaults["geometry_extracut"],
"extracut_length": self.app.defaults["geometry_extracut_length"],
"toolchange": self.app.defaults["geometry_toolchange"],
"toolchangez": self.app.defaults["geometry_toolchangez"],
"endz": self.app.defaults["geometry_endz"],
"endxy": self.app.defaults["geometry_endxy"],
"area_exclusion": self.app.defaults["geometry_area_exclusion"],
"area_shape": self.app.defaults["geometry_area_shape"],
"area_strategy": self.app.defaults["geometry_area_strategy"],
"area_overz": self.app.defaults["geometry_area_overz"],
"plot": self.app.options["geometry_plot"],
"cutz": self.app.options["geometry_cutz"],
"vtipdia": self.app.options["tools_mill_vtipdia"],
"vtipangle": self.app.options["tools_mill_vtipangle"],
"travelz": self.app.options["geometry_travelz"],
"feedrate": self.app.options["geometry_feedrate"],
"feedrate_z": self.app.options["geometry_feedrate_z"],
"feedrate_rapid": self.app.options["geometry_feedrate_rapid"],
"dwell": self.app.options["geometry_dwell"],
"dwelltime": self.app.options["geometry_dwelltime"],
"multidepth": self.app.options["geometry_multidepth"],
"ppname_g": self.app.options["geometry_ppname_g"],
"depthperpass": self.app.options["geometry_depthperpass"],
"extracut": self.app.options["geometry_extracut"],
"extracut_length": self.app.options["geometry_extracut_length"],
"toolchange": self.app.options["geometry_toolchange"],
"toolchangez": self.app.options["geometry_toolchangez"],
"endz": self.app.options["geometry_endz"],
"endxy": self.app.options["geometry_endxy"],
"area_exclusion": self.app.options["geometry_area_exclusion"],
"area_shape": self.app.options["geometry_area_shape"],
"area_strategy": self.app.options["geometry_area_strategy"],
"area_overz": self.app.options["geometry_area_overz"],
"spindlespeed": self.app.defaults["geometry_spindlespeed"],
"toolchangexy": self.app.defaults["geometry_toolchangexy"],
"startz": self.app.defaults["geometry_startz"],
"spindlespeed": self.app.options["geometry_spindlespeed"],
"toolchangexy": self.app.options["geometry_toolchangexy"],
"startz": self.app.options["geometry_startz"],
"tooldia": self.app.defaults["tools_paint_tooldia"],
"tools_paint_offset": self.app.defaults["tools_paint_offset"],
"tools_paint_method": self.app.defaults["tools_paint_method"],
"tools_paint_selectmethod": self.app.defaults["tools_paint_selectmethod"],
"tools_paint_connect": self.app.defaults["tools_paint_connect"],
"tools_paint_contour": self.app.defaults["tools_paint_contour"],
"tools_paint_overlap": self.app.defaults["tools_paint_overlap"],
"tools_paint_rest": self.app.defaults["tools_paint_rest"],
"tooldia": self.app.options["tools_paint_tooldia"],
"tools_paint_offset": self.app.options["tools_paint_offset"],
"tools_paint_method": self.app.options["tools_paint_method"],
"tools_paint_selectmethod": self.app.options["tools_paint_selectmethod"],
"tools_paint_connect": self.app.options["tools_paint_connect"],
"tools_paint_contour": self.app.options["tools_paint_contour"],
"tools_paint_overlap": self.app.options["tools_paint_overlap"],
"tools_paint_rest": self.app.options["tools_paint_rest"],
"tools_ncc_operation": self.app.defaults["tools_ncc_operation"],
"tools_ncc_margin": self.app.defaults["tools_ncc_margin"],
"tools_ncc_method": self.app.defaults["tools_ncc_method"],
"tools_ncc_connect": self.app.defaults["tools_ncc_connect"],
"tools_ncc_contour": self.app.defaults["tools_ncc_contour"],
"tools_ncc_overlap": self.app.defaults["tools_ncc_overlap"],
"tools_ncc_rest": self.app.defaults["tools_ncc_rest"],
"tools_ncc_ref": self.app.defaults["tools_ncc_ref"],
"tools_ncc_offset_choice": self.app.defaults["tools_ncc_offset_choice"],
"tools_ncc_offset_value": self.app.defaults["tools_ncc_offset_value"],
"tools_ncc_milling_type": self.app.defaults["tools_ncc_milling_type"],
"tools_ncc_operation": self.app.options["tools_ncc_operation"],
"tools_ncc_margin": self.app.options["tools_ncc_margin"],
"tools_ncc_method": self.app.options["tools_ncc_method"],
"tools_ncc_connect": self.app.options["tools_ncc_connect"],
"tools_ncc_contour": self.app.options["tools_ncc_contour"],
"tools_ncc_overlap": self.app.options["tools_ncc_overlap"],
"tools_ncc_rest": self.app.options["tools_ncc_rest"],
"tools_ncc_ref": self.app.options["tools_ncc_ref"],
"tools_ncc_offset_choice": self.app.options["tools_ncc_offset_choice"],
"tools_ncc_offset_value": self.app.options["tools_ncc_offset_value"],
"tools_ncc_milling_type": self.app.options["tools_ncc_milling_type"],
"tools_iso_passes": self.app.defaults["tools_iso_passes"],
"tools_iso_overlap": self.app.defaults["tools_iso_overlap"],
"tools_iso_milling_type": self.app.defaults["tools_iso_milling_type"],
"tools_iso_isotype": self.app.defaults["tools_iso_isotype"],
"tools_iso_passes": self.app.options["tools_iso_passes"],
"tools_iso_overlap": self.app.options["tools_iso_overlap"],
"tools_iso_milling_type": self.app.options["tools_iso_milling_type"],
"tools_iso_isotype": self.app.options["tools_iso_isotype"],
"tools_iso_rest": self.app.defaults["tools_iso_rest"],
"tools_iso_combine_passes": self.app.defaults["tools_iso_combine_passes"],
"tools_iso_isoexcept": self.app.defaults["tools_iso_isoexcept"],
"tools_iso_selection": self.app.defaults["tools_iso_selection"],
"tools_iso_poly_ints": self.app.defaults["tools_iso_poly_ints"],
"tools_iso_force": self.app.defaults["tools_iso_force"],
"tools_iso_area_shape": self.app.defaults["tools_iso_area_shape"]
"tools_iso_rest": self.app.options["tools_iso_rest"],
"tools_iso_combine_passes": self.app.options["tools_iso_combine_passes"],
"tools_iso_isoexcept": self.app.options["tools_iso_isoexcept"],
"tools_iso_selection": self.app.options["tools_iso_selection"],
"tools_iso_poly_ints": self.app.options["tools_iso_poly_ints"],
"tools_iso_force": self.app.options["tools_iso_force"],
"tools_iso_area_shape": self.app.options["tools_iso_area_shape"]
})
# will store the geometry here for compatibility reason
@@ -237,7 +237,7 @@ class HPGL2:
'tooldia': float('%.*f' %
(
self.decimals,
float(self.app.defaults['tools_mill_tooldia'])
float(self.app.options['tools_mill_tooldia'])
)
),
'offset': 'Path',