From 7aed88dbcf9d37a1f40c8cad115f055c4d69e7a9 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Thu, 29 Dec 2016 19:03:16 -0200 Subject: Parent/child optimization implemented And others bugfixes. --- .codelite/.tern-port | 2 +- .codelite/PSP.session | 44 ++--- .codelite/PSP.tags | Bin 79133696 -> 79142912 bytes .codelite/compilation.db | Bin 65536 -> 65536 bytes .codelite/refactoring.db | Bin 2988032 -> 2988032 bytes Buglist.txt | 7 +- Project/Branch.cpp | 236 ++++++++++++------------- Project/Capacitor.cpp | 1 + Project/ElectricCalculation.cpp | 28 +-- Project/Element.cpp | 17 ++ Project/Element.h | 8 + Project/Inductor.cpp | 1 + Project/Line.cpp | 17 +- Project/Load.cpp | 1 + Project/Machines.cpp | 9 +- Project/Release/Branch.cpp.o | Bin 36478 -> 38491 bytes Project/Release/Bus.cpp.o | Bin 51482 -> 53553 bytes Project/Release/BusForm.cpp.o | Bin 119004 -> 119004 bytes Project/Release/Capacitor.cpp.o | Bin 51864 -> 53887 bytes Project/Release/ElectricCalculation.cpp.o | Bin 74373 -> 74659 bytes Project/Release/Element.cpp.o | Bin 161826 -> 165690 bytes Project/Release/FileHanding.cpp.o | Bin 197048 -> 197260 bytes Project/Release/GeneratorStabForm.cpp.o | Bin 104202 -> 104202 bytes Project/Release/IndMotor.cpp.o | Bin 44699 -> 46722 bytes Project/Release/IndMotorForm.cpp.o | Bin 87116 -> 87116 bytes Project/Release/Inductor.cpp.o | Bin 51732 -> 53771 bytes Project/Release/Line.cpp.o | Bin 170313 -> 172448 bytes Project/Release/LineForm.cpp.o | Bin 101112 -> 101112 bytes Project/Release/Load.cpp.o | Bin 50527 -> 52598 bytes Project/Release/LoadForm.cpp.o | Bin 86741 -> 86741 bytes Project/Release/Machines.cpp.o | Bin 41245 -> 43306 bytes Project/Release/MainFrame.cpp.o | Bin 155520 -> 155536 bytes Project/Release/PSP-UFU.exe | Bin 4451624 -> 4458510 bytes Project/Release/PowerFlow.cpp.o | Bin 31888 -> 31904 bytes Project/Release/ReactiveShuntElementForm.cpp.o | Bin 93115 -> 93115 bytes Project/Release/Shunt.cpp.o | Bin 37015 -> 39028 bytes Project/Release/SwitchingForm.cpp.o | Bin 107046 -> 107046 bytes Project/Release/SyncGenerator.cpp.o | Bin 50365 -> 52372 bytes Project/Release/SyncMachineForm.cpp.o | Bin 123729 -> 123729 bytes Project/Release/SyncMotor.cpp.o | Bin 47540 -> 49547 bytes Project/Release/Text.cpp.o | Bin 110498 -> 112553 bytes Project/Release/TextForm.cpp.o | Bin 165817 -> 165833 bytes Project/Release/Transformer.cpp.o | Bin 57842 -> 59897 bytes Project/Release/TransformerForm.cpp.o | Bin 108670 -> 108670 bytes Project/Release/Workspace.cpp.o | Bin 224878 -> 228913 bytes Project/Shunt.cpp | 8 +- Project/Transformer.cpp | 16 +- Project/Workspace.cpp | 96 +++++++--- Project/Workspace.h | 5 +- 49 files changed, 288 insertions(+), 208 deletions(-) diff --git a/.codelite/.tern-port b/.codelite/.tern-port index 58b5345..7d990b9 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -50786 \ No newline at end of file +55500 \ No newline at end of file diff --git a/.codelite/PSP.session b/.codelite/PSP.session index 216e489..867ce55 100644 --- a/.codelite/PSP.session +++ b/.codelite/PSP.session @@ -1,19 +1,19 @@ - + - - + + - - + + @@ -33,43 +33,29 @@ - - - - - - - - - + + - + - - - - - - - - + - - - + + + - - - + + + diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags index 4f08983..56bcbbd 100644 Binary files a/.codelite/PSP.tags and b/.codelite/PSP.tags differ diff --git a/.codelite/compilation.db b/.codelite/compilation.db index d5fa7f5..98a3256 100644 Binary files a/.codelite/compilation.db and b/.codelite/compilation.db differ diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db index 5a941e9..a2492ff 100644 Binary files a/.codelite/refactoring.db and b/.codelite/refactoring.db differ diff --git a/Buglist.txt b/Buglist.txt index 20634d5..c05ac90 100644 --- a/Buglist.txt +++ b/Buglist.txt @@ -1,12 +1,10 @@ BUG/TODO LIST [pt-br] PRIORIDADE 1: --> Generalizar a classe ElementDataObject e o método Workspace::Paste (é possível?); --> Elemento texto impactando bastante no desempenho gráfico (otimizar o algoritmo atual ou encontrar outra solução para desenhar textos no OpenGL?); --> Texto de teste da solução do fluxo de carga sendo exibido desnecessariamente. +-> Elemento texto impactando bastante no desempenho gráfico (otimizar o algoritmo atual ou encontrar outra solução para desenhar textos no OpenGL (freetype-gl)?); PRIORIDADE 2: --> Máquinas síncronas que atinge o limite de reativo igual a zero são atribuídos valores errados (-1,#J); +-> Atualizar a posição dos disjuntores quando um circuito for colado; -> Implementar uma visão rápida da solução (usar wxPopupTransientWindow ou wxPopupWindow); -> Abrir formulário pelo menu de contexto; -> Abrir o formulário do elemento após inserir o mesmo; @@ -21,7 +19,6 @@ PRIORIDADE 2: -> Setas do fluxo de carga das máquinas elétricas não são atualizadas quando a barra conectada é rotacionada; -> Criar segurança caso um aquivo não possa ser escrito ou aberto; -> Linhas dos transformadores desalinhadas quando abertos de um arquivo salvo; --> Algoritmo de mover apresenta desempenho ruim quando possui elementos diferentes de barras (cálculos gráficos de atualização das posições dos pontos dos elementos sendo realizados desnecessariamente? Fazer um child list para evitar a busca desnecessária do parent?); -> Remover a ferramenta Exportar/Importar. PRIORIDADE 3: diff --git a/Project/Branch.cpp b/Project/Branch.cpp index d0af388..e971411 100644 --- a/Project/Branch.cpp +++ b/Project/Branch.cpp @@ -1,23 +1,25 @@ #include "Branch.h" -Branch::Branch() : Element() {} +Branch::Branch() + : Element() +{ +} Branch::~Branch() {} bool Branch::NodeContains(wxPoint2DDouble position) { wxRect2DDouble nodeRect1(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); wxRect2DDouble nodeRect2(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize, - m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, 10 + 2.0 * m_borderSize, - 10 + 2.0 * m_borderSize); + m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); if(nodeRect1.Contains(position)) { - m_activeNodeID = 1; - return true; - } + m_activeNodeID = 1; + return true; + } if(nodeRect2.Contains(position)) { - m_activeNodeID = 2; - return true; - } + m_activeNodeID = 2; + return true; + } m_activeNodeID = 0; return false; @@ -29,99 +31,98 @@ bool Branch::SetNodeParent(Element* parent) if(m_activeNodeID == 2 && parent == m_parentList[1]) return false; if(parent && m_activeNodeID != 0) { - wxRect2DDouble nodeRect(0, 0, 0, 0); - if(m_activeNodeID == 1) { - nodeRect = - wxRect2DDouble(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); - } - if(m_activeNodeID == 2) { - nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize, - m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); - } - - if(parent->Intersects(nodeRect)) { - if(m_activeNodeID == 1) { - // Check if the user is trying to connect the same bus. - if(m_parentList[1] == parent) { - m_activeNodeID = 0; - return false; - } - - m_parentList[0] = parent; - - // Centralize the node on bus. - wxPoint2DDouble parentPt = parent->RotateAtPosition( - m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position. - parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. - parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); - m_pointList[0] = parentPt; - - UpdateSwitchesPosition(); - return true; - } - if(m_activeNodeID == 2) { - if(m_parentList[0] == parent) { - m_activeNodeID = 0; - return false; - } - - m_parentList[1] = parent; - - wxPoint2DDouble parentPt = - parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], -parent->GetAngle()); - parentPt.m_y = parent->GetPosition().m_y; - parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); - m_pointList[m_pointList.size() - 1] = parentPt; - - UpdateSwitchesPosition(); - return true; - } - } - else - { - if(m_activeNodeID == 1) m_parentList[0] = NULL; - if(m_activeNodeID == 2) m_parentList[1] = NULL; - } - } + wxRect2DDouble nodeRect(0, 0, 0, 0); + if(m_activeNodeID == 1) { + nodeRect = wxRect2DDouble(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + } + if(m_activeNodeID == 2) { + nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize, + m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, 10 + 2.0 * m_borderSize, + 10 + 2.0 * m_borderSize); + } + + if(parent->Intersects(nodeRect)) { + if(m_activeNodeID == 1) { + // Check if the user is trying to connect the same bus. + if(m_parentList[1] == parent) { + m_activeNodeID = 0; + return false; + } + + m_parentList[0] = parent; + + // Centralize the node on bus. + wxPoint2DDouble parentPt = parent->RotateAtPosition( + m_pointList[0], -parent->GetAngle()); // Rotate click to horizontal position. + parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. + parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); + m_pointList[0] = parentPt; + + UpdateSwitchesPosition(); + return true; + } + if(m_activeNodeID == 2) { + if(m_parentList[0] == parent) { + m_activeNodeID = 0; + return false; + } + + m_parentList[1] = parent; + + wxPoint2DDouble parentPt = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], -parent->GetAngle()); + parentPt.m_y = parent->GetPosition().m_y; + parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); + m_pointList[m_pointList.size() - 1] = parentPt; + + UpdateSwitchesPosition(); + return true; + } + } else { + if(m_activeNodeID == 1) m_parentList[0] = NULL; + if(m_activeNodeID == 2) m_parentList[1] = NULL; + } + } return false; } void Branch::RemoveParent(Element* parent) { for(int i = 0; i < 2; i++) { - if(parent == m_parentList[i]) { - m_parentList[i] = NULL; - m_online = false; - UpdateSwitchesPosition(); - } - } + if(parent == m_parentList[i]) { + m_parentList[i] = NULL; + m_online = false; + UpdateSwitchesPosition(); + } + } } void Branch::UpdateNodes() { if(m_parentList[0]) { - wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); - - if(!m_parentList[0]->Intersects(nodeRect)) { - m_parentList[0] = NULL; - m_online = false; - UpdateSwitchesPosition(); - } - } + wxRect2DDouble nodeRect(m_pointList[0].m_x - 5.0 - m_borderSize, m_pointList[0].m_y - 5.0 - m_borderSize, + 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); + + if(!m_parentList[0]->Intersects(nodeRect)) { + m_parentList[0]->RemoveChild(this); + m_parentList[0] = NULL; + m_online = false; + UpdateSwitchesPosition(); + } + } if(m_parentList[1]) { - wxRect2DDouble nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize, - m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, - 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); - - if(!m_parentList[1]->Intersects(nodeRect)) { - m_parentList[1] = NULL; - m_online = false; - UpdateSwitchesPosition(); - } - } + wxRect2DDouble nodeRect = wxRect2DDouble(m_pointList[m_pointList.size() - 1].m_x - 5.0 - m_borderSize, + m_pointList[m_pointList.size() - 1].m_y - 5.0 - m_borderSize, 10 + 2.0 * m_borderSize, + 10 + 2.0 * m_borderSize); + + if(!m_parentList[1]->Intersects(nodeRect)) { + m_parentList[1]->RemoveChild(this); + m_parentList[1] = NULL; + m_online = false; + UpdateSwitchesPosition(); + } + } } void Branch::RotateNode(Element* parent, bool clockwise) @@ -130,48 +131,41 @@ void Branch::RotateNode(Element* parent, bool clockwise) if(!clockwise) rotAngle = -m_rotationAngle; if(parent == m_parentList[0]) { - m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); - } - else if(parent == m_parentList[1]) - { - m_pointList[m_pointList.size() - 1] = - parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle); - } + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); + } else if(parent == m_parentList[1]) { + m_pointList[m_pointList.size() - 1] = parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle); + } UpdateSwitchesPosition(); } void Branch::UpdateSwitchesPosition() { if(m_parentList[0]) { - m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); - } - else - { - m_pointList[1] = m_pointList[0]; - } + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); + } else { + m_pointList[1] = m_pointList[0]; + } if(m_parentList[1]) { - m_pointList[m_pointList.size() - 2] = GetSwitchPoint(m_parentList[1], m_pointList[m_pointList.size() - 1], - m_pointList[m_pointList.size() - 3]); - } - else - { - m_pointList[m_pointList.size() - 2] = m_pointList[m_pointList.size() - 1]; - } + m_pointList[m_pointList.size() - 2] = + GetSwitchPoint(m_parentList[1], m_pointList[m_pointList.size() - 1], m_pointList[m_pointList.size() - 3]); + } else { + m_pointList[m_pointList.size() - 2] = m_pointList[m_pointList.size() - 1]; + } UpdateSwitches(); } void Branch::UpdateSwitches() { - wxPoint2DDouble swCenter = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[1].m_x) / 2.0, - (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0); - m_switchRect[0] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize, - m_switchSize); + wxPoint2DDouble swCenter = wxPoint2DDouble( + (m_pointList[0].m_x + m_pointList[1].m_x) / 2.0, (m_pointList[0].m_y + m_pointList[1].m_y) / 2.0); + m_switchRect[0] = wxRect2DDouble( + swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize, m_switchSize); if(m_switchRect.size() > 1) { - swCenter = wxPoint2DDouble( - (m_pointList[m_pointList.size() - 1].m_x + m_pointList[m_pointList.size() - 2].m_x) / 2.0, - (m_pointList[m_pointList.size() - 1].m_y + m_pointList[m_pointList.size() - 2].m_y) / 2.0); - m_switchRect[1] = wxRect2DDouble(swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, - m_switchSize, m_switchSize); - } + swCenter = + wxPoint2DDouble((m_pointList[m_pointList.size() - 1].m_x + m_pointList[m_pointList.size() - 2].m_x) / 2.0, + (m_pointList[m_pointList.size() - 1].m_y + m_pointList[m_pointList.size() - 2].m_y) / 2.0); + m_switchRect[1] = wxRect2DDouble( + swCenter.m_x - m_switchSize / 2.0, swCenter.m_y - m_switchSize / 2.0, m_switchSize, m_switchSize); + } } diff --git a/Project/Capacitor.cpp b/Project/Capacitor.cpp index a4320c9..7545135 100644 --- a/Project/Capacitor.cpp +++ b/Project/Capacitor.cpp @@ -15,6 +15,7 @@ bool Capacitor::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. diff --git a/Project/ElectricCalculation.cpp b/Project/ElectricCalculation.cpp index 3c4c1e5..4514f05 100644 --- a/Project/ElectricCalculation.cpp +++ b/Project/ElectricCalculation.cpp @@ -139,8 +139,8 @@ bool ElectricCalculation::GetYBus(std::vector > else { // Complex turns ratio double radPhaseShift = wxDegToRad(data.phaseShift); - std::complex a = std::complex(data.turnsRatio * std::cos(radPhaseShift), - -data.turnsRatio * std::sin(radPhaseShift)); + std::complex a = std::complex( + data.turnsRatio * std::cos(radPhaseShift), -data.turnsRatio * std::sin(radPhaseShift)); // Transformer admitance std::complex y = 1.0 / std::complex(data.resistance, data.indReactance); @@ -157,11 +157,15 @@ bool ElectricCalculation::GetYBus(std::vector > } void ElectricCalculation::UpdateElementsPowerFlow(std::vector > voltage, - std::vector > power, - std::vector busType, - std::vector reactiveLimit, - double systemPowerBase) + std::vector > power, + std::vector busType, + std::vector reactiveLimit, + double systemPowerBase) { + for(int i = 0; i < (int)reactiveLimit.size(); ++i) { + if(reactiveLimit[i].maxLimit > -1e-5 && reactiveLimit[i].maxLimit < 1e-5) reactiveLimit[i].maxLimit = 1e-5; + if(reactiveLimit[i].minLimit > -1e-5 && reactiveLimit[i].minLimit < 1e-5) reactiveLimit[i].minLimit = 1e-5; + } // Buses voltages for(int i = 0; i < (int)m_busList.size(); i++) { Bus* bus = m_busList[i]; @@ -182,9 +186,9 @@ void ElectricCalculation::UpdateElementsPowerFlow(std::vector v2 = voltage[n2]; data.current[0] = (v1 - v2) / std::complex(data.resistance, data.indReactance) + - v1 * std::complex(0.0, data.capSusceptance / 2.0); + v1 * std::complex(0.0, data.capSusceptance / 2.0); data.current[1] = (v2 - v1) / std::complex(data.resistance, data.indReactance) + - v2 * std::complex(0.0, data.capSusceptance / 2.0); + v2 * std::complex(0.0, data.capSusceptance / 2.0); data.powerFlow[0] = v1 * std::conj(data.current[0]); data.powerFlow[1] = v2 * std::conj(data.current[1]); @@ -205,8 +209,8 @@ void ElectricCalculation::UpdateElementsPowerFlow(std::vectorGetElectricalData(); int n1 = ((Bus*)transformer->GetParentList()[0])->GetEletricalData().number; int n2 = ((Bus*)transformer->GetParentList()[1])->GetEletricalData().number; - std::complex v1 = voltage[n1]; // Primary voltage - std::complex v2 = voltage[n2]; // Secondary voltage + std::complex v1 = voltage[n1]; // Primary voltage + std::complex v2 = voltage[n2]; // Secondary voltage // Transformer admitance std::complex y = 1.0 / std::complex(data.resistance, data.indReactance); @@ -386,8 +390,8 @@ void ElectricCalculation::UpdateElementsPowerFlow(std::vector GetParentList() const { return m_parentList; } + virtual std::vector GetChildList() const { return m_childList; } virtual wxPoint2DDouble GetMoveStartPosition() const { return m_moveStartPt; } virtual wxPoint2DDouble GetMovePosition() const { return m_movePos; } virtual void CalculateBoundaries(wxPoint2DDouble& leftUp, wxPoint2DDouble& rightBottom) const; @@ -205,7 +211,9 @@ public: static wxString StringFromDouble(double value, int minDecimal = 1); protected: + int m_elementID = 0; std::vector m_parentList; + std::vector m_childList; wxRect2DDouble m_rect; wxPoint2DDouble m_position; diff --git a/Project/Inductor.cpp b/Project/Inductor.cpp index b3f80d9..0a272c1 100644 --- a/Project/Inductor.cpp +++ b/Project/Inductor.cpp @@ -15,6 +15,7 @@ bool Inductor::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. diff --git a/Project/Line.cpp b/Project/Line.cpp index 3180cf8..4b7f6c4 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -119,6 +119,7 @@ bool Line::AddParent(Element* parent, wxPoint2DDouble position) if(m_parentList.size() == 0) { m_position = position; m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. @@ -149,6 +150,7 @@ bool Line::AddParent(Element* parent, wxPoint2DDouble position) } m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. @@ -240,14 +242,21 @@ void Line::MoveNode(Element* parent, wxPoint2DDouble position) } } } else { + // If parent is setted to NULL for the firts time, remove the parent child if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - m_parentList[0] = NULL; - m_online = false; + if(m_parentList[0]) { + m_parentList[0]->RemoveChild(this); + m_parentList[0] = NULL; + m_online = false; + } } else if(m_activeNodeID == 2) { m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; - m_parentList[1] = NULL; - m_online = false; + if(m_parentList[1]) { + m_parentList[1]->RemoveChild(this); + m_parentList[1] = NULL; + m_online = false; + } } } diff --git a/Project/Load.cpp b/Project/Load.cpp index f5afda3..be5d1bb 100644 --- a/Project/Load.cpp +++ b/Project/Load.cpp @@ -7,6 +7,7 @@ bool Load::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. diff --git a/Project/Machines.cpp b/Project/Machines.cpp index bda8a7a..6377f08 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -9,6 +9,7 @@ bool Machines::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. @@ -107,8 +108,11 @@ void Machines::MoveNode(Element* element, wxPoint2DDouble position) } else { if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - m_parentList[0] = NULL; - m_online = false; + if(m_parentList[0]) { + m_parentList[0]->RemoveChild(this); + m_parentList[0] = NULL; + m_online = false; + } } } @@ -192,6 +196,7 @@ void Machines::UpdateNodes() 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); if(!m_parentList[0]->Intersects(nodeRect)) { + m_parentList[0]->RemoveChild(this); m_parentList[0] = NULL; m_online = false; UpdateSwitchesPosition(); diff --git a/Project/Release/Branch.cpp.o b/Project/Release/Branch.cpp.o index 2fde385..650804e 100644 Binary files a/Project/Release/Branch.cpp.o and b/Project/Release/Branch.cpp.o differ diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o index a8b586f..1340ef8 100644 Binary files a/Project/Release/Bus.cpp.o and b/Project/Release/Bus.cpp.o differ diff --git a/Project/Release/BusForm.cpp.o b/Project/Release/BusForm.cpp.o index 028f7ff..8951fc6 100644 Binary files a/Project/Release/BusForm.cpp.o and b/Project/Release/BusForm.cpp.o differ diff --git a/Project/Release/Capacitor.cpp.o b/Project/Release/Capacitor.cpp.o index 7ce764b..5d66a63 100644 Binary files a/Project/Release/Capacitor.cpp.o and b/Project/Release/Capacitor.cpp.o differ diff --git a/Project/Release/ElectricCalculation.cpp.o b/Project/Release/ElectricCalculation.cpp.o index 0c9d36d..2dfcbc1 100644 Binary files a/Project/Release/ElectricCalculation.cpp.o and b/Project/Release/ElectricCalculation.cpp.o differ diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o index 866bd66..fde7b9d 100644 Binary files a/Project/Release/Element.cpp.o and b/Project/Release/Element.cpp.o differ diff --git a/Project/Release/FileHanding.cpp.o b/Project/Release/FileHanding.cpp.o index 7483e5a..710256c 100644 Binary files a/Project/Release/FileHanding.cpp.o and b/Project/Release/FileHanding.cpp.o differ diff --git a/Project/Release/GeneratorStabForm.cpp.o b/Project/Release/GeneratorStabForm.cpp.o index 51022f9..c79ab0f 100644 Binary files a/Project/Release/GeneratorStabForm.cpp.o and b/Project/Release/GeneratorStabForm.cpp.o differ diff --git a/Project/Release/IndMotor.cpp.o b/Project/Release/IndMotor.cpp.o index 672e91e..c977c83 100644 Binary files a/Project/Release/IndMotor.cpp.o and b/Project/Release/IndMotor.cpp.o differ diff --git a/Project/Release/IndMotorForm.cpp.o b/Project/Release/IndMotorForm.cpp.o index 9d803e3..bc4d845 100644 Binary files a/Project/Release/IndMotorForm.cpp.o and b/Project/Release/IndMotorForm.cpp.o differ diff --git a/Project/Release/Inductor.cpp.o b/Project/Release/Inductor.cpp.o index e7c996a..9162679 100644 Binary files a/Project/Release/Inductor.cpp.o and b/Project/Release/Inductor.cpp.o differ diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o index ba713e2..ebc38b3 100644 Binary files a/Project/Release/Line.cpp.o and b/Project/Release/Line.cpp.o differ diff --git a/Project/Release/LineForm.cpp.o b/Project/Release/LineForm.cpp.o index 298d75a..0c481b7 100644 Binary files a/Project/Release/LineForm.cpp.o and b/Project/Release/LineForm.cpp.o differ diff --git a/Project/Release/Load.cpp.o b/Project/Release/Load.cpp.o index f38aae6..4cf5b30 100644 Binary files a/Project/Release/Load.cpp.o and b/Project/Release/Load.cpp.o differ diff --git a/Project/Release/LoadForm.cpp.o b/Project/Release/LoadForm.cpp.o index 2072699..9a89929 100644 Binary files a/Project/Release/LoadForm.cpp.o and b/Project/Release/LoadForm.cpp.o differ diff --git a/Project/Release/Machines.cpp.o b/Project/Release/Machines.cpp.o index 1ea13c6..77bb073 100644 Binary files a/Project/Release/Machines.cpp.o and b/Project/Release/Machines.cpp.o differ diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o index a7639f0..4b8b802 100644 Binary files a/Project/Release/MainFrame.cpp.o and b/Project/Release/MainFrame.cpp.o differ diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe index c66b8dc..ef49ff3 100644 Binary files a/Project/Release/PSP-UFU.exe and b/Project/Release/PSP-UFU.exe differ diff --git a/Project/Release/PowerFlow.cpp.o b/Project/Release/PowerFlow.cpp.o index 670fffe..6cb09be 100644 Binary files a/Project/Release/PowerFlow.cpp.o and b/Project/Release/PowerFlow.cpp.o differ diff --git a/Project/Release/ReactiveShuntElementForm.cpp.o b/Project/Release/ReactiveShuntElementForm.cpp.o index 951d7f8..363e8c9 100644 Binary files a/Project/Release/ReactiveShuntElementForm.cpp.o and b/Project/Release/ReactiveShuntElementForm.cpp.o differ diff --git a/Project/Release/Shunt.cpp.o b/Project/Release/Shunt.cpp.o index 2706951..5476fab 100644 Binary files a/Project/Release/Shunt.cpp.o and b/Project/Release/Shunt.cpp.o differ diff --git a/Project/Release/SwitchingForm.cpp.o b/Project/Release/SwitchingForm.cpp.o index 00668c4..8e3123b 100644 Binary files a/Project/Release/SwitchingForm.cpp.o and b/Project/Release/SwitchingForm.cpp.o differ diff --git a/Project/Release/SyncGenerator.cpp.o b/Project/Release/SyncGenerator.cpp.o index ec0e7ae..5d23073 100644 Binary files a/Project/Release/SyncGenerator.cpp.o and b/Project/Release/SyncGenerator.cpp.o differ diff --git a/Project/Release/SyncMachineForm.cpp.o b/Project/Release/SyncMachineForm.cpp.o index 8239d77..bddf083 100644 Binary files a/Project/Release/SyncMachineForm.cpp.o and b/Project/Release/SyncMachineForm.cpp.o differ diff --git a/Project/Release/SyncMotor.cpp.o b/Project/Release/SyncMotor.cpp.o index c882bf6..5adf1ba 100644 Binary files a/Project/Release/SyncMotor.cpp.o and b/Project/Release/SyncMotor.cpp.o differ diff --git a/Project/Release/Text.cpp.o b/Project/Release/Text.cpp.o index 2f2c0b8..d690ed4 100644 Binary files a/Project/Release/Text.cpp.o and b/Project/Release/Text.cpp.o differ diff --git a/Project/Release/TextForm.cpp.o b/Project/Release/TextForm.cpp.o index 6881ff3..0ae59b4 100644 Binary files a/Project/Release/TextForm.cpp.o and b/Project/Release/TextForm.cpp.o differ diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o index 449b86c..41c0cea 100644 Binary files a/Project/Release/Transformer.cpp.o and b/Project/Release/Transformer.cpp.o differ diff --git a/Project/Release/TransformerForm.cpp.o b/Project/Release/TransformerForm.cpp.o index 58055cf..f7be3ea 100644 Binary files a/Project/Release/TransformerForm.cpp.o and b/Project/Release/TransformerForm.cpp.o differ diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o index d2d4a85..2c08502 100644 Binary files a/Project/Release/Workspace.cpp.o and b/Project/Release/Workspace.cpp.o differ diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index d932abd..0cd5736 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -34,8 +34,11 @@ void Shunt::MoveNode(Element* element, wxPoint2DDouble position) } else { if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - m_parentList[0] = NULL; - m_online = false; + if(m_parentList[0]) { + m_parentList[0]->RemoveChild(this); + m_parentList[0] = NULL; + m_online = false; + } } } @@ -109,6 +112,7 @@ void Shunt::UpdateNodes() 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); if(!m_parentList[0]->Intersects(nodeRect)) { + m_parentList[0]->RemoveChild(this); m_parentList[0] = NULL; m_online = false; UpdateSwitchesPosition(); diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 2ba6850..4dfa7f4 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -28,6 +28,7 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) if(m_parentList.size() == 0) { m_position = position; m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. @@ -43,6 +44,7 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) // Second bus. else if(parent != m_parentList[0]) { m_parentList.push_back(parent); + parent->AddChild(this); wxPoint2DDouble parentPt = parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. @@ -220,12 +222,18 @@ void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) } else { if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - m_parentList[0] = NULL; - m_online = false; + if(m_parentList[0]) { + m_parentList[0]->RemoveChild(this); + m_parentList[0] = NULL; + m_online = false; + } } else if(m_activeNodeID == 2) { m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; - m_parentList[1] = NULL; - m_online = false; + if(m_parentList[1]) { + m_parentList[1]->RemoveChild(this); + m_parentList[1] = NULL; + m_online = false; + } } } diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 2894ed2..c045408 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -401,6 +401,7 @@ void Workspace::OnLeftClickUp(wxMouseEvent& event) Element* parent = m_elementList[i]; if(typeid(*parent) == typeid(Bus)) { if(element->SetNodeParent(parent)) { + parent->AddChild(element); findNewParent = true; itnp = it; element->ResetNodes(); @@ -537,19 +538,15 @@ void Workspace::OnMouseMotion(wxMouseEvent& event) case MODE_MOVE_ELEMENT: case MODE_PASTE: { - for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { Element* element = *it; - // Parent's element moving... - for(int i = 0; i < (int)element->GetParentList().size(); i++) { - Element* parent = element->GetParentList()[i]; - if(parent) { - if(parent->IsSelected()) { - element->MoveNode(parent, m_camera->ScreenToWorld(event.GetPosition())); - } - } - } if(element->IsSelected()) { element->Move(m_camera->ScreenToWorld(event.GetPosition())); + // Move child nodes + for(int i = 0; i < (int)element->GetChildList().size(); i++) { + Element* child = element->GetChildList()[i]; + child->MoveNode(element, m_camera->ScreenToWorld(event.GetPosition())); + } redraw = true; } } @@ -688,13 +685,13 @@ void Workspace::OnKeyDown(wxKeyEvent& event) } break; case 'L': { if(!insertingElement) { - if(event.GetModifiers() == wxMOD_SHIFT) { // Insert a load. + if(!event.ControlDown() && event.ShiftDown()) { // Insert a load. Load* newLoad = new Load(wxString::Format(_("Load %d"), GetElementNumber(ID_LOAD))); IncrementElementNumber(ID_LOAD); m_elementList.push_back(newLoad); m_mode = MODE_INSERT; m_statusBar->SetStatusText(_("Insert Load: Click on a buses, ESC to cancel.")); - } else { // Insert a power line. + } else if(!event.ControlDown() && !event.ShiftDown()) { // Insert a power line. Line* newLine = new Line(wxString::Format(_("Line %d"), GetElementNumber(ID_LINE))); IncrementElementNumber(ID_LINE); m_elementList.push_back(newLine); @@ -703,6 +700,14 @@ void Workspace::OnKeyDown(wxKeyEvent& event) } Redraw(); } + // Tests - Ctrl + Shift + L + if(event.ControlDown() && event.ShiftDown()) { + int numBus = 0; + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + if(typeid(**it) == typeid(Bus)) numBus++; + } + wxMessageBox(wxString::Format("%d buses\n%d elements", numBus, m_elementList.size())); + } } break; case 'T': // Insert a transformer. { @@ -890,6 +895,7 @@ void Workspace::OnPopupClick(wxCommandEvent& event) Element* parent = child->GetParentList()[i]; if(parent == element) { child->RemoveParent(parent); + parent->RemoveChild(child); } } } @@ -940,15 +946,16 @@ void Workspace::DeleteSelectedElements() Element* element = *it; if(element->IsSelected()) { - for(auto itp = m_elementList.begin(); itp != m_elementList.end(); ++itp) { - Element* child = *itp; - // Parent's element being deleted... - for(int i = 0; i < (int)child->GetParentList().size(); i++) { - Element* parent = child->GetParentList()[i]; - if(parent == element) { - child->RemoveParent(parent); - } - } + + // Remove itself from parent list + for(int i = 0; i < (int)element->GetParentList().size(); ++i) { + Element* parent = element->GetParentList()[i]; + if(parent) parent->RemoveChild(element); + } + // Remove child parent. + for(int i = 0; i < (int)element->GetChildList().size(); ++i) { + Element* child = element->GetChildList()[i]; + if(child) child->RemoveParent(element); } for(auto itt = m_textList.begin(); itt != m_textList.end(); ++itt) { @@ -1092,6 +1099,7 @@ void Workspace::UpdateTextElements() void Workspace::CopySelection() { + UpdateElementsID(); std::vector selectedElements; // The buses need to be numerated to associate the child's parents to the copies. int busNumber = 0; @@ -1149,9 +1157,9 @@ bool Workspace::Paste() for(auto it = parentList.begin(), itEnd = parentList.end(); it != itEnd; ++it) { Element* copy = (*it)->GetCopy(); if(copy) { - pastedElements.push_back((Bus*)copy); + pastedElements.push_back(copy); pastedBusList.push_back((Bus*)copy); - m_elementList.push_back((Bus*)copy); + m_elementList.push_back(copy); } } @@ -1180,12 +1188,14 @@ bool Workspace::Paste() for(int j = 0; j < (int)copy->GetParentList().size(); j++) { Bus* currentParent = (Bus*)copy->GetParentList()[j]; if(currentParent) { - int parentNumber = currentParent->GetEletricalData().number; + int parentID = currentParent->GetID(); bool parentCopied = false; for(int k = 0; k < (int)pastedBusList.size(); k++) { Bus* newParent = pastedBusList[k]; - if(parentNumber == newParent->GetEletricalData().number) + if(parentID == newParent->GetID()) { copy->ReplaceParent(currentParent, newParent); + break; + } } if(!parentCopied) copy->RemoveParent(currentParent); } @@ -1197,6 +1207,24 @@ bool Workspace::Paste() } } + // Update buses childs + for(auto it = pastedBusList.begin(), itEnd = pastedBusList.end(); it != itEnd; ++it) { + Bus* bus = *it; + for(int i = 0; i < (int)bus->GetChildList().size(); ++i) { + Element* currentChild = bus->GetChildList()[i]; + int childID = currentChild->GetID(); + bool childCopied = false; + for(int j = 0; j < (int)pastedElements.size(); j++) { + Element* newChild = pastedElements[j]; + if(childID == newChild->GetID()) { + bus->ReplaceChild(currentChild, newChild); + break; + } + } + if(!childCopied) bus->RemoveChild(currentChild); + } + } + // Move elements (and nodes) to the mouse position. // The start position it's the center of the pasted objects. wxPoint2DDouble leftUpCorner, rightDownCorner; @@ -1218,10 +1246,11 @@ bool Workspace::Paste() return false; } - Redraw(); + UpdateElementsID(); m_mode = MODE_PASTE; m_statusBar->SetStatusText(_("Click to paste.")); UpdateStatusBar(); + Redraw(); return true; } @@ -1236,3 +1265,18 @@ void Workspace::UnselectAll() text->SetSelected(false); } } + +void Workspace::UpdateElementsID() +{ + int id = 0; + for(auto it = m_elementList.begin(), itEnd = m_elementList.end(); it != itEnd; ++it) { + Element* element = *it; + element->SetID(id); + id++; + } + for(auto it = m_textList.begin(), itEnd = m_textList.end(); it != itEnd; ++it) { + Text* text = *it; + text->SetID(id); + id++; + } +} diff --git a/Project/Workspace.h b/Project/Workspace.h index 21a1a56..fe2a25f 100644 --- a/Project/Workspace.h +++ b/Project/Workspace.h @@ -91,7 +91,8 @@ public: void ValidateBusesVoltages(Element* initialBus); void ValidateElementsVoltages(); - + + void UpdateElementsID(); void UpdateTextElements(); int GetElementNumber(ElementID elementID) { return m_elementNumber[elementID]; } @@ -159,7 +160,7 @@ protected: wxPoint2DDouble m_mousePosition; - double m_zoomMin = 0.05; + double m_zoomMin = 0.01; double m_zoomMax = 3.0; }; -- cgit