Salome HOME
1. CanStopOperation knows which operation is stopped. Scenario: Unpress Sketch in...
authornds <nds@opencascade.com>
Thu, 27 Aug 2015 10:04:50 +0000 (13:04 +0300)
committernds <nds@opencascade.com>
Thu, 27 Aug 2015 10:05:21 +0000 (13:05 +0300)
2. Cashed previous current feature should be found in the document with 'true' flag. Scenario: ExtrusionCut, Create a line on the sketch, Edit the line. Change any value, start circle creation. Result: the line presentation disappears in the viewer.

src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_OperationFeature.cpp
src/ModuleBase/ModuleBase_OperationFeature.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_OperationMgr.cpp
src/XGUI/XGUI_OperationMgr.h

index 3fe2524f3f512002f407eb42ca281702702635e9..7de4b0ee5e0e5912510d5d0aae8bd9e452728fe9 100644 (file)
@@ -143,7 +143,7 @@ void ModuleBase_IModule::onFeatureTriggered()
   //Do nothing on uncheck
   if (aCmd->isCheckable() && !aCmd->isChecked()) {
     ModuleBase_Operation* anOperation = myWorkshop->findStartedOperation(aCmd->data().toString());
-    if (myWorkshop->canStopOperation())
+    if (myWorkshop->canStopOperation(anOperation))
       myWorkshop->abortOperation(anOperation);
     else {
       aCmd->setChecked(true);
index 9e8f1a28f3e1c01429d301a4a6565597064730a5..67fed3b81fcc130ded827a86e23cb6129f59fe20 100644 (file)
@@ -80,8 +80,9 @@ Q_OBJECT
   virtual ModuleBase_Operation* findStartedOperation(const QString& theId) = 0;
 
   //! Returns true if the operation with id theId can be stopped
+  //! \param theId a stopped operation
   //! \return boolean result
-  virtual bool canStopOperation() = 0;
+  virtual bool canStopOperation(ModuleBase_Operation* theOperation) = 0;
 
   //! Aborts the operation.
   //! \param theId an aborted operation
index 2c00e35430b5ae8278fd6df69a0ec090ecc03d95..18eba405d98e0b535329c078d2f06e7c8d580251 100755 (executable)
@@ -145,7 +145,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,10 +185,10 @@ void ModuleBase_OperationFeature::abort()
     bool aIsOp = aMgr->isOperation();
     if (!aIsOp)
       aMgr->startOperation();
-    aDoc->setCurrentFeature(myCurrentFeature, true);
+    aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
     if (!aIsOp)
       aMgr->finishOperation();
-    myCurrentFeature = FeaturePtr();
+    myPreviousCurrentFeature = FeaturePtr();
   }
   abortOperation();
 
@@ -220,10 +228,10 @@ bool ModuleBase_OperationFeature::commit()
       bool aIsOp = aMgr->isOperation();
       if (!aIsOp)
         aMgr->startOperation();
-      aDoc->setCurrentFeature(myCurrentFeature, true);
+      aDoc->setCurrentFeature(myPreviousCurrentFeature, true);
       if (!aIsOp)
         aMgr->finishOperation();
-      myCurrentFeature = FeaturePtr();
+      myPreviousCurrentFeature = FeaturePtr();
     }
     commitOperation();
     aMgr->finishOperation();
index dedbb6a16dd1683f9c898d564a4e966aded8829f..c2eeb0087459168239810d314131e1a948605d75 100755 (executable)
@@ -146,8 +146,9 @@ signals:
   /// before operation feature creating
   CompositeFeaturePtr myParentFeature;  
 
-  /// Last current feature before editing operation
-  FeaturePtr myCurrentFeature;
+  /// Last current feature before editing operation. It is cashed when Edit operation is started
+  /// in order to restore the document current feature on commit/abort this operation.
+  FeaturePtr myPreviousCurrentFeature;
 };
 
 #endif
index 301b1019285ed126fa4d9407c4146b606394b80b..ee5f029d8445a4dd698c781be9e7555f00ae9bc0 100644 (file)
@@ -123,9 +123,9 @@ ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString&
   return myWorkshop->operationMgr()->findOperation(theId);
 }
 
-bool XGUI_ModuleConnector::canStopOperation()
+bool XGUI_ModuleConnector::canStopOperation(ModuleBase_Operation* theOperation)
 {
-  return myWorkshop->operationMgr()->canStopOperation();
+  return myWorkshop->operationMgr()->canStopOperation(theOperation);
 }
 
 void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
index 428cefe32c33b6e7071aefa8e9f5767fb7691f2c..4a2be1a4842773b22c4bc11dbd9861e9007833ab 100644 (file)
@@ -63,8 +63,9 @@ Q_OBJECT
   virtual ModuleBase_Operation* findStartedOperation(const QString& theId);
 
   //! Returns true if the operation with id theId can be stopped. The operation manager is called.
+  //! \param theId a stopped operation
   //! \return boolean result
-  virtual bool canStopOperation();
+  virtual bool canStopOperation(ModuleBase_Operation* theOperation);
 
   //! Aborts the operation. The operation manager is called.
   //! \param theId an aborted operation
index 259d3411d4aac5f85da5bcc76dc4cec6131f7ad1..229801de9664c36f3b383a1716fc703d01a4bb04 100644 (file)
@@ -135,8 +135,9 @@ bool XGUI_OperationMgr::abortAllOperations()
     return aResult;
 
   if (operationsCount() == 1) {
-    if (canStopOperation()) {
-      abortOperation(currentOperation());
+    ModuleBase_Operation* aCurrentOperation = currentOperation();
+    if (canStopOperation(aCurrentOperation)) {
+      abortOperation(aCurrentOperation);
     }
     else
       aResult = false;
@@ -237,13 +238,13 @@ bool XGUI_OperationMgr::isParentOperationValid() const
   return aPrevOp && aPrevOp->isValid();
 }
 
-bool XGUI_OperationMgr::canStopOperation()
+bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
 {
-  ModuleBase_Operation* anOperation = currentOperation();
-  if(operationsCount() > 1) //in case of nested (sketch) operation no confirmation needed
+  //in case of nested (sketch) operation no confirmation needed
+  if (isGrantedOperation(theOperation))
     return true;
-  if (anOperation && anOperation->isModified()) {
-    QString aMessage = tr("%1 operation will be aborted.").arg(anOperation->id());
+  if (theOperation && theOperation->isModified()) {
+    QString aMessage = tr("%1 operation will be aborted.").arg(theOperation->id());
     int anAnswer = QMessageBox::question(qApp->activeWindow(),
                                          tr("Abort operation"),
                                          aMessage,
@@ -268,13 +269,34 @@ void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
   theOperation->resume();
 }
 
+bool XGUI_OperationMgr::isGrantedOperation(ModuleBase_Operation* theOperation)
+{
+  bool isGranted = false;
+
+  QListIterator<ModuleBase_Operation*> anIt(myOperations);
+  anIt.toBack();
+  ModuleBase_Operation* aPreviousOperation = 0;
+  while (anIt.hasPrevious()) {
+    ModuleBase_Operation* anOp = anIt.previous();
+    if (anOp == theOperation) {
+      if (anIt.hasPrevious())
+        aPreviousOperation = anIt.previous();
+      break;
+    }
+  }
+  if (aPreviousOperation)
+    isGranted = aPreviousOperation->isGranted(theOperation->id());
+
+  return isGranted;
+}
+
 bool XGUI_OperationMgr::canStartOperation(QString theId)
 {
   bool aCanStart = true;
   ModuleBase_Operation* aCurrentOp = currentOperation();
   if (aCurrentOp) {
     if (!aCurrentOp->isGranted(theId)) {
-      if (canStopOperation()) {
+      if (canStopOperation(aCurrentOp)) {
         if (myIsApplyEnabled && aCurrentOp->isModified())
           aCurrentOp->commit();
         else
@@ -314,8 +336,9 @@ void XGUI_OperationMgr::onCommitOperation()
 
 void XGUI_OperationMgr::onAbortOperation()
 {
-  if (hasOperation() && canStopOperation()) {
-    abortOperation(currentOperation());
+  ModuleBase_Operation* aCurrentOperation = currentOperation();
+  if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
+    abortOperation(aCurrentOperation);
   }
 }
 
index 48b6a7ea2927b4c54be8715cbda86274fd672d3d..55260d6ec1d0eb096d24605a28f109bd5b6d57b6 100644 (file)
@@ -55,8 +55,10 @@ Q_OBJECT
   /// Returns true is operation manager has an operation with given Id.
   bool hasOperation(const QString& theId) const;
 
-  /// Returns true if the operation can be aborted
-  bool canStopOperation();
+  /// Returns true if the operation can be aborted. If the operation is modified,
+  /// the warning message box is shown.
+  /// \param theOperation an operation which is checked on stop
+  bool canStopOperation(ModuleBase_Operation* theOperation);
 
   /// Find and return operation by its Id.
   ModuleBase_Operation* findOperation(const QString& theId) const;
@@ -167,6 +169,13 @@ protected: // TEMPORARY
   /// \param theOperation the started operation
   void resumeOperation(ModuleBase_Operation* theOperation);
 
+  /// Returns whether the parameter operation is granted in relation to the previous operation
+  /// in a stack of started operations. It is used in canStopOperation to avoid warning message
+  /// when granted operation is aborted, e.g. SketchLine in Sketch
+  /// \param theOperation the started operation
+  /// \return boolean result
+  bool isGrantedOperation(ModuleBase_Operation* theOperation);
+
  public slots:
   /// SLOT, that is called by the key in the property panel is clicked.
   /// \param theEvent the mouse event