Commit f7a52e52 authored by sumpfralle's avatar sumpfralle

merged forgotten parts of r1053 (detection of empty models)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1121 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 2b1bf811
...@@ -174,7 +174,7 @@ def load_model_file(filename, program_locations, unit=None): ...@@ -174,7 +174,7 @@ def load_model_file(filename, program_locations, unit=None):
return None return None
importer = pycam.Importers.detect_file_type(uri)[1] importer = pycam.Importers.detect_file_type(uri)[1]
model = importer(uri, program_locations=program_locations, unit=unit) model = importer(uri, program_locations=program_locations, unit=unit)
if model is None: if not model:
log.warn("Failed to load the model file (%s)." % uri) log.warn("Failed to load the model file (%s)." % uri)
return None return None
else: else:
...@@ -355,7 +355,7 @@ There is NO WARRANTY, to the extent permitted by law.''' % VERSION ...@@ -355,7 +355,7 @@ There is NO WARRANTY, to the extent permitted by law.''' % VERSION
else: else:
model = load_model_file(inputfile, model = load_model_file(inputfile,
program_locations=program_locations, unit=opts.unit_size) program_locations=program_locations, unit=opts.unit_size)
if model is None: if not model:
# something went wrong - we quit # something went wrong - we quit
return EXIT_CODES["load_model_failed"] return EXIT_CODES["load_model_failed"]
# calculate the processing boundary # calculate the processing boundary
......
...@@ -27,7 +27,7 @@ from pycam.Geometry.Triangle import Triangle ...@@ -27,7 +27,7 @@ from pycam.Geometry.Triangle import Triangle
from pycam.Geometry.Line import Line from pycam.Geometry.Line import Line
from pycam.Geometry.Plane import Plane from pycam.Geometry.Plane import Plane
from pycam.Geometry.Polygon import Polygon from pycam.Geometry.Polygon import Polygon
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.TriangleKdtree import TriangleKdtree from pycam.Geometry.TriangleKdtree import TriangleKdtree
from pycam.Geometry.Matrix import TRANSFORMATIONS from pycam.Geometry.Matrix import TRANSFORMATIONS
from pycam.Toolpath import Bounds from pycam.Toolpath import Bounds
...@@ -97,6 +97,12 @@ class BaseModel(TransformableContainer): ...@@ -97,6 +97,12 @@ class BaseModel(TransformableContainer):
result.append(item) result.append(item)
return result return result
def __len__(self):
""" Return the number of available items in the model.
This is mainly useful for evaluating an empty model as False.
"""
return sum([len(igroup) for igroup in self._item_groups])
def next(self): def next(self):
for item_group in self._item_groups: for item_group in self._item_groups:
for item in item_group: for item in item_group:
...@@ -1183,8 +1189,9 @@ class Rectangle(TransformableContainer): ...@@ -1183,8 +1189,9 @@ class Rectangle(TransformableContainer):
corners = [] corners = []
for rectangle, vertices in ((r1, shared_vertices), for rectangle, vertices in ((r1, shared_vertices),
(r2, shared_vertices2)): (r2, shared_vertices2)):
i1 = rectangle.get_points().index(vertices[0]) # turn the tuple into a list (".index" was introduced in Python 2.6)
i2 = rectangle.get_points().index(vertices[1]) i1 = list(rectangle.get_points()).index(vertices[0])
i2 = list(rectangle.get_points()).index(vertices[1])
if i1 + i2 % 2 == 0: if i1 + i2 % 2 == 0:
# shared vertices are at opposite corners # shared vertices are at opposite corners
return None return None
......
...@@ -282,7 +282,7 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs): ...@@ -282,7 +282,7 @@ def ImportModel(filename, use_kdtree=True, callback=None, **kwargs):
edges = 0 edges = 0
kdtree = None kdtree = None
if model.minx is None: if not model:
# no valid items added to the model # no valid items added to the model
return None return None
else: else:
......
...@@ -134,12 +134,12 @@ def generate_toolpath(model, tool_settings=None, ...@@ -134,12 +134,12 @@ def generate_toolpath(model, tool_settings=None,
trimesh_models.append(support_model) trimesh_models.append(support_model)
# Adapt the contour_model to the engraving offset. This offset is # Adapt the contour_model to the engraving offset. This offset is
# considered to be part of the material_allowance. # considered to be part of the material_allowance.
if (not contour_model is None) and (engrave_offset != 0): if contour_model and (engrave_offset != 0):
if not callback is None: if not callback is 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,
callback=callback) callback=callback)
if contour_model is None: if contour_model:
return "Failed to calculate offset polygons" return "Failed to calculate offset polygons"
if not callback is None: if not callback is None:
# reset percentage counter after the contour model calculation # reset percentage counter after the contour model calculation
...@@ -165,7 +165,7 @@ def generate_toolpath(model, tool_settings=None, ...@@ -165,7 +165,7 @@ def generate_toolpath(model, tool_settings=None,
# no collisions and no user interruption # no collisions and no user interruption
pass pass
# check the pocketing type # check the pocketing type
if (not contour_model is None) and (pocketing_type != "none"): if contour_model and (pocketing_type != "none"):
if not callback is None: if not callback is None:
callback(text="Generating pocketing polygons ...") callback(text="Generating pocketing polygons ...")
pocketing_offset = cutter.radius * 1.8 pocketing_offset = cutter.radius * 1.8
...@@ -227,7 +227,7 @@ def generate_toolpath(model, tool_settings=None, ...@@ -227,7 +227,7 @@ def generate_toolpath(model, tool_settings=None,
# use minz/maxz of the contour model (in other words: ignore z) # use minz/maxz of the contour model (in other words: ignore z)
contour_model = contour_model.get_cropped_model(minx, maxx, miny, maxy, contour_model = contour_model.get_cropped_model(minx, maxx, miny, maxy,
contour_model.minz, contour_model.maxz) contour_model.minz, contour_model.maxz)
if contour_model is None: if contour_model:
return "No part of the contour model is within the bounding box." return "No part of the contour model is within the bounding box."
physics = _get_physics(trimesh_models, cutter, calculation_backend) physics = _get_physics(trimesh_models, cutter, calculation_backend)
if isinstance(physics, basestring): if isinstance(physics, basestring):
......
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