Commit d97a82d9 authored by Lars Kruse's avatar Lars Kruse

changed toolpath filters chain from "apply" to "get"

* this allows to handle the filters separately instead of applying the immediately
parent 84d9a05a
...@@ -35,26 +35,26 @@ class GCodeSafetyHeight(pycam.Plugins.PluginBase): ...@@ -35,26 +35,26 @@ class GCodeSafetyHeight(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
# TODO: update the current filters after a change # TODO: update the current filters after a change
self.control = pycam.Gui.ControlsGTK.InputNumber(digits=0, self.control = pycam.Gui.ControlsGTK.InputNumber(digits=0,
change_handler=lambda *args: \ lower=-1000, upper=1000, change_handler=lambda *args: \
self.core.emit_event("visual-item-updated")) self.core.emit_event("visual-item-updated"))
self.core.get("register_parameter")("toolpath_processor", "safety_height", self.core.get("register_parameter")("toolpath_processor",
self.control) "safety_height", self.control)
self.core.register_ui("gcode_general_parameters", "Safety Height", self.core.register_ui("gcode_general_parameters", "Safety Height",
self.control.get_widget(), weight=20) self.control.get_widget(), weight=20)
self.core.register_chain("toolpath_filters", self.apply_filter) self.core.register_chain("toolpath_filters", self.get_toolpath_filters)
return True return True
def teardown(self): def teardown(self):
self.core.unregister_chain("toolpath_filters", self.apply_filter) self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters)
self.core.unregister_ui("gcode_general_parameters", self.core.unregister_ui("gcode_general_parameters",
self.control.get_widget()) self.control.get_widget())
self.core.get("unregister_parameter")("toolpath_processor", self.core.get("unregister_parameter")("toolpath_processor",
"safety_height") "safety_height")
def apply_filter(self, settings_dict, filters_list): @Filters.toolpath_filter("settings", "safety_height")
if "safety_height" in settings_dict: def get_toolpath_filters(self, safety_height):
filters_list.append(Filters.SafetyHeightFilter( return [Filters.SafetyHeightFilter(safety_height)]
settings_dict["safety_height"]))
#TODO: move to settings for ToolpathOutputDialects #TODO: move to settings for ToolpathOutputDialects
...@@ -78,9 +78,10 @@ class GCodeFilenameExtension(pycam.Plugins.PluginBase): ...@@ -78,9 +78,10 @@ class GCodeFilenameExtension(pycam.Plugins.PluginBase):
self.core.get("unregister_parameter")("toolpath_processor", self.core.get("unregister_parameter")("toolpath_processor",
"filename_extension") "filename_extension")
def apply_filter(self, settings_dict, filters_list): @Filters.toolpath_filter("settings", "filename_extension")
# TODO: implement this after moving to Dialects def get_toolpath_filters(self, safety_height):
pass # TODO: see above - move to ToolpathOutputDialects
return []
class GCodeStepWidth(pycam.Plugins.PluginBase): class GCodeStepWidth(pycam.Plugins.PluginBase):
...@@ -103,11 +104,12 @@ class GCodeStepWidth(pycam.Plugins.PluginBase): ...@@ -103,11 +104,12 @@ class GCodeStepWidth(pycam.Plugins.PluginBase):
self.core.get("register_parameter")("toolpath_processor", self.core.get("register_parameter")("toolpath_processor",
"step_width_%s" % key, control) "step_width_%s" % key, control)
self.controls.append((key, control)) self.controls.append((key, control))
self.core.register_chain("toolpath_filters", self.apply_filter) self.core.register_chain("toolpath_filters", self.get_toolpath_filters)
return True return True
def teardown(self): def teardown(self):
self.core.unregister_chain("toolpath_filters", self.apply_filter) self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters)
for key, control in self.controls: for key, control in self.controls:
self.core.unregister_ui("gcode_step_width", control) self.core.unregister_ui("gcode_step_width", control)
self.core.get("unregister_parameter")("toolpath_processor", self.core.get("unregister_parameter")("toolpath_processor",
...@@ -115,13 +117,10 @@ class GCodeStepWidth(pycam.Plugins.PluginBase): ...@@ -115,13 +117,10 @@ class GCodeStepWidth(pycam.Plugins.PluginBase):
self.core.unregister_ui("gcode_general_parameters", self.core.unregister_ui("gcode_general_parameters",
self._table.get_widget()) self._table.get_widget())
def apply_filter(self, settings_dict, filters_list): @Filters.toolpath_filter("settings",
result = {} ("step_width_x", "step_width_y", "step_width_z"))
if any([("step_width_%s" % key) in settings_dict def get_toolpath_filters(self, **kwargs):
for key in "xyz"]): return [Filters.StepWidth(**kwargs)]
full_key = "step_width_%s" % key
result[full_key] = settings_dict.get(full_key, 0.0)
filters_list.append(Filters.StepWidth(**result))
class GCodeSpindle(pycam.Plugins.PluginBase): class GCodeSpindle(pycam.Plugins.PluginBase):
...@@ -147,12 +146,13 @@ class GCodeSpindle(pycam.Plugins.PluginBase): ...@@ -147,12 +146,13 @@ class GCodeSpindle(pycam.Plugins.PluginBase):
self.spindle_enable.get_widget(), weight=10) self.spindle_enable.get_widget(), weight=10)
self.core.get("register_parameter")("toolpath_processor", self.core.get("register_parameter")("toolpath_processor",
"spindle_enable", self.spindle_enable) "spindle_enable", self.spindle_enable)
self.core.register_chain("toolpath_filters", self.apply_filter) self.core.register_chain("toolpath_filters", self.get_toolpath_filters)
self.update_widgets() self.update_widgets()
return True return True
def teardown(self): def teardown(self):
self.core.unregister_chain("toolpath_filters", self.apply_filter) self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters)
self.core.unregister_ui("gcode_spindle", self.core.unregister_ui("gcode_spindle",
self.spindle_delay.get_widget()) self.spindle_delay.get_widget())
self.core.unregister_ui("gcode_spindle", self.core.unregister_ui("gcode_spindle",
...@@ -168,11 +168,12 @@ class GCodeSpindle(pycam.Plugins.PluginBase): ...@@ -168,11 +168,12 @@ class GCodeSpindle(pycam.Plugins.PluginBase):
widget = self.spindle_delay.get_widget() widget = self.spindle_delay.get_widget()
widget.set_sensitive(self.spindle_enable.get_value()) widget.set_sensitive(self.spindle_enable.get_value())
def apply_filter(self, settings_dict, filters_list): @Filters.toolpath_filter("settings", ("spindle_enable", "spindle_delay"))
if not settings_dict.get("spindle_enable", False): def get_toolpath_filters(self, spindle_enable=False, spindle_delay=0):
return if spindle_enable:
filters_list.append(Filters.TriggerSpindle( return [Filters.TriggerSpindle(spindle_delay)]
settings_dict.get("spindle_delay", 0))) else:
return []
class GCodeCornerStyle(pycam.Plugins.PluginBase): class GCodeCornerStyle(pycam.Plugins.PluginBase):
...@@ -208,12 +209,13 @@ class GCodeCornerStyle(pycam.Plugins.PluginBase): ...@@ -208,12 +209,13 @@ class GCodeCornerStyle(pycam.Plugins.PluginBase):
self.path_mode.get_widget(), weight=10) self.path_mode.get_widget(), weight=10)
self.core.get("register_parameter")("toolpath_processor", "path_mode", self.core.get("register_parameter")("toolpath_processor", "path_mode",
self.path_mode) self.path_mode)
self.core.register_chain("toolpath_filters", self.apply_filter) self.core.register_chain("toolpath_filters", self.get_toolpath_filters)
self.update_widgets() self.update_widgets()
return True return True
def teardown(self): def teardown(self):
self.core.unregister_chain("toolpath_filters", self.apply_filter) self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters)
self.core.unregister_ui("gcode_corner_style", self.core.unregister_ui("gcode_corner_style",
self.motion_tolerance.get_widget()) self.motion_tolerance.get_widget())
self.core.unregister_ui("gcode_corner_style", self.core.unregister_ui("gcode_corner_style",
...@@ -231,10 +233,9 @@ class GCodeCornerStyle(pycam.Plugins.PluginBase): ...@@ -231,10 +233,9 @@ class GCodeCornerStyle(pycam.Plugins.PluginBase):
for control in controls: for control in controls:
control.get_widget().set_sensitive(enable_tolerances) control.get_widget().set_sensitive(enable_tolerances)
def apply_filter(self, settings_dict, filters_list): @Filters.toolpath_filter("settings",
param_dict = {} ("path_mode", "motion_tolerance", "naive_tolerance"))
for name in ("path_mode", "motion_tolerance", "naive_tolerance"): def get_toolpath_filters(self, path_mode=CORNER_STYLE_EXACT_PATH,
if name in settings_dict: motion_tolerance=0, naive_tolerance=0):
param_dict[name] = settings_dict[name] return [Filters.PathMode(path_mode, motion_tolerance, naive_tolerance)]
filers_list.insert(Filters.MachineSetting("corner_style", param_dict))
...@@ -47,7 +47,7 @@ class ToolParamRadius(pycam.Plugins.PluginBase): ...@@ -47,7 +47,7 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
def teardown(self): def teardown(self):
self.core.get("unregister_parameter")("tool", "radius") self.core.get("unregister_parameter")("tool", "radius")
self.core.unregister_ui("tool_size", self.control.get_widget()) self.core.unregister_ui("tool_size", self.control.get_widget())
self.core.unregister_chain("get_toolpath_filters", self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters) self.get_toolpath_filters)
@toolpath_filter("tool", "radius") @toolpath_filter("tool", "radius")
...@@ -87,14 +87,14 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase): ...@@ -87,14 +87,14 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
self.core.get("register_parameter")("tool", "feedrate", self.control) self.core.get("register_parameter")("tool", "feedrate", self.control)
self.core.register_ui("tool_speed", "Feedrate", self.core.register_ui("tool_speed", "Feedrate",
self.control.get_widget(), weight=10) self.control.get_widget(), weight=10)
self.core.register_chain("get_toolpath_filters", self.core.register_chain("toolpath_filters",
self.get_toolpath_filters) self.get_toolpath_filters)
return True return True
def teardown(self): def teardown(self):
self.core.unregister_ui("tool_speed", self.control.get_widget()) self.core.unregister_ui("tool_speed", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "feedrate") self.core.get("unregister_parameter")("tool", "feedrate")
self.core.unregister_chain("get_toolpath_filters", self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters) self.get_toolpath_filters)
@toolpath_filter("tool", "feedrate") @toolpath_filter("tool", "feedrate")
...@@ -115,14 +115,14 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase): ...@@ -115,14 +115,14 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
self.control) self.control)
self.core.register_ui("tool_speed", "Spindle Speed", self.core.register_ui("tool_speed", "Spindle Speed",
self.control.get_widget(), weight=50) self.control.get_widget(), weight=50)
self.core.register_chain("get_toolpath_filters", self.core.register_chain("toolpath_filters",
self.get_toolpath_filters) self.get_toolpath_filters)
return True return True
def teardown(self): def teardown(self):
self.core.unregister_ui("tool_speed", self.control.get_widget()) self.core.unregister_ui("tool_speed", self.control.get_widget())
self.core.get("unregister_parameter")("tool", "spindle_speed") self.core.get("unregister_parameter")("tool", "spindle_speed")
self.core.unregister_chain("get_toolpath_filters", self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters) self.get_toolpath_filters)
@toolpath_filter("tool", "spindle_speed") @toolpath_filter("tool", "spindle_speed")
......
...@@ -26,11 +26,12 @@ import pycam.Cutters.SphericalCutter ...@@ -26,11 +26,12 @@ import pycam.Cutters.SphericalCutter
import pycam.Cutters.ToroidalCutter import pycam.Cutters.ToroidalCutter
import pycam.Cutters.CylindricalCutter import pycam.Cutters.CylindricalCutter
def tool_params_and_filters(*param_names): def tool_params_and_filters(*param_names):
def get_params_and_filters_inner(func): def get_params_and_filters_inner(func):
def get_tool_func(self, parameters): def get_tool_func(self, parameters):
filters = [] filters = []
self.core.call_chain("get_toolpath_filters", "tool", parameters, self.core.call_chain("toolpath_filters", "tool", parameters,
filters) filters)
args = [] args = []
for param_name in param_names: for param_name in param_names:
......
...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,6 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
import pycam.Plugins import pycam.Plugins
from pycam.Toolpath.Filters import toolpath_filter
class Tools(pycam.Plugins.ListPluginBase): class Tools(pycam.Plugins.ListPluginBase):
...@@ -37,8 +38,6 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -37,8 +38,6 @@ class Tools(pycam.Plugins.ListPluginBase):
tool_frame.unparent() tool_frame.unparent()
self.core.register_ui("main", "Tools", tool_frame, weight=10) self.core.register_ui("main", "Tools", tool_frame, weight=10)
self._gtk_handlers = [] self._gtk_handlers = []
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
self._modelview = self.gui.get_object("ToolTable") self._modelview = self.gui.get_object("ToolTable")
self.set_gtk_modelview(self._modelview) self.set_gtk_modelview(self._modelview)
self.register_model_update(lambda: self.register_model_update(lambda:
...@@ -116,6 +115,8 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -116,6 +115,8 @@ class Tools(pycam.Plugins.ListPluginBase):
self._update_widgets() self._update_widgets()
self._trigger_table_update() self._trigger_table_update()
self._tool_switch() self._tool_switch()
self.core.register_chain("toolpath_filters",
self.get_toolpath_filters)
self.core.register_namespace("tools", self.core.register_namespace("tools",
pycam.Plugins.get_filter(self)) pycam.Plugins.get_filter(self))
self.register_state_item("tools", self) self.register_state_item("tools", self)
...@@ -124,6 +125,8 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -124,6 +125,8 @@ class Tools(pycam.Plugins.ListPluginBase):
def teardown(self): def teardown(self):
self.clear_state_items() self.clear_state_items()
self.core.unregister_namespace("tools") self.core.unregister_namespace("tools")
self.core.unregister_chain("toolpath_filters",
self.get_toolpath_filters)
if self.gui: if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolBox")) self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_ui_section("tool_speed") self.core.unregister_ui_section("tool_speed")
...@@ -135,17 +138,11 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -135,17 +138,11 @@ class Tools(pycam.Plugins.ListPluginBase):
self.core.unregister_ui_section("tool_parameters") self.core.unregister_ui_section("tool_parameters")
self.unregister_gtk_handlers(self._gtk_handlers) self.unregister_gtk_handlers(self._gtk_handlers)
self.unregister_event_handlers(self._event_handlers) self.unregister_event_handlers(self._event_handlers)
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
self.core.set("tools", None) self.core.set("tools", None)
while len(self) > 0: while len(self) > 0:
self.pop() self.pop()
return True return True
def get_toolpath_information(self, item, data):
if item in self:
data["tool_id"] = item["id"]
def _trigger_table_update(self): def _trigger_table_update(self):
self.gui.get_object("IDColumn").set_cell_data_func( self.gui.get_object("IDColumn").set_cell_data_func(
self.gui.get_object("IDCell"), self._render_tool_info, "id") self.gui.get_object("IDCell"), self._render_tool_info, "id")
...@@ -287,6 +284,10 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -287,6 +284,10 @@ class Tools(pycam.Plugins.ListPluginBase):
self.append(new_tool) self.append(new_tool)
self.select(new_tool) self.select(new_tool)
@toolpath_filter("tool", "tool_id")
def get_toolpath_filters(self, tool_id):
return [pycam.Toolpath.Filters.SelectTool(tool_id)]
class ToolEntity(pycam.Plugins.ObjectWithAttributes): class ToolEntity(pycam.Plugins.ObjectWithAttributes):
......
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