|
@@ -18,12 +18,12 @@ from vispy.geometry import Rect
|
|
|
log = logging.getLogger('base')
|
|
log = logging.getLogger('base')
|
|
|
|
|
|
|
|
|
|
|
|
|
-class PlotCanvas(QtCore.QObject):
|
|
|
|
|
|
|
+class PlotCanvas(QtCore.QObject, VisPyCanvas):
|
|
|
"""
|
|
"""
|
|
|
Class handling the plotting area in the application.
|
|
Class handling the plotting area in the application.
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
- def __init__(self, container, app):
|
|
|
|
|
|
|
+ def __init__(self, container, fcapp):
|
|
|
"""
|
|
"""
|
|
|
The constructor configures the VisPy figure that
|
|
The constructor configures the VisPy figure that
|
|
|
will contain all plots, creates the base axes and connects
|
|
will contain all plots, creates the base axes and connects
|
|
@@ -34,8 +34,12 @@ class PlotCanvas(QtCore.QObject):
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
super(PlotCanvas, self).__init__()
|
|
super(PlotCanvas, self).__init__()
|
|
|
|
|
+ VisPyCanvas.__init__(self)
|
|
|
|
|
|
|
|
- self.app = app
|
|
|
|
|
|
|
+ # VisPyCanvas does not allow new attributes. Override.
|
|
|
|
|
+ self.unfreeze()
|
|
|
|
|
+
|
|
|
|
|
+ self.fcapp = fcapp
|
|
|
|
|
|
|
|
# Parent container
|
|
# Parent container
|
|
|
self.container = container
|
|
self.container = container
|
|
@@ -44,19 +48,19 @@ class PlotCanvas(QtCore.QObject):
|
|
|
# which might decrease performance
|
|
# which might decrease performance
|
|
|
self.b_line, self.r_line, self.t_line, self.l_line = None, None, None, None
|
|
self.b_line, self.r_line, self.t_line, self.l_line = None, None, None, None
|
|
|
|
|
|
|
|
- # Attach to parent
|
|
|
|
|
- self.vispy_canvas = VisPyCanvas()
|
|
|
|
|
|
|
+ # <VisPyCanvas>
|
|
|
|
|
+ self.create_native()
|
|
|
|
|
+ self.native.setParent(self.fcapp.ui)
|
|
|
|
|
|
|
|
- self.vispy_canvas.create_native()
|
|
|
|
|
- self.vispy_canvas.native.setParent(self.app.ui)
|
|
|
|
|
- self.container.addWidget(self.vispy_canvas.native)
|
|
|
|
|
|
|
+ # <QtCore.QObject>
|
|
|
|
|
+ self.container.addWidget(self.native)
|
|
|
|
|
|
|
|
# ## AXIS # ##
|
|
# ## AXIS # ##
|
|
|
self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=True,
|
|
self.v_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=True,
|
|
|
- parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ parent=self.view.scene)
|
|
|
|
|
|
|
|
self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=False,
|
|
self.h_line = InfiniteLine(pos=0, color=(0.70, 0.3, 0.3, 1.0), vertical=False,
|
|
|
- parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ parent=self.view.scene)
|
|
|
|
|
|
|
|
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
|
|
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
|
|
|
# all CNC have a limited workspace
|
|
# all CNC have a limited workspace
|
|
@@ -70,12 +74,15 @@ class PlotCanvas(QtCore.QObject):
|
|
|
self.shape_collections = []
|
|
self.shape_collections = []
|
|
|
|
|
|
|
|
self.shape_collection = self.new_shape_collection()
|
|
self.shape_collection = self.new_shape_collection()
|
|
|
- self.app.pool_recreated.connect(self.on_pool_recreated)
|
|
|
|
|
|
|
+ self.fcapp.pool_recreated.connect(self.on_pool_recreated)
|
|
|
self.text_collection = self.new_text_collection()
|
|
self.text_collection = self.new_text_collection()
|
|
|
|
|
|
|
|
# TODO: Should be setting to show/hide CNC job annotations (global or per object)
|
|
# TODO: Should be setting to show/hide CNC job annotations (global or per object)
|
|
|
self.text_collection.enabled = True
|
|
self.text_collection.enabled = True
|
|
|
|
|
|
|
|
|
|
+ # Keep VisPy canvas happy by letting it be "frozen" again.
|
|
|
|
|
+ self.freeze()
|
|
|
|
|
+
|
|
|
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
|
|
# draw a rectangle made out of 4 lines on the canvas to serve as a hint for the work area
|
|
|
# all CNC have a limited workspace
|
|
# all CNC have a limited workspace
|
|
|
def draw_workspace(self):
|
|
def draw_workspace(self):
|
|
@@ -91,38 +98,38 @@ class PlotCanvas(QtCore.QObject):
|
|
|
a3p_mm = np.array([(0, 0), (297, 0), (297, 420), (0, 420)])
|
|
a3p_mm = np.array([(0, 0), (297, 0), (297, 420), (0, 420)])
|
|
|
a3l_mm = np.array([(0, 0), (420, 0), (420, 297), (0, 297)])
|
|
a3l_mm = np.array([(0, 0), (420, 0), (420, 297), (0, 297)])
|
|
|
|
|
|
|
|
- if self.app.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM':
|
|
|
|
|
- if self.app.defaults['global_workspaceT'] == 'A4P':
|
|
|
|
|
|
|
+ if self.fcapp.ui.general_defaults_form.general_app_group.units_radio.get_value().upper() == 'MM':
|
|
|
|
|
+ if self.fcapp.defaults['global_workspaceT'] == 'A4P':
|
|
|
a = a4p_mm
|
|
a = a4p_mm
|
|
|
- elif self.app.defaults['global_workspaceT'] == 'A4L':
|
|
|
|
|
|
|
+ elif self.fcapp.defaults['global_workspaceT'] == 'A4L':
|
|
|
a = a4l_mm
|
|
a = a4l_mm
|
|
|
- elif self.app.defaults['global_workspaceT'] == 'A3P':
|
|
|
|
|
|
|
+ elif self.fcapp.defaults['global_workspaceT'] == 'A3P':
|
|
|
a = a3p_mm
|
|
a = a3p_mm
|
|
|
- elif self.app.defaults['global_workspaceT'] == 'A3L':
|
|
|
|
|
|
|
+ elif self.fcapp.defaults['global_workspaceT'] == 'A3L':
|
|
|
a = a3l_mm
|
|
a = a3l_mm
|
|
|
else:
|
|
else:
|
|
|
- if self.app.defaults['global_workspaceT'] == 'A4P':
|
|
|
|
|
|
|
+ if self.fcapp.defaults['global_workspaceT'] == 'A4P':
|
|
|
a = a4p_in
|
|
a = a4p_in
|
|
|
- elif self.app.defaults['global_workspaceT'] == 'A4L':
|
|
|
|
|
|
|
+ elif self.fcapp.defaults['global_workspaceT'] == 'A4L':
|
|
|
a = a4l_in
|
|
a = a4l_in
|
|
|
- elif self.app.defaults['global_workspaceT'] == 'A3P':
|
|
|
|
|
|
|
+ elif self.fcapp.defaults['global_workspaceT'] == 'A3P':
|
|
|
a = a3p_in
|
|
a = a3p_in
|
|
|
- elif self.app.defaults['global_workspaceT'] == 'A3L':
|
|
|
|
|
|
|
+ elif self.fcapp.defaults['global_workspaceT'] == 'A3L':
|
|
|
a = a3l_in
|
|
a = a3l_in
|
|
|
|
|
|
|
|
self.delete_workspace()
|
|
self.delete_workspace()
|
|
|
|
|
|
|
|
self.b_line = Line(pos=a[0:2], color=(0.70, 0.3, 0.3, 1.0),
|
|
self.b_line = Line(pos=a[0:2], color=(0.70, 0.3, 0.3, 1.0),
|
|
|
- antialias= True, method='agg', parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ antialias= True, method='agg', parent=self.view.scene)
|
|
|
self.r_line = Line(pos=a[1:3], color=(0.70, 0.3, 0.3, 1.0),
|
|
self.r_line = Line(pos=a[1:3], color=(0.70, 0.3, 0.3, 1.0),
|
|
|
- antialias= True, method='agg', parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ antialias= True, method='agg', parent=self.view.scene)
|
|
|
|
|
|
|
|
self.t_line = Line(pos=a[2:4], color=(0.70, 0.3, 0.3, 1.0),
|
|
self.t_line = Line(pos=a[2:4], color=(0.70, 0.3, 0.3, 1.0),
|
|
|
- antialias= True, method='agg', parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ antialias= True, method='agg', parent=self.view.scene)
|
|
|
self.l_line = Line(pos=np.array((a[0], a[3])), color=(0.70, 0.3, 0.3, 1.0),
|
|
self.l_line = Line(pos=np.array((a[0], a[3])), color=(0.70, 0.3, 0.3, 1.0),
|
|
|
- antialias= True, method='agg', parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ antialias= True, method='agg', parent=self.view.scene)
|
|
|
|
|
|
|
|
- if self.app.defaults['global_workspace'] is False:
|
|
|
|
|
|
|
+ if self.fcapp.defaults['global_workspace'] is False:
|
|
|
self.delete_workspace()
|
|
self.delete_workspace()
|
|
|
|
|
|
|
|
# delete the workspace lines from the plot by removing the parent
|
|
# delete the workspace lines from the plot by removing the parent
|
|
@@ -138,21 +145,21 @@ class PlotCanvas(QtCore.QObject):
|
|
|
# redraw the workspace lines on the plot by readding them to the parent view.scene
|
|
# redraw the workspace lines on the plot by readding them to the parent view.scene
|
|
|
def restore_workspace(self):
|
|
def restore_workspace(self):
|
|
|
try:
|
|
try:
|
|
|
- self.b_line.parent = self.vispy_canvas.view.scene
|
|
|
|
|
- self.r_line.parent = self.vispy_canvas.view.scene
|
|
|
|
|
- self.t_line.parent = self.vispy_canvas.view.scene
|
|
|
|
|
- self.l_line.parent = self.vispy_canvas.view.scene
|
|
|
|
|
|
|
+ self.b_line.parent = self.view.scene
|
|
|
|
|
+ self.r_line.parent = self.view.scene
|
|
|
|
|
+ self.t_line.parent = self.view.scene
|
|
|
|
|
+ self.l_line.parent = self.view.scene
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
def vis_connect(self, event_name, callback):
|
|
def vis_connect(self, event_name, callback):
|
|
|
- return getattr(self.vispy_canvas.events, event_name).connect(callback)
|
|
|
|
|
|
|
+ return getattr(self.events, event_name).connect(callback)
|
|
|
|
|
|
|
|
def vis_disconnect(self, event_name, callback=None):
|
|
def vis_disconnect(self, event_name, callback=None):
|
|
|
if callback is None:
|
|
if callback is None:
|
|
|
- getattr(self.vispy_canvas.events, event_name).disconnect()
|
|
|
|
|
|
|
+ getattr(self.events, event_name).disconnect()
|
|
|
else:
|
|
else:
|
|
|
- getattr(self.vispy_canvas.events, event_name).disconnect(callback)
|
|
|
|
|
|
|
+ getattr(self.events, event_name).disconnect(callback)
|
|
|
|
|
|
|
|
def zoom(self, factor, center=None):
|
|
def zoom(self, factor, center=None):
|
|
|
"""
|
|
"""
|
|
@@ -165,7 +172,7 @@ class PlotCanvas(QtCore.QObject):
|
|
|
:type center: list
|
|
:type center: list
|
|
|
:return: None
|
|
:return: None
|
|
|
"""
|
|
"""
|
|
|
- self.vispy_canvas.view.camera.zoom(factor, center)
|
|
|
|
|
|
|
+ self.view.camera.zoom(factor, center)
|
|
|
|
|
|
|
|
def new_shape_group(self, shape_collection=None):
|
|
def new_shape_group(self, shape_collection=None):
|
|
|
if shape_collection:
|
|
if shape_collection:
|
|
@@ -173,13 +180,13 @@ class PlotCanvas(QtCore.QObject):
|
|
|
return ShapeGroup(self.shape_collection)
|
|
return ShapeGroup(self.shape_collection)
|
|
|
|
|
|
|
|
def new_shape_collection(self, **kwargs):
|
|
def new_shape_collection(self, **kwargs):
|
|
|
- # sc = ShapeCollection(parent=self.vispy_canvas.view.scene, pool=self.app.pool, **kwargs)
|
|
|
|
|
|
|
+ # sc = ShapeCollection(parent=self.view.scene, pool=self.app.pool, **kwargs)
|
|
|
# self.shape_collections.append(sc)
|
|
# self.shape_collections.append(sc)
|
|
|
# return sc
|
|
# return sc
|
|
|
- return ShapeCollection(parent=self.vispy_canvas.view.scene, pool=self.app.pool, **kwargs)
|
|
|
|
|
|
|
+ return ShapeCollection(parent=self.view.scene, pool=self.fcapp.pool, **kwargs)
|
|
|
|
|
|
|
|
def new_cursor(self):
|
|
def new_cursor(self):
|
|
|
- c = Cursor(pos=np.empty((0, 2)), parent=self.vispy_canvas.view.scene)
|
|
|
|
|
|
|
+ c = Cursor(pos=np.empty((0, 2)), parent=self.view.scene)
|
|
|
c.antialias = 0
|
|
c.antialias = 0
|
|
|
return c
|
|
return c
|
|
|
|
|
|
|
@@ -190,7 +197,7 @@ class PlotCanvas(QtCore.QObject):
|
|
|
return TextGroup(self.text_collection)
|
|
return TextGroup(self.text_collection)
|
|
|
|
|
|
|
|
def new_text_collection(self, **kwargs):
|
|
def new_text_collection(self, **kwargs):
|
|
|
- return TextCollection(parent=self.vispy_canvas.view.scene, **kwargs)
|
|
|
|
|
|
|
+ return TextCollection(parent=self.view.scene, **kwargs)
|
|
|
|
|
|
|
|
def fit_view(self, rect=None):
|
|
def fit_view(self, rect=None):
|
|
|
|
|
|
|
@@ -212,7 +219,7 @@ class PlotCanvas(QtCore.QObject):
|
|
|
rect.right *= 1.01
|
|
rect.right *= 1.01
|
|
|
rect.top *= 1.01
|
|
rect.top *= 1.01
|
|
|
|
|
|
|
|
- self.vispy_canvas.view.camera.rect = rect
|
|
|
|
|
|
|
+ self.view.camera.rect = rect
|
|
|
|
|
|
|
|
self.shape_collection.unlock_updates()
|
|
self.shape_collection.unlock_updates()
|
|
|
|
|
|
|
@@ -227,7 +234,7 @@ class PlotCanvas(QtCore.QObject):
|
|
|
except TypeError:
|
|
except TypeError:
|
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
- self.vispy_canvas.view.camera.rect = rect
|
|
|
|
|
|
|
+ self.view.camera.rect = rect
|
|
|
|
|
|
|
|
self.shape_collection.unlock_updates()
|
|
self.shape_collection.unlock_updates()
|
|
|
|
|
|