PartDesign: Prepare for clang-format (#16048)

* PartDesign: Prepare for clang-format

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
wwmayer
2024-09-02 17:48:26 +02:00
committed by GitHub
parent e88b1b49c9
commit e98ffc3060
13 changed files with 1286 additions and 899 deletions

View File

@@ -22,8 +22,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QSignalBlocker>
# include <QAction>
#include <QSignalBlocker>
#include <QAction>
#endif
#include <App/Document.h>
@@ -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<std::string> 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<double>(&Gui::PrefQuantitySpinBox::valueChanged),
this, &TaskExtrudeParameters::onLengthChanged);
this, &TaskExtrudeParameters::onLengthChanged);
connect(ui->lengthEdit2, qOverload<double>(&Gui::PrefQuantitySpinBox::valueChanged),
this, &TaskExtrudeParameters::onLength2Changed);
this, &TaskExtrudeParameters::onLength2Changed);
connect(ui->offsetEdit, qOverload<double>(&Gui::PrefQuantitySpinBox::valueChanged),
this, &TaskExtrudeParameters::onOffsetChanged);
this, &TaskExtrudeParameters::onOffsetChanged);
connect(ui->taperEdit, qOverload<double>(&Gui::PrefQuantitySpinBox::valueChanged),
this, &TaskExtrudeParameters::onTaperChanged);
this, &TaskExtrudeParameters::onTaperChanged);
connect(ui->taperEdit2, qOverload<double>(&Gui::PrefQuantitySpinBox::valueChanged),
this, &TaskExtrudeParameters::onTaper2Changed);
this, &TaskExtrudeParameters::onTaper2Changed);
connect(ui->directionCB, qOverload<int>(&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<double>(&QDoubleSpinBox::valueChanged),
this, &TaskExtrudeParameters::onXDirectionEditChanged);
this, &TaskExtrudeParameters::onXDirectionEditChanged);
connect(ui->YDirectionEdit, qOverload<double>(&QDoubleSpinBox::valueChanged),
this, &TaskExtrudeParameters::onYDirectionEditChanged);
this, &TaskExtrudeParameters::onYDirectionEditChanged);
connect(ui->ZDirectionEdit, qOverload<double>(&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<int>(&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<PartDesign::FeatureExtrude>();
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<ViewProviderExtrude>()->highlightShapeFaces(getShapeFaces());
break;
case SelectReferenceAxis:
onSelectReference(AllowSelection::EDGE | AllowSelection::PLANAR | AllowSelection::CIRCLE);
onSelectReference(AllowSelection::EDGE | AllowSelection::PLANAR
| AllowSelection::CIRCLE);
break;
default:
getViewObject<ViewProviderExtrude>()->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<std::string> PartDesignGui::TaskExtrudeParameters::getShapeFaces()
auto extrude = getObject<PartDesign::FeatureExtrude>();
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<PartDesign::ProfileBased>();
Part::Part2DObject* pcSketch = dynamic_cast<Part::Part2DObject*>(pcFeat->Profile.getValue());
Part::Part2DObject* pcSketch =
dynamic_cast<Part::Part2DObject*>(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<PartDesign::FeatureExtrude>();
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<std::string>(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<std::string>& sub) const
void TaskExtrudeParameters::getReferenceAxis(App::DocumentObject*& obj,
std::vector<std::string>& 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<PartDesign::ProfileBased>();
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());