diff --git a/src/cuttemplate.h b/src/cuttemplate.h index af370eb4..08b1a159 100644 --- a/src/cuttemplate.h +++ b/src/cuttemplate.h @@ -8,7 +8,6 @@ enum class CutTemplate { Quad = 0, - Triangle, Count }; @@ -19,8 +18,6 @@ QString CutTemplateToDispName(CutTemplate cutTemplate) \ switch (cutTemplate) { \ case CutTemplate::Quad: \ return QObject::tr("Quad"); \ - case CutTemplate::Triangle: \ - return QObject::tr("Triangle"); \ default: \ return ""; \ } \ @@ -37,12 +34,6 @@ std::vector CutTemplateToPoints(CutTemplate cutTemplate) \ { 1.0, 1.0}, \ {-1.0, 1.0}, \ }; \ - case CutTemplate::Triangle: \ - return { \ - {0, -1.0}, \ - {1.732, 0}, \ - {0, 1.0}, \ - }; \ default: \ return { \ {-1.0, -1.0}, \ diff --git a/src/partwidget.cpp b/src/partwidget.cpp index 7a7f740f..fd973493 100644 --- a/src/partwidget.cpp +++ b/src/partwidget.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "partwidget.h" #include "theme.h" #include "floatnumberwidget.h" @@ -495,9 +496,10 @@ void PartWidget::showCutTemplateSettingPopup(const QPoint &pos) initShortCuts(popup, graphicsWidget); std::vector presetButtons; - for (size_t i = 0; i < (size_t)CutTemplate::Count; ++i) { - CutTemplate cutTemplate = (CutTemplate)i; - QPushButton *button = new QPushButton(CutTemplateToDispName(cutTemplate)); + + { + CutTemplate cutTemplate = CutTemplate::Quad; + QPushButton *button = new QPushButton(tr("Reset")); connect(button, &QPushButton::clicked, [cutTemplate, &cutDocument, this]() { auto points = CutTemplateToPoints(cutTemplate); cutDocument.fromCutTemplate(points); @@ -508,6 +510,36 @@ void PartWidget::showCutTemplateSettingPopup(const QPoint &pos) presetButtons.push_back(button); } + /* + { + QPushButton *button = new QPushButton(tr("Subdivide")); + connect(button, &QPushButton::clicked, [&cutDocument, this]() { + std::vector cutTemplate; + cutDocument.toCutTemplate(cutTemplate); + nodemesh::subdivideFace2D(&cutTemplate); + cutDocument.fromCutTemplate(cutTemplate); + emit setPartCutTemplate(m_partId, cutTemplate); + emit groupOperationAdded(); + }); + Theme::initToolButton(button); + presetButtons.push_back(button); + } + */ + + { + QPushButton *button = new QPushButton(tr("Chamfer")); + connect(button, &QPushButton::clicked, [&cutDocument, this]() { + std::vector cutTemplate; + cutDocument.toCutTemplate(cutTemplate); + nodemesh::chamferFace2D(&cutTemplate); + cutDocument.fromCutTemplate(cutTemplate); + emit setPartCutTemplate(m_partId, cutTemplate); + emit groupOperationAdded(); + }); + Theme::initToolButton(button); + presetButtons.push_back(button); + } + QVBoxLayout *layout = new QVBoxLayout; QHBoxLayout *presetButtonsLayout = new QHBoxLayout; for (const auto &it: presetButtons) diff --git a/thirdparty/nodemesh/nodemesh/misc.cpp b/thirdparty/nodemesh/nodemesh/misc.cpp index d8b77f77..2d54ca29 100644 --- a/thirdparty/nodemesh/nodemesh/misc.cpp +++ b/thirdparty/nodemesh/nodemesh/misc.cpp @@ -491,3 +491,27 @@ void nodemesh::trim(std::vector *vertices, bool normalize) } } } + +void nodemesh::subdivideFace2D(std::vector *face) +{ + auto oldFace = *face; + face->clear(); + for (size_t i = 0; i < oldFace.size(); ++i) { + size_t j = (i + 1) % oldFace.size(); + QVector2D direct = (oldFace[i] + oldFace[j]).normalized(); + float length = (oldFace[i].length() + oldFace[j].length()) * 0.4; // 0.4 = 0.5 * 0.8 + face->push_back(oldFace[i] * 0.8); + face->push_back(direct * length); + } +} + +void nodemesh::chamferFace2D(std::vector *face) +{ + auto oldFace = *face; + face->clear(); + for (size_t i = 0; i < oldFace.size(); ++i) { + size_t j = (i + 1) % oldFace.size(); + face->push_back(oldFace[i] * 0.8 + oldFace[j] * 0.2); + face->push_back(oldFace[i] * 0.2 + oldFace[j] * 0.8); + } +} diff --git a/thirdparty/nodemesh/nodemesh/misc.h b/thirdparty/nodemesh/nodemesh/misc.h index 53305a02..8f76f1e6 100644 --- a/thirdparty/nodemesh/nodemesh/misc.h +++ b/thirdparty/nodemesh/nodemesh/misc.h @@ -1,6 +1,7 @@ #ifndef NODEMESH_MISC_H #define NODEMESH_MISC_H #include +#include #include #include #include @@ -31,6 +32,8 @@ size_t weldSeam(const std::vector &sourceVertices, const std::vector< std::vector &destVertices, std::vector> &destTriangles); bool isManifold(const std::vector> &faces); void trim(std::vector *vertices, bool normalize=false); +void subdivideFace2D(std::vector *face); +void chamferFace2D(std::vector *face); } diff --git a/thirdparty/nodemesh/nodemesh/modifier.cpp b/thirdparty/nodemesh/nodemesh/modifier.cpp index 68719393..6ce3f0ed 100644 --- a/thirdparty/nodemesh/nodemesh/modifier.cpp +++ b/thirdparty/nodemesh/nodemesh/modifier.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -47,15 +48,7 @@ void Modifier::createIntermediateNode(const Node &firstNode, const Node &secondN void Modifier::subdivide() { for (auto &node: m_nodes) { - auto oldCutTemplate = node.cutTemplate; - node.cutTemplate.clear(); - for (size_t i = 0; i < oldCutTemplate.size(); ++i) { - size_t j = (i + 1) % oldCutTemplate.size(); - QVector2D direct = (oldCutTemplate[i] + oldCutTemplate[j]).normalized(); - float length = (oldCutTemplate[i].length() + oldCutTemplate[j].length()) * 0.4; // 0.4 = 0.5 * 0.8 - node.cutTemplate.push_back(oldCutTemplate[i] * 0.8); - node.cutTemplate.push_back(direct * length); - } + subdivideFace2D(&node.cutTemplate); } }