X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FXGUI%2FXGUI_ErrorMgr.cpp;h=e360e99716aeefaf3e0de208b83d3a9556f7bfe2;hb=1cef78af4c4328ecf99a3ced86bda38e6e82e15c;hp=7a7a86c202872fd938a8d5554ea793b1f7ed7167;hpb=803af3deaa4abc9b937e8cfb4a42e7060b6acc22;p=modules%2Fshaper.git diff --git a/src/XGUI/XGUI_ErrorMgr.cpp b/src/XGUI/XGUI_ErrorMgr.cpp index 7a7a86c20..e360e9971 100644 --- a/src/XGUI/XGUI_ErrorMgr.cpp +++ b/src/XGUI/XGUI_ErrorMgr.cpp @@ -7,8 +7,13 @@ #include "XGUI_ErrorMgr.h" #include "XGUI_OperationMgr.h" +#include "XGUI_ModuleConnector.h" +#include "XGUI_Workshop.h" +#include "XGUI_ActionsMgr.h" #include +#include +#include #include #include @@ -17,11 +22,30 @@ #include #include +#include +#include +#include +#include +#include +#include +#include + +const QString INVALID_VALUE = "invalid_action"; + -XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent /*= 0*/) - : ModuleBase_IErrorMgr(theParent) +XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop) + : ModuleBase_IErrorMgr(theParent), + myErrorDialog(0), + myErrorLabel(0), + myWorkshop(theWorkshop) { + ModuleBase_ModelWidget* anActiveWidget = activeWidget(); + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); + myAcceptAllToolTip = anAcceptAllAction->toolTip(); + QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); + myAcceptToolTip = anOkAction->toolTip(); } XGUI_ErrorMgr::~XGUI_ErrorMgr() @@ -29,74 +53,95 @@ XGUI_ErrorMgr::~XGUI_ErrorMgr() } -const char* toString(ModelAPI_ExecState theExecState) +void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature) { -#define TO_STRING(__NAME__) case __NAME__: return #__NAME__; - switch (theExecState) { - TO_STRING(ModelAPI_StateDone) - TO_STRING(ModelAPI_StateMustBeUpdated) - TO_STRING(ModelAPI_StateExecFailed) - TO_STRING(ModelAPI_StateInvalidArgument) - TO_STRING(ModelAPI_StateNothing) - default: return "Unknown ExecState."; + //update Ok Action and header of property panel if the current operation started for the feature + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (workshop()->operationMgr()->currentOperation()); + if (aFOperation && aFOperation->feature() == theFeature) { + QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); + + ModuleBase_ModelWidget* anActiveWidget = activeWidget(); + bool isApplyEnabledByActiveWidget = false; + if (anActiveWidget) + isApplyEnabledByActiveWidget = anActiveWidget->getValueState() == + ModuleBase_ModelWidget::ModifiedInPP; + QString anError = ""; + QString aWidgetError = ""; + if (!isApplyEnabledByActiveWidget) { + anError = myWorkshop->module()->getFeatureError(theFeature); + if (anActiveWidget) + aWidgetError = anActiveWidget->getError(); + if (anError.isEmpty()) + anError = aWidgetError; + } + updateActionState(anOkAction, anError); + updateToolTip(anActiveWidget, aWidgetError); } -#undef TO_STRING } -void XGUI_ErrorMgr::onValidationStateChanged() +void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature) { - XGUI_OperationMgr* anOperationMgr = dynamic_cast(sender()); - if (!anOperationMgr) - return; - ModuleBase_OperationFeature* aFOperation = dynamic_cast - (anOperationMgr->currentOperation()); - if (!myPropertyPanel || !aFOperation) - return; - - // get feature - FeaturePtr aFeature = aFOperation->feature(); - if (!aFeature.get() || !aFeature->data()->isValid()) - return; - - // set error indication - QString anError = QString::fromStdString(aFeature->error()); + QString anError = myWorkshop->module()->getFeatureError(theFeature); if (anError.isEmpty()) { - bool isDone = ( aFeature->data()->execState() == ModelAPI_StateDone - || aFeature->data()->execState() == ModelAPI_StateMustBeUpdated ); - if (!isDone) - anError = toString(aFeature->data()->execState()); + ModuleBase_ModelWidget* anActiveWidget = activeWidget(); + if (anActiveWidget) + anError = anActiveWidget->getError(); + } + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + if (workshop()->isFeatureOfNested(theFeature)) { + QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL); + bool anEnabled = anError.isEmpty(); + anAcceptAllAction->setEnabled(anEnabled); + anAcceptAllAction->setToolTip(!anEnabled ? anError : myAcceptAllToolTip); } +} - QWidget* aWidget = myPropertyPanel->headerWidget(); - if (aWidget) { - aWidget->setToolTip(anError); - aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;"); +bool XGUI_ErrorMgr::isApplyEnabled() const +{ + bool isEnabled = false; + XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr(); + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (workshop()->operationMgr()->currentOperation()); + if (aFOperation) { + QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept); + isEnabled = anOkAction && anOkAction->isEnabled(); } + return isEnabled; } +void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError) +{ + bool anEnabled = theError.isEmpty(); + + theAction->setEnabled(anEnabled); + theAction->setToolTip(anEnabled ? myAcceptToolTip : theError); + // some operations have no property panel, so it is important to check that it is not null + if (myPropertyPanel) { + // update controls error information + QWidget* aWidget = myPropertyPanel->headerWidget(); + if (aWidget) + aWidget->setToolTip(theError); + } +} void XGUI_ErrorMgr::onWidgetChanged() { - static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators(); - ModuleBase_ModelWidget* aModelWidget = dynamic_cast(sender()); if (!aModelWidget || !aModelWidget->feature().get()) return; - std::string anAttributeID = aModelWidget->attributeID(); - AttributePtr anAttribute = aModelWidget->feature()->attribute(anAttributeID); - if (!anAttribute.get()) - return; + QString aWidgetError = aModelWidget->getError(); + updateToolTip(aModelWidget, aWidgetError); +} - std::string aValidatorID; - std::string anErrorMsg; - if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) { - if (anErrorMsg.empty()) - anErrorMsg = "unknown error."; - anErrorMsg = "Attribute \"" + anAttributeID + "\" invalidated by \"" + aValidatorID + "\" with error: " + anErrorMsg; - } +void XGUI_ErrorMgr::updateToolTip(ModuleBase_ModelWidget* theWidget, + const QString& theError) +{ + if (!theWidget) + return; - QString anError = QString::fromStdString(anErrorMsg); - QList aWidgetList = aModelWidget->getControls(); + QList aWidgetList = theWidget->getControls(); foreach(QWidget* aWidget, aWidgetList) { QLabel* aLabel = qobject_cast(aWidget); // We won't set the effect to QLabels - it looks ugly @@ -105,12 +150,34 @@ void XGUI_ErrorMgr::onWidgetChanged() // Get the original tool tip of the widget QString aTTip = aWidget->toolTip().section("Errors:\n", 0, 0).trimmed(); // Add the error message into the tool tip - if (!anError.isEmpty()) { + if (!theError.isEmpty()) { if (!aTTip.isEmpty()) aTTip.append('\n'); - aTTip += "Errors:\n" + anError; + aTTip += "Errors:\n" + theError; } aWidget->setToolTip(aTTip); - aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;"); + //aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;"); } } + +XGUI_Workshop* XGUI_ErrorMgr::workshop() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); + return aConnector->workshop(); +} + +ModuleBase_ModelWidget* XGUI_ErrorMgr::activeWidget() const +{ + ModuleBase_ModelWidget* anActiveWidget = 0; + + ModuleBase_OperationFeature* aFOperation = dynamic_cast + (workshop()->operationMgr()->currentOperation()); + if (aFOperation) { + ModuleBase_IPropertyPanel* aPropertyPanel = aFOperation->propertyPanel(); + if (aPropertyPanel) { + anActiveWidget = aPropertyPanel->activeWidget(); + } + } + return anActiveWidget; +} +