X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSetPlugin%2FPartSetPlugin_Duplicate.cpp;h=4e900e8c492c2b50fb599f441793ac33ac1a1569;hb=21a0c85b52bb93f94680e2342370764e6510e387;hp=d1032abf8a29e9c792adbb9cb842f903923c093f;hpb=036ba4eb4c2df048fd651a54f68882a01769eb08;p=modules%2Fshaper.git diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index d1032abf8..4e900e8c4 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -1,40 +1,38 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: PartSetPlugin_Duplicate.cxx // Created: 20 May 2014 // Author: Mikhail PONIKAROV #include "PartSetPlugin_Duplicate.h" +#include "PartSetPlugin_Part.h" #include #include #include #include +#include +#include -using namespace std; - -PartSetPlugin_Duplicate::PartSetPlugin_Duplicate() -{ -} - -void PartSetPlugin_Duplicate::initAttributes() +void PartSetPlugin_Duplicate::execute() { - PartSetPlugin_Part::initAttributes(); - data()->addAttribute(PartSetPlugin_Duplicate::DOC_REF(), ModelAPI_AttributeRefAttr::type()); + 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) { + // create a new Part feature + FeaturePtr aNewPart = aRoot->addFeature(PartSetPlugin_Part::ID(), false); + aNewPart->execute(); // to make result and generate a unique name - boost::shared_ptr aRef = data()->refattr(PartSetPlugin_Duplicate::DOC_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->object(ModelAPI_Feature::group(), a)); - if (aSource->data()->docRef(PartSetPlugin_Part::DOC_REF())->value() == aPManager->currentDocument()) - break; - aSource.reset(); - } - if (aSource) { - boost::shared_ptr aCopy = - aPManager->copy(aSource->data()->docRef(PartSetPlugin_Part::DOC_REF())->value(), data()->name()); - aRef->setObject(aSource); - } + std::shared_ptr aCopy = aPManager->copy( + aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value(), + std::dynamic_pointer_cast(aNewPart->firstResult())->partDoc()->id()); } }