Antares Simulator
Power System Simulator
xcast-allareas.hxx
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_TOOLBOX_COMPONENT_DATAGRID_RENDERER_AREA_XCAST_ALL_AREAS_HXX__
22 #define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_AREA_XCAST_ALL_AREAS_HXX__
23 
24 #include "../../../../../application/study.h"
25 #include "../../component.h"
26 #include <antares/study/xcast/xcast.h>
27 
28 namespace Antares::Component::Datagrid::Renderer
29 {
30 template<enum Data::TimeSeriesType T>
32  pControl(parent),
33  pNotifier(notifier)
34 {
35  OnStudyAreaRename.connect(this, &XCastAllAreas<T>::onAreaRenamed);
36 }
37 
38 template<enum Data::TimeSeriesType T>
40 {
41  destroyBoundEvents();
42 }
43 
44 template<enum Data::TimeSeriesType T>
45 inline int XCastAllAreas<T>::width() const
46 {
47  return 4;
48 }
49 
50 template<enum Data::TimeSeriesType T>
51 inline int XCastAllAreas<T>::height() const
52 {
53  auto study = GetCurrentStudy();
54  return !study ? 0 : study->areas.size();
55 }
56 
57 template<enum Data::TimeSeriesType T>
58 inline bool XCastAllAreas<T>::valid() const
59 {
60  auto study = GetCurrentStudy();
61  return !(!study) and study->areas.size() != 0;
62 }
63 
64 template<enum Data::TimeSeriesType T>
65 wxString XCastAllAreas<T>::columnCaption(int colIndx) const
66 {
67  switch (colIndx)
68  {
69  case 0:
70  return wxT(" Capacity ");
71  case 1:
72  return wxT("Distribution");
73  case 2:
74  return wxT("Conversion");
75  case 3:
76  return wxT(" Translation");
77  }
78  return wxEmptyString;
79 }
80 
81 template<enum Data::TimeSeriesType T>
82 wxString XCastAllAreas<T>::rowCaption(int rowIndx) const
83 {
84  auto study = GetCurrentStudy();
85  if (!study || (uint)rowIndx >= study->areas.size())
86  {
87  return wxEmptyString;
88  }
89  return wxStringFromUTF8(study->areas.byIndex[rowIndx]->name);
90 }
91 
92 template<enum Data::TimeSeriesType T>
93 IRenderer::CellStyle XCastAllAreas<T>::cellStyle(int x, int y) const
94 {
95  auto study = GetCurrentStudy();
96  if (!study)
97  {
98  return IRenderer::cellStyleDefaultCenterDisabled;
99  }
100 
101  auto& area = *(study->areas.byIndex[y]);
102  auto& xcastData = *area.xcastData<T>();
103  if (Yuni::Math::Zero(xcastData.capacity))
104  {
105  return IRenderer::cellStyleDefaultCenterDisabled;
106  }
107  switch (x)
108  {
109  case 0:
110  return Yuni::Math::Zero(xcastData.capacity) ? IRenderer::cellStyleDefaultCenterDisabled
111  : IRenderer::cellStyleConstraintWeight;
112  case 2:
113  return xcastData.useConversion ? IRenderer::cellStyleDefaultCenter
114  : IRenderer::cellStyleDefaultCenterDisabled;
115  case 3:
116  {
117  switch (xcastData.useTranslation)
118  {
120  return IRenderer::cellStyleDefaultCenterDisabled;
121  default:
122  return IRenderer::cellStyleDefaultCenter;
123  }
124  return IRenderer::cellStyleDefaultCenter;
125  }
126  }
127  return IRenderer::cellStyleDefaultCenter;
128 }
129 
130 template<enum Data::TimeSeriesType T>
131 wxColour XCastAllAreas<T>::cellBackgroundColor(int, int y) const
132 {
133  auto study = GetCurrentStudy();
134  if (!study)
135  {
136  return wxColour(0, 0, 0);
137  }
138  auto& area = *(study->areas.byIndex[y]);
139  return wxColor(area.ui->color[0], area.ui->color[1], area.ui->color[2]);
140 }
141 
142 template<enum Data::TimeSeriesType T>
143 wxString XCastAllAreas<T>::cellValue(int x, int y) const
144 {
145  auto study = GetCurrentStudy();
146  if (!study)
147  {
148  return wxEmptyString;
149  }
150 
151  auto& area = *(study->areas.byIndex[y]);
152  auto& xcastData = *area.xcastData<T>();
153  switch (x)
154  {
155  case 0:
156  return DoubleToWxString(xcastData.capacity);
157  case 1:
158  return wxStringFromUTF8(Data::XCast::DistributionToCString(xcastData.distribution));
159  case 2:
160  return xcastData.useConversion ? wxT("Yes") : wxT("No");
161  case 3:
162  {
163  switch (xcastData.useTranslation)
164  {
166  return wxT("BEFORE scaling");
168  return wxT("AFTER scaling");
169  default:
170  return wxT("No");
171  }
172  return wxT("No");
173  }
174  }
175  return wxEmptyString;
176 }
177 
178 template<enum Data::TimeSeriesType T>
179 double XCastAllAreas<T>::cellNumericValue(int x, int y) const
180 {
181  auto study = GetCurrentStudy();
182  if (!study)
183  {
184  return 0.;
185  }
186  auto& area = *(study->areas.byIndex[y]);
187  auto& xcastData = *area.xcastData<T>();
188  switch (x)
189  {
190  case 0:
191  return xcastData.capacity;
192  case 1:
193  return double(xcastData.distribution);
194  case 2:
195  return xcastData.useConversion ? 1. : 0.;
196  case 3:
197  {
198  switch (xcastData.useTranslation)
199  {
201  return -1.;
203  return +1.;
204  default:
205  return 0.;
206  }
207  return 0.;
208  }
209  }
210  return 0.;
211 }
212 
213 template<enum Data::TimeSeriesType T>
214 bool XCastAllAreas<T>::cellValue(int x, int y, const Yuni::String& value)
215 {
216  auto study = GetCurrentStudy();
217  if (!study)
218  {
219  return false;
220  }
221 
222  YString v = value;
223  v.toLower();
224  auto& area = *(study->areas.byIndex[y]);
225  auto& xcastData = *area.xcastData<T>();
226  switch (x)
227  {
228  case 0:
229  {
230  double d;
231  if (v.to<double>(d) and not Yuni::Math::Equals(d, xcastData.capacity))
232  {
233  xcastData.capacity = d;
234  if (&area == pNotifier->lastArea())
235  {
236  pNotifier->reloadLastArea();
237  }
238  return true;
239  }
240  break;
241  }
242  case 1:
243  {
245  if (d != Data::XCast::dtNone and d != xcastData.distribution)
246  {
247  xcastData.distribution = d;
248  if (&area == pNotifier->lastArea())
249  {
250  pNotifier->reloadLastArea();
251  }
252  return true;
253  }
254  break;
255  }
256  case 2:
257  {
258  bool b = v.to<bool>();
259  if (b != xcastData.useConversion)
260  {
261  xcastData.useConversion = b;
262  if (&area == pNotifier->lastArea())
263  {
264  pNotifier->reloadLastArea();
265  }
266  return true;
267  }
268  break;
269  }
270  case 3:
271  {
272  auto t = Data::XCast::CStringToTSTranslationUse(v);
273  if (t != xcastData.useTranslation)
274  {
275  xcastData.useTranslation = t;
276  if (&area == pNotifier->lastArea())
277  {
278  pNotifier->reloadLastArea();
279  }
280  return true;
281  }
282  break;
283  }
284  }
285  return false;
286 }
287 
288 template<enum Data::TimeSeriesType T>
290 {
291  if (pControl)
292  {
293  pControl->Refresh();
294  }
295 }
296 
297 } // namespace Antares::Component::Datagrid::Renderer
298 
299 #endif // __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_AREA_XCAST_ALL_AREAS_HXX__
virtual ~XCastAllAreas()
Destructor.
Definition: xcast-allareas.hxx:39
virtual wxString columnCaption(int colIndx) const
Get the caption of a column.
Definition: xcast-allareas.hxx:65
virtual double cellNumericValue(int, int) const
Get the floating value of a Cell.
Definition: xcast-allareas.hxx:179
virtual int width() const
The effective width of the grid.
Definition: xcast-allareas.hxx:45
virtual int height() const
The effective height of the grid.
Definition: xcast-allareas.hxx:51
virtual wxString cellValue(int, int) const
Get the string representation of a Cell.
Definition: xcast-allareas.hxx:143
virtual wxString rowCaption(int rowIndx) const
Get the caption of a row.
Definition: xcast-allareas.hxx:82
XCastAllAreas(wxWindow *parent, Toolbox::InputSelector::Area *notifier)
Constructor.
Definition: xcast-allareas.hxx:31
Definition for a single area.
Definition: area.h:51
@ dtNone
None.
Definition: xcast.h:63
static const char * DistributionToCString(Distribution d)
Convert a distribution into its human readable representation.
Definition: xcast.cpp:71
@ tsTranslationNone
Do not use the time-series average.
Definition: xcast.h:87
@ tsTranslationBeforeConversion
Add the time-series average before computing the transfer function.
Definition: xcast.h:89
@ tsTranslationAfterConversion
Add the time-series average after computing the transfer function.
Definition: xcast.h:91
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:37