]> git.sur5r.net Git - fstl/commitdiff
Raise an error message box on ascii stl
authorMatt Keeter <matt.j.keeter@gmail.com>
Tue, 25 Mar 2014 00:14:13 +0000 (20:14 -0400)
committerMatt Keeter <matt.j.keeter@gmail.com>
Tue, 25 Mar 2014 01:01:43 +0000 (21:01 -0400)
src/loader.cpp
src/loader.h
src/window.cpp
src/window.h

index 107d90f2b8363b28ed6da1c59c63e782c0fee66b..d7ce46a4a0e167ca560e18725c870e6f358f4f24 100644 (file)
@@ -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);
 }
index 350985cd9c5f6f7bc6e56bb3135e955fc12f8273..85e0c53a299a651c92b8a09e9ba395c3088d8aa1 100644 (file)
@@ -15,6 +15,7 @@ public:
 signals:
     void loaded_file(QString filename);
     void got_mesh(Mesh* m);
+    void error_ascii_stl();
 
 private:
     const QString filename;
index 15ffb0324d32000b4685b7e125b1718c254949db..5f8ac9e2667198fdf21daaed05cca7393b85d735 100644 (file)
@@ -69,6 +69,14 @@ void Window::on_about()
         "   style=\"color: #93a1a1;\">matt.j.keeter@gmail.com</a></p>");
 }
 
+void Window::on_ascii_stl()
+{
+    QMessageBox::critical(this, "Error",
+                          "<b>Error:</b><br>"
+                          "Cannot open ASCII <code>.stl</code> file<br>"
+                          "Please convert to binary <code>.stl</code> 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);
index 22c35cb1737dd992e0004ab8a80664146963bb32..84848226c465091361f6586f0d837cb798e0f00c 100644 (file)
@@ -15,6 +15,7 @@ public:
 public slots:
     void on_open();
     void on_about();
+    void on_ascii_stl();
 
     void enable_open();
     void disable_open();