#include "loader.h"
Window::Window(QWidget *parent) :
- QMainWindow(parent)
+ QMainWindow(parent),
+ open_action(new QAction("Open", this)),
+ about_action(new QAction("About", this)),
+ quit_action(new QAction("Quit", this))
+
{
setWindowTitle("fstl");
canvas = new Canvas(format, this);
setCentralWidget(canvas);
- open_action = new QAction("Open", this);
open_action->setShortcut(QKeySequence::Open);
QObject::connect(open_action, &QAction::triggered,
this, &Window::on_open);
- quit_action = new QAction("Quit", this);
quit_action->setShortcut(QKeySequence::Quit);
QObject::connect(quit_action, &QAction::triggered,
this, &Window::close);
- about_action = new QAction("About", this);
QObject::connect(about_action, &QAction::triggered,
this, &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::on_bad_stl()
+{
+ QMessageBox::critical(this, "Error",
+ "<b>Error:</b><br>"
+ "This <code>.stl</code> file is invalid or corrupted.<br>"
+ "Please export it from the original source, verify, and retry.");
+}
+
+void Window::enable_open()
+{
+ open_action->setEnabled(true);
+}
+
+void Window::disable_open()
+{
+ open_action->setEnabled(false);
+}
+
bool Window::load_stl(const QString& filename)
{
if (!open_action->isEnabled()) return false;
Loader* loader = new Loader(this, filename);
connect(loader, &Loader::started,
- [=](){ open_action->setEnabled(false); });
+ this, &Window::disable_open);
connect(loader, &Loader::got_mesh,
canvas, &Canvas::load_mesh);
+ connect(loader, &Loader::error_ascii_stl,
+ this, &Window::on_ascii_stl);
+ connect(loader, &Loader::error_bad_stl,
+ this, &Window::on_bad_stl);
connect(loader, &Loader::finished,
loader, &Loader::deleteLater);
connect(loader, &Loader::finished,
- [=](){ open_action->setEnabled(true); });
+ this, &Window::enable_open);
connect(loader, &Loader::finished,
- [=](){ canvas->set_status(""); });
+ canvas, &Canvas::clear_status);
- connect(loader, &Loader::loaded_file,
- this, &Window::setWindowTitle);
+ if (filename[0] != ':')
+ {
+ connect(loader, &Loader::loaded_file,
+ this, &Window::setWindowTitle);
+ }
loader->start();
return true;