Power System Platform  2026w11a-beta
Loading...
Searching...
No Matches
MainApp Class Reference
Inheritance diagram for MainApp:
Collaboration diagram for MainApp:

Public Member Functions

bool LoadInitFile (PropertiesData *propertiesData)
 
void LoadCatalogs (wxLocale *locale, PropertiesData *propertiesData)
 
virtual bool OnInit ()
 
virtual int OnExit ()
 

Detailed Description

Definition at line 70 of file main.cpp.

Constructor & Destructor Documentation

◆ MainApp()

MainApp::MainApp ( )
inline

Definition at line 74 of file main.cpp.

74{}

◆ ~MainApp()

virtual MainApp::~MainApp ( )
inlinevirtual

Definition at line 75 of file main.cpp.

75{}

Member Function Documentation

◆ LoadCatalogs()

void MainApp::LoadCatalogs ( wxLocale *  locale,
PropertiesData propertiesData 
)
inline

Definition at line 188 of file main.cpp.

189 {
190 // Load language catalogs according the propertiesData attribute.
191 if (!locale->Init(propertiesData->GetGeneralPropertiesData().language, wxLOCALE_DONT_LOAD_DEFAULT)) {
192 wxMessageDialog msgDialog(nullptr, _("This language is not supported by the system."), _("Error"),
193 wxOK | wxCENTRE | wxICON_ERROR);
194 msgDialog.ShowModal();
195 }
196
197 //wxFileName fn(wxStandardPaths::Get().GetExecutablePath());
198 wxString langPath = Paths::GetDataPath() + "/lang";
199 locale->AddCatalogLookupPathPrefix(langPath);
200 // pt_BR
201 if (propertiesData->GetGeneralPropertiesData().language == wxLANGUAGE_PORTUGUESE_BRAZILIAN) {
202 if (!locale->AddCatalog(wxT("pt_BR"))) {
203 wxMessageDialog msgDialog(nullptr, _("Fail to load brazilian portuguese language catalog."), _("Error"),
204 wxOK | wxCENTRE | wxICON_ERROR);
205 msgDialog.ShowModal();
206 }
207 }
208 }

◆ LoadInitFile()

bool MainApp::LoadInitFile ( PropertiesData propertiesData)
inline

Definition at line 76 of file main.cpp.

77 {
78#ifdef _DEBUG
79 wxSizerFlags::DisableConsistencyChecks();
80#endif
81
82 // Load configuration file, if don't exists create it.
83 wxFileName fn(Paths::GetDocumentsPath() + "/PSP-UFU/config.ini");
84 if (!fn.DirExists()) {
85 fn.Mkdir();
86 }
87
88 wxTextFile file(fn.GetFullPath());
89 auto data = propertiesData->GetGeneralPropertiesData();
90
91 if (!file.Create()) {
92 if (!file.Open()) return false;
93
94 wxString line;
95 for (line = file.GetFirstLine(); !file.Eof(); line = file.GetNextLine()) {
96 wxString tag = "";
97 wxString tagValue = "";
98 bool parseValue = false;
99 for (unsigned int i = 0; i < line.Len(); ++i) {
100 if (line[i] == '=') {
101 parseValue = true;
102 }
103 else {
104 if (parseValue)
105 tagValue += line[i];
106 else
107 tag += line[i];
108 }
109 }
110 // Language
111 if (tag == "lang") {
112 if (tagValue == "pt-br" || tagValue == "pt") {
113 data.language = wxLANGUAGE_PORTUGUESE_BRAZILIAN;
114 }
115 else if (tagValue == "en" || tagValue == "en-us" || tagValue == "en-uk") {
116 data.language = wxLANGUAGE_ENGLISH;
117 }
118 }
119 if (tag == "theme") {
120 if (tagValue == "light") {
121 data.theme = THEME_LIGHT;
122 }
123 else if (tagValue == "dark") {
124 data.theme = THEME_DARK;
125 }
126 }
127 if (tag == "plotlib") {
128 if (tagValue == "chartdir") {
129 data.plotLib = PlotLib::wxCHART_DIR;
130 }
131 else if (tagValue == "mathplot") {
132 data.plotLib = PlotLib::wxMATH_PLOT;
133 }
134 }
135 //if (tag == "useOpenGL") {
136 // if (tagValue == "yes") {
137 // data.useOpenGL = true;
138 // }
139 // else if (tagValue == "no") {
140 // data.useOpenGL = false;
141 // }
142 //}
143 if (tag == "labelfont") {
144 data.labelFont = tagValue;
145 }
146 if (tag == "labelfontsize") {
147 long size = 10;
148 tagValue.ToLong(&size);
149 data.labelFontSize = static_cast<int>(size);
150 }
151 if (tag == "atpfile") {
152 data.atpPath = wxFileName(tagValue);
153 }
154 }
155 file.Close();
156 }
157 else { // Create default init file.
158 if (!file.Open()) return false;
159
160 // Default parameters.
161 file.AddLine("lang=en");
162 file.AddLine("plotlib=chartdir");
163 file.AddLine("theme=light");
164 file.AddLine("labelfont=Arial");
165 file.AddLine("labelfontsize=10");
166 file.AddLine("atpfile=");
167 //file.AddLine("useOpenGL=yes");
168
169 file.Write();
170 file.Close();
171
172 data.language = wxLANGUAGE_ENGLISH;
173 data.theme = THEME_LIGHT;
174 data.plotLib = PlotLib::wxCHART_DIR;
175 //data.useOpenGL = true;
176 propertiesData->SetGeneralPropertiesData(data);
177 }
178
179 // Check if the atp folder exists, if not create it.
180 wxString atpFolder = Paths::GetDocumentsPath() + "/PSP-UFU/atp";
181 if (!wxDir::Exists(atpFolder)) wxDir::Make(atpFolder);
182 data.atpWorkFolder = atpFolder;
183
184 propertiesData->SetGeneralPropertiesData(data);
185 return true;
186 }

◆ OnExit()

virtual int MainApp::OnExit ( )
inlinevirtual

Definition at line 266 of file main.cpp.

267 {
268 // clean up
269 return 0;
270 }

◆ OnInit()

virtual bool MainApp::OnInit ( )
inlinevirtual

Definition at line 210 of file main.cpp.

211 {
212 // Add image handlers
213 wxImage::AddHandler(new wxPNGHandler);
214 wxImage::AddHandler(new wxJPEGHandler);
215
216 // Load fonts
217#ifdef __WXMSW__
218 //wxFileName fn(wxStandardPaths::Get().GetExecutablePath());
219 wxString fontsPath = Paths::GetDataPath() + "/fonts";
220 bool loadFont = wxFont::AddPrivateFont(fontsPath + "/cmunrm.ttf"); // regular
221 if (loadFont) loadFont = wxFont::AddPrivateFont(fontsPath + "/cmunbx.ttf"); // bold
222 if (!loadFont) {
223 wxMessageDialog msgDialog(nullptr, _("Failed to load local font."), _("Error"),
224 wxOK | wxCENTRE | wxICON_ERROR);
225 msgDialog.ShowModal();
226 }
227#endif // __WXMSW__
228
229 PropertiesData* propertiesData = new PropertiesData();
230 LoadInitFile(propertiesData);
231
232 wxLocale* locale = new wxLocale();
233 LoadCatalogs(locale, propertiesData);
234
235 wxString openFilePath = "";
236
237 // Load command line attributes. This is used to directly open saved files (.psp).
238 wxCmdLineParser cmdLineParser(wxApp::argc, wxApp::argv);
239 //cmdLineParser.SetDesc(cmdLineDesc);
240 cmdLineParser.AddParam("", wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);
241 cmdLineParser.AddSwitch("t", "test", "Run PSP-UFU tests");
242
243 bool test = false;
244 if (cmdLineParser.Parse() == 0) {
245 wxCmdLineArgs args = cmdLineParser.GetArguments();
246 for (auto it = args.begin(), itEnd = args.end(); it != itEnd; ++it) {
247 if (it->GetKind() == wxCMD_LINE_PARAM) { openFilePath = it->GetStrVal(); }
248 else if (it->GetShortName() == "t") {
249 test = true;
250 }
251 }
252 }
253 MainFrame* mainFrame = new MainFrame(nullptr, locale, propertiesData, openFilePath);
254#ifdef __WXMSW__
255 // Set application icon for windows
256 mainFrame->SetIcon(wxICON(aaaaprogicon));
257#endif
258 SetTopWindow(mainFrame);
259 if (test) {
260 GetTopWindow()->Show();
261 exit(mainFrame->RunPSPTest());
262 }
263 return GetTopWindow()->Show();
264 }
Main frame of the program. This class manage the ribbon menu and the notebook behavior.
Definition MainFrame.h:69
General and simulation data manager.

The documentation for this class was generated from the following file: