Commit 1e716228 authored by sumpfralle's avatar sumpfralle

renamed events "*-parameter-changed" to "*-changed"

migrated task settings to the new parameter manager


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1144 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent ea4da952
......@@ -187,7 +187,7 @@
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment1">
<object class="GtkAlignment" id="ProcessSelectorBox">
<property name="visible">True</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
......
......@@ -82,6 +82,20 @@
</row>
</data>
</object>
<object class="GtkListStore" id="TaskTypeList">
<columns>
<!-- column-name label -->
<column type="gchararray"/>
<!-- column-name name -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">Test</col>
<col id="1" translatable="yes">sfd</col>
</row>
</data>
</object>
<object class="GtkVPaned" id="TaskBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
......@@ -256,55 +270,18 @@
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkHBox" id="hbox1">
<object class="GtkAlignment" id="TaskChooserBox">
<property name="visible">True</property>
<property name="spacing">3</property>
<child>
<object class="GtkFrame" id="TaskModelsFram">
<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="left_padding">12</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
<object class="GtkViewport" id="viewport1">
<property name="visible">True</property>
<property name="resize_mode">queue</property>
<property name="shadow_type">etched-out</property>
<child>
<object class="GtkTreeView" id="Models">
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">ModelsList</property>
<property name="headers_visible">False</property>
<property name="headers_clickable">False</property>
<property name="search_column">0</property>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title">column</property>
<property name="spacing">3</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="TaskModelsFrame">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Models&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
<property name="label" translatable="yes">Task type:</property>
</object>
<packing>
<property name="expand">False</property>
......@@ -312,260 +289,39 @@
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator1">
<object class="GtkComboBox" id="TaskTypeSelector">
<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="ComponentsFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkTable" id="table9">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="column_spacing">5</property>
<property name="row_spacing">3</property>
<property name="model">TaskTypeList</property>
<child>
<object class="GtkLabel" id="TaskToolLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Tool:</property>
</object>
<packing>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="TaskProcessLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Process:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="TaskBoundsLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Bounds:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="ToolSelector">
<property name="visible">True</property>
<property name="model">ToolList</property>
<child>
<object class="GtkCellRendererText" id="ToolListCell"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="ProcessSelector">
<property name="visible">True</property>
<property name="model">ProcessList</property>
<child>
<object class="GtkCellRendererText" id="ProcessListCell"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="BoundsSelector">
<property name="visible">True</property>
<property name="model">BoundsList</property>
<child>
<object class="GtkCellRendererText" id="BoundsListCell"/>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">1</attribute>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="ComponentsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Components&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>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator2">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame12">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment19">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="top_padding">3</property>
<property name="left_padding">12</property>
<child>
<object class="GtkTable" id="table5">
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="column_spacing">4</property>
<property name="row_spacing">4</property>
<child>
<object class="GtkLabel" id="FeedrateLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Feedrate:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="SpindleSpeedLabel">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Spindle Speed:</property>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="FeedrateControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="adjustment">feedrate</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="SpindleSpeedControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="adjustment">speed</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="SpeedLimitsUnitLabel">
<object class="GtkHBox" id="TaskParameterBox">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Unit:</property>
</object>
</child>
<property name="spacing">5</property>
<child>
<object class="GtkLabel" id="SpeedUnit">
<property name="visible">True</property>
<property name="label" translatable="yes">inches/minute</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="ProcessingSpeedLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Speed&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
</object>
......
......@@ -222,7 +222,7 @@
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment1">
<object class="GtkAlignment" id="ToolSelectorBox">
<property name="visible">True</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
......@@ -267,7 +267,7 @@
<child>
<object class="GtkHBox" id="ToolParameterBox">
<property name="visible">True</property>
<property name="spacing">3</property>
<property name="spacing">5</property>
<child>
<placeholder/>
</child>
......
......@@ -31,7 +31,7 @@ _GTK_COLOR_MAX = 65535.0
class Models(pycam.Plugins.ListPluginBase):
UI_FILE = "models.ui"
COLUMN_ID, COLUMN_NAME, COLUMN_VISIBLE, COLUMN_COLOR, COLUMN_ALPHA = range(5)
COLUMN_REF, COLUMN_NAME, COLUMN_VISIBLE, COLUMN_COLOR, COLUMN_ALPHA = range(5)
LIST_ATTRIBUTE_MAP = {"name": COLUMN_NAME, "visible": COLUMN_VISIBLE,
"color": COLUMN_COLOR, "alpha": COLUMN_ALPHA}
ICONS = {"visible": "visible.svg", "hidden": "visible_off.svg"}
......@@ -78,7 +78,7 @@ class Models(pycam.Plugins.ListPluginBase):
self._model_cache = {}
cache = self._model_cache
for row in self._treemodel:
cache[row[self.COLUMN_ID]] = list(row)
cache[row[self.COLUMN_REF]] = list(row)
self._treemodel.clear()
for index, item in enumerate(self):
if id(item) in cache:
......
......@@ -267,6 +267,9 @@ class ParameterSectionGTK(object):
widget.set_label(param["label"])
self._table.attach(widget, 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
elif not param["label"]:
self._table.attach(widget, 0, 2, index, index + 1,
xoptions=gtk.FILL, yoptions=gtk.FILL)
else:
# spinbutton, combobox, ...
label = gtk.Label("%s:" % param["label"])
......
......@@ -33,7 +33,7 @@ class PathParamOverlap(pycam.Plugins.PluginBase):
# configure the input/output converter
widget = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
increment=10, change_handler=lambda widget=None: \
self.core.emit_event("process-parameter-changed"))
self.core.emit_event("process-changed"))
widget.set_conversion(
set_conv=lambda float_value: int(float_value * 100.0),
get_conv=lambda percent: percent / 100.0)
......@@ -53,7 +53,7 @@ class PathParamStepDown(pycam.Plugins.PluginBase):
def setup(self):
widget = pycam.Gui.ControlsGTK.InputNumber(lower=0.01, upper=1000,
digits=2, start=1, change_handler=lambda widget=None: \
self.core.emit_event("process-parameter-changed"))
self.core.emit_event("process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"step_down", "Step down", widget, weight=20)
return True
......@@ -70,7 +70,7 @@ class PathParamMaterialAllowance(pycam.Plugins.PluginBase):
def setup(self):
widget = pycam.Gui.ControlsGTK.InputNumber(start=0, lower=0, upper=100,
digits=2, change_handler=lambda widget=None: \
self.core.emit_event("process-parameter-changed"))
self.core.emit_event("process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"material_allowance", "Material allowance", widget, weight=30)
return True
......@@ -90,7 +90,7 @@ class PathParamMillingStyle(pycam.Plugins.PluginBase):
("climb / down", "climb"),
("conventional / up", "conventional")),
change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed"))
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"milling_style", "Milling style", input_control, weight=50)
return True
......@@ -108,7 +108,7 @@ class PathParamGridDirection(pycam.Plugins.PluginBase):
input_control = pycam.Gui.ControlsGTK.InputChoice(
(("x", "x"), ("y", "y"), ("xy", "xy")),
change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed"))
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"grid_direction", "Direction", input_control, weight=40)
return True
......@@ -125,7 +125,7 @@ class PathParamRadiusCompensation(pycam.Plugins.PluginBase):
def setup(self):
widget = pycam.Gui.ControlsGTK.InputCheckBox(
change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed"))
"process-changed"))
self.core.get("register_parameter")("process", "pathgenerator",
"radius_compensation", "Radius compensation", widget, weight=80)
return True
......@@ -140,10 +140,9 @@ class PathParamTraceModel(pycam.Plugins.PluginBase):
DEPENDS = ["Processes", "Models"]
def setup(self):
# TODO: check if gtk is in use
self.input_control = pycam.Gui.ControlsGTK.InputTable([], force_type=long,
change_handler=lambda widget=None: self.core.emit_event(
"process-parameter-changed"))
self.input_control = pycam.Gui.ControlsGTK.InputTable([],
force_type=long, change_handler=lambda widget=None: \
self.core.emit_event("process-changed"))
# configure the input/output converter
def get_converter(model_refs):
models_dict = {}
......
......@@ -101,7 +101,7 @@ class Processes(pycam.Plugins.ListPluginBase):
self.register_model_update(update_model)
self.core.register_event("process-selection-changed",
self._process_switch)
self.core.register_event("process-parameter-changed",
self.core.register_event("process-changed",
self._store_process_settings)
self.core.register_event("process-strategy-changed",
self._store_process_settings)
......@@ -166,6 +166,11 @@ class Processes(pycam.Plugins.ListPluginBase):
self.pop(index)
# show "new" only if a strategy is available
self.gui.get_object("ProcessNew").set_sensitive(len(model) > 0)
selector_box = self.gui.get_object("ProcessSelectorBox")
if len(model) < 2:
selector_box.hide()
else:
selector_box.show()
def _get_strategy(self, name=None):
strategies = self.core.get("get_parameter_sets")("process")
......@@ -212,7 +217,7 @@ class Processes(pycam.Plugins.ListPluginBase):
if not process:
control_box.hide()
else:
self.core.block_event("process-parameter-changed")
self.core.block_event("process-changed")
self.core.block_event("process-strategy-changed")
strategy_name = process["strategy"]
self.select_strategy(strategy_name)
......@@ -220,7 +225,7 @@ class Processes(pycam.Plugins.ListPluginBase):
self.core.get("set_parameter_values")("process", process["parameters"])
control_box.show()
self.core.unblock_event("process-strategy-changed")
self.core.unblock_event("process-parameter-changed")
self.core.unblock_event("process-changed")
self.core.emit_event("process-strategy-changed")
def _process_new(self, *args):
......
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
import pycam.Gui.ControlsGTK
class TaskParamCollisionModels(pycam.Plugins.PluginBase):
DEPENDS = ["Models", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputTable([],
force_type=long, change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
# 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.input_control.set_conversion(set_conv=set_converter,
get_conv=get_converter)
self.input_control.get_widget().set_size_request(240, -1)
self.core.get("register_parameter")("task", "models",
"collision_models", "", self.input_control,
weight=5)
self.core.register_event("model-list-changed", self._update_models)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "models",
"collision_models")
def _update_models(self):
choices = []
models = self.core.get("models")
for model in models:
if hasattr(model, "triangles"):
choices.append((models.get_attr(model, "name"), id(model)))
self.input_control.update_choices(choices)
class TaskParamTool(pycam.Plugins.PluginBase):
DEPENDS = ["Tools", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
force_type=long, change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.core.get("register_parameter")("task", "components", "tool",
"Tool", self.input_control, weight=10)
self.core.register_event("tool-list-changed", self._update_tools)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "tool")
def _update_tools(self):
choices = []
tools = self.core.get("tools")
for tool in tools:
choices.append((tools.get_attr(tool, "name"), id(tool)))
self.input_control.update_choices(choices)
class TaskParamProcess(pycam.Plugins.PluginBase):
DEPENDS = ["Processes", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
force_type=long, change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.core.get("register_parameter")("task", "components", "process",
"Process", self.input_control, weight=20)
self.core.register_event("process-list-changed", self._update_processes)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "process")
def _update_processes(self):
choices = []
processes = self.core.get("processes")
for process in processes:
choices.append((processes.get_attr(process, "name"), id(process)))
self.input_control.update_choices(choices)
class TaskParamBounds(pycam.Plugins.PluginBase):
DEPENDS = ["Bounds", "Tasks"]
def setup(self):
self.input_control = pycam.Gui.ControlsGTK.InputChoice([],
force_type=long, change_handler=lambda widget=None: \
self.core.emit_event("task-changed"))
self.core.get("register_parameter")("task", "components", "bounds",
"Bounds", self.input_control, weight=30)
self.core.register_event("bounds-list-changed", self._update_bounds)
return True
def teardown(self):
self.core.get("unregister_parameter")("task", "components", "bounds")
def _update_bounds(self):
choices = []
bounds = self.core.get("bounds")
for bound in bounds:
choices.append((bounds.get_attr(bound, "name"), id(bound)))
self.input_control.update_choices(choices)
# -*- coding: utf-8 -*-
"""
$Id$
Copyright 2011 Lars Kruse <devel@sumpfralle.de>
This file is part of PyCAM.
PyCAM 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
import pycam.Plugins
class TaskTypeMilling(pycam.Plugins.PluginBase):
DEPENDS = ["Tasks", "TaskParamCollisionModels", "TaskParamTool",
"TaskParamProcess", "TaskParamBounds"]
def setup(self):
parameters = {"collision_models": [],
"tool": None,
"process": None,
"bounds": None,
}
self.core.get("register_parameter_set")("task", "milling",
"Milling", self.run_task, parameters=parameters,
weight=10)
return True
def teardown(self):
self.core.get("unregister_parameter_set")("task", "milling")
def run_task(self):
pass
......@@ -25,16 +25,6 @@ import time
import pycam.Plugins
import pycam.Utils
from pycam.Exporters.GCodeExporter import GCodeGenerator
from pycam.Toolpath.MotionGrid import MILLING_STYLE_IGNORE, \
MILLING_STYLE_CONVENTIONAL, MILLING_STYLE_CLIMB, GRID_DIRECTION_X, \
GRID_DIRECTION_Y, GRID_DIRECTION_XY, get_lines_grid, get_fixed_grid
import pycam.PathProcessors.SimpleCutter
import pycam.PathGenerators.PushCutter
import pycam.PathProcessors.ContourCutter
import pycam.PathGenerators.ContourFollow
import pycam.PathProcessors.PathAccumulator
import pycam.PathGenerators.DropCutter
import pycam.PathGenerators.EngraveCutter
class Tasks(pycam.Plugins.ListPluginBase):
......@@ -59,9 +49,40 @@ class Tasks(pycam.Plugins.ListPluginBase):
self.gui.get_object(obj_name))
self.gui.get_object("TaskNew").connect("clicked",
self._task_new)
# parameters
parameters_box = self.gui.get_object("TaskParameterBox")
def clear_parameter_widgets():
parameters_box.foreach(
lambda widget: parameters_box.remove(widget))
def add_parameter_widget(item, name):
# create a frame within an alignment and the item inside
frame_label = gtk.Label()
frame_label.set_markup("<b>%s</b>" % name)
frame = gtk.Frame()
frame.set_label_widget(frame_label)
align = gtk.Alignment()
frame.add(align)
align.set_padding(0, 3, 12, 3)
align.add(item)
frame.show_all()
parameters_box.pack_start(frame, expand=False)
self.core.register_ui_section("task_parameters",
add_parameter_widget, clear_parameter_widgets)
self.core.get("register_parameter_group")("task",
changed_set_event="task-type-changed",
changed_set_list_event="task-type-list-changed",
get_current_set_func=self._get_type)
models_parameter_widget = self.core.get(
"register_parameter_section")("task", "models")
self.core.register_ui("task_parameters", "Collision models",
models_parameter_widget, weight=20)
components_parameter_widget = self.core.get(
"register_parameter_section")("task", "components")
self.core.register_ui("task_parameters", "Components",
components_parameter_widget, weight=10)
# handle table events
self.core.register_event("task-selection-changed",
self._switch_task)
self._task_switch)
self.gui.get_object("TaskNameCell").connect("edited",
self._edit_task_name)
selection = self._taskview.get_selection()
......@@ -90,32 +111,19 @@ class Tasks(pycam.Plugins.ListPluginBase):
else:
self._treemodel.append((id(item), "Task #%d" % index))
self.core.emit_event("task-list-changed")
self._detail_handlers = []
for obj_name in ("FeedrateControl", "SpindleSpeedControl"):
obj = self.gui.get_object(obj_name)
handler = obj.connect("value-changed",
lambda widget: self.core.emit_event("task-changed"))
self._detail_handlers.append((obj, handler))
self.gui.get_object("Models").get_selection().set_mode(
self._gtk.SELECTION_MULTIPLE)
for obj_name in ("Models", "ToolSelector", "ProcessSelector", "BoundsSelector"):
obj = self.gui.get_object(obj_name)
obj.get_model().clear()
if hasattr(obj, "get_selection"):
obj = obj.get_selection()
handler = obj.connect("changed",
lambda widget: self.core.emit_event("task-changed"))
self._detail_handlers.append((obj, handler))
for category, event in (("models", "model-list-changed"),
("tool", "tool-list-changed"),
("process", "process-list-changed"),
("bounds", "bounds-list-changed")):
self.core.register_event(event, self._update_external_model,
category)
self._update_external_model(category)
# shape selector
type_selector = self.gui.get_object("TaskTypeSelector")
type_selector.connect("changed", lambda widget: \
self.core.emit_event("task-type-changed"))
self.core.register_event("task-type-list-changed",
self._update_widgets)
self.core.register_event("task-selection-changed",
self._task_switch)
self.core.register_event("task-changed", self._store_task)
self.core.register_event("task-type-changed", self._store_task)
self.register_model_update(update_model)
self._switch_task()
self._update_widgets()
self._task_switch()
self.core.set("tasks", self)
return True
......@@ -123,53 +131,24 @@ class Tasks(pycam.Plugins.ListPluginBase):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("TaskBox"))
self.core.unregister_event("task-selection-changed",
self._switch_task)
self._task_switch)
self.core.unregister_event("task-selection-changed",
self._switch_task)
self._task_switch)
self.core.unregister_event("task-changed", self._store_task)
def _get_modelview_and_content(self, category):
model = {None: self._taskview,
"tool": self.gui.get_object("ToolSelector"),
"process": self.gui.get_object("ProcessSelector"),
"bounds": self.gui.get_object("BoundsSelector"),
"models": self.gui.get_object("Models")}[category]
content = {None: self,
"tool": self.core.get("tools"),
"process": self.core.get("processes"),
"bounds": self.core.get("bounds"),
"models": self.core.get("models")}[category]
return model, content
def get_selected(self, category=None, index=False):
modelview, content = self._get_modelview_and_content(category)
return self._get_selected(modelview, index=index, content=content)
def get_selected(self, index=False):
return self._get_selected(self._taskview, index=index)
def select(self, item, category=None, keep=False):
if isinstance(item, list):
keep = False
if not item:
self.select(None, category=category)
else:
for one in item:
self.select(one, category=category, keep=keep)
keep = True
else:
modelview, content = self._get_modelview_and_content(category)
if (item is None) or (item in content):
if not item is None:
index = [id(entry) for entry in content].index(id(item))
if hasattr(modelview, "get_selection"):
selection = modelview.get_selection()
if not keep:
selection.unselect_all()
if not item is None:
def select(self, tasks):
print "Tasks: %s" % str(tasks)
selection = self._taskview.get_selection()
if not isinstance(tasks, (list, tuple)):
tasks = [tasks]
for index, task in enumerate(self):
if task in tasks:
selection.select_path((index,))
else:
if item is None:
modelview.set_active(-1)
else:
modelview.set_active(index)
selection.unselect_path((index,))
def _edit_task_name(self, cell, path, new_text):
path = int(path)
......@@ -177,70 +156,94 @@ class Tasks(pycam.Plugins.ListPluginBase):
new_text:
self._treemodel[path][self.COLUMN_NAME] = new_text
def _switch_task(self):
tasks = self.get_selected()
if tasks:
task = tasks[0]
def _get_type(self, name=None):
types = self.core.get("get_parameter_sets")("task")
if name is None:
# find the currently selected one
selector = self.gui.get_object("TaskTypeSelector")
model = selector.get_model()
index = selector.get_active()
if index < 0:
return None
type_name = model[index][1]
else:
task = None
details_box = self.gui.get_object("TaskDetails")
if task:
# block all "change" signals for the task controls
for obj, signal_handler in self._detail_handlers:
obj.handler_block(signal_handler)
for key in ("tool", "process", "bounds", "models"):
self.select(task[key], category=key)
self.gui.get_object("FeedrateControl").set_value(task["feedrate"])
self.gui.get_object("SpindleSpeedControl").set_value(task["spindlespeed"])
# unblock the signals again
for obj, signal_handler in self._detail_handlers:
obj.handler_unblock(signal_handler)
details_box.show()
type_name = name
if type_name in types:
return types[type_name]
else:
details_box.hide()
return None
def _store_task(self, widget=None):
def select_type(self, name):
selector = self.gui.get_object("TaskTypeSelector")
for index, row in enumerate(selector.get_model()):
if row[1] == name:
selector.set_active(index)
break
else:
selector.set_active(-1)
def _update_widgets(self):
model = self.gui.get_object("TaskTypeList")
model.clear()
types = self.core.get("get_parameter_sets")("task").values()
types.sort(key=lambda item: item["weight"])
for one_type in types:
model.append((one_type["label"], one_type["name"]))
# check if any on the processes became obsolete due to a missing plugin
removal = []
type_names = [one_type["name"] for one_type in types]
for index, task in enumerate(self):
if not task["type"] in tape_names:
removal.append(index)
removal.reverse()
for index in removal:
self.pop(index)
# show "new" only if a strategy is available
self.gui.get_object("TaskNew").set_sensitive(len(model) > 0)
selector_box = self.gui.get_object("TaskChooserBox")
if len(model) < 2:
selector_box.hide()
else:
selector_box.show()
def _task_switch(self):
tasks = self.get_selected()
if tasks:
task = tasks[0]
control_box = self.gui.get_object("TaskDetails")
if len(tasks) != 1:
control_box.hide()
else:
task = None
task = tasks[0]
self.core.block_event("task-changed")
self.core.block_event("task-type-changed")
type_name = task["type"]
self.select_type(type_name)
one_type = self._get_type(type_name)
self.core.get("set_parameter_values")("task", task["parameters"])
control_box.show()
self.core.unblock_event("task-type-changed")
self.core.unblock_event("task-changed")
# trigger a widget update
self.core.emit_event("task-type-changed")
def _store_task(self, widget=None):
tasks = self.get_selected()
details_box = self.gui.get_object("TaskDetails")
if task is None:
task_type = self._get_type()
if (len(tasks) != 1) or not task_type:
details_box.hide()
return
else:
task["feedrate"] = self.gui.get_object("FeedrateControl").get_value()
task["spindlespeed"] = self.gui.get_object("SpindleSpeedControl").get_value()
for key in ("tool", "process", "bounds", "models"):
task[key] = self.get_selected(category=key)
task = tasks[0]
task["type"] = task_type["name"]
parameters = task["parameters"]
parameters.update(self.core.get("get_parameter_values")("task"))
details_box.show()
def _update_external_model(self, category):
modelview, content = self._get_modelview_and_content(category)
ids = [id(item) for item in content]
model = modelview.get_model()
for index, one_id in enumerate(ids):
while (len(model) > index) and \
(model[index][self.COLUMN_REF] != one_id):
index_iter = model.get_iter((index, ))
if model[index][self.COLUMN_REF] in ids:
# move it to the end of the list
model.move_before(index_iter, None)
else:
model.remove(index_iter)
if len(model) <= index:
name = content.get_attr(content[index], "name", id_col=self.COLUMN_REF)
model.append((one_id, name))
def _task_new(self, *args):
new_task = {
"models": [],
"tool": [],
"process": [],
"bounds": [],
"feedrate": 300,
"spindlespeed": 1000,
types = self.core.get("get_parameter_sets")("task").values()
types.sort(key=lambda item: item["weight"])
one_type = types[0]
new_task = {"type": one_type["name"],
"parameters": one_type["parameters"].copy(),
}
self.append(new_task)
self.select(new_task)
......@@ -262,58 +265,6 @@ class Tasks(pycam.Plugins.ListPluginBase):
def _generate_all_toolpaths(self, widget=None):
self.generate_toolpaths(self)
def _get_path_generator(self, process):
if process["PushRemoveStrategy"]:
processor = pycam.PathProcessors.SimpleCutter.SimpleCutter
generator = pycam.PathGenerators.PushCutter.PushCutter
elif process["ContourPolygonStrategy"]:
processor = pycam.PathProcessors.ContourCutter.ContourCutter
generator = pycam.PathGenerators.PushCutter.PushCutter
elif process["ContourFollowStrategy"]:
processor = pycam.PathProcessors.SimpleCutter.SimpleCutter
generator = pycam.PathGenerators.ContourFollow.ContourFollow
elif process["SurfaceStrategy"]:
processor = pycam.PathProcessors.PathAccumulator.PathAccumulator
generator = pycam.PathGenerators.DropCutter.DropCutter
elif process["EngraveStrategy"]:
processor = pycam.PathProcessors.SimpleCutter.SimpleCutter
generator = pycam.PathGenerators.EngraveCutter.EngraveCutter
else:
self.log.error("Unknown path strategy: %s" % str(process))
return
# TODO: "physics" should be set, as well
return generator(processor(), physics=None)
def _get_motion_grid(self, tool, process, bounds, models):
step_width = float(tool.radius) / 4.0
milling_style_map = {
"MillingStyleConventional": MILLING_STYLE_CONVENTIONAL,
"MillingStyleClimb": MILLING_STYLE_CLIMB,
"MillingStyleIgnore": MILLING_STYLE_IGNORE,
}
for key in milling_style_map:
if process[key]:
milling_style = milling_style_map[key]
break
grid_direction_map = {"GridDirectionX": GRID_DIRECTION_X,
"GridDirectionY": GRID_DIRECTION_Y,
"GridDirectionXY": GRID_DIRECTION_XY,
}
for key in grid_direction_map:
if process[key]:
grid_direction = grid_direction_map[key]
break
line_distance = 2 * float(tool.radius) * \
(1 - 0.01 * float(process["OverlapPercent"]))
# TODO: handle offset and pocketing
if process["EngraveStrategy"]:
return get_lines_grid(models, bounds, process["MaxStepDown"],
step_width=step_width, milling_style=milling_style)
else:
return get_fixed_grid(bounds, process["MaxStepDown"],
line_distance=line_distance, grid_direction=grid_direction,
milling_style=milling_style)
def generate_toolpath(self, task, progress=None):
models = task["models"]
tool = task["tool"]
......
......@@ -32,7 +32,7 @@ class ToolParamRadius(pycam.Plugins.PluginBase):
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
change_handler=lambda widget=None: self.core.emit_event(
"tool-parameter-changed"))
"tool-changed"))
control.set_conversion(set_conv=lambda value: value * 2.0,
get_conv=lambda value: value / 2.0)
self.core.get("register_parameter")("tool", "size", "radius",
......@@ -50,7 +50,7 @@ class ToolParamTorusRadius(pycam.Plugins.PluginBase):
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=99, digits=0,
change_handler=lambda widget=None: self.core.emit_event(
"tool-parameter-changed"))
"tool-changed"))
self.core.get("register_parameter")("tool", "size", "torus_radius",
"Torus radius", control, weight=20)
return True
......@@ -66,7 +66,7 @@ class ToolParamFeedrate(pycam.Plugins.PluginBase):
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=10000,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-parameter-changed"))
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "feedrate",
"Feedrate", control, weight=10)
return True
......@@ -82,7 +82,7 @@ class ToolParamSpindleSpeed(pycam.Plugins.PluginBase):
def setup(self):
control = pycam.Gui.ControlsGTK.InputNumber(lower=0, upper=100000,
digits=0, change_handler=lambda widget=None: \
self.core.emit_event("tool-parameter-changed"))
self.core.emit_event("tool-changed"))
self.core.get("register_parameter")("tool", "speed", "spindle_speed",
"Spindle speed", control, weight=20)
return True
......
......@@ -51,10 +51,7 @@ class Tools(pycam.Plugins.ListPluginBase):
parameters_box.foreach(
lambda widget: parameters_box.remove(widget))
def add_parameter_widget(item, name):
# create a frame with an align and the item inside
if len(parameters_box.get_children()) > 0:
# add a separator between two content blocks
parameters_box.pack_start(gtk.VSeparator())
# create a frame within an alignment and the item inside
frame_label = gtk.Label()
frame_label.set_markup("<b>%s</b>" % name)
frame = gtk.Frame()
......@@ -67,7 +64,6 @@ class Tools(pycam.Plugins.ListPluginBase):
parameters_box.pack_start(frame, expand=True)
self.core.register_ui_section("tool_parameters",
add_parameter_widget, clear_parameter_widgets)
selector = self.gui.get_object("ToolShapeSelector")
self.core.get("register_parameter_group")("tool",
changed_set_event="tool-shape-changed",
changed_set_list_event="tool-shape-list-changed",
......@@ -80,6 +76,7 @@ class Tools(pycam.Plugins.ListPluginBase):
"tool", "speed")
self.core.register_ui("tool_parameters", "Speed",
speed_parameter_widget, weight=20)
# table updates
cell = self.gui.get_object("ToolTableShapeCell")
self.gui.get_object("ToolTableShapeColumn").set_cell_data_func(
cell, self._render_tool_shape)
......@@ -107,20 +104,21 @@ class Tools(pycam.Plugins.ListPluginBase):
selection.connect("changed",
lambda widget, event: self.core.emit_event(event),
"tool-selection-changed")
# shape selector
shape_selector = self.gui.get_object("ToolShapeSelector")
shape_selector.connect("changed", lambda widget: \
self.core.emit_event("tool-shape-changed"))
self.core.register_event("tool-shape-list-changed",
self._update_widgets)
self.register_model_update(update_model)
self.core.register_event("tool-selection-changed",
self._tool_change)
self.core.register_event("tool-parameter-changed",
self._tool_switch)
self.core.register_event("tool-changed",
self._store_tool_settings)
self.core.register_event("tool-shape-changed",
self._store_tool_settings)
self.register_model_update(update_model)
self._update_widgets()
self._tool_change()
self._tool_switch()
self.core.set("tools", self)
return True
......@@ -128,7 +126,7 @@ class Tools(pycam.Plugins.ListPluginBase):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolBox"))
self.core.unregister_event("tool-selection-changed",
self._tool_change)
self._tool_switch)
self.core.set("tools", None)
return True
......@@ -201,10 +199,9 @@ class Tools(pycam.Plugins.ListPluginBase):
cell.set_cell_data_func(renderer, self._render_tool_shape)
def _update_widgets(self):
# TODO: keep the current selection
model = self.gui.get_object("ToolShapeList")
model.clear()
shapes = list(self.core.get("get_parameter_sets")("tool").values())
shapes = self.core.get("get_parameter_sets")("tool").values()
shapes.sort(key=lambda item: item["weight"])
for shape in shapes:
model.append((shape["label"], shape["name"]))
......@@ -219,6 +216,11 @@ class Tools(pycam.Plugins.ListPluginBase):
self.pop(index)
# show "new" only if a strategy is available
self.gui.get_object("ToolNew").set_sensitive(len(model) > 0)
selector_box = self.gui.get_object("ToolSelectorBox")
if len(model) < 2:
selector_box.hide()
else:
selector_box.show()
def _store_tool_settings(self):
tool = self.get_selected()
......@@ -233,13 +235,13 @@ class Tools(pycam.Plugins.ListPluginBase):
control_box.show()
self._trigger_table_update()
def _tool_change(self, widget=None, data=None):
def _tool_switch(self, widget=None, data=None):
tool = self.get_selected()
control_box = self.gui.get_object("ToolSettingsControlsBox")
if not tool:
control_box.hide()
else:
self.core.block_event("tool-parameter-changed")
self.core.block_event("tool-changed")
self.core.block_event("tool-shape-changed")
shape_name = tool["shape"]
self.select_shape(shape_name)
......@@ -247,7 +249,7 @@ class Tools(pycam.Plugins.ListPluginBase):
self.core.get("set_parameter_values")("tool", tool["parameters"])
control_box.show()
self.core.unblock_event("tool-shape-changed")
self.core.unblock_event("tool-parameter-changed")
self.core.unblock_event("tool-changed")
# trigger a widget update
self.core.emit_event("tool-shape-changed")
......@@ -260,3 +262,4 @@ class Tools(pycam.Plugins.ListPluginBase):
}
self.append(new_tool)
self.select(new_tool)
......@@ -405,7 +405,7 @@ class ListPluginBase(PluginBase, list):
# TODO: "self.treemodel" should not be used here
model = self._treemodel
if id_col is None:
id_col = self.COLUMN_ID
id_col = self.COLUMN_REF
if attr in self.LIST_ATTRIBUTE_MAP:
col = self.LIST_ATTRIBUTE_MAP[attr]
for index in range(len(model)):
......
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