Salome HOME
SetCurrentFeature in resumeOperation(). It should be improved by moving this call...
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
index ff49f71454cfc80d42835df98295220ff4ca8d28..82f6db270ae09966b8bd19e8afebe9fb66d37598 100755 (executable)
@@ -26,6 +26,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
 
 #include <GeomAPI_Pnt2d.h>
 
@@ -72,6 +73,63 @@ bool ModuleBase_OperationFeature::isValid() const
   return aValid && isDone;
 }
 
+void ModuleBase_OperationFeature::startOperation()
+{
+  FeaturePtr aFeature = feature();
+  if (!aFeature.get() || !isEditOperation())
+    return;
+
+  myVisualizedObjects.clear();
+  // store hidden result features
+  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr>::const_iterator aIt;
+  for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+    ObjectPtr anObject = *aIt;
+    if (anObject.get() && !anObject->isDisplayed()) {
+      myVisualizedObjects.insert(*aIt);
+      anObject->setDisplayed(true);
+    }
+  }
+  if (!aFeature->isDisplayed()) {
+    myVisualizedObjects.insert(aFeature);
+    aFeature->setDisplayed(true);
+  }
+  Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
+void ModuleBase_OperationFeature::stopOperation()
+{
+  FeaturePtr aFeature = feature();
+  if (!aFeature.get() || !isEditOperation())
+    return;
+
+  // store hidden result features
+  std::list<ResultPtr> aResults = aFeature->results();
+  std::list<ResultPtr>::const_iterator aIt;
+  for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
+    ObjectPtr anObject = *aIt;
+    if (anObject.get() && myVisualizedObjects.find(anObject) != myVisualizedObjects.end()) {
+      anObject->setDisplayed(false);
+    }
+  }
+  if (myVisualizedObjects.find(aFeature) != myVisualizedObjects.end()) {
+    aFeature->setDisplayed(false);
+  }
+  aFeature->setStable(true);
+  if (myVisualizedObjects.size() > 0)
+    Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
+void ModuleBase_OperationFeature::resumeOperation()
+{
+  ModuleBase_Operation::resumeOperation();
+  //if (!myIsEditing)
+    setCurrentFeature(feature());
+  //SessionPtr aMgr = ModelAPI_Session::get();
+  //DocumentPtr aDoc = aMgr->activeDocument();
+  //aDoc->setCurrentFeature(feature(), false);
+}
+
 FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage)
 {
   if (myParentFeature.get()) {
@@ -100,6 +158,7 @@ FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage
 void ModuleBase_OperationFeature::setFeature(FeaturePtr theFeature)
 {
   myFeature = theFeature;
+  myFeature->setStable(false);
   myIsEditing = true;
 }
 
@@ -119,6 +178,11 @@ bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const
   return false;
 }
 
+bool ModuleBase_OperationFeature::isDisplayedOnStart(ObjectPtr theObject)
+{
+  return myVisualizedObjects.find(theObject) != myVisualizedObjects.end();
+}
+
 void ModuleBase_OperationFeature::start()
 {
   setIsModified(false);
@@ -145,7 +209,15 @@ void ModuleBase_OperationFeature::start()
   if (myIsEditing) {
     SessionPtr aMgr = ModelAPI_Session::get();
     DocumentPtr aDoc = aMgr->activeDocument();
-    myCurrentFeature = aDoc->currentFeature(true);
+    // the parameter of current feature should be false, we should use all feature, not only visible
+    // in order to correctly save the previous feature of the nested operation, where the
+    // features can be not visible in the tree. The problem case is Edit sketch entitity(line)
+    // in the Sketch, created in ExtrusionCut operation. The entity disappears by commit.
+    // When sketch entity operation started, the sketch should be cashed here as the current.
+    // Otherwise(the flag is true), the ExtrusionCut is cashed, when commit happens, the sketch
+    // is disabled, sketch entity is disabled as extrusion cut is created earliest then sketch.
+    // As a result the sketch disappears from the viewer. However after commit it is displayed back.
+    myPreviousCurrentFeature = aDoc->currentFeature(false);
     aDoc->setCurrentFeature(feature(), false);
   }
 
@@ -177,17 +249,14 @@ void ModuleBase_OperationFeature::abort()
     bool aIsOp = aMgr->isOperation();
     if (!aIsOp)
       aMgr->startOperation();
-    aDoc->setCurrentFeature(myCurrentFeature, true);
+    aDoc->setCurrentFeature(myPreviousCurrentFeature, false);//true);
     if (!aIsOp)
       aMgr->finishOperation();
-    myCurrentFeature = FeaturePtr();
+    myPreviousCurrentFeature = FeaturePtr();
   }
   abortOperation();
 
   stopOperation();
-  // is is necessary to deactivate current widgets before the model operation is aborted
-  // because abort removes the feature and activated filters should not check it
-  propertyPanel()->cleanContent();
 
   aMgr->abortOperation();
   emit stopped();
@@ -215,15 +284,24 @@ bool ModuleBase_OperationFeature::commit()
 
     SessionPtr aMgr = ModelAPI_Session::get();
     /// Set current feature and remeber old current feature
+
     if (myIsEditing) {
-      DocumentPtr aDoc = aMgr->activeDocument();
+      setCurrentFeature(myPreviousCurrentFeature);
+      /*DocumentPtr aDoc = aMgr->activeDocument();
       bool aIsOp = aMgr->isOperation();
       if (!aIsOp)
         aMgr->startOperation();
-      aDoc->setCurrentFeature(myCurrentFeature, true);
+      aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
       if (!aIsOp)
-        aMgr->finishOperation();
-      myCurrentFeature = FeaturePtr();
+        aMgr->finishOperation();*/
+      myPreviousCurrentFeature = FeaturePtr();
+    }
+    else {
+      /*CompositeFeaturePtr aCompositeFeature = ModelAPI_Tools::compositeOwner(feature());
+      if (aCompositeFeature.get())
+        setCurrentFeature(aCompositeFeature);//myPreviousCurrentFeature);
+      //else
+      //  setCurrentFeature(feature());*/
     }
     commitOperation();
     aMgr->finishOperation();
@@ -238,6 +316,18 @@ bool ModuleBase_OperationFeature::commit()
   return false;
 }
 
+void ModuleBase_OperationFeature::setCurrentFeature(const FeaturePtr& theFeature)
+{
+  SessionPtr aMgr = ModelAPI_Session::get();
+  DocumentPtr aDoc = aMgr->activeDocument();
+  bool aIsOp = aMgr->isOperation();
+  if (!aIsOp)
+    aMgr->startOperation();
+  aDoc->setCurrentFeature(theFeature, false);//true);
+  if (!aIsOp)
+    aMgr->finishOperation();
+}
+
 void ModuleBase_OperationFeature::activateByPreselection()
 {
   if (myPreSelection.empty())
@@ -347,9 +437,9 @@ void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* th
     // 4. activate the first obligatory widget
     theProp->activateNextWidget(NULL);
   }
-}
-
-bool ModuleBase_OperationFeature::isGranted(QString theId) const
-{
-  return myNestedFeatures.contains(theId);
+  else {
+    // set focus on Ok button in order to operation manager could process Enter press
+    if (theProp)
+      theProp->setFocusOnOkButton();
+  }
 }