Antares Simulator
Power System Simulator
renderer.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_TOOLBOX_COMPONENT_DATAGRID_RENDERER_H__
22 #define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_H__
23 
24 #include <yuni/core/event.h>
25 #include <antares/date/date.h>
26 #include <wx/colour.h>
27 #include "default.h"
28 #include <antares/study/study.h>
29 
30 #ifdef YUNI_OS_MSVC
31 // Disable warning C4250, inherits via dominance
32 #pragma warning(disable : 4250)
33 #endif
34 
35 namespace Antares::Component::Datagrid
36 {
37 class VGridHelper;
38 
39 namespace Renderer
40 {
49 class IRenderer: public Yuni::IEventObserver<IRenderer>
50 {
51 public:
52  enum CellStyle
53  {
54  cellStyleDefault = 0,
55  cellStyleCustom,
56  cellStyleDefaultAlternate,
57  cellStyleDefaultDisabled,
58  cellStyleDefaultAlternateDisabled,
59  cellStyleDefaultCenter,
60  cellStyleDefaultCenterAlternate,
61  cellStyleDefaultCenterDisabled,
62  cellStyleDefaultCenterAlternateDisabled,
63  cellStyleWarning,
64  cellStyleError,
65  cellStyleDisabled,
66  cellStyleAverage,
67  cellStyleSum,
68  cellStyleMinMax,
69  cellStyleConstraintEnabled,
70  cellStyleConstraintDisabled,
71  cellStyleConstraintNoWeight,
72  cellStyleConstraintWeight,
73  cellStyleConstraintWeightCount,
74  cellStyleConstraintOperator,
75  cellStyleConstraintType,
76  cellStyleLayerDisabled,
77  cellStyleFilterYearByYearOn,
78  cellStyleFilterYearByYearOff,
79  cellStyleFilterSynthesisOn,
80  cellStyleFilterSynthesisOff,
81  cellStyleFilterUndefined,
82  cellStyleAdqPatchVirtual,
83  cellStyleAdqPatchOutside,
84  cellStyleAdqPatchInside,
85 
86  cellStyleMax /* Max items in the list */
87  };
88 
89  static const wxChar* CellStyleToCSSClass(CellStyle s);
90  static void CellStyleToCSSClass(CellStyle s, Yuni::String& str);
91 
92 public:
94 
95 
98  IRenderer();
100  virtual ~IRenderer();
102 
104 
105  virtual bool valid() const = 0;
107 
109 
110 
113  virtual int width() const = 0;
114 
118  virtual int height() const = 0;
119 
125  virtual int internalWidth() const;
131  virtual int internalHeight() const;
133 
135 
136 
139  virtual wxString columnCaption(int colIndx) const = 0;
140 
144  virtual wxString rowCaption(int rowIndx) const = 0;
146 
148 
149 
152  virtual wxString asString(int x, int y) const;
156  virtual double asDouble(int x, int y) const;
157 
161  virtual wxString cellValue(int x, int y) const = 0;
162 
163  void appendCellValue(int x, int y, Yuni::String& s) const;
164 
168  virtual double cellNumericValue(int x, int y) const = 0;
169 
174  virtual bool cellValue(int x, int y, const Yuni::String& value) = 0;
176 
178 
179  virtual void resetColors(int x, int y, wxColour& background, wxColour& textForeground) const
180  = 0;
181 
183 
184  virtual IRenderer::CellStyle cellStyle(int, int y) const;
185  IRenderer::CellStyle cellStyleWithNumericCheck(int x, int y) const;
186 
187  virtual wxColour cellBackgroundColor(int, int) const;
188  virtual wxColour cellTextColor(int, int) const;
189 
191  virtual wxColour verticalBorderColor(int x, int y) const;
192 
194  virtual wxColour horizontalBorderColor(int x, int y) const;
195 
197  virtual int cellAlignment(int x, int y) const;
198 
200  virtual int columnWidthCustom(int x) const;
202  virtual void hintForColumnWidth(int x, wxString& out) const;
204 
208  virtual Date::Precision precision();
209 
213  virtual bool ensureDataAreLoaded();
215 
217 
218 
222  virtual uint maxWidthResize() const;
227  virtual uint maxHeightResize() const;
228 
232  virtual void resizeMatrixToXColumns(uint /*m*/)
233  {
234  }
235 
245  virtual bool onMatrixResize(uint oldX, uint oldY, uint& newX, uint& newY);
246 
250  virtual void onMatrixLoad()
251  {
252  }
253 
260  virtual bool circularShiftRowsUntilDate(MonthName month, uint daymonth);
261 
263 
265 
266  virtual void onSelectCell(uint, uint)
268  {
269  }
270 
272  virtual void onScroll()
273  {
274  }
275 
277 
278  virtual void applyLayerFiltering(size_t layerID, VGridHelper* gridHelper);
279 
280 public:
282  Yuni::Event<void()> onRefresh;
284  // This property is set by VGridHelper
285  Date::Precision dataGridPrecision;
287  Data::Study::Ptr study;
288 
291 
292 protected:
294  virtual void onStudyClosed();
296  virtual void onStudyLoaded();
297 
298 }; // class IRenderer
299 
300 } // namespace Renderer
301 } // namespace Antares::Component::Datagrid
302 
303 #include "renderer.hxx"
304 
305 #endif // __ANTARES_TOOLBOX_COMPONENT_DATAGRID_RENDERER_H__
Data provider for Datagrids.
Definition: renderer.h:50
virtual bool circularShiftRowsUntilDate(MonthName month, uint daymonth)
Rotate all rows until a given date.
Definition: renderer.hxx:119
virtual ~IRenderer()
Destructor.
Definition: renderer.cpp:169
virtual bool ensureDataAreLoaded()
Make sure all data are effectively loaded.
Definition: renderer.hxx:37
Data::Study::Ptr study
Attached study (if any)
Definition: renderer.h:287
virtual double asDouble(int x, int y) const
Read a cell as a double.
Definition: renderer.hxx:109
virtual int internalHeight() const
The real height of the matrix in memory.
Definition: renderer.hxx:32
virtual double cellNumericValue(int x, int y) const =0
Get the floating value of a Cell.
virtual wxColour verticalBorderColor(int x, int y) const
Get the color of the vertical right border.
Definition: renderer.hxx:69
virtual bool cellValue(int x, int y, const Yuni::String &value)=0
Try to modify a cell value.
virtual void onMatrixLoad()
Event triggered right after a matrix was loaded by the renderer.
Definition: renderer.h:250
virtual wxString cellValue(int x, int y) const =0
Get the string representation of a Cell.
virtual uint maxWidthResize() const
The most suitable column count.
Definition: renderer.hxx:79
virtual void resizeMatrixToXColumns(uint)
Resize the internal matrix with a given col count.
Definition: renderer.h:232
virtual wxString asString(int x, int y) const
Read a cell as a string.
Definition: renderer.hxx:104
virtual void hintForColumnWidth(int x, wxString &out) const
String to use.
Definition: renderer.hxx:99
virtual wxString rowCaption(int rowIndx) const =0
Get the caption of a row.
virtual int internalWidth() const
The real width of the matrix in memory.
Definition: renderer.hxx:27
Yuni::Event< void()> onRefresh
Event on refresh.
Definition: renderer.h:282
virtual bool onMatrixResize(uint oldX, uint oldY, uint &newX, uint &newY)
Event trigerred before resizing a matrix.
Definition: renderer.hxx:64
virtual int width() const =0
The effective width of the grid.
virtual void onStudyClosed()
Event: the study has been closed.
Definition: renderer.cpp:180
virtual int cellAlignment(int x, int y) const
Get the alignment of a cell (-1: left, 0: center, +1: right)
Definition: renderer.hxx:89
virtual void onScroll()
A scroll event has been triggered.
Definition: renderer.h:272
virtual Date::Precision precision()
Time Precision.
Definition: renderer.hxx:114
virtual int height() const =0
The effective height of the grid.
virtual wxString columnCaption(int colIndx) const =0
Get the caption of a column.
virtual wxColour horizontalBorderColor(int x, int y) const
Get the color of the horizontal bottom border.
Definition: renderer.hxx:74
virtual void onStudyLoaded()
Event: the study has been loaded.
Definition: renderer.cpp:175
virtual void onSelectCell(uint, uint)
A cell has been selected.
Definition: renderer.h:267
bool invalidate
True to invalidate the current data and force a refresh for the next call to DBGrid:onDraw.
Definition: renderer.h:290
IRenderer()
Default constructor.
Definition: renderer.cpp:160
Date::Precision dataGridPrecision
The real precision asked by the datagrid.
Definition: renderer.h:285
virtual uint maxHeightResize() const
The most suitable column count.
Definition: renderer.hxx:84
virtual int columnWidthCustom(int x) const
Get how the a column must resize (0: auto, >0: specific width, <0: use custom string)
Definition: renderer.hxx:94
Wrapper between a wxGridTableBase and a renderer
Definition: gridhelper.h:42