Commit b6602b5c authored by sumpfralle's avatar sumpfralle

added pocketing selector


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1222 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b62bd6ea
...@@ -324,3 +324,26 @@ class PathParamTraceModel(pycam.Plugins.PluginBase): ...@@ -324,3 +324,26 @@ class PathParamTraceModel(pycam.Plugins.PluginBase):
choices.append((model["name"], model)) choices.append((model["name"], model))
self.control.update_choices(choices) self.control.update_choices(choices)
class PathParamPocketingType(pycam.Plugins.PluginBase):
DEPENDS = ["Processes"]
CATEGORIES = ["Process", "Parameter"]
def setup(self):
self.control = pycam.Gui.ControlsGTK.InputChoice(
(("none", pycam.Toolpath.MotionGrid.POCKETING_TYPE_NONE),
("holes", pycam.Toolpath.MotionGrid.POCKETING_TYPE_HOLES),
("material", pycam.Toolpath.MotionGrid.POCKETING_TYPE_MATERIAL)),
change_handler=lambda widget=None: self.core.emit_event(
"process-changed"))
self.core.get("register_parameter")("process", "pocketing_type",
self.control)
self.core.register_ui("process_path_parameters", "Pocketing",
self.control.get_widget(), weight=60)
return True
def teardown(self):
self.core.unregister_ui("process_path_parameters", self.control.get_widget())
self.core.get("unregister_parameter")("path_pattern", "pocketing_type")
...@@ -148,7 +148,7 @@ class ProcessStrategyEngraving(pycam.Plugins.PluginBase): ...@@ -148,7 +148,7 @@ class ProcessStrategyEngraving(pycam.Plugins.PluginBase):
DEPENDS = ["ParameterGroupManager", "PathParamStepDown", DEPENDS = ["ParameterGroupManager", "PathParamStepDown",
"PathParamMillingStyle", "PathParamRadiusCompensation", "PathParamMillingStyle", "PathParamRadiusCompensation",
"PathParamTraceModel"] "PathParamTraceModel", "PathParamPocketingType"]
CATEGORIES = ["Process"] CATEGORIES = ["Process"]
def setup(self): def setup(self):
...@@ -156,6 +156,7 @@ class ProcessStrategyEngraving(pycam.Plugins.PluginBase): ...@@ -156,6 +156,7 @@ class ProcessStrategyEngraving(pycam.Plugins.PluginBase):
"milling_style": pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE, "milling_style": pycam.Toolpath.MotionGrid.MILLING_STYLE_IGNORE,
"radius_compensation": False, "radius_compensation": False,
"trace_models": [], "trace_models": [],
"pocketing_type": pycam.Toolpath.MotionGrid.POCKETING_TYPE_NONE,
} }
self.core.get("register_parameter_set")("process", "engraving", self.core.get("register_parameter_set")("process", "engraving",
"Engraving", self.run_process, parameters=parameters, "Engraving", self.run_process, parameters=parameters,
...@@ -190,8 +191,10 @@ class ProcessStrategyEngraving(pycam.Plugins.PluginBase): ...@@ -190,8 +191,10 @@ class ProcessStrategyEngraving(pycam.Plugins.PluginBase):
progress.update(text="Calculating moves") progress.update(text="Calculating moves")
motion_grid = pycam.Toolpath.MotionGrid.get_lines_grid(models, motion_grid = pycam.Toolpath.MotionGrid.get_lines_grid(models,
(low, high), process["parameters"]["step_down"], (low, high), process["parameters"]["step_down"],
line_distance=1.8*tool_params["radius"],
step_width=(tool_params["radius"] / 4.0), step_width=(tool_params["radius"] / 4.0),
milling_style=process["parameters"]["milling_style"], milling_style=process["parameters"]["milling_style"],
pocketing_type=process["parameters"]["pocketing_type"],
callback=progress.update) callback=progress.update)
progress.finish() progress.finish()
return path_generator, motion_grid, (low, high) return path_generator, motion_grid, (low, high)
......
...@@ -24,10 +24,15 @@ from pycam.Geometry.Point import Point, Vector ...@@ -24,10 +24,15 @@ from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.Line import Line from pycam.Geometry.Line import Line
from pycam.Geometry.utils import epsilon from pycam.Geometry.utils import epsilon
from pycam.Geometry.Polygon import PolygonSorter from pycam.Geometry.Polygon import PolygonSorter
import pycam.Utils.log
import pycam.Geometry import pycam.Geometry
import math import math
_log = pycam.Utils.log.get_logger()
GRID_DIRECTION_X = 0 GRID_DIRECTION_X = 0
GRID_DIRECTION_Y = 1 GRID_DIRECTION_Y = 1
GRID_DIRECTION_XY = 2 GRID_DIRECTION_XY = 2
...@@ -43,6 +48,11 @@ START_Z = 0x4 ...@@ -43,6 +48,11 @@ START_Z = 0x4
SPIRAL_DIRECTION_IN = 0 SPIRAL_DIRECTION_IN = 0
SPIRAL_DIRECTION_OUT = 1 SPIRAL_DIRECTION_OUT = 1
POCKETING_TYPE_NONE = 0
POCKETING_TYPE_HOLES = 1
POCKETING_TYPE_MATERIAL = 2
def isiterable(obj): def isiterable(obj):
try: try:
iter(obj) iter(obj)
...@@ -389,12 +399,20 @@ def _get_sorted_polygons(models, callback=None): ...@@ -389,12 +399,20 @@ def _get_sorted_polygons(models, callback=None):
def get_lines_grid(models, (low, high), layer_distance, line_distance=None, def get_lines_grid(models, (low, high), layer_distance, line_distance=None,
step_width=None, milling_style=MILLING_STYLE_CONVENTIONAL, step_width=None, milling_style=MILLING_STYLE_CONVENTIONAL,
start_position=START_Z, callback=None): start_position=START_Z, pocketing_type=POCKETING_TYPE_NONE,
callback=None):
# the lower limit is never below the model # the lower limit is never below the model
polygons = _get_sorted_polygons(models, callback=callback) polygons = _get_sorted_polygons(models, callback=callback)
if polygons: if polygons:
low_limit_lines = min([polygon.minz for polygon in polygons]) low_limit_lines = min([polygon.minz for polygon in polygons])
low[2] = max(low[2], low_limit_lines) low[2] = max(low[2], low_limit_lines)
# calculate pockets
if pocketing_type != POCKETING_TYPE_NONE:
if not callback is None:
callback(text="Generating pocketing polygons ...")
polygons = get_pocketing_polygons(polygons, line_distance,
pocketing_type, callback=callback)
# extract lines in correct order from all polygons
lines = [] lines = []
for polygon in polygons: for polygon in polygons:
if callback: if callback:
...@@ -413,9 +431,9 @@ def get_lines_grid(models, (low, high), layer_distance, line_distance=None, ...@@ -413,9 +431,9 @@ def get_lines_grid(models, (low, high), layer_distance, line_distance=None,
else: else:
layers = floatrange(low[2], high[2], inc=layer_distance, layers = floatrange(low[2], high[2], inc=layer_distance,
reverse=bool(start_position & START_Z)) reverse=bool(start_position & START_Z))
last_z = None
# turn the generator into a list - otherwise the slicing fails # turn the generator into a list - otherwise the slicing fails
layers = list(layers) layers = list(layers)
last_z = None
if layers: if layers:
# the upper layers are used for PushCutter operations # the upper layers are used for PushCutter operations
for z in layers[:-1]: for z in layers[:-1]:
...@@ -430,3 +448,55 @@ def get_lines_grid(models, (low, high), layer_distance, line_distance=None, ...@@ -430,3 +448,55 @@ def get_lines_grid(models, (low, high), layer_distance, line_distance=None,
yield get_lines_layer(lines, layers[-1], last_z=last_z, yield get_lines_layer(lines, layers[-1], last_z=last_z,
step_width=step_width, milling_style=milling_style) step_width=step_width, milling_style=milling_style)
def get_pocketing_polygons(polygons, offset, pocketing_type, callback=None):
pocketing_limit = 1000
base_polygons = []
other_polygons = []
if pocketing_type == POCKETING_TYPE_HOLES:
# go inwards
offset *= -1
for poly in polygons:
if poly.is_closed and poly.is_outer():
base_polygons.append(poly)
else:
other_polygons.append(poly)
elif pocketing_type == POCKETING_TYPE_MATERIAL:
for poly in polygons:
if poly.is_closed and not poly.is_outer():
base_polygons.append(poly)
else:
other_polygons.append(poly)
else:
_log.warning("Invalid pocketing type given: %d" % str(pocketing_type))
return polygons
# For now we use only the polygons that do not surround any other
# polygons. Sorry - the pocketing is currently very simple ...
base_filtered_polygons = []
for candidate in base_polygons:
if callback and callback():
# we were interrupted
return polygons
for other in other_polygons:
if candidate.is_polygon_inside(other):
break
else:
base_filtered_polygons.append(candidate)
# start the pocketing for all remaining polygons
pocket_polygons = []
for base_polygon in base_filtered_polygons:
pocket_polygons.append(base_polygon)
current_queue = [base_polygon]
next_queue = []
pocket_depth = 0
while current_queue and (pocket_depth < pocketing_limit):
if callback and callback():
return polygons
for poly in current_queue:
result = poly.get_offset_polygons(offset)
pocket_polygons.extend(result)
next_queue.extend(result)
pocket_depth += 1
current_queue = next_queue
next_queue = []
return pocket_polygons
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