Antares Simulator
Power System Simulator
gridhelper.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_COMPONENTS_DATAGRID__GRID_HELPER_H__
22 #define __ANTARES_TOOLBOX_COMPONENTS_DATAGRID__GRID_HELPER_H__
23 
24 #include <wx/panel.h>
25 #include <wx/grid.h>
26 #include <vector>
27 #include <yuni/core/math.h>
28 #include "renderer.h"
29 
30 namespace Antares::Component::Datagrid
31 {
41 class VGridHelper final: public wxGridTableBase
42 {
43 public:
45  using Indices = std::vector<int>;
46 
47 public:
49 
50  VGridHelper(Renderer::IRenderer* renderer, bool markModified);
51 
53  virtual ~VGridHelper()
54  {
55  }
56 
58 
62  virtual int GetNumberRows() override;
63 
67  virtual int GetNumberCols() override;
68 
73  virtual wxString GetRowLabelValue(int row) override;
74 
79  virtual wxString GetColLabelValue(int col) override;
80 
88  virtual wxString GetValue(int row, int col) override;
89 
90  virtual double GetValueAsDouble(int row, int col) override;
91 
92  virtual bool GetValueAsBool(int row, int col) override;
93 
103  virtual double GetNumericValue(int row, int col) const; // override;
104 
112  virtual void SetValue(int row, int col, const wxString& v) override;
113  virtual void SetValue(int row, int col, const Yuni::String& v); // override
114 
118  bool IsEmptyCell(int, int) override;
119 
128  int realCol(uint col) const;
129 
138  int realRow(uint row) const;
139 
140  virtual bool CanValueAs(int, int, const wxString&); // override
141 
142  void resetIndicesToDefault();
143  void resetIndicesToDefaultWithoutInit();
144 
145  void precision(const Date::Precision p);
146 
147  void loadFromMatrix();
148 
152  Renderer::IRenderer* renderer() const;
153 
154  wxColour foregroundColorFromCellStyle(Renderer::IRenderer::CellStyle s) const;
155  wxColour backgroundColorFromCellStyle(Renderer::IRenderer::CellStyle s) const;
156 
157  void appendCSSForAllCellStyles(wxString& s);
158  void appendCSSForAllCellStyles2(Yuni::String& s);
159 
160  bool markTheStudyAsModified() const;
161 
162 public:
163  Indices indicesRows;
164  Indices indicesCols;
165  wxPoint virtualSize;
167  bool valid;
168 
169 private:
171  Renderer::IRenderer* pRenderer;
173  Date::Precision pDataGridPrecision;
174 
175  bool pMarkStudyModifiedWhenModifyingCell;
176 
177 }; // class VGridHelper
178 
179 } // namespace Antares::Component::Datagrid
180 
181 #include "gridhelper.hxx"
182 
183 #endif // __ANTARES_TOOLBOX_COMPONENTS_DATAGRID__GRID_HELPER_H__
Data provider for Datagrids.
Definition: renderer.h:50
Wrapper between a wxGridTableBase and a renderer
Definition: gridhelper.h:42
virtual wxString GetRowLabelValue(int row) override
Get the label for a given row.
Definition: gridhelper.cpp:532
std::vector< int > Indices
Indices.
Definition: gridhelper.h:45
virtual int GetNumberCols() override
Get the number of columns that the wxGrid should display.
Definition: gridhelper.hxx:31
int realRow(uint row) const
Get the real index used by the renderer of a given row index used by the wxGrid.
Definition: gridhelper.hxx:57
bool IsEmptyCell(int, int) override
Get if a cell is empty or not (unused)
Definition: gridhelper.hxx:46
Renderer::IRenderer * renderer() const
The renderer.
Definition: gridhelper.hxx:68
virtual ~VGridHelper()
Destructor.
Definition: gridhelper.h:53
virtual wxString GetColLabelValue(int col) override
Get the label for a given colum.
Definition: gridhelper.cpp:541
virtual void SetValue(int row, int col, const wxString &v) override
Try to set the value of a given cell.
Definition: gridhelper.cpp:560
int realCol(uint col) const
Get the real index used by the renderer of a given column index used by the wxGrid.
Definition: gridhelper.hxx:51
virtual double GetNumericValue(int row, int col) const
Get the float value of the cell at a given position.
Definition: gridhelper.cpp:555
virtual int GetNumberRows() override
Get the number of rows that the wxGrid should display.
Definition: gridhelper.hxx:26
bool valid
Get if the grid is valid.
Definition: gridhelper.h:167
virtual wxString GetValue(int row, int col) override
Get the string representation of the cell at a given position.
Definition: gridhelper.cpp:546