Antares Simulator
Power System Simulator
datasources.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 
22 #include "../../toolbox/components/datagrid/component.h"
23 #include "../../toolbox/components/datagrid/renderer/correlation.h"
24 
25 namespace Antares::Window
26 {
29 {
30 public:
32  {
33  }
34 
35  virtual wxString name() const
36  {
37  return wxT("Areas in alphabetical order");
38  }
39 
40  virtual const char* icon() const
41  {
42  return "images/16x16/sort_alphabet.png";
43  }
44 
45  virtual void reload()
46  {
47  pArray.clear();
48  auto study = GetCurrentStudy();
49  if (!(!study))
50  {
51  pArray.reserve(study->areas.size());
52  const Data::Area::Map::iterator end = study->areas.end();
53  for (Data::Area::Map::iterator i = study->areas.begin(); i != end; ++i)
54  {
55  pArray.push_back(i->second);
56  }
57  }
58  }
59 
60  virtual uint size() const
61  {
62  return (uint)pArray.size();
63  }
64 
65  virtual const Data::Area* at(uint i) const
66  {
67  return (i < pArray.size()) ? pArray[i] : NULL;
68  }
69 
70  virtual uint areaIndex(uint i) const
71  {
72  return pArray[i]->index;
73  }
74 
75 public:
76  Data::Area::Vector pArray;
77 };
78 
81 {
82 public:
84  {
85  }
86 
87  virtual wxString name() const
88  {
89  return wxT("Areas in reverse alphabetical order");
90  }
91 
92  virtual const char* icon() const
93  {
94  return "images/16x16/sort_alphabet_descending.png";
95  }
96 
97  virtual void reload()
98  {
99  pArray.clear();
100 
101  auto study = GetCurrentStudy();
102  if (!(!study))
103  {
104  pArray.reserve(study->areas.size());
105  const Data::Area::Map::reverse_iterator end = study->areas.rend();
106  for (Data::Area::Map::reverse_iterator i = study->areas.rbegin(); i != end; ++i)
107  {
108  pArray.push_back(i->second);
109  }
110  }
111  }
112 
113  virtual uint size() const
114  {
115  return (uint)pArray.size();
116  }
117 
118  virtual const Data::Area* at(uint i) const
119  {
120  return (i < pArray.size()) ? pArray[i] : NULL;
121  }
122 
123  virtual uint areaIndex(uint i) const
124  {
125  return pArray[i]->index;
126  }
127 
128 public:
129  Data::Area::Vector pArray;
130 };
131 
132 struct SortColor
133 {
134  inline bool operator()(const Data::Area* a, const Data::Area* b) const
135  {
136  // We must have strict weak ordering
137  return (a->ui->cacheColorHSV == b->ui->cacheColorHSV)
138  ? (a->name < b->name)
139  : (a->ui->cacheColorHSV) > (b->ui->cacheColorHSV);
140  }
141 };
142 
144 {
145 public:
147  {
148  }
149 
150  virtual wxString name() const
151  {
152  return wxT("Areas ordered by theur color");
153  }
154 
155  virtual const char* icon() const
156  {
157  return "images/16x16/color.png";
158  }
159 
160  virtual void reload()
161  {
162  pArray.clear();
163 
164  auto study = GetCurrentStudy();
165  if (!(!study))
166  {
167  {
168  const Data::Area::Map::iterator end = study->areas.end();
169  for (Data::Area::Map::iterator i = study->areas.begin(); i != end; ++i)
170  {
171  pArray.push_back(i->second);
172  }
173  }
174  std::sort(pArray.begin(), pArray.end(), SortColor());
175  pRegionStart.resize(pArray.size(), 0);
176  pRegionEnd.resize(pArray.size(), 0);
177  pRegionColor.resize(pArray.size());
178  pRegionColorIdentity.resize(pArray.size());
179 
180  {
181  int lastLevel = 0;
182  int j = 0;
183  Yuni::CString<12, false> old;
184  wxColour color;
185  wxColour colorIdentity;
186  const Data::Area::Vector::const_iterator end = pArray.end();
187  for (Data::Area::Vector::const_iterator i = pArray.begin(); i != end; ++i, ++j)
188  {
189  if (old != (*i)->ui->cacheColorHSV)
190  {
191  for (int z = lastLevel; z < j; ++z)
192  {
193  pRegionEnd[z] = j - 1;
194  }
195  old = (*i)->ui->cacheColorHSV;
196  color.Set(
197  (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[0] + 35, 0, 255),
198  (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[1] + 35, 0, 255),
199  (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[2] + 35, 0, 255));
200  colorIdentity.Set(
201  (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[0] - 35, 0, 255),
202  (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[1] - 35, 0, 255),
203  (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[2] - 35, 0, 255));
204  lastLevel = j;
205  }
206  pRegionStart[j] = lastLevel;
207  pRegionColor[j] = color;
208  pRegionColorIdentity[j] = colorIdentity;
209  }
210  for (int z = lastLevel; z < (int)pArray.size(); ++z)
211  {
212  pRegionEnd[z] = (int)pArray.size() - 1;
213  }
214  }
215  }
216  }
217 
218  virtual uint size() const
219  {
220  return (uint)pArray.size();
221  }
222 
223  virtual const Data::Area* at(uint i) const
224  {
225  return (i < pArray.size()) ? pArray[i] : NULL;
226  }
227 
228  virtual Component::Datagrid::Renderer::IRenderer::CellStyle cellStyle(int col, int row) const
229  {
230  return (col == row || (row >= pRegionStart[col] && row <= pRegionEnd[col]))
231  ? Component::Datagrid::Renderer::IRenderer::cellStyleCustom
232  : Component::Datagrid::Renderer::IRenderer::cellStyleDefault;
233  }
234 
235  virtual wxColour cellBackgroundColor(int col, int row) const
236  {
237  return (col == row) ? pRegionColorIdentity[col] : pRegionColor[col];
238  }
239 
240  virtual wxColour cellTextColor(int, int) const
241  {
242  return wxColour(0, 0, 0);
243  }
244 
245  virtual uint areaIndex(uint i) const
246  {
247  return pArray[i]->index;
248  }
249 
250 public:
251  Data::Area::Vector pArray;
252  std::vector<int> pRegionStart;
253  std::vector<int> pRegionEnd;
254  std::vector<wxColour> pRegionColor;
255  std::vector<wxColour> pRegionColorIdentity;
256 
257 }; // class DatasourceAlphaOrder
258 
259 } // namespace Antares::Window
Definition for a single area.
Definition: area.h:51
AreaName name
Name of the area.
Definition: area.h:212
std::unique_ptr< AreaUI > ui
Information for the UI.
Definition: area.h:303
Definition: datasources.hxx:29
Definition: datasources.hxx:144
Definition: datasources.hxx:81
Definition: datasources.hxx:133