X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSetPlugin%2FPartSetPlugin_Duplicate.cpp;h=462a7366bdab45a2b9ebef798aa12ccf0bc41bdf;hb=61cd0845b41710ad4e7eae07cc6106904be67b9f;hp=9b6a47e162bf23a009d2b01782f5de71d035678c;hpb=353537a42781ba9ab4774057c0e8acdfeef8c6dd;p=modules%2Fshaper.git diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index 9b6a47e16..462a7366b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: PartSetPlugin_Duplicate.cxx // Created: 20 May 2014 // Author: Mikhail PONIKAROV @@ -7,6 +9,8 @@ #include #include #include +#include +#include using namespace std; @@ -17,24 +21,34 @@ PartSetPlugin_Duplicate::PartSetPlugin_Duplicate() void PartSetPlugin_Duplicate::initAttributes() { PartSetPlugin_Part::initAttributes(); - data()->addAttribute(PART_DUPLICATE_ATTR_REF, ModelAPI_AttributeRefAttr::type()); - - boost::shared_ptr aRef = data()->refattr(PART_DUPLICATE_ATTR_REF); - if (!aRef->attr()) { // create a copy: if not created yet attribute is not initialized - boost::shared_ptr aPManager = ModelAPI_PluginManager::get(); - boost::shared_ptr aRoot = aPManager->rootDocument(); - boost::shared_ptr aSource; // searching for source document attribute - for(int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { - aSource = boost::dynamic_pointer_cast( - aRoot->feature(getGroup(), a, true)); - if (aSource->data()->docRef(PART_ATTR_DOC_REF)->value() == aPManager->currentDocument()) - break; - aSource.reset(); - } - if (aSource) { - boost::shared_ptr aCopy = - aPManager->copy(aSource->data()->docRef(PART_ATTR_DOC_REF)->value(), data()->getName()); - aRef->setFeature(aSource); - } + + std::shared_ptr aPManager = ModelAPI_Session::get(); + std::shared_ptr aRoot = aPManager->moduleDocument(); + std::shared_ptr aSource; // searching for source document attribute + for (int a = aRoot->size(getGroup()) - 1; a >= 0; a--) { + aSource = std::dynamic_pointer_cast(aRoot->object(getGroup(), a)); + if (aSource && aSource->data() + && aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value() + == aPManager->activeDocument()) + break; + aSource.reset(); + } + if (aSource) { + std::shared_ptr 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(); +} + +const std::string& PartSetPlugin_Duplicate::documentToAdd() +{ + // part must be added only to the module document + return ModelAPI_Session::get()->moduleDocument()->kind(); +}