Use is<T>() when possible
This commit is contained in:
@@ -160,10 +160,7 @@ bool ViewProviderAssembly::doubleClicked()
|
||||
bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const
|
||||
{
|
||||
// The user should not be able to drag the joint group out of the assembly
|
||||
if (!obj || obj->getTypeId() == Assembly::JointGroup::getClassTypeId()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return obj && !obj->is<Assembly::JointGroup>();
|
||||
}
|
||||
|
||||
bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
|
||||
@@ -1028,9 +1025,8 @@ bool ViewProviderAssembly::onDelete(const std::vector<std::string>& subNames)
|
||||
{
|
||||
// Delete the assembly groups when assembly is deleted
|
||||
for (auto obj : getObject()->getOutList()) {
|
||||
if (obj->getTypeId() == Assembly::JointGroup::getClassTypeId()
|
||||
|| obj->getTypeId() == Assembly::ViewGroup::getClassTypeId()
|
||||
|| obj->getTypeId() == Assembly::BomGroup::getClassTypeId()) {
|
||||
if (obj->is<Assembly::JointGroup>() || obj->is<Assembly::ViewGroup>()
|
||||
|| obj->is<Assembly::BomGroup>()) {
|
||||
|
||||
// Delete the group content first.
|
||||
Gui::Command::doCommand(Gui::Command::Doc,
|
||||
|
||||
@@ -385,7 +385,7 @@ void ViewProviderInspection::setDistances()
|
||||
SoDebugError::post("ViewProviderInspection::setDistances", "Unknown property 'Distances'");
|
||||
return;
|
||||
}
|
||||
if (pDistances->getTypeId() != Inspection::PropertyDistanceList::getClassTypeId()) {
|
||||
if (!pDistances->is<Inspection::PropertyDistanceList>()) {
|
||||
SoDebugError::post(
|
||||
"ViewProviderInspection::setDistances",
|
||||
"Property 'Distances' has type %s (Inspection::PropertyDistanceList was expected)",
|
||||
|
||||
@@ -73,9 +73,9 @@ private:
|
||||
return;
|
||||
Part::Geometry* g1 = items[0];
|
||||
Part::Geometry* g2 = items[1];
|
||||
if (!g1 || g1->getTypeId() != Part::GeomArcOfCircle::getClassTypeId())
|
||||
if (!g1 || !g1->is<Part::GeomArcOfCircle>())
|
||||
return;
|
||||
if (!g2 || g2->getTypeId() != Part::GeomLineSegment::getClassTypeId())
|
||||
if (!g2 || !g2->is<Part::GeomLineSegment>())
|
||||
return;
|
||||
Part::GeomArcOfCircle* arc = static_cast<Part::GeomArcOfCircle*>(g1);
|
||||
Part::GeomLineSegment* seg = static_cast<Part::GeomLineSegment*>(g2);
|
||||
|
||||
@@ -510,7 +510,7 @@ Py::Boolean ExternalGeometryFacadePy::getConstruction() const
|
||||
|
||||
void ExternalGeometryFacadePy::setConstruction(Py::Boolean arg)
|
||||
{
|
||||
if (getExternalGeometryFacadePtr()->getTypeId() != Part::GeomPoint::getClassTypeId()) {
|
||||
if (!getExternalGeometryFacadePtr()->is<Part::GeomPoint>()) {
|
||||
getExternalGeometryFacadePtr()->setConstruction(arg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class GeometryFacadePy;
|
||||
*
|
||||
* Part::Geometry* copy = v->copy();
|
||||
*
|
||||
* if(construction && copy->getTypeId() != Part::GeomPoint::getClassTypeId()) {
|
||||
* if(construction && !copy->is<Part::GeomPoint>()) {
|
||||
* GeometryFacade::setConstruction(copy, construction);
|
||||
* }
|
||||
*
|
||||
|
||||
@@ -46,15 +46,16 @@ std::string PythonConverter::convert(const Part::Geometry* geo, Mode mode)
|
||||
command = boost::str(boost::format("addGeometry(%s,%s)\n") % sg.creation
|
||||
% (sg.construction ? "True" : "False"));
|
||||
|
||||
if ((geo->getTypeId() != Part::GeomEllipse::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomArcOfParabola::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId())
|
||||
&& mode == Mode::CreateInternalGeometry) {
|
||||
// clang-format off: keep line breaks for readability
|
||||
if ((!geo->is<Part::GeomEllipse>()
|
||||
|| !geo->is<Part::GeomArcOfEllipse>()
|
||||
|| !geo->is<Part::GeomArcOfHyperbola>()
|
||||
|| !geo->is<Part::GeomArcOfParabola>()
|
||||
|| !geo->is<Part::GeomBSplineCurve>()) && mode == Mode::CreateInternalGeometry) {
|
||||
command +=
|
||||
boost::str(boost::format("exposeInternalGeometry(len(ActiveSketch.Geometry))\n"));
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
return command;
|
||||
}
|
||||
@@ -149,15 +150,17 @@ std::string PythonConverter::convert(const std::string& doc,
|
||||
if (mode == Mode::CreateInternalGeometry) {
|
||||
for (auto geo : geos) {
|
||||
index++;
|
||||
if (geo->getTypeId() != Part::GeomEllipse::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomArcOfEllipse::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomArcOfHyperbola::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomArcOfParabola::getClassTypeId()
|
||||
|| geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId()) {
|
||||
// clang-format off: keep line breaks for readability
|
||||
if (!geo->is<Part::GeomEllipse>()
|
||||
|| !geo->is<Part::GeomArcOfEllipse>()
|
||||
|| !geo->is<Part::GeomArcOfHyperbola>()
|
||||
|| !geo->is<Part::GeomArcOfParabola>()
|
||||
|| !geo->is<Part::GeomBSplineCurve>()) {
|
||||
std::string newcommand =
|
||||
boost::str(boost::format("exposeInternalGeometry(lastGeoId + %d)\n") % (index));
|
||||
command += newcommand;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2480,8 +2480,8 @@ void SketchObject::transferFilletConstraints(int geoId1, PointPos posId1, int ge
|
||||
// TODO: Add support for curved lines.
|
||||
const Part::Geometry* geo1 = getGeometry(geoId1);
|
||||
const Part::Geometry* geo2 = getGeometry(geoId2);
|
||||
if (geo1->getTypeId() != Part::GeomLineSegment::getClassTypeId()
|
||||
|| geo2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) {
|
||||
if (!geo1->is<Part::GeomLineSegment>()
|
||||
|| !geo2->is<Part::GeomLineSegment>()) {
|
||||
delConstraintOnPoint(geoId1, posId1, false);
|
||||
delConstraintOnPoint(geoId2, posId2, false);
|
||||
return;
|
||||
@@ -4458,7 +4458,7 @@ bool SketchObject::isCarbonCopyAllowed(App::Document* pDoc, App::DocumentObject*
|
||||
std::string sketchArchType ("Sketcher::SketchObjectPython");
|
||||
|
||||
// Only applicable to sketches
|
||||
if (pObj->getTypeId() != Sketcher::SketchObject::getClassTypeId()
|
||||
if (!pObj->is<Sketcher::SketchObject>()
|
||||
&& sketchArchType != pObj->getTypeId().getName()) {
|
||||
if (rsn) {
|
||||
*rsn = rlNotASketch;
|
||||
@@ -6913,13 +6913,15 @@ bool SketchObject::increaseBSplineDegree(int GeoId, int degreeincrement /*= 1*/)
|
||||
// no need to check input data validity as this is an sketchobject managed operation.
|
||||
Base::StateLocker lock(managedoperation, true);
|
||||
|
||||
if (GeoId < 0 || GeoId > getHighestCurveIndex())
|
||||
if (GeoId < 0 || GeoId > getHighestCurveIndex()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const Part::Geometry* geo = getGeometry(GeoId);
|
||||
|
||||
if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId())
|
||||
if (!geo->is<Part::GeomBSplineCurve>()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto* bsp = static_cast<const Part::GeomBSplineCurve*>(geo);
|
||||
|
||||
@@ -6960,7 +6962,7 @@ bool SketchObject::decreaseBSplineDegree(int GeoId, int degreedecrement /*= 1*/)
|
||||
|
||||
const Part::Geometry* geo = getGeometry(GeoId);
|
||||
|
||||
if (geo->getTypeId() != Part::GeomBSplineCurve::getClassTypeId())
|
||||
if (!geo->is<Part::GeomBSplineCurve>())
|
||||
return false;
|
||||
|
||||
const auto* bsp = static_cast<const Part::GeomBSplineCurve*>(geo);
|
||||
@@ -7449,7 +7451,7 @@ int SketchObject::carbonCopy(App::DocumentObject* pObj, bool construction)
|
||||
for (std::vector<Part::Geometry*>::const_iterator it = svals.begin(); it != svals.end(); ++it) {
|
||||
Part::Geometry* geoNew = (*it)->copy();
|
||||
generateId(geoNew);
|
||||
if (construction && geoNew->getTypeId() != Part::GeomPoint::getClassTypeId()) {
|
||||
if (construction && !geoNew->is<Part::GeomPoint>()) {
|
||||
GeometryFacade::setConstruction(geoNew, true);
|
||||
}
|
||||
newVals.push_back(geoNew);
|
||||
@@ -10111,7 +10113,7 @@ void SketchObject::onChanged(const App::Property* prop)
|
||||
|
||||
if (ext->testMigrationType(Part::GeometryMigrationExtension::Construction)) {
|
||||
bool oldconstr = ext->getConstruction();
|
||||
if (geometryValue->getTypeId() == Part::GeomPoint::getClassTypeId()
|
||||
if (geometryValue->is<Part::GeomPoint>()
|
||||
&& !gf->isInternalAligned()) {
|
||||
oldconstr = true;
|
||||
}
|
||||
|
||||
@@ -735,9 +735,8 @@ private:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (isLineSegment(*geo2)
|
||||
|| geo2->getTypeId() == Part::GeomArcOfConic::getClassTypeId()
|
||||
|| isBSplineCurve(*geo2)) {
|
||||
else if (isLineSegment(*geo2) || isBSplineCurve(*geo2)
|
||||
|| geo2->is<Part::GeomArcOfConic>()) {
|
||||
// cases where arc is created by arc join mode.
|
||||
Base::Vector3d p2, p3;
|
||||
|
||||
|
||||
@@ -65,12 +65,16 @@ public:
|
||||
int GeoId = std::atoi(element.substr(4, 4000).c_str()) - 1;
|
||||
Sketcher::SketchObject* Sketch = static_cast<Sketcher::SketchObject*>(object);
|
||||
const Part::Geometry* geom = Sketch->getGeometry(GeoId);
|
||||
if (geom->is<Part::GeomLineSegment>() || geom->is<Part::GeomCircle>()
|
||||
|
||||
// clang-format off: keep line breaks for readability
|
||||
if (geom->is<Part::GeomLineSegment>()
|
||||
|| geom->is<Part::GeomCircle>()
|
||||
|| geom->is<Part::GeomEllipse>()
|
||||
|| geom->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId())
|
||||
|| geom->is<Part::GeomBSplineCurve>()) {
|
||||
return true;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
else if (element.substr(0, 6) == "Vertex") {
|
||||
int VertId = std::atoi(element.substr(6, 4000).c_str()) - 1;
|
||||
@@ -114,12 +118,15 @@ public:
|
||||
int curveGeoId = getPreselectCurve();
|
||||
if (curveGeoId >= 0) {
|
||||
const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(curveGeoId);
|
||||
if (geom->is<Part::GeomLineSegment>() || geom->is<Part::GeomCircle>()
|
||||
// clang-format off: keep line breaks for readability
|
||||
if (geom->is<Part::GeomLineSegment>()
|
||||
|| geom->is<Part::GeomCircle>()
|
||||
|| geom->is<Part::GeomEllipse>()
|
||||
|| geom->isDerivedFrom(Part::GeomArcOfConic::getClassTypeId())
|
||||
|| geom->is<Part::GeomBSplineCurve>()) {
|
||||
GeoId = curveGeoId;
|
||||
}
|
||||
// clang-format on
|
||||
}
|
||||
else {
|
||||
// No curve of interest is pre-selected. Try pre-selected point.
|
||||
|
||||
@@ -573,7 +573,7 @@ Property* Sheet::setFloatProperty(CellAddress key, double value)
|
||||
Property* prop = props.getDynamicPropertyByName(name.c_str());
|
||||
PropertyFloat* floatProp;
|
||||
|
||||
if (!prop || prop->getTypeId() != PropertyFloat::getClassTypeId()) {
|
||||
if (!prop || !prop->is<PropertyFloat>()) {
|
||||
if (prop) {
|
||||
this->removeDynamicProperty(name.c_str());
|
||||
propAddress.erase(prop);
|
||||
@@ -601,7 +601,7 @@ Property* Sheet::setIntegerProperty(CellAddress key, long value)
|
||||
Property* prop = props.getDynamicPropertyByName(name.c_str());
|
||||
PropertyInteger* intProp;
|
||||
|
||||
if (!prop || prop->getTypeId() != PropertyInteger::getClassTypeId()) {
|
||||
if (!prop || !prop->is<PropertyInteger>()) {
|
||||
if (prop) {
|
||||
this->removeDynamicProperty(name.c_str());
|
||||
propAddress.erase(prop);
|
||||
@@ -641,7 +641,7 @@ Property* Sheet::setQuantityProperty(CellAddress key, double value, const Base::
|
||||
Property* prop = props.getDynamicPropertyByName(name.c_str());
|
||||
PropertySpreadsheetQuantity* quantityProp;
|
||||
|
||||
if (!prop || prop->getTypeId() != PropertySpreadsheetQuantity::getClassTypeId()) {
|
||||
if (!prop || !prop->is<PropertySpreadsheetQuantity>()) {
|
||||
if (prop) {
|
||||
this->removeDynamicProperty(name.c_str());
|
||||
propAddress.erase(prop);
|
||||
|
||||
Reference in New Issue
Block a user