Commit 510f85cc authored by Guillaume Seguin's avatar Guillaume Seguin

Fix reloading of visualization after UI change

parent f810f246
...@@ -273,7 +273,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -273,7 +273,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
temppanel.Destroy() temppanel.Destroy()
self.panel.Layout() self.panel.Layout()
if self.fgcode: if self.fgcode:
self.post_gcode_load(print_stats = False) self.start_viz_thread()
self.ui_ready = True self.ui_ready = True
self.Thaw() self.Thaw()
...@@ -1363,10 +1363,13 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1363,10 +1363,13 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
def layer_ready_cb(self, gcode, layer): def layer_ready_cb(self, gcode, layer):
self.viz_last_layer = layer self.viz_last_layer = layer
def start_viz_thread(self, gcode = None):
threading.Thread(target = self.loadviz, args = (gcode,)).start()
def pre_gcode_load(self): def pre_gcode_load(self):
gcode = gcoder.GCode(deferred = True) gcode = gcoder.GCode(deferred = True)
self.viz_last_layer = -1 self.viz_last_layer = -1
threading.Thread(target = self.loadviz, args = (gcode,)).start() self.start_viz_thread(gcode)
return gcode return gcode
def post_gcode_load(self, print_stats = True): def post_gcode_load(self, print_stats = True):
...@@ -1384,32 +1387,38 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1384,32 +1387,38 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
print _("- from %.2f mm to %.2f mm in Z and is %.2f mm high") % (gcode.zmin, gcode.zmax, gcode.height) print _("- from %.2f mm to %.2f mm in Z and is %.2f mm high") % (gcode.zmin, gcode.zmax, gcode.height)
print _("Estimated duration: %d layers, %s") % gcode.estimate_duration() print _("Estimated duration: %d layers, %s") % gcode.estimate_duration()
def loadviz(self, gcode): def loadviz(self, gcode = None):
self.gviz.clear() self.gviz.clear()
self.gwindow.p.clear() self.gwindow.p.clear()
generator = self.gviz.addfile_perlayer(gcode, True) if gcode is not None:
next_layer = 0 generator = self.gviz.addfile_perlayer(gcode, True)
# Progressive loading of visualization next_layer = 0
# We load layers up to the last one which has been processed in GCoder # Progressive loading of visualization
# (self.viz_last_layer) # We load layers up to the last one which has been processed in GCoder
# Once the GCode has been entirely loaded, this variable becomes None, # (self.viz_last_layer)
# indicating that we can do the last generator call to finish the # Once the GCode has been entirely loaded, this variable becomes None,
# loading of the visualization, which will itself return None. # indicating that we can do the last generator call to finish the
# During preloading we verify that the layer we added is the one we # loading of the visualization, which will itself return None.
# expected through the assert call. # During preloading we verify that the layer we added is the one we
while True: # expected through the assert call.
max_layer = self.viz_last_layer while True:
if max_layer is None: max_layer = self.viz_last_layer
break if max_layer is None:
while next_layer <= max_layer: break
assert(generator.next() == next_layer) while next_layer <= max_layer:
next_layer += 1 assert(generator.next() == next_layer)
time.sleep(0.1) next_layer += 1
generator_output = generator.next() time.sleep(0.1)
while generator_output is not None:
assert(generator_output in (None, next_layer))
next_layer += 1
generator_output = generator.next() generator_output = generator.next()
while generator_output is not None:
assert(generator_output in (None, next_layer))
next_layer += 1
generator_output = generator.next()
else:
# If GCode is not being loaded asynchroneously, it is already
# loaded, so let's make visualization sequentially
gcode = self.fgcode
self.gviz.addfile(gcode)
wx.CallAfter(self.gviz.Refresh) wx.CallAfter(self.gviz.Refresh)
# Load external window sequentially now that everything is ready. # Load external window sequentially now that everything is ready.
# We can't really do any better as the 3D viewer might clone the # We can't really do any better as the 3D viewer might clone the
......
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