From 7c66e6b5d0db0b3e751251167f10d198338fa811 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Mon, 8 Jul 2019 07:33:39 +0930 Subject: [PATCH] Sort cut face list by x position of center --- src/cutfacelistwidget.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/cutfacelistwidget.cpp b/src/cutfacelistwidget.cpp index 4418cee9..22029432 100644 --- a/src/cutfacelistwidget.cpp +++ b/src/cutfacelistwidget.cpp @@ -208,6 +208,28 @@ void CutFaceListWidget::reload() setColumnCount(columns); for (int i = 0; i < columns; i++) setColumnWidth(i, columnWidth); + + // Sort cut face by center.x of front view + std::map centerOffsetMap; + for (const auto &partId: m_cutFacePartIdList) { + const SkeletonPart *part = m_document->findPart(partId); + if (nullptr == part) + continue; + float offsetSum = 0; + for (const auto &nodeId: part->nodeIds) { + const SkeletonNode *node = m_document->findNode(nodeId); + if (nullptr == node) + continue; + offsetSum += node->x; + } + if (qFuzzyIsNull(offsetSum)) + continue; + centerOffsetMap[partId] = offsetSum / part->nodeIds.size(); + } + std::sort(m_cutFacePartIdList.begin(), m_cutFacePartIdList.end(), + [&](const QUuid &firstPartId, const QUuid &secondPartId) { + return centerOffsetMap[firstPartId] < centerOffsetMap[secondPartId]; + }); decltype(m_cutFacePartIdList.size()) cutFaceIndex = 0; while (cutFaceIndex < m_cutFacePartIdList.size()) {