From ce77e62550c698202229cb42f5e3486bed235668 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 29 Jul 2014 16:01:04 +0400 Subject: [PATCH] Wait cursor for solver operation --- src/Events/Events_LongOp.cpp | 12 ++++++------ src/Events/Events_LongOp.h | 2 +- src/Model/Model_Update.cpp | 4 ++-- src/SketchSolver/SketchSolver_Solver.cpp | 3 +++ src/XGUI/XGUI_Workshop.cpp | 13 +++++++++++-- src/XGUI/XGUI_Workshop.h | 2 ++ 6 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/Events/Events_LongOp.cpp b/src/Events/Events_LongOp.cpp index 7cc46c3cd..647d2bb4c 100644 --- a/src/Events/Events_LongOp.cpp +++ b/src/Events/Events_LongOp.cpp @@ -10,7 +10,7 @@ std::map MY_SENDERS; Events_LongOp::Events_LongOp(void* theSender) - : Events_Message(Events_LongOp::errorID(), theSender) + : Events_Message(Events_LongOp::eventID(), theSender) { } @@ -18,7 +18,7 @@ Events_LongOp::~Events_LongOp() { } -Events_ID Events_LongOp::errorID() +Events_ID Events_LongOp::eventID() { Events_Loop* aLoop = Events_Loop::loop(); return aLoop->eventByName("LongOperation"); @@ -33,8 +33,8 @@ void Events_LongOp::start(void* theSender) MY_SENDERS[theSender]++; if (toSend) { - Events_LongOp anError(theSender); - Events_Loop::loop()->send(anError); + Events_LongOp anEvent(theSender); + Events_Loop::loop()->send(anEvent); } } @@ -46,8 +46,8 @@ void Events_LongOp::end(void* theSender) else MY_SENDERS[theSender] = aCount - 1; } if (MY_SENDERS.empty()) { - Events_LongOp anError(theSender); - Events_Loop::loop()->send(anError); + Events_LongOp anEvent(theSender); + Events_Loop::loop()->send(anEvent); } } diff --git a/src/Events/Events_LongOp.h b/src/Events/Events_LongOp.h index bc698ac50..dfb06cae4 100644 --- a/src/Events/Events_LongOp.h +++ b/src/Events/Events_LongOp.h @@ -17,7 +17,7 @@ class EVENTS_EXPORT Events_LongOp: public Events_Message public: virtual ~Events_LongOp(); /// Returns the identifier of this event - static Events_ID errorID(); + static Events_ID eventID(); /// Starts the long operation static void start(void* theSender = 0); /// Stops the long operation diff --git a/src/Model/Model_Update.cpp b/src/Model/Model_Update.cpp index af5407caf..d8ccc3dd9 100644 --- a/src/Model/Model_Update.cpp +++ b/src/Model/Model_Update.cpp @@ -26,7 +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); + //Events_LongOp::start(this); isExecuted = true; const ModelAPI_ObjectUpdatedMessage* aMsg = dynamic_cast(theMessage); @@ -52,7 +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); + //Events_LongOp::end(this); isExecuted = false; } diff --git a/src/SketchSolver/SketchSolver_Solver.cpp b/src/SketchSolver/SketchSolver_Solver.cpp index 40c76d1a7..b91d267f6 100644 --- a/src/SketchSolver/SketchSolver_Solver.cpp +++ b/src/SketchSolver/SketchSolver_Solver.cpp @@ -3,6 +3,7 @@ // Author: Artem ZHIDKOV #include "SketchSolver_Solver.h" +#include SketchSolver_Solver::SketchSolver_Solver() { @@ -111,7 +112,9 @@ int SketchSolver_Solver::solve() if (myEquationsSystem.constraints <= 0) return SLVS_RESULT_EMPTY_SET; + Events_LongOp::start(this); Slvs_Solve(&myEquationsSystem, myGroupID); + Events_LongOp::end(this); return myEquationsSystem.result; } diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 5cf57b2aa..fe055eff4 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -264,10 +264,11 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) return; } - if (theMessage->eventID() == Events_Loop::loop()->eventByName("LongOperation")) { + if (theMessage->eventID() == Events_LongOp::eventID()) { if (Events_LongOp::isPerformed()) QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); - else + //QTimer::singleShot(10, this, SLOT(onStartWaiting())); + else QApplication::restoreOverrideCursor(); return; } @@ -294,6 +295,14 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } } +//****************************************************** +void XGUI_Workshop::onStartWaiting() +{ + if (Events_LongOp::isPerformed()) { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + } +} + //****************************************************** void XGUI_Workshop::onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg) { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 3fbe33e20..b857becb3 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -179,6 +179,8 @@ protected slots: void onWidgetValuesChanged(); + void onStartWaiting(); + private: void initMenu(); -- 2.39.2