Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DivingDuck committed Aug 14, 2023
2 parents ca6af28 + 2f2b7d7 commit 2c83130
Show file tree
Hide file tree
Showing 9 changed files with 584 additions and 275 deletions.
8 changes: 6 additions & 2 deletions printrun/excluder.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ def __init__(self, excluder, *args, **kwargs):
self.SetTitle(_("Print Excluder"))
self.parent = excluder

self.toolbar.ClearTools()
self.build_toolbar(excluder = True)
tool_pos = self.toolbar.GetToolPos(6)
self.toolbar.InsertTool(tool_pos, 8, _('Reset Selection'),
wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(),
shortHelp = _("Reset Selection"))
self.toolbar.DeleteTool(6)
self.toolbar.DeleteTool(7)
self.toolbar.Realize()
minsize = self.toolbar.GetEffectiveMinSize().width
self.SetMinClientSize((minsize, minsize))
Expand Down
52 changes: 33 additions & 19 deletions printrun/gcview.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

from .gviz import GvizBaseFrame

from .gui.widgets import get_space
from .utils import imagefile, install_locale, get_home_pos
install_locale('pronterface')

Expand Down Expand Up @@ -154,7 +155,7 @@ def draw_objects(self):
if not obj.model \
or not obj.model.loaded:
continue
# Skip (comment out) initialized check, which safely causes empty
# Skip (comment out) initialized check, which safely causes empty
# model during progressive load. This can cause exceptions/garbage
# render, but seems fine for now
# May need to lock init() and draw_objects() together
Expand Down Expand Up @@ -238,7 +239,7 @@ def layerdown(self):
def handle_wheel(self, event):
if self.wheelTimestamp == event.Timestamp:
# filter duplicate event delivery in Ubuntu, Debian issue #1110
return
return

self.wheelTimestamp = event.Timestamp

Expand All @@ -251,8 +252,10 @@ def handle_wheel(self, event):
return
count = 1 if not event.ControlDown() else 10
for i in range(count):
if delta > 0: self.layerup()
else: self.layerdown()
if delta > 0:
self.layerup()
else:
self.layerdown()
return
x, y = event.GetPosition() * self.GetContentScaleFactor()
x, y, _ = self.mouse_to_3d(x, y)
Expand Down Expand Up @@ -426,7 +429,7 @@ def __init__(self, parent, ID, title, build_dimensions, objects = None,
pos, size, style)
self.root = root

panel, vbox = self.create_base_ui()
panel, h_sizer = self.create_base_ui()

self.refresh_timer = wx.CallLater(100, self.Refresh)
self.p = self # Hack for backwards compatibility with gviz API
Expand All @@ -436,24 +439,35 @@ def __init__(self, parent, ID, title, build_dimensions, objects = None,
self.objects = [GCObject(self.platform), GCObject(None)]

fit_image = wx.Image(imagefile('fit.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.toolbar.InsertTool(6, 8, " " + _("Fit to plate"), fit_image,
shortHelp = _("Fit to plate [F]"),
longHelp = '')
tool_pos = self.toolbar.GetToolPos(3) + 1
self.toolbar.InsertTool(tool_pos, 10, " " + _("Fit to plate"), fit_image,
shortHelp = _("Fit to plate [F]"), longHelp = '')
self.toolbar.Realize()
self.glpanel = GcodeViewPanel(panel,
build_dimensions = build_dimensions,
realparent = self,
antialias_samples = antialias_samples, perspective=perspective)
vbox.Add(self.glpanel, 1, flag = wx.EXPAND)

self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.zoom_to_center(1.2), id = 1)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.zoom_to_center(1 / 1.2), id = 2)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.layerup(), id = 3)
if self.root and hasattr(self.root, "gcview_color_background"):
self.glpanel.color_background = self.root.gcview_color_background

h_sizer.Add(self.glpanel, 1, wx.EXPAND)
h_sizer.Add(self.layerslider, 0, wx.EXPAND | wx.ALL, get_space('minor'))
self.glpanel.SetToolTip("Left-click to pan, right-click to move the view "
"and shift + scroll to change the layer")

minsize = self.toolbar.GetEffectiveMinSize().width
self.SetMinClientSize((minsize, minsize))

self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.zoom_to_center(1 / 1.2), id = 1)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.zoom_to_center(1.2), id = 2)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.resetview(), id = 3)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.layerdown(), id = 4)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.resetview(), id = 5)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.fit(), id = 8)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.layerup(), id = 5)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.fit(), id = 10)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.inject(), id = 6)
self.Bind(wx.EVT_TOOL, lambda x: self.glpanel.editlayer(), id = 7)
self.Bind(wx.EVT_TOOL, lambda x: self.Close(), id = 9)

def setlayercb(self, layer):
self.layerslider.SetValue(layer)
Expand All @@ -465,9 +479,9 @@ def update_status(self, extra):
if filtered:
true_layer = filtered[0]
z = self.model.gcode.all_layers[true_layer].z
message = _("Layer %d -%s Z = %.03f mm") % (layer, extra, z)
message = _("Layer %d: %s Z = %.03f mm") % (layer, extra, z)
else:
message = _("Entire object")
message = _("Last layer: Object complete")
wx.CallAfter(self.SetStatusText, message, 0)

def process_slider(self, event):
Expand All @@ -479,7 +493,7 @@ def process_slider(self, event):
self.update_status("")
wx.CallAfter(self.Refresh)
else:
logging.info(_("G-Code view, can't process slider. Please wait until model is loaded completely."))
logging.info(_("G-Code Viewer: Can't process slider. Please wait until model is loaded completely."))

def set_current_gline(self, gline):
if gline.is_move and gline.gcview_end_vertex is not None \
Expand All @@ -499,7 +513,7 @@ def addfile(self, gcode = None):
GcodeViewLoader.addfile(self, gcode)
self.layerslider.SetRange(1, self.model.max_layers + 1)
self.layerslider.SetValue(self.model.max_layers + 1)
wx.CallAfter(self.SetStatusText, _("Entire object"), 0)
wx.CallAfter(self.SetStatusText, _("Last layer: Object complete"), 0)
wx.CallAfter(self.Refresh)

def clear(self):
Expand All @@ -511,7 +525,7 @@ def clear(self):
import sys
app = wx.App(redirect = False)
build_dimensions = [200, 200, 100, 0, 0, 0]
title = 'Gcode view, shift to move view, mousewheel to set layer'
title = 'G-Code Viewer'
frame = GcodeViewFrame(None, wx.ID_ANY, title, size = (400, 400),
build_dimensions = build_dimensions)
gcode = gcoder.GCode(open(sys.argv[1]), get_home_pos(build_dimensions))
Expand Down
2 changes: 1 addition & 1 deletion printrun/gui/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, root, parentpanel = None):
objects = None
if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper):
objects = root.gviz.objects
root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer',
root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'G-Code Viewer',
size = (600, 600),
build_dimensions = root.build_dimensions_list,
objects = objects,
Expand Down
Loading

0 comments on commit 2c83130

Please sign in to comment.