From aa76cbc875159436d981e400f3f62765413f10b3 Mon Sep 17 00:00:00 2001 From: Mark Ganson TheMarkster <39143564+mwganson@users.noreply.github.com> Date: Fri, 4 Feb 2022 18:50:51 -0600 Subject: [PATCH] [PartDesign Fillet/Chamfer] add UseAllEdges boolean property (#5340) - [PartDesign Fillet/Chamfer] add UseAllEdges boolean property - add UseAllEdges checkbox to fillet and chamfer dialogs - put UseAllEdges property into Chamfer and Fillet groups, create Fillet group for fillets and put Radius into it, too. --- src/Mod/PartDesign/App/FeatureChamfer.cpp | 17 +++++++++- src/Mod/PartDesign/App/FeatureChamfer.h | 1 + src/Mod/PartDesign/App/FeatureFillet.cpp | 19 ++++++++++-- src/Mod/PartDesign/App/FeatureFillet.h | 1 + src/Mod/PartDesign/Gui/Command.cpp | 31 ++++++++++++------- .../PartDesign/Gui/TaskChamferParameters.cpp | 19 ++++++++++++ .../PartDesign/Gui/TaskChamferParameters.h | 1 + .../PartDesign/Gui/TaskChamferParameters.ui | 7 +++++ .../PartDesign/Gui/TaskDressUpParameters.cpp | 1 - .../PartDesign/Gui/TaskDressUpParameters.h | 1 + .../PartDesign/Gui/TaskFilletParameters.cpp | 17 ++++++++++ src/Mod/PartDesign/Gui/TaskFilletParameters.h | 1 + .../PartDesign/Gui/TaskFilletParameters.ui | 7 +++++ 13 files changed, 108 insertions(+), 15 deletions(-) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 06eee9cf15..4401ba295b 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -76,6 +76,9 @@ Chamfer::Chamfer() Angle.setConstraints(&floatAngle); ADD_PROPERTY_TYPE(FlipDirection, (false), "Chamfer", App::Prop_None, "Flip direction"); + ADD_PROPERTY_TYPE(UseAllEdges, (false), "Chamfer", App::Prop_None, + "Chamfer all edges if true, else use only those edges in Base property.\n" + "If true, then this overrides any edge changes made to the Base property or in the dialog.\n"); updateProperties(); } @@ -115,8 +118,20 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) } std::vector SubNames = std::vector(Base.getSubValues()); + + if (UseAllEdges.getValue()){ + SubNames.clear(); + std::string edgeTypeName = Part::TopoShape::shapeName(TopAbs_EDGE); //"Edge" + int count = TopShape.countSubElements(edgeTypeName.c_str()); + for (int ii = 0; ii < count; ii++){ + std::ostringstream edgeName; + edgeName << edgeTypeName << ii+1; + SubNames.push_back(edgeName.str()); + } + } + std::vector FaceNames; - + getContinuousEdges(TopShape, SubNames, FaceNames); if (SubNames.size() == 0) diff --git a/src/Mod/PartDesign/App/FeatureChamfer.h b/src/Mod/PartDesign/App/FeatureChamfer.h index 96536a777c..168699846e 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.h +++ b/src/Mod/PartDesign/App/FeatureChamfer.h @@ -44,6 +44,7 @@ public: App::PropertyQuantityConstraint Size2; App::PropertyAngle Angle; App::PropertyBool FlipDirection; + App::PropertyBool UseAllEdges; /** @name methods override feature */ //@{ diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index 5f2d52c4d0..0003162b34 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -53,9 +53,12 @@ const App::PropertyQuantityConstraint::Constraints floatRadius = {0.0,FLT_MAX,0. Fillet::Fillet() { - ADD_PROPERTY(Radius,(1.0)); + ADD_PROPERTY_TYPE(Radius, (1.0), "Fillet", App::Prop_None, "Fillet radius."); Radius.setUnit(Base::Unit::Length); Radius.setConstraints(&floatRadius); + ADD_PROPERTY_TYPE(UseAllEdges, (false), "Fillet", App::Prop_None, + "Fillet all edges if true, else use only those edges in Base property.\n" + "If true, then this overrides any edge changes made to the Base property or in the dialog.\n"); } short Fillet::mustExecute() const @@ -73,7 +76,19 @@ App::DocumentObjectExecReturn *Fillet::execute(void) } catch (Base::Exception& e) { return new App::DocumentObjectExecReturn(e.what()); } - std::vector SubNames = std::vector(Base.getSubValues()); + std::vector SubNames = std::vector(Base.getSubValues()); + + if (UseAllEdges.getValue()){ + SubNames.clear(); + std::string edgeTypeName = Part::TopoShape::shapeName(TopAbs_EDGE); //"Edge" + int count = TopShape.countSubElements(edgeTypeName.c_str()); + for (int ii = 0; ii < count; ii++){ + std::ostringstream edgeName; + edgeName << edgeTypeName << ii+1; + SubNames.push_back(edgeName.str()); + } + } + getContinuousEdges(TopShape, SubNames); if (SubNames.size() == 0) diff --git a/src/Mod/PartDesign/App/FeatureFillet.h b/src/Mod/PartDesign/App/FeatureFillet.h index e46b5b05bd..0e0e992e22 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.h +++ b/src/Mod/PartDesign/App/FeatureFillet.h @@ -40,6 +40,7 @@ public: Fillet(); App::PropertyQuantityConstraint Radius; + App::PropertyBool UseAllEdges; /** @name methods override feature */ //@{ diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 0d9612d8a3..a6bae0cee7 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -1861,7 +1861,7 @@ bool CmdPartDesignSubtractiveHelix::isActive(void) //=========================================================================== bool dressupGetSelected(Gui::Command* cmd, const std::string& which, - Gui::SelectionObject &selected) + Gui::SelectionObject &selected, bool &useAllEdges) { // No PartDesign feature without Body past FreeCAD 0.16 App::Document *doc = cmd->getDocument(); @@ -1912,13 +1912,16 @@ bool dressupGetSelected(Gui::Command* cmd, const std::string& which, } // if 1 Part::Feature object selected, but no subobjects, select all edges for the user - if (selection[0].getSubNames().size() == 0){ - int count = TopShape.countSubElements("Edge"); + // but only for fillet and chamfer (not for draft or thickness) + if (selection[0].getSubNames().size() == 0 && (which.compare("Fillet") == 0 || which.compare("Chamfer") == 0)){ + useAllEdges = true; + std::string edgeTypeName = Part::TopoShape::shapeName(TopAbs_EDGE); //"Edge" + int count = TopShape.countSubElements(edgeTypeName.c_str()); std::string docName = App::GetApplication().getDocumentName(base->getDocument()); std::string objName = base->getNameInDocument(); for (int ii = 0; ii < count; ii++){ std::ostringstream edgeName; - edgeName << "Edge" << ii+1; + edgeName << edgeTypeName << ii+1; Gui::Selection().addSelection(docName.c_str(), objName.c_str(), edgeName.str().c_str()); } selection = cmd->getSelection().getSelectionEx(); @@ -1930,7 +1933,7 @@ bool dressupGetSelected(Gui::Command* cmd, const std::string& which, } void finishDressupFeature(const Gui::Command* cmd, const std::string& which, - Part::Feature *base, const std::vector & SubNames) + Part::Feature *base, const std::vector & SubNames, const bool useAllEdges) { if (SubNames.size() == 0) { QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"), @@ -1953,6 +1956,9 @@ void finishDressupFeature(const Gui::Command* cmd, const std::string& which, FCMD_OBJ_CMD(body,"newObject('PartDesign::"<getDocument()->getObject(FeatName.c_str()); FCMD_OBJ_CMD(Feat,"Base = " << str.str()); + if (useAllEdges && (which.compare("Fillet") == 0 || which.compare("Chamfer") == 0)){ + FCMD_OBJ_CMD(Feat,"UseAllEdges = True"); + } cmd->doCommand(cmd->Gui, "Gui.Selection.clearSelection()"); finishFeature(cmd, Feat, base); @@ -1968,15 +1974,16 @@ void finishDressupFeature(const Gui::Command* cmd, const std::string& which, void makeChamferOrFillet(Gui::Command* cmd, const std::string& which) { + bool useAllEdges = false; Gui::SelectionObject selected; - if (!dressupGetSelected ( cmd, which, selected)) + if (!dressupGetSelected ( cmd, which, selected, useAllEdges)) return; Part::Feature *base = static_cast(selected.getObject()); std::vector SubNames = std::vector(selected.getSubNames()); - finishDressupFeature (cmd, which, base, SubNames); + finishDressupFeature (cmd, which, base, SubNames, useAllEdges); } //=========================================================================== @@ -2057,7 +2064,8 @@ void CmdPartDesignDraft::activated(int iMsg) { Q_UNUSED(iMsg); Gui::SelectionObject selected; - if (!dressupGetSelected ( this, "Draft", selected)) + bool useAllEdges = false; + if (!dressupGetSelected ( this, "Draft", selected, useAllEdges)) return; Part::Feature *base = static_cast(selected.getObject()); @@ -2084,7 +2092,7 @@ void CmdPartDesignDraft::activated(int iMsg) i++; } - finishDressupFeature (this, "Draft", base, SubNames); + finishDressupFeature (this, "Draft", base, SubNames, useAllEdges); } bool CmdPartDesignDraft::isActive(void) @@ -2114,7 +2122,8 @@ void CmdPartDesignThickness::activated(int iMsg) { Q_UNUSED(iMsg); Gui::SelectionObject selected; - if (!dressupGetSelected ( this, "Thickness", selected)) + bool useAllEdges = false; + if (!dressupGetSelected ( this, "Thickness", selected, useAllEdges)) return; Part::Feature *base = static_cast(selected.getObject()); @@ -2133,7 +2142,7 @@ void CmdPartDesignThickness::activated(int iMsg) i++; } - finishDressupFeature (this, "Thickness", base, SubNames); + finishDressupFeature (this, "Thickness", base, SubNames, useAllEdges); } bool CmdPartDesignThickness::isActive(void) diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp index 996501b7a9..d0955a9351 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp @@ -67,6 +67,12 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); setUpUI(pcChamfer); + + bool useAllEdges = pcChamfer->UseAllEdges.getValue(); + ui->checkBoxUseAllEdges->setChecked(useAllEdges); + ui->buttonRefAdd->setEnabled(!useAllEdges); + ui->buttonRefRemove->setEnabled(!useAllEdges); + ui->listWidgetReferences->setEnabled(!useAllEdges); QMetaObject::invokeMethod(ui->chamferSize, "setFocus", Qt::QueuedConnection); std::vector strings = pcChamfer->Base.getSubValues(); @@ -91,6 +97,8 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q this, SLOT(onButtonRefAdd(bool))); connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), this, SLOT(onButtonRefRemove(bool))); + connect(ui->checkBoxUseAllEdges, SIGNAL(toggled(bool)), + this, SLOT(onCheckBoxUseAllEdgesToggled(bool))); // Create context menu createDeleteAction(ui->listWidgetReferences, ui->buttonRefRemove); @@ -147,6 +155,7 @@ void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer) ui->sizeLabel->setMinimumWidth(minWidth); ui->size2Label->setMinimumWidth(minWidth); ui->angleLabel->setMinimumWidth(minWidth); + } void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -190,6 +199,16 @@ void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) } } +void TaskChamferParameters::onCheckBoxUseAllEdgesToggled(bool checked) +{ + PartDesign::Chamfer* pcChamfer = static_cast(DressUpView->getObject()); + ui->buttonRefRemove->setEnabled(!checked); + ui->buttonRefAdd->setEnabled(!checked); + ui->listWidgetReferences->setEnabled(!checked); + pcChamfer->UseAllEdges.setValue(checked); + pcChamfer->getDocument()->recomputeFeature(pcChamfer); +} + void TaskChamferParameters::clearButtons(const selectionModes notThis) { if (notThis != refAdd) ui->buttonRefAdd->setChecked(false); diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.h b/src/Mod/PartDesign/Gui/TaskChamferParameters.h index 965da94e76..94ca780c7a 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.h +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.h @@ -52,6 +52,7 @@ private Q_SLOTS: void onFlipDirection(bool); void onRefDeleted(void); void onAddAllEdges(void); + void onCheckBoxUseAllEdgesToggled(bool checked); protected: virtual void clearButtons(const selectionModes notThis); diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui index 2c2f0ee230..52b2295fe5 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.ui @@ -132,6 +132,13 @@ click again to end selection + + + + Use All Edges + + + diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index f61141910a..4ed672d54f 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -429,7 +429,6 @@ TaskDlgDressUpParameters::~TaskDlgDressUpParameters() bool TaskDlgDressUpParameters::accept() { getDressUpView()->highlightReferences(false); - std::vector refs = parameter->getReferences(); std::stringstream str; str << Gui::Command::getObjectCmd(vp->getObject()) << ".Base = (" diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h index 197a698da1..b29479f7a2 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h @@ -80,6 +80,7 @@ protected: bool KeyEvent(QEvent *e); void hideOnError(); void addAllEdges(QListWidget* listWidget); + protected: enum selectionModes { none, refAdd, refRemove, plane, line }; virtual void clearButtons(const selectionModes notThis) = 0; diff --git a/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp b/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp index 768bd3bca2..a08d1050ad 100644 --- a/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp @@ -63,6 +63,11 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi this->groupLayout()->addWidget(proxy); PartDesign::Fillet* pcFillet = static_cast(DressUpView->getObject()); + bool useAllEdges = pcFillet->UseAllEdges.getValue(); + ui->checkBoxUseAllEdges->setChecked(useAllEdges); + ui->buttonRefAdd->setEnabled(!useAllEdges); + ui->buttonRefRemove->setEnabled(!useAllEdges); + ui->listWidgetReferences->setEnabled(!useAllEdges); double r = pcFillet->Radius.getValue(); ui->filletRadius->setUnit(Base::Unit::Length); @@ -85,6 +90,8 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi this, SLOT(onButtonRefAdd(bool))); connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), this, SLOT(onButtonRefRemove(bool))); + connect(ui->checkBoxUseAllEdges, SIGNAL(toggled(bool)), + this, SLOT(onCheckBoxUseAllEdgesToggled(bool))); // Create context menu createDeleteAction(ui->listWidgetReferences, ui->buttonRefRemove); @@ -145,6 +152,16 @@ void TaskFilletParameters::onSelectionChanged(const Gui::SelectionChanges& msg) } } +void TaskFilletParameters::onCheckBoxUseAllEdgesToggled(bool checked) +{ + PartDesign::Fillet* pcFillet = static_cast(DressUpView->getObject()); + ui->buttonRefRemove->setEnabled(!checked); + ui->buttonRefAdd->setEnabled(!checked); + ui->listWidgetReferences->setEnabled(!checked); + pcFillet->UseAllEdges.setValue(checked); + pcFillet->getDocument()->recomputeFeature(pcFillet); +} + void TaskFilletParameters::clearButtons(const selectionModes notThis) { if (notThis != refAdd) ui->buttonRefAdd->setChecked(false); diff --git a/src/Mod/PartDesign/Gui/TaskFilletParameters.h b/src/Mod/PartDesign/Gui/TaskFilletParameters.h index 7d60ddbcea..eef9929631 100644 --- a/src/Mod/PartDesign/Gui/TaskFilletParameters.h +++ b/src/Mod/PartDesign/Gui/TaskFilletParameters.h @@ -45,6 +45,7 @@ private Q_SLOTS: void onLengthChanged(double); void onRefDeleted(void); void onAddAllEdges(void); + void onCheckBoxUseAllEdgesToggled(bool checked); protected: double getLength(void) const; diff --git a/src/Mod/PartDesign/Gui/TaskFilletParameters.ui b/src/Mod/PartDesign/Gui/TaskFilletParameters.ui index 968a7487fc..2718be1f63 100644 --- a/src/Mod/PartDesign/Gui/TaskFilletParameters.ui +++ b/src/Mod/PartDesign/Gui/TaskFilletParameters.ui @@ -75,6 +75,13 @@ click again to end selection + + + + Use All Edges + + +