From 12197bdb44dfd53e83dfdc8ff9535ad7005ae48c Mon Sep 17 00:00:00 2001 From: Jeremy HU Date: Thu, 6 Oct 2022 22:16:47 +1100 Subject: [PATCH] Select component by part: shortcut F --- application/sources/component_list_model.cc | 15 +++++++------- application/sources/component_list_model.h | 1 + application/sources/document_window.cc | 2 ++ application/sources/part_manage_widget.cc | 23 +++++++++++++++++++++ application/sources/part_manage_widget.h | 2 ++ dust3d/mesh/mesh_generator.cc | 2 ++ dust3d/mesh/stitch_mesh_builder.cc | 9 ++++++-- dust3d/mesh/stitch_mesh_builder.h | 5 +++-- 8 files changed, 48 insertions(+), 11 deletions(-) diff --git a/application/sources/component_list_model.cc b/application/sources/component_list_model.cc index 3fa121d5..f066c4d0 100644 --- a/application/sources/component_list_model.cc +++ b/application/sources/component_list_model.cc @@ -27,7 +27,6 @@ ComponentListModel::ComponentListModel(const Document *document, QObject *parent void ComponentListModel::reload() { - std::pair 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()) diff --git a/application/sources/component_list_model.h b/application/sources/component_list_model.h index 35b88eff..07ee5b67 100644 --- a/application/sources/component_list_model.h +++ b/application/sources/component_list_model.h @@ -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: diff --git a/application/sources/document_window.cc b/application/sources/document_window.cc index 560dde4c..90cbecbc 100644 --- a/application/sources/document_window.cc +++ b/application/sources/document_window.cc @@ -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); diff --git a/application/sources/part_manage_widget.cc b/application/sources/part_manage_widget.cc index be88bb44..ad26eea5 100644 --- a/application/sources/part_manage_widget.cc +++ b/application/sources/part_manage_widget.cc @@ -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()); diff --git a/application/sources/part_manage_widget.h b/application/sources/part_manage_widget.h index cd2960ee..d8e08d76 100644 --- a/application/sources/part_manage_widget.h +++ b/application/sources/part_manage_widget.h @@ -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: diff --git a/dust3d/mesh/mesh_generator.cc b/dust3d/mesh/mesh_generator.cc index 09c19d1d..ad77f9ea 100644 --- a/dust3d/mesh/mesh_generator.cc +++ b/dust3d/mesh/mesh_generator.cc @@ -480,6 +480,8 @@ std::unique_ptr MeshGenerator::combineStitchingMesh(const st auto stitchMeshBuilder = std::make_unique(std::move(splines)); stitchMeshBuilder->build(); + // stitchMeshBuilder->splines(); + collectSharedQuadEdges(stitchMeshBuilder->generatedVertices(), stitchMeshBuilder->generatedFaces(), &componentCache.sharedQuadEdges); diff --git a/dust3d/mesh/stitch_mesh_builder.cc b/dust3d/mesh/stitch_mesh_builder.cc index 90c17e65..a898b402 100644 --- a/dust3d/mesh/stitch_mesh_builder.cc +++ b/dust3d/mesh/stitch_mesh_builder.cc @@ -32,12 +32,12 @@ StitchMeshBuilder::StitchMeshBuilder(std::vector &&splines) m_splines = std::move(splines); } -const std::vector &StitchMeshBuilder::generatedVertices() +const std::vector &StitchMeshBuilder::generatedVertices() const { return m_generatedVertices; } -const std::vector> &StitchMeshBuilder::generatedFaces() +const std::vector> &StitchMeshBuilder::generatedFaces() const { return m_generatedFaces; } @@ -225,6 +225,11 @@ void StitchMeshBuilder::addQuadButMaybeTriangle(const std::vector &quadB m_generatedFaces.emplace_back(finalFace); } +const std::vector &StitchMeshBuilder::splines() const +{ + return m_splines; +} + void StitchMeshBuilder::build() { if (m_splines.empty()) diff --git a/dust3d/mesh/stitch_mesh_builder.h b/dust3d/mesh/stitch_mesh_builder.h index cadc3964..58eaa723 100644 --- a/dust3d/mesh/stitch_mesh_builder.h +++ b/dust3d/mesh/stitch_mesh_builder.h @@ -46,8 +46,9 @@ public: StitchMeshBuilder(std::vector &&splines); void build(); - const std::vector &generatedVertices(); - const std::vector> &generatedFaces(); + const std::vector &generatedVertices() const; + const std::vector> &generatedFaces() const; + const std::vector &splines() const; private: struct StitchingPoint