Antares Simulator
Power System Simulator
dbgrid.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_DBGRID_H__
22 #define __ANTARES_TOOLBOX_COMPONENT_DATAGRID_DBGRID_H__
23 
24 #include <wx/grid.h>
25 #include <yuni/yuni.h>
26 
27 namespace Antares::Component::Datagrid
28 {
29 // Forward declaration
30 class Component;
31 
32 class DBGrid final: public wxGrid
33 {
34 public:
36 
37 
40  DBGrid(Component* parent);
42  virtual ~DBGrid();
43 
45 
46  const wxPoint& currentPosition() const
47  {
48  return pCurrentPosition;
49  }
50 
51  Component* component() const
52  {
53  return pParentComponent;
54  }
55 
56  void copyToClipboard();
57  void copyAllToClipboard();
58  void pasteFromClipboard();
59 
60  void ensureDataAreLoaded();
61 
62  void resizeAllHeaders(bool nodelay = false);
63 
67  void enableRefresh(bool enabled)
68  {
69  pAllowRefresh = enabled;
70  }
71 
72  bool canRefresh() const
73  {
74  return pAllowRefresh;
75  }
76 
77  void DrawColLabel(wxDC& dc, int col, uint& offset);
78  void DrawRowLabel(wxDC& dc, int row, uint& offset);
79  void DrawCellHighlight(wxDC& dc, const wxGridCellAttr* attr);
80 
81  void disableColorMappingForRowLabels()
82  {
83  pColorMappingRowLabels = false;
84  }
85 
86  // For synchronizing scroll with another grid purpose
87  void setOtherGrid(DBGrid* otherGrid);
88 
89 private:
91  bool dataAreReady() const;
92 
93  void ensureDataAreLoadedDelayed();
94 
98  void onGridSelectCell(wxGridEvent& evt);
99 
103  void onGridRangeSelect(wxGridRangeSelectEvent& evt);
104 
108  void onGridLeave(wxFocusEvent& evt);
109 
110  void onDraw(wxPaintEvent& evt);
111 
112  void onKeyUp(wxKeyEvent& evt);
113 
114  void evtOnResizeHeaders(wxCommandEvent& evt);
115 
116  void evtCornerPaint(wxPaintEvent& evt);
117 
118  void onEraseBackground(wxEraseEvent&)
119  {
120  }
121 
122  void onDrawColLabels(wxPaintEvent&);
123  void onDrawRowLabels(wxPaintEvent&);
124 
125  void onScroll(wxScrollWinEvent&);
126 
127 private:
129  Component* pParentComponent;
130  wxPoint pCurrentPosition;
131  bool pAllowRefresh;
132  bool pColorMappingRowLabels;
133  // The other grid we want scroll synchronously with
134  DBGrid* otherGrid_ = nullptr;
135 
136  DECLARE_EVENT_TABLE();
137 
138 }; // class DBGrid
139 
140 } // namespace Antares::Component::Datagrid
141 
142 #endif // __ANTARES_TOOLBOX_COMPONENT_DATAGRID_DBGRID_H__
A datagrid with virtual values.
Definition: component.h:84
void enableRefresh(bool enabled)
Allow refresh.
Definition: dbgrid.h:67
virtual ~DBGrid()
Destructor.
Definition: dbgrid.cpp:123
DBGrid(Component *parent)
Constructor.
Definition: dbgrid.cpp:74