From c478afa9fbef4b21ea85dbc266169b9eebf369a9 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 30 Aug 2016 17:30:54 -0300 Subject: Transformer --- Project/Transformer.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Project/Transformer.cpp (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp new file mode 100644 index 0000000..30413d5 --- /dev/null +++ b/Project/Transformer.cpp @@ -0,0 +1,63 @@ +#include "Transformer.h" + +Transformer::Transformer() : Element() {} +Transformer::~Transformer() {} +bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) +{ + if(parent) { + // First bus. + if(m_parentList.size() == 0) { + m_position = position; + 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_pointList.push_back(parentPt); // First point + m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); + return false; + } + // Second bus. + else if(parent != m_parentList[0]) + { + 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. + + // Set first switch point. + wxPoint2DDouble secondPoint = parentPt; + if(m_pointList.size() > 2) { + secondPoint = m_pointList[2]; + } + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], secondPoint); + + // Set the second switch point. + m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_pointList[m_pointList.size() - 1])); + + m_pointList.push_back(parentPt); // Last point. + m_inserted = true; + + // The average between the two bus points. + m_position = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[m_pointList.size() - 1].m_x) / 2.0, + (m_pointList[0].m_y + m_pointList[m_pointList.size() - 1].m_y) / 2.0); + + m_width = 80.0; + m_height = 50.0; + m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, + m_height); + + return true; + } + } + return false; +} +bool Transformer::Contains(wxPoint2DDouble position) const {return m_rect.Contains(position);} +void Transformer::Draw(wxPoint2DDouble translation, double scale) const +{ + +} +bool Transformer::Intersects(wxRect2DDouble rect) const { return false;} +void Transformer::Rotate() {} +void Transformer::UpdateSwitchesPosition() {} -- cgit From 8f475833e585692544cb0f481b0dce0c3439a1a9 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Wed, 31 Aug 2016 23:09:16 -0300 Subject: Transformer complete --- Project/Transformer.cpp | 329 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 315 insertions(+), 14 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 30413d5..3cd0b6e 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -26,6 +26,19 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) parentPt.m_y = parent->GetPosition().m_y; // Centralize on bus. parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back. + // Get the average between the two bus points. + m_position = wxPoint2DDouble((m_pointList[0].m_x + parentPt.m_x) / 2.0, + (m_pointList[0].m_y + parentPt.m_y) / 2.0); + // Set the transformer rectangle. + m_width = 70.0; + m_height = 40.0; + m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, + m_height); + // Set the "side" points. + m_pointList.push_back(wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(-10, m_height / 2.0))); + m_pointList.push_back( + wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(m_width + 10, m_height / 2.0))); + // Set first switch point. wxPoint2DDouble secondPoint = parentPt; if(m_pointList.size() > 2) { @@ -38,26 +51,314 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) m_pointList.push_back(parentPt); // Last point. m_inserted = true; + return true; + } + } + return false; +} - // The average between the two bus points. - m_position = wxPoint2DDouble((m_pointList[0].m_x + m_pointList[m_pointList.size() - 1].m_x) / 2.0, - (m_pointList[0].m_y + m_pointList[m_pointList.size() - 1].m_y) / 2.0); +bool Transformer::Contains(wxPoint2DDouble position) const +{ + wxPoint2DDouble ptR = RotateAtPosition(position, -m_angle); + return m_rect.Contains(ptR); +} - m_width = 80.0; - m_height = 50.0; - m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, - m_height); +void Transformer::Draw(wxPoint2DDouble translation, double scale) const +{ + if(m_inserted) { + // Draw selection (layer 1). + if(m_selected) { + // Push the current matrix on stack. + glLineWidth(1.5 + m_borderSize * 2.0); + glColor4d(0.0, 0.5, 1.0, 0.5); + DrawLine(m_pointList); + glPushMatrix(); + // Rotate the matrix around the object position. + glTranslated(m_position.m_x, m_position.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - return true; + // glColor4d(0.0, 0.5, 1.0, 0.5); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, + 20, GL_POLYGON); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, + 20, GL_POLYGON); + + glPopMatrix(); + + // Draw nodes selection. + if(m_pointList.size() > 0) { + DrawCircle(m_pointList[0], 5.0 + m_borderSize, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize, 10, GL_POLYGON); + } + } + } + + // Draw transformer (layer 2). + // Transformer line + glLineWidth(1.5); + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawLine(m_pointList); + + // Draw nodes. + if(m_pointList.size() > 0) { + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, GL_POLYGON); + } } + + // Push the current matrix on stack. + glPushMatrix(); + // Rotate the matrix around the object position. + glTranslated(m_position.m_x, m_position.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-m_position.m_x, -m_position.m_y, 0.0); + + glColor4d(1.0, 1.0, 1.0, 1.0); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, GL_POLYGON); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, GL_POLYGON); + + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20); + + DrawPoint(m_rect.GetPosition(), 8.0 * scale); + + glPopMatrix(); } +} + +bool Transformer::Intersects(wxRect2DDouble rect) const +{ + if(m_angle == 0.0 || m_angle == 180.0) return m_rect.Intersects(rect); + return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0); +} + +void Transformer::Rotate() +{ + m_angle += m_rotationAngle; + if(m_angle >= 360.0) m_angle = 0.0; + + // Rotate all the points, except the switches and buses points. + for(int i = 2; i < (int)m_pointList.size() - 2; i++) { + m_pointList[i] = RotateAtPosition(m_pointList[i], m_rotationAngle); + } +} + +void Transformer::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]; + } + 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]; + } +} + +void Transformer::Move(wxPoint2DDouble position) +{ + SetPosition(m_movePos + position - m_moveStartPt); + + // Move all the points, except the switches and buses points. + for(int i = 2; i < (int)m_pointList.size() - 2; 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[1]) { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + } + + UpdateSwitchesPosition(); +} + +void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) +{ + if(parent) { + // First bus. + if(parent == m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + // Second bus. + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + } + } + else + { + if(m_activeNodeID == 1) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + m_parentList[0] = NULL; + } + else if(m_activeNodeID == 2) + { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + m_parentList[1] = NULL; + } + } + + // Recalculate switches positions + UpdateSwitchesPosition(); +} + +void Transformer::StartMove(wxPoint2DDouble position) +{ + m_moveStartPt = position; + m_movePts = m_pointList; + m_movePos = m_position; +} + +void Transformer::RemoveParent(Element* parent) +{ + for(int i = 0; i < 2; i++) { + if(parent == m_parentList[i]) { + m_parentList[i] = NULL; + m_parentList[i] = NULL; + UpdateSwitchesPosition(); + } + } +} + +bool Transformer::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); + 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); + + if(nodeRect1.Contains(position)) { + m_activeNodeID = 1; + return true; + } + if(nodeRect2.Contains(position)) { + m_activeNodeID = 2; + return true; + } + + m_activeNodeID = 0; return false; } -bool Transformer::Contains(wxPoint2DDouble position) const {return m_rect.Contains(position);} -void Transformer::Draw(wxPoint2DDouble translation, double scale) const + +bool Transformer::SetNodeParent(Element* parent) +{ + if(m_activeNodeID == 1 && parent == m_parentList[0]) return false; + 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; + } + } + return false; +} + +void Transformer::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(); + } + } + 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; + UpdateSwitchesPosition(); + } + } +} + +void Transformer::RotateNode(Element* parent) +{ + if(parent == m_parentList[0]) { + m_pointList[0] = parent->RotateAtPosition(m_pointList[0], m_rotationAngle); + } + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], m_rotationAngle); + } + UpdateSwitchesPosition(); +} + +bool Transformer::GetContextMenu(wxMenu& menu) { - + menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); + menu.Append(ID_DELETE, _("Delete")); + return true; } -bool Transformer::Intersects(wxRect2DDouble rect) const { return false;} -void Transformer::Rotate() {} -void Transformer::UpdateSwitchesPosition() {} -- cgit From b06d4c3d76cca3ed8a54dae1d978030d687233b2 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Thu, 1 Sep 2016 18:23:56 -0300 Subject: generator under implementation --- Project/Transformer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 3cd0b6e..de92bea 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -88,9 +88,9 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const // Draw nodes selection. if(m_pointList.size() > 0) { - DrawCircle(m_pointList[0], 5.0 + m_borderSize, 10, GL_POLYGON); + DrawCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, GL_POLYGON); if(m_inserted) { - DrawCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize, 10, GL_POLYGON); + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize / scale, 10, GL_POLYGON); } } } @@ -227,7 +227,6 @@ void Transformer::RemoveParent(Element* parent) { for(int i = 0; i < 2; i++) { if(parent == m_parentList[i]) { - m_parentList[i] = NULL; m_parentList[i] = NULL; UpdateSwitchesPosition(); } @@ -359,6 +358,7 @@ void Transformer::RotateNode(Element* parent) bool Transformer::GetContextMenu(wxMenu& menu) { menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); + menu.Append(ID_ROTATE, _("Rotate")); menu.Append(ID_DELETE, _("Delete")); return true; } -- cgit 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/Transformer.cpp | 153 +----------------------------------------------- 1 file changed, 1 insertion(+), 152 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index de92bea..cb18d2f 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -1,6 +1,6 @@ #include "Transformer.h" -Transformer::Transformer() : Element() {} +Transformer::Transformer() : Branch() {} Transformer::~Transformer() {} bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) { @@ -148,25 +148,6 @@ void Transformer::Rotate() } } -void Transformer::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]; - } - 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]; - } -} - void Transformer::Move(wxPoint2DDouble position) { SetPosition(m_movePos + position - m_moveStartPt); @@ -223,138 +204,6 @@ void Transformer::StartMove(wxPoint2DDouble position) m_movePos = m_position; } -void Transformer::RemoveParent(Element* parent) -{ - for(int i = 0; i < 2; i++) { - if(parent == m_parentList[i]) { - m_parentList[i] = NULL; - UpdateSwitchesPosition(); - } - } -} - -bool Transformer::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); - 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); - - if(nodeRect1.Contains(position)) { - m_activeNodeID = 1; - return true; - } - if(nodeRect2.Contains(position)) { - m_activeNodeID = 2; - return true; - } - - m_activeNodeID = 0; - return false; -} - -bool Transformer::SetNodeParent(Element* parent) -{ - if(m_activeNodeID == 1 && parent == m_parentList[0]) return false; - 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; - } - } - return false; -} - -void Transformer::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(); - } - } - 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; - UpdateSwitchesPosition(); - } - } -} - -void Transformer::RotateNode(Element* parent) -{ - if(parent == m_parentList[0]) { - m_pointList[0] = parent->RotateAtPosition(m_pointList[0], m_rotationAngle); - } - else if(parent == m_parentList[1]) - { - m_pointList[m_pointList.size() - 1] = - parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], m_rotationAngle); - } - UpdateSwitchesPosition(); -} - bool Transformer::GetContextMenu(wxMenu& menu) { menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); -- 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/Transformer.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index cb18d2f..ce1d12e 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -15,6 +15,10 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) parentPt = parent->RotateAtPosition(parentPt, parent->GetAngle()); // Rotate back. m_pointList.push_back(parentPt); // First point m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); + + wxRect2DDouble genRect(0,0,0,0); + m_switchRect.push_back(genRect); + return false; } // Second bus. @@ -51,6 +55,11 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) m_pointList.push_back(parentPt); // Last point. m_inserted = true; + + wxRect2DDouble genRect(0,0,0,0); + m_switchRect.push_back(genRect); + UpdateSwitches(); + return true; } } @@ -78,7 +87,6 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const glRotated(m_angle, 0.0, 0.0, 1.0); glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - // glColor4d(0.0, 0.5, 1.0, 0.5); DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, 20, GL_POLYGON); DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, @@ -109,7 +117,9 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const DrawCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, GL_POLYGON); } } - + + DrawSwitches(); + // Push the current matrix on stack. glPushMatrix(); // Rotate the matrix around the object position. @@ -185,11 +195,13 @@ void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) if(m_activeNodeID == 1) { m_pointList[0] = m_movePts[0] + position - m_moveStartPt; 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; } } -- 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/Transformer.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index ce1d12e..0bb32d8 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -147,14 +147,17 @@ bool Transformer::Intersects(wxRect2DDouble rect) const return RotatedRectanglesIntersects(m_rect, rect, m_angle, 0.0); } -void Transformer::Rotate() +void Transformer::Rotate(bool clockwise) { - m_angle += m_rotationAngle; + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + + m_angle += rotAngle; if(m_angle >= 360.0) m_angle = 0.0; // Rotate all the points, except the switches and buses points. for(int i = 2; i < (int)m_pointList.size() - 2; i++) { - m_pointList[i] = RotateAtPosition(m_pointList[i], m_rotationAngle); + m_pointList[i] = RotateAtPosition(m_pointList[i], rotAngle); } } @@ -219,7 +222,8 @@ void Transformer::StartMove(wxPoint2DDouble position) bool Transformer::GetContextMenu(wxMenu& menu) { menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); - menu.Append(ID_ROTATE, _("Rotate")); + menu.Append(ID_ROTATE_CLOCK, _("Rotate clockwise")); + menu.Append(ID_ROTATE_COUNTERCLOCK, _("Rotate counter-clockwise")); menu.Append(ID_DELETE, _("Delete")); return true; } -- cgit From fb8a409d7e35735afc9d28bfc0d7b49974f0d3a2 Mon Sep 17 00:00:00 2001 From: Thales Lima Oliveira Date: Wed, 7 Sep 2016 23:52:26 -0300 Subject: Movementation and rotation fixed --- Project/Transformer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 0bb32d8..03d71e7 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -222,8 +222,6 @@ void Transformer::StartMove(wxPoint2DDouble position) bool Transformer::GetContextMenu(wxMenu& menu) { menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); - menu.Append(ID_ROTATE_CLOCK, _("Rotate clockwise")); - menu.Append(ID_ROTATE_COUNTERCLOCK, _("Rotate counter-clockwise")); - menu.Append(ID_DELETE, _("Delete")); + GeneralMenuItens(menu); return true; } -- cgit From d60de5e4c4774c5b840c5cab2cb629a5bbe9df42 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Fri, 14 Oct 2016 17:45:25 -0300 Subject: Switching implemented --- Project/Transformer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 03d71e7..37237dd 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -1,3 +1,4 @@ +#include "TransformerForm.h" #include "Transformer.h" Transformer::Transformer() : Branch() {} @@ -225,3 +226,14 @@ bool Transformer::GetContextMenu(wxMenu& menu) GeneralMenuItens(menu); return true; } + +bool Transformer::ShowForm(wxWindow* parent, Element* element) +{ + TransformerForm* transfForm = new TransformerForm(parent, this); + if(transfForm->ShowModal() == wxID_OK) { + transfForm->Destroy(); + return true; + } + transfForm->Destroy(); + return false; +} -- cgit From c4f6b784f575b19506d3207d3f8fbf9496db5b43 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Mon, 17 Oct 2016 17:27:49 -0200 Subject: Transformer form under implementation --- Project/Transformer.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 37237dd..31a987b 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -237,3 +237,17 @@ bool Transformer::ShowForm(wxWindow* parent, Element* element) transfForm->Destroy(); return false; } + +void Transformer::SetNominalVoltage(std::vector nominalVoltage, std::vector nominalVoltageUnit) +{ + if(nominalVoltage.size() == 1) { + m_electricalData.primaryNominalVoltage = nominalVoltage[0]; + m_electricalData.primaryNominalVoltageUnit = nominalVoltageUnit[0]; + } + else if(nominalVoltage.size() == 2) { + m_electricalData.primaryNominalVoltage = nominalVoltage[0]; + m_electricalData.primaryNominalVoltageUnit = nominalVoltageUnit[0]; + m_electricalData.secondaryNominalVoltage = nominalVoltage[1]; + m_electricalData.secondaryNominalVoltageUnit = nominalVoltageUnit[1]; + } +} -- cgit From dc8e7b67eb2141cfbed0f26ac50a8d14104f391b Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Tue, 18 Oct 2016 16:59:36 -0200 Subject: Transformer form implemented --- Project/Transformer.cpp | 319 +++++++++++++++++++++++------------------------- 1 file changed, 156 insertions(+), 163 deletions(-) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 31a987b..57614bb 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -2,68 +2,67 @@ #include "Transformer.h" Transformer::Transformer() : Branch() {} +Transformer::Transformer(wxString name) : Branch() { m_electricalData.name = name; } Transformer::~Transformer() {} bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { - // First bus. - if(m_parentList.size() == 0) { - m_position = position; - 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_pointList.push_back(parentPt); // First point - m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); - - wxRect2DDouble genRect(0,0,0,0); - m_switchRect.push_back(genRect); - - return false; - } - // Second bus. - else if(parent != m_parentList[0]) - { - 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. - - // Get the average between the two bus points. - m_position = wxPoint2DDouble((m_pointList[0].m_x + parentPt.m_x) / 2.0, - (m_pointList[0].m_y + parentPt.m_y) / 2.0); - // Set the transformer rectangle. - m_width = 70.0; - m_height = 40.0; - m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, - m_height); - // Set the "side" points. - m_pointList.push_back(wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(-10, m_height / 2.0))); - m_pointList.push_back( - wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(m_width + 10, m_height / 2.0))); - - // Set first switch point. - wxPoint2DDouble secondPoint = parentPt; - if(m_pointList.size() > 2) { - secondPoint = m_pointList[2]; - } - m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], secondPoint); - - // Set the second switch point. - m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_pointList[m_pointList.size() - 1])); - - m_pointList.push_back(parentPt); // Last point. - m_inserted = true; - - wxRect2DDouble genRect(0,0,0,0); - m_switchRect.push_back(genRect); - UpdateSwitches(); - - return true; - } - } + // First bus. + if(m_parentList.size() == 0) { + m_position = position; + 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_pointList.push_back(parentPt); // First point + m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_position)); + + wxRect2DDouble genRect(0, 0, 0, 0); + m_switchRect.push_back(genRect); + + return false; + } + // Second bus. + else if(parent != m_parentList[0]) { + 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. + + // Get the average between the two bus points. + m_position = + wxPoint2DDouble((m_pointList[0].m_x + parentPt.m_x) / 2.0, (m_pointList[0].m_y + parentPt.m_y) / 2.0); + // Set the transformer rectangle. + m_width = 70.0; + m_height = 40.0; + m_rect = wxRect2DDouble(m_position.m_x - m_width / 2.0, m_position.m_y - m_height / 2.0, m_width, m_height); + // Set the "side" points. + m_pointList.push_back(wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(-10, m_height / 2.0))); + m_pointList.push_back( + wxPoint2DDouble(m_rect.GetPosition() + wxPoint2DDouble(m_width + 10, m_height / 2.0))); + + // Set first switch point. + wxPoint2DDouble secondPoint = parentPt; + if(m_pointList.size() > 2) { + secondPoint = m_pointList[2]; + } + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], secondPoint); + + // Set the second switch point. + m_pointList.push_back(GetSwitchPoint(parent, parentPt, m_pointList[m_pointList.size() - 1])); + + m_pointList.push_back(parentPt); // Last point. + m_inserted = true; + + wxRect2DDouble genRect(0, 0, 0, 0); + m_switchRect.push_back(genRect); + UpdateSwitches(); + + return true; + } + } return false; } @@ -76,70 +75,70 @@ bool Transformer::Contains(wxPoint2DDouble position) const void Transformer::Draw(wxPoint2DDouble translation, double scale) const { if(m_inserted) { - // Draw selection (layer 1). - if(m_selected) { - // Push the current matrix on stack. - glLineWidth(1.5 + m_borderSize * 2.0); - glColor4d(0.0, 0.5, 1.0, 0.5); - DrawLine(m_pointList); - glPushMatrix(); - // Rotate the matrix around the object position. - glTranslated(m_position.m_x, m_position.m_y, 0.0); - glRotated(m_angle, 0.0, 0.0, 1.0); - glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - - DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, - 20, GL_POLYGON); - DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, - 20, GL_POLYGON); - - glPopMatrix(); - - // Draw nodes selection. - if(m_pointList.size() > 0) { - DrawCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, GL_POLYGON); - if(m_inserted) { - DrawCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize / scale, 10, GL_POLYGON); - } - } - } - - // Draw transformer (layer 2). - // Transformer line - glLineWidth(1.5); - glColor4d(0.2, 0.2, 0.2, 1.0); - DrawLine(m_pointList); - - // Draw nodes. - if(m_pointList.size() > 0) { - glColor4d(0.2, 0.2, 0.2, 1.0); - DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); - if(m_inserted) { - DrawCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, GL_POLYGON); - } - } - - DrawSwitches(); - - // Push the current matrix on stack. - glPushMatrix(); - // Rotate the matrix around the object position. - glTranslated(m_position.m_x, m_position.m_y, 0.0); - glRotated(m_angle, 0.0, 0.0, 1.0); - glTranslated(-m_position.m_x, -m_position.m_y, 0.0); - - glColor4d(1.0, 1.0, 1.0, 1.0); - DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, GL_POLYGON); - DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, GL_POLYGON); - - glColor4d(0.2, 0.2, 0.2, 1.0); - DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20); - DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20); - - DrawPoint(m_rect.GetPosition(), 8.0 * scale); - - glPopMatrix(); - } + // Draw selection (layer 1). + if(m_selected) { + // Push the current matrix on stack. + glLineWidth(1.5 + m_borderSize * 2.0); + glColor4d(0.0, 0.5, 1.0, 0.5); + DrawLine(m_pointList); + glPushMatrix(); + // Rotate the matrix around the object position. + glTranslated(m_position.m_x, m_position.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-m_position.m_x, -m_position.m_y, 0.0); + + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20 + (m_borderSize + 1.5) / scale, 20, + GL_POLYGON); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20 + (m_borderSize + 1.5) / scale, 20, + GL_POLYGON); + + glPopMatrix(); + + // Draw nodes selection. + if(m_pointList.size() > 0) { + DrawCircle(m_pointList[0], 5.0 + m_borderSize / scale, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0 + m_borderSize / scale, 10, GL_POLYGON); + } + } + } + + // Draw transformer (layer 2). + // Transformer line + glLineWidth(1.5); + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawLine(m_pointList); + + // Draw nodes. + if(m_pointList.size() > 0) { + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_pointList[0], 5.0, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(m_pointList[m_pointList.size() - 1], 5.0, 10, GL_POLYGON); + } + } + + DrawSwitches(); + + // Push the current matrix on stack. + glPushMatrix(); + // Rotate the matrix around the object position. + glTranslated(m_position.m_x, m_position.m_y, 0.0); + glRotated(m_angle, 0.0, 0.0, 1.0); + glTranslated(-m_position.m_x, -m_position.m_y, 0.0); + + glColor4d(1.0, 1.0, 1.0, 1.0); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20, GL_POLYGON); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20, GL_POLYGON); + + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(20.0, 20.0), 20, 20); + DrawCircle(m_rect.GetPosition() + wxPoint2DDouble(50.0, 20.0), 20, 20); + + DrawPoint(m_rect.GetPosition(), 8.0 * scale); + + glPopMatrix(); + } } bool Transformer::Intersects(wxRect2DDouble rect) const @@ -150,16 +149,16 @@ bool Transformer::Intersects(wxRect2DDouble rect) const void Transformer::Rotate(bool clockwise) { - double rotAngle = m_rotationAngle; - if(!clockwise) rotAngle = -m_rotationAngle; - + double rotAngle = m_rotationAngle; + if(!clockwise) rotAngle = -m_rotationAngle; + m_angle += rotAngle; if(m_angle >= 360.0) m_angle = 0.0; // Rotate all the points, except the switches and buses points. for(int i = 2; i < (int)m_pointList.size() - 2; i++) { - m_pointList[i] = RotateAtPosition(m_pointList[i], rotAngle); - } + m_pointList[i] = RotateAtPosition(m_pointList[i], rotAngle); + } } void Transformer::Move(wxPoint2DDouble position) @@ -168,15 +167,15 @@ void Transformer::Move(wxPoint2DDouble position) // Move all the points, except the switches and buses points. for(int i = 2; i < (int)m_pointList.size() - 2; i++) { - m_pointList[i] = m_movePts[i] + 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; - } + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } if(!m_parentList[1]) { - m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; - } + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + } UpdateSwitchesPosition(); } @@ -184,30 +183,25 @@ void Transformer::Move(wxPoint2DDouble position) void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) { if(parent) { - // First bus. - if(parent == m_parentList[0]) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - } - // Second bus. - else if(parent == m_parentList[1]) - { - m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; - } - } - else - { - if(m_activeNodeID == 1) { - m_pointList[0] = m_movePts[0] + position - m_moveStartPt; - 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; - } - } + // First bus. + if(parent == m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + } + // Second bus. + else if(parent == m_parentList[1]) { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + } + } else { + if(m_activeNodeID == 1) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + 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; + } + } // Recalculate switches positions UpdateSwitchesPosition(); @@ -223,7 +217,7 @@ void Transformer::StartMove(wxPoint2DDouble position) bool Transformer::GetContextMenu(wxMenu& menu) { menu.Append(ID_EDIT_TRANSFORMER, _("Edit tranformer")); - GeneralMenuItens(menu); + GeneralMenuItens(menu); return true; } @@ -231,9 +225,9 @@ bool Transformer::ShowForm(wxWindow* parent, Element* element) { TransformerForm* transfForm = new TransformerForm(parent, this); if(transfForm->ShowModal() == wxID_OK) { - transfForm->Destroy(); - return true; - } + transfForm->Destroy(); + return true; + } transfForm->Destroy(); return false; } @@ -243,8 +237,7 @@ void Transformer::SetNominalVoltage(std::vector nominalVoltage, std::vec if(nominalVoltage.size() == 1) { m_electricalData.primaryNominalVoltage = nominalVoltage[0]; m_electricalData.primaryNominalVoltageUnit = nominalVoltageUnit[0]; - } - else if(nominalVoltage.size() == 2) { + } else if(nominalVoltage.size() == 2) { m_electricalData.primaryNominalVoltage = nominalVoltage[0]; m_electricalData.primaryNominalVoltageUnit = nominalVoltageUnit[0]; m_electricalData.secondaryNominalVoltage = nominalVoltage[1]; -- 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/Transformer.cpp | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 57614bb..8ebf4f3 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -59,6 +59,7 @@ bool Transformer::AddParent(Element* parent, wxPoint2DDouble position) wxRect2DDouble genRect(0, 0, 0, 0); m_switchRect.push_back(genRect); UpdateSwitches(); + UpdatePowerFlowArrowsPosition(); return true; } @@ -119,6 +120,7 @@ void Transformer::Draw(wxPoint2DDouble translation, double scale) const } DrawSwitches(); + DrawPowerFlowPts(); // Push the current matrix on stack. glPushMatrix(); @@ -159,6 +161,8 @@ void Transformer::Rotate(bool clockwise) for(int i = 2; i < (int)m_pointList.size() - 2; i++) { m_pointList[i] = RotateAtPosition(m_pointList[i], rotAngle); } + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Transformer::Move(wxPoint2DDouble position) @@ -178,6 +182,7 @@ void Transformer::Move(wxPoint2DDouble position) } UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) @@ -205,6 +210,7 @@ void Transformer::MoveNode(Element* parent, wxPoint2DDouble position) // Recalculate switches positions UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); } void Transformer::StartMove(wxPoint2DDouble position) @@ -244,3 +250,110 @@ void Transformer::SetNominalVoltage(std::vector nominalVoltage, std::vec m_electricalData.secondaryNominalVoltageUnit = nominalVoltageUnit[1]; } } + +void Transformer::UpdatePowerFlowArrowsPosition() +{ + std::vector edges; + switch(m_pfDirection) { + case PF_NONE: { + m_powerFlowArrow.clear(); + } break; + case PF_BUS1_TO_BUS2: { + for(int i = 1; i < (int)m_pointList.size() - 1; i++) { + edges.push_back(m_pointList[i]); + } + } break; + case PF_BUS2_TO_BUS1: { + for(int i = (int)m_pointList.size() - 2; i > 0; i--) { + edges.push_back(m_pointList[i]); + } + } break; + default: + break; + } + CalculatePowerFlowPts(edges); +} + +void Transformer::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], rotAngle); + } + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = + parent->RotateAtPosition(m_pointList[m_pointList.size() - 1], rotAngle); + } + UpdateSwitchesPosition(); + UpdatePowerFlowArrowsPosition(); +} + +bool Transformer::SetNodeParent(Element* parent) +{ + if(m_activeNodeID == 1 && parent == m_parentList[0]) return false; + 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(); + UpdatePowerFlowArrowsPosition(); + 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(); + UpdatePowerFlowArrowsPosition(); + return true; + } + } + else + { + if(m_activeNodeID == 1) m_parentList[0] = NULL; + if(m_activeNodeID == 2) m_parentList[1] = NULL; + } + } + return false; +} -- 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/Transformer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Project/Transformer.cpp') diff --git a/Project/Transformer.cpp b/Project/Transformer.cpp index 8ebf4f3..93013e0 100644 --- a/Project/Transformer.cpp +++ b/Project/Transformer.cpp @@ -357,3 +357,9 @@ bool Transformer::SetNodeParent(Element* parent) } return false; } + +void Transformer::SetPowerFlowDirection(PowerFlowDirection pfDirection) +{ + m_pfDirection = pfDirection; + UpdatePowerFlowArrowsPosition(); +} -- cgit