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
......@@ -910,303 +910,6 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="ToolBox">
<property name="no_show_all">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="ToolFileHandling">
<property name="visible">True</property>
<child>
<object class="GtkFrame" id="ToolFileLoadFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkFileChooserButton" id="ToolFileLoad">
<property name="visible">True</property>
<property name="create_folders">False</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="ToolFileLoadLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Load Tool Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator5">
<property name="visible">True</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="ToolFileSaveFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment8">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkButton" id="ToolSaveFileButton">
<property name="label" translatable="yes">To File</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="ToolFileSaveFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Save&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="ToolsList">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tab_pos">left</property>
<property name="scrollable">True</property>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment9">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkComboBox" id="combobox1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame1&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator6">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment10">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame2&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator5">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame3">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment11">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame3&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator4">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame4">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment12">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame4&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">page 1</property>
</object>
<packing>
<property name="tab_fill">False</property>
<property name="reorderable">True</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="spacing">4</property>
<child>
<object class="GtkButton" id="AddToolButton">
<property name="label" translatable="yes">Add a Tool</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">Add foo</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="RemoveToolButton">
<property name="label" translatable="yes">Remove this Tool</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">Remove foo</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="Tool">
<property name="no_show_all">True</property>
<property name="label" translatable="yes">Tool</property>
</object>
<packing>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox7">
<property name="visible">True</property>
......@@ -1465,16 +1168,16 @@
</child>
</object>
<packing>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="ToolsLabelOld">
<object class="GtkLabel" id="ToolsLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Tool</property>
</object>
<packing>
<property name="position">2</property>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
......@@ -2081,7 +1784,7 @@
</child>
</object>
<packing>
<property name="position">3</property>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
......@@ -2090,13 +1793,69 @@
<property name="label" translatable="yes">Processing</property>
</object>
<packing>
<property name="position">3</property>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox6">
<property name="visible">True</property>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkFrame" id="GeneralSettingsFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="vbox14">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkCheckButton" id="SettingEnableODE">
<property name="label" translatable="yes">Enable experimental ODE calculations</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Requires the Python Bindings for ODE. Install the python-pyode package to enable this feature.</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="GeneralSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;General Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator5">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame13">
<property name="visible">True</property>
......@@ -2220,6 +1979,11 @@
</object>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
......@@ -2270,16 +2034,16 @@
</child>
</object>
<packing>
<property name="position">4</property>
<property name="position">3</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="VisualizationTabLabel">
<object class="GtkLabel" id="SettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Visualization</property>
<property name="label" translatable="yes">Settings</property>
</object>
<packing>
<property name="position">4</property>
<property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
......@@ -2454,14 +2218,6 @@
<property name="page_increment">10</property>
<property name="page_size">10</property>
</object>
<object class="GtkImage" id="Add foo">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
</object>
<object class="GtkImage" id="Remove foo">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
</object>
<object class="GtkAdjustment" id="lines">
<property name="upper">100</property>
<property name="step_increment">1</property>
......
......@@ -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