PartDesign: modernize type checking

This commit is contained in:
Florian Foinant-Willig
2023-10-15 21:39:11 +02:00
parent 2e16f5aa36
commit 6adc675a12
26 changed files with 114 additions and 114 deletions

View File

@@ -189,7 +189,7 @@ bool Body::isMemberOfMultiTransform(const App::DocumentObject* obj)
// to auto set it when the originals are not null. See:
// App::DocumentObjectExecReturn *Transformed::execute(void)
//
return (obj->getTypeId().isDerivedFrom(PartDesign::Transformed::getClassTypeId()) &&
return (obj->isDerivedFrom<PartDesign::Transformed>() &&
static_cast<const PartDesign::Transformed*>(obj)->Originals.getValues().empty());
}
@@ -198,7 +198,7 @@ bool Body::isSolidFeature(const App::DocumentObject *obj)
if (!obj)
return false;
if (obj->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) &&
if (obj->isDerivedFrom<PartDesign::Feature>() &&
!PartDesign::Feature::isDatum(obj)) {
// Transformed Features inside a MultiTransform are not solid features
return !isMemberOfMultiTransform(obj);
@@ -212,15 +212,15 @@ bool Body::isAllowed(const App::DocumentObject *obj)
return false;
// TODO: Should we introduce a PartDesign::FeaturePython class? This should then also return true for isSolidFeature()
return (obj->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) ||
obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId()) ||
return (obj->isDerivedFrom<PartDesign::Feature>() ||
obj->isDerivedFrom<Part::Datum>() ||
// TODO Shouldn't we replace it with Sketcher::SketchObject? (2015-08-13, Fat-Zer)
obj->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()) ||
obj->getTypeId().isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId()) ||
obj->getTypeId().isDerivedFrom(PartDesign::SubShapeBinder::getClassTypeId())
obj->isDerivedFrom<Part::Part2DObject>() ||
obj->isDerivedFrom<PartDesign::ShapeBinder>() ||
obj->isDerivedFrom<PartDesign::SubShapeBinder>()
// TODO Why this lines was here? why should we allow anything of those? (2015-08-13, Fat-Zer)
//obj->getTypeId().isDerivedFrom(Part::FeaturePython::getClassTypeId()) // trouble with this line on Windows!? Linker fails to find getClassTypeId() of the Part::FeaturePython...
//obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())
//obj->isDerivedFrom<Part::FeaturePython>() // trouble with this line on Windows!? Linker fails to find getClassTypeId() of the Part::FeaturePython...
//obj->isDerivedFrom<Part::Feature>()
);
}

View File

@@ -116,7 +116,7 @@ Part::Feature* Feature::getBaseObject(bool silent) const {
const char *err = nullptr;
if (BaseLink) {
if (BaseLink->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (BaseLink->isDerivedFrom<Part::Feature>()) {
BaseObject = static_cast<Part::Feature*>(BaseLink);
}
if (!BaseObject) {
@@ -191,8 +191,8 @@ PyObject* Feature::getPyObject()
bool Feature::isDatum(const App::DocumentObject* feature)
{
return feature->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()) ||
feature->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId());
return feature->isDerivedFrom<App::OriginFeature>() ||
feature->isDerivedFrom<Part::Datum>();
}
gp_Pln Feature::makePlnFromPlane(const App::DocumentObject* obj)

View File

@@ -125,11 +125,11 @@ App::DocumentObjectExecReturn *Draft::execute()
gp_Dir pullDirection;
App::DocumentObject* refDirection = PullDirection.getValue();
if (refDirection) {
if (refDirection->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
if (refDirection->isDerivedFrom<PartDesign::Line>()) {
PartDesign::Line* line = static_cast<PartDesign::Line*>(refDirection);
Base::Vector3d d = line->getDirection();
pullDirection = gp_Dir(d.x, d.y, d.z);
} else if (refDirection->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
} else if (refDirection->isDerivedFrom<Part::Feature>()) {
std::vector<std::string> subStrings = PullDirection.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::ValueError("No pull direction reference specified");
@@ -209,14 +209,14 @@ App::DocumentObjectExecReturn *Draft::execute()
if (!found)
throw Base::RuntimeError("No neutral plane specified and none can be guessed");
} else {
if (refPlane->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
if (refPlane->isDerivedFrom<PartDesign::Plane>()) {
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(refPlane);
Base::Vector3d b = plane->getBasePoint();
Base::Vector3d n = plane->getNormal();
neutralPlane = gp_Pln(gp_Pnt(b.x, b.y, b.z), gp_Dir(n.x, n.y, n.z));
} else if (refPlane->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
} else if (refPlane->isDerivedFrom<App::Plane>()) {
neutralPlane = Feature::makePlnFromPlane(refPlane);
} else if (refPlane->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
} else if (refPlane->isDerivedFrom<Part::Feature>()) {
std::vector<std::string> subStrings = NeutralPlane.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::ValueError("No neutral plane reference specified");

View File

@@ -66,7 +66,7 @@ short DressUp::mustExecute() const
void DressUp::positionByBaseFeature()
{
Part::Feature *base = static_cast<Part::Feature*>(BaseFeature.getValue());
if (base && base->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
if (base && base->isDerivedFrom<Part::Feature>())
this->Placement.setValue(base->Placement.getValue());
}

View File

@@ -110,7 +110,7 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
throw Base::ValueError("No direction reference specified");
gp_Dir dir;
if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (refObject->isDerivedFrom<Part::Part2DObject>()) {
Part::Part2DObject* refSketch = static_cast<Part::Part2DObject*>(refObject);
Base::Axis axis;
if (subStrings[0] == "H_Axis") {
@@ -151,21 +151,21 @@ const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App
axis.setDirection(Base::Vector3d(d.X(), d.Y(), d.Z()));
}
dir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z);
} else if (refObject->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
} else if (refObject->isDerivedFrom<PartDesign::Plane>()) {
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(refObject);
Base::Vector3d d = plane->getNormal();
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
} else if (refObject->isDerivedFrom<PartDesign::Line>()) {
PartDesign::Line* line = static_cast<PartDesign::Line*>(refObject);
Base::Vector3d d = line->getDirection();
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
} else if (refObject->isDerivedFrom<App::Line>()) {
App::Line* line = static_cast<App::Line*>(refObject);
Base::Rotation rot = line->Placement.getValue().getRotation();
Base::Vector3d d(1,0,0);
rot.multVec(d, d);
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
} else if (refObject->isDerivedFrom<Part::Feature>()) {
if (subStrings[0].empty())
throw Base::ValueError("No direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);

View File

@@ -68,7 +68,7 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
gp_Pnt axbase;
gp_Dir axdir;
if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (refObject->isDerivedFrom<Part::Part2DObject>()) {
Part::Part2DObject* refSketch = static_cast<Part::Part2DObject*>(refObject);
Base::Axis axis;
if (subStrings[0] == "H_Axis")
@@ -88,13 +88,13 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
axis *= refSketch->Placement.getValue();
axbase = gp_Pnt(axis.getBase().x, axis.getBase().y, axis.getBase().z);
axdir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z);
} else if (refObject->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
} else if (refObject->isDerivedFrom<PartDesign::Plane>()) {
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(refObject);
Base::Vector3d base = plane->getBasePoint();
axbase = gp_Pnt(base.x, base.y, base.z);
Base::Vector3d dir = plane->getNormal();
axdir = gp_Dir(dir.x, dir.y, dir.z);
} else if (refObject->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
} else if (refObject->isDerivedFrom<App::Plane>()) {
App::Plane* plane = static_cast<App::Plane*>(refObject);
Base::Vector3d base = plane->Placement.getValue().getPosition();
axbase = gp_Pnt(base.x, base.y, base.z);
@@ -102,7 +102,7 @@ const std::list<gp_Trsf> Mirrored::getTransformations(const std::vector<App::Doc
Base::Vector3d dir(0,0,1);
rot.multVec(dir, dir);
axdir = gp_Dir(dir.x, dir.y, dir.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
} else if (refObject->isDerivedFrom<Part::Feature>()) {
if (subStrings[0].empty())
throw Base::ValueError("No direction reference specified");
Part::TopoShape baseShape = static_cast<Part::Feature*>(refObject)->Shape.getShape();

View File

@@ -51,7 +51,7 @@ void MultiTransform::positionBySupport()
PartDesign::Transformed::positionBySupport();
std::vector<App::DocumentObject*> transFeatures = Transformations.getValues();
for (auto f : transFeatures) {
if (!(f->getTypeId().isDerivedFrom(PartDesign::Transformed::getClassTypeId())))
if (!(f->isDerivedFrom<PartDesign::Transformed>()))
throw Base::TypeError("Transformation features must be subclasses of Transformed");
PartDesign::Transformed* transFeature = static_cast<PartDesign::Transformed*>(f);
transFeature->Placement.setValue(this->Placement.getValue());
@@ -80,7 +80,7 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
Part::Feature* originalFeature = static_cast<Part::Feature*>(originals.front());
TopoDS_Shape original;
if (originalFeature->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
if (originalFeature->isDerivedFrom<PartDesign::FeatureAddSub>()) {
PartDesign::FeatureAddSub* addFeature = static_cast<PartDesign::FeatureAddSub*>(originalFeature);
//if (addFeature->getAddSubType() == FeatureAddSub::Additive)
// original = addFeature->AddSubShape.getShape().getShape();
@@ -97,7 +97,7 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
std::vector<App::DocumentObject*>::const_iterator f;
for (f = transFeatures.begin(); f != transFeatures.end(); ++f) {
if (!((*f)->getTypeId().isDerivedFrom(PartDesign::Transformed::getClassTypeId())))
if (!((*f)->isDerivedFrom<PartDesign::Transformed>()))
throw Base::TypeError("Transformation features must be subclasses of Transformed");
PartDesign::Transformed* transFeature = static_cast<PartDesign::Transformed*>(*f);
std::list<gp_Trsf> newTransformations = transFeature->getTransformations(originals);
@@ -116,7 +116,7 @@ const std::list<gp_Trsf> MultiTransform::getTransformations(const std::vector<Ap
std::list<gp_Pnt> oldCogs;
cogs.swap(oldCogs); // empty cogs to receive new cogs
if ((*f)->getTypeId() == PartDesign::Scaled::getClassTypeId()) {
if ((*f)->is<PartDesign::Scaled>()) {
// Diagonal method
// Multiply every element in the old transformations' slices with the corresponding
// element in the newTransformations. Example:

View File

@@ -173,7 +173,7 @@ App::DocumentObjectExecReturn *Pipe::execute()
// build the paths
App::DocumentObject* spine = Spine.getValue();
if (!(spine && spine->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
if (!(spine && spine->isDerivedFrom<Part::Feature>()))
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "No spine linked"));
std::vector<std::string> subedge = Spine.getSubValues();
@@ -186,7 +186,7 @@ App::DocumentObjectExecReturn *Pipe::execute()
TopoDS_Shape auxpath;
if (Mode.getValue() == 3) {
App::DocumentObject* auxspine = AuxillerySpine.getValue();
if (!(auxspine && auxspine->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
if (!(auxspine && auxspine->isDerivedFrom<Part::Feature>()))
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "No auxiliary spine linked."));
std::vector<std::string> auxsubedge = AuxillerySpine.getSubValues();

View File

@@ -104,7 +104,7 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
gp_Pnt axbase;
gp_Dir axdir;
if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (refObject->isDerivedFrom<Part::Part2DObject>()) {
Part::Part2DObject* refSketch = static_cast<Part::Part2DObject*>(refObject);
Base::Axis axis;
if (subStrings[0] == "H_Axis")
@@ -121,19 +121,19 @@ const std::list<gp_Trsf> PolarPattern::getTransformations(const std::vector<App:
axis *= refSketch->Placement.getValue();
axbase = gp_Pnt(axis.getBase().x, axis.getBase().y, axis.getBase().z);
axdir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z);
} else if (refObject->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
} else if (refObject->isDerivedFrom<PartDesign::Line>()) {
PartDesign::Line* line = static_cast<PartDesign::Line*>(refObject);
Base::Vector3d base = line->getBasePoint();
axbase = gp_Pnt(base.x, base.y, base.z);
Base::Vector3d dir = line->getDirection();
axdir = gp_Dir(dir.x, dir.y, dir.z);
} else if (refObject->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
} else if (refObject->isDerivedFrom<App::Line>()) {
App::Line* line = static_cast<App::Line*>(refObject);
Base::Rotation rot = line->Placement.getValue().getRotation();
Base::Vector3d d(1,0,0);
rot.multVec(d, d);
axdir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
} else if (refObject->isDerivedFrom<Part::Feature>()) {
if (subStrings[0].empty())
throw Base::ValueError("No axis reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);

View File

@@ -69,7 +69,7 @@ const std::list<gp_Trsf> Scaled::getTransformations(const std::vector<App::Docum
Part::Feature* originalFeature = static_cast<Part::Feature*>(originals.front());
TopoDS_Shape original;
if (originalFeature->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
if (originalFeature->isDerivedFrom<PartDesign::FeatureAddSub>()) {
PartDesign::FeatureAddSub* Feature = static_cast<PartDesign::FeatureAddSub*>(originalFeature);
//if(Feature->getAddSubType() == FeatureAddSub::Additive)
// original = Feature->AddSubShape.getShape().getShape();

View File

@@ -130,7 +130,7 @@ Part::Part2DObject* ProfileBased::getVerifiedSketch(bool silent) const {
err = "No profile linked at all";
}
else {
if (!result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (!result->isDerivedFrom<Part::Part2DObject>()) {
err = "Linked object is not a Sketch or Part2DObject";
result = nullptr;
}
@@ -152,7 +152,7 @@ Part::Feature* ProfileBased::getVerifiedObject(bool silent) const {
err = "No object linked";
}
else {
if (!result->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
if (!result->isDerivedFrom<Part::Feature>())
err = "Linked object is not a Sketch, Part2DObject or Feature";
}
@@ -213,12 +213,12 @@ TopoDS_Shape ProfileBased::getVerifiedFace(bool silent) const {
}
}
else {
if (result->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (result->isDerivedFrom<Part::Part2DObject>()) {
auto wires = getProfileWires();
return Part::FaceMakerCheese::makeFace(wires);
}
else if (result->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
else if (result->isDerivedFrom<Part::Feature>()) {
if (Profile.getSubValues().empty())
err = "Linked object has no subshape specified";
else {
@@ -424,17 +424,17 @@ void ProfileBased::getFaceFromLinkSub(TopoDS_Face& upToFace, const App::Property
if (!ref)
throw Base::ValueError("SketchBased: No face selected");
if (ref->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
if (ref->isDerivedFrom<App::Plane>()) {
upToFace = TopoDS::Face(makeShapeFromPlane(ref));
return;
}
else if (ref->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
else if (ref->isDerivedFrom<PartDesign::Plane>()) {
Part::Datum* datum = static_cast<Part::Datum*>(ref);
upToFace = TopoDS::Face(datum->getShape());
return;
}
if (!ref->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
if (!ref->isDerivedFrom<Part::Feature>())
throw Base::TypeError("SketchBased: Must be face of a feature");
Part::TopoShape baseShape = static_cast<Part::Feature*>(ref)->Shape.getShape();
@@ -1008,7 +1008,7 @@ void ProfileBased::getAxis(const App::DocumentObject * pcReferenceAxis, const st
App::DocumentObject* profile = Profile.getValue();
gp_Pln sketchplane;
if (profile->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (profile->isDerivedFrom<Part::Part2DObject>()) {
Part::Part2DObject* sketch = getVerifiedSketch();
Base::Placement SketchPlm = sketch->Placement.getValue();
Base::Vector3d SketchVector = Base::Vector3d(0, 0, 1);
@@ -1048,7 +1048,7 @@ void ProfileBased::getAxis(const App::DocumentObject * pcReferenceAxis, const st
}
}
else if (profile->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
else if (profile->isDerivedFrom<Part::Feature>()) {
Base::Placement SketchPlm = getVerifiedObject()->Placement.getValue();
Base::Vector3d SketchVector = getProfileNormal();
Base::Vector3d SketchPos = SketchPlm.getPosition();
@@ -1056,7 +1056,7 @@ void ProfileBased::getAxis(const App::DocumentObject * pcReferenceAxis, const st
}
// get reference axis
if (pcReferenceAxis->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
if (pcReferenceAxis->isDerivedFrom<PartDesign::Line>()) {
const PartDesign::Line* line = static_cast<const PartDesign::Line*>(pcReferenceAxis);
base = line->getBasePoint();
dir = line->getDirection();
@@ -1065,7 +1065,7 @@ void ProfileBased::getAxis(const App::DocumentObject * pcReferenceAxis, const st
return;
}
if (pcReferenceAxis->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
if (pcReferenceAxis->isDerivedFrom<App::Line>()) {
const App::Line* line = static_cast<const App::Line*>(pcReferenceAxis);
base = Base::Vector3d(0, 0, 0);
line->Placement.getValue().multVec(Base::Vector3d(1, 0, 0), dir);
@@ -1074,7 +1074,7 @@ void ProfileBased::getAxis(const App::DocumentObject * pcReferenceAxis, const st
return;
}
if (pcReferenceAxis->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (pcReferenceAxis->isDerivedFrom<Part::Feature>()) {
if (subReferenceAxis.empty())
throw Base::ValueError("No rotation axis reference specified");
const Part::Feature* refFeature = static_cast<const Part::Feature*>(pcReferenceAxis);

View File

@@ -107,23 +107,23 @@ Part::Feature* Transformed::getBaseObject(bool silent) const {
App::DocumentObject* Transformed::getSketchObject() const
{
std::vector<DocumentObject*> originals = Originals.getValues();
if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
if (!originals.empty() && originals.front()->isDerivedFrom<PartDesign::ProfileBased>()) {
return (static_cast<PartDesign::ProfileBased*>(originals.front()))->getVerifiedSketch(true);
}
else if (!originals.empty() && originals.front()->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
else if (!originals.empty() && originals.front()->isDerivedFrom<PartDesign::FeatureAddSub>()) {
return nullptr;
}
else if (this->getTypeId().isDerivedFrom(LinearPattern::getClassTypeId())) {
else if (this->isDerivedFrom<LinearPattern>()) {
// if Originals is empty then try the linear pattern's Direction property
const LinearPattern* pattern = static_cast<const LinearPattern*>(this);
return pattern->Direction.getValue();
}
else if (this->getTypeId().isDerivedFrom(PolarPattern::getClassTypeId())) {
else if (this->isDerivedFrom<PolarPattern>()) {
// if Originals is empty then try the polar pattern's Axis property
const PolarPattern* pattern = static_cast<const PolarPattern*>(this);
return pattern->Axis.getValue();
}
else if (this->getTypeId().isDerivedFrom(Mirrored::getClassTypeId())) {
else if (this->isDerivedFrom<Mirrored>()) {
// if Originals is empty then try the mirror pattern's MirrorPlane property
const Mirrored* pattern = static_cast<const Mirrored*>(this);
return pattern->MirrorPlane.getValue();
@@ -143,7 +143,7 @@ void Transformed::handleChangedPropertyType(Base::XMLReader &reader, const char
// The property 'Angle' of PolarPattern has changed from PropertyFloat
// to PropertyAngle and the property 'Length' has changed to PropertyLength.
Base::Type inputType = Base::Type::fromName(TypeName);
if (prop->getTypeId().isDerivedFrom(App::PropertyFloat::getClassTypeId()) &&
if (prop->isDerivedFrom<App::PropertyFloat>() &&
inputType.isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
// Do not directly call the property's Restore method in case the implementation
// has changed. So, create a temporary PropertyFloat object and assign the value.
@@ -254,7 +254,7 @@ App::DocumentObjectExecReturn *Transformed::execute()
Part::TopoShape fuseShape;
Part::TopoShape cutShape;
if (original->getTypeId().isDerivedFrom(PartDesign::FeatureAddSub::getClassTypeId())) {
if (original->isDerivedFrom<PartDesign::FeatureAddSub>()) {
PartDesign::FeatureAddSub* feature = static_cast<PartDesign::FeatureAddSub*>(original);
feature->getAddSubShape(fuseShape, cutShape);
if (fuseShape.isNull() && cutShape.isNull())

View File

@@ -151,7 +151,7 @@ void ShapeBinder::getFilteredReferences(const App::PropertyLinkSubList* prop,
//we only allow one part feature, so get the first one we find
size_t index = 0;
for (auto* it : objs) {
if (it && it->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (it && it->isDerivedFrom<Part::Feature>()) {
obj = static_cast<Part::Feature*>(it);
break;
}
@@ -182,11 +182,11 @@ void ShapeBinder::getFilteredReferences(const App::PropertyLinkSubList* prop,
else {
// search for Origin features
for (auto* it : objs) {
if (it && it->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
if (it && it->isDerivedFrom<App::Line>()) {
obj = static_cast<App::GeoFeature*>(it);
break;
}
else if (it && it->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
else if (it && it->isDerivedFrom<App::Plane>()) {
obj = static_cast<App::GeoFeature*>(it);
break;
}
@@ -199,7 +199,7 @@ Part::TopoShape ShapeBinder::buildShapeFromReferences(App::GeoFeature* obj, std:
if (!obj)
return TopoDS_Shape();
if (obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (obj->isDerivedFrom<Part::Feature>()) {
Part::Feature* part = static_cast<Part::Feature*>(obj);
if (subs.empty())
return part->Shape.getValue();
@@ -224,14 +224,14 @@ Part::TopoShape ShapeBinder::buildShapeFromReferences(App::GeoFeature* obj, std:
return cmp;
}
}
else if (obj->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
else if (obj->isDerivedFrom<App::Line>()) {
gp_Lin line;
BRepBuilderAPI_MakeEdge mkEdge(line);
Part::TopoShape shape(mkEdge.Shape());
shape.setPlacement(obj->Placement.getValue());
return shape;
}
else if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
else if (obj->isDerivedFrom<App::Plane>()) {
gp_Pln plane;
BRepBuilderAPI_MakeFace mkFace(plane);
Part::TopoShape shape(mkFace.Shape());
@@ -273,7 +273,7 @@ void ShapeBinder::slotChangedObject(const App::DocumentObject& Obj, const App::P
return;
if (!TraceSupport.getValue())
return;
if (!Prop.getTypeId().isDerivedFrom(App::PropertyPlacement::getClassTypeId()))
if (!Prop.isDerivedFrom<App::PropertyPlacement>())
return;
App::GeoFeature* obj = nullptr;

View File

@@ -617,9 +617,9 @@ unsigned validateSketches(std::vector<App::DocumentObject*>& sketches,
std::vector<App::DocumentObject*>::iterator o = inList.begin();
while (o != inList.end()) {
//Base::Console().Error("Inlist: %s\n", (*o)->getNameInDocument());
if ((*o)->getTypeId().isDerivedFrom(PartDesign::Body::getClassTypeId()))
if ((*o)->isDerivedFrom<PartDesign::Body>())
o = inList.erase(o); //ignore bodies
else if (!( (*o)->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) ))
else if (!( (*o)->isDerivedFrom<PartDesign::Feature>() ))
o = inList.erase(o); //ignore non-partDesign
else
++o;
@@ -2244,7 +2244,7 @@ void CmdPartDesignMultiTransform::activated(int iMsg)
if (!features.empty()) {
// Throw out MultiTransform features, we don't want to nest them
for (std::vector<App::DocumentObject*>::iterator f = features.begin(); f != features.end(); ) {
if ((*f)->getTypeId().isDerivedFrom(PartDesign::MultiTransform::getClassTypeId()))
if ((*f)->isDerivedFrom<PartDesign::MultiTransform>())
f = features.erase(f);
else
f++;

View File

@@ -231,7 +231,7 @@ void CmdPartDesignBody::activated(int iMsg)
if (body) {
std::vector<App::DocumentObject*> links = body->Group.getValues();
for (auto it : links) {
if (it->getTypeId().isDerivedFrom(PartDesign::FeatureBase::getClassTypeId())) {
if (it->isDerivedFrom<PartDesign::FeatureBase>()) {
PartDesign::FeatureBase* base = static_cast<PartDesign::FeatureBase*>(it);
if (base && base->BaseFeature.getValue() == baseFeature) {
Gui::Application::Instance->hideViewProvider(baseFeature);
@@ -797,7 +797,7 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
}
// Fix sketch support
if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
if (feat->isDerivedFrom<Sketcher::SketchObject>()) {
Sketcher::SketchObject *sketch = static_cast<Sketcher::SketchObject*>(feat);
try {
PartDesignGui::fixSketchSupport(sketch);

View File

@@ -68,11 +68,11 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
}
// Enable selection from origin of current part/
if (pObj->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) {
if (pObj->isDerivedFrom<App::OriginFeature>()) {
return allowOrigin(body, originGroup, pObj);
}
if (pObj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
if (pObj->isDerivedFrom<Part::Datum>()) {
return allowDatum(body, pObj);
}
@@ -90,11 +90,11 @@ bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, c
return type.testFlag(AllowSelection::WHOLE);
// resolve links if needed
if (!pObj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (!pObj->isDerivedFrom<Part::Feature>()) {
pObj = Part::Feature::getShapeOwner(pObj, sSubName);
}
if (pObj && pObj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (pObj && pObj->isDerivedFrom<Part::Feature>()) {
return allowPartFeature(pObj, sSubName);
}
@@ -138,10 +138,10 @@ App::OriginGroupExtension* ReferenceSelection::getOriginGroupExtension(PartDesig
bool ReferenceSelection::allowOrigin(PartDesign::Body *body, App::OriginGroupExtension* originGroup, App::DocumentObject* pObj) const
{
bool fits = false;
if (type.testFlag(AllowSelection::FACE) && pObj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
if (type.testFlag(AllowSelection::FACE) && pObj->isDerivedFrom<App::Plane>()) {
fits = true;
}
else if (type.testFlag(AllowSelection::EDGE) && pObj->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
else if (type.testFlag(AllowSelection::EDGE) && pObj->isDerivedFrom<App::Line>()) {
fits = true;
}
@@ -173,11 +173,11 @@ bool ReferenceSelection::allowDatum(PartDesign::Body *body, App::DocumentObject*
return false;
}
if (type.testFlag(AllowSelection::FACE) && (pObj->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())))
if (type.testFlag(AllowSelection::FACE) && (pObj->isDerivedFrom<PartDesign::Plane>()))
return true;
if (type.testFlag(AllowSelection::EDGE) && (pObj->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())))
if (type.testFlag(AllowSelection::EDGE) && (pObj->isDerivedFrom<PartDesign::Line>()))
return true;
if (type.testFlag(AllowSelection::POINT) && (pObj->getTypeId().isDerivedFrom(PartDesign::Point::getClassTypeId())))
if (type.testFlag(AllowSelection::POINT) && (pObj->isDerivedFrom<PartDesign::Point>()))
return true;
return false;

View File

@@ -111,7 +111,7 @@ void TaskBooleanParameters::onSelectionChanged(const Gui::SelectionChanges& msg)
return;
// if the selected object is not a body then get the body it is part of
if (!pcBody->getTypeId().isDerivedFrom(PartDesign::Body::getClassTypeId())) {
if (!pcBody->isDerivedFrom<PartDesign::Body>()) {
pcBody = PartDesign::Body::findBodyOf(pcBody);
if (!pcBody)
return;

View File

@@ -100,7 +100,7 @@ bool TaskDlgFeatureParameters::accept() {
}
// Make sure the feature is what we are expecting
// Should be fine but you never know...
if ( !feature->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) ) {
if ( !feature->isDerivedFrom<PartDesign::Feature>() ) {
throw Base::TypeError("Bad object processed in the feature dialog.");
}

View File

@@ -263,7 +263,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures()
else if (status == notInBody) {
activeBody->addObject(copy);
// doesn't supposed to get here anything but sketch but to be on the safe side better to check
if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
if (copy->isDerivedFrom<Sketcher::SketchObject>()) {
Sketcher::SketchObject *sketch = static_cast<Sketcher::SketchObject*>(copy);
PartDesignGui::fixSketchSupport(sketch);
}
@@ -325,10 +325,10 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st
//independent copies don't have links and are not attached
if(independent && (
prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId()) ||
prop->getTypeId().isDerivedFrom(App::PropertyLinkList::getClassTypeId()) ||
prop->getTypeId().isDerivedFrom(App::PropertyLinkSub::getClassTypeId()) ||
prop->getTypeId().isDerivedFrom(App::PropertyLinkSubList::getClassTypeId())||
prop->isDerivedFrom<App::PropertyLink>() ||
prop->isDerivedFrom<App::PropertyLinkList>() ||
prop->isDerivedFrom<App::PropertyLinkSub>() ||
prop->isDerivedFrom<App::PropertyLinkSubList>()||
( prop->getGroup() && strcmp(prop->getGroup(),"Attachment")==0) )) {
++it;
@@ -378,13 +378,13 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st
long int mode = mmDeactivated;
Part::Datum *datumCopy = static_cast<Part::Datum*>(copy);
if(obj->getTypeId() == PartDesign::Point::getClassTypeId()) {
if(obj->is<PartDesign::Point>()) {
mode = mm0Vertex;
}
else if(obj->getTypeId() == PartDesign::Line::getClassTypeId()) {
else if(obj->is<PartDesign::Line>()) {
mode = mm1TwoPoints;
}
else if(obj->getTypeId() == PartDesign::Plane::getClassTypeId()) {
else if(obj->is<PartDesign::Plane>()) {
mode = mmFlatFace;
}
else
@@ -401,7 +401,7 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st
datumCopy->Shape.setValue(static_cast<Part::Datum*>(obj)->Shape.getValue());
}
}
else if(obj->getTypeId() == PartDesign::ShapeBinder::getClassTypeId() ||
else if(obj->is<PartDesign::ShapeBinder>() ||
obj->isDerivedFrom(Part::Feature::getClassTypeId())) {
copy = App::GetApplication().getActiveDocument()->addObject("PartDesign::ShapeBinder", name.c_str());

View File

@@ -260,13 +260,13 @@ void TaskMultiTransformParameters::onTransformEdit()
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
subFeature = static_cast<PartDesign::Transformed*>(transformFeatures[row]);
if (transformFeatures[row]->getTypeId() == PartDesign::Mirrored::getClassTypeId())
if (transformFeatures[row]->is<PartDesign::Mirrored>())
subTask = new TaskMirroredParameters(this, ui->verticalLayout);
else if (transformFeatures[row]->getTypeId() == PartDesign::LinearPattern::getClassTypeId())
else if (transformFeatures[row]->is<PartDesign::LinearPattern>())
subTask = new TaskLinearPatternParameters(this, ui->verticalLayout);
else if (transformFeatures[row]->getTypeId() == PartDesign::PolarPattern::getClassTypeId())
else if (transformFeatures[row]->is<PartDesign::PolarPattern>())
subTask = new TaskPolarPatternParameters(this, ui->verticalLayout);
else if (transformFeatures[row]->getTypeId() == PartDesign::Scaled::getClassTypeId())
else if (transformFeatures[row]->is<PartDesign::Scaled>())
subTask = new TaskScaledParameters(this, ui->verticalLayout);
else
return; // TODO: Show an error?

View File

@@ -146,11 +146,11 @@ QVariant TaskSketchBasedParameters::setUpToFace(const QString& text)
if (!obj)
return {};
if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
if (obj->isDerivedFrom<App::Plane>()) {
// everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree)
return {};
}
else if (obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
else if (obj->isDerivedFrom<Part::Datum>()) {
// it's up to the document to check that the datum plane is in the same body
return {};
}
@@ -256,7 +256,7 @@ bool TaskDlgSketchBasedParameters::accept() {
// Make sure the feature is what we are expecting
// Should be fine but you never know...
if (!feature->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
if (!feature->isDerivedFrom<PartDesign::ProfileBased>()) {
throw Base::TypeError("Bad object processed in the sketch based dialog.");
}

View File

@@ -457,14 +457,14 @@ bool isFeatureMovable(App::DocumentObject* const feat)
if (!feat)
return false;
if (feat->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) {
if (feat->isDerivedFrom<PartDesign::Feature>()) {
auto prim = static_cast<PartDesign::Feature*>(feat);
App::DocumentObject* bf = prim->BaseFeature.getValue();
if (bf)
return false;
}
if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
if (feat->isDerivedFrom<PartDesign::ProfileBased>()) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
auto sk = prim->getVerifiedSketch(true);
@@ -501,7 +501,7 @@ bool isFeatureMovable(App::DocumentObject* const feat)
if (feat->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) {
auto attachable = feat->getExtensionByType<Part::AttachExtension>();
App::DocumentObject* support = attachable->Support.getValue();
if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId()))
if (support && !support->isDerivedFrom<App::OriginFeature>())
return false;
}
@@ -516,7 +516,7 @@ std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::Do
{
// Get sketches and datums from profile based features
if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
if (feat->isDerivedFrom<PartDesign::ProfileBased>()) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
Part::Part2DObject* sk = prim->getVerifiedSketch(true);
if (sk) {
@@ -529,19 +529,19 @@ std::vector<App::DocumentObject*> collectMovableDependencies(std::vector<App::Do
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
if (axis && !axis->isDerivedFrom<App::OriginFeature>()){
unique_objs.insert(axis);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("Spine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
if (axis && !axis->isDerivedFrom<App::OriginFeature>()){
unique_objs.insert(axis);
}
}
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("AuxillerySpine"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
if (axis && !axis->isDerivedFrom<App::OriginFeature>()){
unique_objs.insert(axis);
}
}
@@ -560,7 +560,7 @@ void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
if (feat->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) {
auto attachable = feat->getExtensionByType<Part::AttachExtension>();
App::DocumentObject* support = attachable->Support.getValue();
if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) {
if (support && support->isDerivedFrom<App::OriginFeature>()) {
auto originfeat = static_cast<App::OriginFeature*>(support);
App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue());
if (targetOriginFeature) {
@@ -568,11 +568,11 @@ void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody)
}
}
}
else if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) {
else if (feat->isDerivedFrom<PartDesign::ProfileBased>()) {
auto prim = static_cast<PartDesign::ProfileBased*>(feat);
if (auto prop = static_cast<App::PropertyLinkSub*>(prim->getPropertyByName("ReferenceAxis"))) {
App::DocumentObject* axis = prop->getValue();
if (axis && axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){
if (axis && axis->isDerivedFrom<App::OriginFeature>()){
auto originfeat = static_cast<App::OriginFeature*>(axis);
App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue());
if (targetOriginFeature) {

View File

@@ -161,7 +161,7 @@ void ViewProvider::unsetEdit(int ModNum)
void ViewProvider::updateData(const App::Property* prop)
{
// TODO What's that? (2015-07-24, Fat-Zer)
if (prop->getTypeId() == Part::PropertyPartShape::getClassTypeId() &&
if (prop->is<Part::PropertyPartShape>() &&
strcmp(prop->getName(),"AddSubShape") == 0) {
return;
}

View File

@@ -490,7 +490,7 @@ bool ViewProviderBody::canDropObject(App::DocumentObject* obj) const
void ViewProviderBody::dropObject(App::DocumentObject* obj)
{
PartDesign::Body* body = static_cast<PartDesign::Body*>(getObject());
if (obj->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
if (obj->isDerivedFrom<Part::Part2DObject>()) {
body->addObject(obj);
}
else if (PartDesign::Body::isAllowed(obj) && PartDesignGui::isFeatureMovable(obj)) {
@@ -519,7 +519,7 @@ void ViewProviderBody::dropObject(App::DocumentObject* obj)
// check if a proxy object has been created for the base feature
std::vector<App::DocumentObject*> links = body->Group.getValues();
for (auto it : links) {
if (it->getTypeId().isDerivedFrom(PartDesign::FeatureBase::getClassTypeId())) {
if (it->isDerivedFrom<PartDesign::FeatureBase>()) {
PartDesign::FeatureBase* base = static_cast<PartDesign::FeatureBase*>(it);
if (base && base->BaseFeature.getValue() == obj) {
Gui::Application::Instance->hideViewProvider(obj);

View File

@@ -105,22 +105,22 @@ void ViewProviderDatum::attach(App::DocumentObject *obj)
// TODO remove this field (2015-09-08, Fat-Zer)
App::DocumentObject* o = getObject();
if (o->getTypeId() == PartDesign::Plane::getClassTypeId()) {
if (o->is<PartDesign::Plane>()) {
datumType = QString::fromLatin1("Plane");
datumText = QObject::tr("Plane");
datumMenuText = tr("Datum Plane parameters");
}
else if (o->getTypeId() == PartDesign::Line::getClassTypeId()) {
else if (o->is<PartDesign::Line>()) {
datumType = QString::fromLatin1("Line");
datumText = QObject::tr("Line");
datumMenuText = tr("Datum Line parameters");
}
else if (o->getTypeId() == PartDesign::Point::getClassTypeId()) {
else if (o->is<PartDesign::Point>()) {
datumType = QString::fromLatin1("Point");
datumText = QObject::tr("Point");
datumMenuText = tr("Datum Point parameters");
}
else if (o->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId()) {
else if (o->is<PartDesign::CoordinateSystem>()) {
datumType = QString::fromLatin1("CoordinateSystem");
datumText = QObject::tr("Coordinate System");
datumMenuText = tr("Local Coordinate System parameters");

View File

@@ -136,7 +136,7 @@ void ViewProviderShapeBinder::highlightReferences(bool on)
return;
// stop if not a Part feature was found
if (!obj || !obj->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
if (!obj || !obj->isDerivedFrom<Part::Feature>())
return;
PartGui::ViewProviderPart* svp = dynamic_cast<PartGui::ViewProviderPart*>(