diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,12 @@ Widgets SerialPort Charts + Quick + Qml + 3DCore + 3DExtras + 3DRender + 3DInput ) if(BUILD_TESTING) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,6 @@ ecm_create_qm_loader(atelier_SRCS atelier) -target_link_libraries(atelier AtelierWidgets AtelierDialogs AtCore::AtCore KF5::Solid KF5::XmlGui KF5::ConfigWidgets) +target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D AtCore::AtCore KF5::Solid KF5::XmlGui KF5::ConfigWidgets) install(TARGETS atelier RUNTIME DESTINATION bin) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -224,6 +224,7 @@ fileName = fileNameFromDialog; ui->gcodeEditorWidget->loadFile(fileName); guiFactory()->addClient(ui->gcodeEditorWidget->gcodeView()); + ui->view3DWidget->drawModel(fileName.toString()); } } diff --git a/src/mainwindow.ui b/src/mainwindow.ui --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -16,24 +16,7 @@ - - - QFrame::Box - - - - - 6 - 6 - 47 - 18 - - - - 3DView - - - + @@ -292,6 +275,12 @@
widgets/pushgcodewidget.h
1 + + Viewer3D + QWidget +
widgets/3dview/viewer3d.h
+ 1 +
diff --git a/src/widgets/3dview/AnimatedEntity.qml b/src/widgets/3dview/AnimatedEntity.qml new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/AnimatedEntity.qml @@ -0,0 +1,97 @@ +import QtQuick 2.7 +import Qt3D.Core 2.0 +import Qt3D.Render 2.0 +import Qt3D.Input 2.0 +import Qt3D.Extras 2.0 +import Qt3D.Logic 2.0 +import GridMesh 1.0 +import LineMesh 1.0 + +Entity { + id: sceneRoot + + signal fpsChanged(var fps) + + function runLineMesh(path) { + lineMesh.readAndRun(path) + } + + Camera { + id: camera + projectionType: CameraLens.PerspectiveProjection + fieldOfView: 45 + aspectRatio: 16/9 + nearPlane : 0.01 + farPlane : 1000.0 + position: Qt.vector3d( 10.0, -10.0, 35.0 ) + upVector: Qt.vector3d( 0.0, 0.85, 0.75 ) + viewCenter: Qt.vector3d( 10.0, 10.0, 0.0 ) + } + + FirstPersonCameraController { camera: camera } + + components: [ + RenderSettings { + activeFrameGraph: ClearBuffers { + buffers: ClearBuffers.ColorDepthBuffer + clearColor: "transparent" + + RenderSurfaceSelector { + id: surfaceSelector + ClearBuffers { + buffers : ClearBuffers.ColorDepthBuffer + NoDraw {} + } + + Viewport { + id: topLeftViewport + CameraSelector { + id: cameraSelectorTopLeftViewport + camera: camera + } + } + } + } + }, + InputSettings { } + ] + + FrameAction { + id: frameAction + + onTriggered: { + sceneRoot.fpsChanged(1/dt) + } + } + + GridMesh { + id: gridMesh + enabled: true + } + + LineMesh { + id: lineMesh + objectName: "lineMesh" + enabled: true + } + + PhongMaterial { + id: material + ambient: "darkBlue" + } + + PhongMaterial { + id: lineMaterial + ambient: "darkGreen" + } + + Entity { + id: gridEntity + components: [ gridMesh, material ] + } + + Entity { + id: lineEntity + components: [ lineMesh, lineMaterial ] + } +} diff --git a/src/widgets/3dview/CMakeLists.txt b/src/widgets/3dview/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/CMakeLists.txt @@ -0,0 +1,28 @@ +set(3d_SRCS + gcodeto4d.cpp + fileloader.cpp + linemesh.cpp + gridmesh.cpp + linemeshgeometry.cpp + viewer3d.cpp +) + +file(GLOB 3d_SRC_QML + AnimatedEntity.qml + viewer3d.qml + ) + +qt5_add_resources(3dfiles_RCS viewer3d.qrc) + +add_library(Atelier3D STATIC ${3d_SRCS} ${3dfiles_RCS} ${3d_SRC_QML}) + +target_link_libraries(Atelier3D + Qt5::Core + Qt5::Widgets + Qt5::Quick + Qt5::Qml + Qt5::3DCore + Qt5::3DExtras + Qt5::3DRender + Qt5::3DInput + ) diff --git a/src/widgets/3dview/fileloader.h b/src/widgets/3dview/fileloader.h new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/fileloader.h @@ -0,0 +1,49 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include + +class QString; +class QVector4D; + +class FileLoader : public QObject +{ + Q_OBJECT + +public: + FileLoader(QString &fileName, QObject *parent = nullptr); + ~FileLoader(); + +private: + QFile _file; + +signals: + void percentUpdate(QVariant var); + void posFinished(const QList &pos); + +public slots: + void run(); +}; diff --git a/src/widgets/3dview/fileloader.cpp b/src/widgets/3dview/fileloader.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/fileloader.cpp @@ -0,0 +1,131 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "fileloader.h" + +#include +#include +#include +#include +#include + +namespace +{ +const static QString _commentChar = QStringLiteral(";"); +const static QStringList _moveCommands = {QStringLiteral("G0"), QStringLiteral("G1")}; +const static QString _space = QStringLiteral(" "); + +const static QString _E = QStringLiteral("E"); +const static QString _X = QStringLiteral("X"); +const static QString _Y = QStringLiteral("Y"); +const static QString _Z = QStringLiteral("Z"); +}; + +FileLoader::FileLoader(QString &fileName, QObject *parent) + : QObject(parent) + , _file(fileName) +{ +} + +void FileLoader::run() +{ + QList pos; + qint64 totalSize = _file.bytesAvailable(); + qint64 stillSize = totalSize; + float lastPerc = 0.0; + + if (_file.open(QIODevice::ReadOnly)) { + QTextStream in(&_file); + while (!in.atEnd()) { + //Get each line + QString line = in.readLine(); + stillSize -= line.size() + 1; // +1 endl + const float perc = (totalSize - stillSize) * 100.0 / totalSize; + if (perc - lastPerc > 1) { + emit percentUpdate((int)perc); + lastPerc = perc; + } + line = line.simplified(); + //Is it a comment ? Drop it + if (line.isEmpty()) { + continue; + } + //Remove comment in the end of command + if (line.indexOf(_commentChar) != -1) { + line.resize(line.indexOf(_commentChar)); + //Remove trailing spaces + line = line.simplified(); + } + + //Split command and args + QStringList commAndArgs = line.split(_space); + + if (_moveCommands.contains(commAndArgs[0])) { + QVector4D actualPos; + //Compute args + commAndArgs.removeFirst(); + for (QString element : commAndArgs) { + if (element.contains(_X)) { + actualPos.setX(element.remove(0, 1).toFloat() / 10); + } + + if (element.contains(_Y)) { + actualPos.setY(element.remove(0, 1).toFloat() / 10); + } + + if (element.contains(_Z)) { + actualPos.setZ(element.remove(0, 1).toFloat() / 10); + } + + if (element.contains(_E)) { + actualPos.setW(element.remove(0, 1).toFloat() / 10); + } + } + + if (!pos.isEmpty()) { + if (!line.contains(_X)) { + actualPos.setX(pos.last().x()); + } + + if (!line.contains(_Y)) { + actualPos.setY(pos.last().y()); + } + + if (!line.contains(_Z)) { + actualPos.setZ(pos.last().z()); + } + + if (!line.contains(_E)) { + actualPos.setW(pos.last().w()); + } + } + + pos.append(actualPos); + } + } + emit percentUpdate(100); + emit posFinished(pos); + } +}; + +FileLoader::~FileLoader() +{ +}; \ No newline at end of file diff --git a/src/widgets/3dview/gcodeto4d.h b/src/widgets/3dview/gcodeto4d.h new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/gcodeto4d.h @@ -0,0 +1,44 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include + +class GcodeTo4D : public QObject +{ + Q_OBJECT + +public: + explicit GcodeTo4D(QObject *parent = 0); + ~GcodeTo4D(); + +public: + void read(const QString &url); + +signals: + void percentUpdate(const QVariant &percent); + void posFinished(const QList &pos); + +private: + QThread *_thread; + bool _wait; +}; diff --git a/src/widgets/3dview/gcodeto4d.cpp b/src/widgets/3dview/gcodeto4d.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/gcodeto4d.cpp @@ -0,0 +1,52 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "gcodeto4d.h" +#include "fileloader.h" + +#include +#include +#include +#include +#include + +GcodeTo4D::GcodeTo4D(QObject *parent) : + QObject(parent) +{ +} + +void GcodeTo4D::read(const QString &url) +{ + _thread = new QThread; + QString path = QUrl(url).path(); + auto fileLoader = new FileLoader(path); + fileLoader->moveToThread(_thread); + connect(fileLoader, &FileLoader::percentUpdate, this, &GcodeTo4D::percentUpdate); + connect(fileLoader, &FileLoader::posFinished, this, &GcodeTo4D::posFinished); + connect(fileLoader, &FileLoader::posFinished, _thread, &QThread::quit); + connect(_thread, &QThread::started, fileLoader, &FileLoader::run); + connect(_thread, &QThread::finished, fileLoader, &FileLoader::deleteLater); + _thread->start(); +} + +GcodeTo4D::~GcodeTo4D() +{ +} \ No newline at end of file diff --git a/src/widgets/3dview/gridmesh.h b/src/widgets/3dview/gridmesh.h new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/gridmesh.h @@ -0,0 +1,34 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include + +class GridMesh : public Qt3DRender::QGeometryRenderer +{ + Q_OBJECT +public: + explicit GridMesh(Qt3DCore::QNode *parent = nullptr); + ~GridMesh(); +}; diff --git a/src/widgets/3dview/gridmesh.cpp b/src/widgets/3dview/gridmesh.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/gridmesh.cpp @@ -0,0 +1,57 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "linemeshgeometry.h" +#include "gridmesh.h" + +#include +#include +#include +#include + +GridMesh::GridMesh(Qt3DCore::QNode *parent) + : Qt3DRender::QGeometryRenderer(parent) +{ + setInstanceCount(1); + setIndexOffset(0); + setFirstInstance(0); + setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); + + QVector2D s(20, 20); + QList vertices; + for (uint i = 0; i <= s.x(); i++) { + for (uint j = 0; j <= s.y(); j++) { + vertices.append(QVector4D(i, 0, 0, 0)); + vertices.append(QVector4D(i, j, 0, 0)); + + vertices.append(QVector4D(0, j, 0, 0)); + vertices.append(QVector4D(i, j, 0, 0)); + } + } + + auto geometry = new LineMeshGeometry(vertices, this); + setVertexCount(geometry->vertexCount()); + setGeometry(geometry); +} + +GridMesh::~GridMesh() +{ +} diff --git a/src/widgets/3dview/linemesh.h b/src/widgets/3dview/linemesh.h new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/linemesh.h @@ -0,0 +1,53 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include + +#include "gcodeto4d.h" + +class LineMeshGeometry; +class QString; +class QVector4D; + +class LineMesh : public Qt3DRender::QGeometryRenderer +{ + Q_OBJECT +public: + explicit LineMesh(Qt3DCore::QNode *parent = Q_NULLPTR); + ~LineMesh(); + Q_INVOKABLE void readAndRun(const QString &path); + void read(const QString &path); + void posUpdate(const QList &pos); + +signals: + void finished(); + void run(const QString &path); + +private: + QList _vertices; + LineMeshGeometry *_lineMeshGeo; + GcodeTo4D _gcode; +}; diff --git a/src/widgets/3dview/linemesh.cpp b/src/widgets/3dview/linemesh.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/linemesh.cpp @@ -0,0 +1,64 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "gcodeto4d.h" +#include "linemesh.h" +#include "linemeshgeometry.h" + +#include +#include +#include + +LineMesh::LineMesh(Qt3DCore::QNode *parent) + : Qt3DRender::QGeometryRenderer(parent) + , _lineMeshGeo(nullptr) +{ + setInstanceCount(1); + setIndexOffset(0); + setFirstInstance(0); + setPrimitiveType(Qt3DRender::QGeometryRenderer::LineStrip); + + qRegisterMetaType >("QList"); + connect(&_gcode, &GcodeTo4D::posFinished, this, &LineMesh::posUpdate); +} + +void LineMesh::readAndRun(const QString &path) +{ + _gcode.read(path); +} + +void LineMesh::read(const QString &path) +{ + emit run(path); +} + +void LineMesh::posUpdate(const QList &pos) +{ + _vertices = pos; + _lineMeshGeo = new LineMeshGeometry(_vertices, this); + setVertexCount(_lineMeshGeo->vertexCount()); + setGeometry(_lineMeshGeo); + emit finished(); +} + +LineMesh::~LineMesh() +{ +} diff --git a/src/widgets/3dview/linemeshgeometry.h b/src/widgets/3dview/linemeshgeometry.h new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/linemeshgeometry.h @@ -0,0 +1,41 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include + +class LineMeshGeometry : public Qt3DRender::QGeometry +{ + Q_OBJECT +public: + LineMeshGeometry(const QList &vertices, Qt3DCore::QNode *parent = Q_NULLPTR); + ~LineMeshGeometry(); + + int vertexCount(); + +private: + Qt3DRender::QAttribute *_positionAttribute; + Qt3DRender::QBuffer *_vertexBuffer; + QVector _vertices; +}; diff --git a/src/widgets/3dview/linemeshgeometry.cpp b/src/widgets/3dview/linemeshgeometry.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/linemeshgeometry.cpp @@ -0,0 +1,62 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "linemeshgeometry.h" + +#include +#include +#include + +LineMeshGeometry::LineMeshGeometry(const QList &vertices, Qt3DCore::QNode *parent) : + Qt3DRender::QGeometry(parent) + , _positionAttribute(new Qt3DRender::QAttribute(this)) + , _vertexBuffer(new Qt3DRender::QBuffer(Qt3DRender::QBuffer::VertexBuffer, this)) +{ + QByteArray vertexBufferData; + vertexBufferData.resize(vertices.size() * 3 * sizeof(float)); + float *rawVertexArray = reinterpret_cast(vertexBufferData.data()); + int idx = 0; + for (const auto &v : vertices) { + rawVertexArray[idx++] = v.x(); + rawVertexArray[idx++] = v.y(); + rawVertexArray[idx++] = v.z(); + _vertices.append(v.toVector3D()); + } + + _vertexBuffer->setData(vertexBufferData); + + _positionAttribute->setAttributeType(Qt3DRender::QAttribute::VertexAttribute); + _positionAttribute->setBuffer(_vertexBuffer); + _positionAttribute->setDataType(Qt3DRender::QAttribute::Float); + _positionAttribute->setDataSize(3); + _positionAttribute->setName(Qt3DRender::QAttribute::defaultPositionAttributeName()); + + addAttribute(_positionAttribute); +} + +int LineMeshGeometry::vertexCount() +{ + return _vertices.size(); +} + +LineMeshGeometry::~LineMeshGeometry() +{ +} diff --git a/src/widgets/3dview/viewer3d.h b/src/widgets/3dview/viewer3d.h new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/viewer3d.h @@ -0,0 +1,44 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#pragma once + +#include +#include +#include + +class LineMesh; +class QString; + +class Viewer3D : public QWidget +{ + Q_OBJECT + +public: + explicit Viewer3D(QWidget *parent = nullptr); + ~Viewer3D() override; + + void drawModel(QString file); +private: + QQuickView *_view; + LineMesh *_lineMesh; + QQmlApplicationEngine _engine; +}; diff --git a/src/widgets/3dview/viewer3d.cpp b/src/widgets/3dview/viewer3d.cpp new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/viewer3d.cpp @@ -0,0 +1,69 @@ +/* Atelier KDE Printer Host for 3D Printing + Copyright (C) <2017> + Author: Patrick José Pereira - patrickelectric@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 3 of + the License or any later version accepted by the membership of + KDE e.V. (or its successor approved by the membership of KDE + e.V.), which shall act as a proxy defined in Section 14 of + version 3 of the license. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "linemesh.h" +#include "gridmesh.h" +#include "viewer3d.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +Viewer3D::Viewer3D(QWidget *parent) + : QWidget(parent) + , _lineMesh(new LineMesh) +{ + Q_INIT_RESOURCE(viewer3d); + + QDirIterator it(QStringLiteral(":"), QDirIterator::Subdirectories); + while (it.hasNext()) { + qDebug() << it.next(); + } + + qmlRegisterType("GridMesh", 1, 0, "GridMesh"); + qmlRegisterType("LineMesh", 1, 0, "LineMesh"); + + _view = new QQuickView(&_engine, nullptr); + _view->setResizeMode(QQuickView::SizeRootObjectToView); + _view->setSource(QUrl(QStringLiteral("qrc:/viewer3d.qml"))); + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addWidget(QWidget::createWindowContainer(_view)); + this->setLayout(mainLayout); +} + +void Viewer3D::drawModel(QString file) +{ + + QObject *object = _view->rootObject(); + QObject *fileName = object->findChild(QStringLiteral("fileName")); + fileName->setProperty("text", QVariant(file)); +} + +Viewer3D::~Viewer3D() +{ +} diff --git a/src/widgets/3dview/viewer3d.qml b/src/widgets/3dview/viewer3d.qml new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/viewer3d.qml @@ -0,0 +1,36 @@ +import QtQuick 2.0 +import QtQuick.Scene3D 2.0 +import LineMesh 1.0 + +Item { + id: item + width: 1000 + height: 1000 + Rectangle { + id: scene + anchors.fill: parent + Scene3D { + id: scene3d + anchors.fill: parent + focus: true + aspects: ["input", "logic"] + cameraAspectRatioMode: Scene3D.AutomaticAspectRatio + AnimatedEntity { + id: entity + onFpsChanged: { + // print(fps) + } + } + + } + } + + Text { + objectName: "fileName" + id: fileName + text: "" + onTextChanged: { + entity.runLineMesh(text) + } + } +} diff --git a/src/widgets/3dview/viewer3d.qrc b/src/widgets/3dview/viewer3d.qrc new file mode 100644 --- /dev/null +++ b/src/widgets/3dview/viewer3d.qrc @@ -0,0 +1,6 @@ + + + AnimatedEntity.qml + viewer3d.qml + + diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -11,4 +11,13 @@ add_library(AtelierWidgets STATIC ${widgets_SRCS}) -target_link_libraries(AtelierWidgets Qt5::Core Qt5::Widgets Qt5::SerialPort KF5::Solid KF5::I18n KF5::TextEditor Qt5::Charts) +target_link_libraries(AtelierWidgets + Qt5::Core + Qt5::Widgets + Qt5::SerialPort + KF5::Solid + KF5::I18n + KF5::TextEditor + Qt5::Charts) + +add_subdirectory(3dview)