Salome HOME
Application errors handling
authorsbh <sergey.belash@opencascade.com>
Tue, 29 Apr 2014 07:35:46 +0000 (11:35 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 29 Apr 2014 07:35:46 +0000 (11:35 +0400)
src/Events/CMakeLists.txt
src/Events/Events_Error.cpp [new file with mode: 0644]
src/Events/Events_Error.h [new file with mode: 0644]
src/PartSet/PartSet_Module.cpp
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ErrorDialog.cpp [new file with mode: 0644]
src/XGUI/XGUI_ErrorDialog.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index 08c3903c2dccbcb65d12f81634dea337c1e6dca2..89a27f31c8a51a7bfc3b92920942925b95d0a7c2 100644 (file)
@@ -5,12 +5,14 @@ SET(PROJECT_HEADERS
     Events_Message.h
     Events_Listener.h
     Events_Loop.h
+    Events_Error.h
 )
 
 SET(PROJECT_SOURCES
     Events_Message.cpp
     Events_Listener.cpp
     Events_Loop.cpp
+    Events_Error.cpp
 )
 
 ADD_DEFINITIONS(-DEVENTS_EXPORTS)
diff --git a/src/Events/Events_Error.cpp b/src/Events/Events_Error.cpp
new file mode 100644 (file)
index 0000000..eba313e
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Events_Error.cpp
+ *
+ *  Created on: Apr 28, 2014
+ *      Author: sbh
+ */
+
+#include <Events_Error.h>
+#include <Events_Loop.h>
+
+Events_Error::Events_Error(char* theDescription, const void* theSender)
+ : Events_Message(Events_Error::errorID(), theSender)
+{
+  myDescription = theDescription;
+}
+
+Events_Error::~Events_Error()
+{
+}
+
+Events_ID Events_Error::errorID()
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  return aLoop->eventByName("ApplicationError");
+}
+
+char* Events_Error::description() const
+{
+  return myDescription;
+}
+
+void Events_Error::send(char* theDescription, const void* theSender)
+{
+  Events_Error anError(theDescription, theSender);
+  Events_Loop::loop()->send(anError);
+}
+
+static void send(std::string theDescription, const void* theSender = 0)
+{
+  Events_Error::send(theDescription.c_str(), theSender);
+}
diff --git a/src/Events/Events_Error.h b/src/Events/Events_Error.h
new file mode 100644 (file)
index 0000000..7e2e62e
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Events_Error.h
+ *
+ *  Created on: Apr 28, 2014
+ *      Author: sbh
+ */
+
+#ifndef EVENTS_ERROR_H_
+#define EVENTS_ERROR_H_
+
+#include <Events.h>
+#include <Events_Message.h>
+
+#include <string>
+
+class EVENTS_EXPORT Events_Error: public Events_Message
+{
+  char* myDescription; ///< pointer to the description of the error
+
+public:
+  virtual ~Events_Error();
+
+  static Events_ID errorID();
+  char* description() const;
+  static void send(char* theDescription, const void* theSender = 0);
+  static void send(std::string theDescription, const void* theSender = 0);
+
+protected:
+  Events_Error(char* theDescription, const void* theSender = 0);
+};
+
+#endif /* EVENTS_ERROR_H_ */
index 8acf0c38cb12232c1f6dfee1ff79ceb63e266e74..9eece1559f9a44fc8d35bfa67c1c3497d0ca8d04 100644 (file)
@@ -19,6 +19,7 @@
 #include <Config_WidgetReader.h>
 #include <Events_Loop.h>
 #include <Events_Message.h>
+#include <Events_Error.h>
 
 #include <GeomAPI_Shape.h>
 
index 989980d3b6703be775e7e581dceab9942f963da5..d8de8a441ad697af43190a3fe5aa38200e6af2e6 100644 (file)
@@ -27,6 +27,7 @@ SET(PROJECT_HEADERS
     XGUI_SelectionMgr.h
     XGUI_SalomeConnector.h
     XGUI_ActionsMgr.h
+    XGUI_ErrorDialog.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -53,6 +54,7 @@ SET(PROJECT_SOURCES
        XGUI_OperationMgr.cpp
     XGUI_SelectionMgr.cpp
     XGUI_ActionsMgr.cpp
+    XGUI_ErrorDialog.cpp
 )
 
 SET(PROJECT_RESOURCES 
diff --git a/src/XGUI/XGUI_ErrorDialog.cpp b/src/XGUI/XGUI_ErrorDialog.cpp
new file mode 100644 (file)
index 0000000..5a8258d
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * XGUI_ErrorDialog.cpp
+ *
+ *  Created on: Apr 28, 2014
+ *      Author: sbh
+ */
+#include <XGUI_ErrorDialog.h>
+
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QTextEdit>
+
+XGUI_ErrorDialog::XGUI_ErrorDialog(QWidget* parent)
+    : QDialog(parent)
+{
+  QVBoxLayout* aDlgLay = new QVBoxLayout(this);
+  setWindowTitle(tr("Application errors"));
+  myErrorLog = new QTextEdit(this);
+  myErrorLog->setReadOnly(true);
+  aDlgLay->addWidget(myErrorLog);
+  QDialogButtonBox* aButtonBox =
+      new QDialogButtonBox(QDialogButtonBox::Close, Qt::Horizontal, this);
+  aDlgLay->addWidget(aButtonBox);
+  aDlgLay->setContentsMargins(2,2,2,2);
+  aDlgLay->setSpacing(2);
+  setLayout(aDlgLay);
+  resize(420, 240);
+
+  connect(aButtonBox, SIGNAL(accepted()), this, SLOT(clear()));
+  connect(aButtonBox, SIGNAL(rejected()), this, SLOT(clear()));
+}
+
+XGUI_ErrorDialog::~XGUI_ErrorDialog()
+{
+}
+
+void XGUI_ErrorDialog::refresh()
+{
+  myErrorLog->clear();
+  foreach(QString eachError, myErrors)
+  {
+    myErrorLog->append(eachError);
+  }
+}
+
+void XGUI_ErrorDialog::clear()
+{
+  myErrorLog->clear();
+  myErrors.clear();
+  QDialog::reject();
+}
+
+void XGUI_ErrorDialog::addError(const QString& theError)
+{
+  myErrors.append(theError);
+  refresh();
+}
+
+void XGUI_ErrorDialog::removeError(const QString& theError)
+{
+  myErrors.removeAll(theError);
+  refresh();
+}
+
diff --git a/src/XGUI/XGUI_ErrorDialog.h b/src/XGUI/XGUI_ErrorDialog.h
new file mode 100644 (file)
index 0000000..59de505
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * XGUI_ErrorDialog.h
+ *
+ *  Created on: Apr 28, 2014
+ *      Author: sbh
+ */
+
+#ifndef XGUI_ERRORDIALOG_H_
+#define XGUI_ERRORDIALOG_H_
+
+#include <XGUI.h>
+#include <QDialog>
+
+class QTextEdit;
+
+class XGUI_ErrorDialog: public QDialog
+{
+  Q_OBJECT
+public:
+  XGUI_EXPORT XGUI_ErrorDialog(QWidget* parent);
+  XGUI_EXPORT virtual ~XGUI_ErrorDialog();
+
+public slots:
+  XGUI_EXPORT void refresh();
+  XGUI_EXPORT void clear();
+  XGUI_EXPORT void addError(const QString&);
+  XGUI_EXPORT void removeError(const QString&);
+
+private:
+  QTextEdit* myErrorLog;
+  QStringList myErrors;
+};
+
+#endif /* XGUI_ERRORDIALOG_H_ */
index 6186aaedd3ab39aff8b9dc2fb383174999d7a8fb..dd6e1200fc321ab3db8b5f3fd42f04f45d916ab4 100644 (file)
@@ -15,6 +15,7 @@
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
 #include "XGUI_ActionsMgr.h"
+#include "XGUI_ErrorDialog.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Feature.h>
@@ -22,6 +23,7 @@
 #include <ModelAPI_AttributeDocRef.h>
 
 #include <Events_Loop.h>
+#include <Events_Error.h>
 #include <ModuleBase_PropPanelOperation.h>
 #include <ModuleBase_Operation.h>
 #include <Config_FeatureMessage.h>
@@ -63,9 +65,12 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   mySelector = new XGUI_SelectionMgr(this);
   myOperationMgr = new XGUI_OperationMgr(this);
   myActionsMgr = new XGUI_ActionsMgr(this);
+  myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
+
   connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
+  connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
 }
 
 //******************************************************
@@ -79,6 +84,7 @@ void XGUI_Workshop::startApplication()
   initMenu();
   //Initialize event listening
   Events_Loop* aLoop = Events_Loop::loop();
+  aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
   //TODO(sbh): Implement static method to extract event id [SEID]
   Events_ID aFeatureId = aLoop->eventByName("FeatureEvent");
   aLoop->registerListener(this, aFeatureId);
@@ -175,13 +181,11 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
 {
   static Events_ID aFeatureId = Events_Loop::loop()->eventByName("FeatureEvent");
   if (theMessage->eventID() == aFeatureId) {
-    const Config_FeatureMessage* aFeatureMsg =
-        dynamic_cast<const Config_FeatureMessage*>(theMessage);
+    const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
     addFeature(aFeatureMsg);
     return;
   }
-  const Config_PointerMessage* aPartSetMsg =
-      dynamic_cast<const Config_PointerMessage*>(theMessage);
+  const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
   if (aPartSetMsg) {
     ModuleBase_PropPanelOperation* anOperation =
         (ModuleBase_PropPanelOperation*)(aPartSetMsg->pointer());
@@ -194,6 +198,13 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
     }
     return;
   }
+  const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
+  if (anAppError) {
+      emit errorOccurred(QString::fromLatin1(anAppError->description()));
+      myErrorDlg->show();
+      myErrorDlg->raise();
+      myErrorDlg->activateWindow();
+  }
 
 #ifdef _DEBUG
   qDebug() << "XGUI_Workshop::ProcessEvent: "
index bedb8bbe119f481fd71ce60b847127104dfe6c9f..6406381ed243554dbcdd6accc9f70c71d4ba051d 100644 (file)
@@ -19,6 +19,7 @@ class XGUI_OperationMgr;
 class XGUI_SalomeConnector;
 class XGUI_ObjectsBrowser;
 class XGUI_ActionsMgr;
+class XGUI_ErrorDialog;
 class ModuleBase_Operation;
 class ModuleBase_PropPanelOperation;
 
@@ -90,6 +91,9 @@ public slots:
 
   void onFeatureTriggered();
 
+signals:
+  void errorOccurred(const QString&);
+
 protected:
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
@@ -128,6 +132,7 @@ private:
   XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
   XGUI_ActionsMgr* myActionsMgr;
   XGUI_SalomeConnector* mySalomeConnector;
+  XGUI_ErrorDialog* myErrorDlg;
 };
 
 #endif