Commit 051cf5b7 authored by sumpfralle's avatar sumpfralle

r577@erker: lars | 2010-02-05 00:01:02 +0100

 added "save model" action


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@100 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 096df4a2
......@@ -3,6 +3,7 @@
import OpenGL.GL as GL
import OpenGL.GLUT as GLUT
import pycam.Importers.STLImporter
import pycam.Exporters.STLExporter
import pycam.Gui.Settings
import pycam.Gui.common as GuiCommon
import pygtk
......@@ -117,6 +118,7 @@ class ProjectGui:
self.file_selector.connect("file-set",
self.load_model_file, self.file_selector.get_filename)
self.window.connect("destroy", self.destroy)
self.gui.get_object("SaveModel").connect("clicked", self.save_model)
self.window.show()
self.model = None
self.toolpath = None
......@@ -172,6 +174,61 @@ class ProjectGui:
GuiCommon.transform_model(self.model, value)
self.view3d.paint()
def save_model(self, widget):
no_dialog = False
if isinstance(widget, basestring):
filename = widget
no_dialog = True
else:
# we open a dialog
dialog = gtk.FileChooserDialog(title="Save model to ...",
parent=self.window, action=gtk.FILE_CHOOSER_ACTION_SAVE,
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
gtk.STOCK_SAVE, gtk.RESPONSE_OK))
# add filter for stl files
filter = gtk.FileFilter()
filter.set_name("STL models")
filter.add_pattern("*.stl")
dialog.add_filter(filter)
# add filter for all files
filter = gtk.FileFilter()
filter.set_name("All files")
filter.add_pattern("*")
dialog.add_filter(filter)
done = False
while not done:
response = dialog.run()
filename = dialog.get_filename()
dialog.hide()
if response == gtk.RESPONSE_CANCEL:
dialog.destroy()
return
if os.path.exists(filename):
overwrite_window = gtk.MessageDialog(self.window, type=gtk.MESSAGE_WARNING,
buttons=gtk.BUTTONS_YES_NO,
message_format="This file exists. Do you want to overwrite it?")
overwrite_window.set_title("Confirm overwriting existing file")
response = overwrite_window.run()
overwrite_window.destroy()
done = (response == gtk.RESPONSE_YES)
else:
done = True
dialog.destroy()
# no filename given -> exit
if not filename:
return
try:
fi = open(filename, "w")
pycam.Exporters.STLExporter.STLExporter(self.model).write(fi)
fi.close()
except IOError, err_msg:
if not no_dialog:
warn_window = gtk.MessageDialog(self.window, type=gtk.MESSAGE_ERROR,
buttons=gtk.BUTTONS_OK, message_format=str(err_msg))
warn_window.set_title("Failed to save model file")
warn_window.run()
warn_window.destroy()
def shift_model(self, widget, use_form_values=True):
if use_form_values:
shift_x = self.gui.get_object("shift_x").get_value()
......
......@@ -13,6 +13,9 @@
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">4</property>
<child>
<object class="GtkHBox" id="hbox4">
<property name="visible">True</property>
<child>
<object class="GtkFrame" id="File Selection">
<property name="visible">True</property>
......@@ -44,6 +47,53 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator6">
<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="frame5">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment13">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkButton" id="SaveModel">
<property name="label" translatable="yes">To File</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="SaveModelFrame">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Save Model&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="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator1">
<property name="visible">True</property>
......@@ -63,12 +113,13 @@
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkTable" id="Transformations">
<object class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">3</property>
<property name="column_spacing">4</property>
<property name="row_spacing">2</property>
<property name="spacing">3</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkVButtonBox" id="rotate directions">
<property name="visible">True</property>
......@@ -120,7 +171,40 @@
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Rotate">
<property name="label" translatable="yes">Rotate</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator3">
<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="GtkVBox" id="vbox4">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkVButtonBox" id="flip directions">
<property name="visible">True</property>
......@@ -172,10 +256,39 @@
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Flip">
<property name="label" translatable="yes">Flip</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator4">
<property name="visible">True</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox5">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkVButtonBox" id="swap directions">
<property name="visible">True</property>
......@@ -227,51 +340,23 @@
</child>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Rotate">
<property name="label" translatable="yes">Rotate</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Flip">
<property name="label" translatable="yes">Flip</property>
<object class="GtkButton" id="Swap">
<property name="label" translatable="yes">Swap</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</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="y_options">GTK_FILL</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="Swap">
<property name="label" translatable="yes">Swap</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">2</property>
<property name="right_attach">3</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
<property name="position">4</property>
</packing>
</child>
</object>
......@@ -391,6 +476,16 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator1">
<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="Shift Model Frame">
<property name="visible">True</property>
......@@ -536,7 +631,17 @@
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator2">
<property name="visible">True</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
......@@ -564,7 +669,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="width_chars">5</property>
<property name="adjustment">min-x</property>
<property name="digits">2</property>
<property name="numeric">True</property>
......@@ -583,7 +688,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="width_chars">5</property>
<property name="adjustment">max-y</property>
<property name="digits">2</property>
<property name="numeric">True</property>
......@@ -602,7 +707,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="width_chars">5</property>
<property name="adjustment">min-z</property>
<property name="digits">2</property>
<property name="numeric">True</property>
......@@ -621,7 +726,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="width_chars">5</property>
<property name="adjustment">max-z</property>
<property name="digits">2</property>
<property name="numeric">True</property>
......@@ -640,7 +745,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="width_chars">5</property>
<property name="adjustment">min-y</property>
<property name="digits">2</property>
<property name="numeric">True</property>
......@@ -659,7 +764,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="width_chars">4</property>
<property name="width_chars">5</property>
<property name="adjustment">max-x</property>
<property name="digits">2</property>
<property name="numeric">True</property>
......@@ -783,7 +888,7 @@
</child>
</object>
<packing>
<property name="position">2</property>
<property name="position">4</property>
</packing>
</child>
</object>
......@@ -805,7 +910,14 @@
</packing>
</child>
<child>
<object class="GtkFrame" id="frame1">
<object class="GtkVBox" id="ToolBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkHBox" id="ToolFileHandling">
<property name="visible">True</property>
<child>
<object class="GtkFrame" id="ToolFileLoadFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
......@@ -814,26 +926,280 @@
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
<object class="GtkFileChooserButton" id="ToolFileLoad">
<property name="visible">True</property>
<property name="create_folders">False</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label1">
<object class="GtkLabel" id="ToolFileLoadLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Load Tool Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVSeparator" id="vseparator5">
<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="ToolFileSaveFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment8">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkButton" id="ToolSaveFileButton">
<property name="label" translatable="yes">To File</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="ToolFileSaveFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;Save&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkNotebook" id="ToolsList">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tab_pos">left</property>
<property name="scrollable">True</property>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">5</property>
<child>
<object class="GtkFrame" id="frame1">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment9">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkComboBox" id="combobox1">
<property name="visible">True</property>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame1&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator6">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment10">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame2&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>
<child>
<object class="GtkHSeparator" id="hseparator5">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame3">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment11">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame3&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator4">
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="frame4">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment12">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<placeholder/>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;frame4&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">page 1</property>
</object>
<packing>
<property name="tab_fill">False</property>
<property name="reorderable">True</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="spacing">4</property>
<child>
<object class="GtkButton" id="AddToolButton">
<property name="label" translatable="yes">Add a Tool</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">Add foo</property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="RemoveToolButton">
<property name="label" translatable="yes">Remove this Tool</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="image">Remove foo</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="Tools">
<object class="GtkLabel" id="Tool">
<property name="visible">True</property>
<property name="label" translatable="yes">Tools</property>
<property name="label" translatable="yes">Tool</property>
</object>
<packing>
<property name="position">1</property>
......@@ -841,7 +1207,7 @@
</packing>
</child>
<child>
<object class="GtkFrame" id="frame2">
<object class="GtkFrame" id="ProcessingFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
......@@ -1047,4 +1413,12 @@
<property name="page_increment">10</property>
<property name="page_size">10</property>
</object>
<object class="GtkImage" id="Add foo">
<property name="visible">True</property>
<property name="stock">gtk-add</property>
</object>
<object class="GtkImage" id="Remove foo">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
</object>
</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