diff -r c82943fb205f -r cce0af6351f0 printrun-src/printrun/stlview.py --- a/printrun-src/printrun/stlview.py Tue Jan 19 20:45:09 2021 +0100 +++ b/printrun-src/printrun/stlview.py Wed Jan 20 10:15:13 2021 +0100 @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # This file is part of the Printrun suite. # @@ -42,7 +42,7 @@ def vec(*args): return (GLfloat * len(args))(*args) -class stlview(object): +class stlview: def __init__(self, facets, batch): # Create the vertex and normal arrays. vertices = [] @@ -54,7 +54,7 @@ normals.extend(i[0]) # Create a list of triangle indices. - indices = range(3 * len(facets)) # [[3*i, 3*i+1, 3*i+2] for i in xrange(len(facets))] + indices = list(range(3 * len(facets))) # [[3*i, 3*i+1, 3*i+2] for i in xrange(len(facets))] self.vertex_list = batch.add_indexed(len(vertices) // 3, GL_TRIANGLES, None, # group, @@ -69,10 +69,11 @@ do_lights = False - def __init__(self, parent, size, id = wx.ID_ANY, + def __init__(self, parent, size, build_dimensions = None, circular = False, - antialias_samples = 0): - super(StlViewPanel, self).__init__(parent, id, wx.DefaultPosition, size, 0, + antialias_samples = 0, + grid = (1, 10)): + super().__init__(parent, wx.DefaultPosition, size, 0, antialias_samples = antialias_samples) self.batches = [] self.rot = 0 @@ -87,10 +88,11 @@ else: self.build_dimensions = [200, 200, 100, 0, 0, 0] self.platform = actors.Platform(self.build_dimensions, - circular = circular) + circular = circular, + grid = grid) self.dist = max(self.build_dimensions[0], self.build_dimensions[1]) self.basequat = [0, 0, 0, 1] - wx.CallAfter(self.forceresize) + wx.CallAfter(self.forceresize) #why needed self.mousepos = (0, 0) def OnReshape(self): @@ -155,8 +157,11 @@ self.parent.clickcb(event) def forceresize(self): - self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1)) - self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1)) + #print('forceresize') + x, y = self.GetClientSize() + #TODO: probably not needed + self.SetClientSize((x, y+1)) + self.SetClientSize((x, y)) self.initialized = False def move(self, event): @@ -167,27 +172,22 @@ RMB: nothing with shift move viewport """ - self.mousepos = event.GetPositionTuple() - if event.Dragging() and event.LeftIsDown(): - self.handle_rotation(event) - elif event.Dragging() and event.RightIsDown(): - self.handle_translation(event) - elif event.ButtonUp(wx.MOUSE_BTN_LEFT): - if self.initpos is not None: - self.initpos = None - elif event.ButtonUp(wx.MOUSE_BTN_RIGHT): - if self.initpos is not None: - self.initpos = None - else: - event.Skip() - return + self.mousepos = event.GetPosition() + if event.Dragging(): + if event.LeftIsDown(): + self.handle_rotation(event) + elif event.RightIsDown(): + self.handle_translation(event) + self.Refresh(False) + elif event.ButtonUp(wx.MOUSE_BTN_LEFT) or \ + event.ButtonUp(wx.MOUSE_BTN_RIGHT): + self.initpos = None event.Skip() - wx.CallAfter(self.Refresh) def handle_wheel(self, event): delta = event.GetWheelRotation() factor = 1.05 - x, y = event.GetPositionTuple() + x, y = event.GetPosition() x, y, _ = self.mouse_to_3d(x, y, local_transform = True) if delta > 0: self.zoom(factor, (x, y)) @@ -257,6 +257,8 @@ if not self.platform.initialized: self.platform.init() self.initialized = 1 + #TODO: this probably creates constant redraw + # create_objects is called during OnDraw, remove wx.CallAfter(self.Refresh) def prepare_model(self, m, scale):