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/Line.cpp | 153 +------------------------------------------------------ 1 file changed, 1 insertion(+), 152 deletions(-) (limited to 'Project/Line.cpp') diff --git a/Project/Line.cpp b/Project/Line.cpp index f26b6f6..5fd6c86 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -1,6 +1,6 @@ #include "Line.h" -Line::Line() {} +Line::Line() : Branch() {} Line::~Line() {} bool Line::Contains(wxPoint2DDouble position) const { @@ -152,18 +152,6 @@ bool Line::PickboxContains(wxPoint2DDouble position) } return false; } -void Line::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(); -} void Line::AddPoint(wxPoint2DDouble point) { @@ -215,25 +203,6 @@ void Line::MoveNode(Element* parent, wxPoint2DDouble position) UpdateSwitchesPosition(); } -void Line::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]; - } -} - double Line::PointToLineDistance(wxPoint2DDouble point, int* segmentNumber) const { //[Ref] http://geomalgorithms.com/a02-_lines.html @@ -310,123 +279,3 @@ void Line::AddNode(wxPoint2DDouble point) } UpdateSwitchesPosition(); } - -bool Line::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 Line::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; - } - } - // m_activeNodeID = 0; - return false; -} - -void Line::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 Line::RemoveParent(Element* parent) -{ - for(int i=0; i<2; i++) { - if(parent == m_parentList[i]) { - m_parentList[i] = NULL; - UpdateSwitchesPosition(); - } - } -} -- cgit