Core: Add VarSets to Groups

If a Group is selected, add the VarSet to the group.
This commit is contained in:
Pieter Hijma
2024-05-19 15:39:46 +02:00
parent cb379dbe05
commit b6026c98c9
3 changed files with 25 additions and 2 deletions

View File

@@ -26,13 +26,15 @@
#include <QApplication>
#endif
#include "App/Document.h"
#include <App/GroupExtension.h>
#include <App/Document.h>
#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<App::GroupExtension>();
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());
}

View File

@@ -24,6 +24,7 @@
#include "PreCompiled.h"
#include <App/Document.h>
#include <App/VarSet.h>
#include <App/Origin.h>
#include <Base/Placement.h>
@@ -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<Part::Part2DObject>() ||
obj->isDerivedFrom<PartDesign::ShapeBinder>() ||
obj->isDerivedFrom<PartDesign::SubShapeBinder>()
obj->isDerivedFrom<PartDesign::SubShapeBinder>() ||
// TODO Why this lines was here? why should we allow anything of those? (2015-08-13, Fat-Zer)
//obj->isDerivedFrom<Part::FeaturePython>() // trouble with this line on Windows!? Linker fails to find getClassTypeId() of the Part::FeaturePython...
//obj->isDerivedFrom<Part::Feature>()
// allow VarSets for parameterization
obj->isDerivedFrom<App::VarSet>()
);
}

View File

@@ -33,6 +33,7 @@
#include <App/Document.h>
#include <App/Origin.h>
#include <App/Part.h>
#include <App/VarSet.h>
#include <Base/Console.h>
#include <Gui/ActionFunction.h>
#include <Gui/Application.h>
@@ -495,6 +496,9 @@ bool ViewProviderBody::canDropObjects() const
bool ViewProviderBody::canDropObject(App::DocumentObject* obj) const
{
if (obj->isDerivedFrom<App::VarSet>()) {
return true;
}
if (!obj->isDerivedFrom(Part::Feature::getClassTypeId())) {
return false;
}