MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / addObject

Method addObject

src/App/Document.cpp:3336–3370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3334}
3335
3336DocumentObject* Document::addObject(
3337 std::string_view sType,
3338 const char* pObjectName,
3339 const bool isNew,
3340 const char* viewType,
3341 const bool isPartial
3342)
3343{
3344 const Base::Type type =
3345 Base::Type::getTypeIfDerivedFrom(sType, DocumentObject::getClassTypeId(), true);
3346 if (type.isBad()) {
3347 std::stringstream str;
3348 str << "Document::addObject: '" << sType << "' is not a document object type";
3349 throw Base::TypeError(str.str());
3350 }
3351
3352 void* typeInstance = type.createInstance();
3353 if (!typeInstance) {
3354 return nullptr;
3355 }
3356
3357 auto* pcObject = static_cast<DocumentObject*>(typeInstance);
3358 pcObject->setDocument(this);
3359
3360 _addObject(pcObject,
3361 pObjectName,
3362 AddObjectOption::SetNewStatus
3363 | (isPartial ? AddObjectOption::SetPartialStatus : AddObjectOption::UnsetPartialStatus)
3364 | (isNew ? AddObjectOption::DoSetup : AddObjectOption::None)
3365 | AddObjectOption::ActivateObject,
3366 viewType);
3367
3368 // return the Object
3369 return pcObject;
3370}
3371
3372std::vector<DocumentObject*>
3373Document::addObjects(const char* sType, const std::vector<std::string>& objectNames, bool isNew)

Callers

nothing calls this directly

Calls 5

isBadMethod · 0.45
strMethod · 0.45
createInstanceMethod · 0.45
setDocumentMethod · 0.45
getDocumentMethod · 0.45

Tested by

no test coverage detected