]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fixes for issue #1956 and issue #2104 : correctly remove features on part remove.
authormpv <mpv@opencascade.com>
Thu, 6 Apr 2017 07:53:12 +0000 (10:53 +0300)
committermpv <mpv@opencascade.com>
Thu, 6 Apr 2017 07:53:30 +0000 (10:53 +0300)
src/Model/Model_Objects.cpp
src/Model/Model_ResultPart.cpp
src/ModelAPI/ModelAPI_Feature.cpp
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/PartSetPlugin/PartSetPlugin_Remove.cpp
src/XGUI/XGUI_DataModel.cpp

index b0964875d73c03b3de14be09f3ee13e0f217bcc9..949f99b927d30c4a2cd4e9f2b4e309d240d3c41a 100644 (file)
@@ -271,7 +271,28 @@ void Model_Objects::removeFeature(FeaturePtr theFeature)
 
 void Model_Objects::eraseAllFeatures()
 {
-  ModelAPI_EventCreator::get()->sendDeleted(myDoc, ModelAPI_Feature::group());
+  static Events_ID kDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+  static const ModelAPI_EventCreator* kCreator = ModelAPI_EventCreator::get();
+  // make all features invalid (like deleted)
+  NCollection_DataMap<TDF_Label, FeaturePtr>::Iterator aFIter(myFeatures);
+  for(; aFIter.More(); aFIter.Next()) {
+    FeaturePtr aFeature = aFIter.Value();
+    std::list<ResultPtr> aResList;
+    ModelAPI_Tools::allResults(aFeature, aResList);
+    std::list<ResultPtr>::iterator aRIter = aResList.begin();
+    for(; aRIter != aResList.end(); aRIter++) {
+      ResultPtr aRes = *aRIter;
+      if (aRes && aRes->data()->isValid()) {
+        kCreator->sendDeleted(myDoc, aRes->groupName());
+        kCreator->sendUpdated(aRes, kDispEvent);
+        aRes->setData(aRes->data()->invalidPtr());
+
+      }
+    }
+    kCreator->sendUpdated(aFeature, kDispEvent);
+    aFeature->setData(aFeature->data()->invalidPtr());
+  }
+  kCreator->sendDeleted(myDoc, ModelAPI_Feature::group());
   myFeatures.Clear(); // just remove features without modification of DS
   updateHistory(ModelAPI_Feature::group());
 }
index d067868692f3cc37314523c448165cbd02fb313c..2beb5f56213aa4cfca6d278abfa126cf349aa37c 100644 (file)
@@ -177,7 +177,7 @@ std::shared_ptr<GeomAPI_Shape> Model_ResultPart::shape()
         for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) {
           ResultPtr aBody = std::dynamic_pointer_cast<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
           // "object" method filters out disabled and concealed anyway, so don't check
-          if (aBody.get() && aBody->shape().get()) {
+          if (aBody.get() && aBody->data()->isValid() && aBody->shape().get()) {
             TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
             if (!aShape.IsNull()) {
               aBuilder.Add(aResultComp, aShape);
index f83cf00a8d379592e284ec204e0c3e67f347156d..783a33009aad74bc691036c462a3916d6122854b 100644 (file)
@@ -167,7 +167,8 @@ void ModelAPI_Feature::erase()
 
 ModelAPI_Feature::~ModelAPI_Feature()
 {
-  erase();
+  if (data() && data()->isValid())
+    erase();
 }
 
 FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject)
index df8b645109bd5d87b6315a15134a99cb5bc9ac66..97100e89b9c49d3a2062ddaf7baaae1dc474ca34 100644 (file)
@@ -112,7 +112,8 @@ void PartSetPlugin_Part::erase() {
   ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
   if (aResult.get()) {
     DocumentPtr aDoc = aResult->partDoc();
-    aDoc->eraseAllFeatures();
+    if (aDoc.get())
+      aDoc->eraseAllFeatures();
   }
   ModelAPI_Feature::erase();
 }
index bf54347099a38c2871a30476577c9ceae6537846..7bc6f3a1cc358ce8a59614e256de426aadd7c648 100644 (file)
@@ -27,8 +27,9 @@ void PartSetPlugin_Remove::execute()
   if (aPart.get()) {
     FeaturePtr aFeature = aRoot->feature(aPart);
     if (aFeature) {
-      // do remove
-      aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
+      // do remove, but don't do real close (features are erased without persistence changes
+      // document remove may be undoed)
+      // aPart->data()->document(ModelAPI_ResultPart::DOC_REF())->value()->close();
       std::set<std::shared_ptr<ModelAPI_Feature> > aRefFeatures;
       aRoot->refsToFeature(aFeature, aRefFeatures);
       if (aRefFeatures.empty()) {
index 88fb28eeb6c6eff05766fad8028f74dd1611e778..2eef35a764ad3cc07869240ddb8a9d30aadfbfa4 100644 (file)
@@ -644,11 +644,7 @@ QModelIndex XGUI_DataModel::index(int theRow, int theColumn, const QModelIndex &
           } else {
             // this is an object under sub document root
             std::string aType = myXMLReader->subType();
-            int aCount = theRow - aNbSubFolders;
-            // To check number of objects before using
-            if (aSubDoc->size(aType) <= aCount)
-              return QModelIndex();
-            ObjectPtr aObj = aSubDoc->object(aType, aCount);
+            ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
             aIndex = objectIndex(aObj);
           }
         } else {