[TD]add extensions for drag and drop

This commit is contained in:
wandererfan
2022-11-27 22:23:12 -05:00
committed by WandererFan
parent c23e1d1bb3
commit ff1147fbae
16 changed files with 656 additions and 51 deletions

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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

View File

@@ -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

View File

@@ -42,6 +42,7 @@
#include <Mod/TechDraw/App/DrawView.h>
#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<TechDraw::DrawView*>(pcObject);

View File

@@ -31,6 +31,7 @@
#include <Gui/ViewProviderDocumentObject.h>
#include <Mod/TechDraw/App/DrawView.h>
#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<TechDraw::DrawPage*>& pages);
void singleParentPaint(const TechDraw::DrawView* dv);
std::string m_myName;
};
} // namespace TechDrawGui

View File

@@ -0,0 +1,108 @@
/***************************************************************************
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
* *
* 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 <QMessageBox>
#endif
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
#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<const ViewProviderDrawingView*>(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<ViewProviderDrawingViewExtension>;
}

View File

@@ -0,0 +1,63 @@
/***************************************************************************
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
* *
* 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 <Mod/TechDraw/TechDrawGlobal.h>
#include <Gui/ViewProviderExtension.h>
#include <Gui/ViewProviderExtensionPy.h>
#include <Gui/ViewProviderExtensionPython.h>
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<ViewProviderDrawingViewExtension>;
} //namespace Gui
#endif // TECHDRAWGUI_VIEWPROVIDERDRAWINGVIEWEXTENSION_H

View File

@@ -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<std::string> &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<TechDraw::DrawView*>(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<ViewProviderPageExtension>();
auto vppe = static_cast<ViewProviderPageExtension*>(vpe);
return vppe;
}
const char* ViewProviderPage::whoAmI() const
{
return m_pageName.c_str();
}

View File

@@ -32,6 +32,7 @@
#include <App/PropertyUnits.h>
#include <Gui/ViewProviderDocumentObject.h>
#include <ViewProviderPageExtension.h>
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<std::string> &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();

View File

@@ -0,0 +1,134 @@
/***************************************************************************
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
* *
* 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 <QMessageBox>
#endif
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
#include <Mod/TechDraw/App/DrawProjGroupItem.h>
#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<TechDraw::DrawView*>(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<const ViewProviderPage*>(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<ViewProviderPageExtension>;
}

View File

@@ -0,0 +1,64 @@
/***************************************************************************
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
* *
* 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 <Mod/TechDraw/TechDrawGlobal.h>
#include <Gui/ViewProviderExtension.h>
#include <Gui/ViewProviderExtensionPy.h>
#include <Gui/ViewProviderExtensionPython.h>
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<ViewProviderPageExtension>;
} //namespace Gui
#endif // TECHDRAWGUI_VIEWPROVIDERPAGEEXTENSION_H

View File

@@ -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<TechDraw::DrawSVGTemplate*>(getTemplate());
if (prop == &(t->Template)) {
@@ -217,3 +227,8 @@ TechDraw::DrawTemplate* ViewProviderTemplate::getTemplate() const
{
return dynamic_cast<TechDraw::DrawTemplate*>(pcObject);
}
const char* ViewProviderTemplate::whoAmI() const
{
return m_myName.c_str();
}

View File

@@ -22,9 +22,12 @@
#ifndef DRAWINGGUI_VIEWPROVIDERTEMPLATE_H
#define DRAWINGGUI_VIEWPROVIDERTEMPLATE_H
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <Mod/TechDraw/TechDrawGlobal.h>
#include <Gui/ViewProviderDocumentObject.h>
#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<std::string> &) override;
const char* whoAmI() const;
private:
std::string m_myName;
};
} // namespace TechDrawGui

View File

@@ -0,0 +1,101 @@
/***************************************************************************
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
* *
* 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 <QMessageBox>
#endif
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <Base/Console.h>
#include <Base/Tools.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawTemplate.h>
#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<const ViewProviderTemplate*>(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<ViewProviderTemplateExtension>;
}

View File

@@ -0,0 +1,62 @@
/***************************************************************************
* Copyright (c) 2022 WandererFan <wandererfan@gmail.com> *
* *
* 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 <Mod/TechDraw/TechDrawGlobal.h>
#include <Gui/ViewProviderExtension.h>
#include <Gui/ViewProviderExtensionPy.h>
#include <Gui/ViewProviderExtensionPython.h>
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<ViewProviderTemplateExtension>;
} //namespace Gui
#endif // TECHDRAWGUI_VIEWPROVIDERTEMPLATEEXTENSION_H