From a1c5767643ed76244aad63dde790dc117b953044 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sun, 19 Jan 2025 01:49:04 +0100 Subject: [PATCH] Mod: Use new addObject(...) using regex --- src/Gui/CommandLink.cpp | 2 +- src/Mod/CAM/App/Area.cpp | 3 +-- src/Mod/Drawing/Gui/TaskOrthoViews.cpp | 3 +-- src/Mod/Fem/App/AppFemPy.cpp | 9 +++---- src/Mod/Import/App/ImportOCAF.cpp | 10 +++---- src/Mod/Import/App/ImportOCAF2.cpp | 20 ++++++-------- src/Mod/Import/App/ImportOCAFAssembly.cpp | 2 +- src/Mod/Import/App/dxf/ImpExpDxf.cpp | 3 +-- src/Mod/Mesh/App/AppMeshPy.cpp | 3 +-- src/Mod/Mesh/App/Importer.cpp | 3 +-- src/Mod/Mesh/Gui/Command.cpp | 9 +++---- src/Mod/Mesh/Gui/ViewProvider.cpp | 2 +- src/Mod/Mesh/Gui/ViewProviderCurvature.cpp | 3 +-- src/Mod/MeshPart/Gui/Command.cpp | 2 +- src/Mod/MeshPart/Gui/CrossSections.cpp | 3 +-- src/Mod/MeshPart/Gui/CurveOnMesh.cpp | 5 ++-- src/Mod/MeshPart/Gui/Tessellation.cpp | 2 +- src/Mod/Part/App/AppPartPy.cpp | 2 +- src/Mod/Part/App/ImportIges.cpp | 7 +++-- src/Mod/Part/App/ImportStep.cpp | 4 +-- src/Mod/Part/App/PartFeature.cpp | 2 +- src/Mod/Part/Gui/CrossSections.cpp | 3 +-- src/Mod/Part/Gui/DlgProjectionOnSurface.cpp | 3 +-- src/Mod/Part/Gui/SectionCutting.cpp | 6 ++--- src/Mod/PartDesign/App/Body.cpp | 2 +- src/Mod/Points/App/AppPointsPy.cpp | 3 +-- src/Mod/Points/Gui/Command.cpp | 6 ++--- src/Mod/ReverseEngineering/Gui/Command.cpp | 6 ++--- src/Mod/Sandbox/App/DocumentThread.cpp | 2 +- src/Mod/Sandbox/Gui/Command.cpp | 8 +++--- src/Mod/TechDraw/Gui/Command.cpp | 12 +++------ src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp | 2 +- tests/src/Mod/Assembly/App/AssemblyObject.cpp | 3 +-- tests/src/Mod/Measure/App/MeasureDistance.cpp | 7 +++-- tests/src/Mod/Mesh/App/Exporter.cpp | 6 ++--- tests/src/Mod/Part/App/AttachExtension.cpp | 8 +++--- tests/src/Mod/Part/App/FeatureChamfer.cpp | 4 +-- tests/src/Mod/Part/App/FeatureCompound.cpp | 2 +- tests/src/Mod/Part/App/FeatureExtrusion.cpp | 6 ++--- tests/src/Mod/Part/App/FeatureFillet.cpp | 4 +-- tests/src/Mod/Part/App/FeatureMirroring.cpp | 4 +-- tests/src/Mod/Part/App/FeatureOffset.cpp | 8 +++--- tests/src/Mod/Part/App/FeaturePartBoolean.cpp | 2 +- tests/src/Mod/Part/App/FeaturePartCommon.cpp | 2 +- tests/src/Mod/Part/App/FeaturePartCut.cpp | 2 +- tests/src/Mod/Part/App/FeaturePartFuse.cpp | 8 +++--- tests/src/Mod/Part/App/FeatureRevolution.cpp | 4 +-- tests/src/Mod/Part/App/FuzzyBoolean.cpp | 6 ++--- tests/src/Mod/Part/App/PartFeature.cpp | 2 +- tests/src/Mod/Part/App/PartFeatures.cpp | 26 +++++++++---------- tests/src/Mod/Part/App/PartTestHelpers.cpp | 2 +- tests/src/Mod/Part/App/PropertyTopoShape.cpp | 2 +- .../Part/App/TopoShapeMakeElementRefine.cpp | 2 +- tests/src/Mod/PartDesign/App/DatumPlane.cpp | 4 +-- tests/src/Mod/PartDesign/App/Pad.cpp | 7 +++-- tests/src/Mod/PartDesign/App/ShapeBinder.cpp | 10 +++---- tests/src/Mod/Sketcher/App/SketchObject.cpp | 1 + 57 files changed, 125 insertions(+), 159 deletions(-) diff --git a/src/Gui/CommandLink.cpp b/src/Gui/CommandLink.cpp index 875f5b093b..eddb113e8a 100644 --- a/src/Gui/CommandLink.cpp +++ b/src/Gui/CommandLink.cpp @@ -413,7 +413,7 @@ static void linkConvert(bool unlink) { continue; }else{ auto name = doc->getUniqueObjectName("Link"); - auto link = static_cast(doc->addObject("App::Link",name.c_str())); + auto link = doc->addObject(name.c_str()); if(!link) FC_THROWM(Base::RuntimeError,"Failed to create link"); link->setLink(-1,obj); diff --git a/src/Mod/CAM/App/Area.cpp b/src/Mod/CAM/App/Area.cpp index bb1969a63f..46c53279e4 100644 --- a/src/Mod/CAM/App/Area.cpp +++ b/src/Mod/CAM/App/Area.cpp @@ -1452,8 +1452,7 @@ void Area::showShape(const TopoDS_Shape& shape, const char* name, const char* fm va_end(args); name = buf; } - Part::Feature* pcFeature = - static_cast(pcDoc->addObject("Part::Feature", name)); + Part::Feature* pcFeature = pcDoc->addObject(name); pcFeature->Shape.setValue(shape); } } diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp index 140ffc4218..98d8a2897f 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp @@ -150,8 +150,7 @@ orthoview::orthoview(App::Document* parent, cy = partbox->GetCenter().y; cz = partbox->GetCenter().z; - this_view = static_cast( - parent_doc->addObject("Drawing::FeatureViewPart", myname.c_str())); + this_view = parent_doc->addObject(myname.c_str()); static_cast(page)->addObject(this_view); this_view->Source.setValue(part); diff --git a/src/Mod/Fem/App/AppFemPy.cpp b/src/Mod/Fem/App/AppFemPy.cpp index 37da55d573..232fe7a62d 100644 --- a/src/Mod/Fem/App/AppFemPy.cpp +++ b/src/Mod/Fem/App/AppFemPy.cpp @@ -123,8 +123,7 @@ private: Base::FileInfo file(EncodedName.c_str()); // create new document and add Import feature App::Document* pcDoc = App::GetApplication().newDocument(); - FemMeshObject* pcFeature = static_cast( - pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); + FemMeshObject* pcFeature = pcDoc->addObject(file.fileNamePure().c_str()); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.release()); pcFeature->purgeTouched(); @@ -160,8 +159,7 @@ private: std::unique_ptr mesh(new FemMesh); mesh->read(EncodedName.c_str()); - FemMeshObject* pcFeature = static_cast( - pcDoc->addObject("Fem::FemMeshObject", file.fileNamePure().c_str())); + FemMeshObject* pcFeature = pcDoc->addObject(file.fileNamePure().c_str()); pcFeature->Label.setValue(file.fileNamePure().c_str()); pcFeature->FemMesh.setValuePtr(mesh.release()); pcFeature->purgeTouched(); @@ -321,8 +319,7 @@ private: } FemMeshPy* pShape = static_cast(pcObj); - Fem::FemMeshObject* pcFeature = - static_cast(pcDoc->addObject("Fem::FemMeshObject", name)); + Fem::FemMeshObject* pcFeature = pcDoc->addObject(name); // copy the data pcFeature->FemMesh.setValue(*(pShape->getFemMeshPtr())); pcDoc->recompute(); diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index b684ba8a68..4db7eeba24 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -250,7 +250,7 @@ void ImportOCAF::loadShapes(const TDF_Label& label, if (!localValue.empty()) { if (aShapeTool->IsAssembly(label)) { App::Part* pcPart = nullptr; - pcPart = static_cast(doc->addObject("App::Part", asm_name.c_str())); + pcPart = doc->addObject(asm_name.c_str()); pcPart->Label.setValue(asm_name); pcPart->addObjects(localValue); @@ -326,7 +326,7 @@ void ImportOCAF::createShape(const TDF_Label& label, // Ok we got a Compound which is computed // Just need to add it to a Part::Feature and push it to lValue if (!comp.IsNull() && (ctSolids || ctShells || ctEdges || ctVertices)) { - Part::Feature* part = static_cast(doc->addObject("Part::Feature")); + Part::Feature* part = doc->addObject(); // Let's allocate the relative placement of the Compound from the STEP file tryPlacementFromLoc(part, loc); if (!loc.IsIdentity()) { @@ -352,7 +352,7 @@ void ImportOCAF::createShape(const TDF_Label& label, } if (!localValue.empty() && !mergeShape) { - pcPart = static_cast(doc->addObject("App::Part", name.c_str())); + pcPart = doc->addObject(name.c_str()); pcPart->Label.setValue(name); // localValue contain the objects that must added to the local Part @@ -376,7 +376,7 @@ void ImportOCAF::createShape(const TopoDS_Shape& aShape, const std::string& name, std::vector& lvalue) { - Part::Feature* part = static_cast(doc->addObject("Part::Feature")); + Part::Feature* part = doc->addObject(); if (!loc.IsIdentity()) { part->Shape.setValue(aShape.Moved(loc)); @@ -497,7 +497,7 @@ void ImportXCAF::loadShapes() void ImportXCAF::createShape(const TopoDS_Shape& shape, bool perface, bool setname) const { Part::Feature* part; - part = static_cast(doc->addObject("Part::Feature", default_name.c_str())); + part = doc->addObject(default_name.c_str()); part->Label.setValue(default_name); part->Shape.setValue(shape); std::map::const_iterator jt; diff --git a/src/Mod/Import/App/ImportOCAF2.cpp b/src/Mod/Import/App/ImportOCAF2.cpp index 1cabfbb9f6..feb927adfa 100644 --- a/src/Mod/Import/App/ImportOCAF2.cpp +++ b/src/Mod/Import/App/ImportOCAF2.cpp @@ -269,8 +269,7 @@ ImportOCAF2::expandShape(App::Document* doc, TDF_Label label, const TopoDS_Shape if (objs.empty()) { return nullptr; } - auto compound = - static_cast(doc->addObject("Part::Compound2", "Compound")); + auto compound = doc->addObject("Compound"); compound->Links.setValues(objs); setPlacement(&compound->Placement, shape); return compound; @@ -382,8 +381,7 @@ bool ImportOCAF2::createObject(App::Document* doc, assert(feature); } else { - feature = static_cast( - doc->addObject("Part::Feature", tshape.shapeName().c_str())); + feature = doc->addObject(tshape.shapeName().c_str()); feature->Shape.setValue(shape); } applyFaceColors(feature, {info.faceColor}); @@ -479,10 +477,10 @@ bool ImportOCAF2::createGroup(App::Document* doc, myCollapsedObjects.emplace(info.obj, info.propPlacement); return true; } - auto group = static_cast(doc->addObject("App::LinkGroup", "LinkGroup")); + auto group = doc->addObject("LinkGroup"); for (auto& child : children) { if (child->getDocument() != doc) { - auto link = static_cast(doc->addObject("App::Link", "Link")); + auto link = doc->addObject("Link"); link->Label.setValue(child->Label.getValue()); link->setLink(-1, child); auto pla = Base::freecad_dynamic_cast( @@ -566,8 +564,7 @@ App::DocumentObject* ImportOCAF2::loadShapes() } if (options.merge && ret && !ret->isDerivedFrom()) { auto shape = Part::Feature::getTopoShape(ret); - auto feature = - static_cast(pDocument->addObject("Part::Feature", "Feature")); + auto feature = pDocument->addObject("Feature"); auto name = Tools::labelName(pDoc->Main()); feature->Label.setValue(name.empty() ? default_name.c_str() : name.c_str()); feature->Shape.setValue(shape); @@ -701,8 +698,7 @@ App::DocumentObject* ImportOCAF2::loadShape(App::Document* doc, auto name = getLabelName(label); if (info.faceColor != it->second.faceColor || info.edgeColor != it->second.edgeColor || (!name.empty() && !info.baseName.empty() && name != info.baseName)) { - auto compound = - static_cast(doc->addObject("Part::Compound2", "Compound")); + auto compound = doc->addObject("Compound"); compound->Links.setValue(info.obj); info.propPlacement = &compound->Placement; if (info.faceColor != it->second.faceColor) { @@ -719,7 +715,7 @@ App::DocumentObject* ImportOCAF2::loadShape(App::Document* doc, return info.obj; } - auto link = static_cast(doc->addObject("App::Link", "Link")); + auto link = doc->addObject("Link"); link->setLink(-1, info.obj); setPlacement(&link->Placement, shape); info.obj = link; @@ -826,7 +822,7 @@ bool ImportOCAF2::createAssembly(App::Document* _doc, visibilities[i] = true; // Okay, we are creating a link array - auto link = static_cast(doc->addObject("App::Link", "Link")); + auto link = doc->addObject("Link"); link->setLink(-1, child); link->ShowElement.setValue(false); link->ElementCount.setValue(childInfo.plas.size()); diff --git a/src/Mod/Import/App/ImportOCAFAssembly.cpp b/src/Mod/Import/App/ImportOCAFAssembly.cpp index 2778f00a77..29ecb1d54e 100644 --- a/src/Mod/Import/App/ImportOCAFAssembly.cpp +++ b/src/Mod/Import/App/ImportOCAFAssembly.cpp @@ -241,7 +241,7 @@ void ImportOCAFAssembly::createShape(const TopoDS_Shape& aShape, const TopLoc_Location& loc, const std::string& name) { - Part::Feature* part = static_cast(doc->addObject("Part::Feature")); + Part::Feature* part = doc->addObject(); if (!loc.IsIdentity()) { part->Shape.setValue(aShape.Moved(loc)); } diff --git a/src/Mod/Import/App/dxf/ImpExpDxf.cpp b/src/Mod/Import/App/dxf/ImpExpDxf.cpp index a7284f54b1..c51c1b620a 100644 --- a/src/Mod/Import/App/dxf/ImpExpDxf.cpp +++ b/src/Mod/Import/App/dxf/ImpExpDxf.cpp @@ -736,8 +736,7 @@ std::string ImpExpDxfRead::Deformat(const char* text) void ImpExpDxfRead::DrawingEntityCollector::AddObject(const TopoDS_Shape& shape, const char* nameBase) { - auto pcFeature = - dynamic_cast(Reader.document->addObject("Part::Feature", nameBase)); + auto pcFeature = Reader.document->addObject(nameBase); pcFeature->Shape.setValue(shape); Reader.MoveToLayer(pcFeature); Reader.ApplyGuiStyles(pcFeature); diff --git a/src/Mod/Mesh/App/AppMeshPy.cpp b/src/Mod/Mesh/App/AppMeshPy.cpp index cfcbf3e0ef..0bf62df25a 100644 --- a/src/Mod/Mesh/App/AppMeshPy.cpp +++ b/src/Mod/Mesh/App/AppMeshPy.cpp @@ -303,8 +303,7 @@ private: pcDoc = App::GetApplication().newDocument(); } MeshPy* pMesh = static_cast(pcObj); - Mesh::Feature* pcFeature = - static_cast(pcDoc->addObject("Mesh::Feature", name)); + Mesh::Feature* pcFeature = pcDoc->addObject(name); Mesh::MeshObject* mo = pMesh->getMeshObjectPtr(); if (!mo) { throw Py::Exception(PyExc_ReferenceError, "object doesn't reference a valid mesh"); diff --git a/src/Mod/Mesh/App/Importer.cpp b/src/Mod/Mesh/App/Importer.cpp index 097cca3d9c..647a8fd116 100644 --- a/src/Mod/Mesh/App/Importer.cpp +++ b/src/Mod/Mesh/App/Importer.cpp @@ -119,8 +119,7 @@ void Importer::createMeshFromSegments(const std::string& name, Feature* Importer::createMesh(const std::string& name, MeshObject& mesh) { - Mesh::Feature* pcFeature = - static_cast(document->addObject("Mesh::Feature", name.c_str())); + Mesh::Feature* pcFeature = document->addObject(name.c_str()); pcFeature->Label.setValue(name); pcFeature->Mesh.swapMesh(mesh); return pcFeature; diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index 595bc84f33..970c21f411 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -503,8 +503,7 @@ void CmdMeshFromGeometry::activated(int) } // create a mesh feature and assign the mesh - Mesh::Feature* mf = - static_cast(doc->addObject("Mesh::Feature", "Mesh")); + Mesh::Feature* mf = doc->addObject("Mesh"); mf->Mesh.setValue(mesh.getKernel()); } } @@ -1703,8 +1702,7 @@ void CmdMeshMerge::activated(int) } openCommand(QT_TRANSLATE_NOOP("Command", "Mesh merge")); - Mesh::Feature* pcFeature = - static_cast(pcDoc->addObject("Mesh::Feature", "Mesh")); + Mesh::Feature* pcFeature = pcDoc->addObject("Mesh"); Mesh::MeshObject* newMesh = pcFeature->Mesh.startEditing(); std::vector objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); @@ -1759,8 +1757,7 @@ void CmdMeshSplitComponents::activated(int) std::unique_ptr kernel(mesh.meshFromSegment(comp)); kernel->setTransform(mesh.getTransform()); - Mesh::Feature* feature = - static_cast(pcDoc->addObject("Mesh::Feature", "Component")); + Mesh::Feature* feature = pcDoc->addObject("Component"); feature->Mesh.setValuePtr(kernel.release()); } } diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index 620f82d049..923073307a 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -975,7 +975,7 @@ public: Gui::Document* gui = mesh->getDocument(); App::Document* doc = gui->getDocument(); - auto cpy = static_cast(doc->addObject("Mesh::Feature")); + auto cpy = doc->addObject(); auto org = mesh->getObject(); cpy->Label.setValue(org->Label.getValue()); cpy->Mesh.setValue(org->Mesh.getValue()); diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp index b66239b902..7c3e18e4e4 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp @@ -480,8 +480,7 @@ public: } } if (!group) { - group = dynamic_cast( - doc->addObject("App::DocumentObjectGroup", internalname.c_str())); + group = doc->addObject(internalname.c_str()); } auto anno = dynamic_cast( diff --git a/src/Mod/MeshPart/Gui/Command.cpp b/src/Mod/MeshPart/Gui/Command.cpp index f2a85f05c1..a261d71a95 100644 --- a/src/Mod/MeshPart/Gui/Command.cpp +++ b/src/Mod/MeshPart/Gui/Command.cpp @@ -159,7 +159,7 @@ void CmdMeshPartTrimByPlane::activated(int) copy.trimByPlane(plnBase, -plnNormal); App::Document* doc = it->getDocument(); - Mesh::Feature* fea = static_cast(doc->addObject("Mesh::Feature")); + Mesh::Feature* fea = doc->addObject(); fea->Label.setValue(it->Label.getValue()); Mesh::MeshObject* feamesh = fea->Mesh.startEditing(); feamesh->swap(copy); diff --git a/src/Mod/MeshPart/Gui/CrossSections.cpp b/src/Mod/MeshPart/Gui/CrossSections.cpp index 5ecd5524a5..3058d443a4 100644 --- a/src/Mod/MeshPart/Gui/CrossSections.cpp +++ b/src/Mod/MeshPart/Gui/CrossSections.cpp @@ -327,8 +327,7 @@ void CrossSections::apply() App::Document* doc = it->getDocument(); std::string s = it->getNameInDocument(); s += "_cs"; - Part::Feature* section = - static_cast(doc->addObject("Part::Feature", s.c_str())); + Part::Feature* section = doc->addObject(s.c_str()); section->Shape.setValue(comp); section->purgeTouched(); } diff --git a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp index cdc22b02b9..445b21a37a 100644 --- a/src/Mod/MeshPart/Gui/CurveOnMesh.cpp +++ b/src/Mod/MeshPart/Gui/CurveOnMesh.cpp @@ -533,7 +533,7 @@ void CurveOnMeshHandler::displaySpline(const Handle(Geom_BSplineCurve) & spline) Gui::View3DInventorViewer* view3d = d_ptr->viewer->getViewer(); App::Document* doc = view3d->getDocument()->getDocument(); doc->openTransaction("Add spline"); - Part::Feature* part = static_cast(doc->addObject("Part::Spline", "Spline")); + Part::Feature* part = doc->addObject("Spline"); part->Shape.setValue(edge); doc->commitTransaction(); } @@ -562,8 +562,7 @@ void CurveOnMeshHandler::displayPolyline(const TopoDS_Wire& wire) Gui::View3DInventorViewer* view3d = d_ptr->viewer->getViewer(); App::Document* doc = view3d->getDocument()->getDocument(); doc->openTransaction("Add polyline"); - Part::Feature* part = - static_cast(doc->addObject("Part::Feature", "Polyline")); + Part::Feature* part = doc->addObject("Polyline"); part->Shape.setValue(wire); doc->commitTransaction(); } diff --git a/src/Mod/MeshPart/Gui/Tessellation.cpp b/src/Mod/MeshPart/Gui/Tessellation.cpp index 875f98433c..d885c7897e 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.cpp +++ b/src/Mod/MeshPart/Gui/Tessellation.cpp @@ -655,7 +655,7 @@ bool Mesh2ShapeGmsh::loadOutput() stlIn.close(); kernel.harmonizeNormals(); - auto fea = static_cast(doc->addObject("Mesh::Feature", "Mesh")); + auto fea = doc->addObject("Mesh"); fea->Label.setValue(d->label); fea->Mesh.setValue(kernel.getKernel()); stl.deleteFile(); diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index ae1a188980..c14aa38d89 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -866,7 +866,7 @@ private: } else { throw Py::TypeError("Expects argument of type DocumentObject, Shape, or Geometry"); } - Part::Feature *pcFeature = static_cast(pcDoc->addObject("Part::Feature", name)); + Part::Feature *pcFeature = pcDoc->addObject(name); // copy the data pcFeature->Shape.setValue(shape); pcFeature->purgeTouched(); diff --git a/src/Mod/Part/App/ImportIges.cpp b/src/Mod/Part/App/ImportIges.cpp index c299b0384f..272a8173ee 100644 --- a/src/Mod/Part/App/ImportIges.cpp +++ b/src/Mod/Part/App/ImportIges.cpp @@ -103,8 +103,8 @@ int Part::ImportIgesParts(App::Document *pcDoc, const char* FileName) if (aShape.ShapeType() == TopAbs_SOLID || aShape.ShapeType() == TopAbs_COMPOUND || aShape.ShapeType() == TopAbs_SHELL) { - App::DocumentObject* obj = pcDoc->addObject("Part::Feature", aName.c_str()); - static_cast(obj)->Shape.setValue(aShape); + auto* obj = pcDoc->addObject(aName.c_str()); + obj->Shape.setValue(aShape); } else { builder.Add(comp, aShape); @@ -114,8 +114,7 @@ int Part::ImportIgesParts(App::Document *pcDoc, const char* FileName) } if (!emptyComp) { std::string name = fi.fileNamePure(); - Part::Feature *pcFeature = static_cast(pcDoc->addObject - ("Part::Feature", name.c_str())); + auto* pcFeature = pcDoc->addObject(name.c_str()); pcFeature->Shape.setValue(comp); } } diff --git a/src/Mod/Part/App/ImportStep.cpp b/src/Mod/Part/App/ImportStep.cpp index 4c13aaf2af..8c26ab469e 100644 --- a/src/Mod/Part/App/ImportStep.cpp +++ b/src/Mod/Part/App/ImportStep.cpp @@ -132,7 +132,7 @@ int Part::ImportStepParts(App::Document *pcDoc, const char* Name) //} Part::Feature *pcFeature; - pcFeature = static_cast(pcDoc->addObject("Part::Feature", name.c_str())); + pcFeature = pcDoc->addObject(name.c_str()); pcFeature->Shape.setValue(aSolid); // This is a trick to access the GUI via Python and set the color property @@ -167,7 +167,7 @@ int Part::ImportStepParts(App::Document *pcDoc, const char* Name) // name += ws->Model()->StringLabel(ent)->ToCString(); //} - Part::Feature *pcFeature = static_cast(pcDoc->addObject("Part::Feature", name.c_str())); + Part::Feature *pcFeature = pcDoc->addObject(name.c_str()); pcFeature->Shape.setValue(aShell); } diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index 147f4c362b..fdb2c3fbd4 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -1575,7 +1575,7 @@ Feature* Feature::create(const TopoShape& shape, const char* name, App::Document document = App::GetApplication().newDocument(); } } - auto res = static_cast(document->addObject("Part::Feature", name)); + auto res = document->addObject(name); res->Shape.setValue(shape); res->purgeTouched(); return res; diff --git a/src/Mod/Part/Gui/CrossSections.cpp b/src/Mod/Part/Gui/CrossSections.cpp index 5e34e4f09d..d859f83e85 100644 --- a/src/Mod/Part/Gui/CrossSections.cpp +++ b/src/Mod/Part/Gui/CrossSections.cpp @@ -260,8 +260,7 @@ void CrossSections::apply() App::Document* doc = (*it)->getDocument(); std::string s = (*it)->getNameInDocument(); s += "_cs"; - Part::Feature* section = static_cast - (doc->addObject("Part::Feature",s.c_str())); + auto* section = doc->addObject(s.c_str()); section->Shape.setValue(comp); section->purgeTouched(); } diff --git a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp index bc7448a2d7..1bf794f2b6 100644 --- a/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp +++ b/src/Mod/Part/Gui/DlgProjectionOnSurface.cpp @@ -165,8 +165,7 @@ DlgProjectionOnSurface::DlgProjectionOnSurface(QWidget* parent) } this->attachDocument(m_partDocument); m_partDocument->openTransaction("Project on surface"); - m_projectionObject = dynamic_cast( - m_partDocument->addObject("Part::Feature", "Projection Object")); + m_projectionObject = m_partDocument->addObject("Projection Object"); if (!m_projectionObject) { throw Base::ValueError(QString(tr("Can not create a projection object!!!")).toUtf8()); } diff --git a/src/Mod/Part/Gui/SectionCutting.cpp b/src/Mod/Part/Gui/SectionCutting.cpp index fbfa8b66c2..bf7d5c2e12 100644 --- a/src/Mod/Part/Gui/SectionCutting.cpp +++ b/src/Mod/Part/Gui/SectionCutting.cpp @@ -606,7 +606,7 @@ void SectionCut::restoreVisibility() Part::Box* SectionCut::createBox(const char* name, const Base::Vector3f& size) // NOLINT { // create a box - auto pcBox = dynamic_cast(doc->addObject("Part::Box", name)); + auto pcBox = doc->addObject(name); if (!pcBox) { throw Base::RuntimeError(std::string("SectionCut error: ") + std::string(name) + std::string(" could not be added\n")); @@ -785,7 +785,7 @@ Part::Box* SectionCut::createZBox(const Base::Vector3f& pos, const Base::Vector3 Part::Cut* SectionCut::createCut(const char* name) { - auto pcCut = dynamic_cast(doc->addObject("Part::Cut", name)); + auto pcCut = doc->addObject(name); if (!pcCut) { throw Base::RuntimeError(std::string("SectionCut error: ") + std::string(name) + std::string(" could not be added\n")); @@ -1004,7 +1004,7 @@ std::vector createLinks(App::Document* doc, const std::vec } newName += "_CutLink"; - auto pcLink = dynamic_cast(doc->addObject("App::Link", newName.c_str())); + auto pcLink = doc->addObject(newName.c_str()); if (!pcLink) { throw Base::RuntimeError("'App::Link' could not be added"); } diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index ab032aa702..1d9dba2a8f 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -442,7 +442,7 @@ void Body::onChanged(const App::Property* prop) { if (BaseFeature.getValue()) { //setup the FeatureBase if needed if (!first || !first->isDerivedFrom()) { - bf = static_cast(getDocument()->addObject("PartDesign::FeatureBase", "BaseFeature")); + bf = getDocument()->addObject("BaseFeature"); insertObject(bf, first, false); if (!Tip.getValue()) diff --git a/src/Mod/Points/App/AppPointsPy.cpp b/src/Mod/Points/App/AppPointsPy.cpp index e5f1d49e1e..677c3059c4 100644 --- a/src/Mod/Points/App/AppPointsPy.cpp +++ b/src/Mod/Points/App/AppPointsPy.cpp @@ -414,8 +414,7 @@ private: pcDoc = App::GetApplication().newDocument(); } PointsPy* pPoints = static_cast(pcObj); - Points::Feature* pcFeature = - static_cast(pcDoc->addObject("Points::Feature", name)); + Points::Feature* pcFeature = pcDoc->addObject(name); // copy the data pcFeature->Points.setValue(*(pPoints->getPointKernelPtr())); return Py::asObject(pcFeature->getPyObject()); diff --git a/src/Mod/Points/Gui/Command.cpp b/src/Mod/Points/Gui/Command.cpp index b84839a640..03d52f9b45 100644 --- a/src/Mod/Points/Gui/Command.cpp +++ b/src/Mod/Points/Gui/Command.cpp @@ -386,8 +386,7 @@ void CmdPointsMerge::activated(int iMsg) App::Document* doc = App::GetApplication().getActiveDocument(); doc->openTransaction("Merge point clouds"); - Points::Feature* pts = - static_cast(doc->addObject("Points::Feature", "Merged Points")); + Points::Feature* pts = doc->addObject("Merged Points"); Points::PointKernel* kernel = pts->Points.startEditing(); std::vector docObj = @@ -455,8 +454,7 @@ void CmdPointsStructure::activated(int iMsg) for (auto it : docObj) { std::string name = it->Label.getValue(); name += " (Structured)"; - Points::Structured* output = - static_cast(doc->addObject("Points::Structured", name.c_str())); + Points::Structured* output = doc->addObject(name.c_str()); output->Label.setValue(name); // Already sorted, so just make a copy diff --git a/src/Mod/ReverseEngineering/Gui/Command.cpp b/src/Mod/ReverseEngineering/Gui/Command.cpp index acfbbc2a1a..ef03de7103 100644 --- a/src/Mod/ReverseEngineering/Gui/Command.cpp +++ b/src/Mod/ReverseEngineering/Gui/Command.cpp @@ -576,13 +576,11 @@ void CmdMeshBoundary::activated(int) } if (!shape.IsNull()) { - Part::Feature* shapeFea = - static_cast(document->addObject("Part::Feature", "Face from mesh")); + Part::Feature* shapeFea = document->addObject("Face from mesh"); shapeFea->Shape.setValue(shape); } else { - Part::Feature* shapeFea = - static_cast(document->addObject("Part::Feature", "Wire from mesh")); + Part::Feature* shapeFea = document->addObject("Wire from mesh"); shapeFea->Shape.setValue(compound); } } diff --git a/src/Mod/Sandbox/App/DocumentThread.cpp b/src/Mod/Sandbox/App/DocumentThread.cpp index b1a68a867f..bd11674f01 100644 --- a/src/Mod/Sandbox/App/DocumentThread.cpp +++ b/src/Mod/Sandbox/App/DocumentThread.cpp @@ -218,7 +218,7 @@ void DocumentTestThread::run() Base::Console().Message("DocumentTestThread::run()\n"); App::Document* doc = App::GetApplication().getActiveDocument(); DocumentProtector dp(doc); - SandboxObject* obj = static_cast(dp.addObject("Sandbox::SandboxObject")); + SandboxObject* obj = dp.addObject(); DocumentObjectProtector op(obj); App::PropertyString Name;Name.setValue("MyLabel"); diff --git a/src/Mod/Sandbox/Gui/Command.cpp b/src/Mod/Sandbox/Gui/Command.cpp index 5709af9019..d7891830ce 100644 --- a/src/Mod/Sandbox/Gui/Command.cpp +++ b/src/Mod/Sandbox/Gui/Command.cpp @@ -593,7 +593,7 @@ void CmdSandboxMeshLoader::activated(int) Base::Reference data = thread.getMesh(); App::Document* doc = App::GetApplication().getActiveDocument(); - Mesh::Feature* mesh = static_cast(doc->addObject("Mesh::Feature","Mesh")); + Mesh::Feature* mesh = doc->addObject("Mesh"); mesh->Mesh.setValuePtr((Mesh::MeshObject*)data); mesh->purgeTouched(); } @@ -650,7 +650,7 @@ void CmdSandboxMeshLoaderBoost::activated(int) fi.wait(); // wait for it to be finished App::Document* doc = App::GetApplication().getActiveDocument(); - Mesh::Feature* mesh = static_cast(doc->addObject("Mesh::Feature","Mesh")); + Mesh::Feature* mesh = doc->addObject("Mesh"); mesh->Mesh.setValuePtr((Mesh::MeshObject*)fi.get()); mesh->purgeTouched(); } @@ -704,7 +704,7 @@ void CmdSandboxMeshLoaderFuture::activated(int) App::Document* doc = App::GetApplication().getActiveDocument(); for (QFuture< Base::Reference >::const_iterator it = future.begin(); it != future.end(); ++it) { - Mesh::Feature* mesh = static_cast(doc->addObject("Mesh::Feature","Mesh")); + Mesh::Feature* mesh = doc->addObject("Mesh"); mesh->Mesh.setValuePtr((Mesh::MeshObject*)(*it)); mesh->purgeTouched(); } @@ -1368,7 +1368,7 @@ void CmdMengerSponge::activated(int) kernel.RebuildNeighbours(); App::Document* doc = App::GetApplication().newDocument(); - Mesh::Feature* feature = static_cast(doc->addObject("Mesh::Feature","MengerSponge")); + Mesh::Feature* feature = doc->addObject("MengerSponge"); feature->Mesh.setValue(*mesh); feature->purgeTouched(); } diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index 5f540a18ae..02d1551960 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -124,15 +124,13 @@ void CmdTechDrawPageDefault::activated(int iMsg) Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page")); - auto page = dynamic_cast - (getDocument()->addObject("TechDraw::DrawPage", "Page")); + auto page = getDocument()->addObject("Page"); if (!page) { throw Base::TypeError("CmdTechDrawPageDefault - page not created"); } page->translateLabel("DrawPage", "Page", page->getNameInDocument()); - auto svgTemplate = dynamic_cast - (getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template")); + auto svgTemplate = getDocument()->addObject("Template"); if (!svgTemplate) { throw Base::TypeError("CmdTechDrawPageDefault - template not created"); } @@ -195,15 +193,13 @@ void CmdTechDrawPageTemplate::activated(int iMsg) Gui::WaitCursor wc; openCommand(QT_TRANSLATE_NOOP("Command", "Drawing create page")); - auto page = dynamic_cast - (getDocument()->addObject("TechDraw::DrawPage", "Page")); + auto page = getDocument()->addObject("Page"); if (!page) { throw Base::TypeError("CmdTechDrawPageTemplate - page not created"); } page->translateLabel("DrawPage", "Page", page->getNameInDocument()); - auto svgTemplate = dynamic_cast - (getDocument()->addObject("TechDraw::DrawSVGTemplate", "Template")); + auto svgTemplate = getDocument()->addObject("Template"); if (!svgTemplate) { throw Base::TypeError("CmdTechDrawPageTemplate - template not created"); } diff --git a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp index a554abba31..316f0eefbf 100644 --- a/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp +++ b/src/Mod/TechDraw/Gui/TaskWeldingSymbol.cpp @@ -457,7 +457,7 @@ TechDraw::DrawWeldSymbol* TaskWeldingSymbol::createWeldingSymbol() { // Base::Console().Message("TWS::createWeldingSymbol()\n"); App::Document *doc = Application::Instance->activeDocument()->getDocument(); - auto weldSymbol = dynamic_cast(doc->addObject("TechDraw::DrawWeldSymbol", "WeldSymbol")); + auto weldSymbol = doc->addObject("WeldSymbol"); if (!weldSymbol) { throw Base::RuntimeError("TaskWeldingSymbol - new symbol object not found"); } diff --git a/tests/src/Mod/Assembly/App/AssemblyObject.cpp b/tests/src/Mod/Assembly/App/AssemblyObject.cpp index f3ac682166..27e59c68b2 100644 --- a/tests/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/tests/src/Mod/Assembly/App/AssemblyObject.cpp @@ -24,8 +24,7 @@ protected: { _docName = App::GetApplication().getUniqueDocumentName("test"); auto _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _assemblyObj = - static_cast(_doc->addObject("Assembly::AssemblyObject")); + _assemblyObj = _doc->addObject(); _jointGroupObj = static_cast( _assemblyObj->addObject("Assembly::JointGroup", "jointGroupTest")); } diff --git a/tests/src/Mod/Measure/App/MeasureDistance.cpp b/tests/src/Mod/Measure/App/MeasureDistance.cpp index 86aee30c5a..c88a6fd7d0 100644 --- a/tests/src/Mod/Measure/App/MeasureDistance.cpp +++ b/tests/src/Mod/Measure/App/MeasureDistance.cpp @@ -48,13 +48,12 @@ private: TEST_F(MeasureDistance, testCircleCircle) { App::Document* doc = getDocument(); - auto p1 = dynamic_cast(doc->addObject("Part::Feature", "Shape1")); + auto p1 = doc->addObject("Shape1"); p1->Shape.setValue(makeCircle(gp_Pnt(0.0, 0.0, 0.0))); - auto p2 = dynamic_cast(doc->addObject("Part::Feature", "Shape2")); + auto p2 = doc->addObject("Shape2"); p2->Shape.setValue(makeCircle(gp_Pnt(3.0, 4.0, 0.0))); - auto md = dynamic_cast( - doc->addObject("Measure::MeasureDistance", "Distance")); + auto md = doc->addObject("Distance"); md->Element1.setValue(p1, {"Edge1"}); md->Element2.setValue(p2, {"Edge1"}); diff --git a/tests/src/Mod/Mesh/App/Exporter.cpp b/tests/src/Mod/Mesh/App/Exporter.cpp index 07efa7d2cb..cb63eff7b1 100644 --- a/tests/src/Mod/Mesh/App/Exporter.cpp +++ b/tests/src/Mod/Mesh/App/Exporter.cpp @@ -22,11 +22,11 @@ protected: fileInfo.setFile(Base::FileInfo::getTempFileName() + ".stl"); const double value = 10.0; - cube1 = dynamic_cast(document->addObject("Mesh::Cube", "Cube1")); + cube1 = document->addObject("Cube1"); cube1->Length.setValue(value); cube1->Width.setValue(value); cube1->Height.setValue(value); - cube2 = dynamic_cast(document->addObject("Mesh::Cube", "Cube2")); + cube2 = document->addObject("Cube2"); cube2->Length.setValue(value); cube2->Width.setValue(value); cube2->Height.setValue(value); @@ -130,7 +130,7 @@ TEST_F(ExporterTest, TestMeshesInPart) // add extra scope because the file will be written when destroying the exporter { - auto part = dynamic_cast(getDocument()->addObject("App::Part", "Part")); + auto part = getDocument()->addObject("Part"); part->placement().setValue(plm); part->addObjects(getObjects()); Mesh::MergeExporter exporter(getFileName(), MeshCore::MeshIO::Format::STL); diff --git a/tests/src/Mod/Part/App/AttachExtension.cpp b/tests/src/Mod/Part/App/AttachExtension.cpp index 89afe01be1..65973b8f9b 100644 --- a/tests/src/Mod/Part/App/AttachExtension.cpp +++ b/tests/src/Mod/Part/App/AttachExtension.cpp @@ -38,8 +38,8 @@ private: TEST_F(AttachExtensionTest, testPlanePlane) { - auto plane1 = dynamic_cast(getDocument()->addObject("Part::Plane", "Plane1")); - auto plane2 = dynamic_cast(getDocument()->addObject("Part::Plane", "Plane2")); + auto plane1 = getDocument()->addObject("Plane1"); + auto plane2 = getDocument()->addObject("Plane2"); ASSERT_TRUE(plane1); ASSERT_TRUE(plane2); @@ -57,7 +57,7 @@ TEST_F(AttachExtensionTest, testPlanePlane) TEST_F(AttachExtensionTest, testAttacherEngineType) { - auto plane = dynamic_cast(getDocument()->addObject("Part::Plane", "Plane")); + auto plane = getDocument()->addObject("Plane"); EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEngine3D"); EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine 3D"); @@ -76,7 +76,7 @@ TEST_F(AttachExtensionTest, testAttacherEngineType) TEST_F(AttachExtensionTest, testAttacherTypeEngine) { - auto plane = dynamic_cast(getDocument()->addObject("Part::Plane", "Plane")); + auto plane = getDocument()->addObject("Plane"); EXPECT_STREQ(plane->AttacherType.getValue(), "Attacher::AttachEngine3D"); EXPECT_STREQ(plane->AttacherEngine.getValueAsString(), "Engine 3D"); diff --git a/tests/src/Mod/Part/App/FeatureChamfer.cpp b/tests/src/Mod/Part/App/FeatureChamfer.cpp index 630d8797ee..963153c57b 100644 --- a/tests/src/Mod/Part/App/FeatureChamfer.cpp +++ b/tests/src/Mod/Part/App/FeatureChamfer.cpp @@ -28,11 +28,11 @@ protected: _boxes[1]->Length.setValue(1); _boxes[1]->Width.setValue(2); _boxes[1]->Height.setValue(3); - _fused = dynamic_cast(_doc->addObject("Part::Fuse")); + _fused = _doc->addObject(); _fused->Base.setValue(_boxes[0]); _fused->Tool.setValue(_boxes[1]); _fused->execute(); - _chamfer = dynamic_cast(_doc->addObject("Part::Chamfer")); + _chamfer = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/FeatureCompound.cpp b/tests/src/Mod/Part/App/FeatureCompound.cpp index 1a250b4b5b..219bb88a65 100644 --- a/tests/src/Mod/Part/App/FeatureCompound.cpp +++ b/tests/src/Mod/Part/App/FeatureCompound.cpp @@ -19,7 +19,7 @@ protected: void SetUp() override { createTestDoc(); - _compound = dynamic_cast(_doc->addObject("Part::Compound")); + _compound = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/FeatureExtrusion.cpp b/tests/src/Mod/Part/App/FeatureExtrusion.cpp index 7374ed729b..0d14aa7c73 100644 --- a/tests/src/Mod/Part/App/FeatureExtrusion.cpp +++ b/tests/src/Mod/Part/App/FeatureExtrusion.cpp @@ -21,7 +21,7 @@ protected: void SetUp() override { createTestDoc(); - _extrusion = dynamic_cast(_doc->addObject("Part::Extrusion")); + _extrusion = _doc->addObject(); PartTestHelpers::rectangle(len, wid, "Rect1"); _extrusion->Base.setValue(_doc->getObjects().back()); _extrusion->LengthFwd.setValue(ext1); @@ -252,7 +252,7 @@ TEST_F(FeatureExtrusionTest, testExecuteEdge) const double ang = 30; const double tangent = tan(ang / 180.0 * M_PI); BRepBuilderAPI_MakeEdge e1(gp_Pnt(0, 0, 0), gp_Pnt(ext1, ext1, ext1)); - auto edge = dynamic_cast(_doc->addObject("Part::Feature", "Edge")); + auto edge = _doc->addObject("Edge"); edge->Shape.setValue(e1); _extrusion->DirLink.setValue(edge); _extrusion->DirMode.setValue(1); @@ -310,7 +310,7 @@ TEST_F(FeatureExtrusionTest, testFaceWithHoles) // newFace cleans that up and is the outside minus the internal hole. auto face2 = newFace.getShape(); - auto partFeature = dynamic_cast(_doc->addObject("Part::Feature")); + auto partFeature = _doc->addObject(); partFeature->Shape.setValue(face2); _extrusion->Base.setValue(_doc->getObjects().back()); _extrusion->FaceMakerClass.setValue("Part::FaceMakerCheese"); diff --git a/tests/src/Mod/Part/App/FeatureFillet.cpp b/tests/src/Mod/Part/App/FeatureFillet.cpp index 1d4ba4a467..0f1aeb1bb2 100644 --- a/tests/src/Mod/Part/App/FeatureFillet.cpp +++ b/tests/src/Mod/Part/App/FeatureFillet.cpp @@ -28,11 +28,11 @@ protected: _boxes[1]->Length.setValue(1); _boxes[1]->Width.setValue(2); _boxes[1]->Height.setValue(3); - _fused = dynamic_cast(_doc->addObject("Part::Fuse")); + _fused = _doc->addObject(); _fused->Base.setValue(_boxes[0]); _fused->Tool.setValue(_boxes[1]); _fused->execute(); - _fillet = dynamic_cast(_doc->addObject("Part::Fillet")); + _fillet = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/FeatureMirroring.cpp b/tests/src/Mod/Part/App/FeatureMirroring.cpp index 8e999b7785..abd8177c4d 100644 --- a/tests/src/Mod/Part/App/FeatureMirroring.cpp +++ b/tests/src/Mod/Part/App/FeatureMirroring.cpp @@ -21,7 +21,7 @@ protected: void SetUp() override { createTestDoc(); - _mirror = dynamic_cast(_doc->addObject("Part::Mirroring")); + _mirror = _doc->addObject(); _mirror->Source.setValue(_boxes[0]); _mirror->Base.setValue(1, 0, 0); _mirror->execute(); @@ -61,7 +61,7 @@ TEST_F(FeatureMirroringTest, testYMirrorWithExistingElementMap) { // Arrange Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework - _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); + _fuse = _doc->addObject(); _fuse->Base.setValue(_boxes[0]); _fuse->Tool.setValue(_boxes[1]); // Act diff --git a/tests/src/Mod/Part/App/FeatureOffset.cpp b/tests/src/Mod/Part/App/FeatureOffset.cpp index 5d9f61fdad..7642c16d41 100644 --- a/tests/src/Mod/Part/App/FeatureOffset.cpp +++ b/tests/src/Mod/Part/App/FeatureOffset.cpp @@ -21,7 +21,7 @@ protected: void SetUp() override { createTestDoc(); - _offset = dynamic_cast(_doc->addObject("Part::Offset")); + _offset = _doc->addObject(); _offset->Source.setValue(_boxes[0]); _offset->Value.setValue(1); _offset->Join.setValue((int)JoinType::intersection); @@ -52,7 +52,7 @@ TEST_F(FeatureOffsetTest, testOffset3DWithExistingElementMap) { // Arrange Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework - _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); + _fuse = _doc->addObject(); _fuse->Base.setValue(_boxes[0]); _fuse->Tool.setValue(_boxes[1]); _fuse->Refine.setValue(true); @@ -76,8 +76,8 @@ TEST_F(FeatureOffsetTest, testOffset3DWithExistingElementMap) TEST_F(FeatureOffsetTest, testOffset2D) { // Arrange - Part::Offset2D* _offset2 = dynamic_cast(_doc->addObject("Part::Offset2D")); - Part::Plane* _pln = dynamic_cast(_doc->addObject("Part::Plane")); + Part::Offset2D* _offset2 = _doc->addObject(); + Part::Plane* _pln = _doc->addObject(); _pln->Length.setValue(2); _pln->Width.setValue(3); _offset2->Source.setValue(_pln); diff --git a/tests/src/Mod/Part/App/FeaturePartBoolean.cpp b/tests/src/Mod/Part/App/FeaturePartBoolean.cpp index 074b1dc9a1..d9548e2091 100644 --- a/tests/src/Mod/Part/App/FeaturePartBoolean.cpp +++ b/tests/src/Mod/Part/App/FeaturePartBoolean.cpp @@ -19,7 +19,7 @@ protected: void SetUp() override { // createTestDoc(); - // _boolean = dynamic_cast(_doc->addObject("Part::Boolean")); + // _boolean = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/FeaturePartCommon.cpp b/tests/src/Mod/Part/App/FeaturePartCommon.cpp index 65c986cc93..0e2cc3a639 100644 --- a/tests/src/Mod/Part/App/FeaturePartCommon.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCommon.cpp @@ -19,7 +19,7 @@ protected: void SetUp() override { createTestDoc(); - _common = dynamic_cast(_doc->addObject("Part::Common")); + _common = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/FeaturePartCut.cpp b/tests/src/Mod/Part/App/FeaturePartCut.cpp index f0c42ac92c..9f52671250 100644 --- a/tests/src/Mod/Part/App/FeaturePartCut.cpp +++ b/tests/src/Mod/Part/App/FeaturePartCut.cpp @@ -18,7 +18,7 @@ protected: void SetUp() override { createTestDoc(); - _cut = dynamic_cast(_doc->addObject("Part::Cut")); + _cut = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/FeaturePartFuse.cpp b/tests/src/Mod/Part/App/FeaturePartFuse.cpp index cf7e53a395..b95806b807 100644 --- a/tests/src/Mod/Part/App/FeaturePartFuse.cpp +++ b/tests/src/Mod/Part/App/FeaturePartFuse.cpp @@ -20,8 +20,8 @@ protected: void SetUp() override { createTestDoc(); - _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); - _multiFuse = dynamic_cast(_doc->addObject("Part::MultiFuse")); + _fuse = _doc->addObject(); + _multiFuse = _doc->addObject(); } void TearDown() override @@ -58,7 +58,7 @@ TEST_F(FeaturePartFuseTest, testCompound) { // Arrange Part::Compound* _compound = nullptr; - _compound = dynamic_cast(_doc->addObject("Part::Compound")); + _compound = _doc->addObject(); _compound->Links.setValues({_boxes[0], _boxes[1]}); _multiFuse->Shapes.setValues({_compound}); @@ -85,7 +85,7 @@ TEST_F(FeaturePartFuseTest, testRecursiveCompound) Part::Compound* _compound[3] = {nullptr}; int t; for (t = 0; t < 3; t++) { - _compound[t] = dynamic_cast(_doc->addObject("Part::Compound")); + _compound[t] = _doc->addObject(); } _compound[0]->Links.setValues({_boxes[0], _boxes[1]}); _compound[1]->Links.setValues({_compound[0]}); diff --git a/tests/src/Mod/Part/App/FeatureRevolution.cpp b/tests/src/Mod/Part/App/FeatureRevolution.cpp index 99abb7ea46..38eeafa562 100644 --- a/tests/src/Mod/Part/App/FeatureRevolution.cpp +++ b/tests/src/Mod/Part/App/FeatureRevolution.cpp @@ -25,7 +25,7 @@ protected: void SetUp() override { createTestDoc(); - _revolution = dynamic_cast(_doc->addObject("Part::Revolution")); + _revolution = _doc->addObject(); PartTestHelpers::rectangle(len, wid, "Rect1"); _revolution->Source.setValue(_doc->getObjects().back()); _revolution->Axis.setValue(0, 1, 0); @@ -95,7 +95,7 @@ TEST_F(FeatureRevolutionTest, testAxisLink) { // Arrange BRepBuilderAPI_MakeEdge e1(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, ext1)); - auto edge = dynamic_cast(_doc->addObject("Part::Feature", "Edge")); + auto edge = _doc->addObject("Edge"); edge->Shape.setValue(e1); _revolution->AxisLink.setValue(edge); // double puckVolume = wid * wid * M_PI * len; // Area is PIr2; apply height diff --git a/tests/src/Mod/Part/App/FuzzyBoolean.cpp b/tests/src/Mod/Part/App/FuzzyBoolean.cpp index 95c4e5d7b6..7a3192f50d 100644 --- a/tests/src/Mod/Part/App/FuzzyBoolean.cpp +++ b/tests/src/Mod/Part/App/FuzzyBoolean.cpp @@ -22,10 +22,10 @@ protected: { createTestDoc(); std::string testPath = App::Application::getHomePath() + "/tests/brepfiles/"; - _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); - _cylinder1 = dynamic_cast(_doc->addObject("Part::ImportBrep")); + _fuse = _doc->addObject(); + _cylinder1 = _doc->addObject(); _cylinder1->FileName.setValue(testPath + "cylinder1.brep"); - _helix1 = dynamic_cast(_doc->addObject("Part::ImportBrep")); + _helix1 = _doc->addObject(); _helix1->FileName.setValue(testPath + "helix1.brep"); // Load diff --git a/tests/src/Mod/Part/App/PartFeature.cpp b/tests/src/Mod/Part/App/PartFeature.cpp index 8ae03c2224..db20e801df 100644 --- a/tests/src/Mod/Part/App/PartFeature.cpp +++ b/tests/src/Mod/Part/App/PartFeature.cpp @@ -24,7 +24,7 @@ protected: void SetUp() override { createTestDoc(); - _common = dynamic_cast(_doc->addObject("Part::Common")); + _common = _doc->addObject(); } void TearDown() override diff --git a/tests/src/Mod/Part/App/PartFeatures.cpp b/tests/src/Mod/Part/App/PartFeatures.cpp index f631f76d66..550a478356 100644 --- a/tests/src/Mod/Part/App/PartFeatures.cpp +++ b/tests/src/Mod/Part/App/PartFeatures.cpp @@ -30,8 +30,8 @@ protected: TEST_F(PartFeaturesTest, testRuledSurface) { // Arrange - auto _edge1 = dynamic_cast(_doc->addObject("Part::Line")); - auto _edge2 = dynamic_cast(_doc->addObject("Part::Line")); + auto _edge1 = _doc->addObject(); + auto _edge2 = _doc->addObject(); _edge1->X1.setValue(0); _edge1->Y1.setValue(0); _edge1->Z1.setValue(0); @@ -44,7 +44,7 @@ TEST_F(PartFeaturesTest, testRuledSurface) _edge2->X2.setValue(2); _edge2->Y2.setValue(2); _edge2->Z2.setValue(0); - auto _ruled = dynamic_cast(_doc->addObject("Part::RuledSurface")); + auto _ruled = _doc->addObject(); _ruled->Curve1.setValue(_edge1); _ruled->Curve2.setValue(_edge2); // Act @@ -65,14 +65,14 @@ TEST_F(PartFeaturesTest, testRuledSurface) TEST_F(PartFeaturesTest, testLoft) { // Arrange - auto _plane1 = dynamic_cast(_doc->addObject("Part::Plane")); + auto _plane1 = _doc->addObject(); _plane1->Length.setValue(4); _plane1->Width.setValue(4); - auto _plane2 = dynamic_cast(_doc->addObject("Part::Plane")); + auto _plane2 = _doc->addObject(); _plane2->Length.setValue(4); _plane2->Width.setValue(4); _plane2->Placement.setValue(Base::Placement(Base::Vector3d(0, 0, 2), Base::Rotation())); - auto _loft = dynamic_cast(_doc->addObject("Part::Loft")); + auto _loft = _doc->addObject(); _loft->Sections.setValues({_plane1, _plane2}); _loft->Solid.setValue((true)); // Act @@ -93,17 +93,17 @@ TEST_F(PartFeaturesTest, testLoft) TEST_F(PartFeaturesTest, testSweep) { // Arrange - auto _edge1 = dynamic_cast(_doc->addObject("Part::Line")); + auto _edge1 = _doc->addObject(); _edge1->X1.setValue(0); _edge1->Y1.setValue(0); _edge1->Z1.setValue(0); _edge1->X2.setValue(0); _edge1->Y2.setValue(0); _edge1->Z2.setValue(3); - auto _plane1 = dynamic_cast(_doc->addObject("Part::Plane")); + auto _plane1 = _doc->addObject(); _plane1->Length.setValue(4); _plane1->Width.setValue(4); - auto _sweep = dynamic_cast(_doc->addObject("Part::Sweep")); + auto _sweep = _doc->addObject(); _sweep->Sections.setValues({_plane1}); _sweep->Spine.setValue(_edge1); // Act @@ -124,7 +124,7 @@ TEST_F(PartFeaturesTest, testSweep) TEST_F(PartFeaturesTest, testThickness) { // Arrange - auto _thickness = dynamic_cast(_doc->addObject("Part::Thickness")); + auto _thickness = _doc->addObject(); _thickness->Faces.setValue(_boxes[0], {"Face1"}); _thickness->Value.setValue(0.25); _thickness->Join.setValue("Intersection"); @@ -146,12 +146,12 @@ TEST_F(PartFeaturesTest, testThickness) TEST_F(PartFeaturesTest, testRefine) { // Arrange - auto _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); + auto _fuse = _doc->addObject(); _fuse->Base.setValue(_boxes[0]); _fuse->Tool.setValue(_boxes[3]); _fuse->execute(); Part::TopoShape fusedts = _fuse->Shape.getShape(); - auto _refine = dynamic_cast(_doc->addObject("Part::Refine")); + auto _refine = _doc->addObject(); _refine->Source.setValue(_fuse); // Act _refine->execute(); @@ -175,7 +175,7 @@ TEST_F(PartFeaturesTest, testRefine) TEST_F(PartFeaturesTest, testReverse) { // Arrange - auto _reverse = dynamic_cast(_doc->addObject("Part::Reverse")); + auto _reverse = _doc->addObject(); _reverse->Source.setValue(_boxes[0]); // Act _reverse->execute(); diff --git a/tests/src/Mod/Part/App/PartTestHelpers.cpp b/tests/src/Mod/Part/App/PartTestHelpers.cpp index a97de3c0e8..392240f4fb 100644 --- a/tests/src/Mod/Part/App/PartTestHelpers.cpp +++ b/tests/src/Mod/Part/App/PartTestHelpers.cpp @@ -44,7 +44,7 @@ void PartTestHelperClass::createTestDoc() Base::Vector3d(0, 2 - minimalDistance, 0)}; for (unsigned i = 0; i < _boxes.size(); i++) { - auto box = _boxes[i] = dynamic_cast(_doc->addObject("Part::Box")); // NOLINT + auto box = _boxes[i] = _doc->addObject(); // NOLINT box->Length.setValue(1); box->Width.setValue(2); box->Height.setValue(3); diff --git a/tests/src/Mod/Part/App/PropertyTopoShape.cpp b/tests/src/Mod/Part/App/PropertyTopoShape.cpp index a6464c3b25..be33e28c1d 100644 --- a/tests/src/Mod/Part/App/PropertyTopoShape.cpp +++ b/tests/src/Mod/Part/App/PropertyTopoShape.cpp @@ -23,7 +23,7 @@ protected: void SetUp() override { createTestDoc(); - _common = dynamic_cast(_doc->addObject("Part::Common")); + _common = _doc->addObject(); _common->Base.setValue(_boxes[0]); _common->Tool.setValue(_boxes[1]); _common->execute(); // We should now have an elementMap with 26 entries. diff --git a/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp b/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp index 6331ceb09a..14e048c2d1 100644 --- a/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp +++ b/tests/src/Mod/Part/App/TopoShapeMakeElementRefine.cpp @@ -29,7 +29,7 @@ TEST_F(FeaturePartMakeElementRefineTest, makeElementRefineBoxes) { // Arrange auto _doc = App::GetApplication().getActiveDocument(); - auto _fuse = dynamic_cast(_doc->addObject("Part::Fuse")); + auto _fuse = _doc->addObject(); _fuse->Base.setValue(_boxes[0]); _fuse->Tool.setValue(_boxes[3]); // Act diff --git a/tests/src/Mod/PartDesign/App/DatumPlane.cpp b/tests/src/Mod/PartDesign/App/DatumPlane.cpp index a7c6c9cf15..3c65129c49 100644 --- a/tests/src/Mod/PartDesign/App/DatumPlane.cpp +++ b/tests/src/Mod/PartDesign/App/DatumPlane.cpp @@ -22,7 +22,7 @@ protected: { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _body = dynamic_cast(_doc->addObject("PartDesign::Body")); + _body = _doc->addObject(); } void TearDown() override @@ -48,7 +48,7 @@ private: TEST_F(DatumPlaneTest, attachDatumPlane) { - auto datumPlane = getDocument()->addObject("PartDesign::Plane", "Plane"); + auto datumPlane = getDocument()->addObject("Plane"); ASSERT_TRUE(datumPlane); getBody()->addObject(datumPlane); auto origin = getBody()->getOrigin(); diff --git a/tests/src/Mod/PartDesign/App/Pad.cpp b/tests/src/Mod/PartDesign/App/Pad.cpp index a4bd4af4f4..69eff9f416 100644 --- a/tests/src/Mod/PartDesign/App/Pad.cpp +++ b/tests/src/Mod/PartDesign/App/Pad.cpp @@ -23,9 +23,8 @@ protected: void SetUp() override { _doc = App::GetApplication().newDocument("Pad_test", "testUser"); - _body = dynamic_cast(_doc->addObject("PartDesign::Body")); - _sketch = dynamic_cast( - _doc->addObject("Sketcher::SketchObject", "Sketch")); + _body = _doc->addObject(); + _sketch = _doc->addObject("Sketch"); _body->addObject(_sketch); _sketch->AttachmentSupport.setValue(_doc->getObject("XY_Plane"), ""); @@ -69,7 +68,7 @@ TEST_F(PadTest, TestMidPlaneTwoLength) doc->recompute(); - auto pad = dynamic_cast(doc->addObject("PartDesign::Pad", "Pad")); + auto pad = doc->addObject("Pad"); body->addObject(pad); pad->Profile.setValue(sketch, {""}); pad->Direction.setValue(0.0, 0.0, 1.0); diff --git a/tests/src/Mod/PartDesign/App/ShapeBinder.cpp b/tests/src/Mod/PartDesign/App/ShapeBinder.cpp index 52768ae160..e3105faa8b 100644 --- a/tests/src/Mod/PartDesign/App/ShapeBinder.cpp +++ b/tests/src/Mod/PartDesign/App/ShapeBinder.cpp @@ -23,8 +23,8 @@ protected: { _docName = App::GetApplication().getUniqueDocumentName("test"); _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser"); - _body = dynamic_cast(_doc->addObject("PartDesign::Body")); // NOLINT - _box = dynamic_cast(_doc->addObject("Part::Box")); // NOLINT + _body = _doc->addObject(); + _box = _doc->addObject(); _box->Length.setValue(1); _box->Width.setValue(2); _box->Height.setValue(3); @@ -32,10 +32,8 @@ protected: Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); // NOLINT // _body->addObject(_box); // Invalid, Part::Features can't go in a PartDesign::Body, // but we can bind them. - _binder = dynamic_cast( - _doc->addObject("PartDesign::ShapeBinder", "ShapeBinderFoo")); // NOLINT - _subbinder = dynamic_cast( - _doc->addObject("PartDesign::SubShapeBinder", "SubShapeBinderBar")); // NOLINT + _binder = _doc->addObject("ShapeBinderFoo"); + _subbinder = _doc->addObject("SubShapeBinderBar"); _binder->Shape.setValue(_box->Shape.getShape()); _subbinder->setLinks({{_box, {"Face1", "Face2"}}}, false); _body->addObject(_binder); diff --git a/tests/src/Mod/Sketcher/App/SketchObject.cpp b/tests/src/Mod/Sketcher/App/SketchObject.cpp index 30e4432387..603ec299e9 100644 --- a/tests/src/Mod/Sketcher/App/SketchObject.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObject.cpp @@ -12,6 +12,7 @@ using namespace SketcherTestHelpers; + TEST_F(SketchObjectTest, createSketchObject) // NOLINT { // Arrange