Merge pull request #19142 from hyarion/refactor/add-template-addobject

Add new addObject<T>() function
This commit is contained in:
Chris Hennes
2025-02-11 09:42:47 -06:00
committed by GitHub
95 changed files with 335 additions and 340 deletions

View File

@@ -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<Part::Box*>(doc->addObject("Part::Box", name));
auto pcBox = doc->addObject<Part::Box>(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<Part::Cut*>(doc->addObject("Part::Cut", name));
auto pcCut = doc->addObject<Part::Cut>(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<App::DocumentObject*> createLinks(App::Document* doc, const std::vec
}
newName += "_CutLink";
auto pcLink = dynamic_cast<App::Link*>(doc->addObject("App::Link", newName.c_str()));
auto pcLink = doc->addObject<App::Link>(newName.c_str());
if (!pcLink) {
throw Base::RuntimeError("'App::Link' could not be added");
}
@@ -1019,13 +1019,10 @@ std::vector<App::DocumentObject*> createLinks(App::Document* doc, const std::vec
// if the object is part of an App::Part container,
// the link needs to get the container placement
auto parents = itCuts->getInList();
if (!parents.empty()) {
if (auto parents = itCuts->getInList(); !parents.empty()) {
for (auto parent : parents) {
if (auto pcPartParent = dynamic_cast<App::Part*>(parent)) {
auto placement = Base::freecad_dynamic_cast<App::PropertyPlacement>(
pcPartParent->getPropertyByName("Placement"));
if (placement) {
if (auto placement = pcPartParent->getPropertyByName<App::PropertyPlacement>("Placement")) {
pcLink->Placement.setValue(placement->getValue());
}
}
@@ -2421,7 +2418,7 @@ App::DocumentObject* SectionCut::createBooleanFragments(
Part::Compound* SectionCut::createCompound(const std::vector<App::DocumentObject*>& links,
int transparency)
{
auto CutCompoundPart = dynamic_cast<Part::Compound*>(doc->addObject("Part::Compound", CompoundName));
auto CutCompoundPart = doc->addObject<Part::Compound>(CompoundName);
if (!CutCompoundPart) {
throw Base::RuntimeError((std::string("SectionCut error: ") + std::string(CompoundName)
+ std::string(" could not be added\n")).c_str());