Salome HOME
1. Create->Edit->Create is realized as 2 transaction: for the first pair the setEditO...
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
index 797f9e2ab19cfd0b2fba3a76fc3506a6e9a8ff9c..5ac197114f7e6bbf4233c31c94cd08edce8b037f 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>
 
@@ -48,6 +49,15 @@ ModuleBase_OperationFeature::~ModuleBase_OperationFeature()
   clearPreselection();
 }
 
+void ModuleBase_OperationFeature::setEditOperation()
+{
+  if (isEditOperation())
+    return;
+
+  myIsEditing = true;
+  propertyPanel()->setEditingMode(isEditOperation());
+}
+
 FeaturePtr ModuleBase_OperationFeature::feature() const
 {
   return myFeature;
@@ -72,6 +82,55 @@ bool ModuleBase_OperationFeature::isValid() const
   return aValid && isDone;
 }
 
+void ModuleBase_OperationFeature::startOperation()
+{
+  FeaturePtr aFeature = feature();
+  if (!aFeature.get() || !isEditOperation())
+    return;
+
+  if (aFeature.get() && isEditOperation())
+    aFeature->setStable(false);
+
+  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);
+  }
+  if (myVisualizedObjects.size() > 0)
+    Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
+}
+
 FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage)
 {
   if (myParentFeature.get()) {
@@ -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);
@@ -128,6 +192,7 @@ void ModuleBase_OperationFeature::start()
   }
   ModelAPI_Session::get()->startOperation(anId.toStdString());
 
+  emit beforeStarted();
   startOperation();
 
   if (!myIsEditing) {
@@ -141,29 +206,15 @@ void ModuleBase_OperationFeature::start()
       return;
     }
   }
-  /// Set current feature and remeber old current feature
-  if (myIsEditing) {
-    SessionPtr aMgr = ModelAPI_Session::get();
-    DocumentPtr aDoc = aMgr->activeDocument();
-    // 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);
-  }
-
-  startOperation();
+  //Already called startOperation();
   emit started();
 
 }
 
 void ModuleBase_OperationFeature::abort()
 {
+  emit beforeAborted();
+
   // the viewer update should be blocked in order to avoid the features blinking before they are
   // hidden
   std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
@@ -179,26 +230,12 @@ void ModuleBase_OperationFeature::abort()
   if (aPropertyPanel)
     aPropertyPanel->cleanContent();
 
-  SessionPtr aMgr = ModelAPI_Session::get();
-  if (myIsEditing) {
-    DocumentPtr aDoc = aMgr->activeDocument();
-    bool aIsOp = aMgr->isOperation();
-    if (!aIsOp)
-      aMgr->startOperation();
-    aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
-    if (!aIsOp)
-      aMgr->finishOperation();
-    myPreviousCurrentFeature = FeaturePtr();
-  }
-  abortOperation();
+  myFeature->setStable(true);
 
+  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
-  if (aPropertyPanel) { // feature may be not created (plugin load fail)
-    aPropertyPanel->cleanContent();
-  }
 
+  SessionPtr aMgr = ModelAPI_Session::get();
   aMgr->abortOperation();
   emit stopped();
   // the viewer update should be unblocked in order to avoid the features blinking before they are
@@ -222,19 +259,13 @@ bool ModuleBase_OperationFeature::commit()
     ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
     if (aPropertyPanel)
       aPropertyPanel->cleanContent();
+    
+    myFeature->setStable(true);
 
     SessionPtr aMgr = ModelAPI_Session::get();
     /// Set current feature and remeber old current feature
-    if (myIsEditing) {
-      DocumentPtr aDoc = aMgr->activeDocument();
-      bool aIsOp = aMgr->isOperation();
-      if (!aIsOp)
-        aMgr->startOperation();
-      aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
-      if (!aIsOp)
-        aMgr->finishOperation();
-      myPreviousCurrentFeature = FeaturePtr();
-    }
+
+    emit beforeCommitted();
     commitOperation();
     aMgr->finishOperation();
 
@@ -253,6 +284,8 @@ void ModuleBase_OperationFeature::activateByPreselection()
   if (myPreSelection.empty())
     return;
 
+  ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection);
+
   ModuleBase_ModelWidget* aFilledWgt = 0;
   ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
   if (aPropertyPanel) {
@@ -304,6 +337,16 @@ CompositeFeaturePtr ModuleBase_OperationFeature::parentFeature() const
   return myParentFeature;
 }
 
+void ModuleBase_OperationFeature::setPreviousCurrentFeature(const FeaturePtr& theFeature)
+{
+  myPreviousCurrentFeature = theFeature;
+}
+
+FeaturePtr ModuleBase_OperationFeature::previousCurrentFeature()
+{
+  return myPreviousCurrentFeature;
+}
+
 void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection,
                                          ModuleBase_IViewer* theViewer)
 {
@@ -357,4 +400,9 @@ void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* th
     // 4. activate the first obligatory widget
     theProp->activateNextWidget(NULL);
   }
+  else {
+    // set focus on Ok button in order to operation manager could process Enter press
+    if (theProp)
+      theProp->setFocusOnOkButton();
+  }
 }