- fixed CNCJob and Excellon plotting in legacy graphic engine

- in legacy graphic engine fixed the travel vs cut lines in CNCJob objects
- final fix for key shortcuts with modifier in legacy graphic engine
- refactored some of the code in the legacy graphic engine
This commit is contained in:
Marius Stanciu 2019-09-21 18:26:03 +03:00 committed by Marius
parent 9aef293a26
commit bc6dc3decf
11 changed files with 299 additions and 196 deletions

View File

@ -6690,7 +6690,12 @@ class App(QtCore.QObject):
if self.is_legacy is True: if self.is_legacy is True:
# Remove plot only if the object was plotted otherwise delaxes will fail # Remove plot only if the object was plotted otherwise delaxes will fail
if isPlotted: if isPlotted:
self.plotcanvas.figure.delaxes(self.collection.get_active().axes) try:
# self.plotcanvas.figure.delaxes(self.collection.get_active().axes)
self.plotcanvas.figure.delaxes(self.collection.get_active().shapes.axes)
except Exception as e:
log.debug("App.delete_first_selected() --> %s" % str(e))
self.plotcanvas.auto_adjust_axes() self.plotcanvas.auto_adjust_axes()
# Remove from dictionary # Remove from dictionary
@ -6740,7 +6745,12 @@ class App(QtCore.QObject):
def on_set_zero_click(self, event): def on_set_zero_click(self, event):
# this function will be available only for mouse left click # this function will be available only for mouse left click
pos_canvas = self.plotcanvas.translate_coords(event.pos) if self.is_legacy is False:
event_pos = event.pos
else:
event_pos = (event.xdata, event.ydata)
pos_canvas = self.plotcanvas.translate_coords(event_pos)
if event.button == 1: if event.button == 1:
if self.grid_status() == True: if self.grid_status() == True:
pos = self.geo_editor.snap(pos_canvas[0], pos_canvas[1]) pos = self.geo_editor.snap(pos_canvas[0], pos_canvas[1])
@ -11011,7 +11021,7 @@ class App(QtCore.QObject):
self.hover_shapes = ShapeCollection(parent=self.plotcanvas.view.scene, layers=1) self.hover_shapes = ShapeCollection(parent=self.plotcanvas.view.scene, layers=1)
else: else:
# will use the default Matplotlib axes # will use the default Matplotlib axes
self.hover_shapes = ShapeCollectionLegacy() self.hover_shapes = ShapeCollectionLegacy(obj=self, app=self, name='hover')
def on_zoom_fit(self, event): def on_zoom_fit(self, event):
""" """

View File

@ -85,7 +85,7 @@ class FlatCAMObj(QtCore.QObject):
if self.app.is_legacy is False: if self.app.is_legacy is False:
self.shapes = self.app.plotcanvas.new_shape_group() self.shapes = self.app.plotcanvas.new_shape_group()
else: else:
self.shapes = ShapeCollectionLegacy() self.shapes = ShapeCollectionLegacy(obj=self, app=self.app)
# self.mark_shapes = self.app.plotcanvas.new_shape_collection(layers=2) # self.mark_shapes = self.app.plotcanvas.new_shape_collection(layers=2)
self.mark_shapes = {} self.mark_shapes = {}
@ -339,22 +339,7 @@ class FlatCAMObj(QtCore.QObject):
if self.deleted: if self.deleted:
return False return False
if self.app.is_legacy: self.clear()
# 2D mode
# Axes must exist and be attached to canvas.
if self.axes is None or self.axes not in self.app.plotcanvas.figure.axes:
self.axes = self.app.plotcanvas.new_axes(self.options['name'])
if not self.options["plot"]:
self.axes.cla()
self.app.plotcanvas.auto_adjust_axes()
return False
# Clear axes or we will plot on top of them.
self.axes.cla()
else:
# 3D mode
self.clear()
return True return True
def single_object_plot(self): def single_object_plot(self):
@ -414,11 +399,12 @@ class FlatCAMObj(QtCore.QObject):
def worker_task(app_obj): def worker_task(app_obj):
self.shapes.visible = value self.shapes.visible = value
# Not all object types has annotations if self.app.is_legacy is False:
try: # Not all object types has annotations
self.annotation.visible = value try:
except Exception as e: self.annotation.visible = value
pass except Exception as e:
pass
if threaded is False: if threaded is False:
worker_task(app_obj=self.app) worker_task(app_obj=self.app)
@ -655,7 +641,8 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=2) self.mark_shapes[ap_code] = self.app.plotcanvas.new_shape_collection(layers=2)
else: else:
for ap_code in self.apertures: for ap_code in self.apertures:
self.mark_shapes[ap_code] = ShapeCollectionLegacy() self.mark_shapes[ap_code] = ShapeCollectionLegacy(obj=self, app=self.app,
name=self.options['name'] + str(ap_code))
# set initial state of the aperture table and associated widgets # set initial state of the aperture table and associated widgets
self.on_aperture_table_visibility_change() self.on_aperture_table_visibility_change()
@ -1369,73 +1356,45 @@ class FlatCAMGerber(FlatCAMObj, Gerber):
except TypeError: except TypeError:
geometry = [geometry] geometry = [geometry]
if self.app.is_legacy is False: # if self.app.is_legacy is False:
def random_color(): def random_color():
color = np.random.rand(4) color = np.random.rand(4)
color[3] = 1 color[3] = 1
return color return color
try: try:
if self.options["solid"]: if self.options["solid"]:
for g in geometry: for g in geometry:
if type(g) == Polygon or type(g) == LineString: 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:
self.add_shape(shape=g, color=color, self.add_shape(shape=g, color=color,
face_color=random_color() if self.options['multicolored'] face_color=random_color() if self.options['multicolored']
else face_color, visible=visible) else face_color, visible=visible)
elif type(g) == Point: else:
pass for g in geometry:
else: if type(g) == Polygon or type(g) == LineString:
try: self.add_shape(shape=g, color=random_color() if self.options['multicolored'] else 'black',
for el in g: visible=visible)
self.add_shape(shape=el, color=color, elif type(g) == Point:
face_color=random_color() if self.options['multicolored'] pass
else face_color, visible=visible) else:
except TypeError: for el in g:
self.add_shape(shape=g, color=color, self.add_shape(shape=el, color=random_color() if self.options['multicolored'] else 'black',
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) visible=visible)
elif type(g) == Point: self.shapes.redraw()
pass except (ObjectDeleted, AttributeError):
else: self.shapes.clear(update=True)
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 # experimental plot() when the solid_geometry is stored in the self.apertures
def plot_aperture(self, **kwargs): def plot_aperture(self, **kwargs):
@ -3164,42 +3123,22 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
visible = visible if visible else self.options['plot'] visible = visible if visible else self.options['plot']
if self.app.is_legacy is False: try:
try: # Plot Excellon (All polygons?)
# Plot Excellon (All polygons?)
if self.options["solid"]:
for geo in self.solid_geometry:
self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
visible=visible,
layer=2)
else:
for geo in self.solid_geometry:
self.add_shape(shape=geo.exterior, color='red', visible=visible)
for ints in geo.interiors:
self.add_shape(shape=ints, color='orange', visible=visible)
self.shapes.redraw()
except (ObjectDeleted, AttributeError):
self.shapes.clear(update=True)
else:
# Plot excellon (All polygons?)
if self.options["solid"]: if self.options["solid"]:
for geo in self.solid_geometry: for geo in self.solid_geometry:
patch = PolygonPatch(geo, self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
facecolor="#C40000", visible=visible,
edgecolor="#750000", layer=2)
alpha=0.75,
zorder=3)
self.axes.add_patch(patch)
else: else:
for geo in self.solid_geometry: for geo in self.solid_geometry:
x, y = geo.exterior.coords.xy self.add_shape(shape=geo.exterior, color='red', visible=visible)
self.axes.plot(x, y, 'r-')
for ints in geo.interiors: for ints in geo.interiors:
x, y = ints.coords.xy self.add_shape(shape=ints, color='orange', visible=visible)
self.axes.plot(x, y, 'g-')
self.app.plotcanvas.auto_adjust_axes() self.shapes.redraw()
except (ObjectDeleted, AttributeError):
self.shapes.clear(update=True)
class FlatCAMGeometry(FlatCAMObj, Geometry): class FlatCAMGeometry(FlatCAMObj, Geometry):
@ -5434,21 +5373,21 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.plot_element(sub_el) self.plot_element(sub_el)
except TypeError: # Element is not iterable... except TypeError: # Element is not iterable...
if self.app.is_legacy is False: # if self.app.is_legacy is False:
self.add_shape(shape=element, color=color, visible=visible, layer=0) self.add_shape(shape=element, color=color, visible=visible, layer=0)
else: # else:
if type(element) == Polygon: # if type(element) == Polygon:
x, y = element.exterior.coords.xy # x, y = element.exterior.coords.xy
self.axes.plot(x, y, 'r-') # self.axes.plot(x, y, 'r-')
for ints in element.interiors: # for ints in element.interiors:
x, y = ints.coords.xy # x, y = ints.coords.xy
self.axes.plot(x, y, 'r-') # self.axes.plot(x, y, 'r-')
return # return
#
if type(element) == LineString or type(element) == LinearRing: # if type(element) == LineString or type(element) == LinearRing:
x, y = element.coords.xy # x, y = element.coords.xy
self.axes.plot(x, y, 'r-') # self.axes.plot(x, y, 'r-')
return # return
def plot(self, visible=None, kind=None): def plot(self, visible=None, kind=None):
""" """
@ -5479,10 +5418,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
self.plot_element(self.solid_geometry, visible=visible) self.plot_element(self.solid_geometry, visible=visible)
# self.plot_element(self.solid_geometry, visible=self.options['plot']) # self.plot_element(self.solid_geometry, visible=self.options['plot'])
if self.app.is_legacy is False:
self.shapes.redraw() self.shapes.redraw()
else:
self.app.plotcanvas.auto_adjust_axes()
except (ObjectDeleted, AttributeError): except (ObjectDeleted, AttributeError):
self.shapes.clear(update=True) self.shapes.clear(update=True)
@ -5644,9 +5582,10 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
# from predecessors. # from predecessors.
self.ser_attrs += ['options', 'kind', 'cnc_tools', 'multitool'] self.ser_attrs += ['options', 'kind', 'cnc_tools', 'multitool']
self.text_col = self.app.plotcanvas.new_text_collection() if self.app.is_legacy is False:
self.text_col.enabled = True self.text_col = self.app.plotcanvas.new_text_collection()
self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col) self.text_col.enabled = True
self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col)
def build_ui(self): def build_ui(self):
self.ui_disconnect() self.ui_disconnect()
@ -5821,8 +5760,9 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
pass pass
self.ui.annotation_cb.stateChanged.connect(self.on_annotation_change) self.ui.annotation_cb.stateChanged.connect(self.on_annotation_change)
# set if to display text annotations if self.app.is_legacy is False:
self.ui.annotation_cb.set_value(self.app.defaults["cncjob_annotation"]) # set if to display text annotations
self.ui.annotation_cb.set_value(self.app.defaults["cncjob_annotation"])
# Show/Hide Advanced Options # Show/Hide Advanced Options
if self.app.defaults["global_app_level"] == 'b': if self.app.defaults["global_app_level"] == 'b':
@ -6271,11 +6211,12 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
visible = visible if visible else self.options['plot'] visible = visible if visible else self.options['plot']
if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value(): if self.app.is_legacy is False:
self.text_col.enabled = True if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
else: self.text_col.enabled = True
self.text_col.enabled = False else:
self.annotation.redraw() self.text_col.enabled = False
self.annotation.redraw()
try: try:
if self.multitool is False: # single tool usage if self.multitool is False: # single tool usage
@ -6294,16 +6235,20 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
self.shapes.redraw() self.shapes.redraw()
except (ObjectDeleted, AttributeError): except (ObjectDeleted, AttributeError):
self.shapes.clear(update=True) self.shapes.clear(update=True)
self.annotation.clear(update=True) if self.app.is_legacy is False:
self.annotation.clear(update=True)
def on_annotation_change(self): def on_annotation_change(self):
if self.ui.annotation_cb.get_value(): if self.app.is_legacy is False:
self.text_col.enabled = True if self.ui.annotation_cb.get_value():
self.text_col.enabled = True
else:
self.text_col.enabled = False
# kind = self.ui.cncplot_method_combo.get_value()
# self.plot(kind=kind)
self.annotation.redraw()
else: else:
self.text_col.enabled = False self.inform.emit(_("Not available with the current Graphic Engine Legacy(2D)."))
# kind = self.ui.cncplot_method_combo.get_value()
# self.plot(kind=kind)
self.annotation.redraw()
def convert_units(self, units): def convert_units(self, units):
log.debug("FlatCAMObj.FlatCAMECNCjob.convert_units()") log.debug("FlatCAMObj.FlatCAMECNCjob.convert_units()")

View File

@ -12,8 +12,12 @@ CAD program, and create G-Code for Isolation routing.
21.09.2019 21.09.2019
- fixed Measuring Tool in legacy graphic engine - fixed Measuring Tool in legacy graphic engine
- fixed Gerber plotting - fixed Gerber plotting in legacy graphic engine
- fixed Geometry plotting - fixed Geometry plotting in legacy graphic engine
- fixed CNCJob and Excellon plotting in legacy graphic engine
- in legacy graphic engine fixed the travel vs cut lines in CNCJob objects
- final fix for key shortcuts with modifier in legacy graphic engine
- refactored some of the code in the legacy graphic engine
20.09.2019 20.09.2019

View File

@ -125,7 +125,7 @@ class Geometry(object):
self.temp_shapes = self.app.plotcanvas.new_shape_group() self.temp_shapes = self.app.plotcanvas.new_shape_group()
else: else:
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.temp_shapes = ShapeCollectionLegacy() self.temp_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='camlib.geometry')
# if geo_steps_per_circle is None: # if geo_steps_per_circle is None:
# geo_steps_per_circle = int(Geometry.defaults["geo_steps_per_circle"]) # geo_steps_per_circle = int(Geometry.defaults["geo_steps_per_circle"])

View File

@ -2017,8 +2017,8 @@ class FlatCAMExcEditor(QtCore.QObject):
self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1) self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1)
else: else:
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.shapes = ShapeCollectionLegacy() self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_exc_editor')
self.tool_shape = ShapeCollectionLegacy() self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_exc_editor')
self.app.pool_recreated.connect(self.pool_recreated) self.app.pool_recreated.connect(self.pool_recreated)

View File

@ -3030,8 +3030,8 @@ class FlatCAMGeoEditor(QtCore.QObject):
self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1) self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1)
else: else:
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.shapes = ShapeCollectionLegacy() self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_geo_editor')
self.tool_shape = ShapeCollectionLegacy() self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_geo_editor')
self.app.pool_recreated.connect(self.pool_recreated) self.app.pool_recreated.connect(self.pool_recreated)

View File

@ -2827,9 +2827,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
self.ma_annotation = self.canvas.new_text_group() self.ma_annotation = self.canvas.new_text_group()
else: else:
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.shapes = ShapeCollectionLegacy() self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_grb_editor')
self.tool_shape = ShapeCollectionLegacy() self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_grb_editor')
self.ma_annotation = ShapeCollectionLegacy() self.ma_annotation = ShapeCollectionLegacy(obj=self, app=self.app, name='ma_anno_grb_editor')
self.app.pool_recreated.connect(self.pool_recreated) self.app.pool_recreated.connect(self.pool_recreated)

View File

@ -2272,31 +2272,23 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
# events from the GUI are of type QKeyEvent # events from the GUI are of type QKeyEvent
elif type(event) == QtGui.QKeyEvent: elif type(event) == QtGui.QKeyEvent:
key = event.key() key = event.key()
elif isinstance(event, mpl_key_event): elif isinstance(event, mpl_key_event): # MatPlotLib key events are tricky to interpret as the rest
key = event.key key = event.key
# if modifiers == QtCore.Qt.NoModifier: key = QtGui.QKeySequence(key)
try:
key = ord(key.upper()) # check for modifiers
except TypeError: key_string = key.toString().lower()
key = key.upper() if '+' in key_string:
if 'ctrl' in key.lower(): mod, __, key_text = key_string.rpartition('+')
if mod.lower() == 'ctrl':
modifiers = QtCore.Qt.ControlModifier modifiers = QtCore.Qt.ControlModifier
try: elif mod.lower() == 'alt':
key = ord(key.rpartition('+')[2].upper())
except TypeError:
pass
elif 'alt' in key.lower():
modifiers = QtCore.Qt.AltModifier modifiers = QtCore.Qt.AltModifier
try: elif mod.lower() == 'shift':
key = ord(key.rpartition('+')[2].upper())
except TypeError:
pass
elif 'shift' in key.lower():
modifiers = QtCore.Qt.ShiftModifier modifiers = QtCore.Qt.ShiftModifier
try: else:
key = ord(key.rpartition('+')[2].upper()) modifiers = QtCore.Qt.NoModifier
except TypeError: key = QtGui.QKeySequence(key_text)
pass
# events from Vispy are of type KeyEvent # events from Vispy are of type KeyEvent
else: else:

View File

@ -16,7 +16,14 @@ from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_agg import FigureCanvasAgg from matplotlib.backends.backend_agg import FigureCanvasAgg
from matplotlib.widgets import Cursor from matplotlib.widgets import Cursor
# needed for legacy mode
# Used for solid polygons in Matplotlib
from descartes.patch import PolygonPatch
from shapely.geometry import Polygon, LineString, LinearRing, Point, MultiPolygon, MultiLineString
import FlatCAMApp import FlatCAMApp
from copy import deepcopy
import logging import logging
mpl_use("Qt5Agg") mpl_use("Qt5Agg")
@ -679,26 +686,171 @@ class MplCursor(Cursor):
class ShapeCollectionLegacy(): class ShapeCollectionLegacy():
def __init__(self): def __init__(self, obj, app, name=None):
self._shapes = []
self.obj = obj
self.app = app
self._shapes = dict()
self.shape_dict = dict()
self.shape_id = 0
self._color = None
self._face_color = None
self._visible = True
self._update = False
self._obj = None
self._gcode_parsed = None
if name is None:
axes_name = self.obj.options['name']
else:
axes_name = name
# Axes must exist and be attached to canvas.
if axes_name not in self.app.plotcanvas.figure.axes:
self.axes = self.app.plotcanvas.new_axes(axes_name)
def add(self, shape=None, color=None, face_color=None, alpha=None, visible=True, def add(self, shape=None, color=None, face_color=None, alpha=None, visible=True,
update=False, layer=1, tolerance=0.01): update=False, layer=1, tolerance=0.01, obj=None, gcode_parsed=None, tool_tolerance=None, tooldia=None):
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._visible = visible
self._update = update
# CNCJob oject related arguments
self._obj = obj
self._gcode_parsed = gcode_parsed
self._tool_tolerance = tool_tolerance
self._tooldia = tooldia
try: try:
for sh in shape: for sh in shape:
self._shapes.append(sh) self.shape_id += 1
except TypeError: self.shape_dict.update({
self._shapes.append(shape) 'color': self._color,
'face_color': self._face_color,
'shape': sh
})
return len(self._shapes) - 1 self._shapes.update({
self.shape_id: deepcopy(self.shape_dict)
})
except TypeError:
self.shape_id += 1
self.shape_dict.update({
'color': self._color,
'face_color': self._face_color,
'shape': shape
})
self._shapes.update({
self.shape_id: deepcopy(self.shape_dict)
})
return self.shape_id
def clear(self, update=None): def clear(self, update=None):
self._shapes[:] = [] self._shapes.clear()
self.shape_id = 0
self.axes.cla()
self.app.plotcanvas.auto_adjust_axes()
if update is True: if update is True:
self.redraw() self.redraw()
def redraw(self): def redraw(self):
pass path_num = 0
if self._visible:
for element in self._shapes:
if self.obj.kind == 'excellon':
# Plot excellon (All polygons?)
if self.obj.options["solid"]:
patch = PolygonPatch(self._shapes[element]['shape'],
facecolor="#C40000",
edgecolor="#750000",
alpha=0.75,
zorder=3)
self.axes.add_patch(patch)
else:
x, y = self._shapes[element]['shape'].exterior.coords.xy
self.axes.plot(x, y, 'r-')
for ints in self._shapes[element]['shape'].interiors:
x, y = ints.coords.xy
self.axes.plot(x, y, 'o-')
elif self.obj.kind == 'geometry':
if type(self._shapes[element]['shape']) == Polygon:
x, y = self._shapes[element]['shape'].exterior.coords.xy
self.axes.plot(x, y, self._shapes[element]['color'], linestyle='-')
for ints in self._shapes[element]['shape'].interiors:
x, y = ints.coords.xy
self.axes.plot(x, y, self._shapes[element]['color'], linestyle='-')
elif type(element) == LineString or type(element) == LinearRing:
x, y = element.coords.xy
self.axes.plot(x, y, self._shapes[element]['color'], marker='-')
return
elif self.obj.kind == 'gerber':
if self.obj.options["multicolored"]:
linespec = '-'
else:
linespec = 'k-'
if self.obj.options["solid"]:
try:
patch = PolygonPatch(self._shapes[element]['shape'],
facecolor=self._shapes[element]['face_color'],
edgecolor=self._shapes[element]['color'],
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(element))
else:
x, y = self._shapes[element]['shape'].exterior.xy
self.axes.plot(x, y, linespec)
for ints in self._shapes[element]['shape'].interiors:
x, y = ints.coords.xy
self.axes.plot(x, y, linespec)
elif self.obj.kind == 'cncjob':
if self._shapes[element]['face_color'] is None:
linespec = '--'
linecolor = self._shapes[element]['color']
# if geo['kind'][0] == 'C':
# linespec = 'k-'
x, y = self._shapes[element]['shape'].coords.xy
self.axes.plot(x, y, linespec, color=linecolor)
else:
path_num += 1
if isinstance(self._shapes[element]['shape'], Polygon):
self.axes.annotate(str(path_num), xy=self._shapes[element]['shape'].exterior.coords[0],
xycoords='data')
else:
self.axes.annotate(str(path_num), xy=self._shapes[element]['shape'].coords[0],
xycoords='data')
patch = PolygonPatch(self._shapes[element]['shape'],
facecolor=self._shapes[element]['face_color'],
edgecolor=self._shapes[element]['color'],
alpha=0.75, zorder=2)
self.axes.add_patch(patch)
self.app.plotcanvas.auto_adjust_axes()
@property
def visible(self):
return self._visible
@visible.setter
def visible(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

View File

@ -117,7 +117,7 @@ class Measurement(FlatCAMTool):
self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1) self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1)
else: else:
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.sel_shapes = ShapeCollectionLegacy() self.sel_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='measurement')
self.measure_btn.clicked.connect(self.activate_measure_tool) self.measure_btn.clicked.connect(self.activate_measure_tool)

View File

@ -48,7 +48,7 @@ class ToolMove(FlatCAMTool):
self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1) self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1)
else: else:
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
self.sel_shapes = ShapeCollectionLegacy() self.sel_shapes = ShapeCollectionLegacy(obj=self, app=self.app, name="move")
self.replot_signal[list].connect(self.replot) self.replot_signal[list].connect(self.replot)