Extensions: Port ViewProvider of GeoFeatureGroup

This commit is contained in:
Stefan Tröger 2016-08-27 15:14:13 +02:00 committed by wmayer
parent cd53eb2280
commit 261798da2e
14 changed files with 272 additions and 114 deletions

View File

@ -120,10 +120,12 @@ public:
virtual ~ExtensionContainer();
void registerExtension(Base::Type extension, App::Extension* ext);
bool hasExtension(Base::Type) const;
bool hasExtension(Base::Type) const; //returns first of type (or derived from) and throws otherwise
bool hasExtension(const char* name) const; //this version does not check derived classes
App::Extension* getExtension(Base::Type);
App::Extension* getExtension(Base::Type); //returns first of type (or derived from) and throws otherwise
App::Extension* getExtension(const char* name); //this version does not check derived classes
//returns first of type (or derived from) and throws otherwise
template<typename ExtensionT>
ExtensionT* getExtensionByType() {
return dynamic_cast<ExtensionT*>(getExtension(ExtensionT::getClassTypeId()));

View File

@ -1473,6 +1473,7 @@ void Application::initTypes(void)
Gui::ViewProvider ::init();
Gui::ViewProviderExtension ::init();
Gui::ViewProviderGroupExtension ::init();
Gui::ViewProviderGeoFeatureGroupExtension ::init();
Gui::ViewProviderExtern ::init();
Gui::ViewProviderDocumentObject ::init();
Gui::ViewProviderFeature ::init();

View File

@ -823,6 +823,7 @@ SET(Viewprovider_CPP_SRCS
ViewProvider.cpp
ViewProviderExtension.cpp
ViewProviderGroupExtension.cpp
ViewProviderGeoFeatureGroupExtension.cpp
ViewProviderAnnotation.cpp
ViewProviderDocumentObject.cpp
ViewProviderDocumentObjectGroup.cpp
@ -852,6 +853,7 @@ SET(Viewprovider_SRCS
ViewProvider.h
ViewProviderExtension.h
ViewProviderGroupExtension.h
ViewProviderGeoFeatureGroupExtension.h
ViewProviderAnnotation.h
ViewProviderDocumentObject.h
ViewProviderDocumentObjectGroup.h

View File

@ -306,8 +306,30 @@ std::vector<std::string> ViewProvider::getDisplayMaskModes() const
void ViewProvider::setDisplayMode(const char* ModeName)
{
_sCurrentMode = ModeName;
//infom the exteensions
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionSetDisplayMode(ModeName);
}
const char* ViewProvider::getDefaultDisplayMode() const {
return 0;
}
vector<std::string> ViewProvider::getDisplayModes(void) const {
std::vector< std::string > modes;
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
auto extModes = ext->extensionGetDisplayModes();
modes.insert( modes.end(), extModes.begin(), extModes.end() );
}
return modes;
}
std::string ViewProvider::getActiveDisplayMode(void) const
{
return _sCurrentMode;
@ -593,4 +615,44 @@ void ViewProvider::Restore(Base::XMLReader& reader) {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionRestore(reader);
}
}
void ViewProvider::updateData(const App::Property* prop) {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionUpdateData(prop);
}
SoSeparator* ViewProvider::getBackRoot(void) const {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
auto* node = ext->extensionGetBackRoot();
if(node)
return node;
}
return nullptr;
}
SoGroup* ViewProvider::getChildRoot(void) const {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
auto* node = ext->extensionGetChildRoot();
if(node)
return node;
}
return nullptr;
}
SoSeparator* ViewProvider::getFrontRoot(void) const {
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector) {
auto* node = ext->extensionGetFrontRoot();
if(node)
return node;
}
return nullptr;
}

View File

@ -99,11 +99,11 @@ public:
// returns the root for the Annotations.
SoSeparator* getAnnotation(void);
// returns the root node of the Provider (3D)
virtual SoSeparator* getFrontRoot(void) const {return 0;}
virtual SoSeparator* getFrontRoot(void) const;
// returns the root node where the children gets collected(3D)
virtual SoGroup* getChildRoot(void) const {return 0;}
virtual SoGroup* getChildRoot(void) const;
// returns the root node of the Provider (3D)
virtual SoSeparator* getBackRoot(void) const {return 0;}
virtual SoSeparator* getBackRoot(void) const;
/** deliver the children belonging to this object
* this method is used to deliver the objects to
* the 3DView which should be grouped under its
@ -208,7 +208,7 @@ public:
* the data has manipulated.
*/
void update(const App::Property*);
virtual void updateData(const App::Property*)=0;
virtual void updateData(const App::Property*);
bool isUpdatesEnabled () const;
void setUpdatesEnabled (bool enable);
@ -227,9 +227,9 @@ public:
/// set the display mode
virtual void setDisplayMode(const char* ModeName);
/// get the default display mode
virtual const char* getDefaultDisplayMode() const=0;
virtual const char* getDefaultDisplayMode() const;
/// returns a list of all possible display modes
virtual std::vector<std::string> getDisplayModes(void) const=0;
virtual std::vector<std::string> getDisplayModes(void) const;
/// Hides the view provider
virtual void hide(void);
/// Shows the view provider
@ -313,7 +313,7 @@ public:
//restoring the object from document: this may itnerest extensions, hence call them
virtual void Restore(Base::XMLReader& reader);
protected:
/** @name Display mask modes
* Mainly controls an SoSwitch node which selects the display mask modes.
* The number of display mask modes doesn't necessarily match with the number
@ -332,6 +332,8 @@ protected:
std::vector<std::string> getDisplayMaskModes() const;
void setDefaultMode(int);
//@}
protected:
/** Helper method to get picked entities while editing.
* It's in the responsibility of the caller to delete the returned instance.
*/

View File

@ -42,6 +42,7 @@
#include "MDIView.h"
#include "TaskView/TaskAppearance.h"
#include "ViewProviderDocumentObject.h"
#include "ViewProviderExtension.h"
#include <Gui/ViewProviderDocumentObjectPy.h>
@ -160,7 +161,7 @@ void ViewProviderDocumentObject::attach(App::DocumentObject *pcObj)
{
// save Object pointer
pcObject = pcObj;
// Retrieve the supported display modes of the view provider
aDisplayModesArray = this->getDisplayModes();
@ -179,6 +180,11 @@ void ViewProviderDocumentObject::attach(App::DocumentObject *pcObj)
const char* defmode = this->getDefaultDisplayMode();
if (defmode)
DisplayMode.setValue(defmode);
//attach the extensions
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
for(Gui::ViewProviderExtension* ext : vector)
ext->extensionAttach(pcObj);
}
Gui::Document* ViewProviderDocumentObject::getDocument() const
@ -265,18 +271,6 @@ void ViewProviderDocumentObject::setActiveMode()
ViewProvider::hide();
}
const char* ViewProviderDocumentObject::getDefaultDisplayMode() const
{
// We use the first item then
return 0;
}
std::vector<std::string> ViewProviderDocumentObject::getDisplayModes(void) const
{
// empty
return std::vector<std::string>();
}
PyObject* ViewProviderDocumentObject::getPyObject()
{
if (!pyViewObject)

View File

@ -62,10 +62,6 @@ public:
App::PropertyBool Visibility;
virtual void attach(App::DocumentObject *pcObject);
/// Get the default display mode
virtual const char* getDefaultDisplayMode() const;
/// Return a list of all possible modes
virtual std::vector<std::string> getDisplayModes(void) const;
/// Set the active mode, i.e. the first item of the 'Display' property.
void setActiveMode();
/// Hide the object in the view
@ -78,8 +74,6 @@ public:
/// Run a redraw
void updateView();
/// Gets called if some of the property hade bin changed
virtual void updateData(const App::Property*){}
/// Get the object of this ViewProvider object
App::DocumentObject *getObject(void) const {return pcObject;}
/// Get the GUI document to this ViewProvider object

View File

@ -57,4 +57,7 @@ ViewProviderDocumentObject* ViewProviderExtension::getExtendedViewProvider() {
return static_cast<ViewProviderDocumentObject*>(getExtendedContainer());
}
void ViewProviderExtension::extensionUpdateData(const App::Property*) {
}

View File

@ -71,6 +71,16 @@ public:
virtual void extensionRestore(Base::XMLReader& reader) { };
virtual SoSeparator* extensionGetFrontRoot(void) const {return nullptr;}
virtual SoGroup* extensionGetChildRoot(void) const {return nullptr;}
virtual SoSeparator* extensionGetBackRoot(void) const {return nullptr;}
virtual void extensionAttach(App::DocumentObject* pcObject) { };
virtual void extensionSetDisplayMode(const char* ModeName) { };
virtual std::vector<std::string> extensionGetDisplayModes(void) const {return std::vector<std::string>();};
//update data of extended opject
virtual void extensionUpdateData(const App::Property*);
private:
Gui::ViewProviderDocumentObject* m_viewBase = nullptr;
};

View File

@ -36,58 +36,17 @@
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderGeoFeatureGroup, Gui::ViewProviderDocumentObjectGroup)
PROPERTY_SOURCE_WITH_EXTENSIONS(Gui::ViewProviderGeoFeatureGroup, Gui::ViewProviderDocumentObject, (Gui::ViewProviderGeoFeatureGroupExtension))
ViewProviderGeoFeatureGroup::ViewProviderGeoFeatureGroup()
{
pcGroupChildren = new SoGroup();
pcGroupChildren->ref();
ViewProviderGeoFeatureGroupExtension::initExtension(this);
}
ViewProviderGeoFeatureGroup::~ViewProviderGeoFeatureGroup()
{
pcGroupChildren->unref();
pcGroupChildren = 0;
}
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroup::claimChildren3D(void) const {
return dynamic_cast<App::GeoFeatureGroupExtension *>(getObject()->getExtension(App::GeoFeatureGroupExtension::getClassTypeId()))->getGeoSubObjects ();
}
void ViewProviderGeoFeatureGroup::attach(App::DocumentObject* pcObject)
{
Gui::ViewProviderDocumentObjectGroup::attach(pcObject);
addDisplayMaskMode(pcGroupChildren, "Group");
}
void ViewProviderGeoFeatureGroup::setDisplayMode(const char* ModeName)
{
if ( strcmp("Group",ModeName)==0 )
setDisplayMaskMode("Group");
ViewProviderDocumentObjectGroup::setDisplayMode( ModeName );
}
std::vector<std::string> ViewProviderGeoFeatureGroup::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderDocumentObjectGroup::getDisplayModes();
// add your own modes
StrList.push_back("Group");
return StrList;
}
void ViewProviderGeoFeatureGroup::updateData(const App::Property* prop)
{
App::GeoFeatureGroupExtension *obj = dynamic_cast<App::GeoFeatureGroupExtension*> ( getObject()->getExtension(App::GeoFeatureGroupExtension::getClassTypeId()) );
if (prop == &obj->Placement) {
setTransformation ( obj->Placement.getValue().toMatrix() );
} else {
ViewProviderDocumentObjectGroup::updateData ( prop );
}
}
// Python feature -----------------------------------------------------------------------

View File

@ -26,40 +26,22 @@
#define GUI_VIEWPROVIDER_ViewProviderGeoFeatureGroup_H
#include "ViewProviderDocumentObjectGroup.h"
#include "ViewProviderDocumentObject.h"
#include "ViewProviderGeoFeatureGroupExtension.h"
#include "ViewProviderPythonFeature.h"
namespace Gui {
class GuiExport ViewProviderGeoFeatureGroup : public ViewProviderDocumentObjectGroup
class GuiExport ViewProviderGeoFeatureGroup : public ViewProviderDocumentObject,
public ViewProviderGeoFeatureGroupExtension
{
PROPERTY_HEADER(Gui::ViewProviderGeoFeatureGroup);
PROPERTY_HEADER_WITH_EXTENSIONS(Gui::ViewProviderGeoFeatureGroup);
public:
/// constructor.
ViewProviderGeoFeatureGroup();
/// destructor.
virtual ~ViewProviderGeoFeatureGroup();
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
virtual SoGroup* getChildRoot(void) const {return pcGroupChildren;};
virtual void attach(App::DocumentObject* pcObject);
virtual void setDisplayMode(const char* ModeName);
virtual std::vector<std::string> getDisplayModes(void) const;
/// Show the object in the view: suppresses behavior of DocumentObjectGroup
virtual void show(void) {
ViewProviderDocumentObject::show();
}
/// Hide the object in the view: suppresses behavior of DocumentObjectGroup
virtual void hide(void) {
ViewProviderDocumentObject::hide();
}
virtual void updateData(const App::Property*);
protected:
SoGroup *pcGroupChildren;
};
typedef ViewProviderPythonFeatureT<ViewProviderGeoFeatureGroup> ViewProviderGeoFeatureGroupPython;

View File

@ -0,0 +1,90 @@
/***************************************************************************
* Copyright (c) 2016 Stefan Tröger <stefantroeger@gmx.net> *
* *
* 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_
#endif
#include "ViewProviderGeoFeatureGroupExtension.h"
#include <App/GeoFeatureGroupExtension.h>
#include <Inventor/nodes/SoGroup.h>
using namespace Gui;
PROPERTY_SOURCE(Gui::ViewProviderGeoFeatureGroupExtension, Gui::ViewProviderGroupExtension)
ViewProviderGeoFeatureGroupExtension::ViewProviderGeoFeatureGroupExtension()
{
initExtension(ViewProviderGeoFeatureGroupExtension::getClassTypeId());
pcGroupChildren = new SoGroup();
pcGroupChildren->ref();
}
ViewProviderGeoFeatureGroupExtension::~ViewProviderGeoFeatureGroupExtension()
{
pcGroupChildren->unref();
pcGroupChildren = 0;
}
std::vector<App::DocumentObject*> ViewProviderGeoFeatureGroupExtension::extensionClaimChildren3D(void) const {
auto* ext = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
return ext->getGeoSubObjects();
}
void ViewProviderGeoFeatureGroupExtension::extensionAttach(App::DocumentObject* pcObject)
{
ViewProviderGroupExtension::extensionAttach(pcObject);
getExtendedViewProvider()->addDisplayMaskMode(pcGroupChildren, "Group");
}
void ViewProviderGeoFeatureGroupExtension::extensionSetDisplayMode(const char* ModeName)
{
if ( strcmp("Group",ModeName)==0 )
getExtendedViewProvider()->setDisplayMaskMode("Group");
ViewProviderGroupExtension::extensionSetDisplayMode( ModeName );
}
std::vector<std::string> ViewProviderGeoFeatureGroupExtension::extensionGetDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderGroupExtension::extensionGetDisplayModes();
// add your own modes
StrList.push_back("Group");
return StrList;
}
void ViewProviderGeoFeatureGroupExtension::extensionUpdateData(const App::Property* prop)
{
auto obj = getExtendedViewProvider()->getObject()->getExtensionByType<App::GeoFeatureGroupExtension>();
if (prop == &obj->Placement) {
getExtendedViewProvider()->setTransformation ( obj->Placement.getValue().toMatrix() );
} else {
ViewProviderGroupExtension::extensionUpdateData ( prop );
}
}

View File

@ -0,0 +1,67 @@
/***************************************************************************
* Copyright (c) 2011 Juergen Riegel <FreeCAD@juergen-riegel.net> *
* Copyright (c) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> *
* Copyright (c) 2016 Stefan Tröger <stefantroeger@gmx.net> *
* *
* 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_VIEWPROVIDERGEOFEATUREGROUPEXTENSION_H
#define GUI_VIEWPROVIDERGEOFEATUREGROUPEXTENSION_H
#include <App/Extension.h>
#include "ViewProviderGroupExtension.h"
namespace Gui
{
class GuiExport ViewProviderGeoFeatureGroupExtension : public ViewProviderGroupExtension
{
PROPERTY_HEADER(Gui::ViewProviderGeoFeatureGroupExtension);
public:
/// Constructor
ViewProviderGeoFeatureGroupExtension(void);
virtual ~ViewProviderGeoFeatureGroupExtension();
virtual std::vector<App::DocumentObject*> extensionClaimChildren3D(void)const override;
virtual SoGroup* extensionGetChildRoot(void) const override {return pcGroupChildren;};
virtual void extensionAttach(App::DocumentObject* pcObject) override;
virtual void extensionSetDisplayMode(const char* ModeName) override;
virtual std::vector<std::string> extensionGetDisplayModes(void) const override;
/// Show the object in the view: suppresses behavior of DocumentObjectGroup
virtual void extensionShow(void) override {
ViewProviderExtension::extensionShow();
}
/// Hide the object in the view: suppresses behavior of DocumentObjectGroup
virtual void extensionHide(void) override {
ViewProviderExtension::extensionHide();
}
virtual void extensionUpdateData(const App::Property*) override;
protected:
SoGroup *pcGroupChildren;
};
} //namespace Gui
#endif // GUI_VIEWPROVIDERGEOFEATUREGROUPEXTENSION_H

View File

@ -76,9 +76,7 @@ bool ViewProviderGroupExtension::extensionCanDropObjects() const {
bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj) const {
auto vector = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
assert(vector.size() == 1);
App::GroupExtension* group = vector.front();
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
//we cannot drop thing of this group into it again
if (group->hasObject(obj))
@ -132,10 +130,9 @@ void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) {
std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren(void) const {
auto ext = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
assert(ext.size() == 1);
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
return std::vector<App::DocumentObject*>(ext.front()->Group.getValues());
return std::vector<App::DocumentObject*>(group->Group.getValues());
}
@ -144,10 +141,8 @@ void ViewProviderGroupExtension::extensionShow(void) {
// when reading the Visibility property from file then do not hide the
// objects of this group because they have stored their visibility status, too
if (!getExtendedViewProvider()->Visibility.testStatus(App::Property::User1) && !this->visible) {
auto ext = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
assert(ext.size() == 1);
App::GroupExtension* group = ext.front();
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
const std::vector<App::DocumentObject*> & links = group->Group.getValues();
Gui::Document* doc = Application::Instance->getDocument(group->getExtendedObject()->getDocument());
for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
@ -167,10 +162,8 @@ void ViewProviderGroupExtension::extensionHide(void) {
// objects of this group because they have stored their visibility status, too
if (!getExtendedViewProvider()->Visibility.testStatus(App::Property::User1) && this->visible) {
auto ext = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
assert(ext.size() == 1);
App::GroupExtension* group = ext.front();
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
const std::vector<App::DocumentObject*> & links = group->Group.getValues();
Gui::Document* doc = Application::Instance->getDocument(getExtendedViewProvider()->getObject()->getDocument());
for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
@ -186,10 +179,7 @@ void ViewProviderGroupExtension::extensionHide(void) {
bool ViewProviderGroupExtension::extensionOnDelete(const std::vector< std::string >& vec) {
auto ext = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
assert(ext.size() == 1);
App::GroupExtension *group = ext.front();
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
// If the group is nonempty ask the user if he wants to delete it's content
if ( group->Group.getSize () ) {
QMessageBox::StandardButton choice =