Gui: Allow users to add groups to active objects

As the title says, if right now there is Arch type active (like Level,
Building, etc. etc.), then it's not possible to assign Group to it
automatically (it's being created on root level of the document).

So this patch basically takes an active object and tries to insert it.
This commit is contained in:
tetektoza
2025-06-20 20:20:58 +02:00
committed by Benjamin Nauck
parent 5ed384c7f3
commit ecad444131

View File

@@ -32,6 +32,7 @@
#include "ActiveObjectList.h"
#include "Application.h"
#include "Document.h"
#include "MDIView.h"
#include "ViewProviderDocumentObject.h"
#include "Selection.h"
@@ -121,9 +122,27 @@ void StdCmdGroup::activated(int iMsg)
std::string GroupName;
GroupName = getUniqueObjectName("Group");
QString label = QApplication::translate("Std_Group", "Group");
doCommand(Doc,"App.activeDocument().Tip = App.activeDocument().addObject('App::DocumentObjectGroup','%s')",GroupName.c_str());
doCommand(Doc,"App.activeDocument().%s.Label = '%s'", GroupName.c_str(),
label.toUtf8().data());
// create a group
doCommand(Doc,"group = App.activeDocument().addObject('App::DocumentObjectGroup','%s')",GroupName.c_str());
doCommand(Doc,"group.Label = '%s'", label.toUtf8().data());
doCommand(Doc,"App.activeDocument().Tip = group");
// try to add the group to any active object that supports grouping (has GroupExtension)
if (auto* activeDoc = Gui::Application::Instance->activeDocument()) {
if (auto* activeView = activeDoc->getActiveView()) {
// find the first active object with GroupExtension
if (auto* activeObj = activeView->getActiveObjectWithExtension(
App::GroupExtension::getExtensionClassTypeId())) {
doCommand(Doc,
"active_obj = App.activeDocument().getObject('%s')\n"
"if active_obj and active_obj.allowObject(group):\n"
" active_obj.Group += [group]",
activeObj->getNameInDocument());
}
}
} // if we have no active object, group will be added to root doc
commitCommand();
Gui::Document* gui = Application::Instance->activeDocument();