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