summaryrefslogtreecommitdiffstats
path: root/Project/Shunt.cpp
diff options
context:
space:
mode:
authorThales1330 <thaleslima.ufu@gmail.com>2016-09-03 17:09:24 -0300
committerThales1330 <thaleslima.ufu@gmail.com>2016-09-03 17:09:24 -0300
commit726686c9b378f3a727ded52226b13a760cba1e6c (patch)
tree941150985ee1823041024ce50bc812303d30868e /Project/Shunt.cpp
parent077270f0294d236c6047d850703c5d011cb4b711 (diff)
downloadPSP.git-726686c9b378f3a727ded52226b13a760cba1e6c.tar.gz
PSP.git-726686c9b378f3a727ded52226b13a760cba1e6c.tar.xz
PSP.git-726686c9b378f3a727ded52226b13a760cba1e6c.zip
Inductor under implementation
Ind motor, sync condenser and load implemented
Diffstat (limited to 'Project/Shunt.cpp')
-rw-r--r--Project/Shunt.cpp129
1 files changed, 129 insertions, 0 deletions
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();
+ }
+}
+