23
#include "PreCompiled.h"
26
# include <QMessageBox>
29
#include <App/Document.h>
30
#include <App/DocumentObject.h>
31
#include <App/GroupExtension.h>
32
#include <Base/Console.h>
33
#include <Base/Tools.h>
35
#include "ViewProviderGroupExtension.h"
36
#include "ViewProviderDocumentObject.h"
39
#include "MainWindow.h"
44
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderGroupExtension, Gui::ViewProviderExtension)
46
ViewProviderGroupExtension::ViewProviderGroupExtension()
48
initExtensionType(ViewProviderGroupExtension::getExtensionClassTypeId());
51
ViewProviderGroupExtension::~ViewProviderGroupExtension() = default;
53
bool ViewProviderGroupExtension::extensionCanDragObjects() const {
57
bool ViewProviderGroupExtension::extensionCanDragObject(App::DocumentObject*) const {
63
void ViewProviderGroupExtension::extensionDragObject(App::DocumentObject* obj) {
65
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObject("
66
"App.getDocument(\"%s\").getObject(\"%s\"))",
67
getExtendedViewProvider()->getObject()->getDocument()->getName(), getExtendedViewProvider()->getObject()->getNameInDocument(),
68
obj->getDocument()->getName(), obj->getNameInDocument() );
71
bool ViewProviderGroupExtension::extensionCanDropObjects() const {
75
bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj) const {
78
Base::Console().Log("Check ViewProviderGroupExtension");
81
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
84
if (group->hasObject(obj) && !getExtendedViewProvider()->acceptReorderingObjects())
87
if (group->allowObject(obj))
93
void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) {
95
auto grp = static_cast<App::DocumentObject*>(getExtendedViewProvider()->getObject());
96
App::Document* doc = grp->getDocument();
100
cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").addObject("
101
"App.getDocument(\"%1\").getObject(\"%3\"))")
102
.arg(QString::fromLatin1(doc->getName()),
103
QString::fromLatin1(grp->getNameInDocument()),
104
QString::fromLatin1(obj->getNameInDocument()));
106
Gui::Command::doCommand(Gui::Command::App, cmd.toUtf8());
109
std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren() const {
111
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
112
return group->Group.getValues();
115
void ViewProviderGroupExtension::extensionShow() {
120
Base::StateLocker lock(guard);
127
if (!getExtendedViewProvider()->isRestoring()
128
&& !getExtendedViewProvider()->Visibility.testStatus(App::Property::User1)) {
129
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
130
for(auto obj : group->Group.getValues()) {
131
if(obj && !obj->Visibility.getValue())
132
obj->Visibility.setValue(true);
136
ViewProviderExtension::extensionShow();
139
void ViewProviderGroupExtension::extensionHide() {
144
Base::StateLocker lock(guard);
151
if (!getExtendedViewProvider()->isRestoring()
152
&& !getExtendedViewProvider()->Visibility.testStatus(App::Property::User1))
154
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
155
for(auto obj : group->Group.getValues()) {
156
if(obj && obj->Visibility.getValue())
157
obj->Visibility.setValue(false);
160
ViewProviderExtension::extensionHide();
163
bool ViewProviderGroupExtension::extensionOnDelete(const std::vector< std::string >& ) {
165
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
167
if (group->Group.getSize() > 0) {
168
QMessageBox::StandardButton choice =
169
QMessageBox::question(getMainWindow(), QObject::tr ( "Delete group content?" ),
170
QObject::tr ( "The %1 is not empty, delete its content as well?")
171
.arg ( QString::fromUtf8 ( getExtendedViewProvider()->getObject()->Label.getValue () ) ),
172
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
174
if (choice == QMessageBox::Yes) {
175
Gui::Command::doCommand(Gui::Command::Doc,
176
"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()"
177
, getExtendedViewProvider()->getObject()->getDocument()->getName()
178
, getExtendedViewProvider()->getObject()->getNameInDocument());
186
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderGroupExtensionPython, Gui::ViewProviderGroupExtension)
189
template class GuiExport ViewProviderExtensionPythonT<ViewProviderGroupExtension>;