Antares Simulator
Power System Simulator
xcast-conversion.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_CONVERTION_HXX__
22 #define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_AREA_XCAST_CONVERTION_HXX__
23 
24 #include <antares/study/xcast/xcast.h>
25 
26 namespace Antares::Component::Datagrid::Renderer
27 {
28 template<enum Data::TimeSeriesType T>
30  MatrixAncestorType(control),
31  Renderer::ARendererArea(control, notifier)
32 {
33 }
34 
35 template<enum Data::TimeSeriesType T>
37 {
38  destroyBoundEvents();
39 }
40 
41 template<enum Data::TimeSeriesType T>
42 inline wxString XCastConversion<T>::columnCaption(int colIndx) const
43 {
44  return wxString() << wxT(" point ") << (colIndx + 1) << wxT(' ');
45 }
46 
47 template<enum Data::TimeSeriesType T>
48 inline wxString XCastConversion<T>::cellValue(int x, int y) const
49 {
50  return MatrixAncestorType::cellValue(x + 1, y);
51 }
52 
53 template<enum Data::TimeSeriesType T>
54 double XCastConversion<T>::cellNumericValue(int x, int y) const
55 {
56  return MatrixAncestorType::cellNumericValue(x + 1, y);
57 }
58 
59 template<enum Data::TimeSeriesType T>
60 inline bool XCastConversion<T>::cellValue(int x, int y, const Yuni::String& value)
61 {
62  return MatrixAncestorType::cellValue(x + 1, y, value);
63 }
64 
65 template<enum Data::TimeSeriesType T>
67 {
68  if (area)
69  {
70  auto* xcastData = area->xcastData<T>();
71  this->matrix(&(xcastData->conversion));
72  }
73  else
74  {
75  this->matrix(NULL);
76  }
77  Renderer::ARendererArea::internalAreaChanged(area);
78 }
79 
80 template<enum Data::TimeSeriesType T>
81 IRenderer::CellStyle XCastConversion<T>::cellStyle(int col, int row) const
82 {
83  double b = MatrixAncestorType::cellNumericValue(col + 1, 0);
84  return (Yuni::Math::Abs(b) >= 1.0e+19)
85  || (col > 0 && b <= MatrixAncestorType::cellNumericValue(col, 0))
86  ? cellStyleError
87  : MatrixAncestorType::cellStyle(col, row);
88 }
89 
90 template<enum Data::TimeSeriesType T>
91 wxString XCastConversion<T>::rowCaption(int rowIndx) const
92 {
93  return (rowIndx == 0) ? wxT("IN") : wxT("OUT");
94 }
95 
96 template<enum Data::TimeSeriesType T>
97 bool XCastConversion<T>::onMatrixResize(uint, uint, uint& newX, uint&)
98 {
100  {
101  return false;
102  }
103  auto& matrix = (*pMatrix);
104  matrix[matrix.width - 1][0] = 0;
105  matrix[matrix.width - 1][1] = 0;
106  matrix.resizeWithoutDataLost(newX + 2, 2);
107  matrix[matrix.width - 1][0] = +std::numeric_limits<float>::max();
108  matrix.markAsModified();
109  MarkTheStudyAsModified();
110  return false;
111 }
112 
113 template<enum Data::TimeSeriesType T>
115 {
116  auto& matrix = *pMatrix;
117  if (matrix.height != 2)
118  {
119  // It may happen when the file is not loaded
120  matrix.reset(3, 2);
121  matrix.markAsModified();
122  MarkTheStudyAsModified();
123  }
124  if (matrix.width >= 3 && matrix.width <= Data::XCast::conversionMaxPoints)
125  {
126  matrix[0][0] = -std::numeric_limits<float>::max();
127  matrix[0][1] = matrix[1][1];
128  matrix[matrix.width - 1][0] = +std::numeric_limits<float>::max();
129  matrix[matrix.width - 1][1] = matrix[matrix.width - 2][1];
130  }
131  else
132  {
133  matrix.reset(3, 2);
134  matrix[0][0] = -std::numeric_limits<float>::max();
135  matrix[0][1] = 0.f;
136  matrix[1][0] = 0.f;
137  matrix[1][1] = 0.f;
138  matrix[2][0] = +std::numeric_limits<float>::max();
139  matrix[2][1] = 0.f;
140  }
141 }
142 
143 template<enum Data::TimeSeriesType T>
145 {
148 }
149 
150 template<enum Data::TimeSeriesType T>
152 {
155 }
156 
157 } // namespace Antares::Component::Datagrid::Renderer
158 
159 #endif // __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_AREA_XCAST_CONVERTION_HXX__
virtual void onStudyClosed() override
The study has been closed.
Definition: area.cpp:86
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition: area.cpp:92
virtual ~XCastConversion()
Destructor.
Definition: xcast-conversion.hxx:36
virtual wxString rowCaption(int rowIndx) const
Get the row caption.
Definition: xcast-conversion.hxx:91
virtual void onMatrixLoad()
Event triggered right after a matrix was loaded by the renderer.
Definition: xcast-conversion.hxx:114
virtual void onStudyClosed() override
Event: the study has been closed.
Definition: xcast-conversion.hxx:144
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition: xcast-conversion.hxx:151
virtual double cellNumericValue(int x, int y) const
Get the value of a cell.
Definition: xcast-conversion.hxx:54
virtual wxString columnCaption(int colIndx) const
Get the column caption.
Definition: xcast-conversion.hxx:42
virtual wxString cellValue(int x, int y) const
Get the string representation of a cell.
Definition: xcast-conversion.hxx:48
XCastConversion(wxWindow *control, Toolbox::InputSelector::Area *notifier)
Constructor.
Definition: xcast-conversion.hxx:29
virtual bool onMatrixResize(uint oldX, uint oldY, uint &newX, uint &newY)
Event trigerred before resizing a matrix.
Definition: xcast-conversion.hxx:97
Definition for a single area.
Definition: area.h:51
@ conversionMaxPoints
Hard limit for the number of points of the transfer function.
Definition: xcast.h:81
A n-by-n matrix.
Definition: matrix.h:44
Visual Component for displaying all available areas (and groups)
Definition: area.h:37