From: nds Date: Thu, 27 Aug 2015 10:04:50 +0000 (+0300) Subject: 1. CanStopOperation knows which operation is stopped. Scenario: Unpress Sketch in... X-Git-Tag: V_1.4.0_beta4~227 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=39542b37664439ffc0bd754c74a72853997102f6;p=modules%2Fshaper.git 1. CanStopOperation knows which operation is stopped. Scenario: Unpress Sketch in ToolBar when sketch entity is active should visualizes the Abort warnning dialog. 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. --- diff --git a/src/ModuleBase/ModuleBase_IModule.cpp b/src/ModuleBase/ModuleBase_IModule.cpp index 3fe2524f3..7de4b0ee5 100644 --- a/src/ModuleBase/ModuleBase_IModule.cpp +++ b/src/ModuleBase/ModuleBase_IModule.cpp @@ -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); diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index 9e8f1a28f..67fed3b81 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index 2c00e3543..18eba405d 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -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(); diff --git a/src/ModuleBase/ModuleBase_OperationFeature.h b/src/ModuleBase/ModuleBase_OperationFeature.h index dedbb6a16..c2eeb0087 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.h +++ b/src/ModuleBase/ModuleBase_OperationFeature.h @@ -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 diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 301b10192..ee5f029d8 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -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) diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index 428cefe32..4a2be1a48 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -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 diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index 259d3411d..229801de9 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -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 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); } } diff --git a/src/XGUI/XGUI_OperationMgr.h b/src/XGUI/XGUI_OperationMgr.h index 48b6a7ea2..55260d6ec 100644 --- a/src/XGUI/XGUI_OperationMgr.h +++ b/src/XGUI/XGUI_OperationMgr.h @@ -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