]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for removing sketch and sub-components not correct history position was defined
authormpv <mpv@opencascade.com>
Tue, 26 May 2015 12:46:01 +0000 (15:46 +0300)
committermpv <mpv@opencascade.com>
Tue, 26 May 2015 12:46:01 +0000 (15:46 +0300)
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_Objects.cpp
src/Model/Model_Session.cpp
src/Model/Model_Update.cpp
src/ModelAPI/ModelAPI_Document.h
src/ModelAPI/ModelAPI_Feature.cpp

index 0d35b4533b38d851d93a1bd76261738d40d90746..a554fd5994a88b7d0318db65defda9fc16e92280 100644 (file)
@@ -171,8 +171,7 @@ bool Model_Document::load(const char* theFileName, DocumentPtr theThis)
     setCurrentFeature(currentFeature(false), false);
     aSession->setCheckTransactions(true);
     aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false);
-    // this is done in Part result "activate", so no needed here. Causes not-blue active part.
-    //aSession->setActiveDocument(anApp->getDocument(myID), true); 
+    aSession->setActiveDocument(anApp->getDocument(myID), true);
   }
   return !isError;
 }
@@ -566,11 +565,6 @@ void Model_Document::refsToFeature(FeaturePtr theFeature,
 
 void Model_Document::removeFeature(FeaturePtr theFeature)
 {
-  // if this feature is current, make the current the previous feature
-  if (theFeature == currentFeature(false)) {
-    FeaturePtr aPrev = myObjs->nextFeature(theFeature, true);
-    setCurrentFeature(aPrev, false);
-  }
   myObjs->removeFeature(theFeature);
 }
 
@@ -721,6 +715,15 @@ void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurr
   aLoop->flush(aRedispEvent);
 }
 
+void Model_Document::setCurrentFeatureUp()
+{
+  FeaturePtr aCurrent = currentFeature(false);
+  if (aCurrent.get()) { // if not, do nothing because null is the upper
+    FeaturePtr aPrev = myObjs->nextFeature(aCurrent, true);
+    setCurrentFeature(aPrev, false);
+  }
+}
+
 TDF_Label Model_Document::generalLabel() const
 {
   return myDoc->Main().FindChild(TAG_GENERAL);
index 127934e03f201519a994a428b089d96876634b1b..7969d17245c4cd08aa59da983961a659f73d09dc 100644 (file)
@@ -133,6 +133,9 @@ class Model_Document : public ModelAPI_Document
   MODEL_EXPORT virtual void setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurrent,
     const bool theVisible);
 
+  //! Makes the current feature one feature upper
+  MODEL_EXPORT virtual void setCurrentFeatureUp();
+
   /// Creates a construction cresults
   MODEL_EXPORT virtual std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
index 9ebc1e4d8ae617241b5a107657cc1ed2af931804..9ca1a15d4f740d66d1b97ff878a7e1ded76c9136 100644 (file)
@@ -203,14 +203,7 @@ void Model_Objects::refsToFeature(FeaturePtr theFeature,
 void Model_Objects::removeFeature(FeaturePtr theFeature)
 {
   std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theFeature->data());
-  if (aData) {
-    TDF_Label aFeatureLabel = aData->label().Father();
-    if (myFeatures.IsBound(aFeatureLabel))
-      myFeatures.UnBind(aFeatureLabel);
-    else
-      return;  // not found feature => do not remove
-
-    clearHistory(theFeature);
+  if (aData && aData->isValid()) {
     // checking that the sub-element of composite feature is removed: if yes, inform the owner
     std::set<std::shared_ptr<ModelAPI_Feature> > aRefs;
     refsToFeature(theFeature, aRefs, false);
@@ -224,6 +217,13 @@ void Model_Objects::removeFeature(FeaturePtr theFeature)
     }
     // erase fields
     theFeature->erase();
+
+    TDF_Label aFeatureLabel = aData->label().Father();
+    if (myFeatures.IsBound(aFeatureLabel))
+      myFeatures.UnBind(aFeatureLabel);
+
+    clearHistory(theFeature);
+
     static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
     ModelAPI_EventCreator::get()->sendUpdated(theFeature, EVENT_DISP);
     // erase all attributes under the label of feature
@@ -834,7 +834,7 @@ ResultPtr Model_Objects::findByName(const std::string theName)
 FeaturePtr Model_Objects::nextFeature(FeaturePtr theCurrent, const bool theReverse)
 {
   std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
-  if (aData) {
+  if (aData && aData->isValid()) {
     TDF_Label aFeatureLabel = aData->label().Father();
     Handle(TDataStd_ReferenceArray) aRefs;
     if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
index d5a79927c9eb78537dc0d221989490297776fc4d..04229f2c2257af2b46404547d8a463d4c23fe384 100644 (file)
@@ -49,7 +49,6 @@ bool Model_Session::save(const char* theFileName, std::list<std::string>& theRes
 void Model_Session::closeAll()
 {
   Model_Application::getApplication()->deleteAllDocuments();
-  //ROOT_DOC->close(true);
 }
 
 void Model_Session::startOperation(const std::string& theId)
index e710c5a876693c6ce87fee66ec6aa5769621e1a2..08a7d4097feabb6af6c8341c5a88771aa9bdb32b 100644 (file)
@@ -413,10 +413,11 @@ void Model_Update::updateFeature(FeaturePtr theFeature)
         if (std::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
             !theFeature->isPersistentResult()) {
           if (aFactory->validate(theFeature)) {
+            FeaturePtr aCurrent = theFeature->document()->currentFeature(false);
             if (myIsAutomatic || !theFeature->isPersistentResult() /* execute quick, not persistent results */
                 || (isUpdated(theFeature) && 
-                     (theFeature == theFeature->document()->currentFeature(false) || 
-                      theFeature->document()->currentFeature(false)->isMacro()))) // currently edited
+                     (theFeature == aCurrent || 
+                      (aCurrent.get() && aCurrent->isMacro())))) // currently edited
             {
               if (aState == ModelAPI_StateDone || aState == ModelAPI_StateMustBeUpdated) {
                 executeFeature(theFeature);
index 72a69e045c7bd51434f2f110a952521b9f2c08ef..5f344ea085160b4f18000328183db249ea526a73 100644 (file)
@@ -99,6 +99,8 @@ public:
   //! \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;
+  //! Makes the current feature one feature upper
+  virtual void setCurrentFeatureUp() = 0;
 
   /// To virtually destroy the fields of successors
   MODELAPI_EXPORT virtual ~ModelAPI_Document();
index 1fe0244f0d91aa4a654cf10bdf77d4a00668f4f3..ba51db2605a72c83429296ed85b6c782ddacf759 100644 (file)
@@ -117,6 +117,11 @@ const std::string& ModelAPI_Feature::documentToAdd()
 
 void ModelAPI_Feature::erase()
 {
+  // if this is the current feature, make the upper feature as current before removing
+  if (document().get() && document()->currentFeature(false).get() == this) {
+    document()->setCurrentFeatureUp();
+  }
+
   static Events_Loop* aLoop = Events_Loop::loop();
   static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();