Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Std_ToggleTransparency: Fixes #11353 #13180

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 33 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 @@ -95,7 +96,7 @@
namespace {
// A helper class to open a transaction when changing properties of view providers.
// It uses the same parameter key as the PropertyView to control the behaviour.
class TransactionView {

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

class 'TransactionView' defines a non-default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]
Gui::Document* document;

public:
Expand Down Expand Up @@ -145,9 +146,9 @@
if (iMsg == 1) {
auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
if (!cam || cam->getTypeId() != SoOrthographicCamera::getClassTypeId())

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'SoCamera *' -> bool [readability-implicit-bool-conversion]

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'SbBool' (aka 'int') -> bool [readability-implicit-bool-conversion]

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]

doCommand(Command::Gui,"Gui.activeDocument().activeView().setCameraType(\"Orthographic\")");

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]
}
}

Expand All @@ -158,9 +159,9 @@
// update the action group if needed
bool check = _pcAction->isChecked();
SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
bool mode = cam ? cam->getTypeId() == SoOrthographicCamera::getClassTypeId() : false;

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'int' -> bool [readability-implicit-bool-conversion]

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion bool -> 'int' [readability-implicit-bool-conversion]

if (mode != check)

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

statement should be inside braces [readability-braces-around-statements]
_pcAction->setChecked(mode);
return true;
}
Expand Down Expand Up @@ -195,7 +196,7 @@
if (iMsg == 1) {
auto view = qobject_cast<View3DInventor*>(getMainWindow()->activeWindow());
SoCamera* cam = view->getViewer()->getSoRenderManager()->getCamera();
if (!cam || cam->getTypeId() != SoPerspectiveCamera::getClassTypeId())

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

implicit conversion 'SoCamera *' -> bool [readability-implicit-bool-conversion]

doCommand(Command::Gui,"Gui.activeDocument().activeView().setCameraType(\"Perspective\")");
}
Expand Down Expand Up @@ -925,33 +926,44 @@
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
// Tip prop.
const std::vector<App::DocumentObject*> parents = obj->getInList();
if (!parents.empty()) {
App::Document* parentDoc = parents[0]->getDocument();
Gui::ViewProvider* parentView = Application::Instance->getDocument(parentDoc)->getViewProvider(parents[0]);
App::Property* parentProp = parents[0]->getPropertyByName("Tip");
if (parentProp) {
// Make sure it has a transparency prop too
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 Expand Up @@ -2702,7 +2714,7 @@
};
}

std::unique_ptr<SelectionCallbackHandler> SelectionCallbackHandler::currentSelectionHandler = std::unique_ptr<SelectionCallbackHandler>();

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

View workflow job for this annotation

GitHub Actions / Lint / Lint

non-POD static (unique_ptr) [-Wclazy-non-pod-global-static]
//===========================================================================
// Std_ViewBoxZoom
//===========================================================================
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