فهرست منبع

- fixed Measuring Tool in legacy graphic engine
- fixed Gerber plotting
- fixed Geometry plotting

Marius Stanciu 6 سال پیش
والد
کامیت
9aef293a26
5فایلهای تغییر یافته به همراه130 افزوده شده و 43 حذف شده
  1. 21 4
      FlatCAMApp.py
  2. 87 37
      FlatCAMObj.py
  3. 6 0
      README.md
  4. 3 0
      flatcamGUI/PlotCanvasLegacy.py
  5. 13 2
      flatcamTools/ToolMeasurement.py

+ 21 - 4
FlatCAMApp.py

@@ -6777,6 +6777,10 @@ class App(QtCore.QObject):
         """
         self.report_usage("on_jump_to()")
 
+        if self.is_legacy is True:
+            self.inform.emit(_("Not available with the current Graphic Engine Legacy(2D)."))
+            return
+
         if not custom_location:
             dia_box = Dialog_box(title=_("Jump to ..."),
                                  label=_("Enter the coordinates in format X,Y:"),
@@ -6796,14 +6800,27 @@ class App(QtCore.QObject):
             location = custom_location
 
         if fit_center:
-            self.plotcanvas.fit_center(loc=location)
+            if self.is_legacy is False:
+                self.plotcanvas.fit_center(loc=location)
+            else:
+                pass
+                # self.plotcanvas.fit_view()
 
         cursor = QtGui.QCursor()
 
-        canvas_origin = self.plotcanvas.native.mapToGlobal(QtCore.QPoint(0, 0))
-        jump_loc = self.plotcanvas.translate_coords_2((location[0], location[1]))
+        if self.is_legacy is False:
+            canvas_origin = self.plotcanvas.native.mapToGlobal(QtCore.QPoint(0, 0))
+            jump_loc = self.plotcanvas.translate_coords_2((location[0], location[1]))
+            cursor.setPos(canvas_origin.x() + jump_loc[0], (canvas_origin.y() + jump_loc[1]))
+        else:
+            # the origin finding works but not mapping the location to pixels
+            canvas_origin = self.plotcanvas.native.mapToGlobal(QtCore.QPoint(0, 0))
+            x0, y0 = canvas_origin.x(), canvas_origin.y() + self.ui.right_layout.geometry().height()
+            x0, y0 = x0 + self.plotcanvas.axes.transData.transform((0, 0))[0], y0 - \
+                     self.plotcanvas.axes.transData.transform((0, 0))[1]
+            loc = self.plotcanvas.axes.transData.transform(location)
+            cursor.setPos(x0 + loc[0]/50, y0 - loc[1]/50)
 
-        cursor.setPos(canvas_origin.x() + jump_loc[0], (canvas_origin.y() + jump_loc[1]))
         self.inform.emit('[success] %s' %
                          _("Done."))
         return location

+ 87 - 37
FlatCAMObj.py

@@ -650,8 +650,12 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
             self.ui.create_buffer_button.hide()
 
         # add the shapes storage for marking apertures
-        for ap_code in self.apertures:
-            self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=2)
+        if self.app.is_legacy is False:
+            for ap_code in self.apertures:
+                self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=2)
+        else:
+            for ap_code in self.apertures:
+                self.mark_shapes[ap_code] = ShapeCollectionLegacy()
 
         # set initial state of the aperture table and associated widgets
         self.on_aperture_table_visibility_change()
@@ -1365,44 +1369,73 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
         except TypeError:
             geometry = [geometry]
 
-        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
 
-        try:
-            if self.options["solid"]:
-                for g in geometry:
-                    if type(g) == Polygon or type(g) == LineString:
-                        self.add_shape(shape=g, color=color,
-                                       face_color=random_color() if self.options['multicolored']
-                                       else face_color, visible=visible)
-                    elif type(g) == Point:
-                        pass
-                    else:
-                        try:
-                            for el in g:
-                                self.add_shape(shape=el, color=color,
-                                               face_color=random_color() if self.options['multicolored']
-                                               else face_color, visible=visible)
-                        except TypeError:
+            try:
+                if self.options["solid"]:
+                    for g in geometry:
+                        if type(g) == Polygon or type(g) == LineString:
                             self.add_shape(shape=g, color=color,
                                            face_color=random_color() if self.options['multicolored']
                                            else face_color, visible=visible)
-            else:
-                for g in geometry:
-                    if type(g) == Polygon or type(g) == LineString:
-                        self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black',
-                                       visible=visible)
-                    elif type(g) == Point:
-                        pass
-                    else:
-                        for el in g:
-                            self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black',
+                        elif type(g) == Point:
+                            pass
+                        else:
+                            try:
+                                for el in g:
+                                    self.add_shape(shape=el, color=color,
+                                                   face_color=random_color() if self.options['multicolored']
+                                                   else face_color, visible=visible)
+                            except TypeError:
+                                self.add_shape(shape=g, color=color,
+                                               face_color=random_color() if self.options['multicolored']
+                                               else face_color, visible=visible)
+                else:
+                    for g in geometry:
+                        if type(g) == Polygon or type(g) == LineString:
+                            self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black',
                                            visible=visible)
-            self.shapes.redraw()
-        except (ObjectDeleted, AttributeError):
-            self.shapes.clear(update=True)
+                        elif type(g) == Point:
+                            pass
+                        else:
+                            for el in g:
+                                self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black',
+                                               visible=visible)
+                self.shapes.redraw()
+            except (ObjectDeleted, AttributeError):
+                self.shapes.clear(update=True)
+        else:
+            if self.options["multicolored"]:
+                linespec = '-'
+            else:
+                linespec = 'k-'
+
+            if self.options["solid"]:
+                for poly in geometry:
+                    # TODO: Too many things hardcoded.
+                    try:
+                        patch = PolygonPatch(poly,
+                                             facecolor="#BBF268",
+                                             edgecolor="#006E20",
+                                             alpha=0.75,
+                                             zorder=2)
+                        self.axes.add_patch(patch)
+                    except AssertionError:
+                        FlatCAMApp.App.log.warning("A geometry component was not a polygon:")
+                        FlatCAMApp.App.log.warning(str(poly))
+            else:
+                for poly in geometry:
+                    x, y = poly.exterior.xy
+                    self.axes.plot(x, y, linespec)
+                    for ints in poly.interiors:
+                        x, y = ints.coords.xy
+                        self.axes.plot(x, y, linespec)
+
+            self.app.plotcanvas.auto_adjust_axes()
 
     # experimental plot() when the solid_geometry is stored in the self.apertures
     def plot_aperture(self, **kwargs):
@@ -5401,7 +5434,21 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
                 self.plot_element(sub_el)
 
         except TypeError:  # Element is not iterable...
-            self.add_shape(shape=element, color=color, visible=visible, layer=0)
+            if self.app.is_legacy is False:
+                self.add_shape(shape=element, color=color, visible=visible, layer=0)
+            else:
+                if type(element) == Polygon:
+                    x, y = element.exterior.coords.xy
+                    self.axes.plot(x, y, 'r-')
+                    for ints in element.interiors:
+                        x, y = ints.coords.xy
+                        self.axes.plot(x, y, 'r-')
+                    return
+
+                if type(element) == LineString or type(element) == LinearRing:
+                    x, y = element.coords.xy
+                    self.axes.plot(x, y, 'r-')
+                    return
 
     def plot(self, visible=None, kind=None):
         """
@@ -5432,7 +5479,10 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
                     self.plot_element(self.solid_geometry, visible=visible)
 
             # self.plot_element(self.solid_geometry, visible=self.options['plot'])
-            self.shapes.redraw()
+            if self.app.is_legacy is False:
+                self.shapes.redraw()
+            else:
+                self.app.plotcanvas.auto_adjust_axes()
         except (ObjectDeleted, AttributeError):
             self.shapes.clear(update=True)
 

+ 6 - 0
README.md

@@ -9,6 +9,12 @@ CAD program, and create G-Code for Isolation routing.
 
 =================================================
 
+21.09.2019
+
+- fixed Measuring Tool in legacy graphic engine
+- fixed Gerber plotting
+- fixed Geometry plotting
+
 20.09.2019
 
 - final fix for the --shellvar having spaces within the assigned value; now they are retained

+ 3 - 0
flatcamGUI/PlotCanvasLegacy.py

@@ -366,6 +366,9 @@ class PlotCanvasLegacy(QtCore.QObject):
         ymin, ymax = self.axes.get_ylim()
         self.adjust_axes(xmin, ymin, xmax, ymax)
 
+    def fit_view(self):
+        self.auto_adjust_axes()
+
     def zoom(self, factor, center=None):
         """
         Zooms the plot by factor around a given

+ 13 - 2
flatcamTools/ToolMeasurement.py

@@ -284,7 +284,13 @@ class Measurement(FlatCAMTool):
         log.debug("Measuring Tool --> mouse click release")
 
         if event.button == 1:
-            pos_canvas = self.canvas.translate_coords(event.pos)
+            if self.app.is_legacy is False:
+                event_pos = event.pos
+            else:
+                event_pos = (event.xdata, event.ydata)
+
+            pos_canvas = self.canvas.translate_coords(event_pos)
+
             # if GRID is active we need to get the snapped positions
             if self.app.grid_status() == True:
                 pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
@@ -323,7 +329,12 @@ class Measurement(FlatCAMTool):
 
     def on_mouse_move_meas(self, event):
         try:  # May fail in case mouse not within axes
-            pos_canvas = self.app.plotcanvas.translate_coords(event.pos)
+            if self.app.is_legacy is False:
+                event_pos = event.pos
+            else:
+                event_pos = (event.xdata, event.ydata)
+
+            pos_canvas = self.app.plotcanvas.translate_coords(event_pos)
             if self.app.grid_status() == True:
                 pos = self.app.geo_editor.snap(pos_canvas[0], pos_canvas[1])
                 # Update cursor