Commit dcfc6c0f authored by sumpfralle's avatar sumpfralle

collect toolpath parameters via a chained caller


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1159 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 5ae43e3b
...@@ -295,7 +295,7 @@ class EventCore(pycam.Gui.Settings.Settings): ...@@ -295,7 +295,7 @@ class EventCore(pycam.Gui.Settings.Settings):
else: else:
log.debug("Trying to unregister unknown ui section: %s" % section) log.debug("Trying to unregister unknown ui section: %s" % section)
def register_chain(self, name, func, weight): def register_chain(self, name, func, weight=100):
if not name in self.chains: if not name in self.chains:
self.chains[name] = [] self.chains[name] = []
self.chains[name].append((func, weight)) self.chains[name].append((func, weight))
......
...@@ -57,26 +57,10 @@ class TaskTypeMilling(pycam.Plugins.PluginBase): ...@@ -57,26 +57,10 @@ class TaskTypeMilling(pycam.Plugins.PluginBase):
models = task["parameters"]["collision_models"] models = task["parameters"]["collision_models"]
moves = path_generator.GenerateToolPath(tool, models, motion_grid, moves = path_generator.GenerateToolPath(tool, models, motion_grid,
minz=low[2], maxz=high[2], draw_callback=callback) minz=low[2], maxz=high[2], draw_callback=callback)
kwargs = {} data = {}
try: for item_name in ("tool", "process", "bounds"):
kwargs["max_safe_distance"] = 2 * environment["tool"]["radius"] self.core.call_chain("get_toolpath_information",
except KeyError: environment[item_name], data)
pass tp = pycam.Toolpath.Toolpath(moves, parameters=data)
try:
kwargs["feedrate"] = environment["tool"]["feedrate"]
except KeyError:
pass
try:
kwargs["spindle_speed"] = environment["tool"]["spindle_speed"]
except KeyError:
# TODO: somehow spindle_speed is not available???
kwargs["spindle_speed"] = 1000
pass
try:
# TODO: get the tool_id!
kwargs["tool_id"] = 1
except KeyError:
pass
tp = pycam.Toolpath.Toolpath(moves, **kwargs)
return tp return tp
...@@ -37,10 +37,19 @@ class ToolParamRadius(pycam.Plugins.PluginBase): ...@@ -37,10 +37,19 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
get_conv=lambda value: value / 2.0) get_conv=lambda value: value / 2.0)
self.core.get("register_parameter")("tool", "size", "radius", self.core.get("register_parameter")("tool", "size", "radius",
"Tool diameter", control, weight=10) "Tool diameter", control, weight=10)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True return True
def teardown(self): def teardown(self):
self.core.get("unregister_parameter")("tool", "size", "radius") self.core.get("unregister_parameter")("tool", "size", "radius")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
def get_toolpath_information(self, item, data):
if item in self.core.get("tools") and \
"radius" in item["parameters"]:
data["tool_radius"] = item["parameters"]["radius"]
class ToolParamTorusRadius(pycam.Plugins.PluginBase): class ToolParamTorusRadius(pycam.Plugins.PluginBase):
...@@ -69,11 +78,19 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase): ...@@ -69,11 +78,19 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
self.core.emit_event("tool-changed")) self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "feedrate", self.core.get("register_parameter")("tool", "speed", "feedrate",
"Feedrate", control, weight=10) "Feedrate", control, weight=10)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True return True
def teardown(self): def teardown(self):
self.core.get("unregister_parameter")("tool", "speed", "feedrate") self.core.get("unregister_parameter")("tool", "speed", "feedrate")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
def get_toolpath_information(self, item, data):
if item in self.core.get("tools") and \
"feedrate" in item["parameters"]:
data["tool_feedrate"] = item["parameters"]["feedrate"]
class ToolParamSpindleSpeed(pycam.Plugins.PluginBase): class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
...@@ -85,8 +102,17 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase): ...@@ -85,8 +102,17 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
self.core.emit_event("tool-changed")) self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "spindle_speed", self.core.get("register_parameter")("tool", "speed", "spindle_speed",
"Spindle speed", control, weight=20) "Spindle speed", control, weight=20)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True return True
def teardown(self): def teardown(self):
self.core.get("unregister_parameter")("tool", "speed", "spindle_speed") self.core.get("unregister_parameter")("tool", "speed", "spindle_speed")
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
def get_toolpath_information(self, item, data):
if item in self.core.get("tools") and \
"spindle_speed" in item["parameters"]:
data["spindle_speed"] = item["parameters"]["spindle_speed"]
...@@ -210,9 +210,10 @@ class ToolpathExport(pycam.Plugins.PluginBase): ...@@ -210,9 +210,10 @@ class ToolpathExport(pycam.Plugins.PluginBase):
self.core.get("gcode_motion_tolerance"), self.core.get("gcode_motion_tolerance"),
naive_tolerance) naive_tolerance)
for toolpath in toolpaths: for toolpath in toolpaths:
tool_id = toolpath.get_params()["tool_id"] params = toolpath.get_params()
feedrate = toolpath.get_params()["feedrate"] tool_id = params.get("tool_id", 1)
spindle_speed = toolpath.get_params()["spindle_speed"] feedrate = params.get("tool_feedrate", 300)
spindle_speed = params.get("spindle_speed", 1000)
generator.set_speed(feedrate, spindle_speed) generator.set_speed(feedrate, spindle_speed)
# TODO: implement toolpath.get_meta_data() # TODO: implement toolpath.get_meta_data()
generator.add_moves(toolpath.get_moves(safety_height), generator.add_moves(toolpath.get_moves(safety_height),
......
...@@ -39,6 +39,8 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -39,6 +39,8 @@ class Tools(pycam.Plugins.ListPluginBase):
tool_frame = self.gui.get_object("ToolBox") tool_frame = self.gui.get_object("ToolBox")
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.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
self._modelview = self.gui.get_object("ToolEditorTable") self._modelview = self.gui.get_object("ToolEditorTable")
for action, obj_name in ((self.ACTION_UP, "ToolMoveUp"), for action, obj_name in ((self.ACTION_UP, "ToolMoveUp"),
(self.ACTION_DOWN, "ToolMoveDown"), (self.ACTION_DOWN, "ToolMoveDown"),
...@@ -128,6 +130,8 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -128,6 +130,8 @@ class Tools(pycam.Plugins.ListPluginBase):
self.core.unregister_ui("main", self.gui.get_object("ToolBox")) self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_event("tool-selection-changed", self.core.unregister_event("tool-selection-changed",
self._tool_switch) self._tool_switch)
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
self.core.set("tools", None) self.core.set("tools", None)
return True return True
...@@ -142,6 +146,10 @@ class Tools(pycam.Plugins.ListPluginBase): ...@@ -142,6 +146,10 @@ class Tools(pycam.Plugins.ListPluginBase):
selection.unselect_all() selection.unselect_all()
selection.select_path((index,)) selection.select_path((index,))
def get_toolpath_information(self, item, data):
if item in self:
data["tool_id"] = self.get_attr(item, "id")
def _render_tool_shape(self, column, cell, model, m_iter): def _render_tool_shape(self, column, cell, model, m_iter):
path = model.get_path(m_iter) path = model.get_path(m_iter)
tool = self[path[0]] tool = self[path[0]]
......
...@@ -62,18 +62,17 @@ def simplify_toolpath(path): ...@@ -62,18 +62,17 @@ def simplify_toolpath(path):
class Toolpath(object): class Toolpath(object):
def __init__(self, paths, max_safe_distance=0, feedrate=300, **kwargs): def __init__(self, paths, parameters=None):
self.paths = paths self.paths = paths
self._max_safe_distance = max_safe_distance if parameters:
self._feedrate = feedrate self.parameters = parameters
self._other_params = kwargs else:
self.parameters = {}
self._max_safe_distance = 2 * parameters.get("tool_radius", 0)
self._feedrate = parameters.get("tool_feedrate", 300)
def get_params(self): def get_params(self):
result = {"max_safe_distance": self._max_safe_distance, return dict(self.parameters)
"feedrate": self._feedrate,
}
result.update(self._other_params)
return result
def _get_limit_generic(self, attr, func): def _get_limit_generic(self, attr, func):
path_min = [] path_min = []
......
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