Salome HOME
Make preview of python Box feature working correctly
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Duplicate.cpp
index b02ae41f83810e9400f5293793bdf5d91be21861..35134c64b7aa2a43603aebea9975e7d6bc8f2b5c 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
@@ -8,6 +10,7 @@
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_ResultPart.h>
+#include <ModelAPI_Session.h>
 
 using namespace std;
 
@@ -18,22 +21,28 @@ PartSetPlugin_Duplicate::PartSetPlugin_Duplicate()
 void PartSetPlugin_Duplicate::initAttributes()
 {
   PartSetPlugin_Part::initAttributes();
-  data()->addAttribute(ORIGIN_REF(), ModelAPI_AttributeRefAttr::type());
 
-  boost::shared_ptr<ModelAPI_PluginManager> aPManager = ModelAPI_PluginManager::get();
-  boost::shared_ptr<ModelAPI_Document> aRoot = aPManager->rootDocument();
-  boost::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));
-    if (aSource && aSource->data() && 
-        aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value() == 
-        aPManager->currentDocument())
+  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 = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aRoot->object(getGroup(), a));
+    if (aSource && aSource->data()
+        && aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value()
+            == aPManager->activeDocument())
       break;
     aSource.reset();
   }
   if (aSource) {
-    boost::shared_ptr<ModelAPI_Document> aCopy = aPManager->copy(
-      aSource->data()->docRef(ModelAPI_ResultPart::DOC_REF())->value(),
-      data()->name());
+    std::shared_ptr<ModelAPI_Document> aCopy = aPManager->copy(
+        aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value(), data()->name());
+  } else { // invalid part copy: do nothing, keep this in empty name
+    data()->setName("");
   }
 }
+
+void PartSetPlugin_Duplicate::execute()
+{
+  if (!data()->name().empty())
+    PartSetPlugin_Part::execute();
+}