FreeCAD

Форк
0
/
ViewProviderPageExtension.cpp 
140 строк · 5.2 Кб
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/DocumentObject.h>
26
#include <Mod/TechDraw/App/DrawPage.h>
27
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
28
#include <Mod/TechDraw/App/DrawTemplate.h>
29

30
#include "ViewProviderPageExtension.h"
31
#include "ViewProviderPage.h"
32

33

34
using namespace TechDrawGui;
35

36
EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderPageExtension, Gui::ViewProviderExtension)
37

38
ViewProviderPageExtension::ViewProviderPageExtension()
39
{
40
    initExtensionType(ViewProviderPageExtension::getExtensionClassTypeId());
41
}
42

43
ViewProviderPageExtension::~ViewProviderPageExtension() {}
44

45
bool ViewProviderPageExtension::extensionCanDragObjects() const { return true; }
46

47
//we don't want another extension to drag our objects, so we say that we can handle this object
48
bool ViewProviderPageExtension::extensionCanDragObject(App::DocumentObject* docObj) const
49
{
50
    (void)docObj;
51
    return true;
52
}
53

54
//we don't take any action on drags.  everything is handling in drop
55
void ViewProviderPageExtension::extensionDragObject(App::DocumentObject* obj) { (void)obj; }
56

57
//we handle our own drops
58
bool ViewProviderPageExtension::extensionCanDropObjects() const { return true; }
59

60
bool ViewProviderPageExtension::extensionCanDropObject(App::DocumentObject* obj) const
61
{
62
    //only DrawView objects can live on pages (except special case Template)
63
    if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
64
        return true;
65
    }
66
    if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
67
        //don't let another extension try to drop templates
68
        return true;
69
    }
70

71
    return false;
72
}
73

74
bool ViewProviderPageExtension::extensionCanDropObjectEx(App::DocumentObject* obj, App::DocumentObject* owner,
75
    const char* subname,
76
    const std::vector<std::string>& elements) const
77
{
78
    //only DrawView objects can live on pages (except special case Template)
79
    if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
80
        return true;
81
    }
82
    if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
83
        //don't let another extension try to drop templates
84
        return true;
85
    }
86

87
    return false;
88
}
89

90
void ViewProviderPageExtension::extensionDropObject(App::DocumentObject* obj)
91
{
92
    if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
93
        dropObject(obj);
94
        return;
95
    }
96
}
97

98
//this code used to live in ViewProviderPage
99
void ViewProviderPageExtension::dropObject(App::DocumentObject* docObj)
100
{
101
    if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
102
        //DPGI can not be dropped onto the Page as it belongs to DPG, not Page
103
        return;
104
    }
105
    if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
106
        auto dv = static_cast<TechDraw::DrawView*>(docObj);
107
        if (dv->findParentPage()) {
108
            dv->findParentPage()->removeView(dv);
109
        }
110
        getViewProviderPage()->getDrawPage()->addView(dv);
111
        //don't run ancestor's method as addView does everything we need
112
        return;
113
    }
114
    //don't try to drop random objects
115
}
116

117
const ViewProviderPage* ViewProviderPageExtension::getViewProviderPage() const
118
{
119
    return dynamic_cast<const ViewProviderPage*>(getExtendedViewProvider());
120
}
121

122

123
const char* ViewProviderPageExtension::whoAmI() const
124
{
125
    auto parent = getViewProviderPage();
126
    if (parent) {
127
        return parent->whoAmI();
128
    }
129
    return nullptr;
130
}
131

132
namespace Gui
133
{
134
EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDrawGui::ViewProviderPageExtensionPython,
135
                                   TechDrawGui::ViewProviderPageExtension)
136

137
// explicit template instantiation
138
template class TechDrawGuiExport
139
    ViewProviderExtensionPythonT<TechDrawGui::ViewProviderPageExtension>;
140
}// namespace Gui
141

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

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

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

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