Commit ec46d22b authored by sumpfralle's avatar sumpfralle

use the new "Bounds" class more consistently


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@452 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent c3c12167
......@@ -2033,23 +2033,18 @@ class ProjectGui:
# this should never happen
log.error("Assertion failed: invalid boundary_mode (%s)" % str(self.settings.get("boundary_mode")))
abs_bounds_low, abs_bounds_high = bounds.get_absolute_limits(
border = (offset, offset, 0)
processing_bounds = Bounds(Bounds.TYPE_FIXED_MARGIN, border, border,
reference=self.model.get_bounds())
minx = float(abs_bounds_low[0])-offset
miny = float(abs_bounds_low[1])-offset
minz = float(abs_bounds_low[2])
maxx = float(abs_bounds_high[0])+offset
maxy = float(abs_bounds_high[1])+offset
maxz = float(abs_bounds_high[2])
toolpath_settings.set_bounds(minx, maxx, miny, maxy, minz, maxz)
# check if the boundary limits are valid
if (minx > maxx) or (miny > maxy) or (minz > maxz):
if not processing_bounds.is_valid():
# don't generate a toolpath if the area is too small (e.g. due to the tool size)
log.error("Processing boundaries are too small for this tool size.")
return None
toolpath_settings.set_bounds(processing_bounds)
# put the tool settings together
tool_id = self.tool_list.index(tool_settings) + 1
toolpath_settings.set_tool(tool_id, tool_settings["shape"],
......
......@@ -529,18 +529,21 @@ class ToolpathSettings:
self.support_grid = {}
self.process_settings = {}
def set_bounds(self, minx, maxx, miny, maxy, minz, maxz):
def set_bounds(self, bounds):
low, high = bounds.get_absolute_limits()
self.bounds = {
"minx": minx,
"maxx": maxx,
"miny": miny,
"maxy": maxy,
"minz": minz,
"maxz": maxz,
"minx": low[0],
"maxx": high[0],
"miny": low[1],
"maxy": high[1],
"minz": low[2],
"maxz": high[2],
}
def get_bounds(self):
return self.bounds
low = (self.bounds["minx"], self.bounds["miny"], self.bounds["minz"])
high = (self.bounds["maxx"], self.bounds["maxy"], self.bounds["maxz"])
return Bounds(Bounds.TYPE_CUSTOM, low, high)
def set_tool(self, index, shape, tool_radius, torus_radius=None, speed=0.0, feedrate=0.0):
self.tool_settings = {"id": index,
......
......@@ -2707,7 +2707,7 @@ This operation is not available for engraving.</property>
<child>
<object class="GtkLabel" id="max label">
<property name="visible">True</property>
<property name="label" translatable="yes">max</property>
<property name="label" translatable="yes">upper</property>
</object>
<packing>
<property name="left_attach">2</property>
......@@ -2732,7 +2732,7 @@ This operation is not available for engraving.</property>
<child>
<object class="GtkLabel" id="min label">
<property name="visible">True</property>
<property name="label" translatable="yes">min</property>
<property name="label" translatable="yes">lower</property>
</object>
<packing>
<property name="left_attach">1</property>
......
......@@ -37,23 +37,23 @@ def generate_toolpath_from_settings(model, tp_settings, callback=None):
process = tp_settings.get_process_settings()
grid = tp_settings.get_support_grid()
backend = tp_settings.get_calculation_backend()
bounds = []
bounds_dict = tp_settings.get_bounds()
for key in ("minx", "maxx", "miny", "maxy", "minz", "maxz"):
bounds.append(bounds_dict[key])
bounds_obj = tp_settings.get_bounds()
bounds_low, bounds_high = bounds_obj.get_absolute_limits()
return generate_toolpath(model, tp_settings.get_tool_settings(),
bounds, process["path_direction"], process["generator"],
process["postprocessor"], process["material_allowance"],
process["safety_height"], process["overlap"],
process["step_down"], process["engrave_offset"], grid["distance"],
grid["thickness"], grid["height"], backend, callback)
bounds_low, bounds_high, process["path_direction"],
process["generator"], process["postprocessor"],
process["material_allowance"], process["safety_height"],
process["overlap"], process["step_down"], process["engrave_offset"],
grid["distance"], grid["thickness"], grid["height"], backend,
callback)
def generate_toolpath(model, tool_settings=None,
bounds=None, direction="x", path_generator="DropCutter",
path_postprocessor="ZigZagCutter", material_allowance=0.0,
safety_height=None, overlap=0.0, step_down=0.0, engrave_offset=0.0,
support_grid_distance=None, support_grid_thickness=None,
support_grid_height=None, calculation_backend=None, callback=None):
bounds_low=None, bounds_high=None, direction="x",
path_generator="DropCutter", path_postprocessor="ZigZagCutter",
material_allowance=0.0, safety_height=None, overlap=0.0, step_down=0.0,
engrave_offset=0.0, support_grid_distance=None,
support_grid_thickness=None, support_grid_height=None,
calculation_backend=None, callback=None):
""" abstract interface for generating a toolpath
@type model: pycam.Geometry.Model.Model
......@@ -64,9 +64,12 @@ def generate_toolpath(model, tool_settings=None,
"shape": any of possible cutter shape (see "pycam.Cutters")
"tool_radius": main radius of the tools
"torus_radius": (only for ToroidalCutter) second toroidal radius
@type bounds: tuple(float) | list(float)
@value bounds: the processing boundary (relative to the center of the tool)
(order: minx, maxx, miny, maxy, minz, maxz)
@type bounds_low: tuple(float) | list(float)
@value bounds_low: the lower processing boundary (used for the center of
the tool) (order: minx, miny, minz)
@type bounds_high: tuple(float) | list(float)
@value bounds_high: the lower processing boundary (used for the center of
the tool) (order: maxx, maxy, maxz)
@type direction: str
@value direction: any member of the DIRECTIONS set (e.g. "x", "y" or "xy")
@type path_generator: str
......@@ -94,13 +97,16 @@ def generate_toolpath(model, tool_settings=None,
@return: the resulting toolpath object or an error string in case of invalid
arguments
"""
if bounds is None:
if bounds_low is None:
# no bounds were given - we use the boundaries of the model
minx, maxx = model.minx, model.maxx
miny, maxy = model.miny, model.maxy
minz, maxz = model.minz, model.maxz
minx, miny, minz = (model.minx, model.miny, model.minz)
else:
minx, maxx, miny, maxy, minz, maxz = bounds
minx, miny, minz = bounds_low
if bounds_high is None:
# no bounds were given - we use the boundaries of the model
maxx, maxy, maxz = (model.maxx, model.maxy, model.maxz)
else:
maxx, maxy, maxz = bounds_high
# trimesh model or contour model?
if isinstance(model, pycam.Geometry.Model.Model):
# trimesh model
......
......@@ -120,7 +120,8 @@ class Bounds:
TYPE_FIXED_MARGIN = 1
TYPE_CUSTOM = 2
def __init__(self, bounds_type=None, bounds_low=None, bounds_high=None):
def __init__(self, bounds_type=None, bounds_low=None, bounds_high=None,
reference=None):
""" create a new Bounds instance
@value bounds_type: any of TYPE_RELATIVE_MARGIN | TYPE_FIXED_MARGIN | TYPE_CUSTOM
......@@ -132,6 +133,8 @@ class Bounds:
@type bounds_low: (tuple|list) of float
@value bounds_high: see 'bounds_low'
@type bounds_high: (tuple|list) of float
@value reference: optional default reference Bounds instance
@type reference: Bounds
"""
self.name = "No name"
# set type
......@@ -145,6 +148,14 @@ class Bounds:
if bounds_high is None:
bounds_high = [0, 0, 0]
self.set_bounds(bounds_low, bounds_high)
self.reference = reference
def is_valid(self):
for index in range(3):
if self.bounds_low[index] > self.bounds_high[index]:
return False
else:
return True
def set_name(self, name):
self.name = name
......@@ -193,6 +204,9 @@ class Bounds:
@returns: a tuple of two lists containg the low and high limits
@rvalue: tuple(list)
"""
# use the default reference if none was given
if reference is None:
reference = self.reference
# check if a reference is given (if necessary)
if self.bounds_type \
in (Bounds.TYPE_RELATIVE_MARGIN, Bounds.TYPE_FIXED_MARGIN):
......@@ -241,6 +255,9 @@ class Bounds:
value. This argument is ignored for the boundary type "TYPE_CUSTOM".
@type reference: (tuple|list) of float
"""
# use the default reference if none was given
if reference is None:
reference = self.reference
# check if a reference is given (if necessary)
if self.bounds_type \
in (Bounds.TYPE_RELATIVE_MARGIN, Bounds.TYPE_FIXED_MARGIN):
......
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