return myOperations.count();
}
+QStringList XGUI_OperationMgr::operationList() const
+{
+ QStringList result;
+ foreach(ModuleBase_Operation* eachOperation, myOperations) {
+ FeaturePtr aFeature = eachOperation->feature();
+ if(aFeature) {
+ result << QString::fromStdString(aFeature->getKind());
+ }
+ }
+ return result;
+}
+
+ModuleBase_Operation* XGUI_OperationMgr::previousOperation(ModuleBase_Operation* theOperation) const
+{
+ int idx = myOperations.lastIndexOf(theOperation);
+ if(idx == -1 || idx == 0) {
+ return NULL;
+ }
+ return myOperations.at(idx - 1);
+}
+
+bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
+{
+ if (theEvent->type() == QEvent::KeyRelease) {
+ QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+ if(aKeyEvent) {
+ onKeyReleased(aKeyEvent);
+ return true;
+ }
+ }
+ return QObject::eventFilter(theObject, theEvent);
+}
+
bool XGUI_OperationMgr::startOperation(ModuleBase_Operation* theOperation)
{
if (!canStartOperation(theOperation))
SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)));
theOperation->start();
- validateCurrentOperation();
- return true;
-}
-
-bool XGUI_OperationMgr::abortOperation()
-{
- ModuleBase_Operation* aCurrentOp = currentOperation();
- if (!aCurrentOp || !canStopOperation())
- return false;
-
- aCurrentOp->abort();
+ onValidateOperation();
return true;
}
-QStringList XGUI_OperationMgr::operationList()
+bool XGUI_OperationMgr::abortAllOperations()
{
- QStringList result;
- foreach(ModuleBase_Operation* eachOperation, myOperations)
- {
- result << eachOperation->id();
+ if(!hasOperation()) {
+ return true;
+ } else if (operationsCount() == 1) {
+ onAbortOperation();
+ return true;
+ }
+ QString aMessage = tr("All active operations will be aborted.");
+ int anAnswer = QMessageBox::question(qApp->activeWindow(),
+ tr("Abort operation"),
+ aMessage,
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel);
+ bool result = anAnswer == QMessageBox::Ok;
+ while(result && hasOperation()) {
+ currentOperation()->abort();
}
return result;
}
-void XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
+bool XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
{
- //Get operation Id and feature to validate
- QString anOperationId = theOperation->id();
+ //Get operation feature to validate
FeaturePtr aFeature = theOperation->feature();
+ if (!aFeature) return true; // rename operation
//Get validators for the Id
- PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+ SessionPtr aMgr = ModelAPI_Session::get();
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(anOperationId.toStdString(), aValidators, anArguments);
- //
- std::list<ModelAPI_Validator*>::iterator it = aValidators.begin();
- bool isValid = true;
- for (; it != aValidators.end(); it++) {
- const ModelAPI_FeatureValidator* aFeatureValidator =
- dynamic_cast<const ModelAPI_FeatureValidator*>(*it);
- if (!aFeatureValidator)
- continue;
- if (!aFeatureValidator->isValid(aFeature)) {
- isValid = false;
- break;
- }
- }
+
+ bool isValid = aFactory->validate(aFeature);
emit operationValidated(isValid);
+ return isValid;
}
-void XGUI_OperationMgr::validateCurrentOperation()
+void XGUI_OperationMgr::onValidateOperation()
{
if (!hasOperation())
return;
validateOperation(currentOperation());
}
-bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
+bool XGUI_OperationMgr::commitOperation()
{
- if (theEvent->type() == QEvent::KeyRelease) {
- QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent;
- if (aKeyEvent && aKeyEvent->key() == Qt::Key_Escape) {
- // TODO: this is Escape button processing when the property panel has empty content,
- // but the operation should be stopped by the Enter has been clicked
- onKeyReleased("", aKeyEvent);
- return true;
- }
+ if (validateOperation(currentOperation())) {
+ onCommitOperation();
+ return true;
}
- return QObject::eventFilter(theObject, theEvent);
+ return false;
}
void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
if (aCurrentOp) {
if (!theOperation->isGranted()) {
if (!aCurrentOp->isValid(theOperation)) {
- if (canStopOperation()) {
+ if (canAbortOperation()) {
aCurrentOp->abort();
} else {
aCanStart = false;
return aCanStart;
}
-bool XGUI_OperationMgr::canStopOperation()
-{
- ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation) {
- if (anOperation->isModified()) {
- int anAnswer = QMessageBox::question(
- qApp->activeWindow(), tr("Operation launch"),
- tr("Previous operation is not finished and will be aborted"), QMessageBox::Ok,
- QMessageBox::Cancel);
- return anAnswer == QMessageBox::Ok;
- }
- }
- return true;
-}
void XGUI_OperationMgr::onCommitOperation()
{
void XGUI_OperationMgr::onAbortOperation()
{
- ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation && canAbortOperation())
- anOperation->abort();
+ if (hasOperation() && canAbortOperation()) {
+ currentOperation()->abort();
+ }
}
bool XGUI_OperationMgr::canAbortOperation()
{
ModuleBase_Operation* anOperation = currentOperation();
+ if(operationsCount() > 1) //in case of nested (sketch) operation no confirmation needed
+ return true;
if (anOperation && anOperation->isModified()) {
- int anAnswer = QMessageBox::question(
- qApp->activeWindow(), tr("Cancel operation"),
- tr("Operation %1 will be cancelled. Continue?").arg(anOperation->id()), QMessageBox::Yes,
- QMessageBox::No);
- return anAnswer == QMessageBox::Yes;
+ QString aMessage = tr("%1 operation will be aborted.").arg(anOperation->id());
+ int anAnswer = QMessageBox::question(qApp->activeWindow(),
+ tr("Abort operation"),
+ aMessage,
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel);
+ return anAnswer == QMessageBox::Ok;
}
return true;
}
}
if (aResultOp) {
resumeOperation(aResultOp);
- validateCurrentOperation();
+ onValidateOperation();
}
}
-void XGUI_OperationMgr::onKeyReleased(const std::string& theName, QKeyEvent* theEvent)
+void XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
{
+ // Let the manager decide what to do with the given key combination.
ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation)
- anOperation->keyReleased(theName, theEvent);
+ bool isRestart = false;
+ switch (theEvent->key()) {
+ case Qt::Key_Escape: {
+ onAbortOperation();
+ }
+ break;
+ case Qt::Key_Return:
+ case Qt::Key_Enter: {
+ if(anOperation) {
+ anOperation->activateNextToCurrentWidget();
+ }
+ commitOperation();
+ }
+ break;
+ default:
+ break;
+ }
+ if(anOperation)
+ anOperation->keyReleased(theEvent->key());
}
void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget)