Commit 06009c2d authored by sumpfralle's avatar sumpfralle

implemented grid and spiral path patterns as separate plugins


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1182 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 3276773e
...@@ -32,9 +32,7 @@ _log = pycam.Utils.log.get_logger() ...@@ -32,9 +32,7 @@ _log = pycam.Utils.log.get_logger()
def _input_conversion(func): def _input_conversion(func):
def _input_conversion_wrapper(self, value): def _input_conversion_wrapper(self, value):
if value is None: if hasattr(self, "_input_converter") and self._input_converter:
new_value = None
elif hasattr(self, "_input_converter") and self._input_converter:
new_value = self._input_converter(value) new_value = self._input_converter(value)
else: else:
new_value = value new_value = value
...@@ -103,6 +101,7 @@ class InputChoice(InputBaseClass): ...@@ -103,6 +101,7 @@ class InputChoice(InputBaseClass):
if change_handler: if change_handler:
self.control.connect("changed", change_handler) self.control.connect("changed", change_handler)
@_output_conversion
def get_value(self): def get_value(self):
index = self.control.get_active() index = self.control.get_active()
if index < 0: if index < 0:
...@@ -110,6 +109,7 @@ class InputChoice(InputBaseClass): ...@@ -110,6 +109,7 @@ class InputChoice(InputBaseClass):
else: else:
return self._values[index] return self._values[index]
@_input_conversion
def set_value(self, value): def set_value(self, value):
if value is None: if value is None:
self.control.set_active(-1) self.control.set_active(-1)
......
...@@ -93,7 +93,7 @@ class PathParamMaterialAllowance(pycam.Plugins.PluginBase): ...@@ -93,7 +93,7 @@ class PathParamMaterialAllowance(pycam.Plugins.PluginBase):
class PathParamMillingStyle(pycam.Plugins.PluginBase): class PathParamMillingStyle(pycam.Plugins.PluginBase):
DEPENDS = ["Processes"] DEPENDS = ["Processes", "PathParamPattern"]
CATEGORIES = ["Process", "Parameter"] CATEGORIES = ["Process", "Parameter"]
def setup(self): def setup(self):
...@@ -103,7 +103,7 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase): ...@@ -103,7 +103,7 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase):
("conventional / up", pycam.Toolpath.MotionGrid.MILLING_STYLE_CONVENTIONAL)), ("conventional / up", pycam.Toolpath.MotionGrid.MILLING_STYLE_CONVENTIONAL)),
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"process-changed")) "process-changed"))
self.core.get("register_parameter")("process", "milling_style", self.core.get("register_parameter")("path_pattern", "milling_style",
self.control) self.control)
self.core.register_ui("process_path_parameters", "Milling style", self.core.register_ui("process_path_parameters", "Milling style",
self.control.get_widget(), weight=50) self.control.get_widget(), weight=50)
...@@ -111,12 +111,12 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase): ...@@ -111,12 +111,12 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase):
def teardown(self): def teardown(self):
self.core.unregister_ui("process_path_parameters", self.control.get_widget()) self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "milling_style") self.core.get("unregister_parameter")("path_pattern", "milling_style")
class PathParamGridDirection(pycam.Plugins.PluginBase): class PathParamGridDirection(pycam.Plugins.PluginBase):
DEPENDS = ["Processes"] DEPENDS = ["Processes", "PathParamPattern"]
CATEGORIES = ["Process", "Parameter"] CATEGORIES = ["Process", "Parameter"]
def setup(self): def setup(self):
...@@ -126,7 +126,7 @@ class PathParamGridDirection(pycam.Plugins.PluginBase): ...@@ -126,7 +126,7 @@ class PathParamGridDirection(pycam.Plugins.PluginBase):
("xy", pycam.Toolpath.MotionGrid.GRID_DIRECTION_XY)), ("xy", pycam.Toolpath.MotionGrid.GRID_DIRECTION_XY)),
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"process-changed")) "process-changed"))
self.core.get("register_parameter")("process", "grid_direction", self.core.get("register_parameter")("path_pattern", "grid_direction",
self.control) self.control)
self.core.register_ui("process_path_parameters", "Direction", self.core.register_ui("process_path_parameters", "Direction",
self.control.get_widget(), weight=40) self.control.get_widget(), weight=40)
...@@ -134,30 +134,101 @@ class PathParamGridDirection(pycam.Plugins.PluginBase): ...@@ -134,30 +134,101 @@ class PathParamGridDirection(pycam.Plugins.PluginBase):
def teardown(self): def teardown(self):
self.core.unregister_ui("process_path_parameters", self.control.get_widget()) self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "grid_direction") self.core.get("unregister_parameter")("path_pattern", "grid_direction")
class PathParamPattern(pycam.Plugins.PluginBase): class PathParamSpiralDirection(pycam.Plugins.PluginBase):
DEPENDS = ["Processes"] DEPENDS = ["Processes", "PathParamPattern"]
CATEGORIES = ["Process", "Parameter"] CATEGORIES = ["Process", "Parameter"]
def setup(self): def setup(self):
self.control = pycam.Gui.ControlsGTK.InputChoice( self.control = pycam.Gui.ControlsGTK.InputChoice(
(("grid", pycam.Toolpath.MotionGrid.get_fixed_grid), (("outside -> center", pycam.Toolpath.MotionGrid.SPIRAL_DIRECTION_IN),
("spiral", pycam.Toolpath.MotionGrid.get_spiral)), ("center -> outside", pycam.Toolpath.MotionGrid.SPIRAL_DIRECTION_OUT)),
change_handler=lambda widget=None: self.core.emit_event(
"process-changed"))
self.core.get("register_parameter")("path_pattern", "spiral_direction",
self.control)
self.core.register_ui("process_path_parameters", "Direction",
self.control.get_widget(), weight=40)
return True
def teardown(self):
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("path_pattern", "spiral_direction")
class PathParamPattern(pycam.Plugins.PluginBase):
DEPENDS = ["Processes", "ParameterGroupManager"]
CATEGORIES = ["Process", "Parameter"]
def setup(self):
self.choices = []
self.control = pycam.Gui.ControlsGTK.InputChoice([],
change_handler=lambda widget=None: self.core.emit_event( change_handler=lambda widget=None: self.core.emit_event(
"process-changed")) "process-changed"))
self.control.set_conversion(set_conv=self._set_value_converter,
get_conv=self._get_value_converter)
self.core.get("register_parameter")("process", "path_pattern", self.core.get("register_parameter")("process", "path_pattern",
self.control) self.control)
self.core.get("register_parameter_group")("path_pattern",
changed_set_event="process-path-pattern-changed",
changed_set_list_event="process-path-pattern-list-changed",
get_current_set_func=self._get_pattern)
self.core.register_ui("process_path_parameters", "Pattern", self.core.register_ui("process_path_parameters", "Pattern",
self.control.get_widget(), weight=5) self.control.get_widget(), weight=5)
self.control.get_widget().connect("changed", lambda widget: \
self.core.emit_event("process-path-pattern-changed"))
self.core.register_event("process-path-pattern-list-changed",
self._update_selector)
return True return True
def _get_value_converter(self, value):
if value:
parameter_keys = self.core.get("get_parameter_sets")("path_pattern")[value]["parameters"].keys()
all_parameters = self.core.get("get_parameter_values")("path_pattern")
result = {"name": value, "parameters": {}}
for parameter_key in parameter_keys:
result["parameters"][parameter_key] = all_parameters[parameter_key]
return result
else:
return None
def _set_value_converter(self, value):
if value:
self.core.get("set_parameter_values")("path_pattern", value["parameters"])
return value["name"]
elif self.choices:
# use the first entry as the default value
return self.choices[0][1]
else:
return None
def teardown(self): def teardown(self):
self.core.unregister_ui("process_path_parameters", self.control.get_widget()) self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("process", "path_pattern") self.core.get("unregister_parameter")("process", "path_pattern")
def _update_selector(self):
patterns = list(self.core.get("get_parameter_sets")(
"path_pattern").values())
patterns.sort(key=lambda item: item["weight"])
self.choices = []
for pattern in patterns:
self.choices.append((pattern["label"], pattern["name"]))
self.control.update_choices(self.choices)
if not self.control.get_value() and self.choices:
print {"name": self.choices[0][1], "parameters": {}}
self.control.set_value({"name": self.choices[0][1], "parameters": {}})
def _get_pattern(self):
pattern_set = self.control.get_value()
if pattern_set:
return self.core.get("get_parameter_sets")("path_pattern")[pattern_set["name"]]
else:
return None
class PathParamRadiusCompensation(pycam.Plugins.PluginBase): class PathParamRadiusCompensation(pycam.Plugins.PluginBase):
......
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
PyCAM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
import pycam.Toolpath.MotionGrid
class PathPatternSpiral(pycam.Plugins.PluginBase):
DEPENDS = ["ParameterGroupManager", "PathParamPattern",
"PathParamMillingStyle", "PathParamSpiralDirection"]
CATEGORIES = ["Process"]
def setup(self):
parameters = {
"milling_style": pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE,
"spiral_direction": None,
}
self.core.get("register_parameter_set")("path_pattern", "spiral",
"Spiral", self.get_grid_generator, parameters=parameters,
weight=30)
return True
def teardown(self):
self.core.get("unregister_parameter_set")("path_pattern", "spiral")
def get_grid_generator(self, pattern):
kwargs = pattern["parameters"]
func = pycam.Toolpath.MotionGrid.get_spiral
return func, kwargs
class PathPatternGrid(pycam.Plugins.PluginBase):
DEPENDS = ["ParameterGroupManager", "PathParamPattern",
"PathParamMillingStyle", "PathParamGridDirection"]
CATEGORIES = ["Process"]
def setup(self):
parameters = {
"milling_style": pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE,
"grid_direction": pycam.Toolpath.MotionGrid.GRID_DIRECTION_X,
}
self.core.get("register_parameter_set")("path_pattern", "grid",
"Grid", self.get_grid_generator, parameters=parameters,
weight=10)
return True
def teardown(self):
self.core.get("unregister_parameter_set")("path_pattern", "grid")
def get_grid_generator(self, pattern):
kwargs = pattern["parameters"]
func = pycam.Toolpath.MotionGrid.get_fixed_grid
return func, kwargs
...@@ -31,7 +31,6 @@ class ProcessStrategySlicing(pycam.Plugins.PluginBase): ...@@ -31,7 +31,6 @@ class ProcessStrategySlicing(pycam.Plugins.PluginBase):
DEPENDS = ["ParameterGroupManager", "PathParamOverlap", DEPENDS = ["ParameterGroupManager", "PathParamOverlap",
"PathParamStepDown", "PathParamMaterialAllowance", "PathParamStepDown", "PathParamMaterialAllowance",
"PathParamMillingStyle", "PathParamGridDirection",
"PathParamPattern"] "PathParamPattern"]
CATEGORIES = ["Process"] CATEGORIES = ["Process"]
...@@ -39,9 +38,7 @@ class ProcessStrategySlicing(pycam.Plugins.PluginBase): ...@@ -39,9 +38,7 @@ class ProcessStrategySlicing(pycam.Plugins.PluginBase):
parameters = {"overlap": 0.1, parameters = {"overlap": 0.1,
"step_down": 1.0, "step_down": 1.0,
"material_allowance": 0, "material_allowance": 0,
"milling_style": pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE, "path_pattern": None,
"grid_direction": pycam.Toolpath.MotionGrid.GRID_DIRECTION_X,
"path_pattern": pycam.Toolpath.MotionGrid.get_fixed_grid,
} }
self.core.get("register_parameter_set")("process", "slicing", self.core.get("register_parameter_set")("process", "slicing",
"Slice removal", self.run_process, parameters=parameters, "Slice removal", self.run_process, parameters=parameters,
...@@ -60,11 +57,13 @@ class ProcessStrategySlicing(pycam.Plugins.PluginBase): ...@@ -60,11 +57,13 @@ class ProcessStrategySlicing(pycam.Plugins.PluginBase):
(1.0 - process["parameters"]["overlap"]) (1.0 - process["parameters"]["overlap"])
path_generator = pycam.PathGenerators.PushCutter.PushCutter( path_generator = pycam.PathGenerators.PushCutter.PushCutter(
pycam.PathProcessors.PathAccumulator.PathAccumulator()) pycam.PathProcessors.PathAccumulator.PathAccumulator())
motion_grid = process["parameters"]["path_pattern"]( path_pattern = process["parameters"]["path_pattern"]
(low, high), process["parameters"]["step_down"], path_get_func = self.core.get("get_parameter_sets")(
line_distance=line_distance, "path_pattern")[path_pattern["name"]]["func"]
grid_direction=process["parameters"]["grid_direction"], grid_func, kwargs = path_get_func(path_pattern)
milling_style=process["parameters"]["milling_style"]) motion_grid = grid_func((low, high),
process["parameters"]["step_down"],
line_distance=line_distance, **kwargs)
return path_generator, motion_grid, (low, high) return path_generator, motion_grid, (low, high)
...@@ -94,15 +93,14 @@ class ProcessStrategyContour(pycam.Plugins.PluginBase): ...@@ -94,15 +93,14 @@ class ProcessStrategyContour(pycam.Plugins.PluginBase):
class ProcessStrategySurfacing(pycam.Plugins.PluginBase): class ProcessStrategySurfacing(pycam.Plugins.PluginBase):
DEPENDS = ["ParameterGroupManager", "PathParamOverlap", DEPENDS = ["ParameterGroupManager", "PathParamOverlap",
"PathParamMaterialAllowance", "PathParamMillingStyle", "PathParamStepDown", "PathParamMaterialAllowance",
"PathParamGridDirection"] "PathParamPattern"]
CATEGORIES = ["Process"] CATEGORIES = ["Process"]
def setup(self): def setup(self):
parameters = {"overlap": 0.6, parameters = {"overlap": 0.6,
"material_allowance": 0, "material_allowance": 0,
"milling_style": pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE, "path_pattern": None,
"grid_direction": pycam.Toolpath.MotionGrid.GRID_DIRECTION_X,
} }
self.core.get("register_parameter_set")("process", "surfacing", self.core.get("register_parameter_set")("process", "surfacing",
"Surfacing", self.run_process, parameters=parameters, "Surfacing", self.run_process, parameters=parameters,
...@@ -121,12 +119,14 @@ class ProcessStrategySurfacing(pycam.Plugins.PluginBase): ...@@ -121,12 +119,14 @@ class ProcessStrategySurfacing(pycam.Plugins.PluginBase):
(1.0 - process["parameters"]["overlap"]) (1.0 - process["parameters"]["overlap"])
path_generator = pycam.PathGenerators.DropCutter.DropCutter( path_generator = pycam.PathGenerators.DropCutter.DropCutter(
pycam.PathProcessors.PathAccumulator.PathAccumulator()) pycam.PathProcessors.PathAccumulator.PathAccumulator())
motion_grid = pycam.Toolpath.MotionGrid.get_fixed_grid( path_pattern = process["parameters"]["path_pattern"]
(low, high), process["parameters"]["step_down"], path_get_func = self.core.get("get_parameter_sets")(
line_distance=line_distance, "path_pattern")[path_pattern["name"]]["func"]
grid_func, kwargs = path_get_func(path_pattern)
motion_grid = grid_func((low, high),
process["parameters"]["step_down"],
step_width=(tool_params["radius"] / 4.0), step_width=(tool_params["radius"] / 4.0),
grid_direction=process["parameters"]["grid_direction"], line_distance=line_distance, **kwargs)
milling_style=process["parameters"]["milling_style"])
return path_generator, motion_grid, (low, high) return path_generator, motion_grid, (low, high)
......
...@@ -39,6 +39,9 @@ START_X = 0x1 ...@@ -39,6 +39,9 @@ START_X = 0x1
START_Y = 0x2 START_Y = 0x2
START_Z = 0x4 START_Z = 0x4
SPIRAL_DIRECTION_IN = 0
SPIRAL_DIRECTION_OUT = 1
def isiterable(obj): def isiterable(obj):
try: try:
iter(obj) iter(obj)
...@@ -160,8 +163,7 @@ def get_fixed_grid_layer(minx, maxx, miny, maxy, z, line_distance, ...@@ -160,8 +163,7 @@ def get_fixed_grid_layer(minx, maxx, miny, maxy, z, line_distance,
def get_fixed_grid((low, high), layer_distance, line_distance=None, def get_fixed_grid((low, high), layer_distance, line_distance=None,
step_width=None, grid_direction=GRID_DIRECTION_X, step_width=None, grid_direction=GRID_DIRECTION_X,
milling_style=MILLING_STYLE_IGNORE, start_position=START_Z, milling_style=MILLING_STYLE_IGNORE, start_position=START_Z):
reverse=False):
""" Calculate the grid positions for toolpath moves """ Calculate the grid positions for toolpath moves
""" """
if isiterable(layer_distance): if isiterable(layer_distance):
...@@ -257,10 +259,9 @@ def get_spiral_layer(minx, maxx, miny, maxy, z, line_distance, step_width, ...@@ -257,10 +259,9 @@ def get_spiral_layer(minx, maxx, miny, maxy, z, line_distance, step_width,
yield points yield points
def get_spiral((low, high), layer_distance, line_distance=None, def get_spiral((low, high), layer_distance, line_distance=None,
step_width=None, grid_direction=None, step_width=None, milling_style=MILLING_STYLE_IGNORE,
milling_style=MILLING_STYLE_IGNORE, spiral_direction=SPIRAL_DIRECTION_IN,
start_position=(START_X | START_Y | START_Z), start_position=(START_X | START_Y | START_Z)):
reverse=True):
""" Calculate the grid positions for toolpath moves """ Calculate the grid positions for toolpath moves
""" """
if isiterable(layer_distance): if isiterable(layer_distance):
...@@ -276,6 +277,7 @@ def get_spiral((low, high), layer_distance, line_distance=None, ...@@ -276,6 +277,7 @@ def get_spiral((low, high), layer_distance, line_distance=None,
start_direction = GRID_DIRECTION_X start_direction = GRID_DIRECTION_X
else: else:
start_direction = GRID_DIRECTION_Y start_direction = GRID_DIRECTION_Y
reverse = (spiral_direction == SPIRAL_DIRECTION_OUT)
for z in layers: for z in layers:
yield get_spiral_layer(low[0], high[0], low[1], high[1], z, yield get_spiral_layer(low[0], high[0], low[1], high[1], z,
line_distance, step_width=step_width, line_distance, step_width=step_width,
......
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