Disable three nodes branch by default

Three nodes branch wrapping is very easy to fail, so disable by default.
master
Jeremy Hu 2019-06-26 21:05:56 +09:30
parent 4689ed163a
commit 1d04e1771e
8 changed files with 68 additions and 6 deletions

View File

@ -28,3 +28,4 @@ bvanevery <https://www.reddit.com/user/bvanevery>
Toshio Araki <https://github.com/Toshiwoz> Toshio Araki <https://github.com/Toshiwoz>
Evan Gruda <evangruda@ufl.edu> Evan Gruda <evangruda@ufl.edu>
KeepFenDou <https://github.com/KeepFenDou> KeepFenDou <https://github.com/KeepFenDou>
Kubilay Yalçın <https://twitter.com/KhaynaraKioni>

View File

@ -61,6 +61,9 @@ Document::Document() :
{ {
connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange); connect(&Preferences::instance(), &Preferences::partColorChanged, this, &Document::applyPreferencePartColorChange);
connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange); connect(&Preferences::instance(), &Preferences::flatShadingChanged, this, &Document::applyPreferenceFlatShadingChange);
connect(&Preferences::instance(), &Preferences::threeNodesBranchEnableStateChanged, this, [&]() {
threeNodesBranchEnabled = Preferences::instance().threeNodesBranchEnabled();
});
} }
void Document::applyPreferencePartColorChange() void Document::applyPreferencePartColorChange()

View File

@ -15,6 +15,7 @@ void Preferences::loadDefault()
m_componentCombineMode = CombineMode::Normal; m_componentCombineMode = CombineMode::Normal;
m_partColor = Qt::white; m_partColor = Qt::white;
m_flatShading = false; m_flatShading = false;
m_threeNodesBranchEnabled = false;
} }
Preferences::Preferences() Preferences::Preferences()
@ -32,9 +33,16 @@ Preferences::Preferences()
} }
{ {
QString value = m_settings.value("flatShading").toString(); QString value = m_settings.value("flatShading").toString();
if (!value.isEmpty()) if (value.isEmpty())
m_flatShading = true;
else
m_flatShading = isTrueValueString(value); m_flatShading = isTrueValueString(value);
} }
{
QString value = m_settings.value("threeNodesBranchEnabled").toString();
if (!value.isEmpty())
m_threeNodesBranchEnabled = isTrueValueString(value);
}
} }
CombineMode Preferences::componentCombineMode() const CombineMode Preferences::componentCombineMode() const
@ -52,6 +60,11 @@ bool Preferences::flatShading() const
return m_flatShading; return m_flatShading;
} }
bool Preferences::threeNodesBranchEnabled() const
{
return m_threeNodesBranchEnabled;
}
void Preferences::setComponentCombineMode(CombineMode mode) void Preferences::setComponentCombineMode(CombineMode mode)
{ {
if (m_componentCombineMode == mode) if (m_componentCombineMode == mode)
@ -79,6 +92,15 @@ void Preferences::setFlatShading(bool flatShading)
emit flatShadingChanged(); emit flatShadingChanged();
} }
void Preferences::setThreeNodesBranchEnableState(bool enabled)
{
if (m_threeNodesBranchEnabled == enabled)
return;
m_threeNodesBranchEnabled = enabled;
m_settings.setValue("threeNodesBranchEnabled", enabled ? "true" : "false");
emit threeNodesBranchEnableStateChanged();
}
void Preferences::reset() void Preferences::reset()
{ {
m_settings.clear(); m_settings.clear();
@ -86,4 +108,5 @@ void Preferences::reset()
emit componentCombineModeChanged(); emit componentCombineModeChanged();
emit partColorChanged(); emit partColorChanged();
emit flatShadingChanged(); emit flatShadingChanged();
emit threeNodesBranchEnableStateChanged();
} }

View File

@ -13,20 +13,24 @@ public:
CombineMode componentCombineMode() const; CombineMode componentCombineMode() const;
const QColor &partColor() const; const QColor &partColor() const;
bool flatShading() const; bool flatShading() const;
bool threeNodesBranchEnabled() const;
signals: signals:
void componentCombineModeChanged(); void componentCombineModeChanged();
void partColorChanged(); void partColorChanged();
void flatShadingChanged(); void flatShadingChanged();
void threeNodesBranchEnableStateChanged();
public slots: public slots:
void setComponentCombineMode(CombineMode mode); void setComponentCombineMode(CombineMode mode);
void setPartColor(const QColor &color); void setPartColor(const QColor &color);
void setFlatShading(bool flatShading); void setFlatShading(bool flatShading);
void setThreeNodesBranchEnableState(bool enabled);
void reset(); void reset();
private: private:
CombineMode m_componentCombineMode = CombineMode::Normal; CombineMode m_componentCombineMode = CombineMode::Normal;
QColor m_partColor; QColor m_partColor;
bool m_flatShading; bool m_flatShading;
QSettings m_settings; QSettings m_settings;
bool m_threeNodesBranchEnabled;
private: private:
void loadDefault(); void loadDefault();
}; };

View File

@ -60,15 +60,22 @@ PreferencesWidget::PreferencesWidget(const Document *document, QWidget *parent)
Preferences::instance().setFlatShading(flatShadingBox->isChecked()); Preferences::instance().setFlatShading(flatShadingBox->isChecked());
}); });
QCheckBox *threeNodesBranchEnabledBox = new QCheckBox();
connect(threeNodesBranchEnabledBox, &QCheckBox::stateChanged, this, [=]() {
Preferences::instance().setThreeNodesBranchEnableState(threeNodesBranchEnabledBox->isChecked());
});
QFormLayout *formLayout = new QFormLayout; QFormLayout *formLayout = new QFormLayout;
formLayout->addRow(tr("Part color:"), colorLayout); formLayout->addRow(tr("Part color:"), colorLayout);
formLayout->addRow(tr("Combine mode:"), combineModeSelectBox); formLayout->addRow(tr("Combine mode:"), combineModeSelectBox);
formLayout->addRow(tr("Flat shading:"), flatShadingBox); formLayout->addRow(tr("Flat shading:"), flatShadingBox);
formLayout->addRow(tr("Three nodes branch:"), threeNodesBranchEnabledBox);
auto loadFromPreferences = [=]() { auto loadFromPreferences = [=]() {
updatePickButtonColor(); updatePickButtonColor();
combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode()); combineModeSelectBox->setCurrentIndex((int)Preferences::instance().componentCombineMode());
flatShadingBox->setChecked(Preferences::instance().flatShading()); flatShadingBox->setChecked(Preferences::instance().flatShading());
threeNodesBranchEnabledBox->setChecked(Preferences::instance().threeNodesBranchEnabled());
}; };
loadFromPreferences(); loadFromPreferences();

View File

@ -71,3 +71,12 @@ void SkeletonDocument::findAllNeighbors(QUuid nodeId, std::set<QUuid> &neighbors
} }
} }
bool SkeletonDocument::isNodeConnectable(QUuid nodeId) const
{
if (threeNodesBranchEnabled)
return true;
const SkeletonNode *node = findNode(nodeId);
if (nullptr == node)
return false;
return node->edgeIds.size() < 2;
}

View File

@ -259,6 +259,7 @@ public:
bool ylocked = false; bool ylocked = false;
bool zlocked = false; bool zlocked = false;
bool radiusLocked = false; bool radiusLocked = false;
bool threeNodesBranchEnabled = Preferences::instance().threeNodesBranchEnabled();
QImage turnaround; QImage turnaround;
QByteArray turnaroundPngByteArray; QByteArray turnaroundPngByteArray;
std::map<QUuid, SkeletonPart> partMap; std::map<QUuid, SkeletonPart> partMap;
@ -270,6 +271,7 @@ public:
const SkeletonPart *findPart(QUuid partId) const; const SkeletonPart *findPart(QUuid partId) const;
const SkeletonEdge *findEdgeByNodes(QUuid firstNodeId, QUuid secondNodeId) const; const SkeletonEdge *findEdgeByNodes(QUuid firstNodeId, QUuid secondNodeId) const;
void findAllNeighbors(QUuid nodeId, std::set<QUuid> &neighbors) const; void findAllNeighbors(QUuid nodeId, std::set<QUuid> &neighbors) const;
bool isNodeConnectable(QUuid nodeId) const;
virtual bool undoable() const = 0; virtual bool undoable() const = 0;
virtual bool redoable() const = 0; virtual bool redoable() const = 0;

View File

@ -346,6 +346,10 @@ bool SkeletonGraphicsWidget::hasTwoDisconnectedNodesSelection()
return false; return false;
if (m_document->findEdgeByNodes(nodeIds[0], nodeIds[1])) if (m_document->findEdgeByNodes(nodeIds[0], nodeIds[1]))
return false; return false;
if (!m_document->isNodeConnectable(nodeIds[0]))
return false;
if (!m_document->isNodeConnectable(nodeIds[1]))
return false;
return true; return true;
} }
@ -378,6 +382,10 @@ void SkeletonGraphicsWidget::connectSelected()
return; return;
if (m_document->findEdgeByNodes(nodeIds[0], nodeIds[1])) if (m_document->findEdgeByNodes(nodeIds[0], nodeIds[1]))
return; return;
if (!m_document->isNodeConnectable(nodeIds[0]))
return;
if (!m_document->isNodeConnectable(nodeIds[1]))
return;
emit addEdge(nodeIds[0], nodeIds[1]); emit addEdge(nodeIds[0], nodeIds[1]);
emit groupOperationAdded(); emit groupOperationAdded();
} }
@ -581,8 +589,11 @@ void SkeletonGraphicsWidget::editModeChanged()
if (!m_rangeSelectionSet.empty()) { if (!m_rangeSelectionSet.empty()) {
std::set<SkeletonGraphicsNodeItem *> nodeItems; std::set<SkeletonGraphicsNodeItem *> nodeItems;
readMergedSkeletonNodeSetFromRangeSelection(&nodeItems); readMergedSkeletonNodeSetFromRangeSelection(&nodeItems);
if (nodeItems.size() == 1) if (nodeItems.size() == 1) {
choosenNodeItem = *nodeItems.begin(); choosenNodeItem = *nodeItems.begin();
if (!m_document->isNodeConnectable(choosenNodeItem->id()))
choosenNodeItem = nullptr;
}
} }
m_addFromNodeItem = choosenNodeItem; m_addFromNodeItem = choosenNodeItem;
} }
@ -1267,9 +1278,11 @@ bool SkeletonGraphicsWidget::mousePress(QMouseEvent *event)
m_hoveredNodeItem->profile() == m_addFromNodeItem->profile() && m_hoveredNodeItem->profile() == m_addFromNodeItem->profile() &&
!m_document->findEdgeByNodes(m_addFromNodeItem->id(), m_hoveredNodeItem->id()) && !m_document->findEdgeByNodes(m_addFromNodeItem->id(), m_hoveredNodeItem->id()) &&
m_document->isNodeEditable(m_hoveredNodeItem->id())) { m_document->isNodeEditable(m_hoveredNodeItem->id())) {
emit addEdge(m_addFromNodeItem->id(), m_hoveredNodeItem->id()); if (m_document->isNodeConnectable(m_hoveredNodeItem->id())) {
emit groupOperationAdded(); emit addEdge(m_addFromNodeItem->id(), m_hoveredNodeItem->id());
return true; emit groupOperationAdded();
return true;
}
} }
} }
QPointF mainProfile = m_cursorNodeItem->origin(); QPointF mainProfile = m_cursorNodeItem->origin();