Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
job.h
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21#ifndef __ANTARES_TOOLBOX_JOB_H__
22#define __ANTARES_TOOLBOX_JOB_H__
23
24#include <antares/logs/logs.h>
25#include <yuni/core/slist/slist.h>
26#include <yuni/thread/thread.h>
27#include <yuni/thread/timer.h>
28
29#include <wx/dialog.h>
30#include <wx/frame.h>
31#include <wx/animate.h>
32#include <wx/stattext.h>
33#include <wx/timer.h>
34#include <wx/stattext.h>
35#include <wx/regex.h>
36#include "../components/progressbar.h"
37#include "../create.h"
38#include <ui/common/component/panel.h>
39
40#include <mutex>
41#include <atomic>
42#include <list>
43
44namespace Antares
45{
46namespace Toolbox
47{
48namespace Jobs
49{
50// Forward declarations
51class JobThread;
52class TimerElapsedTime;
53class TimerRemainingTime;
54class PartList;
55
56class Job : public wxDialog, public Yuni::IEventObserver<Job>
57{
58public:
60
61
64 Job(const wxString& title, const wxString& subTitle, const char* icon);
68 virtual ~Job();
70
72
73 bool displayProgression() const
74 {
75 return pDisplayProgression;
76 }
77 void displayProgression(const bool v)
78 {
79 pDisplayProgression = v;
80 }
82
84
85 bool canCancel() const
86 {
87 return pCanCancel;
88 }
89 void canCancel(const bool v)
90 {
91 pCanCancel = v;
92 }
94
96
97 bool result() const
98 {
99 return pResult;
100 }
101 void result(const bool v)
102 {
103 pResult = v;
104 }
106
108
109
113 bool isRunning() const
114 {
115 return !(!pJobIsRunning);
116 }
117
121 bool run();
122
126 void stop();
128
129protected:
133 virtual bool executeTask() = 0; // Please override
134
140 void updateTheProgressValue(double progress);
141
148 void updateTheMessage(const wxString& msg, bool mustBeInterpreted = true);
149
157 virtual void onBeforeRunning()
158 {
159 }
160
168 virtual bool onRunQuery()
169 {
170 return true;
171 }
172
176 virtual void onCancel()
177 { /* do nothing */
178 }
179
184
188 void manageLogLevelMessage(enum LogLevel lvl, const wxString& msg);
189
190protected:
194 void onCancel(void*);
195
196 void evtOnClose(wxCloseEvent& evt);
197
198 void onLogMessage(int, const std::string& message);
199
200protected:
204 wxSizer* createMainPnl(wxWindow* parent);
205
209 wxSizer* createPnlButtons(wxWindow* parent);
210
211 wxSizer* createPnlLoading(wxWindow* parent);
212
216 void displayGauge(const bool visible = true);
217
218 void displayMessage(const wxString& line);
219
220 void onUIUpdateProgression(uint value);
221 void onUIUpdateMessage();
222 void onUIUpdateLabelErrors();
223
224 void onUIUpdateElapsedTime(const Yuni::String& text);
225 void onUIUpdateRemainingTime(const Yuni::String& text);
226
227 void evtOnInit(wxInitDialogEvent& event);
228
229 void deleteAllThreads();
230
231 void recomputeWindowSize();
232
233 void disableAllComponents();
234
235private:
237 const wxString& pTitle;
238 const wxString& pSubTitle;
239 const char* pIcon;
240 bool pDisplayProgression;
241 bool pCanCancel;
242 bool pResult;
243 long pMemoryFootprint;
244
246 wxSizer* pGaugeSizer;
247 wxSizer* pGaugeParentSizer;
248 wxSizer* pRemainingSizer;
250 wxSizer* pCancelSizer;
252 wxStaticText* pProgrText;
253 wxStaticText* pProgrSubText;
254 wxStaticText* pElapsedTimeText;
255 wxStaticText* pRemainingTimeText;
256 wxStaticText* pReadWriteStats;
258 Yuni::String::ListPtr pWarningList;
259 Yuni::String::ListPtr pErrorList;
260
261 std::atomic<int> pJobIsRunning;
262 std::atomic<int> pGUICanUpdate;
263
264 // Event table
265 DECLARE_EVENT_TABLE()
266
267private:
269 TimerElapsedTime* pTimerElapsedTime;
271 // (only if a progress is available)
272 TimerRemainingTime* pTimerRemainingTime;
273
274 mutable Yuni::Thread::IThread::Ptr pThread;
275 wxAnimationCtrl* pAnim;
276 wxStaticText* pLblErrors;
277 wxString pLastNoticeMessage;
278 wxButton* pBtnCancel;
279
280 wxRegEx pLogRegex;
281 wxString pLogEntryLevelTmp;
282 wxString pLogEntryTmp;
283
284 bool pCatchLogEvents;
285
286 wxString pMessage;
287 wxString pSubMessage;
288
289 std::mutex pMutex;
290 std::mutex pErrorMutex;
291
292 PartList* pPartList;
293
294 wxColour pDefaultBGColor;
295 Component::Panel* pPanelButtons;
296 Component::Panel* pPanelHeader;
297
298 wxWindow* pWndCancelOperation;
299
301 wxTimer* pTimerMessageUpdater;
302 wxTimer* pTimerReadWriteStats;
303
304 // Our friends !
305 friend class JobThread;
306 friend class TimerElapsedTime;
307 friend class TimerRemainingTime;
308
309}; // class Job
310
311} // namespace Jobs
312} // namespace Toolbox
313} // namespace Antares
314
315#endif // __ANTARES_TOOLBOX_JOB_H__
A simple panel with a caption.
Definition progressbar.h:34
Definition job.cpp:240
Definition job.h:57
wxSizer * createMainPnl(wxWindow *parent)
Create the main panel, which contains all important controls.
Definition job.cpp:1094
void updateTheMessage(const wxString &msg, bool mustBeInterpreted=true)
Update the message displayed for the user.
Definition job.cpp:1393
wxSizer * createPnlButtons(wxWindow *parent)
Create the bottom panel, which contains buttons to cancel and to continue.
Definition job.cpp:1204
virtual void onBeforeRunning()
Event: Before the thread is launched.
Definition job.h:157
virtual bool executeTask()=0
Execute the real task.
void displayGauge(const bool visible=true)
Display (or not) the gauge.
Definition job.cpp:761
void stop()
Stop the job gracefully.
Definition job.cpp:1235
virtual bool onRunQuery()
Event: Ask if the job is allow to run.
Definition job.h:168
bool isRunning() const
Get if the job is running.
Definition job.h:113
void onUIUpdateMessage()
Definition job.cpp:1404
virtual void onCancel()
Event: The user ask to cancel the operation.
Definition job.h:176
void stopAllGuiComponents()
Gracefully Stop all Gui components.
Definition job.cpp:1258
virtual ~Job()
Destructor.
Definition job.cpp:682
Job(const wxString &title, const wxString &subTitle, const char *icon)
Constructor.
Definition job.cpp:590
void manageLogLevelMessage(enum LogLevel lvl, const wxString &msg)
Dispatch a log entry, grabbed from from the standard output.
Definition job.cpp:819
bool run()
Run the job.
Definition job.cpp:1282
void updateTheProgressValue(double progress)
Update the progress value.
Definition job.cpp:1361
Definition job.cpp:114