diff options
-rw-r--r-- | .codelite/.tern-port | 2 | ||||
-rw-r--r-- | .codelite/PSP.session | 26 | ||||
-rw-r--r-- | .codelite/PSP.tags | bin | 80431104 -> 80438272 bytes | |||
-rw-r--r-- | .codelite/compilation.db | bin | 24576 -> 24576 bytes | |||
-rw-r--r-- | .codelite/compile_commands.json | 4 | ||||
-rw-r--r-- | .codelite/refactoring.db | bin | 416768 -> 424960 bytes | |||
-rw-r--r-- | Project/Element.cpp | 38 | ||||
-rw-r--r-- | Project/Element.h | 41 | ||||
-rw-r--r-- | Project/Line.cpp | 72 | ||||
-rw-r--r-- | Project/Line.h | 5 | ||||
-rw-r--r-- | Project/Project.mk | 2 | ||||
-rw-r--r-- | Project/Release/Bus.cpp.o | bin | 15853 -> 19467 bytes | |||
-rw-r--r-- | Project/Release/Element.cpp.o | bin | 5581 -> 10291 bytes | |||
-rw-r--r-- | Project/Release/Line.cpp.o | bin | 12836 -> 21187 bytes | |||
-rw-r--r-- | Project/Release/PSP-UFU.exe | bin | 3249482 -> 3257480 bytes | |||
-rw-r--r-- | Project/Release/Workspace.cpp.o | bin | 93816 -> 94521 bytes | |||
-rw-r--r-- | Project/Release/wxmsw310u_gcc_64x.dll (renamed from Project/Release/wxmsw310u_gcc_cl.dll) | bin | 27581981 -> 27581981 bytes | |||
-rw-r--r-- | Project/Release/wxmsw310u_gcc_custom.dll | bin | 27581981 -> 0 bytes | |||
-rw-r--r-- | Project/Release/wxmsw310u_gl_gcc_64x.dll (renamed from Project/Release/wxmsw310u_gl_gcc_cl.dll) | bin | 2634304 -> 2634306 bytes | |||
-rw-r--r-- | Project/Release/wxmsw310u_gl_gcc_custom.dll | bin | 2634312 -> 0 bytes | |||
-rw-r--r-- | Project/Workspace.cpp | 32 |
21 files changed, 172 insertions, 50 deletions
diff --git a/.codelite/.tern-port b/.codelite/.tern-port index 2deb3ef..e023d6b 100644 --- a/.codelite/.tern-port +++ b/.codelite/.tern-port @@ -1 +1 @@ -49674
\ No newline at end of file +60403
\ No newline at end of file diff --git a/.codelite/PSP.session b/.codelite/PSP.session index fef011c..e683af5 100644 --- a/.codelite/PSP.session +++ b/.codelite/PSP.session @@ -5,57 +5,57 @@ <TabInfoArray Name="TabInfoArray"> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.cpp" Name="FileName"/> - <int Value="124" Name="FirstVisibleLine"/> - <int Value="151" Name="CurrentLine"/> + <int Value="296" Name="FirstVisibleLine"/> + <int Value="319" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Workspace.h" Name="FileName"/> - <int Value="3" Name="FirstVisibleLine"/> + <int Value="24" Name="FirstVisibleLine"/> <int Value="24" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Bus.cpp" Name="FileName"/> - <int Value="0" Name="FirstVisibleLine"/> - <int Value="10" Name="CurrentLine"/> + <int Value="6" Name="FirstVisibleLine"/> + <int Value="20" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Bus.h" Name="FileName"/> <int Value="0" Name="FirstVisibleLine"/> - <int Value="11" Name="CurrentLine"/> + <int Value="18" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Element.cpp" Name="FileName"/> - <int Value="8" Name="FirstVisibleLine"/> - <int Value="32" Name="CurrentLine"/> + <int Value="66" Name="FirstVisibleLine"/> + <int Value="82" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Element.h" Name="FileName"/> - <int Value="32" Name="FirstVisibleLine"/> - <int Value="55" Name="CurrentLine"/> + <int Value="60" Name="FirstVisibleLine"/> + <int Value="72" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Line.h" Name="FileName"/> <int Value="0" Name="FirstVisibleLine"/> - <int Value="20" Name="CurrentLine"/> + <int Value="14" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> <TabInfo> <wxString Value="C:\Users\Thales\Documents\GitHub\PSP\Project\Line.cpp" Name="FileName"/> - <int Value="0" Name="FirstVisibleLine"/> - <int Value="19" Name="CurrentLine"/> + <int Value="69" Name="FirstVisibleLine"/> + <int Value="98" Name="CurrentLine"/> <wxArrayString Name="Bookmarks"/> <IntVector Name="CollapsedFolds"/> </TabInfo> diff --git a/.codelite/PSP.tags b/.codelite/PSP.tags Binary files differindex 8634b95..3f48701 100644 --- a/.codelite/PSP.tags +++ b/.codelite/PSP.tags diff --git a/.codelite/compilation.db b/.codelite/compilation.db Binary files differindex aa03708..0332b48 100644 --- a/.codelite/compilation.db +++ b/.codelite/compilation.db diff --git a/.codelite/compile_commands.json b/.codelite/compile_commands.json index baf2ea6..6269964 100644 --- a/.codelite/compile_commands.json +++ b/.codelite/compile_commands.json @@ -6,8 +6,4 @@ "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.", "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/Workspace.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/Workspace.cpp.o -I. -I.", - "file": "C:\\Users\\Thales\\Documents\\GitHub\\PSP\\Project\\Workspace.cpp" }]
\ No newline at end of file diff --git a/.codelite/refactoring.db b/.codelite/refactoring.db Binary files differindex a443b36..4c92b1b 100644 --- a/.codelite/refactoring.db +++ b/.codelite/refactoring.db diff --git a/Project/Element.cpp b/Project/Element.cpp index a485c82..55cb87d 100644 --- a/Project/Element.cpp +++ b/Project/Element.cpp @@ -46,8 +46,18 @@ void Element::DrawRectangle(wxPoint2DDouble* points, GLenum mode) const glEnd(); } +void Element::DrawLine(std::vector<wxPoint2DDouble> points, GLenum mode) const +{ + glBegin(mode); + for(auto it = points.begin(); it != points.end(); ++it) { + glVertex2d((*it).m_x, (*it).m_y); + } + glEnd(); +} + void Element::DrawPickbox(wxPoint2DDouble position) const { + glLineWidth(1.0); glColor4d(1.0, 1.0, 1.0, 0.8); DrawRectangle(position, 8.0, 8.0); glColor4d(0.0, 0.0, 0.0, 1.0); @@ -66,11 +76,29 @@ wxPoint2DDouble Element::RotateAtPosition(wxPoint2DDouble pointToRotate, double void Element::StartMove(wxPoint2DDouble position) { - this->m_moveStartPt = position; - this->m_movePos = m_position; + this->m_moveStartPt = position; + this->m_movePos = m_position; } -void Element::Move(wxPoint2DDouble position) +void Element::Move(wxPoint2DDouble position) { SetPosition(m_movePos + position - m_moveStartPt); } +wxPoint2DDouble Element::GetSwitchPoint(Element* parent, wxPoint2DDouble parentPoint, wxPoint2DDouble secondPoint) const { - SetPosition(m_movePos + position - m_moveStartPt); -}
\ No newline at end of file + double swLineSize = 25.0; + wxPoint2DDouble swPoint = wxPoint2DDouble(parentPoint.m_x, parentPoint.m_y - swLineSize); + + // Rotate the second point (to compare). + double angle = parent->GetAngle(); + + secondPoint = + wxPoint2DDouble(std::cos(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) - + std::sin(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_x, + std::sin(wxDegToRad(-angle)) * (secondPoint.m_x - parentPoint.m_x) + + std::cos(wxDegToRad(-angle)) * (secondPoint.m_y - parentPoint.m_y) + parentPoint.m_y); + + // Rotate + if(secondPoint.m_y > parentPoint.m_y) angle -= 180.0; + return wxPoint2DDouble(std::cos(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) - + std::sin(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_x, + std::sin(wxDegToRad(angle)) * (swPoint.m_x - parentPoint.m_x) + + std::cos(wxDegToRad(angle)) * (swPoint.m_y - parentPoint.m_y) + parentPoint.m_y); +} diff --git a/Project/Element.h b/Project/Element.h index dfffba2..1287bc4 100644 --- a/Project/Element.h +++ b/Project/Element.h @@ -41,31 +41,42 @@ class Element double GetAngle() const { return m_angle; } bool IsPickboxShown() const { return m_showPickbox; } // Pure-virtuals methods - virtual bool AddParent(Element* parent, wxPoint2DDouble position) = 0; + virtual bool AddParent(Element* parent, wxPoint2DDouble position) = 0; virtual void Draw(wxPoint2DDouble translation, double scale) const = 0; virtual void Rotate() = 0; virtual bool Contains(wxPoint2DDouble position) const = 0; - virtual bool Intersects(wxRect2DDouble rect) const = 0; + virtual bool Intersects(wxRect2DDouble rect) const = 0; virtual bool PickboxContains(wxPoint2DDouble position) = 0; virtual void MovePickbox(wxPoint2DDouble position) = 0; virtual wxCursor GetBestPickboxCursor() const = 0; // General methods - virtual void AddPoint(wxPoint2DDouble point) {}; + virtual void AddPoint(wxPoint2DDouble point){}; virtual void StartMove(wxPoint2DDouble position); - virtual void Move(wxPoint2DDouble position); - void ResetPickboxes() { m_activePickboxID = ID_PB_NONE; } - wxPoint2DDouble WorldToScreen(wxPoint2DDouble translation, - double scale, - double offsetX = 0.0, - double offsetY = 0.0) const; - void DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode = GL_LINE_LOOP) const; - void DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode = GL_QUADS) const; - void DrawRectangle(wxPoint2DDouble* points, GLenum mode = GL_QUADS) const; - void DrawPickbox(wxPoint2DDouble position) const; - wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees = true) const; + virtual void Move(wxPoint2DDouble position); + virtual void MoveNode(Element* parent, wxPoint2DDouble position){}; + virtual wxPoint2DDouble GetSwitchPoint(Element* parent, + wxPoint2DDouble parentPoint, + wxPoint2DDouble secondPoint) const; + virtual void ResetPickboxes() { m_activePickboxID = ID_PB_NONE; } + virtual wxPoint2DDouble WorldToScreen(wxPoint2DDouble translation, + double scale, + double offsetX = 0.0, + double offsetY = 0.0) const; + virtual void DrawCircle(wxPoint2DDouble position, double radius, int numSegments, GLenum mode = GL_LINE_LOOP) const; + virtual void DrawRectangle(wxPoint2DDouble position, double width, double height, GLenum mode = GL_QUADS) const; + virtual void DrawRectangle(wxPoint2DDouble* points, GLenum mode = GL_QUADS) const; + virtual void DrawLine(std::vector<wxPoint2DDouble> points, GLenum mode = GL_LINE_STRIP) const; + virtual void DrawPickbox(wxPoint2DDouble position) const; + virtual wxPoint2DDouble RotateAtPosition(wxPoint2DDouble pointToRotate, double angle, bool degrees = true) const; + + virtual std::vector<Element*> GetParentList() const { return m_parentList; } + virtual wxPoint2DDouble GetMoveStartPosition() const { return m_moveStartPt; } + virtual wxPoint2DDouble GetMovePosition() const { return m_movePos; } protected: + std::vector<Element*> m_parentList; + wxRect2DDouble m_rect; wxPoint2DDouble m_position; double m_width = 0.0; @@ -80,7 +91,7 @@ class Element int m_activePickboxID = ID_PB_NONE; wxPoint2DDouble m_moveStartPt; - wxPoint2DDouble m_movePos; + wxPoint2DDouble m_movePos; }; #endif // ELEMENT_H diff --git a/Project/Line.cpp b/Project/Line.cpp index d0df0a2..b8686bb 100644 --- a/Project/Line.cpp +++ b/Project/Line.cpp @@ -3,20 +3,69 @@ Line::Line() {} Line::~Line() {} bool Line::Contains(wxPoint2DDouble position) const { return false; } -void Line::Draw(wxPoint2DDouble translation, double scale) const {} +void Line::Draw(wxPoint2DDouble translation, double scale) const +{ + std::vector<wxPoint2DDouble> pointList = m_pointList; + if(!m_inserted && pointList.size() > 0) { + wxPoint2DDouble secondPoint = m_position; + if(pointList.size() > 2) { + secondPoint = pointList[2]; + } + pointList[1] = GetSwitchPoint(m_parentList[0], pointList[0], secondPoint); + pointList.push_back(m_position); + } + + glLineWidth(1.5); + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawLine(pointList); + + // Draw nodes. + if(pointList.size() > 0) { + glColor4d(0.2, 0.2, 0.2, 1.0); + DrawCircle(pointList[0], 5.0, 10, GL_POLYGON); + if(m_inserted) { + DrawCircle(pointList[pointList.size() - 1], 5.0, 10, GL_POLYGON); + } + } +} + wxCursor Line::GetBestPickboxCursor() const { return wxCURSOR_ARROW; } bool Line::AddParent(Element* parent, wxPoint2DDouble position) { if(parent) { + // First bus. if(m_parentList.size() == 0) { + m_position = position; m_parentList.push_back(parent); - m_pointList.push_back(position); // First point + 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); - m_pointList.push_back(position); // Last point + 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; return true; } } @@ -32,3 +81,20 @@ void Line::AddPoint(wxPoint2DDouble point) m_pointList.push_back(point); } } + +void Line::MoveNode(Element* parent, wxPoint2DDouble position) +{ + // First bus. + if(parent == m_parentList[0]) { + m_pointList[0] = parent->GetMovePosition() + position - parent->GetMoveStartPosition(); + } + // Second bus. + else if(parent == m_parentList[1]) + { + m_pointList[m_pointList.size() - 1] = parent->GetMovePosition() + position - parent->GetMoveStartPosition(); + } + // Recalculate switches positions + m_pointList[1] = GetSwitchPoint(m_parentList[0], m_pointList[0], m_pointList[2]); + m_pointList[m_pointList.size() - 2] = + GetSwitchPoint(m_parentList[1], m_pointList[m_pointList.size() - 1], m_pointList[m_pointList.size() - 3]); +} diff --git a/Project/Line.h b/Project/Line.h index fd68585..6717783 100644 --- a/Project/Line.h +++ b/Project/Line.h @@ -12,6 +12,8 @@ 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 MoveNode(Element* parent, wxPoint2DDouble position); virtual wxCursor GetBestPickboxCursor() const; virtual bool AddParent(Element* parent, wxPoint2DDouble position); virtual bool Intersects(wxRect2DDouble rect) const; @@ -19,9 +21,10 @@ class Line : public Element virtual bool PickboxContains(wxPoint2DDouble position); virtual void Rotate(); virtual void AddPoint(wxPoint2DDouble point); + protected: - std::vector<Element*> m_parentList; std::vector<wxPoint2DDouble> m_pointList; + bool m_inserted = false; }; #endif // LINE_H diff --git a/Project/Project.mk b/Project/Project.mk index d8a7e7f..b4c2164 100644 --- a/Project/Project.mk +++ b/Project/Project.mk @@ -13,7 +13,7 @@ CurrentFileName := CurrentFilePath := CurrentFileFullPath := User :=Thales -Date :=09/08/2016 +Date :=17/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 f8d4fc3..21460aa 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 efeeec9..eb21254 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 1eb02e9..8194ffd 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 0135e56..2a86ce5 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 4f94218..67d882f 100644 --- a/Project/Release/Workspace.cpp.o +++ b/Project/Release/Workspace.cpp.o diff --git a/Project/Release/wxmsw310u_gcc_cl.dll b/Project/Release/wxmsw310u_gcc_64x.dll Binary files differindex 9422e8e..06cdd5c 100644 --- a/Project/Release/wxmsw310u_gcc_cl.dll +++ b/Project/Release/wxmsw310u_gcc_64x.dll diff --git a/Project/Release/wxmsw310u_gcc_custom.dll b/Project/Release/wxmsw310u_gcc_custom.dll Binary files differdeleted file mode 100644 index ab556f8..0000000 --- a/Project/Release/wxmsw310u_gcc_custom.dll +++ /dev/null diff --git a/Project/Release/wxmsw310u_gl_gcc_cl.dll b/Project/Release/wxmsw310u_gl_gcc_64x.dll Binary files differindex 0af00c8..cfe5014 100644 --- a/Project/Release/wxmsw310u_gl_gcc_cl.dll +++ b/Project/Release/wxmsw310u_gl_gcc_64x.dll diff --git a/Project/Release/wxmsw310u_gl_gcc_custom.dll b/Project/Release/wxmsw310u_gl_gcc_custom.dll Binary files differdeleted file mode 100644 index fef4708..0000000 --- a/Project/Release/wxmsw310u_gl_gcc_custom.dll +++ /dev/null diff --git a/Project/Workspace.cpp b/Project/Workspace.cpp index 2bfeeac..f33948b 100644 --- a/Project/Workspace.cpp +++ b/Project/Workspace.cpp @@ -133,20 +133,26 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event) { bool foundElement = false; if(m_mode == MODE_INSERT) { - // Too confuse... + // Get the last element inserted on the list. Element* newElement = *(m_elementList.end() - 1); for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* element = *it; + // Clicked in any element. if(element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { + // Click at a bus. if(typeid(*element) == typeid(Bus)) { + // Select the bus. element->SetSelected(); - foundElement = true; + foundElement = true; // Element found. + // Add the new element's parent. If the element being inserted return true, return + // to edit mode. if(newElement->AddParent(element, m_camera->ScreenToWorld(event.GetPosition()))) { m_mode = MODE_EDIT; } } } } + // The line element can have an indefined number of points. if(!foundElement) { if(typeid(*newElement) == typeid(Line)) { newElement->AddPoint(m_camera->ScreenToWorld(event.GetPosition())); @@ -160,19 +166,23 @@ void Workspace::OnLeftClickDown(wxMouseEvent& event) for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* element = *it; element->ResetPickboxes(); // Reset pickbox state. - element->StartMove(m_camera->ScreenToWorld(event.GetPosition())); + element->StartMove(m_camera->ScreenToWorld( + event.GetPosition())); // Set movement initial position (not necessarily will be moved). + // Click at an element if(element->Contains(m_camera->ScreenToWorld(event.GetPosition()))) { if(!foundElement) { + // Select and show pickbox. element->SetSelected(); element->ShowPickbox(); foundElement = true; } - + // If pickbox contains the click, move the pickbox if(element->PickboxContains(m_camera->ScreenToWorld(event.GetPosition()))) { m_mode = MODE_MOVE_PICKBOX; clickPickbox = true; } + // If didn't foud a pickbox, move the element if(!clickPickbox) { m_mode = MODE_MOVE_ELEMENT; } @@ -242,9 +252,7 @@ void Workspace::OnMouseMotion(wxMouseEvent& event) case MODE_INSERT: { Element* newElement = *(m_elementList.end() - 1); - if(typeid(*newElement) == typeid(Bus)) { - newElement->SetPosition(m_camera->ScreenToWorld(event.GetPosition())); - } + newElement->SetPosition(m_camera->ScreenToWorld(event.GetPosition())); Redraw(); } break; @@ -305,6 +313,16 @@ void Workspace::OnMouseMotion(wxMouseEvent& event) { for(auto it = m_elementList.begin(); it != m_elementList.end(); ++it) { Element* element = *it; + //Parent's element moving... + for(int i=0; i<(int)element->GetParentList().size(); i++) { + //wxMessageBox(wxString::Format("%d", element->GetParentList().size())); + //Element* parent = *itp; + Element* parent = element->GetParentList()[i]; + if(parent->IsSelected()) { + element->MoveNode(parent, m_camera->ScreenToWorld(event.GetPosition())); + //itp = element->GetParentList().end();//Exit the for because the element was already moved. + } + } if(element->IsSelected()) { element->Move(m_camera->ScreenToWorld(event.GetPosition())); Redraw(); |