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 "PartSetPlugin_Part.h"
21 #include "ModelAPI_Session.h"
22 #include "ModelAPI_Document.h"
23 #include "ModelAPI_Data.h"
24 #include "ModelAPI_AttributeDocRef.h"
25 #include <ModelAPI_ResultPart.h>
26 #include <ModelAPI_Events.h>
28 PartSetPlugin_Part::PartSetPlugin_Part()
32 void PartSetPlugin_Part::initAttributes()
33 { // all is in part result
36 void PartSetPlugin_Part::execute()
38 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
40 aResult = document()->createPart(data());
42 // do not activate part by simple execution if it is not loaded yet: it must be explicitly
44 if (!ModelAPI_Session::get()->isLoadByDemand(aResult->data()->name())) {
45 // On undo/redo creation of the part result the Object Browser must get creation event
46 // earlier that activation of this part event (otherwise the crash is produced)
47 // So, send a creation event earlier, without any grouping
48 static Events_ID aCreateID = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
49 ModelAPI_EventCreator::get()->sendUpdated(aResult, aCreateID, false);
53 } else { // execute is called for result update anyway
54 aResult->updateShape();
58 const std::string& PartSetPlugin_Part::documentToAdd()
60 // part must be added only to the module document
61 return ModelAPI_Session::get()->moduleDocument()->kind();
64 std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::addFeature(std::string theID)
66 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
68 DocumentPtr aDoc = aResult->partDoc();
69 if (aDoc.get() && aDoc->isOpened())
70 return aDoc->addFeature(theID);
75 int PartSetPlugin_Part::numberOfSubs(bool forTree) const
77 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
79 DocumentPtr aDoc = aResult->partDoc();
80 if (aDoc.get() && aDoc->isOpened())
81 return aDoc->numInternalFeatures();
86 std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex, bool forTree)
88 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
90 DocumentPtr aDoc = aResult->partDoc();
91 if (aDoc.get() && aDoc->isOpened()) {
92 return aDoc->internalFeature(theIndex);
98 int PartSetPlugin_Part::subFeatureId(const int theIndex) const
100 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
102 DocumentPtr aDoc = aResult->partDoc();
103 if (aDoc.get() && aDoc->isOpened()) {
104 return aDoc->object(ModelAPI_Feature::group(), theIndex)->data()->featureId();
110 bool PartSetPlugin_Part::isSub(ObjectPtr theObject) const
112 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
114 DocumentPtr aDoc = aResult->partDoc();
115 return theObject->document() == aDoc;
120 void PartSetPlugin_Part::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
124 void PartSetPlugin_Part::erase() {
125 ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
127 DocumentPtr aDoc = aResult->partDoc();
129 aDoc->eraseAllFeatures();
131 ModelAPI_Feature::erase();