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