FreeCAD
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
32using namespace TechDrawGui;33
34EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingViewExtension, Gui::ViewProviderExtension)35
36ViewProviderDrawingViewExtension::ViewProviderDrawingViewExtension()37{
38initExtensionType(ViewProviderDrawingViewExtension::getExtensionClassTypeId());39}
40
41ViewProviderDrawingViewExtension::~ViewProviderDrawingViewExtension() {}42
43bool 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
47bool ViewProviderDrawingViewExtension::extensionCanDragObject(App::DocumentObject* docObj) const48{
49(void)docObj;50return 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.
55void 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
59bool ViewProviderDrawingViewExtension::extensionCanDropObjects() const { return true; }60
61//let the page have any drops we receive.
62bool ViewProviderDrawingViewExtension::extensionCanDropObject(App::DocumentObject* obj) const63{
64// it can happen that if the tree gets badly corrupted, there can be loose65// objects that have no page or view provider, so we need to check that66// all these objects exist.67auto vpdv = getViewProviderDrawingView();68if (!vpdv) {69return false;70}71auto vpp = vpdv->getViewProviderPage();72if (!vpp) {73return false;74}75auto vppEx = vpp->getVPPExtension();76if (!vppEx) {77return false;78}79return getViewProviderDrawingView()80->getViewProviderPage()81->getVPPExtension()82->extensionCanDropObject(obj);83}
84
85//let the page have any drops we receive
86void ViewProviderDrawingViewExtension::extensionDropObject(App::DocumentObject* obj)87{
88getViewProviderDrawingView()->getViewProviderPage()->getVPPExtension()->extensionDropObject(89obj);90}
91
92const ViewProviderDrawingView* ViewProviderDrawingViewExtension::getViewProviderDrawingView() const93{
94return dynamic_cast<const ViewProviderDrawingView*>(getExtendedViewProvider());95}
96
97const char* ViewProviderDrawingViewExtension::whoAmI() const98{
99auto parent = getViewProviderDrawingView();100if (parent) {101return parent->whoAmI();102}103return nullptr;104}
105
106namespace Gui107{
108EXTENSION_PROPERTY_SOURCE_TEMPLATE(TechDrawGui::ViewProviderDrawingViewExtensionPython,109TechDrawGui::ViewProviderDrawingViewExtension)110
111// explicit template instantiation
112template class TechDrawGuiExport113ViewProviderExtensionPythonT<TechDrawGui::ViewProviderDrawingViewExtension>;114}// namespace Gui115