App: Add Document::addObject<T>(...) to simplify code

This commit is contained in:
Benjamin Nauck
2025-01-19 01:46:46 +01:00
parent ddb0113ded
commit 0712b481e9
2 changed files with 25 additions and 12 deletions

View File

@@ -3544,7 +3544,7 @@ DocumentObject* Document::addObject(const char* sType,
const char* viewType,
bool isPartial)
{
Base::Type type =
const Base::Type type =
Base::Type::getTypeIfDerivedFrom(sType, App::DocumentObject::getClassTypeId(), true);
if (type.isBad()) {
std::stringstream str;
@@ -3557,8 +3557,7 @@ DocumentObject* Document::addObject(const char* sType,
return nullptr;
}
App::DocumentObject* pcObject = static_cast<App::DocumentObject*>(typeInstance);
auto* pcObject = static_cast<App::DocumentObject*>(typeInstance);
pcObject->setDocument(this);
// do no transactions if we do a rollback!
@@ -3571,15 +3570,8 @@ DocumentObject* Document::addObject(const char* sType,
}
// get Unique name
string ObjectName;
if (pObjectName && pObjectName[0] != '\0') {
ObjectName = getUniqueObjectName(pObjectName);
}
else {
ObjectName = getUniqueObjectName(sType);
}
const bool hasName = pObjectName && pObjectName[0] != '\0';
const string ObjectName = getUniqueObjectName(hasName ? pObjectName : type.getName());
d->activeObject = pcObject;