From 961c4bca2ffba0673d38b3121c1d1e789286c1cd Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sun, 22 Sep 2019 14:03:20 +0300 Subject: [PATCH] - fixed the MultiColor plot option Gerber selected tab to work in legacy graphic engine - documented some methods in the ShapeCollectionLegacy class --- FlatCAMApp.py | 4 ++-- FlatCAMObj.py | 27 ++++++++++++++++++++----- README.md | 2 ++ flatcamGUI/PlotCanvasLegacy.py | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 9dcd1676..1aa8de88 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -124,7 +124,7 @@ class App(QtCore.QObject): # ################## Version and VERSION DATE ############################## # ########################################################################## version = 8.97 - version_date = "2019/09/20" + version_date = "2019/09/22" beta = True engine = '3D' @@ -2760,7 +2760,7 @@ class App(QtCore.QObject): :param name: String that store the project path and project name :return: None """ - self.ui.setWindowTitle('FlatCAM %s %s - %s - (%s) %s' % + self.ui.setWindowTitle('FlatCAM %s %s - %s - [%s] %s' % (self.version, ('BETA' if self.beta else ''), platform.architecture()[0], diff --git a/FlatCAMObj.py b/FlatCAMObj.py index f5a9e3dc..5285f70c 100644 --- a/FlatCAMObj.py +++ b/FlatCAMObj.py @@ -1356,11 +1356,26 @@ class FlatCAMGerber(FlatCAMObj, Gerber): except TypeError: geometry = [geometry] - # if self.app.is_legacy is False: - def random_color(): - color = np.random.rand(4) - color[3] = 1 - return color + if self.app.is_legacy is False: + def random_color(): + color = np.random.rand(4) + color[3] = 1 + return color + else: + def random_color(): + while True: + color = np.random.rand(4) + color[3] = 1 + + new_color = '#' + for idx in range(len(color)): + new_color += '%x' % int(color[idx] * 255) + # do it until a valid color is generated + # a valid color has the # symbol, another 6 chars for the color and the last 2 chars for alpha + # for a total of 9 chars + if len(new_color) == 9: + break + return new_color try: if self.options["solid"]: @@ -1395,6 +1410,8 @@ class FlatCAMGerber(FlatCAMObj, Gerber): self.shapes.redraw() except (ObjectDeleted, AttributeError): self.shapes.clear(update=True) + except Exception as e: + log.debug("FlatCAMGerber.plot() --> %s" % str(e)) # experimental plot() when the solid_geometry is stored in the self.apertures def plot_aperture(self, run_thread=True, **kwargs): diff --git a/README.md b/README.md index 7aad33cb..73d9d12e 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ CAD program, and create G-Code for Isolation routing. - made hover shapes work in legacy graphic engine - fixed bug in display of the apertures marked in the Aperture table found in the Gerber Selected tab and through this made it to also work with the legacy graphic engine - fixed annotation in Mark Area Tool in Gerber Editor to work in legacy graphic engine +- fixed the MultiColor plot option Gerber selected tab to work in legacy graphic engine +- documented some methods in the ShapeCollectionLegacy class 21.09.2019 diff --git a/flatcamGUI/PlotCanvasLegacy.py b/flatcamGUI/PlotCanvasLegacy.py index d0a9d736..c43f2afb 100644 --- a/flatcamGUI/PlotCanvasLegacy.py +++ b/flatcamGUI/PlotCanvasLegacy.py @@ -753,7 +753,23 @@ class ShapeCollectionLegacy: def add(self, shape=None, color=None, face_color=None, alpha=None, visible=True, update=False, layer=1, tolerance=0.01, obj=None, gcode_parsed=None, tool_tolerance=None, tooldia=None): + """ + This function will add shapes to the shape collection + :param shape: the Shapely shape to be added to the shape collection + :param color: edge color of the shape, hex value + :param face_color: the body color of the shape, hex value + :param alpha: level of transparency of the shape [0.0 ... 1.0]; Float + :param visible: if True will allow the shapes to be added + :param update: not used; just for compatibility with VIsPy canvas + :param layer: just for compatibility with VIsPy canvas + :param tolerance: just for compatibility with VIsPy canvas + :param obj: not used + :param gcode_parsed: not used; just for compatibility with VIsPy canvas + :param tool_tolerance: just for compatibility with VIsPy canvas + :param tooldia: + :return: + """ self._color = color[:-2] if color is not None else None self._face_color = face_color[:-2] if face_color is not None else None self._alpha = int(face_color[-2:], 16) / 255 if face_color is not None else 0.75 @@ -802,6 +818,12 @@ class ShapeCollectionLegacy: return self.shape_id def clear(self, update=None): + """ + Clear the canvas of the shapes. + + :param update: + :return: None + """ self._shapes.clear() self.shape_id = 0 @@ -812,6 +834,11 @@ class ShapeCollectionLegacy: self.redraw() def redraw(self): + """ + This draw the shapes in the shapes collection, on canvas + + :return: None + """ path_num = 0 local_shapes = deepcopy(self._shapes) @@ -922,7 +949,16 @@ class ShapeCollectionLegacy: self.app.plotcanvas.auto_adjust_axes() def set(self, text, pos, visible=True, font_size=16, color=None): + """ + This will set annotations on the canvas. + :param text: a list of text elements to be used as annotations + :param pos: a list of positions for showing the text elements above + :param visible: if True will display annotations, if False will clear them on canvas + :param font_size: the font size or the annotations + :param color: color of the annotations + :return: None + """ if color is None: color = "#000000FF"