// SLOT(onMouseDoubleClick(QMouseEvent*)));
}
-
void ModuleBase_IModule::launchOperation(const QString& theCmdId)
{
if (!myWorkshop->canStartOperation(theCmdId))
{
QAction* aCmd = dynamic_cast<QAction*>(sender());
//Do nothing on uncheck
- if (aCmd->isCheckable() && !aCmd->isChecked())
- return;
- launchOperation(aCmd->data().toString());
- emit operationLaunched();
+ if (aCmd->isCheckable() && !aCmd->isChecked()) {
+ ModuleBase_Operation* anOperation = myWorkshop->findStartedOperation(aCmd->data().toString());
+ if (myWorkshop->canStopOperation())
+ myWorkshop->abortOperation(anOperation);
+ else {
+ aCmd->setChecked(true);
+ }
+ }
+ else {
+ launchOperation(aCmd->data().toString());
+ emit operationLaunched();
+ }
}
-
void ModuleBase_IModule::editFeature(FeaturePtr theFeature)
{
std::string aFeatureId = theFeature->getKind();
//! Returns true if the operation with id theId can be started
virtual bool canStartOperation(QString theId) = 0;
+ //! Returns started operation by the operation identifier
+ //! \param theId an operation id
+ //! \return an operation instance or NULL
+ virtual ModuleBase_Operation* findStartedOperation(const QString& theId) = 0;
+
+ //! Returns true if the operation with id theId can be stopped
+ //! \return boolean result
+ virtual bool canStopOperation() = 0;
+
+ //! Aborts the operation.
+ //! \param theId an aborted operation
+ virtual void abortOperation(ModuleBase_Operation* theOperation) = 0;
+
//! Returns AIS object by data object
virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const = 0;
return false;
}
-void ModuleBase_Operation::setRunning(bool theState)
-{
- emit triggered(theState);
-}
-
void ModuleBase_Operation::onValuesChanged()
{
myIsModified = true;
/// The operation is postponed
void postponed();
- /// The operation is triggered
- /// \param theState a new triggered state
- void triggered(bool theState);
-
/// The operation is filled with existing preselection
void activatedByPreselection();
/// Redefine commitOperation method to change behavior of operation instead
bool commit();
- /// Alias for start/abort slots
- /// Public slot. Aborts operation if false, else does nothing.
- /// Provided for S/S compatibility with QAction's toggle(bool)
- /// \param theState th flag to abort, if it is true, do nothing, overwise abort
- void setRunning(bool theState);
-
/// Changes the modified flag of the operation
void onValuesChanged();
return myWorkshop->operationMgr()->canStartOperation(theId);
}
+ModuleBase_Operation* XGUI_ModuleConnector::findStartedOperation(const QString& theId)
+{
+ return myWorkshop->operationMgr()->findOperation(theId);
+}
+
+bool XGUI_ModuleConnector::canStopOperation()
+{
+ return myWorkshop->operationMgr()->canStopOperation();
+}
+
+void XGUI_ModuleConnector::abortOperation(ModuleBase_Operation* theOperation)
+{
+ myWorkshop->operationMgr()->abortOperation(theOperation);
+}
//! Returns true if the operation with id theId can be started
virtual bool canStartOperation(QString theId);
+ //! Returns started operation by the operation identifier. The operation manager is called.
+ //! \param theId an operation id
+ //! \return an operation instance or NULL
+ virtual ModuleBase_Operation* findStartedOperation(const QString& theId);
+
+ //! Returns true if the operation with id theId can be stopped. The operation manager is called.
+ //! \return boolean result
+ virtual bool canStopOperation();
+
+ //! Aborts the operation. The operation manager is called.
+ //! \param theId an aborted operation
+ void abortOperation(ModuleBase_Operation* theOperation);
+
//! Returns AIS opbject by data object
virtual AISObjectPtr findPresentation(const ObjectPtr& theObject) const;
bool XGUI_OperationMgr::abortAllOperations()
{
- if(!hasOperation()) {
- return true;
- } else if (operationsCount() == 1) {
- onAbortOperation();
- return true;
+ bool aResult = true;
+ if(!hasOperation())
+ return aResult;
+
+ if (operationsCount() == 1) {
+ if (canStopOperation()) {
+ abortOperation(currentOperation());
+ }
+ else
+ aResult = false;
}
- 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();
+ else {
+ aResult = QMessageBox::question(qApp->activeWindow(),
+ tr("Abort operation"),
+ tr("All active operations will be aborted."),
+ QMessageBox::Ok | QMessageBox::Cancel,
+ QMessageBox::Cancel) == QMessageBox::Ok;
+ while(aResult && hasOperation()) {
+ abortOperation(currentOperation());
+ }
}
- return result;
+ return aResult;
}
bool XGUI_OperationMgr::commitAllOperations()
if (isApplyEnabled()) {
onCommitOperation();
} else {
- anOperation->abort();
+ abortOperation(anOperation);
}
FeaturePtr aFeature = anOperation->feature();
CompositeFeaturePtr aComposite =
if (myIsApplyEnabled)
aCurrentOp->commit();
else
- aCurrentOp->abort();
+ abortOperation(aCurrentOp);
} else {
aCanStart = false;
}
return aCanStart;
}
+void XGUI_OperationMgr::abortOperation(ModuleBase_Operation* theOperation)
+{
+ ModuleBase_Operation* aCurrentOperation = currentOperation();
+ if (theOperation == aCurrentOperation)
+ theOperation->abort();
+ else {
+ // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
+ // all operation from the current to triggered should also be aborted
+ // operations over the parameter one are not aborted(e.g. extrusion cut, sketch abort)
+ while(hasOperation()) {
+ ModuleBase_Operation* aCurrentOperation = currentOperation();
+ aCurrentOperation->abort();
+ if(theOperation == aCurrentOperation)
+ break;
+ }
+ }
+}
void XGUI_OperationMgr::onCommitOperation()
{
void XGUI_OperationMgr::onAbortOperation()
{
if (hasOperation() && canStopOperation()) {
- currentOperation()->abort();
+ abortOperation(currentOperation());
}
}
}
}
-void XGUI_OperationMgr::onOperationTriggered(bool theState)
-{
- ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
- if (aSenderOperation && !theState) {
- ModuleBase_Operation* aCurrentOperation = currentOperation();
- if (aSenderOperation == aCurrentOperation)
- aCurrentOperation->abort();
- else {
- // it is possible to trigger upper operation(e.g. sketch, current is sketch line)
- // all operation from the current to triggered should also be aborted
- while(hasOperation()) {
- ModuleBase_Operation* aCurrentOperation = currentOperation();
- aCurrentOperation->abort();
- if(aSenderOperation == aCurrentOperation)
- break;
- }
- }
- }
-}
-
bool XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
{
// Let the manager decide what to do with the given key combination.
/// \param theId id of the operation which is going to start
bool canStartOperation(QString theId);
+ /// Aborts the parameter operation if it is current, else abort operations from the stack
+ /// of operations until the operation is found. All operations upper the parameter one are
+ /// not aborted.
+ /// \param theOperation an aborted operation
+ void abortOperation(ModuleBase_Operation* theOperation);
+
/// Blocking/unblocking enabling of Ok button in property panel.
/// It is used when operation can not be validated even all attributes are valid
void setLockValidating(bool toLock);
/// Slot called on operation resume
void onOperationResumed();
- /// Slot called on operation triggered
- void onOperationTriggered(bool theState);
-
private:
typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
Operations myOperations; ///< a stack of started operations. The active operation is on top,
setNestedFeatures(theOperation);
if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
- connectWithOperation(theOperation);
setPropertyPanel(theOperation);
// filling the operation values by the current selection
// if the operation can be commited after the controls filling, the method perform should
setNestedFeatures(theOperation);
if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
- // connectWithOperation(theOperation); already connected
setPropertyPanel(theOperation);
}
updateCommandStatus();
myErrorMgr->setPropertyPanel(myPropertyPanel);
}
-/*
- * Makes a signal/slot connections between Property Panel
- * and given operation. The given operation becomes a
- * current operation and previous operation if exists
- */
-void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
-{
- QAction* aCommand = 0;
- if (isSalomeMode()) {
- aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
- } else {
- AppElements_MainMenu* aMenu = myMainWindow->menuObject();
- FeaturePtr aFeature = theOperation->feature();
- if(aFeature)
- aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
- }
- //Abort operation on uncheck the command
- if (aCommand) {
- connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
- }
-}
-
/*
* Saves document with given name.
*/
void XGUI_Workshop::onUndo(int theTimes)
{
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
+ if (operationMgr()->canStopOperation())
+ operationMgr()->abortOperation(operationMgr()->currentOperation());
+ else
+ return;
+
SessionPtr aMgr = ModelAPI_Session::get();
- if (aMgr->isOperation())
- operationMgr()->onAbortOperation();
for (int i = 0; i < theTimes; ++i) {
aMgr->undo();
}
//******************************************************
void XGUI_Workshop::onRedo(int theTimes)
{
+ if (operationMgr()->canStopOperation())
+ operationMgr()->abortOperation(operationMgr()->currentOperation());
+ else
+ return;
+
// the viewer update should be blocked in order to avoid the features blinking. For the created
// feature a results are created, the flush of the created signal caused the viewer redisplay for
// each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
SessionPtr aMgr = ModelAPI_Session::get();
- if (aMgr->isOperation())
- operationMgr()->onAbortOperation();
for (int i = 0; i < theTimes; ++i) {
aMgr->redo();
}
myObjectBrowser->parentWidget()->hide();
}
-//******************************************************
-//void XGUI_Workshop::onFeatureTriggered()
-//{
-// QAction* aCmd = dynamic_cast<QAction*>(sender());
-// if (aCmd) {
-// QString aId = salomeConnector()->commandId(aCmd);
-// if (!aId.isNull())
-// myModule->launchOperation(aId);
-// }
-//}
-
//******************************************************
void XGUI_Workshop::salomeViewerSelectionChanged()
{
/// Hide object Browser
void hideObjectBrowser();
- /// Reaction on command call
- //void onFeatureTriggered();
-
/// Close document
void closeDocument();
/// \param theOperation an operation
void setPropertyPanel(ModuleBase_Operation* theOperation);
- /// Connect to operation signals
- /// \param theOperation an operation
- void connectWithOperation(ModuleBase_Operation* theOperation);
-
private:
/// Display all results
//void displayAllResults();