]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Introduce Long Operation event: now for waiting cursor only
authormpv <mikhail.ponikarov@opencascade.com>
Tue, 29 Jul 2014 07:24:51 +0000 (11:24 +0400)
committermpv <mikhail.ponikarov@opencascade.com>
Tue, 29 Jul 2014 07:24:51 +0000 (11:24 +0400)
src/Events/CMakeLists.txt
src/Events/Events_LongOp.cpp [new file with mode: 0644]
src/Events/Events_LongOp.h [new file with mode: 0644]
src/Model/Model_Update.cpp

index af4155f4268119e19d78b8f3a0241823fb22e9de..b33e8516623d2ae4080d88f0472f2d9277a12ec3 100644 (file)
@@ -7,6 +7,7 @@ SET(PROJECT_HEADERS
     Events_Listener.h
     Events_Loop.h
     Events_Error.h
+    Events_LongOp.h
 )
 
 SET(PROJECT_SOURCES
@@ -14,6 +15,7 @@ SET(PROJECT_SOURCES
     Events_Listener.cpp
     Events_Loop.cpp
     Events_Error.cpp
+    Events_LongOp.cpp
 )
 
 ADD_DEFINITIONS(-DEVENTS_EXPORTS)
diff --git a/src/Events/Events_LongOp.cpp b/src/Events/Events_LongOp.cpp
new file mode 100644 (file)
index 0000000..04fc673
--- /dev/null
@@ -0,0 +1,50 @@
+// File:        Events_LongOp.cpp
+// Created:     29 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#include <Events_LongOp.h>
+#include <Events_Loop.h>
+
+/// senders of the long operation collected, ends the long operation event only
+/// if all senders are stopped
+std::map<void*, int> MY_SENDERS;
+
+Events_LongOp::Events_LongOp(void* theSender)
+ : Events_Message(Events_LongOp::errorID(), theSender)
+{
+}
+
+Events_LongOp::~Events_LongOp()
+{
+}
+
+Events_ID Events_LongOp::errorID()
+{
+  Events_Loop* aLoop = Events_Loop::loop();
+  return aLoop->eventByName("LongOperation");
+}
+
+void Events_LongOp::start(void* theSender)
+{
+  if (MY_SENDERS.empty()) {
+    Events_LongOp anError(theSender);
+    Events_Loop::loop()->send(anError);
+  }
+  if (MY_SENDERS.find(theSender) == MY_SENDERS.end())
+    MY_SENDERS[theSender] = 1;
+  else 
+    MY_SENDERS[theSender]++;
+}
+
+void Events_LongOp::end(void* theSender)
+{
+  if (MY_SENDERS.find(theSender) != MY_SENDERS.end()) {
+    int aCount = MY_SENDERS[theSender];
+    if (aCount <= 1) MY_SENDERS.erase(theSender);
+    else MY_SENDERS[theSender] = aCount - 1;
+  }
+  if (MY_SENDERS.empty()) {
+    Events_LongOp anError(theSender);
+    Events_Loop::loop()->send(anError);
+  }
+}
diff --git a/src/Events/Events_LongOp.h b/src/Events/Events_LongOp.h
new file mode 100644 (file)
index 0000000..bc698ac
--- /dev/null
@@ -0,0 +1,32 @@
+// File:        Events_LongOp.h
+// Created:     29 Jul 2014
+// Author:      Mikhail PONIKAROV
+
+#ifndef EVENTS_LONGOP_H_
+#define EVENTS_LONGOP_H_
+
+#include <Events.h>
+#include <Events_Message.h>
+
+/**
+ * Informs the application that the long operation is performed.
+ * Causes waiting coursor in GUI.
+ */
+class EVENTS_EXPORT Events_LongOp: public Events_Message
+{
+public:
+  virtual ~Events_LongOp();
+  /// Returns the identifier of this event
+  static Events_ID errorID();
+  /// Starts the long operation
+  static void start(void* theSender = 0);
+  /// Stops the long operation
+  static void end(void* theSender = 0);
+  /// Returns true if the long operation is performed
+  static bool isPerformed(); 
+
+protected:
+  Events_LongOp(void* theSender = 0);
+};
+
+#endif /* EVENTS_ERROR_H_ */
index 070e5a8c09f37f9a723ec0ba7d28c9ba222481ff..af5407cafedba7467c26761d5fc88277ca062f14 100644 (file)
@@ -11,6 +11,7 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Result.h>
 #include <Events_Loop.h>
+#include <Events_LongOp.h>
 
 using namespace std;
 
@@ -25,6 +26,7 @@ Model_Update::Model_Update()
 void Model_Update::processEvent(const Events_Message* theMessage)
 {
   if (isExecuted) return; // nothing to do: it is executed now
+  Events_LongOp::start(this);
   isExecuted = true;
   const ModelAPI_ObjectUpdatedMessage* aMsg = 
     dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
@@ -50,6 +52,7 @@ void Model_Update::processEvent(const Events_Message* theMessage)
   // flush
   static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
   Events_Loop::loop()->flush(EVENT_DISP);
+  Events_LongOp::end(this);
   isExecuted = false;
 }