1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSetPlugin_Remove.cxx
4 // Created: 20 May 2014
5 // Author: Mikhail PONIKAROV
7 #include "PartSetPlugin_Remove.h"
8 #include "PartSetPlugin_Part.h"
10 #include <ModelAPI_Document.h>
11 #include <ModelAPI_Data.h>
12 #include <ModelAPI_AttributeDocRef.h>
13 #include <ModelAPI_ResultPart.h>
14 #include <ModelAPI_Session.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Tools.h>
17 #include <ModelAPI_Events.h>
19 #include <Events_Loop.h>
21 void PartSetPlugin_Remove::execute()
23 std::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
24 std::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
25 DocumentPtr aThisDoc = document();
26 ResultPtr aPart = ModelAPI_Tools::findPartResult(aRoot, aThisDoc);
28 FeaturePtr aFeature = aRoot->feature(aPart);
31 aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
32 std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
33 aRoot->refsToFeature(aFeature, aRefFeatures);
34 if (aRefFeatures.empty()) {
35 aRoot->removeFeature(aFeature);
36 // the redisplay signal should be flushed in order to erase the feature presentation
37 // in the viewer after removeFeature from the document
38 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));