81 wxSizerFlags::DisableConsistencyChecks();
85 wxFileName fn(Paths::GetDocumentsPath() +
"/PSP-UFU/config.ini");
86 if (!fn.DirExists()) {
90 wxTextFile file(fn.GetFullPath());
91 auto data = propertiesData->GetGeneralPropertiesData();
94 if (!file.Open())
return false;
97 for (line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
99 wxString tagValue =
"";
100 bool parseValue =
false;
101 for (
unsigned int i = 0; i < line.Len(); ++i) {
102 if (line[i] ==
'=') {
114 if (tagValue ==
"pt-br" || tagValue ==
"pt") {
115 data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
117 else if (tagValue ==
"en" || tagValue ==
"en-us" || tagValue ==
"en-uk") {
118 data.language = wxLANGUAGE_ENGLISH;
121 if (tag ==
"theme") {
122 if (tagValue ==
"light") {
123 data.theme = THEME_LIGHT;
125 else if (tagValue ==
"dark") {
126 data.theme = THEME_DARK;
129 if (tag ==
"plotlib") {
130 if (tagValue ==
"chartdir") {
131 data.plotLib = PlotLib::wxCHART_DIR;
133 else if (tagValue ==
"mathplot") {
134 data.plotLib = PlotLib::wxMATH_PLOT;
145 if (tag ==
"labelfont") {
146 data.labelFont = tagValue;
148 if (tag ==
"labelfontsize") {
150 tagValue.ToLong(&size);
151 data.labelFontSize =
static_cast<int>(size);
153 if (tag ==
"atpfile") {
154 data.atpPath = wxFileName(tagValue);
156 if (tag ==
"elementstoolbar") {
157 if (tagValue ==
"none") {
158 data.elementsToolbar = NONE;
160 else if (tagValue ==
"vertical") {
161 data.elementsToolbar = VERTICAL;
163 else if (tagValue ==
"horizontal") {
164 data.elementsToolbar = HORIZONTAL;
168 data.elementsToolbar = VERTICAL;
171 if (tag ==
"usevoltagebuscolours") {
172 if (tagValue ==
"yes" || tagValue ==
"true" || tagValue ==
"1") {
173 data.useBusVoltageColours =
true;
175 else if (tagValue ==
"no" || tagValue ==
"false" || tagValue ==
"0") {
176 data.useBusVoltageColours =
false;
179 if (tag ==
"voltage_levels") {
180 data.voltageLevels.clear();
181 wxStringTokenizer tkz(tagValue,
";");
182 while (tkz.HasMoreTokens()) {
183 wxString token = tkz.GetNextToken().Trim().Trim(
false);
184 if (token.IsEmpty())
continue;
185 wxString vStr = token.BeforeFirst(
':');
186 wxString cStr = token.AfterFirst(
':');
188 if (vStr.ToCDouble(&v) || vStr.ToDouble(&v)) {
190 if (!col.IsOk()) col = *wxBLACK;
191 data.voltageLevels.push_back({ v, col });
199 if (!file.Open())
return false;
201 wxString plotLibProp =
"plotlib=chartdir";
203 plotLibProp =
"plotlib=mathplot";
207 file.AddLine(
"lang=en");
208 file.AddLine(plotLibProp);
209 file.AddLine(
"theme=light");
210 file.AddLine(
"labelfont=Arial");
211 file.AddLine(
"labelfontsize=10");
212 file.AddLine(
"atpfile=");
213 file.AddLine(
"elementstoolbar=no");
214 file.AddLine(
"usevoltagebuscolours=no");
217 wxString vlProp =
"voltage_levels=";
218 for (
size_t i = 0; i < data.voltageLevels.size(); ++i) {
219 if (i > 0) vlProp +=
";";
220 vlProp += wxString::Format(
"%s:%s", wxString::FromCDouble(data.voltageLevels[i].voltage), data.voltageLevels[i].colour.GetAsString(wxC2S_HTML_SYNTAX));
222 file.AddLine(vlProp);
227 data.language = wxLANGUAGE_ENGLISH;
228 data.theme = THEME_LIGHT;
229 data.plotLib = PlotLib::wxCHART_DIR;
231 data.plotLib = PlotLib::wxMATH_PLOT;
233 data.elementsToolbar = VERTICAL;
234 data.useBusVoltageColours =
true;
236 propertiesData->SetGeneralPropertiesData(data);
240 wxString atpFolder = Paths::GetDocumentsPath() +
"/PSP-UFU/atp";
241 if (!wxDir::Exists(atpFolder)) wxDir::Make(atpFolder);
242 data.atpWorkFolder = atpFolder;
244 propertiesData->SetGeneralPropertiesData(data);
248 void LoadCatalogs(wxLocale* locale,
PropertiesData* propertiesData)
251 if (!locale->Init(propertiesData->GetGeneralPropertiesData().language, wxLOCALE_DONT_LOAD_DEFAULT)) {
252 wxMessageDialog msgDialog(
nullptr, _(
"This language is not supported by the system."), _(
"Error"),
253 wxOK | wxCENTRE | wxICON_ERROR);
254 msgDialog.ShowModal();
258 wxString langPath = Paths::GetDataPath() +
"/lang";
259 locale->AddCatalogLookupPathPrefix(langPath);
261 if (propertiesData->GetGeneralPropertiesData().language == wxLANGUAGE_PORTUGUESE_BRAZILIAN) {
262 if (!locale->AddCatalog(wxT(
"pt_BR"))) {
263 wxMessageDialog msgDialog(
nullptr, _(
"Fail to load brazilian portuguese language catalog."), _(
"Error"),
264 wxOK | wxCENTRE | wxICON_ERROR);
265 msgDialog.ShowModal();
270 virtual bool OnInit()
273 wxImage::AddHandler(
new wxPNGHandler);
274 wxImage::AddHandler(
new wxJPEGHandler);
279 wxString fontsPath = Paths::GetDataPath() +
"/fonts";
280 bool loadFont = wxFont::AddPrivateFont(fontsPath +
"/cmunrm.ttf");
281 if (loadFont) loadFont = wxFont::AddPrivateFont(fontsPath +
"/cmunbx.ttf");
283 wxMessageDialog msgDialog(
nullptr, _(
"Failed to load local font."), _(
"Error"),
284 wxOK | wxCENTRE | wxICON_ERROR);
285 msgDialog.ShowModal();
291 LoadInitFile(propertiesData);
293 if (propertiesData->GetGeneralPropertiesData().theme == THEME_LIGHT)
294 SetAppearance(Appearance::Light);
295 else if (propertiesData->GetGeneralPropertiesData().theme == THEME_DARK)
296 SetAppearance(Appearance::Dark);
298 SetAppearance(Appearance::System);
300 wxLocale* locale =
new wxLocale();
301 LoadCatalogs(locale, propertiesData);
303 wxString openFilePath =
"";
306 wxCmdLineParser cmdLineParser(wxApp::argc, wxApp::argv);
308 cmdLineParser.AddParam(
"", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
309 cmdLineParser.AddSwitch(
"t",
"test",
"Run PSP-UFU tests");
312 if (cmdLineParser.Parse() == 0) {
313 wxCmdLineArgs args = cmdLineParser.GetArguments();
314 for (
auto it = args.begin(), itEnd = args.end(); it != itEnd; ++it) {
315 if (it->GetKind() == wxCMD_LINE_PARAM) { openFilePath = it->GetStrVal(); }
316 else if (it->GetShortName() ==
"t") {
324 mainFrame->SetIcon(wxICON(aaaaprogicon));
326 SetTopWindow(mainFrame);
328 GetTopWindow()->Show();
329 exit(mainFrame->RunPSPTest());
331 return GetTopWindow()->Show();
Main frame of the program. This class manage the ribbon menu and the notebook behavior.