1 // File: PartSetPlugin_Duplicate.cxx
2 // Created: 20 May 2014
3 // Author: Mikhail PONIKAROV
5 #include "PartSetPlugin_Duplicate.h"
6 #include <ModelAPI_AttributeRefAttr.h>
7 #include <ModelAPI_AttributeDocRef.h>
8 #include <ModelAPI_Data.h>
9 #include <ModelAPI_Document.h>
13 PartSetPlugin_Duplicate::PartSetPlugin_Duplicate()
17 void PartSetPlugin_Duplicate::initAttributes()
19 PartSetPlugin_Part::initAttributes();
20 data()->addAttribute(PART_DUPLICATE_ATTR_REF, ModelAPI_AttributeRefAttr::type());
22 boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef = data()->refattr(PART_DUPLICATE_ATTR_REF);
23 if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized
24 boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
25 boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
26 boost::shared_ptr<PartSetPlugin_Part> aSource; // searching for source document attribute
27 for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
28 aSource = boost::dynamic_pointer_cast<PartSetPlugin_Part>(
29 aRoot->feature(getGroup(), a, true));
30 if (aSource->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument())
35 boost::shared_ptr<ModelAPI_Document> aCopy =
36 aPManager->copy(aSource->data()->docRef(PART_ATTR_DOC_REF)->value(), data()->getName());
37 aRef->setFeature(aSource);