Commit 77ca068e authored by Guillaume Seguin's avatar Guillaume Seguin

Cleaner, more generic object move

parent 0a6e668b
......@@ -28,22 +28,6 @@ from printrun import gcoder
from printrun.objectplater import Plater
from printrun.gl.libtatlin import actors
class GcodeViewPanel(gcview.GcodeViewPanel):
def handle_rotation(self, event):
if self.initpos is None:
self.initpos = event.GetPositionTuple()
else:
if not event.ShiftDown():
p1 = self.initpos
p2 = event.GetPositionTuple()
x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
self.parent.move_shape((x2 - x1, y2 - y1))
self.initpos = p2
else:
super(GcodeViewPanel, self).handle_rotation(event)
class GcodePlater(Plater):
load_wildcard = _("STL files (*.stl;*.STL)|*.stl;*.STL|OpenSCAD files (*.scad)|*.scad")
......@@ -51,7 +35,7 @@ class GcodePlater(Plater):
def __init__(self, filenames = [], size = (800, 580), callback = None, parent = None, build_dimensions = None):
super(GcodePlater, self).__init__(filenames, size, callback, parent, build_dimensions)
viewer = GcodeViewPanel(self, build_dimensions = self.build_dimensions)
viewer = gcview.GcodeViewPanel(self, build_dimensions = self.build_dimensions)
self.set_viewer(viewer)
self.platform = actors.Platform(self.build_dimensions)
self.platform_object = gcview.GCObject(self.platform)
......
......@@ -19,6 +19,7 @@ from printrun.printrun_utils import install_locale, iconfile
install_locale('plater')
import os
import types
import wx
class Plater(wx.Frame):
......@@ -78,6 +79,25 @@ class Plater(wx.Frame):
self.build_dimensions = [200, 200, 100, 0, 0, 0]
def set_viewer(self, viewer):
# Patch handle_rotation on the fly
if hasattr(viewer, "handle_rotation"):
orig_handler = viewer.handle_rotation
def handle_rotation(self, event, orig_handler = orig_handler):
if self.initpos is None:
self.initpos = event.GetPositionTuple()
else:
if not event.ShiftDown():
p1 = self.initpos
p2 = event.GetPositionTuple()
x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
self.parent.move_shape((x2 - x1, y2 - y1))
self.initpos = p2
else:
orig_handler(self, event)
viewer.handle_rotation = types.MethodType(handle_rotation, viewer)
self.s = viewer
self.mainsizer.Add(self.s, 1, wx.EXPAND)
......
......@@ -155,18 +155,6 @@ class StlViewPanel(wxGLPanel):
"""
self.mousepos = event.GetPositionTuple()
if event.Dragging() and event.LeftIsDown():
if self.initpos is None:
self.initpos = event.GetPositionTuple()
else:
if not event.ShiftDown():
p1 = self.initpos
p2 = event.GetPositionTuple()
x1, y1, _ = self.mouse_to_3d(p1[0], p1[1])
x2, y2, _ = self.mouse_to_3d(p2[0], p2[1])
self.parent.move_shape((x2 - x1, y2 - y1))
self.initpos = p2
self.Refresh()
else:
self.handle_rotation(event)
elif event.Dragging() and event.RightIsDown():
self.handle_translation(event)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment