Repository: FreeCAD/FreeCAD
File: src/Gui/Selection/Selection.cpp (C++)

Code before:

void SelectionSingleton::clearCompleteSelection(bool clearPreSelect)
{
    if(!_PickedList.empty()) {
        _PickedList.clear();
        notify(SelectionChanges(SelectionChanges::PickedListChanged));
    }

    if(clearPreSelect)
        rmvPreselect();

    if(_SelList.empty())
        return;

    if(!logDisabled)
        Application::Instance->macroManager()->addLine(MacroManager::Cmt,
                clearPreSelect?"Gui.Selection.clearSelection()"
                              :"Gui.Selection.clearSelection(False)");

    // Send the clear selection notification to all view providers associated with the
    // objects being deselected.

    std::set<ViewProvider*> viewProviders;
    for (_SelObj& sel : _SelList) {
        auto vp = Application::Instance->getViewProvider(sel.pObject);
        if (vp) {
            viewProviders.insert(vp);
        }
    }

    for (auto& vp : viewProviders) {
        SelectionChanges Chng(SelectionChanges::ClrSelection);
        vp->onSelectionChanged(Chng);
    }

    _SelList.clear();

    SelectionChanges Chng(SelectionChanges::ClrSelection);

    FC_LOG("Clear selection");

    notify(std::move(Chng));
    getMainWindow()->updateActions();
}

bool SelectionSingleton::isSelected(const char* pDocName, const char* pObjectName,
                                    const char* pSubName, ResolveMode resolve) const
{
    _SelObj sel;
    return checkSelection(pDocName, pObjectName, pSubName, resolve, sel, &_SelList) > 0;
}

Review comment (suggestion):
```suggestion
        if (auto vp = Application::Instance->getViewProvider(sel.pObject)) {
```

Code after:
            std::ostringstream ss;
            ss << "Gui.Selection.clearSelection('" << docName << "'";
            if (!clearPreSelect)
                ss << ", False";
            ss << ')';
            Application::Instance->macroManager()->addLine(MacroManager::Cmt,ss.str().c_str());
        }

        notify(SelectionChanges(SelectionChanges::ClrSelection,docName.c_str()));

        getMainWindow()->updateActions();
    }
}

void SelectionSingleton::clearCompleteSelection(bool clearPreSelect)
{
    if(!_PickedList.empty()) {
        _PickedList.clear();
        notify(SelectionChanges(SelectionChanges::PickedListChanged));
    }

    if(clearPreSelect)
        rmvPreselect();

    if(_SelList.empty())
        return;

    if(!logDisabled)
        Application::Instance->macroManager()->addLine(MacroManager::Cmt,
                clearPreSelect?"Gui.Selection.clearSelection()"
                              :"Gui.Selection.clearSelection(False)");

    // Send the clear selection notification to all view providers associated with the
    // objects being deselected.

    std::set<ViewProvider*> viewProviders;
    for (_SelObj& sel : _SelList) {
        if (auto vp = Application::Instance->getViewProvider(sel.pObject)) {
            viewProviders.insert(vp);
        }
    }

    for (auto& vp : viewProviders) {
        SelectionChanges Chng(SelectionChanges::ClrSelection);
        vp->onSelectionChanged(Chng);
    }

    _SelList.clear();

    SelectionChanges Chng(SelectionChanges::ClrSelection);