Commit 36c8141e authored by sumpfralle's avatar sumpfralle

fixed output tool IDs in GCode

added EMC tool definition export


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@279 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 0e2e3a56
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import pycam.Importers.STLImporter import pycam.Importers.STLImporter
import pycam.Exporters.STLExporter import pycam.Exporters.STLExporter
import pycam.Exporters.SimpleGCodeExporter import pycam.Exporters.SimpleGCodeExporter
import pycam.Exporters.EMCToolExporter
import pycam.Gui.Settings import pycam.Gui.Settings
import pycam.Gui.common as GuiCommon import pycam.Gui.common as GuiCommon
import pycam.Cutters import pycam.Cutters
...@@ -34,6 +35,7 @@ GTKMENU_FILE = "menubar.xml" ...@@ -34,6 +35,7 @@ GTKMENU_FILE = "menubar.xml"
FILTER_GCODE = ("GCode files", ("*.ngc", "*.nc", "*.gc", "*.gcode")) FILTER_GCODE = ("GCode files", ("*.ngc", "*.nc", "*.gc", "*.gcode"))
FILTER_MODEL = ("STL models", "*.stl") FILTER_MODEL = ("STL models", "*.stl")
FILTER_CONFIG = ("Config files", "*.conf") FILTER_CONFIG = ("Config files", "*.conf")
FILTER_EMC_TOOL = ("EMC tool files", "*.tbl")
BUTTON_ROTATE = gtk.gdk.BUTTON1_MASK BUTTON_ROTATE = gtk.gdk.BUTTON1_MASK
BUTTON_MOVE = gtk.gdk.BUTTON2_MASK BUTTON_MOVE = gtk.gdk.BUTTON2_MASK
...@@ -393,6 +395,7 @@ class ProjectGui: ...@@ -393,6 +395,7 @@ class ProjectGui:
("SaveModel", self.save_model, lambda: self.last_model_file, "<Control>s"), ("SaveModel", self.save_model, lambda: self.last_model_file, "<Control>s"),
("SaveAsModel", self.save_model, None, "<Control><Shift>s"), ("SaveAsModel", self.save_model, None, "<Control><Shift>s"),
("ExportGCode", self.save_toolpath, None, "<Control><Shift>e"), ("ExportGCode", self.save_toolpath, None, "<Control><Shift>e"),
("ExportEMCToolDefinition", self.export_emc_tools, None, None),
("Quit", self.destroy, None, "<Control>q"), ("Quit", self.destroy, None, "<Control>q"),
("GeneralSettings", self.toggle_settings_window, None, "<Control>p"), ("GeneralSettings", self.toggle_settings_window, None, "<Control>p"),
("Toggle3DView", self.toggle_3d_view, None, "<Control>v")): ("Toggle3DView", self.toggle_3d_view, None, "<Control>v")):
...@@ -628,7 +631,6 @@ class ProjectGui: ...@@ -628,7 +631,6 @@ class ProjectGui:
self.load_settings() self.load_settings()
self.update_toolpath_table() self.update_toolpath_table()
self.update_tool_table() self.update_tool_table()
self.update_tool_controls()
self.disable_invalid_process_settings() self.disable_invalid_process_settings()
self.update_process_table() self.update_process_table()
self.update_tasklist_table() self.update_tasklist_table()
...@@ -840,6 +842,7 @@ class ProjectGui: ...@@ -840,6 +842,7 @@ class ProjectGui:
if obj.get_value() == 0: if obj.get_value() == 0:
# set the value to the configured minimum # set the value to the configured minimum
obj.set_value(default_value) obj.set_value(default_value)
self.gui.get_object("ExportEMCToolDefinition").set_sensitive(len(self.tool_list) > 0)
@gui_activity_guard @gui_activity_guard
def toggle_about_window(self, widget=None, event=None, state=None): def toggle_about_window(self, widget=None, event=None, state=None):
...@@ -1049,7 +1052,7 @@ class ProjectGui: ...@@ -1049,7 +1052,7 @@ class ProjectGui:
if not new_index is None: if not new_index is None:
self.gui.get_object("ToolSettingsControlsBox").show() self.gui.get_object("ToolSettingsControlsBox").show()
self._put_tool_settings_to_gui(self.tool_list[new_index]) self._put_tool_settings_to_gui(self.tool_list[new_index])
self.update_tool_controls() self.update_tool_table()
else: else:
self.gui.get_object("ToolSettingsControlsBox").hide() self.gui.get_object("ToolSettingsControlsBox").hide()
...@@ -1097,6 +1100,7 @@ class ProjectGui: ...@@ -1097,6 +1100,7 @@ class ProjectGui:
else: else:
self.gui.get_object("ToolSettingsControlsBox").show() self.gui.get_object("ToolSettingsControlsBox").show()
# remove any broken tasks and update changed names # remove any broken tasks and update changed names
self.update_tool_controls()
self.update_tasklist_table() self.update_tasklist_table()
def update_unit_labels(self, widget=None, data=None): def update_unit_labels(self, widget=None, data=None):
...@@ -1233,6 +1237,24 @@ class ProjectGui: ...@@ -1233,6 +1237,24 @@ class ProjectGui:
if filename: if filename:
self.load_model(pycam.Importers.STLImporter.ImportModel(filename)) self.load_model(pycam.Importers.STLImporter.ImportModel(filename))
@gui_activity_guard
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)
if filename:
export = pycam.Exporters.EMCToolExporter.EMCToolExporter(self.tool_list)
text = export.get_tool_definition_string()
try:
out = file(filename, "w")
out.write(text)
out.close()
except IOError, err_msg:
if not no_dialog:
show_error_dialog(self.window, "Failed to save EMC tool file")
def open_settings_file(self, filename): def open_settings_file(self, filename):
""" This function is used by the commandline handler """ """ This function is used by the commandline handler """
self.last_settings_file = filename self.last_settings_file = filename
...@@ -1620,9 +1642,10 @@ class ProjectGui: ...@@ -1620,9 +1642,10 @@ class ProjectGui:
self.toolpath[-1].visible = False self.toolpath[-1].visible = False
# add the new toolpath # add the new toolpath
description = "%s / %s" % (tool_settings["name"], process_settings["name"]) description = "%s / %s" % (tool_settings["name"], process_settings["name"])
# the tool id numbering should start with 1 instead of zero
tool_id = self.tool_list.index(tool_settings) + 1
self.toolpath.add_toolpath(toolpath, self.toolpath.add_toolpath(toolpath,
description, description, self.cutter, tool_id,
self.cutter,
tool_settings["speed"], tool_settings["speed"],
tool_settings["feedrate"], tool_settings["feedrate"],
process_settings["material_allowance"], process_settings["material_allowance"],
...@@ -1634,10 +1657,6 @@ class ProjectGui: ...@@ -1634,10 +1657,6 @@ class ProjectGui:
# return "False" if the action was cancelled # return "False" if the action was cancelled
return not self._progress_cancel_requested return not self._progress_cancel_requested
# for compatibility with old pycam GUI (see pycamGUI)
# TODO: remove it in v0.3
generateToolpath = generate_toolpath
def get_filename_via_dialog(self, title, mode_load=False, type_filter=None): def get_filename_via_dialog(self, title, mode_load=False, type_filter=None):
# we open a dialog # we open a dialog
if mode_load: if mode_load:
......
...@@ -68,9 +68,9 @@ shape: CylindricalCutter ...@@ -68,9 +68,9 @@ shape: CylindricalCutter
tool_radius: 3 tool_radius: 3
[Tool1] [Tool1]
name: Spherical (0.1 inch) name: Spherical (0.5 inch)
shape: SphericalCutter shape: SphericalCutter
tool_radius: 1 tool_radius: 0.5
[Tool2] [Tool2]
name: Toroidal (2 inch) name: Toroidal (2 inch)
......
...@@ -153,27 +153,11 @@ class EmergencyDialog: ...@@ -153,27 +153,11 @@ class EmergencyDialog:
class ToolPathList(list): class ToolPathList(list):
def add_toolpath(self, toolpath, name, cutter, *args): def add_toolpath(self, toolpath, name, cutter, *args):
drill_id = self._get_drill_id(cutter) self.append(ToolPathInfo(toolpath, name, cutter, *args))
self.append(ToolPathInfo(toolpath, name, drill_id, cutter, *args))
def _get_drill_id(self, cutter):
used_ids = []
# check if a drill with the same dimensions was used before
for tp in self:
if tp.drill == cutter:
return tp.drill_id
else:
used_ids.append(tp.drill_id)
# find the smallest unused drill id
index = 1
while index in used_ids:
index += 1
return index
class ToolPathInfo: class ToolPathInfo:
def __init__(self, toolpath, name, drill_id, cutter, speed, feedrate, def __init__(self, toolpath, name, cutter, drill_id, speed, feedrate,
material_allowance, safety_height, unit, start_x, start_y, start_z): material_allowance, safety_height, unit, start_x, start_y, start_z):
self.toolpath = toolpath self.toolpath = toolpath
self.name = name self.name = name
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
<menuitem action="SaveSettings"/> <menuitem action="SaveSettings"/>
<menuitem action="SaveAsSettings"/> <menuitem action="SaveAsSettings"/>
<separator /> <separator />
<menuitem action="ExportEMCToolDefinition"/>
<separator />
<menuitem action="GeneralSettings"/> <menuitem action="GeneralSettings"/>
</menu> </menu>
<menu action="WindowMenu"> <menu action="WindowMenu">
......
...@@ -3987,4 +3987,8 @@ ODE is required for this setting.</property> ...@@ -3987,4 +3987,8 @@ ODE is required for this setting.</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-execute</property> <property name="stock">gtk-execute</property>
</object> </object>
<object class="GtkAction" id="ExportEMCToolDefinition">
<property name="label">_Export EMC tools</property>
<property name="stock_id">gtk-execute</property>
</object>
</interface> </interface>
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