From: mpv Date: Tue, 29 Jul 2014 07:24:51 +0000 (+0400) Subject: Introduce Long Operation event: now for waiting cursor only X-Git-Tag: V_0.4.4~136^2~1^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a0247c36615e233b68bc5ed98c1b87a999a4a51e;p=modules%2Fshaper.git Introduce Long Operation event: now for waiting cursor only --- diff --git a/src/Events/CMakeLists.txt b/src/Events/CMakeLists.txt index af4155f42..b33e85166 100644 --- a/src/Events/CMakeLists.txt +++ b/src/Events/CMakeLists.txt @@ -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 index 000000000..04fc6734e --- /dev/null +++ b/src/Events/Events_LongOp.cpp @@ -0,0 +1,50 @@ +// File: Events_LongOp.cpp +// Created: 29 Jul 2014 +// Author: Mikhail PONIKAROV + +#include +#include + +/// senders of the long operation collected, ends the long operation event only +/// if all senders are stopped +std::map 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 index 000000000..bc698ac50 --- /dev/null +++ b/src/Events/Events_LongOp.h @@ -0,0 +1,32 @@ +// File: Events_LongOp.h +// Created: 29 Jul 2014 +// Author: Mikhail PONIKAROV + +#ifndef EVENTS_LONGOP_H_ +#define EVENTS_LONGOP_H_ + +#include +#include + +/** + * 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_ */ diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index 070e5a8c0..af5407caf 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -11,6 +11,7 @@ #include #include #include +#include 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(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; }