]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
authornds <natalia.donis@opencascade.com>
Fri, 20 Feb 2015 10:24:08 +0000 (13:24 +0300)
committernds <natalia.donis@opencascade.com>
Fri, 20 Feb 2015 10:24:08 +0000 (13:24 +0300)
src/Model/Model_Document.cpp
src/ModelAPI/ModelAPI_CompositeFeature.h
src/SketchPlugin/SketchPlugin_Feature.h
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h

index 762dff5fa852d28b61d29b066954bba52def6e91..b6221cc4c38004413759c2e6f404f4babe9e3bb5 100644 (file)
@@ -419,8 +419,11 @@ bool Model_Document::isModified()
 
 bool Model_Document::canUndo()
 {
-  if (myDoc->GetAvailableUndos() > 0 && (myNestedNum.empty() || *myNestedNum.rbegin() != 0) &&
-      !myTransactions.empty() /* for omitting the first useless transaction */)
+  // issue 406 : if transaction is opened, but nothing to undo behind, can not undo
+  int aCurrentNum = isOperation() ? 1 : 0;
+  if (myDoc->GetAvailableUndos() > 0 && 
+      (myNestedNum.empty() || *myNestedNum.rbegin() - aCurrentNum > 0) && // there is something to undo in nested
+      myTransactions.size() - aCurrentNum > 0 /* for omitting the first useless transaction */)
     return true;
   // check other subs contains operation that can be undoed
   const std::set<std::string> aSubs = subDocuments(true);
@@ -651,17 +654,32 @@ void Model_Document::removeFeature(FeaturePtr theFeature/*, const bool theCheck*
       myObjs.UnBind(aFeatureLabel);
     else
       return;  // not found feature => do not remove
+
+    // 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);
+    std::set<std::shared_ptr<ModelAPI_Feature> >::iterator aRefIter = aRefs.begin();
+    for(; aRefIter != aRefs.end(); aRefIter++) {
+      std::shared_ptr<ModelAPI_CompositeFeature> aComposite = 
+        std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aRefIter);
+      if (aComposite.get()) {
+        aComposite->removeFeature(theFeature);
+      }
+    }
+
     // erase fields
     theFeature->erase();
+    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
     aFeatureLabel.ForgetAllAttributes();
     // remove it from the references array
     if (theFeature->isInHistory()) {
       RemoveFromRefArray(featuresLabel(), aFeatureLabel);
     }
+    // event: feature is deleted
+    ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
   }
-  // event: feature is deleted
-  ModelAPI_EventCreator::get()->sendDeleted(theFeature->document(), ModelAPI_Feature::group());
 }
 
 FeaturePtr Model_Document::feature(TDF_Label& theLabel) const
index df78236d98e2a124d40c7ad632fb35e559821329..f243cb3338bec21e2e6728846c097efc249f054b 100644 (file)
@@ -35,6 +35,10 @@ public:
 
   /// Returns true if feature or reuslt belong to this composite feature as subs
   virtual bool isSub(ObjectPtr theObject) const = 0;
+
+  /// This method to inform that sub-feature is removed and must be removed from the internal data
+  /// structures of the owner (the remove from the document will be done outside just after)
+  virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature) = 0;
 };
 
 //! Pointer on the composite feature object
index 248f19c7b8db3f747478b18fc9194377c2935024..076b1d038f3f5456a92aef3b17fc5ef6a66bf932 100644 (file)
@@ -100,16 +100,6 @@ class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
       thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
   }
 
-  /// removes also all sub-sketch elements
-  SKETCHPLUGIN_EXPORT virtual void erase()
-  {
-    /*SketchPlugin_Sketch* aSketch = sketch();
-    if (aSketch)
-      aSketch->removeFeature(this);
-      */
-    ModelAPI_Feature::erase();
-  }
-
   /// Returns the sketch of this feature
   SketchPlugin_Sketch* sketch();
 protected:
index 67fd1be899f23b7c4835f135abe87ed7b749f1b7..624ac16ab6d48455065bc0c226959764e7b0483a 100644 (file)
@@ -133,7 +133,7 @@ std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string th
   return aNew;
 }
 
-void SketchPlugin_Sketch::removeFeature(ModelAPI_Feature* theFeature)
+void SketchPlugin_Sketch::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
 {
   if (!data().get()) // sketch is already removed (case on undo of sketch), sync is not needed
     return;
@@ -143,7 +143,7 @@ void SketchPlugin_Sketch::removeFeature(ModelAPI_Feature* theFeature)
   bool aHasEmtpyFeature = false;
   for(; aSubIt != aLastIt && !isRemoved; aSubIt++) {
     std::shared_ptr<ModelAPI_Feature> aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aSubIt);
-    if (aFeature.get() != NULL && aFeature.get() == theFeature) {
+    if (aFeature.get() != NULL && aFeature == theFeature) {
       data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(aFeature);
       isRemoved = true;
     }
index f6978b6ab16b1f15045f6d8c8ba2750e98bb3fd5..c4721f547bfb114dbd7d50a0f6d9c948d3d4b966 100644 (file)
@@ -114,8 +114,8 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I
   /// appends a feature to the sketch sub-elements container
   SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
 
-  /// appends a feature from the sketch sub-elements container
-  SKETCHPLUGIN_EXPORT virtual void removeFeature(ModelAPI_Feature* theFeature);
+  /// Just to synchronise the container of sub-features
+  virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
 
   /// Returns the number of sub-elements
   SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;