--- /dev/null
+// 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);
+ }
+}
--- /dev/null
+// 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_ */
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Result.h>
#include <Events_Loop.h>
+#include <Events_LongOp.h>
using namespace std;
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);
// 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;
}