Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ImportForm.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 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#ifndef IMPORTFORM_H
19#define IMPORTFORM_H
20
21#include "PropertiesFormBase.h"
22
23#include <wx/geometry.h>
24#include <wx/msgdlg.h>
25#include <wx/textfile.h>
26#include <wx/tokenzr.h>
27#include <bitset>
28#include <complex>
29
30class Workspace;
31class Bus;
32class SyncGenerator;
33class SyncMotor;
34class Load;
35class Capacitor;
36class Inductor;
37class Capacitor;
38class IndMotor;
39class Transformer;
40class Line;
41class PropertiesData;
42
43class GraphAutoLayout;
44
52class ImportForm : public ImportFormBase
53{
54 public:
55 ImportForm(wxWindow* parent, Workspace* workspace);
56 virtual ~ImportForm();
57
58 Workspace* GetWorkspace() { return m_workspace; }
59
60 protected:
61 virtual void OnButtonCancelClick(wxCommandEvent& event);
62 virtual void OnButtonOKClick(wxCommandEvent& event);
63 bool ImportSelectedFiles();
64 bool ImportCEPELFiles();
65 bool ImportMatpowerFiles();
66 Bus* GetBusFromID(std::vector<Bus*> busList, int id);
67
68 Workspace* m_workspace = nullptr;
69 wxWindow* m_parent;
70};
71
88
97{
98 public:
99 // Graphic files data structs
100 struct Component {
101 int id = 0;
103 double length = 0.0;
104 int rotationID = 0;
105 wxPoint2DDouble position;
106 int electricalID = 0;
107 std::pair<int, int> busConnectionID[2] = {
108 std::make_pair(0, 0), std::make_pair(0, 0)};
109 std::pair<int, int> busConnectionNode[2] = {std::make_pair(0, 0),
110 std::make_pair(0, 0)};
111 };
112 struct PowerLine {
113 int id = 0;
115 int electricalID = 0;
116 std::pair<int, int> busConnectionID[2] = {
117 std::make_pair(0, 0), std::make_pair(0, 0)};
118 std::pair<int, int> busConnectionNode[2] = {std::make_pair(0, 0),
119 std::make_pair(0, 0)};
120 std::vector<wxPoint2DDouble> nodesPosition;
121 };
122 struct BusData {
123 int id = 0;
124 bool isOnline = true;
125 int type = 0;
126 wxString voltageBase = "0";
127 wxString busName = "Bus";
128 double voltage = 1.0;
129 double angle = 0.0;
130 std::complex<double> genPower = std::complex<double>(0, 0);
131 double minReactivePower = -9999.0;
132 double maxReactivePower = 99999.0;
133 int ctrlBusID = 0;
134 std::complex<double> loadPower = std::complex<double>(0, 0);
136 0.0;
137 };
138 struct BranchData {
139 int id = 0;
141 std::pair<int, int> busConnections = std::make_pair(0, 0);
142 bool isOnline = true;
143 double resistance = 0.0;
144 double indReactance = 0.0;
145 double capSusceptance = 0.0;
146 double tap = 0.0;
147 double phaseShift = 0.0;
148 };
150 int id = 0;
153 bool isOnline = true;
154 std::complex<double> power = std::complex<double>(0, 0);
155 int numUnits = 0;
156 };
158 double minReactivePower = -9999.0;
159 double maxReactivePower = 99999.0;
160 double xt = 1.0;
161 double xd = 1.0;
162 double xq = 1.0;
163 double xl = 1.0;
164 double ratedPower = 100.0;
165 };
166
167 ParseAnarede(wxFileName lstFile, wxFileName pwfFile);
168 ~ParseAnarede() { ClearData(); }
169
170 bool Parse();
171
172 std::vector<Component*> GetComponents() const { return m_components; }
173 std::vector<PowerLine*> GetLines() const { return m_lines; }
174 std::vector<BranchData*> GetBranchData() const { return m_branchData; }
175 std::vector<BusData*> GetBusData() const { return m_busData; }
176 std::vector<IndElementData*> GetIndElementData() const { return m_indElementData; }
177 wxString GetProjectName() const { return m_projectName; }
178 double GetMVAPowerBase() const { return m_mvaBase; }
179
180 wxPoint2DDouble GetNodePositionFromID(Bus* bus, double scale, int nodeID);
181 BusData* GetBusDataFromID(int id);
182 BranchData* GetBranchDataFromID(int id, int fromBus, int toBus, ElementTypeAnarede type);
183 IndElementData* GetIndElementDataFromID(int id, int busID, ElementTypeAnarede type);
184
185 void ClearData();
186
187 protected:
188 bool GetLenghtAndRotationFromBusCode(wxString code, double& lenght, int& rotationID);
189 wxString GetLSTLineNextValue(wxString line, int& currentPos);
190 bool StrToElementType(wxString strType, ElementTypeAnarede& type);
191 bool ParsePWFExeCode(wxString data, wxString exeCode);
192 bool GetPWFStructuredData(wxString data,
193 unsigned int startPos,
194 unsigned int dataLenght,
195 int& value,
196 int decimalPos = -1);
197 bool GetPWFStructuredData(wxString data,
198 unsigned int startPos,
199 unsigned int dataLenght,
200 double& value,
201 int decimalPos = -1);
202
203 wxFileName m_lstFile;
204 wxFileName m_pwfFile;
205
206 std::vector<Component*> m_components;
207 std::vector<PowerLine*> m_lines;
208 std::vector<BusData*> m_busData;
209 std::vector<BranchData*> m_branchData;
210 std::vector<IndElementData*> m_indElementData;
211
212 wxString m_projectName = _("Imported project");
213 double m_mvaBase = 100.0;
214};
215
217{
218 public:
219 struct BusData {
220 int id = 0;
221 int type = 0;
222 double pd = 0.0;
223 double qd = 0.0;
224 double gs = 0.0;
225 double bs = 0.0;
226 int area = 0;
227 double voltage = 1.0;
228 double angle = 0.0;
229 double baseVoltage = 138;
230 wxString busName = "Bus";
231 wxPoint2DDouble busPosition = wxPoint2DDouble(0,0);
232 };
233 struct GenData {
234 int busID = 0;
235 double pg = 0.0;
236 double qg = 0.0;
237 double maxReactivePower = 99999.0;
238 double minReactivePower = -9999.0;
239 double baseMVA = 100;
240 bool isOnline = true;
241 };
242 struct BranchData {
243 std::pair<int, int> busConnections = std::make_pair(0, 0);
244 double resistance = 0.0;
245 double indReactance = 0.0;
246 double capSusceptance = 0.0;
247 double tap = 0.0;
248 double phaseShift = 0.0;
249 bool isOnline = true;
250 };
251
252 ParseMatpower(wxFileName mFile);
253 ~ParseMatpower() { ClearData(); }
254
255 void ClearData();
256
257 bool Parse();
258
259 std::vector<BranchData*> GetBranchData() const { return m_branchData; }
260 std::vector<BusData*> GetBusData() const { return m_busData; }
261 std::vector<GenData*> GetGenData() const { return m_genData; }
262 double GetMVAPowerBase() const { return m_mvaBase; }
263
264 BusData* GetBusDataFromID(int id);
265 Bus* GetBusFromID(int id, std::vector<Bus*> busList);
266
267 protected:
268 wxStringTokenizer GetMFileTokenData(wxTextFile& mFile, wxString currentLine);
269 wxFileName m_mFile;
270
271 std::vector<BusData*> m_busData;
272 std::vector<BranchData*> m_branchData;
273 std::vector<GenData*> m_genData;
274
275 wxString m_projectName = _("Imported project");
276 double m_mvaBase = 100.0;
277};
278
279#endif // IMPORTFORM_H
ElementTypeAnarede
Definition ImportForm.h:76
@ ANA_IND_GENERATOR
Definition ImportForm.h:86
@ ANA_MIT
Definition ImportForm.h:81
@ ANA_GENERATOR
Definition ImportForm.h:78
@ ANA_BUS
Definition ImportForm.h:77
@ ANA_LINE
Definition ImportForm.h:83
@ ANA_IND_LOAD
Definition ImportForm.h:84
@ ANA_SHUNT
Definition ImportForm.h:80
@ ANA_TRANSFORMER
Definition ImportForm.h:82
@ ANA_LOAD
Definition ImportForm.h:79
@ ANA_IND_SHUNT
Definition ImportForm.h:85
Node for power elements. All others power elements are connected through this.
Definition Bus.h:86
Shunt capactior power element.
Definition Capacitor.h:39
Form to import other programs files to PSP.
Definition ImportForm.h:53
Induction motor power element.
Definition IndMotor.h:119
Inductor shunt power element.
Definition Inductor.h:39
Power line element.
Definition Line.h:64
Loas shunt power element.
Definition Load.h:74
Class responsible to parse ANAREDE files to import data to PSP.
Definition ImportForm.h:97
General and simulation data manager.
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
Definition SyncMotor.h:135
Two-winding transformer power element.
Definition Transformer.h:84
This class manages the graphical and power elements. It is responsible for handling the user's intera...
Definition Workspace.h:103
std::pair< int, int > busConnections
Definition ImportForm.h:141
ElementTypeAnarede type
Definition ImportForm.h:140
std::complex< double > loadPower
Definition ImportForm.h:134
std::complex< double > genPower
Definition ImportForm.h:130
ElementTypeAnarede type
Definition ImportForm.h:102
std::pair< int, int > busConnectionNode[2]
Definition ImportForm.h:109
wxPoint2DDouble position
Definition ImportForm.h:105
std::pair< int, int > busConnectionID[2]
Definition ImportForm.h:107
std::complex< double > power
Definition ImportForm.h:154
ElementTypeAnarede type
Definition ImportForm.h:152
std::vector< wxPoint2DDouble > nodesPosition
Definition ImportForm.h:120
std::pair< int, int > busConnectionNode[2]
Definition ImportForm.h:118
std::pair< int, int > busConnectionID[2]
Definition ImportForm.h:116
ElementTypeAnarede type
Definition ImportForm.h:114
std::pair< int, int > busConnections
Definition ImportForm.h:243
wxPoint2DDouble busPosition
Definition ImportForm.h:231