Commit 6f20d950 authored by sumpfralle's avatar sumpfralle

r677@erker: lars | 2010-02-17 13:33:30 +0100

 ODE can be enabled via GUI and is detected automatically
 fixed closing of "save file" dialog via ESC


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@135 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent c213eda5
......@@ -11,7 +11,6 @@ import pycam.Gui.common as GuiCommon
import pycam.Cutters
import pycam.PathGenerators
import pycam.PathProcessors
import pycam.Gui.ode_objects as ode_objects
import pycam.Geometry.utils as utils
import pycam.Gui.OpenGLTools as ogl_tools
import threading
......@@ -324,16 +323,24 @@ class ProjectGui:
self.settings.add_item("tool_radius", obj.get_value, obj.set_value)
obj = self.gui.get_object("TorusRadiusControl")
self.settings.add_item("torus_radius", obj.get_value, obj.set_value)
# visual settings
# visual and general settings
self.gui.get_object("Toggle3dView").connect("toggled", self.toggle_3d_view)
for name, objname in (("show_model", "ShowModelCheckBox"),
("show_axes", "ShowAxesCheckBox"),
("show_bounding_box", "ShowBoundingCheckBox"),
("show_toolpath", "ShowToolPathCheckBox"),
("show_drill_progress", "ShowDrillProgressCheckBox")):
("show_drill_progress", "ShowDrillProgressCheckBox"),
("enable_ode", "SettingEnableODE")):
obj = self.gui.get_object(objname)
self.settings.add_item(name, obj.get_active, obj.set_active)
obj.connect("toggled", self.update_view)
# set the availability of ODE
if GuiCommon.is_ode_available():
self.settings.set("enable_ode", True)
self.gui.get_object("SettingEnableODE").set_sensitive(True)
else:
self.settings.set("enable_ode", False)
self.gui.get_object("SettingEnableODE").set_sensitive(False)
# preconfigure some values
self.settings.set("show_model", True)
self.settings.set("show_toolpath", True)
......@@ -415,7 +422,10 @@ class ProjectGui:
self.view3d.paint()
def update_physics(self):
if self.settings.get("enable_ode"):
self.physics = GuiCommon.generate_physics(self.settings, self.cutter, self.physics)
else:
self.physics = None
@gui_activity_guard
def toggle_3d_view(self, widget=None, value=None):
......@@ -749,7 +759,7 @@ class ProjectGui:
response = dialog.run()
filename = dialog.get_filename()
dialog.hide()
if response == gtk.RESPONSE_CANCEL:
if response != gtk.RESPONSE_OK:
dialog.destroy()
return None
if os.path.exists(filename):
......
import OpenGL.GL as GL
import OpenGL.GLUT as GLUT
import ode_objects
# "ode" is imported later, if required
#import ode_objects
MODEL_TRANSFORMATIONS = {
......@@ -185,6 +186,7 @@ def scale_model(model, scale):
model.transform(matrix)
def generate_physics(settings, cutter, physics=None):
import ode_objects
if physics is None:
physics = ode_objects.PhysicalWorld()
physics.reset()
......@@ -198,3 +200,10 @@ def generate_physics(settings, cutter, physics=None):
physics.set_drill(shape_info[0], shape_info[2])
return physics
def is_ode_available():
try:
import ode
return True
except ImportError:
return False
This diff is collapsed.
......@@ -36,6 +36,9 @@ class DropCutter:
self.model = model
self.processor = PathProcessor
self.physics = physics
# used for the non-ode code
self._triangle_last = None
self._cut_last = None
def GenerateToolPath(self, minx, maxx, miny, maxy, z0, z1, d0, d1, direction, draw_callback=None):
if self.processor:
......@@ -64,25 +67,46 @@ class DropCutter:
while dims[1].check_bounds():
dims[0].set(dims[0].start)
pa.new_scanline()
t_last = None
self._triangle_last = None
self._cut_last = None
while dims[0].check_bounds():
p = Point(dims[x].get(), dims[y].get(), dim_height.get())
if self.physics:
points = self.get_max_height_with_ode(dims[x], dims[y], dim_height, order=dim_attrs[:])
else:
points = self.get_max_height_manually(dims[x], dims[y], dim_height, order=dim_attrs[:])
low, high = z0, z1
for next_point in points:
pa.append(next_point)
self.cutter.moveto(next_point)
if draw_callback:
draw_callback()
dims[0].shift(d0)
pa.end_scanline()
dims[1].shift(d1)
pa.end_direction()
pa.finish()
return pa.paths
def get_max_height_with_ode(self, x, y, dim_height, order=None):
low, high = dim_height.end, dim_height.start
trip_start = 20
safe_z = None
# check if the full step-down would be ok
self.physics.set_drill_position((dims[x].get(), dims[y].get(), z0))
self.physics.set_drill_position((x.get(), y.get(), dim_height.end))
if self.physics.check_collision():
# there is an object between z1 and z0 - we need more loops
# there is an object between z1 and z0 - we need more=None loops
trips = trip_start
else:
# no need for further collision detection - we can go down the whole range z1..z0
trips = 0
safe_z = z0
safe_z = dim_height.end
while trips > 0:
current_z = (low + high)/2.0
self.physics.set_drill_position((dims[x].get(), dims[y].get(), current_z))
self.physics.set_drill_position((x.get(), y.get(), current_z))
if self.physics.check_collision():
low = current_z
else:
......@@ -92,25 +116,24 @@ class DropCutter:
#current_z -= dz
if safe_z is None:
# no safe position was found - let's check the upper bound
self.physics.set_drill_position((dims[x].get(), dims[y].get(), z1))
self.physics.set_drill_position((x.get(), y.get(), dim_height.start))
if self.physics.check_collision():
# the object fills the whole range of z0..z1 - we should issue a warning
next_point = Point(dims[x].get(), dims[y].get(), INFINITE)
next_point = Point(x.get(), y.get(), INFINITE)
else:
next_point = Point(dims[x].get(), dims[y].get(), z1)
next_point = Point(x.get(), y.get(), dim_height.start)
else:
next_point = Point(dims[x].get(), dims[y].get(), safe_z)
pa.append(next_point)
self.cutter.moveto(next_point)
if draw_callback:
draw_callback()
"""
next_point = Point(x.get(), y.get(), safe_z)
return [next_point]
def get_max_height_manually(self, x, y, dim_height, order=None):
result = []
if order is None:
order = ["x", "y"]
p = Point(x.get(), y.get(), dim_height.get())
height_max = -INFINITE
cut_max = None
triangle_max = None
cut_last = None
self.cutter.moveto(p)
box_x_min = p.x - self.cutter.radius
box_x_max = p.x + self.cutter.radius
......@@ -127,56 +150,49 @@ class DropCutter:
cut_max = cut
triangle_max = t
if not cut_max or not dim_height.check_bounds(cut_max.z):
cut_max = Point(dims[x].get(), dims[y].get(), dim_height.end)
if cut_last and ((triangle_max and not triangle_last) or (triangle_last and not triangle_max)):
if dim_height.check_bounds(cut_last.z):
pa.append(Point(cut_last.x, cut_last.y, cut_max.z))
cut_max = Point(x.get(), y.get(), dim_height.end)
if self._cut_last and ((triangle_max and not self._triangle_last) or (self._triangle_last and not triangle_max)):
if dim_height.check_bounds(self._cut_last.z):
result.append(Point(self._cut_last.x, self._cut_last.y, cut_max.z))
else:
pa.append(Point(cut_max.x, cut_max.y, cut_last.z))
elif (triangle_max and triangle_last and cut_last and cut_max) and (triangle_max != triangle_last):
result.append(Point(cut_max.x, cut_max.y, self._cut_last.z))
elif (triangle_max and self._triangle_last and self._cut_last and cut_max) and (triangle_max != self._triangle_last):
nl = range(3)
nl[0] = -getattr(triangle_last.normal(), dim_attrs[0])
nl[2] = triangle_last.normal().z
nl[0] = -getattr(self._triangle_last.normal(), order[0])
nl[2] = self._triangle_last.normal().z
nm = range(3)
nm[0] = -getattr(triangle_max.normal(), dim_attrs[0])
nm[0] = -getattr(triangle_max.normal(), order[0])
nm[2] = triangle_max.normal().z
last = range(3)
last[0] = getattr(cut_last, dim_attrs[0])
last[2] = cut_last.z
last[0] = getattr(self._cut_last, order[0])
last[2] = self._cut_last.z
mx = range(3)
mx[0] = getattr(cut_max, dim_attrs[0])
mx[0] = getattr(cut_max, order[0])
mx[2] = cut_max.z
c = range(3)
(c[0], c[2]) = intersect_lines(last[0], last[2], nl[0], nl[2], mx[0], mx[2], nm[0], nm[2])
if c[0] and last[0] < c[0] and c[0] < mx[0] and (c[2] > last[2] or c[2] > mx[2]):
c[1] = getattr(cut_last, dim_attrs[1])
if c[2]<dims[2].min-10 or c[2]>dims[2].max+10:
print "^", "%sl=" % dim_attrs[0], last[0], \
", %sl=" % dim_attrs[2], last[2], \
", n%sl=" % dim_attrs[0], nl[0], \
", n%sl=" %dim_attrs[2], nl[2], \
", %s=" % dim_attrs[0].upper(), c[0], \
", %s=" % dim_attrs[2].upper(), c[2], \
", %sm=" % dim_attrs[0], mx[0], \
", %sm=" % dim_attrs[2], mx[2], \
", n%sm=" % dim_attrs[0], nm[0], \
", n%sm=" % dim_attrs[2], nm[2]
c[1] = getattr(self._cut_last, order[1])
if c[2]<dim_height.end-10 or c[2]>dim_height.start+10:
print "^", "%sl=%s" % (order[0], last[0]), \
", %sl=%s" % ("z", last[2]), \
", n%sl=%s" % (order[0], nl[0]), \
", n%sl=%s" % ("z", nl[2]), \
", %s=%s" % (order[0].upper(), c[0]), \
", %s=%s" % ("z".upper(), c[2]), \
", %sm=%s" % (order[0], mx[0]), \
", %sm=%s" % ("z", mx[2]), \
", n%sm=%s" % (order[0], nm[0]), \
", n%sm=%s" % ("z", nm[2])
else:
pa.append(Point(c[x], c[y], c[2]))
pa.append(cut_max)
cut_last = cut_max
triangle_last = triangle_max
"""
dims[0].shift(d0)
pa.end_scanline()
dims[1].shift(d1)
pa.end_direction()
if order[0] == "x":
result.append(Point(c[0], c[1], c[2]))
else:
result.append(Point(c[1], c[0], c[2]))
result.append(cut_max)
pa.finish()
return pa.paths
self._cut_last = cut_max
self._triangle_last = triangle_max
return result
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