Commit f113e154 authored by sumpfralle's avatar sumpfralle

fixed code-style issues


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@494 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 14f3e6ea
...@@ -45,7 +45,6 @@ def generate_physics(model, cutter, physics=None): ...@@ -45,7 +45,6 @@ def generate_physics(model, cutter, physics=None):
return physics return physics
def is_ode_available(): def is_ode_available():
global _ode_override_state
if not _ode_override_state is None: if not _ode_override_state is None:
return _ode_override_state return _ode_override_state
else: else:
......
...@@ -25,11 +25,12 @@ import pycam.PathProcessors ...@@ -25,11 +25,12 @@ import pycam.PathProcessors
import pycam.Cutters import pycam.Cutters
import pycam.Toolpath.SupportGrid import pycam.Toolpath.SupportGrid
import pycam.Geometry.Model import pycam.Geometry.Model
import sys
DIRECTIONS = frozenset(("x", "y", "xy")) DIRECTIONS = frozenset(("x", "y", "xy"))
PATH_GENERATORS = frozenset(("DropCutter", "PushCutter", "EngraveCutter")) PATH_GENERATORS = frozenset(("DropCutter", "PushCutter", "EngraveCutter"))
PATH_POSTPROCESSORS = frozenset(("ContourCutter", "PathAccumulator", "PolygonCutter", "SimpleCutter", "ZigZagCutter")) PATH_POSTPROCESSORS = frozenset(("ContourCutter", "PathAccumulator",
"PolygonCutter", "SimpleCutter", "ZigZagCutter"))
CALCULATION_BACKENDS = frozenset((None, "ODE")) CALCULATION_BACKENDS = frozenset((None, "ODE"))
...@@ -44,7 +45,8 @@ def generate_toolpath_from_settings(model, tp_settings, callback=None): ...@@ -44,7 +45,8 @@ def generate_toolpath_from_settings(model, tp_settings, callback=None):
process["generator"], process["postprocessor"], process["generator"], process["postprocessor"],
process["material_allowance"], process["safety_height"], process["material_allowance"], process["safety_height"],
process["overlap"], process["step_down"], process["engrave_offset"], process["overlap"], process["step_down"], process["engrave_offset"],
grid["distance"], grid["thickness"], grid["height"], backend, grid["distance_x"], grid["distance_y"], grid["thickness"],
grid["height"], grid["offset_x"], grid["offset_y"], backend,
callback) callback)
def generate_toolpath(model, tool_settings=None, def generate_toolpath(model, tool_settings=None,
...@@ -128,7 +130,7 @@ def generate_toolpath(model, tool_settings=None, ...@@ -128,7 +130,7 @@ def generate_toolpath(model, tool_settings=None,
# create the grid model if requested # create the grid model if requested
if (((not support_grid_distance_x is None) \ if (((not support_grid_distance_x is None) \
or (not support_grid_distance_y is None)) \ or (not support_grid_distance_y is None)) \
and (support_grid_thickness is None)): and (not support_grid_thickness is None)):
# grid height defaults to the thickness # grid height defaults to the thickness
if support_grid_height is None: if support_grid_height is None:
support_grid_height = support_grid_thickness support_grid_height = support_grid_thickness
...@@ -156,13 +158,14 @@ def generate_toolpath(model, tool_settings=None, ...@@ -156,13 +158,14 @@ def generate_toolpath(model, tool_settings=None,
callback(text="Preparing contour model with offset ...") callback(text="Preparing contour model with offset ...")
contour_model = contour_model.get_offset_model(engrave_offset) contour_model = contour_model.get_offset_model(engrave_offset)
if not callback is None: if not callback is None:
callback(text="Checking contour model with offset for collisions ...") callback(text="Checking contour model with offset for collisions " \
+ "...")
if contour_model.check_for_collisions(): if contour_model.check_for_collisions():
return "The contour model contains colliding line groups." \ return "The contour model contains colliding line groups." \
+ " This is not allowed in combination with an" \ + " This is not allowed in combination with an" \
+ " engraving offset." + " engraving offset."
# Due to some weirdness the height of the drill must be bigger than the object's size. # Due to some weirdness the height of the drill must be bigger than the
# Otherwise some collisions are not detected. # object's size. Otherwise some collisions are not detected.
cutter_height = 4 * (maxy - miny) cutter_height = 4 * (maxy - miny)
cutter = pycam.Cutters.get_tool_from_settings(tool_settings, cutter_height) cutter = pycam.Cutters.get_tool_from_settings(tool_settings, cutter_height)
if isinstance(cutter, basestring): if isinstance(cutter, basestring):
...@@ -172,12 +175,12 @@ def generate_toolpath(model, tool_settings=None, ...@@ -172,12 +175,12 @@ def generate_toolpath(model, tool_settings=None,
if isinstance(physics, basestring): if isinstance(physics, basestring):
return physics return physics
generator = _get_pathgenerator_instance(trimesh_model, contour_model, generator = _get_pathgenerator_instance(trimesh_model, contour_model,
cutter, path_generator, path_postprocessor, material_allowance, cutter, path_generator, path_postprocessor, safety_height, physics)
safety_height, physics)
if isinstance(generator, basestring): if isinstance(generator, basestring):
return generator return generator
if (overlap < 0) or (overlap >= 1): if (overlap < 0) or (overlap >= 1):
return "Invalid overlap value (%f): should be greater or equal 0 and lower than 1" return "Invalid overlap value (%f): should be greater or equal 0 " \
+ "and lower than 1"
effective_toolradius = tool_settings["tool_radius"] * (1.0 - overlap) effective_toolradius = tool_settings["tool_radius"] * (1.0 - overlap)
if path_generator == "DropCutter": if path_generator == "DropCutter":
if direction == "x": if direction == "x":
...@@ -185,11 +188,15 @@ def generate_toolpath(model, tool_settings=None, ...@@ -185,11 +188,15 @@ def generate_toolpath(model, tool_settings=None,
elif direction == "y": elif direction == "y":
direction_param = 1 direction_param = 1
else: else:
return "Invalid direction value (%s): not one of %s" % (direction, DIRECTIONS) return "Invalid direction value (%s): not one of %s" \
% (direction, DIRECTIONS)
if safety_height < maxz: if safety_height < maxz:
return "Safety height (%.4f) is within the bounding box height (%.4f) - this can cause collisions of the tool with the material." % (safety_height, maxz) return ("Safety height (%.4f) is within the bounding box height " \
toolpath = generator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, + "(%.4f) - this can cause collisions of the tool with " \
effective_toolradius, effective_toolradius, direction_param, callback) + "the material.") % (safety_height, maxz)
toolpath = generator.GenerateToolPath(minx, maxx, miny, maxy, minz,
maxz, effective_toolradius, effective_toolradius,
direction_param, callback)
elif path_generator == "PushCutter": elif path_generator == "PushCutter":
if step_down > 0: if step_down > 0:
dz = step_down dz = step_down
...@@ -202,28 +209,33 @@ def generate_toolpath(model, tool_settings=None, ...@@ -202,28 +209,33 @@ def generate_toolpath(model, tool_settings=None,
elif direction == "xy": elif direction == "xy":
dx, dy = effective_toolradius, effective_toolradius dx, dy = effective_toolradius, effective_toolradius
else: else:
return "Invalid direction (%s): not one of %s" % (direction, DIRECTIONS) return "Invalid direction (%s): not one of %s" \
toolpath = generator.GenerateToolPath(minx, maxx, miny, maxy, minz, maxz, dx, dy, dz, callback) % (direction, DIRECTIONS)
toolpath = generator.GenerateToolPath(minx, maxx, miny, maxy, minz,
maxz, dx, dy, dz, callback)
else: else:
# EngraveCutter # EngraveCutter
if step_down > 0: if step_down > 0:
dz = step_down dz = step_down
else: else:
dz = maxz - minz dz = maxz - minz
toolpath = generator.GenerateToolPath(minz, maxz, effective_toolradius, dz, callback) toolpath = generator.GenerateToolPath(minz, maxz, effective_toolradius,
dz, callback)
return toolpath return toolpath
def _get_pathgenerator_instance(trimesh_model, contour_model, cutter, pathgenerator, pathprocessor, def _get_pathgenerator_instance(trimesh_model, contour_model, cutter,
material_allowance, safety_height, physics): pathgenerator, pathprocessor, safety_height, physics):
if pathgenerator == "DropCutter": if pathgenerator == "DropCutter":
if pathprocessor == "ZigZagCutter": if pathprocessor == "ZigZagCutter":
processor = pycam.PathProcessors.PathAccumulator(zigzag=True) processor = pycam.PathProcessors.PathAccumulator(zigzag=True)
elif pathprocessor == "PathAccumulator": elif pathprocessor == "PathAccumulator":
processor = pycam.PathProcessors.PathAccumulator() processor = pycam.PathProcessors.PathAccumulator()
else: else:
return "Invalid postprocessor (%s) for 'DropCutter': only 'ZigZagCutter' or 'PathAccumulator' are allowed" % str(pathprocessor) return ("Invalid postprocessor (%s) for 'DropCutter': only " \
return DropCutter.DropCutter(cutter, trimesh_model, processor, physics=physics, + "'ZigZagCutter' or 'PathAccumulator' are allowed") \
safety_height=safety_height) % str(pathprocessor)
return DropCutter.DropCutter(cutter, trimesh_model, processor,
physics=physics, safety_height=safety_height)
elif pathgenerator == "PushCutter": elif pathgenerator == "PushCutter":
if pathprocessor == "PathAccumulator": if pathprocessor == "PathAccumulator":
processor = pycam.PathProcessors.PathAccumulator() processor = pycam.PathProcessors.PathAccumulator()
...@@ -236,27 +248,34 @@ def _get_pathgenerator_instance(trimesh_model, contour_model, cutter, pathgenera ...@@ -236,27 +248,34 @@ def _get_pathgenerator_instance(trimesh_model, contour_model, cutter, pathgenera
elif pathprocessor == "ContourCutter": elif pathprocessor == "ContourCutter":
processor = pycam.PathProcessors.ContourCutter() processor = pycam.PathProcessors.ContourCutter()
else: else:
return "Invalid postprocessor (%s) for 'PushCutter' - it should be one of these: %s" % (processor, PATH_POSTPROCESSORS) return ("Invalid postprocessor (%s) for 'PushCutter' - it should " \
return PushCutter.PushCutter(cutter, trimesh_model, processor, physics=physics) + "be one of these: %s") % (processor, PATH_POSTPROCESSORS)
return PushCutter.PushCutter(cutter, trimesh_model, processor,
physics=physics)
elif pathgenerator == "EngraveCutter": elif pathgenerator == "EngraveCutter":
if pathprocessor == "SimpleCutter": if pathprocessor == "SimpleCutter":
processor = pycam.PathProcessors.SimpleCutter() processor = pycam.PathProcessors.SimpleCutter()
else: else:
return "Invalid postprocessor (%s) for 'EngraveCutter' - it should be one of these: %s" % (processor, PATH_POSTPROCESSORS) return ("Invalid postprocessor (%s) for 'EngraveCutter' - it " \
+ "should be one of these: %s") \
% (processor, PATH_POSTPROCESSORS)
if not contour_model: if not contour_model:
return "The EngraveCutter requires a contour model (e.g. from a DXF file)." return "The EngraveCutter requires a contour model (e.g. from a " \
+ "DXF file)."
return EngraveCutter.EngraveCutter(cutter, trimesh_model, return EngraveCutter.EngraveCutter(cutter, trimesh_model,
contour_model, processor, physics=physics) contour_model, processor, physics=physics)
else: else:
return "Invalid path generator (%s): not one of %s" % (pathgenerator, PATH_GENERATORS) return "Invalid path generator (%s): not one of %s" \
% (pathgenerator, PATH_GENERATORS)
def _get_physics(trimesh_model, cutter, calculation_backend): def _get_physics(trimesh_model, cutter, calculation_backend):
if calculation_backend is None: if calculation_backend is None:
# triangular collision detection does not need any physical model # triangular collision detection does not need any physical model
return None return None
elif calculation_backend == "ODE": elif calculation_backend == "ODE":
import pycam.Physics.ode_physics import pycam.Physics.ode_physics as ode_physics
return pycam.Physics.ode_physics.generate_physics(trimesh_model, cutter) return ode_physics.generate_physics(trimesh_model, cutter)
else: else:
return "Invalid calculation backend (%s): not one of %s" % (calculation_backend, CALCULATION_BACKENDS) return "Invalid calculation backend (%s): not one of %s" \
% (calculation_backend, CALCULATION_BACKENDS)
...@@ -21,7 +21,6 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -21,7 +21,6 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry import Point, Line, Triangle, Model from pycam.Geometry import Point, Line, Triangle, Model
import math
def _add_cuboid_to_model(minx, maxx, miny, maxy, minz, maxz): def _add_cuboid_to_model(minx, maxx, miny, maxy, minz, maxz):
...@@ -42,17 +41,23 @@ def _add_cuboid_to_model(minx, maxx, miny, maxy, minz, maxz): ...@@ -42,17 +41,23 @@ def _add_cuboid_to_model(minx, maxx, miny, maxy, minz, maxz):
Point(minx, maxy, maxz)) Point(minx, maxy, maxz))
triangles = [] triangles = []
# lower face # lower face
triangles.extend(get_triangles_for_face((points[0], points[1], points[2], points[3]))) triangles.extend(get_triangles_for_face(
(points[0], points[1], points[2], points[3])))
# upper face # upper face
triangles.extend(get_triangles_for_face((points[4], points[5], points[6], points[7]))) triangles.extend(get_triangles_for_face(
(points[4], points[5], points[6], points[7])))
# front face # front face
triangles.extend(get_triangles_for_face((points[0], points[1], points[5], points[4]))) triangles.extend(get_triangles_for_face(
(points[0], points[1], points[5], points[4])))
# back face # back face
triangles.extend(get_triangles_for_face((points[2], points[3], points[7], points[6]))) triangles.extend(get_triangles_for_face(
(points[2], points[3], points[7], points[6])))
# right face # right face
triangles.extend(get_triangles_for_face((points[1], points[2], points[6], points[5]))) triangles.extend(get_triangles_for_face(
(points[1], points[2], points[6], points[5])))
# left face # left face
triangles.extend(get_triangles_for_face((points[3], points[0], points[4], points[7]))) triangles.extend(get_triangles_for_face(
(points[3], points[0], points[4], points[7])))
# add all triangles to the model # add all triangles to the model
model = Model.Model() model = Model.Model()
for t in triangles: for t in triangles:
......
...@@ -51,7 +51,8 @@ class ToolPath: ...@@ -51,7 +51,8 @@ class ToolPath:
return self.toolpath return self.toolpath
def get_start_position(self): def get_start_position(self):
safety_height = self.toolpath_settings.get_process_settings()["safety_height"] safety_height = \
self.toolpath_settings.get_process_settings()["safety_height"]
for path in self.toolpath: for path in self.toolpath:
if path.points: if path.points:
p = path.points[0] p = path.points[0]
...@@ -92,16 +93,18 @@ class ToolPath: ...@@ -92,16 +93,18 @@ class ToolPath:
@rtype: float @rtype: float
@returns: the machine time used for processing the toolpath in minutes @returns: the machine time used for processing the toolpath in minutes
""" """
settings = self.toolpath_settings
if start_position is None: if start_position is None:
start_position = Point(0, 0, 0) start_position = Point(0, 0, 0)
feedrate = self.toolpath_settings.get_tool_settings()["feedrate"] feedrate = settings.get_tool_settings()["feedrate"]
current_position = start_position
result_time = 0
def move(new_pos): def move(new_pos):
move.result_time += new_pos.sub(move.current_position).norm() / feedrate global current_position, result_time
move.current_position = new_pos result_time += new_pos.sub(current_position).norm() / feedrate
move.current_position = start_position current_position = new_pos
move.result_time = 0
# move to safey height at the starting position # move to safey height at the starting position
safety_height = self.toolpath_settings.get_process_settings()["safety_height"] safety_height = settings.get_process_settings()["safety_height"]
move(Point(start_position.x, start_position.y, safety_height)) move(Point(start_position.x, start_position.y, safety_height))
for path in self.get_path(): for path in self.get_path():
# go to safety height (horizontally from the previous x/y location) # go to safety height (horizontally from the previous x/y location)
...@@ -113,7 +116,7 @@ class ToolPath: ...@@ -113,7 +116,7 @@ class ToolPath:
# go to safety height (vertically up from the current x/y location) # go to safety height (vertically up from the current x/y location)
if len(path.points) > 0: if len(path.points) > 0:
move(Point(path.points[-1].x, path.points[-1].y, safety_height)) move(Point(path.points[-1].x, path.points[-1].y, safety_height))
return move.result_time return result_time
class Bounds: class Bounds:
...@@ -126,7 +129,8 @@ class Bounds: ...@@ -126,7 +129,8 @@ class Bounds:
reference=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
@type bounds_type: int @type bounds_type: int
@value bounds_low: the lower margin of the boundary compared to the @value bounds_low: the lower margin of the boundary compared to the
reference object (for TYPE_RELATIVE_MARGIN | TYPE_FIXED_MARGIN) or reference object (for TYPE_RELATIVE_MARGIN | TYPE_FIXED_MARGIN) or
...@@ -140,11 +144,14 @@ class Bounds: ...@@ -140,11 +144,14 @@ class Bounds:
""" """
self.name = "No name" self.name = "No name"
# set type # set type
self.bounds_type = None
if bounds_type is None: if bounds_type is None:
self.set_type(Bounds.TYPE_CUSTOM) self.set_type(Bounds.TYPE_CUSTOM)
else: else:
self.set_type(bounds_type) self.set_type(bounds_type)
# store the bounds values # store the bounds values
self.bounds_low = None
self.bounds_high = None
if bounds_low is None: if bounds_low is None:
bounds_low = [0, 0, 0] bounds_low = [0, 0, 0]
if bounds_high is None: if bounds_high is None:
...@@ -194,7 +201,8 @@ class Bounds: ...@@ -194,7 +201,8 @@ class Bounds:
if not high is None: if not high is None:
if len(high) != 3: if len(high) != 3:
raise ValueError, "upper bounds should be supplied as a " \ raise ValueError, "upper bounds should be supplied as a " \
+ "tuple/list of 3 items - but %d were given" % len(high) + "tuple/list of 3 items - but %d were given" \
% len(high)
else: else:
self.bounds_high = list(high[:]) self.bounds_high = list(high[:])
......
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