From 66e4c37a253044dc95ff5deca8b5bed6f33265e1 Mon Sep 17 00:00:00 2001 From: Uwe Date: Sun, 27 Mar 2022 21:38:15 +0200 Subject: [PATCH] fix some occurrences where size() is misused as Boolean - as suggested by @wwmayer: https://github.com/FreeCAD/FreeCAD/commit/4d51d1d0b1c2cd33cd443d477c60eb575fc0e52f#r69648152 --- src/Mod/Fem/Gui/Command.cpp | 2 +- src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp | 2 +- src/Mod/Part/Gui/SectionCutting.cpp | 2 +- src/Mod/Part/Gui/TaskAttacher.cpp | 3 ++- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 2 +- src/Mod/PartDesign/App/ShapeBinder.cpp | 16 ++++++++-------- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Mod/Fem/Gui/Command.cpp b/src/Mod/Fem/Gui/Command.cpp index d2794e9404..da53fdc29d 100644 --- a/src/Mod/Fem/Gui/Command.cpp +++ b/src/Mod/Fem/Gui/Command.cpp @@ -1817,7 +1817,7 @@ void CmdFemPostPipelineFromResult::activated(int) Fem::FemAnalysis* pcAnalysis; std::string FeatName = getUniqueObjectName("ResultPipeline"); auto parents = results[0]->getInList(); - if (parents.size()) { + if (!parents.empty()) { for (auto parentObject : parents) { if (parentObject->getTypeId() == Base::Type::fromName("Fem::FemAnalysis")) { pcAnalysis = static_cast(parentObject); diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp index 90114c8864..b49ae2a32d 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostObject.cpp @@ -430,7 +430,7 @@ void ViewProviderFemPostObject::WritePointData(vtkPoints* points, vtkDataArray* // we must inherit the Scale of parent meshes (for example for clip filters) auto parents = pcObject->getInList(); - if (parents.size()) { + if (!parents.empty()) { for (auto itParents = parents.begin(); itParents != parents.end(); ++itParents) { if ((*itParents)->getTypeId() == Base::Type::fromName("Fem::FemPostPipeline")) { auto vpObject = dynamic_cast( diff --git a/src/Mod/Part/Gui/SectionCutting.cpp b/src/Mod/Part/Gui/SectionCutting.cpp index b0400e3928..31e4b99714 100644 --- a/src/Mod/Part/Gui/SectionCutting.cpp +++ b/src/Mod/Part/Gui/SectionCutting.cpp @@ -513,7 +513,7 @@ void SectionCut::startCutting(bool isInitial) // if the object is part of an App::Part container, the link needs to get the container placement auto parents = (*itCuts)->getInList(); - if (parents.size()) { + if (!parents.empty()) { for (auto itParents = parents.begin(); itParents != parents.end(); ++itParents) { if ((*itParents)->getTypeId() == Base::Type::fromName("App::Part")) { App::Part* pcPartParent = static_cast((*itParents)); diff --git a/src/Mod/Part/Gui/TaskAttacher.cpp b/src/Mod/Part/Gui/TaskAttacher.cpp index 7a62eaa9dc..14884c2e23 100644 --- a/src/Mod/Part/Gui/TaskAttacher.cpp +++ b/src/Mod/Part/Gui/TaskAttacher.cpp @@ -972,7 +972,8 @@ void TaskAttacher::visibilityAutomation(bool opening_not_closing) QString::fromLatin1(editSubName.c_str()), QString::fromLatin1(postfix.c_str())); Gui::Command::runCommand(Gui::Command::Gui,code.toLatin1().constData()); - } else if(postfix.size()) { + } + else if (!postfix.empty()) { QString code = QString::fromLatin1( "_tv_%1.restore()\n" "del(_tv_%1)" diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 4b0f8ee208..bf8d9bc1b8 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -167,7 +167,7 @@ Part::Feature* ProfileBased::getVerifiedObject(bool silent) const { Part::TopoShape ProfileBased::getProfileShape() const { auto shape = getTopoShape(Profile.getValue()); - if (!shape.isNull() && Profile.getSubValues().size()) { + if (!shape.isNull() && !Profile.getSubValues().empty()) { std::vector shapes; for (auto& sub : Profile.getSubValues(true)) shapes.emplace_back(shape.getSubShape(sub.c_str())); diff --git a/src/Mod/PartDesign/App/ShapeBinder.cpp b/src/Mod/PartDesign/App/ShapeBinder.cpp index 2ddcfb63de..1d00a5d7bd 100644 --- a/src/Mod/PartDesign/App/ShapeBinder.cpp +++ b/src/Mod/PartDesign/App/ShapeBinder.cpp @@ -479,17 +479,17 @@ void SubShapeBinder::update(SubShapeBinder::UpdateOption options) { if(!Relative.getValue()) parent = nullptr; else { - if(parent && parent->getSubObject(parentSub.c_str())==this) { + if (parent && parent->getSubObject(parentSub.c_str())==this) { auto parents = parent->getParents(); - if(parents.size()) { + if (!parents.empty()) { parent = parents.begin()->first; parentSub = parents.begin()->second + parentSub; } } else parent = nullptr; - if(!parent && parentSub.empty()) { + if (!parent && parentSub.empty()) { auto parents = getParents(); - if(parents.size()) { + if(!parents.empty()) { parent = parents.begin()->first; parentSub = parents.begin()->second; } @@ -561,7 +561,7 @@ void SubShapeBinder::update(SubShapeBinder::UpdateOption options) { auto tmpDoc = App::GetApplication().newDocument( "_tmp_binder", nullptr, false, true); auto objs = tmpDoc->copyObject({obj},true,true); - if(objs.size()) { + if (!objs.empty()) { for(auto it=objs.rbegin(); it!=objs.rend(); ++it) _CopiedObjs.emplace_back(*it); copied = objs.back(); @@ -648,7 +648,7 @@ void SubShapeBinder::update(SubShapeBinder::UpdateOption options) { if(!init) { - if(errMsg.size()) { + if (!errMsg.empty()) { if(!(options & UpdateInit)) FC_THROWM(Base::RuntimeError, errMsg); if(!Shape.getValue().IsNull()) @@ -706,7 +706,7 @@ void SubShapeBinder::update(SubShapeBinder::UpdateOption options) { else solids.push_back(s.getShape()); } - if(solids.size()) { + if (!solids.empty()) { result = solid.fuse(solids); fused = true; } else if (!solid.isNull()) { @@ -819,7 +819,7 @@ void SubShapeBinder::onChanged(const App::Property *prop) { if(prop == &Support) { clearCopiedObjects(); setupCopyOnChange(); - if(Support.getSubListValues().size()) { + if (!Support.getSubListValues().empty()) { update(); if(BindMode.getValue() == 2) Support.setValue(nullptr);