- optimized the Move Tool

- added support for key-based panning in 3D graphic engine. Moving the mouse wheel while pressing the CTRL key will pan up-down and while pressing SHIFT key will pan left-right
This commit is contained in:
Marius Stanciu
2019-10-12 16:31:44 +03:00
committed by Marius
parent 0ca078abf2
commit 3bebc16725
8 changed files with 196 additions and 148 deletions

View File

@@ -12,6 +12,7 @@ import logging
from flatcamGUI.VisPyCanvas import VisPyCanvas, time, Color
from flatcamGUI.VisPyVisuals import ShapeGroup, ShapeCollection, TextCollection, TextGroup, Cursor
from vispy.scene.visuals import InfiniteLine, Line
import numpy as np
from vispy.geometry import Rect
@@ -103,6 +104,8 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
# Keep VisPy canvas happy by letting it be "frozen" again.
self.freeze()
self.graph_event_connect('mouse_wheel', self.on_mouse_scroll)
# 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
def draw_workspace(self):
@@ -250,6 +253,43 @@ class PlotCanvas(QtCore.QObject, VisPyCanvas):
self.cursor_v_line.set_data(pos=pos[0], color=self.line_color)
self.view.scene.update()
def on_mouse_scroll(self, event):
# key modifiers
modifiers = event.modifiers
pan_delta_x = self.fcapp.defaults["global_gridx"]
pan_delta_y = self.fcapp.defaults["global_gridy"]
curr_pos = event.pos
# Controlled pan by mouse wheel
if 'Shift' in modifiers:
p1 = np.array(curr_pos)[:2]
if event.delta[1] > 0:
curr_pos[0] -= pan_delta_x
else:
curr_pos[0] += pan_delta_x
p2 = np.array(curr_pos)[:2]
self.view.camera.pan(p2 - p1)
elif 'Control' in modifiers:
p1 = np.array(curr_pos)[:2]
if event.delta[1] > 0:
curr_pos[1] += pan_delta_y
else:
curr_pos[1] -= pan_delta_y
p2 = np.array(curr_pos)[:2]
self.view.camera.pan(p2 - p1)
if self.fcapp.grid_status() == True:
pos_canvas = self.translate_coords(curr_pos)
pos = self.fcapp.geo_editor.snap(pos_canvas[0], pos_canvas[1])
# Update cursor
self.fcapp.app_cursor.set_data(np.asarray([(pos[0], pos[1])]),
symbol='++', edge_color=self.fcapp.cursor_color_3D,
size=self.fcapp.defaults["global_cursor_size"])
def new_text_group(self, collection=None):
if collection:
return TextGroup(collection)

View File

@@ -133,6 +133,9 @@ class Camera(scene.PanZoomCamera):
if event.handled or not self.interactive:
return
# key modifiers
modifiers = event.mouse_event.modifiers
# Limit mouse move events
last_event = event.last_event
t = time.time()
@@ -147,21 +150,21 @@ class Camera(scene.PanZoomCamera):
event.handled = True
return
# Scrolling
# ################### Scrolling ##########################
BaseCamera.viewbox_mouse_event(self, event)
if event.type == 'mouse_wheel':
center = self._scene_transform.imap(event.pos)
scale = (1 + self.zoom_factor) ** (-event.delta[1] * 30)
self.limited_zoom(scale, center)
if not modifiers:
center = self._scene_transform.imap(event.pos)
scale = (1 + self.zoom_factor) ** (-event.delta[1] * 30)
self.limited_zoom(scale, center)
event.handled = True
elif event.type == 'mouse_move':
if event.press_event is None:
return
modifiers = event.mouse_event.modifiers
# ################ Panning ############################
# self.pan_button_setting is actually self.FlatCAM.APP.defaults['global_pan_button']
if event.button == int(self.pan_button_setting) and not modifiers:
# Translate