From 24fbff4218b11c3cc9aa1d93ff0b0a3e1979b00f Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Sun, 18 Mar 2018 16:46:53 +0800 Subject: [PATCH] Add node delete operation --- src/main.cpp | 4 +++ src/mainwindow.cpp | 1 + src/skeletoneditgraphicsview.cpp | 57 ++++++++++++++++++++++++++++++++ src/skeletoneditgraphicsview.h | 3 ++ src/skeletontomesh.cpp | 3 +- 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bcd16e34..1fceb064 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "mainwindow.h" #include "meshlite.h" @@ -30,6 +31,9 @@ int main(int argc, char ** argv) QCoreApplication::setApplicationName("Dust 3D"); + const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); + QApplication::setFont(fixedFont); + MainWindow mainWindow; mainWindow.showMaximized(); return app.exec(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5c6e03ca..5c6be9c9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -149,6 +149,7 @@ void MainWindow::loadModel() } } } + m_skeletonWidget->graphicsView()->turnOffAddNodeMode(); } void MainWindow::saveModel() diff --git a/src/skeletoneditgraphicsview.cpp b/src/skeletoneditgraphicsview.cpp index e79ce62a..ea01a3ba 100644 --- a/src/skeletoneditgraphicsview.cpp +++ b/src/skeletoneditgraphicsview.cpp @@ -116,6 +116,60 @@ float SkeletonEditGraphicsView::findXForSlave(float x) return x - m_backgroundItem->boundingRect().width() / 4; } +void SkeletonEditGraphicsView::removeSelectedItems() +{ + if (m_nextStartNodeItem) { + SkeletonEditNodeItem *nodeItem = m_nextStartNodeItem; + setNextStartNodeItem(NULL); + removeNodeItem(nodeItem); + emit nodesChanged(); + } +} + +void SkeletonEditGraphicsView::removeNodeItem(SkeletonEditNodeItem *nodeItem) +{ + if (nodeItem->pair()) { + scene()->removeItem(nodeItem->pair()); + } + scene()->removeItem(nodeItem); + QList::iterator it; + QList list = scene()->items(); + for (it = list.begin(); it != list.end(); ++it) { + if ((*it)->data(0).toString() == "edge") { + SkeletonEditEdgeItem *edgeItem = static_cast(*it); + if (edgeItem->firstNode() == nodeItem || edgeItem->secondNode() == nodeItem) { + scene()->removeItem(edgeItem); + } + } + } +} + +void SkeletonEditGraphicsView::removeGroupByNodeItem(SkeletonEditNodeItem *nodeItem) +{ + if (nodeItem->pair()) { + scene()->removeItem(nodeItem->pair()); + } + scene()->removeItem(nodeItem); + QList::iterator it; + QList list = scene()->items(); + std::vector delayRemoveList; + for (it = list.begin(); it != list.end(); ++it) { + if ((*it)->data(0).toString() == "edge") { + SkeletonEditEdgeItem *edgeItem = static_cast(*it); + if (edgeItem->firstNode() == nodeItem) { + scene()->removeItem(edgeItem); + delayRemoveList.push_back(edgeItem->secondNode()); + } else if (edgeItem->secondNode() == nodeItem) { + scene()->removeItem(edgeItem); + delayRemoveList.push_back(edgeItem->firstNode()); + } + } + } + for (size_t i = 0; i < delayRemoveList.size(); i++) { + removeNodeItem(delayRemoveList[i]); + } +} + void SkeletonEditGraphicsView::keyPressEvent(QKeyEvent *event) { QWidget::keyPressEvent(event); @@ -123,6 +177,9 @@ void SkeletonEditGraphicsView::keyPressEvent(QKeyEvent *event) return; if (event->key() == Qt::Key_A) toggleAddNodeMode(); + else if (event->key() == Qt::Key_Delete || event->key() ==Qt::Key_Backspace) { + removeSelectedItems(); + } } void SkeletonEditGraphicsView::resizeEvent(QResizeEvent *event) diff --git a/src/skeletoneditgraphicsview.h b/src/skeletoneditgraphicsview.h index e0351605..b263407c 100644 --- a/src/skeletoneditgraphicsview.h +++ b/src/skeletoneditgraphicsview.h @@ -55,6 +55,9 @@ private: void AddItemRadius(QGraphicsEllipseItem *item, float delta); bool canAddItemRadius(QGraphicsEllipseItem *item, float delta); void adjustItems(QSizeF oldSceneSize, QSizeF newSceneSize); + void removeSelectedItems(); + void removeNodeItem(SkeletonEditNodeItem *nodeItem); + void removeGroupByNodeItem(SkeletonEditNodeItem *nodeItem); }; #endif diff --git a/src/skeletontomesh.cpp b/src/skeletontomesh.cpp index ee4d7f96..dcaea2d6 100644 --- a/src/skeletontomesh.cpp +++ b/src/skeletontomesh.cpp @@ -267,7 +267,7 @@ Mesh *SkeletonToMesh::takeResultMesh() return mesh; } -#define USE_CARVE 0 +#define USE_CARVE 1 #if USE_CARVE #define ExternalMesh carve::poly::Polyhedron @@ -342,7 +342,6 @@ void SkeletonToMesh::process() meshlite_bmesh_add_edge(context, group->bmeshId, firstNode->bmeshNodeId, secondNode->bmeshNodeId); } group->meshId = meshlite_bmesh_generate_mesh(context, group->bmeshId, group->nodes[group->rootNode].bmeshNodeId); - group->meshId = meshlite_triangulate(context, group->meshId); } ExternalMesh *unionPolyhedron = makeExternalMeshFromMeshlite(context, m_groups[0].meshId);