Skip to content

Commit

Permalink
Merge pull request kliment#1347 from neofelis2X/uxui_dev_dlgs
Browse files Browse the repository at this point in the history
UXUI Polishing Part 2: Platers, G-Code Viewers, ProjectLayer and SpoolManager
  • Loading branch information
rockstorm101 authored May 29, 2023
2 parents 94323e6 + d1e92a0 commit ceeb651
Show file tree
Hide file tree
Showing 9 changed files with 1,139 additions and 728 deletions.
26 changes: 15 additions & 11 deletions printrun/excluder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,24 @@
class ExcluderWindow(gviz.GvizWindow):

def __init__(self, excluder, *args, **kwargs):
super(ExcluderWindow, self).__init__(*args, **kwargs)
self.SetTitle(_("Part excluder: draw rectangles where print instructions should be ignored"))
self.toolbar.AddTool(128, " " + _("Reset selection"),
wx.Image(imagefile('reset.png'), wx.BITMAP_TYPE_PNG).ConvertToBitmap(),
_("Reset selection"))
self.Bind(wx.EVT_TOOL, self.reset_selection, id = 128)
super().__init__(*args, **kwargs)
self.SetTitle(_("Print Excluder"))
self.parent = excluder

self.toolbar.ClearTools()
self.build_toolbar(excluder = True)
self.toolbar.Realize()
minsize = self.toolbar.GetEffectiveMinSize().width
self.SetMinClientSize((minsize, minsize))
self.p.SetToolTip(
_("Draw rectangles where print instructions should be ignored.") +
_("\nExcluder always affects all layers, layer setting is disregarded."))

self.p.paint_overlay = self.paint_selection
self.p.layerup()

self.CenterOnParent()

def real_to_gcode(self, x, y):
return (x + self.p.build_dimensions[3],
self.p.build_dimensions[4] + self.p.build_dimensions[1] - y)
Expand Down Expand Up @@ -96,11 +104,6 @@ def paint_selection(self, dc):
dc.DrawRectangleList([self._line_scaler(rect)
for rect in self.parent.rectangles],
None, wx.Brush((200, 200, 200, 150)))

def reset_selection(self, event):
self.parent.rectangles = []
wx.CallAfter(self.p.Refresh)

class Excluder:

def __init__(self):
Expand All @@ -122,6 +125,7 @@ def close_window(self, event = None):
self.window.Destroy()
self.window = None


if __name__ == '__main__':
import sys
from . import gcoder
Expand Down
47 changes: 30 additions & 17 deletions printrun/gcodeplater.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
# You should have received a copy of the GNU General Public License
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.

# Set up Internationalization using gettext
# searching for installed locales on /usr/share; uses relative folder if not found (windows)
from .utils import install_locale, get_home_pos
install_locale('pronterface')

import wx
import sys
import os
Expand All @@ -35,6 +30,11 @@
import printrun.gui.viz # NOQA
from printrun import gcview

from .utils import install_locale, get_home_pos
install_locale('pronterface')
# Set up Internationalization using gettext
# searching for installed locales on /usr/share; uses relative folder if not found (windows)

def extrusion_only(gline):
return gline.e is not None \
and (gline.x, gline.y, gline.z) == (None, None, None)
Expand All @@ -44,6 +44,7 @@ def gcoder_write(self, f, line, store = False):
f.write(line)
self.append(line, store = store)


rewrite_exp = re.compile("(%s)" % "|".join(["X([-+]?[0-9]*\.?[0-9]*)",
"Y([-+]?[0-9]*\.?[0-9]*)"]))

Expand All @@ -66,38 +67,42 @@ def rewrite_gline(centeroffset, gline, cosr, sinr):
new = {"X": new_x, "Y": new_y}
new_line = rewrite_exp.sub(lambda ax: new[ax.group()[0]], gline.raw)
new_line = new_line.split(";")[0]
if gline.x is None: new_line += " " + new_x
if gline.y is None: new_line += " " + new_y
if gline.x is None:
new_line += " " + new_x
if gline.y is None:
new_line += " " + new_y
return new_line
else:
return gline.raw
return gline.raw

class GcodePlaterPanel(PlaterPanel):

load_wildcard = _("GCODE files (*.gcode;*.GCODE;*.g)") + "|*.gcode;*.gco;*.g"
save_wildcard = _("GCODE files (*.gcode;*.GCODE;*.g)") + "|*.gcode;*.gco;*.g"
load_wildcard = _("GCODE files") + " (*.gcode;*.GCODE;*.g)|*.gcode;*.gco;*.g"
save_wildcard = load_wildcard

def prepare_ui(self, filenames = [], callback = None,
parent = None, build_dimensions = None,
circular_platform = False,
antialias_samples = 0,
grid = (1, 10)):
super(GcodePlaterPanel, self).prepare_ui(filenames, callback, parent, build_dimensions)
super().prepare_ui(filenames, callback, parent, build_dimensions, cutting_tool = False)
viewer = gcview.GcodeViewPanel(self, build_dimensions = self.build_dimensions,
antialias_samples = antialias_samples)
self.set_viewer(viewer)
self.platform = actors.Platform(self.build_dimensions,
circular = circular_platform,
grid = grid)
self.platform_object = gcview.GCObject(self.platform)
self.Layout()
self.SetMinClientSize(self.topsizer.CalcMin())
self.SetTitle("G-Code Plate Builder")

def get_objects(self):
return [self.platform_object] + list(self.models.values())
objects = property(get_objects)

def load_file(self, filename):
gcode = gcoder.GCode(open(filename, "rU"),
get_home_pos(self.build_dimensions))
with open(filename, "r") as file:
gcode = gcoder.GCode(file, get_home_pos(self.build_dimensions))
model = actors.GcodeModel()
if gcode.filament_length > 0:
model.display_travels = False
Expand Down Expand Up @@ -142,17 +147,20 @@ def done(self, event, cb):
# but the end goal is to have a clean per-layer merge
def export_to(self, name):
return self.export_combined(name)
return self.export_sequential(name)

def export_combined(self, name):
models = list(self.models.values())
last_real_position = None
# Sort models by Z max to print smaller objects first
models.sort(key = lambda x: x.dims[-1])
alllayers = []

def add_offset(layer):
if layer.z is not None:
return layer.z + model.offsets[2]
return layer.z

for (model_i, model) in enumerate(models):
def add_offset(layer):
return layer.z + model.offsets[2] if layer.z is not None else layer.z
alllayers += [(add_offset(layer), model_i, layer_i)
for (layer_i, layer) in enumerate(model.gcode.all_layers) if add_offset(layer) is not None]
alllayers.sort()
Expand Down Expand Up @@ -199,6 +207,10 @@ def add_offset(layer):
logging.info(_("Exported merged G-Codes to %s") % name)

def export_sequential(self, name):
'''
Initial implementation of the gcode exporter,
which prints objects sequentially. No longer used.
'''
models = list(self.models.values())
last_real_position = None
# Sort models by Z max to print smaller objects first
Expand Down Expand Up @@ -235,6 +247,7 @@ def export_sequential(self, name):
break
logging.info(_("Exported merged G-Codes to %s") % name)


GcodePlater = make_plater(GcodePlaterPanel)

if __name__ == '__main__':
Expand Down
Loading

0 comments on commit ceeb651

Please sign in to comment.