From e1240fb18d675efa27560b60ec6d7375f14a74a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armandas=20Jaru=C5=A1auskas?= Date: Sat, 16 May 2020 22:41:42 +0900 Subject: [PATCH] PartDesign: Chamfer direction flipping support --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 7 +- src/Mod/PartDesign/App/FeatureChamfer.h | 1 + .../PartDesign/Gui/TaskChamferParameters.cpp | 22 +++++- .../PartDesign/Gui/TaskChamferParameters.h | 2 + .../PartDesign/Gui/TaskChamferParameters.ui | 78 ++++++++++++------- 5 files changed, 81 insertions(+), 29 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index d98d1e0318..333668dd7f 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -74,6 +74,8 @@ Chamfer::Chamfer() ADD_PROPERTY(Angle,(45.0)); Angle.setUnit(Base::Unit::Angle); Angle.setConstraints(&floatAngle); + + ADD_PROPERTY(FlipDirection, (false)); } short Chamfer::mustExecute() const @@ -104,6 +106,7 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) const double size = Size.getValue(); const double size2 = Size2.getValue(); const double angle = Angle.getValue(); + const bool flipDirection = FlipDirection.getValue(); auto res = validateParameters(chamferType, size, size2, angle); if (res != App::DocumentObject::StdReturn) { @@ -124,7 +127,9 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) for (std::vector::const_iterator it=SubNames.begin(); it != SubNames.end(); ++it) { TopoDS_Edge edge = TopoDS::Edge(baseShape.getSubShape(it->c_str())); - const TopoDS_Face& face = TopoDS::Face(mapEdgeFace.FindFromKey(edge).First()); + const TopoDS_Face& face = (chamferType != 0 && flipDirection) ? + TopoDS::Face(mapEdgeFace.FindFromKey(edge).Last()) : + TopoDS::Face(mapEdgeFace.FindFromKey(edge).First()); switch (chamferType) { case 0: // Equal distance mkChamfer.Add(size, size, edge, face); diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index 4e119c8a15..7882bb148e 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -43,6 +43,7 @@ public: App::PropertyQuantityConstraint Size; App::PropertyQuantityConstraint Size2; App::PropertyAngle Angle; + App::PropertyBool FlipDirection; /** @name methods override feature */ //@{ diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp index 0a8a1f4bc3..ca118fc0ad 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp @@ -83,6 +83,8 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q this, SLOT(onSize2Changed(double))); connect(ui->chamferAngle, SIGNAL(valueChanged(double)), this, SLOT(onAngleChanged(double))); + connect(ui->flipDirection, SIGNAL(toggled(bool)), + this, SLOT(onFlipDirection(bool))); connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), this, SLOT(onButtonRefAdd(bool))); connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), @@ -105,6 +107,9 @@ void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer) const int index = pcChamfer->ChamferType.getValue(); ui->chamferType->setCurrentIndex(index); + ui->flipDirection->setEnabled(index != 0); // Enable if type is not "Equal distance" + ui->flipDirection->setChecked(pcChamfer->FlipDirection.getValue()); + ui->chamferSize->setUnit(Base::Unit::Length); ui->chamferSize->setMinimum(0); ui->chamferSize->setValue(pcChamfer->Size.getValue()); @@ -121,6 +126,8 @@ void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer) ui->chamferAngle->setMaximum(180.0); ui->chamferAngle->setValue(pcChamfer->Angle.getValue()); ui->chamferAngle->bind(pcChamfer->Angle); + + ui->stackedWidget->setFixedHeight(ui->chamferSize2->sizeHint().height()); } void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -226,7 +233,7 @@ void TaskChamferParameters::onTypeChanged(int index) PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); pcChamfer->ChamferType.setValue(index); ui->stackedWidget->setCurrentIndex(index); - ui->stackedWidget->setFixedHeight(ui->chamferSize2->sizeHint().height()); + ui->flipDirection->setEnabled(index != 0); // Enable if type is not "Equal distance" pcChamfer->getDocument()->recomputeFeature(pcChamfer); } @@ -254,6 +261,14 @@ void TaskChamferParameters::onAngleChanged(double angle) pcChamfer->getDocument()->recomputeFeature(pcChamfer); } +void TaskChamferParameters::onFlipDirection(bool flip) +{ + PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); + setupTransaction(); + pcChamfer->FlipDirection.setValue(flip); + pcChamfer->getDocument()->recomputeFeature(pcChamfer); +} + int TaskChamferParameters::getType(void) const { return ui->chamferType->currentIndex(); @@ -274,6 +289,11 @@ double TaskChamferParameters::getAngle(void) const return ui->chamferAngle->value().getValue(); } +bool TaskChamferParameters::getFlipDirection(void) const +{ + return ui->flipDirection->isChecked(); +} + TaskChamferParameters::~TaskChamferParameters() { Gui::Selection().clearSelection(); diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.h b/src/Mod/PartDesign/Gui/TaskChamferParameters.h index 83d45ec84d..c33c47c14f 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.h +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.h @@ -49,6 +49,7 @@ private Q_SLOTS: void onSizeChanged(double); void onSize2Changed(double); void onAngleChanged(double); + void onFlipDirection(bool); void onRefDeleted(void); protected: @@ -61,6 +62,7 @@ protected: double getSize(void) const; double getSize2(void) const; double getAngle(void) const; + bool getFlipDirection(void) const; private: void setUpUI(PartDesign::Chamfer* pcChamfer); diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui index 42c569b063..5fb1177dbb 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui @@ -58,31 +58,55 @@ click again to end selection - - - - - Type - - + + + + + + + Type + + + + + + + + Equal distance + + + + + Two distances + + + + + Distance and angle + + + + + - - - - - Equal distance - - - - - Two distances - - - - - Distance and angle - - + + + + false + + + Flip direction + + + + + + + :/icons/PartDesign_Flip_Direction.svg:/icons/PartDesign_Flip_Direction.svg + + + true + @@ -90,7 +114,7 @@ click again to end selection - + Size @@ -126,7 +150,7 @@ click again to end selection 0 - + Size 2 @@ -171,7 +195,7 @@ click again to end selection 180.000000000000000 - 0.100000000000000 + 1.000000000000000 45.000000000000000