diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index a421088777..6a7d4f7442 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -470,6 +470,19 @@ bool DrawPage::canUpdate() const return result; } +//true if object belongs to this page +bool DrawPage::hasObject(App::DocumentObject* obj) +{ + for (auto& outObj : getOutList()) { + //TODO: check if pointer comparision is reliable enough + if (outObj == obj) { + return true; + } + } + + return false; +} + //allow/prevent drawing updates for all Pages bool DrawPage::GlobalUpdateDrawings(void) { diff --git a/src/Mod/TechDraw/App/DrawPage.h b/src/Mod/TechDraw/App/DrawPage.h index 5d16d0cf01..72a0031c68 100644 --- a/src/Mod/TechDraw/App/DrawPage.h +++ b/src/Mod/TechDraw/App/DrawPage.h @@ -107,6 +107,8 @@ public: bool canUpdate() const; + bool hasObject(App::DocumentObject* obj); + protected: void onBeforeChange(const App::Property* prop) override; void onChanged(const App::Property* prop) override; diff --git a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp index c1237a5992..b6848f01e4 100644 --- a/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp +++ b/src/Mod/TechDraw/Gui/AppTechDrawGui.cpp @@ -61,6 +61,9 @@ #include "ViewProviderViewPart.h" #include "ViewProviderViewSection.h" #include "ViewProviderWeld.h" +#include "ViewProviderPageExtension.h" +#include "ViewProviderDrawingViewExtension.h" +#include "ViewProviderTemplateExtension.h" #include "Workbench.h" @@ -149,6 +152,11 @@ PyMOD_INIT_FUNC(TechDrawGui) TechDrawGui::ViewProviderTile::init(); TechDrawGui::ViewProviderWeld::init(); + TechDrawGui::ViewProviderPageExtension ::init(); +// TechDrawGui::ViewProviderPageExtensionPython::init(); + TechDrawGui::ViewProviderDrawingViewExtension::init(); + TechDrawGui::ViewProviderTemplateExtension::init(); + TechDrawGui::ViewProviderCosmeticExtension::init(); // register preferences pages diff --git a/src/Mod/TechDraw/Gui/CMakeLists.txt b/src/Mod/TechDraw/Gui/CMakeLists.txt index 6905fb982a..7fd61c955c 100644 --- a/src/Mod/TechDraw/Gui/CMakeLists.txt +++ b/src/Mod/TechDraw/Gui/CMakeLists.txt @@ -351,12 +351,18 @@ SET(TechDrawGuiNav_SRCS SET(TechDrawGuiViewProvider_SRCS ViewProviderPage.cpp ViewProviderPage.h + ViewProviderPageExtension.cpp + ViewProviderPageExtension.h ViewProviderDrawingView.cpp ViewProviderDrawingView.h + ViewProviderDrawingViewExtension.cpp + ViewProviderDrawingViewExtension.h ViewProviderProjGroupItem.cpp ViewProviderProjGroupItem.h ViewProviderTemplate.cpp ViewProviderTemplate.h + ViewProviderTemplateExtension.cpp + ViewProviderTemplateExtension.h ViewProviderDimension.cpp ViewProviderDimension.h ViewProviderBalloon.cpp diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index 7c1dac8520..e0ebcb7e7d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -42,6 +42,7 @@ #include #include "ViewProviderDrawingView.h" +#include "ViewProviderDrawingViewExtension.h" #include "MDIViewPage.h" #include "QGIView.h" #include "QGSPage.h" @@ -52,9 +53,12 @@ namespace bp = boost::placeholders; PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingView, Gui::ViewProviderDocumentObject) -ViewProviderDrawingView::ViewProviderDrawingView() +ViewProviderDrawingView::ViewProviderDrawingView() : + m_myName(std::string()) { // Base::Console().Message("VPDV::VPDV\n"); + initExtension(this); + sPixmap = "TechDraw_TreeView"; static const char *group = "Base"; @@ -79,6 +83,7 @@ void ViewProviderDrawingView::attach(App::DocumentObject *pcFeat) auto bndProgressMessage = boost::bind(&ViewProviderDrawingView::onProgressMessage, this, bp::_1, bp::_2, bp::_3); auto feature = getViewObject(); if (feature) { + m_myName = feature->getNameInDocument(); connectGuiRepaint = feature->signalGuiPaint.connect(bnd); connectProgressMessage = feature->signalProgressMessage.connect(bndProgressMessage); //TODO: would be good to start the QGIV creation process here, but no guarantee we actually have @@ -187,6 +192,11 @@ bool ViewProviderDrawingView::isShow() const return Visibility.getValue(); } +void ViewProviderDrawingView::dropObject(App::DocumentObject* docObj) +{ + getViewProviderPage()->dropObject(docObj); +} + void ViewProviderDrawingView::startRestoring() { Gui::ViewProviderDocumentObject::startRestoring(); @@ -417,6 +427,11 @@ void ViewProviderDrawingView::stackBottom() qView->setStack(minZ - 1); } +const char* ViewProviderDrawingView::whoAmI() const +{ + return m_myName.c_str(); +} + TechDraw::DrawView* ViewProviderDrawingView::getViewObject() const { return dynamic_cast(pcObject); diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h index c9c2d2f430..f1828a9c2b 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.h @@ -31,6 +31,7 @@ #include #include +#include "ViewProviderDrawingViewExtension.h" namespace TechDraw { class DrawView; @@ -41,7 +42,8 @@ class QGIView; class MDIViewPage; class ViewProviderPage; -class TechDrawGuiExport ViewProviderDrawingView : public Gui::ViewProviderDocumentObject +class TechDrawGuiExport ViewProviderDrawingView : public Gui::ViewProviderDocumentObject, + public ViewProviderDrawingViewExtension { PROPERTY_HEADER_WITH_OVERRIDE(TechDrawGui::ViewProviderDrawingView); @@ -62,6 +64,8 @@ public: void show() override; bool isShow() const override; + void dropObject(App::DocumentObject* docObj) override; + void onChanged(const App::Property *prop) override; void updateData(const App::Property*) override; @@ -93,11 +97,13 @@ public: virtual void stackBottom(); virtual int getZ() {return StackOrder.getValue();} + const char* whoAmI() const; + private: void multiParentPaint(std::vector& pages); void singleParentPaint(const TechDraw::DrawView* dv); - + std::string m_myName; }; } // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingViewExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingViewExtension.cpp new file mode 100644 index 0000000000..77c6720c89 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingViewExtension.cpp @@ -0,0 +1,108 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include +#include + +#include +#include + +#include "ViewProviderDrawingViewExtension.h" +#include "ViewProviderDrawingView.h" +#include "ViewProviderPage.h" + +using namespace TechDrawGui; + +EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderDrawingViewExtension, Gui::ViewProviderExtension) + +ViewProviderDrawingViewExtension::ViewProviderDrawingViewExtension() +{ + initExtensionType(ViewProviderDrawingViewExtension::getExtensionClassTypeId()); +} + +ViewProviderDrawingViewExtension::~ViewProviderDrawingViewExtension() +{ +} + +bool ViewProviderDrawingViewExtension::extensionCanDragObjects() const { + return true; +} + +//we don't support dragging children of Views (Dimensions, Balloons, Hatches, etc) now, but we don't want another +//extension to drag our children and cause problems +bool ViewProviderDrawingViewExtension::extensionCanDragObject(App::DocumentObject* docObj) const { + (void)docObj; + return true; +} + +//the default drag will remove the object from the document until it is dropped and re-added, so we claim +//to do the dragging. +void ViewProviderDrawingViewExtension::extensionDragObject(App::DocumentObject* obj) { + (void)obj; +} + +//we don't support dropping of new children of Views (Dimensions, Balloons, Hatches, etc) now, but we don't want another +//extension to try to drop on us and cause problems +bool ViewProviderDrawingViewExtension::extensionCanDropObjects() const { + return true; +} + +//let the page have any drops we receive +bool ViewProviderDrawingViewExtension::extensionCanDropObject(App::DocumentObject* obj) const { + return getViewProviderDrawingView()->getViewProviderPage()->getVPPExtension()->extensionCanDropObject(obj); +} + +//let the page have any drops we receive +void ViewProviderDrawingViewExtension::extensionDropObject(App::DocumentObject* obj) { + getViewProviderDrawingView()->getViewProviderPage()->getVPPExtension()->extensionDropObject(obj); +} + +const ViewProviderDrawingView* ViewProviderDrawingViewExtension::getViewProviderDrawingView() const +{ + return dynamic_cast(getExtendedViewProvider()); +} + +const char* ViewProviderDrawingViewExtension::whoAmI() const +{ + auto parent = getViewProviderDrawingView(); + if (parent) { + return parent->whoAmI(); + } + return nullptr; +} + +namespace Gui { +EXTENSION_PROPERTY_SOURCE_TEMPLATE(ViewProviderDrawingViewExtensionPython, ViewProviderDrawingViewExtension) + +// explicit template instantiation +template class GuiExport ViewProviderExtensionPythonT; +} + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingViewExtension.h b/src/Mod/TechDraw/Gui/ViewProviderDrawingViewExtension.h new file mode 100644 index 0000000000..ff307f98b6 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingViewExtension.h @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_VIEWPROVIDERDRAWINGVIEWEXTENSION_H +#define TECHDRAWGUI_VIEWPROVIDERDRAWINGVIEWEXTENSION_H + +#include +#include +#include +#include + +namespace TechDrawGui +{ +class ViewProviderDrawingView; + +class TechDrawGuiExport ViewProviderDrawingViewExtension : public Gui::ViewProviderExtension +{ + EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderDrawingViewExtension); + +public: + /// Constructor + ViewProviderDrawingViewExtension(); + ~ViewProviderDrawingViewExtension() override; + + bool extensionCanDragObjects() const override; + bool extensionCanDragObject(App::DocumentObject*) const override; + void extensionDragObject(App::DocumentObject*) override; + bool extensionCanDropObjects() const override; + bool extensionCanDropObject(App::DocumentObject*) const override; + void extensionDropObject(App::DocumentObject*) override; + + const ViewProviderDrawingView* getViewProviderDrawingView() const; + const char* whoAmI() const; + +private: +}; + +using ViewProviderDrawingViewExtensionPython = Gui::ViewProviderExtensionPythonT; + +} //namespace Gui + +#endif // TECHDRAWGUI_VIEWPROVIDERDRAWINGVIEWEXTENSION_H + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp index 4a36526192..7cb6688841 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.cpp @@ -61,7 +61,7 @@ #include "QGVPage.h" #include "ViewProviderTemplate.h" #include "ViewProviderPage.h" - +#include "ViewProviderPageExtension.h" using namespace TechDrawGui; using namespace TechDraw; @@ -82,12 +82,14 @@ ViewProviderPage::ViewProviderPage() m_graphicsView(nullptr), m_graphicsScene(nullptr) { + initExtension(this); + sPixmap = "TechDraw_TreePage"; static const char *group = "Grid"; ADD_PROPERTY_TYPE(ShowFrames ,(true), group, App::Prop_None, "Show or hide View frames and Labels on this Page"); ADD_PROPERTY_TYPE(ShowGrid ,(PreferencesGui::showGrid()), group, App::Prop_None, "Show or hide a grid on this Page"); - ADD_PROPERTY_TYPE(GridSpacing, (PreferencesGui::gridSpacing()), group, (App::PropertyType)(App::Prop_None), + ADD_PROPERTY_TYPE(GridSpacing, (PreferencesGui::gridSpacing()), group, (App::PropertyType::Prop_None), "Grid line spacing in mm"); ShowFrames.setStatus(App::Property::Hidden, true); @@ -462,57 +464,29 @@ bool ViewProviderPage::canDelete(App::DocumentObject *obj) const bool ViewProviderPage::canDragObjects() const { -// Base::Console().Message("VPP:canDragObjects()\n"); - return ViewProviderDocumentObject::canDragObjects(); + return getVPPExtension()->extensionCanDragObjects(); } bool ViewProviderPage::canDragObject(App::DocumentObject* docObj) const { -// Base::Console().Message("VPP:canDragObject()\n"); - if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { - //DPGI can not be dragged from the Page as it belongs to DPG, not Page - return false; - } - - if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { - return true; - } - return false; + return getVPPExtension()->extensionCanDragObject(docObj); } +bool ViewProviderPage::canDropObjectEx(App::DocumentObject* obj, App::DocumentObject *owner, + const char *subname, const std::vector &elements) const +{ + return getVPPExtension()->extensionCanDropObjectEx(obj, owner, subname, elements); + +} bool ViewProviderPage::canDropObject(App::DocumentObject* docObj) const { -// Base::Console().Message("VPP:canDropObject()\n"); - if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { - //DPGI can not be dropped onto the Page as it belongs to DPG, not Page - return false; - } - - if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { - return true; - } - return false; + return getVPPExtension()->extensionCanDropObject(docObj); } void ViewProviderPage::dropObject(App::DocumentObject* docObj) { -// Base::Console().Message("VPP:dropObject()\n"); - if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { - //DPGI can not be dropped onto the Page as it belongs to DPG, not Page - ViewProviderDocumentObject::dropObject(docObj); - return; - } - if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { - auto dv = static_cast(docObj); - if (dv->findParentPage()) { - dv->findParentPage()->removeView(dv); - } - getDrawPage()->addView(dv); - //don't run ancestor's method as addView does everything we need - return; - } - ViewProviderDocumentObject::dropObject(docObj); + getVPPExtension()->extensionDropObject(docObj); } //! Redo the whole visual page @@ -565,3 +539,15 @@ void ViewProviderPage::setGrid() widget->updateViewport(); } } + +ViewProviderPageExtension* ViewProviderPage::getVPPExtension() const +{ + auto vpe = getExtensionByType(); + auto vppe = static_cast(vpe); + return vppe; +} + +const char* ViewProviderPage::whoAmI() const +{ + return m_pageName.c_str(); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderPage.h b/src/Mod/TechDraw/Gui/ViewProviderPage.h index 04331bba3c..11d9ed22ce 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderPage.h +++ b/src/Mod/TechDraw/Gui/ViewProviderPage.h @@ -32,6 +32,7 @@ #include #include +#include namespace TechDraw{ class DrawPage; @@ -43,7 +44,8 @@ class MDIViewPage; class QGVPage; class QGSPage; -class TechDrawGuiExport ViewProviderPage : public Gui::ViewProviderDocumentObject +class TechDrawGuiExport ViewProviderPage : public Gui::ViewProviderDocumentObject, + public ViewProviderPageExtension { PROPERTY_HEADER_WITH_OVERRIDE(TechDrawGui::ViewProviderPage); @@ -63,7 +65,12 @@ public: bool canDragObjects() const override; bool canDragObject(App::DocumentObject* docObj) const override; bool canDropObject(App::DocumentObject* docObj) const override; + void dropObject(App::DocumentObject* docObj) override; + void constDropObject(App::DocumentObject* docObj) const; + + bool canDropObjectEx(App::DocumentObject *obj, App::DocumentObject *owner, + const char *subname, const std::vector &elements) const override; bool useNewSelectionModel() const override {return false;} /// returns a list of all possible modes @@ -110,6 +117,10 @@ public: QGSPage* getQGSPage(void) {return m_graphicsScene;} QGVPage* getQGVPage(void) {return m_graphicsView;} + ViewProviderPageExtension* getVPPExtension() const; + + const char* whoAmI() const; + protected: bool setEdit(int ModNum) override; void createMDIViewPage(); diff --git a/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp new file mode 100644 index 0000000000..01c56329ec --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include +#include + +#include +#include +#include + +#include "ViewProviderPageExtension.h" +#include "ViewProviderPage.h" + +using namespace TechDrawGui; + +EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderPageExtension, Gui::ViewProviderExtension) + +ViewProviderPageExtension::ViewProviderPageExtension() +{ + initExtensionType(ViewProviderPageExtension::getExtensionClassTypeId()); +} + +ViewProviderPageExtension::~ViewProviderPageExtension() +{ +} + +bool ViewProviderPageExtension::extensionCanDragObjects() const { + return true; +} + +//we don't want another extension to drag our objects, so we say that we can handle this object +bool ViewProviderPageExtension::extensionCanDragObject(App::DocumentObject* docObj) const { + (void) docObj; + return true; +} + +//we don't take any action on drags. everything is handling in drop +void ViewProviderPageExtension::extensionDragObject(App::DocumentObject* obj) { + (void) obj; +} + +//we handle our own drops +bool ViewProviderPageExtension::extensionCanDropObjects() const { + return true; +} + +bool ViewProviderPageExtension::extensionCanDropObject(App::DocumentObject* obj) const { + //only DrawView objects can live on pages (except special case Template) + if ( obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { + return true; + } + if ( obj->isDerivedFrom(TechDraw::DrawTemplate::getClassTypeId()) ) { + //don't let another extension try to drop templates + return true; + } + + return false; +} + +void ViewProviderPageExtension::extensionDropObject(App::DocumentObject* obj) { + if ( obj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { + dropObject(obj); + return; + } +} + +//this code used to live in ViewProviderPage +void ViewProviderPageExtension::dropObject(App::DocumentObject* docObj) +{ + if (docObj->isDerivedFrom(TechDraw::DrawProjGroupItem::getClassTypeId())) { + //DPGI can not be dropped onto the Page as it belongs to DPG, not Page + return; + } + if (docObj->isDerivedFrom(TechDraw::DrawView::getClassTypeId()) ) { + auto dv = static_cast(docObj); + if (dv->findParentPage()) { + dv->findParentPage()->removeView(dv); + } + getViewProviderPage()->getDrawPage()->addView(dv); + //don't run ancestor's method as addView does everything we need + return; + } + //don't try to drop random objects +} + +const ViewProviderPage* ViewProviderPageExtension::getViewProviderPage() const +{ + return dynamic_cast(getExtendedViewProvider()); +} + + +const char* ViewProviderPageExtension::whoAmI() const +{ + auto parent = getViewProviderPage(); + if (parent) { + return parent->whoAmI(); + } + return nullptr; +} + +namespace Gui { +EXTENSION_PROPERTY_SOURCE_TEMPLATE(ViewProviderPageExtensionPython, ViewProviderPageExtension) + +// explicit template instantiation +template class GuiExport ViewProviderExtensionPythonT; +} + diff --git a/src/Mod/TechDraw/Gui/ViewProviderPageExtension.h b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.h new file mode 100644 index 0000000000..1739dcd9df --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderPageExtension.h @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_VIEWPROVIDERPAGEEXTENSION_H +#define TECHDRAWGUI_VIEWPROVIDERPAGEEXTENSION_H + +#include +#include +#include +#include + +namespace TechDrawGui +{ +class ViewProviderPage; + +class TechDrawGuiExport ViewProviderPageExtension : public Gui::ViewProviderExtension +{ + EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderPageExtension); + +public: + /// Constructor + ViewProviderPageExtension(); + ~ViewProviderPageExtension() override; + + bool extensionCanDragObjects() const override; + bool extensionCanDragObject(App::DocumentObject*) const override; + void extensionDragObject(App::DocumentObject*) override; + bool extensionCanDropObjects() const override; + bool extensionCanDropObject(App::DocumentObject*) const override; + void extensionDropObject(App::DocumentObject*) override; + + void dropObject(App::DocumentObject* docObj); + + const ViewProviderPage* getViewProviderPage() const; + const char* whoAmI() const; + +private: +}; + +using ViewProviderPageExtensionPython = Gui::ViewProviderExtensionPythonT; + +} //namespace Gui + +#endif // TECHDRAWGUI_VIEWPROVIDERPAGEEXTENSION_H + diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp b/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp index 62d88bdd68..229309ae69 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplate.cpp @@ -56,20 +56,30 @@ PROPERTY_SOURCE(TechDrawGui::ViewProviderTemplate, Gui::ViewProviderDocumentObje //************************************************************************** // Construction/Destruction -ViewProviderTemplate::ViewProviderTemplate() +ViewProviderTemplate::ViewProviderTemplate() : + m_myName(std::string()) { + initExtension(this); + sPixmap = "TechDraw_TreePageTemplate"; DisplayMode.setStatus(App::Property::Hidden, true); } -ViewProviderTemplate::~ViewProviderTemplate() +void ViewProviderTemplate::attach(App::DocumentObject *pcFeat) { +// Base::Console().Message("VPT::attach(%s)\n", pcFeat->getNameInDocument()); + ViewProviderDocumentObject::attach(pcFeat); + + auto feature = getTemplate(); + if (feature) { + m_myName = feature->getNameInDocument(); + } } void ViewProviderTemplate::updateData(const App::Property* prop) { - //This doesn't belong here. Should be in attach? + //This doesn't belong here. Should be in a ViewProviderSvgTemplate? if (getTemplate()->isDerivedFrom(TechDraw::DrawSVGTemplate::getClassTypeId())) { auto t = static_cast(getTemplate()); if (prop == &(t->Template)) { @@ -217,3 +227,8 @@ TechDraw::DrawTemplate* ViewProviderTemplate::getTemplate() const { return dynamic_cast(pcObject); } + +const char* ViewProviderTemplate::whoAmI() const +{ + return m_myName.c_str(); +} diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplate.h b/src/Mod/TechDraw/Gui/ViewProviderTemplate.h index b06ca8832a..8f82ff787f 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderTemplate.h +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplate.h @@ -22,9 +22,12 @@ #ifndef DRAWINGGUI_VIEWPROVIDERTEMPLATE_H #define DRAWINGGUI_VIEWPROVIDERTEMPLATE_H - -#include +#include + +#include + +#include "ViewProviderTemplateExtension.h" namespace TechDraw{ class DrawTemplate; } @@ -33,7 +36,8 @@ namespace TechDrawGui { class QGITemplate; class MDIViewPage; -class TechDrawGuiExport ViewProviderTemplate : public Gui::ViewProviderDocumentObject +class TechDrawGuiExport ViewProviderTemplate : public Gui::ViewProviderDocumentObject, + public ViewProviderTemplateExtension { PROPERTY_HEADER_WITH_OVERRIDE(TechDrawGui::ViewProviderTemplate); @@ -41,7 +45,9 @@ public: /// constructor ViewProviderTemplate(); /// destructor - virtual ~ViewProviderTemplate(); + ~ViewProviderTemplate() override = default; + + void attach(App::DocumentObject *) override; virtual bool useNewSelectionModel(void) const override {return false;} virtual void updateData(const App::Property*) override; @@ -56,6 +62,11 @@ public: void setMarkers(bool state); virtual bool onDelete(const std::vector &) override; + + const char* whoAmI() const; + +private: + std::string m_myName; }; } // namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplateExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderTemplateExtension.cpp new file mode 100644 index 0000000000..ee1563d9cd --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplateExtension.cpp @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#include "PreCompiled.h" + +#ifndef _PreComp_ +# include +#endif + +#include +#include +#include +#include + +#include +#include + +#include "ViewProviderTemplateExtension.h" +#include "ViewProviderTemplate.h" +#include "ViewProviderPage.h" + +using namespace TechDrawGui; + +EXTENSION_PROPERTY_SOURCE(TechDrawGui::ViewProviderTemplateExtension, Gui::ViewProviderExtension) + +ViewProviderTemplateExtension::ViewProviderTemplateExtension() +{ + initExtensionType(ViewProviderTemplateExtension::getExtensionClassTypeId()); +} + +ViewProviderTemplateExtension::~ViewProviderTemplateExtension() +{ +} + +//there are no child objects to drag currently, so we will say we handle any dragging rather than letting some +//other extension trying to drag and causing problems. +bool ViewProviderTemplateExtension::extensionCanDragObjects() const { + return true; +} + +//there are no child objects to drag currently, so we will say we handle any dragging +bool ViewProviderTemplateExtension::extensionCanDragObject(App::DocumentObject* docObj) const { + (void) docObj; + return true; +} + +//templates do not accept drops, so rather that let some other extension try to drop into a template, we will +//claim that we can handle drops +bool ViewProviderTemplateExtension::extensionCanDropObjects() const { + return true; +} + +//templates do not accept drops, so rather that let some other extension try to drop into a template, we will +//claim that we can handle drops +bool ViewProviderTemplateExtension::extensionCanDropObject(App::DocumentObject* docObj) const { + (void)docObj; + return true; +} + +const ViewProviderTemplate* ViewProviderTemplateExtension::getViewProviderTemplate() const +{ + return dynamic_cast(getExtendedViewProvider()); +} + +const char* ViewProviderTemplateExtension::whoAmI() const +{ + auto parent = getViewProviderTemplate(); + if (parent) { + return parent->whoAmI(); + } + return nullptr; +} + +namespace Gui { +EXTENSION_PROPERTY_SOURCE_TEMPLATE(ViewProviderTemplateExtensionPython, ViewProviderTemplateExtension) + +// explicit template instantiation +template class GuiExport ViewProviderExtensionPythonT; +} + + + diff --git a/src/Mod/TechDraw/Gui/ViewProviderTemplateExtension.h b/src/Mod/TechDraw/Gui/ViewProviderTemplateExtension.h new file mode 100644 index 0000000000..c302208e48 --- /dev/null +++ b/src/Mod/TechDraw/Gui/ViewProviderTemplateExtension.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (c) 2022 WandererFan * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef TECHDRAWGUI_VIEWPROVIDERTEMPLATEEXTENSION_H +#define TECHDRAWGUI_VIEWPROVIDERTEMPLATEEXTENSION_H + +#include +#include +#include +#include + +namespace TechDrawGui +{ +class ViewProviderTemplate; + +class TechDrawGuiExport ViewProviderTemplateExtension : public Gui::ViewProviderExtension +{ + EXTENSION_PROPERTY_HEADER_WITH_OVERRIDE(Gui::ViewProviderTemplateExtension); + +public: + /// Constructor + ViewProviderTemplateExtension(); + ~ViewProviderTemplateExtension() override; + + bool extensionCanDragObjects() const override; + bool extensionCanDragObject(App::DocumentObject* docObj) const override; + bool extensionCanDropObjects() const override; + bool extensionCanDropObject(App::DocumentObject* docObj) const override; + + const ViewProviderTemplate* getViewProviderTemplate() const; + const char* whoAmI() const; + +private: +}; + +using ViewProviderTemplateExtensionPython = Gui::ViewProviderExtensionPythonT; + +} //namespace Gui + +#endif // TECHDRAWGUI_VIEWPROVIDERTEMPLATEEXTENSION_H + + +