Gui: clean-up Selection API

Replace the int of the 'resolve' argument of several functions with a proper enum class.
* This avoids the inconsistencies in client code where often true/false is passed when an int is expected
* This avoids the use of magic numbers like 0, 1, 2 or the undocumented 3
This commit is contained in:
wmayer
2022-04-09 17:03:43 +02:00
parent 2d266a75cd
commit 0b2c73cf32
24 changed files with 365 additions and 274 deletions

View File

@@ -189,12 +189,15 @@ CmdPartSimpleCopy::CmdPartSimpleCopy()
static void _copyShape(const char *cmdName, bool resolve,bool needElement=false, bool refine=false) {
Gui::WaitCursor wc;
Gui::Command::openCommand(cmdName);
for(auto &sel : Gui::Selection().getSelectionEx("*",App::DocumentObject::getClassTypeId(),resolve)) {
for(auto &sel : Gui::Selection().getSelectionEx("*", App::DocumentObject::getClassTypeId(),
resolve ? Gui::ResolveMode::OldStyleElement : Gui::ResolveMode::NoResolve)) {
std::map<std::string,App::DocumentObject*> subMap;
auto obj = sel.getObject();
if(!obj) continue;
if(resolve || !sel.hasSubNames())
if (!obj)
continue;
if (resolve || !sel.hasSubNames()) {
subMap.emplace("",obj);
}
else {
for(const auto &sub : sel.getSubNames()) {
const char *element = nullptr;
@@ -215,8 +218,9 @@ static void _copyShape(const char *cmdName, bool resolve,bool needElement=false,
"App.ActiveDocument.addObject('Part::Feature','%s').Shape=__shape\n"
"App.ActiveDocument.ActiveObject.Label=%s.Label\n",
parentName.c_str(), v.first.c_str(),
needElement?"True":"False", refine?"True":"False",
needElement?".copy()":"",
needElement ? "True" : "False",
refine ? "True" : "False",
needElement ? ".copy()" : "",
v.second->getNameInDocument(),
Gui::Command::getObjectCmd(v.second).c_str());
auto newObj = App::GetApplication().getActiveDocument()->getActiveObject();