From 262841bb3c8a7498c2213d03ad4c82d274be2b02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armandas=20Jaru=C5=A1auskas?= Date: Wed, 13 May 2020 22:37:23 +0900 Subject: [PATCH] PartDesign: Chamfer with multiple creation modes --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 44 ++++- src/Mod/PartDesign/App/FeatureChamfer.h | 2 + .../PartDesign/Gui/TaskChamferParameters.cpp | 86 +++++++--- .../PartDesign/Gui/TaskChamferParameters.h | 14 +- .../PartDesign/Gui/TaskChamferParameters.ui | 160 ++++++++++++++---- 5 files changed, 243 insertions(+), 63 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 3fc823ba00..a5e35b5241 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -52,14 +52,23 @@ using namespace PartDesign; PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp) +const char* ChamferTypeEnums[] = {"Equal distance", "Two distances", "Distance and Angle", NULL}; const App::PropertyQuantityConstraint::Constraints floatSize = {0.0,FLT_MAX,0.1}; const App::PropertyAngle::Constraints floatAngle = {0.0,180.0,0.1}; Chamfer::Chamfer() { + ADD_PROPERTY(ChamferType, ((long)0)); + ChamferType.setEnums(ChamferTypeEnums); + ADD_PROPERTY(Size,(1.0)); Size.setUnit(Base::Unit::Length); Size.setConstraints(&floatSize); + + ADD_PROPERTY(Size2,(1.0)); + Size2.setUnit(Base::Unit::Length); + Size2.setConstraints(&floatSize); + ADD_PROPERTY(Angle,(45.0)); Angle.setUnit(Base::Unit::Angle); Angle.setConstraints(&floatAngle); @@ -89,13 +98,10 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) if (SubNames.size() == 0) return new App::DocumentObjectExecReturn("No edges specified"); - double size = Size.getValue(); - if (size <= 0) - return new App::DocumentObjectExecReturn("Size must be greater than zero"); - - double angle = Base::toRadians(Angle.getValue()); - if (angle <= 0 || angle >= 180.0) - return new App::DocumentObjectExecReturn("Angle must be greater than 0 and less than 180"); + const int chamferType = ChamferType.getValue(); + const double size = Size.getValue(); + const double size2 = Size2.getValue(); + const double angle = Base::toRadians(Angle.getValue()); this->positionByBaseFeature(); // create an untransformed copy of the basefeature shape @@ -112,7 +118,29 @@ 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()); - mkChamfer.AddDA(size, angle, edge, face); + switch (chamferType) { + case 0: + if (size <= 0) { + return new App::DocumentObjectExecReturn("Size must be greater than zero"); + } else { + mkChamfer.Add(size, size, edge, face); + } + break; + case 1: + if (size <= 0 || size2 <= 0) { + return new App::DocumentObjectExecReturn("Sizes must be greater than zero"); + } else { + mkChamfer.Add(size, size2, edge, face); + } + break; + case 2: + if (angle <= 0 || angle >= 180.0) { + return new App::DocumentObjectExecReturn("Angle must be greater than 0 and less than 180"); + } else { + mkChamfer.AddDA(size, angle, edge, face); + } + break; + } } mkChamfer.Build(); diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index 6a32708cd3..4e119c8a15 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -39,7 +39,9 @@ class PartDesignExport Chamfer : public DressUp public: Chamfer(); + App::PropertyEnumeration ChamferType; App::PropertyQuantityConstraint Size; + App::PropertyQuantityConstraint Size2; App::PropertyAngle Angle; /** @name methods override feature */ diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp index c822a0cbe8..0a8a1f4bc3 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp @@ -64,22 +64,8 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); - double r = pcChamfer->Size.getValue(); - ui->chamferDistance->setUnit(Base::Unit::Length); - ui->chamferDistance->setValue(r); - ui->chamferDistance->setMinimum(0); - ui->chamferDistance->selectNumber(); - ui->chamferDistance->bind(pcChamfer->Size); - QMetaObject::invokeMethod(ui->chamferDistance, "setFocus", Qt::QueuedConnection); - - double a = pcChamfer->Angle.getValue(); - ui->chamferAngle->setUnit(Base::Unit::Angle); - ui->chamferAngle->setValue(a); - ui->chamferAngle->setMinimum(0.0); - ui->chamferAngle->setMaximum(180.0); - ui->chamferAngle->selectAll(); - ui->chamferAngle->bind(pcChamfer->Angle); - QMetaObject::invokeMethod(ui->chamferAngle, "setFocus", Qt::QueuedConnection); + setUpUI(pcChamfer); + QMetaObject::invokeMethod(ui->chamferSize, "setFocus", Qt::QueuedConnection); std::vector strings = pcChamfer->Base.getSubValues(); for (std::vector::const_iterator i = strings.begin(); i != strings.end(); i++) @@ -89,8 +75,12 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q QMetaObject::connectSlotsByName(this); - connect(ui->chamferDistance, SIGNAL(valueChanged(double)), - this, SLOT(onLengthChanged(double))); + connect(ui->chamferType, SIGNAL(currentIndexChanged(int)), + this, SLOT(onTypeChanged(int))); + connect(ui->chamferSize, SIGNAL(valueChanged(double)), + this, SLOT(onSizeChanged(double))); + connect(ui->chamferSize2, SIGNAL(valueChanged(double)), + this, SLOT(onSize2Changed(double))); connect(ui->chamferAngle, SIGNAL(valueChanged(double)), this, SLOT(onAngleChanged(double))); connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), @@ -110,6 +100,29 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q this, SLOT(doubleClicked(QListWidgetItem*))); } +void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer) +{ + const int index = pcChamfer->ChamferType.getValue(); + ui->chamferType->setCurrentIndex(index); + + 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(0.0); + ui->chamferAngle->setMaximum(180.0); + ui->chamferAngle->setValue(pcChamfer->Angle.getValue()); + ui->chamferAngle->bind(pcChamfer->Angle); +} + void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { // executed when the user selected something in the CAD object @@ -208,7 +221,16 @@ void TaskChamferParameters::onRefDeleted(void) } } -void TaskChamferParameters::onLengthChanged(double len) +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()); + pcChamfer->getDocument()->recomputeFeature(pcChamfer); +} + +void TaskChamferParameters::onSizeChanged(double len) { PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); setupTransaction(); @@ -216,9 +238,12 @@ void TaskChamferParameters::onLengthChanged(double len) pcChamfer->getDocument()->recomputeFeature(pcChamfer); } -double TaskChamferParameters::getLength(void) const +void TaskChamferParameters::onSize2Changed(double len) { - return ui->chamferDistance->value().getValue(); + PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); + setupTransaction(); + pcChamfer->Size2.setValue(len); + pcChamfer->getDocument()->recomputeFeature(pcChamfer); } void TaskChamferParameters::onAngleChanged(double angle) @@ -229,6 +254,21 @@ void TaskChamferParameters::onAngleChanged(double angle) pcChamfer->getDocument()->recomputeFeature(pcChamfer); } +int TaskChamferParameters::getType(void) const +{ + return ui->chamferType->currentIndex(); +} + +double TaskChamferParameters::getSize(void) const +{ + return ui->chamferSize->value().getValue(); +} + +double TaskChamferParameters::getSize2(void) const +{ + return ui->chamferSize2->value().getValue(); +} + double TaskChamferParameters::getAngle(void) const { return ui->chamferAngle->value().getValue(); @@ -260,7 +300,9 @@ void TaskChamferParameters::apply() std::string name = DressUpView->getObject()->getNameInDocument(); //Gui::Command::openCommand("Chamfer changed"); - ui->chamferDistance->apply(); + ui->chamferSize->apply(); + ui->chamferSize2->apply(); + ui->chamferAngle->apply(); } //************************************************************************** diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.h b/src/Mod/PartDesign/Gui/TaskChamferParameters.h index 14246e0d5a..83d45ec84d 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.h +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.h @@ -28,6 +28,9 @@ #include "ViewProviderChamfer.h" class Ui_TaskChamferParameters; +namespace PartDesign { +class Chamfer; +} namespace PartDesignGui { @@ -42,7 +45,9 @@ public: virtual void apply(); private Q_SLOTS: - void onLengthChanged(double); + void onTypeChanged(int); + void onSizeChanged(double); + void onSize2Changed(double); void onAngleChanged(double); void onRefDeleted(void); @@ -51,10 +56,15 @@ protected: bool event(QEvent *e); void changeEvent(QEvent *e); virtual void onSelectionChanged(const Gui::SelectionChanges& msg); - double getLength(void) const; + + int getType(void) const; + double getSize(void) const; + double getSize2(void) const; double getAngle(void) const; private: + void setUpUI(PartDesign::Chamfer* pcChamfer); + Ui_TaskChamferParameters* ui; }; diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui index bee65462b5..42c569b063 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui @@ -6,8 +6,8 @@ 0 0 - 182 - 185 + 263 + 240 @@ -57,49 +57,130 @@ click again to end selection - - - - + + + + + + Type + + + + + + + + Equal distance + + + + + Two distances + + + + + Distance and angle + + + + + + + + + + Size - - + + + + 1.000000000000000 + + - - - - - Angle + + + 0 + + + + + + 0 - - - - - - deg + + 0 - - 0.000000000000000 + + 0 - - 180.000000000000000 + + 0 - - 0.100000000000000 + + + + Size 2 + + + + + + + 1.000000000000000 + + + + + + + + + 0 - - 45.000000000000000 + + 0 - - - + + 0 + + + 0 + + + + + Angle + + + + + + + 0.000000000000000 + + + 180.000000000000000 + + + 0.100000000000000 + + + 45.000000000000000 + + + + + + @@ -111,5 +192,22 @@ click again to end selection - + + + chamferType + currentIndexChanged(int) + stackedWidget + setCurrentIndex(int) + + + 149 + 196 + + + 131 + 222 + + + +