Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
xcast.hxx
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_WINDOWS_XCAST_XCAST_HXX__
22#define __ANTARES_WINDOWS_XCAST_XCAST_HXX__
23
24#include <assert.h>
25#include <wx/statline.h>
26#include "../../toolbox/components/datagrid/renderer/area/xcast-k.h"
27#include "../../toolbox/components/datagrid/renderer/area/xcast-coefficients.h"
28#include "../../toolbox/components/datagrid/renderer/area/xcast-translation.h"
29#include "../../toolbox/components/datagrid/renderer/area/xcast-conversion.h"
30#include "../../toolbox/validator.h"
31#include "../../application/study.h"
32#include "../../windows/inspector.h"
33#include <ui/common/component/panel.h>
34
35namespace Antares
36{
37namespace Window
38{
39template<enum Data::TimeSeriesType T>
40XCast<T>::XCast(wxWindow* parent, Toolbox::InputSelector::Area* notifier) :
41 wxPanel(parent, wxID_ANY), pNotifier(notifier), pArea(nullptr)
42{
43 assert(pNotifier != NULL);
44
45 // Grids
47
48 auto* hsizer = new wxBoxSizer(wxVERTICAL);
49 this->SetSizer(hsizer);
50
51 auto* notebook = new Component::Notebook(this, Component::Notebook::orTop);
52 pNotebook = notebook;
53 notebook->theme(Component::Notebook::themeLight);
54
56 notebook, new Component::Datagrid::Renderer::XCastCoefficients<T>(this, notifier));
57 pGridCoeffs = grid;
58 pPageGeneral = notebook->add(grid, wxT("coeffs"), wxT("Coefficients"));
59
61 notebook, new Component::Datagrid::Renderer::XCastK<T>(this, notifier));
62 pPageDailyProfile = notebook->add(grid, wxT("Daily profile"));
63
65 notebook, new Component::Datagrid::Renderer::XCastTranslation<T>(this, notifier));
66 pPageDailyProfile = notebook->add(grid, wxT("Translation"));
67
68 wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
69 hsizer->Add(sizer, 0, wxALL | wxEXPAND);
70 hsizer->Add(notebook, 1, wxALL | wxEXPAND);
71
72 {
73 auto* pGridSizer = new wxFlexGridSizer(2, 0, 0);
74 wxStaticText* t;
75 wxTextCtrl* edit;
76
77 // Capacity
78 {
79 t = new wxStaticText(
80 this, wxID_ANY, wxT("Capacity : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
81 wxFont f = t->GetFont();
82 f.SetWeight(wxFONTWEIGHT_BOLD);
83 t->SetFont(f);
84 pGridSizer->Add(t, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
85
86 edit = new wxTextCtrl(this,
87 wxID_ANY,
88 wxEmptyString,
89 wxDefaultPosition,
90 wxSize(-1, 22),
91 0,
92 Toolbox::Validator::Numeric());
93 pInstalledCapacity = edit;
94 pGridSizer->Add(edit, 1, wxALL | wxEXPAND, 1);
95 }
96
97 // Probability distribution
98 t = new wxStaticText(
99 this, wxID_ANY, wxT("Distribution : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
100 pGridSizer->Add(t, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
101
102 wxArrayString list;
103 for (uint i = 1; i < Data::XCast::dtMax; ++i)
104 list.Add(
106 wxChoice* ch = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 22), list);
107 pDistribution = ch;
108 pGridSizer->Add(ch, 1, wxALL | wxEXPAND, 1);
109
110 // TS Translation
111 t = new wxStaticText(
112 this, wxID_ANY, wxT("Translation : "), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
113 pGridSizer->Add(t, 0, wxRIGHT | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
114
115 // see XCast::CStringToTSTranslationUse if you modifiy this list
116 list.Clear();
117 list.Add(wxT("Do not use"));
118 list.Add(wxT("Add BEFORE scaling"));
119 list.Add(wxT("Add AFTER scaling"));
120 useTranslation = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 22), list);
121 pGridSizer->Add(useTranslation, 1, wxALL | wxEXPAND, 1);
122
123 wxBoxSizer* divider = new wxBoxSizer(wxHORIZONTAL);
124 divider->Add(20, 5);
125 divider->Add(pGridSizer, 0, wxALL | wxEXPAND, 7);
126 divider->Add(
127 new wxStaticLine(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL),
128 0,
129 wxALL | wxEXPAND,
130 5);
131 divider->AddSpacer(15);
132 wxBoxSizer* transferSizer = new wxBoxSizer(wxVERTICAL);
133
134 useConversion = new wxCheckBox(this, wxID_ANY, wxT(" Use Conversion"));
135 transferSizer->AddSpacer(15);
136 transferSizer->Add(useConversion, 0, wxALL | wxEXPAND);
137
138 divider->Add(transferSizer, 1, wxALL | wxEXPAND);
139
140 sizer->Add(divider, 1, wxALL | wxEXPAND);
141
142 pDistribution->Connect(pDistribution->GetId(),
143 wxEVT_COMMAND_CHOICE_SELECTED,
144 wxCommandEventHandler(XCast<T>::onUpdateDistribution),
145 NULL,
146 this);
147 useTranslation->Connect(useTranslation->GetId(),
148 wxEVT_COMMAND_CHOICE_SELECTED,
149 wxCommandEventHandler(XCast<T>::onUpdateTSTranslationUse),
150 NULL,
151 this);
152 useConversion->Connect(useConversion->GetId(),
153 wxEVT_COMMAND_CHECKBOX_CLICKED,
154 wxCommandEventHandler(XCast<T>::onUpdateConversion),
155 NULL,
156 this);
157 }
158
159 {
161 wxSizer* ss = new wxBoxSizer(wxVERTICAL);
162
164 panel, new Component::Datagrid::Renderer::XCastConversion<T>(this, notifier));
165 ss->Add(grid, 0, wxALL | wxEXPAND);
166 ss->SetItemMinSize(grid, 100, 150);
167
168 panel->SetSizer(ss);
169 pPageTranslation = notebook->add(panel, wxT("Conversion"));
170 }
171
172 // Events
173 OnStudyClosed.connect(this, &XCast<T>::onStudyClosed);
174 if (notifier)
175 notifier->onAreaChanged.connect(this, &XCast<T>::onAreaChanged);
176 pInstalledCapacity->Connect(pInstalledCapacity->GetId(),
177 wxEVT_COMMAND_TEXT_UPDATED,
178 wxCommandEventHandler(XCast<T>::onInstalledCapacityChanged),
179 NULL,
180 this);
181
182 // Select the page by default
183 pPageGeneral->select();
184}
185
186template<enum Data::TimeSeriesType T>
188{
189 ObserverAncestorType::destroyBoundEvents();
190}
191
192template<enum Data::TimeSeriesType T>
193void XCast<T>::onUpdateDistribution(wxCommandEvent& evt)
194{
195 wxChoice* obj = (wxChoice*)evt.GetEventObject();
196 if (obj and pArea)
197 {
198 Data::XCast* xcast = pArea->xcastData<T>();
199 if (!xcast)
200 return;
201
202 YString s;
203 wxStringToString(obj->GetStringSelection(), s);
205 if (d != Data::XCast::dtNone and d != xcast->distribution)
206 {
207 xcast->distribution = d;
208 MarkTheStudyAsModified();
209 Window::Inspector::Refresh();
210 if (pGridCoeffs and pNotebook->selected()
211 and pNotebook->selected()->name() == wxT("coeffs"))
212 pGridCoeffs->Refresh();
213 }
214 }
215}
216
217template<enum Data::TimeSeriesType T>
218void XCast<T>::onUpdateConversion(wxCommandEvent& evt)
219{
220 if (!pArea)
221 return;
222
223 Data::XCast* xcast = pArea->xcastData<T>();
224 if (!xcast)
225 return;
226
227 if (xcast->useConversion != evt.IsChecked())
228 {
229 xcast->useConversion = evt.IsChecked();
230 MarkTheStudyAsModified();
231 Window::Inspector::Refresh();
232 }
233}
234
235template<enum Data::TimeSeriesType T>
236void XCast<T>::onUpdateTSTranslationUse(wxCommandEvent& evt)
237{
238 wxChoice* obj = (wxChoice*)evt.GetEventObject();
239 if (obj and pArea)
240 {
241 Data::XCast* xcast = pArea->xcastData<T>();
242 if (!xcast)
243 return;
244
245 YString s;
246 wxStringToString(obj->GetStringSelection(), s);
247 Data::XCast::TSTranslationUse d = Data::XCast::CStringToTSTranslationUse(s);
248 if (d != xcast->useTranslation)
249 {
250 xcast->useTranslation = d;
251 MarkTheStudyAsModified();
252 Window::Inspector::Refresh();
253 }
254 }
255}
256
257template<enum Data::TimeSeriesType T>
258inline void XCast<T>::selectDefaultPage()
259{
260 if (pPageGeneral)
261 pPageGeneral->select();
262}
263
264template<enum Data::TimeSeriesType T>
265void XCast<T>::onStudyClosed()
266{
267 pArea = nullptr;
268 selectDefaultPage();
269}
270
271template<enum Data::TimeSeriesType T>
272void XCast<T>::onAreaChanged(Data::Area* area)
273{
274 using namespace Yuni;
275 // Keeping a pointer to the current area
276 pArea = area;
277
278 // Updating the installed capacity of the current area
279 if (pArea)
280 {
281 Data::XCast* xcast = pArea->xcastData<T>();
282 if (xcast)
283 {
284 // Capacity
285 pInstalledCapacity->ChangeValue(DoubleToWxString(xcast->capacity));
286
287 // Distribution
288 int indx = (int)xcast->distribution - 1;
289 if (indx < 0 or indx > 5)
290 indx = 1;
291 pDistribution->SetSelection(indx);
292
293 // Transfert
294 useConversion->SetValue(xcast->useConversion);
295 useTranslation->SetSelection((int)xcast->useTranslation);
296 return;
297 }
298 }
299 pInstalledCapacity->ChangeValue(wxT("0"));
300 pDistribution->SetSelection(1);
301 useConversion->SetValue(false);
302 useTranslation->SetSelection(0);
303}
304
305template<enum Data::TimeSeriesType T>
306void XCast<T>::onInstalledCapacityChanged(wxCommandEvent& evt)
307{
308 if (!pArea)
309 return;
310 double d;
311 evt.GetString().ToDouble(&d);
312 if (d < 0.)
313 d = 0.;
314
315 Data::XCast* xcastData = pArea->xcastData<T>();
316 if (xcastData and not Yuni::Math::Equals(d, xcastData->capacity))
317 {
318 xcastData->capacity = d;
319 MarkTheStudyAsModified();
320 }
321}
322
323} // namespace Window
324} // namespace Antares
325
326#endif // __ANTARES_WINDOWS_XCAST_XCAST_HXX__
A datagrid with virtual values.
Definition component.h:84
Page * select(bool force=false)
Select the page.
Definition notebook.cpp:816
Notebook.
Definition notebook.h:38
void theme(Theme t)
Set the current theme.
Definition notebook.h:281
Panel implementation.
Definition panel.h:36
Definition for a single area.
Definition area.h:52
Definition xcast.h:35
Distribution distribution
The probability distribution to use.
Definition xcast.h:182
double capacity
The installed capacity.
Definition xcast.h:185
TSTranslationUse useTranslation
How to use the timeseries average.
Definition xcast.h:179
bool useConversion
True to use the transfer function after the generation of the time-series.
Definition xcast.h:188
Distribution
All available probability distribution.
Definition xcast.h:61
@ dtMax
The maximum number of distributions.
Definition xcast.h:75
@ dtNone
None.
Definition xcast.h:63
static const char * DistributionToCString(Distribution d)
Convert a distribution into its human readable representation.
Definition xcast.cpp:71
TSTranslationUse
Definition xcast.h:85
static Distribution StringToDistribution(AnyString str)
Convert a CString into a probability distribution.
Definition xcast.cpp:92
Visual Component for displaying all available areas (and groups)
Definition area.h:41
static Yuni::Event< void(Data::Area *)> onAreaChanged
Public event, triggered when the selected area has changed.
Definition area.h:72
Definition xcast.h:40
XCast(wxWindow *parent, Toolbox::InputSelector::Area *notifier)
Default constructor.
Definition xcast.hxx:40
virtual ~XCast()
Destructor.
Definition xcast.hxx:187