]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #2909 : Folder becomes empty after "export to GEOM"
authormpv <mpv@opencascade.com>
Wed, 17 Apr 2019 14:29:42 +0000 (17:29 +0300)
committermpv <mpv@opencascade.com>
Wed, 17 Apr 2019 14:29:42 +0000 (17:29 +0300)
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Folder.cpp
src/ModelAPI/ModelAPI_Folder.h
src/PartSet/PartSet_Tools.cpp

index 8b26c6a037303c1185bc42d894fb48f0460d297c..26cb173d5f40d9755eb03ebb65deb3f7f6dc80b3 100644 (file)
@@ -2037,6 +2037,16 @@ void Model_Document::eraseAllFeatures()
     myObjs->eraseAllFeatures();
 }
 
+std::shared_ptr<ModelAPI_Feature> Model_Document::nextFeature(
+  std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse) const
+{
+  if (theCurrent.get() && myObjs) {
+    int anIndex = kUNDEFINED_FEATURE_INDEX;
+    return myObjs->nextFeature(theCurrent, anIndex, theReverse);
+  }
+  return FeaturePtr(); // nothing by default
+}
+
 void Model_Document::setExecuteFeatures(const bool theFlag)
 {
   myExecuteFeatures = theFlag;
index 8778402e0d3d8df692d5035e6ee7a1e624bf17e3..a61cc6ad471266c44c5eb343ca8fbf38278992ed 100644 (file)
@@ -299,6 +299,11 @@ class Model_Document : public ModelAPI_Document
   /// Just removes all features without touching the document data (to be able undo)
   MODEL_EXPORT virtual void eraseAllFeatures();
 
+  /// Returns the next (from the history point of view) feature, any: invisible or disabled
+  /// \param theCurrent previous to the resulting feature
+  /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> nextFeature(
+    std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse = false) const;
 
  protected:
   //! Returns (creates if needed) the general label
index 6e368d7e4e3003e9b53a4dea28cc64e93bb1536a..9cc95bad2be1874f0205d34a714ba8fb5cea26ce 100644 (file)
@@ -253,6 +253,12 @@ public:
   /// Just removes all features without touching the document data (to be able undo)
   MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
 
+  /// Returns the next (from the history point of view) feature, any: invisible or disabled
+  /// \param theCurrent previous to the resulting feature
+  /// \param theReverse if it is true, iterates in reversed order (next becomes previous)
+  MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_Feature> nextFeature(
+    std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theReverse = false) const = 0;
+
 protected:
   //! Only for SWIG wrapping it is here
   MODELAPI_EXPORT ModelAPI_Document();
index df1ac82a6fa30a73ddfde683ec3660d97286a796..439330c9a92637e3a7f47da703eaaf6960eb0015 100644 (file)
@@ -42,3 +42,16 @@ void ModelAPI_Folder::initAttributes()
 void ModelAPI_Folder::execute()
 {
 }
+
+std::shared_ptr<ModelAPI_Feature> ModelAPI_Folder::lastVisibleFeature()
+{
+  FeaturePtr aResult;
+  AttributeReferencePtr aLastFeatAttr = data()->reference(LAST_FEATURE_ID());
+  if (!aLastFeatAttr.get())
+    return aResult;
+  aResult = ModelAPI_Feature::feature(aLastFeatAttr->value());
+  while(aResult.get() && !aResult->isInHistory()) { // searching for previous feature
+    aResult = aResult->document()->nextFeature(aResult, true);
+  }
+  return aResult;
+}
index 7945ff12d1917d13ec3080dc07b63e4f1e30cbf6..1fd19958ee5f8b209069b18b4770424962f5750b 100644 (file)
@@ -92,6 +92,10 @@ public:
     return data()->reference(theID);
   }
 
+  /// Returns the last visible feature in the folder, passing through invisible,
+  /// that may appear as the last ones.
+  MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> lastVisibleFeature();
+
 protected:
   /// This method is called just after creation of the object: it must initialize
   /// all fields, normally initialized in the constructor
index dcd677d5ab4b50b3a20cedcd0c307d4b0913204e..5779d33bb9113104757939211571e46636bbfdc7 100644 (file)
@@ -772,14 +772,10 @@ void PartSet_Tools::getFirstAndLastIndexInFolder(const ObjectPtr& theFolder,
   if (!aFirstFeatureInFolder.get())
     return;
 
-  AttributeReferencePtr aLastFeatAttr =
-    aFolder->data()->reference(ModelAPI_Folder::LAST_FEATURE_ID());
-  if (!aLastFeatAttr.get())
-    return;
-  FeaturePtr aLastFeatureInFolder = ModelAPI_Feature::feature(aLastFeatAttr->value());
+  FeaturePtr aLastFeatureInFolder = aFolder->lastVisibleFeature();
   if (!aLastFeatureInFolder.get())
     return;
 
   theFirst = aDoc->index(aFirstFeatureInFolder);
   theLast = aDoc->index(aLastFeatureInFolder);
-}
\ No newline at end of file
+}