FreeCAD

Форк
0
/
ViewProviderGroupExtension.cpp 
190 строк · 7.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2016 Stefan Tröger <stefantroeger@gmx.net>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 of the License, or (at your option) any later version.      *
10
 *                                                                         *
11
 *   This library  is distributed in the hope that it will be useful,      *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23
#include "PreCompiled.h"
24

25
#ifndef _PreComp_
26
# include <QMessageBox>
27
#endif
28

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>
34

35
#include "ViewProviderGroupExtension.h"
36
#include "ViewProviderDocumentObject.h"
37
#include "Command.h"
38
#include "Document.h"
39
#include "MainWindow.h"
40

41

42
using namespace Gui;
43

44
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderGroupExtension, Gui::ViewProviderExtension)
45

46
ViewProviderGroupExtension::ViewProviderGroupExtension()
47
{
48
    initExtensionType(ViewProviderGroupExtension::getExtensionClassTypeId());
49
}
50

51
ViewProviderGroupExtension::~ViewProviderGroupExtension() = default;
52

53
bool ViewProviderGroupExtension::extensionCanDragObjects() const {
54
    return true;
55
}
56

57
bool ViewProviderGroupExtension::extensionCanDragObject(App::DocumentObject*) const {
58

59
    //we can drag anything out
60
    return true;
61
}
62

63
void ViewProviderGroupExtension::extensionDragObject(App::DocumentObject* obj) {
64

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() );
69
}
70

71
bool ViewProviderGroupExtension::extensionCanDropObjects() const {
72
    return true;
73
}
74

75
bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj) const {
76

77
#ifdef FC_DEBUG
78
    Base::Console().Log("Check ViewProviderGroupExtension");
79
#endif
80

81
    auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
82

83
    //we cannot drop thing of this group into it again if it does not allow reorder
84
    if (group->hasObject(obj) && !getExtendedViewProvider()->acceptReorderingObjects())
85
        return false;
86

87
    if (group->allowObject(obj))
88
        return true;
89

90
    return false;
91
}
92

93
void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) {
94

95
    auto grp = static_cast<App::DocumentObject*>(getExtendedViewProvider()->getObject());
96
    App::Document* doc = grp->getDocument();
97

98
    // build Python command for execution
99
    QString cmd;
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()));
105

106
    Gui::Command::doCommand(Gui::Command::App, cmd.toUtf8());
107
}
108

109
std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren() const {
110

111
    auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
112
    return group->Group.getValues();
113
}
114

115
void ViewProviderGroupExtension::extensionShow() {
116

117
    // avoid possible infinite recursion
118
    if (guard)
119
        return;
120
    Base::StateLocker lock(guard);
121

122
    // when reading the Visibility property from file then do not hide the
123
    // objects of this group because they have stored their visibility status, too
124
    //
125
    // Property::User1 is used by ViewProviderDocumentObject to mark for
126
    // temporary visibility changes. Do not propagate the change to children.
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);
133
        }
134
    }
135

136
    ViewProviderExtension::extensionShow();
137
}
138

139
void ViewProviderGroupExtension::extensionHide() {
140

141
    // avoid possible infinite recursion
142
    if (guard)
143
        return;
144
    Base::StateLocker lock(guard);
145

146
    // when reading the Visibility property from file then do not hide the
147
    // objects of this group because they have stored their visibility status, too
148
    //
149
    // Property::User1 is used by ViewProviderDocumentObject to mark for
150
    // temporary visibility changes. Do not propagate the change to children.
151
    if (!getExtendedViewProvider()->isRestoring()
152
            && !getExtendedViewProvider()->Visibility.testStatus(App::Property::User1))
153
    {
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);
158
        }
159
    }
160
    ViewProviderExtension::extensionHide();
161
}
162

163
bool ViewProviderGroupExtension::extensionOnDelete(const std::vector< std::string >& ) {
164

165
    auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
166
    // If the group is nonempty ask the user if they want to delete its content
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 );
173

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());
179
        }
180
    }
181
    return true;
182
}
183

184

185
namespace Gui {
186
EXTENSION_PROPERTY_SOURCE_TEMPLATE(Gui::ViewProviderGroupExtensionPython, Gui::ViewProviderGroupExtension)
187

188
// explicit template instantiation
189
template class GuiExport ViewProviderExtensionPythonT<ViewProviderGroupExtension>;
190
}
191

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.