Drawing: modernize type checking

This commit is contained in:
Florian Foinant-Willig
2023-10-15 21:39:01 +02:00
parent 027ac1b456
commit da1dd02ff0
8 changed files with 16 additions and 20 deletions

View File

@@ -117,7 +117,7 @@ App::DocumentObjectExecReturn* FeatureClip::execute(void)
// get through the children and collect all the views
const vector<App::DocumentObject*>& Grp = Group.getValues();
for (vector<App::DocumentObject*>::const_iterator It = Grp.begin(); It != Grp.end(); ++It) {
if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
if ((*It)->isDerivedFrom<Drawing::FeatureView>()) {
Drawing::FeatureView* View = static_cast<Drawing::FeatureView*>(*It);
svg << View->ViewResult.getValue() << endl;
}

View File

@@ -181,22 +181,21 @@ App::DocumentObjectExecReturn* FeaturePage::execute(void)
for (std::vector<App::DocumentObject*>::const_iterator It = Grp.begin();
It != Grp.end();
++It) {
if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
if ((*It)->isDerivedFrom<Drawing::FeatureView>()) {
Drawing::FeatureView* View = static_cast<Drawing::FeatureView*>(*It);
if (View->Visible.getValue()) {
ofile << View->ViewResult.getValue();
ofile << tempendl << tempendl << tempendl;
}
}
else if ((*It)->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) {
else if ((*It)->isDerivedFrom<Drawing::FeatureClip>()) {
Drawing::FeatureClip* Clip = static_cast<Drawing::FeatureClip*>(*It);
if (Clip->Visible.getValue()) {
ofile << Clip->ViewResult.getValue();
ofile << tempendl << tempendl << tempendl;
}
}
else if ((*It)->getTypeId().isDerivedFrom(
App::DocumentObjectGroup::getClassTypeId())) {
else if ((*It)->isDerivedFrom<App::DocumentObjectGroup>()) {
// getting children inside subgroups too
App::DocumentObjectGroup* SubGroup =
static_cast<App::DocumentObjectGroup*>(*It);
@@ -204,8 +203,7 @@ App::DocumentObjectExecReturn* FeaturePage::execute(void)
for (std::vector<App::DocumentObject*>::const_iterator Grit = SubGrp.begin();
Grit != SubGrp.end();
++Grit) {
if ((*Grit)->getTypeId().isDerivedFrom(
Drawing::FeatureView::getClassTypeId())) {
if ((*Grit)->isDerivedFrom<Drawing::FeatureView>()) {
Drawing::FeatureView* SView = static_cast<Drawing::FeatureView*>(*Grit);
if (SView->Visible.getValue()) {
ofile << SView->ViewResult.getValue();

View File

@@ -67,7 +67,7 @@ App::DocumentObjectExecReturn* FeatureProjection::execute(void)
if (!link) {
return new App::DocumentObjectExecReturn("No object linked");
}
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (!link->isDerivedFrom<Part::Feature>()) {
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
}
const TopoDS_Shape& shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();

View File

@@ -87,7 +87,7 @@ App::DocumentObjectExecReturn* FeatureViewPart::execute(void)
if (!link) {
return new App::DocumentObjectExecReturn("No object linked");
}
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (!link->isDerivedFrom<Part::Feature>()) {
return new App::DocumentObjectExecReturn("Linked object is not a Part object");
}
TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape().getShape();

View File

@@ -81,7 +81,7 @@ App::DocumentObjectExecReturn* FeatureViewSpreadsheet::execute(void)
if (!link) {
return new App::DocumentObjectExecReturn("No spreadsheet linked");
}
if (!link->getTypeId().isDerivedFrom(Spreadsheet::Sheet::getClassTypeId())) {
if (!link->isDerivedFrom<Spreadsheet::Sheet>()) {
return new App::DocumentObjectExecReturn("The linked object is not a spreadsheet");
}
if ((scellstart.empty()) || (scellend.empty())) {

View File

@@ -146,7 +146,7 @@ private:
if (PyObject_TypeCheck(item, &(App::DocumentObjectPy::Type))) {
App::DocumentObject* obj =
static_cast<App::DocumentObjectPy*>(item)->getDocumentObjectPtr();
if (obj->getTypeId().isDerivedFrom(Drawing::FeaturePage::getClassTypeId())) {
if (obj->isDerivedFrom<Drawing::FeaturePage>()) {
Base::FileInfo fi_out(EncodedName.c_str());
Base::ofstream str_out(fi_out, std::ios::out | std::ios::binary);
if (!str_out) {
@@ -176,16 +176,14 @@ private:
for (std::vector<App::DocumentObject*>::const_iterator it = views.begin();
it != views.end();
++it) {
if ((*it)->getTypeId().isDerivedFrom(
Drawing::FeatureViewPart::getClassTypeId())) {
if ((*it)->isDerivedFrom<Drawing::FeatureViewPart>()) {
Drawing::FeatureViewPart* view =
static_cast<Drawing::FeatureViewPart*>(*it);
App::DocumentObject* link = view->Source.getValue();
if (!link) {
throw Py::ValueError("No object linked");
}
if (!link->getTypeId().isDerivedFrom(
Part::Feature::getClassTypeId())) {
if (!link->isDerivedFrom<Part::Feature>()) {
throw Py::TypeError("Linked object is not a Part object");
}
TopoDS_Shape shape =

View File

@@ -104,7 +104,7 @@ void ViewProviderDrawingPage::hide(void)
void ViewProviderDrawingPage::updateData(const App::Property* prop)
{
Gui::ViewProviderDocumentObjectGroup::updateData(prop);
if (prop->getTypeId() == App::PropertyFileIncluded::getClassTypeId()) {
if (prop->is<App::PropertyFileIncluded>()) {
if (std::string(getPageObject()->PageResult.getValue()) != "") {
if (view) {
view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));

View File

@@ -69,7 +69,7 @@ void ViewProviderDrawingView::show(void)
if (!obj || obj->isRestoring()) {
return;
}
if (obj->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
if (obj->isDerivedFrom<Drawing::FeatureView>()) {
// The 'Visible' property is marked as 'Output'. To update the drawing on recompute
// the parent page object is touched.
static_cast<Drawing::FeatureView*>(obj)->Visible.setValue(true);
@@ -88,7 +88,7 @@ void ViewProviderDrawingView::hide(void)
if (!obj || obj->isRestoring()) {
return;
}
if (obj->getTypeId().isDerivedFrom(Drawing::FeatureView::getClassTypeId())) {
if (obj->isDerivedFrom<Drawing::FeatureView>()) {
// The 'Visible' property is marked as 'Output'. To update the drawing on recompute
// the parent page object is touched.
static_cast<Drawing::FeatureView*>(obj)->Visible.setValue(false);
@@ -172,7 +172,7 @@ void ViewProviderDrawingClip::show(void)
if (!obj || obj->isRestoring()) {
return;
}
if (obj->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) {
if (obj->isDerivedFrom<Drawing::FeatureClip>()) {
// The 'Visible' property is marked as 'Output'. To update the drawing on recompute
// the parent page object is touched.
static_cast<Drawing::FeatureClip*>(obj)->Visible.setValue(true);
@@ -191,7 +191,7 @@ void ViewProviderDrawingClip::hide(void)
if (!obj || obj->isRestoring()) {
return;
}
if (obj->getTypeId().isDerivedFrom(Drawing::FeatureClip::getClassTypeId())) {
if (obj->isDerivedFrom<Drawing::FeatureClip>()) {
// The 'Visible' property is marked as 'Output'. To update the drawing on recompute
// the parent page object is touched.
static_cast<Drawing::FeatureClip*>(obj)->Visible.setValue(false);