Commit 37ce8a9e authored by Lars Kruse's avatar Lars Kruse

apply configured GCode settings to toolpath visualization

* this is based on a dirty copy'n'paste code piece that needs to be cleaned
parent e2c33c26
......@@ -75,11 +75,21 @@ class OpenGLViewToolpath(pycam.Plugins.PluginBase):
def draw_toolpaths(self):
if self._is_visible():
# TODO: this is ugly copy'n'paste from pycam.Plugins.ToolpathExport (_export_toolpaths)
# KEEP IN SYNC
processor = self.core.get("toolpath_processors").get_selected()
if not processor:
self.log.warn("No toolpath processor selected")
return
filter_func = processor["func"]
filter_params = self.core.get("get_parameter_values")(
"toolpath_processor")
settings_filters = filter_func(filter_params)
for toolpath in self.core.get("toolpaths").get_visible():
# TODO: enable the VBO code for speedup!
#moves = toolpath.get_moves_for_opengl(self.core.get("gcode_safety_height"))
#self._draw_toolpath_moves2(moves)
moves = toolpath.get_basic_moves()
moves = toolpath.get_basic_moves(filters=settings_filters)
self._draw_toolpath_moves(moves)
def _draw_toolpath_moves2(self, paths):
......
......@@ -82,6 +82,8 @@ class ToolpathExport(pycam.Plugins.PluginBase):
self._export_toolpaths(self.core.get("toolpaths").get_selected())
def _export_toolpaths(self, toolpaths):
# TODO: this is ugly copy'n'paste from pycam.Plugins.OpenGLViewToolpath (draw_toolpaths)
# KEEP IN SYNC
processor = self.core.get("toolpath_processors").get_selected()
if not processor:
self.log.warn("No toolpath processor selected")
......
......@@ -37,6 +37,10 @@ MAX_DIGITS = 12
_log = pycam.Utils.log.get_logger()
""" Toolpath filters are used for applying parameters to generic toolpaths.
"""
def toolpath_filter(our_category, key):
""" decorator for toolpath filter functions
e.g. see pycam.Plugins.ToolTypes
......@@ -101,11 +105,12 @@ class BaseFilter(object):
if hasattr(toolpath, "path") and hasattr(toolpath, "filters"):
toolpath = toolpath.path
# use a copy of the list -> changes will be permitted
_log.debug("Applying toolpath filter: %s" % self.__class__)
return self.filter_toolpath(list(toolpath))
def __repr__(self):
class_name = str(self.__class__).split("'")[1]
return "%s - %s" % (class_name, self._render_settings())
class_name = str(self.__class__).split("'")[1].split(".")[-1]
return "%s(%s)" % (class_name, self._render_settings())
# comparison functions: they allow to use "filters.sort()"
__eq__ = lambda self, other: self.WEIGHT == other.WEIGHT
......
......@@ -38,7 +38,7 @@ import os
import math
from itertools import groupby
log = pycam.Utils.log.get_logger()
_log = pycam.Utils.log.get_logger()
MOVE_STRAIGHT, MOVE_STRAIGHT_RAPID, MOVE_ARC, MOVE_SAFETY, MACHINE_SETTING, \
......@@ -114,6 +114,8 @@ class Toolpath(object):
def clear_cache(self):
self.opengl_safety_height = None
self._cache_basic_moves = None
self._cache_visual_filters_string = None
self._cache_visual_filters = None
self._minx = None
self._maxx = None
self._miny = None
......@@ -329,12 +331,23 @@ class Toolpath(object):
current_position = args
return length, duration
def get_basic_moves(self, reset_cache=False):
if reset_cache or not self._cache_basic_moves:
result = list(self.path)
for move_filter in self.filters:
result |= move_filter
self._cache_basic_moves = result
def get_basic_moves(self, filters=None, reset_cache=False):
if filters is None:
# implicitly assume that we use the default (latest) filters if nothing is given
filters = self._cache_visual_filters
if reset_cache or not self._cache_basic_moves or \
(str(filters) != self._cache_visual_filters_string):
# late import due to dependency cycle
import pycam.Toolpath.Filters as Filters
self._cache_basic_moves = \
pycam.Toolpath.Filters.get_filtered_moves(self.path,
tuple(self.filters) + tuple(filters))
self._cache_visual_filters_string = str(filters)
self._cache_visual_filters = filters
_log.debug("Applying toolpath filters: %s" % \
", ".join([str(fil) for fil in self.filters]))
_log.debug("Toolpath step changes: %d (before) -> %d (after)" % \
(len(self.path), len(self._cache_basic_moves)))
return self._cache_basic_moves
......@@ -522,9 +535,9 @@ class Bounds(object):
# Display warning messages, if we can't reach the requested
# absolute dimension.
if ref_low[index] != limits_low[index]:
log.info(message % "lower")
_log.info(message % "lower")
if ref_high[index] != limits_high[index]:
log.info(message % "upper")
_log.info(message % "upper")
self.bounds_low[index] = 0
self.bounds_high[index] = 0
else:
......
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