summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.codelite/.tern-port2
-rw-r--r--.codelite/PSP.session44
-rw-r--r--.codelite/PSP.tagsbin79133696 -> 79142912 bytes
-rw-r--r--.codelite/compilation.dbbin65536 -> 65536 bytes
-rw-r--r--.codelite/refactoring.dbbin2988032 -> 2988032 bytes
-rw-r--r--Buglist.txt7
-rw-r--r--Project/Branch.cpp236
-rw-r--r--Project/Capacitor.cpp1
-rw-r--r--Project/ElectricCalculation.cpp28
-rw-r--r--Project/Element.cpp17
-rw-r--r--Project/Element.h8
-rw-r--r--Project/Inductor.cpp1
-rw-r--r--Project/Line.cpp17
-rw-r--r--Project/Load.cpp1
-rw-r--r--Project/Machines.cpp9
-rw-r--r--Project/Release/Branch.cpp.obin36478 -> 38491 bytes
-rw-r--r--Project/Release/Bus.cpp.obin51482 -> 53553 bytes
-rw-r--r--Project/Release/BusForm.cpp.obin119004 -> 119004 bytes
-rw-r--r--Project/Release/Capacitor.cpp.obin51864 -> 53887 bytes
-rw-r--r--Project/Release/ElectricCalculation.cpp.obin74373 -> 74659 bytes
-rw-r--r--Project/Release/Element.cpp.obin161826 -> 165690 bytes
-rw-r--r--Project/Release/FileHanding.cpp.obin197048 -> 197260 bytes
-rw-r--r--Project/Release/GeneratorStabForm.cpp.obin104202 -> 104202 bytes
-rw-r--r--Project/Release/IndMotor.cpp.obin44699 -> 46722 bytes
-rw-r--r--Project/Release/IndMotorForm.cpp.obin87116 -> 87116 bytes
-rw-r--r--Project/Release/Inductor.cpp.obin51732 -> 53771 bytes
-rw-r--r--Project/Release/Line.cpp.obin170313 -> 172448 bytes
-rw-r--r--Project/Release/LineForm.cpp.obin101112 -> 101112 bytes
-rw-r--r--Project/Release/Load.cpp.obin50527 -> 52598 bytes
-rw-r--r--Project/Release/LoadForm.cpp.obin86741 -> 86741 bytes
-rw-r--r--Project/Release/Machines.cpp.obin41245 -> 43306 bytes
-rw-r--r--Project/Release/MainFrame.cpp.obin155520 -> 155536 bytes
-rw-r--r--Project/Release/PSP-UFU.exebin4451624 -> 4458510 bytes
-rw-r--r--Project/Release/PowerFlow.cpp.obin31888 -> 31904 bytes
-rw-r--r--Project/Release/ReactiveShuntElementForm.cpp.obin93115 -> 93115 bytes
-rw-r--r--Project/Release/Shunt.cpp.obin37015 -> 39028 bytes
-rw-r--r--Project/Release/SwitchingForm.cpp.obin107046 -> 107046 bytes
-rw-r--r--Project/Release/SyncGenerator.cpp.obin50365 -> 52372 bytes
-rw-r--r--Project/Release/SyncMachineForm.cpp.obin123729 -> 123729 bytes
-rw-r--r--Project/Release/SyncMotor.cpp.obin47540 -> 49547 bytes
-rw-r--r--Project/Release/Text.cpp.obin110498 -> 112553 bytes
-rw-r--r--Project/Release/TextForm.cpp.obin165817 -> 165833 bytes
-rw-r--r--Project/Release/Transformer.cpp.obin57842 -> 59897 bytes
-rw-r--r--Project/Release/TransformerForm.cpp.obin108670 -> 108670 bytes
-rw-r--r--Project/Release/Workspace.cpp.obin224878 -> 228913 bytes
-rw-r--r--Project/Shunt.cpp8
-rw-r--r--Project/Transformer.cpp16
-rw-r--r--Project/Workspace.cpp96
-rw-r--r--Project/Workspace.h5
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 @@
<?xml version="1.0" encoding="UTF-8"?>
<Session Name="C:\Users\Thales\Documents\GitHub\PSP\PSP.workspace">
- <int Value="0" Name="m_selectedTab"/>
+ <int Value="6" Name="m_selectedTab"/>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\PSP.workspace" Name="m_workspaceName"/>
<TabInfoArray Name="TabInfoArray">
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.cpp" Name="FileName"/>
- <int Value="1167" Name="FirstVisibleLine"/>
- <int Value="1184" Name="CurrentLine"/>
+ <int Value="27" Name="FirstVisibleLine"/>
+ <int Value="45" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.h" Name="FileName"/>
- <int Value="141" Name="FirstVisibleLine"/>
- <int Value="49" Name="CurrentLine"/>
+ <int Value="136" Name="FirstVisibleLine"/>
+ <int Value="151" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
@@ -33,43 +33,29 @@
</TabInfo>
<TabInfo>
<wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Element.h" Name="FileName"/>
- <int Value="0" Name="FirstVisibleLine"/>
- <int Value="205" Name="CurrentLine"/>
- <wxArrayString Name="Bookmarks"/>
- <IntVector Name="CollapsedFolds"/>
- </TabInfo>
- <TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\ElementDataObject.h" Name="FileName"/>
- <int Value="3" Name="FirstVisibleLine"/>
- <int Value="0" Name="CurrentLine"/>
+ <int Value="126" Name="FirstVisibleLine"/>
+ <int Value="143" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\ElementDataObject.cpp" Name="FileName"/>
+ <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\PowerFlow.cpp" Name="FileName"/>
<int Value="0" Name="FirstVisibleLine"/>
- <int Value="34" Name="CurrentLine"/>
- <wxArrayString Name="Bookmarks"/>
- <IntVector Name="CollapsedFolds"/>
- </TabInfo>
- <TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Element.cpp" Name="FileName"/>
- <int Value="453" Name="FirstVisibleLine"/>
- <int Value="15" Name="CurrentLine"/>
+ <int Value="20" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Inductor.cpp" Name="FileName"/>
- <int Value="146" Name="FirstVisibleLine"/>
- <int Value="43" Name="CurrentLine"/>
+ <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\ElectricCalculation.cpp" Name="FileName"/>
+ <int Value="148" Name="FirstVisibleLine"/>
+ <int Value="166" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
<TabInfo>
- <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Capacitor.cpp" Name="FileName"/>
- <int Value="147" Name="FirstVisibleLine"/>
- <int Value="163" Name="CurrentLine"/>
+ <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\ElectricCalculation.h" Name="FileName"/>
+ <int Value="15" Name="FirstVisibleLine"/>
+ <int Value="30" Name="CurrentLine"/>
<wxArrayString Name="Bookmarks"/>
<IntVector Name="CollapsedFolds"/>
</TabInfo>
diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags
index 4f08983..56bcbbd 100644
--- a/.codelite/PSP.tags
+++ b/.codelite/PSP.tags
Binary files differ
diff --git a/.codelite/compilation.db b/.codelite/compilation.db
index d5fa7f5..98a3256 100644
--- a/.codelite/compilation.db
+++ b/.codelite/compilation.db
Binary files differ
diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db
index 5a941e9..a2492ff 100644
--- a/.codelite/refactoring.db
+++ b/.codelite/refactoring.db
Binary files 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<std::vector<std::complex<double> >
else {
// Complex turns ratio
double radPhaseShift = wxDegToRad(data.phaseShift);
- std::complex<double> a = std::complex<double>(data.turnsRatio * std::cos(radPhaseShift),
- -data.turnsRatio * std::sin(radPhaseShift));
+ std::complex<double> a = std::complex<double>(
+ data.turnsRatio * std::cos(radPhaseShift), -data.turnsRatio * std::sin(radPhaseShift));
// Transformer admitance
std::complex<double> y = 1.0 / std::complex<double>(data.resistance, data.indReactance);
@@ -157,11 +157,15 @@ bool ElectricCalculation::GetYBus(std::vector<std::vector<std::complex<double> >
}
void ElectricCalculation::UpdateElementsPowerFlow(std::vector<std::complex<double> > voltage,
- std::vector<std::complex<double> > power,
- std::vector<BusType> busType,
- std::vector<ReactiveLimits> reactiveLimit,
- double systemPowerBase)
+ std::vector<std::complex<double> > power,
+ std::vector<BusType> busType,
+ std::vector<ReactiveLimits> 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<std::complex<doubl
std::complex<double> v2 = voltage[n2];
data.current[0] = (v1 - v2) / std::complex<double>(data.resistance, data.indReactance) +
- v1 * std::complex<double>(0.0, data.capSusceptance / 2.0);
+ v1 * std::complex<double>(0.0, data.capSusceptance / 2.0);
data.current[1] = (v2 - v1) / std::complex<double>(data.resistance, data.indReactance) +
- v2 * std::complex<double>(0.0, data.capSusceptance / 2.0);
+ v2 * std::complex<double>(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::vector<std::complex<doubl
TransformerElectricalData data = transformer->GetElectricalData();
int n1 = ((Bus*)transformer->GetParentList()[0])->GetEletricalData().number;
int n2 = ((Bus*)transformer->GetParentList()[1])->GetEletricalData().number;
- std::complex<double> v1 = voltage[n1]; // Primary voltage
- std::complex<double> v2 = voltage[n2]; // Secondary voltage
+ std::complex<double> v1 = voltage[n1]; // Primary voltage
+ std::complex<double> v2 = voltage[n2]; // Secondary voltage
// Transformer admitance
std::complex<double> y = 1.0 / std::complex<double>(data.resistance, data.indReactance);
@@ -386,8 +390,8 @@ void ElectricCalculation::UpdateElementsPowerFlow(std::vector<std::complex<doubl
reactivePower = childData_PU.minReactive;
reachedMachineLimit = true;
} else if((!childData_PU.haveMaxReactive && reactiveLimit[i].limitReached == RL_MAX_REACHED) ||
- (!childData_PU.haveMinReactive && reactiveLimit[i].limitReached == RL_MIN_REACHED) ||
- (!childData_PU.haveMaxReactive && !childData_PU.haveMaxReactive)) {
+ (!childData_PU.haveMinReactive && reactiveLimit[i].limitReached == RL_MIN_REACHED) ||
+ (!childData_PU.haveMaxReactive && !childData_PU.haveMaxReactive)) {
reactivePower += exceededReactive;
exceededReactive = 0.0;
}
diff --git a/Project/Element.cpp b/Project/Element.cpp
index 4de5ebd..85280d6 100644
--- a/Project/Element.cpp
+++ b/Project/Element.cpp
@@ -456,6 +456,23 @@ void Element::ReplaceParent(Element* oldParent, Element* newParent)
}
}
+void Element::AddChild(Element* child) { m_childList.push_back(child); }
+
+void Element::RemoveChild(Element* child)
+{
+ for(auto it = m_childList.begin(); it != m_childList.end(); ++it) {
+ Element* element = *it;
+ if(element == child) m_childList.erase(it--);
+ }
+}
+
+void Element::ReplaceChild(Element* oldChild, Element* newChild)
+{
+ for(int i = 0; i < (int)m_childList.size(); i++) {
+ if(m_childList[i] == oldChild) m_childList[i] = newChild;
+ }
+}
+
void OpenGLColour::SetRGBA(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha)
{
rgba[0] = red;
diff --git a/Project/Element.h b/Project/Element.h
index 67e0762..c5aa030 100644
--- a/Project/Element.h
+++ b/Project/Element.h
@@ -130,6 +130,11 @@ public:
// General methods
virtual Element* GetCopy() { return NULL; }
+ virtual void SetID(int id) { m_elementID = id; }
+ virtual int GetID() const { return m_elementID; }
+ virtual void AddChild(Element* child);
+ virtual void RemoveChild(Element* child);
+ virtual void ReplaceChild(Element* oldChild, Element* newChild);
virtual void Draw(wxPoint2DDouble translation, double scale) const {};
virtual void Rotate(bool clockwise = true) {}
virtual bool GetContextMenu(wxMenu& menu) { return false; }
@@ -183,6 +188,7 @@ public:
virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees = true) const;
virtual std::vector<Element*> GetParentList() const { return m_parentList; }
+ virtual std::vector<Element*> 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<Element*> m_parentList;
+ std::vector<Element*> 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
--- a/Project/Release/Branch.cpp.o
+++ b/Project/Release/Branch.cpp.o
Binary files differ
diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o
index a8b586f..1340ef8 100644
--- a/Project/Release/Bus.cpp.o
+++ b/Project/Release/Bus.cpp.o
Binary files differ
diff --git a/Project/Release/BusForm.cpp.o b/Project/Release/BusForm.cpp.o
index 028f7ff..8951fc6 100644
--- a/Project/Release/BusForm.cpp.o
+++ b/Project/Release/BusForm.cpp.o
Binary files differ
diff --git a/Project/Release/Capacitor.cpp.o b/Project/Release/Capacitor.cpp.o
index 7ce764b..5d66a63 100644
--- a/Project/Release/Capacitor.cpp.o
+++ b/Project/Release/Capacitor.cpp.o
Binary files differ
diff --git a/Project/Release/ElectricCalculation.cpp.o b/Project/Release/ElectricCalculation.cpp.o
index 0c9d36d..2dfcbc1 100644
--- a/Project/Release/ElectricCalculation.cpp.o
+++ b/Project/Release/ElectricCalculation.cpp.o
Binary files differ
diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o
index 866bd66..fde7b9d 100644
--- a/Project/Release/Element.cpp.o
+++ b/Project/Release/Element.cpp.o
Binary files differ
diff --git a/Project/Release/FileHanding.cpp.o b/Project/Release/FileHanding.cpp.o
index 7483e5a..710256c 100644
--- a/Project/Release/FileHanding.cpp.o
+++ b/Project/Release/FileHanding.cpp.o
Binary files differ
diff --git a/Project/Release/GeneratorStabForm.cpp.o b/Project/Release/GeneratorStabForm.cpp.o
index 51022f9..c79ab0f 100644
--- a/Project/Release/GeneratorStabForm.cpp.o
+++ b/Project/Release/GeneratorStabForm.cpp.o
Binary files differ
diff --git a/Project/Release/IndMotor.cpp.o b/Project/Release/IndMotor.cpp.o
index 672e91e..c977c83 100644
--- a/Project/Release/IndMotor.cpp.o
+++ b/Project/Release/IndMotor.cpp.o
Binary files differ
diff --git a/Project/Release/IndMotorForm.cpp.o b/Project/Release/IndMotorForm.cpp.o
index 9d803e3..bc4d845 100644
--- a/Project/Release/IndMotorForm.cpp.o
+++ b/Project/Release/IndMotorForm.cpp.o
Binary files differ
diff --git a/Project/Release/Inductor.cpp.o b/Project/Release/Inductor.cpp.o
index e7c996a..9162679 100644
--- a/Project/Release/Inductor.cpp.o
+++ b/Project/Release/Inductor.cpp.o
Binary files differ
diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o
index ba713e2..ebc38b3 100644
--- a/Project/Release/Line.cpp.o
+++ b/Project/Release/Line.cpp.o
Binary files differ
diff --git a/Project/Release/LineForm.cpp.o b/Project/Release/LineForm.cpp.o
index 298d75a..0c481b7 100644
--- a/Project/Release/LineForm.cpp.o
+++ b/Project/Release/LineForm.cpp.o
Binary files differ
diff --git a/Project/Release/Load.cpp.o b/Project/Release/Load.cpp.o
index f38aae6..4cf5b30 100644
--- a/Project/Release/Load.cpp.o
+++ b/Project/Release/Load.cpp.o
Binary files differ
diff --git a/Project/Release/LoadForm.cpp.o b/Project/Release/LoadForm.cpp.o
index 2072699..9a89929 100644
--- a/Project/Release/LoadForm.cpp.o
+++ b/Project/Release/LoadForm.cpp.o
Binary files differ
diff --git a/Project/Release/Machines.cpp.o b/Project/Release/Machines.cpp.o
index 1ea13c6..77bb073 100644
--- a/Project/Release/Machines.cpp.o
+++ b/Project/Release/Machines.cpp.o
Binary files differ
diff --git a/Project/Release/MainFrame.cpp.o b/Project/Release/MainFrame.cpp.o
index a7639f0..4b8b802 100644
--- a/Project/Release/MainFrame.cpp.o
+++ b/Project/Release/MainFrame.cpp.o
Binary files differ
diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe
index c66b8dc..ef49ff3 100644
--- a/Project/Release/PSP-UFU.exe
+++ b/Project/Release/PSP-UFU.exe
Binary files differ
diff --git a/Project/Release/PowerFlow.cpp.o b/Project/Release/PowerFlow.cpp.o
index 670fffe..6cb09be 100644
--- a/Project/Release/PowerFlow.cpp.o
+++ b/Project/Release/PowerFlow.cpp.o
Binary files differ
diff --git a/Project/Release/ReactiveShuntElementForm.cpp.o b/Project/Release/ReactiveShuntElementForm.cpp.o
index 951d7f8..363e8c9 100644
--- a/Project/Release/ReactiveShuntElementForm.cpp.o
+++ b/Project/Release/ReactiveShuntElementForm.cpp.o
Binary files differ
diff --git a/Project/Release/Shunt.cpp.o b/Project/Release/Shunt.cpp.o
index 2706951..5476fab 100644
--- a/Project/Release/Shunt.cpp.o
+++ b/Project/Release/Shunt.cpp.o
Binary files differ
diff --git a/Project/Release/SwitchingForm.cpp.o b/Project/Release/SwitchingForm.cpp.o
index 00668c4..8e3123b 100644
--- a/Project/Release/SwitchingForm.cpp.o
+++ b/Project/Release/SwitchingForm.cpp.o
Binary files differ
diff --git a/Project/Release/SyncGenerator.cpp.o b/Project/Release/SyncGenerator.cpp.o
index ec0e7ae..5d23073 100644
--- a/Project/Release/SyncGenerator.cpp.o
+++ b/Project/Release/SyncGenerator.cpp.o
Binary files differ
diff --git a/Project/Release/SyncMachineForm.cpp.o b/Project/Release/SyncMachineForm.cpp.o
index 8239d77..bddf083 100644
--- a/Project/Release/SyncMachineForm.cpp.o
+++ b/Project/Release/SyncMachineForm.cpp.o
Binary files differ
diff --git a/Project/Release/SyncMotor.cpp.o b/Project/Release/SyncMotor.cpp.o
index c882bf6..5adf1ba 100644
--- a/Project/Release/SyncMotor.cpp.o
+++ b/Project/Release/SyncMotor.cpp.o
Binary files differ
diff --git a/Project/Release/Text.cpp.o b/Project/Release/Text.cpp.o
index 2f2c0b8..d690ed4 100644
--- a/Project/Release/Text.cpp.o
+++ b/Project/Release/Text.cpp.o
Binary files differ
diff --git a/Project/Release/TextForm.cpp.o b/Project/Release/TextForm.cpp.o
index 6881ff3..0ae59b4 100644
--- a/Project/Release/TextForm.cpp.o
+++ b/Project/Release/TextForm.cpp.o
Binary files differ
diff --git a/Project/Release/Transformer.cpp.o b/Project/Release/Transformer.cpp.o
index 449b86c..41c0cea 100644
--- a/Project/Release/Transformer.cpp.o
+++ b/Project/Release/Transformer.cpp.o
Binary files differ
diff --git a/Project/Release/TransformerForm.cpp.o b/Project/Release/TransformerForm.cpp.o
index 58055cf..f7be3ea 100644
--- a/Project/Release/TransformerForm.cpp.o
+++ b/Project/Release/TransformerForm.cpp.o
Binary files differ
diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o
index d2d4a85..2c08502 100644
--- a/Project/Release/Workspace.cpp.o
+++ b/Project/Release/Workspace.cpp.o
Binary files 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<Element*> 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;
};