Salome HOME
Revert "Fix Warning in GeomAPI_Trsf"
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Duplicate.cpp
index 8c6e8cc0ae117285373734155090805ffa58069d..462a7366bdab45a2b9ebef798aa12ccf0bc41bdf 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        PartSetPlugin_Duplicate.cxx
 // Created:     20 May 2014
 // Author:      Mikhail PONIKAROV
@@ -19,13 +21,12 @@ PartSetPlugin_Duplicate::PartSetPlugin_Duplicate()
 void PartSetPlugin_Duplicate::initAttributes()
 {
   PartSetPlugin_Part::initAttributes();
-  data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type());
 
-  boost::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
-  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
-  boost::shared_ptr<ModelAPI_ResultPart> aSource;  // searching for source document attribute
+  std::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
+  std::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
+  std::shared_ptr<ModelAPI_ResultPart> aSource;  // searching for source document attribute
   for (int a = aRoot->size(getGroup()) - 1; a >= 0; a--) {
-    aSource = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aRoot->object(getGroup(), a));
+    aSource = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRoot->object(getGroup(), a));
     if (aSource && aSource->data()
         && aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value()
             == aPManager->activeDocument())
@@ -33,14 +34,21 @@ void PartSetPlugin_Duplicate::initAttributes()
     aSource.reset();
   }
   if (aSource) {
-    boost::shared_ptr<ModelAPI_Document> aCopy = aPManager->copy(
+    std::shared_ptr<ModelAPI_Document> aCopy = aPManager->copy(
         aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value(), data()->name());
-    data()->refattr(ORIGIN_REF())->setObject(aSource);
+  } else { // invalid part copy: do nothing, keep this in empty name
+    data()->setName("");
   }
 }
 
 void PartSetPlugin_Duplicate::execute()
 {
-  if (data()->refattr(ORIGIN_REF())->object())
+  if (!data()->name().empty())
     PartSetPlugin_Part::execute();
 }
+
+const std::string& PartSetPlugin_Duplicate::documentToAdd()
+{
+  // part must be added only to the module document
+  return ModelAPI_Session::get()->moduleDocument()->kind();
+}