Commit b0d1d886 authored by sumpfralle's avatar sumpfralle

improved robustness during file opening in STLImporter

check for file existence during "Load Model" (including error dialog)
 * fixed bug: http://sourceforge.net/tracker/index.php?func=detail&aid=2973875&group_id=237831&atid=1104176


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@263 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 76c76d3b
...@@ -1104,13 +1104,15 @@ class ProjectGui: ...@@ -1104,13 +1104,15 @@ class ProjectGui:
self.load_processing_settings(filename) self.load_processing_settings(filename)
def load_model(self, model): def load_model(self, model):
self.model = model # load the new model only if the import worked
# place the "safe height" clearly above the model's peak if not model is None:
self.settings.set("safety_height", (2 * self.model.maxz - self.model.minz)) self.model = model
# do some initialization # place the "safe height" clearly above the model's peak
self.append_to_queue(self.reset_bounds) self.settings.set("safety_height", (2 * self.model.maxz - self.model.minz))
self.append_to_queue(self.toggle_3d_view, value=True) # do some initialization
self.append_to_queue(self.update_view) self.append_to_queue(self.reset_bounds)
self.append_to_queue(self.toggle_3d_view, value=True)
self.append_to_queue(self.update_view)
def load_processing_settings(self, filename=None): def load_processing_settings(self, filename=None):
if not filename is None: if not filename is None:
...@@ -1474,6 +1476,14 @@ class ProjectGui: ...@@ -1474,6 +1476,14 @@ class ProjectGui:
response = overwrite_window.run() response = overwrite_window.run()
overwrite_window.destroy() overwrite_window.destroy()
done = (response == gtk.RESPONSE_YES) done = (response == gtk.RESPONSE_YES)
elif mode_load and not os.path.isfile(filename):
not_found_window = gtk.MessageDialog(self.window, type=gtk.MESSAGE_ERROR,
buttons=gtk.BUTTONS_OK,
message_format="This file does not exist. Please choose a different filename.")
not_found_window.set_title("Invalid filename selected")
response = not_found_window.run()
not_found_window.destroy()
done = False
else: else:
done = True done = True
dialog.destroy() dialog.destroy()
......
import re, os
from struct import unpack
from pycam.Geometry import * from pycam.Geometry import *
from pycam.Geometry.PointKdtree import PointKdtree from pycam.Geometry.PointKdtree import PointKdtree
from pycam.Geometry.TriangleKdtree import TriangleKdtree from pycam.Geometry.TriangleKdtree import TriangleKdtree
from struct import unpack
import re
import os
import sys
vertices = 0 vertices = 0
edges = 0 edges = 0
epsilon = 0.0001 epsilon = 0.0001
...@@ -50,7 +52,11 @@ def ImportModel(filename, use_kdtree=True): ...@@ -50,7 +52,11 @@ def ImportModel(filename, use_kdtree=True):
edges = 0 edges = 0
kdtree = None kdtree = None
f = open(filename,"rb") try:
f = open(filename,"rb")
except IOError, err_msg:
print >>sys.stderr, "Failed to read file (%s): %s" % (filename, err_msg)
return None
# read the first two lines of (potentially non-binary) input - they should contain "solid" and "facet" # read the first two lines of (potentially non-binary) input - they should contain "solid" and "facet"
header = f.readline(200) header = f.readline(200)
header += f.readline(200) header += f.readline(200)
......
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