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):
else:
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:
self.chains[name] = []
self.chains[name].append((func, weight))
......
......@@ -57,26 +57,10 @@ class TaskTypeMilling(pycam.Plugins.PluginBase):
models = task["parameters"]["collision_models"]
moves = path_generator.GenerateToolPath(tool, models, motion_grid,
minz=low[2], maxz=high[2], draw_callback=callback)
kwargs = {}
try:
kwargs["max_safe_distance"] = 2 * environment["tool"]["radius"]
except KeyError:
pass
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)
data = {}
for item_name in ("tool", "process", "bounds"):
self.core.call_chain("get_toolpath_information",
environment[item_name], data)
tp = pycam.Toolpath.Toolpath(moves, parameters=data)
return tp
......@@ -37,10 +37,19 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
get_conv=lambda value: value / 2.0)
self.core.get("register_parameter")("tool", "size", "radius",
"Tool diameter", control, weight=10)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True
def teardown(self):
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):
......@@ -69,11 +78,19 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "feedrate",
"Feedrate", control, weight=10)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True
def teardown(self):
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):
......@@ -85,8 +102,17 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "spindle_speed",
"Spindle speed", control, weight=20)
self.core.register_chain("get_toolpath_information",
self.get_toolpath_information)
return True
def teardown(self):
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):
self.core.get("gcode_motion_tolerance"),
naive_tolerance)
for toolpath in toolpaths:
tool_id = toolpath.get_params()["tool_id"]
feedrate = toolpath.get_params()["feedrate"]
spindle_speed = toolpath.get_params()["spindle_speed"]
params = toolpath.get_params()
tool_id = params.get("tool_id", 1)
feedrate = params.get("tool_feedrate", 300)
spindle_speed = params.get("spindle_speed", 1000)
generator.set_speed(feedrate, spindle_speed)
# TODO: implement toolpath.get_meta_data()
generator.add_moves(toolpath.get_moves(safety_height),
......
......@@ -39,6 +39,8 @@ class Tools(pycam.Plugins.ListPluginBase):
tool_frame = self.gui.get_object("ToolBox")
tool_frame.unparent()
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")
for action, obj_name in ((self.ACTION_UP, "ToolMoveUp"),
(self.ACTION_DOWN, "ToolMoveDown"),
......@@ -128,6 +130,8 @@ class Tools(pycam.Plugins.ListPluginBase):
self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_event("tool-selection-changed",
self._tool_switch)
self.core.unregister_chain("get_toolpath_information",
self.get_toolpath_information)
self.core.set("tools", None)
return True
......@@ -142,6 +146,10 @@ class Tools(pycam.Plugins.ListPluginBase):
selection.unselect_all()
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):
path = model.get_path(m_iter)
tool = self[path[0]]
......
......@@ -62,18 +62,17 @@ def simplify_toolpath(path):
class Toolpath(object):
def __init__(self, paths, max_safe_distance=0, feedrate=300, **kwargs):
def __init__(self, paths, parameters=None):
self.paths = paths
self._max_safe_distance = max_safe_distance
self._feedrate = feedrate
self._other_params = kwargs
if parameters:
self.parameters = parameters
else:
self.parameters = {}
self._max_safe_distance = 2 * parameters.get("tool_radius", 0)
self._feedrate = parameters.get("tool_feedrate", 300)
def get_params(self):
result = {"max_safe_distance": self._max_safe_distance,
"feedrate": self._feedrate,
}
result.update(self._other_params)
return result
return dict(self.parameters)
def _get_limit_generic(self, attr, func):
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