diff --git a/src/Gui/Selection/Selection.cpp b/src/Gui/Selection/Selection.cpp index b450b9f871..30a167f691 100644 --- a/src/Gui/Selection/Selection.cpp +++ b/src/Gui/Selection/Selection.cpp @@ -1151,13 +1151,7 @@ void SelectionSingleton::_SelObj::log(bool remove, bool clearPreselect) ss << "Gui.Selection." << (remove ? "removeSelection" : "addSelection") << "('" << DocName << "','" << FeatName << "'"; if (!SubName.empty()) { - if (!elementName.oldName.empty() && !elementName.newName.empty()) { - ss << ",'" << SubName.substr(0, SubName.size() - elementName.newName.size()) - << elementName.oldName << "'"; - } - else { - ss << ",'" << SubName << "'"; - } + ss << "," << getSubString(); } if (!remove && (x || y || z || !clearPreselect)) { if (SubName.empty()) { @@ -1172,6 +1166,18 @@ void SelectionSingleton::_SelObj::log(bool remove, bool clearPreselect) Application::Instance->macroManager()->addLine(MacroManager::Cmt, ss.str().c_str()); } +std::string SelectionSingleton::_SelObj::getSubString() const +{ + if (!SubName.empty()) { + if (!elementName.oldName.empty() && !elementName.newName.empty()) { + return "'" + SubName.substr(0, SubName.size() - elementName.newName.size()) + + elementName.oldName + "'"; + } + return "'" + SubName + "'"; + } + return ""; +} + bool SelectionSingleton::addSelection( const char* pDocName, const char* pObjectName, @@ -1440,6 +1446,14 @@ bool SelectionSingleton::addSelections( notify(SelectionChanges(SelectionChanges::PickedListChanged)); } + std::ostringstream ss; + bool anyLogged = false; + + if (!logDisabled) { + ss << "Gui.Selection.addSelection(App.getDocument('" << pDocName << "').getObject('" + << pObjectName << "'),["; + } + bool update = false; for (const auto& pSubName : pSubNames) { _SelObj temp; @@ -1452,6 +1466,16 @@ bool SelectionSingleton::addSelections( temp.y = 0; temp.z = 0; + if (!logDisabled && !temp.SubName.empty()) { + temp.logged = true; + if (anyLogged) { + ss << ","; + } + anyLogged = true; + + ss << temp.getSubString(); + } + _SelList.push_back(temp); _SelStackForward.clear(); @@ -1469,6 +1493,11 @@ bool SelectionSingleton::addSelections( update = true; } + if (!logDisabled && anyLogged) { + ss << "])"; + Application::Instance->macroManager()->addLine(MacroManager::Cmt, ss.str().c_str()); + } + if (update) { getMainWindow()->updateActions(); } diff --git a/src/Gui/Selection/Selection.h b/src/Gui/Selection/Selection.h index 358ebf3235..a653758016 100644 --- a/src/Gui/Selection/Selection.h +++ b/src/Gui/Selection/Selection.h @@ -791,6 +791,7 @@ protected: App::DocumentObject* pResolvedObject = nullptr; void log(bool remove = false, bool clearPreselect = true); + std::string getSubString() const; }; mutable std::list<_SelObj> _SelList; diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 32411ab02c..a3051463e5 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -2774,8 +2774,8 @@ void ViewProviderSketch::doBoxSelection(const SbVec2s& startPos, const SbVec2s& if (!batchSelection.empty()) { Gui::Selection().addSelections( - getSketchObject()->getDocument()->getName(), - getSketchObject()->getNameInDocument(), + editDocName.c_str(), + editObjName.c_str(), batchSelection ); } @@ -2929,8 +2929,8 @@ bool ViewProviderSketch::selectAll() if (!batchSelection.empty()) { Gui::Selection().addSelections( - getSketchObject()->getDocument()->getName(), - getSketchObject()->getNameInDocument(), + editDocName.c_str(), + editObjName.c_str(), batchSelection ); }