X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSetPlugin%2FPartSetPlugin_Duplicate.cpp;h=2cfcc177b46bfa480d9b2401a4746c93478c80ed;hb=f9426a402de748e9d13085856a7cf72a3659135d;hp=9b6a47e162bf23a009d2b01782f5de71d035678c;hpb=503b5444d4a5fa95a3046a754f69f5b79e677e33;p=modules%2Fshaper.git diff --git a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp index 9b6a47e16..2cfcc177b 100644 --- a/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Duplicate.cpp @@ -1,40 +1,52 @@ -// File: PartSetPlugin_Duplicate.cxx -// Created: 20 May 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include "PartSetPlugin_Duplicate.h" +#include "PartSetPlugin_Part.h" #include #include #include #include +#include +#include -using namespace std; - -PartSetPlugin_Duplicate::PartSetPlugin_Duplicate() +void PartSetPlugin_Duplicate::execute() { -} - -void PartSetPlugin_Duplicate::initAttributes() -{ - PartSetPlugin_Part::initAttributes(); - data()->addAttribute(PART_DUPLICATE_ATTR_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(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 aCopy = aPManager->copy( + aSource->data()->document(ModelAPI_ResultPart::DOC_REF())->value(), + std::dynamic_pointer_cast(aNewPart->firstResult())->partDoc()->id()); } }