summaryrefslogtreecommitdiffstats
path: root/Project/Machines.cpp
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2017-01-05 19:37:42 -0200
committerGitHub <noreply@github.com>2017-01-05 19:37:42 -0200
commit9df133274802731220546d1f9383c213193c8413 (patch)
tree9c6e2fa2a45d6c6c4c14d8711b2b89066bfb37d7 /Project/Machines.cpp
parentc5343c718cf80620c2fc7452a4315f7ddb9e5826 (diff)
parentb6f96ca48bc156898df79deba63d270b393fb150 (diff)
downloadPSP.git-9df133274802731220546d1f9383c213193c8413.tar.gz
PSP.git-9df133274802731220546d1f9383c213193c8413.tar.xz
PSP.git-9df133274802731220546d1f9383c213193c8413.zip
Merge pull request #5 from Thales1330/opt/element-parent-search
Opt element parent search
Diffstat (limited to 'Project/Machines.cpp')
-rw-r--r--Project/Machines.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/Project/Machines.cpp b/Project/Machines.cpp
index bda8a7a..bde70cb 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;
+ }
}
}
@@ -139,6 +143,7 @@ void Machines::RemoveParent(Element* parent)
{
if(parent == m_parentList[0]) {
m_parentList[0] = NULL;
+ m_online = false;
UpdateSwitchesPosition();
UpdatePowerFlowArrowsPosition();
}
@@ -192,6 +197,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();