Antares Simulator
Power System Simulator
studylogs.h
1 /*
2  * Copyright 2007-2025, 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_APPLICATION_WINDOWS_STUDY_LOGS_H__
22 #define __ANTARES_APPLICATION_WINDOWS_STUDY_LOGS_H__
23 
24 #include <mutex>
25 #include <antares/study/study.h>
26 #include <yuni/core/event.h>
27 
28 #include <wx/htmllbox.h>
29 #include <wx/html/htmlwin.h>
30 #include <wx/stattext.h>
31 #include <wx/timer.h>
32 #include <wx/treectrl.h>
33 
34 #include "../application/study.h"
35 #include "../toolbox/components/datagrid/renderer/logfile.h"
36 #include <ui/common/component/frame/local-frame.h>
37 #include <ui/common/component/spotlight.h>
38 
39 namespace Antares::Window
40 {
41 class CompareDesc final
42 {
43 public:
44  bool operator()(const wxString& s1, const wxString& s2) const;
45 };
46 
47 using MapFileList = std::map<wxString, YString, CompareDesc>;
48 
49 class StudyLogs;
50 
51 class FileListProvider final: public Component::Spotlight::IProvider
52 {
53 public:
55  using Ptr = std::shared_ptr<FileListProvider>;
56 
57  explicit FileListProvider(StudyLogs& frame);
58  ~FileListProvider() override;
59 
60  FileListProvider(const FileListProvider&) = delete;
61  FileListProvider& operator=(const FileListProvider&) = delete;
62 
63  void search(Spotlight::IItem::Vector& out,
64  const Spotlight::SearchToken::Vector& tokens,
65  const Yuni::String& text = "") override;
66  bool onSelect(Spotlight::IItem::Ptr& item) override;
67  bool onSelect(const Spotlight::IItem::Vector&) override;
68  void refreshFileList(bool showAll);
69 
70 private:
71  StudyLogs& pFrame;
73  bool pAutoTriggerSelection;
74  bool pShowAll;
75  MapFileList pAllSimuLogs;
76  MapFileList pAllUILogs;
77  std::shared_ptr<wxBitmap> pBmpFile;
78 }; // class FileListProvider
79 
81 {
82 public:
85 
86  class LogFilenameInfo final
87  {
88  public:
90  struct ltstr final
91  {
92  bool operator()(const Yuni::String& s1, const Yuni::String& s2) const
93  {
94  return s2 < s1;
95  }
96  };
97 
99  using Map = std::map<Yuni::String, LogFilenameInfo, ltstr>;
100 
101  public:
103  wxString html;
104  wxClientData* clientData;
105  };
106 
107 public:
108  // \name Constructors & Destructor
110 
113  StudyLogs(wxFrame* parent);
115  virtual ~StudyLogs();
117 
118  void refreshListOfAllAvailableLogs();
119 
120  void loadFromFile(const Yuni::String& filename);
121 
122  const Yuni::String& lastLogFile() const
123  {
124  return pLastLogFile;
125  }
126 
127  void reloadFromData(LogEntryContainer::Ptr entries, LogEntryContainer::Ptr errors);
128 
129 private:
133  void onButtonRefreshFileList(void*);
137  void onReloadLogFile(void*);
138 
142  void onClose(wxCloseEvent& evt);
143 
147  void enterLoadingMode(const Yuni::String& filename);
148 
149  void onChangeShowAllAdvanced(wxCommandEvent&);
150 
151 private:
153  Yuni::String pLastLogFile;
155  Component::Button* pBtnLogFilenameRefresh;
157  wxStaticText* pTxtFromFolder;
159  Component::Datagrid::Component* pLogDisplay;
161  Component::Datagrid::Component* pLogDisplayErrors;
163  Component::Notebook* pNotebook;
164 
166  Component::Datagrid::Renderer::LogFile* pRendererEntries;
168  Component::Datagrid::Renderer::LogFile* pRendererEntriesErrors;
175  wxSplitterWindow* pSplitter;
176 
178  bool pCanCloseTheWindow;
179 
181  LogFilenameInfo::Map pLogFilenameInfo;
182 
183  std::mutex pLoadingMutex;
184 
186  bool pShowAllLogsFiles;
187 
188  FileListProvider::Ptr mProvider;
189 
191  Yuni::Event<void(bool)> onRefreshListOfFiles;
192 
193  // Event Table
194  DECLARE_EVENT_TABLE()
195 
196 }; // class StudyLogs
197 
198 } // namespace Antares::Window
199 
200 #endif // __ANTARES_APPLICATION_WINDOWS_STUDY_LOGS_H__
Definition: button.h:32
A datagrid with virtual values.
Definition: component.h:84
std::shared_ptr< LogEntryContainer > Ptr
The most suitable smart pointer for the class.
Definition: logfile.h:81
Definition: local-frame.h:32
Notebook.
Definition: notebook.h:36
Definition: spotlight.h:38
Definition: studylogs.h:42
Definition: studylogs.h:52
std::map< Yuni::String, LogFilenameInfo, ltstr > Map
Map.
Definition: studylogs.h:99
wxString html
The html display code.
Definition: studylogs.h:103
Definition: studylogs.h:81
StudyLogs(wxFrame *parent)
Constructor with a parent window and a study.
Definition: studylogs.cpp:705
virtual ~StudyLogs()
Destructor.
Definition: studylogs.cpp:874
Comparison.
Definition: studylogs.h:91