Explorar o código

- 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

Marius Stanciu %!s(int64=6) %!d(string=hai) anos
pai
achega
f00559bf6a

+ 4 - 5
FlatCAMApp.py

@@ -7719,10 +7719,9 @@ class App(QtCore.QObject):
                 if self.grid_status() == True:
                     pos = self.geo_editor.snap(pos_canvas[0], pos_canvas[1])
 
-                    if self.is_legacy is False:
-                        # Update cursor
-                        self.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
-                                                 symbol='++', edge_color='black', size=20)
+                    # Update cursor
+                    self.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
+                                             symbol='++', edge_color='black', size=20)
                 else:
                     pos = (pos_canvas[0], pos_canvas[1])
 
@@ -7766,7 +7765,7 @@ class App(QtCore.QObject):
                                             obj.isHovering = True
                                             obj.notHovering = True
                                             # create the selection box around the selected object
-                                            self.draw_hover_shape(obj, color='#d1e0e0')
+                                            self.draw_hover_shape(obj, color='#d1e0e0FF')
                                     else:
                                         if obj.notHovering is True:
                                             obj.notHovering = False

+ 20 - 15
FlatCAMObj.py

@@ -1397,9 +1397,10 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
             self.shapes.clear(update=True)
 
     # experimental plot() when the solid_geometry is stored in the self.apertures
-    def plot_aperture(self, **kwargs):
+    def plot_aperture(self, run_thread=True, **kwargs):
         """
 
+        :param run_thread: if True run the aperture plot as a thread in a worker
         :param kwargs: color and face_color
         :return:
         """
@@ -1429,31 +1430,34 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
         else:
             visibility = kwargs['visible']
 
-        with self.app.proc_container.new(_("Plotting Apertures")) as proc:
+        with self.app.proc_container.new(_("Plotting Apertures")):
             self.app.progress.emit(30)
 
             def job_thread(app_obj):
-                self.app.progress.emit(30)
                 try:
                     if aperture_to_plot_mark in self.apertures:
                         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,
+                                    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)
 
                 except (ObjectDeleted, AttributeError):
                     self.clear_plot_apertures()
+                except Exception as e:
+                    print(str(e))
 
-            self.app.worker_task.emit({'fcn': job_thread, 'params': [self]})
+            if run_thread:
+                self.app.worker_task.emit({'fcn': job_thread, 'params': [self]})
+            else:
+                job_thread(self)
 
     def clear_plot_apertures(self, aperture='all'):
         """
@@ -1497,8 +1501,9 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
         if self.ui.apertures_table.cellWidget(cw_row, 5).isChecked():
             self.marked_rows.append(True)
             # self.plot_aperture(color='#2d4606bf', marked_aperture=aperture, visible=True)
-            self.plot_aperture(color=self.app.defaults['global_sel_draw_color'], marked_aperture=aperture, visible=True)
-            self.mark_shapes[aperture].redraw()
+            self.plot_aperture(color=self.app.defaults['global_sel_draw_color'] + 'FF',
+                               marked_aperture=aperture, visible=True, run_thread=True)
+            # self.mark_shapes[aperture].redraw()
         else:
             self.marked_rows.append(False)
             self.clear_plot_apertures(aperture=aperture)
@@ -1534,7 +1539,7 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
         if mark_all:
             for aperture in self.apertures:
                 # self.plot_aperture(color='#2d4606bf', marked_aperture=aperture, visible=True)
-                self.plot_aperture(color=self.app.defaults['global_sel_draw_color'],
+                self.plot_aperture(color=self.app.defaults['global_sel_draw_color'] + 'FF',
                                    marked_aperture=aperture, visible=True)
             # HACK: enable/disable the grid for a better look
             self.app.ui.grid_snap_btn.trigger()

+ 3 - 0
README.md

@@ -18,6 +18,9 @@ CAD program, and create G-Code for Isolation routing.
 - fixed display of distance labels and code optimizations in ToolPaint and NCC Tool
 - adjusted axis at startup for legacy graphic engine plotcanvas
 - when the graphic engine is changed in Edit -> Preferences -> General -> App Preferences, the application will restart
+- 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
 
 21.09.2019
 

+ 5 - 6
flatcamEditors/FlatCAMExcEditor.py

@@ -3655,9 +3655,9 @@ class FlatCAMExcEditor(QtCore.QObject):
         # ## Snap coordinates
         if self.app.grid_status() == True:
             x, y = self.app.geo_editor.snap(x, y)
-            if self.app.is_legacy is False:
-                # Update cursor
-                self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+
+            # Update cursor
+            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
 
         self.snap_x = x
         self.snap_y = y
@@ -3704,9 +3704,8 @@ class FlatCAMExcEditor(QtCore.QObject):
         else:
             self.app.selection_type = None
 
-        if self.app.is_legacy is False:
-            # Update cursor
-            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+        # Update cursor
+        self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
 
     def on_canvas_key_release(self, event):
         self.key = None

+ 3 - 3
flatcamEditors/FlatCAMGeoEditor.py

@@ -3739,9 +3739,9 @@ class FlatCAMGeoEditor(QtCore.QObject):
         # ### Snap coordinates ###
         if self.app.grid_status() == True:
             x, y = self.snap(x, y)
-            if self.app.is_legacy is False:
-                # Update cursor
-                self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+
+            # Update cursor
+            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
 
         self.snap_x = x
         self.snap_y = y

+ 13 - 9
flatcamEditors/FlatCAMGrbEditor.py

@@ -2607,8 +2607,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
         self.ma_lower_threshold_entry = FCEntry()
         self.ma_lower_threshold_entry.setValidator(QtGui.QDoubleValidator(0.0000, 9999.9999, 4))
 
-        ma_form_layout.addRow(self.ma_upper_threshold_lbl, self.ma_upper_threshold_entry)
         ma_form_layout.addRow(self.ma_lower_threshold_lbl, self.ma_lower_threshold_entry)
+        ma_form_layout.addRow(self.ma_upper_threshold_lbl, self.ma_upper_threshold_entry)
 
         # Buttons
         hlay_ma = QtWidgets.QHBoxLayout()
@@ -2829,7 +2829,11 @@ class FlatCAMGrbEditor(QtCore.QObject):
             from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
             self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_grb_editor')
             self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_grb_editor')
-            self.ma_annotation = ShapeCollectionLegacy(obj=self, app=self.app, name='ma_anno_grb_editor')
+            self.ma_annotation = ShapeCollectionLegacy(
+                obj=self,
+                app=self.app,
+                name='ma_anno_grb_editor',
+                annotation_job=True)
 
         self.app.pool_recreated.connect(self.pool_recreated)
 
@@ -2983,8 +2987,8 @@ class FlatCAMGrbEditor(QtCore.QObject):
 
         self.buffer_distance_entry.set_value(self.app.defaults["gerber_editor_buff_f"])
         self.scale_factor_entry.set_value(self.app.defaults["gerber_editor_scale_f"])
-        self.ma_upper_threshold_entry.set_value(self.app.defaults["gerber_editor_ma_low"])
-        self.ma_lower_threshold_entry.set_value(self.app.defaults["gerber_editor_ma_high"])
+        self.ma_upper_threshold_entry.set_value(self.app.defaults["gerber_editor_ma_high"])
+        self.ma_lower_threshold_entry.set_value(self.app.defaults["gerber_editor_ma_low"])
 
         self.apsize_entry.set_value(self.app.defaults["gerber_editor_newsize"])
         self.aptype_cb.set_value(self.app.defaults["gerber_editor_newtype"])
@@ -4392,9 +4396,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
         # # ## Snap coordinates
         if self.app.grid_status() == True:
             x, y = self.app.geo_editor.snap(x, y)
-            if self.app.is_legacy is False:
-                # Update cursor
-                self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
+
+            # Update cursor
+            self.app.app_cursor.set_data(np.asarray([(x, y)]), symbol='++', edge_color='black', size=20)
 
         self.snap_x = x
         self.snap_y = y
@@ -4835,7 +4839,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
                         except Exception as e:
                             lower_threshold_val = 0.0
 
-                        if area < float(upper_threshold_val) and area > float(lower_threshold_val):
+                        if float(upper_threshold_val) > area > float(lower_threshold_val):
                             current_pos = geo_el['solid'].exterior.coords[-1]
                             text_elem = '%.4f' % area
                             text.append(text_elem)
@@ -4844,7 +4848,7 @@ class FlatCAMGrbEditor(QtCore.QObject):
         if text:
             self.ma_annotation.set(text=text, pos=position, visible=True,
                                    font_size=self.app.defaults["cncjob_annotation_fontsize"],
-                                   color=self.app.defaults["global_sel_draw_color"])
+                                   color='#000000FF')
             self.app.inform.emit('[success] %s' %
                                  _("Polygon areas marked."))
         else:

+ 75 - 5
flatcamGUI/PlotCanvasLegacy.py

@@ -4,6 +4,7 @@
 # Author: Juan Pablo Caram (c)                             #
 # Date: 2/5/2014                                           #
 # MIT Licence                                              #
+# Modified by Marius Stanciu 09/21/2019                    #
 ############################################################
 
 from PyQt5 import QtGui, QtCore, QtWidgets
@@ -26,6 +27,14 @@ import FlatCAMApp
 from copy import deepcopy
 import logging
 
+import gettext
+import FlatCAMTranslation as fcTranslate
+import builtins
+
+fcTranslate.apply_language('strings')
+if '_' not in builtins.__dict__:
+    _ = gettext.gettext
+
 mpl_use("Qt5Agg")
 log = logging.getLogger('base')
 
@@ -617,7 +626,12 @@ class PlotCanvasLegacy(QtCore.QObject):
         return width / xpx, height / ypx
 
 
-class FakeCursor():
+class FakeCursor:
+    """
+    This is a fake cursor to ensure compatibility with the OpenGL engine (VisPy).
+    This way I don't have to chane (disable) things related to the cursor all over when
+    using the low performance Matplotlib 2D graphic engine.
+    """
     def __init__(self):
         self._enabled = True
 
@@ -629,9 +643,17 @@ class FakeCursor():
     def enabled(self, value):
         self._enabled = value
 
+    def set_data(self, pos, **kwargs):
+        """Internal event handler to draw the cursor when the mouse moves."""
+        pass
+
 
 class MplCursor(Cursor):
-
+    """
+    Unfortunately this gets attached to the current axes and if a new axes is added
+    it will not be showed until that axes is deleted.
+    Not the kind of behavior needed here so I don't use it anymore.
+    """
     def __init__(self, axes, color='red', linewidth=1):
 
         super().__init__(ax=axes, useblit=True, color=color, linewidth=linewidth)
@@ -687,11 +709,23 @@ class MplCursor(Cursor):
 
 
 class ShapeCollectionLegacy:
+    """
+    This will create the axes for each collection of shapes and will also
+    hold the collection of shapes into a dict self._shapes.
+    This handles the shapes redraw on canvas.
+    """
+    def __init__(self, obj, app, name=None, annotation_job=None):
+        """
 
-    def __init__(self, obj, app, name=None):
-
+        :param obj: this is the object to which the shapes collection is attached and for
+        which it will have to draw shapes
+        :param app: this is the FLatCAM.App usually, needed because we have to access attributes there
+        :param name: this is the name given to the Matplotlib axes; it needs to be unique due of Matplotlib requurements
+        :param annotation_job: make this True if the job needed is just for annotation
+        """
         self.obj = obj
         self.app = app
+        self.annotation_job = annotation_job
 
         self._shapes = dict()
         self.shape_dict = dict()
@@ -730,7 +764,7 @@ class ShapeCollectionLegacy:
         self._visible = visible
         self._update = update
 
-        # CNCJob oject related arguments
+        # CNCJob object related arguments
         self._obj = obj
         self._gcode_parsed = gcode_parsed
         self._tool_tolerance = tool_tolerance
@@ -887,6 +921,28 @@ class ShapeCollectionLegacy:
 
         self.app.plotcanvas.auto_adjust_axes()
 
+    def set(self, text, pos, visible=True, font_size=16, color=None):
+
+        if color is None:
+            color = "#000000FF"
+
+        if visible is not True:
+            self.clear()
+            return
+
+        if len(text) != len(pos):
+            self.app.inform.emit('[ERROR_NOTCL] %s' % _("Could not annotate due of a difference between the number "
+                                                        "of text elements and the number of text positions."))
+            return
+
+        for idx in range(len(text)):
+            try:
+                self.axes.annotate(text[idx], xy=pos[idx], xycoords='data', fontsize=font_size, color=color)
+            except Exception as e:
+                log.debug("ShapeCollectionLegacy.set() --> %s" % str(e))
+
+        self.app.plotcanvas.auto_adjust_axes()
+
     @property
     def visible(self):
         return self._visible
@@ -900,3 +956,17 @@ class ShapeCollectionLegacy:
             if self._visible is False:
                 self.redraw()
         self._visible = value
+
+    @property
+    def enabled(self):
+        return self._visible
+
+    @enabled.setter
+    def enabled(self, value):
+        if value is False:
+            self.axes.cla()
+            self.app.plotcanvas.auto_adjust_axes()
+        else:
+            if self._visible is False:
+                self.redraw()
+        self._visible = value

+ 4 - 4
flatcamTools/ToolMeasurement.py

@@ -343,10 +343,10 @@ class Measurement(FlatCAMTool):
 
             if self.app.grid_status() == True:
                 pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
-                if self.app.is_legacy is False:
-                    # Update cursor
-                    self.app.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
-                                                 symbol='++', edge_color='black', size=20)
+
+                # Update cursor
+                self.app.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
+                                             symbol='++', edge_color='black', size=20)
             else:
                 pos = (pos_canvas[0], pos_canvas[1])
 

+ 3 - 3
flatcamTools/ToolNonCopperClear.py

@@ -1280,9 +1280,9 @@ class NonCopperClear(FlatCAMTool, Gerber):
         if self.app.grid_status() == True:
             # Update cursor
             curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1])
-            if self.app.is_legacy is False:
-                self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
-                                             symbol='++', edge_color='black', size=20)
+
+            self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
+                                         symbol='++', edge_color='black', size=20)
 
         # update the positions on status bar
         self.app.ui.position_label.setText("&nbsp;&nbsp;&nbsp;&nbsp;<b>X</b>: %.4f&nbsp;&nbsp;   "

+ 3 - 3
flatcamTools/ToolPaint.py

@@ -1183,9 +1183,9 @@ class ToolPaint(FlatCAMTool, Gerber):
         if self.app.grid_status() == True:
             # Update cursor
             curr_pos = self.app.geo_editor.snap(curr_pos[0], curr_pos[1])
-            if self.app.is_legacy is False:
-                self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
-                                             symbol='++', edge_color='black', size=20)
+
+            self.app.app_cursor.set_data(np.asarray([(curr_pos[0], curr_pos[1])]),
+                                         symbol='++', edge_color='black', size=20)
 
         # update the positions on status bar
         self.app.ui.position_label.setText("&nbsp;&nbsp;&nbsp;&nbsp;<b>X</b>: %.4f&nbsp;&nbsp;   "