commit 290ad7aa6fe103a0c9cb2ac09e51b99853573c7c
parent 0c5d15638f6c00790ac44e4cf6f821c753886a73
Author: Matt Keeter <matt.j.keeter@gmail.com>
Date: Wed, 26 Apr 2017 22:27:51 -0400
Add warning for bad ASCII stls
Diffstat:
4 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/loader.cpp b/src/loader.cpp
@@ -100,10 +100,15 @@ Mesh* Loader::load_stl()
file.seek(0);
return read_stl_ascii(file);
}
+ confusing_stl = true;
+ }
+ else
+ {
+ confusing_stl = false;
}
// Otherwise, skip the rest of the header material and read as binary
- file.read(74);
+ file.seek(0);
return read_stl_binary(file);
}
@@ -114,6 +119,7 @@ Mesh* Loader::read_stl_binary(QFile& file)
data.setFloatingPointPrecision(QDataStream::SinglePrecision);
// Load the triangle count from the .stl file
+ file.seek(80);
uint32_t tri_count;
data >> tri_count;
@@ -144,6 +150,12 @@ Mesh* Loader::read_stl_binary(QFile& file)
// Skip face attribute
data.readRawData(buffer, sizeof(uint16_t));
}
+
+ if (confusing_stl)
+ {
+ emit warning_confusing_stl();
+ }
+
return mesh_from_verts(tri_count, verts);
}
diff --git a/src/loader.h b/src/loader.h
@@ -25,11 +25,15 @@ signals:
void got_mesh(Mesh* m);
void error_bad_stl();
+ void warning_confusing_stl();
void error_missing_file();
private:
const QString filename;
+ /* Used to warn on binary STLs that begin with the word 'solid'" */
+ bool confusing_stl;
+
};
#endif // LOADER_H
diff --git a/src/window.cpp b/src/window.cpp
@@ -99,6 +99,14 @@ void Window::on_bad_stl()
"Please export it from the original source, verify, and retry.");
}
+void Window::on_confusing_stl()
+{
+ QMessageBox::warning(this, "Warning",
+ "<b>Warning:</b><br>"
+ "This <code>.stl</code> file begins with <code>solid </code>but appears to be a binary file.<br>"
+ "<code>fstl</code> loaded it, but other programs may be confused by this file.");
+}
+
void Window::on_missing_file()
{
QMessageBox::critical(this, "Error",
@@ -150,6 +158,8 @@ bool Window::load_stl(const QString& filename)
canvas, &Canvas::load_mesh);
connect(loader, &Loader::error_bad_stl,
this, &Window::on_bad_stl);
+ connect(loader, &Loader::warning_confusing_stl,
+ this, &Window::on_confusing_stl);
connect(loader, &Loader::error_missing_file,
this, &Window::on_missing_file);
diff --git a/src/window.h b/src/window.h
@@ -22,6 +22,7 @@ public slots:
void on_about();
void on_bad_stl();
void on_missing_file();
+ void on_confusing_stl();
void enable_open();
void disable_open();