Salome HOME
Method isStable is defined
[modules/shaper.git] / src / XGUI / XGUI_ErrorMgr.cpp
index 1cf0d45b99a270ffce23d6080d5c4d67136c8a0c..97a163665599dc67817db6f2b04ffd5772dd11cf 100644 (file)
@@ -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 <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IModule.h>
 #include <ModuleBase_ModelWidget.h>
 #include <ModuleBase_OperationFeature.h>
 
 const QString INVALID_VALUE = "invalid_action";
 
 
-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)
 {
 
 }
@@ -41,13 +47,37 @@ 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();
+  QString anError = myWorkshop->module()->getFeatureError(theFeature);
 
-  bool isActionEnabled = theAction->data() != INVALID_VALUE;
+  //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) {
+    QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+    updateActionState(anOkAction, theFeature);
+  }
+}
 
-  QString anError = getFeatureError(theFeature);
+void XGUI_ErrorMgr::updateAcceptAllAction(const FeaturePtr& theFeature)
+{
+  QString anError = myWorkshop->module()->getFeatureError(theFeature);
+
+  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(anError);
+  }
+}
+
+bool XGUI_ErrorMgr::canProcessClick(QAction* theAction, const FeaturePtr& theFeature)
+{
+  QString anError = myWorkshop->module()->getFeatureError(theFeature);
+  bool isActionEnabled = anError.isEmpty();
   if (!isActionEnabled && !anError.isEmpty()) {
     if (!myErrorDialog) {
       myErrorDialog = new QDialog(QApplication::desktop(), Qt::Popup);
@@ -71,28 +101,31 @@ bool XGUI_ErrorMgr::canProcessClick(QAction* theAction, const FeaturePtr& theFea
   return isActionEnabled;
 }
 
-void XGUI_ErrorMgr::updateActionState(QAction* theAction, const FeaturePtr& theFeature,
-                                      const bool theEnabled)
+void XGUI_ErrorMgr::updateActionState(QAction* theAction, const FeaturePtr& theFeature/*,
+                                      const bool theEnabled*/)
 {
+  QString anError = myWorkshop->module()->getFeatureError(theFeature);
+  bool anEnabled = anError.isEmpty();
+
   bool isActionEnabled = theAction->data() != INVALID_VALUE;
-  if (theEnabled  != isActionEnabled) {
+  if (anEnabled  != isActionEnabled) {
     // update enable state of the button
-    theAction->setIcon(theEnabled ? QIcon(":pictures/button_ok.png"): QIcon(":pictures/button_ok_error.png"));
-    if (theEnabled)
+    theAction->setIcon(anEnabled ? QIcon(":pictures/button_ok.png"): QIcon(":pictures/button_ok_error.png"));
+    if (anEnabled)
       theAction->setData("");
     else
       theAction->setData(INVALID_VALUE);
   }
-
-  // update controls error information
-  QWidget* aWidget = myPropertyPanel->headerWidget();
-  if (theEnabled)
-    aWidget->setToolTip("");
-  else
-    aWidget->setToolTip(getFeatureError(theFeature));
+  // 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(anError);
+  }
 }
 
-const char* toString(ModelAPI_ExecState theExecState) 
+/*const char* toString(ModelAPI_ExecState theExecState) 
 {
 #define TO_STRING(__NAME__) case __NAME__: return #__NAME__;
   switch (theExecState) {
@@ -104,7 +137,7 @@ const char* toString(ModelAPI_ExecState theExecState)
   default: return "Unknown ExecState.";
   }
 #undef TO_STRING
-}
+}*/
 
 /*void XGUI_ErrorMgr::onValidationStateChanged()
 {
@@ -126,7 +159,7 @@ const char* toString(ModelAPI_ExecState theExecState)
   }
 }*/
 
-QString XGUI_ErrorMgr::getFeatureError(const FeaturePtr& theFeature) const
+/*QString XGUI_ErrorMgr::getFeatureError(const FeaturePtr& theFeature) const
 {
   QString anError;
   // get feature
@@ -143,7 +176,7 @@ QString XGUI_ErrorMgr::getFeatureError(const FeaturePtr& theFeature) const
   }
 
   return anError;
-}
+}*/
 
 void XGUI_ErrorMgr::onWidgetChanged()
 {
@@ -185,3 +218,9 @@ void XGUI_ErrorMgr::onWidgetChanged()
     //aWidget->setStyleSheet(anError.isEmpty() ? "" : "background-color:pink;");
   }
 }
+
+XGUI_Workshop* XGUI_ErrorMgr::workshop() const
+{
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  return aConnector->workshop();
+}