]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make invisible in the tree objects correctly processed: all invisible after the curre...
authormpv <mpv@opencascade.com>
Wed, 13 May 2015 11:34:09 +0000 (14:34 +0300)
committermpv <mpv@opencascade.com>
Wed, 13 May 2015 11:34:09 +0000 (14:34 +0300)
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/ModelAPI/ModelAPI_Document.h
src/PartSet/PartSet_DocumentDataModel.cpp
src/PartSet/PartSet_PartDataModel.cpp

index b5ee4b75bc2d2a5a0f3dcbd8f397c172260b402d..108bb398e4d45d9d173afff6b0f9e9c6eb2e83b8 100644 (file)
@@ -600,7 +600,7 @@ FeaturePtr Model_Document::addFeature(std::string theID)
       static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
       ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent);
       aFeature->setDisabled(false); // by default created feature is enabled
-      setCurrentFeature(aFeature); // after all this feature stays in the document, so make it current
+      setCurrentFeature(aFeature, false); // after all this feature stays in the document, so make it current
     } else { // feature must be executed
        // no creation event => updater not working, problem with remove part
       aFeature->execute();
@@ -703,11 +703,11 @@ void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck*
       }
     }
     // if this feature is current, make the current the previous feature
-    if (theFeature == currentFeature()) {
+    if (theFeature == currentFeature(false)) {
       int aCurrentIndex = index(theFeature);
       if (aCurrentIndex != -1) {
         setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(
-          object(ModelAPI_Feature::group(), aCurrentIndex - 1)));
+          object(ModelAPI_Feature::group(), aCurrentIndex - 1)), false);
       }
     }
 
@@ -965,24 +965,57 @@ int Model_Document::size(const std::string& theGroupID, const bool theHidden)
   return aResult;
 }
 
-std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature()
+std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theVisible)
 {
   TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
   Handle(TDF_Reference) aRef;
   if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
     TDF_Label aLab = aRef->Get();
-    return feature(aLab);
+    FeaturePtr aResult = feature(aLab);
+    if (theVisible) { // get nearest visible (in history) going up
+      int aTag = aLab.Tag();
+      while(aTag > 1 && (!aResult.get() || !aResult->isInHistory())) {
+        aTag--;
+        aLab = aLab.Father().FindChild(aTag);
+        aResult = feature(aLab);
+      }
+      if (aTag <= 1)
+        aResult.reset();
+    }
+    return aResult;
   }
   return std::shared_ptr<ModelAPI_Feature>(); // null feature means the higher than first
 }
 
-void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent)
+void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+  const bool theVisible)
 {
   TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
   if (theCurrent.get()) {
     std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
     if (aData.get()) {
       TDF_Label aFeatureLabel = aData->label().Father();
+      if (theVisible) { // make features below which are not in history also enabled: sketch subs
+        int aTag = aFeatureLabel.Tag();
+        FeaturePtr aNextFeature;
+        TDF_Label aNextLabel;
+        for(aTag++; true; aTag++) {
+          TDF_Label aLabel = aFeatureLabel.Father().FindChild(aTag, 0);
+          if (aLabel.IsNull())
+            break;
+          FeaturePtr aFeature = feature(aLabel);
+          if (aFeature.get()) {
+            if (aFeature->isInHistory())
+              break;
+            aNextFeature = aFeature;
+            aNextLabel = aLabel;
+          }
+        }
+        if (aNextFeature.get()) {
+          theCurrent = aNextFeature;
+          aFeatureLabel = aNextLabel;
+        }
+      }
       Handle(TDF_Reference) aRef;
       if (aRefLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
         aRef->Set(aFeatureLabel);
index 17c14caa9d008bbd060fd664a3a6570b2d63d0be..f190c55dfb811521199fc8081e39f2bf73f63f64 100644 (file)
@@ -136,12 +136,16 @@ class Model_Document : public ModelAPI_Document
 
   //! Returns the feature that is currently edited in this document, normally
   //! this is the latest created feature
+  //! \param theVisible use visible features only: flag is true for Object Browser functionality
   //! \returns null if next created feature must be the first
-  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> currentFeature();
+  MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible);
 
   //! Sets the current feature: all features below will be disabled, new features
   //! will be appended after this one.
-  MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent);
+  //! \param theCurrent the selected feature as current: blow it everythin become disabled
+  //! \param theVisible use visible features only: flag is true for Object Browser functionality
+  MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+    const bool theVisible);
 
   /// Creates a construction cresults
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
index dc43fac414cfa9ec0bfedbaee65c5f225c317394..be7fa566c1fc21d8186ef5d3ca101d33479ff398 100644 (file)
@@ -90,12 +90,16 @@ public:
 
   //! Returns the feature that is currently edited in this document, normally
   //! this is the latest created feature
+  //! \param theVisible use visible features only: flag is true for Object Browser functionality
   //! \returns null if next created feature must be the first
-  virtual std::shared_ptr<ModelAPI_Feature> currentFeature() = 0;
+  virtual std::shared_ptr<ModelAPI_Feature> currentFeature(const bool theVisible) = 0;
 
   //! Sets the current feature: all features below will be disabled, new features
   //! will be appended after this one.
-  virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent) = 0;
+  //! \param theCurrent the selected feature as current: blow it everythin become disabled
+  //! \param theVisible use visible features only: flag is true for Object Browser functionality
+  virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
+    const bool theVisible) = 0;
 
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_Document();
index 5ca4aef6547973b42b75ee6fd5c0081ac67e69e9..74df2229e96f3af191654653bf4d5c74e33c91dd 100644 (file)
@@ -718,7 +718,7 @@ void PartSet_DocumentDataModel::clear()
 int PartSet_DocumentDataModel::lastHistoryRow() const
 {
   DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
-  FeaturePtr aFeature = aRootDoc->currentFeature();
+  FeaturePtr aFeature = aRootDoc->currentFeature(true);
   if (aFeature.get())
     return historyOffset() + aRootDoc->index(aFeature);
   else 
@@ -733,11 +733,11 @@ void PartSet_DocumentDataModel::setLastHistoryItem(const QModelIndex& theIndex)
   if (theIndex.internalId() == HistoryNode) {
     ObjectPtr aObject = object(theIndex);
     aMgr->startOperation(aOpName);
-    aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+    aRootDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject), true);
     aMgr->finishOperation();
   } else {
     aMgr->startOperation(aOpName);
-    aRootDoc->setCurrentFeature(FeaturePtr());
+    aRootDoc->setCurrentFeature(FeaturePtr(), true);
     aMgr->finishOperation();
   }
 }
index 1ad039559bc62c4dbb2b65b00f71acfd027d6641..e9d378c300da8f71431734500e95268de7d1baaa 100644 (file)
@@ -573,7 +573,7 @@ int PartSet_PartDataModel::getRowsNumber() const
 int PartSet_PartDataModel::lastHistoryRow() const
 {
   DocumentPtr aDoc = partDocument();
-  FeaturePtr aFeature = aDoc->currentFeature();
+  FeaturePtr aFeature = aDoc->currentFeature(true);
   if (aFeature.get())
     return getRowsNumber() + aDoc->index(aFeature);
   else
@@ -588,11 +588,11 @@ void PartSet_PartDataModel::setLastHistoryItem(const QModelIndex& theIndex)
   if (theIndex.internalId() == HistoryObject) {
     ObjectPtr aObject = object(theIndex);
     aMgr->startOperation(aOpName);
-    aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject));
+    aDoc->setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aObject), true);
     aMgr->finishOperation();
   } else {
     aMgr->startOperation(aOpName);
-    aDoc->setCurrentFeature(FeaturePtr());
+    aDoc->setCurrentFeature(FeaturePtr(), true);
     aMgr->finishOperation();
   }
 }