Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
datasources.hxx
1/*
2** Copyright 2007-2024, 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
25namespace Antares
26{
27namespace Window
28{
31{
32public:
34 {
35 }
36
37 virtual wxString name() const
38 {
39 return wxT("Areas in alphabetical order");
40 }
41
42 virtual const char* icon() const
43 {
44 return "images/16x16/sort_alphabet.png";
45 }
46
47 virtual void reload()
48 {
49 pArray.clear();
50 auto study = GetCurrentStudy();
51 if (!(!study))
52 {
53 pArray.reserve(study->areas.size());
54 const Data::Area::Map::iterator end = study->areas.end();
55 for (Data::Area::Map::iterator i = study->areas.begin(); i != end; ++i)
56 pArray.push_back(i->second);
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
75public:
76 Data::Area::Vector pArray;
77};
78
81{
82public:
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 pArray.push_back(i->second);
108 }
109 }
110
111 virtual uint size() const
112 {
113 return (uint)pArray.size();
114 }
115
116 virtual const Data::Area* at(uint i) const
117 {
118 return (i < pArray.size()) ? pArray[i] : NULL;
119 }
120
121 virtual uint areaIndex(uint i) const
122 {
123 return pArray[i]->index;
124 }
125
126public:
127 Data::Area::Vector pArray;
128};
129
131{
132 inline bool operator()(const Data::Area* a, const Data::Area* b) const
133 {
134 // We must have strict weak ordering
135 return (a->ui->cacheColorHSV == b->ui->cacheColorHSV)
136 ? (a->name < b->name)
137 : (a->ui->cacheColorHSV) > (b->ui->cacheColorHSV);
138 }
139};
140
142{
143public:
145 {
146 }
147
148 virtual wxString name() const
149 {
150 return wxT("Areas ordered by theur color");
151 }
152
153 virtual const char* icon() const
154 {
155 return "images/16x16/color.png";
156 }
157
158 virtual void reload()
159 {
160 pArray.clear();
161
162 auto study = GetCurrentStudy();
163 if (!(!study))
164 {
165 {
166 const Data::Area::Map::iterator end = study->areas.end();
167 for (Data::Area::Map::iterator i = study->areas.begin(); i != end; ++i)
168 pArray.push_back(i->second);
169 }
170 std::sort(pArray.begin(), pArray.end(), SortColor());
171 pRegionStart.resize(pArray.size(), 0);
172 pRegionEnd.resize(pArray.size(), 0);
173 pRegionColor.resize(pArray.size());
174 pRegionColorIdentity.resize(pArray.size());
175
176 {
177 int lastLevel = 0;
178 int j = 0;
179 Yuni::CString<12, false> old;
180 wxColour color;
181 wxColour colorIdentity;
182 const Data::Area::Vector::const_iterator end = pArray.end();
183 for (Data::Area::Vector::const_iterator i = pArray.begin(); i != end; ++i, ++j)
184 {
185 if (old != (*i)->ui->cacheColorHSV)
186 {
187 for (int z = lastLevel; z < j; ++z)
188 pRegionEnd[z] = j - 1;
189 old = (*i)->ui->cacheColorHSV;
190 color.Set(
191 (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[0] + 35, 0, 255),
192 (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[1] + 35, 0, 255),
193 (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[2] + 35, 0, 255));
194 colorIdentity.Set(
195 (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[0] - 35, 0, 255),
196 (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[1] - 35, 0, 255),
197 (unsigned char)Yuni::Math::MinMax<int>((*i)->ui->color[2] - 35, 0, 255));
198 lastLevel = j;
199 }
200 pRegionStart[j] = lastLevel;
201 pRegionColor[j] = color;
202 pRegionColorIdentity[j] = colorIdentity;
203 }
204 for (int z = lastLevel; z < (int)pArray.size(); ++z)
205 pRegionEnd[z] = (int)pArray.size() - 1;
206 }
207 }
208 }
209
210 virtual uint size() const
211 {
212 return (uint)pArray.size();
213 }
214
215 virtual const Data::Area* at(uint i) const
216 {
217 return (i < pArray.size()) ? pArray[i] : NULL;
218 }
219
220 virtual Component::Datagrid::Renderer::IRenderer::CellStyle cellStyle(int col, int row) const
221 {
222 return (col == row || (row >= pRegionStart[col] && row <= pRegionEnd[col]))
223 ? Component::Datagrid::Renderer::IRenderer::cellStyleCustom
224 : Component::Datagrid::Renderer::IRenderer::cellStyleDefault;
225 }
226
227 virtual wxColour cellBackgroundColor(int col, int row) const
228 {
229 return (col == row) ? pRegionColorIdentity[col] : pRegionColor[col];
230 }
231
232 virtual wxColour cellTextColor(int, int) const
233 {
234 return wxColour(0, 0, 0);
235 }
236
237 virtual uint areaIndex(uint i) const
238 {
239 return pArray[i]->index;
240 }
241
242public:
243 Data::Area::Vector pArray;
244 std::vector<int> pRegionStart;
245 std::vector<int> pRegionEnd;
246 std::vector<wxColour> pRegionColor;
247 std::vector<wxColour> pRegionColorIdentity;
248
249}; // class DatasourceAlphaOrder
250
251} // namespace Window
252} // namespace Antares
Definition for a single area.
Definition area.h:52
AreaName name
Name of the area.
Definition area.h:213
std::unique_ptr< AreaUI > ui
Information for the UI.
Definition area.h:304
Definition datasources.hxx:31
Definition datasources.hxx:142
Definition datasources.hxx:131