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));
117 bus->
SetID((*it)->id);
118 bus->
SetWidth((*it)->length * scale);
120 if((*it)->rotationID == 0) {
122 }
else if((*it)->rotationID == 1) {
123 for(
int i = 0; i < (*it)->rotationID * 2; ++i) bus->
Rotate();
125 }
else if((*it)->rotationID == 2) {
126 for(
int i = 0; i < (*it)->rotationID * 2; ++i) bus->
Rotate();
128 }
else if((*it)->rotationID == 3) {
129 for(
int i = 0; i < (*it)->rotationID * 2; ++i) bus->
Rotate();
134 auto data = bus->GetElectricalData();
137 data.number = busData->
id;
139 switch(busData->
type) {
142 data.isVoltageControlled =
false;
143 data.slackBus =
false;
146 data.isVoltageControlled =
true;
147 data.slackBus =
false;
150 data.isVoltageControlled =
true;
151 data.slackBus =
true;
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;
163 bus->SetElectricalData(data);
164 busList.push_back(bus);
169 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
170 wxPoint2DDouble nodePos =
171 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
174 bool isMotor =
false;
175 if(busData->
genPower.real() <= 0.0) isMotor =
true;
181 auto data = syncGenerator->GetElectricalData();
183 wxString::Format(
"%s %u (%s)", _(
"Generator"), syncGeneratorList.size() + 1, busData->
busName);
188 double numUnits =
static_cast<double>(genData->
numUnits);
189 data.activePower = genData->
power.real() * numUnits;
190 data.reactivePower = genData->
power.imag() * 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);
199 data.activePower = busData->
genPower.real();
200 data.reactivePower = busData->
genPower.imag();
203 data.useMachineBase =
false;
206 syncGenerator->SetElectricalData(data);
208 machine = syncGenerator;
212 auto data = syncMotor->GetElectricalData();
213 data.name = wxString::Format(
"%s %u (%s)", _(
"Synchronous compensator"), syncMotorList.size() + 1,
215 data.activePower = busData->
genPower.real() == 0.0 ? 0.0 : -busData->
genPower.real();
216 data.reactivePower = busData->
genPower.imag();
219 data.useMachineBase =
false;
221 syncMotor->SetElectricalData(data);
227 machine->
SetID((*it)->id);
231 machine->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
233 for(
int i = 0; i < 2; ++i) machine->
Rotate(
false);
234 for(
int i = 0; i < (*it)->rotationID * 2; ++i) machine->
Rotate();
237 syncGeneratorList.push_back(
static_cast<SyncGenerator*
>(machine));
239 syncMotorList.push_back(
static_cast<SyncMotor*
>(machine));
244 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
245 wxPoint2DDouble nodePos =
246 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
251 load->
SetID((*it)->id);
255 load->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
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);
263 for(
int i = 0; i < (*it)->rotationID * 2; ++i) load->
Rotate();
265 loadList.push_back(load);
269 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
270 wxPoint2DDouble nodePos =
271 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
274 bool isInductor =
false;
275 Shunt* shuntElement =
nullptr;
280 (*it)->electricalID, (*it)->busConnectionID[0].second,
ANA_IND_SHUNT);
282 double numUnits =
static_cast<double>(shuntData->
numUnits);
283 ql = shuntData->
power.imag() * numUnits;
288 if(ql <= 0.0) isInductor =
true;
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);
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);
307 shuntElement->
SetID((*it)->id);
308 shuntElement->
AddParent(parentBus, nodePos);
312 shuntElement->
Move(wxPoint2DDouble(
313 (*it)->position.m_x * scale, (*it)->position.m_y * scale + shuntElement->
GetHeight() / 2 + 10));
314 if((*it)->rotationID != 0) {
316 shuntElement->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
320 (*it)->rotationID * 90.0,
true);
321 shuntElement->
Move(movePt);
323 for(
int i = 0; i < (*it)->rotationID * 2; ++i) shuntElement->
Rotate();
327 capList.push_back(
static_cast<Capacitor*
>(shuntElement));
329 indList.push_back(
static_cast<Inductor*
>(shuntElement));
334 Bus* parentBus = GetBusFromID(busList, (*it)->busConnectionID[0].first);
335 wxPoint2DDouble nodePos =
336 parseAnarede.GetNodePositionFromID(parentBus, scale, (*it)->busConnectionNode[0].second);
339 indMotor->
SetID((*it)->id);
343 indMotor->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
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);
352 for(
int i = 0; i < 2; ++i) indMotor->
Rotate(
false);
353 for(
int i = 0; i < (*it)->rotationID * 2; ++i) indMotor->
Rotate();
355 indMotorList.push_back(indMotor);
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);
366 parseAnarede.GetBranchDataFromID((*it)->electricalID, (*it)->busConnectionID[0].second,
370 transformer->
SetID((*it)->id);
371 transformer->
AddParent(parentBus1, nodePos1);
372 transformer->
AddParent(parentBus2, nodePos2);
375 transformer->
Move(wxPoint2DDouble((*it)->position.m_x * scale, (*it)->position.m_y * scale));
377 for(
int i = 0; i < 2; ++i) transformer->
Rotate();
378 for(
int i = 0; i < (*it)->rotationID * 2; ++i) transformer->
Rotate();
380 auto data = transformer->GetElectricalData();
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;
386 data.turnsRatio = branchData->
tap;
388 transformer->SetElectricaData(data);
390 transformerList.push_back(transformer);
397 auto powerLines = parseAnarede.GetLines();
398 for(
auto it = powerLines.begin(), itEnd = powerLines.end(); it != itEnd; ++it) {
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);
408 (*it)->electricalID, (*it)->busConnectionID[0].second, (*it)->busConnectionID[1].second,
ANA_LINE);
411 line->
SetID((*it)->id);
413 for(
unsigned int i = 0; i < (*it)->nodesPosition.size(); ++i)
415 wxPoint2DDouble((*it)->nodesPosition[i].m_x * scale, (*it)->nodesPosition[i].m_y * scale));
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;
424 line->SetElectricalData(data);
426 lineList.push_back(line);
431 std::vector<ParseAnarede::BusData*> busDataVector = parseAnarede.GetBusData();
432 for(
auto it = busDataVector.begin(), itEnd = busDataVector.end(); it != itEnd; ++it) {
437 for(
auto itB = busList.begin(), itBEnd = busList.end(); itB != itBEnd; ++itB) {
438 if((*itB)->GetElectricalData().number == busData->
id) {
445 if(std::abs(busData->
loadPower.real()) > 1e-5 ||
446 std::abs(busData->
loadPower.imag()) > 1e-5) {
448 Load* load =
nullptr;
449 for(
auto itL = loadList.begin(), itLEnd = loadList.end(); itL != itLEnd; ++itL) {
450 if((*itL)->GetParentList().size() > 0) {
451 if((*itL)->GetParentList()[0] == bus) {
459 new Load(wxString::Format(
"%s %u (%s)", _(
"Load"), loadList.size() + 1, busData->
busName));
461 auto data = newLoad->GetElectricalData();
462 data.activePower = busData->
loadPower.real();
463 data.reactivePower = busData->
loadPower.imag();
464 newLoad->SetElectricalData(data);
466 loadList.push_back(newLoad);
470 if(std::abs(busData->
genPower.real()) > 1e-5 || std::abs(busData->
genPower.imag()) > 1e-5) {
472 if(busData->
genPower.real() > 0.0) {
474 for(
auto itSM = syncGeneratorList.begin(), itSMEnd = syncGeneratorList.end(); itSM != itSMEnd;
476 if((*itSM)->GetParentList().size() > 0) {
477 if((*itSM)->GetParentList()[0] == bus) {
478 syncGenerator = *itSM;
485 "%s %u (%s)", _(
"Generator"), syncGeneratorList.size() + 1, busData->
busName));
487 auto data = newSyncGenerator->GetElectricalData();
488 data.activePower = busData->
genPower.real();
489 data.reactivePower = busData->
genPower.imag();
490 newSyncGenerator->SetElectricalData(data);
492 syncGeneratorList.push_back(newSyncGenerator);
496 for(
auto itSM = syncMotorList.begin(), itSMEnd = syncMotorList.end(); itSM != itSMEnd; ++itSM) {
497 if((*itSM)->GetParentList().size() > 0) {
498 if((*itSM)->GetParentList()[0] == bus) {
506 "%s %u (%s)", _(
"Synchronous compensator"), syncMotorList.size() + 1, busData->
busName));
508 auto data = newSyncMotor->GetElectricalData();
509 data.activePower = std::abs(busData->
genPower.real());
510 data.reactivePower = busData->
genPower.imag();
511 newSyncMotor->SetElectricalData(data);
513 syncMotorList.push_back(newSyncMotor);
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);
532 m_workspace->SetElementList(elementList);
533 m_workspace->SetName(parseAnarede.GetProjectName());
537bool ImportForm::ImportMatpowerFiles()
539 ParseMatpower parseMatpower(m_filePickerMatpowerM->GetFileName());
540 if(!parseMatpower.Parse())
return false;
542 double mvaBasePower = parseMatpower.GetMVAPowerBase();
543 auto simProp = m_workspace->GetProperties()->GetSimulationPropertiesData();
544 simProp.basePower = mvaBasePower;
545 m_workspace->GetProperties()->SetSimulationPropertiesData(simProp);
547 std::vector<Element*> elementList;
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;
559 int iterations = wxAtoi(m_textCtrlIterations->GetValue());
561 if(!m_textCtrlScale->GetValue().ToDouble(&scale))
return false;
564 GraphAutoLayout gal(parseMatpower.GetBusData(), parseMatpower.GetBranchData());
565 gal.CalculatePositions(iterations, scale);
568 auto busDataList = parseMatpower.GetBusData();
569 for(
auto it = busDataList.begin(), itEnd = busDataList.end(); it != itEnd; ++it) {
573 bus->
SetID((*it)->id);
576 auto data = bus->GetElectricalData();
578 data.number = busData->
id;
580 switch(busData->
type) {
582 data.isVoltageControlled =
true;
583 data.slackBus =
true;
586 data.isVoltageControlled =
false;
587 data.slackBus =
false;
590 data.isVoltageControlled =
true;
591 data.slackBus =
false;
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;
605 bus->SetElectricalData(data);
606 busList.push_back(bus);
609 auto branchDataList = parseMatpower.GetBranchData();
611 int transformerID = 0;
612 for(
auto it = branchDataList.begin(), itEnd = branchDataList.end(); it != itEnd; ++it) {
616 if(branchData->
tap > 1e-3) {
618 transformer->
SetID(transformerID);
622 auto data = transformer->GetElectricalData();
625 data.turnsRatio = branchData->
tap;
628 wxString::Format(
"%s %u (%s - %s)", _(
"Transfomer"), transformerList.size() + 1,
629 fstParentBus->GetElectricalData().name, sndParentBus->GetElectricalData().name);
631 transformer->SetElectricaData(data);
635 transformerList.push_back(transformer);
643 auto data = line->GetElectricalData();
648 wxString::Format(
"%s %u (%s - %s)", _(
"Line"), lineList.size() + 1,
649 fstParentBus->GetElectricalData().name, sndParentBus->GetElectricalData().name);
651 line->SetElectricalData(data);
655 lineList.push_back(line);
661 auto genDataList = parseMatpower.GetGenData();
663 for(
auto it = genDataList.begin(), itEnd = genDataList.end(); it != itEnd; ++it) {
666 generator->
SetID(genID);
668 Bus* parentBus = GetBusFromID(busList, (*it)->busID);
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;
678 data.nominalPower = genData->
baseMVA;
679 generator->SetElectricalData(data);
681 syncGeneratorList.push_back(generator);
687 for(
auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
690 if(busData->
pd > 1e-3 || busData->
qd > 1e-3) {
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);
702 loadList.push_back(load);
704 if(std::abs(busData->
gs) > 1e-3) {
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);
717 loadList.push_back(load);
718 }
else if(std::abs(busData->
bs) > 1e-3) {
720 if(busData->
bs < 1e-3) {
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);
731 indList.push_back(inductor);
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);
743 capList.push_back(capacitor);
749 for(
auto it = syncGeneratorList.begin(), itEnd = syncGeneratorList.end(); it != itEnd; ++it) {
754 generator->
GetParentList()[0]->GetPosition() - wxPoint2DDouble(140, 0));
755 generator->
Move(generator->
GetParentList()[0]->GetPosition() - wxPoint2DDouble(40, 100));
761 for(
auto it = loadList.begin(), itEnd = loadList.end(); it != itEnd; ++it) {
770 for(
auto it = capList.begin(), itEnd = capList.end(); it != itEnd; ++it) {
773 capacitor->
StartMove(wxPoint2DDouble(0, 0));
775 wxPoint2DDouble(capacitor->
GetParentList()[0]->GetWidth() / 2 - 20, 0));
776 capacitor->
Move(wxPoint2DDouble(capacitor->
GetParentList()[0]->GetWidth() / 2 - 20, 0));
780 for(
auto it = indList.begin(), itEnd = indList.end(); it != itEnd; ++it) {
783 inductor->
StartMove(wxPoint2DDouble(0, 0));
785 wxPoint2DDouble(inductor->
GetParentList()[0]->GetWidth() / 2 - 10, 0));
786 inductor->
Move(wxPoint2DDouble(inductor->
GetParentList()[0]->GetWidth() / 2 + 10, 0));
790 for(
auto it = busList.begin(), itEnd = busList.end(); it != itEnd; ++it) {
792 int numberOfConnectedBranches = 0;
793 std::vector<Line*> linesConnected;
794 std::vector<Transformer*> transformersConnected;
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++;
802 transformersConnected.push_back(transformer);
803 numberOfConnectedBranches++;
813 if(numberOfConnectedBranches > 0) {
814 double dx = (bus->
GetWidth() - 30) / (
static_cast<double>(numberOfConnectedBranches + 1));
816 for(
unsigned int i = 0; i < linesConnected.size(); ++i) {
817 Line* lineToMove = linesConnected[i];
819 wxPoint2DDouble newPos(dx *
static_cast<double>(i + 1), 0);
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);
829 trafoToMove->SetBestPositionAndRotation();
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);
845 m_workspace->SetElementList(elementList);
850ParseAnarede::ParseAnarede(wxFileName lstFile, wxFileName pwfFile)
856bool ParseAnarede::Parse()
858 wxTextFile lst(m_lstFile.GetFullPath());
859 wxTextFile pwf(m_pwfFile.GetFullPath());
860 if(!lst.Open())
return false;
861 if(!pwf.Open())
return false;
864 for(wxString line = lst.GetFirstLine(); !lst.Eof(); line = lst.GetNextLine()) {
866 switch(
static_cast<char>(line[0])) {
868 int parsePosition = 1;
870 Component* component =
new Component();
872 component->id = wxAtoi(GetLSTLineNextValue(line, parsePosition));
874 if(StrToElementType(GetLSTLineNextValue(line, parsePosition), component->type)) {
875 if(component->type ==
ANA_BUS) {
876 if(!GetLenghtAndRotationFromBusCode(GetLSTLineNextValue(line, parsePosition), component->length,
877 component->rotationID))
880 component->rotationID = wxAtoi(GetLSTLineNextValue(line, parsePosition));
883 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&component->position.m_x))
return false;
884 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&component->position.m_y))
return false;
886 component->electricalID = wxAtoi(GetLSTLineNextValue(line, parsePosition));
889 if(component->type !=
ANA_BUS) {
890 int fromBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
894 toBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
897 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
899 if(fromBus == (*it)->electricalID) {
900 component->busConnectionID[0] = std::make_pair((*it)->id, fromBus);
901 }
else if(toBus == (*it)->electricalID) {
902 component->busConnectionID[1] = std::make_pair((*it)->id, toBus);
907 m_components.push_back(component);
911 int parsePosition = 1;
913 PowerLine* pLine =
new PowerLine();
915 pLine->id = wxAtoi(GetLSTLineNextValue(line, parsePosition));
916 pLine->type =
static_cast<ElementTypeAnarede>(wxAtoi(GetLSTLineNextValue(line, parsePosition)));
919 int fromBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
920 int toBus = wxAtoi(GetLSTLineNextValue(line, parsePosition));
923 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
925 if(fromBus == (*it)->id) {
926 pLine->busConnectionID[0] = std::make_pair((*it)->id, (*it)->electricalID);
927 }
else if(toBus == (*it)->id) {
928 pLine->busConnectionID[1] = std::make_pair((*it)->id, (*it)->electricalID);
932 pLine->electricalID = wxAtoi(GetLSTLineNextValue(line, parsePosition));
934 m_lines.push_back(pLine);
938 int parsePosition = 1;
940 int id = wxAtoi(GetLSTLineNextValue(line, parsePosition));
943 int data1 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
944 int data2 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
945 int data3 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
946 int data4 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
947 int data5 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
948 int data6 = wxAtoi(GetLSTLineNextValue(line, parsePosition));
954 for(
auto it = m_lines.begin(), itEnd = m_lines.end(); it != itEnd; ++it) {
955 if(data5 == (*it)->id) {
956 (*it)->busConnectionNode[0] = std::make_pair(data1, data2);
957 (*it)->busConnectionNode[1] = std::make_pair(data3, data4);
958 for(
int i = 0; i < data6; ++i) {
959 wxPoint2DDouble nodePt;
960 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&nodePt.m_x))
return false;
961 if(!GetLSTLineNextValue(line, parsePosition).ToCDouble(&nodePt.m_y))
return false;
962 (*it)->nodesPosition.push_back(nodePt);
968 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
969 if(data1 == (*it)->id) {
973 for(
auto itDiff = m_components.begin(), itDiffEnd = m_components.end();
974 itDiff != itDiffEnd; ++itDiff) {
975 if(data3 == (*itDiff)->id) {
976 (*itDiff)->busConnectionNode[data4 - 1] = std::make_pair(data1, data2);
981 (*it)->busConnectionNode[data2 - 1] = std::make_pair(data3, data4);
995 for(wxString line = pwf.GetFirstLine(); !pwf.Eof(); line = pwf.GetNextLine()) {
998 m_projectName = pwf.GetNextLine().Trim();
999 }
else if(line !=
"") {
1000 if(line ==
"FIM")
break;
1001 if(line[0] !=
'(') {
1002 wxString exeCode = line;
1004 for(wxString lineData = pwf.GetNextLine(); lineData !=
"99999" && !pwf.Eof();
1005 lineData = pwf.GetNextLine()) {
1006 if(lineData ==
"FIM")
break;
1007 if(lineData[0] !=
'(') {
1008 data += lineData +
"\n";
1011 if(data !=
"" || data !=
"FIM") {
1012 if(!ParsePWFExeCode(data, exeCode))
return false;
1022wxString ParseAnarede::GetLSTLineNextValue(wxString line,
int& currentPos)
1025 wxString strValue =
"=";
1026 for(; currentPos < static_cast<int>(line.length()); ++currentPos) {
1027 if(line[currentPos] !=
' ') {
1028 wxString parsedLine = line.Mid(currentPos);
1029 strValue = parsedLine.BeforeFirst(
' ');
1030 currentPos += strValue.length();
1037bool ParseAnarede::GetLenghtAndRotationFromBusCode(wxString code,
double& lenght,
int& rotationID)
1041 if(!code.ToLong(&longCode))
return false;
1043 std::stringstream hexCode;
1044 hexCode << std::hex << longCode;
1046 wxString hexCodeStr = hexCode.str();
1048 wxString lenghtStr = hexCodeStr.Left(hexCodeStr.length() - 1);
1051 hexCode << lenghtStr.ToStdString();
1053 hexCode >> std::hex >> intLenght;
1054 lenght =
static_cast<double>(intLenght);
1056 wxString rotationIDStr = hexCodeStr.Right(1);
1058 long rotationIDLong;
1059 if(!rotationIDStr.ToLong(&rotationIDLong))
return false;
1060 rotationID =
static_cast<int>(rotationIDLong);
1062 lenght = 3.0 * lenght - 16.0;
1066wxPoint2DDouble ParseAnarede::GetNodePositionFromID(
Bus* bus,
double scale,
int nodeID)
1068 wxPoint2DDouble nodePt;
1070 double offset = (
static_cast<double>(nodeID) - 1.0) * 16.0;
1071 nodePt = bus->
GetPosition() + wxPoint2DDouble(offset * scale, 0) -
1081 int typeInt = wxAtoi(strType);
1102bool ParseAnarede::ParsePWFExeCode(wxString data, wxString exeCode)
1104 if(exeCode ==
"DCTE") {
1107 wxString value =
"";
1108 for(
unsigned int i = 0; i < data.length(); ++i) {
1109 code = data.Mid(i, 4);
1110 value = data.Mid(i + 5, 6).Trim(
false);
1112 if(code ==
"BASE") {
1113 if(!value.ToCDouble(&m_mvaBase))
return false;
1117 }
else if(exeCode ==
"DBAR") {
1118 wxString lineData =
"";
1121 lineData = data.BeforeFirst(
'\n', &rest);
1123 BusData* busData =
new BusData();
1125 if(!GetPWFStructuredData(lineData, 0, 5, busData->id))
return false;
1126 wxString isOnlineCode = lineData.Mid(6, 1);
1127 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1128 busData->isOnline =
true;
1129 else if(isOnlineCode ==
"D")
1130 busData->isOnline =
false;
1133 if(!GetPWFStructuredData(lineData, 7, 1, busData->type))
return false;
1134 busData->voltageBase = lineData.Mid(8, 2);
1135 busData->busName = lineData.Mid(10, 12).Trim();
1136 if(!GetPWFStructuredData(lineData, 24, 4, busData->voltage, 1))
return false;
1137 if(!GetPWFStructuredData(lineData, 28, 4, busData->angle))
return false;
1139 if(!GetPWFStructuredData(lineData, 32, 5, pg))
return false;
1140 if(!GetPWFStructuredData(lineData, 37, 5, qg))
return false;
1141 busData->genPower = std::complex<double>(pg, qg);
1142 if(!GetPWFStructuredData(lineData, 42, 5, busData->minReactivePower))
return false;
1143 if(!GetPWFStructuredData(lineData, 47, 5, busData->maxReactivePower))
return false;
1144 if(!GetPWFStructuredData(lineData, 52, 6, busData->ctrlBusID))
return false;
1146 if(!GetPWFStructuredData(lineData, 58, 5, pl))
return false;
1147 if(!GetPWFStructuredData(lineData, 63, 5, ql))
return false;
1148 busData->loadPower = std::complex<double>(pl, ql);
1149 if(!GetPWFStructuredData(lineData, 68, 5, busData->shuntReactive))
return false;
1151 m_busData.push_back(busData);
1153 }
else if(exeCode ==
"DLIN") {
1154 wxString lineData =
"";
1157 lineData = data.BeforeFirst(
'\n', &rest);
1159 BranchData* branchData =
new BranchData();
1161 if(!GetPWFStructuredData(lineData, 15, 2, branchData->id))
return false;
1163 if(!GetPWFStructuredData(lineData, 0, 5, from))
return false;
1164 if(!GetPWFStructuredData(lineData, 10, 5, to))
return false;
1165 branchData->busConnections = std::make_pair(from, to);
1167 wxString isOnlineCode = lineData.Mid(6, 1) + lineData.Mid(9, 1) + lineData.Mid(17, 1);
1168 if(isOnlineCode.Find(
'D') == wxNOT_FOUND)
1169 branchData->isOnline =
true;
1171 branchData->isOnline =
false;
1172 if(!GetPWFStructuredData(lineData, 20, 6, branchData->resistance, 4))
return false;
1173 if(!GetPWFStructuredData(lineData, 26, 6, branchData->indReactance, 4))
return false;
1174 if(!GetPWFStructuredData(lineData, 32, 6, branchData->capSusceptance, 4))
return false;
1175 if(!GetPWFStructuredData(lineData, 38, 5, branchData->tap, 2))
return false;
1176 if(!GetPWFStructuredData(lineData, 53, 5, branchData->phaseShift, 3))
return false;
1178 if(branchData->tap < 1e-3)
1183 m_branchData.push_back(branchData);
1185 }
else if(exeCode ==
"DCAI") {
1186 wxString lineData =
"";
1189 lineData = data.BeforeFirst(
'\n', &rest);
1191 IndElementData* indData =
new IndElementData();
1194 if(!GetPWFStructuredData(lineData, 9, 2, indData->id))
return false;
1195 if(!GetPWFStructuredData(lineData, 0, 5, indData->busConnection))
return false;
1197 wxString isOnlineCode = lineData.Mid(13, 1);
1198 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1199 indData->isOnline =
true;
1200 else if(isOnlineCode ==
"D")
1201 indData->isOnline =
false;
1206 if(!GetPWFStructuredData(lineData, 22, 5, pl))
return false;
1207 if(!GetPWFStructuredData(lineData, 28, 5, ql))
return false;
1208 indData->power = std::complex<double>(pl, ql);
1210 if(!GetPWFStructuredData(lineData, 18, 3, indData->numUnits))
return false;
1212 m_indElementData.push_back(indData);
1214 }
else if(exeCode ==
"DGEI") {
1215 wxString lineData =
"";
1218 lineData = data.BeforeFirst(
'\n', &rest);
1220 IndGenData* genData =
new IndGenData();
1223 if(!GetPWFStructuredData(lineData, 9, 2, genData->id))
return false;
1224 if(!GetPWFStructuredData(lineData, 0, 5, genData->busConnection))
return false;
1226 wxString isOnlineCode = lineData.Mid(12, 1);
1227 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1228 genData->isOnline =
true;
1229 else if(isOnlineCode ==
"D")
1230 genData->isOnline =
false;
1235 if(!GetPWFStructuredData(lineData, 22, 5, pg))
return false;
1236 if(!GetPWFStructuredData(lineData, 27, 5, qg))
return false;
1237 genData->power = std::complex<double>(pg, qg);
1239 if(!GetPWFStructuredData(lineData, 16, 3, genData->numUnits))
return false;
1240 if(!GetPWFStructuredData(lineData, 32, 5, genData->minReactivePower))
return false;
1241 if(!GetPWFStructuredData(lineData, 37, 5, genData->maxReactivePower))
return false;
1242 if(!GetPWFStructuredData(lineData, 42, 6, genData->xt, 2))
return false;
1243 if(!GetPWFStructuredData(lineData, 49, 5, genData->xd, 4))
return false;
1244 if(!GetPWFStructuredData(lineData, 54, 5, genData->xq, 4))
return false;
1245 if(!GetPWFStructuredData(lineData, 59, 5, genData->xl, 4))
return false;
1246 if(!GetPWFStructuredData(lineData, 69, 5, genData->ratedPower, 3))
return false;
1248 m_indElementData.push_back(genData);
1250 }
else if(exeCode ==
"DBSH") {
1252 wxString lineData =
"";
1257 lineData = data.BeforeFirst(
'\n', &rest);
1260 if(lineNumber == 1) {
1261 if(!GetPWFStructuredData(lineData, 0, 5, busNumber))
return false;
1262 }
else if(lineData ==
"FBAN") {
1265 }
else if(lineNumber >= 2 && busNumber != -1) {
1266 IndElementData* indShunt =
new IndElementData();
1268 indShunt->busConnection = busNumber;
1270 if(!GetPWFStructuredData(lineData, 0, 2, indShunt->id))
return false;
1272 wxString isOnlineCode = lineData.Mid(6, 1);
1273 if(isOnlineCode ==
"L" || isOnlineCode ==
" ")
1274 indShunt->isOnline =
true;
1275 else if(isOnlineCode ==
"D")
1276 indShunt->isOnline =
false;
1280 if(!GetPWFStructuredData(lineData, 12, 3, indShunt->numUnits))
return false;
1282 if(!GetPWFStructuredData(lineData, 16, 6, ql))
return false;
1283 indShunt->power = std::complex<double>(0.0, ql);
1284 m_indElementData.push_back(indShunt);
1293bool ParseAnarede::GetPWFStructuredData(wxString data,
1294 unsigned int startPos,
1295 unsigned int dataLenght,
1299 if(data.length() < startPos || data.length() < (startPos + dataLenght)) {
1303 wxString strValue = data.Mid(startPos, dataLenght);
1304 strValue.Replace(
' ',
'0');
1306 if(!strValue.ToLong(&lValue))
return false;
1307 value =
static_cast<int>(lValue);
1311bool ParseAnarede::GetPWFStructuredData(wxString data,
1312 unsigned int startPos,
1313 unsigned int dataLenght,
1317 if(data.length() < startPos || data.length() < (startPos + dataLenght)) {
1321 wxString strValue = data.Mid(startPos, dataLenght);
1322 if(strValue.Find(
'-') == wxNOT_FOUND) strValue.Replace(
' ',
'0');
1323 if(decimalPos != -1 && strValue.Find(
'.') == wxNOT_FOUND) strValue.insert(decimalPos,
'.');
1324 if(!strValue.ToCDouble(&value))
return false;
1330 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1331 if((*it)->id ==
id)
return *it;
1338 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1339 if((*it)->id ==
id && (*it)->busConnections.first == fromBus && (*it)->busConnections.second == toBus &&
1340 (*it)->type == type)
1348 for(
auto it = m_indElementData.begin(), itEnd = m_indElementData.end(); it != itEnd; ++it) {
1349 if((*it)->id ==
id && (*it)->busConnection == busID && (*it)->type == type)
return *it;
1354void ParseAnarede::ClearData()
1356 for(
auto it = m_components.begin(), itEnd = m_components.end(); it != itEnd; ++it) {
1359 m_components.clear();
1360 for(
auto it = m_lines.begin(), itEnd = m_lines.end(); it != itEnd; ++it) {
1364 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1368 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1371 m_branchData.clear();
1372 for(
auto it = m_indElementData.begin(), itEnd = m_indElementData.end(); it != itEnd; ++it) {
1375 m_indElementData.clear();
1378ParseMatpower::ParseMatpower(wxFileName mFile) { m_mFile = mFile; }
1380void ParseMatpower::ClearData()
1383 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1386 m_branchData.clear();
1387 for(
auto it = m_branchData.begin(), itEnd = m_branchData.end(); it != itEnd; ++it) {
1390 m_branchData.clear();
1391 for(
auto it = m_genData.begin(), itEnd = m_genData.end(); it != itEnd; ++it) {
1397bool ParseMatpower::Parse()
1399 wxTextFile mFile(m_mFile.GetFullPath());
1400 if(!mFile.Open())
return false;
1403 wxString fileTxt =
"";
1404 for(wxString line = mFile.GetFirstLine(); !mFile.Eof(); line = mFile.GetNextLine()) {
1406 if(line.Trim()[0] !=
'%') {
1408 if(line.Find(
"mpc.baseMVA") != wxNOT_FOUND) {
1409 if(!line.AfterFirst(
'=').BeforeFirst(
';').ToCDouble(&m_mvaBase))
return false;
1411 if(line.Find(
"mpc.bus ") != wxNOT_FOUND) {
1412 wxStringTokenizer busStrTok = GetMFileTokenData(mFile, line);
1413 while(busStrTok.HasMoreTokens()) {
1414 BusData* busData =
new BusData();
1415 wxString busDataStr = busStrTok.GetNextToken();
1416 char tokenChar =
'\t';
1417 if(busDataStr.Find(
'\t') == wxNOT_FOUND) { tokenChar =
' '; }
1419 wxStringTokenizer busDataStrTok(busDataStr, tokenChar);
1421 busData->id = wxAtoi(busDataStrTok.GetNextToken());
1422 busData->type = wxAtoi(busDataStrTok.GetNextToken());
1423 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->pd))
return false;
1424 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->qd))
return false;
1425 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->gs))
return false;
1426 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->bs))
return false;
1427 busData->area = wxAtoi(busDataStrTok.GetNextToken());
1428 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->voltage))
return false;
1429 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->angle))
return false;
1430 if(!busDataStrTok.GetNextToken().ToCDouble(&busData->baseVoltage))
return false;
1432 m_busData.push_back(busData);
1435 if(line.Find(
"mpc.gen ") != wxNOT_FOUND) {
1436 wxStringTokenizer genStrTok = GetMFileTokenData(mFile, line);
1437 while(genStrTok.HasMoreTokens()) {
1438 GenData* genData =
new GenData();
1439 wxString genDataStr = genStrTok.GetNextToken();
1440 char tokenChar =
'\t';
1441 if(genDataStr.Find(
'\t') == wxNOT_FOUND) { tokenChar =
' '; }
1443 wxStringTokenizer genDataStrTok(genDataStr, tokenChar);
1444 genData->busID = wxAtoi(genDataStrTok.GetNextToken());
1445 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->pg))
return false;
1446 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->qg))
return false;
1447 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->maxReactivePower))
1449 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->minReactivePower))
1451 genDataStrTok.GetNextToken();
1452 if(!genDataStrTok.GetNextToken().ToCDouble(&genData->baseMVA))
return false;
1453 double machineStatus = 0;
1454 if(!genDataStrTok.GetNextToken().ToCDouble(&machineStatus))
1456 genData->isOnline = machineStatus > 1e-3 ? true :
false;
1458 m_genData.push_back(genData);
1461 if(line.Find(
"mpc.branch") != wxNOT_FOUND) {
1462 wxStringTokenizer branchStrTok = GetMFileTokenData(mFile, line);
1463 while(branchStrTok.HasMoreTokens()) {
1464 BranchData* branchData =
new BranchData();
1465 wxString branchDataStr = branchStrTok.GetNextToken();
1466 char tokenChar =
'\t';
1467 if(branchDataStr.Find(
'\t') == wxNOT_FOUND) { tokenChar =
' '; }
1469 wxStringTokenizer branchDataStrTok(branchDataStr, tokenChar);
1471 int fromBus = wxAtoi(branchDataStrTok.GetNextToken());
1472 int toBus = wxAtoi(branchDataStrTok.GetNextToken());
1473 branchData->busConnections = std::make_pair(fromBus, toBus);
1474 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->resistance))
return false;
1475 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->indReactance))
1477 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->capSusceptance))
1479 branchDataStrTok.GetNextToken();
1480 branchDataStrTok.GetNextToken();
1481 branchDataStrTok.GetNextToken();
1482 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->tap))
return false;
1483 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchData->phaseShift))
1485 double branchStatus = 0;
1486 if(!branchDataStrTok.GetNextToken().ToCDouble(&branchStatus))
1488 branchData->isOnline = branchStatus > 1e-3 ? true :
false;
1490 m_branchData.push_back(branchData);
1493 if(line.Find(
"mpc.bus_name") != wxNOT_FOUND) {
1494 wxString dataStr =
"";
1495 while(line.Find(
'}',
true) == wxNOT_FOUND) {
1497 line = mFile.GetNextLine();
1500 dataStr = dataStr.AfterFirst(
'{').BeforeFirst(
'}');
1501 wxStringTokenizer dataStrTok(dataStr,
";");
1502 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1503 if(dataStrTok.HasMoreTokens())
1504 (*it)->busName = dataStrTok.GetNextToken().AfterFirst(
'\'').BeforeFirst(
'\'');
1514wxStringTokenizer ParseMatpower::GetMFileTokenData(wxTextFile& mFile, wxString currentLine)
1516 wxString dataStr =
"";
1517 while(currentLine.Find(
']',
true) == wxNOT_FOUND) {
1518 dataStr += currentLine;
1519 if(currentLine.Find(
"mpc") == wxNOT_FOUND && currentLine.Find(
';') == wxNOT_FOUND) dataStr +=
';';
1520 currentLine = mFile.GetNextLine();
1522 dataStr += currentLine +
";";
1523 if(currentLine.Find(
';') == wxNOT_FOUND) dataStr +=
';';
1524 dataStr = dataStr.AfterFirst(
'[').BeforeFirst(
']');
1525 wxStringTokenizer dataStrTok(dataStr,
';');
1531 for(
auto it = m_busData.begin(), itEnd = m_busData.end(); it != itEnd; ++it) {
1532 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.
void SetInserted(bool inserted=true)
Set if the element is properly inserted in the workspace.
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