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.
//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);
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
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);
}
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();
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();
/// 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
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)
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
return aResult;
if (operationsCount() == 1) {
- if (canStopOperation()) {
- abortOperation(currentOperation());
+ ModuleBase_Operation* aCurrentOperation = currentOperation();
+ if (canStopOperation(aCurrentOperation)) {
+ abortOperation(aCurrentOperation);
}
else
aResult = false;
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,
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
void XGUI_OperationMgr::onAbortOperation()
{
- if (hasOperation() && canStopOperation()) {
- abortOperation(currentOperation());
+ ModuleBase_Operation* aCurrentOperation = currentOperation();
+ if (aCurrentOperation && canStopOperation(aCurrentOperation)) {
+ abortOperation(aCurrentOperation);
}
}
/// 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;
/// \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