Salome HOME
Fix Warning in NewGeom_Module.cpp
[modules/shaper.git] / src / ModuleBase / ModuleBase_OperationFeature.cpp
index 7458ae9fd27d996e1a27f2579905555c36f18a2d..c8f1224b69d97c89ed9dcd2e6c79b790861d7147 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,32 @@ ModuleBase_OperationFeature::~ModuleBase_OperationFeature()
   clearPreselection();
 }
 
+void ModuleBase_OperationFeature::setEditOperation(const bool theRestartTransaction)
+{
+  if (isEditOperation())
+    return;
+
+  if (theRestartTransaction) {
+    // finsh previous create operation
+    emit beforeCommitted();
+    SessionPtr aMgr = ModelAPI_Session::get();
+    ModelAPI_Session::get()->finishOperation();
+
+    // start new edit operation
+    myIsEditing = true;
+    QString anId = getDescription()->operationId();
+    if (myIsEditing) {
+      anId = anId.append(EditSuffix());
+    }
+    ModelAPI_Session::get()->startOperation(anId.toStdString());
+    emit beforeStarted();
+  }
+  else
+    myIsEditing = true;
+
+  propertyPanel()->setEditingMode(isEditOperation());
+}
+
 FeaturePtr ModuleBase_OperationFeature::feature() const
 {
   return myFeature;
@@ -78,6 +105,9 @@ void ModuleBase_OperationFeature::startOperation()
   if (!aFeature.get() || !isEditOperation())
     return;
 
+  if (aFeature.get() && isEditOperation())
+    aFeature->setStable(false);
+
   myVisualizedObjects.clear();
   // store hidden result features
   std::list<ResultPtr> aResults = aFeature->results();
@@ -170,7 +200,7 @@ bool ModuleBase_OperationFeature::isDisplayedOnStart(ObjectPtr theObject)
   return myVisualizedObjects.find(theObject) != myVisualizedObjects.end();
 }
 
-void ModuleBase_OperationFeature::start()
+bool ModuleBase_OperationFeature::start()
 {
   setIsModified(false);
   QString anId = getDescription()->operationId();
@@ -179,6 +209,7 @@ void ModuleBase_OperationFeature::start()
   }
   ModelAPI_Session::get()->startOperation(anId.toStdString());
 
+  emit beforeStarted();
   startOperation();
 
   if (!myIsEditing) {
@@ -189,32 +220,18 @@ void ModuleBase_OperationFeature::start()
       // in order to update commands status in the workshop, to be exact the feature action
       // to be unchecked
       abort();
-      return;
+      return false;
     }
   }
-  /// 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();
-
+  return true;
 }
 
 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>(
@@ -230,21 +247,13 @@ 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();
+  if (myFeature.get())
+    myFeature->setStable(true);
 
+  abortOperation();
   stopOperation();
 
+  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
@@ -260,6 +269,7 @@ void ModuleBase_OperationFeature::abort()
 bool ModuleBase_OperationFeature::commit()
 {
   if (canBeCommitted()) {
+    emit beforeCommitted();
     // the widgets of property panel should not process any events come from data mode
     // after commit clicked. Some signal such as redisplay/create influence on content
     // of the object browser and viewer context. Therefore it influence to the current
@@ -269,18 +279,11 @@ bool ModuleBase_OperationFeature::commit()
     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();
-    }
+
     commitOperation();
     aMgr->finishOperation();
 
@@ -299,7 +302,7 @@ void ModuleBase_OperationFeature::activateByPreselection()
   if (myPreSelection.empty())
     return;
 
-  ModuleBase_ISelection::filterPreselectionOnEqualPoints(myPreSelection);
+  ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection);
 
   ModuleBase_ModelWidget* aFilledWgt = 0;
   ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
@@ -352,6 +355,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)
 {