Sort cut face list by x position of center

master
Jeremy Hu 2019-07-08 07:33:39 +09:30
parent d65feb2b60
commit 7c66e6b5d0
1 changed files with 22 additions and 0 deletions

View File

@ -209,6 +209,28 @@ void CutFaceListWidget::reload()
for (int i = 0; i < columns; i++) for (int i = 0; i < columns; i++)
setColumnWidth(i, columnWidth); setColumnWidth(i, columnWidth);
// Sort cut face by center.x of front view
std::map<QUuid, float> 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; decltype(m_cutFacePartIdList.size()) cutFaceIndex = 0;
while (cutFaceIndex < m_cutFacePartIdList.size()) { while (cutFaceIndex < m_cutFacePartIdList.size()) {
QTreeWidgetItem *item = new QTreeWidgetItem(this); QTreeWidgetItem *item = new QTreeWidgetItem(this);