Extensions: Introduce ViewProviderExtension
This commit is contained in:
parent
1287f3007a
commit
8c002f1709
|
@ -94,6 +94,7 @@
|
|||
#include "SplitView3DInventor.h"
|
||||
#include "View3DInventor.h"
|
||||
#include "ViewProvider.h"
|
||||
#include "ViewProviderExtension.h"
|
||||
#include "ViewProviderExtern.h"
|
||||
#include "ViewProviderFeature.h"
|
||||
#include "ViewProviderPythonFeature.h"
|
||||
|
@ -1469,6 +1470,7 @@ void Application::initTypes(void)
|
|||
Gui::SplitView3DInventor ::init();
|
||||
// View Provider
|
||||
Gui::ViewProvider ::init();
|
||||
Gui::ViewProviderExtension ::init();
|
||||
Gui::ViewProviderExtern ::init();
|
||||
Gui::ViewProviderDocumentObject ::init();
|
||||
Gui::ViewProviderFeature ::init();
|
||||
|
|
|
@ -821,6 +821,7 @@ SOURCE_GROUP("Quarter" FILES ${Quarter_SRCS})
|
|||
# The view provider sources
|
||||
SET(Viewprovider_CPP_SRCS
|
||||
ViewProvider.cpp
|
||||
ViewProviderExtension.cpp
|
||||
ViewProviderAnnotation.cpp
|
||||
ViewProviderDocumentObject.cpp
|
||||
ViewProviderDocumentObjectGroup.cpp
|
||||
|
@ -848,6 +849,7 @@ SET(Viewprovider_CPP_SRCS
|
|||
SET(Viewprovider_SRCS
|
||||
${Viewprovider_CPP_SRCS}
|
||||
ViewProvider.h
|
||||
ViewProviderExtension.h
|
||||
ViewProviderAnnotation.h
|
||||
ViewProviderDocumentObject.h
|
||||
ViewProviderDocumentObjectGroup.h
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "View3DInventor.h"
|
||||
#include "View3DInventorViewer.h"
|
||||
#include "SoFCDB.h"
|
||||
#include "ViewProviderExtension.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace Gui;
|
||||
|
@ -315,11 +316,21 @@ std::string ViewProvider::getActiveDisplayMode(void) const
|
|||
void ViewProvider::hide(void)
|
||||
{
|
||||
pcModeSwitch->whichChild = -1;
|
||||
|
||||
//tell extensions that we hide
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
ext->extensionHide();
|
||||
}
|
||||
|
||||
void ViewProvider::show(void)
|
||||
{
|
||||
setModeSwitch();
|
||||
|
||||
//tell extensions that we show
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
ext->extensionShow();
|
||||
}
|
||||
|
||||
bool ViewProvider::isShow(void) const
|
||||
|
@ -499,4 +510,80 @@ bool ViewProvider::mouseButtonPressed(int button, bool pressed,
|
|||
(void)cursorPos;
|
||||
(void)viewer;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ViewProvider::onDelete(const vector< string >& subNames) {
|
||||
bool del = true;
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
del = del || ext->extensionOnDelete(subNames);
|
||||
|
||||
return del;
|
||||
}
|
||||
|
||||
bool ViewProvider::canDragObject(App::DocumentObject* obj) const {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
if(ext->extensionCanDragObject(obj))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ViewProvider::canDragObjects() const {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
if(ext->extensionCanDragObjects())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ViewProvider::dragObject(App::DocumentObject* obj) {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector) {
|
||||
if(ext->extensionCanDragObject(obj)) {
|
||||
ext->extensionDragObject(obj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw Base::Exception("ViewProvider::dragObject: no extension for draging given object available.");
|
||||
}
|
||||
|
||||
|
||||
bool ViewProvider::canDropObject(App::DocumentObject* obj) const {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
if(ext->extensionCanDropObject(obj))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ViewProvider::canDropObjects() const {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
if(ext->extensionCanDropObjects())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ViewProvider::dropObject(App::DocumentObject* obj) {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector) {
|
||||
if(ext->extensionCanDropObject(obj)) {
|
||||
ext->extensionDropObject(obj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw Base::Exception("ViewProvider::dropObject: no extension for droping given object available.");
|
||||
}
|
||||
|
|
|
@ -110,8 +110,7 @@ public:
|
|||
* scene graph. This affects the visibility and the 3D
|
||||
* position of the object.
|
||||
*/
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void) const
|
||||
{ return std::vector<App::DocumentObject*>(); }
|
||||
virtual std::vector<App::DocumentObject*> claimChildren3D(void) const;
|
||||
|
||||
/** @name Selection handling
|
||||
* This group of methods do the selection handling.
|
||||
|
@ -161,8 +160,7 @@ public:
|
|||
* be used for any kind of grouping needed for a special
|
||||
* purpose.
|
||||
*/
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void) const
|
||||
{ return std::vector<App::DocumentObject*>(); }
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void) const;
|
||||
//@}
|
||||
|
||||
/** @name Drag and drop
|
||||
|
@ -175,28 +173,22 @@ public:
|
|||
*/
|
||||
//@{
|
||||
/** Check whether children can be removed from the view provider by drag and drop */
|
||||
virtual bool canDragObjects() const
|
||||
{ return false; }
|
||||
virtual bool canDragObjects() const;
|
||||
/** Check whether the object can be removed from the view provider by drag and drop */
|
||||
virtual bool canDragObject(App::DocumentObject*) const
|
||||
{ return true; }
|
||||
virtual bool canDragObject(App::DocumentObject*) const;
|
||||
/** Tell the tree view if this object should apear there */
|
||||
virtual bool showInTree() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/** Remove a child from the view provider by drag and drop */
|
||||
virtual void dragObject(App::DocumentObject*)
|
||||
{ }
|
||||
virtual void dragObject(App::DocumentObject*);
|
||||
/** Check whether objects can be added to the view provider by drag and drop */
|
||||
virtual bool canDropObjects() const
|
||||
{ return false; }
|
||||
virtual bool canDropObjects() const;
|
||||
/** Check whether the object can be dropped to the view provider by drag and drop */
|
||||
virtual bool canDropObject(App::DocumentObject*) const
|
||||
{ return true; }
|
||||
virtual bool canDropObject(App::DocumentObject*) const;
|
||||
/** Add an object to the view provider by drag and drop */
|
||||
virtual void dropObject(App::DocumentObject*)
|
||||
{ }
|
||||
virtual void dropObject(App::DocumentObject*);
|
||||
//@}
|
||||
|
||||
/** @name Signals of the view provider */
|
||||
|
|
|
@ -63,65 +63,8 @@ ViewProviderDocumentObjectGroup::~ViewProviderDocumentObjectGroup()
|
|||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Whenever a property of the group gets changed then the same property of all
|
||||
* associated view providers of the objects of the object group get changed as well.
|
||||
*/
|
||||
void ViewProviderDocumentObjectGroup::onChanged(const App::Property* prop)
|
||||
{
|
||||
ViewProviderDocumentObject::onChanged(prop);
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::attach(App::DocumentObject *pcObj)
|
||||
{
|
||||
ViewProviderDocumentObject::attach(pcObj);
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::updateData(const App::Property* prop)
|
||||
{
|
||||
#if 0
|
||||
if (prop->getTypeId() == App::PropertyLinkList::getClassTypeId()) {
|
||||
std::vector<App::DocumentObject*> obj =
|
||||
static_cast<const App::PropertyLinkList*>(prop)->getValues();
|
||||
Gui::Document* doc = Gui::Application::Instance->getDocument
|
||||
(&this->getObject()->getDocument());
|
||||
MDIView* mdi = doc->getActiveView();
|
||||
if (mdi && mdi->isDerivedFrom(View3DInventor::getClassTypeId())) {
|
||||
View3DInventorViewer* view = static_cast<View3DInventor*>(mdi)->getViewer();
|
||||
SoSeparator* scene_graph = static_cast<SoSeparator*>(view->getSceneGraph());
|
||||
std::vector<ViewProvider*> current_nodes;
|
||||
for (std::vector<App::DocumentObject*>::iterator it = obj.begin(); it != obj.end(); ++it)
|
||||
current_nodes.push_back(doc->getViewProvider(*it));
|
||||
std::sort(current_nodes.begin(), current_nodes.end());
|
||||
std::sort(this->nodes.begin(), this->nodes.end());
|
||||
// get the removed views
|
||||
std::vector<ViewProvider*> diff_1, diff_2;
|
||||
std::back_insert_iterator<std::vector<ViewProvider*> > biit(diff_2);
|
||||
std::set_difference(this->nodes.begin(), this->nodes.end(),
|
||||
current_nodes.begin(), current_nodes.end(), biit);
|
||||
diff_1 = diff_2;
|
||||
diff_2.clear();
|
||||
// get the added views
|
||||
std::set_difference(current_nodes.begin(), current_nodes.end(),
|
||||
this->nodes.begin(), this->nodes.end(), biit);
|
||||
this->nodes = current_nodes;
|
||||
// move from root node to switch
|
||||
for (std::vector<ViewProvider*>::iterator it = diff_1.begin(); it != diff_1.end(); ++it) {
|
||||
view->addViewProviderToGroup(*it, scene_graph);
|
||||
view->removeViewProviderFromGroup(*it, this->pcModeSwitch);
|
||||
}
|
||||
// move from switch node to root node
|
||||
for (std::vector<ViewProvider*>::iterator it = diff_2.begin(); it != diff_2.end(); ++it) {
|
||||
view->addViewProviderToGroup(*it, this->pcModeSwitch);
|
||||
view->removeViewProviderFromGroup(*it, scene_graph);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(prop);
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> ViewProviderDocumentObjectGroup::claimChildren(void)const
|
||||
{
|
||||
return std::vector<App::DocumentObject*>(static_cast<App::DocumentObjectGroup*>(getObject())->Group.getValues());
|
||||
|
|
|
@ -46,8 +46,6 @@ public:
|
|||
virtual bool canDropObjects() const;
|
||||
virtual void dropObject(App::DocumentObject*);
|
||||
|
||||
void attach(App::DocumentObject *pcObject);
|
||||
void updateData(const App::Property*);
|
||||
void Restore(Base::XMLReader &reader);
|
||||
QIcon getIcon(void) const;
|
||||
/// returns a list of all possible modes
|
||||
|
@ -70,8 +68,6 @@ public:
|
|||
const QPoint &pos);
|
||||
|
||||
protected:
|
||||
/// get called by the container whenever a property has been changed
|
||||
void onChanged(const App::Property* prop);
|
||||
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;
|
||||
|
||||
private:
|
||||
|
|
55
src/Gui/ViewProviderExtension.cpp
Normal file
55
src/Gui/ViewProviderExtension.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2016 *
|
||||
* *
|
||||
* 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 <cassert>
|
||||
# include <algorithm>
|
||||
#endif
|
||||
|
||||
#include "ViewProviderExtension.h"
|
||||
//#include "ViewProviderExtensionPy.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
PROPERTY_SOURCE(Gui::ViewProviderExtension, App::Extension)
|
||||
|
||||
ViewProviderExtension::ViewProviderExtension()
|
||||
{
|
||||
initExtension(Gui::ViewProviderExtension::getClassTypeId());
|
||||
}
|
||||
|
||||
ViewProviderExtension::~ViewProviderExtension()
|
||||
{
|
||||
|
||||
}
|
||||
/*
|
||||
PyObject* ViewProviderExtension::getExtensionPyObject(void) {
|
||||
|
||||
if (ExtensionPythonObject.is(Py::_None())){
|
||||
// ref counter is set to 1
|
||||
ExtensionPythonObject = Py::Object(new ViewProviderExtensionPy(this),true);
|
||||
}
|
||||
return Py::new_reference_to(ExtensionPythonObject);
|
||||
}*/
|
71
src/Gui/ViewProviderExtension.h
Normal file
71
src/Gui/ViewProviderExtension.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) Stefan Tröger (stefantroeger@gmx.net) 2016 *
|
||||
* *
|
||||
* 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 GUI_VIEWPROVIDEREXTENSION_H
|
||||
#define GUI_VIEWPROVIDEREXTENSION_H
|
||||
|
||||
#include "App/Extension.h"
|
||||
#include "ViewProvider.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
/**
|
||||
* @brief Extension with special viewprovider calls
|
||||
*
|
||||
*/
|
||||
class GuiExport ViewProviderExtension : public App::Extension
|
||||
{
|
||||
|
||||
//The cass does not have properties itself, but it is important to provide the property access
|
||||
//functions. see cpp file for details
|
||||
PROPERTY_HEADER(Gui::ViewProviderExtension );
|
||||
|
||||
public:
|
||||
|
||||
ViewProviderExtension ();
|
||||
virtual ~ViewProviderExtension ();
|
||||
|
||||
virtual std::vector<App::DocumentObject*> extensionClaimChildren3D(void) const {
|
||||
return std::vector<App::DocumentObject*>(); }
|
||||
|
||||
virtual bool extensionOnDelete(const std::vector<std::string> &subNames){ return true;}
|
||||
|
||||
virtual std::vector<App::DocumentObject*> extensionClaimChildren(void) const {
|
||||
return std::vector<App::DocumentObject*>(); }
|
||||
|
||||
virtual bool extensionCanDragObjects() const { return false; }
|
||||
virtual bool extensionCanDragObject(App::DocumentObject*) const { return true; }
|
||||
virtual void extensionDragObject(App::DocumentObject*) { }
|
||||
virtual bool extensionCanDropObjects() const { return false; }
|
||||
virtual bool extensionCanDropObject(App::DocumentObject*) const { return true; }
|
||||
virtual void extensionDropObject(App::DocumentObject*) { }
|
||||
|
||||
/// Hides the view provider
|
||||
virtual void extensionHide(void) { };
|
||||
/// Shows the view provider
|
||||
virtual void extensionShow(void) { };
|
||||
};
|
||||
|
||||
} //App
|
||||
|
||||
#endif // GUI_VIEWPROVIDEREXTENSION_H
|
Loading…
Reference in New Issue
Block a user