Power System Platform  2026w34a-beta
Loading...
Searching...
No Matches
PropertiesData.cpp
1/*
2 * Copyright (C) 2017 Thales Lima Oliveira <thales@ufu.br>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#include "PropertiesData.h"
19
20#include <wx/msgdlg.h>
21#include <wx/textfile.h>
22#include <wx/stdpaths.h>
23
24PropertiesData::PropertiesData() { SetGUIColourTheme(); }
25PropertiesData::~PropertiesData() {}
26
27void PropertiesData::SetGUIColourTheme()
28{
29 if (m_genData.theme == THEME_LIGHT)
30 {
31 m_guiColour.background = wxColour(250, 249, 246);
32
33 m_guiColour.text = wxColour(35, 35, 35);
34 m_guiColour.enabled = wxColour(20, 20, 20);
35 m_guiColour.disable = wxColour(145, 145, 145);
36
37 m_guiColour.selection = wxColour(40, 120, 255, 90);
38 m_guiColour.altSelection = wxColour(40, 200, 70, 90);
39
40 m_guiColour.bus = wxColour(40, 105, 235);
41 m_guiColour.slackBus = wxColour(40, 105, 235);
42
43 m_guiColour.eventElement = wxColour(255, 120, 0);
44 m_guiColour.pfArrow = wxColour(255, 120, 0);
45
46 m_guiColour.swClose = wxColour(35, 150, 45);
47 m_guiColour.swOpen = wxColour(225, 55, 55);
48 m_guiColour.grid = wxColour(220, 222, 225);
49 }
50 else if (m_genData.theme == THEME_DARK)
51 {
52 m_guiColour.background = wxColour(43, 46, 52);
53
54 m_guiColour.text = wxColour(205, 210, 215);
55 m_guiColour.enabled = wxColour(220, 224, 228);
56 m_guiColour.disable = wxColour(125, 130, 136);
57
58 m_guiColour.selection = wxColour(70, 140, 255, 90);
59 m_guiColour.altSelection = wxColour(70, 200, 90, 90);
60
61 m_guiColour.bus = wxColour(70, 135, 255);
62 m_guiColour.slackBus = wxColour(95, 155, 255);
63
64 m_guiColour.eventElement = wxColour(240, 165, 60);
65 m_guiColour.pfArrow = wxColour(240, 165, 60);
66
67 m_guiColour.swClose = wxColour(60, 180, 70);
68 m_guiColour.swOpen = wxColour(235, 85, 85);
69 m_guiColour.grid = wxColour(60, 64, 72);
70 }
71
72 if (m_genData.voltageLevels.empty()) {
73 m_genData.voltageLevels = GetDefaultVoltageLevels();
74 }
75 m_guiColour.voltageLevels = m_genData.voltageLevels;
76 m_guiColour.useVoltageLevels = m_genData.useBusVoltageColours;
77}
78
79std::vector<VoltageLevelColour> PropertiesData::GetDefaultVoltageLevels()
80{
81 return {
82 { 500.0, wxColour(198, 40, 40) }, // 500 kV - Dark red
83 { 440.0, wxColour(224, 90, 42) }, // 440 kV - Orange-red
84 { 345.0, wxColour(242, 177, 52) }, // 345 kV - Amber
85 { 230.0, wxColour(67, 176, 92) }, // 230 kV - Green
86 { 138.0, wxColour(40, 105, 235) }, // 138 kV - Blue
87 { 69.0, wxColour(0, 180, 220) }, // 69 kV - Cyan
88 { 34.5, wxColour(0, 106, 106) }, // 34.5 kV - Teal
89 { 13.8, wxColour(94, 53, 177) }, // 13.8 kV - Violet
90 { 4.16, wxColour(158, 62, 172) }, // 4.16 kV - Purple
91 { 0.38, wxColour(151, 132, 208) } // 0.38 kV (380 V) - Light purple
92 };
93}
94
95void PropertiesData::SetGeneralPropertiesData(GeneralData generalData)
96{
97 m_genData = generalData;
98 if (m_genData.voltageLevels.empty()) {
99 m_genData.voltageLevels = GetDefaultVoltageLevels();
100 }
101 m_guiColour.voltageLevels = m_genData.voltageLevels;
102}
103
104bool PropertiesData::SaveConfigFile(const GeneralData& data)
105{
106 wxFileName fn(wxStandardPaths::Get().GetDocumentsDir() + wxFileName::GetPathSeparator() + "PSP-UFU" + wxFileName::GetPathSeparator() + "config.ini");
107 if (!fn.DirExists()) {
108 fn.Mkdir();
109 }
110 wxTextFile file(fn.GetFullPath());
111 if (!file.Create()) {
112 if (!file.Open()) {
113 return false;
114 }
115 file.Clear();
116 }
117
118 wxString line = "lang=";
119 switch (data.language) {
120 case wxLANGUAGE_PORTUGUESE_BRAZILIAN:
121 line += "pt-br";
122 break;
123 case wxLANGUAGE_ENGLISH:
124 default:
125 line += "en";
126 break;
127 }
128 file.AddLine(line);
129
130 line = "plotlib=";
131 switch (data.plotLib) {
132 case PlotLib::wxMATH_PLOT:
133 line += "mathplot";
134 break;
135 case PlotLib::wxCHART_DIR:
136 default:
137 line += "chartdir";
138 break;
139 }
140 file.AddLine(line);
141
142 line = "theme=";
143 switch (data.theme) {
144 case THEME_DARK:
145 line += "dark";
146 break;
147 case THEME_LIGHT:
148 default:
149 line += "light";
150 break;
151 }
152 file.AddLine(line);
153
154 line = "labelfont=" + data.labelFont;
155 file.AddLine(line);
156
157 line = wxString::Format("labelfontsize=%d", data.labelFontSize);
158 file.AddLine(line);
159
160 line = "atpfile=" + data.atpPath.GetFullPath();
161 file.AddLine(line);
162
163 line = wxString("elementstoolbar=");
164 switch (data.elementsToolbar) {
165 case NONE:
166 line += "none";
167 break;
168 case VERTICAL:
169 line += "vertical";
170 break;
171 case HORIZONTAL:
172 line += "horizontal";
173 break;
174 default:
175 line += "vertical";
176 break;
177 }
178 file.AddLine(line);
179
180 line = wxString("usevoltagebuscolours=") + (data.useBusVoltageColours ? "yes" : "no");
181 file.AddLine(line);
182
183 if (!data.voltageLevels.empty()) {
184 line = "voltage_levels=";
185 for (size_t i = 0; i < data.voltageLevels.size(); ++i) {
186 if (i > 0) line += ";";
187 line += wxString::Format("%s:%s", wxString::FromCDouble(data.voltageLevels[i].voltage), data.voltageLevels[i].colour.GetAsString(wxC2S_HTML_SYNTAX));
188 }
189 file.AddLine(line);
190 }
191
192 file.Write();
193 file.Close();
194 return true;
195}