return false;
}
-void ModuleBase_Operation::keyReleased(const int theKey)
+bool ModuleBase_Operation::keyReleased(const int theKey)
{
// Do nothing...
+ return false;
}
/// Returns True if the current operation works with the given object (feature or result)
virtual bool hasObject(ObjectPtr theObj) const;
- virtual void keyReleased(const int theKey);
+ virtual bool keyReleased(const int theKey);
public slots:
/// Slots which listen the mode widget activation
#ifdef _DEBUG
#include <QDebug>
+#include <iostream>
#endif
#include <QMouseEvent>
const std::list<ModuleBase_ViewerPrs>& theSelected,
const std::list<ModuleBase_ViewerPrs>& /*theHighlighted*/)
{
- if (commit()) {
- // if the point creation is finished, the next mouse release should commit the modification
- // the next release can happens by double click in the viewer
- restartOperation(feature()->getKind(), feature());
- return;
- }
-
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
double aX = aPoint.X(), anY = aPoint.Y();
aPoint = BRep_Tool::Pnt(aVertex);
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
- PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX,
- anY);
+ PartSet_Tools::setConstraints(sketch(), feature(), myActiveWidget->attributeID(), aX, anY);
}
} else if (aShape.ShapeType() == TopAbs_EDGE) // the line is selected
{
flushUpdated();
emit activateNextWidget(myActiveWidget);
}
+
+ if (commit()) {
+ // if the point creation is finished, the next mouse release should commit the modification
+ // the next release can happens by double click in the viewer
+ restartOperation(feature()->getKind(), feature());
+ return;
+ }
}
void PartSet_OperationFeatureCreate::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
{
- if (commit()) {
- restartOperation(feature()->getKind(), feature());
- } else {
double aX, anY;
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theView);
PartSet_Tools::convertTo2D(aPoint, sketch(), theView, aX, anY);
setWidgetValue(feature(), aX, anY);
flushUpdated();
- }
}
void PartSet_OperationFeatureCreate::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
}
}
-void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
+bool PartSet_OperationFeatureCreate::keyReleased(const int theKey)
{
switch (theKey) {
case Qt::Key_Return:
default:
break;
}
+ return true;
}
void PartSet_OperationFeatureCreate::startOperation()
virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
/// Processes the key pressed in the view
/// \param theKey a key value
- virtual void keyReleased(const int theKey);
+ virtual bool keyReleased(const int theKey);
public slots:
/// Slots which listen the mode widget activation
}
}
-void PartSet_OperationFeatureEdit::keyReleased(const int theKey)
+bool PartSet_OperationFeatureEdit::keyReleased(const int theKey)
{
if (theKey == Qt::Key_Return || theKey == Qt::Key_Enter) {
commit();
- } else
- PartSet_OperationSketchBase::keyReleased(theKey);
+ return true;
+ }
+ return PartSet_OperationSketchBase::keyReleased(theKey);
}
void PartSet_OperationFeatureEdit::startOperation()
/// Processes the key pressed in the view
/// \param theKey a key value
- virtual void keyReleased(const int theKey);
+ virtual bool keyReleased(const int theKey);
protected:
/// \brief Virtual method called when operation is started
{
}
-void PartSet_OperationSketchBase::keyReleased(const int theKey)
-{
- switch (theKey) {
- case Qt::Key_Escape: {
- bool toAbort = true;
- if (isModified()) {
- int anAnswer = QMessageBox::question(
- qApp->activeWindow(),
- tr("Cancel operation"),
- tr("Do you want to cancel %1 operation?").arg(id()),
- QMessageBox::Yes,
- QMessageBox::No);
- toAbort = (anAnswer == QMessageBox::Yes);
- }
- if (toAbort)
- abort();
- }
- break;
- default:
- break;
- }
-}
-
void PartSet_OperationSketchBase::restartOperation(const std::string& theType, ObjectPtr theFeature)
{
FeaturePtr aFeature = ModelAPI_Feature::feature(theFeature);
const std::list<ModuleBase_ViewerPrs>& theSelected,
const std::list<ModuleBase_ViewerPrs>& theHighlighted);
- /// Processes the key pressed in the view
- /// \param theKey a key value
- virtual void keyReleased(const int theKey);
-
/// Emits a signal about the operation start. This signal has an information about the feature.
/// If the provided feature is empty, the current operation feature is used.
/// \param theType a type of an operation started
return myOperations.count();
}
+QStringList XGUI_OperationMgr::operationList()
+{
+ QStringList result;
+ foreach(ModuleBase_Operation* eachOperation, myOperations)
+ {
+ result << eachOperation->id();
+ }
+ return result;
+}
+
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 (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();
//Get validators for the Id
SessionPtr aMgr = ModelAPI_Session::get();
bool isValid = aFactory->validate(aFeature);
emit operationValidated(isValid);
+ return isValid;
}
-void XGUI_OperationMgr::validateCurrentOperation()
+void XGUI_OperationMgr::onValidateOperation()
{
if (!hasOperation())
return;
bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
{
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
+ QKeyEvent* aKeyEvent = dynamic_cast<QKeyEvent*>(theEvent);
+ // 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
+ if(aKeyEvent) {
onKeyReleased(aKeyEvent);
return true;
}
return QObject::eventFilter(theObject, theEvent);
}
+void XGUI_OperationMgr::commitOperation()
+{
+ if (validateOperation(currentOperation())) {
+ onCommitOperation();
+ }
+}
+
void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
{
theOperation->resume();
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, abort it?"),
- QMessageBox::Abort | QMessageBox::Cancel,
- QMessageBox::Cancel);
- return anAnswer == QMessageBox::Abort;
- }
- }
- 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 (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(QKeyEvent* theEvent)
{
ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation)
- anOperation->keyReleased(theEvent->key());
+ if (anOperation) {
+ bool isFinished = anOperation->keyReleased(theEvent->key());
+ if(isFinished)
+ return;
+ }
+ // Let the manager decide what to do with the given key combination.
+ switch (theEvent->key()) {
+ case Qt::Key_Escape:
+ onAbortOperation();
+ break;
+ case Qt::Key_Return:
+ case Qt::Key_Enter:
+ commitOperation();
+ break;
+ default:
+ break;
+ }
}
void XGUI_OperationMgr::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
bool hasOperation() const;
/// Returns number of operations in the stack
int operationsCount() const;
+ /// Returns list of all operations IDs
+ QStringList operationList();
+
+ virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
+
/// Start the operation and append it to the stack of operations
/// \param theOperation the started operation
/// \return the state whether the current operation is started
bool startOperation(ModuleBase_Operation* theOperation);
- /// Abort the operation and append it to the stack of operations
- /// \return the state whether the current operation is aborted
- bool abortOperation();
- ///Returns list of all operations IDs
- QStringList operationList();
-
- virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
+ bool abortAllOperations();
public slots:
- void validateCurrentOperation();
+ /// Slot that commits the current operation.
+ void onCommitOperation();
+ /// Slot that aborts the current operation.
+ void onAbortOperation();
+ /// Slot that validates the current operation using the validateOperation method.
+ void onValidateOperation();
signals:
/// Signal about an operation is started. It is emitted after the start() of operation is done.
void activateNextWidget(ModuleBase_ModelWidget* theWidget);
protected:
+
+ /// Commits the current operatin if it is valid
+ void commitOperation();
/// Sets the current operation or NULL
/// \param theOperation the started operation
/// \param isCheckBeforeStart the flag whether to check whether the operation can be started
/// \return the state whether the operation is resumed
void resumeOperation(ModuleBase_Operation* theOperation);
+ /// Checks if given operation is Valid, if so sends operationValidated signal
+ /// \param theOperation to be validated
+ /// \return validation state (true means valid)
+ bool validateOperation(ModuleBase_Operation* theOperation);
/// Returns whether the operation can be started. Check if there is already started operation and
/// the granted parameter of the launched operation
/// \param theOperation an operation to check
bool canStartOperation(ModuleBase_Operation* theOperation);
- /// Returns whether the operation can be stopped.
bool canStopOperation();
/// Returns true if the operation can be aborted
bool canAbortOperation();
- void validateOperation(ModuleBase_Operation* theOperation);
-
protected slots:
- /// Slot that commits the current operation.
- void onCommitOperation();
- /// Slot that aborts the current operation.
- void onAbortOperation();
-
/// Slot that is called by an operation stop. Removes the stopped operation form the stack.
/// If there is a suspended operation, restart it.
void onOperationStopped();
}
}
}
- myOperationMgr->validateCurrentOperation();
+ myOperationMgr->onValidateOperation();
if (myObjectBrowser)
myObjectBrowser->processEvent(theMsg);
}
bool XGUI_Workshop::isActiveOperationAborted()
{
- if(!myOperationMgr->hasOperation())
- return true;
- return myOperationMgr->abortOperation();
+ return myOperationMgr->abortAllOperations();
}
//******************************************************
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
if (aMgr->isOperation())
- operationMgr()->abortOperation();
+ operationMgr()->onAbortOperation();
aMgr->undo();
updateCommandStatus();
}
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
if (aMgr->isOperation())
- operationMgr()->abortOperation();
+ operationMgr()->onAbortOperation();
aMgr->redo();
updateCommandStatus();
}