diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 379a304b76..6ead8919ec 100644 --- a/src/Gui/ViewProviderCoordinateSystem.cpp +++ b/src/Gui/ViewProviderCoordinateSystem.cpp @@ -72,13 +72,16 @@ ViewProviderCoordinateSystem::~ViewProviderCoordinateSystem() { std::vector ViewProviderCoordinateSystem::claimChildren() const { - auto obj = getObject(); - std::vector childs = obj->OriginFeatures.getValues(); - auto it = std::find(childs.begin(), childs.end(), obj); - if (it != childs.end()) { - childs.erase(it); + if (auto obj = getObject()) { + std::vector childs = obj->OriginFeatures.getValues(); + auto it = std::find(childs.begin(), childs.end(), obj); + if (it != childs.end()) { + childs.erase(it); + } + return childs; } - return childs; + + return {}; } std::vector ViewProviderCoordinateSystem::claimChildren3D() const @@ -106,7 +109,10 @@ void ViewProviderCoordinateSystem::setDisplayMode(const char* ModeName) void ViewProviderCoordinateSystem::setTemporaryVisibility(DatumElements elements) { - auto origin = getObject(); + auto origin = getObject(); + if (!origin) { + return; + } bool saveState = tempVisMap.empty(); @@ -163,32 +169,34 @@ double ViewProviderCoordinateSystem::defaultSize() return hGrp->GetFloat("DatumsSize", 25); } -bool ViewProviderCoordinateSystem::isTemporaryVisibility() { +bool ViewProviderCoordinateSystem::isTemporaryVisibility() +{ return !tempVisMap.empty(); } void ViewProviderCoordinateSystem::setPlaneLabelVisibility(bool val) { - auto lcs = getObject(); - for (auto* plane : lcs->planes()) { - auto* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(plane)); - if (vp) { - vp->setLabelVisibility(val); + if (auto lcs = getObject()) { + for (auto* plane : lcs->planes()) { + auto* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(plane)); + if (vp) { + vp->setLabelVisibility(val); + } } } - } void ViewProviderCoordinateSystem::applyDatumObjects(const DatumObjectFunc& func) { - auto lcs = getObject(); - const auto& objs = lcs->OriginFeatures.getValues(); - for (auto* obj : objs) { - auto* vp = dynamic_cast( - Gui::Application::Instance->getViewProvider(obj)); - if (vp) { - func(vp); + if (auto lcs = getObject()) { + const auto& objs = lcs->OriginFeatures.getValues(); + for (auto* obj : objs) { + auto* vp = dynamic_cast( + Gui::Application::Instance->getViewProvider(obj)); + if (vp) { + func(vp); + } } } } @@ -207,9 +215,9 @@ void ViewProviderCoordinateSystem::resetTemporarySize() }); } -void ViewProviderCoordinateSystem::updateData(const App::Property* prop) { - auto* jcs = dynamic_cast(getObject()); - if(jcs) { +void ViewProviderCoordinateSystem::updateData(const App::Property* prop) +{ + if (auto* jcs = dynamic_cast(getObject())) { if (prop == &jcs->Placement) { // Update position } @@ -217,11 +225,14 @@ void ViewProviderCoordinateSystem::updateData(const App::Property* prop) { ViewProviderDocumentObject::updateData(prop); } -bool ViewProviderCoordinateSystem::onDelete(const std::vector &) { +bool ViewProviderCoordinateSystem::onDelete(const std::vector &) +{ auto lcs = getObject(); + if (!lcs) { + return false; + } - auto origin = dynamic_cast(lcs); - if (origin && !origin->getInList().empty()) { + if (lcs && !lcs->getInList().empty()) { // Do not allow deletion of origin objects that are not lost. return false; }