Select component by part: shortcut F

master
Jeremy HU 2022-10-06 22:16:47 +11:00
parent 5f75a6d7d8
commit 12197bdb44
8 changed files with 48 additions and 11 deletions

View File

@ -27,7 +27,6 @@ ComponentListModel::ComponentListModel(const Document *document, QObject *parent
void ComponentListModel::reload()
{
std::pair<QModelIndex, QModelIndex> beginEnd;
beginResetModel();
m_componentIdToIndexMap.clear();
const SkeletonComponent *listingComponent = m_document->findComponent(m_listingComponentId);
@ -35,17 +34,19 @@ void ComponentListModel::reload()
for (int i = 0; i < (int)listingComponent->childrenIds.size(); ++i) {
m_componentIdToIndexMap[listingComponent->childrenIds[i]] = createIndex(i, 0);
}
if (!listingComponent->childrenIds.empty()) {
beginEnd.first = m_componentIdToIndexMap[listingComponent->childrenIds.front()];
beginEnd.second = m_componentIdToIndexMap[listingComponent->childrenIds.back()];
}
}
endResetModel();
if (!m_componentIdToIndexMap.empty())
emit dataChanged(beginEnd.first, beginEnd.second);
emit layoutChanged();
}
QModelIndex ComponentListModel::componentIdToIndex(const dust3d::Uuid &componentId) const
{
auto findIndex = m_componentIdToIndexMap.find(componentId);
if (findIndex == m_componentIdToIndexMap.end())
return QModelIndex();
return findIndex->second;
}
int ComponentListModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())

View File

@ -19,6 +19,7 @@ public:
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
const SkeletonComponent *modelIndexToComponent(const QModelIndex &index) const;
QModelIndex componentIdToIndex(const dust3d::Uuid &componentId) const;
const dust3d::Uuid modelIndexToComponentId(const QModelIndex &index) const;
const dust3d::Uuid listingComponentId() const;
public slots:

View File

@ -633,6 +633,8 @@ DocumentWindow::DocumentWindow()
connect(m_partManageWidget, &PartManageWidget::unselectAllOnCanvas, canvasGraphicsWidget, &SkeletonGraphicsWidget::unselectAll);
connect(m_partManageWidget, &PartManageWidget::selectPartOnCanvas, canvasGraphicsWidget, &SkeletonGraphicsWidget::addPartToSelection);
connect(canvasGraphicsWidget, &SkeletonGraphicsWidget::partComponentChecked, m_partManageWidget, &PartManageWidget::selectComponentByPartId);
connect(m_document, &Document::skeletonChanged, m_document, &Document::generateMesh);
connect(m_document, &Document::textureChanged, m_document, &Document::generateTexture);
connect(m_document, &Document::resultMeshChanged, m_document, &Document::postProcess);

View File

@ -117,6 +117,29 @@ PartManageWidget::PartManageWidget(Document *document, QWidget *parent):
updateLevelUpButton();
}
void PartManageWidget::selectComponentByPartId(const dust3d::Uuid &partId)
{
const auto &part = m_document->findPart(partId);
if (nullptr == part)
return;
auto componentId = part->componentId;
QModelIndex index = m_componentPreviewGridWidget->componentListModel()->componentIdToIndex(componentId);
if (index.isValid()) {
m_componentPreviewGridWidget->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
return;
}
const auto &component = m_document->findComponent(componentId);
if (nullptr == component)
return;
m_componentPreviewGridWidget->componentListModel()->setListingComponentId(component->parentId);
index = m_componentPreviewGridWidget->componentListModel()->componentIdToIndex(componentId);
if (index.isValid()) {
m_componentPreviewGridWidget->selectionModel()->select(index, QItemSelectionModel::ClearAndSelect);
return;
}
dust3dDebug << "Unable to select component:" << componentId.toString();
}
void PartManageWidget::updateLevelUpButton()
{
const auto &parent = m_document->findComponentParent(m_componentPreviewGridWidget->componentListModel()->listingComponentId());

View File

@ -14,6 +14,8 @@ class PartManageWidget : public QWidget
signals:
void unselectAllOnCanvas();
void selectPartOnCanvas(const dust3d::Uuid &partId);
public slots:
void selectComponentByPartId(const dust3d::Uuid &partId);
public:
PartManageWidget(Document *document, QWidget *parent=nullptr);
private:

View File

@ -480,6 +480,8 @@ std::unique_ptr<MeshCombiner::Mesh> MeshGenerator::combineStitchingMesh(const st
auto stitchMeshBuilder = std::make_unique<StitchMeshBuilder>(std::move(splines));
stitchMeshBuilder->build();
// stitchMeshBuilder->splines();
collectSharedQuadEdges(stitchMeshBuilder->generatedVertices(),
stitchMeshBuilder->generatedFaces(),
&componentCache.sharedQuadEdges);

View File

@ -32,12 +32,12 @@ StitchMeshBuilder::StitchMeshBuilder(std::vector<Spline> &&splines)
m_splines = std::move(splines);
}
const std::vector<Vector3> &StitchMeshBuilder::generatedVertices()
const std::vector<Vector3> &StitchMeshBuilder::generatedVertices() const
{
return m_generatedVertices;
}
const std::vector<std::vector<size_t>> &StitchMeshBuilder::generatedFaces()
const std::vector<std::vector<size_t>> &StitchMeshBuilder::generatedFaces() const
{
return m_generatedFaces;
}
@ -225,6 +225,11 @@ void StitchMeshBuilder::addQuadButMaybeTriangle(const std::vector<size_t> &quadB
m_generatedFaces.emplace_back(finalFace);
}
const std::vector<StitchMeshBuilder::Spline> &StitchMeshBuilder::splines() const
{
return m_splines;
}
void StitchMeshBuilder::build()
{
if (m_splines.empty())

View File

@ -46,8 +46,9 @@ public:
StitchMeshBuilder(std::vector<Spline> &&splines);
void build();
const std::vector<Vector3> &generatedVertices();
const std::vector<std::vector<size_t>> &generatedFaces();
const std::vector<Vector3> &generatedVertices() const;
const std::vector<std::vector<size_t>> &generatedFaces() const;
const std::vector<Spline> &splines() const;
private:
struct StitchingPoint