Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to my master kliment#1054 #2

Merged
merged 9 commits into from
Jun 9, 2020
13 changes: 9 additions & 4 deletions printrun/gcview.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ def addfile(self, gcode = None, showall = False):
def set_gcview_params(self, path_width, path_height):
return set_gcview_params(self, path_width, path_height)

class GcodeViewMainWrapper(GcodeViewLoader):
from printrun.gviz import BaseViz
class GcodeViewMainWrapper(GcodeViewLoader, BaseViz):

def __init__(self, parent, build_dimensions, root, circular, antialias_samples):
self.root = root
Expand All @@ -368,6 +369,13 @@ def __init__(self, parent, build_dimensions, root, circular, antialias_samples):
def __getattr__(self, name):
return getattr(self.glpanel, name)

def on_settings_change(self, changed_settings):
if self.model:
for s in changed_settings:
if s.name.startswith('gcview_color_'):
self.model.update_colors()
break

def set_current_gline(self, gline):
if gline.is_move and gline.gcview_end_vertex is not None \
and self.model and self.model.loaded:
Expand All @@ -378,9 +386,6 @@ def set_current_gline(self, gline):
def recreate_platform(self, build_dimensions, circular):
return recreate_platform(self, build_dimensions, circular)

def addgcodehighlight(self, *a):
pass

def setlayer(self, layer):
if layer in self.model.layer_idxs_map:
viz_layer = self.model.layer_idxs_map[layer]
Expand Down
71 changes: 41 additions & 30 deletions printrun/gl/libtatlin/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def load_data(self, model_data, callback=None):
# to store coordinates/colors/normals.
# Nicely enough we have 3 per kind of thing for all kinds.
coordspervertex = 3
buffered_color_len = 3 # 4th color component (alpha) is ignored
verticesperline = 8
coordsperline = coordspervertex * verticesperline
coords_count = lambda nlines: nlines * coordsperline
Expand All @@ -389,20 +390,19 @@ def load_data(self, model_data, callback=None):
vertices = self.vertices = numpy.zeros(ncoords, dtype = GLfloat)
vertex_k = 0
colors = self.colors = numpy.zeros(ncoords, dtype = GLfloat)

color_k = 0
normals = self.normals = numpy.zeros(ncoords, dtype = GLfloat)
normal_k = 0
indices = self.indices = numpy.zeros(nindices, dtype = GLuint)
index_k = 0
self.layer_idxs_map = {}
self.layer_stops = [0]

prev_is_extruding = False
prev_move_normal_x = None
prev_move_normal_y = None
prev_move_angle = None

prev_pos = (0, 0, 0)
prev_gline = None
layer_idx = 0

self.printed_until = 0
Expand Down Expand Up @@ -437,21 +437,10 @@ def load_data(self, model_data, callback=None):
has_movement = True
current_pos = (gline.current_x, gline.current_y, gline.current_z)
if not gline.extruding:
travel_vertices[travel_vertex_k] = prev_pos[0]
travel_vertices[travel_vertex_k + 1] = prev_pos[1]
travel_vertices[travel_vertex_k + 2] = prev_pos[2]
travel_vertices[travel_vertex_k + 3] = current_pos[0]
travel_vertices[travel_vertex_k + 4] = current_pos[1]
travel_vertices[travel_vertex_k + 5] = current_pos[2]
travel_vertices[travel_vertex_k:travel_vertex_k+3] = prev_pos
travel_vertices[travel_vertex_k + 3:travel_vertex_k + 6] = current_pos
travel_vertex_k += 6
prev_is_extruding = False
else:
gline_color = self.movement_color(gline)

next_move = get_next_move(model_data, layer_idx, gline_idx)
next_is_extruding = (next_move.extruding
if next_move is not None else False)

delta_x = current_pos[0] - prev_pos[0]
delta_y = current_pos[1] - prev_pos[1]
norm = delta_x * delta_x + delta_y * delta_y
Expand All @@ -469,7 +458,7 @@ def load_data(self, model_data, callback=None):
new_indices = []
new_vertices = []
new_normals = []
if prev_is_extruding:
if prev_gline and prev_gline.extruding:
# Store previous vertices indices
prev_id = vertex_k // 3 - 4
avg_move_normal_x = (prev_move_normal_x + move_normal_x) / 2
Expand Down Expand Up @@ -566,6 +555,8 @@ def load_data(self, model_data, callback=None):
new_indices = triangulate_rectangle(first, first + 1,
first + 2, first + 3)

next_move = get_next_move(model_data, layer_idx, gline_idx)
next_is_extruding = next_move and next_move.extruding
if not next_is_extruding:
# Compute caps and link everything
p1x = current_pos[0] - path_halfwidth * move_normal_x
Expand All @@ -591,23 +582,25 @@ def load_data(self, model_data, callback=None):
for new_i, item in enumerate(new_indices):
indices[index_k + new_i] = item
index_k += len(new_indices)
for new_i, item in enumerate(new_vertices):
vertices[vertex_k + new_i] = item
vertex_k += len(new_vertices)
for new_i, item in enumerate(new_normals):
normals[normal_k + new_i] = item
normal_k += len(new_normals)
new_colors = list(gline_color)[:-1] * (len(new_vertices) // 3)
for new_i, item in enumerate(new_colors):
colors[color_k + new_i] = item
color_k += len(new_colors)

prev_is_extruding = True

new_vertices_len = len(new_vertices)
vertices[vertex_k:vertex_k+new_vertices_len] = new_vertices
normals[vertex_k:vertex_k+new_vertices_len] = new_normals
vertex_k += new_vertices_len

new_vertices_count = new_vertices_len//coordspervertex
# settings support alpha (transperancy), but it is ignored here
gline_color = self.movement_color(gline)[:buffered_color_len]
for vi in range(new_vertices_count):
colors[color_k:color_k+buffered_color_len] = gline_color
color_k += buffered_color_len

prev_move_normal_x = move_normal_x
prev_move_normal_y = move_normal_y
prev_move_angle = move_angle

prev_pos = current_pos
prev_gline = gline
count_travel_indices.append(travel_vertex_k // 3)
count_print_indices.append(index_k)
count_print_vertices.append(vertex_k // 3)
Expand Down Expand Up @@ -637,7 +630,7 @@ def load_data(self, model_data, callback=None):
self.travels.resize(travel_vertex_k, refcheck = False)
self.vertices.resize(vertex_k, refcheck = False)
self.colors.resize(color_k, refcheck = False)
self.normals.resize(normal_k, refcheck = False)
self.normals.resize(vertex_k, refcheck = False)
self.indices.resize(index_k, refcheck = False)

self.layer_stops = array.array('L', self.layer_stops)
Expand Down Expand Up @@ -673,6 +666,24 @@ def copy(self):
copy.initialized = False
return copy

def update_colors(self):
"""Rebuild gl color buffer without loading. Used after color settings edit"""
ncoords = self.count_print_vertices[-1]
colors = numpy.empty(ncoords*3, dtype = GLfloat)
cur_vertex = 0
gline_i = 1
for gline in self.gcode.lines:
if gline.gcview_end_vertex:
gline_color = self.movement_color(gline)[:3]
last_vertex = self.count_print_vertices[gline_i]
gline_i += 1
while cur_vertex < last_vertex:
colors[cur_vertex*3:cur_vertex*3+3] = gline_color
cur_vertex += 1
if self.vertex_color_buffer:
self.vertex_color_buffer.delete()
self.vertex_color_buffer = numpy2vbo(colors, use_vbos = self.use_vbos)

# ------------------------------------------------------------------------
# DRAWING
# ------------------------------------------------------------------------
Expand Down
15 changes: 7 additions & 8 deletions printrun/gui/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@

import wx

class NoViz:

showall = False

class BaseViz:
def clear(self, *a):
pass

Expand All @@ -35,16 +32,18 @@ def addfile_perlayer(self, gcode, showall = False):
def addfile(self, *a, **kw):
pass

def addgcode(self, *a, **kw):
def addgcodehighlight(self, *a, **kw):
pass

def addgcodehighlight(self, *a, **kw):
def setlayer(self, *a):
pass

def Refresh(self, *a):
def on_settings_change(self, changed_settings):
pass

def setlayer(self, *a):
class NoViz(BaseViz):
showall = False
def Refresh(self, *a):
pass

class NoVizWindow:
Expand Down
9 changes: 8 additions & 1 deletion printrun/gui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(self, pronterface):
panel = wx.Panel(self)
header = wx.StaticBox(panel, label = _("Settings"))
sbox = wx.StaticBoxSizer(header, wx.VERTICAL)
notebook = wx.Notebook(panel)
self.notebook = notebook = wx.Notebook(panel)
all_settings = pronterface.settings._all_settings()
group_list = []
groups = {}
Expand Down Expand Up @@ -178,14 +178,21 @@ def __init__(self, pronterface):
self.SetSizerAndFit(topsizer)
self.SetMinSize(self.GetSize())

notebookSelection = 0
def PronterOptions(pronterface):
dialog = PronterOptionsDialog(pronterface)
global notebookSelection
dialog.notebook.Selection = notebookSelection
if dialog.ShowModal() == wx.ID_OK:
changed_settings = []
for setting in pronterface.settings._all_settings():
old_value = setting.value
setting.update()
if setting.value != old_value:
pronterface.set(setting.name, setting.value)
changed_settings.append(setting)
pronterface.on_settings_change(changed_settings)
notebookSelection = dialog.notebook.Selection
dialog.Destroy()

class ButtonEdit(wx.Dialog):
Expand Down
3 changes: 2 additions & 1 deletion printrun/gviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def zoom(self, event):
if z > 0: self.p.zoom(event.GetX(), event.GetY(), 1.2)
elif z < 0: self.p.zoom(event.GetX(), event.GetY(), 1 / 1.2)

class Gviz(wx.Panel):
from printrun.gui.viz import BaseViz
class Gviz(wx.Panel, BaseViz):

# Mark canvas as dirty when setting showall
_showall = 0
Expand Down
6 changes: 1 addition & 5 deletions printrun/pronsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ def __init__(self):
self.settings = Settings(self)
self.settings._add(BuildDimensionsSetting("build_dimensions", "200x200x100+0+0+0+0+0+0", _("Build dimensions"), _("Dimensions of Build Platform\n & optional offset of origin\n & optional switch position\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ\nXXXxYYYxZZZ+OffX+OffY+OffZ+HomeX+HomeY+HomeZ"), "Printer"), self.update_build_dimensions)
self.settings._port_list = self.scanserial
self.settings._temperature_abs_cb = self.set_temp_preset
self.settings._temperature_pla_cb = self.set_temp_preset
self.settings._bedtemp_abs_cb = self.set_temp_preset
self.settings._bedtemp_pla_cb = self.set_temp_preset
self.update_build_dimensions(None, self.settings.build_dimensions)
self.update_tcp_streaming_mode(None, self.settings.tcp_streaming_mode)
self.monitoring = 0
Expand Down Expand Up @@ -1458,7 +1454,7 @@ def do_settemp(self, l):
def help_settemp(self):
self.log(_("Sets the hotend temperature to the value entered."))
self.log(_("Enter either a temperature in celsius or one of the following keywords"))
self.log(", ".join([i + "(" + self.temps[i] + ")" for i in self.temps.keys()]))
self.log(', '.join('%s (%s)'%kv for kv in self.temps.items()))

def complete_settemp(self, text, line, begidx, endidx):
if (len(line.split()) == 2 and line[-1] != " ") or (len(line.split()) == 1 and line[-1] == " "):
Expand Down
Loading