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

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