From b6026c98c9df116b755282e057e698305f175df1 Mon Sep 17 00:00:00 2001 From: Pieter Hijma Date: Sun, 19 May 2024 15:39:46 +0200 Subject: [PATCH] Core: Add VarSets to Groups If a Group is selected, add the VarSet to the group. --- src/Gui/CommandStructure.cpp | 18 +++++++++++++++++- src/Mod/PartDesign/App/Body.cpp | 5 ++++- src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Gui/CommandStructure.cpp b/src/Gui/CommandStructure.cpp index c339148dbe..06093e550a 100644 --- a/src/Gui/CommandStructure.cpp +++ b/src/Gui/CommandStructure.cpp @@ -26,13 +26,15 @@ #include #endif -#include "App/Document.h" +#include +#include #include "Command.h" #include "ActiveObjectList.h" #include "Application.h" #include "Document.h" #include "ViewProviderDocumentObject.h" +#include "Selection.h" using namespace Gui; @@ -151,6 +153,20 @@ void StdCmdVarSet::activated(int iMsg) std::string VarSetName; VarSetName = getUniqueObjectName("VarSet"); doCommand(Doc,"App.activeDocument().addObject('App::VarSet','%s')",VarSetName.c_str()); + + // add the varset to a group if it is selected + auto sels = Selection().getSelectionEx(nullptr, App::DocumentObject::getClassTypeId(), + ResolveMode::OldStyleElement, true); + if (sels.size() == 1) { + App::DocumentObject *obj = sels[0].getObject(); + auto group = obj->getExtension(); + if (group) { + Gui::Document* docGui = Application::Instance->activeDocument(); + App::Document* doc = docGui->getDocument(); + group->addObject(doc->getObject(VarSetName.c_str())); + } + } + doCommand(Doc, "App.ActiveDocument.getObject('%s').ViewObject.doubleClicked()", VarSetName.c_str()); } diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index ff92107892..2a89ec9762 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #include +#include #include #include @@ -227,10 +228,12 @@ bool Body::isAllowed(const App::DocumentObject *obj) // TODO Shouldn't we replace it with Sketcher::SketchObject? (2015-08-13, Fat-Zer) obj->isDerivedFrom() || obj->isDerivedFrom() || - obj->isDerivedFrom() + obj->isDerivedFrom() || // TODO Why this lines was here? why should we allow anything of those? (2015-08-13, Fat-Zer) //obj->isDerivedFrom() // trouble with this line on Windows!? Linker fails to find getClassTypeId() of the Part::FeaturePython... //obj->isDerivedFrom() + // allow VarSets for parameterization + obj->isDerivedFrom() ); } diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 68f47a28f5..2bd054c761 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -495,6 +496,9 @@ bool ViewProviderBody::canDropObjects() const bool ViewProviderBody::canDropObject(App::DocumentObject* obj) const { + if (obj->isDerivedFrom()) { + return true; + } if (!obj->isDerivedFrom(Part::Feature::getClassTypeId())) { return false; }