20#include "../elements/powerElement/Bus.h"
21#include "../elements/powerElement/Capacitor.h"
22#include "../elements/powerElement/IndMotor.h"
23#include "../elements/powerElement/Inductor.h"
24#include "../elements/powerElement/Line.h"
25#include "../elements/powerElement/Load.h"
26#include "../elements/powerElement/SyncGenerator.h"
27#include "../elements/powerElement/SyncMotor.h"
28#include "../elements/powerElement/Transformer.h"
30#include "../utils/PropertiesData.h"
31#include "../utils/GraphAutoLayout.h"
33#include "../editors/Workspace.h"
35ImportForm::ImportForm(wxWindow* parent,
Workspace* workspace) : ImportFormBase(parent)
40 m_workspace = workspace;
43ImportForm::~ImportForm() {}
45void ImportForm::OnButtonCancelClick(wxCommandEvent& event)
47 EndModal(wxID_CANCEL);
51void ImportForm::OnButtonOKClick(wxCommandEvent& event)
53 if(ImportSelectedFiles())
57 wxMessageDialog msgDialog(
this, _(
"It was not possible to import the selected files."), _(
"Error"),
58 wxOK | wxCENTRE | wxICON_ERROR);
59 msgDialog.ShowModal();
63bool ImportForm::ImportSelectedFiles()
65 switch(m_notebook->GetSelection()) {
67 return ImportCEPELFiles();
71 return ImportMatpowerFiles();
80Bus* ImportForm::GetBusFromID(std::vector<Bus*> busList,
int id)
82 for(
auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
83 if((*it)->GetID() == id)
return *it;
88bool ImportForm::ImportCEPELFiles()
90 ParseAnarede parseAnarede(m_filePickerANAREDELST->GetFileName(), m_filePickerANAREDEPWF->GetFileName());
91 if(!parseAnarede.Parse())
return false;
94 double mvaBasePower = parseAnarede.GetMVAPowerBase();
95 auto simProp = m_workspace->GetProperties()->GetSimulationPropertiesData();
96 simProp.basePower = mvaBasePower;
97 m_workspace->GetProperties()->SetSimulationPropertiesData(simProp);
99 std::vector<Element*> elementList;
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;
111 auto components = parseAnarede.GetComponents();
112 for(
auto it = components.begin(), itEnd = components.end(); it != itEnd; ++it) {
113 switch((*it)->type) {
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);
119 if((*it)->rotationID == 0) {
121 }
else if((*it)->rotationID == 1) {
122 for(
int i = 0; i < (*it)->rotationID * 2; ++i) bus->
Rotate();
124 }
else if((*it)->rotationID == 2) {
125 for(
int i = 0; i < (*it)->rotationID * 2; ++i) bus->
Rotate();
127 }
else if((*it)->rotationID == 3) {
128 for(
int i = 0; i < (*it)->rotationID * 2; ++i) bus->
Rotate();
133 auto data = bus->GetElectricalData();
136 data.number = busData->
id;
138 switch(busData->
type) {
141 data.isVoltageControlled =
false;
142 data.slackBus =
false;
145 data.isVoltageControlled =
true;
146 data.slackBus =
false;
149 data.isVoltageControlled =
true;
150 data.slackBus =
true;
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;
162 bus->SetElectricalData(data);
163 busList.push_back(bus);
168 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
169 wxPoint2DDouble nodePos =
170 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
173 bool isMotor =
false;
174 if(busData->
genPower.real() <= 0.0) isMotor =
true;
180 auto data = syncGenerator->GetElectricalData();
182 wxString::Format(
"%s %u (%s)", _(
"Generator"), syncGeneratorList.size() + 1, busData->
busName);
187 double numUnits =
static_cast<double>(genData->
numUnits);
188 data.activePower = genData->
power.real() * numUnits;
189 data.reactivePower = genData->
power.imag() * 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);
198 data.activePower = busData->
genPower.real();
199 data.reactivePower = busData->
genPower.imag();
202 data.useMachineBase =
false;
205 syncGenerator->SetElectricalData(data);
207 machine = syncGenerator;
211 auto data = syncMotor->GetElectricalData();
212 data.name = wxString::Format(
"%s %u (%s)", _(
"Synchronous compensator"), syncMotorList.size() + 1,
214 data.activePower = busData->
genPower.real() == 0.0 ? 0.0 : -busData->
genPower.real();
215 data.reactivePower = busData->
genPower.imag();
218 data.useMachineBase =
false;
220 syncMotor->SetElectricalData(data);
226 machine->
SetID((*it)->id);
230 machine->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
232 for(
int i = 0; i < 2; ++i) machine->
Rotate(
false);
233 for(
int i = 0; i < (*it)->rotationID * 2; ++i) machine->
Rotate();
236 syncGeneratorList.push_back(
static_cast<SyncGenerator*
>(machine));
238 syncMotorList.push_back(
static_cast<SyncMotor*
>(machine));
243 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
244 wxPoint2DDouble nodePos =
245 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
250 load->
SetID((*it)->id);
254 load->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
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);
262 for(
int i = 0; i < (*it)->rotationID * 2; ++i) load->
Rotate();
264 loadList.push_back(load);
268 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
269 wxPoint2DDouble nodePos =
270 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
273 bool isInductor =
false;
274 Shunt* shuntElement =
nullptr;
279 (*it)->electricalID, (*it)->busConnectionID[0].second,
ANA_IND_SHUNT);
281 double numUnits =
static_cast<double>(shuntData->
numUnits);
282 ql = shuntData->
power.imag() * numUnits;
287 if(ql <= 0.0) isInductor =
true;
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);
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);
306 shuntElement->
SetID((*it)->id);
307 shuntElement->
AddParent(parentBus, nodePos);
311 shuntElement->
Move(wxPoint2DDouble(
312 (*it)->position.m_x * scale, (*it)->position.m_y * scale + shuntElement->
GetHeight() / 2 + 10));
313 if((*it)->rotationID != 0) {
315 shuntElement->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
319 (*it)->rotationID * 90.0,
true);
320 shuntElement->
Move(movePt);
322 for(
int i = 0; i < (*it)->rotationID * 2; ++i) shuntElement->
Rotate();
326 capList.push_back(
static_cast<Capacitor*
>(shuntElement));
328 indList.push_back(
static_cast<Inductor*
>(shuntElement));
333 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
334 wxPoint2DDouble nodePos =
335 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
338 indMotor->
SetID((*it)->id);
342 indMotor->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
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);
351 for(
int i = 0; i < 2; ++i) indMotor->
Rotate(
false);
352 for(
int i = 0; i < (*it)->rotationID * 2; ++i) indMotor->
Rotate();
354 indMotorList.push_back(indMotor);
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);
365 parseAnarede.GetBranchDataFromID((*it)->electricalID, (*it)->busConnectionID[0].second,
369 transformer->
SetID((*it)->id);
370 transformer->
AddParent(parentBus1, nodePos1);
371 transformer->
AddParent(parentBus2, nodePos2);
374 transformer->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
376 for(
int i = 0; i < 2; ++i) transformer->
Rotate();
377 for(
int i = 0; i < (*it)->rotationID * 2; ++i) transformer->
Rotate();
379 auto data = transformer->GetElectricalData();
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;
385 data.turnsRatio = branchData->
tap;
387 transformer->SetElectricaData(data);
389 transformerList.push_back(transformer);
396 auto powerLines = parseAnarede.GetLines();
397 for(
auto it = powerLines.begin(), itEnd = powerLines.end(); it != itEnd; ++it) {
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);
407 (*it)->electricalID, (*it)->busConnectionID[0].second, (*it)->busConnectionID[1].second,
ANA_LINE);
410 line->
SetID((*it)->id);
412 for(
unsigned int i = 0; i < (*it)->nodesPosition.size(); ++i)
414 wxPoint2DDouble((*it)->nodesPosition[i].m_x * scale, (*it)->nodesPosition[i].m_y * scale));
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;
423 line->SetElectricalData(data);
425 lineList.push_back(line);
430 std::vector<ParseAnarede::BusData*> busDataVector = parseAnarede.GetBusData();
431 for(
auto it = busDataVector.begin(), itEnd = busDataVector.end(); it != itEnd; ++it) {
436 for(
auto itB = busList.begin(), itBEnd = busList.end(); itB != itBEnd; ++itB) {
437 if((*itB)->GetElectricalData().number == busData->
id) {
444 if(std::abs(busData->
loadPower.real()) > 1e-5 ||
445 std::abs(busData->
loadPower.imag()) > 1e-5) {
447 Load* load =
nullptr;
448 for(
auto itL = loadList.begin(), itLEnd = loadList.end(); itL != itLEnd; ++itL) {
449 if((*itL)->GetParentList().size() > 0) {
450 if((*itL)->GetParentList()[0] == bus) {
458 new Load(wxString::Format(
"%s %u (%s)", _(
"Load"), loadList.size() + 1, busData->
busName));
460 auto data = newLoad->GetElectricalData();
461 data.activePower = busData->
loadPower.real();
462 data.reactivePower = busData->
loadPower.imag();
463 newLoad->SetElectricalData(data);
465 loadList.push_back(newLoad);
469 if(std::abs(busData->
genPower.real()) > 1e-5 || std::abs(busData->
genPower.imag()) > 1e-5) {
471 if(busData->
genPower.real() > 0.0) {
473 for(
auto itSM = syncGeneratorList.begin(), itSMEnd = syncGeneratorList.end(); itSM != itSMEnd;
475 if((*itSM)->GetParentList().size() > 0) {
476 if((*itSM)->GetParentList()[0] == bus) {
477 syncGenerator = *itSM;
484 "%s %u (%s)", _(
"Generator"), syncGeneratorList.size() + 1, busData->
busName));
486 auto data = newSyncGenerator->GetElectricalData();
487 data.activePower = busData->
genPower.real();
488 data.reactivePower = busData->
genPower.imag();
489 newSyncGenerator->SetElectricalData(data);
491 syncGeneratorList.push_back(newSyncGenerator);
495 for(
auto itSM = syncMotorList.begin(), itSMEnd = syncMotorList.end(); itSM != itSMEnd; ++itSM) {
496 if((*itSM)->GetParentList().size() > 0) {
497 if((*itSM)->GetParentList()[0] == bus) {
505 "%s %u (%s)", _(
"Synchronous compensator"), syncMotorList.size() + 1, busData->
busName));
507 auto data = newSyncMotor->GetElectricalData();
508 data.activePower = std::abs(busData->
genPower.real());
509 data.reactivePower = busData->
genPower.imag();
510 newSyncMotor->SetElectricalData(data);
512 syncMotorList.push_back(newSyncMotor);
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);
531 m_workspace->SetElementList(elementList);
532 m_workspace->SetName(parseAnarede.GetProjectName());
536bool ImportForm::ImportMatpowerFiles()
538 ParseMatpower parseMatpower(m_filePickerMatpowerM->GetFileName());
539 if(!parseMatpower.Parse())
return false;
541 double mvaBasePower = parseMatpower.GetMVAPowerBase();
542 auto simProp = m_workspace->GetProperties()->GetSimulationPropertiesData();
543 simProp.basePower = mvaBasePower;
544 m_workspace->GetProperties()->SetSimulationPropertiesData(simProp);
546 std::vector<Element*> elementList;
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;
558 int iterations = wxAtoi(m_textCtrlIterations->GetValue());
560 if(!m_textCtrlScale->GetValue().ToDouble(&scale))
return false;
563 GraphAutoLayout gal(parseMatpower.GetBusData(), parseMatpower.GetBranchData());
564 gal.CalculatePositions(iterations, scale);
567 auto busDataList = parseMatpower.GetBusData();
568 for(
auto it = busDataList.begin(), itEnd = busDataList.end(); it != itEnd; ++it) {
572 bus->
SetID((*it)->id);
575 auto data = bus->GetElectricalData();
577 data.number = busData->
id;
579 switch(busData->
type) {
581 data.isVoltageControlled =
true;
582 data.slackBus =
true;
585 data.isVoltageControlled =
false;
586 data.slackBus =
false;
589 data.isVoltageControlled =
true;
590 data.slackBus =
false;
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;
604 bus->SetElectricalData(data);
605 busList.push_back(bus);
608 auto branchDataList = parseMatpower.GetBranchData();
610 int transformerID = 0;
611 for(
auto it = branchDataList.begin(), itEnd = branchDataList.end(); it != itEnd; ++it) {
615 if(branchData->
tap > 1e-3) {
617 transformer->
SetID(transformerID);
621 auto data = transformer->GetElectricalData();
624 data.turnsRatio = branchData->
tap;
627 wxString::Format(
"%s %u (%s - %s)", _(
"Transfomer"), transformerList.size() + 1,
628 fstParentBus->GetElectricalData().name, sndParentBus->GetElectricalData().name);
630 transformer->SetElectricaData(data);
634 transformerList.push_back(transformer);
642 auto data = line->GetElectricalData();
647 wxString::Format(
"%s %u (%s - %s)", _(
"Line"), lineList.size() + 1,
648 fstParentBus->GetElectricalData().name, sndParentBus->GetElectricalData().name);
650 line->SetElectricalData(data);
654 lineList.push_back(line);
660 auto genDataList = parseMatpower.GetGenData();
662 for(
auto it = genDataList.begin(), itEnd = genDataList.end(); it != itEnd; ++it) {
665 generator->
SetID(genID);
667 Bus* parentBus = GetBusFromID(busList, (*it)->busID);
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;
677 data.nominalPower = genData->
baseMVA;
678 generator->SetElectricalData(data);
680 syncGeneratorList.push_back(generator);
686 for(
auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
689 if(busData->
pd > 1e-3 || busData->
qd > 1e-3) {
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);
701 loadList.push_back(load);
703 if(std::abs(busData->
gs) > 1e-3) {
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);
716 loadList.push_back(load);
717 }
else if(std::abs(busData->
bs) > 1e-3) {
719 if(busData->
bs < 1e-3) {
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);
730 indList.push_back(inductor);
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);
742 capList.push_back(capacitor);
748 for(
auto it = syncGeneratorList.begin(), itEnd = syncGeneratorList.end(); it != itEnd; ++it) {
753 generator->
GetParentList()[0]->GetPosition() - wxPoint2DDouble(140, 0));
754 generator->
Move(generator->
GetParentList()[0]->GetPosition() - wxPoint2DDouble(40, 100));
760 for(
auto it = loadList.begin(), itEnd = loadList.end(); it != itEnd; ++it) {
769 for(
auto it = capList.begin(), itEnd = capList.end(); it != itEnd; ++it) {
772 capacitor->
StartMove(wxPoint2DDouble(0, 0));
774 wxPoint2DDouble(capacitor->
GetParentList()[0]->GetWidth() / 2 - 20, 0));
775 capacitor->
Move(wxPoint2DDouble(capacitor->
GetParentList()[0]->GetWidth() / 2 - 20, 0));
779 for(
auto it = indList.begin(), itEnd = indList.end(); it != itEnd; ++it) {
782 inductor->
StartMove(wxPoint2DDouble(0, 0));
784 wxPoint2DDouble(inductor->
GetParentList()[0]->GetWidth() / 2 - 10, 0));
785 inductor->
Move(wxPoint2DDouble(inductor->
GetParentList()[0]->GetWidth() / 2 + 10, 0));
789 for(
auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
791 int numberOfConnectedBranches = 0;
792 std::vector<Line*> linesConnected;
793 std::vector<Transformer*> transformersConnected;
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++;
801 transformersConnected.push_back(transformer);
802 numberOfConnectedBranches++;
812 if(numberOfConnectedBranches > 0) {
813 double dx = (bus->
GetWidth() - 30) / (
static_cast<double>(numberOfConnectedBranches + 1));
815 for(
unsigned int i = 0; i < linesConnected.size(); ++i) {
816 Line* lineToMove = linesConnected[i];
818 wxPoint2DDouble newPos(dx *
static_cast<double>(i + 1), 0);
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);
828 trafoToMove->SetBestPositionAndRotation();
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);
844 m_workspace->SetElementList(elementList);
849ParseAnarede::ParseAnarede(wxFileName lstFile, wxFileName pwfFile)
855bool ParseAnarede::Parse()
857 wxTextFile lst(m_lstFile.GetFullPath());
858 wxTextFile pwf(m_pwfFile.GetFullPath());
859 if(!lst.Open())
return false;
860 if(!pwf.Open())
return false;
863 for(wxString line = lst.GetFirstLine(); !lst.Eof(); line = lst.GetNextLine()) {
865 switch(
static_cast<char>(line[0])) {
867 int parsePosition = 1;
869 Component* component =
new Component();
871 component->id = wxAtoi(GetLSTLineNextValue(line, parsePosition));
873 if(StrToElementType(GetLSTLineNextValue(line, parsePosition), component->type)) {
874 if(component->type ==
ANA_BUS) {
875 if(!GetLenghtAndRotationFromBusCode(GetLSTLineNextValue(line, parsePosition), component->length,
876 component->rotationID))
879 component->rotationID = wxAtoi(GetLSTLineNextValue(line, parsePosition));
882 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&component->position.m_x))
return false;
883 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&component->position.m_y))
return false;
885 component->electricalID = wxAtoi(GetLSTLineNextValue(line, parsePosition));
888 if(component->type !=
ANA_BUS) {
889 int fromBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
893 toBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
896 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
898 if(fromBus == (*it)->electricalID) {
899 component->busConnectionID[0] = std::make_pair((*it)->id, fromBus);
900 }
else if(toBus == (*it)->electricalID) {
901 component->busConnectionID[1] = std::make_pair((*it)->id, toBus);
906 m_components.push_back(component);
910 int parsePosition = 1;
912 PowerLine* pLine =
new PowerLine();
914 pLine->id = wxAtoi(GetLSTLineNextValue(line, parsePosition));
915 pLine->type =
static_cast<ElementTypeAnarede>(wxAtoi(GetLSTLineNextValue(line, parsePosition)));
918 int fromBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
919 int toBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
922 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
924 if(fromBus == (*it)->id) {
925 pLine->busConnectionID[0] = std::make_pair((*it)->id, (*it)->electricalID);
926 }
else if(toBus == (*it)->id) {
927 pLine->busConnectionID[1] = std::make_pair((*it)->id, (*it)->electricalID);
931 pLine->electricalID = wxAtoi(GetLSTLineNextValue(line, parsePosition));
933 m_lines.push_back(pLine);
937 int parsePosition = 1;
939 int id = wxAtoi(GetLSTLineNextValue(line, parsePosition));
942 int data1 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
943 int data2 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
944 int data3 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
945 int data4 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
946 int data5 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
947 int data6 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
953 for(
auto it = m_lines.begin(), itEnd = m_lines.end(); it != itEnd; ++it) {
954 if(data5 == (*it)->id) {
955 (*it)->busConnectionNode[0] = std::make_pair(data1, data2);
956 (*it)->busConnectionNode[1] = std::make_pair(data3, data4);
957 for(
int i = 0; i < data6; ++i) {
958 wxPoint2DDouble nodePt;
959 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&nodePt.m_x))
return false;
960 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&nodePt.m_y))
return false;
961 (*it)->nodesPosition.push_back(nodePt);
967 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
968 if(data1 == (*it)->id) {
972 for(
auto itDiff = m_components.begin(), itDiffEnd = m_components.end();
973 itDiff != itDiffEnd; ++itDiff) {
974 if(data3 == (*itDiff)->id) {
975 (*itDiff)->busConnectionNode[data4 - 1] = std::make_pair(data1, data2);
980 (*it)->busConnectionNode[data2 - 1] = std::make_pair(data3, data4);
994 for(wxString line = pwf.GetFirstLine(); !pwf.Eof(); line = pwf.GetNextLine()) {
997 m_projectName = pwf.GetNextLine().Trim();
998 }
else if(line !=
"") {
999 if(line ==
"FIM")
break;
1000 if(line[0] !=
'(') {
1001 wxString exeCode = line;
1003 for(wxString lineData = pwf.GetNextLine(); lineData !=
"99999" && !pwf.Eof();
1004 lineData = pwf.GetNextLine()) {
1005 if(lineData ==
"FIM")
break;
1006 if(lineData[0] !=
'(') {
1007 data += lineData +
"\n";
1010 if(data !=
"" || data !=
"FIM") {
1011 if(!ParsePWFExeCode(data, exeCode))
return false;
1021wxString ParseAnarede::GetLSTLineNextValue(wxString line,
int& currentPos)
1024 wxString strValue =
"=";
1025 for(; currentPos < static_cast<int>(line.length()); ++currentPos) {
1026 if(line[currentPos] !=
' ') {
1027 wxString parsedLine = line.Mid(currentPos);
1028 strValue = parsedLine.BeforeFirst(
' ');
1029 currentPos += strValue.length();
1036bool ParseAnarede::GetLenghtAndRotationFromBusCode(wxString code,
double& lenght,
int& rotationID)
1040 if(!code.ToLong(&longCode))
return false;
1042 std::stringstream hexCode;
1043 hexCode << std::hex << longCode;
1045 wxString hexCodeStr = hexCode.str();
1047 wxString lenghtStr = hexCodeStr.Left(hexCodeStr.length() - 1);
1050 hexCode << lenghtStr.ToStdString();
1052 hexCode >> std::hex >> intLenght;
1053 lenght =
static_cast<double>(intLenght);
1055 wxString rotationIDStr = hexCodeStr.Right(1);
1057 long rotationIDLong;
1058 if(!rotationIDStr.ToLong(&rotationIDLong))
return false;
1059 rotationID =
static_cast<int>(rotationIDLong);
1061 lenght = 3.0 * lenght - 16.0;
1065wxPoint2DDouble ParseAnarede::GetNodePositionFromID(
Bus* bus,
double scale,
int nodeID)
1067 wxPoint2DDouble nodePt;
1069 double offset = (
static_cast<double>(nodeID) - 1.0) * 16.0;
1070 nodePt = bus->
GetPosition() + wxPoint2DDouble(offset * scale, 0) -
1080 int typeInt = wxAtoi(strType);
1101bool ParseAnarede::ParsePWFExeCode(wxString data, wxString exeCode)
1103 if(exeCode ==
"DCTE") {
1106 wxString value =
"";
1107 for(
unsigned int i = 0; i < data.length(); ++i) {
1108 code = data.Mid(i, 4);
1109 value = data.Mid(i + 5, 6).Trim(
false);
1111 if(code ==
"BASE") {
1112 if(!value.ToCDouble(&m_mvaBase))
return false;
1116 }
else if(exeCode ==
"DBAR") {
1117 wxString lineData =
"";
1120 lineData = data.BeforeFirst(
'\n', &rest);
1122 BusData* busData =
new BusData();
1124 if(!GetPWFStructuredData(lineData, 0, 5, busData->id))
return false;
1125 wxString isOnlineCode = lineData.Mid(6, 1);
1126 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1127 busData->isOnline =
true;
1128 else if(isOnlineCode ==
"D")
1129 busData->isOnline =
false;
1132 if(!GetPWFStructuredData(lineData, 7, 1, busData->type))
return false;
1133 busData->voltageBase = lineData.Mid(8, 2);
1134 busData->busName = lineData.Mid(10, 12).Trim();
1135 if(!GetPWFStructuredData(lineData, 24, 4, busData->voltage, 1))
return false;
1136 if(!GetPWFStructuredData(lineData, 28, 4, busData->angle))
return false;
1138 if(!GetPWFStructuredData(lineData, 32, 5, pg))
return false;
1139 if(!GetPWFStructuredData(lineData, 37, 5, qg))
return false;
1140 busData->genPower = std::complex<double>(pg, qg);
1141 if(!GetPWFStructuredData(lineData, 42, 5, busData->minReactivePower))
return false;
1142 if(!GetPWFStructuredData(lineData, 47, 5, busData->maxReactivePower))
return false;
1143 if(!GetPWFStructuredData(lineData, 52, 6, busData->ctrlBusID))
return false;
1145 if(!GetPWFStructuredData(lineData, 58, 5, pl))
return false;
1146 if(!GetPWFStructuredData(lineData, 63, 5, ql))
return false;
1147 busData->loadPower = std::complex<double>(pl, ql);
1148 if(!GetPWFStructuredData(lineData, 68, 5, busData->shuntReactive))
return false;
1150 m_busData.push_back(busData);
1152 }
else if(exeCode ==
"DLIN") {
1153 wxString lineData =
"";
1156 lineData = data.BeforeFirst(
'\n', &rest);
1158 BranchData* branchData =
new BranchData();
1160 if(!GetPWFStructuredData(lineData, 15, 2, branchData->id))
return false;
1162 if(!GetPWFStructuredData(lineData, 0, 5, from))
return false;
1163 if(!GetPWFStructuredData(lineData, 10, 5, to))
return false;
1164 branchData->busConnections = std::make_pair(from, to);
1166 wxString isOnlineCode = lineData.Mid(6, 1) + lineData.Mid(9, 1) + lineData.Mid(17, 1);
1167 if(isOnlineCode.Find(
'D') == wxNOT_FOUND)
1168 branchData->isOnline =
true;
1170 branchData->isOnline =
false;
1171 if(!GetPWFStructuredData(lineData, 20, 6, branchData->resistance, 4))
return false;
1172 if(!GetPWFStructuredData(lineData, 26, 6, branchData->indReactance, 4))
return false;
1173 if(!GetPWFStructuredData(lineData, 32, 6, branchData->capSusceptance, 4))
return false;
1174 if(!GetPWFStructuredData(lineData, 38, 5, branchData->tap, 2))
return false;
1175 if(!GetPWFStructuredData(lineData, 53, 5, branchData->phaseShift, 3))
return false;
1177 if(branchData->tap < 1e-3)
1182 m_branchData.push_back(branchData);
1184 }
else if(exeCode ==
"DCAI") {
1185 wxString lineData =
"";
1188 lineData = data.BeforeFirst(
'\n', &rest);
1190 IndElementData* indData =
new IndElementData();
1193 if(!GetPWFStructuredData(lineData, 9, 2, indData->id))
return false;
1194 if(!GetPWFStructuredData(lineData, 0, 5, indData->busConnection))
return false;
1196 wxString isOnlineCode = lineData.Mid(13, 1);
1197 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1198 indData->isOnline =
true;
1199 else if(isOnlineCode ==
"D")
1200 indData->isOnline =
false;
1205 if(!GetPWFStructuredData(lineData, 22, 5, pl))
return false;
1206 if(!GetPWFStructuredData(lineData, 28, 5, ql))
return false;
1207 indData->power = std::complex<double>(pl, ql);
1209 if(!GetPWFStructuredData(lineData, 18, 3, indData->numUnits))
return false;
1211 m_indElementData.push_back(indData);
1213 }
else if(exeCode ==
"DGEI") {
1214 wxString lineData =
"";
1217 lineData = data.BeforeFirst(
'\n', &rest);
1219 IndGenData* genData =
new IndGenData();
1222 if(!GetPWFStructuredData(lineData, 9, 2, genData->id))
return false;
1223 if(!GetPWFStructuredData(lineData, 0, 5, genData->busConnection))
return false;
1225 wxString isOnlineCode = lineData.Mid(12, 1);
1226 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1227 genData->isOnline =
true;
1228 else if(isOnlineCode ==
"D")
1229 genData->isOnline =
false;
1234 if(!GetPWFStructuredData(lineData, 22, 5, pg))
return false;
1235 if(!GetPWFStructuredData(lineData, 27, 5, qg))
return false;
1236 genData->power = std::complex<double>(pg, qg);
1238 if(!GetPWFStructuredData(lineData, 16, 3, genData->numUnits))
return false;
1239 if(!GetPWFStructuredData(lineData, 32, 5, genData->minReactivePower))
return false;
1240 if(!GetPWFStructuredData(lineData, 37, 5, genData->maxReactivePower))
return false;
1241 if(!GetPWFStructuredData(lineData, 42, 6, genData->xt, 2))
return false;
1242 if(!GetPWFStructuredData(lineData, 49, 5, genData->xd, 4))
return false;
1243 if(!GetPWFStructuredData(lineData, 54, 5, genData->xq, 4))
return false;
1244 if(!GetPWFStructuredData(lineData, 59, 5, genData->xl, 4))
return false;
1245 if(!GetPWFStructuredData(lineData, 69, 5, genData->ratedPower, 3))
return false;
1247 m_indElementData.push_back(genData);
1249 }
else if(exeCode ==
"DBSH") {
1251 wxString lineData =
"";
1256 lineData = data.BeforeFirst(
'\n', &rest);
1259 if(lineNumber == 1) {
1260 if(!GetPWFStructuredData(lineData, 0, 5, busNumber))
return false;
1261 }
else if(lineData ==
"FBAN") {
1264 }
else if(lineNumber >= 2 && busNumber != -1) {
1265 IndElementData* indShunt =
new IndElementData();
1267 indShunt->busConnection = busNumber;
1269 if(!GetPWFStructuredData(lineData, 0, 2, indShunt->id))
return false;
1271 wxString isOnlineCode = lineData.Mid(6, 1);
1272 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1273 indShunt->isOnline =
true;
1274 else if(isOnlineCode ==
"D")
1275 indShunt->isOnline =
false;
1279 if(!GetPWFStructuredData(lineData, 12, 3, indShunt->numUnits))
return false;
1281 if(!GetPWFStructuredData(lineData, 16, 6, ql))
return false;
1282 indShunt->power = std::complex<double>(0.0, ql);
1283 m_indElementData.push_back(indShunt);
1292bool ParseAnarede::GetPWFStructuredData(wxString data,
1293 unsigned int startPos,
1294 unsigned int dataLenght,
1298 if(data.length() < startPos || data.length() < (startPos + dataLenght)) {
1302 wxString strValue = data.Mid(startPos, dataLenght);
1303 strValue.Replace(
' ',
'0');
1305 if(!strValue.ToLong(&lValue))
return false;
1306 value =
static_cast<int>(lValue);
1310bool ParseAnarede::GetPWFStructuredData(wxString data,
1311 unsigned int startPos,
1312 unsigned int dataLenght,
1316 if(data.length() < startPos || data.length() < (startPos + dataLenght)) {
1320 wxString strValue = data.Mid(startPos, dataLenght);
1321 if(strValue.Find(
'-') == wxNOT_FOUND) strValue.Replace(
' ',
'0');
1322 if(decimalPos != -1 && strValue.Find(
'.') == wxNOT_FOUND) strValue.insert(decimalPos,
'.');
1323 if(!strValue.ToCDouble(&value))
return false;
1329 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1330 if((*it)->id ==
id)
return *it;
1337 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1338 if((*it)->id ==
id && (*it)->busConnections.first == fromBus && (*it)->busConnections.second == toBus &&
1339 (*it)->type == type)
1347 for(
auto it = m_indElementData.begin(), itEnd = m_indElementData.end(); it != itEnd; ++it) {
1348 if((*it)->id ==
id && (*it)->busConnection == busID && (*it)->type == type)
return *it;
1353void ParseAnarede::ClearData()
1355 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
1358 m_components.clear();
1359 for(
auto it = m_lines.begin(), itEnd = m_lines.end(); it != itEnd; ++it) {
1363 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1367 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1370 m_branchData.clear();
1371 for(
auto it = m_indElementData.begin(), itEnd = m_indElementData.end(); it != itEnd; ++it) {
1374 m_indElementData.clear();
1377ParseMatpower::ParseMatpower(wxFileName mFile) { m_mFile = mFile; }
1379void ParseMatpower::ClearData()
1382 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1385 m_branchData.clear();
1386 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1389 m_branchData.clear();
1390 for(
auto it = m_genData.begin(), itEnd = m_genData.end(); it != itEnd; ++it) {
1396bool ParseMatpower::Parse()
1398 wxTextFile mFile(m_mFile.GetFullPath());
1399 if(!mFile.Open())
return false;
1402 wxString fileTxt =
"";
1403 for(wxString line = mFile.GetFirstLine(); !mFile.Eof(); line = mFile.GetNextLine()) {
1405 if(line.Trim()[0] !=
'%') {
1407 if(line.Find(
"mpc.baseMVA") != wxNOT_FOUND) {
1408 if(!line.AfterFirst(
'=').BeforeFirst(
';').ToCDouble(&m_mvaBase))
return false;
1410 if(line.Find(
"mpc.bus ") != wxNOT_FOUND) {
1411 wxStringTokenizer busStrTok = GetMFileTokenData(mFile, line);
1412 while(busStrTok.HasMoreTokens()) {
1413 BusData* busData =
new BusData();
1414 wxString busDataStr = busStrTok.GetNextToken();
1415 char tokenChar =
'\t';
1416 if(busDataStr.Find(
'\t') == wxNOT_FOUND) { tokenChar =
' '; }
1418 wxStringTokenizer busDataStrTok(busDataStr, tokenChar);
1420 busData->id = wxAtoi(busDataStrTok.GetNextToken());
1421 busData->type = wxAtoi(busDataStrTok.GetNextToken());
1422 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->pd))
return false;
1423 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->qd))
return false;
1424 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->gs))
return false;
1425 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->bs))
return false;
1426 busData->area = wxAtoi(busDataStrTok.GetNextToken());
1427 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->voltage))
return false;
1428 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->angle))
return false;
1429 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->baseVoltage))
return false;
1431 m_busData.push_back(busData);
1434 if(line.Find(
"mpc.gen ") != wxNOT_FOUND) {
1435 wxStringTokenizer genStrTok = GetMFileTokenData(mFile, line);
1436 while(genStrTok.HasMoreTokens()) {
1437 GenData* genData =
new GenData();
1438 wxString genDataStr = genStrTok.GetNextToken();
1439 char tokenChar =
'\t';
1440 if(genDataStr.Find(
'\t') == wxNOT_FOUND) { tokenChar =
' '; }
1442 wxStringTokenizer genDataStrTok(genDataStr, tokenChar);
1443 genData->busID = wxAtoi(genDataStrTok.GetNextToken());
1444 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->pg))
return false;
1445 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->qg))
return false;
1446 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->maxReactivePower))
1448 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->minReactivePower))
1450 genDataStrTok.GetNextToken();
1451 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->baseMVA))
return false;
1452 double machineStatus = 0;
1453 if(!genDataStrTok.GetNextToken().ToCDouble(&machineStatus))
1455 genData->isOnline = machineStatus > 1e-3 ? true :
false;
1457 m_genData.push_back(genData);
1460 if(line.Find(
"mpc.branch") != wxNOT_FOUND) {
1461 wxStringTokenizer branchStrTok = GetMFileTokenData(mFile, line);
1462 while(branchStrTok.HasMoreTokens()) {
1463 BranchData* branchData =
new BranchData();
1464 wxString branchDataStr = branchStrTok.GetNextToken();
1465 char tokenChar =
'\t';
1466 if(branchDataStr.Find(
'\t') == wxNOT_FOUND) { tokenChar =
' '; }
1468 wxStringTokenizer branchDataStrTok(branchDataStr, tokenChar);
1470 int fromBus = wxAtoi(branchDataStrTok.GetNextToken());
1471 int toBus = wxAtoi(branchDataStrTok.GetNextToken());
1472 branchData->busConnections = std::make_pair(fromBus, toBus);
1473 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->resistance))
return false;
1474 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->indReactance))
1476 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->capSusceptance))
1478 branchDataStrTok.GetNextToken();
1479 branchDataStrTok.GetNextToken();
1480 branchDataStrTok.GetNextToken();
1481 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->tap))
return false;
1482 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->phaseShift))
1484 double branchStatus = 0;
1485 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchStatus))
1487 branchData->isOnline = branchStatus > 1e-3 ? true :
false;
1489 m_branchData.push_back(branchData);
1492 if(line.Find(
"mpc.bus_name") != wxNOT_FOUND) {
1493 wxString dataStr =
"";
1494 while(line.Find(
'}',
true) == wxNOT_FOUND) {
1496 line = mFile.GetNextLine();
1499 dataStr = dataStr.AfterFirst(
'{').BeforeFirst(
'}');
1500 wxStringTokenizer dataStrTok(dataStr,
";");
1501 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1502 if(dataStrTok.HasMoreTokens())
1503 (*it)->busName = dataStrTok.GetNextToken().AfterFirst(
'\'').BeforeFirst(
'\'');
1513wxStringTokenizer ParseMatpower::GetMFileTokenData(wxTextFile& mFile, wxString currentLine)
1515 wxString dataStr =
"";
1516 while(currentLine.Find(
']',
true) == wxNOT_FOUND) {
1517 dataStr += currentLine;
1518 if(currentLine.Find(
"mpc") == wxNOT_FOUND && currentLine.Find(
';') == wxNOT_FOUND) dataStr +=
';';
1519 currentLine = mFile.GetNextLine();
1521 dataStr += currentLine +
";";
1522 if(currentLine.Find(
';') == wxNOT_FOUND) dataStr +=
';';
1523 dataStr = dataStr.AfterFirst(
'[').BeforeFirst(
']');
1524 wxStringTokenizer dataStrTok(dataStr,
';');
1530 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1531 if((*it)->id ==
id)
return *it;
Node for power elements. All others power elements are connected through this.
virtual void Rotate(bool clockwise=true)
Rotate the element.
Shunt capactior power 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,...
virtual std::vector< Element * > GetParentList() const
Get the parent list.
virtual int GetID() const
Get the element ID.
double GetWidth() const
Get the element width.
wxPoint2DDouble GetPosition() const
Get the element position.
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,...
virtual std::vector< Element * > GetChildList() const
Get the Child list.
double GetAngle() const
Get the element angle.
void SetWidth(double width)
Set element width.
double GetHeight() const
Get the element height.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees=true) const
Rotate a point as element position being the origin.
virtual void SetID(int id)
Set the element ID.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
bool SetOnline(bool online=true)
Set if the element is online or offline.
virtual void Rotate(bool clockwise=true)
Rotate the element.
Induction motor power element.
Inductor shunt power 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,...
virtual void AddPoint(wxPoint2DDouble point)
Add point to the list of points that connect the element to the bus.
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,...
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void MoveNode(Element *parent, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Loas shunt power element.
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,...
Abstract class for rotary machines power elements.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
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,...
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void Rotate(bool clockwise=true)
Rotate the element.
virtual void MoveNode(Element *element, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
Class responsible to parse ANAREDE files to import data to PSP.
Abstract class for shunt power elements.
virtual void MoveNode(Element *element, wxPoint2DDouble position)
Move a node. StartMove(wxPoint2DDouble position) before start moving.
virtual void StartMove(wxPoint2DDouble position)
Update the element attributes related to the movement.
virtual void Move(wxPoint2DDouble position)
Move the element other position.
Synchronous generator power element.
Synchronous motor (synchronous compensator) power element.
This class manages the graphical and power elements. It is responsible for handling the user's intera...
std::complex< double > loadPower
std::complex< double > genPower
std::complex< double > power
std::pair< int, int > busConnections
wxPoint2DDouble busPosition