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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #include "PartSetAPI_Part.h"
21 //--------------------------------------------------------------------------------------
22 #include <ModelAPI_ResultPart.h>
23 #include <ModelAPI_Session.h>
24 #include <ModelHighAPI_Dumper.h>
25 #include <ModelHighAPI_Selection.h>
26 //--------------------------------------------------------------------------------------
27 #include <PartSetPlugin_Duplicate.h>
28 #include <PartSetPlugin_Remove.h>
29 //--------------------------------------------------------------------------------------
30 PartSetAPI_Part::PartSetAPI_Part(
31 const std::shared_ptr<ModelAPI_Feature> & theFeature)
32 : ModelHighAPI_Interface(theFeature)
37 PartSetAPI_Part::~PartSetAPI_Part()
41 //--------------------------------------------------------------------------------------
42 std::shared_ptr<ModelAPI_Document> PartSetAPI_Part::document() const
44 return std::dynamic_pointer_cast<ModelAPI_ResultPart>(defaultResult())->partDoc();
47 void PartSetAPI_Part::dump(ModelHighAPI_Dumper& theDumper) const
49 FeaturePtr aBase = feature();
50 const std::string& aDocName = theDumper.name(aBase->document());
52 theDumper << aBase << " = model.addPart(" << aDocName << ")" << std::endl;
55 //--------------------------------------------------------------------------------------
56 PartPtr addPart(const std::shared_ptr<ModelAPI_Document> & thePart)
58 std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(PartSetAPI_Part::ID());
60 return PartPtr(new PartSetAPI_Part(aFeature));
63 PartPtr duplicatePart(const ModelHighAPI_Interface& thePart)
66 // only the active part is duplicated, so, activate it
67 FeaturePtr aPartFeature = thePart.feature();
69 // duplication of the current part is performed
70 DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
71 aPartSet->setCurrentFeature(aPartFeature, false);
72 DocumentPtr aPartDoc =
73 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult())->partDoc();
75 ModelAPI_Session::get()->setActiveDocument(aPartDoc);
76 FeaturePtr aDuplicate = aPartDoc->addFeature(PartSetPlugin_Duplicate::ID());
77 //aDuplicate->execute(); // it is executed at creation because it is action
78 FeaturePtr aNewPart = aPartSet->currentFeature(false); // a copy becomes a current
80 aResult = PartPtr(new PartSetAPI_Part(aNewPart));
81 DocumentPtr aNewDoc = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
82 aNewPart->firstResult())->partDoc();
83 ModelAPI_Session::get()->setActiveDocument(aNewDoc);
90 void removePart(const ModelHighAPI_Interface& thePart)
92 FeaturePtr aPartFeature = thePart.feature();
94 // duplication of the current part is performed
95 DocumentPtr aPartSet = ModelAPI_Session::get()->moduleDocument();
96 aPartSet->setCurrentFeature(aPartFeature, false);
97 DocumentPtr aPartDoc =
98 std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult())->partDoc();
100 ModelAPI_Session::get()->setActiveDocument(aPartDoc);
101 aPartDoc->addFeature(PartSetPlugin_Remove::ID());
102 ModelAPI_Session::get()->setActiveDocument(aPartSet);