Skip to content

Commit

Permalink
Add front/back/side closed configure UI
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Feb 11, 2023
1 parent 0b58867 commit f6aa2c2
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 210 deletions.
88 changes: 77 additions & 11 deletions application/sources/component_property_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,47 @@ ComponentPropertyWidget::ComponentPropertyWidget(Document* document,

QGroupBox* stitchingLineGroupBox = nullptr;
if (!m_componentIds.empty() && hasStitchingLineConfigure()) {
QCheckBox* closeStateBox = new QCheckBox();
Theme::initCheckbox(closeStateBox);
closeStateBox->setText(tr("Closed"));
closeStateBox->setChecked(lastClosed());
QCheckBox* frontCloseStateBox = new QCheckBox();
Theme::initCheckbox(frontCloseStateBox);
frontCloseStateBox->setText(tr("Front Closed"));
frontCloseStateBox->setChecked(lastFrontClosed());

QCheckBox* backCloseStateBox = new QCheckBox();
Theme::initCheckbox(backCloseStateBox);
backCloseStateBox->setText(tr("Back Closed"));
backCloseStateBox->setChecked(lastBackClosed());

QCheckBox* sideCloseStateBox = new QCheckBox();
Theme::initCheckbox(sideCloseStateBox);
sideCloseStateBox->setText(tr("Side Closed"));
sideCloseStateBox->setChecked(lastSideClosed());

connect(frontCloseStateBox, &QCheckBox::stateChanged, this, [=]() {
bool closed = frontCloseStateBox->isChecked();
for (const auto& componentId : m_componentIds)
emit setComponentFrontCloseState(componentId, closed);
emit groupOperationAdded();
});

connect(closeStateBox, &QCheckBox::stateChanged, this, [=]() {
bool closed = closeStateBox->isChecked();
connect(backCloseStateBox, &QCheckBox::stateChanged, this, [=]() {
bool closed = backCloseStateBox->isChecked();
for (const auto& componentId : m_componentIds)
emit setComponentCloseState(componentId, closed);
emit setComponentBackCloseState(componentId, closed);
emit groupOperationAdded();
});

connect(sideCloseStateBox, &QCheckBox::stateChanged, this, [=]() {
bool closed = sideCloseStateBox->isChecked();
for (const auto& componentId : m_componentIds)
emit setComponentSideCloseState(componentId, closed);
emit groupOperationAdded();
});

QHBoxLayout* optionsLayout = new QHBoxLayout;
optionsLayout->addStretch();
optionsLayout->addWidget(closeStateBox);
optionsLayout->addWidget(frontCloseStateBox);
optionsLayout->addWidget(backCloseStateBox);
optionsLayout->addWidget(sideCloseStateBox);

QVBoxLayout* stitchingLineLayout = new QVBoxLayout;
stitchingLineLayout->addLayout(optionsLayout);
Expand Down Expand Up @@ -421,7 +447,9 @@ ComponentPropertyWidget::ComponentPropertyWidget(Document* document,
connect(this, &ComponentPropertyWidget::setPartChamferState, m_document, &Document::setPartChamferState);
connect(this, &ComponentPropertyWidget::setPartRoundState, m_document, &Document::setPartRoundState);
connect(this, &ComponentPropertyWidget::setComponentColorImage, m_document, &Document::setComponentColorImage);
connect(this, &ComponentPropertyWidget::setComponentCloseState, m_document, &Document::setComponentCloseState);
connect(this, &ComponentPropertyWidget::setComponentSideCloseState, m_document, &Document::setComponentSideCloseState);
connect(this, &ComponentPropertyWidget::setComponentFrontCloseState, m_document, &Document::setComponentFrontCloseState);
connect(this, &ComponentPropertyWidget::setComponentBackCloseState, m_document, &Document::setComponentBackCloseState);
connect(this, &ComponentPropertyWidget::setPartSmoothCutoffDegrees, m_document, &Document::setPartSmoothCutoffDegrees);
connect(this, &ComponentPropertyWidget::setPartCutFace, m_document, &Document::setPartCutFace);
connect(this, &ComponentPropertyWidget::setPartCutFaceLinkedId, m_document, &Document::setPartCutFaceLinkedId);
Expand Down Expand Up @@ -497,15 +525,53 @@ QColor ComponentPropertyWidget::lastColor()
return color;
}

bool ComponentPropertyWidget::lastClosed()
bool ComponentPropertyWidget::lastSideClosed()
{
bool closed = false;
std::map<bool, int> closeStateMap;
for (const auto& componentId : m_componentIds) {
const Document::Component* component = m_document->findComponent(componentId);
if (nullptr == component)
continue;
closeStateMap[component->sideClosed]++;
}
if (!closeStateMap.empty()) {
closed = std::max_element(closeStateMap.begin(), closeStateMap.end(),
[](const std::map<bool, int>::value_type& a, const std::map<bool, int>::value_type& b) {
return a.second < b.second;
})->first;
}
return closed;
}

bool ComponentPropertyWidget::lastFrontClosed()
{
bool closed = false;
std::map<bool, int> closeStateMap;
for (const auto& componentId : m_componentIds) {
const Document::Component* component = m_document->findComponent(componentId);
if (nullptr == component)
continue;
closeStateMap[component->frontClosed]++;
}
if (!closeStateMap.empty()) {
closed = std::max_element(closeStateMap.begin(), closeStateMap.end(),
[](const std::map<bool, int>::value_type& a, const std::map<bool, int>::value_type& b) {
return a.second < b.second;
})->first;
}
return closed;
}

bool ComponentPropertyWidget::lastBackClosed()
{
bool closed = false;
std::map<bool, int> closeStateMap;
for (const auto& componentId : m_componentIds) {
const Document::Component* component = m_document->findComponent(componentId);
if (nullptr == component)
continue;
closeStateMap[component->closed]++;
closeStateMap[component->backClosed]++;
}
if (!closeStateMap.empty()) {
closed = std::max_element(closeStateMap.begin(), closeStateMap.end(),
Expand Down
8 changes: 6 additions & 2 deletions application/sources/component_property_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class ComponentPropertyWidget : public QWidget {
void setPartRoundState(const dust3d::Uuid& partId, bool rounded);
void setPartCutRotation(const dust3d::Uuid& partId, float cutRotation);
void setComponentColorImage(const dust3d::Uuid& componentId, const dust3d::Uuid& imageId);
void setComponentCloseState(const dust3d::Uuid& componentId, bool closed);
void setComponentSideCloseState(const dust3d::Uuid& componentId, bool closed);
void setComponentFrontCloseState(const dust3d::Uuid& componentId, bool closed);
void setComponentBackCloseState(const dust3d::Uuid& componentId, bool closed);
void setPartSmoothCutoffDegrees(const dust3d::Uuid& partId, float degrees);
void setPartCutFace(const dust3d::Uuid& partId, dust3d::CutFace cutFace);
void setPartCutFaceLinkedId(const dust3d::Uuid& partId, dust3d::Uuid linkedId);
Expand All @@ -45,7 +47,9 @@ public slots:
QColor m_color;
QColor lastColor();
dust3d::Uuid lastColorImageId();
bool lastClosed();
bool lastSideClosed();
bool lastFrontClosed();
bool lastBackClosed();
float lastSmoothCutoffDegrees();
void preparePartIds();
QImage* pickImage();
Expand Down
52 changes: 45 additions & 7 deletions application/sources/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -628,19 +628,51 @@ void Document::setComponentExpandState(dust3d::Uuid componentId, bool expanded)
emit optionsChanged();
}

void Document::setComponentCloseState(const dust3d::Uuid& componentId, bool closed)
void Document::setComponentSideCloseState(const dust3d::Uuid& componentId, bool closed)
{
auto component = componentMap.find(componentId);
if (component == componentMap.end()) {
return;
}

if (component->second.closed == closed)
if (component->second.sideClosed == closed)
return;

component->second.dirty = true;
component->second.closed = closed;
emit componentCloseStateChanged(componentId);
component->second.sideClosed = closed;
emit componentSideCloseStateChanged(componentId);
emit skeletonChanged();
}

void Document::setComponentFrontCloseState(const dust3d::Uuid& componentId, bool closed)
{
auto component = componentMap.find(componentId);
if (component == componentMap.end()) {
return;
}

if (component->second.frontClosed == closed)
return;

component->second.dirty = true;
component->second.frontClosed = closed;
emit componentFrontCloseStateChanged(componentId);
emit skeletonChanged();
}

void Document::setComponentBackCloseState(const dust3d::Uuid& componentId, bool closed)
{
auto component = componentMap.find(componentId);
if (component == componentMap.end()) {
return;
}

if (component->second.backClosed == closed)
return;

component->second.dirty = true;
component->second.backClosed = closed;
emit componentBackCloseStateChanged(componentId);
emit skeletonChanged();
}

Expand Down Expand Up @@ -1789,8 +1821,12 @@ void Document::toSnapshot(dust3d::Snapshot* snapshot, const std::set<dust3d::Uui
component["colorImageId"] = componentIt.second.colorImageId.toString();
if (componentIt.second.hasColor)
component["color"] = componentIt.second.color.name(QColor::HexArgb).toUtf8().constData();
if (componentIt.second.closed)
component["closed"] = "true";
if (componentIt.second.sideClosed)
component["sideClosed"] = "true";
if (componentIt.second.frontClosed)
component["frontClosed"] = "true";
if (componentIt.second.backClosed)
component["backClosed"] = "true";
component["__dirty"] = componentIt.second.dirty ? "true" : "false";
std::vector<std::string> childIdList;
for (const auto& childId : componentIt.second.childrenIds) {
Expand Down Expand Up @@ -1996,7 +2032,9 @@ void Document::addFromSnapshot(const dust3d::Snapshot& snapshot, enum SnapshotSo
component.name = dust3d::String::valueOrEmpty(componentKv.second, "name").c_str();
component.expanded = dust3d::String::isTrue(dust3d::String::valueOrEmpty(componentKv.second, "expanded"));
component.combineMode = dust3d::CombineModeFromString(dust3d::String::valueOrEmpty(componentKv.second, "combineMode").c_str());
component.closed = dust3d::String::isTrue(dust3d::String::valueOrEmpty(componentKv.second, "closed"));
component.sideClosed = dust3d::String::isTrue(dust3d::String::valueOrEmpty(componentKv.second, "sideClosed"));
component.frontClosed = dust3d::String::isTrue(dust3d::String::valueOrEmpty(componentKv.second, "frontClosed"));
component.sideClosed = dust3d::String::isTrue(dust3d::String::valueOrEmpty(componentKv.second, "sideClosed"));
const auto& colorImageIt = componentKv.second.find("colorImageId");
if (colorImageIt != componentKv.second.end()) {
component.colorImageId = dust3d::Uuid(colorImageIt->second);
Expand Down
12 changes: 9 additions & 3 deletions application/sources/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ class Document : public QObject {
dust3d::Uuid colorImageId;
bool expanded = true;
dust3d::CombineMode combineMode = dust3d::CombineMode::Normal;
bool closed = false;
bool sideClosed = false;
bool frontClosed = false;
bool backClosed = false;
bool dirty = true;
std::vector<dust3d::Uuid> childrenIds;
bool isPreviewMeshObsolete = false;
Expand Down Expand Up @@ -248,7 +250,9 @@ class Document : public QObject {
void componentExpandStateChanged(dust3d::Uuid componentId);
void componentPreviewMeshChanged(const dust3d::Uuid& componentId);
void componentPreviewPixmapChanged(const dust3d::Uuid& componentId);
void componentCloseStateChanged(const dust3d::Uuid& componentId);
void componentSideCloseStateChanged(const dust3d::Uuid& componentId);
void componentFrontCloseStateChanged(const dust3d::Uuid& componentId);
void componentBackCloseStateChanged(const dust3d::Uuid& componentId);
void nodeRemoved(dust3d::Uuid nodeId);
void edgeRemoved(dust3d::Uuid edgeId);
void nodeRadiusChanged(dust3d::Uuid nodeId);
Expand Down Expand Up @@ -452,7 +456,9 @@ public slots:
void ungroupComponent(const dust3d::Uuid& componentId);
void createNewChildComponent(dust3d::Uuid parentComponentId);
void setComponentExpandState(dust3d::Uuid componentId, bool expanded);
void setComponentCloseState(const dust3d::Uuid& componentId, bool closed);
void setComponentSideCloseState(const dust3d::Uuid& componentId, bool closed);
void setComponentFrontCloseState(const dust3d::Uuid& componentId, bool closed);
void setComponentBackCloseState(const dust3d::Uuid& componentId, bool closed);
void hideOtherComponents(dust3d::Uuid componentId);
void lockOtherComponents(dust3d::Uuid componentId);
void setComponentColorState(const dust3d::Uuid& componentId, bool hasColor, QColor color);
Expand Down
17 changes: 11 additions & 6 deletions dust3d/mesh/mesh_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ bool MeshGenerator::fetchPartOrderedNodes(const std::string& partIdString, std::
std::unique_ptr<MeshState> MeshGenerator::combineStitchingMesh(const std::string& componentIdString,
const std::vector<std::string>& partIdStrings,
const std::vector<std::string>& componentIdStrings,
bool closed,
bool frontClosed,
bool backClosed,
bool sideClosed,
GeneratedComponent& componentCache)
{
std::vector<StitchMeshBuilder::Spline> splines;
Expand All @@ -478,20 +480,17 @@ std::unique_ptr<MeshState> MeshGenerator::combineStitchingMesh(const std::string
continue;
}
bool isCircle = false;
bool isClosing = false;
std::vector<MeshNode> orderedBuilderNodes;
if (!fetchPartOrderedNodes(partIdString, &orderedBuilderNodes, &isCircle))
continue;
if (isCircle)
continue;
isClosing = orderedBuilderNodes.size() <= 1;
splines.emplace_back(StitchMeshBuilder::Spline {
std::move(orderedBuilderNodes),
isClosing,
componentIds[partIndex] });
}

auto stitchMeshBuilder = std::make_unique<StitchMeshBuilder>(std::move(splines), closed);
auto stitchMeshBuilder = std::make_unique<StitchMeshBuilder>(std::move(splines), frontClosed, backClosed, sideClosed);
stitchMeshBuilder->build();

const auto& generatedVertices = stitchMeshBuilder->generatedVertices();
Expand Down Expand Up @@ -882,7 +881,13 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentMesh(const std::string
groupMeshes.emplace_back(std::make_tuple(std::move(childMesh), group.first, String::join(group.second, "|")));
}
if (!stitchingParts.empty()) {
auto stitchingMesh = combineStitchingMesh(componentIdString, stitchingParts, stitchingComponents, String::isTrue(String::valueOrEmpty(*component, "closed")), componentCache);
auto stitchingMesh = combineStitchingMesh(componentIdString,
stitchingParts,
stitchingComponents,
String::isTrue(String::valueOrEmpty(*component, "frontClosed")),
String::isTrue(String::valueOrEmpty(*component, "backClosed")),
String::isTrue(String::valueOrEmpty(*component, "sideClosed")),
componentCache);
if (stitchingMesh && !stitchingMesh->isNull()) {
groupMeshes.emplace_back(std::make_tuple(std::move(stitchingMesh), CombineMode::Normal, String::join(stitchingComponents, ":")));
}
Expand Down
4 changes: 3 additions & 1 deletion dust3d/mesh/mesh_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ class MeshGenerator {
std::unique_ptr<MeshState> combineStitchingMesh(const std::string& componentIdString,
const std::vector<std::string>& partIdStrings,
const std::vector<std::string>& componentIdStrings,
bool closed,
bool frontClosed,
bool backClosed,
bool sideClosed,
GeneratedComponent& componentCache);
void collectUncombinedComponent(const std::string& componentIdString);
void cutFaceStringToCutTemplate(const std::string& cutFaceString, std::vector<Vector2>& cutTemplate);
Expand Down

0 comments on commit f6aa2c2

Please sign in to comment.