From 428aff52a5780af24436a896fec1b6fcd65eea5e Mon Sep 17 00:00:00 2001
From: Matt Keeter
Date: Mon, 24 Mar 2014 20:14:13 -0400
Subject: [PATCH] Raise an error message box on ascii stl
---
src/loader.cpp | 14 ++++++++++----
src/loader.h | 1 +
src/window.cpp | 10 ++++++++++
src/window.h | 1 +
4 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/loader.cpp b/src/loader.cpp
index 107d90f..d7ce46a 100644
--- a/src/loader.cpp
+++ b/src/loader.cpp
@@ -8,10 +8,16 @@ Loader::Loader(QObject* parent, const QString& filename)
void Loader::run()
{
- QTime timer;
- timer.start();
- emit got_mesh(Mesh::load_stl(filename));
- qDebug() << "Time taken:" << timer.elapsed();
+ { // Verify that this isn't an ascii stl file
+ QFile file(filename);
+ file.open(QIODevice::ReadOnly);
+ if (file.read(5) == "solid")
+ {
+ emit error_ascii_stl();
+ return;
+ }
+ }
+ emit got_mesh(Mesh::load_stl(filename));
emit loaded_file(filename);
}
diff --git a/src/loader.h b/src/loader.h
index 350985c..85e0c53 100644
--- a/src/loader.h
+++ b/src/loader.h
@@ -15,6 +15,7 @@ public:
signals:
void loaded_file(QString filename);
void got_mesh(Mesh* m);
+ void error_ascii_stl();
private:
const QString filename;
diff --git a/src/window.cpp b/src/window.cpp
index 15ffb03..5f8ac9e 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -69,6 +69,14 @@ void Window::on_about()
" style=\"color: #93a1a1;\">matt.j.keeter@gmail.com
");
}
+void Window::on_ascii_stl()
+{
+ QMessageBox::critical(this, "Error",
+ "Error:
"
+ "Cannot open ASCII .stl
file
"
+ "Please convert to binary .stl
and retry");
+}
+
void Window::enable_open()
{
open_action->setEnabled(true);
@@ -91,6 +99,8 @@ bool Window::load_stl(const QString& filename)
connect(loader, &Loader::got_mesh,
canvas, &Canvas::load_mesh);
+ connect(loader, &Loader::error_ascii_stl,
+ this, &Window::on_ascii_stl);
connect(loader, &Loader::finished,
loader, &Loader::deleteLater);
diff --git a/src/window.h b/src/window.h
index 22c35cb..8484822 100644
--- a/src/window.h
+++ b/src/window.h
@@ -15,6 +15,7 @@ public:
public slots:
void on_open();
void on_about();
+ void on_ascii_stl();
void enable_open();
void disable_open();
--
2.39.5