Manual changes to improve isDerivedFrom usage

This commit is contained in:
Benjamin Nauck
2025-01-16 23:37:04 +01:00
parent 02c8bfff69
commit 97bf3c5e33
12 changed files with 43 additions and 97 deletions

View File

@@ -575,15 +575,10 @@ const Document* DocumentModel::getDocument(const QModelIndex& index) const
bool DocumentModel::isPropertyLink(const App::Property& prop) const
{
if (prop.isDerivedFrom(App::PropertyLink::getClassTypeId()))
return true;
if (prop.isDerivedFrom(App::PropertyLinkSub::getClassTypeId()))
return true;
if (prop.isDerivedFrom(App::PropertyLinkList::getClassTypeId()))
return true;
if (prop.isDerivedFrom(App::PropertyLinkSubList::getClassTypeId()))
return true;
return false;
return prop.isDerivedFrom<App::PropertyLink>()
|| prop.isDerivedFrom<App::PropertyLinkSub>()
|| prop.isDerivedFrom<App::PropertyLinkList>()
|| prop.isDerivedFrom<App::PropertyLinkSubList>();
}
std::vector<ViewProviderDocumentObject*>

View File

@@ -499,12 +499,10 @@ void ViewProviderDocumentObject::setActiveMode()
bool ViewProviderDocumentObject::canDelete(App::DocumentObject* obj) const
{
Q_UNUSED(obj)
if (getObject()->hasExtension(App::GroupExtension::getExtensionClassTypeId()))
return true;
if (getObject()->isDerivedFrom(App::Origin::getClassTypeId()))
return true;
return false;
Q_UNUSED(obj);
auto* o = getObject();
return o->hasExtension(App::GroupExtension::getExtensionClassTypeId())
|| o->isDerivedFrom<App::Origin>();
}
PyObject* ViewProviderDocumentObject::getPyObject()

View File

@@ -91,8 +91,7 @@ DocumentObjectExecReturn* FemPostFilter::execute()
vtkDataObject* FemPostFilter::getInputData()
{
if (Input.getValue()) {
if (Input.getValue()->getTypeId().isDerivedFrom(
Base::Type::fromName("Fem::FemPostObject"))) {
if (Input.getValue()->isDerivedFrom<Fem::FemPostObject>()) {
return Input.getValue<FemPostObject*>()->Data.getValue();
}
else {

View File

@@ -230,38 +230,25 @@ bool ViewProviderFemAnalysis::canDragObject(App::DocumentObject* obj) const
if (!obj) {
return false;
}
if (obj->isDerivedFrom<Fem::FemMeshObject>()) {
return true;
}
else if (obj->isDerivedFrom<Fem::FemSolverObject>()) {
return true;
}
else if (obj->isDerivedFrom<Fem::FemResultObject>()) {
return true;
}
else if (obj->isDerivedFrom<Fem::Constraint>()) {
return true;
}
else if (obj->isDerivedFrom<Fem::FemSetObject>()) {
return true;
}
else if (obj->getTypeId().isDerivedFrom(Base::Type::fromName("Fem::FeaturePython"))) {
return true;
}
else if (obj->isDerivedFrom<App::MaterialObject>()) {
return true;
}
else if (obj->isDerivedFrom<App::TextDocument>()) {
// clang-format off: keep line breaks for readability
if (obj->isDerivedFrom<Fem::FemMeshObject>()
|| obj->isDerivedFrom<Fem::FemSolverObject>()
|| obj->isDerivedFrom<Fem::FemResultObject>()
|| obj->isDerivedFrom<Fem::Constraint>()
|| obj->isDerivedFrom<Fem::FemSetObject>()
|| obj->isDerivedFrom(Base::Type::fromName("Fem::FeaturePython"))
|| obj->isDerivedFrom<App::MaterialObject>()
|| obj->isDerivedFrom<App::TextDocument>()) {
return true;
}
// clang-format on
#ifdef FC_USE_VTK
else if (obj->isDerivedFrom<Fem::FemPostObject>()) {
return true;
}
#endif
else {
return false;
}
return false;
}
void ViewProviderFemAnalysis::dragObject(App::DocumentObject* obj)

View File

@@ -73,14 +73,8 @@ TopoDS_Shape SketchExportHelper::projectShape(const TopoDS_Shape& inShape,
//! true if obj is a sketch
bool SketchExportHelper::isSketch(App::DocumentObject* obj)
{
// TODO:: the check for an object being a sketch should be done as in the commented
// if statement below. To do this, we need to include Mod/Sketcher/SketchObject.h,
// but that makes Import dependent on Eigen libraries which we don't use. As a
// workaround we will inspect the object's class name.
// if (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
std::string objTypeName = obj->getTypeId().getName();
std::string sketcherToken("Sketcher");
return objTypeName.find(sketcherToken) != std::string::npos;
// Use name to lookup to avoid dependency on Sketcher module
return obj->isDerivedFrom(Base::Type::fromName("Sketcher::SketchObject"));
}

View File

@@ -369,8 +369,7 @@ void TaskMeasure::ensureGroup(Measure::MeasureBase* measurement)
App::DocumentObject* obj = doc->getObject(measurementGroupName);
if (!obj || !obj->isValid()
|| !obj->isDerivedFrom(App::DocumentObjectGroup::getClassTypeId())) {
if (!obj || !obj->isValid() || !obj->isDerivedFrom<App::DocumentObjectGroup>()) {
obj = doc->addObject("App::DocumentObjectGroup",
measurementGroupName,
true,

View File

@@ -139,10 +139,8 @@ App::MeasureElementType PartMeasureTypeCb(App::DocumentObject* ob, const char* s
switch (curve.GetType()) {
case GeomAbs_Line: {
if (ob->getTypeId().isDerivedFrom(Base::Type::fromName("Part::Datum"))) {
return App::MeasureElementType::LINE;
}
return App::MeasureElementType::LINESEGMENT;
return ob->isDerivedFrom<Part::Datum>() ? App::MeasureElementType::LINE
: App::MeasureElementType::LINESEGMENT;
}
case GeomAbs_Circle: { return App::MeasureElementType::CIRCLE; }
case GeomAbs_BezierCurve:

View File

@@ -376,9 +376,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop)
else if (prop == &robObj->ToolShape) {
App::DocumentObject* o = robObj->ToolShape.getValue<App::DocumentObject*>();
if (o
&& (o->isDerivedFrom(Part::Feature::getClassTypeId())
|| o->isDerivedFrom(App::VRMLObject::getClassTypeId()))) {
if (o && (o->isDerivedFrom<Part::Feature>() || o->isDerivedFrom<App::VRMLObject>())) {
// Part::Feature *p = dynamic_cast<Part::Feature *>(o);
toolShape = Gui::Application::Instance->getViewProvider(o);
toolShape->setTransformation(

View File

@@ -70,7 +70,7 @@ public:
if (geom->is<Part::GeomLineSegment>()
|| geom->is<Part::GeomCircle>()
|| geom->is<Part::GeomEllipse>()
|| geom->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId())
|| geom->isDerivedFrom<Part::GeomArcOfConic>()
|| geom->is<Part::GeomBSplineCurve>()) {
return true;
}
@@ -122,7 +122,7 @@ public:
if (geom->is<Part::GeomLineSegment>()
|| geom->is<Part::GeomCircle>()
|| geom->is<Part::GeomEllipse>()
|| geom->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId())
|| geom->isDerivedFrom<Part::GeomArcOfConic>()
|| geom->is<Part::GeomBSplineCurve>()) {
GeoId = curveGeoId;
}

View File

@@ -924,7 +924,7 @@ void Sheet::recomputeCell(CellAddress p)
cellErrors.insert(p);
cellUpdated(p);
if (e.isDerivedFrom(Base::AbortException::getClassTypeId())) {
if (e.isDerivedFrom<Base::AbortException>()) {
throw;
}
}

View File

@@ -115,8 +115,7 @@ App::Property* DlgSheetConf::prepare(CellAddress& from,
e.ReportException();
FC_THROWM(Base::RuntimeError, "Failed to parse expression for property");
}
if (expr->hasComponent()
|| !expr->isDerivedFrom(App::VariableExpression::getClassTypeId())) {
if (expr->hasComponent() || !expr->isDerivedFrom<App::VariableExpression>()) {
FC_THROWM(Base::RuntimeError, "Invalid property expression: " << expr->toString());
}
@@ -196,8 +195,7 @@ void DlgSheetConf::accept()
std::string exprTxt(ui->lineEditProp->text().trimmed().toUtf8().constData());
App::ExpressionPtr expr(App::Expression::parse(sheet, exprTxt));
if (expr->hasComponent()
|| !expr->isDerivedFrom(App::VariableExpression::getClassTypeId())) {
if (expr->hasComponent() || !expr->isDerivedFrom<App::VariableExpression>()) {
FC_THROWM(Base::RuntimeError, "Invalid property expression: " << expr->toString());
}

View File

@@ -398,31 +398,20 @@ bool ShapeExtractor::is2dObject(const App::DocumentObject* obj)
bool ShapeExtractor::isEdgeType(const App::DocumentObject* obj)
{
Base::Type t = obj->getTypeId();
if (t.isDerivedFrom(Part::Line::getClassTypeId()) ) {
return true;
} else if (t.isDerivedFrom(Part::Circle::getClassTypeId())) {
return true;
} else if (t.isDerivedFrom(Part::Ellipse::getClassTypeId())) {
return true;
} else if (t.isDerivedFrom(Part::RegularPolygon::getClassTypeId())) {
return true;
}
return false;
return t.isDerivedFrom(Part::Line::getClassTypeId())
|| t.isDerivedFrom(Part::Circle::getClassTypeId())
|| t.isDerivedFrom(Part::Ellipse::getClassTypeId())
|| t.isDerivedFrom(Part::RegularPolygon::getClassTypeId());
}
bool ShapeExtractor::isPointType(const App::DocumentObject* obj)
{
if (obj) {
Base::Type t = obj->getTypeId();
if (t.isDerivedFrom(Part::Vertex::getClassTypeId())) {
return true;
} else if (isDraftPoint(obj)) {
return true;
} else if (isDatumPoint(obj)) {
return true;
}
if (!obj) {
return false;
}
return false;
return obj->isDerivedFrom<Part::Vertex>()
|| isDraftPoint(obj)
|| isDatumPoint(obj);
}
bool ShapeExtractor::isDraftPoint(const App::DocumentObject* obj)
@@ -486,17 +475,8 @@ TopoDS_Shape ShapeExtractor::getLocatedShape(const App::DocumentObject* docObj)
bool ShapeExtractor::isSketchObject(const App::DocumentObject* obj)
{
// TODO:: the check for an object being a sketch should be done as in the commented
// if statement below. To do this, we need to include Mod/Sketcher/SketchObject.h,
// but that makes TechDraw dependent on Eigen libraries which we don't use. As a
// workaround we will inspect the object's class name.
// if (obj->isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
std::string objTypeName = obj->getTypeId().getName();
std::string sketcherToken("Sketcher");
if (objTypeName.find(sketcherToken) != std::string::npos) {
return true;
}
return false;
// Use name to lookup to avoid dependency on Sketcher module
return obj->isDerivedFrom(Base::Type::fromName("Sketcher::SketchObject"));
}