From: Matt Keeter Date: Tue, 25 Mar 2014 00:14:13 +0000 (-0400) Subject: Raise an error message box on ascii stl X-Git-Tag: v0.9.0~2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=428aff52a5780af24436a896fec1b6fcd65eea5e;p=fstl Raise an error message box on ascii stl --- 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();