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