Skip to content

Commit

Permalink
Add part target convert menu
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Dec 20, 2022
1 parent 494c8f4 commit fc71f69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions application/sources/part_manage_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ PartManageWidget::PartManageWidget(Document* document, QWidget* parent)

connect(this, &PartManageWidget::groupComponents, m_document, &Document::groupComponents);
connect(this, &PartManageWidget::ungroupComponent, m_document, &Document::ungroupComponent);
connect(this, &PartManageWidget::setPartTarget, m_document, &Document::setPartTarget);
connect(this, &PartManageWidget::groupOperationAdded, m_document, &Document::saveSnapshot);

connect(this, &PartManageWidget::customContextMenuRequested, this, &PartManageWidget::showContextMenu);
Expand Down Expand Up @@ -266,5 +267,27 @@ void PartManageWidget::showContextMenu(const QPoint& pos)
contextMenu.addAction(&ungroupAction);
}

QAction convertToCutFaceAction(tr("Convert to Cut Face"), this);
QAction convertToPartAction(tr("Convert to Model"), this);
auto selectedPartIds = m_componentPreviewGridWidget->getSelectedPartIds();
if (1 == selectedPartIds.size()) {
const Document::Part* part = m_document->findPart(selectedPartIds[0]);
if (dust3d::PartTarget::CutFace == part->target) {
connect(&convertToPartAction, &QAction::triggered, this, [=]() {
for (const auto& it : selectedPartIds)
emit this->setPartTarget(it, dust3d::PartTarget::Model);
emit this->groupOperationAdded();
});
contextMenu.addAction(&convertToPartAction);
} else if (dust3d::PartTarget::Model == part->target) {
connect(&convertToCutFaceAction, &QAction::triggered, this, [=]() {
for (const auto& it : selectedPartIds)
emit this->setPartTarget(it, dust3d::PartTarget::CutFace);
emit this->groupOperationAdded();
});
contextMenu.addAction(&convertToCutFaceAction);
}
}

contextMenu.exec(mapToGlobal(pos));
}
2 changes: 2 additions & 0 deletions application/sources/part_manage_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DUST3D_APPLICATION_PART_MANAGE_WIDGET_H_

#include <QWidget>
#include <dust3d/base/part_target.h>
#include <dust3d/base/uuid.h>

class Document;
Expand All @@ -14,6 +15,7 @@ class PartManageWidget : public QWidget {
signals:
void unselectAllOnCanvas();
void selectPartOnCanvas(const dust3d::Uuid& partId);
void setPartTarget(const dust3d::Uuid& partId, dust3d::PartTarget target);
void groupComponents(const std::vector<dust3d::Uuid>& componentIds);
void ungroupComponent(const dust3d::Uuid& componentId);
void groupOperationAdded();
Expand Down

0 comments on commit fc71f69

Please sign in to comment.