Compare commits
18 commits
Author | SHA1 | Date | |
---|---|---|---|
|
5a38a2db97 | ||
|
d9301bbba0 | ||
|
61c930444d | ||
|
9cc3bd82e8 | ||
|
de5c4b440a | ||
|
030f0c5161 | ||
|
70f0297d20 | ||
|
428aff52a5 | ||
|
236a203320 | ||
|
4026982e1a | ||
|
25a7138328 | ||
|
54206d3f9c | ||
|
9283aa4752 | ||
|
e36ff6ae9c | ||
|
b6368a2663 | ||
|
44f171a823 | ||
|
51e25316e8 | ||
|
3cd76f9306 |
12 changed files with 251 additions and 107 deletions
14
app/package.sh
Executable file
14
app/package.sh
Executable file
|
@ -0,0 +1,14 @@
|
||||||
|
#!/bin/sh
|
||||||
|
cd ../build
|
||||||
|
macdeployqt fstl.app
|
||||||
|
cd fstl.app/Contents/PlugIns
|
||||||
|
rm -rf accessible audio imageformats mediaservice playlistformats position printsupport qml1tooling sensorgestures sensors
|
||||||
|
cd ../Frameworks
|
||||||
|
rm -rf QtDeclarative.framework QtMultimedia.framework QtMultimediaWidgets.framework QtNetwork.framework QtPositioning.framework QtQml.framework QtQuick.framework QtScript.framework QtSensors.framework QtSql.framework QtXmlPatterns.framework
|
||||||
|
cd ../Resources
|
||||||
|
rm empty.lproj
|
||||||
|
cd ../../..
|
||||||
|
cp -r fstl.app ..
|
||||||
|
cd ..
|
||||||
|
zip -r fstl_mac.zip fstl.app README.md
|
||||||
|
|
3
exe/package.sh
Normal file
3
exe/package.sh
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
cd ..
|
||||||
|
cp build/release/fstl.exe .
|
||||||
|
/c/Program\ Files/7-Zip/7z.exe a fstl_win.zip fstl.exe README.md
|
|
@ -1,12 +1,18 @@
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
|
uniform float zoom;
|
||||||
|
|
||||||
varying vec3 ec_pos;
|
varying vec3 ec_pos;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 base3 = vec3(0.99, 0.96, 0.89);
|
vec3 base3 = vec3(0.99, 0.96, 0.89);
|
||||||
vec3 base2 = vec3(0.92, 0.91, 0.83);
|
vec3 base2 = vec3(0.92, 0.91, 0.83);
|
||||||
vec3 base00 = vec3(0.40, 0.48, 0.51);
|
vec3 base00 = vec3(0.40, 0.48, 0.51);
|
||||||
|
|
||||||
vec3 ec_normal = normalize(cross(dFdx(ec_pos), dFdy(ec_pos)));
|
vec3 ec_normal = normalize(cross(dFdx(ec_pos), dFdy(ec_pos)));
|
||||||
|
ec_normal.z *= zoom;
|
||||||
|
ec_normal = normalize(ec_normal);
|
||||||
|
|
||||||
float a = dot(ec_normal, vec3(0.0, 0.0, 1.0));
|
float a = dot(ec_normal, vec3(0.0, 0.0, 1.0));
|
||||||
float b = dot(ec_normal, vec3(-0.57, -0.57, 0.57));
|
float b = dot(ec_normal, vec3(-0.57, -0.57, 0.57));
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,10 @@ App::App(int argc, char *argv[]) :
|
||||||
QApplication(argc, argv), window(new Window())
|
QApplication(argc, argv), window(new Window())
|
||||||
{
|
{
|
||||||
window->show();
|
window->show();
|
||||||
window->load_stl(":gl/sphere.stl");
|
if (argc > 1)
|
||||||
|
window->load_stl(argv[1]);
|
||||||
|
else
|
||||||
|
window->load_stl(":gl/sphere.stl");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool App::event(QEvent* e)
|
bool App::event(QEvent* e)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
Canvas::Canvas(const QGLFormat& format, QWidget *parent)
|
Canvas::Canvas(const QGLFormat& format, QWidget *parent)
|
||||||
: QGLWidget(format, parent), mesh(NULL),
|
: QGLWidget(format, parent), mesh(NULL),
|
||||||
scale(1), tilt(90), yaw(0), status(" ")
|
scale(1), zoom(1), tilt(90), yaw(0), status(" ")
|
||||||
{
|
{
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,12 @@ void Canvas::load_mesh(Mesh* m)
|
||||||
pow(m->xmax() - m->xmin(), 2) +
|
pow(m->xmax() - m->xmin(), 2) +
|
||||||
pow(m->ymax() - m->ymin(), 2) +
|
pow(m->ymax() - m->ymin(), 2) +
|
||||||
pow(m->zmax() - m->zmin(), 2));
|
pow(m->zmax() - m->zmin(), 2));
|
||||||
|
|
||||||
|
// Reset other camera parameters
|
||||||
|
zoom = 1;
|
||||||
|
yaw = 0;
|
||||||
|
tilt = 90;
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
delete m;
|
delete m;
|
||||||
|
@ -89,6 +95,9 @@ void Canvas::draw_mesh()
|
||||||
mesh_shader.uniformLocation("view_matrix"),
|
mesh_shader.uniformLocation("view_matrix"),
|
||||||
1, GL_FALSE, view_matrix().data());
|
1, GL_FALSE, view_matrix().data());
|
||||||
|
|
||||||
|
// Compensate for z-flattening when zooming
|
||||||
|
glUniform1f(mesh_shader.uniformLocation("zoom"), 1/zoom);
|
||||||
|
|
||||||
// Find and enable the attribute location for vertex position
|
// Find and enable the attribute location for vertex position
|
||||||
const GLuint vp = mesh_shader.attributeLocation("vertex_position");
|
const GLuint vp = mesh_shader.attributeLocation("vertex_position");
|
||||||
glEnableVertexAttribArray(vp);
|
glEnableVertexAttribArray(vp);
|
||||||
|
@ -122,12 +131,14 @@ QMatrix4x4 Canvas::view_matrix() const
|
||||||
{
|
{
|
||||||
m.scale(-1, width() / float(height()), 0.5);
|
m.scale(-1, width() / float(height()), 0.5);
|
||||||
}
|
}
|
||||||
|
m.scale(zoom, zoom, 1);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Canvas::mousePressEvent(QMouseEvent* event)
|
void Canvas::mousePressEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton ||
|
||||||
|
event->button() == Qt::RightButton)
|
||||||
{
|
{
|
||||||
mouse_pos = event->pos();
|
mouse_pos = event->pos();
|
||||||
setCursor(Qt::ClosedHandCursor);
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
@ -136,7 +147,8 @@ void Canvas::mousePressEvent(QMouseEvent* event)
|
||||||
|
|
||||||
void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton ||
|
||||||
|
event->button() == Qt::RightButton)
|
||||||
{
|
{
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
}
|
}
|
||||||
|
@ -144,13 +156,50 @@ void Canvas::mouseReleaseEvent(QMouseEvent* event)
|
||||||
|
|
||||||
void Canvas::mouseMoveEvent(QMouseEvent* event)
|
void Canvas::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
|
auto p = event->pos();
|
||||||
|
auto d = p - mouse_pos;
|
||||||
|
|
||||||
if (event->buttons() & Qt::LeftButton)
|
if (event->buttons() & Qt::LeftButton)
|
||||||
{
|
{
|
||||||
auto p = event->pos();
|
|
||||||
auto d = p - mouse_pos;
|
|
||||||
yaw = fmod(yaw - d.x(), 360);
|
yaw = fmod(yaw - d.x(), 360);
|
||||||
tilt = fmax(0, fmin(180, tilt - d.y()));
|
tilt = fmax(0, fmin(180, tilt - d.y()));
|
||||||
mouse_pos = p;
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
else if (event->buttons() & Qt::RightButton)
|
||||||
|
{
|
||||||
|
center = transform_matrix().inverted() *
|
||||||
|
view_matrix().inverted() *
|
||||||
|
QVector3D(-d.x() / (0.5*width()),
|
||||||
|
d.y() / (0.5*height()), 0);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
mouse_pos = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Canvas::wheelEvent(QWheelEvent *event)
|
||||||
|
{
|
||||||
|
// Find GL position before the zoom operation
|
||||||
|
// (to zoom about mouse cursor)
|
||||||
|
auto p = event->pos();
|
||||||
|
QVector3D v(1 - p.x() / (0.5*width()),
|
||||||
|
p.y() / (0.5*height()) - 1, 0);
|
||||||
|
QVector3D a = transform_matrix().inverted() *
|
||||||
|
view_matrix().inverted() * v;
|
||||||
|
|
||||||
|
if (event->delta() < 0)
|
||||||
|
{
|
||||||
|
for (int i=0; i > event->delta(); --i)
|
||||||
|
zoom *= 1.001;
|
||||||
|
}
|
||||||
|
else if (event->delta() > 0)
|
||||||
|
{
|
||||||
|
for (int i=0; i < event->delta(); ++i)
|
||||||
|
zoom /= 1.001;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then find the cursor's GL position post-zoom and adjust center.
|
||||||
|
QVector3D b = transform_matrix().inverted() *
|
||||||
|
view_matrix().inverted() * v;
|
||||||
|
center += b - a;
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ protected:
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
void mouseReleaseEvent(QMouseEvent* event);
|
void mouseReleaseEvent(QMouseEvent* event);
|
||||||
void mouseMoveEvent(QMouseEvent* event);
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
|
void wheelEvent(QWheelEvent* event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -48,6 +49,7 @@ private:
|
||||||
|
|
||||||
QVector3D center;
|
QVector3D center;
|
||||||
float scale;
|
float scale;
|
||||||
|
float zoom;
|
||||||
float tilt;
|
float tilt;
|
||||||
float yaw;
|
float yaw;
|
||||||
|
|
||||||
|
|
122
src/loader.cpp
122
src/loader.cpp
|
@ -1,13 +1,129 @@
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "mesh.h"
|
|
||||||
|
|
||||||
Loader::Loader(QObject* parent, const QString& filename)
|
Loader::Loader(QObject* parent, const QString& filename)
|
||||||
: QThread(parent), filename(filename)
|
: QThread(parent), filename(filename)
|
||||||
{
|
{
|
||||||
|
// Nothing to do here
|
||||||
}
|
}
|
||||||
|
|
||||||
void Loader::run()
|
void Loader::run()
|
||||||
{
|
{
|
||||||
emit got_mesh(Mesh::load_stl(filename));
|
Mesh* mesh = load_stl();
|
||||||
emit loaded_file(filename);
|
if (mesh)
|
||||||
|
{
|
||||||
|
emit got_mesh(mesh);
|
||||||
|
emit loaded_file(filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
struct Vec3
|
||||||
|
{
|
||||||
|
GLfloat x, y, z;
|
||||||
|
bool operator!=(const Vec3& rhs) const
|
||||||
|
{
|
||||||
|
return x != rhs.x || y != rhs.y || z != rhs.z;
|
||||||
|
}
|
||||||
|
bool operator<(const Vec3& rhs) const
|
||||||
|
{
|
||||||
|
if (x != rhs.x) return x < rhs.x;
|
||||||
|
else if (y != rhs.y) return y < rhs.y;
|
||||||
|
else if (z != rhs.z) return z < rhs.z;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::pair<Vec3, GLuint> Vec3i;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Mesh* Loader::load_stl()
|
||||||
|
{
|
||||||
|
QFile file(filename);
|
||||||
|
file.open(QIODevice::ReadOnly);
|
||||||
|
if (file.read(5) == "solid")
|
||||||
|
{
|
||||||
|
emit error_ascii_stl();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
// Skip the rest of the header material
|
||||||
|
file.read(75);
|
||||||
|
|
||||||
|
QDataStream data(&file);
|
||||||
|
data.setByteOrder(QDataStream::LittleEndian);
|
||||||
|
data.setFloatingPointPrecision(QDataStream::SinglePrecision);
|
||||||
|
|
||||||
|
// Load the triangle count from the .stl file
|
||||||
|
uint32_t tri_count;
|
||||||
|
data >> tri_count;
|
||||||
|
|
||||||
|
// Verify that the file is the right size
|
||||||
|
if (file.size() != 84 + tri_count*50)
|
||||||
|
{
|
||||||
|
emit error_bad_stl();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract vertices into an array of xyz, unsigned pairs
|
||||||
|
QVector<Vec3i> verts(tri_count*3);
|
||||||
|
|
||||||
|
// Dummy array, because readRawData is faster than skipRawData
|
||||||
|
char buffer[sizeof(float)*3];
|
||||||
|
|
||||||
|
// Store vertices in the array, processing one triangle at a time.
|
||||||
|
for (auto v=verts.begin(); v != verts.end(); v += 3)
|
||||||
|
{
|
||||||
|
// Skip face's normal vector
|
||||||
|
data.readRawData(buffer, 3*sizeof(float));
|
||||||
|
|
||||||
|
// Load vertex data from .stl file into vertices
|
||||||
|
data >> v[0].first.x >> v[0].first.y >> v[0].first.z;
|
||||||
|
data >> v[1].first.x >> v[1].first.y >> v[1].first.z;
|
||||||
|
data >> v[2].first.x >> v[2].first.y >> v[2].first.z;
|
||||||
|
|
||||||
|
// Skip face attribute
|
||||||
|
data.readRawData(buffer, sizeof(uint16_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save indicies as the second element in the array
|
||||||
|
// (so that we can reconstruct triangle order after sorting)
|
||||||
|
for (size_t i=0; i < tri_count*3; ++i)
|
||||||
|
{
|
||||||
|
verts[i].second = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort the set of vertices (to deduplicate)
|
||||||
|
std::sort(verts.begin(), verts.end());
|
||||||
|
|
||||||
|
// This vector will store triangles as sets of 3 indices
|
||||||
|
std::vector<GLuint> indices(tri_count*3);
|
||||||
|
|
||||||
|
// Go through the sorted vertex list, deduplicating and creating
|
||||||
|
// an indexed geometry representation for the triangles.
|
||||||
|
// Unique vertices are moved so that they occupy the first vertex_count
|
||||||
|
// positions in the verts array.
|
||||||
|
size_t vertex_count = 0;
|
||||||
|
for (auto v : verts)
|
||||||
|
{
|
||||||
|
if (!vertex_count || v.first != verts[vertex_count-1].first)
|
||||||
|
{
|
||||||
|
verts[vertex_count++] = v;
|
||||||
|
}
|
||||||
|
indices[v.second] = vertex_count - 1;
|
||||||
|
}
|
||||||
|
verts.resize(vertex_count);
|
||||||
|
|
||||||
|
std::vector<GLfloat> flat_verts;
|
||||||
|
flat_verts.reserve(vertex_count*3);
|
||||||
|
for (auto v : verts)
|
||||||
|
{
|
||||||
|
flat_verts.push_back(v.first.x);
|
||||||
|
flat_verts.push_back(v.first.y);
|
||||||
|
flat_verts.push_back(v.first.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Mesh(flat_verts, indices);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,10 +12,16 @@ public:
|
||||||
explicit Loader(QObject* parent, const QString& filename);
|
explicit Loader(QObject* parent, const QString& filename);
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Mesh* load_stl();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void loaded_file(QString filename);
|
void loaded_file(QString filename);
|
||||||
void got_mesh(Mesh* m);
|
void got_mesh(Mesh* m);
|
||||||
|
|
||||||
|
void error_ascii_stl();
|
||||||
|
void error_bad_stl();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString filename;
|
const QString filename;
|
||||||
|
|
||||||
|
|
96
src/mesh.cpp
96
src/mesh.cpp
|
@ -2,7 +2,6 @@
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QVector3D>
|
#include <QVector3D>
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
|
@ -34,98 +33,3 @@ float Mesh::max(size_t start) const
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
struct Vec3
|
|
||||||
{
|
|
||||||
GLfloat x, y, z;
|
|
||||||
bool operator!=(const Vec3& rhs) const
|
|
||||||
{
|
|
||||||
return x != rhs.x || y != rhs.y || z != rhs.z;
|
|
||||||
}
|
|
||||||
bool operator<(const Vec3& rhs) const
|
|
||||||
{
|
|
||||||
if (x != rhs.x) return x < rhs.x;
|
|
||||||
else if (y != rhs.y) return y < rhs.y;
|
|
||||||
else if (z != rhs.z) return z < rhs.z;
|
|
||||||
else return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::pair<Vec3, GLuint> Vec3i;
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
Mesh* Mesh::load_stl(const QString& filename)
|
|
||||||
{
|
|
||||||
QFile file(filename);
|
|
||||||
file.open(QIODevice::ReadOnly);
|
|
||||||
|
|
||||||
QDataStream data(&file);
|
|
||||||
data.setByteOrder(QDataStream::LittleEndian);
|
|
||||||
data.setFloatingPointPrecision(QDataStream::SinglePrecision);
|
|
||||||
|
|
||||||
// Skip .stl file header
|
|
||||||
data.skipRawData(80);
|
|
||||||
|
|
||||||
// Load the triangle count from the .stl file
|
|
||||||
uint32_t tri_count;
|
|
||||||
data >> tri_count;
|
|
||||||
|
|
||||||
// Extract vertices into an array of xyz, unsigned pairs
|
|
||||||
QVector<Vec3i> verts(tri_count*3);
|
|
||||||
|
|
||||||
// Store vertices in the array, processing one triangle at a time.
|
|
||||||
for (auto v=verts.begin(); v != verts.end(); v += 3)
|
|
||||||
{
|
|
||||||
// Skip face's normal vector
|
|
||||||
data.skipRawData(3*sizeof(float));
|
|
||||||
|
|
||||||
// Load vertex data from .stl file into vertices
|
|
||||||
data >> v[0].first.x >> v[0].first.y >> v[0].first.z;
|
|
||||||
data >> v[1].first.x >> v[1].first.y >> v[1].first.z;
|
|
||||||
data >> v[2].first.x >> v[2].first.y >> v[2].first.z;
|
|
||||||
|
|
||||||
// Skip face attribute
|
|
||||||
data.skipRawData(sizeof(uint16_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save indicies as the second element in the array
|
|
||||||
// (so that we can reconstruct triangle order after sorting)
|
|
||||||
for (size_t i=0; i < tri_count*3; ++i)
|
|
||||||
{
|
|
||||||
verts[i].second = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort the set of vertices (to deduplicate)
|
|
||||||
std::sort(verts.begin(), verts.end());
|
|
||||||
|
|
||||||
// This vector will store triangles as sets of 3 indices
|
|
||||||
std::vector<GLuint> indices(tri_count*3);
|
|
||||||
|
|
||||||
// Go through the sorted vertex list, deduplicating and creating
|
|
||||||
// an indexed geometry representation for the triangles.
|
|
||||||
// Unique vertices are moved so that they occupy the first vertex_count
|
|
||||||
// positions in the verts array.
|
|
||||||
size_t vertex_count = 0;
|
|
||||||
for (auto v : verts)
|
|
||||||
{
|
|
||||||
if (!vertex_count || v.first != verts[vertex_count-1].first)
|
|
||||||
{
|
|
||||||
verts[vertex_count++] = v;
|
|
||||||
}
|
|
||||||
indices[v.second] = vertex_count - 1;
|
|
||||||
}
|
|
||||||
verts.resize(vertex_count);
|
|
||||||
|
|
||||||
std::vector<float> flat_verts;
|
|
||||||
flat_verts.reserve(vertex_count*3);
|
|
||||||
for (auto v : verts)
|
|
||||||
{
|
|
||||||
flat_verts.push_back(v.first.x);
|
|
||||||
flat_verts.push_back(v.first.y);
|
|
||||||
flat_verts.push_back(v.first.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Mesh(flat_verts, indices);
|
|
||||||
}
|
|
||||||
|
|
|
@ -10,7 +10,6 @@ class Mesh
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Mesh(std::vector<GLfloat> vertices, std::vector<GLuint> indices);
|
Mesh(std::vector<GLfloat> vertices, std::vector<GLuint> indices);
|
||||||
static Mesh* load_stl(const QString& filename);
|
|
||||||
|
|
||||||
float min(size_t start) const;
|
float min(size_t start) const;
|
||||||
float max(size_t start) const;
|
float max(size_t start) const;
|
||||||
|
|
|
@ -14,6 +14,7 @@ Window::Window(QWidget *parent) :
|
||||||
|
|
||||||
{
|
{
|
||||||
setWindowTitle("fstl");
|
setWindowTitle("fstl");
|
||||||
|
setAcceptDrops(true);
|
||||||
|
|
||||||
QFile styleFile(":/qt/style.qss");
|
QFile styleFile(":/qt/style.qss");
|
||||||
styleFile.open( QFile::ReadOnly );
|
styleFile.open( QFile::ReadOnly );
|
||||||
|
@ -69,6 +70,22 @@ void Window::on_about()
|
||||||
" style=\"color: #93a1a1;\">matt.j.keeter@gmail.com</a></p>");
|
" 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()
|
void Window::enable_open()
|
||||||
{
|
{
|
||||||
open_action->setEnabled(true);
|
open_action->setEnabled(true);
|
||||||
|
@ -91,6 +108,10 @@ bool Window::load_stl(const QString& filename)
|
||||||
|
|
||||||
connect(loader, &Loader::got_mesh,
|
connect(loader, &Loader::got_mesh,
|
||||||
canvas, &Canvas::load_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,
|
connect(loader, &Loader::finished,
|
||||||
loader, &Loader::deleteLater);
|
loader, &Loader::deleteLater);
|
||||||
|
@ -108,3 +129,18 @@ bool Window::load_stl(const QString& filename)
|
||||||
loader->start();
|
loader->start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasUrls())
|
||||||
|
{
|
||||||
|
auto urls = event->mimeData()->urls();
|
||||||
|
if (urls.size() == 1 && urls.front().path().endsWith(".stl"))
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
load_stl(event->mimeData()->urls().front().toLocalFile());
|
||||||
|
}
|
||||||
|
|
|
@ -12,9 +12,15 @@ public:
|
||||||
explicit Window(QWidget* parent=0);
|
explicit Window(QWidget* parent=0);
|
||||||
bool load_stl(const QString& filename);
|
bool load_stl(const QString& filename);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event);
|
||||||
|
void dropEvent(QDropEvent* event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void on_open();
|
void on_open();
|
||||||
void on_about();
|
void on_about();
|
||||||
|
void on_ascii_stl();
|
||||||
|
void on_bad_stl();
|
||||||
|
|
||||||
void enable_open();
|
void enable_open();
|
||||||
void disable_open();
|
void disable_open();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue