Commit 5c7af0cf authored by sumpfralle's avatar sumpfralle

fixed the "non-zero" detection for models

merged the "get_flat_projection" function for multi-layered 2D models


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1064 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent f482d64d
...@@ -80,9 +80,13 @@ class BaseModel(TransformableContainer): ...@@ -80,9 +80,13 @@ class BaseModel(TransformableContainer):
result = 0 result = 0
for item_group in self._item_groups: for item_group in self._item_groups:
for item in item_group: for item in item_group:
result += 1
if hasattr(item, "get_children_count"): if hasattr(item, "get_children_count"):
result += item.get_children_count() result += item.get_children_count()
else:
try:
result += len(item)
except TypeError:
result += 1
return result return result
def to_OpenGL(self, visible_filter=None, show_directions=False): def to_OpenGL(self, visible_filter=None, show_directions=False):
...@@ -203,6 +207,12 @@ class Model(BaseModel): ...@@ -203,6 +207,12 @@ class Model(BaseModel):
self.__flat_groups_cache = {} self.__flat_groups_cache = {}
self.__uuid = None self.__uuid = None
def __len__(self):
""" Return the number of available items in the model.
This is mainly useful for evaluating an empty model as False.
"""
return len(self._triangles)
@property @property
def uuid(self): def uuid(self):
if (self.__uuid is None) or self._dirty: if (self.__uuid is None) or self._dirty:
...@@ -318,6 +328,12 @@ class ContourModel(BaseModel): ...@@ -318,6 +328,12 @@ class ContourModel(BaseModel):
self._export_function = \ self._export_function = \
pycam.Exporters.SVGExporter.SVGExporterContourModel pycam.Exporters.SVGExporter.SVGExporterContourModel
def __len__(self):
""" Return the number of available items in the model.
This is mainly useful for evaluating an empty model as False.
"""
return len(self._line_groups)
def reset_cache(self): def reset_cache(self):
super(ContourModel, self).reset_cache() super(ContourModel, self).reset_cache()
# reset the offset model cache # reset the offset model cache
...@@ -721,6 +737,14 @@ class ContourModel(BaseModel): ...@@ -721,6 +737,14 @@ class ContourModel(BaseModel):
model += new_model model += new_model
return model return model
def get_flat_projection(self, plane):
result = ContourModel(plane)
for polygon in self.get_polygons():
new_polygon = polygon.get_plane_projection(plane)
if new_polygon:
result.append(new_polygon)
return result or None
class PolygonGroup(object): class PolygonGroup(object):
""" A PolygonGroup consists of one outer and maybe multiple inner polygons. """ A PolygonGroup consists of one outer and maybe multiple inner 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