]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #79 GUI part for posting NewGeom messages through Qt's event system
authorsbh <sergey.belash@opencascade.com>
Fri, 12 Sep 2014 14:49:16 +0000 (18:49 +0400)
committersbh <sergey.belash@opencascade.com>
Fri, 12 Sep 2014 14:49:16 +0000 (18:49 +0400)
src/Config/Config_ValidatorMessage.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_QtEvents.cpp [new file with mode: 0644]
src/XGUI/XGUI_QtEvents.h [new file with mode: 0644]
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index e344cd8863fcfd2f7b6461e70b55e54c0ea0a554..16ec279222b136d3d9c06fbe46ee7132e36b0c51 100644 (file)
@@ -5,8 +5,8 @@
  *      Author: sbh
  */
 
-#ifndef Config_ValidatorMessage_H_
-#define Config_ValidatorMessage_H_
+#ifndef CONFIG_VALIDATORMESSAGE_H_
+#define CONFIG_VALIDATORMESSAGE_H_
 
 #include <Events_Message.h>
 #include <Config_def.h>
@@ -25,16 +25,21 @@ class Config_ValidatorMessage : public Events_Message
   std::list<std::string> myVaidatorParameters;
 
  public:
-  CONFIG_EXPORT Config_ValidatorMessage(const Events_ID theId, const void* theParent = 0);CONFIG_EXPORT virtual ~Config_ValidatorMessage();
+  CONFIG_EXPORT Config_ValidatorMessage(const Events_ID theId, const void* theParent = 0);
+  CONFIG_EXPORT virtual ~Config_ValidatorMessage();
 
   //CONFIG_EXPORT static const char* UID() const;
 
-  CONFIG_EXPORT const std::string& validatorId() const;CONFIG_EXPORT const std::string& featureId() const;CONFIG_EXPORT const std::string& attributeId() const;CONFIG_EXPORT const std::list<
-      std::string>& parameters() const;CONFIG_EXPORT bool isValid() const;
+  CONFIG_EXPORT const std::string& validatorId() const;
+  CONFIG_EXPORT const std::string& featureId() const;
+  CONFIG_EXPORT const std::string& attributeId() const;
+  CONFIG_EXPORT const std::list<std::string>& parameters() const;
+  CONFIG_EXPORT bool isValid() const;
 
-  CONFIG_EXPORT void setValidatorId(const std::string& theId);CONFIG_EXPORT void setFeatureId(
-      const std::string& theId);CONFIG_EXPORT void setAttributeId(const std::string& theId);CONFIG_EXPORT void setValidatorParameters(
-      const std::list<std::string>& parameters);
+  CONFIG_EXPORT void setValidatorId(const std::string& theId);
+  CONFIG_EXPORT void setFeatureId(const std::string& theId);
+  CONFIG_EXPORT void setAttributeId(const std::string& theId);
+  CONFIG_EXPORT void setValidatorParameters(const std::list<std::string>& parameters);
 };
 
 #endif /* Config_ValidatorMessage_H_ */
index 9f336606eb0df5e543770b831ba71aa74ee5f99e..34fe79010c0933d35f158b01e4978a12605934b4 100644 (file)
@@ -33,6 +33,7 @@ SET(PROJECT_HEADERS
        XGUI_Selection.h
        XGUI_Preferences.h
        XGUI_IPrefMgr.h
+       XGUI_QtEvents.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -65,6 +66,7 @@ SET(PROJECT_SOURCES
     XGUI_ModuleConnector.cpp
        XGUI_Selection.cpp
        XGUI_Preferences.cpp
+       XGUI_QtEvents.cpp
 )
 
 SET(PROJECT_RESOURCES 
diff --git a/src/XGUI/XGUI_QtEvents.cpp b/src/XGUI/XGUI_QtEvents.cpp
new file mode 100644 (file)
index 0000000..e3eb2b0
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * XGUI_QEvents.cpp
+ *
+ *  Created on: Sep 12, 2014
+ *      Author: sbh
+ */
+
+#include "XGUI_QtEvents.h"
+
+QEvent::Type PostponeMessageQtEvent::PostponeMessageQtEventType = QEvent::Type(QEvent::registerEventType());
+
+
+//TODO(mpv): #4
+//boost::shared_ptr<Events_Message> PostponeMessageQtEvent::postponedMessage()
+boost::shared_ptr<ModelAPI_Document> PostponeMessageQtEvent::resultDoc()
+{
+  return myTestDoc;
+}
+
diff --git a/src/XGUI/XGUI_QtEvents.h b/src/XGUI/XGUI_QtEvents.h
new file mode 100644 (file)
index 0000000..5c415a2
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * XGUI_QEvents.h
+ *
+ *  Created on: Sep 12, 2014
+ *      Author: sbh
+ */
+
+#ifndef XGUI_QTEVENTS_H_
+#define XGUI_QTEVENTS_H_
+
+#include <XGUI.h>
+
+#include <ModelAPI_ResultPart.h>
+#include <Events_Message.h>
+
+#include <QEvent>
+#include <QString>
+
+class XGUI_EXPORT PostponeMessageQtEvent : public QEvent
+{
+ public:
+  static QEvent::Type PostponeMessageQtEventType;
+
+  //TODO(mpv): ModelAPI_Document is taken here for example
+  //the commented code should be ok when you implement boost::shared_ptr on Events_Message
+  //the same for #1-4
+  PostponeMessageQtEvent(boost::shared_ptr<ModelAPI_Document> theDoc)
+  //PostponeMessageQtEvent(boost::shared_ptr<Events_Message> theMessage)
+      : QEvent(PostponeMessageQtEventType),
+      //TODO(mpv): #1
+      //myMessage(theMessage)
+        myTestDoc(theDoc)
+  {
+  }
+  static QEvent::Type type()
+  {
+    return PostponeMessageQtEventType;
+  }
+
+  //TODO(mpv): #2
+  //boost::shared_ptr<Events_Message> postponedMessage();
+  boost::shared_ptr<ModelAPI_Document> resultDoc();
+
+ private:
+  //TODO(mpv): #3
+  //boost::shared_ptr<Events_Message> myMessage;
+  boost::shared_ptr<ModelAPI_Document> myTestDoc;
+};
+
+#endif /* XGUI_QEVENTS_H_ */
index 27b9716acf38f2ea721b51994e659856c595bed8..bc7625b9af6418a76cb8d9114745d22382cf6c8c 100644 (file)
@@ -22,6 +22,7 @@
 #include "XGUI_ContextMenuMgr.h"
 #include "XGUI_ModuleConnector.h"
 #include "XGUI_Preferences.h"
+#include <XGUI_QtEvents.h>
 
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
 #include <QPushButton>
 #include <QDockWidget>
 #include <QLayout>
-#include <QTimer>
+#include <QThread>
+#include <QObject>
 
 #ifdef _DEBUG
 #include <QDebug>
+#include <iostream>
 #endif
 
 #ifdef WIN32
@@ -232,6 +235,16 @@ XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
 //******************************************************
 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
 {
+  if (QApplication::instance()->thread() != QThread::currentThread()) {
+    #ifdef _DEBUG
+    std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
+    #endif
+    SessionPtr aMgr = ModelAPI_Session::get();
+    PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(aMgr->activeDocument());
+    QApplication::postEvent(this, aPostponeEvent);
+    return;
+  }
+
   //A message to start feature creation received.
   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED)) {
     const Config_FeatureMessage* aFeatureMsg =
@@ -280,7 +293,6 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage)
   else if (theMessage->eventID() == Events_LongOp::eventID()) {
     if (Events_LongOp::isPerformed())
       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-    //QTimer::singleShot(10, this, SLOT(onStartWaiting()));
     else
       QApplication::restoreOverrideCursor();
   }
@@ -477,6 +489,31 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
   myPropertyPanel->cleanContent();
 }
 
+bool XGUI_Workshop::event(QEvent * theEvent)
+{
+  PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
+  if (aPostponedEv) {
+#ifdef _DEBUG
+    std::cout << "XGUI_Workshop::event " << "Got PostponeMessageQtEvent" << std::endl;
+    bool isMyThread = (QApplication::instance()->thread() == QThread::currentThread());
+    std::cout << "XGUI_Workshop::event " << "I am in the Qt's thread: "
+              << isMyThread << std::endl;
+#endif
+    boost::shared_ptr<ModelAPI_Document> aDoc = aPostponedEv->resultDoc();
+    if (aDoc) {
+#ifdef _DEBUG
+      std::cout << "XGUI_Workshop::event " << "Passed boost ptr is ok, doc id: " << aDoc->id()
+          << std::endl;
+#endif
+    }
+    //TODO(mpv): After modifications in the XGUI_QtEvents.* this code should be like...
+    //boost::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
+    //processEvent(aEventPtr);
+    return true;
+  }
+  return false;
+}
+
 /*
  *
  */
index b969861682dec1ec56492aa3dbdf5e594737f444..b4073224ab167a7a2065ba679b787fa32319c23c 100644 (file)
@@ -211,6 +211,7 @@ signals:
   void activateLastPart();
 
  protected:
+  bool event(QEvent * theEvent);
   //Event-loop processing methods:
   void addFeature(const Config_FeatureMessage*);
   void connectWithOperation(ModuleBase_Operation* theOperation);