1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSetAPI_Part.h"
22 //--------------------------------------------------------------------------------------
23 #include <ModelAPI_ResultPart.h>
24 #include <ModelAPI_Session.h>
25 #include <ModelHighAPI_Dumper.h>
26 #include <ModelHighAPI_Selection.h>
27 //--------------------------------------------------------------------------------------
28 #include <PartSetPlugin_Duplicate.h>
29 #include <PartSetPlugin_Remove.h>
30 //--------------------------------------------------------------------------------------
31 PartSetAPI_Part::PartSetAPI_Part(
32 const std::shared_ptr<ModelAPI_Feature> & theFeature)
33 : ModelHighAPI_Interface(theFeature)
38 PartSetAPI_Part::~PartSetAPI_Part()
42 //--------------------------------------------------------------------------------------
43 std::shared_ptr<ModelAPI_Document> PartSetAPI_Part::document() const
45 return std::dynamic_pointer_cast<ModelAPI_ResultPart>(defaultResult())->partDoc();
48 void PartSetAPI_Part::dump(ModelHighAPI_Dumper& theDumper) const
50 FeaturePtr aBase = feature();
51 const std::string& aDocName = theDumper.name(aBase->document());
53 theDumper << aBase << " = model.addPart(" << aDocName << ")" << std::endl;
56 //--------------------------------------------------------------------------------------
57 PartPtr addPart(const std::shared_ptr<ModelAPI_Document> & thePart)
59 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetAPI_Part::ID());
61 return PartPtr(new PartSetAPI_Part(aFeature));
64 PartPtr duplicatePart(const ModelHighAPI_Interface& thePart)
67 // only the active part is duplicated, so, activate it
68 FeaturePtr aPartFeature = thePart.feature();
70 // duplication of the current part is performed
71 DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
72 aPartSet->setCurrentFeature(aPartFeature, false);
73 DocumentPtr aPartDoc =
74 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult())->partDoc();
76 ModelAPI_Session::get()->setActiveDocument(aPartDoc);
77 FeaturePtr aDuplicate = aPartDoc->addFeature(PartSetPlugin_Duplicate::ID());
78 //aDuplicate->execute(); // it is executed at creation because it is action
79 FeaturePtr aNewPart = aPartSet->currentFeature(false); // a copy becomes a current
81 aResult = PartPtr(new PartSetAPI_Part(aNewPart));
82 DocumentPtr aNewDoc = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
83 aNewPart->firstResult())->partDoc();
84 ModelAPI_Session::get()->setActiveDocument(aNewDoc);
91 void removePart(const ModelHighAPI_Interface& thePart)
93 FeaturePtr aPartFeature = thePart.feature();
95 // duplication of the current part is performed
96 DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
97 aPartSet->setCurrentFeature(aPartFeature, false);
98 DocumentPtr aPartDoc =
99 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult())->partDoc();
100 if (aPartDoc.get()) {
101 ModelAPI_Session::get()->setActiveDocument(aPartDoc);
102 aPartDoc->addFeature(PartSetPlugin_Remove::ID());
103 ModelAPI_Session::get()->setActiveDocument(aPartSet);