(GeoFeature)GroupExtension: track children visibility
The future patch will introduce Part::getTopoShape() to construct a compound shape from a group. It will rely on the children visibility to determine whether to include the child shape or not. This patch adds children visibility tracking capability to group, and makes sure that the group object will be marked for recomputation in case of any change in group member, and their visibility status. * Remove Prop_Output from 'Group' property. * Added hidden property _GroupTouched to help propagate children change. * Track children visibility change using signal * GeoFeatureGroupExtension uses new PropertyLinkBase interface for scope checking.
This commit is contained in:
@@ -45,7 +45,7 @@ using namespace Gui;
|
||||
|
||||
EXTENSION_PROPERTY_SOURCE(Gui::ViewProviderGroupExtension, Gui::ViewProviderExtension)
|
||||
|
||||
ViewProviderGroupExtension::ViewProviderGroupExtension() : visible(false), guard(false)
|
||||
ViewProviderGroupExtension::ViewProviderGroupExtension() : guard(false)
|
||||
{
|
||||
initExtensionType(ViewProviderGroupExtension::getExtensionClassTypeId());
|
||||
}
|
||||
@@ -110,29 +110,6 @@ void ViewProviderGroupExtension::extensionDropObject(App::DocumentObject* obj) {
|
||||
Gui::Command::doCommand(Gui::Command::App, cmd.toUtf8());
|
||||
}
|
||||
|
||||
void ViewProviderGroupExtension::extensionReplaceObject(App::DocumentObject* oldValue, App::DocumentObject* newValue) {
|
||||
|
||||
App::DocumentObject* grp = static_cast<App::DocumentObject*>(getExtendedViewProvider()->getObject());
|
||||
App::Document* doc = grp->getDocument();
|
||||
|
||||
// build Python command for execution
|
||||
QString cmd;
|
||||
cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").removeObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromLatin1(doc->getName()),
|
||||
QString::fromLatin1(grp->getNameInDocument()),
|
||||
QString::fromLatin1(oldValue->getNameInDocument()));
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::App, cmd.toUtf8());
|
||||
cmd = QString::fromLatin1("App.getDocument(\"%1\").getObject(\"%2\").addObject("
|
||||
"App.getDocument(\"%1\").getObject(\"%3\"))")
|
||||
.arg(QString::fromLatin1(doc->getName()),
|
||||
QString::fromLatin1(grp->getNameInDocument()),
|
||||
QString::fromLatin1(newValue->getNameInDocument()));
|
||||
|
||||
Gui::Command::doCommand(Gui::Command::App, cmd.toUtf8());
|
||||
}
|
||||
|
||||
std::vector< App::DocumentObject* > ViewProviderGroupExtension::extensionClaimChildren(void) const {
|
||||
|
||||
auto* group = getExtendedViewProvider()->getObject()->getExtensionByType<App::GroupExtension>();
|
||||
@@ -148,20 +125,15 @@ 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()->isRestoring() && !this->visible) {
|
||||
if (!getExtendedViewProvider()->isRestoring() ) {
|
||||
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) {
|
||||
ViewProvider* view = doc->getViewProvider(*it);
|
||||
if (view)
|
||||
view->show();
|
||||
for(auto obj : group->Group.getValues()) {
|
||||
if(obj && !obj->Visibility.getValue())
|
||||
obj->Visibility.setValue(true);
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderExtension::extensionShow();
|
||||
this->visible = true;
|
||||
}
|
||||
|
||||
void ViewProviderGroupExtension::extensionHide(void) {
|
||||
@@ -173,25 +145,14 @@ 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()->isRestoring() && this->visible) {
|
||||
|
||||
if (!getExtendedViewProvider()->isRestoring()) {
|
||||
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());
|
||||
// doc pointer can be null in case the document is about to be destroyed
|
||||
// See https://forum.freecadweb.org/viewtopic.php?f=22&t=26797&p=218804#p218521
|
||||
if (doc) {
|
||||
for (std::vector<App::DocumentObject*>::const_iterator it = links.begin(); it != links.end(); ++it) {
|
||||
ViewProvider* view = doc->getViewProvider(*it);
|
||||
if (view)
|
||||
view->hide();
|
||||
}
|
||||
for(auto obj : group->Group.getValues()) {
|
||||
if(obj && obj->Visibility.getValue())
|
||||
obj->Visibility.setValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
ViewProviderExtension::extensionHide();
|
||||
this->visible = false;
|
||||
}
|
||||
|
||||
bool ViewProviderGroupExtension::extensionOnDelete(const std::vector< std::string >& ) {
|
||||
|
||||
Reference in New Issue
Block a user