Power System Platform  2026w10a-beta
Loading...
Searching...
No Matches
ImportForm Class Reference

Form to import other programs files to PSP. More...

#include <ImportForm.h>

Inheritance diagram for ImportForm:
Collaboration diagram for ImportForm:

Public Member Functions

 ImportForm (wxWindow *parent, Workspace *workspace)
 
WorkspaceGetWorkspace ()
 

Protected Member Functions

virtual void OnButtonCancelClick (wxCommandEvent &event)
 
virtual void OnButtonOKClick (wxCommandEvent &event)
 
bool ImportSelectedFiles ()
 
bool ImportCEPELFiles ()
 
bool ImportMatpowerFiles ()
 
BusGetBusFromID (std::vector< Bus * > busList, int id)
 

Protected Attributes

Workspacem_workspace = nullptr
 
wxWindow * m_parent
 

Detailed Description

Form to import other programs files to PSP.

Author
Thales Lima Oliveira thale.nosp@m.s@uf.nosp@m.u.br
Date
27/03/2018

Definition at line 52 of file ImportForm.h.

Constructor & Destructor Documentation

◆ ImportForm()

ImportForm::ImportForm ( wxWindow *  parent,
Workspace workspace 
)

Definition at line 35 of file ImportForm.cpp.

35 : ImportFormBase(parent)
36{
37 SetInitialSize();
38
39 m_parent = parent;
40 m_workspace = workspace;
41}

◆ ~ImportForm()

ImportForm::~ImportForm ( )
virtual

Definition at line 43 of file ImportForm.cpp.

43{}

Member Function Documentation

◆ GetBusFromID()

Bus * ImportForm::GetBusFromID ( std::vector< Bus * >  busList,
int  id 
)
protected

Definition at line 80 of file ImportForm.cpp.

81{
82 for(auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
83 if((*it)->GetID() == id) return *it;
84 }
85 return nullptr;
86}

◆ GetWorkspace()

Workspace * ImportForm::GetWorkspace ( )
inline

Definition at line 58 of file ImportForm.h.

58{ return m_workspace; }

◆ ImportCEPELFiles()

bool ImportForm::ImportCEPELFiles ( )
protected

Definition at line 88 of file ImportForm.cpp.

89{
90 ParseAnarede parseAnarede(m_filePickerANAREDELST->GetFileName(), m_filePickerANAREDEPWF->GetFileName());
91 if(!parseAnarede.Parse()) return false;
92 double scale = 1.25;
93
94 double mvaBasePower = parseAnarede.GetMVAPowerBase();
95 auto simProp = m_workspace->GetProperties()->GetSimulationPropertiesData();
96 simProp.basePower = mvaBasePower;
97 m_workspace->GetProperties()->SetSimulationPropertiesData(simProp);
98
99 std::vector<Element*> elementList;
100
101 std::vector<Bus*> busList;
102 std::vector<SyncGenerator*> syncGeneratorList;
103 std::vector<SyncMotor*> syncMotorList;
104 std::vector<Load*> loadList;
105 std::vector<Inductor*> indList;
106 std::vector<Capacitor*> capList;
107 std::vector<IndMotor*> indMotorList;
108 std::vector<Transformer*> transformerList;
109 std::vector<Line*> lineList;
110
111 auto components = parseAnarede.GetComponents();
112 for(auto it = components.begin(), itEnd = components.end(); it != itEnd; ++it) {
113 switch((*it)->type) {
114 case ANA_BUS: {
115 Bus* bus = new Bus(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
116 bus->SetID((*it)->id);
117 bus->SetWidth((*it)->length * scale);
118 bus->StartMove(bus->GetPosition());
119 if((*it)->rotationID == 0) {
120 bus->Move(bus->GetPosition() + wxPoint2DDouble(bus->GetWidth() / 2, bus->GetHeight() / 2));
121 } else if((*it)->rotationID == 1) {
122 for(int i = 0; i < (*it)->rotationID * 2; ++i) bus->Rotate();
123 bus->Move(bus->GetPosition() + wxPoint2DDouble(-bus->GetHeight() / 2, bus->GetWidth() / 2));
124 } else if((*it)->rotationID == 2) {
125 for(int i = 0; i < (*it)->rotationID * 2; ++i) bus->Rotate();
126 bus->Move(bus->GetPosition() + wxPoint2DDouble(-bus->GetWidth() / 2, -bus->GetHeight() / 2));
127 } else if((*it)->rotationID == 3) {
128 for(int i = 0; i < (*it)->rotationID * 2; ++i) bus->Rotate();
129 bus->Move(bus->GetPosition() + wxPoint2DDouble(-bus->GetHeight() / 2, -bus->GetWidth() / 2));
130 }
131
132 // Electrical data
133 auto data = bus->GetElectricalData();
134 ParseAnarede::BusData* busData = parseAnarede.GetBusDataFromID((*it)->electricalID);
135 if(busData) {
136 data.number = busData->id;
137 data.name = busData->busName;
138 switch(busData->type) {
139 case 0:
140 case 3: {
141 data.isVoltageControlled = false;
142 data.slackBus = false;
143 } break;
144 case 1: {
145 data.isVoltageControlled = true;
146 data.slackBus = false;
147 } break;
148 case 2: {
149 data.isVoltageControlled = true;
150 data.slackBus = true;
151 } break;
152 default: {
153 return false;
154 } break;
155 }
156 data.voltage = std::complex<double>(busData->voltage * std::cos(wxDegToRad(busData->angle)),
157 busData->voltage * std::sin(wxDegToRad(busData->angle)));
158 data.controlledVoltage = busData->voltage;
159 } else
160 return false;
161
162 bus->SetElectricalData(data);
163 busList.push_back(bus);
164 } break;
165 case ANA_GENERATOR:
166 case ANA_IND_GENERATOR: {
167 // Find parent bus
168 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
169 wxPoint2DDouble nodePos =
170 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
171
172 ParseAnarede::BusData* busData = parseAnarede.GetBusDataFromID((*it)->busConnectionID[0].second);
173 bool isMotor = false;
174 if(busData->genPower.real() <= 0.0) isMotor = true;
175 Machines* machine = nullptr;
176
177 if(!isMotor) {
178 SyncGenerator* syncGenerator = new SyncGenerator();
179
180 auto data = syncGenerator->GetElectricalData();
181 data.name =
182 wxString::Format("%s %u (%s)", _("Generator"), syncGeneratorList.size() + 1, busData->busName);
183 if((*it)->type == ANA_IND_GENERATOR) {
184 ParseAnarede::IndGenData* genData =
185 static_cast<ParseAnarede::IndGenData*>(parseAnarede.GetIndElementDataFromID(
186 (*it)->electricalID, (*it)->busConnectionID[0].second, ANA_IND_GENERATOR));
187 double numUnits = static_cast<double>(genData->numUnits);
188 data.activePower = genData->power.real() * numUnits;
189 data.reactivePower = genData->power.imag() * numUnits;
190 data.maxReactive = genData->maxReactivePower * numUnits;
191 data.minReactive = genData->minReactivePower * numUnits;
192 data.nominalPower = genData->ratedPower * numUnits;
193 double xd = genData->xd / (100.0 * numUnits);
194 data.syncXd = xd > 1e-3 ? xd : 1.0;
195 data.syncXq = genData->xq / (100.0 * numUnits);
196 data.potierReactance = genData->xl / (100.0 * numUnits);
197 } else {
198 data.activePower = busData->genPower.real();
199 data.reactivePower = busData->genPower.imag();
200 data.minReactive = busData->minReactivePower;
201 data.maxReactive = busData->maxReactivePower;
202 data.useMachineBase = false; // ANAREDE use system's base
203 }
204
205 syncGenerator->SetElectricalData(data);
206
207 machine = syncGenerator;
208 } else {
209 SyncMotor* syncMotor = new SyncMotor();
210
211 auto data = syncMotor->GetElectricalData();
212 data.name = wxString::Format("%s %u (%s)", _("Synchronous compensator"), syncMotorList.size() + 1,
213 busData->busName);
214 data.activePower = busData->genPower.real() == 0.0 ? 0.0 : -busData->genPower.real();
215 data.reactivePower = busData->genPower.imag();
216 data.minReactive = busData->minReactivePower;
217 data.maxReactive = busData->maxReactivePower;
218 data.useMachineBase = false; // ANAREDE use system's base
219
220 syncMotor->SetElectricalData(data);
221
222 machine = syncMotor;
223 }
224
225 if(machine) {
226 machine->SetID((*it)->id);
227 machine->AddParent(parentBus, nodePos);
228
229 machine->StartMove(machine->GetPosition());
230 machine->Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
231
232 for(int i = 0; i < 2; ++i) machine->Rotate(false); // Set to ANAREDE default rotation
233 for(int i = 0; i < (*it)->rotationID * 2; ++i) machine->Rotate();
234
235 if(!isMotor)
236 syncGeneratorList.push_back(static_cast<SyncGenerator*>(machine));
237 else
238 syncMotorList.push_back(static_cast<SyncMotor*>(machine));
239 }
240 } break;
241 case ANA_LOAD:
242 case ANA_IND_LOAD: {
243 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
244 wxPoint2DDouble nodePos =
245 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
246
247 ParseAnarede::BusData* busData = parseAnarede.GetBusDataFromID((*it)->busConnectionID[0].second);
248
249 Load* load = new Load();
250 load->SetID((*it)->id);
251 load->AddParent(parentBus, nodePos);
252
253 load->StartMove(load->GetPosition());
254 load->Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
255
256 auto data = load->GetElectricalData();
257 data.name = wxString::Format("%s %u (%s)", _("Load"), loadList.size() + 1, busData->busName);
258 data.activePower = busData->loadPower.real();
259 data.reactivePower = busData->loadPower.imag();
260 load->SetElectricalData(data);
261
262 for(int i = 0; i < (*it)->rotationID * 2; ++i) load->Rotate();
263
264 loadList.push_back(load);
265 } break;
266 case ANA_SHUNT:
267 case ANA_IND_SHUNT: {
268 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
269 wxPoint2DDouble nodePos =
270 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
271
272 ParseAnarede::BusData* busData = parseAnarede.GetBusDataFromID((*it)->busConnectionID[0].second);
273 bool isInductor = false;
274 Shunt* shuntElement = nullptr;
275
276 double ql = 0.0;
277 if((*it)->type == ANA_IND_SHUNT) {
278 ParseAnarede::IndElementData* shuntData = parseAnarede.GetIndElementDataFromID(
279 (*it)->electricalID, (*it)->busConnectionID[0].second, ANA_IND_SHUNT);
280 if(shuntData) {
281 double numUnits = static_cast<double>(shuntData->numUnits);
282 ql = shuntData->power.imag() * numUnits;
283 }
284 } else {
285 ql = busData->shuntReactive;
286 }
287 if(ql <= 0.0) isInductor = true;
288
289 if(!isInductor) {
290 Capacitor* cap = new Capacitor();
291 auto data = cap->GetElectricalData();
292 data.name = wxString::Format("%s %u (%s)", _("Capacitor"), indList.size() + 1, busData->busName);
293 data.reactivePower = ql;
294 cap->SetElectricalData(data);
295 shuntElement = cap;
296 } else {
297 Inductor* ind = new Inductor();
298 auto data = ind->GetElectricalData();
299 data.name = wxString::Format("%s %u (%s)", _("Inductor"), indList.size() + 1, busData->busName);
300 data.reactivePower = std::abs(ql);
301 ind->SetElectricalData(data);
302 shuntElement = ind;
303 }
304
305 if(shuntElement) {
306 shuntElement->SetID((*it)->id);
307 shuntElement->AddParent(parentBus, nodePos);
308
309 shuntElement->StartMove(shuntElement->GetPosition());
310 // Offset (ind->GetHeight() / 2 + 10) to adequate the y coordinate
311 shuntElement->Move(wxPoint2DDouble(
312 (*it)->position.m_x * scale, (*it)->position.m_y * scale + shuntElement->GetHeight() / 2 + 10));
313 if((*it)->rotationID != 0) {
314 // Remove offset in position
315 shuntElement->Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
316 // Get the rotated point ralated to the offset
317 wxPoint2DDouble movePt = shuntElement->RotateAtPosition(
318 shuntElement->GetPosition() + wxPoint2DDouble(0, shuntElement->GetHeight() / 2 + 10),
319 (*it)->rotationID * 90.0, true);
320 shuntElement->Move(movePt);
321
322 for(int i = 0; i < (*it)->rotationID * 2; ++i) shuntElement->Rotate();
323 }
324
325 if(!isInductor)
326 capList.push_back(static_cast<Capacitor*>(shuntElement));
327 else
328 indList.push_back(static_cast<Inductor*>(shuntElement));
329 }
330 } break;
331 case ANA_MIT: {
332 // Find parent bus
333 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
334 wxPoint2DDouble nodePos =
335 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
336
337 IndMotor* indMotor = new IndMotor();
338 indMotor->SetID((*it)->id);
339 indMotor->AddParent(parentBus, nodePos);
340
341 indMotor->StartMove(indMotor->GetPosition());
342 indMotor->Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
343
344 auto data = indMotor->GetElectricalData();
345 data.name = wxString::Format("%s %u (%s)", _("Motor"), indMotorList.size() + 1,
346 parentBus->GetElectricalData().name);
347 data.activePower = 0.0;
348 data.reactivePower = 0.0;
349 indMotor->SetElectricalData(data);
350
351 for(int i = 0; i < 2; ++i) indMotor->Rotate(false); // Set to ANAREDE default rotation
352 for(int i = 0; i < (*it)->rotationID * 2; ++i) indMotor->Rotate();
353
354 indMotorList.push_back(indMotor);
355 } break;
356 case ANA_TRANSFORMER: {
357 Bus* parentBus1 = GetBusFromID(busList, (*it)->busConnectionID[0].first);
358 Bus* parentBus2 = GetBusFromID(busList, (*it)->busConnectionID[1].first);
359 wxPoint2DDouble nodePos1 =
360 parseAnarede.GetNodePositionFromID(parentBus1, scale, (*it)->busConnectionNode[0].second);
361 wxPoint2DDouble nodePos2 =
362 parseAnarede.GetNodePositionFromID(parentBus2, scale, (*it)->busConnectionNode[1].second);
363
364 ParseAnarede::BranchData* branchData =
365 parseAnarede.GetBranchDataFromID((*it)->electricalID, (*it)->busConnectionID[0].second,
366 (*it)->busConnectionID[1].second, ANA_TRANSFORMER);
367
368 Transformer* transformer = new Transformer();
369 transformer->SetID((*it)->id);
370 transformer->AddParent(parentBus1, nodePos1);
371 transformer->AddParent(parentBus2, nodePos2);
372
373 transformer->StartMove(transformer->GetPosition());
374 transformer->Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
375
376 for(int i = 0; i < 2; ++i) transformer->Rotate(); // Set to ANAREDE default rotation
377 for(int i = 0; i < (*it)->rotationID * 2; ++i) transformer->Rotate();
378
379 auto data = transformer->GetElectricalData();
380 data.name =
381 wxString::Format("%s %u (%s - %s)", _("Transformer"), transformerList.size() + 1,
382 parentBus1->GetElectricalData().name, parentBus2->GetElectricalData().name);
383 data.resistance = branchData->resistance / 100.0;
384 data.indReactance = branchData->indReactance / 100.0;
385 data.turnsRatio = branchData->tap;
386 data.phaseShift = branchData->phaseShift;
387 transformer->SetElectricaData(data);
388
389 transformerList.push_back(transformer);
390 } break;
391 default: {
392 } break;
393 }
394 }
395
396 auto powerLines = parseAnarede.GetLines();
397 for(auto it = powerLines.begin(), itEnd = powerLines.end(); it != itEnd; ++it) {
398 if((*it)->type == ANA_LINE) {
399 Bus* parentBus1 = GetBusFromID(busList, (*it)->busConnectionID[0].first);
400 Bus* parentBus2 = GetBusFromID(busList, (*it)->busConnectionID[1].first);
401 wxPoint2DDouble nodePos1 =
402 parseAnarede.GetNodePositionFromID(parentBus1, scale, (*it)->busConnectionNode[0].second);
403 wxPoint2DDouble nodePos2 =
404 parseAnarede.GetNodePositionFromID(parentBus2, scale, (*it)->busConnectionNode[1].second);
405
406 ParseAnarede::BranchData* branchData = parseAnarede.GetBranchDataFromID(
407 (*it)->electricalID, (*it)->busConnectionID[0].second, (*it)->busConnectionID[1].second, ANA_LINE);
408
409 Line* line = new Line();
410 line->SetID((*it)->id);
411 line->AddParent(parentBus1, nodePos1);
412 for(unsigned int i = 0; i < (*it)->nodesPosition.size(); ++i)
413 line->AddPoint(
414 wxPoint2DDouble((*it)->nodesPosition[i].m_x * scale, (*it)->nodesPosition[i].m_y * scale));
415 line->AddParent(parentBus2, nodePos2);
416
417 auto data = line->GetElectricalData();
418 data.name = wxString::Format("%s %u (%s - %s)", _("Line"), lineList.size() + 1,
419 parentBus1->GetElectricalData().name, parentBus2->GetElectricalData().name);
420 data.resistance = branchData->resistance / 100.0;
421 data.indReactance = branchData->indReactance / 100.0;
422 data.capSusceptance = branchData->capSusceptance / mvaBasePower;
423 line->SetElectricalData(data);
424
425 lineList.push_back(line);
426 }
427 }
428
429 // Search for bus data without component
430 std::vector<ParseAnarede::BusData*> busDataVector = parseAnarede.GetBusData();
431 for(auto it = busDataVector.begin(), itEnd = busDataVector.end(); it != itEnd; ++it) {
432 ParseAnarede::BusData* busData = *it;
433
434 // Search for bus
435 Bus* bus = nullptr;
436 for(auto itB = busList.begin(), itBEnd = busList.end(); itB != itBEnd; ++itB) {
437 if((*itB)->GetElectricalData().number == busData->id) {
438 bus = *itB;
439 break;
440 }
441 }
442 if(bus) {
443 // Check load data
444 if(std::abs(busData->loadPower.real()) > 1e-5 ||
445 std::abs(busData->loadPower.imag()) > 1e-5) { // Have loads
446 // Find load associated with the bus
447 Load* load = nullptr;
448 for(auto itL = loadList.begin(), itLEnd = loadList.end(); itL != itLEnd; ++itL) {
449 if((*itL)->GetParentList().size() > 0) { // Don't search in empty vectors
450 if((*itL)->GetParentList()[0] == bus) { // Found load
451 load = *itL;
452 break;
453 }
454 }
455 }
456 if(!load) { // The load don't exists, create a new one.
457 Load* newLoad =
458 new Load(wxString::Format("%s %u (%s)", _("Load"), loadList.size() + 1, busData->busName));
459 newLoad->AddParent(bus, bus->GetPosition());
460 auto data = newLoad->GetElectricalData();
461 data.activePower = busData->loadPower.real();
462 data.reactivePower = busData->loadPower.imag();
463 newLoad->SetElectricalData(data);
464
465 loadList.push_back(newLoad);
466 }
467 }
468 // Check generation data
469 if(std::abs(busData->genPower.real()) > 1e-5 || std::abs(busData->genPower.imag()) > 1e-5) {
470 // Find synchornous machine associated with bus
471 if(busData->genPower.real() > 0.0) { // Synchronous generator
472 SyncGenerator* syncGenerator = nullptr;
473 for(auto itSM = syncGeneratorList.begin(), itSMEnd = syncGeneratorList.end(); itSM != itSMEnd;
474 ++itSM) {
475 if((*itSM)->GetParentList().size() > 0) { // Don't search in empty vectors
476 if((*itSM)->GetParentList()[0] == bus) { // Found load
477 syncGenerator = *itSM;
478 break;
479 }
480 }
481 }
482 if(!syncGenerator) {
483 SyncGenerator* newSyncGenerator = new SyncGenerator(wxString::Format(
484 "%s %u (%s)", _("Generator"), syncGeneratorList.size() + 1, busData->busName));
485 newSyncGenerator->AddParent(bus, bus->GetPosition());
486 auto data = newSyncGenerator->GetElectricalData();
487 data.activePower = busData->genPower.real();
488 data.reactivePower = busData->genPower.imag();
489 newSyncGenerator->SetElectricalData(data);
490
491 syncGeneratorList.push_back(newSyncGenerator);
492 }
493 } else {
494 SyncMotor* syncMotor = nullptr;
495 for(auto itSM = syncMotorList.begin(), itSMEnd = syncMotorList.end(); itSM != itSMEnd; ++itSM) {
496 if((*itSM)->GetParentList().size() > 0) { // Don't search in empty vectors
497 if((*itSM)->GetParentList()[0] == bus) { // Found load
498 syncMotor = *itSM;
499 break;
500 }
501 }
502 }
503 if(!syncMotor) {
504 SyncMotor* newSyncMotor = new SyncMotor(wxString::Format(
505 "%s %u (%s)", _("Synchronous compensator"), syncMotorList.size() + 1, busData->busName));
506 newSyncMotor->AddParent(bus, bus->GetPosition());
507 auto data = newSyncMotor->GetElectricalData();
508 data.activePower = std::abs(busData->genPower.real());
509 data.reactivePower = busData->genPower.imag();
510 newSyncMotor->SetElectricalData(data);
511
512 syncMotorList.push_back(newSyncMotor);
513 }
514 }
515 }
516 }
517 }
518 // Check for branch data without component (?)
519
520 for(auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) elementList.push_back(*it);
521 for(auto it = transformerList.begin(), itEnd = transformerList.end(); it != itEnd; ++it) elementList.push_back(*it);
522 for(auto it = lineList.begin(), itEnd = lineList.end(); it != itEnd; ++it) elementList.push_back(*it);
523 for(auto it = syncGeneratorList.begin(), itEnd = syncGeneratorList.end(); it != itEnd; ++it)
524 elementList.push_back(*it);
525 for(auto it = syncMotorList.begin(), itEnd = syncMotorList.end(); it != itEnd; ++it) elementList.push_back(*it);
526 for(auto it = loadList.begin(), itEnd = loadList.end(); it != itEnd; ++it) elementList.push_back(*it);
527 for(auto it = indList.begin(), itEnd = indList.end(); it != itEnd; ++it) elementList.push_back(*it);
528 for(auto it = capList.begin(), itEnd = capList.end(); it != itEnd; ++it) elementList.push_back(*it);
529 for(auto it = indMotorList.begin(), itEnd = indMotorList.end(); it != itEnd; ++it) elementList.push_back(*it);
530
531 m_workspace->SetElementList(elementList);
532 m_workspace->SetName(parseAnarede.GetProjectName());
533 return true;
534}
@ 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
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Bus.cpp:315
Shunt capactior power element.
Definition Capacitor.h:39
double GetWidth() const
Get the element width.
Definition Element.h:206
wxPoint2DDouble GetPosition() const
Get the element position.
Definition Element.h:186
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Element.h:239
void SetWidth(double width)
Set element width.
Definition Element.h:149
double GetHeight() const
Get the element height.
Definition Element.h:196
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Element.cpp:329
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
Definition Element.cpp:292
virtual void SetID(int id)
Set the element ID.
Definition Element.h:266
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Definition Element.cpp:335
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Element.h:316
Induction motor power element.
Definition IndMotor.h:119
Inductor shunt power element.
Definition Inductor.h:39
Power line element.
Definition Line.h:64
virtual void AddPoint(wxPoint2DDouble point)
Add point to the list of points that connect the element to the bus.
Definition Line.cpp:372
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Line.cpp:275
Loas shunt power element.
Definition Load.h:74
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Load.cpp:270
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Load.cpp:33
Abstract class for rotary machines power elements.
Definition Machines.h:34
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Definition Machines.cpp:223
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Machines.cpp:24
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Machines.cpp:258
virtual void Rotate(bool clockwise=true)
Rotate the element.
Definition Machines.cpp:344
Class responsible to parse ANAREDE files to import data to PSP.
Definition ImportForm.h:97
Abstract class for shunt power elements.
Definition Shunt.h:32
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Shunt.cpp:67
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Definition Shunt.cpp:32
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
Definition SyncMotor.h:135
Two-winding transformer power element.
Definition Transformer.h:84
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
std::complex< double > loadPower
Definition ImportForm.h:134
std::complex< double > genPower
Definition ImportForm.h:130
std::complex< double > power
Definition ImportForm.h:154

◆ ImportMatpowerFiles()

bool ImportForm::ImportMatpowerFiles ( )
protected

Definition at line 536 of file ImportForm.cpp.

537{
538 ParseMatpower parseMatpower(m_filePickerMatpowerM->GetFileName());
539 if(!parseMatpower.Parse()) return false;
540
541 double mvaBasePower = parseMatpower.GetMVAPowerBase();
542 auto simProp = m_workspace->GetProperties()->GetSimulationPropertiesData();
543 simProp.basePower = mvaBasePower;
544 m_workspace->GetProperties()->SetSimulationPropertiesData(simProp);
545
546 std::vector<Element*> elementList;
547
548 std::vector<Bus*> busList;
549 std::vector<SyncGenerator*> syncGeneratorList;
550 std::vector<SyncMotor*> syncMotorList;
551 std::vector<Load*> loadList;
552 std::vector<Inductor*> indList;
553 std::vector<Capacitor*> capList;
554 std::vector<IndMotor*> indMotorList;
555 std::vector<Transformer*> transformerList;
556 std::vector<Line*> lineList;
557
558 int iterations = wxAtoi(m_textCtrlIterations->GetValue());
559 double scale;
560 if(!m_textCtrlScale->GetValue().ToDouble(&scale)) return false;
561
562 // Automatically calculate buses positions using weighted graph to determine the layout
563 GraphAutoLayout gal(parseMatpower.GetBusData(), parseMatpower.GetBranchData());
564 gal.CalculatePositions(iterations, scale);
565
566 // Fill bus list
567 auto busDataList = parseMatpower.GetBusData();
568 for(auto it = busDataList.begin(), itEnd = busDataList.end(); it != itEnd; ++it) {
569 ParseMatpower::BusData* busData = *it;
570
571 Bus* bus = new Bus(busData->busPosition);
572 bus->SetID((*it)->id);
573
574 // Electrical data
575 auto data = bus->GetElectricalData();
576 if(busData) {
577 data.number = busData->id;
578 data.name = busData->busName;
579 switch(busData->type) {
580 case 3: {
581 data.isVoltageControlled = true;
582 data.slackBus = true;
583 } break;
584 case 1: {
585 data.isVoltageControlled = false;
586 data.slackBus = false;
587 } break;
588 case 2: {
589 data.isVoltageControlled = true;
590 data.slackBus = false;
591 } break;
592 default: {
593 return false;
594 } break;
595 }
596 data.voltage = std::complex<double>(busData->voltage * std::cos(wxDegToRad(busData->angle)),
597 busData->voltage * std::sin(wxDegToRad(busData->angle)));
598 data.controlledVoltage = busData->voltage;
599 // TODO: Nominal voltage are getting errors (e.g. 118bus.m)
600 // if(busData->baseVoltage > 1e-3) { data.nominalVoltage = busData->baseVoltage; }
601 } else
602 return false;
603
604 bus->SetElectricalData(data);
605 busList.push_back(bus);
606 }
607 // Fill lines list
608 auto branchDataList = parseMatpower.GetBranchData();
609 int lineID = 0;
610 int transformerID = 0;
611 for(auto it = branchDataList.begin(), itEnd = branchDataList.end(); it != itEnd; ++it) {
612 ParseMatpower::BranchData* branchData = *it;
613 Bus* fstParentBus = GetBusFromID(busList, branchData->busConnections.first);
614 Bus* sndParentBus = GetBusFromID(busList, branchData->busConnections.second);
615 if(branchData->tap > 1e-3) { // Transformer
616 Transformer* transformer = new Transformer();
617 transformer->SetID(transformerID);
618 transformer->AddParent(fstParentBus, fstParentBus->GetPosition());
619 transformer->AddParent(sndParentBus, sndParentBus->GetPosition());
620
621 auto data = transformer->GetElectricalData();
622 data.resistance = branchData->resistance;
623 data.indReactance = branchData->indReactance;
624 data.turnsRatio = branchData->tap;
625 data.phaseShift = branchData->phaseShift;
626 data.name =
627 wxString::Format("%s %u (%s - %s)", _("Transfomer"), transformerList.size() + 1,
628 fstParentBus->GetElectricalData().name, sndParentBus->GetElectricalData().name);
629
630 transformer->SetElectricaData(data);
631
632 transformer->SetOnline(branchData->isOnline);
633
634 transformerList.push_back(transformer);
635 transformerID++;
636 } else { // Line
637 Line* line = new Line();
638 line->SetID(lineID);
639 line->AddParent(fstParentBus, fstParentBus->GetPosition());
640 line->AddParent(sndParentBus, sndParentBus->GetPosition());
641
642 auto data = line->GetElectricalData();
643 data.resistance = branchData->resistance;
644 data.indReactance = branchData->indReactance;
645 data.capSusceptance = branchData->capSusceptance;
646 data.name =
647 wxString::Format("%s %u (%s - %s)", _("Line"), lineList.size() + 1,
648 fstParentBus->GetElectricalData().name, sndParentBus->GetElectricalData().name);
649
650 line->SetElectricalData(data);
651
652 line->SetOnline(branchData->isOnline);
653
654 lineList.push_back(line);
655 lineID++;
656 }
657 }
658
659 // Connect Generators
660 auto genDataList = parseMatpower.GetGenData();
661 int genID = 0;
662 for(auto it = genDataList.begin(), itEnd = genDataList.end(); it != itEnd; ++it) {
663 SyncGenerator* generator = new SyncGenerator();
664 ParseMatpower::GenData* genData = *it;
665 generator->SetID(genID);
666
667 Bus* parentBus = GetBusFromID(busList, (*it)->busID);
668 generator->AddParent(parentBus, parentBus->GetPosition());
669
670 auto data = generator->GetElectricalData();
671 data.name = wxString::Format("%s %u (%s)", _("Machine"), syncGeneratorList.size() + 1,
672 parentBus->GetElectricalData().name);
673 data.activePower = genData->pg;
674 data.reactivePower = genData->qg;
675 data.maxReactive = genData->maxReactivePower;
676 data.minReactive = genData->minReactivePower;
677 data.nominalPower = genData->baseMVA;
678 generator->SetElectricalData(data);
679
680 syncGeneratorList.push_back(generator);
681
682 genID++;
683 }
684
685 // Connect Loads and capacitors
686 for(auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
687 Bus* bus = *it;
688 ParseMatpower::BusData* busData = parseMatpower.GetBusDataFromID(bus->GetID());
689 if(busData->pd > 1e-3 || busData->qd > 1e-3) {
690 // The bus have load
691 Load* load = new Load();
692
693 load->AddParent(bus, bus->GetPosition());
694
695 auto data = load->GetElectricalData();
696 data.name = wxString::Format("%s %u (%s)", _("Load"), loadList.size() + 1, busData->busName);
697 data.activePower = busData->pd;
698 data.reactivePower = busData->qd;
699 load->SetElectricalData(data);
700
701 loadList.push_back(load);
702 }
703 if(std::abs(busData->gs) > 1e-3) {
704 // The bus have constant impedance load
705 Load* load = new Load();
706
707 load->AddParent(bus, bus->GetPosition());
708
709 auto data = load->GetElectricalData();
710 data.name = wxString::Format("%s %u (%s)", _("Load"), loadList.size() + 1, busData->busName);
711 data.activePower = busData->gs;
712 data.reactivePower = busData->bs;
713 data.loadType = CONST_IMPEDANCE;
714 load->SetElectricalData(data);
715
716 loadList.push_back(load);
717 } else if(std::abs(busData->bs) > 1e-3) {
718 // The bus have capacitor or inductor connected
719 if(busData->bs < 1e-3) {
720 // Inductor
721 Inductor* inductor = new Inductor();
722
723 inductor->AddParent(bus, bus->GetPosition());
724
725 auto data = inductor->GetElectricalData();
726 data.name = wxString::Format("%s %u (%s)", _("Inductor"), indList.size() + 1, busData->busName);
727 data.reactivePower = std::abs(busData->bs);
728 inductor->SetElectricalData(data);
729
730 indList.push_back(inductor);
731 } else {
732 // Capacitor
733 Capacitor* capacitor = new Capacitor();
734
735 capacitor->AddParent(bus, bus->GetPosition());
736
737 auto data = capacitor->GetElectricalData();
738 data.name = wxString::Format("%s %u (%s)", _("Capacitor"), capList.size() + 1, busData->busName);
739 data.reactivePower = std::abs(busData->bs);
740 capacitor->SetElectricalData(data);
741
742 capList.push_back(capacitor);
743 }
744 }
745 }
746
747 // Adjust generators positions
748 for(auto it = syncGeneratorList.begin(), itEnd = syncGeneratorList.end(); it != itEnd; ++it) {
749 SyncGenerator* generator = *it;
750 generator->StartMove(generator->GetPosition());
751 // TODO: Check why node position have 100 pts offset in x axis
752 generator->MoveNode(generator->GetParentList()[0],
753 generator->GetParentList()[0]->GetPosition() - wxPoint2DDouble(140, 0));
754 generator->Move(generator->GetParentList()[0]->GetPosition() - wxPoint2DDouble(40, 100));
755 generator->Rotate();
756 generator->Rotate();
757 }
758
759 // Adjust loads positions
760 for(auto it = loadList.begin(), itEnd = loadList.end(); it != itEnd; ++it) {
761 Load* load = *it;
762 // Move load to the left of the bus
763 load->StartMove(wxPoint2DDouble(0, 0));
764 load->MoveNode(load->GetParentList()[0], wxPoint2DDouble(-load->GetParentList()[0]->GetWidth() / 2 + 10, 0));
765 load->Move(wxPoint2DDouble(-load->GetParentList()[0]->GetWidth() / 2 + 10, 0));
766 }
767
768 // Adjust capacitors positions
769 for(auto it = capList.begin(), itEnd = capList.end(); it != itEnd; ++it) {
770 Capacitor* capacitor = *it;
771 // Move capacitor to the right of the bus capacitor->StartMove(wxPoint2DDouble(0, 0));
772 capacitor->StartMove(wxPoint2DDouble(0, 0));
773 capacitor->MoveNode(capacitor->GetParentList()[0],
774 wxPoint2DDouble(capacitor->GetParentList()[0]->GetWidth() / 2 - 20, 0));
775 capacitor->Move(wxPoint2DDouble(capacitor->GetParentList()[0]->GetWidth() / 2 - 20, 0));
776 }
777
778 // Adjust inductors positions
779 for(auto it = indList.begin(), itEnd = indList.end(); it != itEnd; ++it) {
780 Inductor* inductor = *it;
781 // Move indutor to the far right of the bus inductor->StartMove(wxPoint2DDouble(0, 0));
782 inductor->StartMove(wxPoint2DDouble(0, 0));
783 inductor->MoveNode(inductor->GetParentList()[0],
784 wxPoint2DDouble(inductor->GetParentList()[0]->GetWidth() / 2 - 10, 0));
785 inductor->Move(wxPoint2DDouble(inductor->GetParentList()[0]->GetWidth() / 2 + 10, 0));
786 }
787
788 // Adjust branches
789 for(auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
790 Bus* bus = *it;
791 int numberOfConnectedBranches = 0;
792 std::vector<Line*> linesConnected;
793 std::vector<Transformer*> transformersConnected;
794
795 std::vector<Element*> childElements = bus->GetChildList();
796 for(unsigned int i = 0; i < childElements.size(); ++i) {
797 if(Line* line = dynamic_cast<Line*>(childElements[i])) {
798 linesConnected.push_back(line);
799 numberOfConnectedBranches++;
800 } else if(Transformer* transformer = dynamic_cast<Transformer*>(childElements[i])) {
801 transformersConnected.push_back(transformer);
802 numberOfConnectedBranches++;
803 }
804 }
805 /*for(auto itc = bus->GetChildList().begin(), itEnd = bus->GetChildList().end(); itc != itEnd; ++itc) {
806 if(Line* line = dynamic_cast<Line*>(*itc)) {
807 linesConnected.push_back(line);
808 numberOfConnectedLines++;
809 }
810 }*/
811
812 if(numberOfConnectedBranches > 0) {
813 double dx = (bus->GetWidth() - 30) / (static_cast<double>(numberOfConnectedBranches + 1));
814 int cont = 0;
815 for(unsigned int i = 0; i < linesConnected.size(); ++i) {
816 Line* lineToMove = linesConnected[i];
817 // Line nove move in x axis
818 wxPoint2DDouble newPos(dx * static_cast<double>(i + 1), 0);
819 lineToMove->StartMove(bus->GetPosition());
820 lineToMove->MoveNode(bus, bus->GetPosition() - wxPoint2DDouble(bus->GetWidth() / 2 - 10, 0) + newPos);
821 cont++;
822 }
823 for(unsigned int i = 0; i < transformersConnected.size(); ++i) {
824 Transformer* trafoToMove = transformersConnected[i];
825 wxPoint2DDouble newPos(dx * static_cast<double>(i + cont + 1), 0);
826 trafoToMove->StartMove(bus->GetPosition());
827 trafoToMove->MoveNode(bus, bus->GetPosition() - wxPoint2DDouble(bus->GetWidth() / 2 - 10, 0) + newPos);
828 trafoToMove->SetBestPositionAndRotation();
829 }
830 }
831 }
832
833 for(auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) elementList.push_back(*it);
834 for(auto it = transformerList.begin(), itEnd = transformerList.end(); it != itEnd; ++it) elementList.push_back(*it);
835 for(auto it = lineList.begin(), itEnd = lineList.end(); it != itEnd; ++it) elementList.push_back(*it);
836 for(auto it = syncGeneratorList.begin(), itEnd = syncGeneratorList.end(); it != itEnd; ++it)
837 elementList.push_back(*it);
838 for(auto it = syncMotorList.begin(), itEnd = syncMotorList.end(); it != itEnd; ++it) elementList.push_back(*it);
839 for(auto it = loadList.begin(), itEnd = loadList.end(); it != itEnd; ++it) elementList.push_back(*it);
840 for(auto it = indList.begin(), itEnd = indList.end(); it != itEnd; ++it) elementList.push_back(*it);
841 for(auto it = capList.begin(), itEnd = capList.end(); it != itEnd; ++it) elementList.push_back(*it);
842 for(auto it = indMotorList.begin(), itEnd = indMotorList.end(); it != itEnd; ++it) elementList.push_back(*it);
843
844 m_workspace->SetElementList(elementList);
845
846 return true;
847}
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Capacitor.cpp:32
virtual std::vector< Element * > GetParentList() const
Get the parent list.
Definition Element.h:559
virtual int GetID() const
Get the element ID.
Definition Element.h:271
virtual std::vector< Element * > GetChildList() const
Get the Child list.
Definition Element.h:564
bool SetOnline(bool online=true)
Set if the element is online or offline.
Definition Element.cpp:447
virtual bool AddParent(Element *parent, wxPoint2DDouble position)
Add a parent to the element. This method must be used on power elements that connect to a bus,...
Definition Inductor.cpp:34
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
Definition Line.cpp:377
virtual void MoveNode(Element *parent, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Definition Line.cpp:383
virtual void MoveNode(Element *element, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Definition Machines.cpp:236
virtual void MoveNode(Element *element, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Definition Shunt.cpp:45
virtual void MoveNode(Element *parent, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
std::pair< int, int > busConnections
Definition ImportForm.h:243
wxPoint2DDouble busPosition
Definition ImportForm.h:231

◆ ImportSelectedFiles()

bool ImportForm::ImportSelectedFiles ( )
protected

Definition at line 63 of file ImportForm.cpp.

64{
65 switch(m_notebook->GetSelection()) {
66 case 0: {
67 return ImportCEPELFiles();
68 break;
69 }
70 case 1: {
71 return ImportMatpowerFiles();
72 break;
73 }
74 default:
75 break;
76 }
77 return false;
78}

◆ OnButtonCancelClick()

void ImportForm::OnButtonCancelClick ( wxCommandEvent &  event)
protectedvirtual

Definition at line 45 of file ImportForm.cpp.

46{
47 EndModal(wxID_CANCEL);
48 //if(m_workspace) delete m_workspace;
49}

◆ OnButtonOKClick()

void ImportForm::OnButtonOKClick ( wxCommandEvent &  event)
protectedvirtual

Definition at line 51 of file ImportForm.cpp.

52{
53 if(ImportSelectedFiles())
54 EndModal(wxID_OK);
55 else {
56 // Error message
57 wxMessageDialog msgDialog(this, _("It was not possible to import the selected files."), _("Error"),
58 wxOK | wxCENTRE | wxICON_ERROR);
59 msgDialog.ShowModal();
60 }
61}

Member Data Documentation

◆ m_parent

wxWindow* ImportForm::m_parent
protected

Definition at line 69 of file ImportForm.h.

◆ m_workspace

Workspace* ImportForm::m_workspace = nullptr
protected

Definition at line 68 of file ImportForm.h.


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