TechDraw: remove double type checking

Fixes #20131
This commit is contained in:
jonzirk76
2025-03-20 06:03:03 -04:00
committed by Chris Hennes
parent bdf04aafbd
commit 9ac7e6d17c
6 changed files with 21 additions and 31 deletions

View File

@@ -442,7 +442,7 @@ DrawViewClip* DrawView::getClipGroup()
{
for (auto* obj : getInList()) {
if (obj->isDerivedFrom<DrawViewClip>()) {
return dynamic_cast<DrawViewClip*>(obj);
return static_cast<DrawViewClip*>(obj);
}
}
return nullptr;
@@ -452,7 +452,7 @@ DrawViewCollection *DrawView::getCollection() const
{
for (auto* obj : getInList()) {
if (obj->isDerivedFrom<DrawViewCollection>()) {
return dynamic_cast<DrawViewCollection*>(obj);
return static_cast<DrawViewCollection*>(obj);
}
}
return nullptr;
@@ -551,7 +551,7 @@ std::vector<TechDraw::DrawLeaderLine*> DrawView::getLeaders() const
std::vector<App::DocumentObject*> children = getInList();
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != children.end(); ++it) {
if ((*it)->isDerivedFrom<DrawLeaderLine>()) {
TechDraw::DrawLeaderLine* lead = dynamic_cast<TechDraw::DrawLeaderLine*>(*it);
TechDraw::DrawLeaderLine* lead = static_cast<TechDraw::DrawLeaderLine*>(*it);
result.push_back(lead);
}
}

View File

@@ -69,25 +69,15 @@ void DrawViewClip::onChanged(const App::Property* prop)
void DrawViewClip::addView(App::DocumentObject* docObj)
{
if (!docObj->isDerivedFrom<DrawView>() && !docObj->isDerivedFrom<App::Link>()) {
if(docObj->isDerivedFrom<App::Link>()) {
auto* link = static_cast<App::Link*>(docObj);
docObj = link->getLinkedObject();
}
if (!docObj->isDerivedFrom<DrawView>()) {
return;
}
auto* view = dynamic_cast<DrawView*>(docObj);
if (!view) {
auto* link = dynamic_cast<App::Link*>(docObj);
if (!link) {
return;
}
if (link) {
view = dynamic_cast<DrawView*>(link->getLinkedObject());
if (!view) {
return;
}
}
}
auto* view = static_cast<DrawView*>(docObj);
std::vector<App::DocumentObject*> newViews(Views.getValues());
newViews.push_back(docObj);

View File

@@ -718,7 +718,7 @@ std::vector<TechDraw::DrawHatch*> DrawViewPart::getHatches() const
std::vector<App::DocumentObject*> children = getInList();
for (auto& child : children) {
if (child->isDerivedFrom<DrawHatch>() && !child->isRemoving()) {
TechDraw::DrawHatch* hatch = dynamic_cast<TechDraw::DrawHatch*>(child);
TechDraw::DrawHatch* hatch = static_cast<TechDraw::DrawHatch*>(child);
result.push_back(hatch);
}
}
@@ -733,7 +733,7 @@ std::vector<TechDraw::DrawGeomHatch*> DrawViewPart::getGeomHatches() const
for (auto& child : children) {
if (child->isDerivedFrom<DrawGeomHatch>()
&& !child->isRemoving()) {
TechDraw::DrawGeomHatch* geom = dynamic_cast<TechDraw::DrawGeomHatch*>(child);
TechDraw::DrawGeomHatch* geom = static_cast<TechDraw::DrawGeomHatch*>(child);
result.push_back(geom);
}
}
@@ -752,7 +752,7 @@ std::vector<TechDraw::DrawViewDimension*> DrawViewPart::getDimensions() const
std::unique(children.begin(), children.end());
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != newEnd; ++it) {
if ((*it)->isDerivedFrom<DrawViewDimension>()) {
TechDraw::DrawViewDimension* dim = dynamic_cast<TechDraw::DrawViewDimension*>(*it);
TechDraw::DrawViewDimension* dim = static_cast<TechDraw::DrawViewDimension*>(*it);
result.push_back(dim);
}
}
@@ -768,7 +768,7 @@ std::vector<TechDraw::DrawViewBalloon*> DrawViewPart::getBalloons() const
std::unique(children.begin(), children.end());
for (std::vector<App::DocumentObject*>::iterator it = children.begin(); it != newEnd; ++it) {
if ((*it)->isDerivedFrom<DrawViewBalloon>()) {
TechDraw::DrawViewBalloon* balloon = dynamic_cast<TechDraw::DrawViewBalloon*>(*it);
TechDraw::DrawViewBalloon* balloon = static_cast<TechDraw::DrawViewBalloon*>(*it);
result.push_back(balloon);
}
}
@@ -1142,7 +1142,7 @@ std::vector<DrawViewSection*> DrawViewPart::getSectionRefs() const
if (o->isDerivedFrom<DrawViewSection>()) {
// expressions can add extra links to this DVP so we keep only
// objects that are BaseViews
auto section = dynamic_cast<TechDraw::DrawViewSection*>(o);
auto section = static_cast<TechDraw::DrawViewSection*>(o);
auto base = section->BaseView.getValue();
if (base == this) {
result.push_back(section);
@@ -1161,7 +1161,7 @@ std::vector<DrawViewDetail*> 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<TechDraw::DrawViewDetail*>(o);
auto detail = static_cast<TechDraw::DrawViewDetail*>(o);
auto base = detail->BaseView.getValue();
if (base == this) {
result.push_back(detail);

View File

@@ -127,7 +127,7 @@ TopoDS_Shape ShapeExtractor::getShapes(const std::vector<App::DocumentObject*> l
}
if (obj->isDerivedFrom<App::Link>()) {
App::Link* xLink = dynamic_cast<App::Link*>(obj);
App::Link* xLink = static_cast<App::Link*>(obj);
std::vector<TopoDS_Shape> xShapes = getXShapes(xLink);
if (!xShapes.empty()) {
sourceShapes.insert(sourceShapes.end(), xShapes.begin(), xShapes.end());

View File

@@ -62,7 +62,7 @@ TechDraw::DrawView* CommandHelpers::firstViewInSelection(Gui::Command* cmd)
for (auto& selobj : selection) {
if (selobj.getObject()->isDerivedFrom<DrawView>()) {
auto docobj = selobj.getObject();
baseView = dynamic_cast<TechDraw::DrawView *>(docobj);
baseView = static_cast<TechDraw::DrawView *>(docobj);
break;
}
}
@@ -81,7 +81,7 @@ TechDraw::DrawView* CommandHelpers::firstNonSpreadsheetInSelection(Gui::Command*
continue;
} else {
auto docobj = selobj.getObject();
baseView = dynamic_cast<TechDraw::DrawView *>(docobj);
baseView = static_cast<TechDraw::DrawView *>(docobj);
break;
}
}

View File

@@ -893,7 +893,7 @@ void QGSPage::findMissingViews(const std::vector<App::DocumentObject*>& list,
if (obj->isDerivedFrom<TechDraw::DrawViewCollection>()) {
std::vector<App::DocumentObject*> missingChildViews;
auto* collection = dynamic_cast<TechDraw::DrawViewCollection*>(obj);
auto* collection = static_cast<TechDraw::DrawViewCollection*>(obj);
// Find Child Views recursively
findMissingViews(collection->getViews(), missingChildViews);
@@ -1000,7 +1000,7 @@ bool QGSPage::orphanExists(const char* viewName, const std::vector<App::Document
//Check child objects too recursively
if (obj->isDerivedFrom<TechDraw::DrawViewCollection>()) {
auto* collection = dynamic_cast<TechDraw::DrawViewCollection*>(obj);
auto* collection = static_cast<TechDraw::DrawViewCollection*>(obj);
if (orphanExists(viewName, collection->getViews()))
return true;
}