From 06e57f5c75772dcba902e3032c756f79090f3424 Mon Sep 17 00:00:00 2001 From: Thales1330 Date: Mon, 29 Aug 2016 17:26:50 -0300 Subject: Delete implemented --- .codelite/.tern-port | 2 +- .codelite/PSP.session | 20 ++++++------ .codelite/PSP.tags | Bin 80476160 -> 80476160 bytes .codelite/compilation.db | Bin 24576 -> 24576 bytes .codelite/compile_commands.json | 8 +++++ .codelite/refactoring.db | Bin 520192 -> 531456 bytes Project/Bus.cpp | 1 + Project/Element.h | 4 ++- Project/Line.cpp | 11 +++++++ Project/Line.h | 1 + Project/Project.mk | 2 +- Project/Release/Bus.cpp.o | Bin 28972 -> 30860 bytes Project/Release/Element.cpp.o | Bin 14070 -> 14638 bytes Project/Release/Line.cpp.o | Bin 39241 -> 40746 bytes Project/Release/PSP-UFU.exe | Bin 3290651 -> 3294109 bytes Project/Release/Workspace.cpp.o | Bin 114623 -> 117977 bytes Project/Workspace.cpp | 66 ++++++++++++++++++++++++++++++++++++---- Project/Workspace.h | 1 + 18 files changed, 97 insertions(+), 19 deletions(-) diff --git a/.codelite/.tern-port b/.codelite/.tern-port index a40d0e4..980fde0 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -57419 \ No newline at end of file +50602 \ No newline at end of file diff --git a/.codelite/PSP.session b/.codelite/PSP.session index 6ec6b04..7fdc807 100644 --- a/.codelite/PSP.session +++ b/.codelite/PSP.session @@ -1,26 +1,26 @@ - + - - + + - + - + @@ -40,22 +40,22 @@ - - + + - + - - + + diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags index 6c8329c..08ab4a5 100644 Binary files a/.codelite/PSP.tags and b/.codelite/PSP.tags differ diff --git a/.codelite/compilation.db b/.codelite/compilation.db index 00c5615..a974fb2 100644 Binary files a/.codelite/compilation.db and b/.codelite/compilation.db differ diff --git a/.codelite/compile_commands.json b/.codelite/compile_commands.json index 6269964..f71231e 100644 --- a/.codelite/compile_commands.json +++ b/.codelite/compile_commands.json @@ -1,7 +1,15 @@ [{ + "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", + "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/Bus.cpp.o -MF./Release/Bus.cpp.o.d -MM Bus.cpp", + "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Bus.cpp" + }, { "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", "command": "C:/TDM-GCC-64/bin/g++.exe -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -I. -I. -MG -MP -MT./Release/Line.cpp.o -MF./Release/Line.cpp.o.d -MM Line.cpp", "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Line.cpp" + }, { + "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", + "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/Bus.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/Bus.cpp.o -I. -I.", + "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Bus.cpp" }, { "directory": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project", "command": "C:/TDM-GCC-64/bin/g++.exe -c C:/Users/Thales/Documents/GitHub/PSP/Project/Line.cpp -O2 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -DNDEBUG -D_UNICODE -IC:/wxWidgets-3.1.0/lib/gcc_dll/mswu -IC:/wxWidgets-3.1.0/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -std=c++11 -DNDEBUG -DUNICODE -o ./Release/Line.cpp.o -I. -I.", diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db index 9e05231..38f07df 100644 Binary files a/.codelite/refactoring.db and b/.codelite/refactoring.db differ diff --git a/Project/Bus.cpp b/Project/Bus.cpp index 847308d..b2f1ff1 100644 --- a/Project/Bus.cpp +++ b/Project/Bus.cpp @@ -225,5 +225,6 @@ bool Bus::GetContextMenu(wxMenu& menu) { menu.Append(ID_EDIT_BUS, _("Edit bus")); menu.Append(ID_ROTATE, _("Rotate")); + menu.Append(ID_DELETE, _("Delete bus")); return true; } diff --git a/Project/Element.h b/Project/Element.h index bccd993..ec7496a 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -25,7 +25,8 @@ enum ContextMenuID ID_LINE_ADD_NODE, ID_LINE_REMOVE_NODE, - ID_ROTATE + ID_ROTATE, + ID_DELETE }; class Element @@ -71,6 +72,7 @@ class Element virtual bool NodeContains(wxPoint2DDouble position) { return false; } virtual void UpdateNodes() {} virtual bool SetNodeParent(Element* parent) { return false; } + virtual void RemoveParent(Element* parent) {} virtual void RotateNode(Element* parent) {} virtual wxPoint2DDouble GetSwitchPoint(Element* parent, wxPoint2DDouble parentPoint, diff --git a/Project/Line.cpp b/Project/Line.cpp index 0cc5d11..6c5457e 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -284,6 +284,7 @@ bool Line::GetContextMenu(wxMenu& menu) { menu.Append(ID_LINE_REMOVE_NODE, _("Remove node")); } + menu.Append(ID_DELETE, _("Delete line")); return true; } @@ -419,3 +420,13 @@ void Line::UpdateNodes() } } } + +void Line::RemoveParent(Element* parent) +{ + for(int i=0; i<2; i++) { + if(parent == m_parentList[i]) { + m_parentList[i] = NULL; + UpdateSwitchesPosition(); + } + } +} diff --git a/Project/Line.h b/Project/Line.h index 596b1a4..983293a 100644 --- a/Project/Line.h +++ b/Project/Line.h @@ -17,6 +17,7 @@ class Line : public Element virtual void MoveNode(Element* parent, wxPoint2DDouble position); virtual bool NodeContains(wxPoint2DDouble position); virtual bool SetNodeParent(Element* parent); + virtual void RemoveParent(Element* parent); virtual void UpdateNodes(); virtual wxCursor GetBestPickboxCursor() const { return wxCURSOR_SIZING; } virtual bool AddParent(Element* parent, wxPoint2DDouble position); diff --git a/Project/Project.mk b/Project/Project.mk index 5053587..e221228 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=25/08/2016 +Date :=29/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 index b51f1c5..8774df4 100644 Binary files a/Project/Release/Bus.cpp.o and b/Project/Release/Bus.cpp.o differ diff --git a/Project/Release/Element.cpp.o b/Project/Release/Element.cpp.o index e306643..9080983 100644 Binary files a/Project/Release/Element.cpp.o and b/Project/Release/Element.cpp.o differ diff --git a/Project/Release/Line.cpp.o b/Project/Release/Line.cpp.o index 8f96b12..80137cf 100644 Binary files a/Project/Release/Line.cpp.o and b/Project/Release/Line.cpp.o differ diff --git a/Project/Release/PSP-UFU.exe b/Project/Release/PSP-UFU.exe index 1515590..2790ce1 100644 Binary files a/Project/Release/PSP-UFU.exe and b/Project/Release/PSP-UFU.exe differ diff --git a/Project/Release/Workspace.cpp.o b/Project/Release/Workspace.cpp.o index 96bf767..2b551da 100644 Binary files a/Project/Release/Workspace.cpp.o and b/Project/Release/Workspace.cpp.o differ diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 22d3858..10e58d3 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -226,14 +226,21 @@ void Workspace::OnRightClickDown(wxMouseEvent& event) menu.Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Workspace::OnPopupClick), NULL, this); PopupMenu(&menu); + redraw = true; } element->ResetPickboxes(); - redraw = true; + + if(redraw){ + Redraw(); + redraw = false; + } + // If the last element was removed using the menu, we must leave the "search for" to prevent error. + break; } } + } } - if(redraw) Redraw(); } void Workspace::OnLeftClickUp(wxMouseEvent& event) @@ -507,6 +514,28 @@ void Workspace::OnKeyDown(wxKeyEvent& event) } } break; + case WXK_DELETE: // Delete selected elements + { + for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { + Element* element = *it; + + if(element->IsSelected()) { + for(auto itp = m_elementList.begin(); itp != m_elementList.end(); ++itp) { + Element* child = *itp; + // Parent's element being deleted... + for(int i = 0; i < (int)child->GetParentList().size(); i++) { + Element* parent = child->GetParentList()[i]; + if(parent == element) { + child->RemoveParent(parent); + } + } + } + m_elementList.erase(it--); + } + } + Redraw(); + } + break; case 'R': // Rotate the selected elements. { for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { @@ -626,17 +655,42 @@ void Workspace::OnPopupClick(wxCommandEvent& event) { element->Rotate(); for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { - Element* nonEditedElement = *it; + Element* iElement = *it; // Parent's element rotating... - for(int i = 0; i < (int)nonEditedElement->GetParentList().size(); i++) { - Element* parent = nonEditedElement->GetParentList()[i]; + for(int i = 0; i < (int)iElement->GetParentList().size(); i++) { + Element* parent = iElement->GetParentList()[i]; if(parent == element) { - nonEditedElement->RotateNode(parent); + iElement->RotateNode(parent); } } } Redraw(); } break; + case ID_DELETE: + { + for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { + Element* iElement = *it; + + if(element == iElement) { + for(auto itp = m_elementList.begin(); itp != m_elementList.end(); ++itp) { + Element* child = *itp; + // Parent's element being deleted... + for(int i = 0; i < (int)child->GetParentList().size(); i++) { + Element* parent = child->GetParentList()[i]; + if(parent == element) { + child->RemoveParent(parent); + } + } + } + m_elementList.erase(it--); + } + } + Redraw(); + } + break; } + delete menu; } + +void Workspace::DeleteElement(Element* element) {} diff --git a/Project/Workspace.h b/Project/Workspace.h index 3f25130..d6e1803 100644 --- a/Project/Workspace.h +++ b/Project/Workspace.h @@ -36,6 +36,7 @@ class Workspace : public WorkspaceBase void SetName(wxString name) { m_name = name; } std::vector GetElementList() { return m_elementList; } void Redraw() { m_glCanvas->Refresh(); } + void DeleteElement(Element* element); protected: virtual void OnRightClickDown(wxMouseEvent& event); -- cgit