- 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:
parent
9aef293a26
commit
bc6dc3decf
|
@ -6690,7 +6690,12 @@ class App(QtCore.QObject):
|
|||
if self.is_legacy is True:
|
||||
# Remove plot only if the object was plotted otherwise delaxes will fail
|
||||
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()
|
||||
|
||||
# Remove from dictionary
|
||||
|
@ -6740,7 +6745,12 @@ class App(QtCore.QObject):
|
|||
def on_set_zero_click(self, event):
|
||||
# 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 self.grid_status() == True:
|
||||
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)
|
||||
else:
|
||||
# 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):
|
||||
"""
|
||||
|
|
247
FlatCAMObj.py
247
FlatCAMObj.py
|
@ -85,7 +85,7 @@ class FlatCAMObj(QtCore.QObject):
|
|||
if self.app.is_legacy is False:
|
||||
self.shapes = self.app.plotcanvas.new_shape_group()
|
||||
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 = {}
|
||||
|
@ -339,22 +339,7 @@ class FlatCAMObj(QtCore.QObject):
|
|||
if self.deleted:
|
||||
return False
|
||||
|
||||
if self.app.is_legacy:
|
||||
# 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()
|
||||
self.clear()
|
||||
return True
|
||||
|
||||
def single_object_plot(self):
|
||||
|
@ -414,11 +399,12 @@ class FlatCAMObj(QtCore.QObject):
|
|||
def worker_task(app_obj):
|
||||
self.shapes.visible = value
|
||||
|
||||
# Not all object types has annotations
|
||||
try:
|
||||
self.annotation.visible = value
|
||||
except Exception as e:
|
||||
pass
|
||||
if self.app.is_legacy is False:
|
||||
# Not all object types has annotations
|
||||
try:
|
||||
self.annotation.visible = value
|
||||
except Exception as e:
|
||||
pass
|
||||
|
||||
if threaded is False:
|
||||
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)
|
||||
else:
|
||||
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
|
||||
self.on_aperture_table_visibility_change()
|
||||
|
@ -1369,73 +1356,45 @@ 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
|
||||
|
||||
try:
|
||||
if self.options["solid"]:
|
||||
for g in geometry:
|
||||
if type(g) == Polygon or type(g) == LineString:
|
||||
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:
|
||||
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,
|
||||
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',
|
||||
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',
|
||||
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',
|
||||
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()
|
||||
self.shapes.redraw()
|
||||
except (ObjectDeleted, AttributeError):
|
||||
self.shapes.clear(update=True)
|
||||
|
||||
# experimental plot() when the solid_geometry is stored in the self.apertures
|
||||
def plot_aperture(self, **kwargs):
|
||||
|
@ -3164,42 +3123,22 @@ class FlatCAMExcellon(FlatCAMObj, Excellon):
|
|||
|
||||
visible = visible if visible else self.options['plot']
|
||||
|
||||
if self.app.is_legacy is False:
|
||||
try:
|
||||
# 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?)
|
||||
try:
|
||||
# Plot Excellon (All polygons?)
|
||||
if self.options["solid"]:
|
||||
for geo in self.solid_geometry:
|
||||
patch = PolygonPatch(geo,
|
||||
facecolor="#C40000",
|
||||
edgecolor="#750000",
|
||||
alpha=0.75,
|
||||
zorder=3)
|
||||
self.axes.add_patch(patch)
|
||||
self.add_shape(shape=geo, color='#750000BF', face_color='#C40000BF',
|
||||
visible=visible,
|
||||
layer=2)
|
||||
else:
|
||||
for geo in self.solid_geometry:
|
||||
x, y = geo.exterior.coords.xy
|
||||
self.axes.plot(x, y, 'r-')
|
||||
self.add_shape(shape=geo.exterior, color='red', visible=visible)
|
||||
for ints in geo.interiors:
|
||||
x, y = ints.coords.xy
|
||||
self.axes.plot(x, y, 'g-')
|
||||
self.add_shape(shape=ints, color='orange', visible=visible)
|
||||
|
||||
self.app.plotcanvas.auto_adjust_axes()
|
||||
self.shapes.redraw()
|
||||
except (ObjectDeleted, AttributeError):
|
||||
self.shapes.clear(update=True)
|
||||
|
||||
|
||||
class FlatCAMGeometry(FlatCAMObj, Geometry):
|
||||
|
@ -5434,21 +5373,21 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
self.plot_element(sub_el)
|
||||
|
||||
except TypeError: # Element is not iterable...
|
||||
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
|
||||
# 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):
|
||||
"""
|
||||
|
@ -5479,10 +5418,9 @@ class FlatCAMGeometry(FlatCAMObj, Geometry):
|
|||
self.plot_element(self.solid_geometry, visible=visible)
|
||||
|
||||
# self.plot_element(self.solid_geometry, visible=self.options['plot'])
|
||||
if self.app.is_legacy is False:
|
||||
self.shapes.redraw()
|
||||
else:
|
||||
self.app.plotcanvas.auto_adjust_axes()
|
||||
|
||||
self.shapes.redraw()
|
||||
|
||||
except (ObjectDeleted, AttributeError):
|
||||
self.shapes.clear(update=True)
|
||||
|
||||
|
@ -5644,9 +5582,10 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
|||
# from predecessors.
|
||||
self.ser_attrs += ['options', 'kind', 'cnc_tools', 'multitool']
|
||||
|
||||
self.text_col = self.app.plotcanvas.new_text_collection()
|
||||
self.text_col.enabled = True
|
||||
self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col)
|
||||
if self.app.is_legacy is False:
|
||||
self.text_col = self.app.plotcanvas.new_text_collection()
|
||||
self.text_col.enabled = True
|
||||
self.annotation = self.app.plotcanvas.new_text_group(collection=self.text_col)
|
||||
|
||||
def build_ui(self):
|
||||
self.ui_disconnect()
|
||||
|
@ -5821,8 +5760,9 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
|||
pass
|
||||
self.ui.annotation_cb.stateChanged.connect(self.on_annotation_change)
|
||||
|
||||
# set if to display text annotations
|
||||
self.ui.annotation_cb.set_value(self.app.defaults["cncjob_annotation"])
|
||||
if self.app.is_legacy is False:
|
||||
# set if to display text annotations
|
||||
self.ui.annotation_cb.set_value(self.app.defaults["cncjob_annotation"])
|
||||
|
||||
# Show/Hide Advanced Options
|
||||
if self.app.defaults["global_app_level"] == 'b':
|
||||
|
@ -6271,11 +6211,12 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
|||
|
||||
visible = visible if visible else self.options['plot']
|
||||
|
||||
if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
|
||||
self.text_col.enabled = True
|
||||
else:
|
||||
self.text_col.enabled = False
|
||||
self.annotation.redraw()
|
||||
if self.app.is_legacy is False:
|
||||
if self.ui.annotation_cb.get_value() and self.ui.plot_cb.get_value():
|
||||
self.text_col.enabled = True
|
||||
else:
|
||||
self.text_col.enabled = False
|
||||
self.annotation.redraw()
|
||||
|
||||
try:
|
||||
if self.multitool is False: # single tool usage
|
||||
|
@ -6294,16 +6235,20 @@ class FlatCAMCNCjob(FlatCAMObj, CNCjob):
|
|||
self.shapes.redraw()
|
||||
except (ObjectDeleted, AttributeError):
|
||||
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):
|
||||
if self.ui.annotation_cb.get_value():
|
||||
self.text_col.enabled = True
|
||||
if self.app.is_legacy is False:
|
||||
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:
|
||||
self.text_col.enabled = False
|
||||
# kind = self.ui.cncplot_method_combo.get_value()
|
||||
# self.plot(kind=kind)
|
||||
self.annotation.redraw()
|
||||
self.inform.emit(_("Not available with the current Graphic Engine Legacy(2D)."))
|
||||
|
||||
def convert_units(self, units):
|
||||
log.debug("FlatCAMObj.FlatCAMECNCjob.convert_units()")
|
||||
|
|
|
@ -12,8 +12,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
|
||||
- fixed Gerber plotting in legacy graphic engine
|
||||
- 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
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ class Geometry(object):
|
|||
self.temp_shapes = self.app.plotcanvas.new_shape_group()
|
||||
else:
|
||||
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:
|
||||
# geo_steps_per_circle = int(Geometry.defaults["geo_steps_per_circle"])
|
||||
|
|
|
@ -2017,8 +2017,8 @@ class FlatCAMExcEditor(QtCore.QObject):
|
|||
self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1)
|
||||
else:
|
||||
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
||||
self.shapes = ShapeCollectionLegacy()
|
||||
self.tool_shape = ShapeCollectionLegacy()
|
||||
self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_exc_editor')
|
||||
self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_exc_editor')
|
||||
|
||||
self.app.pool_recreated.connect(self.pool_recreated)
|
||||
|
||||
|
|
|
@ -3030,8 +3030,8 @@ class FlatCAMGeoEditor(QtCore.QObject):
|
|||
self.tool_shape = self.app.plotcanvas.new_shape_collection(layers=1)
|
||||
else:
|
||||
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
||||
self.shapes = ShapeCollectionLegacy()
|
||||
self.tool_shape = ShapeCollectionLegacy()
|
||||
self.shapes = ShapeCollectionLegacy(obj=self, app=self.app, name='shapes_geo_editor')
|
||||
self.tool_shape = ShapeCollectionLegacy(obj=self, app=self.app, name='tool_shapes_geo_editor')
|
||||
|
||||
self.app.pool_recreated.connect(self.pool_recreated)
|
||||
|
||||
|
|
|
@ -2827,9 +2827,9 @@ class FlatCAMGrbEditor(QtCore.QObject):
|
|||
self.ma_annotation = self.canvas.new_text_group()
|
||||
else:
|
||||
from flatcamGUI.PlotCanvasLegacy import ShapeCollectionLegacy
|
||||
self.shapes = ShapeCollectionLegacy()
|
||||
self.tool_shape = ShapeCollectionLegacy()
|
||||
self.ma_annotation = 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.app.pool_recreated.connect(self.pool_recreated)
|
||||
|
||||
|
|
|
@ -2272,31 +2272,23 @@ class FlatCAMGUI(QtWidgets.QMainWindow):
|
|||
# events from the GUI are of type QKeyEvent
|
||||
elif type(event) == QtGui.QKeyEvent:
|
||||
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
|
||||
# if modifiers == QtCore.Qt.NoModifier:
|
||||
try:
|
||||
key = ord(key.upper())
|
||||
except TypeError:
|
||||
key = key.upper()
|
||||
if 'ctrl' in key.lower():
|
||||
key = QtGui.QKeySequence(key)
|
||||
|
||||
# check for modifiers
|
||||
key_string = key.toString().lower()
|
||||
if '+' in key_string:
|
||||
mod, __, key_text = key_string.rpartition('+')
|
||||
if mod.lower() == 'ctrl':
|
||||
modifiers = QtCore.Qt.ControlModifier
|
||||
try:
|
||||
key = ord(key.rpartition('+')[2].upper())
|
||||
except TypeError:
|
||||
pass
|
||||
elif 'alt' in key.lower():
|
||||
elif mod.lower() == 'alt':
|
||||
modifiers = QtCore.Qt.AltModifier
|
||||
try:
|
||||
key = ord(key.rpartition('+')[2].upper())
|
||||
except TypeError:
|
||||
pass
|
||||
elif 'shift' in key.lower():
|
||||
elif mod.lower() == 'shift':
|
||||
modifiers = QtCore.Qt.ShiftModifier
|
||||
try:
|
||||
key = ord(key.rpartition('+')[2].upper())
|
||||
except TypeError:
|
||||
pass
|
||||
else:
|
||||
modifiers = QtCore.Qt.NoModifier
|
||||
key = QtGui.QKeySequence(key_text)
|
||||
|
||||
# events from Vispy are of type KeyEvent
|
||||
else:
|
||||
|
|
|
@ -16,7 +16,14 @@ from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
|
|||
from matplotlib.backends.backend_agg import FigureCanvasAgg
|
||||
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
|
||||
from copy import deepcopy
|
||||
import logging
|
||||
|
||||
mpl_use("Qt5Agg")
|
||||
|
@ -679,26 +686,171 @@ class MplCursor(Cursor):
|
|||
|
||||
class ShapeCollectionLegacy():
|
||||
|
||||
def __init__(self):
|
||||
self._shapes = []
|
||||
def __init__(self, obj, app, name=None):
|
||||
|
||||
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,
|
||||
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:
|
||||
for sh in shape:
|
||||
self._shapes.append(sh)
|
||||
except TypeError:
|
||||
self._shapes.append(shape)
|
||||
self.shape_id += 1
|
||||
self.shape_dict.update({
|
||||
'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):
|
||||
self._shapes[:] = []
|
||||
self._shapes.clear()
|
||||
self.shape_id = 0
|
||||
|
||||
self.axes.cla()
|
||||
self.app.plotcanvas.auto_adjust_axes()
|
||||
|
||||
if update is True:
|
||||
self.redraw()
|
||||
|
||||
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
|
||||
|
|
|
@ -117,7 +117,7 @@ class Measurement(FlatCAMTool):
|
|||
self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1)
|
||||
else:
|
||||
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)
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class ToolMove(FlatCAMTool):
|
|||
self.sel_shapes = ShapeCollection(parent=self.app.plotcanvas.view.scene, layers=1)
|
||||
else:
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue