PartDesign: apply std::ranges

This commit is contained in:
bofdahof
2025-03-12 20:01:50 +10:00
committed by Chris Hennes
parent 2e2f872da6
commit 965af2bf9a
13 changed files with 60 additions and 71 deletions

View File

@@ -353,7 +353,7 @@ std::vector<App::DocumentObject*> Body::removeObject(App::DocumentObject* featur
}
std::vector<App::DocumentObject*> model = Group.getValues();
std::vector<App::DocumentObject*>::iterator it = std::find(model.begin(), model.end(), feature);
const auto it = std::ranges::find(model, feature);
// Adjust Tip feature if it is pointing to the deleted object
if (Tip.getValue()== feature) {

View File

@@ -158,7 +158,7 @@ void DressUp::getContinuousEdges(Part::TopoShape TopShape, std::vector< std::str
buf << "Edge";
buf << id;
if(std::find(SubNames.begin(),SubNames.end(),buf.str()) == SubNames.end())
if (std::ranges::find(SubNames, buf.str()) == SubNames.end())
{
SubNames.push_back(buf.str());
}

View File

@@ -72,11 +72,11 @@ Loft::getSectionShape(const char *name,
size_t expected_size)
{
std::vector<TopoShape> shapes;
// Be smart. If part of a sketch is selected, use the entire sketch unless it is a single vertex -
// Be smart. If part of a sketch is selected, use the entire sketch unless it is a single vertex -
// backward compatibility (#16630)
auto subName = subs.empty() ? "" : subs.front();
auto useEntireSketch = obj->isDerivedFrom<Part::Part2DObject>() && subName.find("Vertex") != 0;
if (subs.empty() || std::find(subs.begin(), subs.end(), std::string()) != subs.end() || useEntireSketch ) {
if (subs.empty() || std::ranges::find(subs, std::string()) != subs.end() || useEntireSketch ) {
shapes.push_back(Part::Feature::getTopoShape(obj));
if (shapes.back().isNull())
FC_THROWM(Part::NullShapeException, "Failed to get shape of "

View File

@@ -317,8 +317,7 @@ void ShapeBinder::slotChangedObject(const App::DocumentObject& Obj, const App::P
list = obj->getInListRecursive();
chain.insert(chain.end(), list.begin(), list.end());
auto it = std::find(chain.begin(), chain.end(), &Obj);
if (it != chain.end()) {
if (const auto it = std::ranges::find(chain, &Obj); it != chain.end()) {
if (hasPlacementChanged()) {
enforceRecompute();
}

View File

@@ -379,16 +379,16 @@ void CmdPartDesignMigrate::activated(int iMsg)
featIt = baseFeatSetIt;
continue;
} else {
// The base feature seems already assigned to some chain
// Find which
// The base feature seems already assigned to some chain. Find which
std::list<PartDesign::Feature *>::iterator baseFeatIt;
auto chainIt = std::find_if( featureChains.begin(), featureChains.end(),
[baseFeat, &baseFeatIt] ( std::list<PartDesign::Feature *>&chain ) mutable -> bool {
baseFeatIt = std::find( chain.begin(), chain.end(), baseFeat );
return baseFeatIt != chain.end();
} );
auto isChain = [baseFeat, &baseFeatIt](
std::list<PartDesign::Feature*>& fchain) mutable -> bool {
baseFeatIt = std::ranges::find(fchain, baseFeat);
return baseFeatIt != fchain.end();
};
if ( chainIt != featureChains.end() ) {
if (auto chainIt = std::ranges::find_if(featureChains, isChain);
chainIt != featureChains.end() ) {
assert (baseFeatIt != chainIt->end());
if ( std::next ( baseFeatIt ) == chainIt->end() ) {
// just append our chain to already found

View File

@@ -136,7 +136,7 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
std::vector<App::DocumentObject*> bodies = pcBoolean->Group.getValues();
if (selectionMode == bodyAdd) {
if (std::find(bodies.begin(), bodies.end(), pcBody) == bodies.end()) {
if (std::ranges::find(bodies, pcBody) == bodies.end()) {
bodies.push_back(pcBody);
pcBoolean->Group.setValues(std::vector<App::DocumentObject*>());
pcBoolean->addObjects(bodies);
@@ -178,13 +178,11 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
}
}
else if (selectionMode == bodyRemove) {
std::vector<App::DocumentObject*>::iterator b =
std::find(bodies.begin(), bodies.end(), pcBody);
if (b != bodies.end()) {
if (const auto b = std::ranges::find(bodies, pcBody); b != bodies.end()) {
bodies.erase(b);
pcBoolean->setObjects(bodies);
QString internalName = QString::fromStdString(body);
const QString internalName = QString::fromStdString(body);
for (int row = 0; row < ui->listWidgetBodies->count(); row++) {
QListWidgetItem* item = ui->listWidgetBodies->item(row);
QString name = item->data(Qt::UserRole).toString();

View File

@@ -119,19 +119,19 @@ void TaskDressUpParameters::referenceSelected(const Gui::SelectionChanges& msg,
// TODO: Must we make a copy here instead of assigning to const char* ?
const char* fname = base->getNameInDocument();
if (strcmp(msg.pObjectName, fname) != 0)
if (strcmp(msg.pObjectName, fname) != 0) {
return;
}
std::string subName(msg.pSubName);
const std::string subName(msg.pSubName);
std::vector<std::string> refs = pcDressUp->Base.getSubValues();
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), subName);
if (f != refs.end()) { //If it's found then it's in the list so we remove it.
refs.erase(f);
if (const auto f = std::ranges::find(refs, subName); f != refs.end()) {
refs.erase(f); // it's in the list. Remove it
removeItemFromListWidget(widget, msg.pSubName);
}
else { //if it's not found then it's not yet in the list so we add it.
refs.push_back(subName);
else {
refs.push_back(subName); // not yet in the list so we add it
widget->addItem(QString::fromStdString(msg.pSubName));
}

View File

@@ -404,19 +404,18 @@ void TaskExtrudeParameters::selectedShapeFace(const Gui::SelectionChanges& msg)
}
std::vector<std::string> faces = getShapeFaces();
std::string subName(msg.pSubName);
const std::string subName(msg.pSubName);
if (subName.empty()) {
return;
}
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.
faces.erase(positionInList);
if (const auto positionInList = std::ranges::find(faces, subName);
positionInList != faces.end()) { // it's in the list
faces.erase(positionInList); // remove it.
}
else { // if it's not found then it's not yet in the list so we add it.
faces.push_back(subName);
else {
faces.push_back(subName); // not yet in the list so add it.
}
extrude->UpToShape.setValue(base, faces);

View File

@@ -29,6 +29,8 @@
#include <QTimer>
#endif
#include <ranges>
#include <fmt/format.h>
#include <App/Document.h>
@@ -555,9 +557,7 @@ void TaskFeaturePick::onDoubleClick(QListWidgetItem* item)
void TaskFeaturePick::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj)
{
std::vector<Gui::ViewProviderCoordinateSystem*>::iterator it;
it = std::find(origins.begin(), origins.end(), &Obj);
if (it != origins.end()) {
if (const auto it = std::ranges::find(origins, &Obj); it != origins.end()) {
origins.erase(it);
}
}

View File

@@ -214,11 +214,11 @@ bool TaskLoftParameters::referenceSelected(const Gui::SelectionChanges& msg) con
loft->Profile.setValue(obj, {msg.pSubName});
return true;
}
else if (selectionMode == refAdd || selectionMode == refRemove) {
if (selectionMode == refAdd || selectionMode == refRemove) {
// now check the sections
std::vector<App::DocumentObject*> refs = loft->Sections.getValues();
std::vector<App::DocumentObject*>::iterator f =
std::find(refs.begin(), refs.end(), obj);
const auto f = std::ranges::find(refs, obj);
if (selectionMode == refAdd) {
if (f != refs.end()) {
@@ -266,12 +266,10 @@ void TaskLoftParameters::onDeleteSection()
delete item;
// search inside the list of sections
if (auto loft = getObject<PartDesign::Loft>()) {
if (const auto loft = getObject<PartDesign::Loft>()) {
std::vector<App::DocumentObject*> refs = loft->Sections.getValues();
App::DocumentObject* obj = loft->getDocument()->getObject(data.constData());
std::vector<App::DocumentObject*>::iterator f =
std::find(refs.begin(), refs.end(), obj);
if (f != refs.end()) {
if (const auto f = std::ranges::find(refs, obj); f != refs.end()) {
loft->Sections.removeValue(obj);
recomputeFeature();

View File

@@ -294,13 +294,12 @@ void TaskPipeParameters::onDeleteEdge()
delete item;
// search inside the list of spines
auto pipe = getObject<PartDesign::Pipe>();
const auto pipe = getObject<PartDesign::Pipe>();
std::vector<std::string> refs = pipe->Spine.getSubValues();
std::string obj = data.constData();
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), obj);
const std::string obj = data.constData();
// if something was found, delete it and update the spine list
if (f != refs.end()) {
if (const auto f = std::ranges::find(refs, obj); f != refs.end()) {
refs.erase(f);
pipe->Spine.setValue(pipe->Spine.getValue(), refs);
clearButtons();
@@ -339,7 +338,7 @@ bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const
std::vector<App::DocumentObject*> sections = pipe->Sections.getValues();
// cannot use the same object for profile and section
if (std::find(sections.begin(), sections.end(), profile) != sections.end()) {
if (std::ranges::find(sections, profile) != sections.end()) {
success = false;
}
else {
@@ -358,10 +357,10 @@ bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const
case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd:
case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: {
// change the references
std::string subName(msg.pSubName);
auto pipe = getObject<PartDesign::Pipe>();
const std::string subName(msg.pSubName);
const auto pipe = getObject<PartDesign::Pipe>();
std::vector<std::string> refs = pipe->Spine.getSubValues();
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), subName);
const auto f = std::ranges::find(refs, subName);
if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpine) {
getViewObject<ViewProviderPipe>()->highlightReferences(ViewProviderPipe::Spine,
@@ -792,11 +791,11 @@ bool TaskPipeOrientation::referenceSelected(const SelectionChanges& msg) const
return false;
}
if (auto pipe = getObject<PartDesign::Pipe>()) {
if (const auto pipe = getObject<PartDesign::Pipe>()) {
// change the references
std::string subName(msg.pSubName);
const std::string subName(msg.pSubName);
std::vector<std::string> refs = pipe->AuxillerySpine.getSubValues();
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), subName);
const auto f = std::ranges::find(refs, subName);
if (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpine) {
refs.clear();
@@ -846,13 +845,12 @@ void TaskPipeOrientation::onDeleteItem()
delete item;
// search inside the list of spines
if (auto pipe = getObject<PartDesign::Pipe>()) {
if (const auto pipe = getObject<PartDesign::Pipe>()) {
std::vector<std::string> refs = pipe->AuxillerySpine.getSubValues();
std::string obj = data.constData();
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), obj);
const std::string obj = data.constData();
// if something was found, delete it and update the spine list
if (f != refs.end()) {
if (const auto f = std::ranges::find(refs, obj); f != refs.end()) {
refs.erase(f);
pipe->AuxillerySpine.setValue(pipe->AuxillerySpine.getValue(), refs);
clearButtons();
@@ -1048,11 +1046,10 @@ bool TaskPipeScaling::referenceSelected(const SelectionChanges& msg) const
}
// change the references
if (auto pipe = getObject<PartDesign::Pipe>()) {
if (const auto pipe = getObject<PartDesign::Pipe>()) {
std::vector<App::DocumentObject*> refs = pipe->Sections.getValues();
App::DocumentObject* obj = pipe->getDocument()->getObject(msg.pObjectName);
std::vector<App::DocumentObject*>::iterator f =
std::find(refs.begin(), refs.end(), obj);
const auto f = std::ranges::find(refs, obj);
if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionAdd) {
if (f != refs.end()) {
@@ -1100,13 +1097,11 @@ void TaskPipeScaling::onDeleteSection()
.first->getNameInDocument());
delete item;
if (auto pipe = getObject<PartDesign::Pipe>()) {
if (const auto pipe = getObject<PartDesign::Pipe>()) {
std::vector<App::DocumentObject*> refs = pipe->Sections.getValues();
App::DocumentObject* obj = pipe->getDocument()->getObject(data.constData());
std::vector<App::DocumentObject*>::iterator f =
std::find(refs.begin(), refs.end(), obj);
if (f != refs.end()) {
if (const auto f = std::ranges::find(refs.begin(), refs.end(), obj); f != refs.end()) {
pipe->Sections.removeValue(obj);
clearButtons();
recomputeFeature();

View File

@@ -204,11 +204,10 @@ void TaskShapeBinder::deleteItem()
PartDesign::ShapeBinder* binder = vp->getObject<PartDesign::ShapeBinder>();
PartDesign::ShapeBinder::getFilteredReferences(&binder->Support, obj, subs);
std::string subname = data.constData();
std::vector<std::string>::iterator it = std::find(subs.begin(), subs.end(), subname);
const std::string subname = data.constData();
// if something was found, delete it and update the support
if (it != subs.end()) {
if (const auto it = std::ranges::find(subs, subname); it != subs.end()) {
subs.erase(it);
binder->Support.setValue(obj, subs);
@@ -317,10 +316,11 @@ bool TaskShapeBinder::referenceSelected(const SelectionChanges& msg) const
if (selectionMode != refObjAdd) {
// ensure the new selected subref belongs to the same object
if (strcmp(msg.pObjectName, obj->getNameInDocument()) != 0)
if (strcmp(msg.pObjectName, obj->getNameInDocument()) != 0) {
return false;
}
std::vector<std::string>::iterator f = std::find(refs.begin(), refs.end(), subName);
const auto f = std::ranges::find(refs, subName);
if (selectionMode == refAdd) {
if (f == refs.end())

View File

@@ -238,7 +238,7 @@ bool TaskTransformedParameters::originalSelected(const Gui::SelectionChanges& ms
// Do the same like in TaskDlgTransformedParameters::accept() but without doCommand
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
auto or_iter = std::find(originals.begin(), originals.end(), selectedObject);
const auto or_iter = std::ranges::find(originals, selectedObject);
if (selectionMode == SelectionMode::AddFeature) {
if (or_iter == originals.end()) {
originals.push_back(selectedObject);