From fbf0d48dd82eae17da7e07b11bc31b2c774c6ad6 Mon Sep 17 00:00:00 2001 From: Florian Foinant-Willig Date: Sun, 15 Oct 2023 21:38:51 +0200 Subject: [PATCH] Inspection: modernize type checking --- src/Mod/Inspection/App/InspectionFeature.cpp | 12 ++++----- .../Inspection/Gui/ViewProviderInspection.cpp | 25 ++++++++----------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/Mod/Inspection/App/InspectionFeature.cpp b/src/Mod/Inspection/App/InspectionFeature.cpp index 46a77575a7..b1cbfda5a1 100644 --- a/src/Mod/Inspection/App/InspectionFeature.cpp +++ b/src/Mod/Inspection/App/InspectionFeature.cpp @@ -805,15 +805,15 @@ App::DocumentObjectExecReturn* Feature::execute() } InspectActualGeometry* actual = nullptr; - if (pcActual->getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) { + if (pcActual->isDerivedFrom()) { Mesh::Feature* mesh = static_cast(pcActual); actual = new InspectActualMesh(mesh->Mesh.getValue()); } - else if (pcActual->getTypeId().isDerivedFrom(Points::Feature::getClassTypeId())) { + else if (pcActual->isDerivedFrom()) { Points::Feature* pts = static_cast(pcActual); actual = new InspectActualPoints(pts->Points.getValue()); } - else if (pcActual->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + else if (pcActual->isDerivedFrom()) { useMultithreading = false; Part::Feature* part = static_cast(pcActual); actual = new InspectActualShape(part->Shape.getShape()); @@ -828,15 +828,15 @@ App::DocumentObjectExecReturn* Feature::execute() const std::vector& nominals = Nominals.getValues(); for (auto it : nominals) { InspectNominalGeometry* nominal = nullptr; - if (it->getTypeId().isDerivedFrom(Mesh::Feature::getClassTypeId())) { + if (it->isDerivedFrom()) { Mesh::Feature* mesh = static_cast(it); nominal = new InspectNominalMesh(mesh->Mesh.getValue(), this->SearchRadius.getValue()); } - else if (it->getTypeId().isDerivedFrom(Points::Feature::getClassTypeId())) { + else if (it->isDerivedFrom()) { Points::Feature* pts = static_cast(it); nominal = new InspectNominalPoints(pts->Points.getValue(), this->SearchRadius.getValue()); } - else if (it->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) { + else if (it->isDerivedFrom()) { useMultithreading = false; Part::Feature* part = static_cast(it); nominal = new InspectNominalShape(part->Shape.getValue(), this->SearchRadius.getValue()); diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp index b5d363f6ff..bb02d337dc 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.cpp +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.cpp @@ -247,8 +247,7 @@ bool ViewProviderInspection::setupPoints(const Data::ComplexGeoData* data, // If getPoints() doesn't deliver normals check a second property if (normals.empty() && container) { App::Property* propN = container->getPropertyByName("Normal"); - if (propN - && propN->getTypeId().isDerivedFrom(Points::PropertyNormalList::getClassTypeId())) { + if (propN && propN->isDerivedFrom()) { normals = static_cast(propN)->getValues(); } } @@ -327,7 +326,7 @@ void ViewProviderInspection::setupFaceIndexes(const std::vectorgetTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { + if (prop->isDerivedFrom()) { App::GeoFeature* object = static_cast(prop)->getValue(); const App::PropertyComplexGeoData* propData = @@ -343,7 +342,7 @@ void ViewProviderInspection::updateData(const App::Property* prop) } } } - else if (prop->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { + else if (prop->is()) { // force an update of the Inventor data nodes if (this->pcObject) { App::Property* link = this->pcObject->getPropertyByName("Actual"); @@ -353,7 +352,7 @@ void ViewProviderInspection::updateData(const App::Property* prop) setDistances(); } } - else if (prop->getTypeId() == App::PropertyFloat::getClassTypeId()) { + else if (prop->is()) { if (strcmp(prop->getName(), "SearchRadius") == 0) { float fSearchRadius = ((App::PropertyFloat*)prop)->getValue(); this->search_radius = fSearchRadius; @@ -427,7 +426,7 @@ QIcon ViewProviderInspection::getIcon() const // Get the icon of the view provider to the associated feature QIcon px = inherited::getIcon(); App::Property* pActual = pcObject->getPropertyByName("Actual"); - if (pActual && pActual->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { + if (pActual && pActual->isDerivedFrom()) { App::DocumentObject* docobj = ((App::PropertyLink*)pActual)->getValue(); if (docobj) { Gui::Document* doc = Gui::Application::Instance->getDocument(docobj->getDocument()); @@ -572,7 +571,7 @@ void ViewProviderInspection::inspectCallback(void* ud, SoEventCallback* n) // check if we have picked one a node of the view provider we are insterested in Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath()); - if (vp && vp->getTypeId().isDerivedFrom(ViewProviderInspection::getClassTypeId())) { + if (vp && vp->isDerivedFrom()) { ViewProviderInspection* that = static_cast(vp); QString info = that->inspectDistance(point); Gui::getMainWindow()->setPaneText(1, info); @@ -594,9 +593,7 @@ void ViewProviderInspection::inspectCallback(void* ud, SoEventCallback* n) for (int i = 0; i < pps.getLength(); ++i) { const SoPickedPoint* point = pps[i]; vp = view->getViewProviderByPathFromTail(point->getPath()); - if (vp - && vp->getTypeId().isDerivedFrom( - ViewProviderInspection::getClassTypeId())) { + if (vp && vp->isDerivedFrom()) { ViewProviderInspection* self = static_cast(vp); QString info = self->inspectDistance(point); Gui::getMainWindow()->setPaneText(1, info); @@ -661,8 +658,7 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const // get the distances of the three points of the picked facet const SoFaceDetail* facedetail = static_cast(detail); App::Property* pDistance = this->pcObject->getPropertyByName("Distances"); - if (pDistance - && pDistance->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { + if (pDistance && pDistance->is()) { Inspection::PropertyDistanceList* dist = static_cast(pDistance); int index1 = facedetail->getPoint(0)->getCoordinateIndex(); @@ -673,8 +669,7 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const float fVal3 = (*dist)[index3]; App::Property* pActual = this->pcObject->getPropertyByName("Actual"); - if (pActual - && pActual->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId())) { + if (pActual && pActual->isDerivedFrom()) { float fSearchRadius = this->search_radius; if (fVal1 > fSearchRadius || fVal2 > fSearchRadius || fVal3 > fSearchRadius) { info = QObject::tr("Distance: > %1").arg(fSearchRadius); @@ -714,7 +709,7 @@ QString ViewProviderInspection::inspectDistance(const SoPickedPoint* pp) const // get the distance of the picked point int index = pointdetail->getCoordinateIndex(); App::Property* prop = this->pcObject->getPropertyByName("Distances"); - if (prop && prop->getTypeId() == Inspection::PropertyDistanceList::getClassTypeId()) { + if (prop && prop->is()) { Inspection::PropertyDistanceList* dist = static_cast(prop); float fVal = (*dist)[index];