diff --git a/src/Mod/PartDesign/App/AppPartDesign.cpp b/src/Mod/PartDesign/App/AppPartDesign.cpp index 944764ce67..c9118aa464 100644 --- a/src/Mod/PartDesign/App/AppPartDesign.cpp +++ b/src/Mod/PartDesign/App/AppPartDesign.cpp @@ -59,7 +59,8 @@ #include "ShapeBinder.h" -namespace PartDesign { +namespace PartDesign +{ extern PyObject* initModule(); } @@ -71,7 +72,7 @@ PyMOD_INIT_FUNC(_PartDesign) Base::Interpreter().runString("import Part"); Base::Interpreter().runString("import Sketcher"); } - catch(const Base::Exception& e) { + catch (const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); PyMOD_Return(nullptr); } @@ -84,6 +85,7 @@ PyMOD_INIT_FUNC(_PartDesign) // call PyType_Ready, otherwise we run into a segmentation fault, later on. // This function is responsible for adding inherited slots from a type's base class. + // clang-format off PartDesign::Feature ::init(); PartDesign::FeaturePython ::init(); PartDesign::Solid ::init(); @@ -155,6 +157,7 @@ PyMOD_INIT_FUNC(_PartDesign) PartDesign::FeatureBase ::init(); PartDesign::Measure ::initialize(); + // clang-format on PyMOD_Return(mod); } diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index 550f8d62bc..9ccb4a38e3 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -76,13 +76,15 @@ void loadPartDesignResource() Gui::Translator::instance()->refresh(); } -namespace PartDesignGui { -class Module : public Py::ExtensionModule +namespace PartDesignGui +{ +class Module: public Py::ExtensionModule { public: - Module() : Py::ExtensionModule("PartDesignGui") + Module() + : Py::ExtensionModule("PartDesignGui") { - initialize("This module is the PartDesignGui module."); // register with Python + initialize("This module is the PartDesignGui module."); // register with Python } private: @@ -93,7 +95,7 @@ PyObject* initModule() return Base::Interpreter().addModule(new Module); } -} // namespace PartDesignGui +} // namespace PartDesignGui /* Python entry */ @@ -108,7 +110,7 @@ PyMOD_INIT_FUNC(PartDesignGui) Base::Interpreter().runString("import PartGui"); Base::Interpreter().runString("import SketcherGui"); } - catch(const Base::Exception& e) { + catch (const Base::Exception& e) { PyErr_SetString(PyExc_ImportError, e.what()); PyMOD_Return(nullptr); } @@ -121,6 +123,7 @@ PyMOD_INIT_FUNC(PartDesignGui) CreatePartDesignBodyCommands(); CreatePartDesignPrimitiveCommands(); + // clang-format off PartDesignGui::Workbench ::init(); PartDesignGui::ViewProvider ::init(); PartDesignGui::ViewProviderPython ::init(); @@ -158,8 +161,9 @@ PyMOD_INIT_FUNC(PartDesignGui) PartDesignGui::ViewProviderLoft ::init(); PartDesignGui::ViewProviderHelix ::init(); PartDesignGui::ViewProviderBase ::init(); + // clang-format on - // add resources and reloads the translators + // add resources and reloads the translators loadPartDesignResource(); PyMOD_Return(mod); diff --git a/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp b/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp index 15e81ff043..bfa1b30273 100644 --- a/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskBooleanParameters.cpp @@ -25,8 +25,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -48,8 +48,11 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskBooleanParameters */ -TaskBooleanParameters::TaskBooleanParameters(ViewProviderBoolean *BooleanView,QWidget *parent) - : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Boolean"), tr("Boolean parameters"), true, parent) +TaskBooleanParameters::TaskBooleanParameters(ViewProviderBoolean* BooleanView, QWidget* parent) + : TaskBox(Gui::BitmapFactory().pixmap("PartDesign_Boolean"), + tr("Boolean parameters"), + true, + parent) , ui(new Ui_TaskBooleanParameters) , BooleanView(BooleanView) { @@ -60,12 +63,14 @@ TaskBooleanParameters::TaskBooleanParameters(ViewProviderBoolean *BooleanView,QW ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + // clang-format off connect(ui->buttonBodyAdd, &QToolButton::toggled, this, &TaskBooleanParameters::onButtonBodyAdd); connect(ui->buttonBodyRemove, &QToolButton::toggled, this, &TaskBooleanParameters::onButtonBodyRemove); connect(ui->comboType, qOverload(&QComboBox::currentIndexChanged), this, &TaskBooleanParameters::onTypeChanged); + // clang-format on this->groupLayout()->addWidget(proxy); @@ -94,27 +99,33 @@ TaskBooleanParameters::TaskBooleanParameters(ViewProviderBoolean *BooleanView,QW void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (selectionMode == none) + if (selectionMode == none) { return; + } if (msg.Type == Gui::SelectionChanges::AddSelection) { - if (strcmp(msg.pDocName, BooleanView->getObject()->getDocument()->getName()) != 0) + if (strcmp(msg.pDocName, BooleanView->getObject()->getDocument()->getName()) != 0) { return; + } // get the selected object - PartDesign::Boolean* pcBoolean = static_cast(BooleanView->getObject()); + PartDesign::Boolean* pcBoolean = + static_cast(BooleanView->getObject()); std::string body(msg.pObjectName); - if (body.empty()) + if (body.empty()) { return; + } App::DocumentObject* pcBody = pcBoolean->getDocument()->getObject(body.c_str()); - if (!pcBody) + if (!pcBody) { return; + } // if the selected object is not a body then get the body it is part of if (!pcBody->isDerivedFrom()) { pcBody = PartDesign::Body::findBodyOf(pcBody); - if (!pcBody) + if (!pcBody) { return; + } body = pcBody->getNameInDocument(); } @@ -137,26 +148,34 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg) // Hide the bodies if (bodies.size() == 1) { // Hide base body and added body - Gui::ViewProviderDocumentObject* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(pcBoolean->BaseFeature.getValue())); - if (vp) + Gui::ViewProviderDocumentObject* vp = + dynamic_cast( + Gui::Application::Instance->getViewProvider( + pcBoolean->BaseFeature.getValue())); + if (vp) { vp->hide(); + } vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(bodies.front())); - if (vp) + Gui::Application::Instance->getViewProvider(bodies.front())); + if (vp) { vp->hide(); + } BooleanView->show(); - } else { + } + else { // Hide newly added body - Gui::ViewProviderDocumentObject* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(bodies.back())); - if (vp) + Gui::ViewProviderDocumentObject* vp = + dynamic_cast( + Gui::Application::Instance->getViewProvider(bodies.back())); + if (vp) { vp->hide(); + } } } } else if (selectionMode == bodyRemove) { - std::vector::iterator b = std::find(bodies.begin(), bodies.end(), pcBody); + std::vector::iterator b = + std::find(bodies.begin(), bodies.end(), pcBody); if (b != bodies.end()) { bodies.erase(b); pcBoolean->setObjects(bodies); @@ -177,15 +196,20 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg) exitSelectionMode(); // Make bodies visible again - Gui::ViewProviderDocumentObject* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(pcBody)); - if (vp) + Gui::ViewProviderDocumentObject* vp = + dynamic_cast( + Gui::Application::Instance->getViewProvider(pcBody)); + if (vp) { vp->show(); + } if (bodies.empty()) { - Gui::ViewProviderDocumentObject* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(pcBoolean->BaseFeature.getValue())); - if (vp) + Gui::ViewProviderDocumentObject* vp = + dynamic_cast( + Gui::Application::Instance->getViewProvider( + pcBoolean->BaseFeature.getValue())); + if (vp) { vp->show(); + } BooleanView->hide(); } } @@ -196,14 +220,17 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskBooleanParameters::onButtonBodyAdd(bool checked) { if (checked) { - PartDesign::Boolean* pcBoolean = static_cast(BooleanView->getObject()); + PartDesign::Boolean* pcBoolean = + static_cast(BooleanView->getObject()); Gui::Document* doc = BooleanView->getDocument(); BooleanView->hide(); - if (pcBoolean->Group.getValues().empty() && pcBoolean->BaseFeature.getValue()) + if (pcBoolean->Group.getValues().empty() && pcBoolean->BaseFeature.getValue()) { doc->setHide(pcBoolean->BaseFeature.getValue()->getNameInDocument()); + } selectionMode = bodyAdd; Gui::Selection().clearSelection(); - } else { + } + else { exitSelectionMode(); } } @@ -212,11 +239,13 @@ void TaskBooleanParameters::onButtonBodyRemove(bool checked) { if (checked) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (doc) + if (doc) { BooleanView->show(); + } selectionMode = bodyRemove; Gui::Selection().clearSelection(); - } else { + } + else { exitSelectionMode(); } } @@ -226,10 +255,17 @@ void TaskBooleanParameters::onTypeChanged(int index) PartDesign::Boolean* pcBoolean = static_cast(BooleanView->getObject()); switch (index) { - case 0: pcBoolean->Type.setValue("Fuse"); break; - case 1: pcBoolean->Type.setValue("Cut"); break; - case 2: pcBoolean->Type.setValue("Common"); break; - default: pcBoolean->Type.setValue("Fuse"); + case 0: + pcBoolean->Type.setValue("Fuse"); + break; + case 1: + pcBoolean->Type.setValue("Cut"); + break; + case 2: + pcBoolean->Type.setValue("Common"); + break; + default: + pcBoolean->Type.setValue("Fuse"); } pcBoolean->getDocument()->recomputeFeature(pcBoolean); @@ -238,8 +274,10 @@ void TaskBooleanParameters::onTypeChanged(int index) const std::vector TaskBooleanParameters::getBodies() const { std::vector result; - for (int i = 0; i < ui->listWidgetBodies->count(); i++) - result.push_back(ui->listWidgetBodies->item(i)->data(Qt::UserRole).toString().toStdString()); + for (int i = 0; i < ui->listWidgetBodies->count(); i++) { + result.push_back( + ui->listWidgetBodies->item(i)->data(Qt::UserRole).toString().toStdString()); + } return result; } @@ -253,8 +291,9 @@ void TaskBooleanParameters::onBodyDeleted() PartDesign::Boolean* pcBoolean = static_cast(BooleanView->getObject()); std::vector bodies = pcBoolean->Group.getValues(); int index = ui->listWidgetBodies->currentRow(); - if (index < 0 && (size_t) index > bodies.size()) + if (index < 0 && (size_t)index > bodies.size()) { return; + } App::DocumentObject* body = bodies[index]; QString internalName = ui->listWidgetBodies->item(index)->data(Qt::UserRole).toString(); @@ -272,21 +311,23 @@ void TaskBooleanParameters::onBodyDeleted() // Make bodies visible again Gui::ViewProviderDocumentObject* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(body)); - if (vp) + Gui::Application::Instance->getViewProvider(body)); + if (vp) { vp->show(); + } if (bodies.empty()) { Gui::ViewProviderDocumentObject* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(pcBoolean->BaseFeature.getValue())); - if (vp) + Gui::Application::Instance->getViewProvider(pcBoolean->BaseFeature.getValue())); + if (vp) { vp->show(); + } BooleanView->hide(); } } TaskBooleanParameters::~TaskBooleanParameters() = default; -void TaskBooleanParameters::changeEvent(QEvent *e) +void TaskBooleanParameters::changeEvent(QEvent* e) { TaskBox::changeEvent(e); if (e->type() == QEvent::LanguageChange) { @@ -301,8 +342,9 @@ void TaskBooleanParameters::exitSelectionMode() { selectionMode = none; Gui::Document* doc = Gui::Application::Instance->activeDocument(); - if (doc) + if (doc) { doc->setShow(BooleanView->getObject()->getNameInDocument()); + } } //************************************************************************** @@ -310,11 +352,12 @@ void TaskBooleanParameters::exitSelectionMode() // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgBooleanParameters::TaskDlgBooleanParameters(ViewProviderBoolean *BooleanView) - : TaskDialog(),BooleanView(BooleanView) +TaskDlgBooleanParameters::TaskDlgBooleanParameters(ViewProviderBoolean* BooleanView) + : TaskDialog() + , BooleanView(BooleanView) { assert(BooleanView); - parameter = new TaskBooleanParameters(BooleanView); + parameter = new TaskBooleanParameters(BooleanView); Content.push_back(parameter); } @@ -325,45 +368,46 @@ TaskDlgBooleanParameters::~TaskDlgBooleanParameters() = default; void TaskDlgBooleanParameters::open() -{ - -} +{} void TaskDlgBooleanParameters::clicked(int) -{ - -} +{} bool TaskDlgBooleanParameters::accept() { auto obj = BooleanView->getObject(); - if(!obj || !obj->isAttachedToDocument()) + if (!obj || !obj->isAttachedToDocument()) { return false; + } BooleanView->Visibility.setValue(true); try { std::vector bodies = parameter->getBodies(); if (bodies.empty()) { - QMessageBox::warning(parameter, tr("Empty body list"), + QMessageBox::warning(parameter, + tr("Empty body list"), tr("The body list cannot be empty")); return false; } std::stringstream str; str << Gui::Command::getObjectCmd(obj) << ".setObjects( ["; - for (const auto & body : bodies) { - str << "App.getDocument('" << obj->getDocument()->getName() << "').getObject('" << body << "'),"; + for (const auto& body : bodies) { + str << "App.getDocument('" << obj->getDocument()->getName() << "').getObject('" << body + << "'),"; } str << "])"; - Gui::Command::runCommand(Gui::Command::Doc,str.str().c_str()); + Gui::Command::runCommand(Gui::Command::Doc, str.str().c_str()); } catch (const Base::Exception& e) { - QMessageBox::warning(parameter, tr("Boolean: Accept: Input error"), QCoreApplication::translate("Exception", e.what())); + QMessageBox::warning(parameter, + tr("Boolean: Accept: Input error"), + QCoreApplication::translate("Exception", e.what())); return false; } - FCMD_OBJ_CMD(obj,"Type = " << parameter->getType()); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + FCMD_OBJ_CMD(obj, "Type = " << parameter->getType()); + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().resetEdit()"); Gui::Command::commitCommand(); return true; @@ -386,12 +430,11 @@ bool TaskDlgBooleanParameters::reject() // roll back the done things Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().resetEdit()"); return true; } - #include "moc_TaskBooleanParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp index baf69e1b7f..4914511509 100644 --- a/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskChamferParameters.cpp @@ -24,10 +24,10 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -47,7 +47,7 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskChamferParameters */ -TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, QWidget *parent) +TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp* DressUpView, QWidget* parent) : TaskDressUpParameters(DressUpView, true, true, parent) , ui(new Ui_TaskChamferParameters) { @@ -67,45 +67,51 @@ TaskChamferParameters::TaskChamferParameters(ViewProviderDressUp *DressUpView, Q QMetaObject::invokeMethod(ui->chamferSize, "setFocus", Qt::QueuedConnection); std::vector strings = pcChamfer->Base.getSubValues(); - for (const auto & string : strings) { + for (const auto& string : strings) { ui->listWidgetReferences->addItem(QString::fromStdString(string)); } QMetaObject::connectSlotsByName(this); + // clang-format off connect(ui->chamferType, qOverload(&QComboBox::currentIndexChanged), - this, &TaskChamferParameters::onTypeChanged); + this, &TaskChamferParameters::onTypeChanged); connect(ui->chamferSize, qOverload(&Gui::QuantitySpinBox::valueChanged), - this, &TaskChamferParameters::onSizeChanged); + this, &TaskChamferParameters::onSizeChanged); connect(ui->chamferSize2, qOverload(&Gui::QuantitySpinBox::valueChanged), - this, &TaskChamferParameters::onSize2Changed); + this, &TaskChamferParameters::onSize2Changed); connect(ui->chamferAngle, qOverload(&Gui::QuantitySpinBox::valueChanged), - this, &TaskChamferParameters::onAngleChanged); + this, &TaskChamferParameters::onAngleChanged); connect(ui->flipDirection, &QCheckBox::toggled, - this, &TaskChamferParameters::onFlipDirection); + this, &TaskChamferParameters::onFlipDirection); connect(ui->buttonRefSel, &QToolButton::toggled, - this, &TaskChamferParameters::onButtonRefSel); + this, &TaskChamferParameters::onButtonRefSel); connect(ui->checkBoxUseAllEdges, &QCheckBox::toggled, this, &TaskChamferParameters::onCheckBoxUseAllEdgesToggled); // Create context menu createDeleteAction(ui->listWidgetReferences); - connect(deleteAction, &QAction::triggered, this, &TaskChamferParameters::onRefDeleted); + connect(deleteAction, &QAction::triggered, + this, &TaskChamferParameters::onRefDeleted); createAddAllEdgesAction(ui->listWidgetReferences); - connect(addAllEdgesAction, &QAction::triggered, this, &TaskChamferParameters::onAddAllEdges); + connect(addAllEdgesAction, &QAction::triggered, + this, &TaskChamferParameters::onAddAllEdges); connect(ui->listWidgetReferences, &QListWidget::currentItemChanged, - this, &TaskChamferParameters::setSelection); + this, &TaskChamferParameters::setSelection); connect(ui->listWidgetReferences, &QListWidget::itemClicked, - this, &TaskChamferParameters::setSelection); + this, &TaskChamferParameters::setSelection); connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked, - this, &TaskChamferParameters::doubleClicked); + this, &TaskChamferParameters::doubleClicked); + // clang-format on - if (strings.size() == 0) + if (strings.size() == 0) { setSelectionMode(refSel); - else + } + else { hideOnError(); + } } void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer) @@ -113,7 +119,7 @@ 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->setEnabled(index != 0); // Enable if type is not "Equal distance" ui->flipDirection->setChecked(pcChamfer->FlipDirection.getValue()); ui->chamferSize->setUnit(Base::Unit::Length); @@ -140,12 +146,11 @@ void TaskChamferParameters::setUpUI(PartDesign::Chamfer* pcChamfer) minWidth = std::max(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->sizeLabel->text())); minWidth = std::max(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->size2Label->text())); minWidth = std::max(minWidth, Gui::QtTools::horizontalAdvance(fm, ui->angleLabel->text())); - minWidth = minWidth + 5; //spacing + minWidth = minWidth + 5; // spacing ui->typeLabel->setMinimumWidth(minWidth); ui->sizeLabel->setMinimumWidth(minWidth); ui->size2Label->setMinimumWidth(minWidth); ui->angleLabel->setMinimumWidth(minWidth); - } void TaskChamferParameters::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -196,7 +201,7 @@ void TaskChamferParameters::onTypeChanged(int index) setSelectionMode(none); chamfer->ChamferType.setValue(index); ui->stackedWidget->setCurrentIndex(index); - ui->flipDirection->setEnabled(index != 0); // Enable if type is not "Equal distance" + ui->flipDirection->setEnabled(index != 0); // Enable if type is not "Equal distance" chamfer->recomputeFeature(); // hide the chamfer if there was a computation error hideOnError(); @@ -283,17 +288,17 @@ TaskChamferParameters::~TaskChamferParameters() Gui::Selection().rmvSelectionGate(); } catch (const Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); } } -bool TaskChamferParameters::event(QEvent *e) +bool TaskChamferParameters::event(QEvent* e) { return TaskDressUpParameters::KeyEvent(e); } -void TaskChamferParameters::changeEvent(QEvent *e) +void TaskChamferParameters::changeEvent(QEvent* e) { TaskBox::changeEvent(e); if (e->type() == QEvent::LanguageChange) { @@ -307,24 +312,25 @@ void TaskChamferParameters::apply() const int chamfertype = chamfer->ChamferType.getValue(); - switch(chamfertype) { + switch (chamfertype) { - case 0: // "Equal distance" + case 0: // "Equal distance" ui->chamferSize->apply(); break; - case 1: // "Two distances" + case 1: // "Two distances" ui->chamferSize->apply(); ui->chamferSize2->apply(); break; - case 2: // "Distance and Angle" + case 2: // "Distance and Angle" ui->chamferSize->apply(); ui->chamferAngle->apply(); break; } - //Alert user if he created an empty feature - if (ui->listWidgetReferences->count() == 0) + // Alert user if he created an empty feature + if (ui->listWidgetReferences->count() == 0) { Base::Console().Warning(tr("Empty chamfer created !\n").toStdString().c_str()); + } } //************************************************************************** @@ -332,10 +338,10 @@ void TaskChamferParameters::apply() // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgChamferParameters::TaskDlgChamferParameters(ViewProviderChamfer *DressUpView) +TaskDlgChamferParameters::TaskDlgChamferParameters(ViewProviderChamfer* DressUpView) : TaskDlgDressUpParameters(DressUpView) { - parameter = new TaskChamferParameters(DressUpView); + parameter = new TaskChamferParameters(DressUpView); Content.push_back(parameter); } diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp index 5759661edf..9e6b27b2bd 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp @@ -25,10 +25,10 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include -# include +#include +#include +#include +#include #endif #include @@ -48,7 +48,7 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskDraftParameters */ -TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidget *parent) +TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp* DressUpView, QWidget* parent) : TaskDressUpParameters(DressUpView, false, true, parent) , ui(new Ui_TaskDraftParameters) { @@ -74,33 +74,35 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidg ui->checkReverse->setChecked(r); std::vector strings = pcDraft->Base.getSubValues(); - for (const auto & string : strings) { + for (const auto& string : strings) { ui->listWidgetReferences->addItem(QString::fromStdString(string)); } QMetaObject::connectSlotsByName(this); + // clang-format off connect(ui->draftAngle, qOverload(&Gui::QuantitySpinBox::valueChanged), - this, &TaskDraftParameters::onAngleChanged); + this, &TaskDraftParameters::onAngleChanged); connect(ui->checkReverse, &QCheckBox::toggled, - this, &TaskDraftParameters::onReversedChanged); + this, &TaskDraftParameters::onReversedChanged); connect(ui->buttonRefSel, &QToolButton::toggled, - this, &TaskDraftParameters::onButtonRefSel); + this, &TaskDraftParameters::onButtonRefSel); connect(ui->buttonPlane, &QToolButton::toggled, - this, &TaskDraftParameters::onButtonPlane); + this, &TaskDraftParameters::onButtonPlane); connect(ui->buttonLine, &QToolButton::toggled, - this, &TaskDraftParameters::onButtonLine); + this, &TaskDraftParameters::onButtonLine); // Create context menu createDeleteAction(ui->listWidgetReferences); connect(deleteAction, &QAction::triggered, this, &TaskDraftParameters::onRefDeleted); connect(ui->listWidgetReferences, &QListWidget::currentItemChanged, - this, &TaskDraftParameters::setSelection); + this, &TaskDraftParameters::setSelection); connect(ui->listWidgetReferences, &QListWidget::itemClicked, - this, &TaskDraftParameters::setSelection); + this, &TaskDraftParameters::setSelection); connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked, - this, &TaskDraftParameters::doubleClicked); + this, &TaskDraftParameters::doubleClicked); + // clang-format on App::DocumentObject* ref = pcDraft->NeutralPlane.getValue(); strings = pcDraft->NeutralPlane.getSubValues(); @@ -110,10 +112,12 @@ TaskDraftParameters::TaskDraftParameters(ViewProviderDressUp *DressUpView, QWidg strings = pcDraft->PullDirection.getSubValues(); ui->lineLine->setText(getRefStr(ref, strings)); - if (strings.size() == 0) + if (strings.size() == 0) { setSelectionMode(refSel); - else + } + else { hideOnError(); + } } void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -130,8 +134,9 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) std::vector planes; App::DocumentObject* selObj {}; getReferencedSelection(pcDraft, msg, selObj, planes); - if(!selObj) + if (!selObj) { return; + } setupTransaction(); pcDraft->NeutralPlane.setValue(selObj, planes); ui->linePlane->setText(getRefStr(selObj, planes)); @@ -141,14 +146,15 @@ void TaskDraftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) getDressUpView()->highlightReferences(true); // hide the draft if there was a computation error hideOnError(); - } + } else if (selectionMode == line) { auto pcDraft = getObject(); std::vector edges; App::DocumentObject* selObj; getReferencedSelection(pcDraft, msg, selObj, edges); - if(!selObj) + if (!selObj) { return; + } setupTransaction(); pcDraft->PullDirection.setValue(selObj, edges); ui->lineLine->setText(getRefStr(selObj, edges)); @@ -177,9 +183,9 @@ void TaskDraftParameters::onButtonPlane(bool checked) hideObject(); selectionMode = plane; Gui::Selection().clearSelection(); - Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), AllowSelection::EDGE | - AllowSelection::FACE | - AllowSelection::PLANAR)); + Gui::Selection().addSelectionGate(new ReferenceSelection( + this->getBase(), + AllowSelection::EDGE | AllowSelection::FACE | AllowSelection::PLANAR)); } } @@ -190,8 +196,8 @@ void TaskDraftParameters::onButtonLine(bool checked) hideObject(); selectionMode = line; Gui::Selection().clearSelection(); - Gui::Selection().addSelectionGate(new ReferenceSelection(this->getBase(), AllowSelection::EDGE | - AllowSelection::PLANAR)); + Gui::Selection().addSelectionGate( + new ReferenceSelection(this->getBase(), AllowSelection::EDGE | AllowSelection::PLANAR)); } } @@ -202,20 +208,22 @@ void TaskDraftParameters::onRefDeleted() void TaskDraftParameters::getPlane(App::DocumentObject*& obj, std::vector& sub) const { - sub = std::vector(1,""); + sub = std::vector(1, ""); QStringList parts = ui->linePlane->text().split(QChar::fromLatin1(':')); obj = getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); - if (parts.size() > 1) + if (parts.size() > 1) { sub[0] = parts[1].toStdString(); + } } void TaskDraftParameters::getLine(App::DocumentObject*& obj, std::vector& sub) const { - sub = std::vector(1,""); + sub = std::vector(1, ""); QStringList parts = ui->lineLine->text().split(QChar::fromLatin1(':')); obj = getObject()->getDocument()->getObject(parts[0].toStdString().c_str()); - if (parts.size() > 1) + if (parts.size() > 1) { sub[0] = parts[1].toStdString(); + } } void TaskDraftParameters::onAngleChanged(double angle) @@ -259,17 +267,17 @@ TaskDraftParameters::~TaskDraftParameters() Gui::Selection().rmvSelectionGate(); } catch (const Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); } } -bool TaskDraftParameters::event(QEvent *e) +bool TaskDraftParameters::event(QEvent* e) { return TaskDressUpParameters::KeyEvent(e); } -void TaskDraftParameters::changeEvent(QEvent *e) +void TaskDraftParameters::changeEvent(QEvent* e) { TaskBox::changeEvent(e); if (e->type() == QEvent::LanguageChange) { @@ -279,9 +287,10 @@ void TaskDraftParameters::changeEvent(QEvent *e) void TaskDraftParameters::apply() { - //Alert user if he created an empty feature - if (ui->listWidgetReferences->count() == 0) + // Alert user if he created an empty feature + if (ui->listWidgetReferences->count() == 0) { Base::Console().Warning(tr("Empty draft created !\n").toStdString().c_str()); + } TaskDressUpParameters::apply(); } @@ -291,10 +300,10 @@ void TaskDraftParameters::apply() // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft *DressUpView) +TaskDlgDraftParameters::TaskDlgDraftParameters(ViewProviderDraft* DressUpView) : TaskDlgDressUpParameters(DressUpView) { - parameter = new TaskDraftParameters(DressUpView); + parameter = new TaskDraftParameters(DressUpView); Content.push_back(parameter); } @@ -322,14 +331,16 @@ bool TaskDlgDraftParameters::accept() draftparameter->getLine(obj, strings); std::string pullDirection = buildLinkSingleSubPythonStr(obj, strings); - FCMD_OBJ_CMD(tobj,"Angle = " << draftparameter->getAngle()); - FCMD_OBJ_CMD(tobj,"Reversed = " << draftparameter->getReversed()); - if(neutralPlane.empty()) + FCMD_OBJ_CMD(tobj, "Angle = " << draftparameter->getAngle()); + FCMD_OBJ_CMD(tobj, "Reversed = " << draftparameter->getReversed()); + if (neutralPlane.empty()) { neutralPlane = "None"; - FCMD_OBJ_CMD(tobj,"NeutralPlane = " << neutralPlane); - if(pullDirection.empty()) + } + FCMD_OBJ_CMD(tobj, "NeutralPlane = " << neutralPlane); + if (pullDirection.empty()) { pullDirection = "None"; - FCMD_OBJ_CMD(tobj,"PullDirection = " << pullDirection); + } + FCMD_OBJ_CMD(tobj, "PullDirection = " << pullDirection); return TaskDlgDressUpParameters::accept(); } diff --git a/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp b/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp index 6c2d4ef97e..4b2ffdc46f 100644 --- a/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskExtrudeParameters.cpp @@ -22,8 +22,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include +#include +#include #endif #include @@ -44,8 +44,10 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskExtrudeParameters */ -TaskExtrudeParameters::TaskExtrudeParameters(ViewProviderExtrude *SketchBasedView, QWidget *parent, - const std::string& pixmapname, const QString& parname) +TaskExtrudeParameters::TaskExtrudeParameters(ViewProviderExtrude* SketchBasedView, + QWidget* parent, + const std::string& pixmapname, + const QString& parname) : TaskSketchBasedParameters(SketchBasedView, parent, pixmapname, parname) , propReferenceAxis(nullptr) , ui(new Ui_TaskPadPocketParameters) @@ -85,15 +87,16 @@ void TaskExtrudeParameters::setupDialog() bool midplane = extrude->Midplane.getValue(); bool reversed = extrude->Reversed.getValue(); - int index = extrude->Type.getValue(); // must extract value here, clear() kills it! - App::DocumentObject* obj = extrude->UpToFace.getValue(); + int index = extrude->Type.getValue(); // must extract value here, clear() kills it! + App::DocumentObject* obj = extrude->UpToFace.getValue(); std::vector subStrings = extrude->UpToFace.getSubValues(); std::string upToFace; int faceId = -1; if (obj && !subStrings.empty()) { upToFace = subStrings.front(); - if (upToFace.compare(0, 4, "Face") == 0) + if (upToFace.compare(0, 4, "Face") == 0) { faceId = std::atoi(&upToFace[4]); + } } // set decimals for the direction edits @@ -152,10 +155,10 @@ void TaskExtrudeParameters::setupDialog() ui->lineFaceName->setProperty("FeatureName", QByteArray(obj->getNameInDocument())); } else if (obj && faceId >= 0) { - ui->lineFaceName->setText(QString::fromLatin1("%1:%2%3") - .arg(QString::fromUtf8(obj->Label.getValue()), - tr("Face"), - QString::number(faceId))); + ui->lineFaceName->setText( + QString::fromLatin1("%1:%2%3").arg(QString::fromUtf8(obj->Label.getValue()), + tr("Face"), + QString::number(faceId))); ui->lineFaceName->setProperty("FeatureName", QByteArray(obj->getNameInDocument())); } else { @@ -181,7 +184,7 @@ void TaskExtrudeParameters::setupDialog() ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); connectSlots(); - + ui->checkBoxAllFaces->setChecked(ui->listWidgetReferences->count() == 0); this->propReferenceAxis = &(extrude->ReferenceAxis); @@ -208,48 +211,50 @@ void TaskExtrudeParameters::connectSlots() { QMetaObject::connectSlotsByName(this); + // clang-format off connect(ui->lengthEdit, qOverload(&Gui::PrefQuantitySpinBox::valueChanged), - this, &TaskExtrudeParameters::onLengthChanged); + this, &TaskExtrudeParameters::onLengthChanged); connect(ui->lengthEdit2, qOverload(&Gui::PrefQuantitySpinBox::valueChanged), - this, &TaskExtrudeParameters::onLength2Changed); + this, &TaskExtrudeParameters::onLength2Changed); connect(ui->offsetEdit, qOverload(&Gui::PrefQuantitySpinBox::valueChanged), - this, &TaskExtrudeParameters::onOffsetChanged); + this, &TaskExtrudeParameters::onOffsetChanged); connect(ui->taperEdit, qOverload(&Gui::PrefQuantitySpinBox::valueChanged), - this, &TaskExtrudeParameters::onTaperChanged); + this, &TaskExtrudeParameters::onTaperChanged); connect(ui->taperEdit2, qOverload(&Gui::PrefQuantitySpinBox::valueChanged), - this, &TaskExtrudeParameters::onTaper2Changed); + this, &TaskExtrudeParameters::onTaper2Changed); connect(ui->directionCB, qOverload(&QComboBox::activated), - this, &TaskExtrudeParameters::onDirectionCBChanged); + this, &TaskExtrudeParameters::onDirectionCBChanged); connect(ui->checkBoxAlongDirection, &QCheckBox::toggled, - this, &TaskExtrudeParameters::onAlongSketchNormalChanged); + this, &TaskExtrudeParameters::onAlongSketchNormalChanged); connect(ui->checkBoxDirection, &QCheckBox::toggled, - this, &TaskExtrudeParameters::onDirectionToggled); + this, &TaskExtrudeParameters::onDirectionToggled); connect(ui->XDirectionEdit, qOverload(&QDoubleSpinBox::valueChanged), - this, &TaskExtrudeParameters::onXDirectionEditChanged); + this, &TaskExtrudeParameters::onXDirectionEditChanged); connect(ui->YDirectionEdit, qOverload(&QDoubleSpinBox::valueChanged), - this, &TaskExtrudeParameters::onYDirectionEditChanged); + this, &TaskExtrudeParameters::onYDirectionEditChanged); connect(ui->ZDirectionEdit, qOverload(&QDoubleSpinBox::valueChanged), - this, &TaskExtrudeParameters::onZDirectionEditChanged); + this, &TaskExtrudeParameters::onZDirectionEditChanged); connect(ui->checkBoxMidplane, &QCheckBox::toggled, - this, &TaskExtrudeParameters::onMidplaneChanged); + this, &TaskExtrudeParameters::onMidplaneChanged); connect(ui->checkBoxReversed, &QCheckBox::toggled, - this, &TaskExtrudeParameters::onReversedChanged); + this, &TaskExtrudeParameters::onReversedChanged); connect(ui->checkBoxAllFaces, &QCheckBox::toggled, - this, &TaskExtrudeParameters::onAllFacesToggled); + this, &TaskExtrudeParameters::onAllFacesToggled); connect(ui->changeMode, qOverload(&QComboBox::currentIndexChanged), - this, &TaskExtrudeParameters::onModeChanged); + this, &TaskExtrudeParameters::onModeChanged); connect(ui->buttonFace, &QToolButton::toggled, - this, &TaskExtrudeParameters::onSelectFaceToggle); + this, &TaskExtrudeParameters::onSelectFaceToggle); connect(ui->buttonShape, &QToolButton::toggled, - this, &TaskExtrudeParameters::onSelectShapeToggle); + this, &TaskExtrudeParameters::onSelectShapeToggle); connect(ui->lineFaceName, &QLineEdit::textEdited, - this, &TaskExtrudeParameters::onFaceName); + this, &TaskExtrudeParameters::onFaceName); connect(ui->checkBoxUpdateView, &QCheckBox::toggled, - this, &TaskExtrudeParameters::onUpdateView); + this, &TaskExtrudeParameters::onUpdateView); connect(ui->buttonShapeFace, &QToolButton::toggled, - this, &TaskExtrudeParameters::onSelectShapeFacesToggle); + this, &TaskExtrudeParameters::onSelectShapeFacesToggle); connect(unselectShapeFaceAction, &QAction::triggered, - this, &TaskExtrudeParameters::onUnselectShapeFacesTrigger); + this, &TaskExtrudeParameters::onUnselectShapeFacesTrigger); + // clang-format on } void TaskExtrudeParameters::onSelectShapeFacesToggle(bool checked) @@ -257,7 +262,8 @@ void TaskExtrudeParameters::onSelectShapeFacesToggle(bool checked) if (checked) { setSelectionMode(SelectShapeFaces); ui->buttonShapeFace->setText(tr("Preview")); - } else { + } + else { setSelectionMode(None); ui->buttonShapeFace->setText(tr("Select faces")); } @@ -270,8 +276,8 @@ void PartDesignGui::TaskExtrudeParameters::onUnselectShapeFacesTrigger() auto extrude = getObject(); - faces.erase(std::remove_if(faces.begin(), faces.end(), [selected](const std::string &face) { - for (auto &item : selected) { + faces.erase(std::remove_if(faces.begin(), faces.end(), [selected](const std::string& face) { + for (auto& item : selected) { if (item->text().toStdString() == face) { return true; } @@ -300,7 +306,8 @@ void TaskExtrudeParameters::setSelectionMode(SelectionMode mode) switch (mode) { case SelectShape: onSelectReference(AllowSelection::WHOLE); - Gui::Selection().addSelectionGate(new SelectionFilterGate("SELECT Part::Feature COUNT 1")); + Gui::Selection().addSelectionGate( + new SelectionFilterGate("SELECT Part::Feature COUNT 1")); break; case SelectFace: onSelectReference(AllowSelection::FACE); @@ -310,7 +317,8 @@ void TaskExtrudeParameters::setSelectionMode(SelectionMode mode) getViewObject()->highlightShapeFaces(getShapeFaces()); break; case SelectReferenceAxis: - onSelectReference(AllowSelection::EDGE | AllowSelection::PLANAR | AllowSelection::CIRCLE); + onSelectReference(AllowSelection::EDGE | AllowSelection::PLANAR + | AllowSelection::CIRCLE); break; default: getViewObject()->highlightShapeFaces({}); @@ -399,10 +407,10 @@ void TaskExtrudeParameters::selectedShapeFace(const Gui::SelectionChanges& msg) auto positionInList = std::find(faces.begin(), faces.end(), subName); - if (positionInList != faces.end()) { //If it's found then it's in the list so we remove it. + if (positionInList != faces.end()) { // If it's found then it's in the list so we remove it. faces.erase(positionInList); } - else { //if it's not found then it's not yet in the list so we add it. + else { // if it's not found then it's not yet in the list so we add it. faces.push_back(subName); } @@ -465,7 +473,6 @@ void TaskExtrudeParameters::clearFaceName() ui->lineFaceName->clear(); ui->lineFaceName->setProperty("FeatureName", QVariant()); ui->lineFaceName->setProperty("FaceName", QVariant()); - } void TaskExtrudeParameters::updateShapeName() @@ -489,7 +496,7 @@ void TaskExtrudeParameters::updateShapeFaces() auto faces = getShapeFaces(); ui->listWidgetReferences->clear(); - for (auto &ref : faces) { + for (auto& ref : faces) { ui->listWidgetReferences->addItem(QString::fromStdString(ref)); } @@ -505,11 +512,12 @@ std::vector PartDesignGui::TaskExtrudeParameters::getShapeFaces() auto extrude = getObject(); auto allRefs = extrude->UpToShape.getSubValues(); - std::copy_if( - allRefs.begin(), allRefs.end(), - std::back_inserter(faces), - [](const std::string& ref) { return boost::starts_with(ref, "Face"); } - ); + std::copy_if(allRefs.begin(), + allRefs.end(), + std::back_inserter(faces), + [](const std::string& ref) { + return boost::starts_with(ref, "Face"); + }); return faces; } @@ -579,25 +587,33 @@ void TaskExtrudeParameters::fillDirectionCombo() // we can have sketches or faces // for sketches just get the sketch normal auto pcFeat = getObject(); - Part::Part2DObject* pcSketch = dynamic_cast(pcFeat->Profile.getValue()); + Part::Part2DObject* pcSketch = + dynamic_cast(pcFeat->Profile.getValue()); // for faces we test if it is verified and if we can get its normal if (!pcSketch) { hasFace = hasProfileFace(pcFeat); } - if (pcSketch) + if (pcSketch) { addAxisToCombo(pcSketch, "N_Axis", tr("Sketch normal")); - else if (hasFace) + } + else if (hasFace) { addAxisToCombo(pcFeat->Profile.getValue(), std::string(), tr("Face normal"), false); + } // add the other entries addAxisToCombo(nullptr, std::string(), tr("Select reference...")); // we start with the sketch normal as proposal for the custom direction - if (pcSketch) + if (pcSketch) { addAxisToCombo(pcSketch, "N_Axis", tr("Custom direction")); - else if (hasFace) - addAxisToCombo(pcFeat->Profile.getValue(), std::string(), tr("Custom direction"), false); + } + else if (hasFace) { + addAxisToCombo(pcFeat->Profile.getValue(), + std::string(), + tr("Custom direction"), + false); + } } // add current link, if not in list @@ -615,8 +631,9 @@ void TaskExtrudeParameters::fillDirectionCombo() if (indexOfCurrent == -1 && ax) { assert(subList.size() <= 1); std::string sub; - if (!subList.empty()) + if (!subList.empty()) { sub = subList[0]; + } addAxisToCombo(ax, sub, getRefStr(ax, subList)); indexOfCurrent = axesInList.size() - 1; // the axis is not the normal, thus enable along direction @@ -630,22 +647,27 @@ void TaskExtrudeParameters::fillDirectionCombo() // highlight either current index or set custom direction auto extrude = getObject(); bool hasCustom = extrude->UseCustomVector.getValue(); - if (indexOfCurrent != -1 && !hasCustom) + if (indexOfCurrent != -1 && !hasCustom) { ui->directionCB->setCurrentIndex(indexOfCurrent); - if (hasCustom) + } + if (hasCustom) { ui->directionCB->setCurrentIndex(DirectionModes::Custom); + } } -void TaskExtrudeParameters::addAxisToCombo(App::DocumentObject* linkObj, std::string linkSubname, - QString itemText, bool hasSketch) +void TaskExtrudeParameters::addAxisToCombo(App::DocumentObject* linkObj, + std::string linkSubname, + QString itemText, + bool hasSketch) { this->ui->directionCB->addItem(itemText); this->axesInList.emplace_back(new App::PropertyLinkSub); App::PropertyLinkSub& lnk = *(axesInList.back()); // if we have a face, we leave the link empty since we cannot // store the face normal as sublink - if (hasSketch) + if (hasSketch) { lnk.setValue(linkObj, std::vector(1, linkSubname)); + } } void TaskExtrudeParameters::setCheckboxes(Mode mode, Type type) @@ -676,7 +698,8 @@ void TaskExtrudeParameters::setCheckboxes(Mode mode, Type type) } else if (mode == Mode::ThroughAll && type == Type::Pocket) { isOffsetEditVisible = true; - isOffsetEditEnabled = false; // offset may have some meaning for through all but it doesn't work + isOffsetEditEnabled = + false; // offset may have some meaning for through all but it doesn't work isMidplaneEnabled = true; isMidplaneVisible = true; isReversedEnabled = !ui->checkBoxMidplane->isChecked(); @@ -695,8 +718,9 @@ void TaskExtrudeParameters::setCheckboxes(Mode mode, Type type) isFaceEditVisible = true; QMetaObject::invokeMethod(ui->lineFaceName, "setFocus", Qt::QueuedConnection); // Go into reference selection mode if no face has been selected yet - if (ui->lineFaceName->property("FeatureName").isNull()) + if (ui->lineFaceName->property("FeatureName").isNull()) { ui->buttonFace->setChecked(true); + } } else if (mode == Mode::ToShape) { isReversedEnabled = true; @@ -751,8 +775,9 @@ void TaskExtrudeParameters::setCheckboxes(Mode mode, Type type) void TaskExtrudeParameters::onDirectionCBChanged(int num) { - if (axesInList.empty()) + if (axesInList.empty()) { return; + } // we use this scheme for 'num' // 0: normal to sketch or face @@ -879,10 +904,12 @@ void TaskExtrudeParameters::setDirectionMode(int index) } // disable AlongSketchNormal when the direction is already normal - if (index == DirectionModes::Normal) + if (index == DirectionModes::Normal) { ui->checkBoxAlongDirection->setEnabled(false); - else + } + else { ui->checkBoxAlongDirection->setEnabled(true); + } // if custom direction is used, show it if (index == DirectionModes::Custom) { @@ -904,7 +931,6 @@ void TaskExtrudeParameters::setDirectionMode(int index) ui->YDirectionEdit->setEnabled(true); ui->ZDirectionEdit->setEnabled(true); } - } void TaskExtrudeParameters::onMidplaneChanged(bool on) @@ -927,22 +953,26 @@ void TaskExtrudeParameters::onReversedChanged(bool on) } } -void TaskExtrudeParameters::getReferenceAxis(App::DocumentObject*& obj, std::vector& sub) const +void TaskExtrudeParameters::getReferenceAxis(App::DocumentObject*& obj, + std::vector& sub) const { - if (axesInList.empty()) + if (axesInList.empty()) { throw Base::RuntimeError("Not initialized!"); + } int num = ui->directionCB->currentIndex(); const App::PropertyLinkSub& lnk = *(axesInList[num]); if (!lnk.getValue()) { - // Note: It is possible that a face of an object is directly padded/pocketed without defining a profile shape + // Note: It is possible that a face of an object is directly padded/pocketed without + // defining a profile shape obj = nullptr; sub.clear(); } else { auto pcDirection = getObject(); - if (!pcDirection->getDocument()->isIn(lnk.getValue())) + if (!pcDirection->getDocument()->isIn(lnk.getValue())) { throw Base::RuntimeError("Object was deleted"); + } obj = lnk.getValue(); sub = lnk.getSubValues(); @@ -955,7 +985,7 @@ void TaskExtrudeParameters::onSelectFaceToggle(const bool checked) handleLineFaceNameNo(); } else { - handleLineFaceNameClick(); // sets placeholder text + handleLineFaceNameClick(); // sets placeholder text setSelectionMode(SelectFace); } } @@ -967,7 +997,8 @@ void PartDesignGui::TaskExtrudeParameters::onSelectShapeToggle(const bool checke ui->lineShapeName->setText({}); ui->lineShapeName->setPlaceholderText(tr("Click on a shape in the model")); - } else { + } + else { setSelectionMode(None); updateShapeName(); } @@ -1008,12 +1039,12 @@ void TaskExtrudeParameters::translateFaceName() int faceId = -1; bool ok = false; if (upToFace.indexOf("Face") == 0) { - faceId = upToFace.remove(0,4).toInt(&ok); + faceId = upToFace.remove(0, 4).toInt(&ok); } if (ok) { - ui->lineFaceName->setText(QString::fromLatin1("%1:%2%3") - .arg(parts[0], tr("Face")).arg(faceId)); + ui->lineFaceName->setText( + QString::fromLatin1("%1:%2%3").arg(parts[0], tr("Face")).arg(faceId)); } else { ui->lineFaceName->setText(parts[0]); @@ -1085,7 +1116,7 @@ QString TaskExtrudeParameters::getFaceName() const return QString::fromLatin1("None"); } -void TaskExtrudeParameters::changeEvent(QEvent *e) +void TaskExtrudeParameters::changeEvent(QEvent* e) { TaskBox::changeEvent(e); if (e->type() == QEvent::LanguageChange) { @@ -1103,16 +1134,18 @@ void TaskExtrudeParameters::changeEvent(QEvent *e) // Save all items QStringList items; - for (int i = 0; i < ui->directionCB->count(); i++) + for (int i = 0; i < ui->directionCB->count(); i++) { items << ui->directionCB->itemText(i); + } // Translate direction items int index = ui->directionCB->currentIndex(); ui->retranslateUi(proxy); // Keep custom items - for (int i = 0; i < ui->directionCB->count(); i++) + for (int i = 0; i < ui->directionCB->count(); i++) { items.pop_front(); + } ui->directionCB->addItems(items); ui->directionCB->setCurrentIndex(index); @@ -1142,8 +1175,9 @@ void TaskExtrudeParameters::applyParameters(QString facename) ui->taperEdit->apply(); ui->taperEdit2->apply(); FCMD_OBJ_CMD(obj, "UseCustomVector = " << (getCustom() ? 1 : 0)); - FCMD_OBJ_CMD(obj, "Direction = (" - << getXDirection() << ", " << getYDirection() << ", " << getZDirection() << ")"); + FCMD_OBJ_CMD(obj, + "Direction = (" << getXDirection() << ", " << getYDirection() << ", " + << getZDirection() << ")"); FCMD_OBJ_CMD(obj, "ReferenceAxis = " << getReferenceAxis()); FCMD_OBJ_CMD(obj, "AlongSketchNormal = " << (getAlongSketchNormal() ? 1 : 0)); FCMD_OBJ_CMD(obj, "Type = " << getMode()); diff --git a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp index ec62505211..889cee6809 100644 --- a/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeaturePick.cpp @@ -24,9 +24,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -54,19 +54,29 @@ using namespace PartDesignGui; using namespace Attacher; -// TODO Do ve should snap here to App:Part or GeoFeatureGroup/DocumentObjectGroup ? (2015-09-04, Fat-Zer) +// TODO Do ve should snap here to App:Part or GeoFeatureGroup/DocumentObjectGroup ? (2015-09-04, +// Fat-Zer) const QString TaskFeaturePick::getFeatureStatusString(const featureStatus st) { switch (st) { - case validFeature: return tr("Valid"); - case invalidShape: return tr("Invalid shape"); - case noWire: return tr("No wire in sketch"); - case isUsed: return tr("Sketch already used by other feature"); - case otherBody: return tr("Belongs to another body"); - case otherPart: return tr("Belongs to another part"); - case notInBody: return tr("Doesn't belong to any body"); - case basePlane: return tr("Base plane"); - case afterTip: return tr("Feature is located after the tip feature"); + case validFeature: + return tr("Valid"); + case invalidShape: + return tr("Invalid shape"); + case noWire: + return tr("No wire in sketch"); + case isUsed: + return tr("Sketch already used by other feature"); + case otherBody: + return tr("Belongs to another body"); + case otherPart: + return tr("Belongs to another part"); + case notInBody: + return tr("Doesn't belong to any body"); + case basePlane: + return tr("Base plane"); + case afterTip: + return tr("Feature is located after the tip feature"); } return QString(); @@ -76,15 +86,15 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, const std::vector& status, bool singleFeatureSelect, QWidget* parent) - : TaskBox(Gui::BitmapFactory().pixmap("edit-select-all"), - tr("Select attachment"), true, parent) - , ui(new Ui_TaskFeaturePick) - , doSelection(false) + : TaskBox(Gui::BitmapFactory().pixmap("edit-select-all"), tr("Select attachment"), true, parent) + , ui(new Ui_TaskFeaturePick) + , doSelection(false) { proxy = new QWidget(this); ui->setupUi(proxy); + // clang-format off connect(ui->checkUsed, &QCheckBox::toggled, this, &TaskFeaturePick::onUpdate); connect(ui->checkOtherBody, &QCheckBox::toggled, this, &TaskFeaturePick::onUpdate); connect(ui->checkOtherPart, &QCheckBox::toggled, this, &TaskFeaturePick::onUpdate); @@ -93,16 +103,21 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, connect(ui->radioXRef, &QRadioButton::toggled, this, &TaskFeaturePick::onUpdate); connect(ui->listWidget, &QListWidget::itemSelectionChanged, this, &TaskFeaturePick::onItemSelectionChanged); connect(ui->listWidget, &QListWidget::itemDoubleClicked, this, &TaskFeaturePick::onDoubleClick); + // clang-format on if (!singleFeatureSelect) { ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection); } - enum { axisBit=0, planeBit = 1}; + enum + { + axisBit = 0, + planeBit = 1 + }; // NOTE: generally there shouldn't be more then one origin - std::map > originVisStatus; + std::map> originVisStatus; auto statusIt = status.cbegin(); auto objIt = objects.begin(); @@ -111,11 +126,8 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, bool attached = false; for (; statusIt != status.end(); ++statusIt, ++objIt) { QListWidgetItem* item = new QListWidgetItem( - QString::fromLatin1("%1 (%2)") - .arg(QString::fromUtf8((*objIt)->Label.getValue()), - getFeatureStatusString(*statusIt) - ) - ); + QString::fromLatin1("%1 (%2)").arg(QString::fromUtf8((*objIt)->Label.getValue()), + getFeatureStatusString(*statusIt))); item->setData(Qt::UserRole, QString::fromLatin1((*objIt)->getNameInDocument())); ui->listWidget->addItem(item); @@ -126,29 +138,30 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, attachDocument(Gui::Application::Instance->getDocument(pDoc)); } - //check if we need to set any origin in temporary visibility mode - if (*statusIt != invalidShape && (*objIt)->isDerivedFrom ( App::OriginFeature::getClassTypeId () )) { - App::Origin *origin = static_cast (*objIt)->getOrigin (); + // check if we need to set any origin in temporary visibility mode + if (*statusIt != invalidShape + && (*objIt)->isDerivedFrom(App::OriginFeature::getClassTypeId())) { + App::Origin* origin = static_cast(*objIt)->getOrigin(); if (origin) { - if ((*objIt)->isDerivedFrom (App::Plane::getClassTypeId())) { - originVisStatus[ origin ].set (planeBit, true); + if ((*objIt)->isDerivedFrom(App::Plane::getClassTypeId())) { + originVisStatus[origin].set(planeBit, true); } - else if ( (*objIt)->isDerivedFrom (App::Line::getClassTypeId())) { - originVisStatus[ origin ].set (axisBit, true); + else if ((*objIt)->isDerivedFrom(App::Line::getClassTypeId())) { + originVisStatus[origin].set(axisBit, true); } } } } // Setup the origin's temporary visibility - for (const auto & originPair: originVisStatus) { - const auto &origin = originPair.first; + for (const auto& originPair : originVisStatus) { + const auto& origin = originPair.first; - Gui::ViewProviderOrigin* vpo = static_cast ( - Gui::Application::Instance->getViewProvider ( origin ) ); + Gui::ViewProviderOrigin* vpo = static_cast( + Gui::Application::Instance->getViewProvider(origin)); if (vpo) { - vpo->setTemporaryVisibility( originVisStatus[origin][axisBit], - originVisStatus[origin][planeBit]); + vpo->setTemporaryVisibility(originVisStatus[origin][axisBit], + originVisStatus[origin][planeBit]); origins.push_back(vpo); } } @@ -162,8 +175,9 @@ TaskFeaturePick::TaskFeaturePick(std::vector& objects, TaskFeaturePick::~TaskFeaturePick() { - for(Gui::ViewProviderOrigin* vpo : origins) + for (Gui::ViewProviderOrigin* vpo : origins) { vpo->resetTemporaryVisibility(); + } } void TaskFeaturePick::updateList() @@ -174,15 +188,33 @@ void TaskFeaturePick::updateList() QListWidgetItem* item = ui->listWidget->item(index); switch (status) { - case validFeature: item->setHidden(false); break; - case invalidShape: item->setHidden(true); break; - case isUsed: item->setHidden(!ui->checkUsed->isChecked()); break; - case noWire: item->setHidden(true); break; - case otherBody: item->setHidden(!ui->checkOtherBody->isChecked()); break; - case otherPart: item->setHidden(!ui->checkOtherPart->isChecked()); break; - case notInBody: item->setHidden(!ui->checkOtherPart->isChecked()); break; - case basePlane: item->setHidden(false); break; - case afterTip: item->setHidden(true); break; + case validFeature: + item->setHidden(false); + break; + case invalidShape: + item->setHidden(true); + break; + case isUsed: + item->setHidden(!ui->checkUsed->isChecked()); + break; + case noWire: + item->setHidden(true); + break; + case otherBody: + item->setHidden(!ui->checkOtherBody->isChecked()); + break; + case otherPart: + item->setHidden(!ui->checkOtherPart->isChecked()); + break; + case notInBody: + item->setHidden(!ui->checkOtherPart->isChecked()); + break; + case basePlane: + item->setHidden(false); + break; + case afterTip: + item->setHidden(true); + break; } index++; @@ -192,8 +224,9 @@ void TaskFeaturePick::updateList() void TaskFeaturePick::onUpdate(bool) { bool enable = false; - if (ui->checkOtherBody->isChecked() || ui->checkOtherPart->isChecked()) + if (ui->checkOtherBody->isChecked() || ui->checkOtherPart->isChecked()) { enable = true; + } ui->radioDependent->setEnabled(enable); ui->radioIndependent->setEnabled(enable); @@ -209,8 +242,9 @@ std::vector TaskFeaturePick::getFeatures() while (i.hasNext()) { auto item = i.next(); - if (item->isHidden()) + if (item->isHidden()) { continue; + } QString t = item->data(Qt::UserRole).toString(); features.push_back(t); @@ -233,8 +267,9 @@ std::vector TaskFeaturePick::buildFeatures() std::vector result; try { auto activeBody = PartDesignGui::getBody(false); - if (!activeBody) + if (!activeBody) { return result; + } auto activePart = PartDesignGui::getPartFor(activeBody, false); @@ -243,9 +278,11 @@ std::vector TaskFeaturePick::buildFeatures() if (item->isSelected() && !item->isHidden()) { QString t = item->data(Qt::UserRole).toString(); - auto obj = App::GetApplication().getDocument(documentName.c_str())->getObject(t.toLatin1().data()); + auto obj = App::GetApplication() + .getDocument(documentName.c_str()) + ->getObject(t.toLatin1().data()); - //build the dependent copy or reference if wanted by the user + // build the dependent copy or reference if wanted by the user if (status == otherBody || status == otherPart || status == notInBody) { if (!ui->radioXRef->isChecked()) { auto copy = makeCopy(obj, "", ui->radioIndependent->isChecked()); @@ -255,16 +292,20 @@ std::vector TaskFeaturePick::buildFeatures() } else if (status == otherPart) { auto oBody = PartDesignGui::getBodyFor(obj, false); - if (!oBody) + if (!oBody) { activePart->addObject(copy); - else + } + else { activeBody->addObject(copy); + } } else if (status == notInBody) { activeBody->addObject(copy); - // doesn't supposed to get here anything but sketch but to be on the safe side better to check + // doesn't supposed to get here anything but sketch but to be on the + // safe side better to check if (copy->isDerivedFrom()) { - Sketcher::SketchObject *sketch = static_cast(copy); + Sketcher::SketchObject* sketch = + static_cast(copy); PartDesignGui::fixSketchSupport(sketch); } } @@ -277,7 +318,6 @@ std::vector TaskFeaturePick::buildFeatures() else { result.push_back(obj); } - } index++; @@ -299,37 +339,41 @@ std::vector TaskFeaturePick::buildFeatures() return result; } -App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::string sub, bool independent) { +App::DocumentObject* +TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::string sub, bool independent) +{ App::DocumentObject* copy = nullptr; // Check for null to avoid segfault - if (!obj) + if (!obj) { return copy; - if( independent && - (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) || - obj->isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId()))) { + } + if (independent + && (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) + || obj->isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId()))) { - //we do know that the created instance is a document object, as obj is one. But we do not know which - //exact type - auto name = std::string("Copy") + std::string(obj->getNameInDocument()); - copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), name.c_str()); + // we do know that the created instance is a document object, as obj is one. But we do not + // know which exact type + auto name = std::string("Copy") + std::string(obj->getNameInDocument()); + copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), + name.c_str()); - //copy over all properties + // copy over all properties std::vector props; std::vector cprops; obj->getPropertyList(props); copy->getPropertyList(cprops); auto it = cprops.begin(); - for( App::Property* prop : props ) { + for (App::Property* prop : props) { - //independent copies don't have links and are not attached - if(independent && ( - prop->isDerivedFrom() || - prop->isDerivedFrom() || - prop->isDerivedFrom() || - prop->isDerivedFrom()|| - ( prop->getGroup() && strcmp(prop->getGroup(),"Attachment")==0) )) { + // independent copies don't have links and are not attached + if (independent + && (prop->isDerivedFrom() + || prop->isDerivedFrom() + || prop->isDerivedFrom() + || prop->isDerivedFrom() + || (prop->getGroup() && strcmp(prop->getGroup(), "Attachment") == 0))) { ++it; continue; @@ -337,84 +381,96 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st App::Property* cprop = *it++; - if( prop->getName() && strcmp(prop->getName(), "Label") == 0 ) { + if (prop->getName() && strcmp(prop->getName(), "Label") == 0) { static_cast(cprop)->setValue(name.c_str()); continue; } cprop->Paste(*prop); - //we are a independent copy, therefore no external geometry was copied. WE therefore can delete all - //constraints - if(obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) + // we are a independent copy, therefore no external geometry was copied. WE therefore + // can delete all constraints + if (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) { static_cast(copy)->delConstraintsToExternal(); + } } } else { std::string name; - if(!independent) + if (!independent) { name = std::string("Reference"); - else + } + else { name = std::string("Copy"); + } name += std::string(obj->getNameInDocument()); std::string entity; - if(!sub.empty()) + if (!sub.empty()) { entity = sub; + } Part::PropertyPartShape* shapeProp = nullptr; // TODO Replace it with commands (2015-09-11, Fat-Zer) - if(obj->isDerivedFrom(Part::Datum::getClassTypeId())) { - copy = App::GetApplication().getActiveDocument()->addObject( - obj->getTypeId().getName(), name.c_str() ); + if (obj->isDerivedFrom(Part::Datum::getClassTypeId())) { + copy = App::GetApplication().getActiveDocument()->addObject(obj->getTypeId().getName(), + name.c_str()); assert(copy->isDerivedFrom(Part::Datum::getClassTypeId())); - //we need to reference the individual datums and make again datums. This is important as - //datum adjust their size dependent on the part size, hence simply copying the shape is - //not enough + // we need to reference the individual datums and make again datums. This is important + // as datum adjust their size dependent on the part size, hence simply copying the shape + // is not enough long int mode = mmDeactivated; - Part::Datum *datumCopy = static_cast(copy); + Part::Datum* datumCopy = static_cast(copy); - if(obj->is()) { + if (obj->is()) { mode = mm0Vertex; } - else if(obj->is()) { + else if (obj->is()) { mode = mm1TwoPoints; } - else if(obj->is()) { + else if (obj->is()) { mode = mmFlatFace; } - else + else { return copy; + } - // TODO Recheck this. This looks strange in case of independent copy (2015-10-31, Fat-Zer) - if(!independent) { + // TODO Recheck this. This looks strange in case of independent copy (2015-10-31, + // Fat-Zer) + if (!independent) { datumCopy->AttachmentSupport.setValue(obj, entity.c_str()); datumCopy->MapMode.setValue(mode); } - else if(!entity.empty()) { - datumCopy->Shape.setValue(static_cast(obj)->Shape.getShape().getSubShape(entity.c_str())); - } else { + else if (!entity.empty()) { + datumCopy->Shape.setValue( + static_cast(obj)->Shape.getShape().getSubShape(entity.c_str())); + } + else { datumCopy->Shape.setValue(static_cast(obj)->Shape.getValue()); } } - else if(obj->is() || - obj->isDerivedFrom(Part::Feature::getClassTypeId())) { + else if (obj->is() + || obj->isDerivedFrom(Part::Feature::getClassTypeId())) { - copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str()); + copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", + name.c_str()); - if(!independent) + if (!independent) { static_cast(copy)->Support.setValue(obj, entity.c_str()); - else + } + else { shapeProp = &static_cast(copy)->Shape; + } } - else if(obj->isDerivedFrom(App::Plane::getClassTypeId()) || - obj->isDerivedFrom(App::Line::getClassTypeId())) { + else if (obj->isDerivedFrom(App::Plane::getClassTypeId()) + || obj->isDerivedFrom(App::Line::getClassTypeId())) { - copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str()); + copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", + name.c_str()); if (!independent) { static_cast(copy)->Support.setValue(obj, entity.c_str()); @@ -423,16 +479,20 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st App::GeoFeature* geo = static_cast(obj); std::vector subvalues; subvalues.push_back(entity); - Part::TopoShape shape = PartDesign::ShapeBinder::buildShapeFromReferences(geo, subvalues); + Part::TopoShape shape = + PartDesign::ShapeBinder::buildShapeFromReferences(geo, subvalues); static_cast(copy)->Shape.setValue(shape); } } if (independent && shapeProp) { - if (entity.empty()) + if (entity.empty()) { shapeProp->setValue(static_cast(obj)->Shape.getValue()); - else - shapeProp->setValue(static_cast(obj)->Shape.getShape().getSubShape(entity.c_str())); + } + else { + shapeProp->setValue( + static_cast(obj)->Shape.getShape().getSubShape(entity.c_str())); + } } } @@ -441,27 +501,34 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st bool TaskFeaturePick::isSingleSelectionEnabled() const { - ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")-> - GetGroup("Preferences")->GetGroup("Selection"); + ParameterGrp::handle hGrp = App::GetApplication() + .GetUserParameter() + .GetGroup("BaseApp") + ->GetGroup("Preferences") + ->GetGroup("Selection"); return hGrp->GetBool("singleClickFeatureSelect", true); } void TaskFeaturePick::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (doSelection) + if (doSelection) { return; + } doSelection = true; ui->listWidget->clearSelection(); - for (Gui::SelectionSingleton::SelObj obj : Gui::Selection().getSelection()) { + for (Gui::SelectionSingleton::SelObj obj : Gui::Selection().getSelection()) { for (int row = 0; row < ui->listWidget->count(); row++) { - QListWidgetItem *item = ui->listWidget->item(row); + QListWidgetItem* item = ui->listWidget->item(row); QString t = item->data(Qt::UserRole).toString(); - if (t.compare(QString::fromLatin1(obj.FeatName))==0) { + if (t.compare(QString::fromLatin1(obj.FeatName)) == 0) { item->setSelected(true); if (msg.Type == Gui::SelectionChanges::AddSelection) { if (isSingleSelectionEnabled()) { - QMetaObject::invokeMethod(qobject_cast(&Gui::Control()), "accept", Qt::QueuedConnection); + QMetaObject::invokeMethod( + qobject_cast(&Gui::Control()), + "accept", + Qt::QueuedConnection); } } } @@ -472,13 +539,14 @@ void TaskFeaturePick::onSelectionChanged(const Gui::SelectionChanges& msg) void TaskFeaturePick::onItemSelectionChanged() { - if (doSelection) + if (doSelection) { return; + } doSelection = true; ui->listWidget->blockSignals(true); Gui::Selection().clearSelection(); for (int row = 0; row < ui->listWidget->count(); row++) { - QListWidgetItem *item = ui->listWidget->item(row); + QListWidgetItem* item = ui->listWidget->item(row); QString t = item->data(Qt::UserRole).toString(); if (item->isSelected()) { Gui::Selection().addSelection(documentName.c_str(), t.toLatin1()); @@ -488,16 +556,19 @@ void TaskFeaturePick::onItemSelectionChanged() doSelection = false; } -void TaskFeaturePick::onDoubleClick(QListWidgetItem *item) +void TaskFeaturePick::onDoubleClick(QListWidgetItem* item) { - if (doSelection) + if (doSelection) { return; + } doSelection = true; QString t = item->data(Qt::UserRole).toString(); Gui::Selection().addSelection(documentName.c_str(), t.toLatin1()); doSelection = false; - QMetaObject::invokeMethod(qobject_cast(&Gui::Control()), "accept", Qt::QueuedConnection); + QMetaObject::invokeMethod(qobject_cast(&Gui::Control()), + "accept", + Qt::QueuedConnection); } void TaskFeaturePick::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) @@ -535,15 +606,16 @@ void TaskFeaturePick::showExternal(bool val) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFeaturePick::TaskDlgFeaturePick( std::vector &objects, - const std::vector &status, - std::function)> afunc, - std::function)> wfunc, - bool singleFeatureSelect, - std::function abortfunc /* = NULL */ ) - : TaskDialog(), accepted(false) +TaskDlgFeaturePick::TaskDlgFeaturePick(std::vector& objects, + const std::vector& status, + std::function)> afunc, + std::function)> wfunc, + bool singleFeatureSelect, + std::function abortfunc /* = NULL */) + : TaskDialog() + , accepted(false) { - pick = new TaskFeaturePick(objects, status, singleFeatureSelect); + pick = new TaskFeaturePick(objects, status, singleFeatureSelect); Content.push_back(pick); acceptFunction = afunc; @@ -553,11 +625,16 @@ TaskDlgFeaturePick::TaskDlgFeaturePick( std::vector &objec TaskDlgFeaturePick::~TaskDlgFeaturePick() { - //do the work now as before in accept() the dialog is still open, hence the work - //function could not open another dialog + // do the work now as before in accept() the dialog is still open, hence the work + // function could not open another dialog if (accepted) { - try { workFunction(pick->buildFeatures()); } catch (...) {} - } else if (abortFunction) { + try { + workFunction(pick->buildFeatures()); + } + catch (...) { + } + } + else if (abortFunction) { // Get rid of the TaskFeaturePick before the TaskDialog dtor does. The // TaskFeaturePick holds pointers to things (ie any implicitly created @@ -567,7 +644,11 @@ TaskDlgFeaturePick::~TaskDlgFeaturePick() } Content.clear(); - try { abortFunction(); } catch (...) {} + try { + abortFunction(); + } + catch (...) { + } } } @@ -575,14 +656,10 @@ TaskDlgFeaturePick::~TaskDlgFeaturePick() void TaskDlgFeaturePick::open() -{ - -} +{} void TaskDlgFeaturePick::clicked(int) -{ - -} +{} bool TaskDlgFeaturePick::accept() { @@ -602,5 +679,4 @@ void TaskDlgFeaturePick::showExternal(bool val) } - #include "moc_TaskFeaturePick.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp b/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp index 85cfb04b99..8fa4d7ee6f 100644 --- a/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFilletParameters.cpp @@ -24,9 +24,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -45,7 +45,7 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskFilletParameters */ -TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWidget *parent) +TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp* DressUpView, QWidget* parent) : TaskDressUpParameters(DressUpView, true, true, parent) , ui(new Ui_TaskFilletParameters) { @@ -68,12 +68,13 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi ui->filletRadius->bind(pcFillet->Radius); QMetaObject::invokeMethod(ui->filletRadius, "setFocus", Qt::QueuedConnection); std::vector strings = pcFillet->Base.getSubValues(); - for (const auto & string : strings) { + for (const auto& string : strings) { ui->listWidgetReferences->addItem(QString::fromStdString(string)); } QMetaObject::connectSlotsByName(this); + // clang-format off connect(ui->filletRadius, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &TaskFilletParameters::onLengthChanged); connect(ui->buttonRefSel, &QToolButton::toggled, @@ -94,11 +95,14 @@ TaskFilletParameters::TaskFilletParameters(ViewProviderDressUp *DressUpView, QWi this, &TaskFilletParameters::setSelection); connect(ui->listWidgetReferences, &QListWidget::itemDoubleClicked, this, &TaskFilletParameters::doubleClicked); + // clang-format on - if (strings.empty()) + if (strings.empty()) { setSelectionMode(refSel); - else + } + else { hideOnError(); + } } void TaskFilletParameters::onSelectionChanged(const Gui::SelectionChanges& msg) @@ -167,17 +171,17 @@ TaskFilletParameters::~TaskFilletParameters() Gui::Selection().rmvSelectionGate(); } catch (const Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); } } -bool TaskFilletParameters::event(QEvent *e) +bool TaskFilletParameters::event(QEvent* e) { return TaskDressUpParameters::KeyEvent(e); } -void TaskFilletParameters::changeEvent(QEvent *e) +void TaskFilletParameters::changeEvent(QEvent* e) { TaskBox::changeEvent(e); if (e->type() == QEvent::LanguageChange) { @@ -201,10 +205,10 @@ void TaskFilletParameters::apply() // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgFilletParameters::TaskDlgFilletParameters(ViewProviderFillet *DressUpView) +TaskDlgFilletParameters::TaskDlgFilletParameters(ViewProviderFillet* DressUpView) : TaskDlgDressUpParameters(DressUpView) { - parameter = new TaskFilletParameters(DressUpView); + parameter = new TaskFilletParameters(DressUpView); Content.push_back(parameter); } diff --git a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp index 5a4df16aac..75d8b2c1a6 100644 --- a/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHelixParameters.cpp @@ -48,8 +48,12 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskHelixParameters */ -TaskHelixParameters::TaskHelixParameters(PartDesignGui::ViewProviderHelix* HelixView, QWidget* parent) - : TaskSketchBasedParameters(HelixView, parent, "PartDesign_AdditiveHelix", tr("Helix parameters")) +TaskHelixParameters::TaskHelixParameters(PartDesignGui::ViewProviderHelix* HelixView, + QWidget* parent) + : TaskSketchBasedParameters(HelixView, + parent, + "PartDesign_AdditiveHelix", + tr("Helix parameters")) , ui(new Ui_TaskHelixParameters) { // we need a separate container widget to add all controls to @@ -135,38 +139,41 @@ void TaskHelixParameters::connectSlots() { QMetaObject::connectSlotsByName(this); - connect(ui->pitch, qOverload(&QuantitySpinBox::valueChanged), this, - &TaskHelixParameters::onPitchChanged); - connect(ui->height, qOverload(&QuantitySpinBox::valueChanged), this, - &TaskHelixParameters::onHeightChanged); - connect(ui->turns, qOverload(&QuantitySpinBox::valueChanged), this, - &TaskHelixParameters::onTurnsChanged); - connect(ui->coneAngle, qOverload(&QuantitySpinBox::valueChanged), this, - &TaskHelixParameters::onAngleChanged); - connect(ui->growth, qOverload(&QuantitySpinBox::valueChanged), this, - &TaskHelixParameters::onGrowthChanged); - connect(ui->axis, qOverload(&QComboBox::activated), this, - &TaskHelixParameters::onAxisChanged); - connect(ui->checkBoxLeftHanded, &QCheckBox::toggled, this, - &TaskHelixParameters::onLeftHandedChanged); - connect(ui->checkBoxReversed, &QCheckBox::toggled, this, - &TaskHelixParameters::onReversedChanged); - connect(ui->checkBoxUpdateView, &QCheckBox::toggled, this, - &TaskHelixParameters::onUpdateView); - connect(ui->inputMode, qOverload(&QComboBox::activated), this, - &TaskHelixParameters::onModeChanged); - connect(ui->checkBoxOutside, &QCheckBox::toggled, this, - &TaskHelixParameters::onOutsideChanged); + // clang-format off + connect(ui->pitch, qOverload(&QuantitySpinBox::valueChanged), + this, &TaskHelixParameters::onPitchChanged); + connect(ui->height, qOverload(&QuantitySpinBox::valueChanged), + this, &TaskHelixParameters::onHeightChanged); + connect(ui->turns, qOverload(&QuantitySpinBox::valueChanged), + this, &TaskHelixParameters::onTurnsChanged); + connect(ui->coneAngle, qOverload(&QuantitySpinBox::valueChanged), + this, &TaskHelixParameters::onAngleChanged); + connect(ui->growth, qOverload(&QuantitySpinBox::valueChanged), + this, &TaskHelixParameters::onGrowthChanged); + connect(ui->axis, qOverload(&QComboBox::activated), + this, &TaskHelixParameters::onAxisChanged); + connect(ui->checkBoxLeftHanded, &QCheckBox::toggled, + this, &TaskHelixParameters::onLeftHandedChanged); + connect(ui->checkBoxReversed, &QCheckBox::toggled, + this, &TaskHelixParameters::onReversedChanged); + connect(ui->checkBoxUpdateView, &QCheckBox::toggled, + this, &TaskHelixParameters::onUpdateView); + connect(ui->inputMode, qOverload(&QComboBox::activated), + this, &TaskHelixParameters::onModeChanged); + connect(ui->checkBoxOutside, &QCheckBox::toggled, + this, &TaskHelixParameters::onOutsideChanged); + // clang-format on } void TaskHelixParameters::showCoordinateAxes() { - //show the parts coordinate system axis for selection + // show the parts coordinate system axis for selection if (PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject())) { try { App::Origin* origin = body->getOrigin(); ViewProviderOrigin* vpOrigin; - vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin = static_cast( + Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, false); } catch (const Base::Exception& ex) { @@ -179,27 +186,29 @@ void TaskHelixParameters::fillAxisCombo(bool forceRefill) { Base::StateLocker lock(getUpdateBlockRef(), true); - if (axesInList.empty()) - forceRefill = true;//not filled yet, full refill + if (axesInList.empty()) { + forceRefill = true; // not filled yet, full refill + } if (forceRefill) { ui->axis->clear(); this->axesInList.clear(); - //add sketch axes + // add sketch axes addSketchAxes(); - //add part axes + // add part axes addPartAxes(); - //add "Select reference" + // add "Select reference" addAxisToCombo(nullptr, std::string(), tr("Select reference...")); } - //add current link, if not in list and highlight it + // add current link, if not in list and highlight it int indexOfCurrent = addCurrentLink(); - if (indexOfCurrent != -1) + if (indexOfCurrent != -1) { ui->axis->setCurrentIndex(indexOfCurrent); + } } void TaskHelixParameters::addSketchAxes() @@ -250,8 +259,9 @@ int TaskHelixParameters::addCurrentLink() if (indexOfCurrent == -1 && ax) { assert(subList.size() <= 1); std::string sub; - if (!subList.empty()) + if (!subList.empty()) { sub = subList[0]; + } addAxisToCombo(ax, sub, getRefStr(ax, subList)); indexOfCurrent = axesInList.size() - 1; } @@ -259,7 +269,9 @@ int TaskHelixParameters::addCurrentLink() return indexOfCurrent; } -void TaskHelixParameters::addAxisToCombo(App::DocumentObject* linkObj, std::string linkSubname, QString itemText) +void TaskHelixParameters::addAxisToCombo(App::DocumentObject* linkObj, + std::string linkSubname, + QString itemText) { this->ui->axis->addItem(itemText); this->axesInList.emplace_back(new App::PropertyLinkSub); @@ -302,8 +314,9 @@ void TaskHelixParameters::adaptVisibilityToMode() bool isGrowthVisible = false; auto helix = getObject(); - if (helix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) + if (helix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) { isOutsideVisible = true; + } HelixMode mode = static_cast(propMode->getValue()); if (mode == HelixMode::pitch_height_angle) { @@ -351,7 +364,8 @@ void TaskHelixParameters::adaptVisibilityToMode() void TaskHelixParameters::assignToolTipsFromPropertyDocs() { auto helix = getObject(); - const char* propCategory = "App::Property"; // cf. https://tracker.freecad.org/view.php?id=0002524 + const char* propCategory = + "App::Property"; // cf. https://tracker.freecad.org/view.php?id=0002524 QString toolTip; // Beware that "Axis" in the GUI actually represents the property "ReferenceAxis"! @@ -458,26 +472,26 @@ void TaskHelixParameters::onAxisChanged(int num) { auto helix = getObject(); - if (axesInList.empty()) + if (axesInList.empty()) { return; + } App::DocumentObject* oldRefAxis = propReferenceAxis->getValue(); std::vector oldSubRefAxis = propReferenceAxis->getSubValues(); std::string oldRefName; - if (!oldSubRefAxis.empty()) + if (!oldSubRefAxis.empty()) { oldRefName = oldSubRefAxis.front(); + } App::PropertyLinkSub& lnk = *(axesInList[num]); if (!lnk.getValue()) { // enter reference selection mode // assure the sketch is visible - if (auto sketch = dynamic_cast(helix->Profile.getValue())) { + if (auto sketch = dynamic_cast(helix->Profile.getValue())) { Gui::cmdAppObjectShow(sketch); } - TaskSketchBasedParameters::onSelectReference( - AllowSelection::EDGE | - AllowSelection::PLANAR | - AllowSelection::CIRCLE); + TaskSketchBasedParameters::onSelectReference(AllowSelection::EDGE | AllowSelection::PLANAR + | AllowSelection::CIRCLE); return; } else { @@ -495,12 +509,12 @@ void TaskHelixParameters::onAxisChanged(int num) App::DocumentObject* newRefAxis = propReferenceAxis->getValue(); const std::vector& newSubRefAxis = propReferenceAxis->getSubValues(); std::string newRefName; - if (!newSubRefAxis.empty()) + if (!newSubRefAxis.empty()) { newRefName = newSubRefAxis.front(); + } - if (oldRefAxis != newRefAxis || - oldSubRefAxis.size() != newSubRefAxis.size() || - oldRefName != newRefName) { + if (oldRefAxis != newRefAxis || oldSubRefAxis.size() != newSubRefAxis.size() + || oldRefName != newRefName) { bool reversed = propReversed->getValue(); if (reversed != propReversed->getValue()) { propReversed->setValue(reversed); @@ -563,20 +577,20 @@ void TaskHelixParameters::onOutsideChanged(bool on) TaskHelixParameters::~TaskHelixParameters() { try { - //hide the parts coordinate system axis for selection + // hide the parts coordinate system axis for selection auto obj = getObject(); PartDesign::Body* body = obj ? PartDesign::Body::findBodyOf(obj) : nullptr; if (body) { App::Origin* origin = body->getOrigin(); ViewProviderOrigin* vpOrigin {}; - vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin = static_cast( + Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); } } catch (const Base::Exception& ex) { ex.ReportException(); } - } void TaskHelixParameters::changeEvent(QEvent* e) @@ -593,13 +607,15 @@ void TaskHelixParameters::changeEvent(QEvent* e) fillAxisCombo(true); // restore the indexes - if (axis < ui->axis->count()) + if (axis < ui->axis->count()) { ui->axis->setCurrentIndex(axis); + } ui->inputMode->setCurrentIndex(mode); } } -void TaskHelixParameters::getReferenceAxis(App::DocumentObject*& obj, std::vector& sub) const +void TaskHelixParameters::getReferenceAxis(App::DocumentObject*& obj, + std::vector& sub) const { if (axesInList.empty()) { throw Base::RuntimeError("Not initialized!"); @@ -608,7 +624,8 @@ void TaskHelixParameters::getReferenceAxis(App::DocumentObject*& obj, std::vecto int num = ui->axis->currentIndex(); const App::PropertyLinkSub& lnk = *(axesInList.at(num)); if (!lnk.getValue()) { - throw Base::RuntimeError("Still in reference selection mode; reference wasn't selected yet"); + throw Base::RuntimeError( + "Still in reference selection mode; reference wasn't selected yet"); } else { auto revolution = getObject(); @@ -623,16 +640,20 @@ void TaskHelixParameters::getReferenceAxis(App::DocumentObject*& obj, std::vecto bool TaskHelixParameters::showPreview(PartDesign::Helix* helix) { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/PartDesign"); - if ((hGrp->GetBool("SubractiveHelixPreview", true) && helix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) || - (hGrp->GetBool("AdditiveHelixPreview", false) && helix->getAddSubType() == PartDesign::FeatureAddSub::Additive)) { + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/PartDesign"); + if ((hGrp->GetBool("SubractiveHelixPreview", true) + && helix->getAddSubType() == PartDesign::FeatureAddSub::Subtractive) + || (hGrp->GetBool("AdditiveHelixPreview", false) + && helix->getAddSubType() == PartDesign::FeatureAddSub::Additive)) { return true; } return false; } -void TaskHelixParameters::startReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) +void TaskHelixParameters::startReferenceSelection(App::DocumentObject* profile, + App::DocumentObject* base) { if (auto helix = getObject()) { if (helix && showPreview(helix)) { @@ -647,7 +668,8 @@ void TaskHelixParameters::startReferenceSelection(App::DocumentObject* profile, } } -void TaskHelixParameters::finishReferenceSelection(App::DocumentObject* profile, App::DocumentObject* base) +void TaskHelixParameters::finishReferenceSelection(App::DocumentObject* profile, + App::DocumentObject* base) { if (auto helix = getObject()) { if (helix && showPreview(helix)) { diff --git a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp index d68ea41a62..9661c1424c 100644 --- a/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskHoleParameters.cpp @@ -43,7 +43,7 @@ namespace sp = std::placeholders; // See Hole::HoleCutType_ISOmetric_Enums // and Hole::HoleCutType_ISOmetricfine_Enums -#if 0 // needed for Qt's lupdate utility +#if 0 // needed for Qt's lupdate utility qApp->translate("PartDesignGui::TaskHoleParameters", "Counterbore"); qApp->translate("PartDesignGui::TaskHoleParameters", "Countersink"); qApp->translate("PartDesignGui::TaskHoleParameters", "Counterdrill"); @@ -95,12 +95,15 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare ui->Diameter->setMinimum(pcHole->Diameter.getMinimum()); ui->Diameter->setValue(pcHole->Diameter.getValue()); // Diameter is only enabled if ThreadType is None - if (pcHole->ThreadType.getValue() != 0L) + if (pcHole->ThreadType.getValue() != 0L) { ui->Diameter->setEnabled(false); - if (pcHole->ThreadDirection.getValue() == 0L) + } + if (pcHole->ThreadDirection.getValue() == 0L) { ui->directionRightHand->setChecked(true); - else + } + else { ui->directionLeftHand->setChecked(true); + } // ThreadDirection is only sensible if there is a thread ui->directionRightHand->setEnabled(pcHole->Threaded.getValue()); ui->directionLeftHand->setEnabled(pcHole->Threaded.getValue()); @@ -125,10 +128,12 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare ui->DepthType->setCurrentIndex(pcHole->DepthType.getValue()); ui->Depth->setValue(pcHole->Depth.getValue()); - if (pcHole->DrillPoint.getValue() == 0L) + if (pcHole->DrillPoint.getValue() == 0L) { ui->drillPointFlat->setChecked(true); - else + } + else { ui->drillPointAngled->setChecked(true); + } ui->DrillPointAngle->setMinimum(pcHole->DrillPointAngle.getMinimum()); ui->DrillPointAngle->setMaximum(pcHole->DrillPointAngle.getMaximum()); ui->DrillPointAngle->setValue(pcHole->DrillPointAngle.getValue()); @@ -171,18 +176,22 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare // conditional enabling of thread modeling options ui->ModelThread->setEnabled(ui->Threaded->isChecked() && ui->ThreadType->currentIndex() != 0); - ui->UseCustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); + ui->UseCustomThreadClearance->setEnabled(ui->Threaded->isChecked() + && ui->ModelThread->isChecked()); ui->CustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() - && ui->UseCustomThreadClearance->isChecked()); + && ui->UseCustomThreadClearance->isChecked()); ui->UpdateView->setChecked(false); ui->UpdateView->setEnabled(ui->ModelThread->isChecked()); ui->Depth->setEnabled(std::string(pcHole->DepthType.getValueAsString()) == "Dimension"); ui->ThreadDepthType->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() - && std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension"); + && std::string(pcHole->ThreadDepthType.getValueAsString()) + == "Dimension"); - connect(ui->Threaded, &QCheckBox::clicked, this, &TaskHoleParameters::threadedChanged); + // clang-format off + connect(ui->Threaded, &QCheckBox::clicked, + this, &TaskHoleParameters::threadedChanged); connect(ui->ThreadType, qOverload(&QComboBox::currentIndexChanged), this, &TaskHoleParameters::threadTypeChanged); connect(ui->ThreadSize, qOverload(&QComboBox::currentIndexChanged), @@ -237,6 +246,7 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare this, &TaskHoleParameters::threadDepthTypeChanged); connect(ui->ThreadDepth, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &TaskHoleParameters::threadDepthChanged); + // clang-format on getViewObject()->show(); @@ -250,10 +260,10 @@ TaskHoleParameters::TaskHoleParameters(ViewProviderHole* HoleView, QWidget* pare ui->ThreadDepth->bind(pcHole->ThreadDepth); ui->CustomThreadClearance->bind(pcHole->CustomThreadClearance); - //NOLINTBEGIN + // NOLINTBEGIN connectPropChanged = App::GetApplication().signalChangePropertyEditor.connect( - std::bind(&TaskHoleParameters::changedObject, this, sp::_1, sp::_2)); - //NOLINTEND + std::bind(&TaskHoleParameters::changedObject, this, sp::_1, sp::_2)); + // NOLINTEND this->groupLayout()->addWidget(proxy); } @@ -269,19 +279,22 @@ void TaskHoleParameters::threadedChanged() ui->ModelThread->setEnabled(isChecked); ui->ThreadDepthType->setEnabled(isChecked); - ui->ThreadDepth->setEnabled( - ui->Threaded->isChecked() && ui->ModelThread->isChecked() && - std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension"); + ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() + && std::string(pcHole->ThreadDepthType.getValueAsString()) + == "Dimension"); // conditional enabling of thread modeling options - ui->UseCustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); - ui->CustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() && ui->UseCustomThreadClearance->isChecked()); + ui->UseCustomThreadClearance->setEnabled(ui->Threaded->isChecked() + && ui->ModelThread->isChecked()); + ui->CustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() + && ui->UseCustomThreadClearance->isChecked()); // update view not active if modeling threads // this will also ensure that the feature is recomputed. ui->UpdateView->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); - setUpdateBlocked(ui->Threaded->isChecked() && ui->ModelThread->isChecked() && !(ui->UpdateView->isChecked())); + setUpdateBlocked(ui->Threaded->isChecked() && ui->ModelThread->isChecked() + && !(ui->UpdateView->isChecked())); pcHole->Threaded.setValue(ui->Threaded->isChecked()); recomputeFeature(); @@ -296,14 +309,19 @@ void TaskHoleParameters::modelThreadChanged() // update view not active if modeling threads // this will also ensure that the feature is recomputed. ui->UpdateView->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); - setUpdateBlocked(ui->Threaded->isChecked() && ui->ModelThread->isChecked() && !(ui->UpdateView->isChecked())); + setUpdateBlocked(ui->Threaded->isChecked() && ui->ModelThread->isChecked() + && !(ui->UpdateView->isChecked())); // conditional enabling of thread modeling options - ui->UseCustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); - ui->CustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() && ui->UseCustomThreadClearance->isChecked()); + ui->UseCustomThreadClearance->setEnabled(ui->Threaded->isChecked() + && ui->ModelThread->isChecked()); + ui->CustomThreadClearance->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() + && ui->UseCustomThreadClearance->isChecked()); ui->ThreadDepthType->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked()); - ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() && std::string(pcHole->ThreadDepthType.getValueAsString()) == "Dimension"); + ui->ThreadDepth->setEnabled(ui->Threaded->isChecked() && ui->ModelThread->isChecked() + && std::string(pcHole->ThreadDepthType.getValueAsString()) + == "Dimension"); recomputeFeature(); } @@ -362,8 +380,9 @@ void TaskHoleParameters::threadPitchChanged(double value) void TaskHoleParameters::holeCutTypeChanged(int index) { - if (index < 0) + if (index < 0) { return; + } auto hole = getObject(); @@ -397,19 +416,22 @@ void TaskHoleParameters::holeCutTypeChanged(int index) ui->HoleCutDepth->setEnabled(false); ui->HoleCutCountersinkAngle->setEnabled(false); } - if (HoleCutTypeString == "Counterbore") + if (HoleCutTypeString == "Counterbore") { ui->HoleCutCountersinkAngle->setEnabled(false); - if (HoleCutTypeString == "Countersink") + } + if (HoleCutTypeString == "Countersink") { ui->HoleCutCountersinkAngle->setEnabled(true); + } } - else { // screw definition + else { // screw definition // we can have the case that we have no normed values // in this case HoleCutCustomValues is read-only AND true if (ui->HoleCutCustomValues->isChecked()) { ui->HoleCutDiameter->setEnabled(true); ui->HoleCutDepth->setEnabled(true); - if (!hole->HoleCutCountersinkAngle.isReadOnly()) + if (!hole->HoleCutCountersinkAngle.isReadOnly()) { ui->HoleCutCountersinkAngle->setEnabled(true); + } } else { ui->HoleCutCustomValues->setEnabled(true); @@ -428,8 +450,9 @@ void TaskHoleParameters::holeCutCustomValuesChanged() if (ui->HoleCutCustomValues->isChecked()) { ui->HoleCutDiameter->setEnabled(true); ui->HoleCutDepth->setEnabled(true); - if (!hole->HoleCutCountersinkAngle.isReadOnly()) + if (!hole->HoleCutCountersinkAngle.isReadOnly()) { ui->HoleCutCountersinkAngle->setEnabled(true); + } } else { ui->HoleCutDiameter->setEnabled(false); @@ -465,7 +488,8 @@ void TaskHoleParameters::holeCutDepthChanged(double value) double DepthDifference = value - hole->HoleCutDepth.getValue(); // new diameter is the old one + 2 * tan(angle / 2) * DepthDifference double newDiameter = hole->HoleCutDiameter.getValue() - + 2 * tan(Base::toRadians(hole->HoleCutCountersinkAngle.getValue() / 2)) * DepthDifference; + + 2 * tan(Base::toRadians(hole->HoleCutCountersinkAngle.getValue() / 2)) + * DepthDifference; // only apply if the result is not smaller than the hole diameter if (newDiameter > hole->Diameter.getValue()) { hole->HoleCutDiameter.setValue(newDiameter); @@ -503,7 +527,7 @@ void TaskHoleParameters::depthChanged(int index) ui->DrillPointAngle->setEnabled(true); ui->DrillForDepth->setEnabled(true); } - else { // through all + else { // through all ui->drillPointFlat->setEnabled(false); ui->drillPointAngled->setEnabled(false); ui->DrillPointAngle->setEnabled(false); @@ -511,7 +535,8 @@ void TaskHoleParameters::depthChanged(int index) } recomputeFeature(); // enabling must be handled after recompute - ui->ThreadDepth->setEnabled(std::string(hole->ThreadDepthType.getValueAsString()) == "Dimension"); + ui->ThreadDepth->setEnabled(std::string(hole->ThreadDepthType.getValueAsString()) + == "Dimension"); } void TaskHoleParameters::depthValueChanged(double value) @@ -582,8 +607,9 @@ void TaskHoleParameters::taperedAngleChanged(double value) void TaskHoleParameters::threadTypeChanged(int index) { - if (index < 0) + if (index < 0) { return; + } auto hole = getObject(); if (!hole) { @@ -619,7 +645,8 @@ void TaskHoleParameters::threadTypeChanged(int index) if (ThreadSizeString.indexOf(QString::fromLatin1("x")) > -1) { // we have an ISO fine size // cut of the part behind the 'x' - ThreadSizeString = ThreadSizeString.left(ThreadSizeString.indexOf(QString::fromLatin1("x"))); + ThreadSizeString = + ThreadSizeString.left(ThreadSizeString.indexOf(QString::fromLatin1("x"))); } // search if the string exists in the combobox int threadSizeIndex = ui->ThreadSize->findText(ThreadSizeString, Qt::MatchContains); @@ -628,9 +655,15 @@ void TaskHoleParameters::threadTypeChanged(int index) ui->ThreadSize->setCurrentIndex(threadSizeIndex); } // the names of the clearance types are different in ISO and UTS - ui->ThreadFit->setItemText(0, QCoreApplication::translate("TaskHoleParameters", "Standard", nullptr)); - ui->ThreadFit->setItemText(1, QCoreApplication::translate("TaskHoleParameters", "Close", nullptr)); - ui->ThreadFit->setItemText(2, QCoreApplication::translate("TaskHoleParameters", "Wide", nullptr)); + ui->ThreadFit->setItemText( + 0, + QCoreApplication::translate("TaskHoleParameters", "Standard", nullptr)); + ui->ThreadFit->setItemText( + 1, + QCoreApplication::translate("TaskHoleParameters", "Close", nullptr)); + ui->ThreadFit->setItemText( + 2, + QCoreApplication::translate("TaskHoleParameters", "Wide", nullptr)); } else if (TypeClass == QByteArray("UTS")) { // for all UTS types the size entries are the same @@ -639,19 +672,28 @@ void TaskHoleParameters::threadTypeChanged(int index) ui->ThreadSize->setCurrentIndex(threadSizeIndex); } // the names of the clearance types are different in ISO and UTS - ui->ThreadFit->setItemText(0, QCoreApplication::translate("TaskHoleParameters", "Normal", nullptr)); - ui->ThreadFit->setItemText(1, QCoreApplication::translate("TaskHoleParameters", "Close", nullptr)); - ui->ThreadFit->setItemText(2, QCoreApplication::translate("TaskHoleParameters", "Loose", nullptr)); + ui->ThreadFit->setItemText( + 0, + QCoreApplication::translate("TaskHoleParameters", "Normal", nullptr)); + ui->ThreadFit->setItemText( + 1, + QCoreApplication::translate("TaskHoleParameters", "Close", nullptr)); + ui->ThreadFit->setItemText( + 2, + QCoreApplication::translate("TaskHoleParameters", "Loose", nullptr)); } // Class and cut type - // the class and cut types are the same for both TypeClass so we don't need to distinguish between ISO and UTS + // the class and cut types are the same for both TypeClass so we don't need to distinguish + // between ISO and UTS int threadClassIndex = ui->ThreadClass->findText(ThreadClassString, Qt::MatchContains); - if (threadClassIndex > -1) + if (threadClassIndex > -1) { ui->ThreadClass->setCurrentIndex(threadClassIndex); + } int holeCutIndex = ui->HoleCutType->findText(CutTypeString, Qt::MatchContains); - if (holeCutIndex > -1) + if (holeCutIndex > -1) { ui->HoleCutType->setCurrentIndex(holeCutIndex); + } // we must set the read-only state according to the new HoleCutType holeCutTypeChanged(ui->HoleCutType->currentIndex()); @@ -661,8 +703,9 @@ void TaskHoleParameters::threadTypeChanged(int index) void TaskHoleParameters::threadSizeChanged(int index) { - if (index < 0) + if (index < 0) { return; + } if (auto hole = getObject()) { hole->ThreadSize.setValue(index); @@ -676,8 +719,9 @@ void TaskHoleParameters::threadSizeChanged(int index) void TaskHoleParameters::threadClassChanged(int index) { - if (index < 0) + if (index < 0) { return; + } if (auto hole = getObject()) { hole->ThreadClass.setValue(index); @@ -708,10 +752,12 @@ void TaskHoleParameters::threadFitChanged(int index) void TaskHoleParameters::threadDirectionChanged() { if (auto hole = getObject()) { - if (sender() == ui->directionRightHand) + if (sender() == ui->directionRightHand) { hole->ThreadDirection.setValue(0L); - else + } + else { hole->ThreadDirection.setValue(1L); + } recomputeFeature(); } } @@ -760,7 +806,7 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property ui->HoleCutType->blockSignals(true); ui->HoleCutType->clear(); cursor = hole->HoleCutType.getEnumVector(); - for (const auto& it: cursor) { + for (const auto& it : cursor) { ui->HoleCutType->addItem(QString::fromStdString(it)); } ui->HoleCutType->setCurrentIndex(hole->HoleCutType.getValue()); @@ -864,7 +910,8 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property } else if (&Prop == &hole->HoleCutCountersinkAngle) { ui->HoleCutCountersinkAngle->setEnabled(true); - if (ui->HoleCutCountersinkAngle->value().getValue() != hole->HoleCutCountersinkAngle.getValue()) { + if (ui->HoleCutCountersinkAngle->value().getValue() + != hole->HoleCutCountersinkAngle.getValue()) { ui->HoleCutCountersinkAngle->blockSignals(true); ui->HoleCutCountersinkAngle->setValue(hole->HoleCutCountersinkAngle.getValue()); ui->HoleCutCountersinkAngle->blockSignals(false); @@ -962,7 +1009,8 @@ void TaskHoleParameters::changedObject(const App::Document&, const App::Property } else if (&Prop == &hole->CustomThreadClearance) { ui->CustomThreadClearance->setEnabled(true); - if (ui->CustomThreadClearance->value().getValue() != hole->CustomThreadClearance.getValue()) { + if (ui->CustomThreadClearance->value().getValue() + != hole->CustomThreadClearance.getValue()) { ui->CustomThreadClearance->blockSignals(true); ui->CustomThreadClearance->setValue(hole->CustomThreadClearance.getValue()); ui->CustomThreadClearance->blockSignals(false); @@ -1006,18 +1054,22 @@ long TaskHoleParameters::getThreadType() const long TaskHoleParameters::getThreadSize() const { - if (ui->ThreadSize->currentIndex() == -1) + if (ui->ThreadSize->currentIndex() == -1) { return 0; - else + } + else { return ui->ThreadSize->currentIndex(); + } } long TaskHoleParameters::getThreadClass() const { - if (ui->ThreadSize->currentIndex() == -1) + if (ui->ThreadSize->currentIndex() == -1) { return 0; - else + } + else { return ui->ThreadClass->currentIndex(); + } } long TaskHoleParameters::getThreadFit() const @@ -1034,18 +1086,22 @@ Base::Quantity TaskHoleParameters::getDiameter() const long TaskHoleParameters::getThreadDirection() const { - if (ui->directionRightHand->isChecked()) + if (ui->directionRightHand->isChecked()) { return 0; - else + } + else { return 1; + } } long TaskHoleParameters::getHoleCutType() const { - if (ui->HoleCutType->currentIndex() == -1) + if (ui->HoleCutType->currentIndex() == -1) { return 0; - else + } + else { return ui->HoleCutType->currentIndex(); + } } bool TaskHoleParameters::getHoleCutCustomValues() const @@ -1080,12 +1136,14 @@ Base::Quantity TaskHoleParameters::getDepth() const long TaskHoleParameters::getDrillPoint() const { - if (ui->drillPointFlat->isChecked()) + if (ui->drillPointFlat->isChecked()) { return 0; - if (ui->drillPointAngled->isChecked()) + } + if (ui->drillPointAngled->isChecked()) { return 1; + } assert(0); - return -1; // to avoid a compiler warning + return -1; // to avoid a compiler warning } Base::Quantity TaskHoleParameters::getDrillPointAngle() const @@ -1113,7 +1171,7 @@ bool TaskHoleParameters::getUseCustomThreadClearance() const return ui->UseCustomThreadClearance->isChecked(); } -double TaskHoleParameters::getCustomThreadClearance() const +double TaskHoleParameters::getCustomThreadClearance() const { return ui->CustomThreadClearance->value().getValue(); } @@ -1147,40 +1205,58 @@ void TaskHoleParameters::apply() ui->DrillPointAngle->apply(); ui->TaperedAngle->apply(); - if (!hole->Threaded.isReadOnly()) + if (!hole->Threaded.isReadOnly()) { FCMD_OBJ_CMD(hole, "Threaded = " << (getThreaded() ? 1 : 0)); - if (!hole->ModelThread.isReadOnly()) + } + if (!hole->ModelThread.isReadOnly()) { FCMD_OBJ_CMD(hole, "ModelThread = " << (getModelThread() ? 1 : 0)); - if (!hole->ThreadDepthType.isReadOnly()) + } + if (!hole->ThreadDepthType.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadDepthType = " << getThreadDepthType()); - if (!hole->ThreadDepth.isReadOnly()) + } + if (!hole->ThreadDepth.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadDepth = " << getThreadDepth()); - if (!hole->UseCustomThreadClearance.isReadOnly()) - FCMD_OBJ_CMD(hole, "UseCustomThreadClearance = " << (getUseCustomThreadClearance() ? 1 : 0)); - if (!hole->CustomThreadClearance.isReadOnly()) + } + if (!hole->UseCustomThreadClearance.isReadOnly()) { + FCMD_OBJ_CMD(hole, + "UseCustomThreadClearance = " << (getUseCustomThreadClearance() ? 1 : 0)); + } + if (!hole->CustomThreadClearance.isReadOnly()) { FCMD_OBJ_CMD(hole, "CustomThreadClearance = " << getCustomThreadClearance()); - if (!hole->ThreadType.isReadOnly()) + } + if (!hole->ThreadType.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadType = " << getThreadType()); - if (!hole->ThreadSize.isReadOnly()) + } + if (!hole->ThreadSize.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadSize = " << getThreadSize()); - if (!hole->ThreadClass.isReadOnly()) + } + if (!hole->ThreadClass.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadClass = " << getThreadClass()); - if (!hole->ThreadFit.isReadOnly()) + } + if (!hole->ThreadFit.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadFit = " << getThreadFit()); - if (!hole->ThreadDirection.isReadOnly()) + } + if (!hole->ThreadDirection.isReadOnly()) { FCMD_OBJ_CMD(hole, "ThreadDirection = " << getThreadDirection()); - if (!hole->HoleCutType.isReadOnly()) + } + if (!hole->HoleCutType.isReadOnly()) { FCMD_OBJ_CMD(hole, "HoleCutType = " << getHoleCutType()); - if (!hole->HoleCutCustomValues.isReadOnly()) + } + if (!hole->HoleCutCustomValues.isReadOnly()) { FCMD_OBJ_CMD(hole, "HoleCutCustomValues = " << (getHoleCutCustomValues() ? 1 : 0)); - if (!hole->DepthType.isReadOnly()) + } + if (!hole->DepthType.isReadOnly()) { FCMD_OBJ_CMD(hole, "DepthType = " << getDepthType()); - if (!hole->DrillPoint.isReadOnly()) + } + if (!hole->DrillPoint.isReadOnly()) { FCMD_OBJ_CMD(hole, "DrillPoint = " << getDrillPoint()); - if (!hole->DrillForDepth.isReadOnly()) + } + if (!hole->DrillForDepth.isReadOnly()) { FCMD_OBJ_CMD(hole, "DrillForDepth = " << (getDrillForDepth() ? 1 : 0)); - if (!hole->Tapered.isReadOnly()) + } + if (!hole->Tapered.isReadOnly()) { FCMD_OBJ_CMD(hole, "Tapered = " << getTapered()); + } isApplying = false; } @@ -1207,14 +1283,15 @@ TaskHoleParameters::Observer::Observer(TaskHoleParameters* _owner, PartDesign::H : DocumentObserver(_hole->getDocument()) , owner(_owner) , hole(_hole) -{ -} +{} -void TaskHoleParameters::Observer::slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) +void TaskHoleParameters::Observer::slotChangedObject(const App::DocumentObject& Obj, + const App::Property& Prop) { if (&Obj == hole) { Base::Console().Log("Parameter %s was updated with a new value\n", Prop.getName()); - if (Obj.getDocument()) + if (Obj.getDocument()) { owner->changedObject(*Obj.getDocument(), Prop); + } } } diff --git a/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp b/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp index fb7de4c2df..046417abf3 100644 --- a/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskLoftParameters.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -46,7 +46,7 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskLoftParameters */ -TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj*/, QWidget *parent) +TaskLoftParameters::TaskLoftParameters(ViewProviderLoft* LoftView, bool /*newObj*/, QWidget* parent) : TaskSketchBasedParameters(LoftView, parent, "PartDesign_AdditiveLoft", tr("Loft parameters")) , ui(new Ui_TaskLoftParameters) { @@ -55,6 +55,7 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + // clang-format off connect(ui->buttonProfileBase, &QToolButton::toggled, this, &TaskLoftParameters::onProfileButton); connect(ui->buttonRefAdd, &QToolButton::toggled, @@ -67,6 +68,7 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj this, &TaskLoftParameters::onClosed); connect(ui->checkBoxUpdateView, &QCheckBox::toggled, this, &TaskLoftParameters::onUpdateView); + // clang-format on // Create context menu QAction* remove = new QAction(tr("Remove"), this); @@ -79,17 +81,20 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); connect(remove, &QAction::triggered, this, &TaskLoftParameters::onDeleteSection); - connect(ui->listWidgetReferences->model(), &QAbstractListModel::rowsMoved, - this, &TaskLoftParameters::indexesMoved); + connect(ui->listWidgetReferences->model(), + &QAbstractListModel::rowsMoved, + this, + &TaskLoftParameters::indexesMoved); this->groupLayout()->addWidget(proxy); // Temporarily prevent unnecessary feature recomputes const auto childs = proxy->findChildren(); - for (QWidget* child : childs) + for (QWidget* child : childs) { child->blockSignals(true); + } - //add the profiles + // add the profiles PartDesign::Loft* loft = static_cast(LoftView->getObject()); App::DocumentObject* profile = loft->Profile.getValue(); if (profile) { @@ -100,7 +105,7 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj ui->profileBaseEdit->setText(label); } - for (auto &subSet : loft->Sections.getSubListValues()) { + for (auto& subSet : loft->Sections.getSubListValues()) { Gui::Application::Instance->showViewProvider(subSet.first); // TODO: if it is a single vertex of a sketch, use that subshape's name @@ -116,8 +121,9 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView, bool /*newObj ui->checkBoxClosed->setChecked(loft->Closed.getValue()); // activate and de-activate dialog elements as appropriate - for (QWidget* child : childs) + for (QWidget* child : childs) { child->blockSignals(false); + } updateUI(); } @@ -137,8 +143,9 @@ void TaskLoftParameters::updateUI() void TaskLoftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (selectionMode == none) + if (selectionMode == none) { return; + } if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { @@ -153,8 +160,10 @@ void TaskLoftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) else if (selectionMode == refAdd) { QListWidgetItem* item = new QListWidgetItem(); item->setText(label); - item->setData(Qt::UserRole, - QVariant::fromValue(std::make_pair(object, std::vector(1, msg.pSubName)))); + item->setData( + Qt::UserRole, + QVariant::fromValue( + std::make_pair(object, std::vector(1, msg.pSubName)))); ui->listWidgetReferences->addItem(item); } else if (selectionMode == refRemove) { @@ -172,22 +181,25 @@ void TaskLoftParameters::onSelectionChanged(const Gui::SelectionChanges& msg) } } -bool TaskLoftParameters::referenceSelected(const Gui::SelectionChanges& msg) const { +bool TaskLoftParameters::referenceSelected(const Gui::SelectionChanges& msg) const +{ if (msg.Type == Gui::SelectionChanges::AddSelection && selectionMode != none) { - if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0) + if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0) { return false; + } // not allowed to reference ourself const char* fname = getObject()->getNameInDocument(); - if (strcmp(msg.pObjectName, fname) == 0) + if (strcmp(msg.pObjectName, fname) == 0) { return false; + } - //every selection needs to be a profile in itself, hence currently only full objects are - //supported, not individual edges of a part + // every selection needs to be a profile in itself, hence currently only full objects are + // supported, not individual edges of a part - //change the references + // change the references auto loft = getObject(); App::Document* doc = loft->getDocument(); App::DocumentObject* obj = doc->getObject(msg.pObjectName); @@ -201,11 +213,12 @@ bool TaskLoftParameters::referenceSelected(const Gui::SelectionChanges& msg) con else if (selectionMode == refAdd || selectionMode == refRemove) { // now check the sections std::vector refs = loft->Sections.getValues(); - std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + std::vector::iterator f = + std::find(refs.begin(), refs.end(), obj); if (selectionMode == refAdd) { if (f != refs.end()) { - return false; // duplicate selection + return false; // duplicate selection } loft->Sections.addValue(obj, {msg.pSubName}); @@ -225,7 +238,8 @@ bool TaskLoftParameters::referenceSelected(const Gui::SelectionChanges& msg) con return false; } -void TaskLoftParameters::removeFromListWidget(QListWidget* widget, QString name) { +void TaskLoftParameters::removeFromListWidget(QListWidget* widget, QString name) +{ QList items = widget->findItems(name, Qt::MatchExactly); if (!items.empty()) { @@ -242,14 +256,17 @@ void TaskLoftParameters::onDeleteSection() int row = ui->listWidgetReferences->currentRow(); QListWidgetItem* item = ui->listWidgetReferences->takeItem(row); if (item) { - QByteArray data(item->data(Qt::UserRole).value().first->getNameInDocument()); + QByteArray data(item->data(Qt::UserRole) + .value() + .first->getNameInDocument()); delete item; // search inside the list of sections if (auto loft = getObject()) { std::vector refs = loft->Sections.getValues(); App::DocumentObject* obj = loft->getDocument()->getObject(data.constData()); - std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + std::vector::iterator f = + std::find(refs.begin(), refs.end(), obj); if (f != refs.end()) { loft->Sections.removeValue(obj); @@ -302,9 +319,8 @@ void TaskLoftParameters::exitSelectionMode() this->blockSelection(true); } -void TaskLoftParameters::changeEvent(QEvent * /*e*/) -{ -} +void TaskLoftParameters::changeEvent(QEvent* /*e*/) +{} void TaskLoftParameters::onClosed(bool val) { @@ -355,17 +371,16 @@ void TaskLoftParameters::onRefButtonRemove(bool checked) } - //************************************************************************** //************************************************************************** // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgLoftParameters::TaskDlgLoftParameters(ViewProviderLoft *LoftView,bool newObj) - : TaskDlgSketchBasedParameters(LoftView) +TaskDlgLoftParameters::TaskDlgLoftParameters(ViewProviderLoft* LoftView, bool newObj) + : TaskDlgSketchBasedParameters(LoftView) { assert(LoftView); - parameter = new TaskLoftParameters(LoftView,newObj); + parameter = new TaskLoftParameters(LoftView, newObj); Content.push_back(parameter); } diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 93d11b59dc..b794a8d78d 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -23,9 +23,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include -# include +#include +#include +#include #endif #include @@ -64,7 +64,7 @@ using namespace Gui; // Task Parameter //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj*/, QWidget *parent) +TaskPipeParameters::TaskPipeParameters(ViewProviderPipe* PipeView, bool /*newObj*/, QWidget* parent) : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Pipe parameters")) , ui(new Ui_TaskPipeParameters) , stateHandler(nullptr) @@ -75,10 +75,14 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj QMetaObject::connectSlotsByName(this); // some buttons are handled in a buttongroup - connect(ui->buttonProfileBase, &QToolButton::toggled, - this, &TaskPipeParameters::onProfileButton); - connect(ui->comboBoxTransition, qOverload(&QComboBox::currentIndexChanged), - this, &TaskPipeParameters::onTransitionChanged); + connect(ui->buttonProfileBase, + &QToolButton::toggled, + this, + &TaskPipeParameters::onProfileButton); + connect(ui->comboBoxTransition, + qOverload(&QComboBox::currentIndexChanged), + this, + &TaskPipeParameters::onTransitionChanged); // Create context menu QAction* remove = new QAction(tr("Remove"), this); @@ -111,7 +115,8 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj auto* profileVP = doc->getViewProvider(pipe->Profile.getValue()); profileShow = profileVP->isShow(); profileVP->setVisible(true); - ui->profileBaseEdit->setText(make2DLabel(pipe->Profile.getValue(), pipe->Profile.getSubValues())); + ui->profileBaseEdit->setText( + make2DLabel(pipe->Profile.getValue(), pipe->Profile.getSubValues())); } // the auxiliary spine if (pipe->AuxillerySpine.getValue()) { @@ -121,7 +126,7 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj } // the spine edges std::vector strings = pipe->Spine.getSubValues(); - for (const auto & string : strings) { + for (const auto& string : strings) { QString label = QString::fromStdString(string); QListWidgetItem* item = new QListWidgetItem(); item->setText(label); @@ -143,10 +148,12 @@ TaskPipeParameters::~TaskPipeParameters() { try { if (auto pipe = getObject()) { - // setting visibility to true is needed when preselecting profile and path prior to invoking sweep + // setting visibility to true is needed when preselecting profile and path prior to + // invoking sweep Gui::cmdGuiObject(pipe, "Visibility = True"); getViewObject()->highlightReferences(ViewProviderPipe::Spine, false); - getViewObject()->highlightReferences(ViewProviderPipe::Profile, false); + getViewObject()->highlightReferences(ViewProviderPipe::Profile, + false); } } catch (const Standard_OutOfRange&) { @@ -156,7 +163,7 @@ TaskPipeParameters::~TaskPipeParameters() e.ReportException(); } catch (const Py::Exception&) { - Base::PyException e; // extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); } } @@ -166,20 +173,24 @@ void TaskPipeParameters::updateUI() void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) { return; + } if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refProfile) { + if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refProfile) { App::Document* document = App::GetApplication().getDocument(msg.pDocName); - App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; + App::DocumentObject* object = + document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = make2DLabel(object, {msg.pSubName}); ui->profileBaseEdit->setText(label); } } - else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd) { + else if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd) { QString sub = QString::fromStdString(msg.pSubName); if (!sub.isEmpty()) { QListWidgetItem* item = new QListWidgetItem(); @@ -189,13 +200,15 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) } App::Document* document = App::GetApplication().getDocument(msg.pDocName); - App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; + App::DocumentObject* object = + document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = QString::fromUtf8(object->Label.getValue()); ui->spineBaseEdit->setText(label); } } - else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove) { + else if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove) { QString sub = QString::fromLatin1(msg.pSubName); if (!sub.isEmpty()) { removeFromListWidget(ui->listWidgetReferences, sub); @@ -204,11 +217,13 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->spineBaseEdit->clear(); } } - else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSpine) { + else if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refSpine) { ui->listWidgetReferences->clear(); App::Document* document = App::GetApplication().getDocument(msg.pDocName); - App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; + App::DocumentObject* object = + document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = QString::fromUtf8(object->Label.getValue()); ui->spineBaseEdit->setText(label); @@ -294,76 +309,84 @@ bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const { auto selectionMode = stateHandler->getSelectionMode(); - if (msg.Type == Gui::SelectionChanges::AddSelection && - selectionMode != StateHandlerTaskPipe::SelectionModes::none) { - if (strcmp(msg.pDocName, getAppDocument()->getName()) != 0) + if (msg.Type == Gui::SelectionChanges::AddSelection + && selectionMode != StateHandlerTaskPipe::SelectionModes::none) { + if (strcmp(msg.pDocName, getAppDocument()->getName()) != 0) { return false; + } // not allowed to reference ourself const char* fname = getObject()->getNameInDocument(); - if (strcmp(msg.pObjectName, fname) == 0) + if (strcmp(msg.pObjectName, fname) == 0) { return false; + } switch (selectionMode) { - case StateHandlerTaskPipe::SelectionModes::refProfile: - { - auto pipe = getObject(); - Gui::Document* doc = getGuiDocument(); + case StateHandlerTaskPipe::SelectionModes::refProfile: { + auto pipe = getObject(); + Gui::Document* doc = getGuiDocument(); - getViewObject()->highlightReferences(ViewProviderPipe::Profile, false); + getViewObject()->highlightReferences(ViewProviderPipe::Profile, + false); - bool success = true; - App::DocumentObject* profile = pipe->getDocument()->getObject(msg.pObjectName); - if (profile) { - std::vector sections = pipe->Sections.getValues(); + bool success = true; + App::DocumentObject* profile = pipe->getDocument()->getObject(msg.pObjectName); + if (profile) { + std::vector sections = pipe->Sections.getValues(); - // cannot use the same object for profile and section - if (std::find(sections.begin(), sections.end(), profile) != sections.end()) { - success = false; + // cannot use the same object for profile and section + if (std::find(sections.begin(), sections.end(), profile) != sections.end()) { + success = false; + } + else { + pipe->Profile.setValue(profile, {msg.pSubName}); + } + + // hide the old or new profile again + auto* pvp = doc->getViewProvider(pipe->Profile.getValue()); + if (pvp) { + pvp->setVisible(false); + } } - else { - pipe->Profile.setValue(profile, {msg.pSubName}); + return success; + } + case StateHandlerTaskPipe::SelectionModes::refSpine: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: { + // change the references + std::string subName(msg.pSubName); + auto pipe = getObject(); + std::vector refs = pipe->Spine.getSubValues(); + std::vector::iterator f = std::find(refs.begin(), refs.end(), subName); + + if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpine) { + getViewObject()->highlightReferences(ViewProviderPipe::Spine, + false); + refs.clear(); + } + else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd) { + if (f == refs.end()) { + refs.push_back(subName); + } + else { + return false; // duplicate selection + } + } + else if (selectionMode + == StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove) { + if (f != refs.end()) { + refs.erase(f); + } + else { + return false; + } } - // hide the old or new profile again - auto* pvp = doc->getViewProvider(pipe->Profile.getValue()); - if (pvp) - pvp->setVisible(false); + pipe->Spine.setValue(getAppDocument()->getObject(msg.pObjectName), refs); + return true; } - return success; - } - case StateHandlerTaskPipe::SelectionModes::refSpine: - case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd: - case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: - { - //change the references - std::string subName(msg.pSubName); - auto pipe = getObject(); - std::vector refs = pipe->Spine.getSubValues(); - std::vector::iterator f = std::find(refs.begin(), refs.end(), subName); - - if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpine) { - getViewObject()->highlightReferences(ViewProviderPipe::Spine, false); - refs.clear(); - } - else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd) { - if (f == refs.end()) - refs.push_back(subName); - else - return false; // duplicate selection - } - else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove) { - if (f != refs.end()) - refs.erase(f); - else - return false; - } - - pipe->Spine.setValue(getAppDocument()->getObject(msg.pObjectName), refs); - return true; - } - default: - return false; + default: + return false; } } @@ -415,16 +438,16 @@ void TaskPipeParameters::setVisibilityOfSpineAndProfile() bool TaskPipeParameters::accept() { - //see what to do with external references - //check the prerequisites for the selected objects - //the user has to decide which option we should take if external references are used + // see what to do with external references + // check the prerequisites for the selected objects + // the user has to decide which option we should take if external references are used auto pipe = getObject(); - auto pcActiveBody = PartDesignGui::getBodyFor (pipe, false); + auto pcActiveBody = PartDesignGui::getBodyFor(pipe, false); if (!pcActiveBody) { QMessageBox::warning(this, tr("Input error"), tr("No active body")); return false; } - //auto pcActivePart = PartDesignGui::getPartFor (pcActiveBody, false); + // auto pcActivePart = PartDesignGui::getPartFor (pcActiveBody, false); std::vector copies; bool extReference = false; @@ -435,7 +458,10 @@ bool TaskPipeParameters::accept() QString label = ui->spineBaseEdit->text(); if (!spine && !label.isEmpty()) { QByteArray ba = label.toUtf8(); - std::vector objs = pipe->getDocument()->findObjects(App::DocumentObject::getClassTypeId(), nullptr, ba.constData()); + std::vector objs = + pipe->getDocument()->findObjects(App::DocumentObject::getClassTypeId(), + nullptr, + ba.constData()); if (!objs.empty()) { pipe->Spine.setValue(objs.front()); spine = objs.front(); @@ -445,7 +471,8 @@ bool TaskPipeParameters::accept() if (spine && !pcActiveBody->hasObject(spine) && !pcActiveBody->getOrigin()->hasObject(spine)) { extReference = true; } - else if (auxSpine && !pcActiveBody->hasObject(auxSpine) && !pcActiveBody->getOrigin()->hasObject(auxSpine)) { + else if (auxSpine && !pcActiveBody->hasObject(auxSpine) + && !pcActiveBody->getOrigin()->hasObject(auxSpine)) { extReference = true; } else { @@ -463,31 +490,38 @@ bool TaskPipeParameters::accept() dlg.setupUi(&dia); dia.setModal(true); int result = dia.exec(); - if (result == QDialog::DialogCode::Rejected) + if (result == QDialog::DialogCode::Rejected) { return false; + } if (!dlg.radioXRef->isChecked()) { if (!pcActiveBody->hasObject(spine) && !pcActiveBody->getOrigin()->hasObject(spine)) { - pipe->Spine.setValue(PartDesignGui::TaskFeaturePick::makeCopy(spine, "", - dlg.radioIndependent->isChecked()), - pipe->Spine.getSubValues()); + pipe->Spine.setValue( + PartDesignGui::TaskFeaturePick::makeCopy(spine, + "", + dlg.radioIndependent->isChecked()), + pipe->Spine.getSubValues()); copies.push_back(pipe->Spine.getValue()); } - else if (!pcActiveBody->hasObject(auxSpine) && !pcActiveBody->getOrigin()->hasObject(auxSpine)){ - pipe->AuxillerySpine.setValue(PartDesignGui::TaskFeaturePick::makeCopy(auxSpine, "", - dlg.radioIndependent->isChecked()), - pipe->AuxillerySpine.getSubValues()); + else if (!pcActiveBody->hasObject(auxSpine) + && !pcActiveBody->getOrigin()->hasObject(auxSpine)) { + pipe->AuxillerySpine.setValue( + PartDesignGui::TaskFeaturePick::makeCopy(auxSpine, + "", + dlg.radioIndependent->isChecked()), + pipe->AuxillerySpine.getSubValues()); copies.push_back(pipe->AuxillerySpine.getValue()); } std::vector subSets; - for (auto &subSet : pipe->Sections.getSubListValues()) { - if (!pcActiveBody->hasObject(subSet.first) && - !pcActiveBody->getOrigin()->hasObject(subSet.first)) { + for (auto& subSet : pipe->Sections.getSubListValues()) { + if (!pcActiveBody->hasObject(subSet.first) + && !pcActiveBody->getOrigin()->hasObject(subSet.first)) { subSets.emplace_back( - PartDesignGui::TaskFeaturePick::makeCopy( - subSet.first, "", dlg.radioIndependent->isChecked()), - subSet.second); + PartDesignGui::TaskFeaturePick::makeCopy(subSet.first, + "", + dlg.radioIndependent->isChecked()), + subSet.second); copies.push_back(subSets.back().first); } else { @@ -508,18 +542,22 @@ bool TaskPipeParameters::accept() Gui::cmdAppObjectArgs(pipe, "Spine = %s", propT.getPropertyPython()); Gui::cmdAppDocument(pipe, "recompute()"); - if (!getObject()->isValid()) + if (!getObject()->isValid()) { throw Base::RuntimeError(getObject()->getStatusString()); + } Gui::cmdGuiDocument(pipe, "resetEdit()"); Gui::Command::commitCommand(); - //we need to add the copied features to the body after the command action, as otherwise FreeCAD crashes unexplainably + // we need to add the copied features to the body after the command action, as otherwise + // FreeCAD crashes unexplainably for (auto obj : copies) { pcActiveBody->addObject(obj); } } catch (const Base::Exception& e) { - QMessageBox::warning(this, tr("Input error"), QApplication::translate("Exception", e.what())); + QMessageBox::warning(this, + tr("Input error"), + QApplication::translate("Exception", e.what())); return false; } @@ -532,8 +570,13 @@ bool TaskPipeParameters::accept() // Task Orientation //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newObj*/, QWidget* parent) - : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Section orientation")) +TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, + bool /*newObj*/, + QWidget* parent) + : TaskSketchBasedParameters(PipeView, + parent, + "PartDesign_AdditivePipe", + tr("Section orientation")) , ui(new Ui_TaskPipeOrientation) , stateHandler(nullptr) { @@ -542,6 +585,7 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + // clang-format off // some buttons are handled in a buttongroup connect(ui->comboBoxMode, qOverload(&QComboBox::currentIndexChanged), this, &TaskPipeOrientation::onOrientationChanged); @@ -557,6 +601,7 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO this, &TaskPipeOrientation::onBinormalChanged); connect(ui->doubleSpinBoxZ, qOverload(&QDoubleSpinBox::valueChanged), this, &TaskPipeOrientation::onBinormalChanged); + // clang-format on // Create context menu QAction* remove = new QAction(tr("Remove"), this); @@ -574,12 +619,14 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); - //add initial values - if (pipe->AuxillerySpine.getValue()) - ui->profileBaseEdit->setText(QString::fromUtf8(pipe->AuxillerySpine.getValue()->Label.getValue())); + // add initial values + if (pipe->AuxillerySpine.getValue()) { + ui->profileBaseEdit->setText( + QString::fromUtf8(pipe->AuxillerySpine.getValue()->Label.getValue())); + } std::vector strings = pipe->AuxillerySpine.getSubValues(); - for (const auto & string : strings) { + for (const auto& string : strings) { QString label = QString::fromStdString(string); QListWidgetItem* item = new QListWidgetItem(); item->setText(label); @@ -591,8 +638,10 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO ui->curvelinear->setChecked(pipe->AuxilleryCurvelinear.getValue()); // should be called after panel has become visible - QMetaObject::invokeMethod(this, "updateUI", Qt::QueuedConnection, - Q_ARG(int,pipe->Mode.getValue())); + QMetaObject::invokeMethod(this, + "updateUI", + Qt::QueuedConnection, + Q_ARG(int, pipe->Mode.getValue())); this->blockSelection(false); } @@ -659,12 +708,14 @@ void TaskPipeOrientation::onBinormalChanged(double) void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) { - if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) { return; + } if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd) { + if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd) { QString sub = QString::fromStdString(msg.pSubName); if (!sub.isEmpty()) { QListWidgetItem* item = new QListWidgetItem(); @@ -674,13 +725,15 @@ void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) } App::Document* document = App::GetApplication().getDocument(msg.pDocName); - App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; + App::DocumentObject* object = + document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = QString::fromUtf8(object->Label.getValue()); ui->profileBaseEdit->setText(label); } } - else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove) { + else if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove) { QString sub = QString::fromLatin1(msg.pSubName); if (!sub.isEmpty()) { removeFromListWidget(ui->listWidgetReferences, sub); @@ -689,11 +742,13 @@ void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) ui->profileBaseEdit->clear(); } } - else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refAuxSpine) { + else if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refAuxSpine) { ui->listWidgetReferences->clear(); App::Document* document = App::GetApplication().getDocument(msg.pDocName); - App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; + App::DocumentObject* object = + document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = QString::fromUtf8(object->Label.getValue()); ui->profileBaseEdit->setText(label); @@ -715,20 +770,22 @@ bool TaskPipeOrientation::referenceSelected(const SelectionChanges& msg) const { auto selectionMode = stateHandler->getSelectionMode(); - if (msg.Type == Gui::SelectionChanges::AddSelection && - (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpine || - selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd || - selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove)) { - if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0) + if (msg.Type == Gui::SelectionChanges::AddSelection + && (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpine + || selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd + || selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove)) { + if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0) { return false; + } // not allowed to reference ourself const char* fname = getObject()->getNameInDocument(); - if (strcmp(msg.pObjectName, fname) == 0) + if (strcmp(msg.pObjectName, fname) == 0) { return false; + } if (auto pipe = getObject()) { - //change the references + // change the references std::string subName(msg.pSubName); std::vector refs = pipe->AuxillerySpine.getSubValues(); std::vector::iterator f = std::find(refs.begin(), refs.end(), subName); @@ -738,7 +795,7 @@ bool TaskPipeOrientation::referenceSelected(const SelectionChanges& msg) const } else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd) { if (f != refs.end()) { - return false; // duplicate selection + return false; // duplicate selection } refs.push_back(subName); @@ -799,12 +856,15 @@ void TaskPipeOrientation::onDeleteItem() void TaskPipeOrientation::updateUI(int idx) { - //make sure we resize to the size of the current page - for (int i=0; istackedWidget->count(); ++i) + // make sure we resize to the size of the current page + for (int i = 0; i < ui->stackedWidget->count(); ++i) { ui->stackedWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + } - if (idx < ui->stackedWidget->count()) - ui->stackedWidget->widget(idx)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + if (idx < ui->stackedWidget->count()) { + ui->stackedWidget->widget(idx)->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Expanding); + } } @@ -813,7 +873,10 @@ void TaskPipeOrientation::updateUI(int idx) // Task Scaling //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QWidget* parent) - : TaskSketchBasedParameters(PipeView, parent, "PartDesign_AdditivePipe", tr("Section transformation")) + : TaskSketchBasedParameters(PipeView, + parent, + "PartDesign_AdditivePipe", + tr("Section transformation")) , ui(new Ui_TaskPipeScaling) , stateHandler(nullptr) { @@ -823,10 +886,11 @@ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QW QMetaObject::connectSlotsByName(this); // some buttons are handled in a buttongroup - connect(ui->comboBoxScaling, qOverload(&QComboBox::currentIndexChanged), - this, &TaskPipeScaling::onScalingChanged); - connect(ui->stackedWidget, &QStackedWidget::currentChanged, - this, &TaskPipeScaling::updateUI); + connect(ui->comboBoxScaling, + qOverload(&QComboBox::currentIndexChanged), + this, + &TaskPipeScaling::onScalingChanged); + connect(ui->stackedWidget, &QStackedWidget::currentChanged, this, &TaskPipeScaling::updateUI); // Create context menu QAction* remove = new QAction(tr("Remove"), this); @@ -840,13 +904,15 @@ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QW ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu); connect(remove, &QAction::triggered, this, &TaskPipeScaling::onDeleteSection); - connect(ui->listWidgetReferences->model(), &QAbstractListModel::rowsMoved, - this, &TaskPipeScaling::indexesMoved); + connect(ui->listWidgetReferences->model(), + &QAbstractListModel::rowsMoved, + this, + &TaskPipeScaling::indexesMoved); this->groupLayout()->addWidget(proxy); PartDesign::Pipe* pipe = static_cast(PipeView->getObject()); - for (auto &subSet : pipe->Sections.getSubListValues()) { + for (auto& subSet : pipe->Sections.getSubListValues()) { Gui::Application::Instance->showViewProvider(subSet.first); QString label = make2DLabel(subSet.first, subSet.second); QListWidgetItem* item = new QListWidgetItem(); @@ -858,8 +924,10 @@ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QW ui->comboBoxScaling->setCurrentIndex(pipe->Transformation.getValue()); // should be called after panel has become visible - QMetaObject::invokeMethod(this, "updateUI", Qt::QueuedConnection, - Q_ARG(int,pipe->Transformation.getValue())); + QMetaObject::invokeMethod(this, + "updateUI", + Qt::QueuedConnection, + Q_ARG(int, pipe->Transformation.getValue())); this->blockSelection(false); } @@ -916,8 +984,9 @@ void TaskPipeScaling::onScalingChanged(int idx) void TaskPipeScaling::onSelectionChanged(const SelectionChanges& msg) { - if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) { return; + } if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { @@ -925,14 +994,18 @@ void TaskPipeScaling::onSelectionChanged(const SelectionChanges& msg) App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = make2DLabel(object, {msg.pSubName}); - if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSectionAdd) { + if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refSectionAdd) { QListWidgetItem* item = new QListWidgetItem(); item->setText(label); - item->setData(Qt::UserRole, - QVariant::fromValue(std::make_pair(object, std::vector(1, msg.pSubName)))); + item->setData( + Qt::UserRole, + QVariant::fromValue( + std::make_pair(object, std::vector(1, msg.pSubName)))); ui->listWidgetReferences->addItem(item); } - else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSectionRemove) { + else if (stateHandler->getSelectionMode() + == StateHandlerTaskPipe::SelectionModes::refSectionRemove) { removeFromListWidget(ui->listWidgetReferences, label); } } @@ -949,26 +1022,29 @@ bool TaskPipeScaling::referenceSelected(const SelectionChanges& msg) const { auto selectionMode = stateHandler->getSelectionMode(); - if ((msg.Type == Gui::SelectionChanges::AddSelection) && - ((selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionAdd) || - (selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionRemove))) { - if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0) + if ((msg.Type == Gui::SelectionChanges::AddSelection) + && ((selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionAdd) + || (selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionRemove))) { + if (strcmp(msg.pDocName, getObject()->getDocument()->getName()) != 0) { return false; + } // not allowed to reference ourself const char* fname = getObject()->getNameInDocument(); - if (strcmp(msg.pObjectName, fname) == 0) + if (strcmp(msg.pObjectName, fname) == 0) { return false; + } - //change the references + // change the references if (auto pipe = getObject()) { std::vector refs = pipe->Sections.getValues(); App::DocumentObject* obj = pipe->getDocument()->getObject(msg.pObjectName); - std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + std::vector::iterator f = + std::find(refs.begin(), refs.end(), obj); if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionAdd) { if (f != refs.end()) { - return false; // duplicate selection + return false; // duplicate selection } pipe->Sections.addValue(obj, {msg.pSubName}); @@ -1007,13 +1083,16 @@ void TaskPipeScaling::onDeleteSection() int row = ui->listWidgetReferences->currentRow(); QListWidgetItem* item = ui->listWidgetReferences->takeItem(row); if (item) { - QByteArray data(item->data(Qt::UserRole).value().first->getNameInDocument()); + QByteArray data(item->data(Qt::UserRole) + .value() + .first->getNameInDocument()); delete item; if (auto pipe = getObject()) { std::vector refs = pipe->Sections.getValues(); App::DocumentObject* obj = pipe->getDocument()->getObject(data.constData()); - std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); + std::vector::iterator f = + std::find(refs.begin(), refs.end(), obj); if (f != refs.end()) { pipe->Sections.removeValue(obj); @@ -1026,12 +1105,15 @@ void TaskPipeScaling::onDeleteSection() void TaskPipeScaling::updateUI(int idx) { - //make sure we resize to the size of the current page - for (int i=0; istackedWidget->count(); ++i) + // make sure we resize to the size of the current page + for (int i = 0; i < ui->stackedWidget->count(); ++i) { ui->stackedWidget->widget(i)->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); + } - if (idx < ui->stackedWidget->count()) - ui->stackedWidget->widget(idx)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + if (idx < ui->stackedWidget->count()) { + ui->stackedWidget->widget(idx)->setSizePolicy(QSizePolicy::Expanding, + QSizePolicy::Expanding); + } } @@ -1040,13 +1122,13 @@ void TaskPipeScaling::updateUI(int idx) // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -TaskDlgPipeParameters::TaskDlgPipeParameters(ViewProviderPipe *PipeView,bool newObj) - : TaskDlgSketchBasedParameters(PipeView) +TaskDlgPipeParameters::TaskDlgPipeParameters(ViewProviderPipe* PipeView, bool newObj) + : TaskDlgSketchBasedParameters(PipeView) { assert(PipeView); - parameter = new TaskPipeParameters(PipeView,newObj); - orientation = new TaskPipeOrientation(PipeView,newObj); - scaling = new TaskPipeScaling(PipeView,newObj); + parameter = new TaskPipeParameters(PipeView, newObj); + orientation = new TaskPipeOrientation(PipeView, newObj); + scaling = new TaskPipeScaling(PipeView, newObj); stateHandler = new StateHandlerTaskPipe(); @@ -1061,29 +1143,24 @@ TaskDlgPipeParameters::TaskDlgPipeParameters(ViewProviderPipe *PipeView,bool new buttonGroup = new ButtonGroup(this); buttonGroup->setExclusive(true); - buttonGroup->addButton(parameter->ui->buttonProfileBase, - StateHandlerTaskPipe::refProfile); - buttonGroup->addButton(parameter->ui->buttonSpineBase, - StateHandlerTaskPipe::refSpine); - buttonGroup->addButton(parameter->ui->buttonRefAdd, - StateHandlerTaskPipe::refSpineEdgeAdd); + buttonGroup->addButton(parameter->ui->buttonProfileBase, StateHandlerTaskPipe::refProfile); + buttonGroup->addButton(parameter->ui->buttonSpineBase, StateHandlerTaskPipe::refSpine); + buttonGroup->addButton(parameter->ui->buttonRefAdd, StateHandlerTaskPipe::refSpineEdgeAdd); buttonGroup->addButton(parameter->ui->buttonRefRemove, StateHandlerTaskPipe::refSpineEdgeRemove); - buttonGroup->addButton(orientation->ui->buttonProfileBase, - StateHandlerTaskPipe::refAuxSpine); - buttonGroup->addButton(orientation->ui->buttonRefAdd, - StateHandlerTaskPipe::refAuxSpineEdgeAdd); + buttonGroup->addButton(orientation->ui->buttonProfileBase, StateHandlerTaskPipe::refAuxSpine); + buttonGroup->addButton(orientation->ui->buttonRefAdd, StateHandlerTaskPipe::refAuxSpineEdgeAdd); buttonGroup->addButton(orientation->ui->buttonRefRemove, StateHandlerTaskPipe::refAuxSpineEdgeRemove); - buttonGroup->addButton(scaling->ui->buttonRefAdd, - StateHandlerTaskPipe::refSectionAdd); - buttonGroup->addButton(scaling->ui->buttonRefRemove, - StateHandlerTaskPipe::refSectionRemove); + buttonGroup->addButton(scaling->ui->buttonRefAdd, StateHandlerTaskPipe::refSectionAdd); + buttonGroup->addButton(scaling->ui->buttonRefRemove, StateHandlerTaskPipe::refSectionRemove); - connect(buttonGroup, qOverload(&QButtonGroup::buttonToggled), - this, &TaskDlgPipeParameters::onButtonToggled); + connect(buttonGroup, + qOverload(&QButtonGroup::buttonToggled), + this, + &TaskDlgPipeParameters::onButtonToggled); } TaskDlgPipeParameters::~TaskDlgPipeParameters() @@ -1091,41 +1168,46 @@ TaskDlgPipeParameters::~TaskDlgPipeParameters() delete stateHandler; } -void TaskDlgPipeParameters::onButtonToggled(QAbstractButton *button, bool checked) +void TaskDlgPipeParameters::onButtonToggled(QAbstractButton* button, bool checked) { int id = buttonGroup->id(button); if (checked) { - //hideObject(); + // hideObject(); Gui::Selection().clearSelection(); stateHandler->selectionMode = static_cast(id); } else { Gui::Selection().clearSelection(); - if (stateHandler->selectionMode == static_cast(id)) + if (stateHandler->selectionMode == static_cast(id)) { stateHandler->selectionMode = StateHandlerTaskPipe::SelectionModes::none; + } } switch (id) { - case StateHandlerTaskPipe::SelectionModes::refProfile: - getViewObject()->highlightReferences(ViewProviderPipe::Profile, checked); - break; - case StateHandlerTaskPipe::SelectionModes::refSpine: - case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd: - case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: - getViewObject()->highlightReferences(ViewProviderPipe::Spine, checked); - break; - case StateHandlerTaskPipe::SelectionModes::refAuxSpine: - case StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd: - case StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove: - getViewObject()->highlightReferences(ViewProviderPipe::AuxiliarySpine, checked); - break; - case StateHandlerTaskPipe::SelectionModes::refSectionAdd: - case StateHandlerTaskPipe::SelectionModes::refSectionRemove: - getViewObject()->highlightReferences(ViewProviderPipe::Section, checked); - break; - default: - break; + case StateHandlerTaskPipe::SelectionModes::refProfile: + getViewObject()->highlightReferences(ViewProviderPipe::Profile, + checked); + break; + case StateHandlerTaskPipe::SelectionModes::refSpine: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: + getViewObject()->highlightReferences(ViewProviderPipe::Spine, + checked); + break; + case StateHandlerTaskPipe::SelectionModes::refAuxSpine: + case StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd: + case StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove: + getViewObject()->highlightReferences(ViewProviderPipe::AuxiliarySpine, + checked); + break; + case StateHandlerTaskPipe::SelectionModes::refSectionAdd: + case StateHandlerTaskPipe::SelectionModes::refSectionRemove: + getViewObject()->highlightReferences(ViewProviderPipe::Section, + checked); + break; + default: + break; } } diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index 4cda76ead3..f61dd922dd 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -24,7 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +#include #endif #include @@ -45,6 +45,7 @@ using namespace PartDesignGui; +// clang-format off TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) : TaskBox(QPixmap(),tr("Primitive parameters"), true, parent) , ui(new Ui_DlgPrimitives) @@ -367,24 +368,26 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) connect(ui->wedgeZ2min, qOverload(&Gui::QuantitySpinBox::valueChanged), this, &TaskBoxPrimitives::onWedgeZ2minChanged); } +// clang-format on /* * Destroys the object and frees any allocated resources */ TaskBoxPrimitives::~TaskBoxPrimitives() { - //hide the parts coordinate system axis for selection + // hide the parts coordinate system axis for selection try { auto obj = getObject(); - if (PartDesign::Body * body = obj ? PartDesign::Body::findBodyOf(obj) : nullptr) { - App::Origin *origin = body->getOrigin(); + if (PartDesign::Body* body = obj ? PartDesign::Body::findBodyOf(obj) : nullptr) { + App::Origin* origin = body->getOrigin(); Gui::ViewProviderOrigin* vpOrigin; - vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + vpOrigin = static_cast( + Gui::Application::Instance->getViewProvider(origin)); vpOrigin->resetTemporaryVisibility(); } } - catch (const Base::Exception &ex) { - Base::Console().Error ("%s\n", ex.what () ); + catch (const Base::Exception& ex) { + Base::Console().Error("%s\n", ex.what()); } } @@ -452,10 +455,12 @@ void TaskBoxPrimitives::onCylinderXSkewChanged(double v) cyl->FirstAngle.setValue(v); } else { - if (v == 90.0) + if (v == 90.0) { cyl->FirstAngle.setValue(cyl->FirstAngle.getMaximum()); - else if (v == -90.0) + } + else if (v == -90.0) { cyl->FirstAngle.setValue(cyl->FirstAngle.getMinimum()); + } ui->cylinderXSkew->setValue(cyl->FirstAngle.getQuantityValue()); } cyl->recomputeFeature(); @@ -471,10 +476,12 @@ void TaskBoxPrimitives::onCylinderYSkewChanged(double v) cyl->SecondAngle.setValue(v); } else { - if (v == 90.0) + if (v == 90.0) { cyl->SecondAngle.setValue(cyl->SecondAngle.getMaximum()); - else if (v == -90.0) + } + else if (v == -90.0) { cyl->SecondAngle.setValue(cyl->SecondAngle.getMinimum()); + } ui->cylinderYSkew->setValue(cyl->SecondAngle.getQuantityValue()); } cyl->recomputeFeature(); @@ -484,7 +491,7 @@ void TaskBoxPrimitives::onCylinderYSkewChanged(double v) void TaskBoxPrimitives::onSphereAngle1Changed(double v) { if (auto sph = getObject()) { - ui->sphereAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 + ui->sphereAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 sph->Angle1.setValue(v); sph->recomputeFeature(); } @@ -493,7 +500,7 @@ void TaskBoxPrimitives::onSphereAngle1Changed(double v) void TaskBoxPrimitives::onSphereAngle2Changed(double v) { if (auto sph = getObject()) { - ui->sphereAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 + ui->sphereAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 sph->Angle2.setValue(v); sph->recomputeFeature(); } @@ -507,7 +514,7 @@ void TaskBoxPrimitives::onSphereAngle3Changed(double v) } } -void TaskBoxPrimitives::onSphereRadiusChanged(double v) +void TaskBoxPrimitives::onSphereRadiusChanged(double v) { if (auto sph = getObject()) { sph->Radius.setValue(v); @@ -550,7 +557,7 @@ void TaskBoxPrimitives::onConeRadius2Changed(double v) void TaskBoxPrimitives::onEllipsoidAngle1Changed(double v) { if (auto ell = getObject()) { - ui->ellipsoidAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 + ui->ellipsoidAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 ell->Angle1.setValue(v); ell->recomputeFeature(); } @@ -559,7 +566,7 @@ void TaskBoxPrimitives::onEllipsoidAngle1Changed(double v) void TaskBoxPrimitives::onEllipsoidAngle2Changed(double v) { if (auto ell = getObject()) { - ui->ellipsoidAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle22 + ui->ellipsoidAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle22 ell->Angle2.setValue(v); ell->recomputeFeature(); } @@ -600,7 +607,7 @@ void TaskBoxPrimitives::onEllipsoidRadius3Changed(double v) void TaskBoxPrimitives::onTorusAngle1Changed(double v) { if (auto tor = getObject()) { - ui->torusAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 + ui->torusAngle2->setMinimum(v); // Angle1 must geometrically be <= than Angle2 tor->Angle1.setValue(v); tor->recomputeFeature(); } @@ -609,7 +616,7 @@ void TaskBoxPrimitives::onTorusAngle1Changed(double v) void TaskBoxPrimitives::onTorusAngle2Changed(double v) { if (auto tor = getObject()) { - ui->torusAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 + ui->torusAngle1->setMaximum(v); // Angle1 must geometrically be <= than Angle2 tor->Angle2.setValue(v); tor->recomputeFeature(); } @@ -669,10 +676,12 @@ void TaskBoxPrimitives::onPrismXSkewChanged(double v) prim->FirstAngle.setValue(v); } else { - if (v == 90.0) + if (v == 90.0) { prim->FirstAngle.setValue(89.99999); - else if (v == -90.0) + } + else if (v == -90.0) { prim->FirstAngle.setValue(-89.99999); + } ui->prismXSkew->setValue(prim->FirstAngle.getQuantityValue()); } prim->recomputeFeature(); @@ -688,10 +697,12 @@ void TaskBoxPrimitives::onPrismYSkewChanged(double v) prim->SecondAngle.setValue(v); } else { - if (v == 90.0) + if (v == 90.0) { prim->SecondAngle.setValue(89.99999); - else if (v == -90.0) + } + else if (v == -90.0) { prim->SecondAngle.setValue(-89.99999); + } ui->prismYSkew->setValue(prim->SecondAngle.getQuantityValue()); } prim->recomputeFeature(); @@ -709,7 +720,7 @@ void TaskBoxPrimitives::onPrismPolygonChanged(int v) void TaskBoxPrimitives::onWedgeX2minChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeX2max->setMinimum(v); // wedgeX2min must be <= than wedgeX2max + ui->wedgeX2max->setMinimum(v); // wedgeX2min must be <= than wedgeX2max wedge->X2min.setValue(v); wedge->recomputeFeature(); } @@ -718,7 +729,7 @@ void TaskBoxPrimitives::onWedgeX2minChanged(double v) void TaskBoxPrimitives::onWedgeX2maxChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeX2min->setMaximum(v); // wedgeX2min must be <= than wedgeX2max + ui->wedgeX2min->setMaximum(v); // wedgeX2min must be <= than wedgeX2max wedge->X2max.setValue(v); wedge->recomputeFeature(); } @@ -736,7 +747,7 @@ void TaskBoxPrimitives::onWedgeXminChanged(double v) void TaskBoxPrimitives::onWedgeXmaxChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeXmin->setMaximum(v); // must be < than wedgeXmax + ui->wedgeXmin->setMaximum(v); // must be < than wedgeXmax wedge->Xmax.setValue(v); wedge->recomputeFeature(); } @@ -745,7 +756,7 @@ void TaskBoxPrimitives::onWedgeXmaxChanged(double v) void TaskBoxPrimitives::onWedgeYminChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeYmax->setMinimum(v); // must be > than wedgeYmin + ui->wedgeYmax->setMinimum(v); // must be > than wedgeYmin wedge->Ymin.setValue(v); wedge->recomputeFeature(); } @@ -754,7 +765,7 @@ void TaskBoxPrimitives::onWedgeYminChanged(double v) void TaskBoxPrimitives::onWedgeYmaxChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeYmin->setMaximum(v); // must be < than wedgeYmax + ui->wedgeYmin->setMaximum(v); // must be < than wedgeYmax wedge->Ymax.setValue(v); wedge->recomputeFeature(); } @@ -763,7 +774,7 @@ void TaskBoxPrimitives::onWedgeYmaxChanged(double v) void TaskBoxPrimitives::onWedgeZ2minChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeZ2max->setMinimum(v); // must be >= than wedgeZ2min + ui->wedgeZ2max->setMinimum(v); // must be >= than wedgeZ2min wedge->Z2min.setValue(v); wedge->recomputeFeature(); } @@ -772,7 +783,7 @@ void TaskBoxPrimitives::onWedgeZ2minChanged(double v) void TaskBoxPrimitives::onWedgeZ2maxChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeZ2min->setMaximum(v); // must be <= than wedgeZ2max + ui->wedgeZ2min->setMaximum(v); // must be <= than wedgeZ2max wedge->Z2max.setValue(v); wedge->recomputeFeature(); } @@ -781,7 +792,7 @@ void TaskBoxPrimitives::onWedgeZ2maxChanged(double v) void TaskBoxPrimitives::onWedgeZminChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeZmax->setMinimum(v); // must be > than wedgeZmin + ui->wedgeZmax->setMinimum(v); // must be > than wedgeZmin wedge->Zmin.setValue(v); wedge->recomputeFeature(); } @@ -790,14 +801,14 @@ void TaskBoxPrimitives::onWedgeZminChanged(double v) void TaskBoxPrimitives::onWedgeZmaxChanged(double v) { if (auto wedge = getObject()) { - ui->wedgeZmin->setMaximum(v); // must be < than wedgeZmax + ui->wedgeZmin->setMaximum(v); // must be < than wedgeZmax wedge->Zmax.setValue(v); wedge->recomputeFeature(); } } -bool TaskBoxPrimitives::setPrimitive(App::DocumentObject *obj) +bool TaskBoxPrimitives::setPrimitive(App::DocumentObject* obj) { try { QString name(QString::fromLatin1(Gui::Command::getObjectCmd(obj).c_str())); @@ -808,142 +819,137 @@ bool TaskBoxPrimitives::setPrimitive(App::DocumentObject *obj) } Base::QuantityFormat format(Base::QuantityFormat::Fixed, Base::UnitsApi::getDecimals()); - switch(ui->widgetStack->currentIndex()) { - case 1: // box - cmd = QString::fromLatin1( - "%1.Length='%2'\n" - "%1.Width='%3'\n" - "%1.Height='%4'\n") - .arg(name, - ui->boxLength->value().getSafeUserString(), - ui->boxWidth->value().getSafeUserString(), - ui->boxHeight->value().getSafeUserString()); + switch (ui->widgetStack->currentIndex()) { + case 1: // box + cmd = QString::fromLatin1("%1.Length='%2'\n" + "%1.Width='%3'\n" + "%1.Height='%4'\n") + .arg(name, + ui->boxLength->value().getSafeUserString(), + ui->boxWidth->value().getSafeUserString(), + ui->boxHeight->value().getSafeUserString()); break; case 2: // cylinder - cmd = QString::fromLatin1( - "%1.Radius='%2'\n" - "%1.Height='%3'\n" - "%1.Angle='%4'\n" - "%1.FirstAngle='%5'\n" - "%1.SecondAngle='%6'\n") - .arg(name, - ui->cylinderRadius->value().getSafeUserString(), - ui->cylinderHeight->value().getSafeUserString(), - ui->cylinderAngle->value().getSafeUserString(), - ui->cylinderXSkew->value().getSafeUserString(), - ui->cylinderYSkew->value().getSafeUserString()); + cmd = QString::fromLatin1("%1.Radius='%2'\n" + "%1.Height='%3'\n" + "%1.Angle='%4'\n" + "%1.FirstAngle='%5'\n" + "%1.SecondAngle='%6'\n") + .arg(name, + ui->cylinderRadius->value().getSafeUserString(), + ui->cylinderHeight->value().getSafeUserString(), + ui->cylinderAngle->value().getSafeUserString(), + ui->cylinderXSkew->value().getSafeUserString(), + ui->cylinderYSkew->value().getSafeUserString()); break; case 3: // cone - cmd = QString::fromLatin1( - "%1.Radius1='%2'\n" - "%1.Radius2='%3'\n" - "%1.Height='%4'\n" - "%1.Angle='%5'\n") - .arg(name, - ui->coneRadius1->value().getSafeUserString(), - ui->coneRadius2->value().getSafeUserString(), - ui->coneHeight->value().getSafeUserString(), - ui->coneAngle->value().getSafeUserString()); - break; + cmd = QString::fromLatin1("%1.Radius1='%2'\n" + "%1.Radius2='%3'\n" + "%1.Height='%4'\n" + "%1.Angle='%5'\n") + .arg(name, + ui->coneRadius1->value().getSafeUserString(), + ui->coneRadius2->value().getSafeUserString(), + ui->coneHeight->value().getSafeUserString(), + ui->coneAngle->value().getSafeUserString()); + break; case 4: // sphere - cmd = QString::fromLatin1( - "%1.Radius='%2'\n" - "%1.Angle1='%3'\n" - "%1.Angle2='%4'\n" - "%1.Angle3='%5'\n") - .arg(name, - ui->sphereRadius->value().getSafeUserString(), - ui->sphereAngle1->value().getSafeUserString(), - ui->sphereAngle2->value().getSafeUserString(), - ui->sphereAngle3->value().getSafeUserString()); + cmd = QString::fromLatin1("%1.Radius='%2'\n" + "%1.Angle1='%3'\n" + "%1.Angle2='%4'\n" + "%1.Angle3='%5'\n") + .arg(name, + ui->sphereRadius->value().getSafeUserString(), + ui->sphereAngle1->value().getSafeUserString(), + ui->sphereAngle2->value().getSafeUserString(), + ui->sphereAngle3->value().getSafeUserString()); break; case 5: // ellipsoid - cmd = QString::fromLatin1( - "%1.Radius1='%2'\n" - "%1.Radius2='%3'\n" - "%1.Radius3='%4'\n" - "%1.Angle1='%5'\n" - "%1.Angle2='%6'\n" - "%1.Angle3='%7'\n") - .arg(name, - ui->ellipsoidRadius1->value().getSafeUserString(), - ui->ellipsoidRadius2->value().getSafeUserString(), - ui->ellipsoidRadius3->value().getSafeUserString(), - ui->ellipsoidAngle1->value().getSafeUserString(), - ui->ellipsoidAngle2->value().getSafeUserString(), - ui->ellipsoidAngle3->value().getSafeUserString()); + cmd = QString::fromLatin1("%1.Radius1='%2'\n" + "%1.Radius2='%3'\n" + "%1.Radius3='%4'\n" + "%1.Angle1='%5'\n" + "%1.Angle2='%6'\n" + "%1.Angle3='%7'\n") + .arg(name, + ui->ellipsoidRadius1->value().getSafeUserString(), + ui->ellipsoidRadius2->value().getSafeUserString(), + ui->ellipsoidRadius3->value().getSafeUserString(), + ui->ellipsoidAngle1->value().getSafeUserString(), + ui->ellipsoidAngle2->value().getSafeUserString(), + ui->ellipsoidAngle3->value().getSafeUserString()); break; case 6: // torus - cmd = QString::fromLatin1( - "%1.Radius1='%2'\n" - "%1.Radius2='%3'\n" - "%1.Angle1='%4'\n" - "%1.Angle2='%5'\n" - "%1.Angle3='%6'\n") - .arg(name, - ui->torusRadius1->value().getSafeUserString(), - ui->torusRadius2->value().getSafeUserString(), - ui->torusAngle1->value().getSafeUserString(), - ui->torusAngle2->value().getSafeUserString(), - ui->torusAngle3->value().getSafeUserString()); + cmd = QString::fromLatin1("%1.Radius1='%2'\n" + "%1.Radius2='%3'\n" + "%1.Angle1='%4'\n" + "%1.Angle2='%5'\n" + "%1.Angle3='%6'\n") + .arg(name, + ui->torusRadius1->value().getSafeUserString(), + ui->torusRadius2->value().getSafeUserString(), + ui->torusAngle1->value().getSafeUserString(), + ui->torusAngle2->value().getSafeUserString(), + ui->torusAngle3->value().getSafeUserString()); break; case 7: // prism - cmd = QString::fromLatin1( - "%1.Polygon=%2\n" - "%1.Circumradius='%3'\n" - "%1.Height='%4'\n" - "%1.FirstAngle='%5'\n" - "%1.SecondAngle='%6'\n") - .arg(name, - QString::number(ui->prismPolygon->value()), - ui->prismCircumradius->value().getSafeUserString(), - ui->prismHeight->value().getSafeUserString(), - ui->prismXSkew->value().getSafeUserString(), - ui->prismYSkew->value().getSafeUserString()); + cmd = QString::fromLatin1("%1.Polygon=%2\n" + "%1.Circumradius='%3'\n" + "%1.Height='%4'\n" + "%1.FirstAngle='%5'\n" + "%1.SecondAngle='%6'\n") + .arg(name, + QString::number(ui->prismPolygon->value()), + ui->prismCircumradius->value().getSafeUserString(), + ui->prismHeight->value().getSafeUserString(), + ui->prismXSkew->value().getSafeUserString(), + ui->prismYSkew->value().getSafeUserString()); break; case 8: // wedge // Xmin/max, Ymin/max and Zmin/max must each not be equal if (ui->wedgeXmin->value().getValue() == ui->wedgeXmax->value().getValue()) { - QMessageBox::warning(Gui::getMainWindow(), tr("Invalid wedge parameters"), - tr("X min must not be equal to X max!")); + QMessageBox::warning(Gui::getMainWindow(), + tr("Invalid wedge parameters"), + tr("X min must not be equal to X max!")); return false; } else if (ui->wedgeYmin->value().getValue() == ui->wedgeYmax->value().getValue()) { - QMessageBox::warning(Gui::getMainWindow(), tr("Invalid wedge parameters"), - tr("Y min must not be equal to Y max!")); + QMessageBox::warning(Gui::getMainWindow(), + tr("Invalid wedge parameters"), + tr("Y min must not be equal to Y max!")); return false; } else if (ui->wedgeZmin->value().getValue() == ui->wedgeZmax->value().getValue()) { - QMessageBox::warning(Gui::getMainWindow(), tr("Invalid wedge parameters"), - tr("Z min must not be equal to Z max!")); + QMessageBox::warning(Gui::getMainWindow(), + tr("Invalid wedge parameters"), + tr("Z min must not be equal to Z max!")); return false; } - cmd = QString::fromLatin1( - "%1.Xmin='%2'\n" - "%1.Ymin='%3'\n" - "%1.Zmin='%4'\n" - "%1.X2min='%5'\n" - "%1.Z2min='%6'\n" - "%1.Xmax='%7'\n" - "%1.Ymax='%8'\n" - "%1.Zmax='%9'\n" - "%1.X2max='%10'\n" - "%1.Z2max='%11'\n") - .arg(name, - ui->wedgeXmin->value().getSafeUserString(), - ui->wedgeYmin->value().getSafeUserString(), - ui->wedgeZmin->value().getSafeUserString(), - ui->wedgeX2min->value().getSafeUserString(), - ui->wedgeZ2min->value().getSafeUserString(), - ui->wedgeXmax->value().getSafeUserString(), - ui->wedgeYmax->value().getSafeUserString(), - ui->wedgeZmax->value().getSafeUserString()) - .arg(ui->wedgeX2max->value().getSafeUserString(), - ui->wedgeZ2max->value().getSafeUserString()); + cmd = QString::fromLatin1("%1.Xmin='%2'\n" + "%1.Ymin='%3'\n" + "%1.Zmin='%4'\n" + "%1.X2min='%5'\n" + "%1.Z2min='%6'\n" + "%1.Xmax='%7'\n" + "%1.Ymax='%8'\n" + "%1.Zmax='%9'\n" + "%1.X2max='%10'\n" + "%1.Z2max='%11'\n") + .arg(name, + ui->wedgeXmin->value().getSafeUserString(), + ui->wedgeYmin->value().getSafeUserString(), + ui->wedgeZmin->value().getSafeUserString(), + ui->wedgeX2min->value().getSafeUserString(), + ui->wedgeZ2min->value().getSafeUserString(), + ui->wedgeXmax->value().getSafeUserString(), + ui->wedgeYmax->value().getSafeUserString(), + ui->wedgeZmax->value().getSafeUserString()) + .arg(ui->wedgeX2max->value().getSafeUserString(), + ui->wedgeZ2max->value().getSafeUserString()); break; default: @@ -957,13 +963,16 @@ bool TaskBoxPrimitives::setPrimitive(App::DocumentObject *obj) Gui::Command::runCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); } catch (const Base::PyException& e) { - QMessageBox::warning(this, tr("Create primitive"), QApplication::translate("Exception", e.what())); + QMessageBox::warning(this, + tr("Create primitive"), + QApplication::translate("Exception", e.what())); return false; } return true; } -TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* PrimitiveView) : vp_prm(PrimitiveView) +TaskPrimitiveParameters::TaskPrimitiveParameters(ViewProviderPrimitive* PrimitiveView) + : vp_prm(PrimitiveView) { assert(PrimitiveView); @@ -978,10 +987,11 @@ TaskPrimitiveParameters::~TaskPrimitiveParameters() = default; bool TaskPrimitiveParameters::accept() { bool primitiveOK = primitive->setPrimitive(vp_prm->getObject()); - if (!primitiveOK) + if (!primitiveOK) { return primitiveOK; - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + } + Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().resetEdit()"); return true; } @@ -990,7 +1000,7 @@ bool TaskPrimitiveParameters::reject() { // roll back the done things Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeDocument().resetEdit()"); return true; }