1
/***************************************************************************
2
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
23
#include "PreCompiled.h"
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>
30
#include "ViewProviderPageExtension.h"
31
#include "ViewProviderPage.h"
34
using namespace TechDrawGui;
36
EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderPageExtension, Gui::ViewProviderExtension)
38
ViewProviderPageExtension::ViewProviderPageExtension()
40
initExtensionType(ViewProviderPageExtension::getExtensionClassTypeId());
43
ViewProviderPageExtension::~ViewProviderPageExtension() {}
45
bool ViewProviderPageExtension::extensionCanDragObjects() const { return true; }
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
54
//we don't take any action on drags. everything is handling in drop
55
void ViewProviderPageExtension::extensionDragObject(App::DocumentObject* obj) { (void)obj; }
57
//we handle our own drops
58
bool ViewProviderPageExtension::extensionCanDropObjects() const { return true; }
60
bool ViewProviderPageExtension::extensionCanDropObject(App::DocumentObject* obj) const
62
//only DrawView objects can live on pages (except special case Template)
63
if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
66
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
67
//don't let another extension try to drop templates
74
bool ViewProviderPageExtension::extensionCanDropObjectEx(App::DocumentObject* obj, App::DocumentObject* owner,
76
const std::vector<std::string>& elements) const
78
//only DrawView objects can live on pages (except special case Template)
79
if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
82
if (obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId())) {
83
//don't let another extension try to drop templates
90
void ViewProviderPageExtension::extensionDropObject(App::DocumentObject* obj)
92
if (obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
98
//this code used to live in ViewProviderPage
99
void ViewProviderPageExtension::dropObject(App::DocumentObject* docObj)
101
if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) {
102
//DPGI can not be dropped onto the Page as it belongs to DPG, not Page
105
if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId())) {
106
auto dv = static_cast<TechDraw::DrawView*>(docObj);
107
if (dv->findParentPage()) {
108
dv->findParentPage()->removeView(dv);
110
getViewProviderPage()->getDrawPage()->addView(dv);
111
//don't run ancestor's method as addView does everything we need
114
//don't try to drop random objects
117
const ViewProviderPage* ViewProviderPageExtension::getViewProviderPage() const
119
return dynamic_cast<const ViewProviderPage*>(getExtendedViewProvider());
123
const char* ViewProviderPageExtension::whoAmI() const
125
auto parent = getViewProviderPage();
127
return parent->whoAmI();
134
EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDrawGui::ViewProviderPageExtensionPython,
135
TechDrawGui::ViewProviderPageExtension)
137
// explicit template instantiation
138
template class TechDrawGuiExport
139
ViewProviderExtensionPythonT<TechDrawGui::ViewProviderPageExtension>;