Commit 0b069aaf authored by sumpfralle's avatar sumpfralle

parallel processing separated into plugin

improved toolpath simulation plugin (not done, yet)


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1126 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent a19f544c
This diff is collapsed.
This diff is collapsed.
...@@ -2,10 +2,188 @@ ...@@ -2,10 +2,188 @@
<interface> <interface>
<!-- interface-requires gtk+ 2.12 --> <!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide --> <!-- interface-naming-policy project-wide -->
<object class="GtkButton" id="toolpath_simulate"> <object class="GtkDialog" id="SimulationDialog">
<property name="label" translatable="yes">Simulate</property> <property name="border_width">5</property>
<property name="title" translatable="yes">PyCAM simulation</property>
<property name="role">pycam-simulation</property>
<property name="destroy_with_parent">True</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox9">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkVBox" id="vbox23">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">3</property>
<child>
<object class="GtkHBox" id="hbox20">
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="SimulationDetailsControlLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="xpad">5</property>
<property name="label" translatable="yes">Simulation detail level (1..10):</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="SimulationDetailsControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="max_length">6</property>
<property name="invisible_char">&#x25CF;</property>
<property name="adjustment">SimulationDetailsValue</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">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="xalign">0</property>
<property name="label" translatable="yes">&lt;b&gt;Hint:&lt;/b&gt; take a look at the "show drill" and
"OpenGL: polygon" settings in preferences.
&lt;b&gt;Beware:&lt;/b&gt; the simulation feature is new and
experimental. Thus you will quite probably stumble
upon interesting bugs and weird results.</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="SimulationProgressTimelineLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Progress:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkHScale" id="SimulationProgressTimeline">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="adjustment">SimulationProgressTimelineValue</property>
<property name="draw_value">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox36">
<property name="visible">True</property>
<property name="spacing">4</property>
<child>
<object class="GtkLabel" id="SimulationSpeedFactorLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Simulation speed factor:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="SimulationSpeedFactorValueLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">1.00</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">4</property>
</packing>
</child>
<child>
<object class="GtkHScale" id="SimulationSpeedFactor">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">SimulationSpeedFactorValueExponential</property>
<property name="draw_value">False</property>
<property name="value_pos">bottom</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">5</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area8">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="ExitSimulationButton">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">ExitSimulationButton</action-widget>
</action-widgets>
</object>
<object class="GtkAdjustment" id="SimulationProgressTimelineValue">
<property name="upper">100</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="SimulationSpeedFactorValueExponential">
<property name="lower">-2</property>
<property name="upper">4</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="SimulationDetailsValue">
<property name="lower">1</property>
<property name="upper">10</property>
<property name="step_increment">1</property>
</object> </object>
</interface> </interface>
This diff is collapsed.
This diff is collapsed.
...@@ -22,6 +22,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,6 +22,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins import pycam.Plugins
# this requires ODE - we import it later, if necessary
#import pycam.Simulation.ODEBlocks
class ToolpathSimulation(pycam.Plugins.PluginBase): class ToolpathSimulation(pycam.Plugins.PluginBase):
...@@ -29,43 +31,50 @@ class ToolpathSimulation(pycam.Plugins.PluginBase): ...@@ -29,43 +31,50 @@ class ToolpathSimulation(pycam.Plugins.PluginBase):
UI_FILE = "toolpath_simulation.ui" UI_FILE = "toolpath_simulation.ui"
def setup(self): def setup(self):
return False if self.gui:
speed_factor_widget = self.gui.get_object("SimulationSpeedFactor") speed_factor_widget = self.gui.get_object("SimulationSpeedFactor")
self.settings.add_item("simulation_speed_factor", self.core.add_item("simulation_speed_factor",
lambda: pow(10, speed_factor_widget.get_value()), lambda: pow(10, speed_factor_widget.get_value()),
lambda value: speed_factor_widget.set_value(math.log10(max(0.001, value)))) lambda value: speed_factor_widget.set_value(math.log10(
simulation_progress = self.gui.get_object("SimulationProgressTimelineValue") max(0.001, value))))
simulation_progress = self.gui.get_object(
"SimulationProgressTimelineValue")
def update_simulation_progress(widget): def update_simulation_progress(widget):
if widget.get_value() == 100: if widget.get_value() == 100:
# a negative value indicates, that the simulation is finished # a negative value indicates, that the simulation is finished
self.settings.set("simulation_current_distance", -1) self.core.set("simulation_current_distance", -1)
else: else:
complete = self.settings.get("simulation_complete_distance") complete = self.core.get("simulation_complete_distance")
partial = widget.get_value() / 100.0 * complete partial = widget.get_value() / 100.0 * complete
self.settings.set("simulation_current_distance", partial) self.core.set("simulation_current_distance", partial)
simulation_progress.connect("value-changed", update_simulation_progress) simulation_progress.connect("value-changed", update_simulation_progress)
# update the speed factor label # update the speed factor label
speed_factor_widget.connect("value-changed", speed_factor_widget.connect("value-changed", lambda widget: \
lambda widget: self.gui.get_object("SimulationSpeedFactorValueLabel").set_label( self.gui.get_object("SimulationSpeedFactorValueLabel").\
"%.2f" % self.settings.get("simulation_speed_factor"))) set_label("%.2f" % self.core.get("simulation_speed_factor")))
self.simulation_window = self.gui.get_object("SimulationDialog") self.simulation_window = self.gui.get_object("SimulationDialog")
self.simulation_window.connect("delete-event", self.finish_toolpath_simulation) self.simulation_window.connect("delete-event",
self.finish_toolpath_simulation)
sim_detail_obj = self.gui.get_object("SimulationDetailsValue")
self.core.add_item("simulation_details_level",
sim_detail_obj.get_value, sim_detail_obj.set_value)
return True
def finish_toolpath_simulation(self, widget=None, data=None): def finish_toolpath_simulation(self, widget=None, data=None):
# hide the simulation tab # hide the simulation tab
self.simulation_window.hide() self.simulation_window.hide()
# enable all other tabs again # enable all other tabs again
self.toggle_tabs_for_simulation(True) self.toggle_tabs_for_simulation(True)
self.settings.set("simulation_object", None) self.core.set("simulation_object", None)
self.settings.set("simulation_toolpath_moves", None) self.core.set("simulation_toolpath_moves", None)
self.settings.set("show_simulation", False) self.core.set("show_simulation", False)
self.settings.set("simulation_toolpath", None) self.core.set("simulation_toolpath", None)
self.update_view() self.update_view()
# don't destroy the simulation window (for "destroy" event) # don't destroy the simulation window (for "destroy" event)
return True return True
def update_toolpath_simulation(self, widget=None, toolpath=None): def update_toolpath_simulation(self, widget=None, toolpath=None):
s = self.settings s = self.core
# update the GUI # update the GUI
while gtk.events_pending(): while gtk.events_pending():
gtk.main_iteration() gtk.main_iteration()
...@@ -127,8 +136,8 @@ class ToolpathSimulation(pycam.Plugins.PluginBase): ...@@ -127,8 +136,8 @@ class ToolpathSimulation(pycam.Plugins.PluginBase):
# show the simulation controls # show the simulation controls
self.simulation_window.show() self.simulation_window.show()
# start the simulation # start the simulation
self.settings.set("show_simulation", True) self.core.set("show_simulation", True)
time_step = int(1000 / self.settings.get("drill_progress_max_fps")) time_step = int(1000 / self.core.get("drill_progress_max_fps"))
# update the toolpath simulation repeatedly # update the toolpath simulation repeatedly
gobject.timeout_add(time_step, self.update_toolpath_simulation) gobject.timeout_add(time_step, self.update_toolpath_simulation)
...@@ -156,14 +165,14 @@ class ToolpathSimulation(pycam.Plugins.PluginBase): ...@@ -156,14 +165,14 @@ class ToolpathSimulation(pycam.Plugins.PluginBase):
y_steps = int(sqrt(grid_size) / proportion) y_steps = int(sqrt(grid_size) / proportion)
simulation_backend = ODEBlocks.ODEBlocks(toolpath.get_tool_settings(), simulation_backend = ODEBlocks.ODEBlocks(toolpath.get_tool_settings(),
toolpath.get_bounding_box(), x_steps=x_steps, y_steps=y_steps) toolpath.get_bounding_box(), x_steps=x_steps, y_steps=y_steps)
self.settings.set("simulation_object", simulation_backend) self.core.set("simulation_object", simulation_backend)
# disable the simulation widget (avoids confusion regarding "cancel") # disable the simulation widget (avoids confusion regarding "cancel")
if not widget is None: if not widget is None:
self.gui.get_object("SimulationTab").set_sensitive(False) self.gui.get_object("SimulationTab").set_sensitive(False)
# update the view # update the view
self.update_view() self.update_view()
# calculate the simulation and show it simulteneously # calculate the simulation and show it simultaneously
progress = self.settings.get("progress") progress = self.core.get("progress")
for path_index, path in enumerate(paths): for path_index, path in enumerate(paths):
progress_text = "Simulating path %d/%d" % (path_index, len(paths)) progress_text = "Simulating path %d/%d" % (path_index, len(paths))
progress_value_percent = 100.0 * path_index / len(paths) progress_value_percent = 100.0 * path_index / len(paths)
......
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