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 ...@@ -11,7 +11,6 @@ import pycam.Gui.common as GuiCommon
import pycam.Cutters import pycam.Cutters
import pycam.PathGenerators import pycam.PathGenerators
import pycam.PathProcessors import pycam.PathProcessors
import pycam.Gui.ode_objects as ode_objects
import pycam.Geometry.utils as utils import pycam.Geometry.utils as utils
import pycam.Gui.OpenGLTools as ogl_tools import pycam.Gui.OpenGLTools as ogl_tools
import threading import threading
...@@ -324,16 +323,24 @@ class ProjectGui: ...@@ -324,16 +323,24 @@ class ProjectGui:
self.settings.add_item("tool_radius", obj.get_value, obj.set_value) self.settings.add_item("tool_radius", obj.get_value, obj.set_value)
obj = self.gui.get_object("TorusRadiusControl") obj = self.gui.get_object("TorusRadiusControl")
self.settings.add_item("torus_radius", obj.get_value, obj.set_value) 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) self.gui.get_object("Toggle3dView").connect("toggled", self.toggle_3d_view)
for name, objname in (("show_model", "ShowModelCheckBox"), for name, objname in (("show_model", "ShowModelCheckBox"),
("show_axes", "ShowAxesCheckBox"), ("show_axes", "ShowAxesCheckBox"),
("show_bounding_box", "ShowBoundingCheckBox"), ("show_bounding_box", "ShowBoundingCheckBox"),
("show_toolpath", "ShowToolPathCheckBox"), ("show_toolpath", "ShowToolPathCheckBox"),
("show_drill_progress", "ShowDrillProgressCheckBox")): ("show_drill_progress", "ShowDrillProgressCheckBox"),
("enable_ode", "SettingEnableODE")):
obj = self.gui.get_object(objname) obj = self.gui.get_object(objname)
self.settings.add_item(name, obj.get_active, obj.set_active) self.settings.add_item(name, obj.get_active, obj.set_active)
obj.connect("toggled", self.update_view) 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 # preconfigure some values
self.settings.set("show_model", True) self.settings.set("show_model", True)
self.settings.set("show_toolpath", True) self.settings.set("show_toolpath", True)
...@@ -415,7 +422,10 @@ class ProjectGui: ...@@ -415,7 +422,10 @@ class ProjectGui:
self.view3d.paint() self.view3d.paint()
def update_physics(self): def update_physics(self):
self.physics = GuiCommon.generate_physics(self.settings, self.cutter, self.physics) if self.settings.get("enable_ode"):
self.physics = GuiCommon.generate_physics(self.settings, self.cutter, self.physics)
else:
self.physics = None
@gui_activity_guard @gui_activity_guard
def toggle_3d_view(self, widget=None, value=None): def toggle_3d_view(self, widget=None, value=None):
...@@ -749,7 +759,7 @@ class ProjectGui: ...@@ -749,7 +759,7 @@ class ProjectGui:
response = dialog.run() response = dialog.run()
filename = dialog.get_filename() filename = dialog.get_filename()
dialog.hide() dialog.hide()
if response == gtk.RESPONSE_CANCEL: if response != gtk.RESPONSE_OK:
dialog.destroy() dialog.destroy()
return None return None
if os.path.exists(filename): if os.path.exists(filename):
......
import OpenGL.GL as GL import OpenGL.GL as GL
import OpenGL.GLUT as GLUT import OpenGL.GLUT as GLUT
import ode_objects # "ode" is imported later, if required
#import ode_objects
MODEL_TRANSFORMATIONS = { MODEL_TRANSFORMATIONS = {
...@@ -185,6 +186,7 @@ def scale_model(model, scale): ...@@ -185,6 +186,7 @@ def scale_model(model, scale):
model.transform(matrix) model.transform(matrix)
def generate_physics(settings, cutter, physics=None): def generate_physics(settings, cutter, physics=None):
import ode_objects
if physics is None: if physics is None:
physics = ode_objects.PhysicalWorld() physics = ode_objects.PhysicalWorld()
physics.reset() physics.reset()
...@@ -198,3 +200,10 @@ def generate_physics(settings, cutter, physics=None): ...@@ -198,3 +200,10 @@ def generate_physics(settings, cutter, physics=None):
physics.set_drill(shape_info[0], shape_info[2]) physics.set_drill(shape_info[0], shape_info[2])
return physics return physics
def is_ode_available():
try:
import ode
return True
except ImportError:
return False
...@@ -910,303 +910,6 @@ ...@@ -910,303 +910,6 @@
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
</packing> </packing>
</child> </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> <child>
<object class="GtkVBox" id="vbox7"> <object class="GtkVBox" id="vbox7">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -1465,16 +1168,16 @@ ...@@ -1465,16 +1168,16 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="position">2</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child type="tab"> <child type="tab">
<object class="GtkLabel" id="ToolsLabelOld"> <object class="GtkLabel" id="ToolsLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Tool</property> <property name="label" translatable="yes">Tool</property>
</object> </object>
<packing> <packing>
<property name="position">2</property> <property name="position">1</property>
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
</packing> </packing>
</child> </child>
...@@ -2081,7 +1784,7 @@ ...@@ -2081,7 +1784,7 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="position">3</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child type="tab"> <child type="tab">
...@@ -2090,7 +1793,7 @@ ...@@ -2090,7 +1793,7 @@
<property name="label" translatable="yes">Processing</property> <property name="label" translatable="yes">Processing</property>
</object> </object>
<packing> <packing>
<property name="position">3</property> <property name="position">2</property>
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
</packing> </packing>
</child> </child>
...@@ -2098,92 +1801,82 @@ ...@@ -2098,92 +1801,82 @@
<object class="GtkHBox" id="hbox6"> <object class="GtkHBox" id="hbox6">
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GtkFrame" id="frame13"> <object class="GtkVBox" id="vbox6">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label_xalign">0</property> <property name="orientation">vertical</property>
<property name="shadow_type">none</property>
<child> <child>
<object class="GtkAlignment" id="alignment21"> <object class="GtkFrame" id="GeneralSettingsFrame">
<property name="visible">True</property> <property name="visible">True</property>
<property name="left_padding">12</property> <property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child> <child>
<object class="GtkVBox" id="vbox13"> <object class="GtkAlignment" id="alignment6">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="left_padding">12</property>
<property name="spacing">2</property>
<child>
<object class="GtkCheckButton" id="ShowModelCheckBox">
<property name="label" translatable="yes">Show Model</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ShowToolPathCheckBox">
<property name="label" translatable="yes">Show Toolpath</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ShowBoundingCheckBox">
<property name="label" translatable="yes">Show Bounding Box</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ShowAxesCheckBox">
<property name="label" translatable="yes">Show Coordinate System</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child> <child>
<object class="GtkCheckButton" id="ShowDrillProgressCheckBox"> <object class="GtkVBox" id="vbox14">
<property name="label" translatable="yes">Show Drill Progress</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="orientation">vertical</property>
<property name="receives_default">False</property> <child>
<property name="draw_indicator">True</property> <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> </object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child> </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>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment21">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child> <child>
<object class="GtkHBox" id="hbox7"> <object class="GtkVBox" id="vbox13">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property> <property name="spacing">2</property>
<child> <child>
<object class="GtkLabel" id="DrillUpdateSkipLabel"> <object class="GtkCheckButton" id="ShowModelCheckBox">
<property name="label" translatable="yes">Show Model</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Skip Drill Progress Frames:</property> <property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -2191,33 +1884,104 @@ ...@@ -2191,33 +1884,104 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkSpinButton" id="DrillProgressFrameSkipControl"> <object class="GtkCheckButton" id="ShowToolPathCheckBox">
<property name="label" translatable="yes">Show Toolpath</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property> <property name="receives_default">False</property>
<property name="adjustment">DrillProgressFrameSkip</property> <property name="draw_indicator">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkCheckButton" id="ShowBoundingCheckBox">
<property name="label" translatable="yes">Show Bounding Box</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ShowAxesCheckBox">
<property name="label" translatable="yes">Show Coordinate System</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ShowDrillProgressCheckBox">
<property name="label" translatable="yes">Show Drill Progress</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox7">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="DrillUpdateSkipLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Skip Drill Progress Frames:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="DrillProgressFrameSkipControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="adjustment">DrillProgressFrameSkip</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">5</property>
</packing>
</child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="position">5</property>
</packing>
</child> </child>
</object> </object>
</child> </child>
<child type="label">
<object class="GtkLabel" id="VisualSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Display settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object> </object>
</child> <packing>
<child type="label"> <property name="position">2</property>
<object class="GtkLabel" id="VisualSettingsFrameLabel"> </packing>
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Display settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child> </child>
</object> </object>
<packing> <packing>
...@@ -2270,16 +2034,16 @@ ...@@ -2270,16 +2034,16 @@
</child> </child>
</object> </object>
<packing> <packing>
<property name="position">4</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
<child type="tab"> <child type="tab">
<object class="GtkLabel" id="VisualizationTabLabel"> <object class="GtkLabel" id="SettingsTabLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Visualization</property> <property name="label" translatable="yes">Settings</property>
</object> </object>
<packing> <packing>
<property name="position">4</property> <property name="position">3</property>
<property name="tab_fill">False</property> <property name="tab_fill">False</property>
</packing> </packing>
</child> </child>
...@@ -2454,14 +2218,6 @@ ...@@ -2454,14 +2218,6 @@
<property name="page_increment">10</property> <property name="page_increment">10</property>
<property name="page_size">10</property> <property name="page_size">10</property>
</object> </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"> <object class="GtkAdjustment" id="lines">
<property name="upper">100</property> <property name="upper">100</property>
<property name="step_increment">1</property> <property name="step_increment">1</property>
......
...@@ -36,6 +36,9 @@ class DropCutter: ...@@ -36,6 +36,9 @@ class DropCutter:
self.model = model self.model = model
self.processor = PathProcessor self.processor = PathProcessor
self.physics = physics 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): def GenerateToolPath(self, minx, maxx, miny, maxy, z0, z1, d0, d1, direction, draw_callback=None):
if self.processor: if self.processor:
...@@ -64,112 +67,20 @@ class DropCutter: ...@@ -64,112 +67,20 @@ class DropCutter:
while dims[1].check_bounds(): while dims[1].check_bounds():
dims[0].set(dims[0].start) dims[0].set(dims[0].start)
pa.new_scanline() pa.new_scanline()
t_last = None self._triangle_last = None
self._cut_last = None
while dims[0].check_bounds(): 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[:])
low, high = z0, z1
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))
if self.physics.check_collision():
# there is an object between z1 and z0 - we need more loops
trips = trip_start
else: else:
# no need for further collision detection - we can go down the whole range z1..z0 points = self.get_max_height_manually(dims[x], dims[y], dim_height, order=dim_attrs[:])
trips = 0
safe_z = z0
while trips > 0:
current_z = (low + high)/2.0
self.physics.set_drill_position((dims[x].get(), dims[y].get(), current_z))
if self.physics.check_collision():
low = current_z
else:
high = current_z
safe_z = current_z
trips -= 1
#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))
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)
else:
next_point = Point(dims[x].get(), dims[y].get(), z1)
else:
next_point = Point(dims[x].get(), dims[y].get(), safe_z)
pa.append(next_point) for next_point in points:
pa.append(next_point)
self.cutter.moveto(next_point) self.cutter.moveto(next_point)
if draw_callback: if draw_callback:
draw_callback() draw_callback()
"""
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
box_y_min = p.y - self.cutter.radius
box_y_max = p.y + self.cutter.radius
box_z_min = dim_height.end
box_z_max = +INFINITE
triangles = self.model.triangles(box_x_min, box_y_min, box_z_min, box_x_max, box_y_max, box_z_max)
for t in triangles:
if t.normal().z < 0: continue;
cut = self.cutter.drop(t)
if cut and (cut.z > height_max or height_max is None):
height_max = cut.z
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))
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):
nl = range(3)
nl[0] = -getattr(triangle_last.normal(), dim_attrs[0])
nl[2] = triangle_last.normal().z
nm = range(3)
nm[0] = -getattr(triangle_max.normal(), dim_attrs[0])
nm[2] = triangle_max.normal().z
last = range(3)
last[0] = getattr(cut_last, dim_attrs[0])
last[2] = cut_last.z
mx = range(3)
mx[0] = getattr(cut_max, dim_attrs[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]
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) dims[0].shift(d0)
pa.end_scanline() pa.end_scanline()
...@@ -180,3 +91,108 @@ class DropCutter: ...@@ -180,3 +91,108 @@ class DropCutter:
pa.finish() pa.finish()
return pa.paths 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((x.get(), y.get(), dim_height.end))
if self.physics.check_collision():
# 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 = dim_height.end
while trips > 0:
current_z = (low + high)/2.0
self.physics.set_drill_position((x.get(), y.get(), current_z))
if self.physics.check_collision():
low = current_z
else:
high = current_z
safe_z = current_z
trips -= 1
#current_z -= dz
if safe_z is None:
# no safe position was found - let's check the upper bound
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(x.get(), y.get(), INFINITE)
else:
next_point = Point(x.get(), y.get(), dim_height.start)
else:
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
self.cutter.moveto(p)
box_x_min = p.x - self.cutter.radius
box_x_max = p.x + self.cutter.radius
box_y_min = p.y - self.cutter.radius
box_y_max = p.y + self.cutter.radius
box_z_min = dim_height.end
box_z_max = +INFINITE
triangles = self.model.triangles(box_x_min, box_y_min, box_z_min, box_x_max, box_y_max, box_z_max)
for t in triangles:
if t.normal().z < 0: continue;
cut = self.cutter.drop(t)
if cut and (cut.z > height_max or height_max is None):
height_max = cut.z
cut_max = cut
triangle_max = t
if not cut_max or not dim_height.check_bounds(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:
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(self._triangle_last.normal(), order[0])
nl[2] = self._triangle_last.normal().z
nm = range(3)
nm[0] = -getattr(triangle_max.normal(), order[0])
nm[2] = triangle_max.normal().z
last = range(3)
last[0] = getattr(self._cut_last, order[0])
last[2] = self._cut_last.z
mx = range(3)
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(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:
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)
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