Commit 74650323 authored by sumpfralle's avatar sumpfralle

improved warnings for invalid STL input


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@866 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent b88ea8a8
...@@ -22,10 +22,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>. ...@@ -22,10 +22,8 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
""" """
from pycam.Geometry.Point import Point, Vector from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.Line import Line
from pycam.Geometry.Triangle import Triangle from pycam.Geometry.Triangle import Triangle
from pycam.Geometry.PointKdtree import PointKdtree from pycam.Geometry.PointKdtree import PointKdtree
from pycam.Geometry.TriangleKdtree import TriangleKdtree
from pycam.Geometry.utils import epsilon from pycam.Geometry.utils import epsilon
from pycam.Geometry.Model import Model from pycam.Geometry.Model import Model
import pycam.Utils.log import pycam.Utils.log
...@@ -72,15 +70,15 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None, ...@@ -72,15 +70,15 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None,
# contain "solid" and "facet". # contain "solid" and "facet".
header_lines = [] header_lines = []
while len(header_lines) < 2: while len(header_lines) < 2:
current_line = f.readline(200) line = f.readline(200)
if len(current_line) == 0: if len(line) == 0:
# empty line (not even a line-feed) -> EOF # empty line (not even a line-feed) -> EOF
log.error("STLImporter: No valid lines found in '%s'" % filename) log.error("STLImporter: No valid lines found in '%s'" % filename)
return None return None
# ignore comment lines # ignore comment lines
# note: partial comments (starting within a line) are not handled # note: partial comments (starting within a line) are not handled
if not current_line.startswith(";"): if not line.startswith(";"):
header_lines.append(current_line) header_lines.append(line)
header = "".join(header_lines) header = "".join(header_lines)
# read byte 80 to 83 - they contain the "numfacets" value in binary format # read byte 80 to 83 - they contain the "numfacets" value in binary format
f.seek(80) f.seek(80)
...@@ -148,9 +146,9 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None, ...@@ -148,9 +146,9 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None,
elif dotcross < 0: elif dotcross < 0:
if not normal_conflict_warning_seen: if not normal_conflict_warning_seen:
# TODO: use the line number here instead of its content # TODO: use the line number here instead of its content
log.warn(("Inconsistent normal/vertices found in line " \ log.warn(("Inconsistent normal/vertices found in facet " \
+ "%s of '%s'. Please validate the STL file!") \ + "definition %d of '%s'. Please validate the STL " \
% (current_line, filename)) + "file!") % (i, filename))
normal_conflict_warning_seen = True normal_conflict_warning_seen = True
t = Triangle(p1, p2, p3) t = Triangle(p1, p2, p3)
else: else:
...@@ -224,6 +222,11 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None, ...@@ -224,6 +222,11 @@ def ImportModel(filename, use_kdtree=True, program_locations=None, unit=None,
continue continue
m = endfacet.match(line) m = endfacet.match(line)
if m: if m:
if p1 is None or p2 is None or p3 is None:
log.warn(("Invalid facet definition in line " \
+ "%d of '%s'. Please validate the STL file!") \
% (current_line, filename))
n, p1, p2, p3 = None, None, None, None
if not n: if not n:
n = p2.sub(p1).cross(p3.sub(p1)).normalized() n = p2.sub(p1).cross(p3.sub(p1)).normalized()
......
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