-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: XGUI_ErrorMgr.cpp
-// Created: 22 July 2015
-// Author: Sergey POKHODENKO
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
#include "XGUI_ErrorMgr.h"
#include "XGUI_OperationMgr.h"
+#include "XGUI_ModuleConnector.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_ActionsMgr.h"
#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IModule.h>
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_OperationFeature.h>
+#include <ModuleBase_Tools.h>
+#include <QDebug>
+
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
const QString INVALID_VALUE = "invalid_action";
+//#define DEBUG_ERROR_STATE
-XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent /*= 0*/)
+XGUI_ErrorMgr::XGUI_ErrorMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop)
: ModuleBase_IErrorMgr(theParent),
myErrorDialog(0),
- myErrorLabel(0)
+ myErrorLabel(0),
+ myWorkshop(theWorkshop),
+ myAcceptAllToolTip(""),
+ myAcceptAllStatusTip(""),
+ myAcceptToolTip(""),
+ myAcceptStatusTip("")
{
-
}
XGUI_ErrorMgr::~XGUI_ErrorMgr()
{
-
}
-bool XGUI_ErrorMgr::canProcessClick(QAction* theAction, const FeaturePtr& theFeature)
+void XGUI_ErrorMgr::updateActions(const FeaturePtr& theFeature)
{
- QString aData = theAction->data().toString();
-
- bool isActionEnabled = theAction->data() != INVALID_VALUE;
-
- QString anError = getFeatureError(theFeature);
- if (!isActionEnabled && !anError.isEmpty()) {
- if (!myErrorDialog) {
- myErrorDialog = new QDialog(QApplication::desktop(), Qt::Popup);
- QHBoxLayout* aLay = new QHBoxLayout(myErrorDialog);
- aLay->setContentsMargins(0, 0, 0, 0);
-
- QFrame* aMarginWidget = new QFrame(myErrorDialog);
- aMarginWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
-
- aLay->addWidget(aMarginWidget);
- QHBoxLayout* aMarginLay = new QHBoxLayout(aMarginWidget);
- aMarginLay->setContentsMargins(4, 4, 4, 4);
-
- myErrorLabel = new QLabel(aMarginWidget);
- aMarginLay->addWidget(myErrorLabel);
+ //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<ModuleBase_OperationFeature*>
+ (workshop()->operationMgr()->currentOperation());
+ if (aFOperation && aFOperation->feature() == theFeature) {
+ 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;
}
- myErrorLabel->setText(anError);
- myErrorDialog->move(QCursor::pos());
- myErrorDialog->show();
+ updateAcceptActionState(anError);
+ updateToolTip(anActiveWidget, aWidgetError);
+ myWorkshop->setStatusBarMessage(anError);
+
+#ifdef DEBUG_ERROR_STATE
+ QString anInfo = ModuleBase_Tools::objectInfo(theFeature);
+
+ QString aResultInfo = QString("valid = %1, anError = %2, aWidgetError = %3")
+ .arg(anError.isEmpty()).arg(anError).arg(aWidgetError);
+ qDebug(QString("XGUI_ErrorMgr::updateActions for %1, result: %2").arg(anInfo)
+ .arg(aResultInfo).toStdString().c_str());
+#endif
}
- return isActionEnabled;
}
-void XGUI_ErrorMgr::updateActionState(QAction* theAction, const FeaturePtr& theFeature,
- const bool theEnabled)
+void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature)
{
- bool isActionEnabled = theAction->data() != INVALID_VALUE;
- if (theEnabled != isActionEnabled) {
- // update enable state of the button
- theAction->setIcon(theEnabled ? QIcon(":pictures/button_ok.png"): QIcon(":pictures/button_ok_error.png"));
- if (theEnabled)
- theAction->setData("");
- else
- theAction->setData(INVALID_VALUE);
+ if (myAcceptAllToolTip.isEmpty() && myAcceptToolTip.isEmpty())
+ storeInitialActionValues();
+
+ QString anError = "";
+ /// to allow the module have the button always enabled
+ bool isActionStateEnabled =
+ myWorkshop->module()->isActionEnableStateFixed(XGUI_ActionsMgr::AcceptAll);
+ if (!isActionStateEnabled) {
+ anError = myWorkshop->module()->getFeatureError(theFeature);
+ if (anError.isEmpty()) {
+ ModuleBase_ModelWidget* anActiveWidget = activeWidget();
+ if (anActiveWidget)
+ anError = anActiveWidget->getError();
+ }
}
- // 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(getFeatureError(theFeature));
+ XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+ if (workshop()->isFeatureOfNested(theFeature)) {
+ QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
+ bool anEnabled = anError.isEmpty();
+ anAcceptAllAction->setEnabled(anEnabled);
+ anAcceptAllAction->setToolTip(!anEnabled ? anError : myAcceptAllToolTip);
+ anAcceptAllAction->setStatusTip(!anEnabled ? anError : myAcceptAllStatusTip);
}
}
-const char* toString(ModelAPI_ExecState theExecState)
+bool XGUI_ErrorMgr::isApplyEnabled() const
{
-#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.";
+ bool isEnabled = false;
+ XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (workshop()->operationMgr()->currentOperation());
+ if (aFOperation) {
+ QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+ isEnabled = anOkAction && anOkAction->isEnabled();
}
-#undef TO_STRING
+ return isEnabled;
}
-/*void XGUI_ErrorMgr::onValidationStateChanged()
+void XGUI_ErrorMgr::storeInitialActionValues()
{
- XGUI_OperationMgr* anOperationMgr = dynamic_cast<XGUI_OperationMgr*>(sender());
- if (!anOperationMgr)
- return;
- ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
- (anOperationMgr->currentOperation());
- if (!myPropertyPanel || !aFOperation)
- return;
-
- FeaturePtr aFeature = aFOperation->feature();
- QString anError = getFeatureError(aFeature);
-
- QWidget* aWidget = myPropertyPanel->headerWidget();
- if (aWidget) {
- aWidget->setToolTip(anError);
- aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;");
- }
-}*/
+ ModuleBase_ModelWidget* anActiveWidget = activeWidget();
+ XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+ QAction* anAcceptAllAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
+ myAcceptAllToolTip = anAcceptAllAction->toolTip();
+ myAcceptAllStatusTip = anAcceptAllAction->statusTip();
+
+ QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+ myAcceptToolTip = anOkAction->toolTip();
+ myAcceptStatusTip = anOkAction->toolTip();
+}
-QString XGUI_ErrorMgr::getFeatureError(const FeaturePtr& theFeature) const
+void XGUI_ErrorMgr::updateAcceptActionState(const QString& theError)
{
- QString anError;
- // get feature
- if (!theFeature.get() || !theFeature->data()->isValid())
- return anError;
-
- // set error indication
- anError = QString::fromStdString(theFeature->error());
- if (anError.isEmpty()) {
- bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
- || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
- if (!isDone)
- anError = toString(theFeature->data()->execState());
+ XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+ QAction* anAcceptAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+ QAction* anAcceptPlusAction =
+ anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptPlus);
+
+ if (myAcceptAllToolTip.isEmpty() && myAcceptToolTip.isEmpty())
+ storeInitialActionValues();
+
+ bool anEnabled = theError.isEmpty();
+ anAcceptAction->setEnabled(anEnabled);
+ anAcceptPlusAction->setEnabled(anEnabled);
+ anAcceptAction->setToolTip(anEnabled ? myAcceptToolTip : theError);
+ anAcceptAction->setStatusTip(anEnabled ? myAcceptStatusTip : 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);
}
-
- return anError;
}
-
void XGUI_ErrorMgr::onWidgetChanged()
{
- static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
-
ModuleBase_ModelWidget* aModelWidget = dynamic_cast<ModuleBase_ModelWidget*>(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 = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg;
- }
+void XGUI_ErrorMgr::updateToolTip(ModuleBase_ModelWidget* theWidget,
+ const QString& theError)
+{
+ if (!theWidget)
+ return;
- QString anError = QString::fromStdString(anErrorMsg);
- QList<QWidget*> aWidgetList = aModelWidget->getControls();
+ QList<QWidget*> aWidgetList = theWidget->getControls();
foreach(QWidget* aWidget, aWidgetList) {
QLabel* aLabel = qobject_cast<QLabel*>(aWidget);
// We won't set the effect to QLabels - it looks ugly
if (aLabel) continue;
// Get the original tool tip of the widget
- QString aTTip = aWidget->toolTip().section("Errors:\n", 0, 0).trimmed();
+ QString aTTip = aWidget->toolTip().section(tr("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 += tr("Errors:") + "\n" + theError;
}
aWidget->setToolTip(aTTip);
//aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;");
}
}
+
+XGUI_Workshop* XGUI_ErrorMgr::workshop() const
+{
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ return aConnector->workshop();
+}
+
+ModuleBase_ModelWidget* XGUI_ErrorMgr::activeWidget() const
+{
+ ModuleBase_ModelWidget* anActiveWidget = 0;
+
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (workshop()->operationMgr()->currentOperation());
+ if (aFOperation) {
+ ModuleBase_IPropertyPanel* aPropertyPanel = aFOperation->propertyPanel();
+ if (aPropertyPanel) {
+ anActiveWidget = aPropertyPanel->activeWidget();
+ }
+ }
+ return anActiveWidget;
+}
+