Commit 563826b6 authored by sumpfralle's avatar sumpfralle

added a toolpath operation tab interface

fixed toolpath cropping and grid cloning
minor ui tweaks


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1156 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 05f49414
...@@ -92,12 +92,12 @@ ...@@ -92,12 +92,12 @@
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="layout_style">center</property> <property name="layout_style">center</property>
<child> <child>
<object class="GtkButton" id="ModelDelete"> <object class="GtkColorButton" id="ModelColorButton">
<property name="label">gtk-delete</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="receives_default">True</property> <property name="receives_default">True</property>
<property name="use_stock">True</property> <property name="use_alpha">True</property>
<property name="color">#000000000000</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
...@@ -106,8 +106,8 @@ ...@@ -106,8 +106,8 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="ModelDeleteAll"> <object class="GtkButton" id="ModelDelete">
<property name="label">gtk-clear</property> <property name="label">gtk-delete</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="receives_default">True</property> <property name="receives_default">True</property>
...@@ -120,12 +120,12 @@ ...@@ -120,12 +120,12 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkColorButton" id="ModelColorButton"> <object class="GtkButton" id="ModelDeleteAll">
<property name="label">gtk-clear</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="receives_default">True</property> <property name="receives_default">True</property>
<property name="use_alpha">True</property> <property name="use_stock">True</property>
<property name="color">#000000000000</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
<child> <child>
<object class="GtkTreeViewColumn" id="NameColumn"> <object class="GtkTreeViewColumn" id="NameColumn">
<property name="title">Name</property> <property name="title">Name</property>
<property name="expand">True</property>
<child> <child>
<object class="GtkCellRendererText" id="NameCell"/> <object class="GtkCellRendererText" id="NameCell"/>
<attributes> <attributes>
...@@ -62,6 +61,7 @@ ...@@ -62,6 +61,7 @@
<child> <child>
<object class="GtkTreeViewColumn" id="DescriptionColumn"> <object class="GtkTreeViewColumn" id="DescriptionColumn">
<property name="title">Description</property> <property name="title">Description</property>
<property name="expand">True</property>
<child> <child>
<object class="GtkCellRendererText" id="DescriptionCell"/> <object class="GtkCellRendererText" id="DescriptionCell"/>
</child> </child>
......
...@@ -1898,10 +1898,10 @@ Hotkey: &lt;p&gt;</property> ...@@ -1898,10 +1898,10 @@ Hotkey: &lt;p&gt;</property>
<property name="program_name">PyCAM</property> <property name="program_name">PyCAM</property>
<property name="version">0.1</property> <property name="version">0.1</property>
<property name="copyright" translatable="yes">Copyright &#xA9; 2008-2010 Lode Leroy <property name="copyright" translatable="yes">Copyright &#xA9; 2008-2010 Lode Leroy
Copyright &#xA9; 2010 Lars Kruse</property> Copyright &#xA9; 2010-2011 Lars Kruse</property>
<property name="comments" translatable="yes">Toolpath Generation for 3-Axis CNC machining</property> <property name="comments" translatable="yes">Toolpath Generation for 3-Axis CNC machining</property>
<property name="website">http://sourceforge.net/projects/pycam/</property> <property name="website">http://pycam.sourceforge.net/</property>
<property name="website_label" translatable="yes">Webseite des PyCAM-Projekts</property> <property name="website_label" translatable="yes">Website of the PyCAM project</property>
<property name="license" translatable="yes">This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. <property name="license" translatable="yes">This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
PyCAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. PyCAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
......
...@@ -2,20 +2,40 @@ ...@@ -2,20 +2,40 @@
<interface> <interface>
<!-- interface-requires gtk+ 2.12 --> <!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide --> <!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="ToolpathCropDialog"> <object class="GtkAdjustment" id="ToolpathCropMarginValue">
<property name="border_width">5</property> <property name="lower">-1000</property>
<property name="title" translatable="yes">Crop toolpath</property> <property name="upper">1000</property>
<property name="type_hint">normal</property> <property name="step_increment">1</property>
<child internal-child="vbox"> </object>
<object class="GtkVBox" id="dialog-vbox1"> <object class="GtkAdjustment" id="ToolpathCropZSliceValue">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkFrame" id="ToolpathCropFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment1">
<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> <child>
<object class="GtkVBox" id="vbox1"> <object class="GtkVBox" id="vbox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<property name="spacing">3</property> <property name="spacing">3</property>
<child>
<object class="GtkAlignment" id="ModelTableContainer">
<property name="visible">True</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child> <child>
<object class="GtkTable" id="table1"> <object class="GtkTable" id="table1">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -57,7 +77,7 @@ ...@@ -57,7 +77,7 @@
<object class="GtkLabel" id="ToolpathCropZSliceLabel"> <object class="GtkLabel" id="ToolpathCropZSliceLabel">
<property name="visible">True</property> <property name="visible">True</property>
<property name="xalign">0</property> <property name="xalign">0</property>
<property name="label" translatable="yes">Slicing z-level:</property> <property name="label" translatable="yes">Slicing level (z):</property>
</object> </object>
<packing> <packing>
<property name="y_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property>
...@@ -79,20 +99,6 @@ ...@@ -79,20 +99,6 @@
</packing> </packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="ToolpathCropKeepOriginal">
<property name="label" translatable="yes">Keep original toolpath</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="position">1</property> <property name="position">1</property>
...@@ -100,8 +106,9 @@ ...@@ -100,8 +106,9 @@
</child> </child>
<child> <child>
<object class="GtkViewport" id="ToolpathCropInfoBox"> <object class="GtkViewport" id="ToolpathCropInfoBox">
<property name="no_show_all">True</property> <property name="visible">True</property>
<property name="resize_mode">queue</property> <property name="resize_mode">queue</property>
<property name="shadow_type">etched-out</property>
<child> <child>
<object class="GtkLabel" id="ToolpathCropInfo"> <object class="GtkLabel" id="ToolpathCropInfo">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -115,72 +122,54 @@ ...@@ -115,72 +122,54 @@
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child> <child>
<object class="GtkButton" id="ToolpathCropCancel"> <object class="GtkCheckButton" id="ToolpathCropKeepOriginal">
<property name="label">gtk-cancel</property> <property name="label" translatable="yes">Keep original 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="receives_default">True</property> <property name="receives_default">False</property>
<property name="use_stock">True</property> <property name="active">True</property>
<property name="draw_indicator">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="position">3</property>
<property name="position">0</property>
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkButton" id="ToolpathCropOK"> <object class="GtkHButtonBox" id="hbuttonbox1">
<property name="label">gtk-ok</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="layout_style">start</property>
<property name="receives_default">True</property> <child>
<property name="use_stock">True</property> <object class="GtkButton" id="CropButton">
<property name="label">gtk-execute</property>
<property name="visible">True</property>
<property name="can_focus">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">0</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">False</property> <property name="position">4</property>
<property name="position">1</property>
</packing> </packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child> </child>
</object> </object>
</child> </child>
<action-widgets> <child type="label">
<action-widget response="0">ToolpathCropCancel</action-widget> <object class="GtkLabel" id="label1">
<action-widget response="0">ToolpathCropOK</action-widget> <property name="visible">True</property>
</action-widgets> <property name="label" translatable="yes">&lt;b&gt;Crop toolpath&lt;/b&gt;</property>
</object> <property name="use_markup">True</property>
<object class="GtkAdjustment" id="ToolpathCropMarginValue"> </object>
<property name="lower">-1000</property> </child>
<property name="upper">1000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkAdjustment" id="ToolpathCropZSliceValue">
<property name="lower">-1000</property>
<property name="upper">1000</property>
<property name="step_increment">1</property>
</object>
<object class="GtkButton" id="ToolpathCropButton">
<property name="label" translatable="yes">Crop</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object> </object>
</interface> </interface>
This diff is collapsed.
This diff is collapsed.
...@@ -273,16 +273,6 @@ class Tasks(pycam.Plugins.ListPluginBase): ...@@ -273,16 +273,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
self.generate_toolpaths(self) self.generate_toolpaths(self)
def generate_toolpath(self, task, progress=None): def generate_toolpath(self, task, progress=None):
func = self.core.get("get_parameter_sets")("task")[task["type"]]["func"]
toolpath = func(task)
return toolpath
# TODO: remove this obsolete code as soon as toolpath generation works
models = task["models"]
tool = task["tool"]
process = task["process"]
bounds = task["bounds"]
path_generator = self._get_path_generator(process)
motion_grid = self._get_motion_grid(tool, process, bounds, models)
start_time = time.time() start_time = time.time()
if progress: if progress:
use_multi_progress = True use_multi_progress = True
...@@ -318,11 +308,10 @@ class Tasks(pycam.Plugins.ListPluginBase): ...@@ -318,11 +308,10 @@ class Tasks(pycam.Plugins.ListPluginBase):
# run the toolpath generation # run the toolpath generation
progress.update(text="Starting the toolpath generation") progress.update(text="Starting the toolpath generation")
low, high = bounds.get_absolute_limits()
try: try:
toolpath = path_generator.GenerateToolPath(tool, func = self.core.get("get_parameter_sets")(
models, motion_grid, minz=low[2], maxz=high[2], "task")[task["type"]]["func"]
draw_callback=draw_callback) toolpath = func(task, callback=draw_callback)
except Exception: except Exception:
# catch all non-system-exiting exceptions # catch all non-system-exiting exceptions
self.log.error(pycam.Utils.get_exception_report()) self.log.error(pycam.Utils.get_exception_report())
......
...@@ -24,6 +24,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -24,6 +24,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins import pycam.Plugins
from pycam.Geometry.Point import Point from pycam.Geometry.Point import Point
from pycam.Geometry.Plane import Plane from pycam.Geometry.Plane import Plane
import pycam.Gui.ControlsGTK
""" """
...@@ -40,61 +41,141 @@ class ToolpathCrop(pycam.Plugins.PluginBase): ...@@ -40,61 +41,141 @@ class ToolpathCrop(pycam.Plugins.PluginBase):
def setup(self): def setup(self):
if self.gui: if self.gui:
action_button = self.gui.get_object("ToolpathCropButton") self._frame = self.gui.get_object("ToolpathCropFrame")
action_button.unparent() self.core.register_ui("toolpath_handling", "Crop",
self.core.register_ui("toolpath_crop", "Crop", action_button, -3) self._frame, 40)
for objname in ("ToolpathCropZSlice", "ToolpathCropMargin"):
obj = self.gui.get_object(objname)
obj.set_value(0)
obj.connect("value-changed", self._update_widgets)
self.gui.get_object("CropButton").connect("clicked",
self.crop_toolpath)
# model selector
self.models_widget = pycam.Gui.ControlsGTK.InputTable([],
force_type=long, change_handler=self._update_widgets)
# configure the input/output converter
def get_converter(model_refs):
models_dict = {}
for model in self.core.get("models"):
models_dict[id(model)] = model
models = []
for model_ref in model_refs:
models.append(models_dict[model_ref])
return models
def set_converter(models):
return [id(model) for model in models]
self.models_widget.set_conversion(set_conv=set_converter,
get_conv=get_converter)
self.gui.get_object("ModelTableContainer").add(
self.models_widget.get_widget())
self.core.register_event("model-list-changed",
self._update_models_list)
self.core.register_event("toolpath-selection-changed",
self._update_visibility)
self._update_widgets()
self._update_visibility()
return True return True
def teardown(self): def teardown(self):
if self.gui: if self.gui:
self.core.unregister_ui("toolpath_crop", self.gui.get_object("ModelTableContainer").remove(
self.gui.get_object("ToolpathCropButton")) self.models_widget.get_widget())
self.core.unregister_ui("toolpath_handling", self._frame)
def _update_model_type_controls(self): self.core.unregister_event("model-list-changed",
model = self.core.get("model") self._update_models_list)
if not model: self.core.unregister_event("toolpath-selection-changed",
return self._update_visibility)
def _update_models_list(self):
choices = []
models = self.core.get("models")
for model in models:
choices.append((models.get_attr(model, "name"), model))
self.models_widget.update_choices(choices)
def _update_visibility(self):
if self.core.get("toolpaths").get_selected():
self._frame.show()
else:
self._frame.hide()
def _update_widgets(self, widget=None):
models = self.models_widget.get_value()
info_label = self.gui.get_object("ToolpathCropInfo")
info_box = self.gui.get_object("ToolpathCropInfoBox")
button = self.gui.get_object("CropButton")
slicing_models = [model for model in models
if hasattr(model, "get_waterline_contour")]
# show or hide z-slice controls # show or hide z-slice controls
can_slice = hasattr(model, "get_waterline_contour") slice_controls = ("ToolpathCropZSliceLabel", "ToolpathCropZSlice")
for name in "ToolpathCropZSliceLabel", "ToolpathCropZSlice": if slicing_models:
if can_slice: # set lower and upper limit for z-slice
self.gui.get_object(name).show() z_slice = self.gui.get_object("ToolpathCropZSlice")
minz = min([model.minz for model in slicing_models])
maxz = max([model.maxz for model in slicing_models])
z_slice.set_range(minz, maxz)
if z_slice.get_value() > maxz:
z_slice.set_value(maxz)
elif z_slice.get_value() < minz:
z_slice.set_value(minz)
else: else:
pass
for name in slice_controls:
self.gui.get_object(name).show()
else:
for name in slice_controls:
self.gui.get_object(name).hide() self.gui.get_object(name).hide()
# set lower and upper limit for z-slice # update info
z_slice_value = self.gui.get_object("ToolpathCropZSliceValue") if not models:
z_slice_value.set_lower(model.minz) info_box.show()
z_slice_value.set_upper(model.maxz) info_label.set_label("Hint: select a model")
button.set_sensitive(False)
def crop_toolpath(self, widget=None):
# TODO: how to get the currently selected toolpath???
toolpath = self.core.get("toolpath")[0]
model = self.core.get("model")
if not model:
return
if hasattr(model, "get_polygons"):
contour = model
elif hasattr(model, "get_waterline_contour"):
z_slice = self.gui.get_object("ToolpathCropZSlice").get_value()
plane = Plane(Point(0, 0, z_slice))
#self.update_progress_bar("Calculating the 2D projection")
contour = model.get_waterline_contour(plane)
else: else:
self.log.warn(("The current model (%s) does not support " \ polygons = self._get_waterlines()
+ "projections") % str(type(model))) if polygons:
return info_box.hide()
#self.update_progress_bar("Applying the tool diameter offset") button.set_sensitive(True)
else:
info_label.set_label("Hint: there is no usable contour at this splice level")
info_box.show()
button.set_sensitive(False)
def _get_waterlines(self):
models = self.models_widget.get_value()
polygons = []
# get all waterlines and polygons
for model in models:
if hasattr(model, "get_polygons"):
for poly in model.get_polygons():
polygons.append(poly.copy())
elif hasattr(model, "get_waterline_contour"):
z_slice = self.gui.get_object("ToolpathCropZSlice").get_value()
plane = Plane(Point(0, 0, z_slice))
for poly in model.get_waterline_contour(plane).get_polygons():
polygons.append(poly.copy())
# add an offset if requested
margin = self.gui.get_object("ToolpathCropMargin").get_value() margin = self.gui.get_object("ToolpathCropMargin").get_value()
if margin: if margin != 0:
contour = contour.get_offset_model(margin) shifted = []
#self.update_progress_bar("Cropping the toolpath") for poly in polygons:
#toolpath.crop(contour.get_polygons(), callback=self.update_progress_bar) shifted.extend(poly.get_offset_polygons(margin))
if self.gui.get_object("ToolpathCropKeepOriginal").get_active(): polygons = shifted
new_tp = toolpath.get_cropped_copy(contour.get_polygons(), return polygons
callback=self.update_progress_bar)
new_tp.visible = True def crop_toolpath(self, widget=None):
old_index = self.core.get("toolpath").index(toolpath) selected = self.core.get("toolpaths").get_selected()
self.core.get("toolpath").insert(old_index + 1, new_tp) polygons = self._get_waterlines()
else: keep_original = self.gui.get_object(
toolpath.crop(contour.get_polygons(), callback=self.update_progress_bar) "ToolpathCropKeepOriginal").get_active()
for toolpath in self.core.get("toolpaths").get_selected():
new_tp = toolpath.get_cropped_copy(polygons)
if new_tp.paths:
if keep_original:
self.core.get("toolpaths").append(new_tp)
else:
toolpath.paths = new_tp.paths
else:
self.log.info("Toolpath cropping: the result is empty")
self.core.emit_event("visual-item-updated")
self.core.get("toolpaths").select(selected)
...@@ -22,73 +22,88 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,73 +22,88 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
import pycam.Plugins import pycam.Plugins
import pycam.Geometry.Point
class ToolpathGrid(pycam.Plugins.PluginBase): class ToolpathGrid(pycam.Plugins.PluginBase):
UI_FILE = "toolpath_grid.ui" UI_FILE = "toolpath_grid.ui"
DEPENDS = ["Toolpaths"]
def setup(self): def setup(self):
if self.gui: if self.gui:
self._frame = self.gui.get_object("ToolpathGridFrame")
self.core.register_ui("toolpath_handling", "Clone grid",
self._frame, 30)
for objname in ("GridYCount", "GridXCount"):
self.gui.get_object(objname).set_value(1)
for objname in ("GridYCount", "GridXCount", "GridYDistance", for objname in ("GridYCount", "GridXCount", "GridYDistance",
"GridXDistance"): "GridXDistance"):
self.gui.get_object(objname).connect("value-changed", self.gui.get_object(objname).connect("value-changed",
self.update_toolpath_grid_window) self._update_widgets)
# TODO: add a button to the toolpath action UI self.gui.get_object("GridCreate").connect("clicked",
self.create_toolpath_grid)
self.core.register_event("toolpath-selection-changed",
self._update_widgets)
self._update_widgets()
return True return True
def teardown(self): def teardown(self):
if self.gui:
self.core.unregister_ui("toolpath_handling", self._frame)
self.core.unregister_event("toolpath-selection-changed",
self._update_widgets)
pass pass
def update_toolpath_grid_window(self, widget=None): def _get_toolpaths_dim(self, toolpaths):
data = self._toolpath_for_grid_data if toolpaths:
x_dim = data["maxx"] - data["minx"] maxx = max([tp.maxx for tp in toolpaths])
y_dim = data["maxy"] - data["miny"] minx = min([tp.minx for tp in toolpaths])
x_count = self.gui.get_object("GridXCount").get_value() maxy = max([tp.maxy for tp in toolpaths])
x_space = self.gui.get_object("GridXDistance").get_value() miny = min([tp.miny for tp in toolpaths])
y_count = self.gui.get_object("GridYCount").get_value() return (maxx - minx), (maxy - miny)
y_space = self.gui.get_object("GridYDistance").get_value() else:
x_width = x_dim * x_count + x_space * (x_count - 1) return None, None
y_width = y_dim * y_count + y_space * (y_count - 1)
self.gui.get_object("LabelGridXWidth").set_label("%g%s" % \ def _update_widgets(self, widget=None):
(x_width, self.settings.get("unit"))) toolpaths = self.core.get("toolpaths").get_selected()
self.gui.get_object("LabelGridYWidth").set_label("%g%s" % \ if toolpaths:
(y_width, self.settings.get("unit"))) x_dim, y_dim = self._get_toolpaths_dim(toolpaths)
x_count = self.gui.get_object("GridXCount").get_value()
def create_toolpath_grid(self, toolpath):
dialog = self.gui.get_object("ToolpathGridDialog")
data = self._toolpath_for_grid_data
data["minx"] = toolpath.minx()
data["maxx"] = toolpath.maxx()
data["miny"] = toolpath.miny()
data["maxy"] = toolpath.maxy()
self.gui.get_object("GridXCount").set_value(1)
self.gui.get_object("GridYCount").set_value(1)
self.update_toolpath_grid_window()
result = dialog.run()
if result == 1:
# "OK" was pressed
new_tp = []
x_count = int(self.gui.get_object("GridXCount").get_value())
y_count = int(self.gui.get_object("GridYCount").get_value())
x_space = self.gui.get_object("GridXDistance").get_value() x_space = self.gui.get_object("GridXDistance").get_value()
y_count = self.gui.get_object("GridYCount").get_value()
y_space = self.gui.get_object("GridYDistance").get_value() y_space = self.gui.get_object("GridYDistance").get_value()
x_dim = data["maxx"] - data["minx"] x_width = x_dim * x_count + x_space * (x_count - 1)
y_dim = data["maxy"] - data["miny"] y_width = y_dim * y_count + y_space * (y_count - 1)
self.gui.get_object("LabelGridXWidth").set_label("%g%s" % \
(x_width, self.core.get("unit_string")))
self.gui.get_object("LabelGridYWidth").set_label("%g%s" % \
(y_width, self.core.get("unit_string")))
self._frame.show()
else:
self._frame.hide()
def create_toolpath_grid(self, widget=None):
toolpaths = self.core.get("toolpaths").get_selected()
x_count = int(self.gui.get_object("GridXCount").get_value())
y_count = int(self.gui.get_object("GridYCount").get_value())
x_space = self.gui.get_object("GridXDistance").get_value()
y_space = self.gui.get_object("GridYDistance").get_value()
x_dim, y_dim = self._get_toolpaths_dim(toolpaths)
for toolpath in toolpaths:
new_paths = []
for x in range(x_count): for x in range(x_count):
for y in range(y_count): for y in range(y_count):
shift = Point(x * (x_space + x_dim), shift = pycam.Geometry.Point.Vector(x * (x_space + x_dim),
y * (y_space + y_dim), 0) y * (y_space + y_dim), 0)
for path in toolpath.get_paths(): for path in toolpath.paths:
new_path = pycam.Geometry.Path.Path() new_path = pycam.Geometry.Path.Path()
new_path.points = [shift.add(p) for p in path.points] new_path.points = [shift.add(p) for p in path.points]
new_tp.append(new_path) new_paths.append(new_path)
new_toolpath = pycam.Toolpath.Toolpath(new_tp, toolpath.name, if not self.gui.get_object("KeepOriginal").get_active():
toolpath.toolpath_settings) toolpath.paths = new_paths
toolpath.visible = False else:
new_toolpath.visible = True self.core.get("toolpaths").append(new_toolpath)
# TODO: emit "toolpath-list-changed" self.core.emit_event("visual-item-updated")
self.toolpath.append(new_toolpath) self.core.get("toolpaths").select(toolpaths)
self.update_toolpath_table()
dialog.hide()
...@@ -46,12 +46,22 @@ class Toolpaths(pycam.Plugins.ListPluginBase): ...@@ -46,12 +46,22 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
(self.ACTION_CLEAR, "ToolpathDeleteAll")): (self.ACTION_CLEAR, "ToolpathDeleteAll")):
self.register_list_action_button(action, self._modelview, self.register_list_action_button(action, self._modelview,
self.gui.get_object(obj_name)) self.gui.get_object(obj_name))
# toolpath operations
toolpath_handling_obj = self.gui.get_object(
"ToolpathHandlingNotebook")
def clear_toolpath_handling_obj():
for index in range(toolpath_handling_obj.get_n_pages()):
toolpath_handling_obj.remove_page(0)
def add_toolpath_handling_item(item, name):
toolpath_handling_obj.append_page(item, gtk.Label(name))
self.core.register_ui_section("toolpath_handling",
add_toolpath_handling_item, clear_toolpath_handling_obj)
# handle table changes # handle table changes
self._modelview.connect("row-activated", self._modelview.connect("row-activated",
self._list_action_toggle_custom, self.COLUMN_VISIBLE) self._list_action_toggle_custom, self.COLUMN_VISIBLE)
self.gui.get_object("ToolpathVisibleColumn").set_cell_data_func( self.gui.get_object("ToolpathVisibleColumn").set_cell_data_func(
self.gui.get_object("ToolpathVisibleSymbol"), self.gui.get_object("ToolpathVisibleSymbol"),
self._visualize_machine_time) self._visualize_visible_state)
self.gui.get_object("ToolpathNameCell").connect("edited", self.gui.get_object("ToolpathNameCell").connect("edited",
self._edit_toolpath_name) self._edit_toolpath_name)
self.gui.get_object("ToolpathTimeColumn").set_cell_data_func( self.gui.get_object("ToolpathTimeColumn").set_cell_data_func(
...@@ -93,8 +103,10 @@ class Toolpaths(pycam.Plugins.ListPluginBase): ...@@ -93,8 +103,10 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self.register_model_update(update_model) self.register_model_update(update_model)
self.core.register_event("toolpath-list-changed", self.core.register_event("toolpath-list-changed",
self._update_widgets) self._update_widgets)
self.core.register_event("toolpath-list-changed",
lambda: self.core.emit_event("visual-item-updated"))
self._update_widgets() self._update_widgets()
self.core.add_item("toolpaths", lambda: self) self.core.set("toolpaths", self)
return True return True
def teardown(self): def teardown(self):
...@@ -115,6 +127,18 @@ class Toolpaths(pycam.Plugins.ListPluginBase): ...@@ -115,6 +127,18 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
return [self[index] for index, item in enumerate(self._treemodel) return [self[index] for index, item in enumerate(self._treemodel)
if item[self.COLUMN_VISIBLE]] if item[self.COLUMN_VISIBLE]]
def select(self, toolpaths):
selection = self._modelview.get_selection()
model = self._modelview.get_model()
if not isinstance(toolpaths, (list, tuple)):
toolpaths = [toolpaths]
tp_refs = [id(tp) for tp in toolpaths]
for index, row in enumerate(model):
if row[self.COLUMN_REF] in tp_refs:
selection.select_path((index,))
else:
selection.unselect_path((index,))
def _update_widgets(self): def _update_widgets(self):
toolpaths = self toolpaths = self
if not toolpaths: if not toolpaths:
...@@ -147,6 +171,13 @@ class Toolpaths(pycam.Plugins.ListPluginBase): ...@@ -147,6 +171,13 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
new_text: new_text:
self._treemodel[path][self.COLUMN_NAME] = new_text self._treemodel[path][self.COLUMN_NAME] = new_text
def _visualize_visible_state(self, column, cell, model, m_iter):
visible = model.get_value(m_iter, self.COLUMN_VISIBLE)
if visible:
cell.set_property("pixbuf", self.ICONS["visible"])
else:
cell.set_property("pixbuf", self.ICONS["hidden"])
def _visualize_machine_time(self, column, cell, model, m_iter): def _visualize_machine_time(self, column, cell, model, m_iter):
path = model.get_path(m_iter) path = model.get_path(m_iter)
toolpath = self[path[0]] toolpath = self[path[0]]
......
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