]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'master' of newgeom:newgeom.git
authorsbh <sergey.belash@opencascade.com>
Tue, 29 Apr 2014 07:37:19 +0000 (11:37 +0400)
committersbh <sergey.belash@opencascade.com>
Tue, 29 Apr 2014 07:37:19 +0000 (11:37 +0400)
Conflicts:
src/XGUI/XGUI_Workshop.h

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 bc383d3019f745a6025c688d96652a46685c3315..5fb8796e0eedafb0be7ea2bf9e607af989b1f7a8 100644 (file)
@@ -20,6 +20,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 2655b569456ab43b28ea6227a5a35987696e4185..e36e3c26998e037642480ed913fb20c29556a4b4 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>
@@ -46,7 +48,8 @@
 #endif
 
 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
-  : QObject(), 
+  : QObject(),
+  myCurrentFile(QString()),
   myPartSetModule(NULL),
   mySalomeConnector(theConnector),
   myPropertyPanelDock(0),
@@ -63,9 +66,12 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
   connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
   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 +85,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 +182,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 +199,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: "
@@ -307,9 +319,34 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
   connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
 }
 
+/*
+ * Saves document with given name.
+ */
+void XGUI_Workshop::saveDocument(QString theName)
+{
+  QApplication::restoreOverrideCursor();
+  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+  aDoc->save(theName.toLatin1().constData());
+  QApplication::restoreOverrideCursor();
+}
+
 //******************************************************
 void XGUI_Workshop::onExit()
 {
+  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+  if(aDoc->isModified()) {
+    int anAnswer = QMessageBox::question(
+        myMainWindow, tr("Save current file"),
+        tr("The document is modified, save before exit?"),
+        QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
+    if(anAnswer == QMessageBox::Save) {
+      onSave();
+    } else if (anAnswer == QMessageBox::Cancel) {
+      return;
+    }
+  }
   qApp->exit();
 }
 
@@ -334,21 +371,66 @@ void XGUI_Workshop::onNew()
 //******************************************************
 void XGUI_Workshop::onOpen()
 {
-  //QString aFileName = QFileDialog::getOpenFileName(mainWindow());
+  //save current file before close if modified
+  boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+  boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
+  if(aDoc->isModified()) {
+    //TODO(sbh): re-launch the app?
+    int anAnswer = QMessageBox::question(
+        myMainWindow, tr("Save current file"),
+        tr("The document is modified, save before opening another?"),
+        QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
+    if(anAnswer == QMessageBox::Save) {
+      onSave();
+    } else if (anAnswer == QMessageBox::Cancel) {
+      return;
+    }
+    aDoc->close();
+    myCurrentFile = "";
+  }
+
+  //show file dialog, check if readable and open
+  myCurrentFile = QFileDialog::getOpenFileName(mainWindow());
+  if(myCurrentFile.isEmpty())
+    return;
+  QFileInfo aFileInfo(myCurrentFile);
+  if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
+    QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
+    myCurrentFile = "";
+    return;
+  }
+  QApplication::setOverrideCursor(Qt::WaitCursor);
+  aDoc->load(myCurrentFile.toLatin1().constData());
+  QApplication::restoreOverrideCursor();
   updateCommandStatus();
 }
 
 //******************************************************
 void XGUI_Workshop::onSave()
 {
+  if(myCurrentFile.isEmpty()) {
+    onSaveAs();
+    return;
+  }
+  saveDocument(myCurrentFile);
   updateCommandStatus();
 }
 
 //******************************************************
 void XGUI_Workshop::onSaveAs()
 {
-  //QString aFileName = QFileDialog::getSaveFileName(mainWindow());
-  updateCommandStatus();
+  QString aTemp = myCurrentFile;
+  myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
+  if(myCurrentFile.isEmpty()) {
+    myCurrentFile = aTemp;
+    return;
+  }
+  QFileInfo aFileInfo(myCurrentFile);
+  if(aFileInfo.exists() && !aFileInfo.isWritable()) {
+    QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
+    return;
+  }
+  onSave();
 }
 
 //******************************************************
index 7d75839cfae07bc44d117b5e762b673b8212a8cb..3f857ff12400d7f12e68d8f34869a788b504ac65 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;
 
@@ -94,13 +95,16 @@ public slots:
   void hideObjectBrowser();
 
   void onFeatureTriggered();
-
   void changeCurrentDocument();
 
+signals:
+  void errorOccurred(const QString&);
+
 protected:
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
   void connectWithOperation(ModuleBase_Operation* theOperation);
+  void saveDocument(QString theName);
 
 protected slots:
   /// SLOT, that is called after the operation is started. Update workshop state according to
@@ -124,21 +128,17 @@ private:
   void createDockWidgets();
   void setPropertyPannelTitle(const QString& theTitle);
 
-
+  QString myCurrentFile;
   XGUI_MainWindow* myMainWindow;
   XGUI_Module* myPartSetModule;
-
   XGUI_ObjectsBrowser* myObjectBrowser;
   QDockWidget* myPropertyPanelDock;
-
   XGUI_SelectionMgr* mySelector;
   XGUI_Displayer* myDisplayer;
-
   XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
   XGUI_ActionsMgr* myActionsMgr;
-
-
   XGUI_SalomeConnector* mySalomeConnector;
+  XGUI_ErrorDialog* myErrorDlg;
 };
 
 #endif