From 077270f0294d236c6047d850703c5d011cb4b711 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Sat, 3 Sep 2016 01:10:18 -0300 Subject: Motor implementation done, elements classes reorganized --- Project/Machines.cpp | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 Project/Machines.cpp (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp new file mode 100644 index 0000000..2296fd0 --- /dev/null +++ b/Project/Machines.cpp @@ -0,0 +1,192 @@ +#include "Machines.h" + +Machines::Machines() : Element() +{ +} + +Machines::~Machines() +{ +} + +bool Machines::AddParent(Element* parent, wxPoint2DDouble position) +{ + if(parent) { + m_parentList.push_back(parent); + wxPoint2DDouble parentPt = + parent->RotateAtPosition(position, -parent->GetAngle()); // Rotate click to horizontal position. + parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. + parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back. + + m_position = parentPt + wxPoint2DDouble(-100.0, 0.0); // Shifts the position to the left of the bus. + m_width = m_height = 50.0; + m_rect = wxRect2DDouble(m_position.m_x - 25.0, m_position.m_y - 25.0, m_width, m_height); + + m_pointList.push_back(parentPt); + m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); + m_pointList.push_back(m_position + wxPoint2DDouble(35.0, 0.0)); + m_pointList.push_back(m_position + wxPoint2DDouble(25.0, 0.0)); + m_inserted = true; + return true; + } + return false; +} + +void Machines::Draw(wxPoint2DDouble translation, double scale) const +{ + if(m_inserted) { + // Draw Selection (layer 1). + if(m_selected) { + glLineWidth(1.5 + m_borderSize * 2.0); + glColor4d(0.0, 0.5, 1.0, 0.5); + DrawCircle(m_position, 25.0 + (m_borderSize + 1.5) / scale, 20, GL_POLYGON); + DrawLine(m_pointList); + + // Draw node selection. + DrawCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, GL_POLYGON); + } + + // Draw Machines (layer 2). + glLineWidth(1.5); + + // Draw node. + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); + + DrawLine(m_pointList); + + glColor4d(1.0, 1.0, 1.0, 1.0); + DrawCircle(m_position, 25.0, 20, GL_POLYGON); + + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_position, 25.0, 20); + + // Draw machine symbol. + DrawSymbol(); + } +} + +void Machines::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 Machines::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 Machines::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 Machines::StartMove(wxPoint2DDouble position) +{ + m_moveStartPt = position; + m_movePts = m_pointList; + m_movePos = m_position; +} + +void Machines::RotateNode(Element* parent) +{ + if(parent == m_parentList[0]) { + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], m_rotationAngle); + UpdateSwitchesPosition(); + } +} + +void Machines::RemoveParent(Element* parent) +{ + if(parent == m_parentList[0]) { + m_parentList[0] = NULL; + UpdateSwitchesPosition(); + } +} + +bool Machines::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 Machines::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 Machines::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 Machines::Rotate() +{ + m_pointList[2] = RotateAtPosition(m_pointList[2], m_rotationAngle); + m_pointList[3] = RotateAtPosition(m_pointList[3], m_rotationAngle); + UpdateSwitchesPosition(); +} -- cgit 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/Machines.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index 2296fd0..bde4af8 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -61,6 +61,7 @@ void Machines::Draw(wxPoint2DDouble translation, double scale) const DrawCircle(m_position, 25.0, 20); // Draw machine symbol. + glLineWidth(2.0); DrawSymbol(); } } -- 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/Machines.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index bde4af8..29574e6 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -1,13 +1,7 @@ #include "Machines.h" -Machines::Machines() : Element() -{ -} - -Machines::~Machines() -{ -} - +Machines::Machines() : Element() {} +Machines::~Machines() {} bool Machines::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { @@ -26,6 +20,10 @@ bool Machines::AddParent(Element* parent, wxPoint2DDouble position) m_pointList.push_back(m_position + wxPoint2DDouble(35.0, 0.0)); m_pointList.push_back(m_position + wxPoint2DDouble(25.0, 0.0)); m_inserted = true; + + wxRect2DDouble genRect(0,0,0,0); + m_switchRect.push_back(genRect); // Push a general rectangle. + UpdateSwitches(); return true; } return false; @@ -34,6 +32,7 @@ bool Machines::AddParent(Element* parent, wxPoint2DDouble position) void Machines::Draw(wxPoint2DDouble translation, double scale) const { if(m_inserted) { + // Draw Selection (layer 1). if(m_selected) { glLineWidth(1.5 + m_borderSize * 2.0); @@ -53,6 +52,8 @@ void Machines::Draw(wxPoint2DDouble translation, double scale) const DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); DrawLine(m_pointList); + + DrawSwitches(); glColor4d(1.0, 1.0, 1.0, 1.0); DrawCircle(m_position, 25.0, 20, GL_POLYGON); @@ -61,7 +62,7 @@ void Machines::Draw(wxPoint2DDouble translation, double scale) const DrawCircle(m_position, 25.0, 20); // Draw machine symbol. - glLineWidth(2.0); + glLineWidth(2.0); DrawSymbol(); } } @@ -75,6 +76,7 @@ void Machines::UpdateSwitchesPosition() { m_pointList[1] = m_pointList[0]; } + UpdateSwitches(); } void Machines::Move(wxPoint2DDouble position) @@ -83,8 +85,8 @@ void Machines::Move(wxPoint2DDouble position) 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; + if(!m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; } UpdateSwitchesPosition(); } @@ -101,6 +103,7 @@ void Machines::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; } } @@ -167,6 +170,7 @@ bool Machines::SetNodeParent(Element* parent) else { m_parentList[0] = NULL; + m_online = false; } } return false; @@ -180,6 +184,7 @@ void Machines::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/Machines.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index 29574e6..1b11c68 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -118,10 +118,13 @@ void Machines::StartMove(wxPoint2DDouble position) m_movePos = m_position; } -void Machines::RotateNode(Element* parent) +void Machines::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(); } } @@ -190,9 +193,12 @@ void Machines::UpdateNodes() } } -void Machines::Rotate() +void Machines::Rotate(bool clockwise) { - m_pointList[2] = RotateAtPosition(m_pointList[2], m_rotationAngle); - m_pointList[3] = RotateAtPosition(m_pointList[3], m_rotationAngle); + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + + m_pointList[2] = RotateAtPosition(m_pointList[2], rotAngle); + m_pointList[3] = RotateAtPosition(m_pointList[3], rotAngle); UpdateSwitchesPosition(); } -- cgit From 468ba7581675a23567746628d6777ca411b150d3 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Fri, 28 Oct 2016 17:46:43 -0200 Subject: Power flow arrow under implementation --- Project/Machines.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index 1b11c68..c86f7b7 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -54,6 +54,7 @@ void Machines::Draw(wxPoint2DDouble translation, double scale) const DrawLine(m_pointList); DrawSwitches(); + DrawPowerFlowPts(); glColor4d(1.0, 1.0, 1.0, 1.0); DrawCircle(m_position, 25.0, 20, GL_POLYGON); @@ -89,6 +90,12 @@ void Machines::Move(wxPoint2DDouble position) m_pointList[0] = m_movePts[0] + position - m_moveStartPt; } UpdateSwitchesPosition(); + + //Power flow arrows + std::vector edges; + edges.push_back(m_pointList[1]); + edges.push_back(m_pointList[2]); + CalculatePowerFlowPts(edges); } void Machines::MoveNode(Element* element, wxPoint2DDouble position) -- 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/Machines.cpp | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index c86f7b7..0f2dc43 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -24,6 +24,7 @@ bool Machines::AddParent(Element* parent, wxPoint2DDouble position) wxRect2DDouble genRect(0,0,0,0); m_switchRect.push_back(genRect); // Push a general rectangle. UpdateSwitches(); + UpdatePowerFlowArrowsPosition(); return true; } return false; @@ -90,12 +91,7 @@ void Machines::Move(wxPoint2DDouble position) m_pointList[0] = m_movePts[0] + position - m_moveStartPt; } UpdateSwitchesPosition(); - - //Power flow arrows - std::vector edges; - edges.push_back(m_pointList[1]); - edges.push_back(m_pointList[2]); - CalculatePowerFlowPts(edges); + UpdatePowerFlowArrowsPosition(); } void Machines::MoveNode(Element* element, wxPoint2DDouble position) @@ -110,12 +106,14 @@ void Machines::MoveNode(Element* element, wxPoint2DDouble position) if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; m_parentList[0] = NULL; + m_pfDirection = PF_NONE; m_online = false; } } // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Machines::StartMove(wxPoint2DDouble position) @@ -140,7 +138,9 @@ void Machines::RemoveParent(Element* parent) { if(parent == m_parentList[0]) { m_parentList[0] = NULL; + m_pfDirection = PF_NONE; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } } @@ -175,11 +175,13 @@ bool Machines::SetNodeParent(Element* parent) m_pointList[0] = parentPt; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); return true; } else { m_parentList[0] = NULL; + m_pfDirection = PF_NONE; m_online = false; } } @@ -194,8 +196,10 @@ void Machines::UpdateNodes() if(!m_parentList[0]->Intersects(nodeRect)) { m_parentList[0] = NULL; + m_pfDirection = PF_NONE; m_online = false; UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } } } @@ -208,4 +212,27 @@ void Machines::Rotate(bool clockwise) m_pointList[2] = RotateAtPosition(m_pointList[2], rotAngle); m_pointList[3] = RotateAtPosition(m_pointList[3], rotAngle); UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); +} + +void Machines::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); } -- cgit From b306118b2683cf6f264b5f1617c3e0e62a6c9042 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 1 Nov 2016 19:36:24 -0200 Subject: Power flow (gs) under implementation --- Project/Machines.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index 0f2dc43..12afe61 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -106,7 +106,6 @@ void Machines::MoveNode(Element* element, wxPoint2DDouble position) if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; m_parentList[0] = NULL; - m_pfDirection = PF_NONE; m_online = false; } } @@ -138,7 +137,6 @@ void Machines::RemoveParent(Element* parent) { if(parent == m_parentList[0]) { m_parentList[0] = NULL; - m_pfDirection = PF_NONE; UpdateSwitchesPosition(); UpdatePowerFlowArrowsPosition(); } @@ -181,7 +179,6 @@ bool Machines::SetNodeParent(Element* parent) else { m_parentList[0] = NULL; - m_pfDirection = PF_NONE; m_online = false; } } @@ -196,7 +193,6 @@ void Machines::UpdateNodes() if(!m_parentList[0]->Intersects(nodeRect)) { m_parentList[0] = NULL; - m_pfDirection = PF_NONE; m_online = false; UpdateSwitchesPosition(); UpdatePowerFlowArrowsPosition(); -- cgit From 9919f24692c1fe9b8e11fde5c6d5c18f169b5c10 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Fri, 4 Nov 2016 18:02:03 -0200 Subject: Validation implemented --- Project/Machines.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Project/Machines.cpp') diff --git a/Project/Machines.cpp b/Project/Machines.cpp index 12afe61..f859831 100644 --- a/Project/Machines.cpp +++ b/Project/Machines.cpp @@ -232,3 +232,9 @@ void Machines::UpdatePowerFlowArrowsPosition() CalculatePowerFlowPts(edges); } + +void Machines::SetPowerFlowDirection(PowerFlowDirection pfDirection) +{ + m_pfDirection = pfDirection; + UpdatePowerFlowArrowsPosition(); +} -- cgit