Commit 0e05bf87 authored by sumpfralle's avatar sumpfralle

separated EMC tool exporter to a plugin


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@1166 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent dbe030cb
<?xml version="1.0"?>
<interface>
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide -->
<object class="GtkAction" id="ExportEMCToolDefinition">
<property name="label">_Export tools for EMC2 ...</property>
<property name="short_label">_Export tools for EMC2 ...</property>
</object>
</interface>
......@@ -6,6 +6,8 @@
<menuitem action="SaveModel"/>
<menuitem action="SaveAsModel"/>
<separator />
<menu action="ExportMenu" />
<separator />
</menu>
<menu action="EditMenu">
<menuitem action="UndoButton"/>
......@@ -16,8 +18,6 @@
<menuitem action="SaveTaskSettings"/>
<menuitem action="SaveAsTaskSettings"/>
<separator />
<menuitem action="ExportEMCToolDefinition"/>
<separator />
<menuitem action="GeneralSettings"/>
</menu>
<menu action="ViewMenu" />
......
......@@ -1936,9 +1936,6 @@ You should have received a copy of the GNU General Public License along with thi
<property name="label">_About</property>
<property name="stock_id">gtk-about</property>
</object>
<object class="GtkAction" id="ExportEMCToolDefinition">
<property name="label">_Export EMC tools ...</property>
</object>
<object class="GtkAction" id="HelpMenu">
<property name="label">_Help</property>
</object>
......@@ -2091,4 +2088,8 @@ You should have received a copy of the GNU General Public License along with thi
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<object class="GtkAction" id="ExportMenu">
<property name="label">_Export</property>
<property name="short_label">_Export</property>
</object>
</interface>
......@@ -2,17 +2,6 @@
<interface>
<!-- interface-requires gtk+ 2.12 -->
<!-- interface-naming-policy project-wide -->
<object class="GtkAction" id="ExportGCodeSelected">
<property name="label">Export _selected Toolpaths ...</property>
<property name="short_label">Export _selected Toolpaths ...</property>
<property name="tooltip">Write all selected toolpaths to a file.</property>
</object>
<object class="GtkAction" id="ExportGCodeAll">
<property name="label">_Export all Toolpaths ...</property>
<property name="short_label">_Export all Toolpaths ...</property>
<property name="tooltip">Write all toolpaths to a file.</property>
<property name="stock_id">gtk-execute</property>
</object>
<object class="GtkListStore" id="ToolpathListModel">
<columns>
<!-- column-name ref -->
......
......@@ -25,17 +25,23 @@ import os
class EMCToolExporter(object):
def __init__(self, tools):
""" tools are expected to be dictionaries containing the following keys:
- id
- radius
- name
"""
self.tools = tools
def get_tool_definition_string(self):
result = []
tools = list(self.tools)
tools.sort(key=lambda item: item["id"])
#result.append(self.HEADER_ROW)
for index in range(len(self.tools)):
tool = self.tools[index]
for tool in tools:
# use an arbitrary length
tool_length = tool["tool_radius"] * 10
line = "T%d P%d D%f Z-%f ;%s" % (index + 1, index + 1,
2 * tool["tool_radius"], tool_length, tool["name"])
tool_length = tool["radius"] * 10
line = "T%d P%d D%f Z-%f ;%s" % (tool["id"], tool["id"],
2 * tool["radius"], tool_length, tool["name"])
result.append(line)
# add the dummy line for the "last" tool
result.append("T99999 P99999 Z+0.100000 ;dummy tool")
......
......@@ -36,7 +36,6 @@ import StringIO
import pickle
import logging
import pycam.Exporters.EMCToolExporter
import pycam.Gui.Settings
import pycam.Cutters
import pycam.Toolpath.Generator
......@@ -72,7 +71,6 @@ FILTER_MODEL = (("All supported model filetypes",
("STL models", "*.stl"), ("DXF contours", "*.dxf"),
("SVG contours", "*.svg"), ("PS contours", ("*.eps", "*.ps")))
FILTER_CONFIG = (("Config files", "*.conf"),)
FILTER_EMC_TOOL = (("EMC tool files", "*.tbl"),)
PREFERENCES_DEFAULTS = {
"enable_ode": False,
......@@ -374,7 +372,6 @@ class ProjectGui(object):
("OpenModel", self.load_model_file, None, "<Control>o"),
("SaveModel", self.save_model, lambda: self.last_model_uri, "<Control>s"),
("SaveAsModel", self.save_model, None, "<Control><Shift>s"),
("ExportEMCToolDefinition", self.export_emc_tools, None, None),
("Quit", self.destroy, None, "<Control>q"),
("GeneralSettings", self.toggle_preferences_window, None, "<Control>p"),
("UndoButton", self._restore_undo_state, None, "<Control>z"),
......@@ -424,10 +421,6 @@ class ProjectGui(object):
self.update_save_actions)
self.settings.register_event("model-change-after",
lambda: self.settings.emit_event("visual-item-updated"))
def update_emc_tool_button():
tool_num = len(self.settings.get("tools"))
self.gui.get_object("ExportEMCToolDefinition").set_sensitive(tool_num > 0)
self.settings.register_event("tool-selection-changed", update_emc_tool_button)
self.settings.set("load_model", self.load_model)
# set the availability of ODE
self.enable_ode_control = self.gui.get_object("SettingEnableODE")
......@@ -784,7 +777,8 @@ class ProjectGui(object):
return append_func, clear_func
for ui_name, base_path in (("view_menu", "/MenuBar/ViewMenu"),
("file_menu", "/MenuBar/FileMenu"),
("edit_menu", "/MenuBar/EditMenu")):
("edit_menu", "/MenuBar/EditMenu"),
("export_menu", "/MenuBar/FileMenu/ExportMenu")):
append_func, clear_func = get_menu_funcs(ui_name, base_path)
self.settings.register_ui_section(ui_name, append_func, clear_func)
self.settings.register_ui("file_menu", "Quit",
......@@ -795,6 +789,8 @@ class ProjectGui(object):
self.reset_preferences()
self.load_preferences()
self.load_task_settings()
self.settings.register_event("notify-file-saved",
self.add_to_recent_file_list)
# initialize plugins
self.plugin_manager = pycam.Plugins.PluginManager(core=self.settings)
self.plugin_manager.import_plugins()
......@@ -1228,25 +1224,6 @@ class ProjectGui(object):
log.error("Failed to detect filetype!")
return False
def export_emc_tools(self, widget=None, filename=None):
if callable(filename):
filename = filename()
if not filename:
filename = self.get_filename_via_dialog("Exporting EMC tool definition ...",
mode_load=False, type_filter=FILTER_EMC_TOOL,
filename_templates=(self.last_model_uri,))
if filename:
export = pycam.Exporters.EMCToolExporter.EMCToolExporter(self.settings.get("tools"))
text = export.get_tool_definition_string()
try:
out = file(filename, "w")
out.write(text)
out.close()
except IOError, err_msg:
log.error("Failed to save EMC tool file: %s" % err_msg)
else:
self.add_to_recent_file_list(filename)
def finish_startup(self):
""" This function is called by the pycam script after everything is
set up properly.
......
# -*- 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.Exporters.EMCToolExporter
FILTER_EMC_TOOL = (("EMC tool files", "*.tbl"),)
class EMCToolExport(pycam.Plugins.PluginBase):
UI_FILE = "emc_tool_export.ui"
DEPENDS = ["Tools"]
def setup(self):
self._last_emc_tool_file = None
if self.gui:
self.export_action = self.gui.get_object("ExportEMCToolDefinition")
self.register_gtk_accelerator("export", self.export_action, None,
"ExportEMCToolDefinition")
self.export_action.connect("activate", self.export_emc_tools)
self.core.register_ui("export_menu", "ExportEMCToolDefinition",
self.export_action, 80)
self.core.register_event("tool-selection-changed",
self._update_emc_tool_button)
self._update_emc_tool_button()
return True
def teardown(self):
if self.gui:
self.core.unregister_ui("export_menu", self.export_emc_tools)
self.unregister_gtk_accelerator("fonts", self.export_emc_tools)
self.core.unregister_event("tool-selection-changed",
self._update_emc_tool_button)
def _update_emc_tool_button(self, widget=None):
exportable = len(self.core.get("tools")) > 0
self.export_action.set_sensitive(exportable)
def export_emc_tools(self, widget=None, filename=None):
if callable(filename):
filename = filename()
if not filename:
# TODO: separate this away from Gui/Project.py
# TODO: implement "last_model_filename" in core
filename = self.core.get("get_filename_via_dialog")("Save toolpath to ...",
mode_load=False, type_filter=FILTER_EMC_TOOL,
filename_templates=(self._last_emc_tool_file,
self.core.get("last_model_filename")))
if filename:
self._last_emc_tool_file = filename
tools_dict = []
tools = self.core.get("tools")
for tool in tools:
tools_dict.append({"name": tools.get_attr(tool, "name"),
"id": tools.get_attr(tool, "id"),
"radius": tool["parameters"].get("radius", 1)})
export = pycam.Exporters.EMCToolExporter.EMCToolExporter(tools_dict)
text = export.get_tool_definition_string()
try:
out = file(filename, "w")
out.write(text)
out.close()
self.log.info("EMC tool file written: %s" % filename)
except IOError, err_msg:
self.log.error("Failed to save EMC tool file: %s" % err_msg)
else:
self.core.emit_event("notify-file-saved", filename)
......@@ -233,7 +233,5 @@ class ToolpathExport(pycam.Plugins.PluginBase):
except IOError, err_msg:
self.log.error("Failed to save toolpath file: %s" % err_msg)
else:
# TODO: add to recent file list
#self.add_to_recent_file_list(filename)
pass
self.core.emit_event("notify-file-saved", filename)
......@@ -105,10 +105,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
def teardown(self):
if self.gui:
self.core.unregister_ui("main", self.gui.get_object("ToolpathsBox"))
self.unregister_gtk_accelerator("toolpaths",
self.gui.get_object("ExportGCodeAll"))
self.unregister_gtk_accelerator("toolpaths",
self.gui.get_object("ExportGCodeSelected"))
self.core.unregister_event("toolpath-changed",
self._update_widgets)
self.core.unregister_event("toolpath-list-changed",
......@@ -140,11 +136,6 @@ class Toolpaths(pycam.Plugins.ListPluginBase):
self.tp_box.hide()
else:
self.tp_box.show()
# enable/disable the export menu item
self.gui.get_object("ExportGCodeAll").set_sensitive(len(toolpaths) > 0)
selected_toolpaths = self.get_selected()
self.gui.get_object("ExportGCodeSelected").set_sensitive(
len(selected_toolpaths) > 0)
def _trigger_toolpath_time_update(self):
self.gui.get_object("ToolpathTimeColumn").set_cell_data_func(
......
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