Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / PartSetPlugin / PartSetPlugin_Remove.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "PartSetPlugin_Remove.h"
22 #include "PartSetPlugin_Part.h"
23
24 #include <ModelAPI_Document.h>
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_AttributeDocRef.h>
27 #include <ModelAPI_ResultPart.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_Tools.h>
31 #include <ModelAPI_Events.h>
32
33 #include <Events_Loop.h>
34
35 void PartSetPlugin_Remove::execute()
36 {
37   std::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
38   std::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
39   DocumentPtr aThisDoc = document();
40   ResultPtr aPart = ModelAPI_Tools::findPartResult(aRoot, aThisDoc);
41   if (aPart.get()) {
42     FeaturePtr aFeature = aRoot->feature(aPart);
43     if (aFeature) {
44       // do remove, but don't do real close (features are erased without persistence changes
45       // document remove may be undoed)
46       // aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
47       std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
48       aRoot->refsToFeature(aFeature, aRefFeatures);
49       if (aRefFeatures.empty()) {
50         aRoot->removeFeature(aFeature);
51         // the redisplay signal should be flushed in order to erase the feature presentation
52         // in the viewer after removeFeature from the document
53         Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
54       }
55     }
56   }
57 }