diff options
Diffstat (limited to 'Project')
-rw-r--r-- | Project/Line.cpp | 43 | ||||
-rw-r--r-- | Project/Line.h | 4 | ||||
-rw-r--r-- | Project/Project.mk | 2 | ||||
-rw-r--r-- | Project/Release/Line.cpp.o | bin | 29756 -> 35021 bytes | |||
-rw-r--r-- | Project/Release/PSP-UFU.exe | bin | 3277391 -> 3281466 bytes | |||
-rw-r--r-- | Project/Release/Workspace.cpp.o | bin | 110214 -> 110488 bytes | |||
-rw-r--r-- | Project/Workspace.cpp | 22 |
7 files changed, 62 insertions, 9 deletions
diff --git a/Project/Line.cpp b/Project/Line.cpp index 54418d4..6710fbe 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -32,7 +32,7 @@ void Line::Draw(wxPoint2DDouble translation, double scale) const if(pointList.size() > 0) { DrawCircle(pointList[0], 5.0 + m_borderSize, 10, GL_POLYGON); if(m_inserted) { - DrawCircle(pointList[pointList.size() - 1], 5.0 + +m_borderSize, 10, GL_POLYGON); + DrawCircle(pointList[pointList.size() - 1], 5.0 + m_borderSize, 10, GL_POLYGON); } } } @@ -120,7 +120,7 @@ void Line::MovePickbox(wxPoint2DDouble position) for(int i = 2; i < (int)m_pointList.size() - 2; i++) { if(m_activePickboxID == i) { m_pointList[i] = m_movePts[i] + position - m_moveStartPt; - UpdateSwitchesPosition(); + UpdateSwitchesPosition(); } } } @@ -191,7 +191,7 @@ void Line::UpdateSwitchesPosition() GetSwitchPoint(m_parentList[1], m_pointList[m_pointList.size() - 1], m_pointList[m_pointList.size() - 3]); } -double Line::PointToLineDistance(wxPoint2DDouble point) const +double Line::PointToLineDistance(wxPoint2DDouble point, int* segmentNumber) const { //[Ref] http://geomalgorithms.com/a02-_lines.html double distance = 100.0; // Big initial distance. @@ -222,7 +222,10 @@ double Line::PointToLineDistance(wxPoint2DDouble point) const p2.m_y * p1.m_x) / std::sqrt(std::pow(p2.m_y - p1.m_y, 2) + std::pow(p2.m_x - p1.m_x, 2)); } - if(d < distance) distance = d; + if(d < distance) { + distance = d; + if(segmentNumber) *segmentNumber = i; + } } return distance; @@ -230,6 +233,34 @@ double Line::PointToLineDistance(wxPoint2DDouble point) const bool Line::GetContextMenu(wxMenu& menu) { - menu.Append(ID_EDIT_LINE, _("Edit line")); - return true; + menu.Append(ID_EDIT_LINE, _("Edit line")); + if(m_activePickboxID == ID_PB_NONE) { + menu.Append(ID_LINE_ADD_NODE, _("Insert node")); + } + else + { + menu.Append(ID_LINE_REMOVE_NODE, _("Remove node")); + } + return true; +} + +void Line::RemoveNode(wxPoint2DDouble point) +{ + if(PickboxContains(point)) { + for(int i = 2; i < (int)m_pointList.size() - 2; i++) { + if(m_activePickboxID == i) { + m_pointList.erase(m_pointList.begin() + i); + break; + } + } + } +} + +void Line::AddNode(wxPoint2DDouble point) +{ + int segmentNumber = 0; + PointToLineDistance(point, &segmentNumber); + if(segmentNumber > 0 && segmentNumber < (int)m_pointList.size() - 2) { + m_pointList.insert(m_pointList.begin() + segmentNumber + 1, point); + } } diff --git a/Project/Line.h b/Project/Line.h index 08a2b36..9293baa 100644 --- a/Project/Line.h +++ b/Project/Line.h @@ -24,10 +24,12 @@ class Line : public Element 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); protected: void UpdateSwitchesPosition(); - double PointToLineDistance(wxPoint2DDouble point) const; + double PointToLineDistance(wxPoint2DDouble point, int* segmentNumber = NULL) const; std::vector<wxPoint2DDouble> m_pointList; bool m_inserted = false; std::vector<wxPoint2DDouble> m_movePts; diff --git a/Project/Project.mk b/Project/Project.mk index e5e39f0..5c5c3b1 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=18/08/2016 +Date :=19/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/Line.cpp.o b/Project/Release/Line.cpp.o Binary files differindex 587e66d..6717cee 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 04fb13d..604327e 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 9d4cb18..a3a3cfa 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 26c913b..d180b2b 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -202,11 +202,13 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event) void Workspace::OnRightClickDown(wxMouseEvent& event) { + bool redraw = false; if(m_mode == MODE_EDIT) { for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* element = *it; if(element->IsSelected()) { if(element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + element->ShowPickbox(false); wxMenu menu; if(element->GetContextMenu(menu)) { menu.SetClientData(element); @@ -214,10 +216,13 @@ void Workspace::OnRightClickDown(wxMouseEvent& event) wxCommandEventHandler(Workspace::OnPopupClick), NULL, this); PopupMenu(&menu); } + element->ResetPickboxes(); + redraw = true; } } } } + if(redraw) Redraw(); } void Workspace::OnLeftClickUp(wxMouseEvent& event) @@ -520,9 +525,23 @@ void Workspace::OnPopupClick(wxCommandEvent& event) wxMessageBox("Edit line!"); } break; + case ID_LINE_ADD_NODE: + { + Line* line = (Line*)element; + line->AddNode(m_camera->GetMousePosition()); + Redraw(); + } + break; + case ID_LINE_REMOVE_NODE: + { + Line* line = (Line*)element; + line->RemoveNode(m_camera->GetMousePosition()); + Redraw(); + } + break; case ID_ROTATE: { - element->Rotate(); + element->Rotate(); for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* nonEditedElement = *it; // Parent's element rotating... @@ -535,5 +554,6 @@ void Workspace::OnPopupClick(wxCommandEvent& event) } Redraw(); } + break; } } |