Skip to content

Commit

Permalink
Core: Std_ToggleTransparency: Fixes #11353
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddleStroke committed Mar 27, 2024
1 parent dc3e0c3 commit 97779ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
50 changes: 29 additions & 21 deletions src/Gui/CommandView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <App/ComplexGeoDataPy.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/DocumentObjectGroup.h>
#include <App/GeoFeature.h>
#include <App/GeoFeatureGroupExtension.h>
#include <App/Part.h>
Expand Down Expand Up @@ -925,33 +926,40 @@ void StdCmdToggleTransparency::activated(int iMsg)
if (!obj)
continue;

if (!dynamic_cast<App::Part*>(obj) && !dynamic_cast<App::LinkGroup*>(obj)) {
Gui::ViewProvider* view = Application::Instance->getDocument(sel.pDoc)->getViewProvider(obj);
bool isGroup = dynamic_cast<App::Part*>(obj)
|| dynamic_cast<App::LinkGroup*>(obj)
|| dynamic_cast<App::DocumentObjectGroup*>(obj);

auto addObjects = [](App::DocumentObject* obj, std::vector<Gui::ViewProvider*>& views) {
App::Document* doc = obj->getDocument();
Gui::ViewProvider* view = Application::Instance->getDocument(doc)->getViewProvider(obj);
App::Property* prop = view->getPropertyByName("Transparency");
if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
viewsToToggle.push_back(view);
}
}
else {
std::function<void(App::DocumentObject*, std::vector<Gui::ViewProvider*>&)> addSubObjects =
[&addSubObjects](App::DocumentObject* obj, std::vector<Gui::ViewProvider*>& viewsToToggle) {
if (!dynamic_cast<App::Part*>(obj) && !dynamic_cast<App::LinkGroup*>(obj)) {
App::Document* doc = obj->getDocument();
Gui::ViewProvider* view = Application::Instance->getDocument(doc)->getViewProvider(obj);
App::Property* prop = view->getPropertyByName("Transparency");
if (prop && prop->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())
&& std::find(viewsToToggle.begin(), viewsToToggle.end(), view) == viewsToToggle.end()) {
viewsToToggle.push_back(view);
// To prevent toggling the tip of a PD body (see #11353), we check if the parent has a
// transparancy prop. If so then either a body or a link.

Check warning on line 939 in src/Gui/CommandView.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

transparancy ==> transparency
const std::vector<App::DocumentObject*> parents = obj->getInList();
if (!parents.empty() && !dynamic_cast<App::Link*>(obj)) {
App::Document* parentDoc = parents[0]->getDocument();

Check warning on line 942 in src/Gui/CommandView.cpp

View workflow job for this annotation

GitHub Actions / Lint / Lint

unused variable 'parentDoc' [-Wunused-variable]
Gui::ViewProvider* parentView = Application::Instance->getDocument(doc)->getViewProvider(parents[0]);
App::Property* parentProp = parentView->getPropertyByName("Transparency");
if (parentProp && parentProp->getTypeId().isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
view = parentView;
}
}
else {
for (App::DocumentObject* subobj : obj->getOutList()) {
addSubObjects(subobj, viewsToToggle);
}

if (std::find(views.begin(), views.end(), view) == views.end()) {
views.push_back(view);
}
};
}
};

addSubObjects(obj, viewsToToggle);
if (isGroup) {
for (App::DocumentObject* subobj : obj->getOutListRecursive()) {
addObjects(subobj, viewsToToggle);
}
}
else {
addObjects(obj, viewsToToggle);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Gui/Workbench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Std_ToggleNavigation"
<< "Std_SetAppearance"
<< "Std_RandomColor"
<< "Std_ToggleTransparency"
<< "Separator"
<< "Std_Workbench"
<< "Std_ToolBarMenu"
Expand All @@ -711,7 +712,6 @@ MenuItem* StdWorkbench::setupMenuBar() const
*view << "Std_DockOverlay";
}
*view << "Separator"
<< "Std_ToggleTransparency"
<< "Std_LinkSelectActions"
<< "Std_TreeViewActions"
<< "Std_ViewStatusBar";
Expand Down

0 comments on commit 97779ba

Please sign in to comment.