Add part enable/disable

master
Jeremy Hu 2018-04-11 17:19:27 +08:00
parent 2d9f64ebc2
commit 982ee45a16
6 changed files with 93 additions and 11 deletions

View File

@ -147,6 +147,13 @@ void MeshGenerator::process()
float mainProfileMiddleY = mainProfile.y() + mainProfile.height() / 2; float mainProfileMiddleY = mainProfile.y() + mainProfile.height() / 2;
for (const auto &partIdIt: m_snapshot->partIdList) { 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); int bmeshId = meshlite_bmesh_create(meshliteContext);
if (MeshGenerator::enableDebug) if (MeshGenerator::enableDebug)
meshlite_bmesh_enable_debug(meshliteContext, bmeshId, 1); meshlite_bmesh_enable_debug(meshliteContext, bmeshId, 1);
@ -221,7 +228,13 @@ void MeshGenerator::process()
std::vector<int> meshIds; std::vector<int> meshIds;
std::vector<int> subdivMeshIds; std::vector<int> subdivMeshIds;
for (const auto &partIdIt: m_snapshot->partIdList) { 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 bmeshId = partBmeshMap[partIdIt];
int meshId = meshlite_bmesh_generate_mesh(meshliteContext, bmeshId); int meshId = meshlite_bmesh_generate_mesh(meshliteContext, bmeshId);
bool subdived = isTrueValueString(part->second["subdived"]); bool subdived = isTrueValueString(part->second["subdived"]);

View File

@ -500,6 +500,7 @@ void SkeletonDocument::toSnapshot(SkeletonSnapshot *snapshot, const std::set<QUu
part["visible"] = partIt.second.visible ? "true" : "false"; part["visible"] = partIt.second.visible ? "true" : "false";
part["locked"] = partIt.second.locked ? "true" : "false"; part["locked"] = partIt.second.locked ? "true" : "false";
part["subdived"] = partIt.second.subdived ? "true" : "false"; part["subdived"] = partIt.second.subdived ? "true" : "false";
part["disabled"] = partIt.second.disabled ? "true" : "false";
if (!partIt.second.name.isEmpty()) if (!partIt.second.name.isEmpty())
part["name"] = partIt.second.name; part["name"] = partIt.second.name;
snapshot->parts[part["id"]] = part; snapshot->parts[part["id"]] = part;
@ -553,6 +554,7 @@ void SkeletonDocument::addFromSnapshot(const SkeletonSnapshot &snapshot)
part.visible = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "visible")); part.visible = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "visible"));
part.locked = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "locked")); part.locked = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "locked"));
part.subdived = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "subdived")); part.subdived = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "subdived"));
part.disabled = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "disabled"));
partMap[part.id] = part; partMap[part.id] = part;
} }
for (const auto &nodeKv : snapshot.nodes) { for (const auto &nodeKv : snapshot.nodes) {
@ -743,7 +745,6 @@ void SkeletonDocument::setPartVisibleState(QUuid partId, bool visible)
return; return;
part->second.visible = visible; part->second.visible = visible;
emit partVisibleStateChanged(partId); emit partVisibleStateChanged(partId);
emit skeletonChanged();
} }
void SkeletonDocument::setPartSubdivState(QUuid partId, bool subdived) void SkeletonDocument::setPartSubdivState(QUuid partId, bool subdived)
@ -760,6 +761,20 @@ void SkeletonDocument::setPartSubdivState(QUuid partId, bool subdived)
emit skeletonChanged(); 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() void SkeletonDocument::saveSnapshot()
{ {
if (m_undoItems.size() + 1 > m_maxSnapshot) if (m_undoItems.size() + 1 > m_maxSnapshot)

View File

@ -67,12 +67,14 @@ public:
bool visible; bool visible;
bool locked; bool locked;
bool subdived; bool subdived;
bool disabled;
QImage preview; QImage preview;
std::vector<QUuid> nodeIds; std::vector<QUuid> nodeIds;
SkeletonPart(const QUuid &withId=QUuid()) : SkeletonPart(const QUuid &withId=QUuid()) :
visible(true), visible(true),
locked(false), locked(false),
subdived(false) subdived(false),
disabled(false)
{ {
id = withId.isNull() ? QUuid::createUuid() : withId; id = withId.isNull() ? QUuid::createUuid() : withId;
} }
@ -123,6 +125,7 @@ signals:
void partLockStateChanged(QUuid partId); void partLockStateChanged(QUuid partId);
void partVisibleStateChanged(QUuid partId); void partVisibleStateChanged(QUuid partId);
void partSubdivStateChanged(QUuid partId); void partSubdivStateChanged(QUuid partId);
void partDisableStateChanged(QUuid partId);
void cleanup(); void cleanup();
public: public:
SkeletonDocument(); SkeletonDocument();
@ -163,6 +166,7 @@ public slots:
void setPartLockState(QUuid partId, bool locked); void setPartLockState(QUuid partId, bool locked);
void setPartVisibleState(QUuid partId, bool visible); void setPartVisibleState(QUuid partId, bool visible);
void setPartSubdivState(QUuid partId, bool subdived); void setPartSubdivState(QUuid partId, bool subdived);
void setPartDisableState(QUuid partId, bool disabled);
void saveSnapshot(); void saveSnapshot();
void undo(); void undo();
void redo(); void redo();

View File

@ -369,6 +369,7 @@ SkeletonDocumentWindow::SkeletonDocumentWindow() :
connect(m_document, &SkeletonDocument::partLockStateChanged, partListWidget, &SkeletonPartListWidget::partLockStateChanged); connect(m_document, &SkeletonDocument::partLockStateChanged, partListWidget, &SkeletonPartListWidget::partLockStateChanged);
connect(m_document, &SkeletonDocument::partVisibleStateChanged, partListWidget, &SkeletonPartListWidget::partVisibleStateChanged); connect(m_document, &SkeletonDocument::partVisibleStateChanged, partListWidget, &SkeletonPartListWidget::partVisibleStateChanged);
connect(m_document, &SkeletonDocument::partSubdivStateChanged, partListWidget, &SkeletonPartListWidget::partSubdivStateChanged); 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::cleanup, partListWidget, &SkeletonPartListWidget::partListChanged);
connect(m_document, &SkeletonDocument::skeletonChanged, m_document, &SkeletonDocument::generateMesh); connect(m_document, &SkeletonDocument::skeletonChanged, m_document, &SkeletonDocument::generateMesh);

View File

@ -20,15 +20,25 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p
updateButton(m_subdivButton, QChar(fa::cube), false); updateButton(m_subdivButton, QChar(fa::cube), false);
initButton(m_subdivButton); initButton(m_subdivButton);
m_disableButton = new QPushButton();
updateButton(m_disableButton, QChar(fa::toggleon), false);
initButton(m_disableButton);
m_previewLabel = new QLabel; m_previewLabel = new QLabel;
QHBoxLayout *miniToolLayout = new QHBoxLayout; QHBoxLayout *miniTopToolLayout = new QHBoxLayout;
miniToolLayout->setSpacing(0); miniTopToolLayout->setSpacing(0);
miniToolLayout->setContentsMargins(0, 0, 0, 0); miniTopToolLayout->setContentsMargins(0, 0, 0, 0);
miniToolLayout->addWidget(m_visibleButton); miniTopToolLayout->addWidget(m_visibleButton);
miniToolLayout->addWidget(m_lockButton); miniTopToolLayout->addWidget(m_lockButton);
miniToolLayout->addWidget(m_subdivButton); miniTopToolLayout->addWidget(m_subdivButton);
miniToolLayout->addStretch(); 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; QWidget *hrWidget = new QWidget;
hrWidget->setFixedHeight(1); hrWidget->setFixedHeight(1);
@ -39,8 +49,9 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->setSpacing(0); mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addLayout(miniToolLayout); mainLayout->addLayout(miniTopToolLayout);
mainLayout->addWidget(m_previewLabel); mainLayout->addWidget(m_previewLabel);
mainLayout->addLayout(miniBottomToolLayout);
mainLayout->addWidget(hrWidget); mainLayout->addWidget(hrWidget);
setLayout(mainLayout); setLayout(mainLayout);
@ -48,6 +59,7 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p
connect(this, &SkeletonPartWidget::setPartLockState, m_document, &SkeletonDocument::setPartLockState); connect(this, &SkeletonPartWidget::setPartLockState, m_document, &SkeletonDocument::setPartLockState);
connect(this, &SkeletonPartWidget::setPartVisibleState, m_document, &SkeletonDocument::setPartVisibleState); connect(this, &SkeletonPartWidget::setPartVisibleState, m_document, &SkeletonDocument::setPartVisibleState);
connect(this, &SkeletonPartWidget::setPartSubdivState, m_document, &SkeletonDocument::setPartSubdivState); connect(this, &SkeletonPartWidget::setPartSubdivState, m_document, &SkeletonDocument::setPartSubdivState);
connect(this, &SkeletonPartWidget::setPartDisableState, m_document, &SkeletonDocument::setPartDisableState);
connect(m_lockButton, &QPushButton::clicked, [=]() { connect(m_lockButton, &QPushButton::clicked, [=]() {
if (m_lockButton->text() == QChar(fa::lock)) { if (m_lockButton->text() == QChar(fa::lock)) {
@ -72,6 +84,14 @@ SkeletonPartWidget::SkeletonPartWidget(const SkeletonDocument *document, QUuid p
emit setPartSubdivState(m_partId, false); 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) void SkeletonPartWidget::initButton(QPushButton *button)
@ -138,12 +158,26 @@ void SkeletonPartWidget::updateSubdivButton()
updateButton(m_subdivButton, QChar(fa::cube), false); 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() void SkeletonPartWidget::reload()
{ {
updatePreview(); updatePreview();
updateLockButton(); updateLockButton();
updateVisibleButton(); updateVisibleButton();
updateSubdivButton(); updateSubdivButton();
updateDisableButton();
} }
SkeletonPartListWidget::SkeletonPartListWidget(const SkeletonDocument *document) : SkeletonPartListWidget::SkeletonPartListWidget(const SkeletonDocument *document) :
@ -227,3 +261,14 @@ void SkeletonPartListWidget::partSubdivStateChanged(QUuid partId)
SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second); SkeletonPartWidget *widget = (SkeletonPartWidget *)itemWidget(item->second);
widget->updateSubdivButton(); 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();
}

View File

@ -13,6 +13,7 @@ signals:
void setPartLockState(QUuid partId, bool locked); void setPartLockState(QUuid partId, bool locked);
void setPartVisibleState(QUuid partId, bool visible); void setPartVisibleState(QUuid partId, bool visible);
void setPartSubdivState(QUuid partId, bool subdived); void setPartSubdivState(QUuid partId, bool subdived);
void setPartDisableState(QUuid partId, bool disabled);
public: public:
SkeletonPartWidget(const SkeletonDocument *document, QUuid partId); SkeletonPartWidget(const SkeletonDocument *document, QUuid partId);
void reload(); void reload();
@ -20,6 +21,7 @@ public:
void updateLockButton(); void updateLockButton();
void updateVisibleButton(); void updateVisibleButton();
void updateSubdivButton(); void updateSubdivButton();
void updateDisableButton();
private: private:
const SkeletonDocument *m_document; const SkeletonDocument *m_document;
QUuid m_partId; QUuid m_partId;
@ -27,6 +29,7 @@ private:
QPushButton *m_visibleButton; QPushButton *m_visibleButton;
QPushButton *m_lockButton; QPushButton *m_lockButton;
QPushButton *m_subdivButton; QPushButton *m_subdivButton;
QPushButton *m_disableButton;
QLabel *m_nameLabel; QLabel *m_nameLabel;
private: private:
void initButton(QPushButton *button); void initButton(QPushButton *button);
@ -45,6 +48,7 @@ public slots:
void partLockStateChanged(QUuid partId); void partLockStateChanged(QUuid partId);
void partVisibleStateChanged(QUuid partId); void partVisibleStateChanged(QUuid partId);
void partSubdivStateChanged(QUuid partId); void partSubdivStateChanged(QUuid partId);
void partDisableStateChanged(QUuid partId);
private: private:
const SkeletonDocument *m_document; const SkeletonDocument *m_document;
std::map<QUuid, QListWidgetItem *> m_itemMap; std::map<QUuid, QListWidgetItem *> m_itemMap;