From 726686c9b378f3a727ded52226b13a760cba1e6c Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Sat, 3 Sep 2016 17:09:24 -0300 Subject: Inductor under implementation Ind motor, sync condenser and load implemented --- Project/Shunt.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 Project/Shunt.cpp (limited to 'Project/Shunt.cpp') diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp new file mode 100644 index 0000000..6e55dde --- /dev/null +++ b/Project/Shunt.cpp @@ -0,0 +1,129 @@ +#include "Shunt.h" + +Shunt::Shunt() : Element() +{ +} + +Shunt::~Shunt() +{ +} + +void Shunt::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]; + } +} + +void Shunt::Move(wxPoint2DDouble position) +{ + SetPosition(m_movePos + position - m_moveStartPt); + for(int i = 2; i < (int)m_pointList.size(); i++) { + m_pointList[i] = m_movePts[i] + position - m_moveStartPt; + } + if(!m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + UpdateSwitchesPosition(); +} + +void Shunt::MoveNode(Element* element, wxPoint2DDouble position) +{ + if(element) { + if(element == m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + } + else + { + if(m_activeNodeID == 1) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + m_parentList[0] = NULL; + } + } + + // Recalculate switches positions + UpdateSwitchesPosition(); +} + +void Shunt::StartMove(wxPoint2DDouble position) +{ + m_moveStartPt = position; + m_movePts = m_pointList; + m_movePos = m_position; +} + +void Shunt::RemoveParent(Element* parent) +{ + if(parent == m_parentList[0]) { + m_parentList[0] = NULL; + UpdateSwitchesPosition(); + } +} + +bool Shunt::NodeContains(wxPoint2DDouble position) +{ + 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(nodeRect.Contains(position)) { + m_activeNodeID = 1; + return true; + } + + m_activeNodeID = 0; + return false; +} + +bool Shunt::SetNodeParent(Element* parent) +{ + if(parent && m_activeNodeID != 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(parent->Intersects(nodeRect)) { + 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; + } + else + { + m_parentList[0] = NULL; + } + } + return false; +} + +void Shunt::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; + UpdateSwitchesPosition(); + } + } +} + +void Shunt::RotateNode(Element* parent) +{ + if(parent == m_parentList[0]) { + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], m_rotationAngle); + UpdateSwitchesPosition(); + } +} + -- cgit From c1aad656847602f7e4c7aead048f7465a76838d4 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sun, 4 Sep 2016 00:59:41 -0300 Subject: Inductor implemented --- Project/Shunt.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'Project/Shunt.cpp') diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index 6e55dde..34e4068 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -127,3 +127,18 @@ void Shunt::RotateNode(Element* parent) } } +void Shunt::DrawGround(wxPoint2DDouble position) const +{ + std::vector groundPts; + groundPts.push_back(position); + groundPts.push_back(position + wxPoint2DDouble(0, 10)); + groundPts.push_back(position + wxPoint2DDouble(-10, 10)); + groundPts.push_back(position + wxPoint2DDouble(10, 10)); + groundPts.push_back(position + wxPoint2DDouble(-6, 15)); + groundPts.push_back(position + wxPoint2DDouble(6, 15)); + groundPts.push_back(position + wxPoint2DDouble(-3, 20)); + groundPts.push_back(position + wxPoint2DDouble(3, 20)); + + DrawLine(groundPts, GL_LINES); +} + -- cgit From d93ef357da510f2515556ff2cb51688a4e068805 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Mon, 5 Sep 2016 18:43:50 -0300 Subject: All elements implemented, switches implemented --- Project/Shunt.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Project/Shunt.cpp') diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index 34e4068..81a310d 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -17,6 +17,7 @@ void Shunt::UpdateSwitchesPosition() { m_pointList[1] = m_pointList[0]; } + UpdateSwitches(); } void Shunt::Move(wxPoint2DDouble position) @@ -43,6 +44,7 @@ void Shunt::MoveNode(Element* element, wxPoint2DDouble position) if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; m_parentList[0] = NULL; + m_online = false; } } @@ -61,6 +63,7 @@ void Shunt::RemoveParent(Element* parent) { if(parent == m_parentList[0]) { m_parentList[0] = NULL; + m_online = false; UpdateSwitchesPosition(); } } @@ -101,6 +104,7 @@ bool Shunt::SetNodeParent(Element* parent) else { m_parentList[0] = NULL; + m_online = false; } } return false; @@ -114,6 +118,7 @@ void Shunt::UpdateNodes() if(!m_parentList[0]->Intersects(nodeRect)) { m_parentList[0] = NULL; + m_online = false; UpdateSwitchesPosition(); } } -- cgit From 697baaa3cc92e945d2301238dc9bcabffdb465ef Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 6 Sep 2016 18:32:47 -0300 Subject: Counter clockwise rotation implemented --- Project/Shunt.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Project/Shunt.cpp') diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index 81a310d..7df5330 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -124,10 +124,13 @@ void Shunt::UpdateNodes() } } -void Shunt::RotateNode(Element* parent) +void Shunt::RotateNode(Element* parent, bool clockwise) { + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + if(parent == m_parentList[0]) { - m_pointList[0] = parent->RotateAtPosition(m_pointList[0], m_rotationAngle); + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); UpdateSwitchesPosition(); } } -- cgit From 7d4df7195202eaea0e84f227e96f19dec4144081 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Sat, 29 Oct 2016 17:46:00 -0200 Subject: Power flow arrows implemented --- Project/Shunt.cpp | 188 +++++++++++++++++++++++++++++------------------------- 1 file changed, 101 insertions(+), 87 deletions(-) (limited to 'Project/Shunt.cpp') diff --git a/Project/Shunt.cpp b/Project/Shunt.cpp index 7df5330..d932abd 100644 --- a/Project/Shunt.cpp +++ b/Project/Shunt.cpp @@ -1,55 +1,47 @@ #include "Shunt.h" -Shunt::Shunt() : Element() -{ -} - -Shunt::~Shunt() -{ -} - +Shunt::Shunt() : Element() {} +Shunt::~Shunt() {} void Shunt::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]; - } - UpdateSwitches(); + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); + } else { + m_pointList[1] = m_pointList[0]; + } + UpdateSwitches(); } void Shunt::Move(wxPoint2DDouble position) { SetPosition(m_movePos + position - m_moveStartPt); for(int i = 2; i < (int)m_pointList.size(); i++) { - m_pointList[i] = m_movePts[i] + position - m_moveStartPt; - } - if(!m_parentList[0]) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - } + m_pointList[i] = m_movePts[i] + position - m_moveStartPt; + } + if(!m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Shunt::MoveNode(Element* element, wxPoint2DDouble position) { if(element) { - if(element == m_parentList[0]) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - } - } - else - { - if(m_activeNodeID == 1) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - m_parentList[0] = NULL; - m_online = false; - } - } + if(element == m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + } else { + if(m_activeNodeID == 1) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + m_parentList[0] = NULL; + m_online = false; + } + } // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Shunt::StartMove(wxPoint2DDouble position) @@ -62,10 +54,11 @@ void Shunt::StartMove(wxPoint2DDouble position) void Shunt::RemoveParent(Element* parent) { if(parent == m_parentList[0]) { - m_parentList[0] = NULL; - m_online = false; - UpdateSwitchesPosition(); - } + m_parentList[0] = NULL; + m_online = false; + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + } } bool Shunt::NodeContains(wxPoint2DDouble position) @@ -74,9 +67,9 @@ bool Shunt::NodeContains(wxPoint2DDouble position) 10 + 2.0 * m_borderSize, 10 + 2.0 * m_borderSize); if(nodeRect.Contains(position)) { - m_activeNodeID = 1; - return true; - } + m_activeNodeID = 1; + return true; + } m_activeNodeID = 0; return false; @@ -85,68 +78,89 @@ bool Shunt::NodeContains(wxPoint2DDouble position) bool Shunt::SetNodeParent(Element* parent) { if(parent && m_activeNodeID != 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(parent->Intersects(nodeRect)) { - 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; - } - else - { - m_parentList[0] = NULL; - m_online = false; - } - } + 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(parent->Intersects(nodeRect)) { + 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(); + UpdatePowerFlowArrowsPosition(); + return true; + } else { + m_parentList[0] = NULL; + m_online = false; + } + } return false; } void Shunt::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] = NULL; + m_online = false; + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + } + } } void Shunt::RotateNode(Element* parent, bool clockwise) { - double rotAngle = m_rotationAngle; - if(!clockwise) rotAngle = -m_rotationAngle; - + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + if(parent == m_parentList[0]) { - m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); - UpdateSwitchesPosition(); - } + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], rotAngle); + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); + } } void Shunt::DrawGround(wxPoint2DDouble position) const { - std::vector groundPts; - groundPts.push_back(position); - groundPts.push_back(position + wxPoint2DDouble(0, 10)); - groundPts.push_back(position + wxPoint2DDouble(-10, 10)); - groundPts.push_back(position + wxPoint2DDouble(10, 10)); - groundPts.push_back(position + wxPoint2DDouble(-6, 15)); - groundPts.push_back(position + wxPoint2DDouble(6, 15)); - groundPts.push_back(position + wxPoint2DDouble(-3, 20)); - groundPts.push_back(position + wxPoint2DDouble(3, 20)); - - DrawLine(groundPts, GL_LINES); + std::vector groundPts; + groundPts.push_back(position); + groundPts.push_back(position + wxPoint2DDouble(0, 10)); + groundPts.push_back(position + wxPoint2DDouble(-10, 10)); + groundPts.push_back(position + wxPoint2DDouble(10, 10)); + groundPts.push_back(position + wxPoint2DDouble(-6, 15)); + groundPts.push_back(position + wxPoint2DDouble(6, 15)); + groundPts.push_back(position + wxPoint2DDouble(-3, 20)); + groundPts.push_back(position + wxPoint2DDouble(3, 20)); + + DrawLine(groundPts, GL_LINES); } +void Shunt::UpdatePowerFlowArrowsPosition() +{ + std::vector edges; + switch(m_pfDirection) { + case PF_NONE: { + m_powerFlowArrow.clear(); + } break; + case PF_TO_BUS: { + edges.push_back(m_pointList[2]); + edges.push_back(m_pointList[1]); + } break; + case PF_TO_ELEMENT: { + edges.push_back(m_pointList[1]); + edges.push_back(m_pointList[2]); + } break; + default: + break; + } + CalculatePowerFlowPts(edges); +} \ No newline at end of file -- cgit