Skip to content

Commit

Permalink
Add component stitching line options configure UI
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Feb 5, 2023
1 parent cada405 commit bba0d36
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
47 changes: 47 additions & 0 deletions application/sources/component_property_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,31 @@ ComponentPropertyWidget::ComponentPropertyWidget(Document* document,
if (nullptr != colorImageGroupBox)
skinLayout->addWidget(colorImageGroupBox);

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

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

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

QVBoxLayout* stitchingLineLayout = new QVBoxLayout;
stitchingLineLayout->addLayout(optionsLayout);

stitchingLineGroupBox = new QGroupBox(tr("Stitching Line"));
stitchingLineGroupBox->setLayout(stitchingLineLayout);
}

QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addLayout(topLayout);
if (nullptr != deformGroupBox)
Expand All @@ -370,6 +395,8 @@ ComponentPropertyWidget::ComponentPropertyWidget(Document* document,
if (nullptr != smoothGroupBox)
mainLayout->addWidget(smoothGroupBox);
mainLayout->addLayout(skinLayout);
if (nullptr != stitchingLineGroupBox)
mainLayout->addWidget(stitchingLineGroupBox);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);

connect(this, &ComponentPropertyWidget::setComponentColorState, m_document, &Document::setComponentColorState);
Expand All @@ -383,6 +410,7 @@ 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::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 @@ -457,6 +485,25 @@ QColor ComponentPropertyWidget::lastColor()
return color;
}

bool ComponentPropertyWidget::lastClosed()
{
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]++;
}
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;
}

dust3d::Uuid ComponentPropertyWidget::lastColorImageId()
{
dust3d::Uuid colorImageId;
Expand Down
2 changes: 2 additions & 0 deletions application/sources/component_property_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 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 @@ -43,6 +44,7 @@ public slots:
QColor m_color;
QColor lastColor();
dust3d::Uuid lastColorImageId();
bool lastClosed();
float lastSmoothCutoffDegrees();
void preparePartIds();
QImage* pickImage();
Expand Down
2 changes: 1 addition & 1 deletion application/sources/document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ void Document::toSnapshot(dust3d::Snapshot* snapshot, const std::set<dust3d::Uui
if (componentIt.second.hasColor)
component["color"] = componentIt.second.color.name(QColor::HexArgb).toUtf8().constData();
if (componentIt.second.closed)
component["closed"] = componentIt.second.closed;
component["closed"] = "true";
component["__dirty"] = componentIt.second.dirty ? "true" : "false";
std::vector<std::string> childIdList;
for (const auto& childId : componentIt.second.childrenIds) {
Expand Down

0 comments on commit bba0d36

Please sign in to comment.