X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSetAPI%2FPartSetAPI_Part.cpp;h=54a3a6ba2fcd656c74884bd1d84b3390b4abc3e2;hb=b06cf1477fb1ee46d7ae260c234cac5d0000abf2;hp=349651cf3d8241b039127239c808cbb6e9746ba1;hpb=4adaeb56991dd63bbfec723aafb0bc31ca9fc463;p=modules%2Fshaper.git diff --git a/src/PartSetAPI/PartSetAPI_Part.cpp b/src/PartSetAPI/PartSetAPI_Part.cpp index 349651cf3..54a3a6ba2 100644 --- a/src/PartSetAPI/PartSetAPI_Part.cpp +++ b/src/PartSetAPI/PartSetAPI_Part.cpp @@ -1,15 +1,29 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// Name : PartSetAPI_Part.cpp -// Purpose: +// 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 // -// History: -// 16/06/16 - Sergey POKHODENKO - Creation of the file -//-------------------------------------------------------------------------------------- #include "PartSetAPI_Part.h" //-------------------------------------------------------------------------------------- #include +#include #include +#include //-------------------------------------------------------------------------------------- #include #include @@ -42,23 +56,51 @@ void PartSetAPI_Part::dump(ModelHighAPI_Dumper& theDumper) const //-------------------------------------------------------------------------------------- PartPtr addPart(const std::shared_ptr & thePart) { - // TODO(spo): check that thePart is not empty std::shared_ptr aFeature = thePart->addFeature(PartSetAPI_Part::ID()); aFeature->execute(); return PartPtr(new PartSetAPI_Part(aFeature)); } -PartPtr duplicatePart(const std::shared_ptr & thePart) +PartPtr duplicatePart(const ModelHighAPI_Interface& thePart) { - // TODO(spo): check that thePart is not empty - std::shared_ptr aFeature = thePart->addFeature(PartSetPlugin_Duplicate::ID()); - aFeature->execute(); - return PartPtr(new PartSetAPI_Part(aFeature)); + PartPtr aResult; + // only the active part is duplicated, so, activate it + FeaturePtr aPartFeature = thePart.feature(); + if (aPartFeature) { + // duplication of the current part is performed + DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument(); + aPartSet->setCurrentFeature(aPartFeature, false); + DocumentPtr aPartDoc = + std::dynamic_pointer_cast(aPartFeature->firstResult())->partDoc(); + if (aPartDoc.get()) { + ModelAPI_Session::get()->setActiveDocument(aPartDoc); + FeaturePtr aDuplicate = aPartDoc->addFeature(PartSetPlugin_Duplicate::ID()); + //aDuplicate->execute(); // it is executed at creation because it is action + FeaturePtr aNewPart = aPartSet->currentFeature(false); // a copy becomes a current + if (aNewPart.get()) { + aResult = PartPtr(new PartSetAPI_Part(aNewPart)); + DocumentPtr aNewDoc = std::dynamic_pointer_cast( + aNewPart->firstResult())->partDoc(); + ModelAPI_Session::get()->setActiveDocument(aNewDoc); + } + } + } + return aResult; } -void removePart(const std::shared_ptr & thePart) +void removePart(const ModelHighAPI_Interface& thePart) { - // TODO(spo): check that thePart is not empty - std::shared_ptr aFeature = thePart->addFeature(PartSetPlugin_Remove::ID()); - aFeature->execute(); + FeaturePtr aPartFeature = thePart.feature(); + if (aPartFeature) { + // duplication of the current part is performed + DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument(); + aPartSet->setCurrentFeature(aPartFeature, false); + DocumentPtr aPartDoc = + std::dynamic_pointer_cast(aPartFeature->firstResult())->partDoc(); + if (aPartDoc.get()) { + ModelAPI_Session::get()->setActiveDocument(aPartDoc); + aPartDoc->addFeature(PartSetPlugin_Remove::ID()); + ModelAPI_Session::get()->setActiveDocument(aPartSet); + } + } }