- boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = data()->docRef(PART_ATTR_DOC_REF);
- if (!aDocRef->value()) { // create a document if not yet created
- boost::shared_ptr<ModelAPI_Document> aPartSetDoc =
- ModelAPI_PluginManager::get()->rootDocument();
- aDocRef->setValue(aPartSetDoc->subDocument(data()->name()));
- }
- // create a result only once
- if (results().empty()) {
- boost::shared_ptr<ModelAPI_ResultPart> aResult = document()->createPart();
- document()->storeResult(data(), aResult);
- if (aResult->data()->name().empty())
- aResult->data()->setName(data()->name());
+ ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
+ if (!aResult) {
+ aResult = document()->createPart(data());
+ setResult(aResult);
+ aResult->activate();