1 // Copyright (C) 2014-2019 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
20 #include "PartSetPlugin_Remove.h"
21 #include "PartSetPlugin_Part.h"
23 #include <ModelAPI_Document.h>
24 #include <ModelAPI_Data.h>
25 #include <ModelAPI_AttributeDocRef.h>
26 #include <ModelAPI_ResultPart.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Tools.h>
30 #include <ModelAPI_Events.h>
32 #include <Events_Loop.h>
34 void PartSetPlugin_Remove::execute()
36 std::shared_ptr<ModelAPI_Session> aPManager = ModelAPI_Session::get();
37 std::shared_ptr<ModelAPI_Document> aRoot = aPManager->moduleDocument();
38 DocumentPtr aThisDoc = document();
39 ResultPtr aPart = ModelAPI_Tools::findPartResult(aRoot, aThisDoc);
41 FeaturePtr aFeature = aRoot->feature(aPart);
43 // do remove, but don't do real close (features are erased without persistence changes
44 // document remove may be undoed)
45 // aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
46 std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
47 aRoot->refsToFeature(aFeature, aRefFeatures);
48 if (aRefFeatures.empty()) {
49 aRoot->removeFeature(aFeature);
50 // the redisplay signal should be flushed in order to erase the feature presentation
51 // in the viewer after removeFeature from the document
52 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));