Make chamfer tool as a separate tool

Remove cut template customiziation.
master
Jeremy Hu 2019-03-10 07:40:39 +09:30
parent 69b371adb9
commit e2f829d3ce
9 changed files with 212 additions and 156 deletions

View File

@ -859,6 +859,7 @@ void Document::toSnapshot(Snapshot *snapshot, const std::set<QUuid> &limitNodeId
part["xMirrored"] = partIt.second.xMirrored ? "true" : "false"; part["xMirrored"] = partIt.second.xMirrored ? "true" : "false";
part["zMirrored"] = partIt.second.zMirrored ? "true" : "false"; part["zMirrored"] = partIt.second.zMirrored ? "true" : "false";
part["rounded"] = partIt.second.rounded ? "true" : "false"; part["rounded"] = partIt.second.rounded ? "true" : "false";
part["chamfered"] = partIt.second.chamfered ? "true" : "false";
if (partIt.second.cutRotationAdjusted()) if (partIt.second.cutRotationAdjusted())
part["cutRotation"] = QString::number(partIt.second.cutRotation); part["cutRotation"] = QString::number(partIt.second.cutRotation);
if (partIt.second.cutTemplateAdjusted()) if (partIt.second.cutTemplateAdjusted())
@ -1117,6 +1118,7 @@ void Document::addFromSnapshot(const Snapshot &snapshot, bool fromPaste)
part.xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "xMirrored")); part.xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "xMirrored"));
part.zMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "zMirrored")); part.zMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "zMirrored"));
part.rounded = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "rounded")); part.rounded = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "rounded"));
part.chamfered = isTrueValueString(valueOfKeyInMapOrEmpty(partKv.second, "chamfered"));
const auto &cutRotationIt = partKv.second.find("cutRotation"); const auto &cutRotationIt = partKv.second.find("cutRotation");
if (cutRotationIt != partKv.second.end()) if (cutRotationIt != partKv.second.end())
part.setCutRotation(cutRotationIt->second.toFloat()); part.setCutRotation(cutRotationIt->second.toFloat());
@ -2198,6 +2200,21 @@ void Document::setPartRoundState(QUuid partId, bool rounded)
emit skeletonChanged(); emit skeletonChanged();
} }
void Document::setPartChamferState(QUuid partId, bool chamfered)
{
auto part = partMap.find(partId);
if (part == partMap.end()) {
qDebug() << "Part not found:" << partId;
return;
}
if (part->second.chamfered == chamfered)
return;
part->second.chamfered = chamfered;
part->second.dirty = true;
emit partChamferStateChanged(partId);
emit skeletonChanged();
}
void Document::setPartCutRotation(QUuid partId, float cutRotation) void Document::setPartCutRotation(QUuid partId, float cutRotation)
{ {
auto part = partMap.find(partId); auto part = partMap.find(partId);

View File

@ -403,6 +403,7 @@ signals:
void partCutRotationChanged(QUuid partId); void partCutRotationChanged(QUuid partId);
void partCutTemplateChanged(QUuid partId); void partCutTemplateChanged(QUuid partId);
void partMaterialIdChanged(QUuid partId); void partMaterialIdChanged(QUuid partId);
void partChamferStateChanged(QUuid partId);
void componentCombineModeChanged(QUuid componentId); void componentCombineModeChanged(QUuid componentId);
void cleanup(); void cleanup();
void originChanged(); void originChanged();
@ -557,6 +558,7 @@ public slots:
void setPartCutRotation(QUuid partId, float cutRotation); void setPartCutRotation(QUuid partId, float cutRotation);
void setPartCutTemplate(QUuid partId, std::vector<QVector2D> cutTemplate); void setPartCutTemplate(QUuid partId, std::vector<QVector2D> cutTemplate);
void setPartMaterialId(QUuid partId, QUuid materialId); void setPartMaterialId(QUuid partId, QUuid materialId);
void setPartChamferState(QUuid partId, bool chamfered);
void setComponentCombineMode(QUuid componentId, CombineMode combineMode); void setComponentCombineMode(QUuid componentId, CombineMode combineMode);
void moveComponentUp(QUuid componentId); void moveComponentUp(QUuid componentId);
void moveComponentDown(QUuid componentId); void moveComponentDown(QUuid componentId);

View File

@ -839,9 +839,10 @@ DocumentWindow::DocumentWindow() :
connect(m_document, &Document::partDeformThicknessChanged, partTreeWidget, &PartTreeWidget::partDeformChanged); connect(m_document, &Document::partDeformThicknessChanged, partTreeWidget, &PartTreeWidget::partDeformChanged);
connect(m_document, &Document::partDeformWidthChanged, partTreeWidget, &PartTreeWidget::partDeformChanged); connect(m_document, &Document::partDeformWidthChanged, partTreeWidget, &PartTreeWidget::partDeformChanged);
connect(m_document, &Document::partRoundStateChanged, partTreeWidget, &PartTreeWidget::partRoundStateChanged); connect(m_document, &Document::partRoundStateChanged, partTreeWidget, &PartTreeWidget::partRoundStateChanged);
connect(m_document, &Document::partChamferStateChanged, partTreeWidget, &PartTreeWidget::partChamferStateChanged);
connect(m_document, &Document::partColorStateChanged, partTreeWidget, &PartTreeWidget::partColorStateChanged); connect(m_document, &Document::partColorStateChanged, partTreeWidget, &PartTreeWidget::partColorStateChanged);
connect(m_document, &Document::partCutRotationChanged, partTreeWidget, &PartTreeWidget::partCutRotationChanged); connect(m_document, &Document::partCutRotationChanged, partTreeWidget, &PartTreeWidget::partCutRotationChanged);
connect(m_document, &Document::partCutTemplateChanged, partTreeWidget, &PartTreeWidget::partCutTemplateChanged); //connect(m_document, &Document::partCutTemplateChanged, partTreeWidget, &PartTreeWidget::partCutTemplateChanged);
connect(m_document, &Document::partMaterialIdChanged, partTreeWidget, &PartTreeWidget::partMaterialIdChanged); connect(m_document, &Document::partMaterialIdChanged, partTreeWidget, &PartTreeWidget::partMaterialIdChanged);
connect(m_document, &Document::partRemoved, partTreeWidget, &PartTreeWidget::partRemoved); connect(m_document, &Document::partRemoved, partTreeWidget, &PartTreeWidget::partRemoved);
connect(m_document, &Document::cleanup, partTreeWidget, &PartTreeWidget::removeAllContent); connect(m_document, &Document::cleanup, partTreeWidget, &PartTreeWidget::removeAllContent);

View File

@ -143,6 +143,7 @@ nodemesh::Combiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdSt
bool xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(part, "xMirrored")); bool xMirrored = isTrueValueString(valueOfKeyInMapOrEmpty(part, "xMirrored"));
bool subdived = isTrueValueString(valueOfKeyInMapOrEmpty(part, "subdived")); bool subdived = isTrueValueString(valueOfKeyInMapOrEmpty(part, "subdived"));
bool rounded = isTrueValueString(valueOfKeyInMapOrEmpty(part, "rounded")); bool rounded = isTrueValueString(valueOfKeyInMapOrEmpty(part, "rounded"));
bool chamfered = isTrueValueString(valueOfKeyInMapOrEmpty(part, "chamfered"));
QString colorString = valueOfKeyInMapOrEmpty(part, "color"); QString colorString = valueOfKeyInMapOrEmpty(part, "color");
QColor partColor = colorString.isEmpty() ? m_defaultPartColor : QColor(colorString); QColor partColor = colorString.isEmpty() ? m_defaultPartColor : QColor(colorString);
float deformThickness = 1.0; float deformThickness = 1.0;
@ -150,6 +151,8 @@ nodemesh::Combiner::Mesh *MeshGenerator::combinePartMesh(const QString &partIdSt
float cutRotation = 0.0; float cutRotation = 0.0;
std::vector<QVector2D> cutTemplate = cutTemplatePointsFromString(valueOfKeyInMapOrEmpty(part, "cutTemplate")); std::vector<QVector2D> cutTemplate = cutTemplatePointsFromString(valueOfKeyInMapOrEmpty(part, "cutTemplate"));
if (chamfered)
nodemesh::chamferFace2D(&cutTemplate);
normalizeCutTemplatePoints(&cutTemplate); normalizeCutTemplatePoints(&cutTemplate);
QString cutRotationString = valueOfKeyInMapOrEmpty(part, "cutRotation"); QString cutRotationString = valueOfKeyInMapOrEmpty(part, "cutRotation");
if (!cutRotationString.isEmpty()) { if (!cutRotationString.isEmpty()) {

View File

@ -910,6 +910,17 @@ void PartTreeWidget::partRoundStateChanged(QUuid partId)
widget->updateRoundButton(); widget->updateRoundButton();
} }
void PartTreeWidget::partChamferStateChanged(QUuid partId)
{
auto item = m_partItemMap.find(partId);
if (item == m_partItemMap.end()) {
qDebug() << "Part item not found:" << partId;
return;
}
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
widget->updateChamferButton();
}
void PartTreeWidget::partColorStateChanged(QUuid partId) void PartTreeWidget::partColorStateChanged(QUuid partId)
{ {
auto item = m_partItemMap.find(partId); auto item = m_partItemMap.find(partId);
@ -932,16 +943,16 @@ void PartTreeWidget::partCutRotationChanged(QUuid partId)
widget->updateCutRotationButton(); widget->updateCutRotationButton();
} }
void PartTreeWidget::partCutTemplateChanged(QUuid partId) //void PartTreeWidget::partCutTemplateChanged(QUuid partId)
{ //{
auto item = m_partItemMap.find(partId); // auto item = m_partItemMap.find(partId);
if (item == m_partItemMap.end()) { // if (item == m_partItemMap.end()) {
qDebug() << "Part item not found:" << partId; // qDebug() << "Part item not found:" << partId;
return; // return;
} // }
PartWidget *widget = (PartWidget *)itemWidget(item->second, 0); // PartWidget *widget = (PartWidget *)itemWidget(item->second, 0);
widget->updateCutTemplateButton(); // widget->updateCutTemplateButton();
} //}
void PartTreeWidget::partMaterialIdChanged(QUuid partId) void PartTreeWidget::partMaterialIdChanged(QUuid partId)
{ {

View File

@ -59,9 +59,10 @@ public slots:
void partXmirrorStateChanged(QUuid partId); void partXmirrorStateChanged(QUuid partId);
void partDeformChanged(QUuid partId); void partDeformChanged(QUuid partId);
void partRoundStateChanged(QUuid partId); void partRoundStateChanged(QUuid partId);
void partChamferStateChanged(QUuid partId);
void partColorStateChanged(QUuid partId); void partColorStateChanged(QUuid partId);
void partCutRotationChanged(QUuid partId); void partCutRotationChanged(QUuid partId);
void partCutTemplateChanged(QUuid partId); //void partCutTemplateChanged(QUuid partId);
void partMaterialIdChanged(QUuid partId); void partMaterialIdChanged(QUuid partId);
void partChecked(QUuid partId); void partChecked(QUuid partId);
void partUnchecked(QUuid partId); void partUnchecked(QUuid partId);

View File

@ -62,6 +62,11 @@ PartWidget::PartWidget(const Document *document, QUuid partId) :
m_roundButton->setSizePolicy(retainSizePolicy); m_roundButton->setSizePolicy(retainSizePolicy);
initButton(m_roundButton); initButton(m_roundButton);
m_chamferButton = new QPushButton;
m_chamferButton->setToolTip(tr("Chamfer"));
m_chamferButton->setSizePolicy(retainSizePolicy);
initButton(m_chamferButton);
m_colorButton = new QPushButton; m_colorButton = new QPushButton;
m_colorButton->setToolTip(tr("Color and material picker")); m_colorButton->setToolTip(tr("Color and material picker"));
m_colorButton->setSizePolicy(retainSizePolicy); m_colorButton->setSizePolicy(retainSizePolicy);
@ -72,10 +77,10 @@ PartWidget::PartWidget(const Document *document, QUuid partId) :
m_cutRotationButton->setSizePolicy(retainSizePolicy); m_cutRotationButton->setSizePolicy(retainSizePolicy);
initButton(m_cutRotationButton); initButton(m_cutRotationButton);
m_cutTemplateButton = new QPushButton; //m_cutTemplateButton = new QPushButton;
m_cutTemplateButton->setToolTip(tr("Cut template")); //m_cutTemplateButton->setToolTip(tr("Cut template"));
m_cutTemplateButton->setSizePolicy(retainSizePolicy); //m_cutTemplateButton->setSizePolicy(retainSizePolicy);
initButton(m_cutTemplateButton); //initButton(m_cutTemplateButton);
m_previewWidget = new ModelWidget; m_previewWidget = new ModelWidget;
m_previewWidget->setAttribute(Qt::WA_TransparentForMouseEvents); m_previewWidget->setAttribute(Qt::WA_TransparentForMouseEvents);
@ -109,7 +114,8 @@ PartWidget::PartWidget(const Document *document, QUuid partId) :
col = 0; col = 0;
toolsLayout->addWidget(m_subdivButton, row, col++, Qt::AlignTop); toolsLayout->addWidget(m_subdivButton, row, col++, Qt::AlignTop);
toolsLayout->addWidget(m_roundButton, row, col++, Qt::AlignTop); toolsLayout->addWidget(m_roundButton, row, col++, Qt::AlignTop);
toolsLayout->addWidget(m_cutTemplateButton, row, col++, Qt::AlignTop); //toolsLayout->addWidget(m_cutTemplateButton, row, col++, Qt::AlignTop);
toolsLayout->addWidget(m_chamferButton, row, col++, Qt::AlignTop);
toolsLayout->addWidget(m_cutRotationButton, row, col++, Qt::AlignTop); toolsLayout->addWidget(m_cutRotationButton, row, col++, Qt::AlignTop);
toolsLayout->addWidget(m_deformButton, row, col++, Qt::AlignTop); toolsLayout->addWidget(m_deformButton, row, col++, Qt::AlignTop);
@ -157,6 +163,7 @@ PartWidget::PartWidget(const Document *document, QUuid partId) :
connect(this, &PartWidget::setPartDeformThickness, m_document, &Document::setPartDeformThickness); connect(this, &PartWidget::setPartDeformThickness, m_document, &Document::setPartDeformThickness);
connect(this, &PartWidget::setPartDeformWidth, m_document, &Document::setPartDeformWidth); connect(this, &PartWidget::setPartDeformWidth, m_document, &Document::setPartDeformWidth);
connect(this, &PartWidget::setPartRoundState, m_document, &Document::setPartRoundState); connect(this, &PartWidget::setPartRoundState, m_document, &Document::setPartRoundState);
connect(this, &PartWidget::setPartChamferState, m_document, &Document::setPartChamferState);
connect(this, &PartWidget::setPartCutRotation, m_document, &Document::setPartCutRotation); connect(this, &PartWidget::setPartCutRotation, m_document, &Document::setPartCutRotation);
connect(this, &PartWidget::setPartCutTemplate, m_document, &Document::setPartCutTemplate); connect(this, &PartWidget::setPartCutTemplate, m_document, &Document::setPartCutTemplate);
connect(this, &PartWidget::setPartColorState, m_document, &Document::setPartColorState); connect(this, &PartWidget::setPartColorState, m_document, &Document::setPartColorState);
@ -236,6 +243,16 @@ PartWidget::PartWidget(const Document *document, QUuid partId) :
emit groupOperationAdded(); emit groupOperationAdded();
}); });
connect(m_chamferButton, &QPushButton::clicked, [=]() {
const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) {
qDebug() << "Part not found:" << m_partId;
return;
}
emit setPartChamferState(m_partId, !part->chamfered);
emit groupOperationAdded();
});
connect(m_colorButton, &QPushButton::clicked, [=]() { connect(m_colorButton, &QPushButton::clicked, [=]() {
const SkeletonPart *part = m_document->findPart(m_partId); const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) { if (!part) {
@ -254,14 +271,14 @@ PartWidget::PartWidget(const Document *document, QUuid partId) :
showCutRotationSettingPopup(mapFromGlobal(QCursor::pos())); showCutRotationSettingPopup(mapFromGlobal(QCursor::pos()));
}); });
connect(m_cutTemplateButton, &QPushButton::clicked, [=]() { //connect(m_cutTemplateButton, &QPushButton::clicked, [=]() {
const SkeletonPart *part = m_document->findPart(m_partId); // const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) { // if (!part) {
qDebug() << "Part not found:" << m_partId; // qDebug() << "Part not found:" << m_partId;
return; // return;
} // }
showCutTemplateSettingPopup(mapFromGlobal(QCursor::pos())); // showCutTemplateSettingPopup(mapFromGlobal(QCursor::pos()));
}); //});
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
setFixedSize(preferredSize()); setFixedSize(preferredSize());
@ -288,9 +305,10 @@ void PartWidget::updateAllButtons()
updateXmirrorButton(); updateXmirrorButton();
updateDeformButton(); updateDeformButton();
updateRoundButton(); updateRoundButton();
updateChamferButton();
updateColorButton(); updateColorButton();
updateCutRotationButton(); updateCutRotationButton();
updateCutTemplateButton(); //updateCutTemplateButton();
} }
void PartWidget::updateCheckedState(bool checked) void PartWidget::updateCheckedState(bool checked)
@ -443,122 +461,106 @@ void PartWidget::showCutRotationSettingPopup(const QPoint &pos)
popupMenu.exec(mapToGlobal(pos)); popupMenu.exec(mapToGlobal(pos));
} }
void PartWidget::showCutTemplateSettingPopup(const QPoint &pos) //void PartWidget::showCutTemplateSettingPopup(const QPoint &pos)
{ //{
QMenu popupMenu; // QMenu popupMenu;
//
const SkeletonPart *part = m_document->findPart(m_partId); // const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) { // if (!part) {
qDebug() << "Find part failed:" << m_partId; // qDebug() << "Find part failed:" << m_partId;
return; // return;
} // }
//
CutDocument cutDocument; // CutDocument cutDocument;
SkeletonGraphicsWidget *graphicsWidget = new SkeletonGraphicsWidget(&cutDocument); // SkeletonGraphicsWidget *graphicsWidget = new SkeletonGraphicsWidget(&cutDocument);
graphicsWidget->setNodePositionModifyOnly(true); // graphicsWidget->setNodePositionModifyOnly(true);
graphicsWidget->setMainProfileOnly(true); // graphicsWidget->setMainProfileOnly(true);
//
GraphicsContainerWidget *containerWidget = new GraphicsContainerWidget; // GraphicsContainerWidget *containerWidget = new GraphicsContainerWidget;
containerWidget->setGraphicsWidget(graphicsWidget); // containerWidget->setGraphicsWidget(graphicsWidget);
QGridLayout *containerLayout = new QGridLayout; // QGridLayout *containerLayout = new QGridLayout;
containerLayout->setSpacing(0); // containerLayout->setSpacing(0);
containerLayout->setContentsMargins(1, 0, 0, 0); // containerLayout->setContentsMargins(1, 0, 0, 0);
containerLayout->addWidget(graphicsWidget); // containerLayout->addWidget(graphicsWidget);
containerWidget->setLayout(containerLayout); // containerWidget->setLayout(containerLayout);
containerWidget->setFixedSize(160, 100); // containerWidget->setFixedSize(160, 100);
//
connect(containerWidget, &GraphicsContainerWidget::containerSizeChanged, // connect(containerWidget, &GraphicsContainerWidget::containerSizeChanged,
graphicsWidget, &SkeletonGraphicsWidget::canvasResized); // graphicsWidget, &SkeletonGraphicsWidget::canvasResized);
//
connect(graphicsWidget, &SkeletonGraphicsWidget::moveNodeBy, &cutDocument, &CutDocument::moveNodeBy); // connect(graphicsWidget, &SkeletonGraphicsWidget::moveNodeBy, &cutDocument, &CutDocument::moveNodeBy);
connect(graphicsWidget, &SkeletonGraphicsWidget::setNodeOrigin, &cutDocument, &CutDocument::setNodeOrigin); // connect(graphicsWidget, &SkeletonGraphicsWidget::setNodeOrigin, &cutDocument, &CutDocument::setNodeOrigin);
connect(graphicsWidget, &SkeletonGraphicsWidget::groupOperationAdded, &cutDocument, &CutDocument::saveHistoryItem); // connect(graphicsWidget, &SkeletonGraphicsWidget::groupOperationAdded, &cutDocument, &CutDocument::saveHistoryItem);
connect(graphicsWidget, &SkeletonGraphicsWidget::undo, &cutDocument, &CutDocument::undo); // connect(graphicsWidget, &SkeletonGraphicsWidget::undo, &cutDocument, &CutDocument::undo);
connect(graphicsWidget, &SkeletonGraphicsWidget::redo, &cutDocument, &CutDocument::redo); // connect(graphicsWidget, &SkeletonGraphicsWidget::redo, &cutDocument, &CutDocument::redo);
connect(graphicsWidget, &SkeletonGraphicsWidget::paste, &cutDocument, &CutDocument::paste); // connect(graphicsWidget, &SkeletonGraphicsWidget::paste, &cutDocument, &CutDocument::paste);
//
connect(&cutDocument, &CutDocument::cleanup, graphicsWidget, &SkeletonGraphicsWidget::removeAllContent); // connect(&cutDocument, &CutDocument::cleanup, graphicsWidget, &SkeletonGraphicsWidget::removeAllContent);
//
connect(&cutDocument, &CutDocument::nodeAdded, graphicsWidget, &SkeletonGraphicsWidget::nodeAdded); // connect(&cutDocument, &CutDocument::nodeAdded, graphicsWidget, &SkeletonGraphicsWidget::nodeAdded);
connect(&cutDocument, &CutDocument::edgeAdded, graphicsWidget, &SkeletonGraphicsWidget::edgeAdded); // connect(&cutDocument, &CutDocument::edgeAdded, graphicsWidget, &SkeletonGraphicsWidget::edgeAdded);
connect(&cutDocument, &CutDocument::nodeOriginChanged, graphicsWidget, &SkeletonGraphicsWidget::nodeOriginChanged); // connect(&cutDocument, &CutDocument::nodeOriginChanged, graphicsWidget, &SkeletonGraphicsWidget::nodeOriginChanged);
//
cutDocument.fromCutTemplate(part->cutTemplate); // cutDocument.fromCutTemplate(part->cutTemplate);
//
connect(&cutDocument, &CutDocument::cutTemplateChanged, this, [&]() { // connect(&cutDocument, &CutDocument::cutTemplateChanged, this, [&]() {
std::vector<QVector2D> cutTemplate; // std::vector<QVector2D> cutTemplate;
cutDocument.toCutTemplate(cutTemplate); // cutDocument.toCutTemplate(cutTemplate);
emit setPartCutTemplate(m_partId, cutTemplate); // emit setPartCutTemplate(m_partId, cutTemplate);
}); // });
//
QWidget *popup = new QWidget; // QWidget *popup = new QWidget;
//
initShortCuts(popup, graphicsWidget); // initShortCuts(popup, graphicsWidget);
//
std::vector<QPushButton *> presetButtons; // std::vector<QPushButton *> presetButtons;
//
{ // {
CutTemplate cutTemplate = CutTemplate::Quad; // CutTemplate cutTemplate = CutTemplate::Quad;
QPushButton *button = new QPushButton(tr("Reset")); // QPushButton *button = new QPushButton(tr("Reset"));
connect(button, &QPushButton::clicked, [cutTemplate, &cutDocument, this]() { // connect(button, &QPushButton::clicked, [cutTemplate, &cutDocument, this]() {
auto points = CutTemplateToPoints(cutTemplate); // auto points = CutTemplateToPoints(cutTemplate);
cutDocument.fromCutTemplate(points); // cutDocument.fromCutTemplate(points);
emit setPartCutTemplate(m_partId, points); // emit setPartCutTemplate(m_partId, points);
emit groupOperationAdded(); // emit groupOperationAdded();
}); // });
Theme::initToolButton(button); // Theme::initToolButton(button);
presetButtons.push_back(button); // presetButtons.push_back(button);
} // }
//
/* // {
{ // QPushButton *button = new QPushButton(tr("Chamfer"));
QPushButton *button = new QPushButton(tr("Subdivide")); // connect(button, &QPushButton::clicked, [&cutDocument, this]() {
connect(button, &QPushButton::clicked, [&cutDocument, this]() { // std::vector<QVector2D> cutTemplate;
std::vector<QVector2D> cutTemplate; // cutDocument.toCutTemplate(cutTemplate);
cutDocument.toCutTemplate(cutTemplate); // nodemesh::chamferFace2D(&cutTemplate);
nodemesh::subdivideFace2D(&cutTemplate); // cutDocument.fromCutTemplate(cutTemplate);
cutDocument.fromCutTemplate(cutTemplate); // emit setPartCutTemplate(m_partId, cutTemplate);
emit setPartCutTemplate(m_partId, cutTemplate); // emit groupOperationAdded();
emit groupOperationAdded(); // });
}); // Theme::initToolButton(button);
Theme::initToolButton(button); // presetButtons.push_back(button);
presetButtons.push_back(button); // }
} //
*/ // QVBoxLayout *layout = new QVBoxLayout;
// QHBoxLayout *presetButtonsLayout = new QHBoxLayout;
{ // for (const auto &it: presetButtons)
QPushButton *button = new QPushButton(tr("Chamfer")); // presetButtonsLayout->addWidget(it);
connect(button, &QPushButton::clicked, [&cutDocument, this]() { // presetButtonsLayout->addStretch();
std::vector<QVector2D> cutTemplate; // layout->addLayout(presetButtonsLayout);
cutDocument.toCutTemplate(cutTemplate); // layout->addWidget(containerWidget);
nodemesh::chamferFace2D(&cutTemplate); //
cutDocument.fromCutTemplate(cutTemplate); // popup->setLayout(layout);
emit setPartCutTemplate(m_partId, cutTemplate); //
emit groupOperationAdded(); // popup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
}); //
Theme::initToolButton(button); // QWidgetAction action(this);
presetButtons.push_back(button); // action.setDefaultWidget(popup);
} //
// popupMenu.addAction(&action);
QVBoxLayout *layout = new QVBoxLayout; //
QHBoxLayout *presetButtonsLayout = new QHBoxLayout; // popupMenu.exec(mapToGlobal(pos));
for (const auto &it: presetButtons) //}
presetButtonsLayout->addWidget(it);
presetButtonsLayout->addStretch();
layout->addLayout(presetButtonsLayout);
layout->addWidget(containerWidget);
popup->setLayout(layout);
popup->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
QWidgetAction action(this);
action.setDefaultWidget(popup);
popupMenu.addAction(&action);
popupMenu.exec(mapToGlobal(pos));
}
void PartWidget::showDeformSettingPopup(const QPoint &pos) void PartWidget::showDeformSettingPopup(const QPoint &pos)
{ {
@ -741,6 +743,19 @@ void PartWidget::updateRoundButton()
updateButton(m_roundButton, QChar(fa::magnet), false); updateButton(m_roundButton, QChar(fa::magnet), false);
} }
void PartWidget::updateChamferButton()
{
const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) {
qDebug() << "Part not found:" << m_partId;
return;
}
if (part->chamfered)
updateButton(m_chamferButton, QChar(fa::scissors), true);
else
updateButton(m_chamferButton, QChar(fa::scissors), false);
}
void PartWidget::updateColorButton() void PartWidget::updateColorButton()
{ {
const SkeletonPart *part = m_document->findPart(m_partId); const SkeletonPart *part = m_document->findPart(m_partId);
@ -767,18 +782,18 @@ void PartWidget::updateCutRotationButton()
updateButton(m_cutRotationButton, QChar(fa::spinner), false); updateButton(m_cutRotationButton, QChar(fa::spinner), false);
} }
void PartWidget::updateCutTemplateButton() //void PartWidget::updateCutTemplateButton()
{ //{
const SkeletonPart *part = m_document->findPart(m_partId); // const SkeletonPart *part = m_document->findPart(m_partId);
if (!part) { // if (!part) {
qDebug() << "Part not found:" << m_partId; // qDebug() << "Part not found:" << m_partId;
return; // return;
} // }
if (part->cutTemplateAdjusted()) // if (part->cutTemplateAdjusted())
updateButton(m_cutTemplateButton, QChar(fa::objectungroup), true); // updateButton(m_cutTemplateButton, QChar(fa::objectungroup), true);
else // else
updateButton(m_cutTemplateButton, QChar(fa::objectungroup), false); // updateButton(m_cutTemplateButton, QChar(fa::objectungroup), false);
} //}
void PartWidget::reload() void PartWidget::reload()
{ {

View File

@ -19,6 +19,7 @@ signals:
void setPartDeformThickness(QUuid partId, float thickness); void setPartDeformThickness(QUuid partId, float thickness);
void setPartDeformWidth(QUuid partId, float width); void setPartDeformWidth(QUuid partId, float width);
void setPartRoundState(QUuid partId, bool rounded); void setPartRoundState(QUuid partId, bool rounded);
void setPartChamferState(QUuid partId, bool chamfered);
void setPartColorState(QUuid partId, bool hasColor, QColor color); void setPartColorState(QUuid partId, bool hasColor, QColor color);
void setPartCutRotation(QUuid partId, float cutRotation); void setPartCutRotation(QUuid partId, float cutRotation);
void setPartCutTemplate(QUuid partId, std::vector<QVector2D> cutTemplate); void setPartCutTemplate(QUuid partId, std::vector<QVector2D> cutTemplate);
@ -43,6 +44,7 @@ public:
void updateZmirrorButton(); void updateZmirrorButton();
void updateDeformButton(); void updateDeformButton();
void updateRoundButton(); void updateRoundButton();
void updateChamferButton();
void updateColorButton(); void updateColorButton();
void updateCutRotationButton(); void updateCutRotationButton();
void updateCutTemplateButton(); void updateCutTemplateButton();
@ -55,7 +57,7 @@ protected:
public slots: public slots:
void showDeformSettingPopup(const QPoint &pos); void showDeformSettingPopup(const QPoint &pos);
void showCutRotationSettingPopup(const QPoint &pos); void showCutRotationSettingPopup(const QPoint &pos);
void showCutTemplateSettingPopup(const QPoint &pos); //void showCutTemplateSettingPopup(const QPoint &pos);
void showColorSettingPopup(const QPoint &pos); void showColorSettingPopup(const QPoint &pos);
private: // need initialize private: // need initialize
const Document *m_document; const Document *m_document;
@ -71,9 +73,10 @@ private:
QPushButton *m_zMirrorButton; QPushButton *m_zMirrorButton;
QPushButton *m_deformButton; QPushButton *m_deformButton;
QPushButton *m_roundButton; QPushButton *m_roundButton;
QPushButton *m_chamferButton;
QPushButton *m_colorButton; QPushButton *m_colorButton;
QPushButton *m_cutRotationButton; QPushButton *m_cutRotationButton;
QPushButton *m_cutTemplateButton; //QPushButton *m_cutTemplateButton;
QWidget *m_backgroundWidget; QWidget *m_backgroundWidget;
private: private:
void initToolButton(QPushButton *button); void initToolButton(QPushButton *button);

View File

@ -79,6 +79,7 @@ public:
float deformThickness; float deformThickness;
float deformWidth; float deformWidth;
bool rounded; bool rounded;
bool chamfered;
QColor color; QColor color;
bool hasColor; bool hasColor;
QUuid componentId; QUuid componentId;
@ -98,6 +99,7 @@ public:
deformThickness(1.0), deformThickness(1.0),
deformWidth(1.0), deformWidth(1.0),
rounded(false), rounded(false),
chamfered(false),
color(Theme::white), color(Theme::white),
hasColor(false), hasColor(false),
dirty(true), dirty(true),
@ -175,6 +177,7 @@ public:
deformThickness = other.deformThickness; deformThickness = other.deformThickness;
deformWidth = other.deformWidth; deformWidth = other.deformWidth;
rounded = other.rounded; rounded = other.rounded;
chamfered = other.chamfered;
color = other.color; color = other.color;
hasColor = other.hasColor; hasColor = other.hasColor;
cutRotation = other.cutRotation; cutRotation = other.cutRotation;