From aaa81f22b2bf204f8fdefd24d0d4908ae5225d72 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Thu, 9 May 2019 05:01:33 +0300 Subject: [PATCH] - wip --- FlatCAMObj.py | 19 +++++++++---------- camlib.py | 48 +++++++++++++++++++++++++----------------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/FlatCAMObj.py b/FlatCAMObj.py index c817856b..dfd83612 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -1155,17 +1155,16 @@ class FlatCAMGerber(FlatCAMObj, Gerber): self.app.progress.emit(30) try: if aperture_to_plot_mark in self.apertures: - if type(self.apertures[aperture_to_plot_mark]['solid_geometry']) is not list: - self.apertures[aperture_to_plot_mark]['solid_geometry'] = \ - [self.apertures[aperture_to_plot_mark]['solid_geometry']] - for geo in self.apertures[aperture_to_plot_mark]['solid_geometry']: - if type(geo) == Polygon or type(geo) == LineString: - self.add_mark_shape(apid=aperture_to_plot_mark, shape=geo, color=color, - face_color=color, visible=visibility) - else: - for el in geo: - self.add_mark_shape(apid=aperture_to_plot_mark, shape=el, color=color, + for elem in self.apertures[aperture_to_plot_mark]['geometry']: + if 'solid' in elem: + geo = elem['solid'] + if type(geo) == Polygon or type(geo) == LineString: + self.add_mark_shape(apid=aperture_to_plot_mark, shape=geo, color=color, face_color=color, visible=visibility) + else: + for el in geo: + self.add_mark_shape(apid=aperture_to_plot_mark, shape=el, color=color, + face_color=color, visible=visibility) self.mark_shapes[aperture_to_plot_mark].redraw() self.app.progress.emit(100) diff --git a/camlib.py b/camlib.py index 92b4ab92..df5e81d4 100644 --- a/camlib.py +++ b/camlib.py @@ -2186,8 +2186,8 @@ class Gerber (Geometry): # store here the follow geometry follow_buffer = [] - last_path_aperture = None - current_aperture = None + last_path_aperture = '0' + current_aperture = '0' # 1,2 or 3 from "G01", "G02" or "G03" current_interpolation_mode = None @@ -2451,7 +2451,6 @@ class Gerber (Geometry): try: self.apertures[current_aperture]['geometry'].append(geo_dict) except KeyError: - self.apertures[current_aperture] = dict() self.apertures[current_aperture]['geometry'] = [] self.apertures[current_aperture]['geometry'].append(geo_dict) @@ -2478,8 +2477,8 @@ class Gerber (Geometry): # Take care of the current path with the previous tool if len(path) > 1: - if self.apertures[current_aperture]["type"] != 'R': - width = self.apertures[current_aperture]["size"] + if self.apertures[last_path_aperture]["type"] != 'R': + width = self.apertures[last_path_aperture]["size"] geo_f = LineString(path) geo_s = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4)) @@ -2493,10 +2492,10 @@ class Gerber (Geometry): else: geo_dict['solid'] = geo_s try: - self.apertures[current_aperture]['geometry'].append(geo_dict) + self.apertures[last_path_aperture]['geometry'].append(geo_dict) except KeyError: - self.apertures[current_aperture]['geometry'] = [] - self.apertures[current_aperture]['geometry'].append(geo_dict) + self.apertures[last_path_aperture]['geometry'] = [] + self.apertures[last_path_aperture]['geometry'].append(geo_dict) path = [path[-1]] @@ -2506,7 +2505,6 @@ class Gerber (Geometry): if self.regionon_re.search(gline): if len(path) > 1: # Take care of what is left in the path - width = self.apertures[last_path_aperture]["size"] geo_f = LineString(path) @@ -2592,7 +2590,6 @@ class Gerber (Geometry): try: self.apertures['0']['geometry'].append(geo_dict) except KeyError: - self.apertures['0'] = dict() self.apertures['0']['geometry'] = [] self.apertures['0']['geometry'].append(geo_dict) @@ -2623,6 +2620,14 @@ class Gerber (Geometry): # NOTE: Letting it continue allows it to react to the # operation code. + if current_aperture is None: + if '0' not in self.apertures: + self.apertures['0'] = {} + self.apertures['0']['type'] = 'REG' + self.apertures['0']['size'] = 0.0 + self.apertures['0']['geometry'] = [] + current_aperture = '0' + # Parse coordinates if match.group(2) is not None: linear_x = parse_gerber_number(match.group(2), @@ -2648,6 +2653,7 @@ class Gerber (Geometry): # only add the point if it's a new one otherwise skip it (harder to process) if path[-1] != [current_x, current_y]: path.append([current_x, current_y]) + if making_region is False: # if the aperture is rectangle then add a rectangular shape having as parameters the # coordinates of the start and end point and also the width and height @@ -2684,20 +2690,13 @@ class Gerber (Geometry): pass last_path_aperture = current_aperture - if last_path_aperture is None: - if '0' not in self.apertures: - self.apertures['0'] = {} - self.apertures['0']['type'] = 'REG' - self.apertures['0']['size'] = 0.0 - self.apertures['0']['geometry'] = [] - last_path_aperture = '0' else: self.app.inform.emit(_("[WARNING] Coordinates missing, line ignored: %s") % str(gline)) self.app.inform.emit(_("[WARNING_NOTCL] GERBER file might be CORRUPT. Check the file !!!")) elif current_operation_code == 2: + # finish current path if len(path) > 1: - geo = None if last_path_aperture is None: if '0' not in self.apertures: @@ -2752,10 +2751,10 @@ class Gerber (Geometry): # Not allowed in region mode. elif current_operation_code == 3: - # finished the path draw until now width = self.apertures[last_path_aperture]["size"] - + # finish the path draw until now if len(path) > 1 and self.apertures[last_path_aperture]["type"] != 'R': + geo_f = LineString(path) geo_s = LineString(path).buffer(width / 1.999, int(self.steps_per_circle / 4)) follow_buffer.append(geo_f) @@ -3028,10 +3027,10 @@ class Gerber (Geometry): else: geo_dict['solid'] = geo_s try: - self.apertures[current_aperture]['geometry'].append(geo_dict) + self.apertures[last_path_aperture]['geometry'].append(geo_dict) except KeyError: - self.apertures[current_aperture]['geometry'] = [] - self.apertures[current_aperture]['geometry'].append(geo_dict) + self.apertures[last_path_aperture]['geometry'] = [] + self.apertures[last_path_aperture]['geometry'].append(geo_dict) # 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 @@ -3072,6 +3071,9 @@ class Gerber (Geometry): self.apertures[apid][k] = v * conversion_factor # ------------------------------------------------------------- + # for t in self.apertures: + # print(t, self.apertures[t]) + # --- Apply buffer --- # this treats the case when we are storing geometry as paths self.follow_geometry = follow_buffer