diff options
Diffstat (limited to 'Project')
-rw-r--r-- | Project/Element.h | 7 | ||||
-rw-r--r-- | Project/Line.cpp | 74 | ||||
-rw-r--r-- | Project/Line.h | 27 | ||||
-rw-r--r-- | Project/Project.mk | 2 | ||||
-rw-r--r-- | Project/Release/Bus.cpp.o | bin | 28409 -> 28972 bytes | |||
-rw-r--r-- | Project/Release/Element.cpp.o | bin | 13507 -> 14070 bytes | |||
-rw-r--r-- | Project/Release/Line.cpp.o | bin | 37471 -> 39241 bytes | |||
-rw-r--r-- | Project/Release/PSP-UFU.exe | bin | 3287771 -> 3290651 bytes | |||
-rw-r--r-- | Project/Release/Workspace.cpp.o | bin | 113675 -> 114623 bytes | |||
-rw-r--r-- | Project/Workspace.cpp | 34 |
10 files changed, 112 insertions, 32 deletions
diff --git a/Project/Element.h b/Project/Element.h index 0b2d4be..bccd993 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -67,9 +67,10 @@ class Element virtual void AddPoint(wxPoint2DDouble point) {} virtual void StartMove(wxPoint2DDouble position); virtual void Move(wxPoint2DDouble position); - virtual void MoveNode(Element* parent, wxPoint2DDouble position){}; - virtual bool NodeContains(wxPoint2DDouble position) { return false; }; - virtual bool SetNodeParent(Element* parent) { return false; }; + virtual void MoveNode(Element* parent, wxPoint2DDouble position){} + virtual bool NodeContains(wxPoint2DDouble position) { return false; } + virtual void UpdateNodes() {} + virtual bool SetNodeParent(Element* parent) { return false; } virtual void RotateNode(Element* parent) {} virtual wxPoint2DDouble GetSwitchPoint(Element* parent, wxPoint2DDouble parentPoint, diff --git a/Project/Line.cpp b/Project/Line.cpp index 8b17ade..0cc5d11 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -64,7 +64,24 @@ void Line::Draw(wxPoint2DDouble translation, double scale) const } } -wxCursor Line::GetBestPickboxCursor() const { return wxCURSOR_SIZING; } +void Line::Move(wxPoint2DDouble position) +{ + if(!m_parentList[0]) { + m_pointList[0] = m_movePts[0] + position - m_moveStartPt; + UpdateSwitchesPosition(); + } + if(!m_parentList[1]) { + m_pointList[m_pointList.size() - 1] = m_movePts[m_pointList.size() - 1] + position - m_moveStartPt; + UpdateSwitchesPosition(); + } + + if(!m_parentList[0] && !m_parentList[1]) { + for(int i = 2; i < (int)m_pointList.size() - 2; i++) { + m_pointList[i] = m_movePts[i] + position - m_moveStartPt; + } + } +} + bool Line::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { @@ -334,22 +351,38 @@ bool Line::SetNodeParent(Element* parent) if(parent->Intersects(nodeRect)) { if(m_activeNodeID == 1) { - // if(m_parentList[1] == parent){ - // m_activeNodeID = 0; - // return false; - //} + // 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; - //} + 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; } @@ -363,3 +396,26 @@ bool Line::SetNodeParent(Element* parent) // 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(); + } + } +} diff --git a/Project/Line.h b/Project/Line.h index 7374e29..596b1a4 100644 --- a/Project/Line.h +++ b/Project/Line.h @@ -12,29 +12,30 @@ class Line : public Element ~Line(); virtual bool Contains(wxPoint2DDouble position) const; virtual void Draw(wxPoint2DDouble translation, double scale) const; - virtual void Move(wxPoint2DDouble position) {} - virtual void StartMove(wxPoint2DDouble position); + virtual void Move(wxPoint2DDouble position); + virtual void StartMove(wxPoint2DDouble position); virtual void MoveNode(Element* parent, wxPoint2DDouble position); - virtual bool NodeContains(wxPoint2DDouble position); - virtual bool SetNodeParent(Element* parent); - virtual wxCursor GetBestPickboxCursor() const; + virtual bool NodeContains(wxPoint2DDouble position); + virtual bool SetNodeParent(Element* parent); + virtual void UpdateNodes(); + virtual wxCursor GetBestPickboxCursor() const { return wxCURSOR_SIZING; } virtual bool AddParent(Element* parent, wxPoint2DDouble position); virtual bool Intersects(wxRect2DDouble rect) const; virtual void MovePickbox(wxPoint2DDouble position); virtual bool PickboxContains(wxPoint2DDouble position); virtual void Rotate() {} - virtual void RotateNode(Element* parent); + virtual void RotateNode(Element* parent); virtual void AddPoint(wxPoint2DDouble point); - virtual bool GetContextMenu(wxMenu& menu); - virtual void RemoveNode(wxPoint2DDouble point); - virtual void AddNode(wxPoint2DDouble point); + virtual bool GetContextMenu(wxMenu& menu); + virtual void RemoveNode(wxPoint2DDouble point); + virtual void AddNode(wxPoint2DDouble point); -protected: - void UpdateSwitchesPosition(); - double PointToLineDistance(wxPoint2DDouble point, int* segmentNumber = NULL) const; + protected: + void UpdateSwitchesPosition(); + double PointToLineDistance(wxPoint2DDouble point, int* segmentNumber = NULL) const; std::vector<wxPoint2DDouble> m_pointList; bool m_inserted = false; - std::vector<wxPoint2DDouble> m_movePts; + std::vector<wxPoint2DDouble> m_movePts; }; #endif // LINE_H diff --git a/Project/Project.mk b/Project/Project.mk index 7bc77fb..5053587 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=24/08/2016 +Date :=25/08/2016 CodeLitePath :="C:/Program Files/CodeLite" LinkerName :=C:/TDM-GCC-64/bin/g++.exe SharedObjectLinkerName :=C:/TDM-GCC-64/bin/g++.exe -shared -fPIC diff --git a/Project/Release/Bus.cpp.o b/Project/Release/Bus.cpp.o Binary files differindex 0f40d0a..b51f1c5 100644 --- a/Project/Release/Bus.cpp.o +++ b/Project/Release/Bus.cpp.o diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o Binary files differindex 5c4b04c..e306643 100644 --- a/Project/Release/Element.cpp.o +++ b/Project/Release/Element.cpp.o diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o Binary files differindex 327c980..8f96b12 100644 --- a/Project/Release/Line.cpp.o +++ b/Project/Release/Line.cpp.o diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe Binary files differindex 64a92de..1515590 100644 --- a/Project/Release/PSP-UFU.exe +++ b/Project/Release/PSP-UFU.exe diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o Binary files differindex 99752d1..96bf767 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 68e8464..22d3858 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -247,6 +247,27 @@ void Workspace::OnLeftClickUp(wxMouseEvent& event) for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* element = *it; + // The user was moving a pickbox. + if(m_mode == MODE_MOVE_PICKBOX) { + // Catch only the element that have the pickbox shown. + if(element->IsPickboxShown()) { + // If the element is a bus, check if a node is outside. + if(typeid(*element) == typeid(Bus)) { + // Get all the bus children. + for(int i = 0; i < (int)m_elementList.size(); i++) { + Element* child = m_elementList[i]; + for(int j = 0; j < (int)child->GetParentList().size(); j++) { + Element* parent = child->GetParentList()[j]; + // The child have a parent that is the element. + if(parent == element) { + child->UpdateNodes(); + } + } + } + } + } + } + if(m_mode == MODE_SELECTION_RECT) { if(element->Intersects(m_selectionRect)) { element->SetSelected(); @@ -393,9 +414,10 @@ void Workspace::OnMouseMotion(wxMouseEvent& event) // Parent's element moving... for(int i = 0; i < (int)element->GetParentList().size(); i++) { Element* parent = element->GetParentList()[i]; - if(parent) { - if(parent->IsSelected()) { - element->MoveNode(parent, m_camera->ScreenToWorld(event.GetPosition())); + if(parent) { + if(parent->IsSelected()) { + element->MoveNode(parent, + m_camera->ScreenToWorld(event.GetPosition())); } } } @@ -492,9 +514,9 @@ void Workspace::OnKeyDown(wxKeyEvent& event) // Parent's element rotating... for(int i = 0; i < (int)element->GetParentList().size(); i++) { Element* parent = element->GetParentList()[i]; - if(parent) { // Check if parent is not null - if(parent->IsSelected()) { - element->RotateNode(parent); + if(parent) { // Check if parent is not null + if(parent->IsSelected()) { + element->RotateNode(parent); } } } |