From 982ee45a162d4a846aa37cff7034eb60c6e29293 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 11 Apr 2018 17:19:27 +0800 Subject: [PATCH] Add part enable/disable --- src/meshgenerator.cpp | 15 ++++++++- src/skeletondocument.cpp | 17 +++++++++- src/skeletondocument.h | 6 +++- src/skeletondocumentwindow.cpp | 1 + src/skeletonpartlistwidget.cpp | 61 +++++++++++++++++++++++++++++----- src/skeletonpartlistwidget.h | 4 +++ 6 files changed, 93 insertions(+), 11 deletions(-) diff --git a/src/meshgenerator.cpp b/src/meshgenerator.cpp index 72c9cd0c..59e29feb 100644 --- a/src/meshgenerator.cpp +++ b/src/meshgenerator.cpp @@ -147,6 +147,13 @@ void MeshGenerator::process() float mainProfileMiddleY = mainProfile.y() + mainProfile.height() / 2; for (const auto &partIdIt: m_snapshot->partIdList) { + const auto &part = m_snapshot->parts.find(partIdIt); + if (part == m_snapshot->parts.end()) + continue; + QString disabledString = valueOfKeyInMapOrEmpty(part->second, "disabled"); + bool isDisabled = isTrueValueString(disabledString); + if (isDisabled) + continue; int bmeshId = meshlite_bmesh_create(meshliteContext); if (MeshGenerator::enableDebug) meshlite_bmesh_enable_debug(meshliteContext, bmeshId, 1); @@ -221,7 +228,13 @@ void MeshGenerator::process() std::vector meshIds; std::vector subdivMeshIds; for (const auto &partIdIt: m_snapshot->partIdList) { - const auto part = m_snapshot->parts.find(partIdIt); + const auto &part = m_snapshot->parts.find(partIdIt); + if (part == m_snapshot->parts.end()) + continue; + QString disabledString = valueOfKeyInMapOrEmpty(part->second, "disabled"); + bool isDisabled = isTrueValueString(disabledString); + if (isDisabled) + continue; int bmeshId = partBmeshMap[partIdIt]; int meshId = meshlite_bmesh_generate_mesh(meshliteContext, bmeshId); bool subdived = isTrueValueString(part->second["subdived"]); diff --git a/src/skeletondocument.cpp b/src/skeletondocument.cpp index c7844d46..eb274780 100644 --- a/src/skeletondocument.cpp +++ b/src/skeletondocument.cpp @@ -500,6 +500,7 @@ void SkeletonDocument::toSnapshot(SkeletonSnapshot *snapshot, const std::setparts[part["id"]] = part; @@ -553,6 +554,7 @@ void SkeletonDocument::addFromSnapshot(const SkeletonSnapshot &snapshot) part.visible = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "visible")); part.locked = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "locked")); part.subdived = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "subdived")); + part.disabled = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "disabled")); partMap[part.id] = part; } for (const auto &nodeKv : snapshot.nodes) { @@ -743,7 +745,6 @@ void SkeletonDocument::setPartVisibleState(QUuid partId, bool visible) return; part->second.visible = visible; emit partVisibleStateChanged(partId); - emit skeletonChanged(); } void SkeletonDocument::setPartSubdivState(QUuid partId, bool subdived) @@ -760,6 +761,20 @@ void SkeletonDocument::setPartSubdivState(QUuid partId, bool subdived) emit skeletonChanged(); } +void SkeletonDocument::setPartDisableState(QUuid partId, bool disabled) +{ + auto part = partMap.find(partId); + if (part == partMap.end()) { + qDebug() << "Part not found:" << partId; + return; + } + if (part->second.disabled == disabled) + return; + part->second.disabled = disabled; + emit partDisableStateChanged(partId); + emit skeletonChanged(); +} + void SkeletonDocument::saveSnapshot() { if (m_undoItems.size() + 1 > m_maxSnapshot) diff --git a/src/skeletondocument.h b/src/skeletondocument.h index 4e2e31e0..aff26568 100644 --- a/src/skeletondocument.h +++ b/src/skeletondocument.h @@ -67,12 +67,14 @@ public: bool visible; bool locked; bool subdived; + bool disabled; QImage preview; std::vector nodeIds; SkeletonPart(const QUuid &withId=QUuid()) : visible(true), locked(false), - subdived(false) + subdived(false), + disabled(false) { id = withId.isNull() ? QUuid::createUuid() : withId; } @@ -123,6 +125,7 @@ signals: void partLockStateChanged(QUuid partId); void partVisibleStateChanged(QUuid partId); void partSubdivStateChanged(QUuid partId); + void partDisableStateChanged(QUuid partId); void cleanup(); public: SkeletonDocument(); @@ -163,6 +166,7 @@ public slots: void setPartLockState(QUuid partId, bool locked); void setPartVisibleState(QUuid partId, bool visible); void setPartSubdivState(QUuid partId, bool subdived); + void setPartDisableState(QUuid partId, bool disabled); void saveSnapshot(); void undo(); void redo(); diff --git a/src/skeletondocumentwindow.cpp b/src/skeletondocumentwindow.cpp index 268edba3..6f0b6670 100644 --- a/src/skeletondocumentwindow.cpp +++ b/src/skeletondocumentwindow.cpp @@ -369,6 +369,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() : connect(m_document, &SkeletonDocument::partLockStateChanged, partListWidget, &SkeletonPartListWidget::partLockStateChanged); connect(m_document, &SkeletonDocument::partVisibleStateChanged, partListWidget, &SkeletonPartListWidget::partVisibleStateChanged); connect(m_document, &SkeletonDocument::partSubdivStateChanged, partListWidget, &SkeletonPartListWidget::partSubdivStateChanged); + connect(m_document, &SkeletonDocument::partDisableStateChanged, partListWidget, &SkeletonPartListWidget::partDisableStateChanged); connect(m_document, &SkeletonDocument::cleanup, partListWidget, &SkeletonPartListWidget::partListChanged); connect(m_document, &SkeletonDocument::skeletonChanged, m_document, &SkeletonDocument::generateMesh); diff --git a/src/skeletonpartlistwidget.cpp b/src/skeletonpartlistwidget.cpp index adb2740e..5c53d069 100644 --- a/src/skeletonpartlistwidget.cpp +++ b/src/skeletonpartlistwidget.cpp @@ -20,15 +20,25 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p updateButton(m_subdivButton, QChar(fa::cube), false); initButton(m_subdivButton); + m_disableButton = new QPushButton(); + updateButton(m_disableButton, QChar(fa::toggleon), false); + initButton(m_disableButton); + m_previewLabel = new QLabel; - QHBoxLayout *miniToolLayout = new QHBoxLayout; - miniToolLayout->setSpacing(0); - miniToolLayout->setContentsMargins(0, 0, 0, 0); - miniToolLayout->addWidget(m_visibleButton); - miniToolLayout->addWidget(m_lockButton); - miniToolLayout->addWidget(m_subdivButton); - miniToolLayout->addStretch(); + QHBoxLayout *miniTopToolLayout = new QHBoxLayout; + miniTopToolLayout->setSpacing(0); + miniTopToolLayout->setContentsMargins(0, 0, 0, 0); + miniTopToolLayout->addWidget(m_visibleButton); + miniTopToolLayout->addWidget(m_lockButton); + miniTopToolLayout->addWidget(m_subdivButton); + miniTopToolLayout->addStretch(); + + QHBoxLayout *miniBottomToolLayout = new QHBoxLayout; + miniBottomToolLayout->setSpacing(0); + miniBottomToolLayout->setContentsMargins(0, 0, 0, 0); + miniBottomToolLayout->addWidget(m_disableButton); + miniBottomToolLayout->addStretch(); QWidget *hrWidget = new QWidget; hrWidget->setFixedHeight(1); @@ -39,8 +49,9 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setSpacing(0); mainLayout->setContentsMargins(0, 0, 0, 0); - mainLayout->addLayout(miniToolLayout); + mainLayout->addLayout(miniTopToolLayout); mainLayout->addWidget(m_previewLabel); + mainLayout->addLayout(miniBottomToolLayout); mainLayout->addWidget(hrWidget); setLayout(mainLayout); @@ -48,6 +59,7 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p connect(this, &SkeletonPartWidget::setPartLockState, m_document, &SkeletonDocument::setPartLockState); connect(this, &SkeletonPartWidget::setPartVisibleState, m_document, &SkeletonDocument::setPartVisibleState); connect(this, &SkeletonPartWidget::setPartSubdivState, m_document, &SkeletonDocument::setPartSubdivState); + connect(this, &SkeletonPartWidget::setPartDisableState, m_document, &SkeletonDocument::setPartDisableState); connect(m_lockButton, &QPushButton::clicked, [=]() { if (m_lockButton->text() == QChar(fa::lock)) { @@ -72,6 +84,14 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p emit setPartSubdivState(m_partId, false); } }); + + connect(m_disableButton, &QPushButton::clicked, [=]() { + if (m_disableButton->text() == QChar(fa::link)) { + emit setPartDisableState(m_partId, true); + } else { + emit setPartDisableState(m_partId, false); + } + }); } void SkeletonPartWidget::initButton(QPushButton *button) @@ -138,12 +158,26 @@ void SkeletonPartWidget::updateSubdivButton() updateButton(m_subdivButton, QChar(fa::cube), false); } +void SkeletonPartWidget::updateDisableButton() +{ + const SkeletonPart *part = m_document->findPart(m_partId); + if (!part) { + qDebug() << "Part not found:" << m_partId; + return; + } + if (part->disabled) + updateButton(m_disableButton, QChar(fa::unlink), true); + else + updateButton(m_disableButton, QChar(fa::link), false); +} + void SkeletonPartWidget::reload() { updatePreview(); updateLockButton(); updateVisibleButton(); updateSubdivButton(); + updateDisableButton(); } SkeletonPartListWidget::SkeletonPartListWidget(const SkeletonDocument *document) : @@ -227,3 +261,14 @@ void SkeletonPartListWidget::partSubdivStateChanged(QUuid partId) SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second); widget->updateSubdivButton(); } + +void SkeletonPartListWidget::partDisableStateChanged(QUuid partId) +{ + auto item = m_itemMap.find(partId); + if (item == m_itemMap.end()) { + qDebug() << "Part item not found:" << partId; + return; + } + SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second); + widget->updateDisableButton(); +} diff --git a/src/skeletonpartlistwidget.h b/src/skeletonpartlistwidget.h index 343cde81..9b7e1174 100644 --- a/src/skeletonpartlistwidget.h +++ b/src/skeletonpartlistwidget.h @@ -13,6 +13,7 @@ signals: void setPartLockState(QUuid partId, bool locked); void setPartVisibleState(QUuid partId, bool visible); void setPartSubdivState(QUuid partId, bool subdived); + void setPartDisableState(QUuid partId, bool disabled); public: SkeletonPartWidget(const SkeletonDocument *document, QUuid partId); void reload(); @@ -20,6 +21,7 @@ public: void updateLockButton(); void updateVisibleButton(); void updateSubdivButton(); + void updateDisableButton(); private: const SkeletonDocument *m_document; QUuid m_partId; @@ -27,6 +29,7 @@ private: QPushButton *m_visibleButton; QPushButton *m_lockButton; QPushButton *m_subdivButton; + QPushButton *m_disableButton; QLabel *m_nameLabel; private: void initButton(QPushButton *button); @@ -45,6 +48,7 @@ public slots: void partLockStateChanged(QUuid partId); void partVisibleStateChanged(QUuid partId); void partSubdivStateChanged(QUuid partId); + void partDisableStateChanged(QUuid partId); private: const SkeletonDocument *m_document; std::map m_itemMap;