Salome HOME
Fixes for issue #1956 and issue #2104 : correctly remove features on part remove.
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Remove.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSetPlugin_Remove.cxx
4 // Created:     20 May 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "PartSetPlugin_Remove.h"
8 #include "PartSetPlugin_Part.h"
9
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>
18
19 #include <Events_Loop.h>
20
21 void PartSetPlugin_Remove::execute()
22 {
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);
27   if (aPart.get()) {
28     FeaturePtr aFeature = aRoot->feature(aPart);
29     if (aFeature) {
30       // do remove, but don't do real close (features are erased without persistence changes
31       // document remove may be undoed)
32       // aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
33       std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
34       aRoot->refsToFeature(aFeature, aRefFeatures);
35       if (aRefFeatures.empty()) {
36         aRoot->removeFeature(aFeature);
37         // the redisplay signal should be flushed in order to erase the feature presentation
38         // in the viewer after removeFeature from the document
39         Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
40       }
41     }
42   }
43 }