| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| #include <QAction>
|
| #include <QFontMetrics>
|
| #include <QListWidget>
|
| #include <QMessageBox>
|
|
|
| #include <Base/Interpreter.h>
|
| #include <App/Document.h>
|
| #include <App/DocumentObject.h>
|
| #include <Gui/Selection/Selection.h>
|
| #include <Gui/Tools.h>
|
| #include <Gui/ViewProvider.h>
|
| #include <Gui/Inventor/Draggers/SoLinearDragger.h>
|
| #include <Gui/Inventor/Draggers/SoRotationDragger.h>
|
| #include <Gui/Utilities.h>
|
| #include <Mod/PartDesign/App/FeatureChamfer.h>
|
| #include <Mod/Part/App/Geometry.h>
|
| #include <Mod/Part/App/GizmoHelper.h>
|
|
|
| #include <TopoDS.hxx>
|
| #include <BRep_Tool.hxx>
|
| #include <BRepGProp.hxx>
|
| #include <GProp_GProps.hxx>
|
| #include <GeomAPI_ProjectPointOnSurf.hxx>
|
| #include <Base/Converter.h>
|
|
|
| #include "ui_TaskChamferParameters.h"
|
| #include "TaskChamferParameters.h"
|
|
|
|
|
| using namespace PartDesignGui;
|
| using namespace Gui;
|
|
|
|
|
|
|
| TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp* DressUpView, QWidget* parent)
|
| : TaskDressUpParameters(DressUpView, true, true, parent)
|
| , ui(new Ui_TaskChamferParameters)
|
| {
|
|
|
| proxy = new QWidget(this);
|
| ui->setupUi(proxy);
|
| this->groupLayout()->addWidget(proxy);
|
|
|
| PartDesign::Chamfer* pcChamfer = DressUpView->getObject<PartDesign::Chamfer>();
|
|
|
| setUpUI(pcChamfer);
|
|
|
| bool useAllEdges = pcChamfer->UseAllEdges.getValue();
|
| ui->checkBoxUseAllEdges->setChecked(useAllEdges);
|
| ui->buttonRefSel->setEnabled(!useAllEdges);
|
| ui->listWidgetReferences->setEnabled(!useAllEdges);
|
| QMetaObject::invokeMethod(ui->chamferSize, "setFocus", Qt::QueuedConnection);
|
|
|
| std::vector<std::string> strings = pcChamfer->Base.getSubValues();
|
| for (const auto& string : strings) {
|
| ui->listWidgetReferences->addItem(QString::fromStdString(string));
|
| }
|
|
|
| QMetaObject::connectSlotsByName(this);
|
|
|
|
|
| connect(ui->chamferType, qOverload<int>(&QComboBox::currentIndexChanged),
|
| this, &TaskChamferParameters::onTypeChanged);
|
| connect(ui->chamferSize, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
| this, &TaskChamferParameters::onSizeChanged);
|
| connect(ui->chamferSize2, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
| this, &TaskChamferParameters::onSize2Changed);
|
| connect(ui->chamferAngle, qOverload<double>(&Gui::QuantitySpinBox::valueChanged),
|
| this, &TaskChamferParameters::onAngleChanged);
|
| connect(ui->flipDirection, &QCheckBox::toggled,
|
| this, &TaskChamferParameters::onFlipDirection);
|
| connect(ui->buttonRefSel, &QToolButton::toggled,
|
| this, &TaskChamferParameters::onButtonRefSel);
|
| connect(ui->checkBoxUseAllEdges, &QCheckBox::toggled,
|
| this, &TaskChamferParameters::onCheckBoxUseAllEdgesToggled);
|
|
|
|
|
| createDeleteAction(ui->listWidgetReferences);
|
| connect(deleteAction, &QAction::triggered,
|
| this, &TaskChamferParameters::onRefDeleted);
|
|
|
| createAddAllEdgesAction(ui->listWidgetReferences);
|
| connect(addAllEdgesAction, &QAction::triggered,
|
| this, &TaskChamferParameters::onAddAllEdges);
|
|
|
| connect(ui->listWidgetReferences, &QListWidget::currentItemChanged,
|
| this, &TaskChamferParameters::setSelection);
|
| connect(ui->listWidgetReferences, &QListWidget::itemClicked,
|
| this, &TaskChamferParameters::setSelection);
|
| connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked,
|
| this, &TaskChamferParameters::doubleClicked);
|
|
|
|
|
| if (strings.size() == 0) {
|
| setSelectionMode(refSel);
|
| }
|
| else {
|
| hideOnError();
|
| }
|
|
|
| setupGizmos(DressUpView);
|
| }
|
|
|
| void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer)
|
| {
|
| const int index = pcChamfer->ChamferType.getValue();
|
| ui->chamferType->setCurrentIndex(index);
|
|
|
| ui->flipDirection->setEnabled(index != 0);
|
| ui->flipDirection->setChecked(pcChamfer->FlipDirection.getValue());
|
|
|
| ui->chamferSize->setUnit(Base::Unit::Length);
|
| ui->chamferSize->setMinimum(0);
|
| ui->chamferSize->setValue(pcChamfer->Size.getValue());
|
| ui->chamferSize->bind(pcChamfer->Size);
|
| ui->chamferSize->selectNumber();
|
|
|
| ui->chamferSize2->setUnit(Base::Unit::Length);
|
| ui->chamferSize2->setMinimum(0);
|
| ui->chamferSize2->setValue(pcChamfer->Size2.getValue());
|
| ui->chamferSize2->bind(pcChamfer->Size2);
|
|
|
| ui->chamferAngle->setUnit(Base::Unit::Angle);
|
| ui->chamferAngle->setMinimum(pcChamfer->Angle.getMinimum());
|
| ui->chamferAngle->setMaximum(pcChamfer->Angle.getMaximum());
|
| ui->chamferAngle->setValue(pcChamfer->Angle.getValue());
|
| ui->chamferAngle->bind(pcChamfer->Angle);
|
|
|
| ui->stackedWidget->setFixedHeight(ui->chamferSize2->sizeHint().height());
|
|
|
| QFontMetrics fm(ui->typeLabel->font());
|
| int minWidth = Gui::QtTools::horizontalAdvance(fm, ui->typeLabel->text());
|
| minWidth = std::max<int>(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->sizeLabel->text()));
|
| minWidth = std::max<int>(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->size2Label->text()));
|
| minWidth = std::max<int>(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->angleLabel->text()));
|
| minWidth = minWidth + 5;
|
| ui->typeLabel->setMinimumWidth(minWidth);
|
| ui->sizeLabel->setMinimumWidth(minWidth);
|
| ui->size2Label->setMinimumWidth(minWidth);
|
| ui->angleLabel->setMinimumWidth(minWidth);
|
| }
|
|
|
| void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
|
| {
|
|
|
|
|
|
|
| if (msg.Type == Gui::SelectionChanges::AddSelection) {
|
| if (selectionMode == refSel) {
|
| referenceSelected(msg, ui->listWidgetReferences);
|
| }
|
| }
|
| else if (msg.Type == Gui::SelectionChanges::ClrSelection) {
|
|
|
|
|
| setGizmoPositions();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::onCheckBoxUseAllEdgesToggled(bool checked)
|
| {
|
| if (auto chamfer = getObject<PartDesign::Chamfer>()) {
|
| if (checked) {
|
| setSelectionMode(none);
|
| }
|
|
|
| ui->buttonRefSel->setEnabled(!checked);
|
| ui->listWidgetReferences->setEnabled(!checked);
|
| chamfer->UseAllEdges.setValue(checked);
|
| chamfer->recomputeFeature();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::setButtons(const selectionModes mode)
|
| {
|
| ui->buttonRefSel->setChecked(mode == refSel);
|
| ui->buttonRefSel->setText(mode == refSel ? stopSelectionLabel() : startSelectionLabel());
|
| }
|
|
|
| void TaskChamferParameters::onRefDeleted()
|
| {
|
| TaskDressUpParameters::deleteRef(ui->listWidgetReferences);
|
| setGizmoPositions();
|
| }
|
|
|
| void TaskChamferParameters::onAddAllEdges()
|
| {
|
| TaskDressUpParameters::addAllEdges(ui->listWidgetReferences);
|
| }
|
|
|
| void TaskChamferParameters::onTypeChanged(int index)
|
| {
|
| if (auto chamfer = getObject<PartDesign::Chamfer>()) {
|
| setSelectionMode(none);
|
| chamfer->ChamferType.setValue(index);
|
| ui->stackedWidget->setCurrentIndex(index);
|
| ui->flipDirection->setEnabled(index != 0);
|
| chamfer->recomputeFeature();
|
|
|
| hideOnError();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::onSizeChanged(double len)
|
| {
|
| if (auto chamfer = getObject<PartDesign::Chamfer>()) {
|
| setSelectionMode(none);
|
| setupTransaction();
|
| chamfer->Size.setValue(len);
|
| chamfer->recomputeFeature();
|
|
|
| hideOnError();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::onSize2Changed(double len)
|
| {
|
| if (auto chamfer = getObject<PartDesign::Chamfer>()) {
|
| setSelectionMode(none);
|
| setupTransaction();
|
| chamfer->Size2.setValue(len);
|
| chamfer->recomputeFeature();
|
|
|
| hideOnError();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::onAngleChanged(double angle)
|
| {
|
| if (auto chamfer = getObject<PartDesign::Chamfer>()) {
|
| setSelectionMode(none);
|
| setupTransaction();
|
| chamfer->Angle.setValue(angle);
|
| chamfer->recomputeFeature();
|
|
|
| hideOnError();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::onFlipDirection(bool flip)
|
| {
|
| if (auto chamfer = getObject<PartDesign::Chamfer>()) {
|
| setSelectionMode(none);
|
| setupTransaction();
|
| chamfer->FlipDirection.setValue(flip);
|
| chamfer->recomputeFeature();
|
|
|
| hideOnError();
|
|
|
| setGizmoPositions();
|
| }
|
| }
|
|
|
| int TaskChamferParameters::getType() const
|
| {
|
| return ui->chamferType->currentIndex();
|
| }
|
|
|
| double TaskChamferParameters::getSize() const
|
| {
|
| return ui->chamferSize->value().getValue();
|
| }
|
|
|
| double TaskChamferParameters::getSize2() const
|
| {
|
| return ui->chamferSize2->value().getValue();
|
| }
|
|
|
| double TaskChamferParameters::getAngle() const
|
| {
|
| return ui->chamferAngle->value().getValue();
|
| }
|
|
|
| bool TaskChamferParameters::getFlipDirection() const
|
| {
|
| return ui->flipDirection->isChecked();
|
| }
|
|
|
| TaskChamferParameters::~TaskChamferParameters()
|
| {
|
| try {
|
| Gui::Selection().clearSelection();
|
| Gui::Selection().rmvSelectionGate();
|
| }
|
| catch (const Py::Exception&) {
|
| Base::PyException e;
|
| e.reportException();
|
| }
|
| }
|
|
|
| void TaskChamferParameters::changeEvent(QEvent* e)
|
| {
|
| TaskBox::changeEvent(e);
|
| if (e->type() == QEvent::LanguageChange) {
|
| ui->retranslateUi(proxy);
|
| }
|
| }
|
|
|
| void TaskChamferParameters::apply()
|
| {
|
| auto chamfer = getObject<PartDesign::Chamfer>();
|
|
|
| const int chamfertype = chamfer->ChamferType.getValue();
|
|
|
| switch (chamfertype) {
|
|
|
| case 0:
|
| ui->chamferSize->apply();
|
| break;
|
| case 1:
|
| ui->chamferSize->apply();
|
| ui->chamferSize2->apply();
|
| break;
|
| case 2:
|
| ui->chamferSize->apply();
|
| ui->chamferAngle->apply();
|
| break;
|
| }
|
|
|
|
|
| if (ui->listWidgetReferences->count() == 0) {
|
| Base::Console().warning(tr("Empty chamfer created!\n").toStdString().c_str());
|
| }
|
| }
|
|
|
| void TaskChamferParameters::setupGizmos(ViewProviderDressUp* vp)
|
| {
|
| if (!GizmoContainer::isEnabled()) {
|
| return;
|
| }
|
|
|
| distanceGizmo = new Gui::LinearGizmo(ui->chamferSize);
|
| secondDistanceGizmo = new Gui::LinearGizmo(ui->chamferSize);
|
| angleGizmo = new Gui::RotationGizmo(ui->chamferAngle);
|
|
|
| connect(ui->chamferType, qOverload<int>(&QComboBox::currentIndexChanged), [this](int index) {
|
| auto type = static_cast<Part::ChamferType>(index);
|
|
|
| switch (type) {
|
| case Part::ChamferType::equalDistance:
|
| secondDistanceGizmo->setVisibility(true);
|
| angleGizmo->setVisibility(false);
|
|
|
| secondDistanceGizmo->setProperty(ui->chamferSize);
|
|
|
| break;
|
| case Part::ChamferType::twoDistances:
|
| secondDistanceGizmo->setVisibility(true);
|
| angleGizmo->setVisibility(false);
|
|
|
| secondDistanceGizmo->setProperty(ui->chamferSize2);
|
|
|
| break;
|
| case Part::ChamferType::distanceAngle:
|
| secondDistanceGizmo->setVisibility(false);
|
| angleGizmo->setVisibility(true);
|
| }
|
| });
|
|
|
| gizmoContainer = GizmoContainer::create({distanceGizmo, secondDistanceGizmo, angleGizmo}, vp);
|
|
|
| setGizmoPositions();
|
|
|
| ui->chamferType->currentIndexChanged(ui->chamferType->currentIndex());
|
| }
|
|
|
| void TaskChamferParameters::setGizmoPositions()
|
| {
|
| if (!gizmoContainer) {
|
| return;
|
| }
|
|
|
| auto chamfer = getObject<PartDesign::Chamfer>();
|
| if (!chamfer || chamfer->isError()) {
|
| gizmoContainer->visible = false;
|
| return;
|
| }
|
|
|
| PartDesign::TopoShape baseShape = chamfer->getBaseTopoShape(true);
|
| auto shapes = chamfer->getContinuousEdges(baseShape);
|
|
|
| if (shapes.size() == 0) {
|
| gizmoContainer->visible = false;
|
| return;
|
| }
|
| gizmoContainer->visible = true;
|
|
|
| Part::TopoShape edge = shapes[0];
|
| auto [face1, face2] = getAdjacentFacesFromEdge(edge, baseShape);
|
|
|
| DraggerPlacementProps props = getDraggerPlacementFromEdgeAndFace(edge, face1);
|
| DraggerPlacementProps props2 = getDraggerPlacementFromEdgeAndFace(edge, face2);
|
| if (ui->flipDirection->isChecked()) {
|
| std::swap(props, props2);
|
| }
|
|
|
| distanceGizmo->Gizmo::setDraggerPlacement(props.position, props.dir);
|
| secondDistanceGizmo->Gizmo::setDraggerPlacement(props2.position, props2.dir);
|
|
|
| angleGizmo->placeBelowLinearGizmo(distanceGizmo);
|
| angleGizmo->getDraggerContainer()->setArcNormalDirection(
|
| Base::convertTo<SbVec3f>(-props.dir.Cross(props2.dir))
|
| );
|
|
|
| angleGizmo->setVisibility(getType() == 2);
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
| TaskDlgChamferParameters::TaskDlgChamferParameters(ViewProviderChamfer* DressUpView)
|
| : TaskDlgDressUpParameters(DressUpView)
|
| {
|
| parameter = new TaskChamferParameters(DressUpView);
|
|
|
| Content.push_back(parameter);
|
| Content.push_back(preview);
|
| }
|
|
|
| TaskDlgChamferParameters::~TaskDlgChamferParameters() = default;
|
|
|
|
|
|
|
| bool TaskDlgChamferParameters::accept()
|
| {
|
| auto obj = getObject();
|
| if (!obj->isError()) {
|
| getViewObject()->showPreviousFeature(false);
|
| }
|
|
|
| parameter->apply();
|
|
|
| return TaskDlgDressUpParameters::accept();
|
| }
|
|
|
| #include "moc_TaskChamferParameters.cpp"
|
|
|