View pan with MMB added.

Adding "geometry" & "cncjob" object doesn't cause auto zoom.
This commit is contained in:
Denvi
2015-11-28 13:27:29 +05:00
parent af46cae5c7
commit 5b7c9de8b3
2 changed files with 33 additions and 1 deletions

View File

@@ -1300,7 +1300,9 @@ class App(QtCore.QObject):
self.inform.emit("Object (%s) created: %s" % (obj.kind, obj.options['name']))
self.new_object_available.emit(obj)
obj.plot()
self.on_zoom_fit(None)
if obj.kind not in ["geometry", "cncjob"]: self.on_zoom_fit(None)
t1 = time.time() # DEBUG
self.log.debug("%f seconds adding object and plotting." % (t1 - t0))

View File

@@ -66,6 +66,8 @@ class PlotCanvas:
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
# Events
self.canvas.mpl_connect('button_press_event', self.on_mouse_down)
self.canvas.mpl_connect('button_release_event', self.on_mouse_up)
self.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
#self.canvas.connect('configure-event', self.auto_adjust_axes)
self.canvas.mpl_connect('resize_event', self.auto_adjust_axes)
@@ -78,6 +80,9 @@ class PlotCanvas:
self.mouse = [0, 0]
self.key = None
self.mouse_press_button = -1
self.mouse_press_pos = [0, 0]
def on_key_down(self, event):
"""
@@ -272,6 +277,19 @@ class PlotCanvas:
ax.set_xlim((xmin + x * width, xmax + x * width))
ax.set_ylim((ymin + y * height, ymax + y * height))
# Re-draw
self.canvas.draw()
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
def pan_by_coords(self, x, y):
xmin, xmax = self.axes.get_xlim()
ymin, ymax = self.axes.get_ylim()
# Adjust axes
for ax in self.figure.get_axes():
ax.set_xlim((xmin - x, xmax - x))
ax.set_ylim((ymin - y, ymax - y))
# Re-draw
self.canvas.draw()
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
@@ -326,6 +344,16 @@ class PlotCanvas:
self.pan(0, -0.3)
return
def on_mouse_down(self, event):
FlatCAMApp.App.log.debug('on_mouse_down() button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % (
event.button, event.x, event.y, event.xdata, event.ydata))
self.mouse_press_button = event.button
self.mouse_press_pos = [event.xdata, event.ydata]
def on_mouse_up(self, event):
self.mouse_press_button = -1
def on_mouse_move(self, event):
"""
Mouse movement event hadler. Stores the coordinates.
@@ -335,3 +363,5 @@ class PlotCanvas:
"""
self.mouse = [event.xdata, event.ydata]
if self.mouse_press_button == 2:
self.pan_by_coords(event.xdata - self.mouse_press_pos[0], event.ydata - self.mouse_press_pos[1])