Commit 0bf77da9 authored by sumpfralle's avatar sumpfralle

implemented automatically distributed support grids for solid 3D models

reduced output of log messages in status bar


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@758 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ca80568b
......@@ -180,7 +180,7 @@ class Model(BaseModel):
self._item_groups.append(self._triangles)
self._export_function = pycam.Exporters.STLExporter.STLExporter
# marker for state of kdtree and uuid
self._dirty = False
self._dirty = True
# enable/disable kdtree
self._use_kdtree = use_kdtree
self._t_kdtree = None
......@@ -226,7 +226,7 @@ class Model(BaseModel):
def get_waterline_polygons(self, plane):
collision_lines = []
for t in self._triangles:
collision_line = plane.intersect_triangle(t)
collision_line = plane.intersect_triangle(t, counter_clockwise=True)
if not collision_line is None:
collision_lines.append(collision_line)
# combine these lines into polygons
......@@ -238,22 +238,6 @@ class Model(BaseModel):
[len(p.get_lines()) for p in contour.get_polygons()]))
return contour.get_polygons()
def to_OpenGL_waterline(self, num_of_levels=8):
""" Visualize the waterline of the model for various z-levels.
This is only used for debugging.
"""
#super(Model, self).to_OpenGL()
z_diff = (self.maxz - self.minz) / (num_of_levels - 1)
z_levels = [self.minz + z_diff * i for i in range(num_of_levels)]
projection_plane = Plane(Point(0, 0, 0), Vector(0, 0, 1))
contour = ContourModel(projection_plane.n)
for z_level in z_levels:
waterline_plane = Plane(Point(0, 0, z_level), Vector(0, 0, 1))
for polygon in self.get_waterline_polygons(waterline_plane):
projected_polygon = polygon.get_plane_projection(projection_plane)
contour.append(projected_polygon, unify_overlaps=True)
contour.to_OpenGL()
class ContourModel(BaseModel):
......
......@@ -74,7 +74,7 @@ class Plane(TransformableContainer):
cp = point.add(direction.mul(l))
return (cp, l)
def intersect_triangle(self, triangle):
def intersect_triangle(self, triangle, counter_clockwise=False):
""" Returns the line of intersection of a triangle with a plane.
"None" is returned, if:
- the triangle does not intersect with the plane
......@@ -109,7 +109,7 @@ class Plane(TransformableContainer):
if collision_line.len == 0:
return collision_line
cross = self.n.cross(collision_line.dir)
if cross.dot(triangle.normal) < 0:
if (cross.dot(triangle.normal) < 0) == bool(not counter_clockwise):
# anti-clockwise direction -> revert the direction of the line
collision_line = Line(collision_line.p2, collision_line.p1)
return collision_line
......
......@@ -857,16 +857,6 @@ class ProjectGui:
"GridManualShiftExpander": ("grid", ),
"GridAverageDistanceExpander": ("automatic", ),
}
if (self.settings.get("support_grid_type") == GRID_TYPES["automatic"]) \
and (not hasattr(self.model, "get_polygons")):
message = "This feature only works for 2D contour models for now " \
+ "- sorry!"
window = gtk.MessageDialog(self.window, type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_OK, message_format=message)
window.set_title("Under construction ...")
window.run()
window.destroy()
self.settings.set("support_grid_type", GRID_TYPES["none"])
grid_type = self.settings.get("support_grid_type")
if grid_type == GRID_TYPES["grid"]:
grid_square = self.gui.get_object("SupportGridDistanceSquare")
......@@ -1397,7 +1387,10 @@ class ProjectGui:
return True
def add_log_message(self, title, message, record=None):
timestamp = datetime.datetime.fromtimestamp(record.created).strftime("%H:%M")
timestamp = datetime.datetime.fromtimestamp(
record.created).strftime("%H:%M")
# use only the first line (linebreak don't look pretty there)
message = message.split(os.linesep, 1)[0]
try:
message = message.encode("utf-8")
except UnicodeDecodeError:
......
......@@ -23,6 +23,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.Line import Line
from pycam.Geometry.Triangle import Triangle
from pycam.Geometry.Plane import Plane
from pycam.Geometry.Model import Model
from pycam.Geometry.utils import number
......@@ -156,13 +157,17 @@ def get_support_distributed(model, z_plane, average_distance,
if p.sub(point).norm <= distance:
return True
return False
if (average_distance == 0) or (length == 0) or (thickness == 0) \
or (height == 0):
return
result = Model()
if hasattr(model, "get_polygons"):
polygons = model.get_polygons()
else:
# TODO: Solid models are not supported, yet - we need to get the
# maximum outline of the model.
return result
polygons = model.get_waterline_polygons(Plane(Point(0, 0, z_plane),
Vector(0, 0, 1)))
bridge_positions = []
# minimum required distance between two bridge start points
avoid_distance = 1.5 * (abs(length) + thickness)
......
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