Power System Platform  2026w10a-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 69 of file main.cpp.

Constructor & Destructor Documentation

◆ MainApp()

MainApp::MainApp ( )
inline

Definition at line 73 of file main.cpp.

73{}

◆ ~MainApp()

virtual MainApp::~MainApp ( )
inlinevirtual

Definition at line 74 of file main.cpp.

74{}

Member Function Documentation

◆ LoadCatalogs()

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

Definition at line 187 of file main.cpp.

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

◆ LoadInitFile()

bool MainApp::LoadInitFile ( PropertiesData propertiesData)
inline

Definition at line 75 of file main.cpp.

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

◆ OnExit()

virtual int MainApp::OnExit ( )
inlinevirtual

Definition at line 265 of file main.cpp.

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

◆ OnInit()

virtual bool MainApp::OnInit ( )
inlinevirtual

Definition at line 209 of file main.cpp.

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