FreeCAD

Форк
0
/
ViewProviderDrawingViewExtension.cpp 
114 строк · 4.6 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2022 WandererFan <wandererfan@gmail.com>                *
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
#include <App/Document.h>
26

27
#include "ViewProviderDrawingViewExtension.h"
28
#include "ViewProviderDrawingView.h"
29
#include "ViewProviderPage.h"
30

31

32
using namespace TechDrawGui;
33

34
EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingViewExtension, Gui::ViewProviderExtension)
35

36
ViewProviderDrawingViewExtension::ViewProviderDrawingViewExtension()
37
{
38
    initExtensionType(ViewProviderDrawingViewExtension::getExtensionClassTypeId());
39
}
40

41
ViewProviderDrawingViewExtension::~ViewProviderDrawingViewExtension() {}
42

43
bool ViewProviderDrawingViewExtension::extensionCanDragObjects() const { return true; }
44

45
//we don't support dragging children of Views (Dimensions, Balloons, Hatches, etc) now, but we don't want another
46
//extension to drag our children and cause problems
47
bool ViewProviderDrawingViewExtension::extensionCanDragObject(App::DocumentObject* docObj) const
48
{
49
    (void)docObj;
50
    return true;
51
}
52

53
//the default drag will remove the object from the document until it is dropped and re-added, so we claim
54
//to do the dragging.
55
void ViewProviderDrawingViewExtension::extensionDragObject(App::DocumentObject* obj) { (void)obj; }
56

57
//we don't support dropping of new children of Views (Dimensions, Balloons, Hatches, etc) now, but we don't want another
58
//extension to try to drop on us and cause problems
59
bool ViewProviderDrawingViewExtension::extensionCanDropObjects() const { return true; }
60

61
//let the page have any drops we receive.
62
bool ViewProviderDrawingViewExtension::extensionCanDropObject(App::DocumentObject* obj) const
63
{
64
    // it can happen that if the tree gets badly corrupted, there can be loose
65
    // objects that have no page or view provider, so we need to check that
66
    // all these objects exist.
67
    auto vpdv = getViewProviderDrawingView();
68
    if (!vpdv) {
69
        return false;
70
    }
71
    auto vpp  = vpdv->getViewProviderPage();
72
    if (!vpp) {
73
        return false;
74
    }
75
    auto vppEx = vpp->getVPPExtension();
76
    if (!vppEx) {
77
        return false;
78
    }
79
    return getViewProviderDrawingView()
80
        ->getViewProviderPage()
81
        ->getVPPExtension()
82
        ->extensionCanDropObject(obj);
83
}
84

85
//let the page have any drops we receive
86
void ViewProviderDrawingViewExtension::extensionDropObject(App::DocumentObject* obj)
87
{
88
    getViewProviderDrawingView()->getViewProviderPage()->getVPPExtension()->extensionDropObject(
89
        obj);
90
}
91

92
const ViewProviderDrawingView* ViewProviderDrawingViewExtension::getViewProviderDrawingView() const
93
{
94
    return dynamic_cast<const ViewProviderDrawingView*>(getExtendedViewProvider());
95
}
96

97
const char* ViewProviderDrawingViewExtension::whoAmI() const
98
{
99
    auto parent = getViewProviderDrawingView();
100
    if (parent) {
101
        return parent->whoAmI();
102
    }
103
    return nullptr;
104
}
105

106
namespace Gui
107
{
108
EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDrawGui::ViewProviderDrawingViewExtensionPython,
109
                                   TechDrawGui::ViewProviderDrawingViewExtension)
110

111
// explicit template instantiation
112
template class TechDrawGuiExport
113
    ViewProviderExtensionPythonT<TechDrawGui::ViewProviderDrawingViewExtension>;
114
}// namespace Gui
115

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

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

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

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