From 9ac7e6d17c743391cdd6b2f0d88bc5432b200454 Mon Sep 17 00:00:00 2001 From: jonzirk76 Date: Thu, 20 Mar 2025 06:03:03 -0400 Subject: [PATCH] TechDraw: remove double type checking Fixes #20131 --- src/Mod/TechDraw/App/DrawView.cpp | 6 +++--- src/Mod/TechDraw/App/DrawViewClip.cpp | 24 +++++++----------------- src/Mod/TechDraw/App/DrawViewPart.cpp | 12 ++++++------ src/Mod/TechDraw/App/ShapeExtractor.cpp | 2 +- src/Mod/TechDraw/Gui/CommandHelpers.cpp | 4 ++-- src/Mod/TechDraw/Gui/QGSPage.cpp | 4 ++-- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index 4b01917bf6..32ed36cec0 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -442,7 +442,7 @@ DrawViewClip* DrawView::getClipGroup() { for (auto* obj : getInList()) { if (obj->isDerivedFrom()) { - return dynamic_cast(obj); + return static_cast(obj); } } return nullptr; @@ -452,7 +452,7 @@ DrawViewCollection *DrawView::getCollection() const { for (auto* obj : getInList()) { if (obj->isDerivedFrom()) { - return dynamic_cast(obj); + return static_cast(obj); } } return nullptr; @@ -551,7 +551,7 @@ std::vector DrawView::getLeaders() const std::vector children = getInList(); for (std::vector::iterator it = children.begin(); it != children.end(); ++it) { if ((*it)->isDerivedFrom()) { - TechDraw::DrawLeaderLine* lead = dynamic_cast(*it); + TechDraw::DrawLeaderLine* lead = static_cast(*it); result.push_back(lead); } } diff --git a/src/Mod/TechDraw/App/DrawViewClip.cpp b/src/Mod/TechDraw/App/DrawViewClip.cpp index 027dcc6104..6464ba220c 100644 --- a/src/Mod/TechDraw/App/DrawViewClip.cpp +++ b/src/Mod/TechDraw/App/DrawViewClip.cpp @@ -69,25 +69,15 @@ void DrawViewClip::onChanged(const App::Property* prop) void DrawViewClip::addView(App::DocumentObject* docObj) { - if (!docObj->isDerivedFrom() && !docObj->isDerivedFrom()) { + if(docObj->isDerivedFrom()) { + auto* link = static_cast(docObj); + docObj = link->getLinkedObject(); + } + + if (!docObj->isDerivedFrom()) { return; } - - auto* view = dynamic_cast(docObj); - - if (!view) { - auto* link = dynamic_cast(docObj); - if (!link) { - return; - } - - if (link) { - view = dynamic_cast(link->getLinkedObject()); - if (!view) { - return; - } - } - } + auto* view = static_cast(docObj); std::vector newViews(Views.getValues()); newViews.push_back(docObj); diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index 117001a094..dcc6a31333 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -718,7 +718,7 @@ std::vector DrawViewPart::getHatches() const std::vector children = getInList(); for (auto& child : children) { if (child->isDerivedFrom() && !child->isRemoving()) { - TechDraw::DrawHatch* hatch = dynamic_cast(child); + TechDraw::DrawHatch* hatch = static_cast(child); result.push_back(hatch); } } @@ -733,7 +733,7 @@ std::vector DrawViewPart::getGeomHatches() const for (auto& child : children) { if (child->isDerivedFrom() && !child->isRemoving()) { - TechDraw::DrawGeomHatch* geom = dynamic_cast(child); + TechDraw::DrawGeomHatch* geom = static_cast(child); result.push_back(geom); } } @@ -752,7 +752,7 @@ std::vector DrawViewPart::getDimensions() const std::unique(children.begin(), children.end()); for (std::vector::iterator it = children.begin(); it != newEnd; ++it) { if ((*it)->isDerivedFrom()) { - TechDraw::DrawViewDimension* dim = dynamic_cast(*it); + TechDraw::DrawViewDimension* dim = static_cast(*it); result.push_back(dim); } } @@ -768,7 +768,7 @@ std::vector DrawViewPart::getBalloons() const std::unique(children.begin(), children.end()); for (std::vector::iterator it = children.begin(); it != newEnd; ++it) { if ((*it)->isDerivedFrom()) { - TechDraw::DrawViewBalloon* balloon = dynamic_cast(*it); + TechDraw::DrawViewBalloon* balloon = static_cast(*it); result.push_back(balloon); } } @@ -1142,7 +1142,7 @@ std::vector DrawViewPart::getSectionRefs() const if (o->isDerivedFrom()) { // expressions can add extra links to this DVP so we keep only // objects that are BaseViews - auto section = dynamic_cast(o); + auto section = static_cast(o); auto base = section->BaseView.getValue(); if (base == this) { result.push_back(section); @@ -1161,7 +1161,7 @@ std::vector DrawViewPart::getDetailRefs() const !o->isRemoving() ) { // expressions can add extra links to this DVP so we keep only // objects that are BaseViews - auto detail = dynamic_cast(o); + auto detail = static_cast(o); auto base = detail->BaseView.getValue(); if (base == this) { result.push_back(detail); diff --git a/src/Mod/TechDraw/App/ShapeExtractor.cpp b/src/Mod/TechDraw/App/ShapeExtractor.cpp index 46247e125d..74d811957e 100644 --- a/src/Mod/TechDraw/App/ShapeExtractor.cpp +++ b/src/Mod/TechDraw/App/ShapeExtractor.cpp @@ -127,7 +127,7 @@ TopoDS_Shape ShapeExtractor::getShapes(const std::vector l } if (obj->isDerivedFrom()) { - App::Link* xLink = dynamic_cast(obj); + App::Link* xLink = static_cast(obj); std::vector xShapes = getXShapes(xLink); if (!xShapes.empty()) { sourceShapes.insert(sourceShapes.end(), xShapes.begin(), xShapes.end()); diff --git a/src/Mod/TechDraw/Gui/CommandHelpers.cpp b/src/Mod/TechDraw/Gui/CommandHelpers.cpp index e1e2b059f6..45ab2af998 100644 --- a/src/Mod/TechDraw/Gui/CommandHelpers.cpp +++ b/src/Mod/TechDraw/Gui/CommandHelpers.cpp @@ -62,7 +62,7 @@ TechDraw::DrawView* CommandHelpers::firstViewInSelection(Gui::Command* cmd) for (auto& selobj : selection) { if (selobj.getObject()->isDerivedFrom()) { auto docobj = selobj.getObject(); - baseView = dynamic_cast(docobj); + baseView = static_cast(docobj); break; } } @@ -81,7 +81,7 @@ TechDraw::DrawView* CommandHelpers::firstNonSpreadsheetInSelection(Gui::Command* continue; } else { auto docobj = selobj.getObject(); - baseView = dynamic_cast(docobj); + baseView = static_cast(docobj); break; } } diff --git a/src/Mod/TechDraw/Gui/QGSPage.cpp b/src/Mod/TechDraw/Gui/QGSPage.cpp index cb7ac278e0..d5d612d93e 100644 --- a/src/Mod/TechDraw/Gui/QGSPage.cpp +++ b/src/Mod/TechDraw/Gui/QGSPage.cpp @@ -893,7 +893,7 @@ void QGSPage::findMissingViews(const std::vector& list, if (obj->isDerivedFrom()) { std::vector missingChildViews; - auto* collection = dynamic_cast(obj); + auto* collection = static_cast(obj); // Find Child Views recursively findMissingViews(collection->getViews(), missingChildViews); @@ -1000,7 +1000,7 @@ bool QGSPage::orphanExists(const char* viewName, const std::vectorisDerivedFrom()) { - auto* collection = dynamic_cast(obj); + auto* collection = static_cast(obj); if (orphanExists(viewName, collection->getViews())) return true; }