return false;
}
-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 bool keyReleased(const int theKey);
+ virtual void keyReleased(const int theKey) {};
+
+ virtual void activateNextToCurrentWidget() {};
public slots:
/// Slots which listen the mode widget activation
aList.append(mySpinBox);
return aList;
}
-
-bool ModuleBase_WidgetDoubleValue::eventFilter(QObject *theObject, QEvent *theEvent)
-{
- if (theObject == mySpinBox) {
- if (theEvent->type() == QEvent::KeyRelease) {
- QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent;
- if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return ||
- aKeyEvent->key() == Qt::Key_Enter)) {
- emit focusOutWidget(this);
- }
- emit keyReleased((QKeyEvent*) theEvent);
- return true;
- }
- }
- return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
-}
-
return myContainer;
}
- /// Process key release envent on the widget spin box controls
- /// \param theObject the object where the event happens
- /// \param theEvent the processed event
- virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
-
public slots:
/// Delayed value chnged: when user starts typing something,
// it gives him a 0,5 second to finish typing, when sends valueChnaged() signal
return aControls;
}
-bool ModuleBase_WidgetPoint2D::eventFilter(QObject *theObject, QEvent *theEvent)
-{
- if (theObject == myXSpin || theObject == myYSpin) {
- if (theEvent->type() == QEvent::KeyRelease) {
- QKeyEvent* aKeyEvent = (QKeyEvent*) theEvent;
- if (aKeyEvent && (aKeyEvent->key() == Qt::Key_Return ||
- aKeyEvent->key() == Qt::Key_Enter)) {
- emit focusOutWidget(this);
- }
- emit keyReleased((QKeyEvent*) theEvent);
- return true;
- }
- }
- return ModuleBase_ModelWidget::eventFilter(theObject, theEvent);
-}
-
bool ModuleBase_WidgetPoint2D::initFromPrevious(ObjectPtr theObject)
{
if (myOptionParam.length() == 0)
/// \return a control list
virtual QList<QWidget*> getControls() const;
- /// Process key release envent on the widget spin box controls
- /// \param theObject the object where the event happens
- /// \param theEvent the processed event
- virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
-
bool initFromPrevious(ObjectPtr theObject);
signals:
myTextLine->setText("");
}
-//********************************************************************
-bool ModuleBase_WidgetSelector::eventFilter(QObject* theObj, QEvent* theEvent)
-{
- if (theObj == myTextLine) {
- //if (theEvent->type() == QEvent::Polish) {
- // myActivateBtn->setChecked(myActivateOnStart);
- // onSelectionChanged();
- //}
- }
- return ModuleBase_ModelWidget::eventFilter(theObj, theEvent);
-}
-
//********************************************************************
void ModuleBase_WidgetSelector::enableOthersControls(bool toEnable) const
{
/// Activate or deactivate selection
void activateSelection(bool toActivate);
- protected:
- bool eventFilter(QObject* theObj, QEvent* theEvent);
-
private slots:
void onSelectionChanged();
connect(theFeature, SIGNAL(triggered(bool)), this, SLOT(onFeatureTriggered()));
}
-QStringList PartSet_Module::nestedFeatures(QString)
-{
- return QStringList();
-}
-
std::string PartSet_Module::featureFile(const std::string& theFeatureId)
{
return myFeaturesInFiles[theFeatureId];
/// Called on creation of menu item in desktop
virtual void featureCreated(QAction* theFeature);
- /// Returnc list of nested commands for the given feature
- virtual QStringList nestedFeatures(QString theFeature);
std::string featureFile(const std::string&);
/// Creates an operation and send it to loop
}
}
-bool PartSet_OperationFeatureCreate::keyReleased(const int theKey)
+void PartSet_OperationFeatureCreate::keyReleased(const int theKey)
{
switch (theKey) {
case Qt::Key_Return:
}
}
break;
- case Qt::Key_Escape: {
- if (!commit()) {
- abort();
- }
- }
- break;
default:
break;
}
- return true;
+}
+
+void PartSet_OperationFeatureCreate::activateNextToCurrentWidget()
+{
+ emit activateNextWidget(myActiveWidget);
}
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 bool keyReleased(const int theKey);
+ virtual void keyReleased(const int theKey);
+
+ virtual void activateNextToCurrentWidget();
public slots:
/// Slots which listen the mode widget activation
}
}
-bool PartSet_OperationFeatureEdit::keyReleased(const int theKey)
-{
- if (theKey == Qt::Key_Return || theKey == Qt::Key_Enter) {
- commit();
- return true;
- }
- return PartSet_OperationSketchBase::keyReleased(theKey);
-}
-
void PartSet_OperationFeatureEdit::startOperation()
{
PartSet_OperationSketchBase::startOperation();
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 bool keyReleased(const int theKey);
-
protected:
/// \brief Virtual method called when operation is started
/// Virtual method called when operation started (see start() method for more description)
if (myOperationMgr->hasOperation()) {
setAllEnabled(false);
ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
- QString anOperationId = anOperation->id();
- setActionEnabled(anOperationId, true);
- bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
- setNestedCommandsEnabled(isNestedEnabled, anOperationId);
+ FeaturePtr aFeature = anOperation->feature();
+ QString aFeatureId = QString::fromStdString(aFeature->getKind());
+ setActionEnabled(aFeatureId, true);
+ setNestedStackEnabled(anOperation);
} else {
setAllEnabled(true);
setNestedCommandsEnabled(false);
}
}
+void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
+{
+ if(theOperation == NULL)
+ return;
+ FeaturePtr aFeature = theOperation->feature();
+ QString aFeatureId = QString::fromStdString(aFeature->getKind());
+ bool isNestedEnabled = theOperation->isNestedOperationsEnabled();
+ setNestedCommandsEnabled(isNestedEnabled, aFeatureId);
+
+ setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
+}
+
//!
void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
{
QStringList ltNestedActions;
if (theParent.isEmpty()) { //Disable ALL nested
- foreach(QString eachParent, myNestedActions.keys())
- {
+ foreach(QString eachParent, myNestedActions.keys()) {
ltNestedActions << myNestedActions[eachParent];
}
} else {
ltNestedActions << myNestedActions[theParent];
}
- foreach(QString eachNested, ltNestedActions)
- {
+ foreach(QString eachNested, ltNestedActions) {
setActionEnabled(eachNested, theEnabled);
}
}
void XGUI_ActionsMgr::updateCheckState()
{
QString eachCommand = QString();
- foreach(eachCommand, myActions.keys())
- {
+ foreach(eachCommand, myActions.keys()) {
setActionChecked(eachCommand, false);
}
QStringList ltActiveCommands = myOperationMgr->operationList();
- foreach(eachCommand, ltActiveCommands)
- {
+ foreach(eachCommand, ltActiveCommands) {
setActionChecked(eachCommand, true);
}
}
class XGUI_Command;
class XGUI_Workshop;
class XGUI_OperationMgr;
+class ModuleBase_Operation;
class QAction;
class XGUI_EXPORT XGUI_ActionsMgr : public QObject
protected:
//! Sets all actions to isEnabled state.
void setAllEnabled(bool isEnabled);
+ //! Sets to isEnabled state all siblings of the given operation and it's parents recursively
+ void setNestedStackEnabled(ModuleBase_Operation* theOperation);
//! Sets all nested actions to isEnabled state for the command with given ID.
//! If ID is empty - all nested actions will be affected.
void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
#include "XGUI_Command.h"
#include <QEvent>
#include <QToolButton>
+#include <QVariant>
+#include <QDebug>
XGUI_Command::XGUI_Command(const QString& theId, QObject * parent, bool isCheckable)
: QWidgetAction(parent),
void XGUI_Command::setNestedCommands(const QStringList& myUnblockableCommands)
{
this->myNestedCommands = myUnblockableCommands;
-}
+}
\ No newline at end of file
return myOperations.count();
}
-QStringList XGUI_OperationMgr::operationList()
+QStringList XGUI_OperationMgr::operationList() const
{
QStringList result;
- foreach(ModuleBase_Operation* eachOperation, myOperations)
- {
- result << eachOperation->id();
+ 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))
bool XGUI_OperationMgr::abortAllOperations()
{
- if (operationsCount() == 1) {
+ if(!hasOperation()) {
+ return true;
+ } else if (operationsCount() == 1) {
onAbortOperation();
return true;
}
validateOperation(currentOperation());
}
-bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
-{
- if (theEvent->type() == QEvent::KeyRelease) {
- 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()
+bool XGUI_OperationMgr::commitOperation()
{
if (validateOperation(currentOperation())) {
onCommitOperation();
+ return true;
}
+ return false;
}
void XGUI_OperationMgr::resumeOperation(ModuleBase_Operation* theOperation)
void XGUI_OperationMgr::onCommitOperation()
{
ModuleBase_Operation* anOperation = currentOperation();
- anOperation->onWidgetActivated(NULL);
if (anOperation)
anOperation->commit();
}
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()) {
QString aMessage = tr("%1 operation will be aborted.").arg(anOperation->id());
int anAnswer = QMessageBox::question(qApp->activeWindow(),
void XGUI_OperationMgr::onKeyReleased(QKeyEvent* theEvent)
{
- ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation) {
- bool isFinished = anOperation->keyReleased(theEvent->key());
- if(isFinished)
- return;
- }
// Let the manager decide what to do with the given key combination.
+ ModuleBase_Operation* anOperation = currentOperation();
+ bool isRestart = false;
switch (theEvent->key()) {
- case Qt::Key_Escape:
+ case Qt::Key_Escape: {
onAbortOperation();
+ }
break;
case Qt::Key_Return:
- case Qt::Key_Enter:
+ 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)
/// Returns number of operations in the stack
int operationsCount() const;
/// Returns list of all operations IDs
- QStringList operationList();
+ QStringList operationList() const;
+
+ /// Returns previous (parent) operation if given operation started.
+ /// else, or if there is no parent - returns NULL
+ ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
protected:
/// Commits the current operatin if it is valid
- void commitOperation();
+ bool 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
/// Returns true if the operation can be aborted
bool canAbortOperation();
- protected slots:
- /// 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();
-
+ public slots:
/// SLOT, that is called by the key in the property panel is clicked.
/// \param theName the attribute name
/// \param theEvent the mouse event
/// \param theWidget an activated widget
void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
+ protected slots:
+ /// 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();
+
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,
QList<ModuleBase_ModelWidget*>::const_iterator anIt = theWidgets.begin(), aLast =
theWidgets.end();
for (; anIt != aLast; anIt++) {
- //TODO(sbh): Think how to connect prop panle hotkeys and operations mgr
- connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this,
- SIGNAL(keyReleased(QKeyEvent*)));
+ connect(*anIt, SIGNAL(keyReleased(QKeyEvent*)), this, SIGNAL(keyReleased(QKeyEvent*)));
connect(*anIt, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), this,
SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
setTabOrder(anOkBtn, aCancelBtn);
}
}
- onActivateNextWidget(NULL);
}
const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
void cleanContent();
- protected:
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
public slots:
}
myPropertyPanel->setModelWidgets(aWidgets);
+ myPropertyPanel->onActivateNextWidget(NULL);
myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
}
updateCommandStatus();
aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
} else {
XGUI_MainMenu* aMenu = myMainWindow->menuObject();
- aCommand = aMenu->feature(theOperation->getDescription()->operationId());
+ FeaturePtr aFeature = theOperation->feature();
+ if(aFeature)
+ aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
}
//Abort operation on uncheck the command
- if (aCommand)
+ if (aCommand) {
connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
+ }
}
/*
if (aMgr->hasModuleDocument()) {
QAction* aUndoCmd;
QAction* aRedoCmd;
- foreach(QAction* aCmd, aCommands)
- {
+ foreach(QAction* aCmd, aCommands) {
QString aId = aCmd->data().toString();
if (aId == "UNDO_CMD")
aUndoCmd = aCmd;
aUndoCmd->setEnabled(aMgr->canUndo());
aRedoCmd->setEnabled(aMgr->canRedo());
} else {
- foreach(QAction* aCmd, aCommands)
- {
+ foreach(QAction* aCmd, aCommands) {
QString aId = aCmd->data().toString();
if (aId == "NEW_CMD")
aCmd->setEnabled(true);
connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
-//TODO(sbh): KeyReleasedProblem
connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
SLOT(onKeyReleased(QKeyEvent*)));
-
connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
//**************************************************************
void XGUI_Workshop::updateCommandsOnViewSelection()
{
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
XGUI_Selection* aSelection = mySelector->selection();
if (aSelection->getSelected().size() == 0)
return;
+ // Restrict validators to manage only nested (child) features
+ // of the current feature i.e. if current feature is Sketch -
+ // Sketch Features & Constraints can be validated.
+ QStringList aNestedIds;
+ if(myOperationMgr->hasOperation()) {
+ FeaturePtr aFeature = myOperationMgr->currentOperation()->feature();
+ if(aFeature) {
+ aNestedIds << myActionsMgr->nestedCommands(QString::fromStdString(aFeature->getKind()));
+ }
+ }
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
QList<QAction*> aActions = getModuleCommands();
- foreach(QAction* aAction, aActions)
- {
+ foreach(QAction* aAction, aActions) {
QString aId = aAction->data().toString();
+ if(!aNestedIds.contains(aId))
+ continue;
std::list<ModelAPI_Validator*> aValidators;
std::list<std::list<std::string> > anArguments;
aFactory->validators(aId.toStdString(), aValidators, anArguments);