Extensions: Port ViewProvider of groups
This commit is contained in:
parent
8c002f1709
commit
0a539538de
|
@ -75,3 +75,15 @@ PyObject* DocumentObjectExtension::getExtensionPyObject(void) {
|
|||
}
|
||||
return Py::new_reference_to(ExtensionPythonObject);
|
||||
}
|
||||
|
||||
const DocumentObject* DocumentObjectExtension::getExtendedObject() const {
|
||||
|
||||
assert(getExtendedContainer()->isDerivedFrom(DocumentObject::getClassTypeId()));
|
||||
return static_cast<const DocumentObject*>(getExtendedContainer());
|
||||
}
|
||||
|
||||
DocumentObject* DocumentObjectExtension::getExtendedObject() {
|
||||
|
||||
assert(getExtendedContainer()->isDerivedFrom(DocumentObject::getClassTypeId()));
|
||||
return static_cast<DocumentObject*>(getExtendedContainer());
|
||||
}
|
||||
|
|
|
@ -45,6 +45,9 @@ public:
|
|||
DocumentObjectExtension ();
|
||||
virtual ~DocumentObjectExtension ();
|
||||
|
||||
App::DocumentObject* getExtendedObject();
|
||||
const App::DocumentObject* getExtendedObject() const;
|
||||
|
||||
//override if execution is nesseccary
|
||||
virtual short extensionMustExecute(void);
|
||||
virtual App::DocumentObjectExecReturn *extensionExecute(void);
|
||||
|
@ -58,6 +61,10 @@ public:
|
|||
virtual void onExtendedUnsetupObject();
|
||||
|
||||
virtual PyObject* getExtensionPyObject(void);
|
||||
|
||||
/// returns the type name of the ViewProviderExtension which is automatically attached
|
||||
/// to the viewprovider object when it is initiated
|
||||
virtual const char* getViewProviderExtensionName(void) const {return "";};
|
||||
};
|
||||
|
||||
} //App
|
||||
|
|
|
@ -66,7 +66,7 @@ void Extension::initExtension(Base::Type type) {
|
|||
throw Base::Exception("Extension: Extension type not set");
|
||||
}
|
||||
|
||||
void Extension::initExtension(DocumentObject* obj) {
|
||||
void Extension::initExtension(ExtensionContainer* obj) {
|
||||
|
||||
if(m_extensionType.isBad())
|
||||
throw Base::Exception("Extension: Extension type not set");
|
||||
|
|
|
@ -31,6 +31,8 @@
|
|||
|
||||
namespace App {
|
||||
|
||||
class ExtensionContainer;
|
||||
|
||||
/**
|
||||
* @brief Base class for all extension that can be added to a DocumentObject
|
||||
*
|
||||
|
@ -135,10 +137,10 @@ public:
|
|||
Extension();
|
||||
virtual ~Extension();
|
||||
|
||||
void initExtension(App::DocumentObject* obj);
|
||||
void initExtension(App::ExtensionContainer* obj);
|
||||
|
||||
App::DocumentObject* getExtendedObject() {return m_base;};
|
||||
const App::DocumentObject* getExtendedObject() const {return m_base;};
|
||||
App::ExtensionContainer* getExtendedContainer() {return m_base;};
|
||||
const App::ExtensionContainer* getExtendedContainer() const {return m_base;};
|
||||
|
||||
//get extension name without namespace
|
||||
const char* name();
|
||||
|
@ -153,8 +155,8 @@ protected:
|
|||
Py::Object ExtensionPythonObject;
|
||||
|
||||
private:
|
||||
Base::Type m_extensionType;
|
||||
App::DocumentObject* m_base = nullptr;
|
||||
Base::Type m_extensionType;
|
||||
App::ExtensionContainer* m_base = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ ExtensionContainer::~ExtensionContainer() {
|
|||
|
||||
void ExtensionContainer::registerExtension(Base::Type extension, Extension* ext) {
|
||||
|
||||
if(ext->getExtendedObject() != this)
|
||||
if(ext->getExtendedContainer() != this)
|
||||
throw Base::Exception("ExtensionContainer::registerExtension: Extension has not this as base object");
|
||||
|
||||
//no duplicate extensions (including base classes)
|
||||
|
|
|
@ -118,6 +118,7 @@
|
|||
#include "TaskView/TaskDialogPython.h"
|
||||
#include <Gui/Quarter/Quarter.h>
|
||||
#include "View3DViewerPy.h"
|
||||
#include "ViewProviderGroupExtension.h"
|
||||
#include "GuiInitScript.h"
|
||||
|
||||
|
||||
|
@ -1471,6 +1472,7 @@ void Application::initTypes(void)
|
|||
// View Provider
|
||||
Gui::ViewProvider ::init();
|
||||
Gui::ViewProviderExtension ::init();
|
||||
Gui::ViewProviderGroupExtension ::init();
|
||||
Gui::ViewProviderExtern ::init();
|
||||
Gui::ViewProviderDocumentObject ::init();
|
||||
Gui::ViewProviderFeature ::init();
|
||||
|
|
|
@ -822,6 +822,7 @@ SOURCE_GROUP("Quarter" FILES ${Quarter_SRCS})
|
|||
SET(Viewprovider_CPP_SRCS
|
||||
ViewProvider.cpp
|
||||
ViewProviderExtension.cpp
|
||||
ViewProviderGroupExtension.cpp
|
||||
ViewProviderAnnotation.cpp
|
||||
ViewProviderDocumentObject.cpp
|
||||
ViewProviderDocumentObjectGroup.cpp
|
||||
|
@ -850,6 +851,7 @@ SET(Viewprovider_SRCS
|
|||
${Viewprovider_CPP_SRCS}
|
||||
ViewProvider.h
|
||||
ViewProviderExtension.h
|
||||
ViewProviderGroupExtension.h
|
||||
ViewProviderAnnotation.h
|
||||
ViewProviderDocumentObject.h
|
||||
ViewProviderDocumentObjectGroup.h
|
||||
|
|
|
@ -587,3 +587,10 @@ void ViewProvider::dropObject(App::DocumentObject* obj) {
|
|||
|
||||
throw Base::Exception("ViewProvider::dropObject: no extension for droping given object available.");
|
||||
}
|
||||
|
||||
void ViewProvider::Restore(Base::XMLReader& reader) {
|
||||
|
||||
auto vector = getExtensionsDerivedFromType<Gui::ViewProviderExtension>();
|
||||
for(Gui::ViewProviderExtension* ext : vector)
|
||||
ext->extensionRestore(reader);
|
||||
}
|
|
@ -309,6 +309,9 @@ public:
|
|||
public:
|
||||
// this method is called by the viewer when the ViewProvider is in edit
|
||||
static void eventCallback(void * ud, SoEventCallback * node);
|
||||
|
||||
//restoring the object from document: this may itnerest extensions, hence call them
|
||||
virtual void Restore(Base::XMLReader& reader);
|
||||
|
||||
protected:
|
||||
/** @name Display mask modes
|
||||
|
|
|
@ -41,22 +41,24 @@
|
|||
#include "Tree.h"
|
||||
#include "View3DInventor.h"
|
||||
#include "View3DInventorViewer.h"
|
||||
#include <Base/Console.h>
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
|
||||
PROPERTY_SOURCE(Gui::ViewProviderDocumentObjectGroup, Gui::ViewProviderDocumentObject)
|
||||
PROPERTY_SOURCE_WITH_EXTENSIONS(Gui::ViewProviderDocumentObjectGroup, Gui::ViewProviderDocumentObject, (Gui::ViewProviderGroupExtension))
|
||||
|
||||
|
||||
/**
|
||||
* Creates the view provider for an object group.
|
||||
*/
|
||||
ViewProviderDocumentObjectGroup::ViewProviderDocumentObjectGroup() : visible(false)
|
||||
ViewProviderDocumentObjectGroup::ViewProviderDocumentObjectGroup()
|
||||
{
|
||||
#if 0
|
||||
setDefaultMode(SO_SWITCH_ALL);
|
||||
#endif
|
||||
ViewProviderGroupExtension::initExtension(this);
|
||||
}
|
||||
|
||||
ViewProviderDocumentObjectGroup::~ViewProviderDocumentObjectGroup()
|
||||
|
@ -65,68 +67,16 @@ ViewProviderDocumentObjectGroup::~ViewProviderDocumentObjectGroup()
|
|||
|
||||
#else
|
||||
Q_UNUSED(prop);
|
||||
std::vector<App::DocumentObject*> ViewProviderDocumentObjectGroup::claimChildren(void)const
|
||||
{
|
||||
return std::vector<App::DocumentObject*>(static_cast<App::DocumentObjectGroup*>(getObject())->Group.getValues());
|
||||
}
|
||||
|
||||
bool ViewProviderDocumentObjectGroup::canDragObjects() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::dragObject(App::DocumentObject* obj)
|
||||
{
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObject("
|
||||
"App.getDocument(\"%s\").getObject(\"%s\"))",
|
||||
getObject()->getDocument()->getName(), getObject()->getNameInDocument(),
|
||||
obj->getDocument()->getName(), obj->getNameInDocument() );
|
||||
}
|
||||
|
||||
bool ViewProviderDocumentObjectGroup::canDropObjects() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::dropObject(App::DocumentObject* obj)
|
||||
{
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").addObject("
|
||||
"App.getDocument(\"%s\").getObject(\"%s\"))",
|
||||
getObject()->getDocument()->getName(), getObject()->getNameInDocument(),
|
||||
obj->getDocument()->getName(), obj->getNameInDocument() );
|
||||
}
|
||||
|
||||
std::vector<std::string> ViewProviderDocumentObjectGroup::getDisplayModes(void) const
|
||||
{
|
||||
// empty
|
||||
return std::vector<std::string>();
|
||||
}
|
||||
|
||||
bool ViewProviderDocumentObjectGroup::onDelete(const std::vector<std::string> &)
|
||||
{
|
||||
App::DocumentObjectGroup *group = static_cast<App::DocumentObjectGroup *> (getObject());
|
||||
// If the group is nonempty ask the user if he wants to delete it's content
|
||||
if ( group->Group.getSize () ) {
|
||||
QMessageBox::StandardButton choice =
|
||||
QMessageBox::question ( 0, QObject::tr ( "Delete group content?" ),
|
||||
QObject::tr ( "The %1 is not empty, delete it's content as well?")
|
||||
.arg ( QString::fromUtf8 ( group->Label.getValue () ) ),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
|
||||
if ( choice == QMessageBox::Yes ) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()"
|
||||
,getObject()->getDocument()->getName(), getObject()->getNameInDocument());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderDocumentObjectGroup::allowDrop(const std::vector<const App::DocumentObject*> &objList,
|
||||
Qt::KeyboardModifiers keys,
|
||||
Qt::MouseButtons mouseBts,
|
||||
const QPoint &pos)
|
||||
{
|
||||
Q_UNUSED(keys);
|
||||
Q_UNUSED(mouseBts);
|
||||
Q_UNUSED(pos);
|
||||
|
@ -139,7 +89,8 @@ bool ViewProviderDocumentObjectGroup::allowDrop(const std::vector<const App::Doc
|
|||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;*/
|
||||
Base::Console().Message("allow drop called");
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::drop(const std::vector<const App::DocumentObject*> &objList,
|
||||
|
@ -184,60 +135,11 @@ void ViewProviderDocumentObjectGroup::drop(const std::vector<const App::Document
|
|||
gui->commitCommand();
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::hide(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 (!Visibility.testStatus(App::Property::User1) && this->visible) {
|
||||
App::DocumentObject * group = getObject();
|
||||
if (group && group->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
|
||||
const std::vector<App::DocumentObject*> & links = static_cast<App::DocumentObjectGroup*>
|
||||
(group)->Group.getValues();
|
||||
Gui::Document* doc = Application::Instance->getDocument(group->getDocument());
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
|
||||
ViewProvider* view = doc->getViewProvider(*it);
|
||||
if (view) view->hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderDocumentObject::hide();
|
||||
this->visible = false;
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::show(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 (!Visibility.testStatus(App::Property::User1) && !this->visible) {
|
||||
App::DocumentObject * group = getObject();
|
||||
if (group && group->getTypeId().isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
|
||||
const std::vector<App::DocumentObject*> & links = static_cast<App::DocumentObjectGroup*>
|
||||
(group)->Group.getValues();
|
||||
Gui::Document* doc = Application::Instance->getDocument(group->getDocument());
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
|
||||
ViewProvider* view = doc->getViewProvider(*it);
|
||||
if (view) view->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderDocumentObject::show();
|
||||
this->visible = true;
|
||||
}
|
||||
|
||||
bool ViewProviderDocumentObjectGroup::isShow(void) const
|
||||
{
|
||||
return Visibility.getValue();
|
||||
}
|
||||
|
||||
void ViewProviderDocumentObjectGroup::Restore(Base::XMLReader &reader)
|
||||
{
|
||||
Visibility.setStatus(App::Property::User1, true); // tmp. set
|
||||
ViewProviderDocumentObject::Restore(reader);
|
||||
Visibility.setStatus(App::Property::User1, false); // unset
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the associated view providers of the objects of the associated object group group.
|
||||
*/
|
||||
|
|
|
@ -27,12 +27,14 @@
|
|||
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
#include "ViewProviderPythonFeature.h"
|
||||
#include "ViewProviderGroupExtension.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport ViewProviderDocumentObjectGroup : public ViewProviderDocumentObject
|
||||
class GuiExport ViewProviderDocumentObjectGroup : public ViewProviderDocumentObject,
|
||||
public ViewProviderGroupExtension
|
||||
{
|
||||
PROPERTY_HEADER(Gui::ViewProviderDocumentObjectGroup);
|
||||
PROPERTY_HEADER_WITH_EXTENSIONS(Gui::ViewProviderDocumentObjectGroup);
|
||||
|
||||
public:
|
||||
/// constructor.
|
||||
|
@ -40,22 +42,11 @@ public:
|
|||
/// destructor.
|
||||
virtual ~ViewProviderDocumentObjectGroup();
|
||||
|
||||
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
|
||||
virtual bool canDragObjects() const;
|
||||
virtual void dragObject(App::DocumentObject*);
|
||||
virtual bool canDropObjects() const;
|
||||
virtual void dropObject(App::DocumentObject*);
|
||||
|
||||
void Restore(Base::XMLReader &reader);
|
||||
QIcon getIcon(void) const;
|
||||
/// returns a list of all possible modes
|
||||
std::vector<std::string> getDisplayModes(void) const;
|
||||
virtual void hide(void);
|
||||
virtual void show(void);
|
||||
bool isShow(void) const;
|
||||
|
||||
virtual bool onDelete(const std::vector<std::string> &);
|
||||
|
||||
/// get called if the user hover over a object in the tree
|
||||
virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,
|
||||
Qt::KeyboardModifiers keys,
|
||||
|
@ -71,7 +62,6 @@ protected:
|
|||
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;
|
||||
|
||||
private:
|
||||
bool visible; // helper variable
|
||||
std::vector<ViewProvider*> nodes;
|
||||
};
|
||||
|
||||
|
|
|
@ -44,12 +44,17 @@ 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);
|
||||
}*/
|
||||
|
||||
const ViewProviderDocumentObject* ViewProviderExtension::getExtendedViewProvider() const{
|
||||
|
||||
assert(getExtendedContainer()->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()));
|
||||
return static_cast<const ViewProviderDocumentObject*>(getExtendedContainer());
|
||||
}
|
||||
|
||||
ViewProviderDocumentObject* ViewProviderExtension::getExtendedViewProvider() {
|
||||
|
||||
assert(getExtendedContainer()->isDerivedFrom(ViewProviderDocumentObject::getClassTypeId()));
|
||||
return static_cast<ViewProviderDocumentObject*>(getExtendedContainer());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include "App/Extension.h"
|
||||
#include "ViewProvider.h"
|
||||
#include "ViewProviderDocumentObject.h"
|
||||
|
||||
namespace Gui {
|
||||
|
||||
|
@ -37,14 +38,17 @@ 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 );
|
||||
//functions.
|
||||
PROPERTY_HEADER(Gui::ViewProviderExtension);
|
||||
|
||||
public:
|
||||
|
||||
ViewProviderExtension ();
|
||||
virtual ~ViewProviderExtension ();
|
||||
|
||||
Gui::ViewProviderDocumentObject* getExtendedViewProvider();
|
||||
const Gui::ViewProviderDocumentObject* getExtendedViewProvider() const;
|
||||
|
||||
virtual std::vector<App::DocumentObject*> extensionClaimChildren3D(void) const {
|
||||
return std::vector<App::DocumentObject*>(); }
|
||||
|
||||
|
@ -64,6 +68,11 @@ public:
|
|||
virtual void extensionHide(void) { };
|
||||
/// Shows the view provider
|
||||
virtual void extensionShow(void) { };
|
||||
|
||||
virtual void extensionRestore(Base::XMLReader& reader) { };
|
||||
|
||||
private:
|
||||
Gui::ViewProviderDocumentObject* m_viewBase = nullptr;
|
||||
};
|
||||
|
||||
} //App
|
||||
|
|
181
src/Gui/ViewProviderGroupExtension.cpp
Normal file
181
src/Gui/ViewProviderGroupExtension.cpp
Normal file
|
@ -0,0 +1,181 @@
|
|||
/***************************************************************************
|
||||
* 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 "ViewProviderGroupExtensionPy.h"
|
||||
#include "ViewProviderGroupExtension.h"
|
||||
|
||||
#include "Command.h"
|
||||
#include "Application.h"
|
||||
#include "Document.h"
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/GroupExtension.h>
|
||||
#include <App/Expression.h>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
PROPERTY_SOURCE(Gui::ViewProviderGroupExtension, Gui::ViewProviderExtension)
|
||||
|
||||
ViewProviderGroupExtension::ViewProviderGroupExtension() : visible(false)
|
||||
{
|
||||
initExtension(ViewProviderGroupExtension::getClassTypeId());
|
||||
|
||||
}
|
||||
|
||||
ViewProviderGroupExtension::~ViewProviderGroupExtension()
|
||||
{
|
||||
}
|
||||
|
||||
bool ViewProviderGroupExtension::extensionCanDragObjects() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderGroupExtension::extensionCanDragObject(App::DocumentObject*) const {
|
||||
|
||||
//we can drag anything out
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderGroupExtension::extensionDragObject(App::DocumentObject* obj) {
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObject("
|
||||
"App.getDocument(\"%s\").getObject(\"%s\"))",
|
||||
getExtendedViewProvider()->getObject()->getDocument()->getName(), getExtendedViewProvider()->getObject()->getNameInDocument(),
|
||||
obj->getDocument()->getName(), obj->getNameInDocument() );
|
||||
}
|
||||
|
||||
bool ViewProviderGroupExtension::extensionCanDropObjects() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderGroupExtension::extensionCanDropObject(App::DocumentObject* obj) const {
|
||||
|
||||
//we cannot drop anything into the group. We need to find the correct App extension to ask
|
||||
//if this is a supported type, there should only be one
|
||||
auto vector = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
|
||||
assert(vector.size() == 1);
|
||||
if(vector[0]->allowObject(obj))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) {
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").addObject("
|
||||
"App.getDocument(\"%s\").getObject(\"%s\"))",
|
||||
getExtendedViewProvider()->getObject()->getDocument()->getName(), getExtendedViewProvider()->getObject()->getNameInDocument(),
|
||||
obj->getDocument()->getName(), obj->getNameInDocument() );
|
||||
}
|
||||
|
||||
std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren(void) const {
|
||||
|
||||
auto ext = getExtendedViewProvider()->getObject()->getExtensionsDerivedFromType<App::GroupExtension>();
|
||||
assert(ext.size() == 1);
|
||||
|
||||
return std::vector<App::DocumentObject*>(ext.front()->Group.getValues());
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
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) {
|
||||
ViewProvider* view = doc->getViewProvider(*it);
|
||||
if (view)
|
||||
view->show();
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderExtension::extensionShow();
|
||||
this->visible = true;
|
||||
}
|
||||
|
||||
void ViewProviderGroupExtension::extensionHide(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();
|
||||
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) {
|
||||
ViewProvider* view = doc->getViewProvider(*it);
|
||||
if (view)
|
||||
view->hide();
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderExtension::extensionHide();
|
||||
this->visible = false;
|
||||
}
|
||||
|
||||
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();
|
||||
// If the group is nonempty ask the user if he wants to delete it's content
|
||||
if ( group->Group.getSize () ) {
|
||||
QMessageBox::StandardButton choice =
|
||||
QMessageBox::question ( 0, QObject::tr ( "Delete group content?" ),
|
||||
QObject::tr ( "The %1 is not empty, delete it's content as well?")
|
||||
.arg ( QString::fromUtf8 ( getExtendedViewProvider()->getObject()->Label.getValue () ) ),
|
||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes );
|
||||
|
||||
if ( choice == QMessageBox::Yes ) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()"
|
||||
,getExtendedViewProvider()->getObject()->getDocument()->getName(), getExtendedViewProvider()->getObject()->getNameInDocument());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewProviderGroupExtension::extensionRestore(Base::XMLReader& reader) {
|
||||
|
||||
getExtendedViewProvider()->Visibility.setStatus(App::Property::User1, true); // tmp. set
|
||||
ViewProviderExtension::extensionRestore(reader);
|
||||
getExtendedViewProvider()->Visibility.setStatus(App::Property::User1, false); // unset
|
||||
}
|
||||
|
63
src/Gui/ViewProviderGroupExtension.h
Normal file
63
src/Gui/ViewProviderGroupExtension.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2006 Werner Mayer <wmayer[at]users.sourceforge.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_VIEWPROVIDERGROUPEXTENSION_H
|
||||
#define GUI_VIEWPROVIDERGROUPEXTENSION_H
|
||||
|
||||
#include <App/Extension.h>
|
||||
#include "ViewProviderExtension.h"
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
||||
class GuiExport ViewProviderGroupExtension : public ViewProviderExtension
|
||||
{
|
||||
PROPERTY_HEADER(Gui::ViewProviderGroupExtension);
|
||||
|
||||
public:
|
||||
/// Constructor
|
||||
ViewProviderGroupExtension(void);
|
||||
virtual ~ViewProviderGroupExtension();
|
||||
|
||||
virtual std::vector<App::DocumentObject*> extensionClaimChildren(void)const override;
|
||||
virtual bool extensionCanDragObjects() const override;
|
||||
virtual bool extensionCanDragObject(App::DocumentObject*) const override;
|
||||
virtual void extensionDragObject(App::DocumentObject*) override;
|
||||
virtual bool extensionCanDropObjects() const override;
|
||||
virtual bool extensionCanDropObject(App::DocumentObject*) const override;
|
||||
virtual void extensionDropObject(App::DocumentObject*) override;
|
||||
|
||||
virtual void extensionHide(void) override;
|
||||
virtual void extensionShow(void) override;
|
||||
|
||||
virtual bool extensionOnDelete(const std::vector<std::string> &) override;
|
||||
virtual void extensionRestore(Base::XMLReader& reader);
|
||||
|
||||
private:
|
||||
bool visible; // helper variable
|
||||
std::vector<ViewProvider*> nodes;
|
||||
};
|
||||
|
||||
} //namespace Gui
|
||||
|
||||
#endif // GUI_VIEWPROVIDERGROUPEXTENSION_H
|
Loading…
Reference in New Issue
Block a user